FEDRA emulsion software from the OPERA Collaboration
EdbCouplesTree Class Reference

#include <EdbCouplesTree.h>

Inheritance diagram for EdbCouplesTree:
Collaboration diagram for EdbCouplesTree:

Public Member Functions

void ApplyCorrections ()
 
void Close ()
 
 EdbCouplesTree ()
 
Int_t Fill ()
 
Int_t Fill (EdbSegP *s1, EdbSegP *s2, EdbSegP *s=0, EdbSegCouple *cp=0, float xv=0, float yv=0, int pid1=0, int pid2=0)
 
int GetCPData (EdbPattern *pat, EdbPattern *p1=0, EdbPattern *p2=0, TIndex2 *trseg=0)
 
int GetCPData (TObjArray &cparr)
 
int GetCPDataAcceptedMask (EdbPattern *pat)
 
int GetEntry (int i)
 
const char * GetFileName () const
 
bool InitCouplesTree (const char *name="couples", const char *fname=0, Option_t *mode="READ")
 
TEventList * InitCutList ()
 
void Print ()
 
int PutCPData (TObjArray &cparr)
 
void RankCouples (TObjArray &cparr)
 
void SaveTree ()
 
bool WriteTree ()
 
virtual ~EdbCouplesTree ()
 

Public Attributes

EdbMaskeAcceptMask
 
bool eApplyCorrections
 
EdbSegCoupleeCP
 
TCut eCut
 
EdbMaskeEraseMask
 
Int_t ePid1
 
Int_t ePid2
 
EdbPlateP ePlate
 
EdbSegPeS
 
EdbSegPeS1
 
EdbSegPeS2
 
TTree * eTree
 
Float_t eXv
 
Float_t eYv
 

Constructor & Destructor Documentation

◆ EdbCouplesTree()

EdbCouplesTree::EdbCouplesTree ( )

◆ ~EdbCouplesTree()

EdbCouplesTree::~EdbCouplesTree ( )
virtual
39 {
40 // most of the members pointers can be the property of other objects
41 // If the file should be closed - use Close()
42  //SafeDelete(eTree);
43  //SafeDelete(eS);
44  //SafeDelete(eS1);
45  //SafeDelete(eS2);
46  //SafeDelete(eEraseMask);
47 }

Member Function Documentation

◆ ApplyCorrections()

void EdbCouplesTree::ApplyCorrections ( )

224 {
225 }

◆ Close()

void EdbCouplesTree::Close ( )

71 {
72  if (eTree) {
73  TFile *f = (TFile*)(eTree->GetDirectory()->GetFile());
74  if (f) {
75  //f->Print();
76  if(f->IsWritable()) eTree->AutoSave();
77  f->Close();
78  //SafeDelete(eTree);
79  //SafeDelete(f);
80  }
81  //SafeDelete(eTree);
82  //eTree=NULL;
83  }
84 }
FILE * f
Definition: RecDispMC.C:150
TTree * eTree
Definition: EdbCouplesTree.h:25

◆ Fill() [1/2]

Int_t EdbCouplesTree::Fill ( )
210 {
211  return eTree->Fill();
212 }

◆ Fill() [2/2]

Int_t EdbCouplesTree::Fill ( EdbSegP s1,
EdbSegP s2,
EdbSegP s = 0,
EdbSegCouple cp = 0,
float  xv = 0,
float  yv = 0,
int  pid1 = 0,
int  pid2 = 0 
)
201 {
202  eS1=s1; eS2=s2; eS=s; eCP=cp;
203  eXv=xv; eYv=yv; ePid1=pid1; ePid2=pid2;
204  //eDZ1 = dz1; eDZ2 = dz2; eFlag=flag;
205  return Fill();
206 }
Float_t eYv
Definition: EdbCouplesTree.h:22
EdbSegP * eS2
Definition: EdbCouplesTree.h:20
EdbSegP * eS1
Definition: EdbCouplesTree.h:20
Int_t ePid1
Definition: EdbCouplesTree.h:23
Float_t eXv
Definition: EdbCouplesTree.h:22
Int_t ePid2
Definition: EdbCouplesTree.h:23
EdbSegCouple * eCP
Definition: EdbCouplesTree.h:21
Int_t Fill()
Definition: EdbCouplesTree.cxx:209
EdbSegP * eS
Definition: EdbCouplesTree.h:20
EdbSegP * s1
Definition: tlg2pattern.C:30
EdbSegP * s2
Definition: tlg2pattern.C:31
EdbSegP * s
Definition: tlg2pattern.C:32
EdbSegCouple * cp
Definition: tlg2pattern.C:29

◆ GetCPData() [1/2]

int EdbCouplesTree::GetCPData ( EdbPattern pat,
EdbPattern p1 = 0,
EdbPattern p2 = 0,
TIndex2 trseg = 0 
)

TO CHECK !!!

326 {
327  TEventList *lst = InitCutList();
328  if (!lst) return 0;
329  int nlst =lst->GetN();
330 
331  int nseg = 0, nerase=0;
332  pat->SetID(0);
333 
334  int entr=0;
335  for(int i=0; i<nlst; i++ ) {
336  entr = lst->GetEntry(i);
337 
338 // if(trseg) { //exclude segments participating in tracks
339 // if( (trseg->Find(ePlate*1000+ePiece,entr) >= 0) ) continue;
340 // }
341 
342  if(eEraseMask) if(eEraseMask->At(entr)) {
343  Log(3,"EdbCouplesTree::GetCPData","erase %d\n",entr);
344  nerase++;
345  continue;
346  }
347 
348  GetEntry(entr);
349 
350  if(pat) {
351  eS->SetZ( eS->Z() + pat->Z() );
352  //ToDo: s->SetVid(ePlate*1000+ePiece,entr);
353  eS->SetChi2(eCP->CHI2P());
354  pat->AddSegment( *eS );
355  nseg++;
356  }
357  if(p1) {
358  eS1->SetZ( eS1->Z() + pat->Z() );
359  p1->AddSegment( *eS1 );
360  nseg++;
361  }
362  if(p2) {
363  eS2->SetZ( eS2->Z() + pat->Z() );
364  p2->AddSegment( *eS2 );
365  nseg++;
366  }
367  }
368 
369  SafeDelete(lst);
370 
371  Log(2,"EdbCouplesTree::GetCPData","select %d of %d segments by cut %s ; %d erased by mask",nlst, (int)(eTree->GetEntries()), eCut.GetTitle(), nerase);
372 
373  return nseg;
374 }
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
TCut eCut
Definition: EdbCouplesTree.h:31
int GetEntry(int i)
Definition: EdbCouplesTree.cxx:215
EdbMask * eEraseMask
Definition: EdbCouplesTree.h:27
TEventList * InitCutList()
Definition: EdbCouplesTree.cxx:296
int At(int i)
Definition: EdbMask.h:19
void SetID(int id)
Definition: EdbPattern.h:318
float CHI2P() const
Definition: EdbSegCouple.h:59
Float_t Z() const
Definition: EdbSegP.h:150
void SetZ(float z)
Definition: EdbSegP.h:122
void SetChi2(float chi2)
Definition: EdbSegP.h:132
Float_t Z() const
Definition: EdbPattern.h:87
EdbSegP * AddSegment(int i, EdbSegP &s)
Definition: EdbPattern.cxx:71

◆ GetCPData() [2/2]

int EdbCouplesTree::GetCPData ( TObjArray &  cparr)

229 {
230  //read segments into array of EdbSegCouple objects
231  TEventList *lst = InitCutList();
232  if (!lst) return 0;
233  int nlst =lst->GetN();
234  int nseg = 0, nerase=0;
235  int entr=0;
236  for(int i=0; i<nlst; i++ ) {
237  entr = lst->GetEntry(i);
238 
239  if(eEraseMask) if(eEraseMask->At(entr)) {
240  Log(3,"EdbCouplesTree::GetCPData","erase %d\n",entr);
241  nerase++;
242  continue;
243  }
244 
245  GetEntry(entr);
246  EdbSegCouple *cp = new EdbSegCouple(*eCP);
247  cp->eS = new EdbSegP(*eS);
248  cp->eS1 = new EdbSegP(*eS1);
249  cp->eS2 = new EdbSegP(*eS2);
250  cparr.Add( cp );
251 
252  nseg++;
253  }
254 
255  SafeDelete(lst);
256 
257  Log(2,"EdbCouplesTree::GetCPData","select %d of %d segments by cut %s ; %d erased by mask",nlst, (int)(eTree->GetEntries()), eCut.GetTitle(), nerase);
258 
259  return nseg;
260 }
Definition: EdbSegCouple.h:14
EdbSegP * eS
Definition: EdbSegCouple.h:24
EdbSegP * eS2
pointers - useful when all segments are in memory
Definition: EdbSegCouple.h:26
EdbSegP * eS1
the result of the fit
Definition: EdbSegCouple.h:25
Definition: EdbSegP.h:18

◆ GetCPDataAcceptedMask()

int EdbCouplesTree::GetCPDataAcceptedMask ( EdbPattern pat)

TO CHECK !!!

378 {
379  if(!eAcceptMask) return 0;
380  int n = eAcceptMask->N();
381  pat->SetID(0);
382  int nseg=0;
383  for(int i=0; i<n; i++ ) {
384  if(eAcceptMask->At(i)>0) {
385  GetEntry(i);
386  if(pat) {
387  eS->SetZ( eS->Z() + pat->Z() );
388  //ToDo: s->SetVid(ePlate*1000+ePiece,entr);
389  eS->SetChi2(eCP->CHI2P());
390  pat->AddSegment( *eS );
391  nseg++;
392  }
393  }
394  }
395 
396  Log(2,"EdbCouplesTree::GetCPDataAcceptedMask","select %d of %d segments",nseg, (int)(eTree->GetEntries()));
397 
398  return nseg;
399 }
EdbMask * eAcceptMask
Definition: EdbCouplesTree.h:28
int N()
Definition: EdbMask.h:18

◆ GetEntry()

int EdbCouplesTree::GetEntry ( int  i)

216 {
217  int size = eTree->GetEntry(i);
219  return size;
220 }
void ApplyCorrections()
Definition: EdbCouplesTree.cxx:223
bool eApplyCorrections
Definition: EdbCouplesTree.h:32

◆ GetFileName()

const char* EdbCouplesTree::GetFileName ( ) const
inline
52 { if(eTree->GetCurrentFile()) return eTree->GetCurrentFile()->GetName(); else return 0;}

◆ InitCouplesTree()

bool EdbCouplesTree::InitCouplesTree ( const char *  name = "couples",
const char *  fname = 0,
Option_t *  mode = "READ" 
)
88 {
89  Log(3,"EdbCouplesTree::InitCouplesTree","%s at file %s as %s",name,fname,mode);
90  if(fname) { // if fname==0 - assumed that file is already opened
91  //TFile *f = new TFile(fname, mode);
92  //printf("\n ROOT dir before:\n"); gDirectory->ls(); printf("\n");
93  TFile *f = TFile::Open(fname, mode);
94  //printf("\n ROOT dir after:\n"); gDirectory->ls(); printf("\n");
95  if (!f->IsOpen()) return 0;
96  f->cd();
97  }
98 
99  if( (strcmp(mode,"READ")==0)) {
100  eTree = (TTree*)gDirectory->Get(name);
101  if(!eTree) {Log(1,"EdbCouplesTree::InitCouplesTree","ERROR: can not open tree %s",name); return 0;}
102 
103  eTree->SetBranchAddress("pid1", &ePid1);
104  eTree->SetBranchAddress("pid2", &ePid2);
105  eTree->SetBranchAddress("xv" , &eXv);
106  eTree->SetBranchAddress("yv" , &eYv);
107  eTree->SetBranchAddress("cp" , &eCP);
108  eTree->SetBranchAddress("s1." , &eS1);
109  eTree->SetBranchAddress("s2." , &eS2);
110  eTree->SetBranchAddress("s." , &eS);
111  return 1;
112  if( (strcmp(mode,"UPDATE")==0) ) {
113  eTree = (TTree*)gDirectory->Get(name);
114  if(eTree) {
115  eTree->SetBranchAddress("pid1", &ePid1);
116  eTree->SetBranchAddress("pid2", &ePid2);
117  eTree->SetBranchAddress("xv" , &eXv);
118  eTree->SetBranchAddress("yv" , &eYv);
119  eTree->SetBranchAddress("cp" , &eCP);
120  eTree->SetBranchAddress("s1." , &eS1);
121  eTree->SetBranchAddress("s2." , &eS2);
122  eTree->SetBranchAddress("s." , &eS);
123  return 1;
124  }
125  }
126  }
127 
128  const char *fn = fname;
129  if(!fn) if(gDirectory->GetFile()) fn=gDirectory->GetFile()->GetName();
130  Log(2,"EdbCouplesTree::InitCouplesTree","create new tree %s in %s",name, fn);
131 
132  eTree = new TTree(name, "couples tree (s1:s2:s)");
133  eTree->SetMaxTreeSize(64000000000LL); //set 64 Gb file size limit)
134 
135  eTree->Branch("pid1", &ePid1,"pid1/I");
136  eTree->Branch("pid2", &ePid2,"pid2/I");
137  eTree->Branch("xv" , &eXv,"xv/F");
138  eTree->Branch("yv" , &eYv,"yv/F");
139  eTree->Branch("cp" , &eCP,32000,99);
140  eTree->Branch("s1." , &eS1,32000,99);
141  eTree->Branch("s2." , &eS2,32000,99);
142  eTree->Branch("s." , &eS,32000,99);
143 
144  return 1;
145 }
const char * fname
Definition: mc2raw.cxx:41
const char * name
Definition: merge_Energy_SytematicSources_Electron.C:24

◆ InitCutList()

TEventList * EdbCouplesTree::InitCutList ( )

297 {
298  if(!eTree) return 0;
299  int nentr = (int)(eTree->GetEntries()); if(nentr<1) return 0;
300  eTree->Draw(">>lst", eCut );
301  TEventList *lst = (TEventList*)(gDirectory->GetList()->FindObject("lst"));
302  if(!lst) {Log(1,"EdbCouplesTree::GetCPData","ERROR!: events list (lst) did not found! In couples tree %d entries",nentr); return 0;}
303  return lst;
304 }

◆ Print()

void EdbCouplesTree::Print ( )
51 {
52  Log(1,"EdbCouplesTree::Print","s1 s2 s cp:");
53  if(eS1) eS1->PrintNice();
54  if(eS2) eS2->PrintNice();
55  if(eS) eS->PrintNice();
56  if(eCP) eCP->Print();
57 }
void Print()
Definition: EdbSegCouple.cxx:67
void PrintNice() const
Definition: EdbSegP.cxx:418

◆ PutCPData()

int EdbCouplesTree::PutCPData ( TObjArray &  cparr)

308 {
309  int n = cparr.GetEntries();
310  for(int i=0; i<n; i++)
311  {
312  EdbSegCouple *cp = (EdbSegCouple *)cparr.UncheckedAt(i);
313  if(cp) {
314  eCP = cp;
315  eS = cp->eS;
316  eS1 = cp->eS1;
317  eS2 = cp->eS2;
318  Fill();
319  }
320  }
321  return n;
322 }

◆ RankCouples()

void EdbCouplesTree::RankCouples ( TObjArray &  cparr)

264 {
265  // rank couples if in cparr the same segment's pointer appare in several combinations
266  EdbSegCouple::SetSortFlag(0); // sort by CHI2P
267  cparr.UnSort();
268  cparr.Sort();
269 
270  int ncp = cparr.GetEntries();
271 
272  for(int i=0; i<ncp; i++) {
273  EdbSegCouple *sc = (EdbSegCouple*)(cparr.UncheckedAt(i));
274  sc->eS1->SetFlag(0);
275  sc->eS2->SetFlag(0);
276  }
277 
278  for(int i=0; i<ncp; i++) {
279  EdbSegCouple *sc = (EdbSegCouple*)(cparr.UncheckedAt(i));
280  sc->eS1->SetFlag( sc->eS1->Flag()+1 );
281  sc->eS2->SetFlag( sc->eS2->Flag()+1 );
282  sc->SetN1(sc->eS1->Flag());
283  sc->SetN2(sc->eS2->Flag());
284  }
285 
286  for(int i=0; i<ncp; i++) {
287  EdbSegCouple *sc = (EdbSegCouple*)(cparr.UncheckedAt(i));
288  sc->SetN1tot(sc->eS1->Flag());
289  sc->SetN2tot(sc->eS2->Flag());
290  }
291 
292  Log(2,"EdbCouplesTree::RankCouples","%d couples ok", ncp );
293 }
void SetN1(int n1)
Definition: EdbSegCouple.h:40
void SetN2(int n2)
Definition: EdbSegCouple.h:41
void SetN1tot(int n)
Definition: EdbSegCouple.h:42
void SetN2tot(int n)
Definition: EdbSegCouple.h:43
static void SetSortFlag(int s=0)
Definition: EdbSegCouple.cxx:61
void SetFlag(int flag)
Definition: EdbSegP.h:127
Int_t Flag() const
Definition: EdbSegP.h:146

◆ SaveTree()

void EdbCouplesTree::SaveTree ( )

61 {
62  if(eTree)
63  {
64  TFile *f = (TFile*)(eTree->GetDirectory()->GetFile());
65  if(f->IsWritable()) eTree->AutoSave();
66  }
67 }

◆ WriteTree()

bool EdbCouplesTree::WriteTree ( )
192 {
193  if(!eTree) return 0;
194  eTree->Write();
195  SafeDelete(eTree);
196  return 1;
197 }

Member Data Documentation

◆ eAcceptMask

EdbMask* EdbCouplesTree::eAcceptMask

◆ eApplyCorrections

bool EdbCouplesTree::eApplyCorrections

◆ eCP

EdbSegCouple* EdbCouplesTree::eCP

◆ eCut

TCut EdbCouplesTree::eCut

◆ eEraseMask

EdbMask* EdbCouplesTree::eEraseMask

◆ ePid1

Int_t EdbCouplesTree::ePid1

◆ ePid2

Int_t EdbCouplesTree::ePid2

◆ ePlate

EdbPlateP EdbCouplesTree::ePlate

◆ eS

EdbSegP * EdbCouplesTree::eS

◆ eS1

EdbSegP* EdbCouplesTree::eS1

◆ eS2

EdbSegP * EdbCouplesTree::eS2

◆ eTree

TTree* EdbCouplesTree::eTree

◆ eXv

Float_t EdbCouplesTree::eXv

◆ eYv

Float_t EdbCouplesTree::eYv

The documentation for this class was generated from the following files: