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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.63 - (hide annotations) (download)
Tue Sep 30 07:45:24 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: MAIN
Changes since 1.62: +1 -1 lines
InclinationInfo.h included in PamLevel2.h

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

  ViewVC Help
Powered by ViewVC 1.1.23