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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.86 - (hide annotations) (download)
Tue May 11 07:26:27 2010 UTC (14 years, 10 months ago) by mocchiut
Branch: MAIN
Changes since 1.85: +14 -0 lines
Warnings added

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

  ViewVC Help
Powered by ViewVC 1.1.23