FEDRA emulsion software from the OPERA Collaboration
ShowRec_InBTFilling.cpp File Reference
This graph shows which files directly or indirectly include this file:

Functions

void FillGlobalInBTArrayNEW ()
 

Function Documentation

◆ FillGlobalInBTArrayNEW()

void FillGlobalInBTArrayNEW ( )

— ONLY DEBUG —

— ONLY DEBUG —

4 {
5  Log(2, "ShowRec.cpp", "--- void FillGlobalInBTArrayNEW() ---");
6 
7  // Old FillGlobalInBTArray is unclear and poorly written.
8 
9  //--------------------------------------------------------
10  // To fill the Initiator BT array from the gAli
11  // watching boundary conditions for the Plates, MC Cut.
12  //--------------------------------------------------------
13  GLOBAL_InBTArray = new TObjArray();
14  GLOBAL_ShowerSegArray = new TObjArray();
15  EdbSegP *segment;
16  //--------------------------------------------------------
17 
18  // Informational Debug Output
19  cout << "---!! DOWNSTREAM ORDER ASSUMED !!---"<<endl;
20  cout << "---!! IF PROGRAM CRASH HERE, CHECK YOUR INPUT FP,NP;MP;LP !!---"<<endl;
21 
22  cout << "---!! TO BE DONE: WHAT IF BRICK IS IN UPSTREAM ORDERING ??? !!---"<<endl;
23 
24  Int_t npat = GLOBAL_gAli->Npatterns(); //number of plates
25  Int_t firstplate= npat-cmd_FP;
26  Int_t middleplate= npat-cmd_MP;
27  // Change because the lastplate can also be the middleplate (then, by definition, only
28  // showers on the plate will be reconstructed..)
29  //Int_t lastplate= TMath::Max(npat-cmd_LP-1,0); // attention, change (date: 2018 06 20)
30  Int_t lastplate= TMath::Max(npat-cmd_LP,0); // attention, change (date: 2018 06 20)
31 
32  Float_t GLOBAL_gAli__firstplate_Z=GLOBAL_gAli->GetPattern(firstplate)->Z();
33  Float_t GLOBAL_gAli__middleplate_Z=GLOBAL_gAli->GetPattern(middleplate)->Z();
34  Float_t GLOBAL_gAli__lastplate_Z=GLOBAL_gAli->GetPattern(lastplate)->Z();
35 
36  //--------------------------------------------------------
37  if (gEDBDEBUGLEVEL>2) {
38  cout << "--- FillGlobalInBTArray: DOWNSTREAM ORDER" <<endl;
39  cout << "--- npat = " << npat << endl;
40  cout << "--- firstplate = " << firstplate << endl;
41  cout << "--- middleplate = " << middleplate << endl;
42  cout << "--- lastplate = " << lastplate << endl;
43  cout << " GLOBAL_gAli->GetPattern(firstplate)->Z() = " << GLOBAL_gAli->GetPattern(firstplate)->Z() << endl;
44  cout << " GLOBAL_gAli->GetPattern(middleplate)->Z() = " << GLOBAL_gAli->GetPattern(middleplate)->Z() << endl;
45  cout << " GLOBAL_gAli->GetPattern(lastplate)->Z() = " << GLOBAL_gAli->GetPattern(lastplate)->Z() << endl;
46  }
47  //--------------------------------------------------------
48 
49  // return;
50 
51 
52  // Decision Branch for efficiently filling the InBT Array:
53  /*
54  0) criterion Source:
55  -> From Volume
56  -> From LinkedTrack file
57  1) criterion Plate range:
58  -> All from [FP..MP]
59  2) criterion MC-value
60  -> All
61  -> specific MC-event number
62  3) criterion PDG-value
63  -> All
64  -> specific PDG-number (only one at the moment)
65  4) criterion HPLZ
66  -> HPLZ=0 All
67  -> HPLZ=1 Take Highest P() value for each MCEvt
68  -> HPLZ=2 Take Lowest (i.e. lowest) z occurence for each MCEvt
69 
70  5) criterion vertex IP Cut cmd_vtx
71  -> cmd_vtx=0 All
72  -> cmd_vtx=1 IP<100 microns
73  -> cmd_vtx=2 IP<250 microns
74  -> cmd_vtx=3 IP<500 microns
75  -> cmd_vtx=4 IP<1000 microns
76  -> cmd_vtx=5 IP<5000 microns
77  vtx either given from BRICK.TreePGunInfo.txt and -MC=1
78  or from a "real" vertex file ... to be checked !!
79  */
80 
81 
82  /* Technical Realisation
83  * First time:
84  * Add all (EdbSegP*) selected to TObjArray
85  * Then for each criterion:
86  * Those which do NOT fit the criterion, remove from the TObjArray
87  * CHECK IF BY ROOT MEANS THIS IS POSSIBLE
88  * https://root.cern.ch/root/html604/TObjArray.html
89  * virtual TObject* Remove(TObject* obj)
90  * TObject * Remove(TObject* obj)
91  */
92  cout << "Technical Realisation to be implemented here .... " << endl;
93 
94  TObjArray* arrayIntermediate = new TObjArray();
95 
96  //--------------------------------------------------------
97  /*
98  0) criterion Source:
99  -> From Volume
100  -> From LinkedTrack file
101  */
102  //--------------------------------------------------------
103  // Do this in case of -cmd_LT==1,2,3,4 (i.e. -cmd_LT>0)
104  // 1: all starting BTs of a track are taken.
105  // 2: all ending BTs of a track are taken.
106  // 3: all BTs of a track are taken.
107  // 4: (to be specified)
108  //--------------------------------------------------------
109  if (cmd_LT>0) {
110 
111  if (gEDBDEBUGLEVEL>2) cout << "--- Doing filling InBT case cmd_LT>0"<<endl;
112  EdbSegP * s2=0;
113  EdbTrackP *t = 0;
114  TFile * fil = new TFile("linked_tracks.root");
115  TTree* tr= (TTree*)fil->Get("tracks");
116  TClonesArray *seg= new TClonesArray("EdbSegP",60);
117  int nentr = int(tr->GetEntries());
118  int nseg,n0,npl;
119  tr->SetBranchAddress("t.", &t );
120  tr->SetBranchAddress("s", &seg );
121  tr->SetBranchAddress("nseg", &nseg );
122  tr->SetBranchAddress("n0", &n0 );
123  tr->SetBranchAddress("npl", &npl );
124  //tr->Show(0);
125 
126  // Just add the basetracks from the tracks to the global InBTArray.
127  for (int i=0; i<nentr; i++ ) {
128  tr->GetEntry(i);
129  if (gEDBDEBUGLEVEL>3) tr->Show(i);
130 
131  // depending on cmd_LT=1,2,3 different loops have to be gone through:
132  for (int k=0; k<nseg; k++ ) {
133  //cout << "----- Doing i= " << i << " and k= " << k<< endl;
134  if (cmd_LT==1 && k>0) continue; // only first BT
135  if (cmd_LT==2 && k<nseg-1) continue; // only last BT
136  // Take first BT of the tracks:
137  s2=(EdbSegP*) seg->At(k);
138  segment=(EdbSegP*)s2->Clone();
139  //--------------------------------------------------------
140  /*
141  1) criterion Plate range:
142  -> All from [FP..MP]
143  */
144  //--------------------------------------------------------
145  // Comparison is done via the z-values of the plates
146  Float_t patZ=segment->Z();
147  if (patZ<GLOBAL_gAli__firstplate_Z || patZ>GLOBAL_gAli__middleplate_Z) continue;
148 
149  arrayIntermediate->Add(segment);
150 
151  } // of for(int k=0; k<nseg; k++ )
152  } // for(int i=0; i<nentr; i++ )
153  delete tr;
154  delete fil;
155  if (gEDBDEBUGLEVEL>2) cout << "--- Filled " << arrayIntermediate->GetEntries() << " Segments into arrayIntermediate."<<endl;
156  } // end of Do this in case of -cmd_LT>0
157  else if (cmd_LT==0) {
158  cout << "cmd_LT==0" << endl;
159  for (Int_t nr=0; nr<npat; ++nr) {
160 
161  //--------------------------------------------------------
162  /*
163  1) criterion Plate range:
164  -> All from [FP..MP]
165  */
166  //--------------------------------------------------------
167  // Comparison is done via the z-values of the plates
168  Float_t patZ=GLOBAL_gAli->GetPattern(nr)->Z();
169  // cout << "Doing pattern at: " << nr << " with Z()= " << patZ << endl;
170 
171  Bool_t InRange=1;
172  if (patZ<GLOBAL_gAli__firstplate_Z || patZ>GLOBAL_gAli__middleplate_Z) InRange=0;
173  // cout << "Is this pattern element [FP,MP]?" << InRange << endl;
174  if ( !InRange) continue;
175 
176  //cout << "GLOBAL_gAli->GetPattern(nr)->GetN() " << GLOBAL_gAli->GetPattern(nr)->GetN() << endl;
177  //cout << "arrayIntermediate->GetEntries() " << arrayIntermediate->GetEntries() << endl;
178  for (Int_t n=0; n<GLOBAL_gAli->GetPattern(nr)->GetN(); ++n) {
179  segment=GLOBAL_gAli->GetPattern(nr)->GetSegment(n);
180  arrayIntermediate->Add(segment);
181  }
182  }
183  } // Do this in case of -cmd_LT==0
184  //--------------------------------------------------------
185  else {
186  cout << "--- Attention: given cmd_LT value does not macht any criterion. " << endl;
187  cout << "--- Dont fill the arrayIntermediate with anything." << endl;
188  }
189 
190  cout << "--- Criterion 0) Source done." << endl;
191  cout << "--- Criterion 1) Plate range done." << endl;
192  cout << "--- arrayIntermediate->GetEntries() = " << arrayIntermediate->GetEntries() << endl;
193 
194  //--------------------------------------------------------
195  /*
196  2) criterion MC-value
197  -> All
198  -> specific MC-event number (cmd_MC = #nr)
199  */
200  //--------------------------------------------------------
201  TObjArray* arrayIntermediate2 = new TObjArray();
202 
203  Int_t nEnt = arrayIntermediate->GetEntries();
204  Int_t numberMC;
205 
206  for (Int_t n=0; n<nEnt; ++n) {
207  segment=(EdbSegP*) arrayIntermediate->At(n);
208  numberMC = segment->MCEvt();
209  if (cmd_MC == 0 ) arrayIntermediate2->Add(segment);
210  if (cmd_MC == 1 ) if (numberMC>=0) arrayIntermediate2->Add(segment);
211  if (cmd_MC == 2 ) if (numberMC <0) arrayIntermediate2->Add(segment);
212  }
213  cout << "--- Criterion 2) MC flag range done." << endl;
214  cout << "--- arrayIntermediate2->GetEntries() = " << arrayIntermediate2->GetEntries() << endl;
215 
216  //--------------------------------------------------------
217  /*
218  3) criterion PDG-value
219  -> All (cmd_MCFL = 0)
220  -> specific PDG-number (only one at the moment)
221  */
222  //--------------------------------------------------------
223  TObjArray* arrayIntermediate3 = new TObjArray();
224  // if cmd_MCFL==0 (default) then add all segments anyway,
225  // which is equivalent to just copy the array.
226  if (cmd_MCFL == 0 ) {
227  arrayIntermediate3 = arrayIntermediate2;
228  }
229  else {
230  nEnt = arrayIntermediate2->GetEntries();
231  Int_t numberPDGId;
232  for (Int_t n=0; n<nEnt; ++n) {
233  segment=(EdbSegP*) arrayIntermediate2->At(n);
234  //segment->Print();
235  numberPDGId = segment->Flag();
236  if (numberPDGId == cmd_MCFL ) arrayIntermediate3->Add(segment);
237  }
238  }
239  cout << "--- Criterion 3) PDG-value done." << endl;
240  cout << "--- Criterion 3) cmd_MCFL = " << cmd_MCFL << endl;
241  cout << "--- arrayIntermediate3->GetEntries() = " << arrayIntermediate3->GetEntries() << endl;
242 
243  //--------------------------------------------------------
244  /*
245  4) criterion HPLZ
246  -> HPLZ=0 All
247  -> HPLZ=1 Take highest P() value for each MCEvt
248  -> HPLZ=2 Take first (i.e. lowest) z occurence for each MCEvt
249  (if more BT have same minimal Z() value, then take highest P())
250  */
251  //--------------------------------------------------------
252  TObjArray* arrayIntermediate4 = new TObjArray();
253  if (cmd_HPLZ == 0) {
254  arrayIntermediate4 = arrayIntermediate3 ;
255  }
256  else {
257  // Split the two arrays, since only MC array info can be sorted:
258  TObjArray* arrayIntermediateBG = new TObjArray();
259  TObjArray* arrayIntermediateMC = new TObjArray();
260  TObjArray* arrayIntermediateFHZP = new TObjArray();
261 
262  nEnt = arrayIntermediate3->GetEntries();
263  for (Int_t n=0; n<nEnt; ++n) {
264  segment=(EdbSegP*) arrayIntermediate3->At(n);
265  if ( segment->MCEvt()<0) arrayIntermediateBG->Add(segment);
266  else arrayIntermediateMC->Add(segment);
267  }
268  //cout << "--- arrayIntermediateBG->GetEntries() = " << arrayIntermediateBG->GetEntries() << endl;
269  //cout << "--- arrayIntermediateMC->GetEntries() = " << arrayIntermediateMC->GetEntries() << endl;
270  EdbSegP* seg;
271  EdbSegP* segComp;
272  Int_t NarrayIntermediateMC=arrayIntermediateMC->GetEntries();
273  Bool_t OtherSegGreaterPSameMC=kFALSE;
274  Bool_t OtherSegLowerZSameMC=kFALSE;
275  Int_t segMC=-1;
276  Float_t segZ=-1;
277  Int_t segCompMC=-1;
278 
279  // Find minimum and maximum Eventnumber and Z position
280  // in the arrayIntermediateMC array:
281  Int_t segMCmin=NarrayIntermediateMC;
282  Int_t segMCmax=-1;
283 
284  for (Int_t n=0; n<NarrayIntermediateMC; ++n) {
285  seg=(EdbSegP*) arrayIntermediateMC->At(n);
286  segMC = seg->MCEvt();
287  segZ = seg->Z();
288  if (segMC>segMCmax) segMCmax = segMC;
289  if (segMC<segMCmin) segMCmin = segMC;
290  }
291 
292  // cmd_HPLZ == 1 Take highest P() segment per each MCEvt.
293  // cmd_HPLZ == 2 Take first (lowest) Z() semgment per each MCEvt
294  // In case two (or more) BTs have same lowest Z()
295  // then take the highest P() BT.
296 
297  if (cmd_HPLZ == 1 || cmd_HPLZ == 2) {
298  if (cmd_HPLZ == 1) cout << "Take highest P() segment per each MCEvt." << endl;
299  if (cmd_HPLZ == 2) cout << "Take lowest Z() segment per each MCEvt." << endl;
300  // Try search with arrays instead of double loops! Yes, works much faster!
301  // After MCEvt range is set, start to look for highest P() value for each MCEvt:
302  Float_t segP, segZ;
303  Float_t segPmax[segMCmax+1];
304  Int_t segn[segMCmax+1];
305  Float_t segZmin[segMCmax+1];
306  Int_t segm[segMCmax+1];
307 
308  // Reset all array values
309  for (Int_t nrMC=segMCmin; nrMC<=segMCmax; ++nrMC) {
310  segPmax[nrMC]=0;
311  segn[nrMC]=-1;
312  segZmin[nrMC]=9999999999;
313  segm[nrMC]=-1;
314  }
315 
316  EdbSegP* seg2;
317  for (Int_t n=0; n<NarrayIntermediateMC; ++n) {
318  seg=(EdbSegP*) arrayIntermediateMC->At(n);
319  segMC = seg->MCEvt();
320  segP = seg->P();
321  segZ = seg->Z();
322  if (segP>segPmax[segMC]) {
323  segPmax[segMC] = segP;
324  segn[segMC] = n;
325  }
326  if (segZ<segZmin[segMC]) {
327  segZmin[segMC] = segZ;
328  segm[segMC] = n;
329  }
330  // Safe method agains rounding errors:
331  if (TMath::Abs(segZ-segZmin[segMC])<0.1) {
332  // Compare P() with the existing lowest Z segment
333  seg2=(EdbSegP*) arrayIntermediateMC->At(segm[segMC]);
334  //cout << "segP= " << segP << " and seg2->P()= " << seg2->P() << endl;
335  if ( segP > seg2->P() ) {
336  segZmin[segMC] = segZ;
337  segm[segMC] = n;
338  }
339  }
340  }
341 
342  Int_t SegHPLZNumberInArray=0;
343  for (Int_t nrMC=segMCmin; nrMC<=segMCmax; ++nrMC) {
344  if (segn[nrMC]==-1) continue;
345  if (cmd_HPLZ == 1) SegHPLZNumberInArray = segn[nrMC];
346  if (cmd_HPLZ == 2) SegHPLZNumberInArray = segm[nrMC];
347  // cout << "--- For MCEvt " << nrMC << " P() maximal is = " << segPmax[nrMC] << endl;
348  // cout << "--- For MCEvt " << nrMC << " Z() minimal is = " << segZmin[nrMC] << endl;
349  seg=(EdbSegP*) arrayIntermediateMC->At(segn[nrMC]);
350  // cout << "Highest P() segment:" << endl;
351  // seg->PrintNice();
352  seg=(EdbSegP*) arrayIntermediateMC->At(segm[nrMC]);
353  // cout << "Lowest Z() segment:" << endl;
354  // seg->PrintNice();
355  //---------------
356  // Add now the corresponding segment
357  seg=(EdbSegP*) arrayIntermediateMC->At(SegHPLZNumberInArray);
358  arrayIntermediateFHZP->Add(seg);
359  }
360 
361  cout << " Added all FHZP segments. Number of entries = " << arrayIntermediateFHZP->GetEntries() << endl;
362 
363  } // of if (cmd_HPLZ == 1)
364  // unsupported cmd_HPLZ value: copy array before.
365  else {
366  cout << "Warning: unsupported cmd_HPLZ value. Do no cut." << endl;
367  arrayIntermediateFHZP = arrayIntermediate3 ;
368  }
369 
370  // Now merge arrays
371  // arrayIntermediateBG and arrayIntermediateFHZP
372  // into TObjarray* arrayIntermediate4 = new TObjArray();
373  nEnt = arrayIntermediateFHZP->GetEntries();
374  for (Int_t n=0; n<nEnt; ++n) {
375  segment=(EdbSegP*) arrayIntermediateFHZP->At(n);
376  arrayIntermediate4->Add(segment);
377  }
378  nEnt = arrayIntermediateBG->GetEntries();
379  for (Int_t n=0; n<nEnt; ++n) {
380  segment=(EdbSegP*) arrayIntermediateBG->At(n);
381  arrayIntermediate4->Add(segment);
382  }
383 
384  } // of else of if (cmd_HPLZ == 0)
385 
386  cout << "--- Criterion 4) criterion HPLZ " << endl;
387  cout << "--- Criterion 4) cmd_HPLZ = " << cmd_HPLZ << endl;
388  cout << "--- arrayIntermediate4->GetEntries() = " << arrayIntermediate4->GetEntries() << endl;
389 
390  cout << "---- " << endl << endl;
391  cout << "TODO HERE: CRITERION 5 VTX IP CUT ... " << endl;
392  cout << "TODO HERE: CRITERION 5 VTX IP CUT ... " << endl;
393  cout << "WARNING As of July 4th 2018, the VTX IP CUT is not yet implemented " << endl;
394  cout << "in the new FillGlobalInBTArrayNEW() function. TO BE DONE !!! " << endl;
395  cout << "TODO HERE: CRITERION 5 VTX IP CUT ... " << endl;
396  cout << "TODO HERE: CRITERION 5 VTX IP CUT ... " << endl;
397  cout << "---- " << endl << endl;
398 
399  /*
400  5) criterion vertex IP Cut cmd_vtx
401  -> cmd_vtx=0 All
402  -> cmd_vtx=1 IP<100 microns
403  -> cmd_vtx=2 IP<250 microns
404  -> cmd_vtx=3 IP<500 microns
405  -> cmd_vtx=4 IP<1000 microns
406  -> cmd_vtx=5 IP<5000 microns
407  vtx either given from BRICK.TreePGunInfo.txt and -MC=1
408  or from a "real" vertex file ... to be checked !!
409  */
410 
411 
412  // Change the Array:
413  // might leave behind the original array in an unused state...
414  GLOBAL_InBTArray = arrayIntermediate4;
415  Int_t GLOBAL_InBTArrayN= GLOBAL_InBTArray->GetEntries();
416 
417  cout << "GLOBAL_InBTArray filling done.................."<<endl;
418  if (GLOBAL_InBTArray->GetEntries()==0) {
419  cout << "--- GLOBAL_InBTArray->GetEntries() = 0 . RETURN FILL FUNCTION !" << endl;
420  return;
421  }
422 
424  if (gEDBDEBUGLEVEL<0) {
425  EdbSegP* seg0=(EdbSegP*)GLOBAL_InBTArray->At(0);
426  EdbSegP* segend=(EdbSegP*)GLOBAL_InBTArray->At(GLOBAL_InBTArray->GetEntries()-1);
427  cout << "--- GLOBAL_InBTArray->GetEntries() = " << GLOBAL_InBTArray->GetEntries() << endl;
428  cout << "--- GLOBAL_InBTArray->At(0) = " << endl;
429  seg0->PrintNice();
430  cout << "--- GLOBAL_InBTArray->At(Last) = " << endl;
431  segend->PrintNice();
432  }
433 
435  if (gEDBDEBUGLEVEL>2) {
436  for (Int_t n=0; n<GLOBAL_InBTArrayN; ++n) {
437  EdbSegP* seg0=(EdbSegP*)GLOBAL_InBTArray->At(n);
438  seg0->PrintNice();
439  }
440  }
441 
442  // What to do, if GLOBAL_InBTArray has zero entries???
443  cout << "What to do, if GLOBAL_InBTArray has zero entries???" << endl;
444  cout << "Only logical would be that the program stops." << endl;
445  return;
446 }
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
TTree * tr
Definition: Shower_E_FromShowerRoot.C:5
Int_t npat
Definition: Xi2HatStartScript.C:33
EdbPVRec * GLOBAL_gAli
Definition: ShowRec.h:73
TObjArray * GLOBAL_ShowerSegArray
Definition: ShowRec.h:76
Int_t cmd_LT
Definition: ShowRec.h:19
Int_t cmd_FP
Definition: ShowRec.h:15
Int_t cmd_MCFL
Definition: ShowRec.h:21
Int_t cmd_MP
Definition: ShowRec.h:17
Int_t cmd_LP
Definition: ShowRec.h:16
Int_t cmd_MC
Definition: ShowRec.h:20
TObjArray * GLOBAL_InBTArray
Definition: ShowRec.h:74
TTree * t
Definition: check_shower.C:4
Int_t Npatterns() const
Definition: EdbPattern.h:380
EdbPattern * GetPattern(int id) const
Definition: EdbPattern.cxx:1887
Definition: EdbSegP.h:18
Float_t Z() const
Definition: EdbSegP.h:150
Float_t P() const
Definition: EdbSegP.h:149
void PrintNice() const
Definition: EdbSegP.cxx:418
Int_t MCEvt() const
Definition: EdbSegP.h:142
Int_t Flag() const
Definition: EdbSegP.h:146
Float_t Z() const
Definition: EdbPattern.h:87
Int_t GetN() const
Definition: EdbPattern.h:65
EdbSegP * GetSegment(int i) const
Definition: EdbPattern.h:66
Definition: EdbPattern.h:118
gEDBDEBUGLEVEL
Definition: energy.C:7
Int_t cmd_HPLZ
Definition: ShowRec.h:25
EdbSegP * s2
Definition: tlg2pattern.C:31