/[PAMELA software]/PamelaLevel2/src/PamLevel2.cpp
ViewVC logotype

Contents of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.70 - (show annotations) (download)
Wed Dec 10 11:56:35 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: MAIN
Changes since 1.69: +5 -0 lines
New constructor added

1 #include <PamLevel2.h>
2
3
4
5 /////////////////////////////////////////////////////////////////////////////
6 /////////////////////////////////////////////////////////////////////////////
7 /////////////////////////////////////////////////////////////////////////////
8 /////////////////////////////////////////////////////////////////////////////
9
10 void GPamela::Clear(){
11 Irun = 0;
12 Ievnt = 0;
13 Ipa = 0;
14 X0 = 0.;
15 Y0 = 0.;
16 Z0 = 0.;
17 Theta = 0.;
18 Phi = 0.;
19 P0 = 0.;
20 Nthtof = 0;
21 Nthcat = 0;
22 Nthcas = 0;
23 Nthspe = 0;
24 Nstrpx = 0;
25 Nstrpy = 0;
26 Nthcali = 0;
27 Nthcal = 0;
28 Nthnd = 0;
29 Nthcard = 0;
30 }
31
32 void GPamela::Delete(){
33
34 Clear();
35
36 delete [] Ipltof;
37 delete [] Ipaddle;
38 delete [] Ipartof;
39 delete [] Xintof;
40 delete [] Yintof;
41 delete [] Zintof;
42 delete [] Xouttof;
43 delete [] Youttof;
44 delete [] Zouttof;
45 delete [] Ereltof;
46 delete [] Timetof;
47 delete [] Pathtof;
48 delete [] P0tof;
49 delete [] Iparcat;
50 delete [] Icat;
51 delete [] Xincat;
52 delete [] Yincat;
53 delete [] Zincat;
54 delete [] Xoutcat;
55 delete [] Youtcat;
56 delete [] Zoutcat;
57 delete [] Erelcat;
58 delete [] Timecat;
59 delete [] Pathcat;
60 delete [] P0cat;
61 delete [] Iparcas;
62 delete [] Icas;
63 delete [] Xincas;
64 delete [] Yincas;
65 delete [] Zincas;
66 delete [] Xoutcas;
67 delete [] Youtcas;
68 delete [] Zoutcas;
69 delete [] Erelcas;
70 delete [] Timecas;
71 delete [] Pathcas;
72 delete [] P0cas;
73 delete [] Iparspe;
74 delete [] Itrpb;
75 delete [] Itrsl;
76 delete [] Itspa;
77 delete [] Xinspe;
78 delete [] Yinspe;
79 delete [] Zinspe;
80 delete [] Xoutspe;
81 delete [] Youtspe;
82 delete [] Zoutspe;
83 delete [] Xavspe;
84 delete [] Yavspe;
85 delete [] Zavspe;
86 delete [] Erelspe;
87 delete [] Pathspe;
88 delete [] P0spe;
89 delete [] Nxmult;
90 delete [] Nymult;
91 delete [] Npstripx;
92 delete [] Ntstripx;
93 delete [] Istripx;
94 delete [] Qstripx;
95 delete [] Xstripx;
96 delete [] Npstripy;
97 delete [] Ntstripy;
98 delete [] Istripy;
99 delete [] Qstripy;
100 delete [] Ystripy;
101 delete [] Icaplane;
102 delete [] Icastrip;
103 delete [] Icamod;
104 delete [] Enestrip;
105 delete [] Icapl;
106 delete [] Icasi;
107 delete [] Icast;
108 delete [] Xincal;
109 delete [] Yincal;
110 delete [] Zincal;
111 delete [] Erelcal;
112 delete [] Itubend;
113 delete [] Iparnd;
114 delete [] Xinnd;
115 delete [] Yinnd;
116 delete [] Zinnd;
117 delete [] Xoutnd;
118 delete [] Youtnd;
119 delete [] Zoutnd;
120 delete [] Erelnd;
121 delete [] Timend;
122 delete [] Pathnd;
123 delete [] P0nd;
124 delete [] Iparcard;
125 delete [] Icard;
126 delete [] Xincard;
127 delete [] Yincard;
128 delete [] Zincard;
129 delete [] Xoutcard;
130 delete [] Youtcard;
131 delete [] Zoutcard;
132 delete [] Erelcard;
133 delete [] Timecard;
134 delete [] Pathcard;
135 delete [] P0card;
136
137
138 };
139
140
141
142 void GPamela::SetBranchAddress( TChain* fhBookTree ){
143
144 // cout << "fhBookTree "<<fhBookTree << endl;
145 // prepare tree
146 fhBookTree->SetBranchAddress("Irun",&Irun);
147 fhBookTree->SetBranchAddress("Ievnt",&Ievnt);
148 fhBookTree->SetBranchAddress("Ipa",&Ipa);
149 fhBookTree->SetBranchAddress("X0",&X0);
150 fhBookTree->SetBranchAddress("Y0",&Y0);
151 fhBookTree->SetBranchAddress("Z0",&Z0);
152 fhBookTree->SetBranchAddress("Theta",&Theta);
153 fhBookTree->SetBranchAddress("Phi",&Phi);
154 fhBookTree->SetBranchAddress("P0",&P0);
155 fhBookTree->SetBranchAddress("Nthtof",&Nthtof);
156 fhBookTree->SetBranchAddress("Ipltof",Ipltof);
157 fhBookTree->SetBranchAddress("Ipaddle",Ipaddle);
158 fhBookTree->SetBranchAddress("Ipartof",Ipartof);
159 fhBookTree->SetBranchAddress("Xintof",Xintof);
160 fhBookTree->SetBranchAddress("Yintof",Yintof);
161 fhBookTree->SetBranchAddress("Zintof",Zintof);
162 fhBookTree->SetBranchAddress("Xouttof",Xouttof);
163 fhBookTree->SetBranchAddress("Youttof",Youttof);
164 fhBookTree->SetBranchAddress("Zouttof",Zouttof);
165 fhBookTree->SetBranchAddress("Ereltof",Ereltof);
166 fhBookTree->SetBranchAddress("Timetof",Timetof);
167 fhBookTree->SetBranchAddress("Pathtof",Pathtof);
168 fhBookTree->SetBranchAddress("P0tof",P0tof);
169 fhBookTree->SetBranchAddress("Nthcat",&Nthcat);
170 fhBookTree->SetBranchAddress("Iparcat",Iparcat);
171 fhBookTree->SetBranchAddress("Icat",Icat);
172 fhBookTree->SetBranchAddress("Xincat",Xincat);
173 fhBookTree->SetBranchAddress("Yincat",Yincat);
174 fhBookTree->SetBranchAddress("Zincat",Zincat);
175 fhBookTree->SetBranchAddress("Xoutcat",Xoutcat);
176 fhBookTree->SetBranchAddress("Youtcat",Youtcat);
177 fhBookTree->SetBranchAddress("Zoutcat",Zoutcat);
178 fhBookTree->SetBranchAddress("Erelcat",Erelcat);
179 fhBookTree->SetBranchAddress("Timecat",Timecat);
180 fhBookTree->SetBranchAddress("Pathcat",Pathcat);
181 fhBookTree->SetBranchAddress("P0cat",P0cat);
182 fhBookTree->SetBranchAddress("Nthcas",&Nthcas);
183 fhBookTree->SetBranchAddress("Iparcas",Iparcas);
184 fhBookTree->SetBranchAddress("Icas",Icas);
185 fhBookTree->SetBranchAddress("Xincas",Xincas);
186 fhBookTree->SetBranchAddress("Yincas",Yincas);
187 fhBookTree->SetBranchAddress("Zincas",Zincas);
188 fhBookTree->SetBranchAddress("Xoutcas",Xoutcas);
189 fhBookTree->SetBranchAddress("Youtcas",Youtcas);
190 fhBookTree->SetBranchAddress("Zoutcas",Zoutcas);
191 fhBookTree->SetBranchAddress("Erelcas",Erelcas);
192 fhBookTree->SetBranchAddress("Timecas",Timecas);
193 fhBookTree->SetBranchAddress("Pathcas",Pathcas);
194 fhBookTree->SetBranchAddress("P0cas",P0cas);
195 fhBookTree->SetBranchAddress("Nthspe",&Nthspe);
196 fhBookTree->SetBranchAddress("Iparspe",Iparspe);
197 fhBookTree->SetBranchAddress("Itrpb",Itrpb);
198 fhBookTree->SetBranchAddress("Itrsl",Itrsl);
199 fhBookTree->SetBranchAddress("Itspa",Itspa);
200 fhBookTree->SetBranchAddress("Xinspe",Xinspe);
201 fhBookTree->SetBranchAddress("Yinspe",Yinspe);
202 fhBookTree->SetBranchAddress("Zinspe",Zinspe);
203 fhBookTree->SetBranchAddress("Xoutspe",Xoutspe);
204 fhBookTree->SetBranchAddress("Youtspe",Youtspe);
205 fhBookTree->SetBranchAddress("Zoutspe",Zoutspe);
206 fhBookTree->SetBranchAddress("Xavspe",Xavspe);
207 fhBookTree->SetBranchAddress("Yavspe",Yavspe);
208 fhBookTree->SetBranchAddress("Zavspe",Zavspe);
209 fhBookTree->SetBranchAddress("Erelspe",Erelspe);
210 fhBookTree->SetBranchAddress("Pathspe",Pathspe);
211 fhBookTree->SetBranchAddress("P0spe",P0spe);
212 fhBookTree->SetBranchAddress("Nxmult",Nxmult);
213 fhBookTree->SetBranchAddress("Nymult",Nymult);
214 fhBookTree->SetBranchAddress("Nstrpx",&Nstrpx);
215 fhBookTree->SetBranchAddress("Npstripx",Npstripx);
216 fhBookTree->SetBranchAddress("Ntstripx",Ntstripx);
217 fhBookTree->SetBranchAddress("Istripx",Istripx);
218 fhBookTree->SetBranchAddress("Qstripx",Qstripx);
219 fhBookTree->SetBranchAddress("Xstripx",Xstripx);
220 fhBookTree->SetBranchAddress("Nstrpy",&Nstrpy);
221 fhBookTree->SetBranchAddress("Npstripy",Npstripy);
222 fhBookTree->SetBranchAddress("Ntstripy",Ntstripy);
223 fhBookTree->SetBranchAddress("Istripy",Istripy);
224 fhBookTree->SetBranchAddress("Qstripy",Qstripy);
225 fhBookTree->SetBranchAddress("Ystripy",Ystripy);
226 fhBookTree->SetBranchAddress("Nthcali",&Nthcali);
227 fhBookTree->SetBranchAddress("Icaplane",Icaplane);
228 fhBookTree->SetBranchAddress("Icastrip",Icastrip);
229 fhBookTree->SetBranchAddress("Icamod",Icamod);
230 fhBookTree->SetBranchAddress("Enestrip",Enestrip);
231 fhBookTree->SetBranchAddress("Nthcal",&Nthcal);
232 fhBookTree->SetBranchAddress("Icapl",Icapl);
233 fhBookTree->SetBranchAddress("Icasi",Icasi);
234 fhBookTree->SetBranchAddress("Icast",Icast);
235 fhBookTree->SetBranchAddress("Xincal",Xincal);
236 fhBookTree->SetBranchAddress("Yincal",Yincal);
237 fhBookTree->SetBranchAddress("Zincal",Zincal);
238 fhBookTree->SetBranchAddress("Erelcal",Erelcal);
239 fhBookTree->SetBranchAddress("Nthnd",&Nthnd);
240 fhBookTree->SetBranchAddress("Itubend",Itubend);
241 fhBookTree->SetBranchAddress("Iparnd",Iparnd);
242 fhBookTree->SetBranchAddress("Xinnd",Xinnd);
243 fhBookTree->SetBranchAddress("Yinnd",Yinnd);
244 fhBookTree->SetBranchAddress("Zinnd",Zinnd);
245 fhBookTree->SetBranchAddress("Xoutnd",Xoutnd);
246 fhBookTree->SetBranchAddress("Youtnd",Youtnd);
247 fhBookTree->SetBranchAddress("Zoutnd",Zoutnd);
248 fhBookTree->SetBranchAddress("Erelnd",Erelnd);
249 fhBookTree->SetBranchAddress("Timend",Timend);
250 fhBookTree->SetBranchAddress("Pathnd",Pathnd);
251 fhBookTree->SetBranchAddress("P0nd",P0nd);
252 fhBookTree->SetBranchAddress("Nthcard",&Nthcard);
253 fhBookTree->SetBranchAddress("Iparcard",Iparcard);
254 fhBookTree->SetBranchAddress("Icard",Icard);
255 fhBookTree->SetBranchAddress("Xincard",Xincard);
256 fhBookTree->SetBranchAddress("Yincard",Yincard);
257 fhBookTree->SetBranchAddress("Zincard",Zincard);
258 fhBookTree->SetBranchAddress("Xoutcard",Xoutcard);
259 fhBookTree->SetBranchAddress("Youtcard",Youtcard);
260 fhBookTree->SetBranchAddress("Zoutcard",Zoutcard);
261 fhBookTree->SetBranchAddress("Erelcard",Erelcard);
262 fhBookTree->SetBranchAddress("Timecard",Timecard);
263 fhBookTree->SetBranchAddress("Pathcard",Pathcard);
264 fhBookTree->SetBranchAddress("P0card",P0card);
265
266 // fhBookTree->SetBranchStatus("*",0);
267
268 }
269
270 ClassImp(GPamela);
271
272 /////////////////////////////////////////////////////////////////////////////
273 /////////////////////////////////////////////////////////////////////////////
274 /////////////////////////////////////////////////////////////////////////////
275 /////////////////////////////////////////////////////////////////////////////
276 //--------------------------------------
277 //
278 //
279 //--------------------------------------
280 /**
281 * Default constructor
282 */
283 PamTrack::PamTrack(){
284 trk_track = 0;
285 calo_track = 0;
286 tof_track = 0;
287 orb_track = 0;
288 candeleteobj = 0;
289 pscore = 0;
290 iscore = 0;
291 };
292 //--------------------------------------
293 //
294 //
295 //--------------------------------------
296 /**
297 * Constructor
298 */
299 PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r){
300
301 trk_track = 0;
302 calo_track = 0;
303 tof_track = 0;
304 orb_track = 0;
305 // if(t)trk_track = new TrkTrack(*t);
306 // if(c)calo_track = new CaloTrkVar(*c);
307 // if(o)tof_track = new ToFTrkVar(*o);
308 if(t)trk_track = t;
309 if(c)calo_track = c;
310 if(o)tof_track = o;
311 if(r)orb_track = r;
312 candeleteobj = 0;
313
314 };
315 PamTrack::PamTrack(const PamTrack& track){
316
317 TrkTrack *t = track.trk_track;
318 CaloTrkVar *c = track.calo_track;
319 ToFTrkVar *o = track.tof_track;
320 OrbitalInfoTrkVar *r = track.orb_track;
321
322 trk_track = 0;
323 calo_track = 0;
324 tof_track = 0;
325 orb_track = 0;
326 if(t)trk_track = new TrkTrack(*t);
327 if(c)calo_track = new CaloTrkVar(*c);
328 if(o)tof_track = new ToFTrkVar(*o);
329 if(r)orb_track = new OrbitalInfoTrkVar(*r);
330 candeleteobj = 1;
331
332 }
333 void PamTrack::Clear(){
334
335 // cout << "PamTrack::Clear() "<<candeleteobj<<endl;
336 if(candeleteobj){
337 if(trk_track) trk_track->TrkTrack::Clear();
338 if(calo_track) calo_track->CaloTrkVar::Clear();//???
339 if(tof_track) tof_track->ToFTrkVar::Clear();//???
340 if(orb_track) orb_track->OrbitalInfoTrkVar::Clear();//???
341 }else{
342 trk_track = 0;
343 calo_track = 0;
344 tof_track = 0;
345 orb_track = 0;
346 }
347 pscore = 0;
348 iscore = 0;
349
350 }
351 void PamTrack::Delete(){
352 // cout << "PamTrack::Delete() "<<candeleteobj<<endl;
353 if(candeleteobj){
354 if(trk_track) {
355 trk_track->TrkTrack::Clear();
356 delete trk_track;
357 }
358 if(calo_track){
359 calo_track->CaloTrkVar::Clear();//???
360 delete calo_track;
361 }
362 if(tof_track){
363 tof_track->ToFTrkVar::Clear();//???
364 delete tof_track;
365 }
366 if(orb_track){
367 orb_track->OrbitalInfoTrkVar::Clear();//???
368 delete orb_track;
369 }
370 }else{
371 Clear();
372 }
373 }
374 //--------------------------------------
375 //
376 //
377 //--------------------------------------
378 /**
379 * Default Constructor
380 */
381 PamLevel2::PamLevel2(){
382 Initialize();
383 };
384
385 /**
386 * Constructor
387 * @param ddir Name of directory where level2 files are stored.
388 * @param list Name of an ascii file containing the list of file names
389 * @param detlist Options to chose what to load.
390 * Possible options are:
391 * +AUTO --> load all trees/branches in the input files
392 * +(-)ALL --> inlcude(exclude) all trees/branches
393 * +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches
394 * +(-)TRK0 --> include(exclude) tracker level0 tree
395 * +(-)GP --> include exclude GPAMELA output tree
396 * If no options are specified, the default is assumed. Default is:
397 * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
398 */
399 PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
400 Initialize();
401 TList* listf = GetListOfLevel2Files(ddir,list);
402 GetPamTree(listf,detlist);
403 GetRunTree(listf);
404 };
405
406 PamLevel2::PamLevel2(TString ddir,TList *list,TString detlist){
407 Initialize();
408 GetPamTree(list,detlist);
409 GetRunTree(list);
410 };
411 /**
412 * Constructor
413 * @param ddir Name of directory where level2 files are stored.
414 * @param list Name of an ascii file containing the list of file names
415 * Default trees/branches are loaded. Default is:
416 * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
417 */
418 PamLevel2::PamLevel2(TString ddir,TString list){
419 Initialize();
420 TList* listf = GetListOfLevel2Files(ddir,list);
421 GetPamTree(listf,"");
422 GetRunTree(listf);
423 };
424
425
426 void PamLevel2::Initialize(){
427
428 h0_obj = 0;
429 trk0_obj = 0;
430 calo0_obj = 0;
431
432 trk2_obj = 0;
433 trk1_obj = 0;
434 trkh_obj = 0;
435 calo1_obj = 0;
436 calo2_obj = 0;
437 tof_obj = 0;
438 trig_obj = 0;
439 s4_obj = 0;
440 nd_obj = 0;
441 ac_obj = 0;
442 orb_obj = 0;
443 gp_obj = 0;
444
445 run_obj = 0;//new GL_RUN();
446 soft_obj = 0;// Emiliano
447 irun = -1LL;
448 irunt = -1LL;
449 runfirstentry = 0LL;
450 runlastentry = 0LL;
451
452 l0_file = NULL;
453 l0_tree = NULL;
454 iroot = -1;
455 dbc = 0;
456
457 prevshift = 0;
458 maxshift = 10; //EMILIANO
459
460 run_tree = NULL;
461 run_tree_clone = NULL;
462 sel_tree = NULL;
463 sel_tree_clone = NULL;
464
465 irunentry = -1LL;
466 pam_tree = NULL;
467 for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
468
469 totdltime[0] = 0LL;
470 totdltime[1] = 0LL;
471 totdltime[2] = 0LL;
472
473 host = "mysql://localhost/pamelaprod";
474 user = "anonymous";
475 psw = "";
476 const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
477 const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
478 const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
479 if ( !pamdbhost ) pamdbhost = "";
480 if ( !pamdbuser ) pamdbuser = "";
481 if ( !pamdbpsw ) pamdbpsw = "";
482 if ( strcmp(pamdbhost,"") ) host = pamdbhost;
483 if ( strcmp(pamdbuser,"") ) user = pamdbuser;
484 if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
485
486
487
488 // sorted_tracks = 0;//new TRefArray();
489
490 CAL0 = false;
491 CAL1 = true;
492 CAL2 = true;
493 TRK2 = true;
494 TRK1 = false;
495 TRK0 = false;
496 TRKh = false;
497 TRG = true;
498 TOF = true;
499 TOF0 = false;
500 S4 = true;
501 ND = true;
502 AC = true;
503 ORB = true;
504 GP = false;
505
506 RUN = true;
507
508 SELLI = -1;
509
510 ISGP = false;
511
512 DBG = false;
513
514 tsorted=0;
515 timage=0;
516
517 howtosort = "+CAL+TOF";
518 //howtosort = "+TOF";
519 sortthr = 100.;
520
521 };
522 /**
523 * Delete the event (act as Dtor)
524 */
525 void PamLevel2::Delete(){
526
527 if(run_obj)delete run_obj;
528 if(soft_obj)delete soft_obj; //Emiliano
529
530 // cout << "void PamLevel2::Clear()"<<endl;
531 if(h0_obj) delete h0_obj;
532 if(trk0_obj) delete trk0_obj;
533 if(calo0_obj) delete calo0_obj;
534 if(trk1_obj) delete trk1_obj;
535 if(trk2_obj) delete trk2_obj;
536 if(trkh_obj) delete trkh_obj;
537 if(calo1_obj)delete calo1_obj;
538 if(calo2_obj)delete calo2_obj;
539 if(tof_obj) delete tof_obj;
540 if(trig_obj) delete trig_obj;
541 if(s4_obj) delete s4_obj;
542 if(nd_obj) delete nd_obj;
543 if(ac_obj) delete ac_obj;
544 if(orb_obj) delete orb_obj;
545 if(gp_obj) delete gp_obj;
546
547 if(tsorted){
548 tsorted->Delete();
549 delete tsorted;
550 }
551 if(timage){
552 timage->Delete();
553 delete timage;
554 }
555
556 if(dbc){
557 dbc->Close();
558 delete dbc;
559 }
560
561 if(l0_file)l0_file->Close();
562 // if(pam_tree)pam_tree->Delete();;
563
564 if ( pam_tree ){
565 //
566 // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
567 //
568 TList *temp = pam_tree->GetListOfFriends();
569 TList *contents = new TList; // create chain friend list
570 contents->SetOwner();
571 TIter next(temp);
572 TChain *questo = 0;
573 while ( (questo = (TChain*) next()) ){
574 TString name = questo->GetName();
575 contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
576 };
577 //
578 // deleting the main chain
579 //
580 pam_tree->Delete();
581 //
582 // deleting the friends...
583 //
584 TIter next2(contents);
585 TChain *questa = 0;
586 while ( questa = (TChain*)next2() ){
587 TString name = questa->GetName();
588 questa->Delete();
589 questa=NULL;
590 };
591 //
592 };
593 pam_tree = NULL;
594
595 if(run_tree)run_tree->Delete();;
596 if(sel_tree)sel_tree->Delete();;
597 for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
598 if(run_tree_clone)run_tree_clone->Delete();;
599 if(sel_tree_clone)sel_tree_clone->Delete();;
600
601 if(irunoffset) delete [] irunoffset;
602
603 };
604
605 /**
606 * Clear the event (NB! does not deallocate objects)
607 */
608 void PamLevel2::Clear(){
609
610 // cout << "void PamLevel2::Clear()"<<endl;
611
612 //
613 // This method is called once for every entry but RunInfo and SoftInfo do not change until the next run so we cannot clear them here unless we don't
614 // want to load them for each event even if they are the same...
615 //
616 // if(run_obj)delete run_obj;
617 // if(run_obj) run_obj->Clear(); // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
618 // if(soft_obj) soft_obj->Clear();
619
620 if(h0_obj) h0_obj->Clear();
621 // if(trk0_obj) trk0_obj->Clear();
622 if(trk1_obj) trk1_obj->Clear();
623 if(trk2_obj) trk2_obj->Clear();
624 if(trkh_obj) trkh_obj->Clear();
625 if(calo0_obj) calo0_obj->Clear();
626 if(calo1_obj)calo1_obj->Clear();
627 if(calo2_obj)calo2_obj->Clear();
628 if(tof_obj) tof_obj->Clear();
629 if(trig_obj) trig_obj->Clear();
630 if(s4_obj) s4_obj->Clear();
631 if(nd_obj) nd_obj->Clear();
632 if(ac_obj) ac_obj->Clear();
633 if(orb_obj) orb_obj->Clear();
634 if(gp_obj) gp_obj->Clear();
635
636 // if(sorted_tracks)sorted_tracks->Clear();
637 // sorted_tracks.Clear();
638
639 if(tsorted){
640 tsorted->Delete();
641 }
642 if(timage){
643 timage->Delete();
644 }
645 };
646
647 void PamLevel2::Reset(){
648 //
649 // First of all clear everything
650 //
651 Clear();
652 //
653 // close and reset chains and pointers
654 //
655 if ( pam_tree ){
656 //
657 // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
658 //
659 TList *temp = pam_tree->GetListOfFriends();
660 TList *contents = new TList; // create chain friend list
661 contents->SetOwner();
662 TIter next(temp);
663 TChain *questo = 0;
664 while ( (questo = (TChain*) next()) ){
665 TString name = questo->GetName();
666 contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
667 };
668 //
669 // deleting the main chain
670 //
671 pam_tree->Delete();
672 //
673 // deleting the friends...
674 //
675 TIter next2(contents);
676 TChain *questa = 0;
677 while ( questa = (TChain*)next2() ){
678 TString name = questa->GetName();
679 questa->Delete();
680 questa=NULL;
681 };
682 //
683 };
684 pam_tree = NULL;
685 //
686 if(run_tree)run_tree->Delete();;
687 run_tree = NULL;
688 if(sel_tree)sel_tree->Delete();;
689 sel_tree = NULL;
690 //
691 // Close file
692 //
693 if(l0_file)l0_file->Close("R");
694 l0_file = NULL;
695 //
696 h0_obj = 0;
697 trk0_obj = 0;
698 calo0_obj = 0;
699 //
700 trk2_obj = 0;
701 trk1_obj = 0;
702 trkh_obj = 0;
703 calo1_obj = 0;
704 calo2_obj = 0;
705 tof_obj = 0;
706 trig_obj = 0;
707 s4_obj = 0;
708 nd_obj = 0;
709 ac_obj = 0;
710 orb_obj = 0;
711 gp_obj = 0;
712 //
713 // Reset run pointers
714 //
715 run_obj = 0;//new GL_RUN();
716 soft_obj = 0;// Emiliano
717 irun = -1;
718 irunt = -1;
719 runfirstentry = 0ULL;
720 runlastentry = 0ULL;
721 //
722 totdltime[0] = 0LL;
723 totdltime[1] = 0LL;
724 totdltime[2] = 0LL;
725 //
726 };
727
728 Bool_t PamLevel2::IsGood(Bool_t strict){
729 Bool_t goodev=true;
730 //
731 if(calo2_obj && !calo2_obj->IsGood(strict) ) goodev = false;
732 //
733 if ( strict ){
734 if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
735 if(tof_obj && tof_obj->unpackError != 0) goodev = false;
736 if(trig_obj && trig_obj->unpackError != 0) goodev = false;
737 if(s4_obj && s4_obj->unpackError != 0) goodev = false;
738 if(nd_obj && nd_obj->unpackError != 0) goodev = false;
739 if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>3)&1) || ((ac_obj->status[0]>>3)&1)) ) goodev = false;
740 // if(orb_obj)
741 } else {
742 if(nd_obj && nd_obj->unpackError != 0) goodev = false;
743 if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>3)&1) || ((ac_obj->status[0]>>3)&1)) ) goodev = false;
744 };
745 return(goodev);
746 };
747
748 //--------------------------------------
749 //
750 //
751 //--------------------------------------
752 void *PamLevel2::GetPointerTo(const char* c ){
753
754 TString objname = c;
755
756 if(!objname.CompareTo("TrkLevel1")) {
757 if(!trk1_obj){
758 trk1_obj = new TrkLevel1();
759 trk1_obj->Set();
760 }
761 return &trk1_obj;
762 };
763 if(!objname.CompareTo("TrkLevel2")) {
764 if(!trk2_obj){
765 trk2_obj = new TrkLevel2();
766 trk2_obj->Set();
767 }
768 return &trk2_obj;
769 };
770 if(!objname.CompareTo("TrkHough")) {
771 if(!trkh_obj) {
772 trkh_obj = new TrkHough();
773 trkh_obj->Set();
774 }
775 return &trkh_obj;
776 };
777 if(!objname.CompareTo("CaloLevel1")) {
778 if(!calo1_obj) calo1_obj = new CaloLevel1();
779 return &calo1_obj;
780 };
781 if(!objname.CompareTo("CaloLevel2")) {
782 if(!calo2_obj){
783 calo2_obj = new CaloLevel2();
784 calo2_obj->Set();
785 };
786 return &calo2_obj;
787 };
788 if(!objname.CompareTo("ToFLevel2")) {
789 if(!tof_obj){
790 tof_obj = new ToFLevel2();
791 tof_obj->Set();
792 }
793 return &tof_obj;
794 };
795 if(!objname.CompareTo("TrigLevel2")) {
796 if(!trig_obj) trig_obj = new TrigLevel2();
797 return &trig_obj;
798 };
799 if(!objname.CompareTo("S4Level2")) {
800 if(!s4_obj) s4_obj = new S4Level2();
801 return &s4_obj;
802 };
803 if(!objname.CompareTo("NDLevel2")) {
804 if(!nd_obj) nd_obj = new NDLevel2();
805 return &nd_obj;
806 };
807 if(!objname.CompareTo("AcLevel2")) {
808 if(!ac_obj) ac_obj = new AcLevel2();
809 return &ac_obj;
810 };
811 if(!objname.CompareTo("OrbitalInfo")){
812 if(!orb_obj) orb_obj = new OrbitalInfo();
813 return &orb_obj;
814 };
815 if(!objname.CompareTo("GPamela")){
816 if(!gp_obj) gp_obj = new GPamela();
817 return &gp_obj;
818 };
819
820 if(!objname.CompareTo("RunInfo"))return &run_obj;
821
822 if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
823
824 return NULL;
825 };
826 //--------------------------------------
827 //
828 //
829 //--------------------------------------
830 /**
831 * Retrieves the calorimeter track matching the seqno-th tracker stored track.
832 * (If seqno = -1 retrieves the self-trigger calorimeter track)
833 */
834 CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
835
836 if( !calo2_obj )return 0;
837
838 if( calo2_obj->CaloLevel2::ntrk()==0 ){
839 cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
840 return NULL;
841 };
842
843 CaloTrkVar *c = 0;
844 Int_t it_calo=0;
845
846 do{
847 c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
848 it_calo++;
849 } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());
850
851 if(!c || seqno != c->trkseqno){
852 c = 0;
853 if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
854 };
855 return c;
856
857 };
858 //--------------------------------------
859 //
860 //
861 //--------------------------------------
862 /**
863 * Retrieves the ToF track matching the seqno-th tracker stored track.
864 * (If seqno = -1 retrieves the tracker-independent tof track)
865 */
866 ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
867
868 if( !tof_obj )return 0;
869
870 if( tof_obj->ToFLevel2::ntrk()==0 ){
871 cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
872 return NULL;
873 };
874
875 ToFTrkVar *c = 0;
876 Int_t it_tof=0;
877
878 do{
879 c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
880 it_tof++;
881 } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
882
883 if(!c || seqno != c->trkseqno){
884 c = 0;
885 if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
886 };
887 return c;
888
889 };
890
891 //--------------------------------------
892 //
893 //
894 //--------------------------------------
895 /**
896 * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.
897 * (If seqno = -1 retrieves the tracker-independent tof related track)
898 */
899 OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno){
900
901 if( !orb_obj )return 0;
902
903 if( orb_obj->OrbitalInfo::ntrk()==0 ){
904 cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no OrbitalInfo tracks are stored"<<endl;
905 return NULL;
906 };
907
908 OrbitalInfoTrkVar *c = 0;
909 Int_t it_tof=0;
910
911 do{
912 c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
913 it_tof++;
914 } while( c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());
915
916 if(!c || seqno != c->trkseqno){
917 c = 0;
918 if(seqno!=-1)cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match OrbitalInfo stored tracks"<<endl;
919 };
920 return c;
921
922 };
923
924 //--------------------------------------
925 //
926 //
927 //--------------------------------------
928 /**
929 * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.
930 */
931 PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
932
933 cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
934 cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
935
936 CaloTrkVar *c = 0;
937 ToFTrkVar *o = 0;
938 OrbitalInfoTrkVar *r = 0;
939
940 if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
941 if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
942 if(ORB) r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
943
944 // if(t && c && o)track = new PamTrack(t,c,o);
945 PamTrack *track = new PamTrack(t,c,o,r);
946
947 return track;
948
949 };
950 //--------------------------------------
951 //
952 //
953 //--------------------------------------
954 /**
955 * Retrieves the it-th stored track.
956 * It override TrkLevel2::GetTrack(int it).
957 * @param itrk Track number, ranging from 0 to GetNTracks().
958 */
959
960 PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
961
962 cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
963 cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack) OrbitalInfo::GetOrbitalInfoTrkVar(Int_t notrack)"<<endl;
964 cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
965 PamTrack *track = 0;
966
967 if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){
968
969 TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
970 track = GetPamTrackAlong(t);
971
972
973
974 }else{
975 cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
976 };
977
978 return track;
979
980 }
981 //--------------------------------------
982 //
983
984 /**
985 * Sort physical (tracker) tracks. Left here as backward compatibility method.
986 **/
987 void PamLevel2::SortTracks(TString how){
988 printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
989 howtosort = how;
990 SortTracks();
991 };
992
993 //
994 //--------------------------------------
995 /**
996 * Sort physical (tracker) tracks.
997 * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
998 * Sorting cryteria:
999 * TRK: lower chi**2
1000 * CAL: lower Y spatial residual on the first calorimeter plane
1001 * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
1002 * S1: (ask Emiliano)
1003 * S2: (ask Emiliano)
1004 * S3: (ask Emiliano)
1005 * GP: more GP hits
1006 * The default sorting cryterium is "TOF+CAL".
1007 *
1008 * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).
1009 */
1010 void PamLevel2::SortTracks(){
1011 TString how = howtosort;
1012
1013 // cout <<" PamLevel2::SortTracks(TString how) "<<endl;
1014 if( !trk2_obj ){
1015 cout << "void PamLevel2::SortTracks(): TrkLevel2 not loaded !!!";
1016 return;
1017 };
1018 //Save current Object count
1019 Int_t ObjectNumber = TProcessID::GetObjectCount();
1020
1021 // create TCloneArrays to store tracks and its images
1022 if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1023 tsorted->Delete();
1024 TClonesArray &ttsorted = *tsorted;
1025
1026 if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1027 timage->Delete();
1028 TClonesArray &ttimage = *timage;
1029
1030
1031
1032 //--------------------------------------------------
1033 // retrieve sorting method
1034 //--------------------------------------------------
1035 Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
1036 Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
1037 Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
1038 Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
1039 Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
1040 Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
1041 Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
1042
1043 if ( use_TOF ){
1044 use_S1 = true;
1045 use_S2 = true;
1046 use_S3 = true;
1047 };
1048 if( !CAL2 && use_CAL) use_CAL = false;
1049 if( !TOF ){
1050 use_TOF = false;
1051 use_S1 = false;
1052 use_S2 = false;
1053 use_S3 = false;
1054 }
1055 if( !GP ){
1056 use_GP = false;
1057 }
1058
1059 if( !TRK2 ){
1060 cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
1061 return;
1062 };
1063
1064 // cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
1065
1066
1067 //--------------------------------------------------
1068 // loop over "physical" tracks sorted by the tracker
1069 //--------------------------------------------------
1070 for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1071
1072 TrkTrack *ts = 0;
1073 CaloTrkVar *cs = 0;
1074 ToFTrkVar *os = 0;
1075 OrbitalInfoTrkVar *rs = 0;
1076
1077 // get tracker tracks
1078 TrkTrack *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1079 CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1080 ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo());
1081 OrbitalInfoTrkVar *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1082
1083 TrkTrack *ti = 0; //tracker (image)
1084 CaloTrkVar *ci = 0;
1085 ToFTrkVar *oi = 0;
1086 OrbitalInfoTrkVar *ri = 0;
1087 // cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1088 // if track has an image, check image selection
1089
1090 Int_t tp_score = 0; //main track sorted by the tracker
1091 Int_t ti_score = 0; //image track
1092 Int_t totp_score = 0; //main track sorted by the tracker
1093 Int_t toti_score = 0; //image track
1094
1095 if(tp->HasImage()){
1096
1097 ti = trk2_obj->TrkLevel2::GetTrackImage(i); //tracker (image)
1098 ci = GetCaloStoredTrack(ti->GetSeqNo());
1099 oi = GetToFStoredTrack(ti->GetSeqNo());
1100 ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());
1101
1102 // cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1103
1104 //assign starting scores
1105 tp_score = 0; //main track sorted by the tracker
1106 ti_score = 0; //image track
1107
1108 // -----------------------------------------------------------------------------------------
1109 // *****************************************************************************************
1110 // -----------------------------------------------------------------------------------------
1111 // calorimeter check
1112 // -----------------------------------------------------------------------------------------
1113 if( use_CAL && !calo2_obj ){
1114 cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1115 return;
1116 };
1117 if( use_CAL && !cp && ci ){
1118 ti_score++;
1119 toti_score++;
1120 };
1121 if( use_CAL && cp && !ci ){
1122 tp_score++;
1123 totp_score++;
1124 };
1125 if(
1126 use_CAL &&
1127 cp && ci &&
1128 true){
1129
1130
1131 if(
1132 cp->npresh > ci->npresh &&
1133 true){
1134 tp_score++;
1135 totp_score++;
1136 };
1137 if(
1138 cp->npresh < ci->npresh &&
1139 true){
1140 ti_score++;
1141 toti_score++;
1142 };
1143
1144 // cout << "CALO "<<tp_score<<ti_score<<endl;
1145
1146 };
1147 // -----------------------------------------------------------------------------------------
1148 // *****************************************************************************************
1149 // -----------------------------------------------------------------------------------------
1150 // TOF check
1151 // -----------------------------------------------------------------------------------------
1152 // check the number of hit pmts along the track
1153 // on S12 S21 and S32, where paddles are parallel to Y axis
1154 if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1155 cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1156 return;
1157 };
1158 //
1159 if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1160 ti_score++;
1161 toti_score++;
1162 };
1163 if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1164 tp_score++;
1165 totp_score++;
1166 };
1167 if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1168 //
1169 Float_t sen = 0.;
1170 for (Int_t ih=0; ih < op->npmtadc; ih++){
1171 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1172 if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1173 };
1174 for (Int_t ih=0; ih < oi->npmtadc; ih++){
1175 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1176 if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1177 };
1178 //
1179 if ( sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1180 //printf(" IS A NUCLEUS! en = %f \n",sen);
1181 //
1182 // is a nucleus use a different algorithm
1183 //
1184 Int_t nz = 6; Float_t zin[6]; // << define TOF z-coordinates
1185 for(Int_t ip=0; ip<nz; ip++)
1186 zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip)); // << read ToF plane z-coordinates
1187 Trajectory *tr = new Trajectory(nz,zin);
1188 //
1189 Int_t nphit_p =0;
1190 Int_t nphit_i =0;
1191 Float_t enhit_p = 0.;
1192 Float_t enhit_i = 0.;
1193 //
1194 for (Int_t ih=0; ih < op->npmtadc; ih++){
1195 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1196 if(pl == 1 || pl == 2 || pl == 5){
1197 nphit_p++;
1198 enhit_p += (op->dedx).At(ih);
1199 };
1200 };
1201 //
1202 tp->DoTrack2(tr);
1203 //
1204 if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1205 for (Int_t ih=0; ih < op->npmtadc; ih++){
1206 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1207 if(pl == 0){
1208 nphit_p++;
1209 enhit_p += (op->dedx).At(ih);
1210 };
1211 };
1212 };
1213 if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1214 for (Int_t ih=0; ih < op->npmtadc; ih++){
1215 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1216 if(pl == 3){
1217 nphit_p++;
1218 enhit_p += (op->dedx).At(ih);
1219 };
1220 };
1221 };
1222 if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1223 for (Int_t ih=0; ih < op->npmtadc; ih++){
1224 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1225 if(pl == 4){
1226 nphit_p++;
1227 enhit_p += (op->dedx).At(ih);
1228 };
1229 };
1230 };
1231
1232 for (Int_t ih=0; ih < oi->npmtadc; ih++){
1233 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1234 if(pl == 1 || pl == 2 || pl == 5){
1235 nphit_i++;
1236 enhit_i += (op->dedx).At(ih);
1237 };
1238 };
1239 //
1240 ti->DoTrack2(tr);
1241 //
1242 if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1243 for (Int_t ih=0; ih < oi->npmtadc; ih++){
1244 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1245 if(pl == 0){
1246 nphit_i++;
1247 enhit_i += (op->dedx).At(ih);
1248 };
1249 };
1250 };
1251 if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1252 for (Int_t ih=0; ih < oi->npmtadc; ih++){
1253 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1254 if(pl == 3){
1255 nphit_i++;
1256 enhit_i += (op->dedx).At(ih);
1257 };
1258 };
1259 };
1260 if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1261 for (Int_t ih=0; ih < oi->npmtadc; ih++){
1262 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1263 if(pl == 4){
1264 nphit_i++;
1265 enhit_i += (op->dedx).At(ih);
1266 };
1267 };
1268 };
1269
1270
1271 if(
1272 (use_TOF || use_S1 || use_S2 || use_S3) &&
1273 (nphit_p+nphit_i) !=0 &&
1274 true){
1275
1276 // printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);
1277 // printf(" score p %i score i %i \n",tp_score,ti_score);
1278 // if( enhit_p > enhit_i ) tp_score++;
1279 // if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1280 if ( nphit_p > nphit_i ) tp_score++;
1281 if ( nphit_p < nphit_i ) ti_score++;
1282 if ( nphit_p == nphit_i ){
1283 if ( enhit_p > enhit_i ) tp_score++;
1284 else ti_score++;
1285 };
1286 // printf(" dopo score p %i score i %i \n",tp_score,ti_score);
1287 };
1288 delete tr;
1289 //
1290 } else {
1291 // -------------
1292 // NOT a NUCLEUS
1293 // -------------
1294 //printf(" NOT a NUCLEUS! en = %f \n",sen);
1295
1296 Int_t nphit_p =0;
1297 Int_t nphit_i =0;
1298
1299
1300 /* cout << "track: npmtadc "<< op->npmtadc << endl;
1301 cout << "track: npmttdc "<< op->npmttdc << endl;
1302 cout << "image: npmtadc "<< oi->npmtadc << endl;
1303 cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1304
1305 // for (Int_t ih=0; ih < op->npmtadc; ih++){
1306 // Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1307 // if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1308 // };
1309
1310 // for (Int_t ih=0; ih < oi->npmtadc; ih++){
1311 // Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1312 // if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1313 // };
1314 // --- modified to count tdc signals (more efficient?)
1315 // --- and to implement check on tdcflag
1316 for (Int_t ih=0; ih < op->npmttdc; ih++){
1317 Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1318 // if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1319 if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1320 if( (op->tdcflag).At(ih)==0 )nphit_p++;
1321 };
1322 };
1323
1324 for (Int_t ih=0; ih < oi->npmttdc; ih++){
1325 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1326 // if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
1327 if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1328 if( (oi->tdcflag).At(ih)==0 )nphit_i++;
1329 };
1330 };
1331
1332 if(
1333 (nphit_p+nphit_i) !=0 &&
1334 true){
1335
1336 if ( nphit_p != nphit_i ){
1337 totp_score += nphit_p;
1338 toti_score += nphit_i;
1339 tp_score+=nphit_p;
1340 ti_score+=nphit_i;
1341 };
1342 // if ( nphit_p > nphit_i) tp_score+=nphit_p;
1343 // else if( nphit_p < nphit_i) ti_score+=nphit_i;
1344 // else ;//niente
1345 };
1346 };
1347 // cout << "TOF "<<tp_score<<ti_score<<endl;
1348 };
1349
1350
1351 // if(tp_score == ti_score) use_TRK = true;
1352
1353
1354 // -----------------------------------------------------------------------------------------
1355 // *****************************************************************************************
1356 // -----------------------------------------------------------------------------------------
1357 // tracker check
1358 // -----------------------------------------------------------------------------------------
1359 // chi**2 difference is not always large enough to distinguish among
1360 // the real track and its image.
1361 // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1362 // *** MODIFIED ON AUGUST 2007 ***
1363 if(use_TRK){
1364 // if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1365 // else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1366
1367 // CHECK 1 : number of points along X
1368 if ( tp->GetNX() >= ti->GetNX() ){
1369 tp_score++ ;
1370 totp_score++ ;
1371 };
1372 if ( tp->GetNX() <= ti->GetNX() ){
1373 ti_score++ ;
1374 toti_score++ ;
1375 };
1376 // CHECK 2 : number of points along Y
1377 if ( tp->GetNY() >= ti->GetNY() ){
1378 tp_score++ ;
1379 totp_score++ ;
1380 };
1381 if ( tp->GetNY() <= ti->GetNY() ){
1382 ti_score++ ;
1383 toti_score++ ;
1384 };
1385
1386 // cout << "TRK "<<tp_score<<ti_score<<endl;
1387 };
1388
1389
1390 // -----------------------------------------------------------------------------------------
1391 // *****************************************************************************************
1392 // -----------------------------------------------------------------------------------------
1393 // GPamela check
1394 // -----------------------------------------------------------------------------------------
1395
1396 //---------------------------------------------------
1397 // count the number of GP hits
1398 //---------------------------------------------------
1399 if(use_GP){
1400 int ngphits_p=0;
1401 int ngphits_i=0;
1402 float toll = 0.02; //200 micron
1403 for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1404 int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1405 if(
1406 tp &&
1407 tp->YGood(ip) &&
1408 fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1409 true) ngphits_p++;
1410 if( ti &&
1411 ti->YGood(ip) &&
1412 fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1413 true) ngphits_i++;
1414 }
1415 if(
1416 ngphits_p > ngphits_i &&
1417 true){
1418 tp_score++ ;
1419 totp_score++ ;
1420 }
1421 if(
1422 ngphits_p < ngphits_i &&
1423 true){
1424 ti_score++ ;
1425 toti_score++ ;
1426 }
1427 }
1428
1429
1430 // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1431 // the winner is....
1432 // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1433 if (tp_score > ti_score) {
1434
1435
1436 }else if (tp_score < ti_score) {
1437
1438
1439 ts = ti;//its image!!
1440 cs = ci;
1441 os = oi;
1442 rs = ri;
1443 Int_t totis = toti_score;
1444
1445 ti = tp;//its image!!
1446 ci = cp;
1447 oi = op;
1448 ri = rp;
1449
1450 tp = ts;//its image!!
1451 cp = cs;
1452 op = os;
1453 rp = rs;
1454
1455 toti_score = totp_score;
1456 totp_score = totis;
1457
1458
1459 }else {
1460
1461 // cout << "Warning - track image ambiguity not solved" << endl;
1462
1463 };
1464
1465 }else{
1466 totp_score = 1;
1467 toti_score = 0;
1468
1469 // ts = tp;
1470 // cs = cp;
1471 // os = op;
1472 };
1473
1474 // cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1475 // sorted_tracks->Add(ts);//save the track in the sorted array
1476 // sorted_tracks.Add(ts);//save the track in the sorted array
1477 // sorted_tracks.Add(tp);//save the track in the sorted array
1478 // cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1479 // cout<<"o "<<tp<<endl;
1480 // cout<<"o "<<cp<<endl;
1481 // cout<<"o "<<op<<endl;
1482
1483 new(ttsorted[i]) PamTrack(tp,cp,op,rp);
1484 new(ttimage[i]) PamTrack(ti,ci,oi,ri);
1485
1486 ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1487 ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1488 ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1489 ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1490 };
1491
1492 if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1493 cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1494 tsorted->Delete(); tsorted=0;
1495 timage->Delete(); timage=0;
1496 }
1497
1498 //Restore Object count
1499 //To save space in the table keeping track of all referenced objects
1500 //We reset the object count to what it was at the beginning of the event.
1501 TProcessID::SetObjectCount(ObjectNumber);
1502
1503 };
1504 //--------------------------------------
1505 //
1506 //
1507 //--------------------------------------
1508 /**
1509 * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
1510 * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
1511 */
1512 // TRefArray *PamLevel2::GetTracks(){
1513
1514 // // *-*-*-*-*-*-*-*-*-*-*-*-*
1515 // SortTracks("+CAL+TOF");
1516 // // *-*-*-*-*-*-*-*-*-*-*-*-*
1517
1518 // // return sorted_tracks;
1519 // return &sorted_tracks;
1520
1521 // };
1522 TClonesArray *PamLevel2::GetTracks(){
1523
1524 // *-*-*-*-*-*-*-*-*-*-*-*-*
1525 SortTracks();
1526 // *-*-*-*-*-*-*-*-*-*-*-*-*
1527
1528 return tsorted;
1529
1530 };
1531 //--------------------------------------
1532 //
1533 //
1534 //--------------------------------------
1535 /**
1536 * Retrieves the it-th Pamela "physical" track.
1537 * It override TrkLevel2::GetTrack(int it).
1538 * @param it Track number, ranging from 0 to GetNTracks().
1539 */
1540 PamTrack *PamLevel2::GetTrack(int it){
1541
1542 // if(!trk2_obj) return 0;
1543
1544 // // *-*-*-*+-*-*-*-*-*-*-*-*-*
1545 // SortTracks("+CAL+TOF");
1546 // // *-*-*-*-*-*-*-*-*-*-*-*-*
1547 // // if(!sorted_tracks)return 0;
1548 // if(sorted_tracks.IsEmpty())return 0;
1549
1550 // PamTrack *track = 0;
1551
1552 // if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){
1553 // TrkTrack *t = (TrkTrack*)sorted_tracks.At(it);
1554 // track = GetPamTrackAlong(t);
1555 // }else{
1556 // cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1557 // };
1558
1559 // return track;
1560
1561 // cout << "PamLevel2::GetTrack(int it) "<<endl;
1562 // *-*-*-*-*-*-*-*-*-*-*-*-*
1563 SortTracks();
1564 // *-*-*-*-*-*-*-*-*-*-*-*-*
1565 if(!tsorted)return 0;
1566 if(!tsorted->GetEntries())return 0;
1567
1568 PamTrack *track = 0;
1569
1570 if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){
1571 // TrkTrack *t = (TrkTrack*)sorted_tracks.At(it);
1572 // track = GetPamTrackAlong(t);
1573 TClonesArray &t = *(tsorted);
1574 track = (PamTrack*)t[it];
1575
1576 }else{
1577 cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1578 };
1579
1580 return track;
1581
1582 };
1583
1584 //--------------------------------------
1585 //
1586 //
1587 //--------------------------------------
1588 /**
1589 * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
1590 * @param it Track number, ranging from 0 to GetNTracks().
1591 */
1592 PamTrack *PamLevel2::GetTrackImage(int it){
1593
1594 // *-*-*-*-*-*-*-*-*-*-*-*-*
1595 SortTracks();
1596 // *-*-*-*-*-*-*-*-*-*-*-*-*
1597 if(!timage)return 0;
1598 if(!timage->GetEntries())return 0;
1599
1600 PamTrack *image = 0;
1601
1602 if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
1603 TClonesArray &t = *(tsorted);
1604 PamTrack *temp = (PamTrack*)t[it];
1605 if( temp->GetTrkTrack()->HasImage() ){
1606 TClonesArray &t = *(timage);
1607 image = (PamTrack*)t[it];
1608 }else{
1609 // cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
1610 };
1611 }else{
1612 cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1613 };
1614
1615 return image;
1616 }
1617
1618 //--------------------------------------
1619 //
1620 //
1621 //--------------------------------------
1622 /**
1623 * Get the Pamela detector trees in a single file and make them friends.
1624 * @param f TFile pointer
1625 * @param detlist String to select trees to be included
1626 * @return Pointer to a TTree
1627 */
1628 TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
1629
1630 if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1631 cout << "+AUTO"<<endl;
1632 GetWhichTrees(f);
1633 };
1634 SetWhichTrees(detlist);
1635
1636 if ( pam_tree ){
1637 printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1638 return pam_tree;
1639 };
1640 //
1641
1642 cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1643
1644 // SetWhichTrees(detlist);
1645
1646 TTree *Trout =0;
1647
1648 TString fname = f->GetName();
1649 if(!CheckLevel2File(fname))return NULL;
1650
1651 // UInt_t *found=0;
1652
1653 cout<< "GetPamTree(TFile*,TString): detector list --> ";
1654 if(TRK1)cout<<"TRK1 ";
1655 if(TRK2)cout<<"TRK2 ";
1656 if(TRKh)cout<<"TRKH ";
1657 if(CAL1)cout<<"CAL1 ";
1658 if(CAL2)cout<<"CAL2 ";
1659 if(TOF)cout<<"TOF ";
1660 if(TRG)cout<<"TRG ";
1661 if(AC)cout<<"AC ";
1662 if(ND)cout<<"ND ";
1663 if(S4)cout<<"S4 ";
1664 if(ORB)cout<<"ORB ";
1665 if(GP)cout<<"GP ";
1666 cout << endl;
1667 if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
1668
1669 f->cd();
1670
1671 // Tracker
1672 TTree *T = (TTree*)f->Get("Tracker");
1673 if(T && (TRK2||TRK1||TRKh)) {
1674 if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1675 // else T->SetBranchStatus("TrkLevel2",0,found);
1676 if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl;
1677 if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1678 // else T->SetBranchStatus("TrkLevel1",0,found);
1679 if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl;
1680 if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1681 // else T->SetBranchStatus("TrkHough",0,found);
1682 if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl;
1683 if(!Trout)Trout=T;
1684 else Trout->AddFriend(T);
1685 }else{
1686 cout << "Tracker : missing tree"<<endl;
1687 };
1688 // Calorimeter
1689 TTree *C = (TTree*)f->Get("Calorimeter");
1690 if(C && (CAL2||CAL1)) {
1691 if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1692 // else C->SetBranchStatus("CaloLevel2",0,found);
1693 if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1694 if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1695 // else C->SetBranchStatus("CaloLevel1",0,found);
1696 if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1697 if(!Trout)Trout=C;
1698 else Trout->AddFriend(C);
1699 }else{
1700 cout << "Calorimeter : missing tree"<<endl;
1701 };
1702
1703 // ToF
1704 TTree *O = (TTree*)f->Get("ToF");
1705 if(O && TOF) {
1706 O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1707 cout << "ToF : set branch address ToFLevel2"<<endl;
1708 if(!Trout)Trout=O;
1709 else Trout->AddFriend(O);
1710 }else{
1711 cout << "ToF : missing tree"<<endl;
1712 };
1713 // Trigger
1714 TTree *R = (TTree*)f->Get("Trigger");
1715 if(R && TRG) {
1716 R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1717 cout << "Trigger : set branch address TrigLevel2"<<endl;
1718 if(!Trout)Trout=R;
1719 else Trout->AddFriend(R);
1720 }else{
1721 cout << "Trigger : missing tree"<<endl;
1722 };
1723 // S4
1724 TTree *S = (TTree*)f->Get("S4");
1725 if(S && S4) {
1726 S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1727 cout << "S4 : set branch address S4Level2"<<endl;
1728 if(!Trout)Trout=S;
1729 else Trout->AddFriend(S);
1730 }else{
1731 cout << "S4 : missing tree"<<endl;
1732 };
1733 // Neutron Detector
1734 TTree *N = (TTree*)f->Get("NeutronD");
1735 if(N && ND) {
1736 N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1737 cout << "NeutronD : set branch address NDLevel2"<<endl;
1738 if(!Trout)Trout=N;
1739 else Trout->AddFriend(N);
1740 }else{
1741 cout << "NeutronD : missing tree"<<endl;
1742 };
1743 // Anticounters
1744 TTree *A = (TTree*)f->Get("Anticounter");
1745 if(A && AC) {
1746 A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1747 cout << "Anticounter : set branch address AcLevel2"<<endl;
1748 if(!Trout)Trout=A;
1749 else Trout->AddFriend(A);
1750 }else{
1751 cout << "Anticounter : missing tree"<<endl;
1752 };
1753 // Orbital Info
1754 TTree *B = (TTree*)f->Get("OrbitalInfo");
1755 if(B && ORB) {
1756 B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1757 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1758 if(!Trout)Trout=B;
1759 else Trout->AddFriend(B);
1760 }else{
1761 cout << "OrbitalInfo : missing tree"<<endl;
1762 };
1763
1764 // GPamela
1765 TTree *G = (TTree*)f->Get("h20");
1766 if(G && GP) {
1767 if(!gp_obj)gp_obj=new GPamela();
1768 // ------------------------------------
1769 // ATTENZIONE!!!
1770 // non so per quale arcano motivo,
1771 // per l'albero di gpamela il branch address lo devo settare
1772 // DOPO aver fatto friend
1773 // FGRRRVZZZZUTSALKJMSLKJ!!!
1774 // ------------------------------------
1775 // gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
1776 // cout << "h20 : set branch address GPamela "<<endl;
1777 if(!Trout)Trout=G;
1778 else Trout->AddFriend(G);
1779 }else{
1780 // cout << "h20 : missing tree"<<endl;
1781 };
1782
1783
1784 TTree *L = (TTree*)f->Get("SelectionList");
1785 if(L && SELLI==1) {
1786 cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!"<<endl;
1787 sel_tree = 0;
1788 }else{
1789 cout << "SelectionList : missing tree"<<endl;
1790 };
1791
1792 cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1793
1794 // ------------------------------------
1795 // ATTENZIONE!!!
1796 // non so per quale arcano motivo,
1797 // per l'albero di gpamela il branch address lo devo settare
1798 // DOPO aver fatto friend
1799 // FGRRRVZZZZUTSALKJMSLKJ!!!
1800 // ------------------------------------
1801 if(G && GP) {
1802 gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
1803 cout << "h20 : set branch address GPamela "<<endl;
1804 }else{
1805 cout << "h20 : missing tree"<<endl;
1806 };
1807
1808 pam_tree = (TChain*)Trout;
1809
1810 return Trout;
1811
1812 }
1813 //--------------------------------------
1814 //
1815 //
1816 //--------------------------------------
1817 /**
1818 * Get list of Level2 files.
1819 * @param ddir Level2 data directory.
1820 * @param flisttxt Name of txt file containing file list.
1821 * @return Pointer to a TList of TSystemFiles
1822 * If no input file list is given , all the Level2 files inside the directory are processed.
1823 */
1824 TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){
1825
1826 TString wdir = gSystem->WorkingDirectory();
1827
1828 // if(ddir=="")ddir = wdir;
1829 // TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1830 if ( ddir != ""){
1831 cout << "Level2 data directory : "<< ddir << endl;
1832 } else {
1833 cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1834 };
1835 TList *contents = new TList; // create output list
1836 contents->SetOwner();
1837
1838 // char *fullpath;
1839 // const char *fullpath;
1840
1841 // if no input file list is given:
1842 if ( flisttxt != "" ){
1843
1844 // if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){
1845 // if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1846 // cout <<"File "<<flisttxt<<" not found"<<endl;
1847 // return 0;
1848 // }
1849 // flisttxt = fullpath;
1850 if ( !flisttxt.EndsWith(".root") ){
1851
1852 flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1853
1854 if( !gSystem->ChangeDirectory(ddir) ){
1855 cout << "Cannot change directory : "<<ddir<<endl;
1856 return 0;
1857 }
1858
1859 cout <<"Input file list : " << flisttxt <<endl;
1860 ifstream in;
1861 in.open(flisttxt, ios::in); //open input file list
1862 if(!in.good()){
1863 cout <<" ERROR opening the file "<<endl;
1864 gSystem->ChangeDirectory(wdir); // back to the working directory
1865 return 0;
1866 }
1867 int line=0;
1868 while (1) {
1869 TString file;
1870 in >> file;
1871 if (!in.good()) break;
1872 line++;
1873 // cout <<"(1) " << file << endl;
1874 if(file.IsNull()){
1875 cout << "-- list interrupted at line "<<line <<endl;
1876 break;
1877 }
1878 if(file.Contains("#"))file = file(0,file.First("#"));
1879 // cout <<"(2) " << file << endl;
1880 // if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1881 // if( (fullpath = gSystem->FindFile(ddir,file)) ){
1882 if( file.EndsWith(".root") ){
1883 TString filedir;
1884 if (ddir != ""){
1885 filedir = ddir; // take the input dir
1886 } else {
1887 gSystem->ChangeDirectory(wdir); // back to the working directory
1888 filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1889 };
1890 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1891 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1892 delete fullpath;
1893 }
1894 // }else{
1895 // if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1896 // };
1897 };
1898 in.close();
1899 } else {
1900 if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1901 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1902 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1903 delete fullpath;
1904 };
1905 }else{
1906
1907 cout << "No input file list given."<<endl;
1908 cout << "Check for existing root files."<<endl;
1909 // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1910 if ( ddir == "" ){
1911 ddir = wdir;
1912 cout << "Level2 data directory : "<< ddir << endl;
1913 };
1914
1915 TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1916 TList *temp = datadir->GetListOfFiles();
1917 // temp->Print();
1918 // cout << "*************************************" << endl;
1919
1920 TIter next(temp);
1921 TSystemFile *questo = 0;
1922
1923
1924 while ( (questo = (TSystemFile*) next()) ) {
1925 TString name = questo-> GetName();
1926 if( name.EndsWith(".root") ){
1927 // const char *fullpath = gSystem->FindFile(ddir,name);
1928 // char *fullpath;
1929 // gSystem->IsFileInIncludePath(name,&fullpath);
1930 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1931 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1932 delete fullpath;
1933 };
1934 }
1935 delete temp;
1936 delete datadir;
1937
1938 };
1939 gSystem->ChangeDirectory(wdir); // back to the working directory
1940 // cout << endl << "Selected files:" << endl;
1941 // contents->Print();
1942 cout << contents->GetEntries()<<" files \n";
1943 // cout << endl;
1944 // cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1945 return contents;
1946 };
1947 //--------------------------------------
1948 //
1949 //
1950 //--------------------------------------
1951 /**
1952 * Get the Pamela detector chains from a list of files and make them friends.
1953 * @param fl Pointer to a TList of TSystemFiles
1954 * @param detlist String to select trees to be included
1955 * @return Pointer to a TChain
1956 */
1957 TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1958 //
1959 //
1960 //
1961 if ( pam_tree ){
1962 printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
1963 return pam_tree;
1964 };
1965 //
1966
1967 TChain *Trout =0;
1968
1969 // -------------------------------------------
1970 // set flags to include/exclude trees/branches
1971 // -------------------------------------------
1972 if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1973 if( fl->GetEntries()>0 ){
1974 cout << "+AUTO"<<endl;
1975 TFile *fprimo = new TFile( fl->At(0)->GetName() );
1976 GetWhichTrees(fprimo);
1977 fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
1978 fprimo->Delete();
1979 }
1980 };
1981 SetWhichTrees(detlist);
1982
1983
1984 // -------------------------------------------
1985 // build chains
1986 // -------------------------------------------
1987 TChain *T = 0;
1988 TChain *C = 0;
1989 TChain *O = 0;
1990 TChain *R = 0;
1991 TChain *S = 0;
1992 TChain *N = 0;
1993 TChain *A = 0;
1994 TChain *B = 0;
1995 TChain *G = 0;
1996
1997 TChain *L = 0;
1998
1999 if(TRK2||TRK1||TRKh) T = new TChain("Tracker");
2000 if(CAL2||CAL1) C = new TChain("Calorimeter");
2001 if(TOF) O = new TChain("ToF");
2002 if(TRG) R = new TChain("Trigger");
2003 if(S4) S = new TChain("S4");
2004 if(ND) N = new TChain("NeutronD");
2005 if(AC) A = new TChain("Anticounter");
2006 if(ORB) B = new TChain("OrbitalInfo");
2007 if(GP) G = new TChain("h20");
2008 L = new TChain("SelectionList");
2009
2010 // loop over files and create chains
2011 TIter next(fl);
2012 TSystemFile *questo = 0;
2013 while ( (questo = (TSystemFile*) next()) ) {
2014 TString name = questo->GetName();
2015 cout << "File: "<< name << endl;
2016 if( CheckLevel2File(name) ){
2017 if(TRK2||TRK1||TRKh) T->Add(name);
2018 if(CAL1||CAL2) C->Add(name);
2019 if(TOF) O->Add(name);
2020 if(TRG) R->Add(name);
2021 if(S4) S->Add(name);
2022 if(ND) N->Add(name);
2023 if(AC) A->Add(name);
2024 if(ORB) B->Add(name);
2025 if(GP) G->Add(name);
2026 if(SELLI==1) L->Add(name);
2027 };
2028 };
2029
2030 cout << "done chains\n";
2031 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2032
2033
2034 // -------------------------------------------
2035 // make friends
2036 // -------------------------------------------
2037
2038 // Tracker
2039 cout << "Friends: "<<endl;
2040 if(T && (TRK2||TRK1||TRKh)) {
2041 if(!Trout)Trout=T;
2042 else Trout->AddFriend("Tracker");
2043 // cout << "+Tacker"<<endl;
2044 };
2045 // Calorimeter
2046 if(C && (CAL2||CAL1)) {
2047 if(!Trout)Trout=C;
2048 else Trout->AddFriend("Calorimeter");
2049 // cout << "+Calorimeter"<<endl;
2050 };
2051 // ToF
2052 if(O && TOF) {
2053 if(!Trout)Trout=O;
2054 else Trout->AddFriend("ToF");
2055 // cout << "+ToF"<<endl;
2056 };
2057 // Trigger
2058 if(R && TRG) {
2059 if(!Trout)Trout=O;
2060 else Trout->AddFriend("Trigger");
2061 // cout << "+Trigger"<<endl;
2062 };
2063 // S4
2064 if(S && S4) {
2065 if(!Trout)Trout=O;
2066 else Trout->AddFriend("S4");
2067 // cout << "+S4"<<endl;
2068 };
2069 // Neutron Detector
2070 if(N && ND) {
2071 if(!Trout)Trout=O;
2072 else Trout->AddFriend("NeutronD");
2073 // cout << "+NeutronD"<<endl;
2074 };
2075 // Anticounters
2076 if(A && AC) {
2077 if(!Trout)Trout=O;
2078 else Trout->AddFriend("Anticounter");
2079 // cout << "+Anticounter"<<endl;
2080 };
2081 // Orbital Info
2082 if(B && ORB) {
2083 if(!Trout)Trout=O;
2084 else Trout->AddFriend("OrbitalInfo");
2085 // cout << "+OrbitalInfo"<<endl;
2086 };
2087 // GPamela
2088 if(G && GP) {
2089 if(!Trout)Trout=G;
2090 else Trout->AddFriend("h20");
2091 // cout << "+h20"<<endl;
2092 };
2093
2094 // =====================================
2095 // SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
2096 // =====================================
2097 SetBranchAddress(Trout);
2098
2099
2100 // ------------------------------------
2101 // finally handle selection trees...
2102 // (it is not friend of pamela tree)
2103 // ------------------------------------
2104
2105 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2106
2107 // Selection List
2108 if(L && SELLI==1) {
2109 cout<<">>> Found selection-list <<<"<<endl;
2110 // L->SetBranchAddress("RunEntry",&irun);
2111 L->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2112 cout << "SelectionList: set branch address RunEntry"<<endl;
2113 L->SetBranchAddress("EventEntry",&irunentry);
2114 cout << "SelectionList: set branch address EventEntry"<<endl;
2115 sel_tree = L;
2116 // if(!Trout)Trout=O;
2117 // else Trout->AddFriend("SelectionList");
2118 cout << "+SelectionList"<<endl;
2119 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2120 }else{
2121 // cout << "SelectionList : missing tree"<<endl;
2122 if(L)L->Delete();
2123 };
2124
2125 // --------------------------------------------
2126 // return the pamela chain with all the friends
2127 // --------------------------------------------
2128
2129 pam_tree = Trout;
2130
2131 return Trout;
2132 }
2133
2134
2135
2136 //--------------------------------------
2137 //
2138 //
2139 //--------------------------------------
2140 /**
2141 * Set branch addresses for Pamela friend trees
2142 */
2143 void PamLevel2::SetBranchAddress(TTree *t){
2144
2145 TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
2146 TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
2147 TRKh = TRKh & t->GetBranchStatus("TrkHough");
2148 CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
2149 CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
2150 TOF = TOF & t->GetBranchStatus("ToFLevel2");
2151 TRG = TRG & t->GetBranchStatus("TrigLevel2");
2152 S4 = S4 & t->GetBranchStatus("S4Level2");
2153 ND = ND & t->GetBranchStatus("NDLevel2");
2154 AC = AC & t->GetBranchStatus("AcLevel2");
2155 ORB = ORB & t->GetBranchStatus("OrbitalInfo");
2156 GP = GP & t->GetBranchStatus("h20");
2157
2158
2159 // Tracker
2160 if(TRK1) {
2161 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));
2162 cout << "Tracker : set branch address TrkLevel1"<<endl;
2163 };
2164 if(TRK2) {
2165 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
2166 cout << "Tracker : set branch address TrkLevel2"<<endl;
2167 };
2168 if(TRKh) {
2169 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2170 cout << "Tracker : set branch address TrkHough"<<endl;
2171 };
2172
2173 // Calorimeter
2174 if(CAL1) {
2175 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
2176 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
2177 };
2178 if(CAL2) {
2179 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
2180 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
2181 };
2182
2183 // ToF
2184 if(TOF) {
2185 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
2186 cout << "ToF : set branch address ToFLevel2"<<endl;
2187 };
2188 // Trigger
2189 if(TRG) {
2190 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
2191 cout << "Trigger : set branch address TrigLevel2"<<endl;
2192 };
2193 // S4
2194 if(S4) {
2195 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
2196 cout << "S4 : set branch address S4Level2"<<endl;
2197 };
2198 // Neutron Detector
2199 if(ND) {
2200 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
2201 cout << "NeutronD : set branch address NDLevel2"<<endl;
2202 };
2203 // Anticounters
2204 if(AC) {
2205 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
2206 cout << "Anticounter : set branch address AcLevel2"<<endl;
2207 };
2208 // OrbitalInfo
2209 if(ORB) {
2210 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2211 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
2212 };
2213 // GPamela
2214 if(GP) {
2215 // GetPointerTo("GPamela");
2216 if(!gp_obj)gp_obj = new GPamela();
2217 // gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2218 // // t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2219 if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2220 else gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2221
2222 cout << "h20 : set branch address GPamela "<<endl;
2223 };
2224
2225 }
2226 /**
2227 * Set branch addresses for Pamela friend trees
2228 */
2229 void PamLevel2::SetBranchAddress(TChain *t){
2230
2231 // TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
2232 // TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
2233 // TRKh = TRKh & t->GetBranchStatus("TrkHough");
2234 // CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
2235 // CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
2236 // TOF = TOF & t->GetBranchStatus("ToFLevel2");
2237 // TRG = TRG & t->GetBranchStatus("TrigLevel2");
2238 // S4 = S4 & t->GetBranchStatus("S4Level2");
2239 // ND = ND & t->GetBranchStatus("NDLevel2");
2240 // AC = AC & t->GetBranchStatus("AcLevel2");
2241 // ORB = ORB & t->GetBranchStatus("OrbitalInfo");
2242 // GP = GP & t->GetBranchStatus("h20");
2243
2244 // Tracker
2245 if(TRK2) {
2246 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2247 cout << "Tracker : set branch address TrkLevel2"<<endl;
2248 };
2249 if(TRK1) {
2250 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2251 cout << "Tracker : set branch address TrkLevel1"<<endl;
2252 };
2253 if(TRKh) {
2254 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2255 cout << "Tracker : set branch address TrkHough"<<endl;
2256 };
2257
2258 // Calorimeter
2259 if(CAL2) {
2260 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
2261 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
2262 };
2263 if(CAL1) {
2264 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
2265 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
2266 };
2267
2268 // ToF
2269 if(TOF) {
2270 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
2271 cout << "ToF : set branch address ToFLevel2"<<endl;
2272 };
2273 // Trigger
2274 if(TRG) {
2275 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
2276 cout << "Trigger : set branch address TrigLevel2"<<endl;
2277 };
2278 // S4
2279 if(S4) {
2280 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
2281 cout << "S4 : set branch address S4Level2"<<endl;
2282 };
2283 // Neutron Detector
2284 if(ND) {
2285 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
2286 cout << "NeutronD : set branch address NDLevel2"<<endl;
2287 };
2288 // Anticounters
2289 if(AC) {
2290 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
2291 cout << "Anticounter : set branch address AcLevel2"<<endl;
2292 };
2293 // OrbitalInfo
2294 if(ORB) {
2295 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2296 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
2297 };
2298 // GPamela
2299 // cout <<"GP "<<GP<<endl;
2300 if(GP) {
2301 // GetPointerTo("GPamela");
2302 if(!gp_obj)gp_obj = new GPamela();
2303 if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2304 else gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2305 // gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2306 cout << "h20 : set branch address GPamela "<<endl;
2307 };
2308 // SelectionList
2309 // if(SELLI==1){
2310 // t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2311 // cout << "SelectionList: set branch address RunEntry"<<endl;
2312 // t->SetBranchAddress("EventEntry",&irunentry);
2313 // cout << "SelectionList: set branch address EventEntry"<<endl;
2314
2315 // }
2316
2317 }
2318
2319
2320 //--------------------------------------
2321 //
2322 //
2323 //--------------------------------------
2324 /**
2325 * Get the Run tree chain from a list of files.
2326 * @param fl Pointer to a TList of TSystemFiles
2327 * @return Pointer to a TChain
2328 */
2329 TChain *PamLevel2::GetRunTree(TList *fl){
2330 //
2331 //
2332 //
2333 if ( run_tree ){
2334 printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2335 return run_tree;
2336 };
2337 //
2338
2339
2340 TChain *R = new TChain("Run");
2341
2342 // loop over files and create chains
2343 TIter next(fl);
2344 TSystemFile *questo = 0;
2345 while ( (questo = (TSystemFile*) next()) ) {
2346 TString name = questo->GetName();
2347 // cout << "File: "<< name << endl;
2348 if( CheckLevel2File(name) ){
2349 R->Add(name);
2350 };
2351 }
2352
2353
2354 if(RUN && R->GetNtrees()){
2355
2356 R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2357 cout << "Run : set branch address RunInfo"<<endl;
2358 R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2359 cout << "Software : set branch address SoftInfo"<<endl; // Emiliano
2360
2361 irunoffset = new int[R->GetNtrees()];
2362 if(DBG){
2363 cout << "----------------------------------------------------"<<endl;
2364 cout << "irun\t | ";
2365 cout << "tree\t |";
2366 // cout << "offset\t |";
2367 cout << "RUN\t";
2368 cout << "FRAG\t";
2369 cout << "NEVENTS\t";
2370 cout << "absolute time\t\t\t";
2371 cout << "on-board time";
2372 cout<<endl;
2373 }
2374 for (Int_t ii=0; ii<R->GetEntries(); ii++){
2375 R->GetEntry(ii);
2376 if(DBG){
2377 cout << ii<< "\t | ";
2378 cout << R->GetTreeNumber()<< "\t |";
2379 // cout << R->GetChainOffset()<< "\t |";
2380 cout <<GetRunInfo()->ID<<"\t";
2381 cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";
2382 cout <<GetRunInfo()->NEVENTS<< "\t";
2383 cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";
2384 cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";
2385 cout <<endl;
2386 }
2387 irunoffset[R->GetTreeNumber()]=R->GetChainOffset();
2388 }
2389 cout << "N.run = "<<R->GetEntries()<<endl;
2390 cout << "----------------------------------------------------"<<endl;
2391
2392
2393 }else{
2394 delete R;
2395 R=0;
2396 }
2397
2398
2399 run_tree = R;
2400
2401 return R;
2402
2403 }
2404 //--------------------------------------
2405 //
2406 //
2407 //--------------------------------------
2408 /**
2409 * Get the Run tree from a file.
2410 * @param f Pointer to a TFile
2411 * @return Pointer to a TTree
2412 */
2413 TTree *PamLevel2::GetRunTree(TFile *f){
2414 if ( run_tree ){
2415 printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2416 return run_tree;
2417 };
2418
2419
2420 cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
2421
2422 TTree *T = (TTree*)f->Get("Run");
2423
2424 if(T){
2425 T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2426 cout << "Run : set branch address RunInfo"<<endl;
2427 T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2428 cout << "Software : set branch address SoftInfo"<<endl; // Emiliano
2429
2430 }
2431
2432 run_tree = (TChain*)T;
2433
2434 return T;
2435
2436 }
2437 /**
2438 * Update the runinfo informations (to be used to have Run infos event by event basis)
2439 * @param run Pointer to the chain/tree which contains run infos
2440 * @return true if a new run has been read, false if it is still the same run
2441 */
2442 Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2443 //
2444 // check if we have already called once GetEntry, if not call it
2445 //
2446 cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "<<endl;
2447 if(!run){
2448 cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
2449 return(false);
2450 }
2451 if ( run->GetEntries() <= 0 ) return(false);
2452 //
2453
2454 // Int_t oldrun = irun;
2455 Long64_t oldrun = irun;
2456
2457 // --------------------------------------
2458 // if it is a full file (not preselected)
2459 // --------------------------------------
2460 if(SELLI==0){
2461
2462 //
2463 // the absolute time is necessary to relate the event with the run
2464 //
2465 if( !GetOrbitalInfo() && !ISGP){
2466 cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2467 return(false);
2468 }
2469
2470 ULong64_t abstime = 0;
2471 if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2472
2473
2474 //
2475 // the first time the routine is called, set run search from the beginning
2476 //
2477 if ( irun < 0LL ){
2478 irun = 0LL;
2479 run->GetEntry(irun);
2480 runfirstentry = 0LL;
2481 runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2482 if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2483
2484 if( ISGP && run->GetEntries()!=1 ){
2485 cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2486 cout << "** WARNING ** run will not be updated"<<endl;
2487 }
2488
2489 };
2490 //
2491 if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2492 //
2493 if ( irun == run->GetEntries()-1LL &&
2494 !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2495 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2496 ){
2497 irun = -1LL;
2498 irunt = -1LL;
2499 runfirstentry = 0LL;
2500 runlastentry = -1LL;
2501 };
2502 // modificato il controllo sull'aggiornamento del run, per evitare problemi
2503 // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2504 //
2505 bool fromfirst = true;
2506 //
2507 while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2508 // while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2509 irun++;
2510 run->GetEntry(irun);
2511 runfirstentry = runlastentry;
2512 if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2513 runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2514 // cout << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2515 // cout << "runfirstentry "<<runfirstentry<<endl;
2516 // printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
2517 // printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2518 // printf(" IDRUN %u \n",GetRunInfo()->ID);
2519 //
2520 // prevshift = 0;
2521 //
2522 if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
2523 printf(" resetting irun (it should NOT happen!!!)\n");
2524 fromfirst = false;
2525 irun = 0;
2526 run->GetEntry(irun);
2527 runfirstentry = 0ULL;
2528 runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2529 if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2530 };
2531 //
2532 };
2533 //
2534 if (
2535 !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2536 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2537 ) {
2538 printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
2539 return false;
2540 }
2541 //
2542 if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2543 //
2544 // printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
2545 //
2546 prevshift = 0;
2547 cout << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2548 // cout << "runfirstentry "<<runfirstentry<<endl;
2549 return(true);
2550 };
2551 // ----------------------------------------------------
2552 // if it is a preselected file (there is SelectionList)
2553 // NBNB - the event tree MUST be read first
2554 // ----------------------------------------------------
2555 if(SELLI==1){
2556 sel_tree->GetEntry(iev);
2557 // cout << irun << " "<< irunentry << endl;
2558 if(irun != oldrun){
2559 run->GetEntry(irun);
2560 cout << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2561 prevshift = 0;
2562 return true;
2563 }
2564 return false;
2565 }
2566
2567 return false;
2568 //
2569 };
2570
2571 Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
2572
2573 if(!run_tree){
2574 cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
2575 return false;
2576 }
2577 if ( run_tree->GetEntries() <= 0 ) {
2578 cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
2579 return(false);
2580 }
2581
2582 Int_t oldrun = irun; // store current run index
2583
2584 // -----------------------------------------------------------------------
2585 // the first time the routine is called, set run search from the beginning
2586 // -----------------------------------------------------------------------
2587
2588 if ( irun < 0 ){
2589 irun = 0LL;
2590 irunt = 0LL;
2591 irunentry = 0;
2592 prevshift = 0;
2593 run_tree->GetEntry(irun);
2594 if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2595 };
2596 // ---------------------------------------------------------------
2597 // retrieve OBT and absolute time of the event
2598 // ---------------------------------------------------------------
2599 ULong64_t abstime = 0LL;
2600 ULong64_t obt = 0LL;
2601 if( GetOrbitalInfo() ){
2602 abstime = GetOrbitalInfo()->absTime;
2603 obt = GetOrbitalInfo()->OBT;
2604 }else{
2605 abstime = GetRunInfo()->RUNHEADER_TIME;
2606 obt = GetRunInfo()->RUNHEADER_OBT;
2607 }
2608
2609
2610 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2611 // if it is a full file (not preselected)
2612 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2613 if(SELLI==0){
2614
2615 // ---------------------------------------------------------------
2616 // increment dead and live-time counters
2617 // (only when reading a file not preselected)
2618 // ---------------------------------------------------------------
2619 if(SELLI==0){
2620 if( GetTrigLevel2() ){
2621 totdltime[0]+=GetTrigLevel2()->dltime[0];
2622 totdltime[1]+=GetTrigLevel2()->dltime[1];
2623 }
2624 totdltime[2]++;
2625 }
2626
2627 //
2628 bool fromfirst = true; // first loop over runs
2629
2630
2631 // ------------------------------------------------------
2632 // loop over runs to find the one that contains the event
2633 // ------------------------------------------------------
2634 while (
2635 (
2636 // (
2637 // !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
2638 // abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2639 // !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms)
2640 // obt <= GetRunInfo()->RUNTRAILER_OBT)
2641 // )
2642
2643 !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
2644 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2645 ||
2646 !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms)
2647 obt <= GetRunInfo()->RUNTRAILER_OBT)
2648 ||
2649 GetRunInfo()->NEVENTS==0
2650 // || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
2651 ||
2652 !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2653 )
2654 && irun < run_tree->GetEntries() ){
2655
2656
2657 // if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME) )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
2658 // if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
2659 // if( GetRunInfo()->NEVENTS==0 )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;
2660 // if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
2661 // - - - - - - - - - - - - -
2662 // irunentry = position of current entry, relative to the run
2663 // prevshift = shift needed to synchronize l0 and l2 data (nested events)
2664 // - - - - - - - - - - - - -
2665
2666 // -----------------------------------------
2667 // store dead and live-time of previous run
2668 // -----------------------------------------
2669 // if(SELLI==0){
2670 if(fromfirst){
2671 if(oldrun==irun){
2672 /// decrement counters
2673 if( GetTrigLevel2()){
2674 totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2675 totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2676 }
2677 totdltime[2]--; //event counter
2678 cout << endl;
2679 cout << "n.events : "<<totdltime[2]<<endl;
2680 cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2681 cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;
2682 }else{
2683 totdltime[0]=0;//live-time
2684 totdltime[1]=0;//dead-time
2685 totdltime[2]=0; //event counter
2686 cout << " *** JUMP RUN *** irun "<<irun<<endl;
2687 }
2688 /// add an entry
2689 if(run_tree_clone)
2690 if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2691 run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2692 /// reset counters
2693 if( GetTrigLevel2() ){
2694 totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2695 totdltime[1]=0; //dead-time
2696 }
2697 totdltime[2]=1; //event counter
2698 }
2699 // }
2700
2701 irun++;
2702 // ------------------------------------
2703 // if the end of run tree is reached...
2704 // ------------------------------------
2705 if( irun == run_tree->GetEntries() ){
2706 if(!fromfirst){
2707 // -----------------------------------------------------
2708 // if it happened already once and the run was not found
2709 // ---> exit with error
2710 // -----------------------------------------------------
2711 cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
2712 return false;
2713 }
2714 // -----------------------------------------
2715 // ...otherwise repeat search from beginning
2716 // -----------------------------------------
2717 cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;
2718 fromfirst = false;
2719 irun = 0LL;
2720 runfirstentry = 0LL;
2721 }
2722 // -------------------------------------------------------------------
2723 // save the index of the first entry of the run, relative to pam_tree,
2724 // and read a new run
2725 // -------------------------------------------------------------------
2726 if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2727 irunentry = 0;
2728 prevshift = 0;
2729 run_tree->GetEntry(irun);//update runinfo
2730 irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2731 if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2732 cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<" has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2733 cout << " (NB!! in this case some events are assigned to a wrong run)"<<endl;
2734 }
2735 // if(hasfrag && fragid != GetRunInfo()->ID){
2736 // cout << "... where is the next fragment ??"<<endl;
2737 // }
2738 };
2739
2740
2741 // --------------------------------------
2742 // if there was no need to update the run
2743 // ---> exit with FALSE
2744 // --------------------------------------
2745 if ( irun == oldrun ) return(false);
2746
2747 // --------------------------------------
2748 // ... otherwise
2749 // --------------------------------------
2750
2751
2752 // --------------------------------------
2753 // ---> exit with TRUE
2754 // --------------------------------------
2755 if(DBG)cout << endl << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2756 // ----------------------------------------------------
2757 // update the tracker parameters
2758 // (non ho trovato nessun altro modo sicuro di farlo...)
2759 // ----------------------------------------------------
2760 if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2761 TrkParams::Set(GetRunInfo() ,dbc);
2762 if(dbc)dbc->Close();
2763
2764 // ----------------------------------------------------
2765 // then check if the run has a fragment
2766 // in this case we have to switch to the next fragment
2767 // when the end of the first fragment is reached
2768 // ----------------------------------------------------
2769 if(
2770 GetRunInfo()->ID_RUN_FRAG != 0 &&
2771 // GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2772 DBG &&
2773 true ){
2774 cout << "* fragment *"<<endl;
2775 }
2776
2777 return(true);
2778 };
2779 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2780 // if it is a preselected file (there is SelectionList)
2781 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2782 // irun = run entry relative to the chain
2783 // irunt = run entry relative to the tree
2784 if(SELLI==1){
2785 sel_tree->GetEntry(iev);// read irunt from SelectionList
2786 irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2787 if(irun != oldrun ){
2788 if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);
2789 // check if the time is ok (with merged files it is not...)
2790 // if not loop over run and look for the proper entry
2791 bool SECONDO_GIRO=false;
2792 // Long64_t irun_start = irun;
2793 int offset_start = irunoffset[sel_tree->GetTreeNumber()];
2794 while (
2795 (
2796 (
2797 !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
2798 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2799 // ||
2800 // !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms)
2801 // obt <= GetRunInfo()->RUNTRAILER_OBT)
2802 )
2803 || GetRunInfo()->NEVENTS==0
2804 )
2805 // && irun < run_tree->GetEntries()
2806 ){
2807
2808 if(DBG){
2809 cout << " (test) ";
2810 cout << " tree "<<sel_tree->GetTreeNumber();
2811 cout << " irunt "<<irunt;
2812 cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2813 cout << " abs "<<abstime;
2814 cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2815 cout << " obt "<<obt;
2816 cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2817 cout << " *** JUMP RUN *** irun "<<irun;
2818 cout << endl;
2819 }
2820 // irun++;
2821 irunoffset[sel_tree->GetTreeNumber()]++;
2822 irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2823 if(irun == run_tree->GetEntries() && SECONDO_GIRO){
2824 // if(irun == irun_start ){
2825 cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;
2826 irunoffset[sel_tree->GetTreeNumber()] = offset_start;
2827 return false;
2828 }
2829 if( irun >= run_tree->GetEntries() || irun < 0){
2830 cout << "irun = "<<irun<<" >> search from the beginning... <<"<<endl;
2831 SECONDO_GIRO=true;
2832 irun=0;
2833 irunoffset[sel_tree->GetTreeNumber()]=-irunt;
2834 }
2835 run_tree->GetEntry(irun);
2836 }
2837
2838
2839 if(DBG){
2840 cout << " (test) ";
2841 cout << " tree "<<sel_tree->GetTreeNumber();
2842 cout << " irunt "<<irunt;
2843 cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2844 cout << " abs "<<abstime;
2845 cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2846 cout << " obt "<<obt;
2847 cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2848 }
2849 if(DBG)cout << endl;
2850 if(DBG)cout << endl << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;
2851 // ----------------------------------------------------
2852 // update the tracker parameters
2853 // (non ho trovato nessun altro modo sicuro di farlo...)
2854 // ----------------------------------------------------
2855 if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2856 TrkParams::Set(GetRunInfo() ,dbc);
2857 if(dbc)dbc->Close();
2858 // cout << endl;
2859 prevshift = 0;
2860 return true;
2861 }
2862 return false;
2863 }
2864
2865 return false;
2866 //
2867 };
2868 /**
2869 * Update the runinfo informations (to be used to have Run infos event by event basis)
2870 * @param run Pointer to the chain/tree which contains run infos
2871 * @return true if a new run has been read, false if it is still the same run
2872 */
2873 Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2874 return(UpdateRunInfo((TChain*)run,iev));
2875 };
2876
2877 //--------------------------------------
2878 //
2879 //
2880 //--------------------------------------
2881 /**
2882 * Set which trees shoul be analysed
2883 * @param detlist TString containing the sequence of trees required
2884 */
2885 void PamLevel2::SetWhichTrees(TString detlist){
2886
2887 // if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2888 if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2889
2890 cout << " ======================================================== "<<endl;
2891 cout << " (( WARNING )) "<<endl;
2892 cout << " The meaning of the option +ALL has changed!! "<<endl;
2893 cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2894 cout << " and the file is discarded if it does not contain "<<endl;
2895 cout << " all trees or if level0 files are not available!! "<<endl;
2896 cout << " ======================================================== "<<endl;
2897
2898 CAL0 = true;
2899 CAL1 = true;
2900 CAL2 = true;
2901 TRK2 = true;
2902 TRK1 = true;
2903 TRKh = true;
2904 TRK0 = true;
2905 TRG = true;
2906 TOF = true;
2907 TOF0 = true;
2908 S4 = true;
2909 ND = true;
2910 AC = true;
2911 ORB = true;
2912 GP = true;
2913 }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
2914 CAL0 = false;
2915 CAL1 = false;
2916 CAL2 = false;
2917 TRK2 = false;
2918 TRK1 = false;
2919 TRKh = false;
2920 TRK0 = false;
2921 TRG = false;
2922 TOF = false;
2923 TOF0 = false;
2924 S4 = false;
2925 ND = false;
2926 AC = false;
2927 ORB = false;
2928 GP = false;
2929 };
2930
2931 // -------------------------------------------------------------------------
2932 if( detlist.Contains("CAL1", TString::kIgnoreCase) ){
2933 if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
2934 if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
2935 };
2936
2937 if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
2938 if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
2939 if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
2940 };
2941
2942 if( detlist.Contains("CAL2", TString::kIgnoreCase)){
2943 if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
2944 if ( detlist.Contains("+CAL2", TString::kIgnoreCase) )CAL2=true;
2945 };
2946
2947 if( detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2 )CAL2=true;
2948 if( detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2 ){
2949 CAL2=false;
2950 CAL1=false;
2951 }
2952 // -------------------------------------------------------------------------
2953 if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
2954 if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
2955 if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
2956 };
2957
2958 if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
2959 if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
2960 if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
2961 };
2962
2963 if( detlist.Contains("TRK2", TString::kIgnoreCase)){
2964 if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false;
2965 if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true;
2966 };
2967
2968 if( detlist.Contains("TRKh", TString::kIgnoreCase)){
2969 if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false;
2970 if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true;
2971 };
2972
2973 if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true;
2974 if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){
2975 TRK2=false;
2976 TRK1=false;
2977 TRKh=false;
2978 }
2979 // -------------------------------------------------------------------------
2980
2981 if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
2982 else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
2983
2984 if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
2985 else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
2986
2987 if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
2988 else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
2989
2990 if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false;
2991 else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true;
2992
2993 if( detlist.Contains("-ND", TString::kIgnoreCase) )ND = false;
2994 else if( detlist.Contains("+ND", TString::kIgnoreCase) )ND = true;
2995
2996 if( detlist.Contains("-AC", TString::kIgnoreCase) )AC = false;
2997 else if( detlist.Contains("+AC", TString::kIgnoreCase) )AC = true;
2998
2999 if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
3000 else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
3001
3002 if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
3003 else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
3004
3005 cout<< "tree/branch list from input --> ";
3006 if(TRK0)cout<<"TRK0 ";
3007 if(TRK1)cout<<"TRK1 ";
3008 if(TRK2)cout<<"TRK2 ";
3009 if(TRKh)cout<<"TRKH ";
3010 if(CAL0)cout<<"CAL0 ";
3011 if(CAL1)cout<<"CAL1 ";
3012 if(CAL2)cout<<"CAL2 ";
3013 if(TOF)cout<<"TOF ";
3014 if(TRG)cout<<"TRG ";
3015 if(AC)cout<<"AC ";
3016 if(ND)cout<<"ND ";
3017 if(S4)cout<<"S4 ";
3018 if(ORB)cout<<"ORB ";
3019 if(GP)cout<<"GP ";
3020 cout << endl;
3021 // cout<< "Set detector list --> ";
3022 // if(TRK1)cout<<"TRK1 ";
3023 // if(TRK2)cout<<"TRK2 ";
3024 // if(TRKh)cout<<"TRKH ";
3025 // if(CAL1)cout<<"CAL1 ";
3026 // if(CAL2)cout<<"CAL2 ";
3027 // if(TOF0)cout<<"TOF0 ";
3028 // if(TOF)cout<<"TOF ";
3029 // if(TRG)cout<<"TRG ";
3030 // if(AC)cout<<"AC ";
3031 // if(ND)cout<<"ND ";
3032 // if(S4)cout<<"S4 ";
3033 // if(ORB)cout<<"ORB ";
3034 // cout << endl;
3035
3036 };
3037
3038
3039 /**
3040 * Set tree/branch detector flags from the content of a tree
3041 */
3042 void PamLevel2::GetWhichTrees(TFile* f){
3043
3044
3045
3046 // cout << "void PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
3047 // -----------
3048 // reset flags
3049 // -----------
3050 CAL1 = false;
3051 CAL2 = false;
3052 TRK2 = false;
3053 TRK1 = false;
3054 TRKh = false;
3055 TRG = false;
3056 TOF = false;
3057 S4 = false;
3058 ND = false;
3059 AC = false;
3060 ORB = false;
3061 GP = false;
3062
3063 RUN = false;
3064
3065 // cout << "Checking file: "<<f->GetName()<<endl;
3066 if( !f || f->IsZombie() ){
3067 cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
3068 return;
3069 }
3070
3071 TList *lk = f->GetListOfKeys();
3072 TIter next(lk);
3073 TKey *key =0;
3074
3075 Int_t nev = 0;
3076
3077 while( (key = (TKey*)next()) ){
3078
3079 if( !strcmp(key->GetName(),"Run" ) )RUN = true;
3080
3081 //=========================================================
3082 if( !strcmp(key->GetName(),"Trigger" ) ){
3083 TRG = true;
3084 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
3085 if( nev && nevt!=nev){
3086 cout << "File: "<< f->GetName() <<" Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
3087 TRG = false;
3088 }else nev=nevt;
3089 }
3090 //=========================================================
3091 if( !strcmp(key->GetName(),"ToF" ) ){
3092 TOF = true;
3093 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
3094 if( nev && nevt!=nev){
3095 cout << "File: "<< f->GetName() <<" ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
3096 TOF = false;
3097 }else nev=nevt;
3098 }
3099 //=========================================================
3100 if( !strcmp(key->GetName(),"S4" ) ){
3101 S4 = true;
3102 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
3103 if( nev && nevt!=nev){
3104 cout << "File: "<< f->GetName() <<" S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
3105 S4 = false;
3106 }else nev=nevt;
3107 }
3108 //=========================================================
3109
3110 if( !strcmp(key->GetName(),"NeutronD" ) ){
3111 ND = true;
3112 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
3113 if( nev && nevt!=nev){
3114 cout << "File: "<< f->GetName() <<"NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
3115 ND =false;
3116 }else nev=nevt;
3117 }
3118 //=========================================================
3119 if( !strcmp(key->GetName(),"Anticounter") ){
3120 AC = true;
3121 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
3122 if( nev && nevt!=nev){
3123 cout << "File: "<< f->GetName() <<" Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
3124 AC =false;
3125 }else nev=nevt;
3126 }
3127 //=========================================================
3128 if( !strcmp(key->GetName(),"OrbitalInfo") ){
3129 ORB = true;
3130 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
3131 if( nev && nevt!=nev){
3132 cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3133 ORB = false;
3134 }else nev=nevt;
3135 }
3136 //=========================================================
3137 if( !strcmp(key->GetName(),"Tracker" ) ){
3138 TTree *T = (TTree*)f->Get("Tracker");
3139 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
3140 TString name = T->GetListOfBranches()->At(i)->GetName();
3141 if( !name.CompareTo("TrkLevel1") )TRK1=true;
3142 if( !name.CompareTo("TrkLevel2") )TRK2=true;
3143 if( !name.CompareTo("TrkHough") )TRKh=true;
3144 };
3145 Int_t nevt = T->GetEntries();
3146 if( nev && nevt!=nev){
3147 cout << "File: "<< f->GetName() <<" Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
3148 TRK1 = false;
3149 TRK2 = false;
3150 TRKh = false;
3151 }else nev=nevt;
3152 // T->Delete();
3153 };
3154 //=========================================================
3155 if( !strcmp(key->GetName(),"Calorimeter" ) ){
3156 TTree *T = (TTree*)f->Get("Calorimeter");
3157 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
3158 TString name = T->GetListOfBranches()->At(i)->GetName();
3159 if( !name.CompareTo("CaloLevel1") )CAL1=true;
3160 if( !name.CompareTo("CaloLevel2") )CAL2=true;
3161 };
3162 Int_t nevt = T->GetEntries();
3163 if( nev && nevt!=nev){
3164 cout << "File: "<< f->GetName() <<" Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
3165 CAL1 = false;
3166 CAL2 = false;
3167 }else nev=nevt;
3168 // T->Delete();
3169 };
3170 //=========================================================
3171 if( !strcmp(key->GetName(),"h20") ){
3172 GP = true;
3173 Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3174 if( nev && nevt!=nev){
3175 cout << "File: "<< f->GetName() <<" h20 tree has "<<nevt<<" events instead of "<<nev<< endl;
3176 GP = false;
3177 }else nev=nevt;
3178 }
3179
3180 };
3181
3182 // delete lk;
3183
3184 cout<< "tree/branch list from file --> ";
3185 if(TRK1)cout<<"TRK1 ";
3186 if(TRK2)cout<<"TRK2 ";
3187 if(TRKh)cout<<"TRKH ";
3188 if(CAL1)cout<<"CAL1 ";
3189 if(CAL2)cout<<"CAL2 ";
3190 if(TOF)cout<<"TOF ";
3191 if(TRG)cout<<"TRG ";
3192 if(AC)cout<<"AC ";
3193 if(ND)cout<<"ND ";
3194 if(S4)cout<<"S4 ";
3195 if(ORB)cout<<"ORB ";
3196 if(GP)cout<<"GP ";
3197 cout << endl;
3198
3199 return ;
3200
3201 };
3202
3203
3204 //--------------------------------------
3205 //
3206 //
3207 //--------------------------------------
3208 /**
3209 * Check if a file contains selected Pamela Level2 trees.
3210 * @param name File name
3211 * @return true if the file is ok.
3212 */
3213 Bool_t PamLevel2::CheckLevel2File(TString name){
3214
3215 Bool_t CAL1__ok = false;
3216 Bool_t CAL2__ok = false;
3217 Bool_t TRK2__ok = false;
3218 Bool_t TRK1__ok = false;
3219 Bool_t TRKh__ok = false;
3220 Bool_t TRG__ok = false;
3221 Bool_t TOF__ok = false;
3222 Bool_t S4__ok = false;
3223 Bool_t ND__ok = false;
3224 Bool_t AC__ok = false;
3225 Bool_t ORB__ok = false;
3226 Bool_t GP__ok = false;
3227
3228 Bool_t RUN__ok = false;
3229
3230 Bool_t SELLI__ok = false;
3231
3232 // cout << "Checking file: "<<name<<endl;
3233 TFile *f = new TFile(name.Data());
3234 if( !f || f->IsZombie() ){
3235 cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
3236 }
3237 // cout << "Get list of keys: "<<f<<endl;
3238 TList *lk = f->GetListOfKeys();
3239 // lk->Print();
3240 TIter next(lk);
3241 TKey *key =0;
3242
3243 Int_t nev = 0;
3244
3245 while( (key = (TKey*)next()) ){
3246
3247 // cout << key->GetName() << endl;
3248 // cout << key->GetName() << ""<<key->GetClassName()<<endl;
3249 // cout << " Get tree: " << f->Get(key->GetName())<<endl;
3250 // nev_previous = nev;
3251 // cout << " n.entries "<< nev <<endl;
3252 // if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
3253 // nev = ((TTree*)f->Get(key->GetName()))->GetEntries();
3254 // cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;
3255 // return false;
3256 // };
3257
3258 //=========================================================
3259 // check if the file
3260
3261
3262 if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true;
3263
3264 //=========================================================
3265 if( !strcmp(key->GetName(),"SelectionList" ) ){
3266 SELLI__ok = true;
3267 if(SELLI==1){
3268 Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
3269 if( nev && nevt!=nev){
3270 cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
3271 return false;
3272 }
3273 nev=nevt;
3274 }
3275 }
3276
3277 //=========================================================
3278 if( !strcmp(key->GetName(),"Trigger" ) ){
3279 TRG__ok = true;
3280 if(TRG){
3281 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
3282 if( nev && nevt!=nev){
3283 cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
3284 return false;
3285 }
3286 nev=nevt;
3287 }
3288 }
3289 //=========================================================
3290 if( !strcmp(key->GetName(),"ToF" ) ){
3291 TOF__ok = true;
3292 if(TOF){
3293 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
3294 if( nev && nevt!=nev){
3295 cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
3296 return false;
3297 }
3298 nev=nevt;
3299 }
3300 }
3301 //=========================================================
3302 if( !strcmp(key->GetName(),"S4" ) ){
3303 S4__ok = true;
3304 if(S4){
3305 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
3306 if( nev && nevt!=nev){
3307 cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
3308 return false;
3309 }
3310 nev=nevt;
3311 }
3312 }
3313 //=========================================================
3314
3315 if( !strcmp(key->GetName(),"NeutronD" ) ){
3316 ND__ok = true;
3317 if(ND){
3318 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
3319 if( nev && nevt!=nev){
3320 cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
3321 return false;
3322 }
3323 nev=nevt;
3324 }
3325 }
3326 //=========================================================
3327 if( !strcmp(key->GetName(),"Anticounter") ){
3328 AC__ok = true;
3329 if(AC){
3330 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
3331 if( nev && nevt!=nev){
3332 cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
3333 return false;
3334 }
3335 nev=nevt;
3336 }
3337 }
3338 //=========================================================
3339 if( !strcmp(key->GetName(),"OrbitalInfo") ){
3340 ORB__ok = true;
3341 if(ORB){
3342 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
3343 if( nev && nevt!=nev){
3344 cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3345 return false;
3346 }
3347 nev=nevt;
3348 }
3349 }
3350 //=========================================================
3351 if( !strcmp(key->GetName(),"Tracker" ) ){
3352 TTree *T = (TTree*)f->Get("Tracker");
3353 if(TRK1||TRK2||TRKh){
3354 Int_t nevt = T->GetEntries();
3355 if( nev && nevt!=nev){
3356 cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
3357 return false;
3358 }
3359 nev=nevt;
3360 }
3361 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
3362 TString name = T->GetListOfBranches()->At(i)->GetName();
3363 if( !name.CompareTo("TrkLevel1") )TRK1__ok=true;
3364 if( !name.CompareTo("TrkLevel2") )TRK2__ok=true;
3365 if( !name.CompareTo("TrkHough") )TRKh__ok=true;
3366 };
3367 T->Delete();
3368 };
3369 //=========================================================
3370 if( !strcmp(key->GetName(),"Calorimeter" ) ){
3371 TTree *T = (TTree*)f->Get("Calorimeter");
3372 if(CAL1||CAL2){
3373 Int_t nevt = T->GetEntries();
3374 if( nev && nevt!=nev){
3375 cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
3376 return false;
3377 }
3378 nev=nevt;
3379 }
3380 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
3381 TString name = T->GetListOfBranches()->At(i)->GetName();
3382 if( !name.CompareTo("CaloLevel1") )CAL1__ok=true;
3383 if( !name.CompareTo("CaloLevel2") )CAL2__ok=true;
3384 };
3385 T->Delete();
3386 };
3387 //=========================================================
3388 if( !strcmp(key->GetName(),"h20") ){
3389 ISGP = true;
3390 GP__ok = true;
3391 if(GP){
3392 Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3393 if( nev && nevt!=nev){
3394 cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3395 return false;
3396 }
3397 nev=nevt;
3398 }
3399 }
3400
3401 };
3402
3403 if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
3404 if( SELLI==0 && SELLI__ok ){
3405 cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
3406 return false;
3407 }
3408 if( SELLI==1 && !SELLI__ok ){
3409 cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
3410 return false;
3411 }
3412
3413 // cout << "SELLI "<<SELLI<<endl;
3414
3415 // cout<< "CheckLevel2File(TString): detector list --> ";
3416 // if(TRK1__ok)cout<<"TRK1 ";
3417 // if(TRK2__ok)cout<<"TRK2 ";
3418 // if(TRKh__ok)cout<<"TRKH ";
3419 // if(CAL1__ok)cout<<"CAL1 ";
3420 // if(CAL2__ok)cout<<"CAL2 ";
3421 // if(TOF__ok)cout<<"TOF ";
3422 // if(TRG__ok)cout<<"TRG ";
3423 // if(AC__ok)cout<<"AC ";
3424 // if(ND__ok)cout<<"ND ";
3425 // if(S4__ok)cout<<"S4 ";
3426 // if(ORB__ok)cout<<"ORB ";
3427 // cout << endl;
3428
3429
3430 if(TRK2 && TRK1__ok)TRK1=1;
3431 // ----------------------------------------------------------------------------
3432 // NOTA
3433 // se c'e` il level1, lo devo necessarimente leggere.
3434 // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
3435 // comunque, ma non vengono disallocati da PamLevel2::Clear()
3436 // ----------------------------------------------------------------------------
3437
3438
3439 if(!RUN__ok) {
3440 cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree (NB: RUN infos will not be updated)"<< endl;
3441 RUN = false;
3442 };
3443
3444 if(CAL1 && !CAL1__ok){
3445 cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl;
3446 return false;
3447 };
3448 if(CAL2 && !CAL2__ok){
3449 cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl;
3450 return false;
3451 };
3452 if(TRK2 && !TRK2__ok){
3453 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl;
3454 return false;
3455 };
3456 if(TRK1 && !TRK1__ok){
3457 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl;
3458 return false;
3459 };
3460 if(TRKh && !TRKh__ok){
3461 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl;
3462 return false;
3463 };
3464 if(ORB && !ORB__ok){
3465 cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl;
3466 return false;
3467 };
3468 if(AC && !AC__ok){
3469 cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl;
3470 return false;
3471 };
3472 if(S4 && !S4__ok){
3473 cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl;
3474 return false;
3475 };
3476 if(TOF && !TOF__ok){
3477 cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl;
3478 return false;
3479 };
3480
3481 if(ND && !ND__ok){
3482 cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
3483 return false;
3484 };
3485 if(TRG && !TRG__ok){
3486 cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
3487 return false;
3488 };
3489 if(GP && !GP__ok){
3490 cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl;
3491 return false;
3492 };
3493
3494
3495 // lk->Delete();
3496 // delete lk;
3497 f->Close();
3498
3499 // cout<< "CheckLevel2File(TString): detector list --> ";
3500 // if(TRK1)cout<<"TRK1 ";
3501 // if(TRK2)cout<<"TRK2 ";
3502 // if(TRKh)cout<<"TRKH ";
3503 // if(CAL1)cout<<"CAL1 ";
3504 // if(CAL2)cout<<"CAL2 ";
3505 // if(TOF)cout<<"TOF ";
3506 // if(TRG)cout<<"TRG ";
3507 // if(AC)cout<<"AC ";
3508 // if(ND)cout<<"ND ";
3509 // if(S4)cout<<"S4 ";
3510 // if(ORB)cout<<"ORB ";
3511 // if(GP)cout<<"GP ";
3512 // cout << endl;
3513
3514 return true;
3515
3516 };
3517
3518
3519 /**
3520 * Create clone-trees
3521 */
3522 void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){
3523
3524 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3525 cout << "Create clones of PAMELA trees "<<endl;
3526
3527 Int_t i=0;
3528 pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
3529 TString name = pam_tree_clone[i]->GetName();
3530 name.Append("_clone");
3531 // pam_tree_clone[i]->SetName(name.Data());
3532 cout << pam_tree_clone[i]->GetName() <<endl;
3533 i++;
3534
3535 TList *li = fChain->GetListOfFriends();
3536 TIter next(li);
3537 TFriendElement* T_friend=0;
3538 ofile->cd();
3539 while( (T_friend = (TFriendElement*)next()) ){
3540 // cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
3541 // cout<<T_friend->GetTree()->GetName()<< endl;
3542 pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
3543 pam_tree_clone[i]->SetAutoSave(1000000);
3544 name = pam_tree_clone[i]->GetName();
3545 name.Append("_clone");
3546 // pam_tree_clone[i]->SetName(name.Data());
3547 cout << pam_tree_clone[i]->GetName() << endl;
3548 i++;
3549 }
3550
3551 delete li;
3552
3553 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3554
3555 }
3556
3557 /**
3558 * Create clone-trees
3559 */
3560 void PamLevel2::CreateCloneTrees(TFile *ofile){
3561
3562
3563 // if the pointer is null, create a default file
3564 if(!run_tree)return;
3565
3566 if(!ofile){
3567 cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
3568 ofile = new TFile("clone-tree.root","recreate");
3569 }
3570
3571 ofile->cd();
3572
3573 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3574 cout << "Create new PAMELA trees "<<endl;
3575
3576
3577 run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
3578 run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
3579 cout << "Run : branch RunInfo"<<endl;
3580 run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
3581 cout << "Run : branch SoftInfo"<<endl;
3582 // ------------------
3583 // replicate run tree
3584 // ------------------
3585 // cout << "----------------------------------------------------"<<endl;
3586 // cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3587 for (Int_t i=0; i<run_tree->GetEntries(); i++){
3588 run_tree->GetEntry(i);
3589 // cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
3590 run_tree_clone->Fill();
3591 }
3592 cout << "----------------------------------------------------"<<endl;
3593
3594 // ------------------------------------
3595 // add branch with dead and live times
3596 // ------------------------------------
3597 run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3598 cout << "Run : branch DeadLiveTime"<<endl;
3599
3600
3601 sel_tree_clone = new TTree("SelectionList","List of selected events ");
3602 // sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3603 sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3604 sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3605
3606
3607 Int_t i=0;
3608 if(TRK1||TRK2||TRKh){
3609 pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
3610 if(TRK1) {
3611 pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
3612 pam_tree_clone[i]->BranchRef();
3613 cout << "Tracker : branch TrkLevel1"<<endl;
3614 // cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
3615 };
3616 if(TRK2) {
3617 pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
3618 cout << "Tracker : branch TrkLevel2"<<endl;
3619 };
3620 if(TRKh) {
3621 pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
3622 cout << "Tracker : branch TrkHough"<<endl;
3623 };
3624 i++;
3625 }
3626
3627 // Calorimeter
3628 if(CAL1||CAL2){
3629 pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
3630 if(CAL1) {
3631 pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
3632 cout << "Calorimeter : branch CaloLevel1"<<endl;
3633 };
3634 if(CAL2) {
3635 pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
3636 cout << "Calorimeter : branch CaloLevel2"<<endl;
3637 };
3638 i++;
3639 }
3640
3641 // ToF
3642 if(TOF) {
3643 pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
3644 pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
3645 cout << "ToF : branch ToFLevel2"<<endl;
3646 i++;
3647 };
3648 // Trigger
3649 if(TRG) {
3650 pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
3651 pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
3652 cout << "Trigger : branch TrigLevel2"<<endl;
3653 i++;
3654 };
3655 // S4
3656 if(S4) {
3657 pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");
3658 pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
3659 cout << "S4 : branch S4Level2"<<endl;
3660 i++;
3661 };
3662 // Neutron Detector
3663 if(ND) {
3664 pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");
3665 pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
3666 cout << "NeutronD : branch NDLevel2"<<endl;
3667 i++;
3668 };
3669 // Anticounters
3670 if(AC) {
3671 pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");
3672 pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
3673 cout << "Anticounter : branch AcLevel2"<<endl;
3674 i++;
3675 };
3676 // OrbitalInfo
3677 if(ORB) {
3678 pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info ");
3679 pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
3680 cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
3681 i++;
3682 };
3683 // GPamela
3684 if(GP) {
3685 pam_tree_clone[i] = new TTree("h20","PAMELA oribital info ");
3686 pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3687 cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
3688 i++;
3689 };
3690 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3691
3692 }
3693
3694
3695 /**
3696 * Fill tree (created with CreateCloneTrees)
3697 *
3698 */
3699 //void PamLevel2::FillNewPamTree(TTree *T){
3700 void PamLevel2::FillCloneTrees(){
3701
3702 // cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
3703
3704 for(Int_t i=0; i<NCLONES; i++){
3705 if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
3706 }
3707 if(sel_tree_clone)sel_tree_clone->Fill();
3708
3709 }
3710
3711
3712 TTree* PamLevel2::GetCloneTree(TString name){
3713
3714 for(Int_t i=0; i<NCLONES; i++){
3715 if(pam_tree_clone[i]){
3716 TString na = pam_tree_clone[i]->GetName();
3717 if(!name.CompareTo(na))return pam_tree_clone[i];
3718 };
3719 }
3720 if(run_tree_clone){
3721 TString na = run_tree_clone->GetName();
3722 if(!name.CompareTo(na))return run_tree_clone;
3723 }
3724 if(sel_tree_clone){
3725 TString na = sel_tree_clone->GetName();
3726 if(!name.CompareTo(na))return sel_tree_clone;
3727 }
3728 return NULL;
3729
3730 }
3731 void PamLevel2::WriteCloneTrees(){
3732 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3733 cout << "Write clones of PAMELA trees "<<endl;
3734 cout << run_tree_clone->GetName()<<endl;
3735 if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3736 run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3737 run_tree_clone->Write();
3738 cout << sel_tree_clone->GetName()<<endl;
3739 sel_tree_clone->Write();
3740 for(Int_t i=0; i<NCLONES; i++){
3741 if(pam_tree_clone[i]){
3742 cout << pam_tree_clone[i]->GetName()<<endl;
3743 pam_tree_clone[i]->Write();
3744 };
3745 }
3746 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3747
3748 }
3749
3750 /**
3751 * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
3752 */
3753 //Int_t PamLevel2::GetEntry(Int_t iee){
3754 Int_t PamLevel2::GetEntry(Long64_t iee){
3755
3756 // cout << "-------------------------------------"<<endl;
3757 // cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
3758
3759 if(!pam_tree){
3760 cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
3761 return 0;
3762 }
3763
3764
3765 //
3766 // This is a sort of bug: if you don't have the run tree you don't want to exit here you want to have loaded the event anyway...
3767 //
3768 // if(!run_tree ){
3769 // cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
3770 // return 0;
3771 // }
3772
3773 Long64_t ii=0;
3774 //-------------------------------
3775 ii = iee;
3776 if( !pam_tree->GetEntry(ii) ){
3777 cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3778 return 0;
3779 }
3780
3781 //
3782 // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0.
3783 // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not
3784 // a problem if you don't check the return code of getentry.
3785 //
3786 if(!RUN || !run_tree ){
3787 if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3788 cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3789 return 0;
3790 } else {
3791 return 1; //cosi` se non c'e` run esce qua...
3792 }
3793 }
3794
3795 //-------------------------------
3796 ii = iee;
3797 // Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3798 // Bool_t UPDATED = UpdateRunInfo(ii);
3799 UpdateRunInfo(ii);
3800 if(SELLI==0)irunentry = iee-runfirstentry;
3801 // if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3802
3803 // cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
3804
3805 // cout << "irunentry "<<irunentry << endl;
3806 // cout << "runfirstentry "<<runfirstentry << endl;
3807 // cout << "nevents "<<GetRunInfo()->NEVENTS<< endl;
3808
3809 // if( TRK0 || CAL0 || TOF0 ){
3810 // if( !GetYodaEntry( ) ){
3811 // cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3812 // return 0;
3813 // }
3814 // }
3815
3816
3817 return 1;
3818
3819 }
3820
3821 TrkLevel0 *PamLevel2::GetTrkLevel0(){
3822 if( !TRK0 )return NULL;
3823 if( !GetYodaEntry( ) ){
3824 cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3825 return 0;
3826 }
3827 return trk0_obj;
3828 };
3829 CaloLevel0 *PamLevel2::GetCaloLevel0(){
3830 if( !CAL0 )return NULL;
3831 if( !GetYodaEntry( ) ){
3832 cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3833 return 0;
3834 }
3835 return calo0_obj;
3836 };
3837
3838
3839 /**
3840 * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3841 * Given the run ID (...), if needed it query the DB and load the proper file.
3842 * @return Pointer to the tree
3843 */
3844
3845
3846 TTree* PamLevel2::GetYodaTree( ){
3847
3848 // cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
3849 //===================================
3850 // check if iroot has changed
3851 //===================================
3852 if( irun<0 ){
3853 cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;
3854 // cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
3855 return NULL;
3856 }
3857 Int_t irootnew = run_obj->ID_ROOT_L0;
3858 // cout << "iroot "<<iroot<<endl;
3859 // cout << "irootnew "<<irootnew<<endl;
3860
3861 //===================================
3862 // load the level0 file
3863 // (if not already loaded)
3864 //===================================
3865 if( iroot != irootnew || !l0_tree){
3866 iroot = irootnew;
3867 //===================================
3868 // open the DB connection
3869 // (if not already opened)
3870 //===================================
3871 if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3872 GL_ROOT glroot = GL_ROOT();
3873 if( glroot.Query_GL_ROOT(iroot,dbc) ){
3874 cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
3875 return NULL;
3876 };
3877 TString filename = glroot.PATH + glroot.NAME;
3878 if(l0_file){
3879 l0_file->Close();
3880 l0_file->Delete();
3881 }
3882 cout << "Opening LEVEL0 file: "<< filename << endl;
3883 FileStat_t t;
3884 if( gSystem->GetPathInfo(filename.Data(),t) ){
3885 cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
3886 return NULL;
3887 }
3888 l0_file = new TFile(filename);
3889 if( !l0_file )return NULL;
3890 l0_tree = (TTree*)l0_file->Get("Physics");
3891 if(!h0_obj)h0_obj = new EventHeader();
3892 l0_tree->SetBranchAddress("Header" ,&h0_obj);
3893 prevshift = 0;
3894 //---------------------------------------------------
3895 // TRACKER:
3896 if(TRK0){
3897 if(!trk0_obj){
3898 trk0_obj = new TrkLevel0();
3899 trk0_obj->Set();
3900 };
3901 l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3902 }
3903 //--------------------------------------------------
3904 // CALORIMETER:
3905 if(CAL0){
3906 if(!calo0_obj){
3907 calo0_obj = new CaloLevel0();
3908 calo0_obj->Set();
3909 };
3910 l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
3911 // cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
3912 }
3913 //---------------------------------------------------
3914 // TOF:
3915 if(TOF0){
3916 cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3917 }
3918
3919 dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3920
3921
3922 };
3923
3924 // if(!dbc || (dbc && !dbc->IsConnected())){
3925 // cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3926 // }
3927
3928 if ( TRK0 ){
3929 // TrkParams::Load(6);
3930 // if( !TrkParams::IsLoaded(6) ){
3931 // cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3932 // };
3933 // if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3934 TrkParams::SetCalib(run_obj,dbc);
3935 TrkParams::LoadCalib( );
3936 if( !TrkParams::CalibIsLoaded() ){
3937 cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3938 };
3939 // if(dbc)dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3940 }
3941
3942
3943 // cout << l0_tree << endl;
3944 return l0_tree;
3945
3946 }
3947
3948 /**
3949 * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3950 */
3951 Int_t PamLevel2::GetYodaEntry(){
3952
3953 // cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
3954 if(!GetYodaTree())return 0;
3955
3956 // patch
3957 if( irunentry < 0){
3958 // cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
3959 irunentry=0LL;
3960 }
3961 // ---------------------------------
3962 // if file is NOT a preselected file
3963 // ---------------------------------
3964 Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
3965 // cout << " irunentry "<<irunentry<<endl;
3966 // cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
3967 // cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
3968
3969 // cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
3970 // cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
3971 // cout << " time "<< abstime << endl;
3972 // cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
3973
3974 ULong64_t obt = 0;
3975 ULong64_t pktn = 0;
3976 if( GetOrbitalInfo() ){
3977 obt = GetOrbitalInfo()->OBT;
3978 pktn = GetOrbitalInfo()->pkt_num;
3979 }
3980
3981 if( !GetOrbitalInfo() && !ISGP){
3982 cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
3983 return 0;
3984 }
3985 if( obt==0 && pktn==0 && !ISGP ){
3986 cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
3987 return 0;
3988 }
3989
3990 // ---------------------------------------------------------------------
3991 // ATTENTION!!!
3992 // If data are not pre-processed with cleaner, the level0 tree may contain
3993 // spurious nested physics packets.
3994 // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
3995 // while level2 tree DOES NOT!!
3996 // This means that "quellagiusta" in these cases is not correct.
3997 // In order to retrieve the correct level0 event, I implemented a check
3998 // of the OBT and pkt-number. In case of mismatch, the level0 entry number
3999 // is shift forward until when the packets match.
4000 // ---------------------------------------------------------------------
4001 Int_t answer = 0;
4002 Int_t shift =0;
4003 // printf(" siamo qui %i %i \n",shift,prevshift);
4004 // Int_t maxshift = 50; // EMILIANO
4005 do{
4006 if(shift>0){
4007 cout << " PKTNUM L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
4008 if(DBG)cout << " RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM <<endl;
4009 if(DBG)cout << " L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
4010 }
4011 answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
4012 shift++;
4013 if( !GetEventHeader() ){
4014 cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
4015 return 0;
4016 }
4017
4018 if(ISGP){
4019 obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
4020 pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
4021 }
4022
4023 // cout << "PKTNUM "<<shift<<" == L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
4024 // cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
4025 // if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
4026 // cout << " obt "<< obt << endl;
4027 // cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
4028 // cout << " pktn "<< pktn << endl;
4029 // cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
4030 // printf(" IDRUN %u \n",GetRunInfo()->ID);
4031 //
4032 if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
4033 prevshift = 0;
4034 shift = -1;
4035 };
4036
4037 }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
4038 pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) )
4039 && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
4040
4041 if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
4042 cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to "<<maxshift<<" )" <<endl;
4043 return 0;
4044 }
4045 // cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
4046 // return GetYodaTree()->GetEntry(quellagiusta);
4047 if ( shift > 1 ) prevshift += (shift-1);
4048
4049 return answer;
4050
4051 }
4052 /**
4053 * \Brief Set DB connection
4054 */
4055 Bool_t PamLevel2::SetDBConnection(){
4056
4057 // cout << "PamLevel2::SetDBConnection()" << endl;
4058 if(DBG){
4059 cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4060 cout<<"Connecting to DB"<<endl;
4061 cout<<"HOST "<<host<<endl;
4062 cout<<"USER "<<user<<endl;
4063 cout<<"PSW "<<psw<<endl;
4064 }
4065 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
4066 if( !dbc )return false;
4067 if( !dbc->IsConnected() )return false;
4068 stringstream myquery; // EMILIANO
4069 myquery.str(""); // EMILIANO
4070 myquery << "SET time_zone='+0:00'"; // EMILIANO
4071 dbc->Query(myquery.str().c_str()); // EMILIANO
4072 if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4073 return true;
4074
4075 }
4076
4077 /**
4078 * \Brief Add a friend to the pamela chain.
4079 * @param cname name of the chain to be added
4080 */
4081
4082 TChain* PamLevel2::AddFriend(TString cname){
4083
4084 if(!GetPamTree()){
4085 cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;
4086 return NULL;
4087 }
4088
4089
4090 TChain *c = new TChain( cname.Data() );
4091
4092 TIter next( GetPamTree()->GetListOfFiles() );
4093 Int_t nf = 0;
4094 TChainElement* element = 0;
4095 while ((element = (TChainElement*) next())) {
4096 c->Add(element->GetTitle());
4097 nf++;
4098 }
4099
4100 GetPamTree()->AddFriend(cname.Data());
4101
4102 cout << "external chain created and added to pamela friends :"<<cname<<endl;
4103 cout << "n.files "<<nf<<endl;
4104
4105
4106 return c;
4107
4108 }
4109
4110

  ViewVC Help
Powered by ViewVC 1.1.23