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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.84 - (hide annotations) (download)
Thu Aug 6 14:39:33 2009 UTC (15 years, 4 months ago) by mocchiut
Branch: MAIN
CVS Tags: v9r00
Changes since 1.83: +3 -2 lines
Bugs when running with list in ROOT 5.24 fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23