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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.23