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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.97 - (hide annotations) (download)
Fri Oct 17 06:54:11 2014 UTC (10 years, 8 months ago) by pam-fi
Branch: MAIN
Changes since 1.96: +56 -32 lines
Memory leak bug fixed

1 pam-fi 1.1 #include <PamLevel2.h>
2 pam-fi 1.52
3     /////////////////////////////////////////////////////////////////////////////
4     /////////////////////////////////////////////////////////////////////////////
5     /////////////////////////////////////////////////////////////////////////////
6     /////////////////////////////////////////////////////////////////////////////
7    
8 pam-fi 1.81 void GPamela::Clear() {
9     Irun = 0;
10     Ievnt = 0;
11     Ipa = 0;
12     X0 = 0.;
13     Y0 = 0.;
14     Z0 = 0.;
15     Theta = 0.;
16     Phi = 0.;
17     P0 = 0.;
18     Nthtof = 0;
19     Nthcat = 0;
20     Nthcas = 0;
21     Nthspe = 0;
22     Nstrpx = 0;
23     Nstrpy = 0;
24     Nthcali = 0;
25     Nthcal = 0;
26     Nthnd = 0;
27     Nthcard = 0;
28 pam-fi 1.52 }
29    
30 pam-fi 1.81 void GPamela::Delete() {
31    
32     Clear();
33 mocchiut 1.93 /* EM all these are in the stack not in the heap, so no need to delete by hand...
34 pam-fi 1.81 delete[] Ipltof;
35     delete[] Ipaddle;
36     delete[] Ipartof;
37     delete[] Xintof;
38     delete[] Yintof;
39     delete[] Zintof;
40     delete[] Xouttof;
41     delete[] Youttof;
42     delete[] Zouttof;
43     delete[] Ereltof;
44     delete[] Timetof;
45     delete[] Pathtof;
46     delete[] P0tof;
47     delete[] Iparcat;
48     delete[] Icat;
49     delete[] Xincat;
50     delete[] Yincat;
51     delete[] Zincat;
52     delete[] Xoutcat;
53     delete[] Youtcat;
54     delete[] Zoutcat;
55     delete[] Erelcat;
56     delete[] Timecat;
57     delete[] Pathcat;
58     delete[] P0cat;
59     delete[] Iparcas;
60     delete[] Icas;
61     delete[] Xincas;
62     delete[] Yincas;
63     delete[] Zincas;
64     delete[] Xoutcas;
65     delete[] Youtcas;
66     delete[] Zoutcas;
67     delete[] Erelcas;
68     delete[] Timecas;
69     delete[] Pathcas;
70     delete[] P0cas;
71     delete[] Iparspe;
72     delete[] Itrpb;
73     delete[] Itrsl;
74     delete[] Itspa;
75     delete[] Xinspe;
76     delete[] Yinspe;
77     delete[] Zinspe;
78     delete[] Xoutspe;
79     delete[] Youtspe;
80     delete[] Zoutspe;
81     delete[] Xavspe;
82     delete[] Yavspe;
83     delete[] Zavspe;
84     delete[] Erelspe;
85     delete[] Pathspe;
86     delete[] P0spe;
87     delete[] Nxmult;
88     delete[] Nymult;
89     delete[] Npstripx;
90     delete[] Ntstripx;
91     delete[] Istripx;
92     delete[] Qstripx;
93     delete[] Xstripx;
94     delete[] Npstripy;
95     delete[] Ntstripy;
96     delete[] Istripy;
97     delete[] Qstripy;
98     delete[] Ystripy;
99     delete[] Icaplane;
100     delete[] Icastrip;
101     delete[] Icamod;
102     delete[] Enestrip;
103     delete[] Icapl;
104     delete[] Icasi;
105     delete[] Icast;
106     delete[] Xincal;
107     delete[] Yincal;
108     delete[] Zincal;
109     delete[] Erelcal;
110     delete[] Itubend;
111     delete[] Iparnd;
112     delete[] Xinnd;
113     delete[] Yinnd;
114     delete[] Zinnd;
115     delete[] Xoutnd;
116     delete[] Youtnd;
117     delete[] Zoutnd;
118     delete[] Erelnd;
119     delete[] Timend;
120     delete[] Pathnd;
121     delete[] P0nd;
122     delete[] Iparcard;
123     delete[] Icard;
124     delete[] Xincard;
125     delete[] Yincard;
126     delete[] Zincard;
127     delete[] Xoutcard;
128     delete[] Youtcard;
129     delete[] Zoutcard;
130     delete[] Erelcard;
131     delete[] Timecard;
132     delete[] Pathcard;
133     delete[] P0card;
134 mocchiut 1.93 */
135     }
136 pam-fi 1.52
137 pam-fi 1.81
138     void GPamela::SetBranchAddress(TChain* fhBookTree) {
139 pam-fi 1.52
140 pam-fi 1.81 // cout << "fhBookTree "<<fhBookTree << endl;
141     // prepare tree
142     fhBookTree->SetBranchAddress("Irun", &Irun);
143     fhBookTree->SetBranchAddress("Ievnt", &Ievnt);
144     fhBookTree->SetBranchAddress("Ipa", &Ipa);
145     fhBookTree->SetBranchAddress("X0", &X0);
146     fhBookTree->SetBranchAddress("Y0", &Y0);
147     fhBookTree->SetBranchAddress("Z0", &Z0);
148     fhBookTree->SetBranchAddress("Theta", &Theta);
149     fhBookTree->SetBranchAddress("Phi", &Phi);
150     fhBookTree->SetBranchAddress("P0", &P0);
151     fhBookTree->SetBranchAddress("Nthtof", &Nthtof);
152     fhBookTree->SetBranchAddress("Ipltof", Ipltof);
153     fhBookTree->SetBranchAddress("Ipaddle", Ipaddle);
154     fhBookTree->SetBranchAddress("Ipartof", Ipartof);
155     fhBookTree->SetBranchAddress("Xintof", Xintof);
156     fhBookTree->SetBranchAddress("Yintof", Yintof);
157     fhBookTree->SetBranchAddress("Zintof", Zintof);
158     fhBookTree->SetBranchAddress("Xouttof", Xouttof);
159     fhBookTree->SetBranchAddress("Youttof", Youttof);
160     fhBookTree->SetBranchAddress("Zouttof", Zouttof);
161     fhBookTree->SetBranchAddress("Ereltof", Ereltof);
162     fhBookTree->SetBranchAddress("Timetof", Timetof);
163     fhBookTree->SetBranchAddress("Pathtof", Pathtof);
164     fhBookTree->SetBranchAddress("P0tof", P0tof);
165     fhBookTree->SetBranchAddress("Nthcat", &Nthcat);
166     fhBookTree->SetBranchAddress("Iparcat", Iparcat);
167     fhBookTree->SetBranchAddress("Icat", Icat);
168     fhBookTree->SetBranchAddress("Xincat", Xincat);
169     fhBookTree->SetBranchAddress("Yincat", Yincat);
170     fhBookTree->SetBranchAddress("Zincat", Zincat);
171     fhBookTree->SetBranchAddress("Xoutcat", Xoutcat);
172     fhBookTree->SetBranchAddress("Youtcat", Youtcat);
173     fhBookTree->SetBranchAddress("Zoutcat", Zoutcat);
174     fhBookTree->SetBranchAddress("Erelcat", Erelcat);
175     fhBookTree->SetBranchAddress("Timecat", Timecat);
176     fhBookTree->SetBranchAddress("Pathcat", Pathcat);
177     fhBookTree->SetBranchAddress("P0cat", P0cat);
178     fhBookTree->SetBranchAddress("Nthcas", &Nthcas);
179     fhBookTree->SetBranchAddress("Iparcas", Iparcas);
180     fhBookTree->SetBranchAddress("Icas", Icas);
181     fhBookTree->SetBranchAddress("Xincas", Xincas);
182     fhBookTree->SetBranchAddress("Yincas", Yincas);
183     fhBookTree->SetBranchAddress("Zincas", Zincas);
184     fhBookTree->SetBranchAddress("Xoutcas", Xoutcas);
185     fhBookTree->SetBranchAddress("Youtcas", Youtcas);
186     fhBookTree->SetBranchAddress("Zoutcas", Zoutcas);
187     fhBookTree->SetBranchAddress("Erelcas", Erelcas);
188     fhBookTree->SetBranchAddress("Timecas", Timecas);
189     fhBookTree->SetBranchAddress("Pathcas", Pathcas);
190     fhBookTree->SetBranchAddress("P0cas", P0cas);
191     fhBookTree->SetBranchAddress("Nthspe", &Nthspe);
192     fhBookTree->SetBranchAddress("Iparspe", Iparspe);
193     fhBookTree->SetBranchAddress("Itrpb", Itrpb);
194     fhBookTree->SetBranchAddress("Itrsl", Itrsl);
195     fhBookTree->SetBranchAddress("Itspa", Itspa);
196     fhBookTree->SetBranchAddress("Xinspe", Xinspe);
197     fhBookTree->SetBranchAddress("Yinspe", Yinspe);
198     fhBookTree->SetBranchAddress("Zinspe", Zinspe);
199     fhBookTree->SetBranchAddress("Xoutspe", Xoutspe);
200     fhBookTree->SetBranchAddress("Youtspe", Youtspe);
201     fhBookTree->SetBranchAddress("Zoutspe", Zoutspe);
202     fhBookTree->SetBranchAddress("Xavspe", Xavspe);
203     fhBookTree->SetBranchAddress("Yavspe", Yavspe);
204     fhBookTree->SetBranchAddress("Zavspe", Zavspe);
205     fhBookTree->SetBranchAddress("Erelspe", Erelspe);
206     fhBookTree->SetBranchAddress("Pathspe", Pathspe);
207     fhBookTree->SetBranchAddress("P0spe", P0spe);
208     fhBookTree->SetBranchAddress("Nxmult", Nxmult);
209     fhBookTree->SetBranchAddress("Nymult", Nymult);
210     fhBookTree->SetBranchAddress("Nstrpx", &Nstrpx);
211     fhBookTree->SetBranchAddress("Npstripx", Npstripx);
212     fhBookTree->SetBranchAddress("Ntstripx", Ntstripx);
213     fhBookTree->SetBranchAddress("Istripx", Istripx);
214     fhBookTree->SetBranchAddress("Qstripx", Qstripx);
215     fhBookTree->SetBranchAddress("Xstripx", Xstripx);
216     fhBookTree->SetBranchAddress("Nstrpy", &Nstrpy);
217     fhBookTree->SetBranchAddress("Npstripy", Npstripy);
218     fhBookTree->SetBranchAddress("Ntstripy", Ntstripy);
219     fhBookTree->SetBranchAddress("Istripy", Istripy);
220     fhBookTree->SetBranchAddress("Qstripy", Qstripy);
221     fhBookTree->SetBranchAddress("Ystripy", Ystripy);
222     fhBookTree->SetBranchAddress("Nthcali", &Nthcali);
223     fhBookTree->SetBranchAddress("Icaplane", Icaplane);
224     fhBookTree->SetBranchAddress("Icastrip", Icastrip);
225     fhBookTree->SetBranchAddress("Icamod", Icamod);
226     fhBookTree->SetBranchAddress("Enestrip", Enestrip);
227     fhBookTree->SetBranchAddress("Nthcal", &Nthcal);
228     fhBookTree->SetBranchAddress("Icapl", Icapl);
229     fhBookTree->SetBranchAddress("Icasi", Icasi);
230     fhBookTree->SetBranchAddress("Icast", Icast);
231     fhBookTree->SetBranchAddress("Xincal", Xincal);
232     fhBookTree->SetBranchAddress("Yincal", Yincal);
233     fhBookTree->SetBranchAddress("Zincal", Zincal);
234     fhBookTree->SetBranchAddress("Erelcal", Erelcal);
235     fhBookTree->SetBranchAddress("Nthnd", &Nthnd);
236     fhBookTree->SetBranchAddress("Itubend", Itubend);
237     fhBookTree->SetBranchAddress("Iparnd", Iparnd);
238     fhBookTree->SetBranchAddress("Xinnd", Xinnd);
239     fhBookTree->SetBranchAddress("Yinnd", Yinnd);
240     fhBookTree->SetBranchAddress("Zinnd", Zinnd);
241     fhBookTree->SetBranchAddress("Xoutnd", Xoutnd);
242     fhBookTree->SetBranchAddress("Youtnd", Youtnd);
243     fhBookTree->SetBranchAddress("Zoutnd", Zoutnd);
244     fhBookTree->SetBranchAddress("Erelnd", Erelnd);
245     fhBookTree->SetBranchAddress("Timend", Timend);
246     fhBookTree->SetBranchAddress("Pathnd", Pathnd);
247     fhBookTree->SetBranchAddress("P0nd", P0nd);
248     fhBookTree->SetBranchAddress("Nthcard", &Nthcard);
249     fhBookTree->SetBranchAddress("Iparcard", Iparcard);
250     fhBookTree->SetBranchAddress("Icard", Icard);
251     fhBookTree->SetBranchAddress("Xincard", Xincard);
252     fhBookTree->SetBranchAddress("Yincard", Yincard);
253     fhBookTree->SetBranchAddress("Zincard", Zincard);
254     fhBookTree->SetBranchAddress("Xoutcard", Xoutcard);
255     fhBookTree->SetBranchAddress("Youtcard", Youtcard);
256     fhBookTree->SetBranchAddress("Zoutcard", Zoutcard);
257     fhBookTree->SetBranchAddress("Erelcard", Erelcard);
258     fhBookTree->SetBranchAddress("Timecard", Timecard);
259     fhBookTree->SetBranchAddress("Pathcard", Pathcard);
260     fhBookTree->SetBranchAddress("P0card", P0card);
261 pam-fi 1.52
262 pam-fi 1.81 // fhBookTree->SetBranchStatus("*",0);
263 pam-fi 1.52
264     }
265    
266 pam-fi 1.81 ClassImp( GPamela);
267 pam-fi 1.52
268     /////////////////////////////////////////////////////////////////////////////
269     /////////////////////////////////////////////////////////////////////////////
270     /////////////////////////////////////////////////////////////////////////////
271     /////////////////////////////////////////////////////////////////////////////
272 pam-fi 1.1 //--------------------------------------
273     //
274     //
275     //--------------------------------------
276     /**
277 pam-fi 1.81 * Default constructor
278 pam-fi 1.1 */
279 pam-fi 1.81 PamTrack::PamTrack() {
280     trk_track = 0;
281 pam-ts 1.95 trk_ext_track = 0;
282 pam-fi 1.81 calo_track = 0;
283     tof_track = 0;
284     orb_track = 0;
285     candeleteobj = 0;
286     pscore = 0;
287     iscore = 0;
288     }
289     ;
290 pam-fi 1.1 //--------------------------------------
291     //
292     //
293     //--------------------------------------
294     /**
295 pam-fi 1.81 * Constructor
296 pam-fi 1.1 */
297 pam-fi 1.81 PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r) {
298    
299 pam-ts 1.95 trk_ext_track = 0;
300 pam-fi 1.81 trk_track = 0;
301     calo_track = 0;
302     tof_track = 0;
303     orb_track = 0;
304     // if(t)trk_track = new TrkTrack(*t);
305     // if(c)calo_track = new CaloTrkVar(*c);
306     // if(o)tof_track = new ToFTrkVar(*o);
307 pam-ts 1.95 // if (t)
308     // trk_track = t;
309     // if (c)
310     // calo_track = c;
311     // if (o)
312     // tof_track = o;
313     // if (r)
314     // orb_track = r;
315    
316     // candeleteobj = 0;
317    
318    
319     if (t){
320     trk_track = new TrkTrack(*t);
321     trk_ext_track = new ExtTrack(*t);//NB!! ha dimensione 6 invece che 8
322     }
323 pam-fi 1.81 if (c)
324 pam-ts 1.95 calo_track = new CaloTrkVar(*c);
325 pam-fi 1.81 if (o)
326 pam-ts 1.95 tof_track = new ToFTrkVar(*o);
327 pam-fi 1.81 if (r)
328 pam-ts 1.95 orb_track = new OrbitalInfoTrkVar(*r);
329     candeleteobj = 1;
330    
331     }
332     ;
333     /**
334     * Constructor
335     */
336     PamTrack::PamTrack(ExtTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r) {
337    
338     trk_ext_track = 0;
339     trk_track = 0;
340     calo_track = 0;
341     tof_track = 0;
342     orb_track = 0;
343     // if(t)trk_track = new TrkTrack(*t);
344     // if(c)calo_track = new CaloTrkVar(*c);
345     // if(o)tof_track = new ToFTrkVar(*o);
346     // if (t)
347     // trk_track = t;
348     // if (c)
349     // calo_track = c;
350     // if (o)
351     // tof_track = o;
352     // if (r)
353     // orb_track = r;
354    
355     // candeleteobj = 0;
356    
357 pam-fi 1.81
358 pam-ts 1.95 if (t){
359     //// trk_track = new TrkTrack(*t);//in this case TrkTrack object remains null
360     trk_ext_track = new ExtTrack(*t);
361     }
362     if (c)
363     calo_track = new CaloTrkVar(*c);
364     if (o)
365     tof_track = new ToFTrkVar(*o);
366     if (r)
367     orb_track = new OrbitalInfoTrkVar(*r);
368     candeleteobj = 1;
369     pscore = 0;
370     iscore = 0;
371 pam-fi 1.81
372     }
373     ;
374     PamTrack::PamTrack(const PamTrack& track) {
375    
376     TrkTrack *t = track.trk_track;
377 pam-fi 1.97 ExtTrack *e = track.trk_ext_track;
378 pam-fi 1.81 CaloTrkVar *c = track.calo_track;
379     ToFTrkVar *o = track.tof_track;
380     OrbitalInfoTrkVar *r = track.orb_track;
381    
382 pam-fi 1.97 trk_ext_track = 0;
383     trk_track = 0;
384     calo_track = 0;
385     tof_track = 0;
386     orb_track = 0;
387     if(e)
388     trk_ext_track = new ExtTrack(*e);
389 pam-fi 1.81 if (t)
390     trk_track = new TrkTrack(*t);
391     if (c)
392     calo_track = new CaloTrkVar(*c);
393     if (o)
394     tof_track = new ToFTrkVar(*o);
395     if (r)
396     orb_track = new OrbitalInfoTrkVar(*r);
397 pam-fi 1.97
398 pam-fi 1.81 candeleteobj = 1;
399 pam-ts 1.95 pscore = 0;
400     iscore = 0;
401 pam-fi 1.81
402     }
403 pam-fi 1.97 void PamTrack::Clear(Option_t *option) {
404 pam-fi 1.13
405 pam-fi 1.97 // cout << "PamTrack::Clear( "<<option<<" ) "<<candeleteobj<<endl;
406 pam-fi 1.81 if (candeleteobj) {
407 pam-ts 1.95
408     if (trk_ext_track)
409 pam-fi 1.97 trk_ext_track->ExtTrack::Clear(option);
410 pam-fi 1.81 if (trk_track)
411     trk_track->TrkTrack::Clear();
412     if (calo_track)
413     calo_track->CaloTrkVar::Clear();//???
414     if (tof_track)
415     tof_track->ToFTrkVar::Clear();//???
416     if (orb_track)
417     orb_track->OrbitalInfoTrkVar::Clear();//???
418     }
419     else {
420 pam-ts 1.95 trk_ext_track = 0;
421 pam-fi 1.81 trk_track = 0;
422 pam-fi 1.13 calo_track = 0;
423 pam-fi 1.81 tof_track = 0;
424     orb_track = 0;
425     }
426     pscore = 0;
427     iscore = 0;
428 pam-fi 1.13
429 pam-fi 1.81 }
430     void PamTrack::Delete() {
431     // cout << "PamTrack::Delete() "<<candeleteobj<<endl;
432     if (candeleteobj) {
433 pam-ts 1.95 if (trk_ext_track) {
434 pam-fi 1.97 trk_ext_track->ExtTrack::Clear("C");
435 pam-ts 1.95 delete trk_ext_track;
436     }
437 pam-fi 1.81 if (trk_track) {
438     trk_track->TrkTrack::Clear();
439     delete trk_track;
440     }
441     if (calo_track) {
442     calo_track->CaloTrkVar::Clear();//???
443     delete calo_track;
444     }
445     if (tof_track) {
446     tof_track->ToFTrkVar::Clear();//???
447     delete tof_track;
448     }
449     if (orb_track) {
450     orb_track->OrbitalInfoTrkVar::Clear();//???
451     delete orb_track;
452 pam-fi 1.13 }
453 pam-fi 1.81 }
454     else {
455     Clear();
456     }
457 pam-fi 1.13 }
458 pam-ts 1.95
459    
460    
461    
462 pam-fi 1.1 //--------------------------------------
463     //
464     //
465     //--------------------------------------
466     /**
467 pam-fi 1.81 * Default Constructor
468 pam-fi 1.1 */
469 pam-fi 1.81 PamLevel2::PamLevel2() {
470     Initialize();
471     }
472 mocchiut 1.90
473 mocchiut 1.35
474     /**
475 pam-fi 1.52 * Constructor
476     * @param ddir Name of directory where level2 files are stored.
477     * @param list Name of an ascii file containing the list of file names
478     * @param detlist Options to chose what to load.
479 pam-fi 1.81 * Possible options are:
480 pam-fi 1.52 * +AUTO --> load all trees/branches in the input files
481     * +(-)ALL --> inlcude(exclude) all trees/branches
482     * +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches
483 pam-fi 1.81 * +(-)TRK0 --> include(exclude) tracker level0 tree
484 pam-fi 1.52 * +(-)GP --> include exclude GPAMELA output tree
485     * If no options are specified, the default is assumed. Default is:
486     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
487 mocchiut 1.35 */
488 pam-fi 1.81 PamLevel2::PamLevel2(TString ddir, TString llist, TString detlist) {
489     Initialize();
490     TList* listf = GetListOfLevel2Files(ddir, llist);
491     if (listf)
492     GetPamTree(listf, detlist);
493     if (listf)
494     GetRunTree(listf);
495 pam-ts 1.95 SetMaxShift(-1);
496 pam-fi 1.81 }
497 mocchiut 1.90
498 pam-fi 1.81
499     PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) {
500     Initialize();
501     GetPamTree(llist, detlist);
502     GetRunTree(llist);
503 pam-ts 1.95 SetMaxShift(-1);
504 pam-fi 1.81 }
505 mocchiut 1.90
506 mocchiut 1.35 /**
507 pam-fi 1.81 * Constructor
508 pam-fi 1.52 * @param ddir Name of directory where level2 files are stored.
509     * @param list Name of an ascii file containing the list of file names
510     * Default trees/branches are loaded. Default is:
511     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
512 mocchiut 1.35 */
513 pam-fi 1.81 PamLevel2::PamLevel2(TString ddir, TString llist) {
514     Initialize();
515 pam-ts 1.95 TList* listf = GetListOfLevel2Files(ddir, llist);
516     cout << "GetPamTree: "<<endl;
517 pam-fi 1.81 GetPamTree(listf, "");
518 pam-ts 1.95 cout << "GetRunTree: "<<endl;
519 pam-fi 1.81 GetRunTree(listf);
520 pam-ts 1.95 SetMaxShift(-1);
521 pam-fi 1.81 }
522 mocchiut 1.90
523 pam-fi 1.81
524     void PamLevel2::Initialize() {
525 mocchiut 1.35
526 pam-fi 1.81 h0_obj = 0;
527     trk0_obj = 0;
528     calo0_obj = 0;
529    
530     trk2_obj = 0;
531     trk1_obj = 0;
532     trkh_obj = 0;
533     calo1_obj = 0;
534     calo2_obj = 0;
535 pam-ts 1.95 tof2_obj = 0;
536 pam-fi 1.81 trig_obj = 0;
537     s4_obj = 0;
538     nd_obj = 0;
539     ac_obj = 0;
540 pam-ts 1.95 orb2_obj = 0;
541 pam-fi 1.81 gp_obj = 0;
542    
543 pam-ts 1.95 extAlgFlag=0;
544    
545     trk_ext_obj = 0;
546     trk_ext_nuc_obj = 0;
547     trk_nuc_obj = 0;
548    
549     calo_ext_obj = 0;
550     calo_ext_nuc_obj = 0;
551     calo_nuc_obj = 0;
552    
553     tof_ext_obj = 0;
554     tof_ext_nuc_obj = 0;
555     tof_nuc_obj = 0;
556    
557     orb_ext_obj = 0;
558     orb_ext_nuc_obj = 0;
559     orb_nuc_obj = 0;
560    
561     trk2_nuc_obj = 0;
562     calo2_nuc_obj = 0;
563     tof2_nuc_obj = 0;
564     orb2_nuc_obj = 0;
565    
566    
567 pam-fi 1.81 run_obj = 0;//new GL_RUN();
568     soft_obj = 0;// Emiliano
569     irun = -1LL;
570     irunt = -1LL;
571 mocchiut 1.89 totrunentry = 0LL;
572     totrunentrymax = 0LL;
573     totrunentrymin = 0LL;
574 pam-fi 1.81 runfirstentry = 0LL;
575     runlastentry = 0LL;
576     gltsync = 0; // Emiliano
577 mocchiut 1.85 fUpdateRunInfo = true; // Emiliano
578 mocchiut 1.94 fUseDBinRunInfo = true; // Emiliano
579 mocchiut 1.90 isSync = false; // by default assume that the level2 file(s) is(are) not sinchronized between L0/DB and L2, that is we miss some packets in L2 due to nested/DV-skipped events
580     il0entry = 0LL;
581 mocchiut 1.91 // hasL0EE = true;
582 pam-fi 1.81
583     l0_file = NULL;
584     l0_tree = NULL;
585     iroot = -1;
586     dbc = 0;
587    
588     prevshift = 0;
589 mocchiut 1.90 yprevshift = 0;
590     maxshift = 10; //EMILIANO now overridden by SetMaxShift(-1) called by constructors
591 pam-fi 1.81
592     run_tree = NULL;
593     run_tree_clone = NULL;
594     sel_tree = NULL;
595     sel_tree_clone = NULL;
596    
597     irunentry = -1LL;
598     pam_tree = NULL;
599     for (Int_t i = 0; i < NCLONES; i++)
600     pam_tree_clone[i] = NULL;
601    
602     totdltime[0] = 0LL;
603     totdltime[1] = 0LL;
604     totdltime[2] = 0LL;
605    
606     host = "mysql://localhost/pamelaprod";
607     user = "anonymous";
608     psw = "";
609     const char *pamdbhost = gSystem->Getenv("PAM_DBHOST");
610     const char *pamdbuser = gSystem->Getenv("PAM_DBUSER");
611     const char *pamdbpsw = gSystem->Getenv("PAM_DBPSW");
612     if (!pamdbhost)
613     pamdbhost = "";
614     if (!pamdbuser)
615     pamdbuser = "";
616     if (!pamdbpsw)
617     pamdbpsw = "";
618     if (strcmp(pamdbhost, ""))
619     host = pamdbhost;
620     if (strcmp(pamdbuser, ""))
621     user = pamdbuser;
622     if (strcmp(pamdbpsw, ""))
623     psw = pamdbpsw;
624    
625     // sorted_tracks = 0;//new TRefArray();
626    
627     CAL0 = false;
628     CAL1 = true;
629     CAL2 = true;
630     TRK2 = true;
631     TRK1 = false;
632     TRK0 = false;
633     TRKh = false;
634     TRG = true;
635     TOF = true;
636     TOF0 = false;
637     S4 = true;
638     ND = true;
639     AC = true;
640     ORB = true;
641     GP = false;
642    
643 pam-ts 1.95 EXT = false;
644     NUC = false;
645 pam-ts 1.96 trkAlg = "STD";//default tracking algorythm
646 pam-ts 1.95
647 pam-fi 1.81 RUN = true;
648    
649     SELLI = -1;
650    
651     ISGP = false;
652    
653     DBG = false;
654    
655     tsorted = 0;
656     timage = 0;
657 pam-ts 1.95 text = 0 ;
658    
659     tsorted_nuc = 0;
660     timage_nuc = 0;
661     text_nuc = 0 ;
662 pam-fi 1.81
663     howtosort = "+CAL+TOF";
664     //howtosort = "+TOF";
665     sortthr = 100.;
666 mocchiut 1.35
667 pam-fi 1.81 issorted = false;
668     lastsorted = -1;
669 pam-ts 1.95 issorted_new = false;
670     lastsorted_new = -1;
671 mocchiut 1.30
672 pam-fi 1.81 }
673     ;
674     /**
675     * Delete the event (act as Dtor)
676     */
677     void PamLevel2::Delete() {
678 pam-fi 1.20
679 pam-fi 1.81 if (run_obj)
680     delete run_obj;
681     if (soft_obj)
682     delete soft_obj; //Emiliano
683    
684     // cout << "void PamLevel2::Clear()"<<endl;
685     if (h0_obj)
686     delete h0_obj;
687     if (trk0_obj)
688     delete trk0_obj;
689     if (calo0_obj)
690     delete calo0_obj;
691     if (trk1_obj)
692     delete trk1_obj;
693     if (trk2_obj)
694     delete trk2_obj;
695     if (trkh_obj)
696     delete trkh_obj;
697     if (calo1_obj)
698     delete calo1_obj;
699     if (calo2_obj)
700     delete calo2_obj;
701 pam-ts 1.95 if (tof2_obj)
702     delete tof2_obj;
703 pam-fi 1.81 if (trig_obj)
704     delete trig_obj;
705     if (s4_obj)
706     delete s4_obj;
707     if (nd_obj)
708     delete nd_obj;
709     if (ac_obj)
710     delete ac_obj;
711 pam-ts 1.95 if (orb2_obj)
712     delete orb2_obj;
713 pam-fi 1.81 if (gp_obj)
714     delete gp_obj;
715 pam-fi 1.9
716 pam-ts 1.95 if(trk_nuc_obj)trk_nuc_obj->Delete();
717     if(trk_ext_obj)trk_ext_obj->Delete();
718     if(trk_ext_nuc_obj)trk_ext_nuc_obj->Delete();
719    
720     if(calo_nuc_obj)calo_nuc_obj->Delete();
721     if(calo_ext_obj)calo_ext_obj->Delete();
722     if(calo_ext_nuc_obj)calo_ext_nuc_obj->Delete();
723    
724     if(tof_nuc_obj)tof_nuc_obj->Delete();
725     if(tof_ext_obj)tof_ext_obj->Delete();
726     if(tof_ext_nuc_obj)tof_ext_nuc_obj->Delete();
727    
728     if(orb_nuc_obj)orb_nuc_obj->Delete();
729     if(orb_ext_obj)orb_ext_obj->Delete();
730     if(orb_ext_nuc_obj)orb_ext_nuc_obj->Delete();
731    
732    
733     if(trk2_nuc_obj)trk2_nuc_obj->Delete();;
734     if( calo2_nuc_obj)calo2_nuc_obj->Delete();;
735     if(tof2_nuc_obj)tof2_nuc_obj->Delete();;
736     if(orb2_nuc_obj)orb2_nuc_obj->Delete();;
737    
738    
739    
740 pam-fi 1.81 if (tsorted) {
741     tsorted->Delete();
742     delete tsorted;
743     }
744     if (timage) {
745     timage->Delete();
746     delete timage;
747     }
748 pam-ts 1.95 if (text) {
749     text->Delete();
750     delete text;
751     }
752     if (tsorted_nuc) {
753     tsorted_nuc->Delete();
754     delete tsorted_nuc;
755     }
756     if (timage_nuc) {
757     timage_nuc->Delete();
758     delete timage_nuc;
759     }
760     if (text_nuc) {
761     text_nuc->Delete();
762     delete text_nuc;
763     }
764    
765    
766 pam-fi 1.52
767 pam-fi 1.81 if (dbc) {
768     dbc->Close();
769     delete dbc;
770 mocchiut 1.82 dbc=0;
771 pam-fi 1.81 }
772    
773     if (gltsync)
774     delete gltsync;
775    
776     if (l0_file)
777     l0_file->Close();
778     // if(pam_tree)pam_tree->Delete();;
779 pam-fi 1.20
780 pam-fi 1.81 if (pam_tree) {
781     //
782     // 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...
783     //
784     TList *temp = pam_tree->GetListOfFriends();
785     TList *contents = new TList; // create chain friend list
786     contents->SetOwner();
787     TIter next(temp);
788     TChain *questo = 0;
789     while ((questo = (TChain*) next())) {
790     TString name = questo->GetName();
791     contents->Add((TChain*) gROOT->FindObject(name.Data()));// add object to the list
792     };
793     //
794     // deleting the main chain
795     //
796     pam_tree->Delete();
797     //
798     // deleting the friends...
799     //
800     TIter next2(contents);
801     TChain *questa = 0;
802 mocchiut 1.83 while ( (questa = (TChain*)next2()) ) {
803 pam-fi 1.81 TString name = questa->GetName();
804     questa->Delete();
805     questa = NULL;
806     };
807     //
808     };
809     pam_tree = NULL;
810 pam-fi 1.8
811 pam-fi 1.81 if (run_tree)
812     run_tree->Delete();;
813     if (sel_tree)
814     sel_tree->Delete();;
815 pam-fi 1.88
816     // The following lines are commented out since they may generate a double delete error
817     // if the file containing the clone trees is closed. This is because the file owns the
818     // clone trees which are written into it, so it will delete them when it is closed; if
819     // also PamLevel2 will try to delete these trees, a double delete error will be generated
820     // when exiting from analysis program. (Nicola 28/11/2011)
821    
822     /*for (Int_t i = 0; i < NCLONES; i++)
823 pam-fi 1.81 if (pam_tree_clone[i])
824     pam_tree_clone[i]->Delete();;
825     if (run_tree_clone)
826     run_tree_clone->Delete();;
827     if (sel_tree_clone)
828 pam-fi 1.88 sel_tree_clone->Delete();;*/
829 pam-fi 1.43
830 pam-fi 1.81 if (irunoffset)
831     delete[] irunoffset;
832 pam-fi 1.59
833 pam-ts 1.95
834     Initialize();
835    
836 pam-fi 1.81 }
837     ;
838 pam-fi 1.13
839 pam-fi 1.2 /**
840 pam-fi 1.81 * Clear the event (NB! does not deallocate objects)
841 pam-fi 1.2 */
842 pam-fi 1.81 void PamLevel2::Clear() {
843    
844     // cout << "void PamLevel2::Clear()"<<endl;
845 mocchiut 1.35
846 pam-fi 1.81 //
847     // 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
848     // want to load them for each event even if they are the same...
849     //
850     // if(run_obj)delete run_obj;
851     // if(run_obj) run_obj->Clear(); // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
852     // if(soft_obj) soft_obj->Clear();
853    
854     if (h0_obj)
855     h0_obj->Clear();
856     // if(trk0_obj) trk0_obj->Clear();
857     if (trk1_obj)
858     trk1_obj->Clear();
859     if (trk2_obj)
860     trk2_obj->Clear();
861     if (trkh_obj)
862     trkh_obj->Clear();
863     if (calo0_obj)
864     calo0_obj->Clear();
865     if (calo1_obj)
866     calo1_obj->Clear();
867     if (calo2_obj)
868     calo2_obj->Clear();
869 pam-ts 1.95 if (tof2_obj)
870     tof2_obj->Clear();
871 pam-fi 1.81 if (trig_obj)
872     trig_obj->Clear();
873     if (s4_obj)
874     s4_obj->Clear();
875     if (nd_obj)
876     nd_obj->Clear();
877     if (ac_obj)
878     ac_obj->Clear();
879 pam-ts 1.95 if (orb2_obj)
880     orb2_obj->Clear();
881 pam-fi 1.81 if (gp_obj)
882     gp_obj->Clear();
883 pam-fi 1.20
884 pam-fi 1.81 // if(sorted_tracks)sorted_tracks->Clear();
885     // sorted_tracks.Clear();
886 pam-fi 1.13
887 pam-ts 1.95 if(trk_nuc_obj)trk_nuc_obj->Clear();
888     if(trk_ext_obj)trk_ext_obj->Clear();
889     if(trk_ext_nuc_obj)trk_ext_nuc_obj->Clear();
890    
891     if(calo_nuc_obj)calo_nuc_obj->Clear();
892     if(calo_ext_obj)calo_ext_obj->Clear();
893     if(calo_ext_nuc_obj)calo_ext_nuc_obj->Clear();
894    
895     if(tof_nuc_obj)tof_nuc_obj->Clear();
896     if(tof_ext_obj)tof_ext_obj->Clear();
897     if(tof_ext_nuc_obj)tof_ext_nuc_obj->Clear();
898    
899     if(orb_nuc_obj)orb_nuc_obj->Clear();
900     if(orb_ext_obj)orb_ext_obj->Clear();
901     if(orb_ext_nuc_obj)orb_ext_nuc_obj->Clear();
902    
903     if(trk2_nuc_obj)trk2_nuc_obj->Clear();;
904     if( calo2_nuc_obj)calo2_nuc_obj->Clear();;
905     if(tof2_nuc_obj)tof2_nuc_obj->Clear();;
906     if(orb2_nuc_obj)orb2_nuc_obj->Clear();;
907    
908     if (tsorted)tsorted->Delete();
909     if (timage)timage->Delete();
910     if (text) text->Delete();
911    
912     if (tsorted_nuc)tsorted_nuc->Delete();
913     if (timage_nuc)timage_nuc->Delete();
914     if (text_nuc) text_nuc->Delete();
915 pam-fi 1.81 }
916     ;
917 mocchiut 1.35
918 pam-fi 1.81 void PamLevel2::Reset() {
919     //
920     // First of all clear everything
921     //
922     Clear();
923     //
924     // close and reset chains and pointers
925     //
926     if (pam_tree) {
927 mocchiut 1.35 //
928 pam-fi 1.81 // 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...
929 pam-fi 1.55 //
930 pam-fi 1.81 TList *temp = pam_tree->GetListOfFriends();
931     TList *contents = new TList; // create chain friend list
932     contents->SetOwner();
933     TIter next(temp);
934     TChain *questo = 0;
935     while ((questo = (TChain*) next())) {
936     TString name = questo->GetName();
937     contents->Add((TChain*) gROOT->FindObject(name.Data()));// add object to the list
938 pam-fi 1.55 };
939     //
940 pam-fi 1.81 // deleting the main chain
941 pam-fi 1.55 //
942 pam-fi 1.81 pam_tree->Delete();
943 pam-fi 1.55 //
944 pam-fi 1.81 // deleting the friends...
945 pam-fi 1.55 //
946 pam-fi 1.81 TIter next2(contents);
947     TChain *questa = 0;
948 mocchiut 1.83 while ( (questa = (TChain*) next2()) ) {
949 pam-fi 1.81 TString name = questa->GetName();
950     questa->Delete();
951     questa = NULL;
952     };
953 pam-fi 1.55 //
954 pam-fi 1.81 };
955     pam_tree = NULL;
956     //
957     if (run_tree)
958     run_tree->Delete();;
959     run_tree = NULL;
960     if (sel_tree)
961     sel_tree->Delete();;
962     sel_tree = NULL;
963     //
964     // Close file
965     //
966     if (l0_file)
967     l0_file->Close("R");
968     l0_file = NULL;
969     //
970     h0_obj = 0;
971     trk0_obj = 0;
972     calo0_obj = 0;
973     //
974     trk2_obj = 0;
975     trk1_obj = 0;
976     trkh_obj = 0;
977     calo1_obj = 0;
978     calo2_obj = 0;
979 pam-ts 1.95 tof2_obj = 0;
980 pam-fi 1.81 trig_obj = 0;
981     s4_obj = 0;
982     nd_obj = 0;
983     ac_obj = 0;
984 pam-ts 1.95 orb2_obj = 0;
985 pam-fi 1.81 gp_obj = 0;
986 pam-ts 1.95
987     trk_ext_obj = 0;
988     trk_ext_nuc_obj = 0;
989     trk_nuc_obj = 0;
990    
991     calo_ext_obj = 0;
992     calo_ext_nuc_obj = 0;
993     calo_nuc_obj = 0;
994    
995     tof_ext_obj = 0;
996     tof_ext_nuc_obj = 0;
997     tof_nuc_obj = 0;
998    
999     orb_ext_obj = 0;
1000     orb_ext_nuc_obj = 0;
1001     orb_nuc_obj = 0;
1002    
1003     trk2_nuc_obj = 0;
1004     calo2_nuc_obj = 0;
1005     tof2_nuc_obj = 0;
1006     orb2_nuc_obj = 0;
1007    
1008     trk2_nuc_obj = 0;
1009     calo2_nuc_obj = 0;
1010     tof2_nuc_obj = 0;
1011     orb2_nuc_obj = 0;
1012 pam-fi 1.81 //
1013     // Reset run pointers
1014     //
1015     run_obj = 0;//new GL_RUN();
1016     soft_obj = 0;// Emiliano
1017     irun = -1;
1018     irunt = -1;
1019 mocchiut 1.89 totrunentry = 0LL;
1020     totrunentrymax = 0LL;
1021     totrunentrymin = 0LL;
1022 pam-fi 1.81 runfirstentry = 0ULL;
1023     runlastentry = 0ULL;
1024 mocchiut 1.89 prevabstime = 0ULL;
1025     prevpktnum = 0;
1026     abstime = 0ULL;
1027     pktnum = 0;
1028     isFragment = false;
1029 pam-fi 1.81 //
1030     totdltime[0] = 0LL;
1031     totdltime[1] = 0LL;
1032     totdltime[2] = 0LL;
1033     //
1034     }
1035     ;
1036 pam-fi 1.2
1037 pam-fi 1.81 Bool_t PamLevel2::IsGood(Bool_t strict) {
1038     Bool_t goodev = true;
1039 mocchiut 1.69 //
1040 pam-fi 1.81 if (calo2_obj && !calo2_obj->IsGood(strict))
1041     goodev = false;
1042 mocchiut 1.69 //
1043 pam-fi 1.81 if (strict) {
1044     if (trk2_obj && trk2_obj->UnpackError() != 0)
1045     goodev = false;
1046 pam-ts 1.95 if (tof2_obj && tof2_obj->unpackError != 0)
1047 pam-fi 1.81 goodev = false;
1048     if (trig_obj && trig_obj->unpackError != 0)
1049     goodev = false;
1050     if (s4_obj && s4_obj->unpackError != 0)
1051     goodev = false;
1052     if (nd_obj && nd_obj->unpackError != 0)
1053     goodev = false;
1054     if (ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0] >> 2) & 1) || ((ac_obj->status[1] >> 2) & 1)))
1055     goodev = false;
1056 pam-ts 1.95 // if(orb2_obj)
1057 pam-fi 1.81 }
1058     else {
1059     if (nd_obj && nd_obj->unpackError != 0)
1060     goodev = false;
1061     if (ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0] >> 2) & 1) || ((ac_obj->status[1] >> 2) & 1)))
1062     goodev = false;
1063 mocchiut 1.69 };
1064 pam-fi 1.81 return (goodev);
1065     }
1066     ;
1067 pam-fi 1.2
1068 mocchiut 1.86 void PamLevel2::SkipRunInfoUpdate(){
1069     printf("\n\n ******** WARNING ******** \n Skip DB connections, DO NOT USE PamLevel2::GetRunInfo() method! \n\n");
1070     fUpdateRunInfo = false;
1071     this->SetSELLI(2);
1072     printf(" ===============> W A R N I N G <================ \n");
1073     printf(" in case PamLevel2::CreateCloneTrees() will be called \n");
1074     printf(" it will be reverted to PadmeAmidala level2 structure , i.e. NO SELECTIONLIST WILL BE CREATED IN THE NEW LEVEL2 FILE! \n\n");
1075     if ( run_tree_clone ){
1076     printf(" ===============> W A R N I N G <================ \n");
1077     printf(" PamLevel2::SkipRunIndoUpdate or PamLevel2::NoDBconnections() has been called together with PamLevel2::CreateCloneTrees() \n");
1078     printf(" TO AVOID CRASHES call PamLevel2::CreateCloneTrees() after PamLevel2::SkipRunIndoUpdate or PamLevel2::NoDBconnections() \n");
1079     };
1080     }
1081    
1082 mocchiut 1.90 void PamLevel2::SetMaxShift(Int_t sh){
1083     if ( sh >= 0 ){
1084     printf("PamLevel2::SetMaxShift(Int_t) --WARNING-- the default is optimized by checking the level2 file\n it is strongly suggested to let PamLevel2 choose the max shift!\n");
1085     maxshift = sh;
1086     } else {
1087 pam-ts 1.95 ULong64_t nev = GetEntries();
1088 mocchiut 1.90 ULong64_t runnev = 0ULL;
1089     for (Int_t r=0; r< run_tree->GetEntries();r++){
1090     run_tree->GetEntry(r);//update runinfo
1091     runnev += GetRunInfo()->NEVENTS;
1092     }
1093     maxshift = (Int_t)(runnev-nev) + 10; // +10 just to be conservative
1094     if ( (runnev-nev) == 0 ) isSync = true;
1095     if (DBG) printf("PamLevel2::SetMaxShift(Int_t_) - sh negative %i - nev is %lld runnnev is %lld so maxshift set to %i \n",sh,nev,runnev,maxshift);
1096     // printf("PamLevel2::SetMaxShift(Int_t_) - sh negative %i - nev is %lld runnnev is %lld so maxshift set to %i \n",sh,nev,runnev,maxshift); // TOGLITOGLI
1097     }
1098     }
1099    
1100 pam-fi 1.1 //--------------------------------------
1101     //
1102     //
1103     //--------------------------------------
1104 pam-fi 1.81 void *PamLevel2::GetPointerTo(const char* c) {
1105 pam-fi 1.9
1106 pam-fi 1.81 TString objname = c;
1107 pam-fi 1.13
1108 pam-fi 1.81 if (!objname.CompareTo("TrkLevel1")) {
1109     if (!trk1_obj) {
1110     trk1_obj = new TrkLevel1();
1111     trk1_obj->Set();
1112     }
1113     return &trk1_obj;
1114     };
1115     if (!objname.CompareTo("TrkLevel2")) {
1116     if (!trk2_obj) {
1117     trk2_obj = new TrkLevel2();
1118     trk2_obj->Set();
1119     }
1120     return &trk2_obj;
1121     };
1122     if (!objname.CompareTo("TrkHough")) {
1123     if (!trkh_obj) {
1124     trkh_obj = new TrkHough();
1125     trkh_obj->Set();
1126     }
1127     return &trkh_obj;
1128     };
1129     if (!objname.CompareTo("CaloLevel1")) {
1130     if (!calo1_obj)
1131     calo1_obj = new CaloLevel1();
1132     return &calo1_obj;
1133     };
1134     if (!objname.CompareTo("CaloLevel2")) {
1135     if (!calo2_obj) {
1136     calo2_obj = new CaloLevel2();
1137     calo2_obj->Set();
1138 pam-fi 1.13 };
1139 pam-fi 1.81 return &calo2_obj;
1140     };
1141     if (!objname.CompareTo("ToFLevel2")) {
1142 pam-ts 1.95 if (!tof2_obj) {
1143     tof2_obj = new ToFLevel2();
1144     tof2_obj->Set();
1145 pam-fi 1.81 }
1146 pam-ts 1.95 return &tof2_obj;
1147 pam-fi 1.81 };
1148     if (!objname.CompareTo("TrigLevel2")) {
1149     if (!trig_obj)
1150     trig_obj = new TrigLevel2();
1151     return &trig_obj;
1152     };
1153     if (!objname.CompareTo("S4Level2")) {
1154     if (!s4_obj)
1155     s4_obj = new S4Level2();
1156     return &s4_obj;
1157     };
1158     if (!objname.CompareTo("NDLevel2")) {
1159     if (!nd_obj)
1160     nd_obj = new NDLevel2();
1161     return &nd_obj;
1162     };
1163     if (!objname.CompareTo("AcLevel2")) {
1164     if (!ac_obj)
1165     ac_obj = new AcLevel2();
1166     return &ac_obj;
1167     };
1168     if (!objname.CompareTo("OrbitalInfo")) {
1169 pam-ts 1.95 if (!orb2_obj) {
1170     orb2_obj = new OrbitalInfo();
1171     orb2_obj->Set();
1172 pam-fi 1.81 }
1173 pam-ts 1.95 return &orb2_obj;
1174 pam-fi 1.81 };
1175     // if(!objname.CompareTo("OrbitalInfo")){
1176 pam-ts 1.95 // if(!orb2_obj) orb2_obj = new OrbitalInfo();
1177     // return &orb2_obj;
1178 pam-fi 1.81 // };
1179     if (!objname.CompareTo("GPamela")) {
1180     if (!gp_obj)
1181     gp_obj = new GPamela();
1182     return &gp_obj;
1183     };
1184    
1185     if (!objname.CompareTo("RunInfo"))
1186     return &run_obj;
1187 mocchiut 1.15
1188 pam-fi 1.81 if (!objname.CompareTo("SoftInfo"))
1189     return &soft_obj; // Emiliano
1190 mocchiut 1.15
1191 pam-fi 1.81 return NULL;
1192     }
1193     ;
1194 pam-fi 1.9 //--------------------------------------
1195     //
1196     //
1197     //--------------------------------------
1198 pam-fi 1.1 /**
1199 pam-fi 1.81 * Retrieves the calorimeter track matching the seqno-th tracker stored track.
1200 pam-fi 1.3 * (If seqno = -1 retrieves the self-trigger calorimeter track)
1201     */
1202 pam-fi 1.81 CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno) {
1203    
1204     if (!calo2_obj)
1205     return 0;
1206    
1207     if (calo2_obj->CaloLevel2::ntrk() == 0) {
1208     cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno
1209     << " but no Calorimeter tracks are stored" << endl;
1210     return NULL;
1211     };
1212    
1213     CaloTrkVar *c = 0;
1214     Int_t it_calo = 0;
1215    
1216     do {
1217     c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
1218     it_calo++;
1219     } while (c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());
1220    
1221     if (!c || seqno != c->trkseqno) {
1222     c = 0;
1223     if (seqno != -1)
1224     cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno
1225     << " does not match Calorimeter stored tracks" << endl;
1226     };
1227     return c;
1228    
1229     }
1230     ;
1231 pam-fi 1.3 //--------------------------------------
1232 pam-fi 1.55 //
1233     //
1234 pam-fi 1.3 //--------------------------------------
1235     /**
1236 pam-fi 1.81 * Retrieves the ToF track matching the seqno-th tracker stored track.
1237 pam-fi 1.55 * (If seqno = -1 retrieves the tracker-independent tof track)
1238 pam-fi 1.3 */
1239 pam-fi 1.81 ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {
1240    
1241 pam-ts 1.95 if (!tof2_obj)
1242 pam-fi 1.81 return 0;
1243    
1244 pam-ts 1.95 if (tof2_obj->ToFLevel2::ntrk() == 0) {
1245 pam-fi 1.81 cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo " << seqno << " but no ToF tracks are stored"
1246     << endl;
1247     return NULL;
1248     };
1249    
1250     ToFTrkVar *c = 0;
1251     Int_t it_tof = 0;
1252    
1253     do {
1254 pam-ts 1.95 c = tof2_obj->ToFLevel2::GetToFTrkVar(it_tof);
1255 pam-fi 1.81 it_tof++;
1256 pam-ts 1.95 } while (c && seqno != c->trkseqno && it_tof < tof2_obj->ToFLevel2::ntrk());
1257 pam-fi 1.81
1258     if (!c || seqno != c->trkseqno) {
1259     c = 0;
1260     if (seqno != -1)
1261     cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo " << seqno
1262     << " does not match ToF stored tracks" << endl;
1263     };
1264     return c;
1265    
1266     }
1267     ;
1268 pam-fi 1.3
1269     //--------------------------------------
1270 pam-fi 1.55 //
1271     //
1272 pam-fi 1.3 //--------------------------------------
1273     /**
1274 pam-fi 1.81 * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.
1275 mocchiut 1.64 * (If seqno = -1 retrieves the tracker-independent tof related track)
1276     */
1277 pam-fi 1.81 OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {
1278    
1279 pam-ts 1.95 if (!orb2_obj)
1280 pam-fi 1.81 return 0;
1281    
1282 pam-ts 1.95 if (orb2_obj->OrbitalInfo::ntrk() == 0) {
1283 pam-fi 1.81 // // TRICK BEGIN
1284     // OrbitalInfoTrkVar *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
1285     // Int_t nn = 0;
1286 pam-ts 1.95 // TClonesArray &tor = *orb2_obj->OrbitalInfoTrk;
1287     // for(Int_t nt=0; nt < tof2_obj->ToFLevel2::ntrk(); nt++){
1288 pam-fi 1.81 // //
1289 pam-ts 1.95 // ToFTrkVar *ptt = tof2_obj->ToFLevel2::GetToFTrkVar(nt);
1290 pam-fi 1.81 // if ( ptt->trkseqno != -1 ){
1291     // //
1292     // r->trkseqno = ptt->trkseqno;
1293     // //
1294     // r->Eij = 0;
1295     // //
1296     // r->Sij = 0;
1297     // //
1298     // r->pitch = -1000.;
1299     // //
1300     // r->cutoff = -1000.;
1301     // //
1302     // new(tor[nn]) OrbitalInfoTrkVar(*r);
1303     // nn++;
1304     // //
1305     // r->Clear();
1306     // //
1307     // };
1308     // };
1309     // delete r;
1310     // OrbitalInfoTrkVar *c = 0;
1311 pam-ts 1.95 // c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
1312 pam-fi 1.81 // return c;
1313     // //TRICK END
1314     cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
1315     << " but no OrbitalInfo tracks are stored" << endl;
1316     return NULL;
1317     };
1318    
1319     OrbitalInfoTrkVar *c = 0;
1320     Int_t it_tof = 0;
1321    
1322     do {
1323 pam-ts 1.95 c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
1324 pam-fi 1.81 it_tof++;
1325 pam-ts 1.95 } while (c && seqno != c->trkseqno && it_tof < orb2_obj->OrbitalInfo::ntrk());
1326 pam-fi 1.81
1327     if (!c || seqno != c->trkseqno) {
1328     c = 0;
1329     if (seqno != -1)
1330     cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
1331     << " does not match OrbitalInfo stored tracks" << endl;
1332     };
1333     return c;
1334    
1335     }
1336     ;
1337 mocchiut 1.64
1338     //--------------------------------------
1339     //
1340     //
1341     //--------------------------------------
1342     /**
1343 pam-fi 1.81 * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.
1344 pam-fi 1.3 */
1345 pam-fi 1.81 PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t) {
1346    
1347     cout << "PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** " << endl;
1348     cout << "(if you use it, remember to delete the PamTrack object)" << endl;
1349    
1350     CaloTrkVar *c = 0;
1351     ToFTrkVar *o = 0;
1352     OrbitalInfoTrkVar *r = 0;
1353    
1354     if (CAL2)
1355     c = GetCaloStoredTrack(t->GetSeqNo());
1356     if (TOF)
1357     o = GetToFStoredTrack(t->GetSeqNo());
1358     if (ORB)
1359     r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
1360    
1361     // if(t && c && o)track = new PamTrack(t,c,o);
1362     PamTrack *track = new PamTrack(t, c, o, r);
1363    
1364     return track;
1365    
1366     }
1367     ;
1368 pam-fi 1.3 //--------------------------------------
1369     //
1370     //
1371     //--------------------------------------
1372     /**
1373 pam-fi 1.81 * Retrieves the it-th stored track.
1374     * It override TrkLevel2::GetTrack(int it).
1375 pam-fi 1.1 * @param itrk Track number, ranging from 0 to GetNTracks().
1376     */
1377    
1378 pam-fi 1.81 PamTrack* PamLevel2::GetStoredTrack(Int_t itrk) {
1379    
1380     cout << "PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** " << endl;
1381     cout
1382     << "for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack) OrbitalInfo::GetOrbitalInfoTrkVar(Int_t notrack)"
1383     << endl;
1384     cout << "(if you use it, remember to delete the PamTrack object)" << endl;
1385     PamTrack *track = 0;
1386    
1387     if (itrk >= 0 && itrk < trk2_obj->TrkLevel2::ntrk()) {
1388    
1389     TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
1390     track = GetPamTrackAlong(t);
1391    
1392     }
1393     else {
1394     cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo " << itrk << " does not exist (GetNTracks() = "
1395     << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
1396     };
1397    
1398     return track;
1399 pam-fi 1.13
1400 pam-fi 1.1 }
1401     //--------------------------------------
1402     //
1403 mocchiut 1.37
1404     /**
1405 pam-fi 1.55 * Sort physical (tracker) tracks. Left here as backward compatibility method.
1406 mocchiut 1.37 **/
1407 pam-fi 1.81 void PamLevel2::SortTracks(TString how) {
1408     printf(
1409     " WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",
1410     how.Data());
1411     howtosort = how;
1412     SortTracks();
1413     }
1414     ;
1415 mocchiut 1.37
1416 pam-fi 1.1 //
1417     //--------------------------------------
1418     /**
1419 pam-fi 1.55 * Sort physical (tracker) tracks.
1420 pam-fi 1.3 * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
1421     * Sorting cryteria:
1422 pam-fi 1.81 * TRK: lower chi**2
1423 pam-fi 1.3 * CAL: lower Y spatial residual on the first calorimeter plane
1424     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
1425 pam-fi 1.55 * S1: (ask Emiliano)
1426     * S2: (ask Emiliano)
1427     * S3: (ask Emiliano)
1428 pam-fi 1.81 * GP: more GP hits
1429 pam-fi 1.3 * The default sorting cryterium is "TOF+CAL".
1430 pam-fi 1.81 *
1431 pam-fi 1.3 * 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).
1432 pam-fi 1.1 */
1433 pam-fi 1.81 void PamLevel2::SortTracks() {
1434 pam-fi 1.55
1435 pam-fi 1.81 //Check if the current event has already been sorted
1436     if (issorted && lastsorted == GetReadEntry()) {
1437     return;
1438     }
1439     //Reset the sort flags, just in case something will go wrong...
1440     issorted = false;
1441     lastsorted = -1;
1442    
1443     TString how = howtosort;
1444    
1445     // cout <<" PamLevel2::SortTracks(TString how) "<<endl;
1446     if (!trk2_obj) {
1447     cout << "void PamLevel2::SortTracks(): TrkLevel2 not loaded !!!";
1448     return;
1449     };
1450     //Save current Object count
1451     Int_t ObjectNumber = TProcessID::GetObjectCount();
1452 pam-fi 1.1
1453 pam-fi 1.81 // create TCloneArrays to store tracks and its images
1454     if (!tsorted)
1455     tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1456 pam-fi 1.97 tsorted->Clear("C+C");//Delete();
1457 pam-fi 1.81 TClonesArray &ttsorted = *tsorted;
1458    
1459     if (!timage)
1460     timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1461 pam-fi 1.97 timage->Clear("C+C");//Delete();
1462 pam-fi 1.81 TClonesArray &ttimage = *timage;
1463    
1464 pam-ts 1.95
1465    
1466 pam-fi 1.81 //--------------------------------------------------
1467     // retrieve sorting method
1468     //--------------------------------------------------
1469     Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
1470     Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
1471     Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
1472     Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
1473     Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
1474     Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
1475     Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
1476    
1477     if (use_TOF) {
1478     use_S1 = true;
1479     use_S2 = true;
1480     use_S3 = true;
1481     };
1482     if (!CAL2 && use_CAL)
1483     use_CAL = false;
1484     if (!TOF) {
1485     use_TOF = false;
1486     use_S1 = false;
1487     use_S2 = false;
1488     use_S3 = false;
1489     }
1490     if (!GP) {
1491     use_GP = false;
1492     }
1493    
1494     if (!TRK2) {
1495     cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
1496     return;
1497     };
1498 pam-fi 1.55
1499 pam-fi 1.81 // cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
1500 pam-fi 1.13
1501    
1502 pam-fi 1.81 //--------------------------------------------------
1503     // loop over "physical" tracks sorted by the tracker
1504     //--------------------------------------------------
1505     for (Int_t i = 0; i < trk2_obj->TrkLevel2::GetNTracks(); i++) {
1506    
1507     TrkTrack *ts = 0;
1508     CaloTrkVar *cs = 0;
1509     ToFTrkVar *os = 0;
1510     OrbitalInfoTrkVar *rs = 0;
1511    
1512     // get tracker tracks
1513     TrkTrack *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1514     CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1515     ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo());
1516     OrbitalInfoTrkVar *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1517    
1518     TrkTrack *ti = 0; //tracker (image)
1519     CaloTrkVar *ci = 0;
1520     ToFTrkVar *oi = 0;
1521     OrbitalInfoTrkVar *ri = 0;
1522     // cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1523     // if track has an image, check image selection
1524    
1525     Int_t tp_score = 0; //main track sorted by the tracker
1526     Int_t ti_score = 0; //image track
1527     Int_t totp_score = 0; //main track sorted by the tracker
1528     Int_t toti_score = 0; //image track
1529    
1530     if (tp->HasImage()) {
1531    
1532     ti = trk2_obj->TrkLevel2::GetTrackImage(i); //tracker (image)
1533     ci = GetCaloStoredTrack(ti->GetSeqNo());
1534     oi = GetToFStoredTrack(ti->GetSeqNo());
1535     ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());
1536    
1537     // cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1538    
1539     //assign starting scores
1540     tp_score = 0; //main track sorted by the tracker
1541     ti_score = 0; //image track
1542    
1543     // -----------------------------------------------------------------------------------------
1544     // *****************************************************************************************
1545     // -----------------------------------------------------------------------------------------
1546     // calorimeter check
1547     // -----------------------------------------------------------------------------------------
1548     if (use_CAL && !calo2_obj) {
1549     cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but CaloLevel2 not loaded !!!";
1550     return;
1551     };
1552     if (use_CAL && !cp && ci) {
1553     ti_score++;
1554     toti_score++;
1555     };
1556     if (use_CAL && cp && !ci) {
1557     tp_score++;
1558     totp_score++;
1559     };
1560     if (use_CAL && cp && ci && true) {
1561    
1562     if (cp->npresh > ci->npresh && true) {
1563     tp_score++;
1564     totp_score++;
1565     };
1566     if (cp->npresh < ci->npresh && true) {
1567     ti_score++;
1568     toti_score++;
1569     };
1570    
1571     // cout << "CALO "<<tp_score<<ti_score<<endl;
1572    
1573     };
1574     // -----------------------------------------------------------------------------------------
1575     // *****************************************************************************************
1576     // -----------------------------------------------------------------------------------------
1577     // TOF check
1578     // -----------------------------------------------------------------------------------------
1579     // check the number of hit pmts along the track
1580     // on S12 S21 and S32, where paddles are parallel to Y axis
1581 pam-ts 1.95 if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2_obj) {
1582 pam-fi 1.81 cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
1583     return;
1584     };
1585     //
1586     if ((use_TOF || use_S1 || use_S2 || use_S3) && !op && oi) {
1587     ti_score++;
1588     toti_score++;
1589     };
1590     if ((use_TOF || use_S1 || use_S2 || use_S3) && op && !oi) {
1591     tp_score++;
1592     totp_score++;
1593     };
1594     if ((use_TOF || use_S1 || use_S2 || use_S3) && op && oi) {
1595     //
1596     Float_t sen = 0.;
1597     for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1598 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1599 pam-fi 1.81 if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1600     sen += (op->dedx).At(ih);
1601     };
1602     for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1603 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1604 pam-fi 1.81 if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1605     sen += (oi->dedx).At(ih);
1606     };
1607     //
1608     if (sen >= sortthr && false) { // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1609     //printf(" IS A NUCLEUS! en = %f \n",sen);
1610     //
1611     // is a nucleus use a different algorithm
1612     //
1613     Int_t nz = 6;
1614     Float_t zin[6]; // << define TOF z-coordinates
1615     for (Int_t ip = 0; ip < nz; ip++)
1616 pam-ts 1.95 zin[ip] = tof2_obj->ToFLevel2::GetZTOF(tof2_obj->ToFLevel2::GetToFPlaneID(ip)); // << read ToF plane z-coordinates
1617 pam-fi 1.81 Trajectory *tr = new Trajectory(nz, zin);
1618     //
1619     Int_t nphit_p = 0;
1620     Int_t nphit_i = 0;
1621     Float_t enhit_p = 0.;
1622     Float_t enhit_i = 0.;
1623     //
1624     for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1625 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1626 pam-fi 1.81 if (pl == 1 || pl == 2 || pl == 5) {
1627     nphit_p++;
1628     enhit_p += (op->dedx).At(ih);
1629     };
1630     };
1631     //
1632     tp->DoTrack2(tr);
1633     //
1634     if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1635     for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1636 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1637 pam-fi 1.81 if (pl == 0) {
1638     nphit_p++;
1639     enhit_p += (op->dedx).At(ih);
1640     };
1641     };
1642     };
1643     if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1644     for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1645 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1646 pam-fi 1.81 if (pl == 3) {
1647     nphit_p++;
1648     enhit_p += (op->dedx).At(ih);
1649     };
1650     };
1651     };
1652     if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1653     for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1654 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1655 pam-fi 1.81 if (pl == 4) {
1656     nphit_p++;
1657     enhit_p += (op->dedx).At(ih);
1658     };
1659     };
1660     };
1661    
1662     for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1663 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1664 pam-fi 1.81 if (pl == 1 || pl == 2 || pl == 5) {
1665     nphit_i++;
1666     enhit_i += (op->dedx).At(ih);
1667     };
1668     };
1669     //
1670     ti->DoTrack2(tr);
1671     //
1672     if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1673     for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1674 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1675 pam-fi 1.81 if (pl == 0) {
1676     nphit_i++;
1677     enhit_i += (op->dedx).At(ih);
1678     };
1679     };
1680     };
1681     if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1682     for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1683 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1684 pam-fi 1.81 if (pl == 3) {
1685     nphit_i++;
1686     enhit_i += (op->dedx).At(ih);
1687     };
1688     };
1689     };
1690     if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1691     for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1692 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1693 pam-fi 1.81 if (pl == 4) {
1694     nphit_i++;
1695     enhit_i += (op->dedx).At(ih);
1696     };
1697     };
1698     };
1699    
1700     if ((use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p + nphit_i) != 0 && true) {
1701    
1702     // 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);
1703     // printf(" score p %i score i %i \n",tp_score,ti_score);
1704     // if( enhit_p > enhit_i ) tp_score++;
1705     // if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1706     if (nphit_p > nphit_i)
1707     tp_score++;
1708     if (nphit_p < nphit_i)
1709     ti_score++;
1710     if (nphit_p == nphit_i) {
1711     if (enhit_p > enhit_i)
1712     tp_score++;
1713     else
1714     ti_score++;
1715     };
1716     // printf(" dopo score p %i score i %i \n",tp_score,ti_score);
1717     };
1718     delete tr;
1719     //
1720     }
1721     else {
1722     // -------------
1723     // NOT a NUCLEUS
1724     // -------------
1725     //printf(" NOT a NUCLEUS! en = %f \n",sen);
1726    
1727     Int_t nphit_p = 0;
1728     Int_t nphit_i = 0;
1729    
1730     /* cout << "track: npmtadc "<< op->npmtadc << endl;
1731     cout << "track: npmttdc "<< op->npmttdc << endl;
1732     cout << "image: npmtadc "<< oi->npmtadc << endl;
1733     cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1734    
1735     // for (Int_t ih=0; ih < op->npmtadc; ih++){
1736 pam-ts 1.95 // Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1737 pam-fi 1.81 // if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1738     // };
1739    
1740     // for (Int_t ih=0; ih < oi->npmtadc; ih++){
1741 pam-ts 1.95 // Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1742 pam-fi 1.81 // if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1743     // };
1744     // --- modified to count tdc signals (more efficient?)
1745     // --- and to implement check on tdcflag
1746     for (Int_t ih = 0; ih < op->npmttdc; ih++) {
1747 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((op->pmttdc).At(ih));
1748 pam-fi 1.81 // if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1749     if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
1750     || (use_S3 && (pl == 4 || pl == 5))) {
1751     if ((op->tdcflag).At(ih) == 0)
1752     nphit_p++;
1753     };
1754     };
1755    
1756     for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
1757 pam-ts 1.95 Int_t pl = tof2_obj->GetPlaneIndex((oi->pmttdc).At(ih));
1758 pam-fi 1.81 // if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
1759     if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
1760     || (use_S3 && (pl == 4 || pl == 5))) {
1761     if ((oi->tdcflag).At(ih) == 0)
1762     nphit_i++;
1763     };
1764     };
1765    
1766     if ((nphit_p + nphit_i) != 0 && true) {
1767    
1768     if (nphit_p != nphit_i) {
1769     totp_score += nphit_p;
1770     toti_score += nphit_i;
1771     tp_score += nphit_p;
1772     ti_score += nphit_i;
1773     };
1774     // if ( nphit_p > nphit_i) tp_score+=nphit_p;
1775     // else if( nphit_p < nphit_i) ti_score+=nphit_i;
1776     // else ;//niente
1777     };
1778     };
1779     // cout << "TOF "<<tp_score<<ti_score<<endl;
1780     };
1781    
1782     // if(tp_score == ti_score) use_TRK = true;
1783    
1784    
1785     // -----------------------------------------------------------------------------------------
1786     // *****************************************************************************************
1787     // -----------------------------------------------------------------------------------------
1788     // tracker check
1789     // -----------------------------------------------------------------------------------------
1790     // chi**2 difference is not always large enough to distinguish among
1791     // the real track and its image.
1792     // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1793     // *** MODIFIED ON AUGUST 2007 ***
1794     if (use_TRK) {
1795     // if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1796     // else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1797    
1798     // CHECK 1 : number of points along X
1799     if (tp->GetNX() >= ti->GetNX()) {
1800     tp_score++;
1801     totp_score++;
1802     };
1803     if (tp->GetNX() <= ti->GetNX()) {
1804     ti_score++;
1805     toti_score++;
1806     };
1807     // CHECK 2 : number of points along Y
1808     if (tp->GetNY() >= ti->GetNY()) {
1809     tp_score++;
1810     totp_score++;
1811     };
1812     if (tp->GetNY() <= ti->GetNY()) {
1813     ti_score++;
1814     toti_score++;
1815     };
1816    
1817     // cout << "TRK "<<tp_score<<ti_score<<endl;
1818     };
1819    
1820     // -----------------------------------------------------------------------------------------
1821     // *****************************************************************************************
1822     // -----------------------------------------------------------------------------------------
1823     // GPamela check
1824     // -----------------------------------------------------------------------------------------
1825    
1826     //---------------------------------------------------
1827     // count the number of GP hits
1828     //---------------------------------------------------
1829     if (use_GP) {
1830     int ngphits_p = 0;
1831     int ngphits_i = 0;
1832     float toll = 0.02; //200 micron
1833     for (int ih = 0; ih < GetGPamela()->Nthspe; ih++) {
1834     int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1835     if (tp && tp->YGood(ip) && fabs(tp->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
1836     ngphits_p++;
1837     if (ti && ti->YGood(ip) && fabs(ti->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
1838     ngphits_i++;
1839     }
1840     if (ngphits_p > ngphits_i && true) {
1841     tp_score++;
1842     totp_score++;
1843     }
1844     if (ngphits_p < ngphits_i && true) {
1845     ti_score++;
1846     toti_score++;
1847     }
1848     }
1849    
1850     // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1851     // the winner is....
1852     // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1853     if (tp_score > ti_score) {
1854    
1855     }
1856     else if (tp_score < ti_score) {
1857    
1858     ts = ti;//its image!!
1859     cs = ci;
1860     os = oi;
1861     rs = ri;
1862     Int_t totis = toti_score;
1863    
1864     ti = tp;//its image!!
1865     ci = cp;
1866     oi = op;
1867     ri = rp;
1868    
1869     tp = ts;//its image!!
1870     cp = cs;
1871     op = os;
1872     rp = rs;
1873    
1874     toti_score = totp_score;
1875     totp_score = totis;
1876    
1877     }
1878     else {
1879    
1880     // cout << "Warning - track image ambiguity not solved" << endl;
1881    
1882     };
1883    
1884     }
1885     else {
1886     totp_score = 1;
1887     toti_score = 0;
1888    
1889     // ts = tp;
1890     // cs = cp;
1891     // os = op;
1892     };
1893    
1894     // cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1895     // sorted_tracks->Add(ts);//save the track in the sorted array
1896     // sorted_tracks.Add(ts);//save the track in the sorted array
1897     // sorted_tracks.Add(tp);//save the track in the sorted array
1898     // cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1899     // cout<<"o "<<tp<<endl;
1900     // cout<<"o "<<cp<<endl;
1901     // cout<<"o "<<op<<endl;
1902    
1903     new (ttsorted[i]) PamTrack(tp, cp, op, rp);
1904     new (ttimage[i]) PamTrack(ti, ci, oi, ri);
1905    
1906     ((PamTrack*) (ttsorted[i]))->SetPScore(totp_score);
1907     ((PamTrack*) (ttsorted[i]))->SetIScore(toti_score);
1908     ((PamTrack*) (ttimage[i]))->SetPScore(totp_score);
1909     ((PamTrack*) (ttimage[i]))->SetIScore(toti_score);
1910     };
1911 pam-fi 1.41
1912 pam-fi 1.81 if (tsorted->GetEntries() != trk2_obj->GetNTracks()) {
1913     cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() " << tsorted->GetEntries()
1914     << " != trk2_obj->GetNTracks() = " << trk2_obj->GetNTracks() << endl;
1915     tsorted->Delete();
1916     tsorted = 0;
1917     timage->Delete();
1918     timage = 0;
1919     }
1920 pam-fi 1.55
1921 pam-fi 1.81 //Restore Object count
1922     //To save space in the table keeping track of all referenced objects
1923     //We reset the object count to what it was at the beginning of the event.
1924     TProcessID::SetObjectCount(ObjectNumber);
1925    
1926     //Everything went fine so the current event can be tagged as sorted
1927     issorted = true;
1928     lastsorted = GetReadEntry();
1929 pam-fi 1.9
1930 pam-fi 1.81 }
1931     ;
1932 pam-ts 1.95 //
1933     //--------------------------------------
1934     /**
1935     * Sort physical (tracker) tracks.
1936     * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
1937     * Sorting cryteria:
1938     * TRK: lower chi**2
1939     * CAL: lower Y spatial residual on the first calorimeter plane
1940     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
1941     * S1: (ask Emiliano)
1942     * S2: (ask Emiliano)
1943     * S3: (ask Emiliano)
1944     * GP: more GP hits
1945     * The default sorting cryterium is "TOF+CAL".
1946     *
1947     * 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).
1948     *
1949     * New version, with handling of extended tracks and nuclei tracks.
1950     */
1951     void PamLevel2::SortTracksNew() {
1952    
1953     //--------------------------------------------------
1954     //Check if the current event has already been sorted
1955     //--------------------------------------------------
1956     if (issorted_new && lastsorted_new == GetReadEntry()) {
1957     return; //already done for this event
1958     }
1959    
1960    
1961     // cout << "SORT" << endl;
1962    
1963     //Reset the sort flags, just in case something will go wrong...
1964     issorted_new = false;
1965     lastsorted_new = -1;
1966    
1967     //--------------------------------------------------
1968     // set input variables
1969     //--------------------------------------------------
1970    
1971     TString how = howtosort;
1972     //Save current Object count
1973     Int_t ObjectNumber = TProcessID::GetObjectCount();
1974    
1975    
1976    
1977    
1978     TrkLevel2 * trk2 ;
1979     CaloLevel2 * calo2;
1980     ToFLevel2 * tof2 ;
1981     OrbitalInfo * orb2 ;
1982    
1983     TClonesArray * trkext ;
1984     TClonesArray * caloext;
1985     TClonesArray * tofext ;
1986     TClonesArray * orbext ;
1987    
1988    
1989     // cout << "trk2_obj" << trk2_obj<< endl;
1990     // cout << "trk2_nuc_obj" << trk2_nuc_obj<< endl;
1991     // cout << " trk_ext_obj "<<trk_ext_obj<< endl;
1992     // cout << " trk_ext_nuc_obj "<<trk_ext_nuc_obj<< endl;
1993    
1994     //-----------------------------------------------------------
1995     // create/reset TCloneArrays to store tracks and their images
1996     //-----------------------------------------------------------
1997 pam-fi 1.97
1998     // cout << " PamLevel2::SortTracksNew() --- Clear TClonesArray objects"<<endl;
1999 pam-ts 1.95
2000     // main tracks from standard alg
2001 pam-fi 1.97 // if (!tsorted)
2002     // tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2003     // tsorted->Clear("C+C");//Delete();
2004     // // track images from standard alg
2005     // if (!timage)
2006     // timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2007     // timage->Clear("C+C");//Delete();
2008     // // tracks from extended algorythm
2009     // if(EXT && !text)
2010     // text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2011     // if(text)text->Clear("C+C");//Delete();
2012    
2013     if(tsorted)delete tsorted;
2014     if(timage) delete timage;
2015     if(text) delete text;
2016     tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2017     timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2018     text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2019 pam-ts 1.95
2020     //-----------------------------------------------------------
2021     // create/reset TCloneArrays to store tracks and their images
2022     //-----------------------------------------------------------
2023     if(NUC){
2024 pam-fi 1.97
2025    
2026     if(tsorted_nuc)delete tsorted_nuc;
2027     if(timage_nuc) delete timage_nuc;
2028     if(text_nuc) delete text_nuc;
2029     tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2030     timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2031     text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2032    
2033 pam-ts 1.95 // main tracks from standard alg
2034 pam-fi 1.97 // if (!tsorted_nuc)
2035     // tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2036     // tsorted_nuc->Clear("C+C");//Delete();
2037     // // track images from standard alg
2038     // if (!timage_nuc)
2039     // timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2040     // timage_nuc->Clear("C+C");//Delete();
2041     // // tracks from extended algorythm
2042     // if(EXT && !text_nuc)
2043     // text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2044     // if(text_nuc)text_nuc->Clear("C+C");//Delete();
2045    
2046 pam-ts 1.95 }
2047     //--------------------------------------------------
2048     // retrieve sorting method
2049     //--------------------------------------------------
2050     Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
2051     Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
2052     Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
2053     Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
2054     Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
2055     Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
2056     Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
2057    
2058     if (use_TOF) {
2059     use_S1 = true;
2060     use_S2 = true;
2061     use_S3 = true;
2062     };
2063     if (!CAL2 && use_CAL)
2064     use_CAL = false;
2065     if (!TOF) {
2066     use_TOF = false;
2067     use_S1 = false;
2068     use_S2 = false;
2069     use_S3 = false;
2070     }
2071     if (!GP) {
2072     use_GP = false;
2073     }
2074    
2075     if (!TRK2) {
2076     cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
2077     return;
2078     };
2079    
2080    
2081     ///////////////////////////////////////////////////////////////////////////////////
2082     //
2083     // sort tracks and fill PamTrack arrays
2084     //
2085     ///////////////////////////////////////////////////////////////////////////////////
2086     for(int doit=0; doit<2; doit++){
2087    
2088     // cout << "doit "<<doit<<endl;
2089    
2090    
2091     if(doit == 0){
2092    
2093     trk2 = trk2_obj;
2094     calo2 = calo2_obj;
2095     tof2 = tof2_obj;
2096     orb2 = orb2_obj;
2097    
2098     trkext = trk_ext_obj;
2099     caloext = calo_ext_obj;
2100     tofext = tof_ext_obj;
2101     orbext = orb_ext_obj;
2102    
2103    
2104    
2105    
2106    
2107     }else if (doit == 1){
2108    
2109     if(!NUC)break;
2110    
2111    
2112     trk2 = trk2_nuc_obj;
2113     calo2 = calo2_nuc_obj;
2114     tof2 = tof2_nuc_obj;
2115     orb2 = orb2_nuc_obj;
2116    
2117     trkext = trk_ext_nuc_obj;
2118     caloext = calo_ext_nuc_obj;
2119     tofext = tof_ext_nuc_obj;
2120     orbext = orb_ext_nuc_obj;
2121    
2122    
2123    
2124    
2125     }
2126    
2127     // cout << "trk2" << trk2<<endl;
2128     // cout << "calo2" << calo2<<endl;
2129     // cout << "tof2" << tof2<<endl;
2130     // cout << "orb2" << orb2<<endl;
2131     // cout << "trkext" <<trkext <<endl;
2132     // cout << "tofext" << tofext<<endl;
2133     // cout << "caloext" << caloext<<endl;
2134     // cout << "orbext" << orbext<<endl;
2135    
2136     TClonesArray &ttext = (doit==0 ? *text : *text_nuc);
2137     TClonesArray &ttimage = (doit==0 ? *timage : *timage_nuc);
2138     TClonesArray &ttsorted = (doit==0 ? *tsorted : *tsorted_nuc);
2139    
2140     // cout << "tsorted + timage "<<doit<<endl;
2141    
2142     //--------------------------------------------------
2143     // loop over "physical" tracks sorted by the tracker
2144     //--------------------------------------------------
2145     for (Int_t i = 0; i < trk2->TrkLevel2::GetNTracks(); i++) {
2146    
2147     TrkTrack *ts = 0;
2148     CaloTrkVar *cs = 0;
2149     ToFTrkVar *os = 0;
2150     OrbitalInfoTrkVar *rs = 0;
2151    
2152     // get tracker tracks
2153     TrkTrack *tp = trk2->GetTrack(i); //tracker
2154     CaloTrkVar *cp = calo2->GetCaloStoredTrack(tp->GetSeqNo());
2155     ToFTrkVar *op = tof2->GetToFStoredTrack(tp->GetSeqNo());
2156     OrbitalInfoTrkVar *rp = orb2->GetOrbitalInfoStoredTrack(tp->GetSeqNo());
2157    
2158     TrkTrack *ti = 0; //tracker (image)
2159     CaloTrkVar *ci = 0;
2160     ToFTrkVar *oi = 0;
2161     OrbitalInfoTrkVar *ri = 0;
2162     // cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
2163     // if track has an image, check image selection
2164    
2165     Int_t tp_score = 0; //main track sorted by the tracker
2166     Int_t ti_score = 0; //image track
2167     Int_t totp_score = 0; //main track sorted by the tracker
2168     Int_t toti_score = 0; //image track
2169    
2170     if (tp->HasImage()) {
2171    
2172     ti = trk2->GetTrackImage(i); //tracker (image)
2173     ci = calo2->GetCaloStoredTrack(ti->GetSeqNo());
2174     oi = tof2->GetToFStoredTrack(ti->GetSeqNo());
2175     ri = orb2->GetOrbitalInfoStoredTrack(ti->GetSeqNo());
2176    
2177     // cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
2178    
2179     //assign starting scores
2180     tp_score = 0; //main track sorted by the tracker
2181     ti_score = 0; //image track
2182    
2183     // -----------------------------------------------------------------------------------------
2184     // *****************************************************************************************
2185     // -----------------------------------------------------------------------------------------
2186     // calorimeter check
2187     // -----------------------------------------------------------------------------------------
2188     if (use_CAL && !calo2) {
2189     cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but CaloLevel2 not loaded !!!";
2190     return;
2191     };
2192     if (use_CAL && !cp && ci) {
2193     ti_score++;
2194     toti_score++;
2195     };
2196     if (use_CAL && cp && !ci) {
2197     tp_score++;
2198     totp_score++;
2199     };
2200     if (use_CAL && cp && ci && true) {
2201    
2202     if (cp->npresh > ci->npresh && true) {
2203     tp_score++;
2204     totp_score++;
2205     };
2206     if (cp->npresh < ci->npresh && true) {
2207     ti_score++;
2208     toti_score++;
2209     };
2210    
2211     // cout << "CALO "<<tp_score<<ti_score<<endl;
2212    
2213     };
2214     // -----------------------------------------------------------------------------------------
2215     // *****************************************************************************************
2216     // -----------------------------------------------------------------------------------------
2217     // TOF check
2218     // -----------------------------------------------------------------------------------------
2219     // check the number of hit pmts along the track
2220     // on S12 S21 and S32, where paddles are parallel to Y axis
2221     if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2) {
2222     cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
2223     return;
2224     };
2225     //
2226     if ((use_TOF || use_S1 || use_S2 || use_S3) && !op && oi) {
2227     ti_score++;
2228     toti_score++;
2229     };
2230     if ((use_TOF || use_S1 || use_S2 || use_S3) && op && !oi) {
2231     tp_score++;
2232     totp_score++;
2233     };
2234     if ((use_TOF || use_S1 || use_S2 || use_S3) && op && oi) {
2235     //
2236     Float_t sen = 0.;
2237     for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2238     Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2239     if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2240     sen += (op->dedx).At(ih);
2241     };
2242     for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2243     Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2244     if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2245     sen += (oi->dedx).At(ih);
2246     };
2247     //
2248     if (sen >= sortthr && false) { // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
2249     //printf(" IS A NUCLEUS! en = %f \n",sen);
2250     //
2251     // is a nucleus use a different algorithm
2252     //
2253     Int_t nz = 6;
2254     Float_t zin[6]; // << define TOF z-coordinates
2255     for (Int_t ip = 0; ip < nz; ip++)
2256     zin[ip] = tof2->GetZTOF(tof2->GetToFPlaneID(ip)); // << read ToF plane z-coordinates
2257     Trajectory *tr = new Trajectory(nz, zin);
2258     //
2259     Int_t nphit_p = 0;
2260     Int_t nphit_i = 0;
2261     Float_t enhit_p = 0.;
2262     Float_t enhit_i = 0.;
2263     //
2264     for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2265     Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2266     if (pl == 1 || pl == 2 || pl == 5) {
2267     nphit_p++;
2268     enhit_p += (op->dedx).At(ih);
2269     };
2270     };
2271     //
2272     tp->DoTrack2(tr);
2273     //
2274     if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2275     for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2276     Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2277     if (pl == 0) {
2278     nphit_p++;
2279     enhit_p += (op->dedx).At(ih);
2280     };
2281     };
2282     };
2283     if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2284     for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2285     Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2286     if (pl == 3) {
2287     nphit_p++;
2288     enhit_p += (op->dedx).At(ih);
2289     };
2290     };
2291     };
2292     if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2293     for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2294     Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2295     if (pl == 4) {
2296     nphit_p++;
2297     enhit_p += (op->dedx).At(ih);
2298     };
2299     };
2300     };
2301    
2302     for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2303     Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2304     if (pl == 1 || pl == 2 || pl == 5) {
2305     nphit_i++;
2306     enhit_i += (op->dedx).At(ih);
2307     };
2308     };
2309     //
2310     ti->DoTrack2(tr);
2311     //
2312     if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2313     for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2314     Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2315     if (pl == 0) {
2316     nphit_i++;
2317     enhit_i += (op->dedx).At(ih);
2318     };
2319     };
2320     };
2321     if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2322     for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2323     Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2324     if (pl == 3) {
2325     nphit_i++;
2326     enhit_i += (op->dedx).At(ih);
2327     };
2328     };
2329     };
2330     if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2331     for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2332     Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2333     if (pl == 4) {
2334     nphit_i++;
2335     enhit_i += (op->dedx).At(ih);
2336     };
2337     };
2338     };
2339    
2340     if ((use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p + nphit_i) != 0 && true) {
2341    
2342     // 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);
2343     // printf(" score p %i score i %i \n",tp_score,ti_score);
2344     // if( enhit_p > enhit_i ) tp_score++;
2345     // if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
2346     if (nphit_p > nphit_i)
2347     tp_score++;
2348     if (nphit_p < nphit_i)
2349     ti_score++;
2350     if (nphit_p == nphit_i) {
2351     if (enhit_p > enhit_i)
2352     tp_score++;
2353     else
2354     ti_score++;
2355     };
2356     // printf(" dopo score p %i score i %i \n",tp_score,ti_score);
2357     };
2358     delete tr;
2359     //
2360     }
2361     else {
2362     // -------------
2363     // NOT a NUCLEUS
2364     // -------------
2365     //printf(" NOT a NUCLEUS! en = %f \n",sen);
2366    
2367     Int_t nphit_p = 0;
2368     Int_t nphit_i = 0;
2369    
2370     /* cout << "track: npmtadc "<< op->npmtadc << endl;
2371     cout << "track: npmttdc "<< op->npmttdc << endl;
2372     cout << "image: npmtadc "<< oi->npmtadc << endl;
2373     cout << "image: npmttdc "<< oi->npmttdc << endl;*/
2374    
2375     // for (Int_t ih=0; ih < op->npmtadc; ih++){
2376     // Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
2377     // if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
2378     // };
2379    
2380     // for (Int_t ih=0; ih < oi->npmtadc; ih++){
2381     // Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
2382     // if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
2383     // };
2384     // --- modified to count tdc signals (more efficient?)
2385     // --- and to implement check on tdcflag
2386     for (Int_t ih = 0; ih < op->npmttdc; ih++) {
2387     Int_t pl = tof2->GetPlaneIndex((op->pmttdc).At(ih));
2388     // if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
2389     if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2390     || (use_S3 && (pl == 4 || pl == 5))) {
2391     if ((op->tdcflag).At(ih) == 0)
2392     nphit_p++;
2393     };
2394     };
2395    
2396     for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
2397     Int_t pl = tof2->GetPlaneIndex((oi->pmttdc).At(ih));
2398     // if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
2399     if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2400     || (use_S3 && (pl == 4 || pl == 5))) {
2401     if ((oi->tdcflag).At(ih) == 0)
2402     nphit_i++;
2403     };
2404     };
2405    
2406     if ((nphit_p + nphit_i) != 0 && true) {
2407    
2408     if (nphit_p != nphit_i) {
2409     totp_score += nphit_p;
2410     toti_score += nphit_i;
2411     tp_score += nphit_p;
2412     ti_score += nphit_i;
2413     };
2414     // if ( nphit_p > nphit_i) tp_score+=nphit_p;
2415     // else if( nphit_p < nphit_i) ti_score+=nphit_i;
2416     // else ;//niente
2417     };
2418     };
2419     // cout << "TOF "<<tp_score<<ti_score<<endl;
2420     };
2421    
2422     // if(tp_score == ti_score) use_TRK = true;
2423    
2424    
2425     // -----------------------------------------------------------------------------------------
2426     // *****************************************************************************************
2427     // -----------------------------------------------------------------------------------------
2428     // tracker check
2429     // -----------------------------------------------------------------------------------------
2430     // chi**2 difference is not always large enough to distinguish among
2431     // the real track and its image.
2432     // Tracker check will be applied always when calorimeter and tof information is ambiguous.
2433     // *** MODIFIED ON AUGUST 2007 ***
2434     if (use_TRK) {
2435     // if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
2436     // else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
2437    
2438     // CHECK 1 : number of points along X
2439     if (tp->GetNX() >= ti->GetNX()) {
2440     tp_score++;
2441     totp_score++;
2442     };
2443     if (tp->GetNX() <= ti->GetNX()) {
2444     ti_score++;
2445     toti_score++;
2446     };
2447     // CHECK 2 : number of points along Y
2448     if (tp->GetNY() >= ti->GetNY()) {
2449     tp_score++;
2450     totp_score++;
2451     };
2452     if (tp->GetNY() <= ti->GetNY()) {
2453     ti_score++;
2454     toti_score++;
2455     };
2456    
2457     // cout << "TRK "<<tp_score<<ti_score<<endl;
2458     };
2459    
2460     // -----------------------------------------------------------------------------------------
2461     // *****************************************************************************************
2462     // -----------------------------------------------------------------------------------------
2463     // GPamela check
2464     // -----------------------------------------------------------------------------------------
2465    
2466     //---------------------------------------------------
2467     // count the number of GP hits
2468     //---------------------------------------------------
2469     if (use_GP) {
2470     int ngphits_p = 0;
2471     int ngphits_i = 0;
2472     float toll = 0.02; //200 micron
2473     for (int ih = 0; ih < GetGPamela()->Nthspe; ih++) {
2474     int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
2475     if (tp && tp->YGood(ip) && fabs(tp->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2476     ngphits_p++;
2477     if (ti && ti->YGood(ip) && fabs(ti->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2478     ngphits_i++;
2479     }
2480     if (ngphits_p > ngphits_i && true) {
2481     tp_score++;
2482     totp_score++;
2483     }
2484     if (ngphits_p < ngphits_i && true) {
2485     ti_score++;
2486     toti_score++;
2487     }
2488     }
2489    
2490     // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2491     // the winner is....
2492     // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2493     if (tp_score > ti_score) {
2494    
2495     }
2496     else if (tp_score < ti_score) {
2497    
2498     ts = ti;//its image!!
2499     cs = ci;
2500     os = oi;
2501     rs = ri;
2502     Int_t totis = toti_score;
2503    
2504     ti = tp;//its image!!
2505     ci = cp;
2506     oi = op;
2507     ri = rp;
2508    
2509     tp = ts;//its image!!
2510     cp = cs;
2511     op = os;
2512     rp = rs;
2513    
2514     toti_score = totp_score;
2515     totp_score = totis;
2516    
2517     }
2518     else {
2519    
2520     // cout << "Warning - track image ambiguity not solved" << endl;
2521    
2522     };
2523    
2524     }
2525     else {
2526     totp_score = 1;
2527     toti_score = 0;
2528    
2529     // ts = tp;
2530     // cs = cp;
2531     // os = op;
2532     };
2533    
2534     // cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
2535     // sorted_tracks->Add(ts);//save the track in the sorted array
2536     // sorted_tracks.Add(ts);//save the track in the sorted array
2537     // sorted_tracks.Add(tp);//save the track in the sorted array
2538     // cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
2539     // cout<<"o "<<tp<<endl;
2540     // cout<<"o "<<cp<<endl;
2541     // cout<<"o "<<op<<endl;
2542    
2543     new (ttsorted[i]) PamTrack(tp, cp, op, rp);
2544     new (ttimage[i]) PamTrack(ti, ci, oi, ri);
2545    
2546     ((PamTrack*) (ttsorted[i]))->SetPScore(totp_score);
2547     ((PamTrack*) (ttsorted[i]))->SetIScore(toti_score);
2548     ((PamTrack*) (ttimage[i]))->SetPScore(totp_score);
2549     ((PamTrack*) (ttimage[i]))->SetIScore(toti_score);
2550     };
2551    
2552    
2553    
2554    
2555    
2556     // if (tsorted->GetEntries() != trk2->GetNTracks()) {
2557     // cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() " << tsorted->GetEntries()
2558     // << " != trk2->GetNTracks() = " << trk2->GetNTracks() << endl;
2559     // tsorted->Delete();
2560     // tsorted = 0;
2561     // timage->Delete();
2562     // timage = 0;
2563     // }
2564    
2565    
2566     // cout << "text "<<doit<<endl;
2567    
2568    
2569     //--------------------------------------------------
2570     // fill array with extended tracks (this is easy...)
2571     //--------------------------------------------------
2572     if(EXT){
2573     for(int it=0; it<trkext->GetEntries(); it++){
2574    
2575     new (ttext[it]) PamTrack((ExtTrack*)(*trkext)[it], (CaloTrkVar*)(*caloext)[it], (ToFTrkVar*)(*tofext)[it], (OrbitalInfoTrkVar*)(*orbext)[it]);
2576    
2577     }
2578     }
2579    
2580    
2581    
2582     };
2583    
2584    
2585     //Restore Object count
2586     //To save space in the table keeping track of all referenced objects
2587     //We reset the object count to what it was at the beginning of the event.
2588     TProcessID::SetObjectCount(ObjectNumber);
2589    
2590     //Everything went fine so the current event can be tagged as sorted
2591     issorted_new = true;
2592     lastsorted_new = GetReadEntry();
2593    
2594     // cout << " tsorted "<< tsorted << " "<<(tsorted ? tsorted->GetEntries() : 0)<<endl;
2595     // cout << " timage "<< timage << " "<<(timage ? timage->GetEntries() : 0)<<endl;
2596     // cout << " text "<< text << " "<<(text ? text->GetEntries() : 0)<<endl;
2597    
2598    
2599     };
2600 pam-fi 1.1 //--------------------------------------
2601     //
2602     //
2603     //--------------------------------------
2604     /**
2605 pam-fi 1.2 * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
2606     * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
2607 pam-ts 1.96 */
2608 pam-ts 1.95
2609 pam-fi 1.13 // TRefArray *PamLevel2::GetTracks(){
2610    
2611     // // *-*-*-*-*-*-*-*-*-*-*-*-*
2612     // SortTracks("+CAL+TOF");
2613     // // *-*-*-*-*-*-*-*-*-*-*-*-*
2614    
2615     // // return sorted_tracks;
2616     // return &sorted_tracks;
2617 pam-fi 1.81
2618 pam-fi 1.13 // };
2619 pam-fi 1.81
2620 pam-fi 1.8
2621 pam-fi 1.2 //--------------------------------------
2622 pam-fi 1.55 //
2623     //
2624 pam-fi 1.2 //--------------------------------------
2625 pam-ts 1.96
2626 pam-fi 1.2 /**
2627 pam-fi 1.81 * Retrieves the it-th Pamela "physical" track.
2628     * It override TrkLevel2::GetTrack(int it).
2629 pam-fi 1.1 * @param it Track number, ranging from 0 to GetNTracks().
2630     */
2631 pam-ts 1.96 PamTrack *PamLevel2::GetTrackOld(int it) {
2632 pam-fi 1.81
2633 pam-ts 1.95 PamTrack *track = NULL;
2634 pam-fi 1.81
2635     // *-*-*-*-*-*-*-*-*-*-*-*-*
2636     SortTracks();
2637     // *-*-*-*-*-*-*-*-*-*-*-*-*
2638     if (!tsorted)
2639 pam-ts 1.95 return track;
2640 pam-fi 1.81 if (!tsorted->GetEntries())
2641 pam-ts 1.95 return track;
2642 pam-fi 1.81
2643    
2644     if (it >= 0 && it < trk2_obj->TrkLevel2::GetNTracks()) {
2645     track = (PamTrack*)((*tsorted)[it]);
2646     }
2647     else {
2648 pam-ts 1.96 cout << "PamLevel2::GetTrackOld(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2649 pam-fi 1.81 << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2650     };
2651 pam-fi 1.13
2652 pam-fi 1.81 return track;
2653 pam-fi 1.13
2654 pam-ts 1.95 };
2655    
2656     //PamTrack *PamLevel2::GetTrack(int it) { return GetTrack(it,trkAlg); };
2657    
2658     /**
2659     * Retrieves the it-th Pamela "physical" track.
2660     * It override TrkLevel2::GetTrack(int it).
2661     * @param it Track number, ranging from 0 to GetNTracks().
2662     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2663     */
2664 pam-ts 1.96 PamTrack *PamLevel2::GetTrack(int it, const char* alg) {
2665 pam-ts 1.95
2666     TString s(alg);
2667 pam-ts 1.96 if(!s.CompareTo("") ||!s.CompareTo("STD") )return GetTrackOld(it); //old algorythm
2668 pam-ts 1.95
2669    
2670     SortTracksNew();
2671     // >> fill tsorted, timage and text
2672    
2673     if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2674    
2675     if( s.Contains("NUC")){
2676     if(
2677     tsorted_nuc &&
2678     it < tsorted_nuc->GetEntries() && //enough tracks found
2679     it >= 0 && //valid index
2680     true) return (PamTrack*)((*tsorted_nuc)[it]); //ok return the track
2681     }else{
2682     if(
2683     tsorted &&
2684     it < tsorted->GetEntries() && //enough tracks found
2685     it >= 0 && //valid index
2686     true )return (PamTrack*)((*tsorted)[it]); //ok return the track
2687     }
2688    
2689     }
2690    
2691    
2692     /////////////////////////////////////////////////////////////////////////
2693     /// if requested get track from extended algorythm output
2694     /////////////////////////////////////////////////////////////////////////
2695    
2696     if(s.Contains("EXT", TString::kIgnoreCase) && EXT){//if exteded-alg requested
2697    
2698     if(s.Contains("NUC")){
2699     if(
2700     text_nuc &&
2701     it < text_nuc->GetEntries() && //enough tracks found
2702     it >= 0 && //valid index
2703     true) return (PamTrack*)((*text_nuc)[it]);
2704     }else{
2705     if(
2706     text &&
2707     it < text->GetEntries() && //enough tracks found
2708     it >= 0 && //valid index
2709     true) return (PamTrack*)((*text)[it]);
2710     }
2711    
2712     };
2713    
2714    
2715 pam-ts 1.96 cout << "PamTrack *PamLevel2::GetTrack("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2716 pam-ts 1.95
2717     return NULL;
2718    
2719     }
2720     ;
2721     TClonesArray *PamLevel2::GetTracks() {
2722    
2723     // *-*-*-*-*-*-*-*-*-*-*-*-*
2724     SortTracks();
2725     // *-*-*-*-*-*-*-*-*-*-*-*-*
2726    
2727     return tsorted;
2728    
2729 pam-fi 1.81 }
2730     ;
2731 pam-ts 1.96 Int_t PamLevel2::GetNTracks(const char* alg) {
2732 pam-ts 1.95
2733    
2734     // cout << " trk_nuc_obj->GetEntries() "<<trk_nuc_obj->GetEntries()<<" trk2_nuc_obj->GetNTracks() "<<trk2_nuc_obj->GetNTracks()<<endl;
2735    
2736     TString s(alg);
2737    
2738     if(!s.CompareTo("") || !s.CompareTo("STD"))return trk2_obj->TrkLevel2::GetNTracks(); //standard algorythm
2739    
2740     if(s.Contains("EXTF", TString::kIgnoreCase) && EXT){
2741     if(s.Contains("NUC", TString::kIgnoreCase) && NUC)return trk_ext_nuc_obj->GetEntries();//ok
2742     return trk_ext_obj->GetEntries();//ok
2743     }
2744     if( s.Contains("EXT", TString::kIgnoreCase) && EXT) {
2745     if(s.Contains("NUC", TString::kIgnoreCase) && NUC)
2746     return (trk2_nuc_obj->TrkLevel2::GetNTracks() ? trk2_nuc_obj->TrkLevel2::GetNTracks() : trk_ext_nuc_obj->GetEntries() );
2747     return (trk2_obj->TrkLevel2::GetNTracks() ? trk2_obj->TrkLevel2::GetNTracks() : trk_ext_obj->GetEntries() );
2748     }
2749     if(s.Contains("NUC", TString::kIgnoreCase) && NUC )
2750     return trk2_nuc_obj->TrkLevel2::GetNTracks();
2751    
2752 pam-ts 1.96 cout << "Int_t PamLevel2::GetNTracks("<<alg<<") -- unrecognised algorithm"<<endl;
2753    
2754 pam-ts 1.95 return 0;
2755    
2756     }
2757    
2758 pam-fi 1.3
2759 pam-fi 1.1 //--------------------------------------
2760     //
2761     //
2762     //--------------------------------------
2763     /**
2764 pam-fi 1.81 * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2765 pam-fi 1.1 * @param it Track number, ranging from 0 to GetNTracks().
2766     */
2767 pam-ts 1.96 PamTrack *PamLevel2::GetTrackImageOld(int it) {
2768 pam-fi 1.1
2769 pam-fi 1.81 // *-*-*-*-*-*-*-*-*-*-*-*-*
2770     SortTracks();
2771     // *-*-*-*-*-*-*-*-*-*-*-*-*
2772     if (!timage)
2773     return 0;
2774     if (!timage->GetEntries())
2775     return 0;
2776    
2777     PamTrack *image = 0;
2778    
2779     if (it >= 0 && it < trk2_obj->TrkLevel2::GetNTracks()) {
2780     TClonesArray &t = *(tsorted);
2781     PamTrack *temp = (PamTrack*) t[it];
2782     if (temp->GetTrkTrack()->HasImage()) {
2783     TClonesArray & t = *(timage);
2784     image = (PamTrack*) t[it];
2785     }
2786     else {
2787     // cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
2788     };
2789     }
2790     else {
2791 pam-ts 1.96 cout << "PamLevel2::GetTrackImageOld(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2792 pam-fi 1.81 << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2793     };
2794    
2795     return image;
2796 pam-fi 1.1 }
2797 pam-ts 1.95 /**
2798     * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2799     * @param it Track number, ranging from 0 to GetNTracks().
2800     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2801     */
2802 pam-ts 1.96 PamTrack *PamLevel2::GetTrackImage(int it, const char* alg) {
2803 pam-ts 1.95
2804     TString s(alg);
2805 pam-ts 1.96 if(!s.CompareTo("") || !s.CompareTo("STD"))return GetTrackImageOld(it); //old algorythm
2806 pam-ts 1.95
2807    
2808     SortTracksNew();
2809     // >> fill tsorted, timage and text
2810    
2811     if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2812    
2813     if( s.Contains("NUC")){
2814     if(
2815     tsorted_nuc &&
2816     it < tsorted_nuc->GetEntries() && //enough tracks found
2817     it >= 0 && //valid index
2818     true){
2819     TClonesArray &t = *(tsorted_nuc);
2820     PamTrack *temp = (PamTrack*) t[it];
2821     if (temp->GetTrkTrack()->HasImage()) {
2822     return (PamTrack*)((*timage_nuc)[it]); //ok return the track
2823 pam-ts 1.96 }else{
2824     return NULL;
2825 pam-ts 1.95 }
2826    
2827     }
2828     }else{
2829     if(
2830     tsorted &&
2831     it < tsorted->GetEntries() && //enough tracks found
2832     it >= 0 && //valid index
2833     true ){
2834     TClonesArray &t = *(tsorted);
2835     PamTrack *temp = (PamTrack*) t[it];
2836     if (temp->GetTrkTrack()->HasImage()) {
2837     return (PamTrack*)((*timage)[it]); //ok return the track
2838 pam-ts 1.96 }else{
2839     return NULL;
2840 pam-ts 1.95 }
2841     }
2842     }
2843    
2844     }
2845 pam-ts 1.96
2846     cout << "PamTrack *PamLevel2::GetTrackImage("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2847 pam-ts 1.95
2848     return NULL;
2849    
2850     }
2851     ;
2852 pam-fi 1.1
2853     //--------------------------------------
2854     //
2855     //
2856     //--------------------------------------
2857     /**
2858 pam-fi 1.2 * Get the Pamela detector trees in a single file and make them friends.
2859     * @param f TFile pointer
2860     * @param detlist String to select trees to be included
2861     * @return Pointer to a TTree
2862 pam-fi 1.1 */
2863 pam-fi 1.81 TTree *PamLevel2::GetPamTree(TFile *f, TString detlist) {
2864    
2865     if (detlist.Contains("+AUTO", TString::kIgnoreCase)) {
2866     cout << "+AUTO" << endl;
2867     GetWhichTrees(f);
2868     };
2869     SetWhichTrees(detlist);
2870    
2871     if (pam_tree) {
2872     printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
2873     return pam_tree;
2874     };
2875     //
2876 pam-fi 1.4
2877 pam-fi 1.81 cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte " << endl;
2878    
2879     // SetWhichTrees(detlist);
2880 pam-fi 1.52
2881 pam-fi 1.81 TTree *Trout = 0;
2882 mocchiut 1.35
2883 pam-fi 1.81 TString fname = f->GetName();
2884     if (!CheckLevel2File(fname))
2885     return NULL;
2886 pam-fi 1.20
2887 pam-fi 1.81 // UInt_t *found=0;
2888 pam-fi 1.9
2889 pam-fi 1.81 cout << "GetPamTree(TFile*,TString): detector list --> ";
2890     if (TRK1)
2891     cout << "TRK1 ";
2892     if (TRK2)
2893     cout << "TRK2 ";
2894     if (TRKh)
2895     cout << "TRKH ";
2896     if (CAL1)
2897     cout << "CAL1 ";
2898     if (CAL2)
2899     cout << "CAL2 ";
2900     if (TOF)
2901     cout << "TOF ";
2902     if (TRG)
2903     cout << "TRG ";
2904     if (AC)
2905     cout << "AC ";
2906     if (ND)
2907     cout << "ND ";
2908     if (S4)
2909     cout << "S4 ";
2910     if (ORB)
2911     cout << "ORB ";
2912     if (GP)
2913     cout << "GP ";
2914     cout << endl;
2915     if (SELLI && SELLI != 2)
2916     cout << ">>> Found selection-list <<<" << endl; //EMILIANO
2917    
2918     f->cd();
2919    
2920     // Tracker
2921     TTree *T = (TTree*) f->Get("Tracker");
2922     if (T && (TRK2 || TRK1 || TRKh)) {
2923     if (TRK2)
2924     T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2925     // else T->SetBranchStatus("TrkLevel2",0,found);
2926     if (TRK2)
2927     cout << "Tracker : set branch address TrkLevel2" << endl;
2928     if (TRK1)
2929     T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2930     // else T->SetBranchStatus("TrkLevel1",0,found);
2931     if (TRK1)
2932     cout << "Tracker : set branch address TrkLevel1" << endl;
2933     if (TRKh)
2934     T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2935     // else T->SetBranchStatus("TrkHough",0,found);
2936     if (TRKh)
2937     cout << "Tracker : set branch address TrkHough" << endl;
2938     if (!Trout)
2939     Trout = T;
2940     else
2941 pam-ts 1.95 Trout->AddFriend(T);
2942 pam-fi 1.81 }
2943     else {
2944     cout << "Tracker : missing tree" << endl;
2945     };
2946     // Calorimeter
2947     TTree *C = (TTree*) f->Get("Calorimeter");
2948     if (C && (CAL2 || CAL1)) {
2949     if (CAL2)
2950     C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
2951     // else C->SetBranchStatus("CaloLevel2",0,found);
2952     if (CAL2)
2953     cout << "Calorimeter : set branch address CaloLevel2" << endl;
2954     if (CAL1)
2955     C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
2956     // else C->SetBranchStatus("CaloLevel1",0,found);
2957     if (CAL1)
2958     cout << "Calorimeter : set branch address CaloLevel1" << endl;
2959     if (!Trout)
2960     Trout = C;
2961     else
2962     Trout->AddFriend(C);
2963     }
2964     else {
2965     cout << "Calorimeter : missing tree" << endl;
2966     };
2967 pam-fi 1.9
2968 pam-fi 1.81 // ToF
2969     TTree *O = (TTree*) f->Get("ToF");
2970     if (O && TOF) {
2971     O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
2972     cout << "ToF : set branch address ToFLevel2" << endl;
2973     if (!Trout)
2974     Trout = O;
2975     else
2976     Trout->AddFriend(O);
2977     }
2978     else {
2979     cout << "ToF : missing tree" << endl;
2980     };
2981     // Trigger
2982     TTree *R = (TTree*) f->Get("Trigger");
2983     if (R && TRG) {
2984     R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
2985     cout << "Trigger : set branch address TrigLevel2" << endl;
2986     if (!Trout)
2987     Trout = R;
2988     else
2989     Trout->AddFriend(R);
2990     }
2991     else {
2992     cout << "Trigger : missing tree" << endl;
2993     };
2994     // S4
2995     TTree *S = (TTree*) f->Get("S4");
2996     if (S && S4) {
2997     S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
2998     cout << "S4 : set branch address S4Level2" << endl;
2999     if (!Trout)
3000     Trout = S;
3001     else
3002     Trout->AddFriend(S);
3003     }
3004     else {
3005     cout << "S4 : missing tree" << endl;
3006     };
3007     // Neutron Detector
3008     TTree *N = (TTree*) f->Get("NeutronD");
3009     if (N && ND) {
3010     N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
3011     cout << "NeutronD : set branch address NDLevel2" << endl;
3012     if (!Trout)
3013     Trout = N;
3014     else
3015     Trout->AddFriend(N);
3016     }
3017     else {
3018     cout << "NeutronD : missing tree" << endl;
3019     };
3020     // Anticounters
3021     TTree *A = (TTree*) f->Get("Anticounter");
3022     if (A && AC) {
3023     A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
3024     cout << "Anticounter : set branch address AcLevel2" << endl;
3025     if (!Trout)
3026     Trout = A;
3027     else
3028     Trout->AddFriend(A);
3029     }
3030     else {
3031     cout << "Anticounter : missing tree" << endl;
3032     };
3033     // Orbital Info
3034     TTree *B = (TTree*) f->Get("OrbitalInfo");
3035     if (B && ORB) {
3036     B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
3037     cout << "OrbitalInfo : set branch address OrbitalInfo" << endl;
3038     if (!Trout)
3039     Trout = B;
3040     else
3041     Trout->AddFriend(B);
3042     }
3043     else {
3044     cout << "OrbitalInfo : missing tree" << endl;
3045     };
3046 pam-fi 1.9
3047 pam-fi 1.81 // GPamela
3048     TTree *G = (TTree*) f->Get("h20");
3049     if (G && GP) {
3050     if (!gp_obj)
3051     gp_obj = new GPamela();
3052     // ------------------------------------
3053     // ATTENZIONE!!!
3054     // non so per quale arcano motivo,
3055     // per l'albero di gpamela il branch address lo devo settare
3056     // DOPO aver fatto friend
3057     // FGRRRVZZZZUTSALKJMSLKJ!!!
3058     // ------------------------------------
3059     // gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
3060     // cout << "h20 : set branch address GPamela "<<endl;
3061     if (!Trout)
3062     Trout = G;
3063     else
3064     Trout->AddFriend(G);
3065     }
3066     else {
3067     // cout << "h20 : missing tree"<<endl;
3068     };
3069 pam-fi 1.12
3070 pam-fi 1.81 TTree *L = (TTree*) f->Get("SelectionList");
3071     if (L && SELLI == 1) {
3072     cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!" << endl;
3073     sel_tree = 0;
3074     }
3075     else {
3076     cout << "SelectionList : missing tree" << endl;
3077     };
3078 pam-fi 1.20
3079 pam-fi 1.81 cout << endl << " Number of entries: " << Trout->GetEntries() << endl << endl;
3080 pam-fi 1.52
3081 pam-fi 1.81 // ------------------------------------
3082     // ATTENZIONE!!!
3083     // non so per quale arcano motivo,
3084     // per l'albero di gpamela il branch address lo devo settare
3085     // DOPO aver fatto friend
3086     // FGRRRVZZZZUTSALKJMSLKJ!!!
3087     // ------------------------------------
3088     if (G && GP) {
3089     gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
3090     cout << "h20 : set branch address GPamela " << endl;
3091     }
3092     else {
3093     cout << "h20 : missing tree" << endl;
3094     };
3095 pam-fi 1.52
3096 pam-fi 1.81 pam_tree = (TChain*) Trout;
3097 mocchiut 1.28
3098 pam-fi 1.81 return Trout;
3099 pam-fi 1.52
3100 pam-fi 1.1 }
3101 pam-fi 1.2 //--------------------------------------
3102     //
3103     //
3104     //--------------------------------------
3105     /**
3106     * Get list of Level2 files.
3107     * @param ddir Level2 data directory.
3108     * @param flisttxt Name of txt file containing file list.
3109     * @return Pointer to a TList of TSystemFiles
3110     * If no input file list is given , all the Level2 files inside the directory are processed.
3111     */
3112 pam-fi 1.81 TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = "") {
3113    
3114     TString wdir = gSystem->WorkingDirectory();
3115    
3116     if (ddir != "") {
3117     cout << "Level2 data directory : " << ddir << endl;
3118     }
3119     else {
3120     cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory "
3121     << endl;
3122     };
3123     TList *contents = new TList; // create output list
3124     contents->SetOwner();
3125    
3126     // --------------------------------------
3127     // case 1 : input file/file-list provided
3128     // --------------------------------------
3129     if (flisttxt != "") {
3130    
3131 pam-fi 1.79 // --------------------------------------
3132 pam-fi 1.81 // a list of files given as input
3133 pam-fi 1.79 // --------------------------------------
3134 pam-fi 1.81 if (!flisttxt.EndsWith(".root")) {
3135    
3136     TString dir = gSystem->DirName(flisttxt);
3137     // cout << " List directory "<<dir<<endl;
3138     if (dir == "." || dir == "")
3139     flisttxt = gSystem->ConcatFileName(wdir.Data(), gSystem->BaseName(flisttxt));
3140     // flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
3141    
3142     if (!gSystem->ChangeDirectory(ddir)) {
3143     cout << "Cannot change directory : " << ddir << endl;
3144     return 0;
3145     }
3146    
3147     cout << "Input file list : " << flisttxt << endl;
3148     ifstream in;
3149     in.open(flisttxt, ios::in); //open input file list
3150     if (!in.good()) {
3151     cout << " TList* PamLevel2::GetListOfLevel2Files(TString, TString) --> ERROR opening the file " << endl;
3152     gSystem->ChangeDirectory(wdir); // back to the working directory
3153     return 0;
3154     }
3155     int line = 0;
3156     // ...........................
3157     // loop over file-list records
3158     // ...........................
3159     while (1) {
3160     TString file;
3161     in >> file;
3162     if (!in.good())
3163     break;
3164     line++;
3165     cout << "(*) " << file << endl;
3166     if (file.IsNull()) {
3167     cout << "-- list interrupted at line " << line << endl;
3168     break;
3169     }
3170     if (file.Contains("#"))
3171     file = file(0, file.First("#"));
3172     //
3173     // take only root files
3174     //
3175     if (file.EndsWith(".root")) {
3176     TString filedir;
3177     cout << ddir << endl;
3178 mocchiut 1.84 if ( ddir != "" ) {
3179 pam-fi 1.81 filedir = ddir; // take the input dir
3180     }
3181     else {
3182     gSystem->ChangeDirectory(wdir); // back to the working directory
3183     filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
3184     };
3185     filedir.Append("/");
3186 mocchiut 1.84 // char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir), gSystem->BaseName(file));
3187     char *fullpath = gSystem->ConcatFileName(filedir.Data(), gSystem->BaseName(file));
3188 pam-fi 1.81 contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));// add file to the list
3189     cout << fullpath << endl;
3190     delete fullpath;
3191     }
3192     // }else{
3193     // if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
3194     // };
3195     };
3196     in.close();
3197     // --------------------------------------
3198     // a single root file given as input
3199     // --------------------------------------
3200     }
3201     else {
3202     if (flisttxt.Contains("#"))
3203     flisttxt = flisttxt(0, flisttxt.First("#"));
3204     char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt), gSystem->BaseName(flisttxt));
3205     contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));// add file to the list
3206     delete fullpath;
3207     };
3208 pam-fi 1.79 // ---------------------------------------------------------------------------------
3209     // case 2 : no input file/file-list provided --> read all files insede the directory
3210     // ---------------------------------------------------------------------------------
3211 pam-fi 1.81 }
3212     else {
3213    
3214     cout << "No input file list given." << endl;
3215     cout << "Check for existing root files." << endl;
3216     // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
3217     if (ddir == "") {
3218     ddir = wdir;
3219     cout << "Level2 data directory : " << ddir << endl;
3220 pam-fi 1.6 };
3221 pam-fi 1.81
3222     TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir), ddir);
3223     TList *temp = datadir->GetListOfFiles();
3224     if (!temp)
3225     return 0;
3226     // temp->Print();
3227     // cout << "*************************************" << endl;
3228    
3229     TIter next(temp);
3230     TSystemFile *questo = 0;
3231    
3232     while ((questo = (TSystemFile*) next())) {
3233     TString name = questo-> GetName();
3234     if (name.EndsWith(".root")) {
3235     // const char *fullpath = gSystem->FindFile(ddir,name);
3236     // char *fullpath;
3237     // gSystem->IsFileInIncludePath(name,&fullpath);
3238     char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir), gSystem->BaseName(name));
3239     contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));
3240     delete fullpath;
3241     };
3242     }
3243     delete temp;
3244     delete datadir;
3245    
3246     };
3247     gSystem->ChangeDirectory(wdir); // back to the working directory
3248     // cout << endl << "Selected files:" << endl;
3249     // contents->Print();
3250     cout << contents->GetEntries() << " files \n";
3251     // cout << endl;
3252     // cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
3253     return contents;
3254     }
3255     ;
3256 pam-fi 1.2 //--------------------------------------
3257     //
3258     //
3259     //--------------------------------------
3260     /**
3261     * Get the Pamela detector chains from a list of files and make them friends.
3262 pam-fi 1.81 * @param fl Pointer to a TList of TSystemFiles
3263 pam-fi 1.2 * @param detlist String to select trees to be included
3264     * @return Pointer to a TChain
3265     */
3266 pam-fi 1.81 TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) {
3267     //
3268     //
3269     //
3270     if (pam_tree) {
3271     printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
3272     return pam_tree;
3273     };
3274     //
3275 pam-fi 1.2
3276 pam-fi 1.81 TChain *Trout = 0;
3277 pam-fi 1.52
3278 pam-fi 1.81 // -------------------------------------------
3279     // set flags to include/exclude trees/branches
3280     // -------------------------------------------
3281     if (detlist.Contains("+AUTO", TString::kIgnoreCase)) {
3282     if (fl->GetEntries() > 0) {
3283     cout << "+AUTO" << endl;
3284     TFile *fprimo = new TFile(fl->At(0)->GetName());
3285     GetWhichTrees(fprimo);
3286     fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
3287     fprimo->Delete();
3288     }
3289     };
3290     SetWhichTrees(detlist);
3291 pam-fi 1.52
3292 pam-fi 1.81 // -------------------------------------------
3293     // build chains
3294     // -------------------------------------------
3295     TChain *T = 0;
3296     TChain *C = 0;
3297     TChain *O = 0;
3298     TChain *R = 0;
3299     TChain *S = 0;
3300     TChain *N = 0;
3301     TChain *A = 0;
3302     TChain *B = 0;
3303     TChain *G = 0;
3304    
3305     TChain *L = 0;
3306    
3307     if (TRK2 || TRK1 || TRKh)
3308     T = new TChain("Tracker");
3309     if (CAL2 || CAL1)
3310     C = new TChain("Calorimeter");
3311     if (TOF)
3312     O = new TChain("ToF");
3313     if (TRG)
3314     R = new TChain("Trigger");
3315     if (S4)
3316     S = new TChain("S4");
3317     if (ND)
3318     N = new TChain("NeutronD");
3319     if (AC)
3320     A = new TChain("Anticounter");
3321     if (ORB)
3322     B = new TChain("OrbitalInfo");
3323     if (GP)
3324     G = new TChain("h20");
3325     L = new TChain("SelectionList");
3326    
3327     // loop over files and create chains
3328     TIter next(fl);
3329     TSystemFile *questo = 0;
3330     while ((questo = (TSystemFile*) next())) {
3331     TString name = questo->GetName();
3332     cout << "File: " << name << endl;
3333     if (CheckLevel2File(name)) {
3334     if (TRK2 || TRK1 || TRKh)
3335     T->Add(name);
3336     if (CAL1 || CAL2)
3337     C->Add(name);
3338     if (TOF)
3339     O->Add(name);
3340     if (TRG)
3341     R->Add(name);
3342     if (S4)
3343     S->Add(name);
3344     if (ND)
3345     N->Add(name);
3346     if (AC)
3347     A->Add(name);
3348     if (ORB)
3349     B->Add(name);
3350     if (GP)
3351     G->Add(name);
3352     if (SELLI == 1)
3353     L->Add(name);
3354 pam-ts 1.95 };
3355 pam-fi 1.81 };
3356 pam-fi 1.11
3357 pam-ts 1.95 cout << "done data-tree chains "<< T->GetNtrees() <<" \n";
3358     cout << "----------------------------------------------------" << endl;
3359 pam-fi 1.56
3360 pam-fi 1.81 // -------------------------------------------
3361     // make friends
3362     // -------------------------------------------
3363    
3364     // Tracker
3365     cout << "Friends: " << endl;
3366     if (T && (TRK2 || TRK1 || TRKh)) {
3367     if (!Trout)
3368     Trout = T;
3369     else
3370     Trout->AddFriend("Tracker");
3371     // cout << "+Tacker"<<endl;
3372     };
3373     // Calorimeter
3374     if (C && (CAL2 || CAL1)) {
3375     if (!Trout)
3376     Trout = C;
3377     else
3378     Trout->AddFriend("Calorimeter");
3379     // cout << "+Calorimeter"<<endl;
3380     };
3381     // ToF
3382     if (O && TOF) {
3383     if (!Trout)
3384     Trout = O;
3385     else
3386     Trout->AddFriend("ToF");
3387     // cout << "+ToF"<<endl;
3388     };
3389     // Trigger
3390     if (R && TRG) {
3391     if (!Trout)
3392     Trout = O;
3393     else
3394     Trout->AddFriend("Trigger");
3395     // cout << "+Trigger"<<endl;
3396     };
3397     // S4
3398     if (S && S4) {
3399     if (!Trout)
3400     Trout = O;
3401     else
3402     Trout->AddFriend("S4");
3403     // cout << "+S4"<<endl;
3404     };
3405     // Neutron Detector
3406     if (N && ND) {
3407     if (!Trout)
3408     Trout = O;
3409     else
3410     Trout->AddFriend("NeutronD");
3411     // cout << "+NeutronD"<<endl;
3412     };
3413     // Anticounters
3414     if (A && AC) {
3415     if (!Trout)
3416     Trout = O;
3417     else
3418     Trout->AddFriend("Anticounter");
3419     // cout << "+Anticounter"<<endl;
3420     };
3421     // Orbital Info
3422     if (B && ORB) {
3423     if (!Trout)
3424     Trout = O;
3425     else
3426     Trout->AddFriend("OrbitalInfo");
3427     // cout << "+OrbitalInfo"<<endl;
3428     };
3429     // GPamela
3430     if (G && GP) {
3431     if (!Trout)
3432     Trout = G;
3433     else
3434     Trout->AddFriend("h20");
3435     // cout << "+h20"<<endl;
3436     };
3437 pam-fi 1.52
3438 pam-fi 1.81 // =====================================
3439     // SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
3440     // =====================================
3441 pam-ts 1.95 if( Trout->GetNtrees() )SetBranchAddress(Trout);
3442 pam-fi 1.81
3443     // ------------------------------------
3444     // finally handle selection trees...
3445     // (it is not friend of pamela tree)
3446     // ------------------------------------
3447    
3448 pam-ts 1.95 cout << "----------------------------------------------------" << endl;
3449 pam-fi 1.81
3450     // Selection List
3451     if (L && SELLI == 1) {
3452     cout << ">>> Found selection-list <<<" << endl;
3453     // L->SetBranchAddress("RunEntry",&irun);
3454     L->SetBranchAddress("RunEntry", &irunt);//NEWNEW
3455     cout << "SelectionList: set branch address RunEntry" << endl;
3456     L->SetBranchAddress("EventEntry", &irunentry);
3457     cout << "SelectionList: set branch address EventEntry" << endl;
3458 mocchiut 1.91 /* if ( L->GetBranch("L0EventEntry") ){
3459 mocchiut 1.90 hasL0EE = true;
3460     L->SetBranchAddress("L0EventEntry", &il0entry);
3461     cout << "SelectionList: set branch address L0EventEntry" << endl;
3462     } else {
3463     hasL0EE = false; // backward compatibility with old preselected files...
3464 mocchiut 1.91 }*/
3465 pam-fi 1.81 sel_tree = L;
3466     // if(!Trout)Trout=O;
3467     // else Trout->AddFriend("SelectionList");
3468     cout << "+SelectionList" << endl;
3469 pam-ts 1.95 cout << "----------------------------------------------------" << endl;
3470 pam-fi 1.81 }
3471     else {
3472     // cout << "SelectionList : missing tree"<<endl;
3473     if (L)
3474     L->Delete();
3475     };
3476 pam-fi 1.52
3477 pam-fi 1.81 // --------------------------------------------
3478     // return the pamela chain with all the friends
3479     // --------------------------------------------
3480 pam-fi 1.8
3481 pam-fi 1.81 pam_tree = Trout;
3482 pam-fi 1.8
3483 pam-fi 1.81 return Trout;
3484     }
3485 pam-fi 1.8
3486 pam-fi 1.4 //--------------------------------------
3487     //
3488     //
3489     //--------------------------------------
3490     /**
3491     * Set branch addresses for Pamela friend trees
3492     */
3493 pam-fi 1.81 void PamLevel2::SetBranchAddress(TTree *t) {
3494    
3495 pam-ts 1.95 // TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
3496     // TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
3497     // TRKh = TRKh & t->GetBranchStatus("TrkHough");
3498     // CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
3499     // CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
3500     // TOF = TOF & t->GetBranchStatus("ToFLevel2");
3501     // TRG = TRG & t->GetBranchStatus("TrigLevel2");
3502     // S4 = S4 & t->GetBranchStatus("S4Level2");
3503     // ND = ND & t->GetBranchStatus("NDLevel2");
3504     // AC = AC & t->GetBranchStatus("AcLevel2");
3505     // ORB = ORB & t->GetBranchStatus("OrbitalInfo");
3506     // GP = GP & t->GetBranchStatus("h20");
3507    
3508 pam-fi 1.81
3509     // Tracker
3510     if (TRK1) {
3511     t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));
3512     cout << "Tracker : set branch address TrkLevel1" << endl;
3513     };
3514     if (TRK2) {
3515     t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
3516     cout << "Tracker : set branch address TrkLevel2" << endl;
3517 pam-ts 1.95 NUC = t->GetBranchStatus("TrackNuclei");
3518     EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );
3519 pam-fi 1.81 };
3520     if (TRKh) {
3521     t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
3522     cout << "Tracker : set branch address TrkHough" << endl;
3523     };
3524    
3525     // Calorimeter
3526     if (CAL1) {
3527     t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
3528     cout << "Calorimeter : set branch address CaloLevel1" << endl;
3529     };
3530     if (CAL2) {
3531     t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
3532     cout << "Calorimeter : set branch address CaloLevel2" << endl;
3533     };
3534 pam-fi 1.8
3535 pam-fi 1.81 // ToF
3536     if (TOF) {
3537     t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
3538     cout << "ToF : set branch address ToFLevel2" << endl;
3539     };
3540     // Trigger
3541     if (TRG) {
3542     t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
3543     cout << "Trigger : set branch address TrigLevel2" << endl;
3544     };
3545     // S4
3546     if (S4) {
3547     t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
3548     cout << "S4 : set branch address S4Level2" << endl;
3549     };
3550     // Neutron Detector
3551     if (ND) {
3552     t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
3553     cout << "NeutronD : set branch address NDLevel2" << endl;
3554     };
3555     // Anticounters
3556     if (AC) {
3557     t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
3558     cout << "Anticounter : set branch address AcLevel2" << endl;
3559     };
3560     // OrbitalInfo
3561     if (ORB) {
3562     t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
3563     cout << "OrbitalInfo : set branch address OrbitalInfo" << endl;
3564     };
3565     // GPamela
3566     if (GP) {
3567     // GetPointerTo("GPamela");
3568     if (!gp_obj)
3569     gp_obj = new GPamela();
3570     // gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
3571     // // t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
3572     if (SELLI)
3573     t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
3574     else
3575     gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
3576    
3577     cout << "h20 : set branch address GPamela " << endl;
3578     };
3579 pam-ts 1.95 if(NUC){
3580    
3581     cout << "Found nuclei-track branches" << endl;
3582    
3583     if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3584     if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3585     if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3586     if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3587     if (TRK2)t-> SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3588     if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3589     if (TOF )t->GetFriend("ToF")-> SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3590     if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3591    
3592     ///copy the vector content inside a "fake" object (all aother info are missing)
3593    
3594     if( !trk2_nuc_obj )trk2_nuc_obj = new TrkLevel2();
3595     if( !calo2_nuc_obj )calo2_nuc_obj = new CaloLevel2();
3596     if( !tof2_nuc_obj )tof2_nuc_obj = new ToFLevel2();
3597     if( !orb2_nuc_obj )orb2_nuc_obj = new OrbitalInfo();
3598     // *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3599     // *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3600     // *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3601     // *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3602    
3603     trk2_nuc_obj->SetTrackArray( trk_nuc_obj );
3604     calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3605     tof2_nuc_obj->SetTrackArray( tof_nuc_obj );
3606     orb2_nuc_obj->SetTrackArray( orb_nuc_obj );
3607    
3608    
3609     }
3610 pam-fi 1.61
3611 pam-ts 1.95 if(EXT){
3612    
3613     cout << "Found extended tracking algorythm branches" << endl;
3614    
3615     if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3616     if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3617     if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3618     if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3619    
3620     if (TRK2)t-> SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3621     if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3622     if (TOF )t->GetFriend("ToF")-> SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3623     if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3624    
3625    
3626     if(NUC){
3627     if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3628     if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3629     if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3630     if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3631     if (TRK2)t-> SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3632     if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3633     if (TOF )t->GetFriend("ToF")-> SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3634     if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3635     }
3636     }
3637 pam-fi 1.4 }
3638 pam-fi 1.8 /**
3639     * Set branch addresses for Pamela friend trees
3640     */
3641 pam-fi 1.81 void PamLevel2::SetBranchAddress(TChain *t) {
3642    
3643     // TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
3644     // TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
3645     // TRKh = TRKh & t->GetBranchStatus("TrkHough");
3646     // CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
3647     // CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
3648     // TOF = TOF & t->GetBranchStatus("ToFLevel2");
3649     // TRG = TRG & t->GetBranchStatus("TrigLevel2");
3650     // S4 = S4 & t->GetBranchStatus("S4Level2");
3651     // ND = ND & t->GetBranchStatus("NDLevel2");
3652     // AC = AC & t->GetBranchStatus("AcLevel2");
3653     // ORB = ORB & t->GetBranchStatus("OrbitalInfo");
3654     // GP = GP & t->GetBranchStatus("h20");
3655    
3656     // Tracker
3657     if (TRK2) {
3658     t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
3659     cout << "Tracker : set branch address TrkLevel2" << endl;
3660 pam-ts 1.95 NUC = t->GetBranchStatus("TrackNuclei");
3661     EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );
3662 pam-fi 1.81 };
3663     if (TRK1) {
3664     t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
3665     cout << "Tracker : set branch address TrkLevel1" << endl;
3666     };
3667     if (TRKh) {
3668     t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
3669     cout << "Tracker : set branch address TrkHough" << endl;
3670     };
3671    
3672     // Calorimeter
3673     if (CAL2) {
3674     t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
3675 pam-ts 1.95 cout << "Calorimeter : set branch address CaloLevel2" << endl;
3676 pam-fi 1.81 };
3677     if (CAL1) {
3678     t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
3679     cout << "Calorimeter : set branch address CaloLevel1" << endl;
3680     };
3681    
3682     // ToF
3683     if (TOF) {
3684     t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
3685     cout << "ToF : set branch address ToFLevel2" << endl;
3686     };
3687     // Trigger
3688     if (TRG) {
3689     t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
3690     cout << "Trigger : set branch address TrigLevel2" << endl;
3691     };
3692     // S4
3693     if (S4) {
3694     t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
3695     cout << "S4 : set branch address S4Level2" << endl;
3696     };
3697     // Neutron Detector
3698     if (ND) {
3699     t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
3700     cout << "NeutronD : set branch address NDLevel2" << endl;
3701     };
3702     // Anticounters
3703     if (AC) {
3704     t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
3705     cout << "Anticounter : set branch address AcLevel2" << endl;
3706     };
3707     // OrbitalInfo
3708     if (ORB) {
3709     t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
3710     cout << "OrbitalInfo : set branch address OrbitalInfo" << endl;
3711     };
3712     // GPamela
3713     // cout <<"GP "<<GP<<endl;
3714     if (GP) {
3715     // GetPointerTo("GPamela");
3716     if (!gp_obj)
3717     gp_obj = new GPamela();
3718     if (SELLI)
3719     t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
3720     else
3721     gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
3722     // gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
3723     cout << "h20 : set branch address GPamela " << endl;
3724     };
3725     // SelectionList
3726     // if(SELLI==1){
3727     // t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
3728     // cout << "SelectionList: set branch address RunEntry"<<endl;
3729     // t->SetBranchAddress("EventEntry",&irunentry);
3730     // cout << "SelectionList: set branch address EventEntry"<<endl;
3731 pam-fi 1.4
3732 pam-fi 1.81 // }
3733 pam-ts 1.95 if(NUC){
3734    
3735     cout << "Found nuclei-track branches" << endl;
3736    
3737     if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3738     if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3739     if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3740     if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3741     if (TRK2)t-> SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3742     if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3743     if (TOF )t->GetFriend("ToF")-> SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3744     if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3745    
3746     ///copy the vector content inside a "fake" object (all aother info are missing)
3747    
3748     if( !trk2_nuc_obj )trk2_nuc_obj = new TrkLevel2();
3749     if( !calo2_nuc_obj )calo2_nuc_obj = new CaloLevel2();
3750     if( !tof2_nuc_obj )tof2_nuc_obj = new ToFLevel2();
3751     if( !orb2_nuc_obj )orb2_nuc_obj = new OrbitalInfo();
3752    
3753     // *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3754     // *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3755     // *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3756     // *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3757     trk2_nuc_obj->SetTrackArray( trk_nuc_obj );
3758     calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3759     tof2_nuc_obj->SetTrackArray( tof_nuc_obj );
3760     orb2_nuc_obj->SetTrackArray( orb_nuc_obj );
3761    
3762     }
3763     if(EXT){
3764    
3765     cout << "Found extended tracking algorythm branches" << endl;
3766    
3767     t->SetBranchAddress("extAlgFlag",&extAlgFlag);
3768 pam-fi 1.56
3769 pam-ts 1.95 if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3770     if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3771     if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3772     if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3773    
3774     if (TRK2)t-> SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3775     if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3776     if (TOF )t->GetFriend("ToF")-> SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3777     if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3778    
3779     if(NUC){
3780     if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3781     if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3782     if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3783     if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3784     if (TRK2)t-> SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3785     if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3786     if (TOF )t->GetFriend("ToF")-> SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3787     if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3788     }
3789     }
3790    
3791 pam-fi 1.8 }
3792 pam-fi 1.9
3793 pam-ts 1.95 /**
3794     * Set the tracking algorythm
3795     * @param alg String to choose the track.
3796     * "" --> take the output of the standard tracking algorythm
3797     * "STD" --> take the output of the standard tracking algorythm
3798     * "NUC" --> take the output of the standard tracking algorythm for nuclei cluster selection
3799     * "EXT" --> in case the standard tracking algorythm has not found any track, take the output of the extended one
3800     * "EXTF" --> force the extended tracking algorythm
3801     * "NUCEXT" --> as "EXT", but for nuclei
3802     * "NUCEXTF" --> as "EXTF", but for nuclei
3803     */
3804 pam-ts 1.96 // void PamLevel2::SetTrackingAlgorythm(const char *alg){
3805 pam-ts 1.95
3806    
3807 pam-ts 1.96 // TString s(alg);
3808     // if(s.Contains("NUC", TString::kIgnoreCase) && !NUC)
3809     // cout << "Warning! NUC algorythm requested, but branches are missing"<<endl;
3810     // if(s.Contains("EXT", TString::kIgnoreCase) && !EXT)
3811     // cout << "Warning! EXT algorythm requested, but branches are missing"<<endl;;
3812 pam-ts 1.95
3813 pam-ts 1.96 // trkAlg = alg;
3814 pam-ts 1.95
3815 pam-ts 1.96 // };
3816     // const char* PamLevel2::GetTrackingAlgorythm(){
3817 pam-ts 1.95
3818    
3819 pam-ts 1.96 // cout<<endl<<" Implemented tracking algorythm: ";
3820     // cout<<endl<<" \"\" or \"STD\" --> take the output of the standard tracking algorythm";
3821     // cout<<endl<<" \"NUC\" --> take the output of the standard tracking algorythm for nuclei cluster selection";
3822     // cout<<endl<<" \"EXT\" --> in case the standard tracking algorythm has not found any track,";
3823     // cout<<endl<<" take the output of the extended one";
3824     // cout<<endl<<" \"EXTF\" --> force the extended tracking algorythm";
3825     // cout<<endl<<" \"NUCEXT\" --> as \"EXT\", but for nuclei ";
3826     // cout<<endl<<" \"NUCEXTF\" --> as \"EXTF\", but for nuclei";
3827    
3828     // cout<<endl;
3829     // cout<<" <<Currently set algorythm>> "<<trkAlg<<endl;
3830     // cout<<endl;
3831 pam-ts 1.95
3832 pam-ts 1.96 // return trkAlg;
3833     // };
3834 pam-ts 1.95
3835    
3836    
3837 pam-fi 1.4 //--------------------------------------
3838     //
3839     //
3840     //--------------------------------------
3841     /**
3842     * Get the Run tree chain from a list of files.
3843 pam-fi 1.81 * @param fl Pointer to a TList of TSystemFiles
3844 pam-fi 1.4 * @return Pointer to a TChain
3845     */
3846 pam-fi 1.81 TChain *PamLevel2::GetRunTree(TList *fl) {
3847     //
3848     //
3849     //
3850     if (run_tree) {
3851     printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
3852     return run_tree;
3853     };
3854     //
3855    
3856    
3857     TChain *R = new TChain("Run");
3858 pam-fi 1.60
3859 pam-fi 1.81 // loop over files and create chains
3860     TIter next(fl);
3861     TSystemFile *questo = 0;
3862     while ((questo = (TSystemFile*) next())) {
3863     TString name = questo->GetName();
3864     // cout << "File: "<< name << endl;
3865     if (CheckLevel2File(name)) {
3866     R->Add(name);
3867     };
3868     }
3869    
3870 pam-ts 1.95 cout << "done run chain "<< R->GetNtrees() <<" \n";
3871    
3872    
3873 pam-fi 1.81 if (RUN && R->GetNtrees()) {
3874    
3875     R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
3876     cout << "Run : set branch address RunInfo" << endl;
3877     R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
3878     cout << "Software : set branch address SoftInfo" << endl; // Emiliano
3879    
3880     irunoffset = new int[R->GetNtrees()];
3881     if (DBG) {
3882     cout << "----------------------------------------------------" << endl;
3883     cout << "irun\t | ";
3884     cout << "tree\t |";
3885     // cout << "offset\t |";
3886     cout << "RUN\t";
3887     cout << "FRAG\t";
3888     cout << "NEVENTS\t";
3889     cout << "absolute time\t\t\t";
3890     cout << "on-board time";
3891     cout << endl;
3892     }
3893     for (Int_t ii = 0; ii < R->GetEntries(); ii++) {
3894     R->GetEntry(ii);
3895     if (DBG) {
3896     cout << ii << "\t | ";
3897     cout << R->GetTreeNumber() << "\t |";
3898     // cout << R->GetChainOffset()<< "\t |";
3899     cout << GetRunInfo()->ID << "\t";
3900     cout << GetRunInfo()->ID_RUN_FRAG << "\t";
3901     cout << GetRunInfo()->NEVENTS << "\t";
3902     cout << GetRunInfo()->RUNHEADER_TIME << " <---> " << GetRunInfo()->RUNTRAILER_TIME << "\t";
3903     cout << GetRunInfo()->RUNHEADER_OBT << " <---> " << GetRunInfo()->RUNTRAILER_OBT << "\t";
3904     cout << endl;
3905     }
3906     irunoffset[R->GetTreeNumber()] = R->GetChainOffset();
3907     }
3908     cout << "N.run = " << R->GetEntries() << endl;
3909     cout << "----------------------------------------------------" << endl;
3910    
3911     }
3912 pam-ts 1.95 // else {
3913     // delete R;
3914     // R = 0;
3915     // }
3916 pam-fi 1.60
3917 pam-fi 1.81 run_tree = R;
3918 pam-fi 1.20
3919 pam-fi 1.81 return R;
3920 pam-fi 1.20
3921 pam-fi 1.4 }
3922     //--------------------------------------
3923     //
3924     //
3925     //--------------------------------------
3926     /**
3927     * Get the Run tree from a file.
3928 pam-fi 1.81 * @param f Pointer to a TFile
3929 pam-fi 1.4 * @return Pointer to a TTree
3930     */
3931 pam-fi 1.81 TTree *PamLevel2::GetRunTree(TFile *f) {
3932     if (run_tree) {
3933     printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
3934     return run_tree;
3935     };
3936    
3937     cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte " << endl;
3938    
3939     TTree *T = (TTree*) f->Get("Run");
3940 pam-fi 1.4
3941 pam-fi 1.81 if (T) {
3942     T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
3943     cout << "Run : set branch address RunInfo" << endl;
3944     T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
3945     cout << "Software : set branch address SoftInfo" << endl; // Emiliano
3946 pam-fi 1.4
3947 pam-fi 1.81 }
3948 pam-fi 1.56
3949 pam-fi 1.81 run_tree = (TChain*) T;
3950 mocchiut 1.28
3951 pam-fi 1.81 return T;
3952 mocchiut 1.28
3953 pam-fi 1.2 }
3954 mocchiut 1.89
3955 mocchiut 1.90 Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {
3956 pam-fi 1.36
3957 mocchiut 1.90 if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - inside\n");
3958 pam-fi 1.36
3959 pam-fi 1.81 if (!run_tree) {
3960     cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded" << endl;
3961     return false;
3962     }
3963     if (run_tree->GetEntries() <= 0) {
3964     cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty" << endl;
3965     return (false);
3966     }
3967    
3968 mocchiut 1.89
3969     Int_t oldrun = irun; // store current run index
3970    
3971     // -----------------------------------------------------------------------
3972     // the first time the routine is called, set run search from the beginning
3973     // -----------------------------------------------------------------------
3974    
3975     if (irun < 0) {
3976     irun = 0LL;
3977     irunt = 0LL;
3978     totrunentry = 0LL;
3979     totrunentrymin = 0LL;
3980     totrunentrymax = 0LL;
3981 mocchiut 1.90 irunentry = 0LL;
3982     il0entry = 0LL;
3983 mocchiut 1.89 prevshift = 0;
3984 mocchiut 1.90 yprevshift = 0;
3985 mocchiut 1.89 prevabstime = 0;
3986     prevpktnum = 0;
3987     abstime = 0ULL;
3988     pktnum = 0;
3989     isFragment = false;
3990     run_tree->GetEntry(irun);
3991     if (!GetOrbitalInfo())
3992     cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;
3993 mocchiut 1.94 if ( fUseDBinRunInfo ){
3994     if (gltsync)
3995     delete gltsync; //Emiliano
3996     if (!dbc || (dbc && !dbc->IsConnected()))
3997     SetDBConnection(); //Emiliano
3998     gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); //Emiliano // the "false" means not to use level0 file (not necessary here)
3999     if (dbc){
4000     dbc->Close();// Emiliano
4001     delete dbc;
4002     dbc=0;
4003     }
4004     }
4005     }
4006 mocchiut 1.89 // ---------------------------------------------------------------
4007     // retrieve OBT and absolute time of the event
4008     // ---------------------------------------------------------------
4009     Long64_t obt = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted
4010     prevabstime = abstime;
4011     prevpktnum = pktnum;
4012     if (GetOrbitalInfo()) {
4013     abstime = GetOrbitalInfo()->absTime;
4014 mocchiut 1.94 if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
4015 mocchiut 1.89 pktnum = GetOrbitalInfo()->pkt_num; // Emiliano
4016     }
4017     else {
4018     abstime = GetRunInfo()->RUNHEADER_TIME;
4019 mocchiut 1.94 if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
4020 mocchiut 1.89 pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano
4021     }
4022    
4023     if (DBG){
4024     printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4025     printf("0 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4026     printf("0 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4027 mocchiut 1.94 if ( fUseDBinRunInfo ) printf("0 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4028 mocchiut 1.90 printf("0 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun);
4029 mocchiut 1.89 printf("0 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4030     }
4031    
4032     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
4033     // if it is a full file (not preselected)
4034     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
4035     if (SELLI == 0 || SELLI == 2) { // Emiliano
4036    
4037     // ---------------------------------------------------------------
4038     // increment dead and live-time counters
4039     // (only when reading a file not preselected)
4040     // ---------------------------------------------------------------
4041     if (SELLI == 0) {
4042     if (GetTrigLevel2()) {
4043     totdltime[0] += GetTrigLevel2()->dltime[0];
4044     totdltime[1] += GetTrigLevel2()->dltime[1];
4045     }
4046     totdltime[2]++;
4047     }
4048    
4049     //
4050 mocchiut 1.94 bool a = true;
4051     bool b = true;
4052     if ( fUseDBinRunInfo ){
4053     a = false;
4054     b = false;
4055     if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4056     if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4057     }
4058 mocchiut 1.89 if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits
4059     || iev == 0 // or it is the first entry
4060 mocchiut 1.90 || (!isSync && (
4061 mocchiut 1.94 (abstime <= GetRunInfo()->RUNHEADER_TIME && a ) // or it is outside obt limits (and abstime limits for security reasons)
4062     || (abstime >= GetRunInfo()->RUNTRAILER_TIME && b ) ))// or it is outside obt limits (and abstime limits for security reasons)
4063 mocchiut 1.90 ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4064 mocchiut 1.89
4065     // check for a new run (ma prima il primo!)
4066     if (DBG){
4067     printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4068     printf("1 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4069     printf("1 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4070 mocchiut 1.94 if ( fUseDBinRunInfo ) printf("1 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4071 mocchiut 1.90 printf("1 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun);
4072 mocchiut 1.89 printf("1 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4073     }
4074 mocchiut 1.90 // printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4075     // printf("1 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4076     // printf("1 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4077     // printf("1 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4078     // printf("1 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun);
4079     // printf("1 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI
4080 mocchiut 1.89
4081     totrunentry = 0LL;
4082 mocchiut 1.90 runfirstentry = 0LL;
4083 mocchiut 1.89 for (Int_t r=0; r< run_tree->GetEntries();r++){
4084     // -------------------------------------------------------------------
4085     // save the index of the first entry of the run, relative to pam_tree,
4086     // and read a new run
4087     // -------------------------------------------------------------------
4088     run_tree->GetEntry(r);//update runinfo
4089     if ( r > 0 ){
4090     totrunentrymin = totrunentrymax+1;
4091     } else {
4092     totrunentrymin = 0LL;
4093     }
4094     totrunentry += GetRunInfo()->NEVENTS;
4095 mocchiut 1.90 totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
4096 mocchiut 1.89 irun = r;
4097 mocchiut 1.94 if ( fUseDBinRunInfo ){
4098     a = false;
4099     b = false;
4100     if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4101     if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4102     }
4103 mocchiut 1.90 if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits
4104     ( !isSync &&
4105 mocchiut 1.94 ( abstime >= GetRunInfo()->RUNHEADER_TIME && a // or it is inside obt limits (and abstime limits for security reasons)
4106     && abstime <= GetRunInfo()->RUNTRAILER_TIME && b)) // or it is inside obt limits (and abstime limits for security reasons)
4107 mocchiut 1.90 ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4108     if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
4109     if ( !isSync ){
4110     if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n");
4111     if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
4112     // printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n");
4113     // printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
4114     prevshift += (totrunentrymin-iev); // add the new shift to total shift
4115     totrunentrymin -= (totrunentrymin-iev); // shift run position min
4116     totrunentrymax -= (totrunentrymin-iev); // shift run position max
4117     if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
4118     // printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
4119     } else {
4120     printf(" PamLevel2::UpdateRunInfo(Long64_t) ERROR! sync file but unconsistent totrunetrymin %lld and iev %lld!!! \n",totrunentrymin,iev);
4121     cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
4122     cout << "\nFor bug reporting instructions, please see for example:\n";
4123     cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
4124     cout << " " << endl;
4125     }
4126     }
4127     runfirstentry = totrunentrymin; // first entry of the run in the level2
4128    
4129 mocchiut 1.89
4130     //
4131 mocchiut 1.94 if ( fUseDBinRunInfo ){
4132     if (gltsync)
4133     delete gltsync; // Emiliano
4134     if (!dbc || (dbc && !dbc->IsConnected()))
4135     SetDBConnection(); //Emiliano
4136     gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
4137     TrkParams::Set(GetRunInfo(), dbc);
4138     if (dbc){
4139     dbc->Close(); // Emiliano
4140     delete dbc;
4141     dbc=0;
4142     }
4143     if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
4144     cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
4145     << " has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
4146     cout
4147     << " (NB!! in this case some events could be assigned to a wrong run)"
4148     << endl;
4149     }
4150 mocchiut 1.89 }
4151     //
4152     if (DBG) printf(" found \n");
4153 mocchiut 1.90 // printf(" found \n");//TOGLITOGLI
4154 mocchiut 1.89 //
4155     break;
4156     }
4157     } // loop over run
4158    
4159     // --------------------------------------
4160     // if there was no need to update the run
4161     // ---> exit with FALSE
4162     // --------------------------------------
4163 mocchiut 1.90 if (irun == oldrun){
4164     if (DBG) printf(" no new run \n");
4165     // printf(" no new run \n");//TOGLITOGLI
4166 mocchiut 1.89 return (false);
4167 mocchiut 1.90 }
4168 mocchiut 1.89 // --------------------------------------
4169     // ... otherwise
4170     // ---> exit with TRUE
4171     // --------------------------------------
4172    
4173     if (SELLI != 2) {
4174     /// decrement counters since this event belongs to a new run
4175     if (GetTrigLevel2()) {
4176     totdltime[0] -= GetTrigLevel2()->dltime[0];//live-time
4177     totdltime[1] -= GetTrigLevel2()->dltime[1];//dead-time
4178     }
4179     totdltime[2]--; //event counter
4180     if (DBG) {
4181     cout << endl;
4182     cout << "n.events : " << totdltime[2] << endl;
4183     cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl;
4184     cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl;
4185     }
4186     // add an entry
4187     if (run_tree_clone && totdltime[2] > 0)
4188     if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
4189     run_tree_clone->GetBranch("DeadLiveTime")->Fill();
4190     // reset counters
4191     if ( totdltime[2] > 0 ){
4192     if (GetTrigLevel2()) {
4193     totdltime[0] = GetTrigLevel2()->dltime[0];//live-time
4194     totdltime[1] = 0; //dead-time
4195     }
4196     totdltime[2] = 1; //event counter
4197     }
4198     }
4199    
4200     if (DBG){
4201     cout << endl << " ))))) UPDATE RUN INFO ((((( @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun
4202 mocchiut 1.90 << endl;
4203 mocchiut 1.89 printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4204     printf("2 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4205     printf("2 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4206 mocchiut 1.94 if ( fUseDBinRunInfo ) printf("2 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4207 mocchiut 1.90 printf("2 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun);
4208 mocchiut 1.89 printf("2 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4209     }
4210 mocchiut 1.90 // printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4211     // printf("2 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4212     // printf("2 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4213     // printf("2 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4214     // printf("2 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun);
4215     // printf("2 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI
4216 mocchiut 1.89
4217     return (true);
4218     } // need for run upgrade
4219     if (DBG) printf("return false\n");
4220     return (false);
4221     }// SELLI = 0 SELLI = 2
4222    
4223     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
4224     // if it is a preselected file (there is SelectionList)
4225     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
4226     // irun = run entry relative to the chain
4227     // irunt = run entry relative to the tree
4228     if (SELLI == 1) {
4229     sel_tree->GetEntry(iev);// read irunt from SelectionList
4230     irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
4231     if (irun != oldrun) {
4232     if (irun < run_tree->GetEntries())
4233     run_tree->GetEntry(irun);
4234     // check if the time is ok (with merged files it is not...)
4235     // if not loop over run and look for the proper entry
4236     bool SECONDO_GIRO = false;
4237     // Long64_t irun_start = irun;
4238     int offset_start = irunoffset[sel_tree->GetTreeNumber()];
4239     while (((!(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
4240     abstime <= GetRunInfo()->RUNTRAILER_TIME)
4241     // ||
4242     // !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms)
4243     // obt <= GetRunInfo()->RUNTRAILER_OBT)
4244     ) || GetRunInfo()->NEVENTS == 0)
4245     // && irun < run_tree->GetEntries()
4246     ) {
4247    
4248     if (DBG) {
4249     cout << " (test) ";
4250     cout << " tree " << sel_tree->GetTreeNumber();
4251     cout << " irunt " << irunt;
4252     cout << " offset " << irunoffset[sel_tree->GetTreeNumber()];
4253     cout << " abs " << abstime;
4254     cout << " >> " << GetRunInfo()->RUNHEADER_TIME << " " << GetRunInfo()->RUNTRAILER_TIME;
4255     cout << " obt " << obt;
4256     cout << " >> " << GetRunInfo()->RUNHEADER_OBT << " " << GetRunInfo()->RUNTRAILER_OBT;
4257     cout << " *** JUMP RUN *** irun " << irun;
4258     cout << endl;
4259     }
4260     // irun++;
4261     irunoffset[sel_tree->GetTreeNumber()]++;
4262     irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
4263     if (irun == run_tree->GetEntries() && SECONDO_GIRO) {
4264     // if(irun == irun_start ){
4265     cout << " ...grrrvzzkhhhajsdkj!!!! " << endl;
4266     irunoffset[sel_tree->GetTreeNumber()] = offset_start;
4267     return false;
4268     }
4269     if (irun >= run_tree->GetEntries() || irun < 0) {
4270     cout << "irun = " << irun << " >> search from the beginning... <<" << endl;
4271     SECONDO_GIRO = true;
4272     irun = 0;
4273     irunoffset[sel_tree->GetTreeNumber()] = -irunt;
4274     }
4275     run_tree->GetEntry(irun);
4276     }
4277    
4278     if (DBG) {
4279     cout << " (test) ";
4280     cout << " tree " << sel_tree->GetTreeNumber();
4281     cout << " irunt " << irunt;
4282     cout << " offset " << irunoffset[sel_tree->GetTreeNumber()];
4283     cout << " abs " << abstime;
4284     cout << " >> " << GetRunInfo()->RUNHEADER_TIME << " " << GetRunInfo()->RUNTRAILER_TIME;
4285     cout << " obt " << obt;
4286     cout << " >> " << GetRunInfo()->RUNHEADER_OBT << " " << GetRunInfo()->RUNTRAILER_OBT;
4287     }
4288     if (DBG)
4289     cout << endl;
4290     if (DBG)
4291     cout << endl << " ))))) UPDATE RUN INFO ((((( @iev " << iev << " run " << GetRunInfo()->ID << " (run-entry "
4292     << irun << ")" << endl;
4293     // ----------------------------------------------------
4294     // update the tracker parameters
4295     // (non ho trovato nessun altro modo sicuro di farlo...)
4296     // ----------------------------------------------------
4297 mocchiut 1.94 if ( fUseDBinRunInfo ){
4298     if (!dbc || (dbc && !dbc->IsConnected()))
4299     SetDBConnection();
4300     TrkParams::Set(GetRunInfo(), dbc);
4301     if (dbc){
4302     dbc->Close();
4303     delete dbc;
4304     dbc=0;
4305     }
4306     }
4307 mocchiut 1.89 // cout << endl;
4308     prevshift = 0;
4309 mocchiut 1.90 yprevshift = 0;
4310 mocchiut 1.89 return true;
4311     }
4312     return false;
4313     }
4314    
4315     return false;
4316     //
4317     }
4318    
4319 mocchiut 1.90 /**
4320     * Update the runinfo informations (to be used to have Run infos event by event basis)
4321     * @param run Pointer to the chain/tree which contains run infos
4322     * @return true if a new run has been read, false if it is still the same run
4323     */
4324     Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) {
4325     return (UpdateRunInfo(iev));
4326 pam-fi 1.81 }
4327 mocchiut 1.89
4328 mocchiut 1.17 /**
4329     * Update the runinfo informations (to be used to have Run infos event by event basis)
4330 pam-fi 1.81 * @param run Pointer to the chain/tree which contains run infos
4331 mocchiut 1.17 * @return true if a new run has been read, false if it is still the same run
4332     */
4333 pam-fi 1.81 Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {
4334     return (UpdateRunInfo((TChain*) run, iev));
4335     }
4336 mocchiut 1.89
4337 mocchiut 1.17
4338 pam-fi 1.2 //--------------------------------------
4339     //
4340     //
4341     //--------------------------------------
4342     /**
4343 pam-fi 1.8 * Set which trees shoul be analysed
4344 pam-fi 1.81 * @param detlist TString containing the sequence of trees required
4345 pam-fi 1.55 */
4346 pam-fi 1.81 void PamLevel2::SetWhichTrees(TString detlist) {
4347    
4348     // if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
4349     if (detlist.Contains("+ALL", TString::kIgnoreCase)) {
4350    
4351     cout << " ======================================================== " << endl;
4352     cout << " (( WARNING )) " << endl;
4353     cout << " The meaning of the option +ALL has changed!! " << endl;
4354     cout << " Now it includes really all (level0+level1+level2+gpamela)" << endl;
4355     cout << " and the file is discarded if it does not contain " << endl;
4356     cout << " all trees or if level0 files are not available!! " << endl;
4357     cout << " ======================================================== " << endl;
4358    
4359     CAL0 = true;
4360     CAL1 = true;
4361     CAL2 = true;
4362     TRK2 = true;
4363     TRK1 = true;
4364     TRKh = true;
4365     TRK0 = true;
4366     TRG = true;
4367     TOF = true;
4368     TOF0 = true;
4369     S4 = true;
4370     ND = true;
4371     AC = true;
4372     ORB = true;
4373     GP = true;
4374     }
4375     else if (detlist.Contains("-ALL", TString::kIgnoreCase)) {
4376     CAL0 = false;
4377     CAL1 = false;
4378     CAL2 = false;
4379     TRK2 = false;
4380     TRK1 = false;
4381     TRKh = false;
4382     TRK0 = false;
4383     TRG = false;
4384     TOF = false;
4385     TOF0 = false;
4386     S4 = false;
4387     ND = false;
4388     AC = false;
4389     ORB = false;
4390     GP = false;
4391     };
4392    
4393     // -------------------------------------------------------------------------
4394     if (detlist.Contains("CAL1", TString::kIgnoreCase)) {
4395     if (detlist.Contains("-CAL1", TString::kIgnoreCase))
4396     CAL1 = false;
4397     if (detlist.Contains("+CAL1", TString::kIgnoreCase))
4398     CAL1 = true;
4399     };
4400    
4401     if (detlist.Contains("CAL0", TString::kIgnoreCase)) {
4402     if (detlist.Contains("-CAL0", TString::kIgnoreCase))
4403     CAL0 = false;
4404     if (detlist.Contains("+CAL0", TString::kIgnoreCase))
4405     CAL0 = true;
4406     };
4407    
4408     if (detlist.Contains("CAL2", TString::kIgnoreCase)) {
4409     if (detlist.Contains("-CAL2", TString::kIgnoreCase))
4410     CAL2 = false;
4411     if (detlist.Contains("+CAL2", TString::kIgnoreCase))
4412     CAL2 = true;
4413     };
4414    
4415     if (detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2)
4416     CAL2 = true;
4417     if (detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2) {
4418     CAL2 = false;
4419     CAL1 = false;
4420     }
4421     // -------------------------------------------------------------------------
4422     if (detlist.Contains("TRK0", TString::kIgnoreCase)) {
4423     if (detlist.Contains("-TRK0", TString::kIgnoreCase))
4424     TRK0 = false;
4425     if (detlist.Contains("+TRK0", TString::kIgnoreCase))
4426     TRK0 = true;
4427     };
4428    
4429     if (detlist.Contains("TRK1", TString::kIgnoreCase)) {
4430     if (detlist.Contains("-TRK1", TString::kIgnoreCase))
4431     TRK1 = false;
4432     if (detlist.Contains("+TRK1", TString::kIgnoreCase))
4433     TRK1 = true;
4434     };
4435    
4436     if (detlist.Contains("TRK2", TString::kIgnoreCase)) {
4437     if (detlist.Contains("-TRK2", TString::kIgnoreCase))
4438     TRK2 = false;
4439     if (detlist.Contains("+TRK2", TString::kIgnoreCase))
4440     TRK2 = true;
4441     };
4442    
4443     if (detlist.Contains("TRKh", TString::kIgnoreCase)) {
4444     if (detlist.Contains("-TRKh", TString::kIgnoreCase))
4445     TRKh = false;
4446     if (detlist.Contains("+TRKh", TString::kIgnoreCase))
4447     TRKh = true;
4448     };
4449    
4450     if (detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh)
4451     TRK2 = true;
4452     if (detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh) {
4453     TRK2 = false;
4454     TRK1 = false;
4455     TRKh = false;
4456     }
4457     // -------------------------------------------------------------------------
4458 pam-fi 1.20
4459 pam-fi 1.81 if (detlist.Contains("-TRG", TString::kIgnoreCase))
4460     TRG = false;
4461     else if (detlist.Contains("+TRG", TString::kIgnoreCase))
4462     TRG = true;
4463    
4464     if (detlist.Contains("-TOF", TString::kIgnoreCase))
4465     TOF = false;
4466     else if (detlist.Contains("+TOF", TString::kIgnoreCase))
4467     TOF = true;
4468 pam-fi 1.20
4469 pam-fi 1.81 if (detlist.Contains("-TOF0", TString::kIgnoreCase))
4470     TOF0 = false;
4471     else if (detlist.Contains("+TOF0", TString::kIgnoreCase))
4472     TOF0 = true;
4473 pam-fi 1.8
4474 pam-fi 1.81 if (detlist.Contains("-S4", TString::kIgnoreCase))
4475     S4 = false;
4476     else if (detlist.Contains("+S4", TString::kIgnoreCase))
4477     S4 = true;
4478    
4479     if (detlist.Contains("-ND", TString::kIgnoreCase))
4480     ND = false;
4481     else if (detlist.Contains("+ND", TString::kIgnoreCase))
4482     ND = true;
4483    
4484     if (detlist.Contains("-AC", TString::kIgnoreCase))
4485     AC = false;
4486     else if (detlist.Contains("+AC", TString::kIgnoreCase))
4487     AC = true;
4488    
4489     if (detlist.Contains("-ORB", TString::kIgnoreCase))
4490     ORB = false;
4491     else if (detlist.Contains("+ORB", TString::kIgnoreCase))
4492     ORB = true;
4493    
4494     if (detlist.Contains("-GP", TString::kIgnoreCase))
4495     GP = false;
4496     else if (detlist.Contains("+GP", TString::kIgnoreCase))
4497     GP = true;
4498    
4499     cout << "tree/branch list from input --> ";
4500     if (TRK0)
4501     cout << "TRK0 ";
4502     if (TRK1)
4503     cout << "TRK1 ";
4504     if (TRK2)
4505     cout << "TRK2 ";
4506     if (TRKh)
4507     cout << "TRKH ";
4508     if (CAL0)
4509     cout << "CAL0 ";
4510     if (CAL1)
4511     cout << "CAL1 ";
4512     if (CAL2)
4513     cout << "CAL2 ";
4514     if (TOF)
4515     cout << "TOF ";
4516     if (TRG)
4517     cout << "TRG ";
4518     if (AC)
4519     cout << "AC ";
4520     if (ND)
4521     cout << "ND ";
4522     if (S4)
4523     cout << "S4 ";
4524     if (ORB)
4525     cout << "ORB ";
4526     if (GP)
4527     cout << "GP ";
4528     cout << endl;
4529     // cout<< "Set detector list --> ";
4530     // if(TRK1)cout<<"TRK1 ";
4531     // if(TRK2)cout<<"TRK2 ";
4532     // if(TRKh)cout<<"TRKH ";
4533     // if(CAL1)cout<<"CAL1 ";
4534     // if(CAL2)cout<<"CAL2 ";
4535     // if(TOF0)cout<<"TOF0 ";
4536     // if(TOF)cout<<"TOF ";
4537     // if(TRG)cout<<"TRG ";
4538     // if(AC)cout<<"AC ";
4539     // if(ND)cout<<"ND ";
4540     // if(S4)cout<<"S4 ";
4541     // if(ORB)cout<<"ORB ";
4542     // cout << endl;
4543 pam-fi 1.11
4544 pam-fi 1.81 }
4545     ;
4546 pam-fi 1.11
4547     /**
4548     * Set tree/branch detector flags from the content of a tree
4549     */
4550 pam-fi 1.81 void PamLevel2::GetWhichTrees(TFile* f) {
4551 pam-fi 1.20
4552 pam-fi 1.81 // cout << "void PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
4553     // -----------
4554     // reset flags
4555     // -----------
4556     CAL1 = false;
4557     CAL2 = false;
4558     TRK2 = false;
4559     TRK1 = false;
4560     TRKh = false;
4561     TRG = false;
4562     TOF = false;
4563     S4 = false;
4564     ND = false;
4565     AC = false;
4566     ORB = false;
4567     GP = false;
4568    
4569     RUN = false;
4570    
4571     // cout << "Checking file: "<<f->GetName()<<endl;
4572     if (!f || f->IsZombie()) {
4573     cout << "File: " << f->GetName() << " Non valid root file" << endl;
4574     return;
4575     }
4576    
4577     TList *lk = f->GetListOfKeys();
4578     if (!lk)
4579     return;
4580     TIter next(lk);
4581     TKey *key = 0;
4582    
4583     Int_t nev = 0;
4584    
4585     while ((key = (TKey*) next())) {
4586    
4587     if (!strcmp(key->GetName(), "Run"))
4588     RUN = true;
4589    
4590     //=========================================================
4591     if (!strcmp(key->GetName(), "Trigger")) {
4592     TRG = true;
4593     Int_t nevt = ((TTree*) f->Get("Trigger"))->GetEntries();
4594     if (nev && nevt != nev) {
4595     cout << "File: " << f->GetName() << " Trigger tree has " << nevt << " events instead of " << nev << endl;
4596     TRG = false;
4597     }
4598     else
4599     nev = nevt;
4600     }
4601     //=========================================================
4602     if (!strcmp(key->GetName(), "ToF")) {
4603     TOF = true;
4604     Int_t nevt = ((TTree*) f->Get("ToF"))->GetEntries();
4605     if (nev && nevt != nev) {
4606     cout << "File: " << f->GetName() << " ToF tree has " << nevt << " events instead of " << nev << endl;
4607     TOF = false;
4608     }
4609     else
4610     nev = nevt;
4611     }
4612     //=========================================================
4613     if (!strcmp(key->GetName(), "S4")) {
4614     S4 = true;
4615     Int_t nevt = ((TTree*) f->Get("S4"))->GetEntries();
4616     if (nev && nevt != nev) {
4617     cout << "File: " << f->GetName() << " S4 tree has " << nevt << " events instead of " << nev << endl;
4618     S4 = false;
4619     }
4620     else
4621     nev = nevt;
4622     }
4623     //=========================================================
4624    
4625     if (!strcmp(key->GetName(), "NeutronD")) {
4626     ND = true;
4627     Int_t nevt = ((TTree*) f->Get("NeutronD"))->GetEntries();
4628     if (nev && nevt != nev) {
4629     cout << "File: " << f->GetName() << "NeutronD tree has " << nevt << " events instead of " << nev << endl;
4630     ND = false;
4631     }
4632     else
4633     nev = nevt;
4634     }
4635     //=========================================================
4636     if (!strcmp(key->GetName(), "Anticounter")) {
4637     AC = true;
4638     Int_t nevt = ((TTree*) f->Get("Anticounter"))->GetEntries();
4639     if (nev && nevt != nev) {
4640     cout << "File: " << f->GetName() << " Anticounter tree has " << nevt << " events instead of " << nev << endl;
4641     AC = false;
4642     }
4643     else
4644     nev = nevt;
4645     }
4646     //=========================================================
4647     if (!strcmp(key->GetName(), "OrbitalInfo")) {
4648     ORB = true;
4649     Int_t nevt = ((TTree*) f->Get("OrbitalInfo"))->GetEntries();
4650     if (nev && nevt != nev) {
4651     cout << "File: " << f->GetName() << " OrbitalInfo tree has " << nevt << " events instead of " << nev << endl;
4652     ORB = false;
4653     }
4654     else
4655     nev = nevt;
4656     }
4657     //=========================================================
4658     if (!strcmp(key->GetName(), "Tracker")) {
4659     TTree *T = (TTree*) f->Get("Tracker");
4660     for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
4661     TString name = T->GetListOfBranches()->At(i)->GetName();
4662     if (!name.CompareTo("TrkLevel1"))
4663     TRK1 = true;
4664     if (!name.CompareTo("TrkLevel2"))
4665     TRK2 = true;
4666     if (!name.CompareTo("TrkHough"))
4667     TRKh = true;
4668     };
4669     Int_t nevt = T->GetEntries();
4670     if (nev && nevt != nev) {
4671     cout << "File: " << f->GetName() << " Tracker tree has " << nevt << " events instead of " << nev << endl;
4672     TRK1 = false;
4673     TRK2 = false;
4674     TRKh = false;
4675     }
4676     else
4677     nev = nevt;
4678     // T->Delete();
4679     };
4680     //=========================================================
4681     if (!strcmp(key->GetName(), "Calorimeter")) {
4682     TTree *T = (TTree*) f->Get("Calorimeter");
4683     for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
4684     TString name = T->GetListOfBranches()->At(i)->GetName();
4685     if (!name.CompareTo("CaloLevel1"))
4686     CAL1 = true;
4687     if (!name.CompareTo("CaloLevel2"))
4688     CAL2 = true;
4689     };
4690     Int_t nevt = T->GetEntries();
4691     if (nev && nevt != nev) {
4692     cout << "File: " << f->GetName() << " Calorimeter tree has " << nevt << " events instead of " << nev << endl;
4693     CAL1 = false;
4694     CAL2 = false;
4695     }
4696     else
4697     nev = nevt;
4698     // T->Delete();
4699     };
4700     //=========================================================
4701     if (!strcmp(key->GetName(), "h20")) {
4702     GP = true;
4703     Int_t nevt = ((TTree*) f->Get("h20"))->GetEntries();
4704     if (nev && nevt != nev) {
4705     cout << "File: " << f->GetName() << " h20 tree has " << nevt << " events instead of " << nev << endl;
4706     GP = false;
4707     }
4708     else
4709     nev = nevt;
4710     }
4711 pam-fi 1.20
4712 pam-fi 1.81 };
4713 pam-fi 1.11
4714 pam-fi 1.81 // delete lk;
4715    
4716     cout << "tree/branch list from file --> ";
4717     if (TRK1)
4718     cout << "TRK1 ";
4719     if (TRK2)
4720     cout << "TRK2 ";
4721     if (TRKh)
4722     cout << "TRKH ";
4723     if (CAL1)
4724     cout << "CAL1 ";
4725     if (CAL2)
4726     cout << "CAL2 ";
4727     if (TOF)
4728     cout << "TOF ";
4729     if (TRG)
4730     cout << "TRG ";
4731     if (AC)
4732     cout << "AC ";
4733     if (ND)
4734     cout << "ND ";
4735     if (S4)
4736     cout << "S4 ";
4737     if (ORB)
4738     cout << "ORB ";
4739     if (GP)
4740     cout << "GP ";
4741     cout << endl;
4742 pam-fi 1.12
4743 pam-fi 1.81 return;
4744 pam-fi 1.11
4745 pam-fi 1.81 }
4746     ;
4747 pam-fi 1.11
4748 pam-fi 1.2 //--------------------------------------
4749     //
4750     //
4751     //--------------------------------------
4752     /**
4753 pam-fi 1.3 * Check if a file contains selected Pamela Level2 trees.
4754 pam-fi 1.2 * @param name File name
4755 pam-fi 1.4 * @return true if the file is ok.
4756 pam-fi 1.2 */
4757 pam-fi 1.81 Bool_t PamLevel2::CheckLevel2File(TString name) {
4758    
4759     Bool_t CAL1__ok = false;
4760     Bool_t CAL2__ok = false;
4761     Bool_t TRK2__ok = false;
4762     Bool_t TRK1__ok = false;
4763     Bool_t TRKh__ok = false;
4764     Bool_t TRG__ok = false;
4765     Bool_t TOF__ok = false;
4766     Bool_t S4__ok = false;
4767     Bool_t ND__ok = false;
4768     Bool_t AC__ok = false;
4769     Bool_t ORB__ok = false;
4770     Bool_t GP__ok = false;
4771    
4772     Bool_t RUN__ok = false;
4773    
4774     Bool_t SELLI__ok = false;
4775    
4776     // cout << "Checking file: "<<name<<endl;
4777     TFile *f = new TFile(name.Data());
4778     if (!f || f->IsZombie()) {
4779     cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;
4780     return false;
4781     }
4782     // cout << "Get list of keys: "<<f<<endl;
4783     TList *lk = f->GetListOfKeys();
4784     // lk->Print();
4785     TIter next(lk);
4786     TKey *key = 0;
4787    
4788     Int_t nev = 0;
4789    
4790     while ((key = (TKey*) next())) {
4791    
4792     // cout << key->GetName() << endl;
4793     // cout << key->GetName() << ""<<key->GetClassName()<<endl;
4794     // cout << " Get tree: " << f->Get(key->GetName())<<endl;
4795     // nev_previous = nev;
4796     // cout << " n.entries "<< nev <<endl;
4797     // if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
4798     // nev = ((TTree*)f->Get(key->GetName()))->GetEntries();
4799     // cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;
4800     // return false;
4801     // };
4802    
4803     //=========================================================
4804     // check if the file
4805    
4806    
4807     if (!strcmp(key->GetName(), "Run"))
4808     RUN__ok = true;
4809    
4810     //=========================================================
4811     if (!strcmp(key->GetName(), "SelectionList")) {
4812     SELLI__ok = true;
4813     if (SELLI == 1) {
4814     Int_t nevt = ((TTree*) f->Get("SelectionList"))->GetEntries();
4815     if (nev && nevt != nev) {
4816     cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt
4817     << " events instead of " << nev << endl;
4818     return false;
4819     }
4820     nev = nevt;
4821     }
4822     }
4823    
4824     //=========================================================
4825     if (!strcmp(key->GetName(), "Trigger")) {
4826     TRG__ok = true;
4827     if (TRG) {
4828     Int_t nevt = ((TTree*) f->Get("Trigger"))->GetEntries();
4829     if (nev && nevt != nev) {
4830     cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "
4831     << nev << endl;
4832     return false;
4833     }
4834     nev = nevt;
4835     }
4836     }
4837     //=========================================================
4838     if (!strcmp(key->GetName(), "ToF")) {
4839     TOF__ok = true;
4840     if (TOF) {
4841     Int_t nevt = ((TTree*) f->Get("ToF"))->GetEntries();
4842     if (nev && nevt != nev) {
4843     cout << "File: " << f->GetName() << " discarded ---- ToF tree has " << nevt << " events instead of " << nev
4844     << endl;
4845     return false;
4846     }
4847     nev = nevt;
4848     }
4849     }
4850     //=========================================================
4851     if (!strcmp(key->GetName(), "S4")) {
4852     S4__ok = true;
4853     if (S4) {
4854     Int_t nevt = ((TTree*) f->Get("S4"))->GetEntries();
4855     if (nev && nevt != nev) {
4856     cout << "File: " << f->GetName() << " discarded ---- S4 tree has " << nevt << " events instead of " << nev
4857     << endl;
4858     return false;
4859     }
4860     nev = nevt;
4861     }
4862     }
4863     //=========================================================
4864    
4865     if (!strcmp(key->GetName(), "NeutronD")) {
4866     ND__ok = true;
4867     if (ND) {
4868     Int_t nevt = ((TTree*) f->Get("NeutronD"))->GetEntries();
4869     if (nev && nevt != nev) {
4870     cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "
4871     << nev << endl;
4872     return false;
4873     }
4874     nev = nevt;
4875     }
4876     }
4877     //=========================================================
4878     if (!strcmp(key->GetName(), "Anticounter")) {
4879     AC__ok = true;
4880     if (AC) {
4881     Int_t nevt = ((TTree*) f->Get("Anticounter"))->GetEntries();
4882     if (nev && nevt != nev) {
4883     cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "
4884     << nev << endl;
4885     return false;
4886     }
4887     nev = nevt;
4888     }
4889     }
4890     //=========================================================
4891     if (!strcmp(key->GetName(), "OrbitalInfo")) {
4892     ORB__ok = true;
4893     if (ORB) {
4894     Int_t nevt = ((TTree*) f->Get("OrbitalInfo"))->GetEntries();
4895     if (nev && nevt != nev) {
4896     cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "
4897     << nev << endl;
4898     return false;
4899     }
4900     nev = nevt;
4901     }
4902     }
4903     //=========================================================
4904     if (!strcmp(key->GetName(), "Tracker")) {
4905     TTree *T = (TTree*) f->Get("Tracker");
4906     if (TRK1 || TRK2 || TRKh) {
4907     Int_t nevt = T->GetEntries();
4908     if (nev && nevt != nev) {
4909     cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "
4910     << nev << endl;
4911     return false;
4912     }
4913     nev = nevt;
4914     }
4915     for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
4916     TString name = T->GetListOfBranches()->At(i)->GetName();
4917     if (!name.CompareTo("TrkLevel1"))
4918     TRK1__ok = true;
4919     if (!name.CompareTo("TrkLevel2"))
4920     TRK2__ok = true;
4921     if (!name.CompareTo("TrkHough"))
4922     TRKh__ok = true;
4923     };
4924     T->Delete();
4925     };
4926     //=========================================================
4927     if (!strcmp(key->GetName(), "Calorimeter")) {
4928     TTree *T = (TTree*) f->Get("Calorimeter");
4929     if (CAL1 || CAL2) {
4930     Int_t nevt = T->GetEntries();
4931     if (nev && nevt != nev) {
4932     cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "
4933     << nev << endl;
4934     return false;
4935     }
4936     nev = nevt;
4937     }
4938     for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
4939     TString name = T->GetListOfBranches()->At(i)->GetName();
4940     if (!name.CompareTo("CaloLevel1"))
4941     CAL1__ok = true;
4942     if (!name.CompareTo("CaloLevel2"))
4943     CAL2__ok = true;
4944     };
4945     T->Delete();
4946     };
4947     //=========================================================
4948     if (!strcmp(key->GetName(), "h20")) {
4949     ISGP = true;
4950     GP__ok = true;
4951     if (GP) {
4952     Int_t nevt = ((TTree*) f->Get("h20"))->GetEntries();
4953     if (nev && nevt != nev) {
4954     cout << "File: " << f->GetName() << " discarded ---- h20 tree has " << nevt << " events instead of " << nev
4955     << endl;
4956     return false;
4957     }
4958     nev = nevt;
4959     }
4960     }
4961    
4962     };
4963    
4964     if (SELLI == -1)
4965     SELLI = (Int_t) SELLI__ok;
4966     if (SELLI == 0 && SELLI__ok) {
4967     cout << "File: " << f->GetName() << " discarded ---- found SelectionList (it is not a full-event file)" << endl;
4968     return false;
4969     }
4970     if (SELLI == 1 && !SELLI__ok) {
4971     cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;
4972     return false;
4973     }
4974 pam-fi 1.8
4975 pam-fi 1.81 // cout << "SELLI "<<SELLI<<endl;
4976    
4977     // cout<< "CheckLevel2File(TString): detector list --> ";
4978     // if(TRK1__ok)cout<<"TRK1 ";
4979     // if(TRK2__ok)cout<<"TRK2 ";
4980     // if(TRKh__ok)cout<<"TRKH ";
4981     // if(CAL1__ok)cout<<"CAL1 ";
4982     // if(CAL2__ok)cout<<"CAL2 ";
4983     // if(TOF__ok)cout<<"TOF ";
4984     // if(TRG__ok)cout<<"TRG ";
4985     // if(AC__ok)cout<<"AC ";
4986     // if(ND__ok)cout<<"ND ";
4987     // if(S4__ok)cout<<"S4 ";
4988     // if(ORB__ok)cout<<"ORB ";
4989     // cout << endl;
4990    
4991    
4992     if (TRK2 && TRK1__ok)
4993     TRK1 = 1;
4994     // ----------------------------------------------------------------------------
4995     // NOTA
4996     // se c'e` il level1, lo devo necessarimente leggere.
4997     // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
4998     // comunque, ma non vengono disallocati da PamLevel2::Clear()
4999     // ----------------------------------------------------------------------------
5000    
5001    
5002     if (!RUN__ok) {
5003     cout << "File: " << f->GetName() << " *WARNING* ---- Missing RunInfo tree (NB: RUN infos will not be updated)"
5004     << endl;
5005     RUN = false;
5006     };
5007 pam-fi 1.20
5008 pam-fi 1.81 if (CAL1 && !CAL1__ok) {
5009     cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;
5010     return false;
5011     };
5012     if (CAL2 && !CAL2__ok) {
5013     cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;
5014     return false;
5015     };
5016     if (TRK2 && !TRK2__ok) {
5017     cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;
5018     return false;
5019     };
5020     if (TRK1 && !TRK1__ok) {
5021     cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;
5022     return false;
5023     };
5024     if (TRKh && !TRKh__ok) {
5025     cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;
5026     return false;
5027     };
5028     if (ORB && !ORB__ok) {
5029     cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;
5030     return false;
5031     };
5032     if (AC && !AC__ok) {
5033     cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;
5034     return false;
5035     };
5036     if (S4 && !S4__ok) {
5037     cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;
5038     return false;
5039     };
5040     if (TOF && !TOF__ok) {
5041     cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;
5042     return false;
5043     };
5044 pam-fi 1.8
5045 pam-fi 1.81 if (ND && !ND__ok) {
5046     cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;
5047     return false;
5048     };
5049     if (TRG && !TRG__ok) {
5050     cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;
5051     return false;
5052     };
5053     if (GP && !GP__ok) {
5054     cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;
5055     return false;
5056     };
5057 pam-fi 1.8
5058 pam-fi 1.81 // lk->Delete();
5059     // delete lk;
5060     f->Close();
5061    
5062     // cout<< "CheckLevel2File(TString): detector list --> ";
5063     // if(TRK1)cout<<"TRK1 ";
5064     // if(TRK2)cout<<"TRK2 ";
5065     // if(TRKh)cout<<"TRKH ";
5066     // if(CAL1)cout<<"CAL1 ";
5067     // if(CAL2)cout<<"CAL2 ";
5068     // if(TOF)cout<<"TOF ";
5069     // if(TRG)cout<<"TRG ";
5070     // if(AC)cout<<"AC ";
5071     // if(ND)cout<<"ND ";
5072     // if(S4)cout<<"S4 ";
5073     // if(ORB)cout<<"ORB ";
5074     // if(GP)cout<<"GP ";
5075     // cout << endl;
5076 pam-fi 1.8
5077 pam-fi 1.81 return true;
5078 pam-fi 1.2
5079 pam-fi 1.81 }
5080     ;
5081 pam-fi 1.2
5082 pam-fi 1.9 /**
5083     * Create clone-trees
5084     */
5085 pam-fi 1.81 void PamLevel2::CreateCloneTrees0(TChain *fChain, TFile *ofile) {
5086    
5087     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5088     cout << "Create clones of PAMELA trees " << endl;
5089 pam-fi 1.9
5090 pam-fi 1.81 Int_t i = 0;
5091     pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
5092     TString name = pam_tree_clone[i]->GetName();
5093     name.Append("_clone");
5094     // pam_tree_clone[i]->SetName(name.Data());
5095     cout << pam_tree_clone[i]->GetName() << endl;
5096     i++;
5097    
5098     TList *li = fChain->GetListOfFriends();
5099     TIter next(li);
5100     TFriendElement* T_friend = 0;
5101     ofile->cd();
5102     while ((T_friend = (TFriendElement*) next())) {
5103     // cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
5104     // cout<<T_friend->GetTree()->GetName()<< endl;
5105     pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
5106     pam_tree_clone[i]->SetAutoSave(1000000);
5107     name = pam_tree_clone[i]->GetName();
5108 pam-fi 1.9 name.Append("_clone");
5109 pam-fi 1.81 // pam_tree_clone[i]->SetName(name.Data());
5110     cout << pam_tree_clone[i]->GetName() << endl;
5111 pam-fi 1.9 i++;
5112 pam-fi 1.81 }
5113 pam-fi 1.9
5114 pam-fi 1.81 delete li;
5115 pam-fi 1.9
5116 pam-fi 1.81 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5117 pam-fi 1.9
5118     }
5119    
5120 pam-fi 1.11 /**
5121     * Create clone-trees
5122     */
5123 pam-fi 1.81 void PamLevel2::CreateCloneTrees(TFile *ofile) {
5124 pam-fi 1.11
5125 pam-fi 1.81 // if the pointer is null, create a default file
5126     if (!run_tree)
5127     return;
5128    
5129     if (!ofile) {
5130     cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root " << endl;
5131     ofile = new TFile("clone-tree.root", "recreate");
5132     }
5133    
5134     ofile->cd();
5135    
5136     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5137     cout << "Create new PAMELA trees " << endl;
5138    
5139     run_tree_clone = new TTree("Run", "PAMELA Level2 data from the GL_RUN table ");
5140     run_tree_clone->Branch("RunInfo", "GL_RUN", GetPointerTo("RunInfo"));
5141     cout << "Run : branch RunInfo" << endl;
5142     run_tree_clone->Branch("SoftInfo", "SoftInfo", GetPointerTo("SoftInfo"));
5143     cout << "Run : branch SoftInfo" << endl;
5144     // ------------------
5145     // replicate run tree
5146     // ------------------
5147     // cout << "----------------------------------------------------"<<endl;
5148     // cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
5149     for (Int_t i = 0; i < run_tree->GetEntries(); i++) {
5150     run_tree->GetEntry(i);
5151     // cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
5152     run_tree_clone->Fill();
5153     }
5154     cout << "----------------------------------------------------" << endl;
5155    
5156     // ------------------------------------
5157     // add branch with dead and live times
5158     // ------------------------------------
5159     if (SELLI != 2) { // EMILIANO
5160     run_tree_clone->Branch("DeadLiveTime", totdltime, "dltime[3]/l");
5161     cout << "Run : branch DeadLiveTime" << endl;
5162    
5163     sel_tree_clone = new TTree("SelectionList", "List of selected events ");
5164     // sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
5165     sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW
5166     sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L");
5167 mocchiut 1.91 // if ( hasL0EE ) sel_tree_clone->Branch("L0EventEntry", &il0entry, "l0eventry/L");
5168 pam-fi 1.81 };
5169 pam-fi 1.39
5170 pam-fi 1.81 Int_t i = 0;
5171     if (TRK1 || TRK2 || TRKh) {
5172     pam_tree_clone[i] = new TTree("Tracker", "PAMELA tracker level2 data ");
5173     if (TRK1) {
5174     pam_tree_clone[i]->Branch("TrkLevel1", "TrkLevel1", GetPointerTo("TrkLevel1"));
5175     pam_tree_clone[i]->BranchRef();
5176     cout << "Tracker : branch TrkLevel1" << endl;
5177     // cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
5178     };
5179     if (TRK2) {
5180     pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2", GetPointerTo("TrkLevel2"));
5181     cout << "Tracker : branch TrkLevel2" << endl;
5182     };
5183     if (TRKh) {
5184     pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));
5185     cout << "Tracker : branch TrkHough" << endl;
5186     };
5187 pam-ts 1.95 if(NUC){
5188     pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&trk_nuc_obj);
5189     cout << "Tracker : branch TrackNuclei" << endl;
5190     }
5191     if(EXT){
5192     pam_tree_clone[i]->Branch("extAlgFlag",&extAlgFlag,"extAlgFlag/I");
5193     pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&trk_ext_obj);
5194     cout << "Tracker : branch RecoveredTrack" << endl;
5195     if(NUC){
5196     pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&trk_ext_nuc_obj);
5197     cout << "Tracker : branch RecoveredTrackNuclei" << endl;
5198     }
5199     }
5200    
5201 pam-fi 1.81 i++;
5202     }
5203 pam-fi 1.39
5204 pam-fi 1.81 // Calorimeter
5205     if (CAL1 || CAL2) {
5206     pam_tree_clone[i] = new TTree("Calorimeter", "PAMELA calorimeter level2 data ");
5207     if (CAL1) {
5208     pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
5209     cout << "Calorimeter : branch CaloLevel1" << endl;
5210     };
5211     if (CAL2) {
5212     pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));
5213     cout << "Calorimeter : branch CaloLevel2" << endl;
5214 mocchiut 1.72 };
5215 pam-ts 1.95 if(NUC){
5216     pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&calo_nuc_obj);
5217     cout << "Calorimeter : branch TrackNuclei" << endl;
5218     }
5219     if(EXT){
5220     pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&calo_ext_obj);
5221     cout << "Calorimeter : branch RecoveredTrack" << endl;
5222     if(NUC){
5223     pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&calo_ext_nuc_obj);
5224     cout << "Calorimeter : branch RecoveredTrackNuclei" << endl;
5225     }
5226     }
5227 pam-fi 1.81 i++;
5228     }
5229 pam-fi 1.20
5230 pam-fi 1.81 // ToF
5231     if (TOF) {
5232     pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");
5233     pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));
5234     cout << "ToF : branch ToFLevel2" << endl;
5235 pam-ts 1.95 if(NUC){
5236     pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&tof_nuc_obj);
5237     cout << "ToF : branch TrackNuclei" << endl;
5238     }
5239     if(EXT){
5240     pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&tof_ext_obj);
5241     cout << "ToF : branch RecoveredTrack" << endl;
5242     if(NUC){
5243     pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&tof_ext_nuc_obj);
5244     cout << "ToF : branch RecoveredTrackNuclei" << endl;
5245     }
5246     }
5247 pam-fi 1.81 i++;
5248     };
5249     // Trigger
5250     if (TRG) {
5251     pam_tree_clone[i] = new TTree("Trigger", "PAMELA trigger level2 data ");
5252     pam_tree_clone[i]->Branch("TrigLevel2", "TrigLevel2", GetPointerTo("TrigLevel2"));
5253     cout << "Trigger : branch TrigLevel2" << endl;
5254     i++;
5255     };
5256     // S4
5257     if (S4) {
5258     pam_tree_clone[i] = new TTree("S4", "PAMELA S4 level2 data ");
5259     pam_tree_clone[i]->Branch("S4Level2", "S4Level2", GetPointerTo("S4Level2"));
5260     cout << "S4 : branch S4Level2" << endl;
5261     i++;
5262     };
5263     // Neutron Detector
5264     if (ND) {
5265     pam_tree_clone[i] = new TTree("NeutronD", "PAMELA neutron detector level2 data ");
5266     pam_tree_clone[i]->Branch("NDLevel2", "NDLevel2", GetPointerTo("NDLevel2"));
5267     cout << "NeutronD : branch NDLevel2" << endl;
5268     i++;
5269     };
5270     // Anticounters
5271     if (AC) {
5272     pam_tree_clone[i] = new TTree("Anticounter", "PAMELA anticounter detector level2 data ");
5273     pam_tree_clone[i]->Branch("AcLevel2", "AcLevel2", GetPointerTo("AcLevel2"));
5274     cout << "Anticounter : branch AcLevel2" << endl;
5275     i++;
5276     };
5277     // OrbitalInfo
5278     if (ORB) {
5279     pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info ");
5280     pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));
5281     cout << "OrbitalInfo : branch OrbitalInfo" << endl;
5282 pam-ts 1.95 if(NUC){
5283     pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&orb_nuc_obj);
5284     cout << "OrbitalInfo : branch TrackNuclei" << endl;
5285     }
5286     if(EXT){
5287     pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&orb_ext_obj);
5288     cout << "OrbitalInfo : branch RecoveredTrack" << endl;
5289     if(NUC){
5290     pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&orb_ext_nuc_obj);
5291     cout << "OrbitalInfo : branch RecoveredTrackNuclei" << endl;
5292     }
5293     }
5294 pam-fi 1.81 i++;
5295     };
5296     // GPamela
5297     if (GP) {
5298     pam_tree_clone[i] = new TTree("h20", "GPAMELA info ");
5299     pam_tree_clone[i]->Branch("GPamela", "GPamela", GetPointerTo("GPamela"), 32000, 1);//split
5300 pam-fi 1.88 cout << "GPamela : branch GPamela" << endl;
5301 pam-fi 1.81 i++;
5302     };
5303 pam-ts 1.95
5304    
5305 pam-fi 1.81 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5306 pam-fi 1.9
5307 pam-fi 1.11 }
5308 pam-fi 1.9
5309     /**
5310     * Fill tree (created with CreateCloneTrees)
5311     *
5312     */
5313     //void PamLevel2::FillNewPamTree(TTree *T){
5314 pam-fi 1.81 void PamLevel2::FillCloneTrees() {
5315    
5316     // cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
5317 pam-fi 1.24
5318 pam-fi 1.81 for (Int_t i = 0; i < NCLONES; i++) {
5319     if (pam_tree_clone[i])
5320     pam_tree_clone[i]->Fill();
5321     }
5322     if (sel_tree_clone)
5323     sel_tree_clone->Fill();
5324 pam-fi 1.21
5325 pam-fi 1.9 }
5326    
5327 pam-fi 1.81 TTree* PamLevel2::GetCloneTree(TString name) {
5328 pam-fi 1.9
5329 pam-fi 1.81 for (Int_t i = 0; i < NCLONES; i++) {
5330     if (pam_tree_clone[i]) {
5331     TString na = pam_tree_clone[i]->GetName();
5332     if (!name.CompareTo(na))
5333     return pam_tree_clone[i];
5334     };
5335     }
5336     if (run_tree_clone) {
5337     TString na = run_tree_clone->GetName();
5338     if (!name.CompareTo(na))
5339     return run_tree_clone;
5340     }
5341     if (sel_tree_clone) {
5342     TString na = sel_tree_clone->GetName();
5343     if (!name.CompareTo(na))
5344     return sel_tree_clone;
5345     }
5346     return NULL;
5347 pam-fi 1.9
5348     }
5349 pam-fi 1.81 void PamLevel2::WriteCloneTrees() {
5350     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5351     cout << "Write clones of PAMELA trees " << endl;
5352     cout << run_tree_clone->GetName() << endl;
5353     if (SELLI != 2) {// Emiliano
5354     if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
5355     run_tree_clone->GetBranch("DeadLiveTime")->Fill();
5356     };
5357     run_tree_clone->Write();
5358     if (SELLI != 2) { //Emiliano
5359     cout << sel_tree_clone->GetName() << endl;
5360     sel_tree_clone->Write();
5361     };
5362     for (Int_t i = 0; i < NCLONES; i++) {
5363     if (pam_tree_clone[i]) {
5364     cout << pam_tree_clone[i]->GetName() << endl;
5365     pam_tree_clone[i]->Write();
5366 mocchiut 1.72 };
5367 pam-fi 1.81 }
5368     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5369 pam-fi 1.9
5370     }
5371    
5372     /**
5373 pam-fi 1.24 * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
5374 pam-fi 1.9 */
5375 pam-fi 1.81 Int_t PamLevel2::GetEntry(Long64_t iee) {
5376    
5377     if (!pam_tree) {
5378     cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded" << endl;
5379     return 0;
5380     }
5381 mocchiut 1.28
5382 pam-fi 1.81 //
5383     // 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...
5384     //
5385     // if(!run_tree ){
5386     // cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
5387     // return 0;
5388     // }
5389    
5390     //-------------------------------
5391 mocchiut 1.90 if (!pam_tree->GetEntry(iee)) {
5392 pam-fi 1.81 cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree" << endl;
5393     return 0;
5394     }
5395     //
5396     // ... 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.
5397     // 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
5398     // a problem if you don't check the return code of getentry.
5399     //
5400     if (!RUN || !run_tree) {
5401     if (TRK0 || CAL0 || TOF0 || RUN) { //forse cosi` va bene per tornare 1?
5402     cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded" << endl;
5403 mocchiut 1.77 return 0;
5404 pam-fi 1.33 }
5405 pam-fi 1.81 else {
5406     return 1; //cosi` se non c'e` run esce qua...
5407     }
5408     }
5409    
5410     //-------------------------------
5411 mocchiut 1.90 //
5412     if ( fUpdateRunInfo ) UpdateRunInfo(iee); // Emiliano
5413     if (SELLI == 0 || SELLI == 2) irunentry = iee - runfirstentry;
5414 pam-fi 1.81
5415     return 1;
5416 pam-fi 1.20
5417     }
5418    
5419 pam-fi 1.81 TrkLevel0 *PamLevel2::GetTrkLevel0() {
5420     if (!TRK0)
5421     return NULL;
5422     if (!GetYodaEntry()) {
5423     cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree" << endl;
5424     return 0;
5425     }
5426     return trk0_obj;
5427     }
5428     ;
5429     CaloLevel0 *PamLevel2::GetCaloLevel0() {
5430     if (!CAL0)
5431     return NULL;
5432     if (!GetYodaEntry()) {
5433     cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree" << endl;
5434     return 0;
5435     }
5436     return calo0_obj;
5437     }
5438     ;
5439 pam-fi 1.40
5440 pam-fi 1.20 /**
5441     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
5442     * Given the run ID (...), if needed it query the DB and load the proper file.
5443     * @return Pointer to the tree
5444     */
5445    
5446 pam-fi 1.81 TTree* PamLevel2::GetYodaTree() {
5447 pam-fi 1.20
5448 pam-fi 1.81 // cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
5449     //===================================
5450     // check if iroot has changed
5451     //===================================
5452     if (irun < 0) {
5453     cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl;
5454 mocchiut 1.90 if (DBG) cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
5455 pam-fi 1.81 return NULL;
5456     }
5457 mocchiut 1.90 Int_t irootnew = GetRunInfo()->ID_ROOT_L0;
5458     if (DBG){
5459     cout << "iroot "<<iroot<<endl;
5460     cout << "irootnew "<<irootnew<<endl;
5461     }
5462 pam-fi 1.81
5463     //===================================
5464     // load the level0 file
5465     // (if not already loaded)
5466     //===================================
5467     if (iroot != irootnew || !l0_tree) {
5468     iroot = irootnew;
5469 pam-fi 1.20 //===================================
5470 pam-fi 1.81 // open the DB connection
5471     // (if not already opened)
5472 pam-fi 1.20 //===================================
5473 pam-fi 1.81 if (!dbc || (dbc && !dbc->IsConnected()))
5474     SetDBConnection();
5475     GL_ROOT glroot = GL_ROOT();
5476     if (glroot.Query_GL_ROOT(iroot, dbc)) {
5477     cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = " << iroot << " does not exists"
5478     << endl;
5479     return NULL;
5480     };
5481     TString filename = glroot.PATH + glroot.NAME;
5482     if (l0_file) {
5483     l0_file->Close();
5484     l0_file->Delete();
5485     }
5486     cout << "Opening LEVEL0 file: " << filename << endl;
5487     FileStat_t t;
5488     if (gSystem->GetPathInfo(filename.Data(), t)) {
5489     cout << " PamLevel2::GetYodaTree() -- ERROR opening file " << endl;
5490     return NULL;
5491     }
5492     l0_file = new TFile(filename);
5493     if (!l0_file)
5494     return NULL;
5495     l0_tree = (TTree*) l0_file->Get("Physics");
5496     if (!h0_obj)
5497     h0_obj = new EventHeader();
5498     l0_tree->SetBranchAddress("Header", &h0_obj);
5499 mocchiut 1.90 yprevshift = 0; // yes, yprevshift is the shift in the level0, prevshift is the shift in the level2
5500 pam-fi 1.81 //---------------------------------------------------
5501     // TRACKER:
5502     if (TRK0) {
5503     if (!trk0_obj) {
5504     trk0_obj = new TrkLevel0();
5505     trk0_obj->Set();
5506     };
5507     l0_tree->SetBranchAddress("Tracker", trk0_obj->GetPointerToTrackerEvent());
5508     }
5509     //--------------------------------------------------
5510     // CALORIMETER:
5511     if (CAL0) {
5512     if (!calo0_obj) {
5513     calo0_obj = new CaloLevel0();
5514     calo0_obj->Set();
5515     };
5516     l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent());
5517     }
5518     //---------------------------------------------------
5519     // TOF:
5520     if (TOF0) {
5521     cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented " << endl;
5522     }
5523 pam-fi 1.20
5524 pam-fi 1.81 dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
5525 pam-fi 1.87 delete dbc;
5526 mocchiut 1.82 dbc=0;
5527 mocchiut 1.51
5528 pam-fi 1.81 };
5529 mocchiut 1.51
5530 pam-fi 1.81 if (TRK0) {
5531 mocchiut 1.90 if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
5532 pam-fi 1.81 TrkParams::SetCalib(run_obj, dbc);
5533     TrkParams::LoadCalib();
5534     if (!TrkParams::CalibIsLoaded()) {
5535     cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded" << endl;
5536 pam-fi 1.20 };
5537 mocchiut 1.82 if(dbc){
5538     dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
5539 pam-fi 1.87 delete dbc;
5540 mocchiut 1.82 dbc=0;
5541     };
5542 pam-fi 1.81 }
5543     return l0_tree;
5544 pam-fi 1.20 }
5545 pam-fi 1.9
5546 pam-fi 1.20 /**
5547     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
5548     */
5549 pam-fi 1.81 Int_t PamLevel2::GetYodaEntry() {
5550    
5551 mocchiut 1.90 Long64_t iev = this->GetReadEntry();
5552 pam-fi 1.81
5553 mocchiut 1.90 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
5554     // if it is a full file (not preselected)
5555     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
5556 mocchiut 1.91 // if (SELLI == 0 || SELLI == 2 || !hasL0EE) {
5557 pam-fi 1.81
5558 mocchiut 1.90 if (!GetYodaTree()){
5559     printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n");
5560     return 0;
5561     }
5562 pam-fi 1.81
5563 mocchiut 1.90 if (irunentry < 0) {
5564     if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
5565     // cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI
5566     irunentry = 0LL;
5567     }
5568     // ---------------------------------
5569     // if file is NOT a preselected file
5570     // ---------------------------------
5571     Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry
5572    
5573     if (DBG){
5574     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5575     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5576     cout << " time "<< abstime << endl;
5577     }
5578    
5579     ULong64_t obt = 0;
5580     ULong64_t pktn = 0;
5581     if (GetOrbitalInfo()) {
5582     obt = GetOrbitalInfo()->OBT;
5583     pktn = GetOrbitalInfo()->pkt_num;
5584     }
5585 pam-fi 1.81
5586 mocchiut 1.90 if (!GetOrbitalInfo() && !ISGP) {
5587     cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl;
5588     return 0;
5589 pam-fi 1.81 }
5590 mocchiut 1.90 if (obt == 0 && pktn == 0 && !ISGP) {
5591     cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl;
5592 pam-fi 1.81 return 0;
5593     }
5594    
5595 mocchiut 1.90 // ---------------------------------------------------------------------
5596     // ATTENTION!!!
5597     // If data are not pre-processed with cleaner, the level0 tree may contain
5598     // spurious nested physics packets.
5599     // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
5600     // while level2 tree DOES NOT!!
5601     // This means that "quellagiusta" in these cases is not correct.
5602     // In order to retrieve the correct level0 event, I implemented a check
5603     // of the OBT and pkt-number. In case of mismatch, the level0 entry number
5604     // is shift forward until when the packets match.
5605     // ---------------------------------------------------------------------
5606     Long64_t shift = 0LL;
5607     Long64_t answer = quellagiusta + shift + yprevshift;
5608     Int_t readl0 = 0;
5609     readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry
5610    
5611     if (DBG){
5612     printf(" siamo qui shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5613     }
5614    
5615    
5616 pam-fi 1.81 if (ISGP) {
5617     obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
5618     pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
5619     }
5620    
5621 mocchiut 1.90 while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){
5622     if ( isSync && shift == 0LL ){
5623     printf(" PamLevel2::GetYodaEntry() ERROR! sync file but the level0 entry not found in place!!! \n");
5624     cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5625     cout << "\nFor bug reporting instructions, please see for example:\n";
5626     cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5627     cout << " " << endl;
5628     }
5629     if (shift > 0) {
5630 mocchiut 1.93 if (DBG) cout << " PKTNUM L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5631 mocchiut 1.90 if (DBG)
5632     cout << " RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5633     << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
5634     if (DBG)
5635     cout << " L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
5636     << " prevshift " << prevshift << " )" << endl;
5637     }
5638     answer = quellagiusta + shift+ yprevshift;
5639     readl0 = l0_tree->GetEntry(answer);
5640     // printf(" inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5641    
5642     if (!GetEventHeader()) {
5643     cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
5644     return 0;
5645     }
5646 pam-fi 1.81
5647 mocchiut 1.90 //
5648     if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {
5649     if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5650     // printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5651     yprevshift = 0LL;
5652     shift = -1LL;
5653     };
5654    
5655     shift++;
5656     }
5657    
5658 pam-fi 1.81
5659 mocchiut 1.90 if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){
5660     if ( isSync ){
5661     printf(" PamLevel2::GetYodaEntry() ERROR! sync file but the level0 entry not found AT ALL!!! \n");
5662     cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5663     cout << "\nFor bug reporting instructions, please see for example:\n";
5664     cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5665     cout << " " << endl;
5666     }
5667     cout << "Int_t PamLevel2::GetYodaEntry() -- WARNING -- " << endl;
5668     cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to " << maxshift << " )" << endl;
5669     cout << " Nested and/or DarthVader skipped packets in fragmented run? checking and trying to fix " <<endl;
5670     // query the DB for runs containing the event, loop over LEVEL0 files which could contain the level0 event and try to find it
5671     // ma nel mezzo del cammin per ogni run che pesco devo vedere la posizione relativa di iev rispetto al runheader nel livello2 per andare a cercare nel posto giusto
5672     // connect to db
5673     if (!dbc || (dbc && !dbc->IsConnected())) SetDBConnection(); //Emiliano
5674     //
5675     if (GetOrbitalInfo()){
5676     abstime = GetOrbitalInfo()->absTime;
5677     } else {
5678     printf(" PamLevel2::GetYodaEntry() ERROR! no OrbitalInfo, cannot get the absolute time for event \n");
5679     return 0;
5680     }
5681     // query DB looking for runs containing the processed event
5682     TSQLResult *pResult;
5683     TSQLRow *Row = NULL;
5684     TString myquery = Form("select ID,NEVENTS from GL_RUN where RUNHEADER_TIME<=%lld and RUNTRAILER_TIME>=%lld;",abstime,abstime);
5685     if ( DBG ) printf(" query is %s \n",myquery.Data());
5686     // printf(" query is %s \n",myquery.Data());// TOGLITOGLI
5687     pResult = dbc->Query(myquery.Data());
5688     if (!pResult->GetRowCount()){
5689     printf(" PamLevel2::GetYodaEntry() ERROR! event is not included in any run!!! \n");
5690     cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5691     cout << "\nFor bug reporting instructions, please see for example:\n";
5692     cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5693     cout << " " << endl;
5694     return 0;
5695     }
5696     if ( pResult->GetRowCount() == 1 ){
5697     if (DBG) printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");
5698     // printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");//TOGLITOGLI
5699     }
5700     for( Int_t ru=0; ru < pResult->GetRowCount(); ru++){ // loop over runs containing the event
5701     if (Row) delete Row;
5702     Row = pResult->Next();
5703     if( Row == NULL ) break;
5704     UInt_t idrun = (UInt_t)atoll(Row->GetField(0));
5705     UInt_t nev = (UInt_t)atoll(Row->GetField(1));
5706     if (DBG) printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);
5707     // printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);//TOGLITOGLI
5708    
5709     // now look for this run in the level2 file, it must be present! code is taken from updateruninfo of course
5710     Bool_t rfound = false;
5711     totrunentry = 0LL;
5712     runfirstentry = 0LL;
5713     for (Int_t r=0; r< run_tree->GetEntries();r++){
5714     run_tree->GetEntry(r);//update runinfo
5715     if ( r > 0 ){
5716     totrunentrymin = totrunentrymax+1;
5717     } else {
5718     totrunentrymin = 0LL;
5719     }
5720     totrunentry += GetRunInfo()->NEVENTS;
5721     totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
5722     irun = r;
5723    
5724     if (idrun == GetRunInfo()->ID){
5725     if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
5726     if (DBG) printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n");
5727     if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
5728     // printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n");
5729     // printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
5730     prevshift += (totrunentrymin-iev); // add the new shift to total shift
5731     totrunentrymin -= (totrunentrymin-iev); // shift run position min
5732     totrunentrymax -= (totrunentrymin-iev); // shift run position max
5733     if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
5734     // printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
5735     }
5736     runfirstentry = totrunentrymin; // first entry of the run in the level2
5737    
5738 pam-fi 1.81
5739 mocchiut 1.90 //
5740     if (gltsync)
5741     delete gltsync; // Emiliano
5742     if (!dbc || (dbc && !dbc->IsConnected()))
5743     SetDBConnection(); //Emiliano
5744     gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
5745     if (dbc){
5746     dbc->Close(); // Emiliano
5747     delete dbc;
5748     dbc=0;
5749     }
5750     if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
5751     cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
5752     << " has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
5753     cout
5754     << " (NB!! in this case some events could be assigned to a wrong run)"
5755     << endl;
5756     }
5757     //
5758     if (DBG) printf(" found \n");
5759     // printf(" found \n");//TOGLITOGLI
5760     rfound = true;
5761     //
5762     break;
5763     }
5764     } // loop over run
5765     if ( !rfound ){
5766     printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level2 file!!! \n");
5767     cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5768     cout << "\nFor bug reporting instructions, please see for example:\n";
5769     cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5770     cout << " " << endl;
5771     return 0;
5772     }
5773 pam-fi 1.9
5774 mocchiut 1.90 // here we got the first run and we can check if it contains the level0 event
5775     if (!GetYodaTree()){
5776     printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n");
5777     return 0;
5778     }
5779    
5780     // get the current run entry
5781     irunentry = iev - runfirstentry;
5782     if (irunentry < 0) {
5783     if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
5784     // cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI
5785     irunentry = 0LL;
5786     }
5787     // ---------------------------------
5788     // if file is NOT a preselected file
5789     // ---------------------------------
5790     quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry
5791    
5792     if (DBG){
5793     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5794     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5795     cout << " time "<< abstime << endl;
5796     }
5797     // cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5798     // cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5799     // cout << " time "<< abstime << endl; // TOGLITOGLI
5800    
5801     shift = 0;
5802     answer = quellagiusta + shift + yprevshift; // prevshift already included in irunentry
5803     readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry
5804    
5805     if (DBG){
5806     printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5807     }
5808     // printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5809    
5810     while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){
5811     if (shift > 0) {
5812 mocchiut 1.93 if (DBG) cout << " PKTNUM L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5813 mocchiut 1.90 if (DBG)
5814     cout << " RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5815     << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
5816     if (DBG)
5817     cout << " L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
5818     << " prevshift " << prevshift << " )" << endl;
5819     }
5820     answer = quellagiusta + shift+ yprevshift;
5821     readl0 = l0_tree->GetEntry(answer);
5822     // printf(" inside inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5823    
5824     if (!GetEventHeader()) {
5825     cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
5826     return 0;
5827     }
5828     //
5829     if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {
5830     if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5831     // printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5832     yprevshift = 0;
5833     shift = -1;
5834     };
5835    
5836     shift++;
5837     }
5838    
5839     if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){
5840     //still not the good run... continue with the nex one!
5841     printf("still not the good run... continue with the nex one!\n");
5842     } else {
5843     if (DBG) cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
5844     // cout << "LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;//TOGLITOGLI
5845     if (shift > 1) yprevshift = (shift - 1);
5846     if (Row) delete Row;
5847     delete pResult;
5848     if (dbc){
5849     dbc->Close(); // Emiliano
5850     delete dbc;
5851     dbc=0;
5852     }
5853     il0entry = answer;
5854     return readl0;
5855     }
5856     // perhaps it is all
5857     }// loop over runs containing the event
5858     if (Row) delete Row;
5859     delete pResult;
5860     if (dbc){
5861     dbc->Close(); // Emiliano
5862     delete dbc;
5863     dbc=0;
5864     }
5865     // arriving here it means no run found, cannot be! error!
5866     printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level0 files!!! \n");
5867     cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5868     cout << "\nFor bug reporting instructions, please see for example:\n";
5869     cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5870     cout << " " << endl;
5871     return 0;
5872     } else {
5873     if (DBG) cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;
5874     // cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;
5875     // printf("obt %lld (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) %i pktn %lld (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter() %i \n",obt,(UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()), pktn, (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) );
5876     if (shift > 1) yprevshift = (shift - 1);
5877     il0entry = answer;
5878     return readl0;
5879     }
5880    
5881 mocchiut 1.91 /* } // if selli 0 || 2
5882 mocchiut 1.90 if ( SELLI == 1 && hasL0EE ){
5883     sel_tree->GetEntry(iev);
5884     Long64_t answer = il0entry;
5885     Int_t readl0 = 0;
5886     readl0 = l0_tree->GetEntry(answer);
5887     return readl0;
5888 mocchiut 1.91 }*/
5889 mocchiut 1.90 printf(" PamLevel2::GetYodaEntry() ERROR! \n");
5890     cout << " Entry not found! OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5891     cout << "\nFor bug reporting instructions, please see for example:\n";
5892     cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5893     cout << " " << endl;
5894     return 0;
5895 pam-fi 1.20 }
5896 mocchiut 1.90
5897 pam-fi 1.40 /**
5898     * \Brief Set DB connection
5899     */
5900 pam-fi 1.81 Bool_t PamLevel2::SetDBConnection() {
5901 mocchiut 1.30
5902 pam-fi 1.81 // cout << "PamLevel2::SetDBConnection()" << endl;
5903     if (DBG) {
5904     cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
5905     cout << "Connecting to DB" << endl;
5906     cout << "HOST " << host << endl;
5907     cout << "USER " << user << endl;
5908     cout << "PSW " << psw << endl;
5909     }
5910 mocchiut 1.82 Bool_t notconn = true;
5911     Int_t trials = 0;
5912     while ( notconn && trials < 10 ){
5913     // gSystem->Sleep(500);
5914     dbc = TSQLServer::Connect(host.Data(), user.Data(), psw.Data());
5915     //dbc->Connect(host.Data(), user.Data(), psw.Data());
5916     if ( dbc ) notconn = false;
5917     if (DBG) printf("<%i> test connection...\n ",trials);
5918     if (!dbc){
5919     if (DBG) printf(" :( failed, no pointer \n");
5920     notconn = true;
5921     // return false;
5922     };
5923     if (dbc && !dbc->IsConnected()){
5924     if (DBG) printf(" :( failed, no connection \n");
5925     notconn = true;
5926     // return false;
5927     };
5928     trials++;
5929     };
5930     if ( notconn ) return false;
5931     //
5932     if (DBG) printf("=connected!\n");
5933 pam-fi 1.81 stringstream myquery; // EMILIANO
5934     myquery.str(""); // EMILIANO
5935     myquery << "SET time_zone='+0:00'"; // EMILIANO
5936     dbc->Query(myquery.str().c_str()); // EMILIANO
5937 mocchiut 1.82 if ( DBG ) printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
5938 pam-fi 1.81 return true;
5939 mocchiut 1.30
5940 pam-fi 1.40 }
5941 pam-fi 1.45
5942     /**
5943     * \Brief Add a friend to the pamela chain.
5944     * @param cname name of the chain to be added
5945     */
5946    
5947 pam-fi 1.81 TChain* PamLevel2::AddFriend(TString cname) {
5948 pam-fi 1.45
5949 pam-fi 1.81 if (!GetPamTree()) {
5950     cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first" << endl;
5951     return NULL;
5952     }
5953 pam-fi 1.45
5954 pam-fi 1.81 TChain *c = new TChain(cname.Data());
5955 pam-fi 1.45
5956 pam-fi 1.81 TIter next(GetPamTree()->GetListOfFiles());
5957     Int_t nf = 0;
5958     TChainElement* element = 0;
5959     while ((element = (TChainElement*) next())) {
5960     c->Add(element->GetTitle());
5961     nf++;
5962     }
5963 pam-fi 1.45
5964 pam-fi 1.81 GetPamTree()->AddFriend(cname.Data());
5965 pam-fi 1.45
5966 pam-fi 1.81 cout << "external chain created and added to pamela friends :" << cname << endl;
5967     cout << "n.files " << nf << endl;
5968 pam-fi 1.45
5969 pam-fi 1.81 return c;
5970 pam-fi 1.45
5971 pam-fi 1.81 }
5972 pam-fi 1.45
5973 pam-fi 1.81 /**
5974     * Returns the current read entry. This method simply returns the result of the call to
5975     * pam_tree->GetReadEntry(), so it is entirely handled by ROOT.
5976     */
5977     Long64_t PamLevel2::GetReadEntry() {
5978     return pam_tree->GetReadEntry();
5979 pam-fi 1.45 }
5980 pam-fi 1.52
5981 pam-fi 1.81 /**
5982     * Sets the sorting method. If the new method is different from the previous, the issorted
5983     * flag is set to false, forcing a new sort the next time GetTrack is called.
5984     * @see GetTrack
5985     */
5986     void PamLevel2::SetSortingMethod(TString how) {
5987     if (howtosort != how) {
5988     issorted = false;
5989 pam-ts 1.95 issorted_new = false;
5990 pam-fi 1.81 }
5991     howtosort = how;
5992     }

  ViewVC Help
Powered by ViewVC 1.1.23