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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.58 - (hide annotations) (download)
Tue Nov 27 19:34:08 2007 UTC (17 years ago) by pam-fi
Branch: MAIN
Changes since 1.57: +9 -8 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23