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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.64 - (hide annotations) (download)
Wed Oct 1 16:06:19 2008 UTC (16 years, 5 months ago) by mocchiut
Branch: MAIN
Changes since 1.63: +60 -6 lines
PamTrack class changed, OrbitalInfoTrkVar added

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

  ViewVC Help
Powered by ViewVC 1.1.23