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

Contents of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.85 - (show annotations) (download)
Tue May 11 03:57:52 2010 UTC (14 years, 9 months ago) by mocchiut
Branch: MAIN
Changes since 1.84: +2 -1 lines
Skip DB connections - no RunInfo update added

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

  ViewVC Help
Powered by ViewVC 1.1.23