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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.79 - (hide annotations) (download)
Wed Mar 18 09:02:01 2009 UTC (15 years, 11 months ago) by pam-fi
Branch: MAIN
Changes since 1.78: +22 -17 lines
bug fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23