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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.55 - (hide annotations) (download)
Wed Nov 14 11:14:28 2007 UTC (17 years ago) by pam-fi
Branch: MAIN
Changes since 1.54: +795 -759 lines
implemented track sorting with GP hits

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

  ViewVC Help
Powered by ViewVC 1.1.23