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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.30 - (hide annotations) (download)
Sun Mar 18 20:25:54 2007 UTC (17 years, 8 months ago) by mocchiut
Branch: MAIN
Changes since 1.29: +31 -10 lines
Calorimeter level0 fecthing added, minor bugs in the spurious packet handling fixed

1 pam-fi 1.1 #include <PamLevel2.h>
2     //--------------------------------------
3     //
4     //
5     //--------------------------------------
6     /**
7     * Default constructor
8     */
9     PamTrack::PamTrack(){
10 pam-fi 1.13 trk_track = 0;
11     calo_track = 0;
12     tof_track = 0;
13     candeleteobj = 0;
14 pam-fi 1.1 };
15     //--------------------------------------
16     //
17     //
18     //--------------------------------------
19     /**
20     * Constructor
21     */
22     PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){
23 pam-fi 1.13
24     trk_track = 0;
25     calo_track = 0;
26     tof_track = 0;
27     // if(t)trk_track = new TrkTrack(*t);
28     // if(c)calo_track = new CaloTrkVar(*c);
29     // if(o)tof_track = new ToFTrkVar(*o);
30     if(t)trk_track = t;
31     if(c)calo_track = c;
32     if(o)tof_track = o;
33     candeleteobj = 0;
34    
35 pam-fi 1.1 };
36 pam-fi 1.13 PamTrack::PamTrack(const PamTrack& track){
37    
38     TrkTrack *t = track.trk_track;
39     CaloTrkVar *c = track.calo_track;
40     ToFTrkVar *o = track.tof_track;
41    
42     trk_track = 0;
43     calo_track = 0;
44     tof_track = 0;
45     if(t)trk_track = new TrkTrack(*t);
46     if(c)calo_track = new CaloTrkVar(*c);
47     if(o)tof_track = new ToFTrkVar(*o);
48     candeleteobj = 1;
49    
50     }
51     void PamTrack::Clear(){
52 pam-fi 1.1
53 pam-fi 1.13 // cout << "PamTrack::Clear() "<<candeleteobj<<endl;
54     if(candeleteobj){
55     if(trk_track) trk_track->TrkTrack::Clear();
56     if(calo_track) calo_track->CaloTrkVar::Clear();//???
57     if(tof_track) tof_track->ToFTrkVar::Clear();//???
58     }else{
59     trk_track = 0;
60     calo_track = 0;
61     tof_track = 0;
62     }
63     }
64     void PamTrack::Delete(){
65     // cout << "PamTrack::Delete() "<<candeleteobj<<endl;
66     if(candeleteobj){
67     if(trk_track) {
68     trk_track->TrkTrack::Clear();
69     delete trk_track;
70     }
71     if(calo_track){
72     calo_track->CaloTrkVar::Clear();//???
73     delete calo_track;
74     }
75     if(tof_track){
76     tof_track->ToFTrkVar::Clear();//???
77     delete tof_track;
78     }
79     }else{
80     Clear();
81     }
82     }
83 pam-fi 1.1 //--------------------------------------
84     //
85     //
86     //--------------------------------------
87     /**
88     * Constructor
89     */
90     PamLevel2::PamLevel2(){
91 pam-fi 1.2
92 pam-fi 1.13 // trk2_obj = TrkLevel2::GetTrkLevel2();
93     // trk1_obj = TrkLevel1::GetTrkLevel1();
94     // trkh_obj = TrkHough::GetTrkHough();
95     // calo1_obj = CaloLevel1::GetCaloLevel1();
96     // calo2_obj = CaloLevel2::GetCaloLevel2();
97     // tof_obj = ToFLevel2::GetToFLevel2();
98     // trig_obj = TrigLevel2::GetTrigLevel2();
99     // s4_obj = S4Level2::GetS4Level2();
100     // nd_obj = NDLevel2::GetNDLevel2();
101     // ac_obj = AcLevel2::GetAcLevel2();
102     // orb_obj = OrbitalInfo::GetOrbitalInfo();
103 pam-fi 1.20
104     h0_obj = 0;
105     trk0_obj = 0;
106 mocchiut 1.30 calo0_obj = 0;
107 pam-fi 1.20
108 pam-fi 1.13 trk2_obj = 0;
109     trk1_obj = 0;
110     trkh_obj = 0;
111     calo1_obj = 0;
112     calo2_obj = 0;
113     tof_obj = 0;
114     trig_obj = 0;
115     s4_obj = 0;
116     nd_obj = 0;
117     ac_obj = 0;
118     orb_obj = 0;
119    
120     run_obj = 0;//new GL_RUN();
121 mocchiut 1.15 soft_obj = 0;// Emiliano
122 mocchiut 1.17 irun = -1;
123     runfirstentry = 0ULL;
124     runlastentry = 0ULL;
125 pam-fi 1.9
126 pam-fi 1.20 l0_file = NULL;
127     l0_tree = NULL;
128     iroot = -1;
129     dbc = 0;
130 mocchiut 1.30
131     prevshift = 0;
132 pam-fi 1.20
133     irun = -1;
134     run_tree = NULL;
135     run_tree_clone = NULL;
136     sel_tree = NULL;
137     sel_tree_clone = NULL;
138    
139     irunentry = -1;
140     pam_tree = NULL;
141     for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
142    
143     host = "mysql://localhost/pamelaprod";
144     user = "anonymous";
145     psw = "";
146     const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
147     const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
148     const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
149     if ( !pamdbhost ) pamdbhost = "";
150     if ( !pamdbuser ) pamdbuser = "";
151     if ( !pamdbpsw ) pamdbpsw = "";
152     if ( strcmp(pamdbhost,"") ) host = pamdbhost;
153     if ( strcmp(pamdbuser,"") ) user = pamdbuser;
154     if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
155    
156    
157 pam-fi 1.9
158 pam-fi 1.13 // sorted_tracks = 0;//new TRefArray();
159 pam-fi 1.6
160 pam-fi 1.20 CAL0 = false;
161 pam-fi 1.9 CAL1 = true;
162 pam-fi 1.8 CAL2 = true;
163     TRK2 = true;
164     TRK1 = false;
165     TRKh = false;
166 pam-fi 1.20 TRKh = false;
167     TRG = true;
168     TOF = true;
169     TOF0 = false;
170     S4 = true;
171     ND = true;
172     AC = true;
173     ORB = true;
174 pam-fi 1.6
175 pam-fi 1.20 RUN = true;
176    
177     SELLI = -1;
178 pam-fi 1.8
179 pam-fi 1.13 tsorted=0;
180     timage=0;
181    
182 pam-fi 1.2 };
183     /**
184 pam-fi 1.13 * Delete the event (act as Dtor)
185 pam-fi 1.2 */
186 pam-fi 1.13 void PamLevel2::Delete(){
187    
188     if(run_obj)delete run_obj;
189 mocchiut 1.15 if(soft_obj)delete soft_obj; //Emiliano
190 pam-fi 1.13
191     // cout << "void PamLevel2::Clear()"<<endl;
192 pam-fi 1.20 if(h0_obj) delete h0_obj;
193     if(trk0_obj) delete trk0_obj;
194 mocchiut 1.30 if(calo0_obj) delete calo0_obj;
195 pam-fi 1.13 if(trk1_obj) delete trk1_obj;
196     if(trk2_obj) delete trk2_obj;
197     if(trkh_obj) delete trkh_obj;
198     if(calo1_obj)delete calo1_obj;
199     if(calo2_obj)delete calo2_obj;
200     if(tof_obj) delete tof_obj;
201     if(trig_obj) delete trig_obj;
202     if(s4_obj) delete s4_obj;
203     if(nd_obj) delete nd_obj;
204     if(ac_obj) delete ac_obj;
205     if(orb_obj) delete orb_obj;
206    
207     if(tsorted){
208     tsorted->Delete();
209     delete tsorted;
210     }
211     if(timage){
212     timage->Delete();
213     delete timage;
214     }
215 pam-fi 1.20
216     if(dbc){
217     dbc->Close();
218     delete dbc;
219     }
220    
221     if(l0_file)l0_file->Close();
222     if(pam_tree)pam_tree->Delete();;
223     if(run_tree)run_tree->Delete();;
224     if(sel_tree)sel_tree->Delete();;
225     for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
226     if(run_tree_clone)run_tree_clone->Delete();;
227     if(sel_tree_clone)sel_tree_clone->Delete();;
228    
229    
230 pam-fi 1.2 };
231 pam-fi 1.13
232 pam-fi 1.2 /**
233 pam-fi 1.13 * Clear the event (NB! does not deallocate objects)
234 pam-fi 1.2 */
235     void PamLevel2::Clear(){
236 pam-fi 1.3
237 pam-fi 1.13 // cout << "void PamLevel2::Clear()"<<endl;
238 mocchiut 1.15
239     //
240 mocchiut 1.17 // This method is called once for every entry but RunInfo and SoftInfo do not change until the next run so we cannot clear them here unless we don't
241     // want to load them for each event even if they are the same...
242     //
243 mocchiut 1.15 // if(run_obj)delete run_obj;
244 mocchiut 1.17 // if(run_obj) run_obj->Clear(); // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
245     // if(soft_obj) soft_obj->Clear();
246 pam-fi 1.13
247 pam-fi 1.20 if(h0_obj) h0_obj->Clear();
248     if(trk0_obj) trk0_obj->Clear();
249 mocchiut 1.30 if(calo0_obj) calo0_obj->Clear();
250 pam-fi 1.13 if(trk1_obj) trk1_obj->Clear();
251     if(trk2_obj) trk2_obj->Clear();
252     if(trkh_obj) trkh_obj->Clear();
253     if(calo1_obj)calo1_obj->Clear();
254     if(calo2_obj)calo2_obj->Clear();
255     if(tof_obj) tof_obj->Clear();
256     if(trig_obj) trig_obj->Clear();
257     if(s4_obj) s4_obj->Clear();
258     if(nd_obj) nd_obj->Clear();
259     if(ac_obj) ac_obj->Clear();
260     if(orb_obj) orb_obj->Clear();
261 pam-fi 1.6
262 pam-fi 1.13 // if(sorted_tracks)sorted_tracks->Clear();
263     // sorted_tracks.Clear();
264    
265     if(tsorted){
266     tsorted->Delete();
267     }
268     if(timage){
269     timage->Delete();
270     }
271 pam-fi 1.6
272 pam-fi 1.1 };
273 pam-fi 1.2
274    
275 pam-fi 1.1 //--------------------------------------
276     //
277     //
278     //--------------------------------------
279 pam-fi 1.9 void *PamLevel2::GetPointerTo(const char* c ){
280    
281     TString objname = c;
282 pam-fi 1.13
283     if(!objname.CompareTo("TrkLevel1")) {
284 pam-fi 1.14 if(!trk1_obj){
285     trk1_obj = new TrkLevel1();
286     trk1_obj->Set();
287     }
288 pam-fi 1.13 return &trk1_obj;
289     };
290     if(!objname.CompareTo("TrkLevel2")) {
291 pam-fi 1.14 if(!trk2_obj){
292     trk2_obj = new TrkLevel2();
293     trk2_obj->Set();
294     }
295 pam-fi 1.13 return &trk2_obj;
296     };
297     if(!objname.CompareTo("TrkHough")) {
298     if(!trkh_obj) trkh_obj = new TrkHough();
299     return &trkh_obj;
300     };
301     if(!objname.CompareTo("CaloLevel1")) {
302     if(!calo1_obj) calo1_obj = new CaloLevel1();
303     return &calo1_obj;
304     };
305     if(!objname.CompareTo("CaloLevel2")) {
306 pam-fi 1.14 if(!calo2_obj){
307     calo2_obj = new CaloLevel2();
308     calo2_obj->Set();
309     };
310 pam-fi 1.13 return &calo2_obj;
311     };
312     if(!objname.CompareTo("ToFLevel2")) {
313 pam-fi 1.14 if(!tof_obj){
314     tof_obj = new ToFLevel2();
315     tof_obj->Set();
316     }
317 pam-fi 1.13 return &tof_obj;
318     };
319     if(!objname.CompareTo("TrigLevel2")) {
320     if(!trig_obj) trig_obj = new TrigLevel2();
321     return &trig_obj;
322     };
323     if(!objname.CompareTo("S4Level2")) {
324     if(!s4_obj) s4_obj = new S4Level2();
325     return &s4_obj;
326     };
327     if(!objname.CompareTo("NDLevel2")) {
328     if(!nd_obj) nd_obj = new NDLevel2();
329     return &nd_obj;
330     };
331     if(!objname.CompareTo("AcLevel2")) {
332     if(!ac_obj) ac_obj = new AcLevel2();
333     return &ac_obj;
334     };
335     if(!objname.CompareTo("OrbitalInfo")){
336     if(!orb_obj) orb_obj = new OrbitalInfo();
337     return &orb_obj;
338     };
339    
340 pam-fi 1.9 if(!objname.CompareTo("RunInfo"))return &run_obj;
341 mocchiut 1.15
342     if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
343    
344 pam-fi 1.9 return NULL;
345     };
346     //--------------------------------------
347     //
348     //
349     //--------------------------------------
350 pam-fi 1.1 /**
351 pam-fi 1.3 * Retrieves the calorimeter track matching the seqno-th tracker stored track.
352     * (If seqno = -1 retrieves the self-trigger calorimeter track)
353     */
354     CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
355 pam-fi 1.13
356     if( !calo2_obj )return 0;
357    
358     if( calo2_obj->CaloLevel2::ntrk()==0 ){
359 pam-fi 1.6 cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
360     return NULL;
361     };
362    
363     CaloTrkVar *c = 0;
364     Int_t it_calo=0;
365    
366     do{
367 pam-fi 1.13 c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
368 pam-fi 1.6 it_calo++;
369 pam-fi 1.13 } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());
370 pam-fi 1.6
371     if(!c || seqno != c->trkseqno){
372     c = 0;
373     if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
374     };
375     return c;
376    
377 pam-fi 1.3 };
378     //--------------------------------------
379     //
380     //
381     //--------------------------------------
382     /**
383     * Retrieves the ToF track matching the seqno-th tracker stored track.
384     * (If seqno = -1 retrieves the tracker-independent tof track)
385     */
386     ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
387    
388 pam-fi 1.13 if( !tof_obj )return 0;
389    
390     if( tof_obj->ToFLevel2::ntrk()==0 ){
391 pam-fi 1.6 cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
392     return NULL;
393     };
394    
395     ToFTrkVar *c = 0;
396     Int_t it_tof=0;
397    
398     do{
399 pam-fi 1.13 c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
400 pam-fi 1.6 it_tof++;
401 pam-fi 1.13 } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
402 pam-fi 1.6
403     if(!c || seqno != c->trkseqno){
404     c = 0;
405     if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
406     };
407     return c;
408    
409 pam-fi 1.3 };
410    
411     //--------------------------------------
412     //
413     //
414     //--------------------------------------
415     /**
416     * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.
417     */
418     PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
419 pam-fi 1.13
420     cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
421     cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
422    
423 pam-fi 1.6 CaloTrkVar *c = 0;
424     ToFTrkVar *o = 0;
425    
426 pam-fi 1.8 if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
427 pam-fi 1.6 if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
428    
429 pam-fi 1.3 // if(t && c && o)track = new PamTrack(t,c,o);
430 pam-fi 1.6 PamTrack *track = new PamTrack(t,c,o);
431    
432     return track;
433 pam-fi 1.3
434     };
435     //--------------------------------------
436     //
437     //
438     //--------------------------------------
439     /**
440 pam-fi 1.1 * Retrieves the it-th stored track.
441     * It override TrkLevel2::GetTrack(int it).
442     * @param itrk Track number, ranging from 0 to GetNTracks().
443     */
444    
445     PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
446    
447 pam-fi 1.13 cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
448     cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;
449     cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
450 pam-fi 1.6 PamTrack *track = 0;
451    
452 pam-fi 1.13 if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){
453 pam-fi 1.3
454 pam-fi 1.13 TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
455 pam-fi 1.6 track = GetPamTrackAlong(t);
456 pam-fi 1.2
457 pam-fi 1.13
458    
459 pam-fi 1.6 }else{
460 pam-fi 1.13 cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
461 pam-fi 1.6 };
462    
463     return track;
464    
465 pam-fi 1.1 }
466     //--------------------------------------
467     //
468     //
469     //--------------------------------------
470     /**
471 pam-fi 1.3 * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is PamLevel2::sorted_tracks.
472     * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
473     * Sorting cryteria:
474 pam-fi 1.8 * TRK: lower chi**2
475 pam-fi 1.3 * CAL: lower Y spatial residual on the first calorimeter plane
476     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
477     * The default sorting cryterium is "TOF+CAL".
478     *
479     * 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).
480 pam-fi 1.1 */
481 pam-fi 1.3 void PamLevel2::SortTracks(TString how){
482 pam-fi 1.1
483 pam-fi 1.13 // cout <<" PamLevel2::SortTracks(TString how) "<<endl;
484     if( !trk2_obj ){
485     cout << "void PamLevel2::SortTracks(TString how): TrkLevel2 not loaded !!!";
486     return;
487     };
488 pam-fi 1.9 // cout << "call SortTracs() "<<endl;
489 pam-fi 1.4 //Save current Object count
490 pam-fi 1.6 Int_t ObjectNumber = TProcessID::GetObjectCount();
491 pam-fi 1.9
492     // cout << "ObjectNumber "<<ObjectNumber <<endl;
493 pam-fi 1.13
494     // if(!sorted_tracks)sorted_tracks = new TRefArray();
495     // sorted_tracks->Clear();
496     // sorted_tracks.Clear();
497    
498     if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
499     tsorted->Delete();
500     TClonesArray &ttsorted = *tsorted;
501     if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
502     timage->Delete();
503     TClonesArray &ttimage = *timage;
504    
505    
506 pam-fi 1.6 // loop over the tracks sorted by the tracker
507     Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
508     Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
509     Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
510    
511 pam-fi 1.8 if( !CAL2 && use_CAL) use_CAL = false;
512 pam-fi 1.6 if( !TOF && use_TOF) use_TOF = false;
513    
514 pam-fi 1.8 if( !TRK2 ){
515 pam-fi 1.9 // cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
516 pam-fi 1.6 return;
517     };
518 pam-fi 1.9
519     // cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
520 pam-fi 1.6
521 pam-fi 1.13 for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
522 pam-fi 1.4
523 pam-fi 1.13 TrkTrack *ts = 0;
524     CaloTrkVar *cs = 0;
525     ToFTrkVar *os = 0;
526 pam-fi 1.3
527 pam-fi 1.1 // get tracker tracks
528 pam-fi 1.13 TrkTrack *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
529     CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
530     ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo());
531    
532     TrkTrack *ti = 0; //tracker (image)
533     CaloTrkVar *ci = 0;
534     ToFTrkVar *oi = 0;
535 pam-fi 1.9 // cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
536 pam-fi 1.1 // if track has an image, check image selection
537 pam-fi 1.6 if(tp->HasImage()){
538    
539 pam-fi 1.13 ti = trk2_obj->TrkLevel2::GetTrackImage(i); //tracker (image)
540     ci = GetCaloStoredTrack(ti->GetSeqNo());
541     oi = GetToFStoredTrack(ti->GetSeqNo());
542 pam-fi 1.6
543 pam-fi 1.9 // cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
544    
545 pam-fi 1.1 //assign starting scores
546 pam-fi 1.6 Int_t tp_score = 0; //main track sorted by the tracker
547     Int_t ti_score = 0; //image track
548    
549 pam-fi 1.1 // ------------------------
550     // calorimeter check
551     // ------------------------
552 pam-fi 1.6 // check the Y spatial residual on the first calorimeter plane
553     // (cut on calorimeter variables from Emiliano)
554 pam-fi 1.13 if( use_CAL && !calo2_obj ){
555     cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but CaloLevel2 not loaded !!!";
556     return;
557     };
558 pam-fi 1.6 if(
559     use_CAL &&
560 pam-fi 1.13 calo2_obj->npcfit[1] > 15 && //no. of fit planes on Y view
561     calo2_obj->varcfit[1] < 1000. && //fit variance on Y view
562 pam-fi 1.26 cp && ci &&
563 pam-fi 1.6 true){
564 pam-fi 1.9
565 pam-fi 1.6
566 pam-fi 1.13 Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;
567     Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;
568 pam-fi 1.6
569     if(resy_p <= resy_i) tp_score++;
570     else ti_score++;
571 pam-fi 1.9
572     // cout << "CALO "<<tp_score<<ti_score<<endl;
573    
574 pam-fi 1.6 };
575 pam-fi 1.1 // ------------------------
576     // TOF check
577     // ------------------------
578 pam-fi 1.6 // check the number of hit pmts along the track
579     // on S12 S21 and S32, where paddles are parallel to Y axis
580 pam-fi 1.13 if( use_TOF && !tof_obj ){
581     cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";
582     return;
583     };
584 pam-fi 1.26 if( use_TOF && op && oi ){
585 pam-fi 1.6
586     Int_t nphit_p =0;
587     Int_t nphit_i =0;
588    
589    
590 pam-fi 1.5 /* cout << "track: npmtadc "<< op->npmtadc << endl;
591     cout << "track: npmttdc "<< op->npmttdc << endl;
592     cout << "image: npmtadc "<< oi->npmtadc << endl;
593     cout << "image: npmttdc "<< oi->npmttdc << endl;*/
594 pam-fi 1.6
595     for (Int_t ih=0; ih < op->npmtadc; ih++){
596 pam-fi 1.13 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
597 pam-fi 1.6 if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
598     };
599    
600     for (Int_t ih=0; ih < oi->npmtadc; ih++){
601 pam-fi 1.13 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
602 pam-fi 1.6 if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
603     };
604    
605     if(
606     use_TOF &&
607     (nphit_p+nphit_i) !=0 &&
608     true){
609    
610     if( nphit_p >= nphit_i) tp_score++;
611     else ti_score++;
612     };
613 pam-fi 1.9 // cout << "TOF "<<tp_score<<ti_score<<endl;
614 pam-fi 1.6 };
615     if(tp_score == ti_score) use_TRK = true;
616     // ------------------------
617 pam-fi 1.3 // tracker check
618     // ------------------------
619 pam-fi 1.6 // chi**2 difference is not always large enough to distinguish among
620     // the real track and its image.
621     // Tracker check will be applied always when calorimeter and tof information is ambiguous.
622     if(use_TRK){
623     if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
624     else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
625 pam-fi 1.9 // cout << "TRK "<<tp_score<<ti_score<<endl;
626 pam-fi 1.6 };
627    
628 pam-fi 1.1 // ------------------------
629     // the winner is....
630     // ------------------------
631 pam-fi 1.13 if (tp_score > ti_score) {
632     // ts = tp;//the track sorted by the tracker!!
633     // cs = cp;
634     // os = op;
635     }else if (tp_score < ti_score) {
636     ts = ti;//its image!!
637     cs = ci;
638     os = oi;
639    
640     ti = tp;//its image!!
641     ci = cp;
642     oi = op;
643    
644     tp = ts;//its image!!
645     cp = cs;
646     op = os;
647    
648    
649     }else {
650     // ts = tp;
651     // cs = cp;
652     // os = op;
653 pam-fi 1.3 // cout << "Warning - track image ambiguity not solved" << endl;
654     // cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;
655 pam-fi 1.6 };
656    
657     }else{
658 pam-fi 1.13 // ts = tp;
659     // cs = cp;
660     // os = op;
661 pam-fi 1.6 };
662    
663 pam-fi 1.9 // cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
664 pam-fi 1.13 // sorted_tracks->Add(ts);//save the track in the sorted array
665     // sorted_tracks.Add(ts);//save the track in the sorted array
666     // sorted_tracks.Add(tp);//save the track in the sorted array
667 pam-fi 1.9 // cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
668 pam-fi 1.13 // cout<<"o "<<tp<<endl;
669     // cout<<"o "<<cp<<endl;
670     // cout<<"o "<<op<<endl;
671     new(ttsorted[i]) PamTrack(tp,cp,op);
672     new(ttimage[i]) PamTrack(ti,ci,oi);
673 pam-fi 1.6 };
674 pam-fi 1.13
675     if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
676     cout << "void PamLevel2::SortTracks(TString how): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
677     tsorted->Delete(); tsorted=0;
678     timage->Delete(); timage=0;
679     }
680    
681 pam-fi 1.6 //Restore Object count
682     //To save space in the table keeping track of all referenced objects
683 pam-fi 1.13 //We reset the object count to what it was at the beginning of the event.
684 pam-fi 1.6 TProcessID::SetObjectCount(ObjectNumber);
685    
686 pam-fi 1.1 };
687     //--------------------------------------
688     //
689     //
690     //--------------------------------------
691     /**
692 pam-fi 1.2 * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
693     * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
694     */
695 pam-fi 1.13 // TRefArray *PamLevel2::GetTracks(){
696    
697     // // *-*-*-*-*-*-*-*-*-*-*-*-*
698     // SortTracks("+CAL+TOF");
699     // // *-*-*-*-*-*-*-*-*-*-*-*-*
700    
701     // // return sorted_tracks;
702     // return &sorted_tracks;
703    
704     // };
705     TClonesArray *PamLevel2::GetTracks(){
706 pam-fi 1.8
707     // *-*-*-*-*-*-*-*-*-*-*-*-*
708     SortTracks("+CAL+TOF");
709     // *-*-*-*-*-*-*-*-*-*-*-*-*
710    
711 pam-fi 1.13 return tsorted;
712    
713 pam-fi 1.2 };
714     //--------------------------------------
715 pam-fi 1.3 //
716     //
717 pam-fi 1.2 //--------------------------------------
718     /**
719 pam-fi 1.1 * Retrieves the it-th Pamela "physical" track.
720     * It override TrkLevel2::GetTrack(int it).
721     * @param it Track number, ranging from 0 to GetNTracks().
722     */
723     PamTrack *PamLevel2::GetTrack(int it){
724 pam-fi 1.13
725     // if(!trk2_obj) return 0;
726 pam-fi 1.3
727 pam-fi 1.13 // // *-*-*-*-*-*-*-*-*-*-*-*-*
728     // SortTracks("+CAL+TOF");
729     // // *-*-*-*-*-*-*-*-*-*-*-*-*
730     // // if(!sorted_tracks)return 0;
731     // if(sorted_tracks.IsEmpty())return 0;
732    
733     // PamTrack *track = 0;
734    
735     // if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){
736     // TrkTrack *t = (TrkTrack*)sorted_tracks.At(it);
737     // track = GetPamTrackAlong(t);
738     // }else{
739     // cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
740     // };
741    
742     // return track;
743    
744     // cout << "PamLevel2::GetTrack(int it) "<<endl;
745 pam-fi 1.8 // *-*-*-*-*-*-*-*-*-*-*-*-*
746     SortTracks("+CAL+TOF");
747     // *-*-*-*-*-*-*-*-*-*-*-*-*
748 pam-fi 1.13 if(!tsorted)return 0;
749     if(!tsorted->GetEntries())return 0;
750    
751 pam-fi 1.6 PamTrack *track = 0;
752    
753 pam-fi 1.13 if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){
754     // TrkTrack *t = (TrkTrack*)sorted_tracks.At(it);
755     // track = GetPamTrackAlong(t);
756     TClonesArray &t = *(tsorted);
757     track = (PamTrack*)t[it];
758    
759 pam-fi 1.6 }else{
760 pam-fi 1.13 cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
761 pam-fi 1.6 };
762    
763     return track;
764    
765 pam-fi 1.1 };
766 pam-fi 1.3
767 pam-fi 1.1 //--------------------------------------
768     //
769     //
770     //--------------------------------------
771     /**
772 pam-fi 1.3 * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
773 pam-fi 1.1 * @param it Track number, ranging from 0 to GetNTracks().
774     */
775     PamTrack *PamLevel2::GetTrackImage(int it){
776    
777 pam-fi 1.13 // if(!trk2_obj) return 0;
778    
779     // // *-*-*-*-*-*-*-*-*-*-*-*-*
780     // SortTracks("+CAL+TOF");
781     // // *-*-*-*-*-*-*-*-*-*-*-*-*
782     // // if(!sorted_tracks)return 0;
783     // if(sorted_tracks.IsEmpty())return 0;
784    
785     // PamTrack *image = 0;
786    
787     // if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
788     // TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);
789     // if( temp->HasImage() ){
790     // TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
791     // image = GetPamTrackAlong(t);
792     // }else{
793     // cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
794     // };
795     // }else{
796     // cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
797     // };
798    
799     // return image;
800    
801    
802 pam-fi 1.8 // *-*-*-*-*-*-*-*-*-*-*-*-*
803     SortTracks("+CAL+TOF");
804     // *-*-*-*-*-*-*-*-*-*-*-*-*
805 pam-fi 1.13 if(!timage)return 0;
806     if(!timage->GetEntries())return 0;
807 pam-fi 1.8
808     PamTrack *image = 0;
809    
810 pam-fi 1.13 if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
811     TClonesArray &t = *(tsorted);
812     PamTrack *temp = (PamTrack*)t[it];
813     if( temp->GetTrkTrack()->HasImage() ){
814     TClonesArray &t = *(timage);
815     image = (PamTrack*)t[it];
816 pam-fi 1.2 }else{
817 pam-fi 1.13 // cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
818 pam-fi 1.1 };
819 pam-fi 1.8 }else{
820 pam-fi 1.13 cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
821 pam-fi 1.8 };
822 pam-fi 1.1
823 pam-fi 1.8 return image;
824 pam-fi 1.1 }
825    
826     //--------------------------------------
827     //
828     //
829     //--------------------------------------
830     /**
831 pam-fi 1.2 * Get the Pamela detector trees in a single file and make them friends.
832     * @param f TFile pointer
833     * @param detlist String to select trees to be included
834     * @return Pointer to a TTree
835 pam-fi 1.1 */
836 pam-fi 1.11 TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
837 pam-fi 1.4
838 pam-fi 1.12 // if( !detlist.IsNull() ) SetWhichTrees(detlist);
839     // else GetWhichTrees(f);
840 pam-fi 1.20
841     cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
842    
843 pam-fi 1.12 SetWhichTrees(detlist);
844 pam-fi 1.9
845 pam-fi 1.6 TTree *Trout =0;
846 pam-fi 1.9
847     TString fname = f->GetName();
848     if(!CheckLevel2File(fname))return NULL;
849    
850 pam-fi 1.20 // UInt_t *found=0;
851 pam-fi 1.11
852 pam-fi 1.12 cout<< "GetPamTree(TFile*,TString): detector list --> ";
853     if(TRK1)cout<<"TRK1 ";
854     if(TRK2)cout<<"TRK2 ";
855     if(TRKh)cout<<"TRKH ";
856     if(CAL1)cout<<"CAL1 ";
857     if(CAL2)cout<<"CAL2 ";
858     if(TOF)cout<<"TOF ";
859     if(TRG)cout<<"TRG ";
860     if(AC)cout<<"AC ";
861     if(ND)cout<<"ND ";
862     if(S4)cout<<"S4 ";
863     if(ORB)cout<<"ORB ";
864     cout << endl;
865 pam-fi 1.20 if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
866 pam-fi 1.12
867     f->cd();
868    
869 pam-fi 1.4 // Tracker
870 pam-fi 1.1 TTree *T = (TTree*)f->Get("Tracker");
871 pam-fi 1.8 if(T && (TRK2||TRK1||TRKh)) {
872 pam-fi 1.9 if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
873 pam-fi 1.20 // else T->SetBranchStatus("TrkLevel2",0,found);
874 pam-fi 1.8 if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl;
875 pam-fi 1.9 if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
876 pam-fi 1.20 // else T->SetBranchStatus("TrkLevel1",0,found);
877 pam-fi 1.8 if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl;
878 pam-fi 1.9 if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
879 pam-fi 1.20 // else T->SetBranchStatus("TrkHough",0,found);
880 pam-fi 1.9 if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl;
881     if(!Trout)Trout=T;
882     else Trout->AddFriend(T);
883 pam-fi 1.1 }else{
884     cout << "Tracker : missing tree"<<endl;
885     };
886     // Calorimeter
887     TTree *C = (TTree*)f->Get("Calorimeter");
888 pam-fi 1.9 if(C && (CAL2||CAL1)) {
889     if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
890 pam-fi 1.20 // else C->SetBranchStatus("CaloLevel2",0,found);
891 pam-fi 1.9 if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<<endl;
892     if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
893 pam-fi 1.20 // else C->SetBranchStatus("CaloLevel1",0,found);
894 pam-fi 1.9 if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<<endl;
895 pam-fi 1.4 if(!Trout)Trout=C;
896     else Trout->AddFriend(C);
897 pam-fi 1.1 }else{
898     cout << "Calorimeter : missing tree"<<endl;
899     };
900 pam-fi 1.12
901 pam-fi 1.1 // ToF
902     TTree *O = (TTree*)f->Get("ToF");
903 pam-fi 1.2 if(O && TOF) {
904 pam-fi 1.9 O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
905 pam-fi 1.1 cout << "ToF : set branch address ToFLevel2"<<endl;
906 pam-fi 1.4 if(!Trout)Trout=O;
907     else Trout->AddFriend(O);
908 pam-fi 1.1 }else{
909     cout << "ToF : missing tree"<<endl;
910     };
911     // Trigger
912     TTree *R = (TTree*)f->Get("Trigger");
913 pam-fi 1.2 if(R && TRG) {
914 pam-fi 1.9 R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
915 pam-fi 1.1 cout << "Trigger : set branch address TrigLevel2"<<endl;
916 pam-fi 1.4 if(!Trout)Trout=O;
917     else Trout->AddFriend(R);
918 pam-fi 1.1 }else{
919     cout << "Trigger : missing tree"<<endl;
920     };
921     // S4
922     TTree *S = (TTree*)f->Get("S4");
923 pam-fi 1.2 if(S && S4) {
924 pam-fi 1.9 S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
925 pam-fi 1.1 cout << "S4 : set branch address S4Level2"<<endl;
926 pam-fi 1.4 if(!Trout)Trout=O;
927     else Trout->AddFriend(S);
928 pam-fi 1.1 }else{
929     cout << "S4 : missing tree"<<endl;
930     };
931     // Neutron Detector
932     TTree *N = (TTree*)f->Get("NeutronD");
933 pam-fi 1.2 if(N && ND) {
934 pam-fi 1.9 N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
935 pam-fi 1.1 cout << "NeutronD : set branch address NDLevel2"<<endl;
936 pam-fi 1.4 if(!Trout)Trout=O;
937     else Trout->AddFriend(N);
938 pam-fi 1.1 }else{
939     cout << "NeutronD : missing tree"<<endl;
940     };
941     // Anticounters
942     TTree *A = (TTree*)f->Get("Anticounter");
943 pam-fi 1.2 if(A && AC) {
944 pam-fi 1.9 A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
945 pam-fi 1.1 cout << "Anticounter : set branch address AcLevel2"<<endl;
946 pam-fi 1.4 if(!Trout)Trout=O;
947     else Trout->AddFriend(A);
948 pam-fi 1.1 }else{
949     cout << "Anticounter : missing tree"<<endl;
950     };
951 pam-fi 1.2 // Orbital Info
952 pam-fi 1.11 TTree *B = (TTree*)f->Get("OrbitalInfo");
953     if(B && ORB) {
954     B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
955     cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
956     if(!Trout)Trout=O;
957     else Trout->AddFriend(B);
958     }else{
959     cout << "OrbitalInfo : missing tree"<<endl;
960     };
961 pam-fi 1.20
962     TTree *L = (TTree*)f->Get("SelectionList");
963     if(L && SELLI==1) {
964     // L->SetBranchAddress("RunEntry",&irun);
965     // cout << "SelectionList: set branch address RunEntry"<<endl;
966     // L->SetBranchAddress("EventEntry",&irunentry);
967     // cout << "SelectionList: set branch address EventEntry"<<endl;
968     // if(!Trout)Trout=O;
969     // else Trout->AddFriend("SelectionList");
970     cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
971     sel_tree = 0;
972     }else{
973     cout << "SelectionList : missing tree"<<endl;
974     };
975 pam-fi 1.11
976     cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
977 mocchiut 1.28
978     pam_tree = (TChain*)Trout;
979 pam-fi 1.1
980 pam-fi 1.11 return Trout;
981 pam-fi 1.1
982     }
983 pam-fi 1.2 //--------------------------------------
984     //
985     //
986     //--------------------------------------
987     /**
988     * Get list of Level2 files.
989     * @param ddir Level2 data directory.
990     * @param flisttxt Name of txt file containing file list.
991     * @return Pointer to a TList of TSystemFiles
992     * If no input file list is given , all the Level2 files inside the directory are processed.
993     */
994     TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){
995    
996 pam-fi 1.6 TString wdir = gSystem->WorkingDirectory();
997    
998     if(ddir=="")ddir = wdir;
999     // TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1000     cout << "Level2 data directory : "<< ddir << endl;
1001    
1002     TList *contents = new TList; // create output list
1003     contents->SetOwner();
1004    
1005 pam-fi 1.16 // char *fullpath;
1006 pam-fi 1.18 // const char *fullpath;
1007 pam-fi 1.6
1008 pam-fi 1.26 // if no input file list is given:
1009 pam-fi 1.6 if ( flisttxt != "" ){
1010 pam-fi 1.2
1011 pam-fi 1.16 // if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){
1012 pam-fi 1.18 // if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1013     // cout <<"File "<<flisttxt<<" not found"<<endl;
1014     // return 0;
1015     // }
1016     // flisttxt = fullpath;
1017 mocchiut 1.28 if ( !flisttxt.EndsWith(".root") ){
1018 pam-fi 1.18
1019     flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1020 pam-fi 1.16
1021 pam-fi 1.11 if( !gSystem->ChangeDirectory(ddir) ){
1022     cout << "Cannot change directory : "<<ddir<<endl;
1023     return 0;
1024     }
1025 pam-fi 1.2
1026 pam-fi 1.6 cout <<"Input file list : " << flisttxt <<endl;
1027     ifstream in;
1028     in.open(flisttxt, ios::in); //open input file list
1029 pam-fi 1.18 if(!in.good()){
1030     cout <<" ERROR opening the file "<<endl;
1031     gSystem->ChangeDirectory(wdir); // back to the working directory
1032     return 0;
1033     }
1034 pam-fi 1.9 int line=0;
1035 pam-fi 1.6 while (1) {
1036     TString file;
1037     in >> file;
1038     if (!in.good()) break;
1039 pam-fi 1.9 line++;
1040 pam-fi 1.8 // cout <<"(1) " << file << endl;
1041 pam-fi 1.9 if(file.IsNull()){
1042     cout << "-- list interrupted at line "<<line <<endl;
1043     break;
1044     }
1045 pam-fi 1.10 if(file.Contains("#"))file = file(0,file.First("#"));
1046     // cout <<"(2) " << file << endl;
1047 pam-fi 1.16 // if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1048 pam-fi 1.18 // if( (fullpath = gSystem->FindFile(ddir,file)) ){
1049 pam-fi 1.19 if( file.EndsWith(".root") ){
1050     char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file));
1051     contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1052     delete fullpath;
1053     }
1054 pam-fi 1.18 // }else{
1055 pam-fi 1.10 // if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1056 pam-fi 1.18 // };
1057 pam-fi 1.6 };
1058     in.close();
1059 mocchiut 1.28 } else {
1060     char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1061     contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1062     delete fullpath;
1063     };
1064 pam-fi 1.6 }else{
1065 pam-fi 1.2
1066 pam-fi 1.6 cout << "No input file list given."<<endl;
1067     cout << "Check for existing root files."<<endl;
1068 pam-fi 1.2 // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1069 pam-fi 1.6
1070     TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1071     TList *temp = datadir->GetListOfFiles();
1072 pam-fi 1.2 // temp->Print();
1073     // cout << "*************************************" << endl;
1074    
1075 pam-fi 1.6 TIter next(temp);
1076     TSystemFile *questo = 0;
1077    
1078    
1079     while ( (questo = (TSystemFile*) next()) ) {
1080     TString name = questo-> GetName();
1081     if( name.EndsWith(".root") ){
1082 pam-fi 1.18 // const char *fullpath = gSystem->FindFile(ddir,name);
1083 pam-fi 1.16 // char *fullpath;
1084     // gSystem->IsFileInIncludePath(name,&fullpath);
1085 pam-fi 1.18 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1086 pam-fi 1.6 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1087 pam-fi 1.18 delete fullpath;
1088 pam-fi 1.6 };
1089     }
1090     delete temp;
1091     delete datadir;
1092    
1093     };
1094     gSystem->ChangeDirectory(wdir); // back to the working directory
1095 pam-fi 1.5 // cout << endl << "Selected files:" << endl;
1096     // contents->Print();
1097 pam-fi 1.18 cout << contents->GetEntries()<<" files \n";
1098 pam-fi 1.5 // cout << endl;
1099 pam-fi 1.4 // cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1100 pam-fi 1.6 return contents;
1101 pam-fi 1.2 };
1102     //--------------------------------------
1103     //
1104     //
1105     //--------------------------------------
1106     /**
1107     * Get the Pamela detector chains from a list of files and make them friends.
1108     * @param fl Pointer to a TList of TSystemFiles
1109     * @param detlist String to select trees to be included
1110     * @return Pointer to a TChain
1111     */
1112 pam-fi 1.11 TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1113    
1114     TChain *Trout =0;
1115 pam-fi 1.2
1116 pam-fi 1.12 // if( !detlist.IsNull() )SetWhichTrees(detlist);
1117     SetWhichTrees(detlist);
1118 pam-fi 1.6
1119 pam-fi 1.13 cout<< "GetPamTree(TList*,TString): input detector list --> ";
1120 pam-fi 1.12 if(TRK1)cout<<"TRK1 ";
1121     if(TRK2)cout<<"TRK2 ";
1122     if(TRKh)cout<<"TRKH ";
1123     if(CAL1)cout<<"CAL1 ";
1124     if(CAL2)cout<<"CAL2 ";
1125     if(TOF)cout<<"TOF ";
1126     if(TRG)cout<<"TRG ";
1127     if(AC)cout<<"AC ";
1128     if(ND)cout<<"ND ";
1129     if(S4)cout<<"S4 ";
1130     if(ORB)cout<<"ORB ";
1131     cout << endl;
1132    
1133 pam-fi 1.6 TChain *T = 0;
1134     TChain *C = 0;
1135     TChain *O = 0;
1136     TChain *R = 0;
1137     TChain *S = 0;
1138     TChain *N = 0;
1139     TChain *A = 0;
1140     TChain *B = 0;
1141 pam-fi 1.20
1142     TChain *L = 0;
1143 pam-fi 1.6
1144 pam-fi 1.8 if(TRK2||TRK1||TRKh) T = new TChain("Tracker");
1145 pam-fi 1.11 if(CAL2||CAL1) C = new TChain("Calorimeter");
1146     if(TOF) O = new TChain("ToF");
1147     if(TRG) R = new TChain("Trigger");
1148     if(S4) S = new TChain("S4");
1149     if(ND) N = new TChain("NeutronD");
1150     if(AC) A = new TChain("Anticounter");
1151     if(ORB) B = new TChain("OrbitalInfo");
1152 pam-fi 1.20
1153     L = new TChain("SelectionList");
1154 pam-fi 1.6
1155     // loop over files and create chains
1156     TIter next(fl);
1157     TSystemFile *questo = 0;
1158     while ( (questo = (TSystemFile*) next()) ) {
1159     TString name = questo->GetName();
1160 pam-fi 1.13 cout << "File: "<< name << endl;
1161 pam-fi 1.6 if( CheckLevel2File(name) ){
1162 pam-fi 1.8 if(TRK2||TRK1||TRKh) T->Add(name);
1163 pam-fi 1.11 if(CAL1||CAL2) C->Add(name);
1164     if(TOF) O->Add(name);
1165     if(TRG) R->Add(name);
1166     if(S4) S->Add(name);
1167     if(ND) N->Add(name);
1168     if(AC) A->Add(name);
1169     if(ORB) B->Add(name);
1170 pam-fi 1.20 if(SELLI==1) L->Add(name);
1171 pam-fi 1.4 };
1172 pam-fi 1.6 }
1173    
1174     cout << "done chain \n";
1175 pam-fi 1.11
1176 pam-fi 1.20 // UInt_t *found=0;
1177 pam-fi 1.11 // Tracker
1178     if(T && (TRK2||TRK1||TRKh)) {
1179     if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1180 pam-fi 1.20 // else T->SetBranchStatus("TrkLevel2",0,found);
1181 pam-fi 1.11 if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl;
1182     if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1183 pam-fi 1.20 // else T->SetBranchStatus("TrkLevel1",0,found);
1184 pam-fi 1.11 if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl;
1185     if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1186 pam-fi 1.20 // else T->SetBranchStatus("TrkHough",0,found);
1187 pam-fi 1.11 if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl;
1188     if(!Trout)Trout=T;
1189     else Trout->AddFriend("Tracker");
1190     }else{
1191     cout << "Tracker : missing tree"<<endl;
1192     };
1193 pam-fi 1.6 // Calorimeter
1194 pam-fi 1.11 if(C && (CAL2||CAL1)) {
1195     if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1196 pam-fi 1.20 // else C->SetBranchStatus("CaloLevel2",0,found);
1197 pam-fi 1.11 if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1198     if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1199 pam-fi 1.20 // else C->SetBranchStatus("CaloLevel1",0,found);
1200 pam-fi 1.11 if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1201     if(!Trout)Trout=C;
1202     else Trout->AddFriend("Calorimeter");
1203     }else{
1204     cout << "Calorimeter : missing tree"<<endl;
1205 pam-fi 1.6 };
1206 pam-fi 1.4 // ToF
1207 pam-fi 1.11 if(O && TOF) {
1208     O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1209     cout << "ToF : set branch address ToFLevel2"<<endl;
1210     if(!Trout)Trout=O;
1211     else Trout->AddFriend("ToF");
1212     }else{
1213     cout << "ToF : missing tree"<<endl;
1214 pam-fi 1.6 };
1215 pam-fi 1.4 // Trigger
1216 pam-fi 1.11 if(R && TRG) {
1217     R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1218     cout << "Trigger : set branch address TrigLevel2"<<endl;
1219     if(!Trout)Trout=O;
1220     else Trout->AddFriend("Trigger");
1221     }else{
1222     cout << "Trigger : missing tree"<<endl;
1223 pam-fi 1.6 };
1224 pam-fi 1.4 // S4
1225 pam-fi 1.11 if(S && S4) {
1226     S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1227     cout << "S4 : set branch address S4Level2"<<endl;
1228     if(!Trout)Trout=O;
1229     else Trout->AddFriend("S4");
1230     }else{
1231     cout << "S4 : missing tree"<<endl;
1232 pam-fi 1.6 };
1233 pam-fi 1.4 // Neutron Detector
1234 pam-fi 1.11 if(N && ND) {
1235     N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1236     cout << "NeutronD : set branch address NDLevel2"<<endl;
1237     if(!Trout)Trout=O;
1238     else Trout->AddFriend("NeutronD");
1239     }else{
1240     cout << "NeutronD : missing tree"<<endl;
1241 pam-fi 1.6 };
1242 pam-fi 1.4 // Anticounters
1243 pam-fi 1.11 if(A && AC) {
1244     A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1245     cout << "Anticounter : set branch address AcLevel2"<<endl;
1246     if(!Trout)Trout=O;
1247     else Trout->AddFriend("Anticounter");
1248     }else{
1249     cout << "Anticounter : missing tree"<<endl;
1250 pam-fi 1.6 };
1251 pam-fi 1.11 // Orbital Info
1252     if(B && ORB) {
1253     B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1254     cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1255     if(!Trout)Trout=O;
1256     else Trout->AddFriend("OrbitalInfo");
1257     }else{
1258     cout << "OrbitalInfo : missing tree"<<endl;
1259 pam-fi 1.6 };
1260 pam-fi 1.20
1261     // Selection List
1262     if(L && SELLI==1) {
1263     cout<<">>> Found selection-list <<<"<<endl;
1264     L->SetBranchAddress("RunEntry",&irun);
1265     cout << "SelectionList: set branch address RunEntry"<<endl;
1266     L->SetBranchAddress("EventEntry",&irunentry);
1267     cout << "SelectionList: set branch address EventEntry"<<endl;
1268     sel_tree = L;
1269     // if(!Trout)Trout=O;
1270     // else Trout->AddFriend("SelectionList");
1271     }else{
1272     // cout << "SelectionList : missing tree"<<endl;
1273     if(L)L->Delete();
1274     };
1275 pam-fi 1.6
1276 pam-fi 1.11 // cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1277    
1278 pam-fi 1.20 pam_tree = Trout;
1279    
1280 pam-fi 1.11 return Trout;
1281 pam-fi 1.4 }
1282 pam-fi 1.8
1283    
1284    
1285 pam-fi 1.4 //--------------------------------------
1286     //
1287     //
1288     //--------------------------------------
1289     /**
1290     * Set branch addresses for Pamela friend trees
1291     */
1292 pam-fi 1.8 void PamLevel2::SetBranchAddress(TTree *t){
1293    
1294     TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
1295     TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
1296     TRKh = TRKh & t->GetBranchStatus("TrkHough");
1297     CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
1298     CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
1299     TOF = TOF & t->GetBranchStatus("ToFLevel2");
1300     TRG = TRG & t->GetBranchStatus("TrigLevel2");
1301     S4 = S4 & t->GetBranchStatus("S4Level2");
1302     ND = ND & t->GetBranchStatus("NDLevel2");
1303     AC = AC & t->GetBranchStatus("AcLevel2");
1304     ORB = ORB & t->GetBranchStatus("OrbitalInfo");
1305    
1306    
1307 pam-fi 1.4 // Tracker
1308 pam-fi 1.8 if(TRK1) {
1309 pam-fi 1.9 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));
1310 pam-fi 1.8 cout << "Tracker : set branch address TrkLevel1"<<endl;
1311     };
1312     if(TRK2) {
1313 pam-fi 1.9 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
1314 pam-fi 1.6 cout << "Tracker : set branch address TrkLevel2"<<endl;
1315     };
1316 pam-fi 1.8 if(TRKh) {
1317 pam-fi 1.9 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1318 pam-fi 1.8 cout << "Tracker : set branch address TrkHough"<<endl;
1319     };
1320 pam-fi 1.6
1321     // Calorimeter
1322 pam-fi 1.8 if(CAL1) {
1323 pam-fi 1.9 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1324 pam-fi 1.8 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1325     };
1326     if(CAL2) {
1327 pam-fi 1.9 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1328 pam-fi 1.6 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1329     };
1330    
1331 pam-fi 1.4 // ToF
1332 pam-fi 1.6 if(TOF) {
1333 pam-fi 1.9 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1334 pam-fi 1.6 cout << "ToF : set branch address ToFLevel2"<<endl;
1335     };
1336 pam-fi 1.4 // Trigger
1337 pam-fi 1.6 if(TRG) {
1338 pam-fi 1.9 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1339 pam-fi 1.6 cout << "Trigger : set branch address TrigLevel2"<<endl;
1340     };
1341 pam-fi 1.4 // S4
1342 pam-fi 1.6 if(S4) {
1343 pam-fi 1.9 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1344 pam-fi 1.6 cout << "S4 : set branch address S4Level2"<<endl;
1345     };
1346 pam-fi 1.4 // Neutron Detector
1347 pam-fi 1.6 if(ND) {
1348 pam-fi 1.9 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1349 pam-fi 1.6 cout << "NeutronD : set branch address NDLevel2"<<endl;
1350     };
1351 pam-fi 1.4 // Anticounters
1352 pam-fi 1.6 if(AC) {
1353 pam-fi 1.9 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1354 pam-fi 1.6 cout << "Anticounter : set branch address AcLevel2"<<endl;
1355     };
1356 pam-fi 1.4 // OrbitalInfo
1357 pam-fi 1.6 if(ORB) {
1358 pam-fi 1.9 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1359 pam-fi 1.6 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1360     };
1361 pam-fi 1.20 // SelectionList
1362     if(SELLI==1) {
1363     t->SetBranchAddress("RunEntry", &irun);
1364     cout << "SelectionList: set branch address RunEntry"<<endl;
1365     t->SetBranchAddress("EventEntry", &irunentry);
1366     cout << "SelectionList: set branch address EventEntry"<<endl;
1367     };
1368 pam-fi 1.6
1369 pam-fi 1.4 }
1370 pam-fi 1.8 /**
1371     * Set branch addresses for Pamela friend trees
1372     */
1373     void PamLevel2::SetBranchAddress(TChain *t){
1374 pam-fi 1.4
1375 pam-fi 1.8 TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
1376     TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
1377     TRKh = TRKh & t->GetBranchStatus("TrkHough");
1378     CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
1379     CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
1380     TOF = TOF & t->GetBranchStatus("ToFLevel2");
1381     TRG = TRG & t->GetBranchStatus("TrigLevel2");
1382     S4 = S4 & t->GetBranchStatus("S4Level2");
1383     ND = ND & t->GetBranchStatus("NDLevel2");
1384     AC = AC & t->GetBranchStatus("AcLevel2");
1385     ORB = ORB & t->GetBranchStatus("OrbitalInfo");
1386    
1387     // Tracker
1388 pam-fi 1.9 if(TRK2) {
1389 pam-fi 1.11 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1390 pam-fi 1.9 cout << "Tracker : set branch address TrkLevel2"<<endl;
1391     };
1392 pam-fi 1.8 if(TRK1) {
1393 pam-fi 1.9 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1394 pam-fi 1.8 cout << "Tracker : set branch address TrkLevel1"<<endl;
1395     };
1396     if(TRKh) {
1397 pam-fi 1.9 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1398 pam-fi 1.8 cout << "Tracker : set branch address TrkHough"<<endl;
1399     };
1400    
1401     // Calorimeter
1402 pam-fi 1.9 if(CAL2) {
1403     t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1404     cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1405     };
1406 pam-fi 1.8 if(CAL1) {
1407 pam-fi 1.9 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1408 pam-fi 1.8 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1409     };
1410    
1411     // ToF
1412     if(TOF) {
1413 pam-fi 1.9 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1414 pam-fi 1.8 cout << "ToF : set branch address ToFLevel2"<<endl;
1415     };
1416     // Trigger
1417     if(TRG) {
1418 pam-fi 1.9 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1419 pam-fi 1.8 cout << "Trigger : set branch address TrigLevel2"<<endl;
1420     };
1421     // S4
1422     if(S4) {
1423 pam-fi 1.9 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1424 pam-fi 1.8 cout << "S4 : set branch address S4Level2"<<endl;
1425     };
1426     // Neutron Detector
1427     if(ND) {
1428 pam-fi 1.9 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1429 pam-fi 1.8 cout << "NeutronD : set branch address NDLevel2"<<endl;
1430     };
1431     // Anticounters
1432     if(AC) {
1433 pam-fi 1.9 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1434 pam-fi 1.8 cout << "Anticounter : set branch address AcLevel2"<<endl;
1435     };
1436     // OrbitalInfo
1437     if(ORB) {
1438 pam-fi 1.9 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1439 pam-fi 1.8 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1440     };
1441 pam-fi 1.20 // SelectionList
1442     if(SELLI==1) {
1443     t->SetBranchAddress("RunEntry", &irun);
1444     cout << "SelectionList: set branch address RunEntry"<<endl;
1445     t->SetBranchAddress("EventEntry", &irunentry);
1446     cout << "SelectionList: set branch address EventEntry"<<endl;
1447     };
1448 pam-fi 1.8
1449     }
1450 pam-fi 1.9
1451    
1452 pam-fi 1.4 //--------------------------------------
1453     //
1454     //
1455     //--------------------------------------
1456     /**
1457     * Get the Run tree chain from a list of files.
1458     * @param fl Pointer to a TList of TSystemFiles
1459     * @return Pointer to a TChain
1460     */
1461     TChain *PamLevel2::GetRunTree(TList *fl){
1462    
1463 pam-fi 1.6 TChain *R = new TChain("Run");
1464    
1465     // loop over files and create chains
1466     TIter next(fl);
1467     TSystemFile *questo = 0;
1468     while ( (questo = (TSystemFile*) next()) ) {
1469     TString name = questo->GetName();
1470 pam-fi 1.4 // cout << "File: "<< name << endl;
1471 pam-fi 1.6 if( CheckLevel2File(name) ){
1472     R->Add(name);
1473     };
1474     }
1475 pam-fi 1.20
1476     if(R->GetNtrees()){
1477 pam-fi 1.6
1478 pam-fi 1.20 R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1479     cout << "Run : set branch address RunInfo"<<endl;
1480     R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1481     cout << "Software : set branch address SoftInfo"<<endl; // Emiliano
1482     }else{
1483     delete R;
1484     R=0;
1485     }
1486    
1487     run_tree = R;
1488    
1489 pam-fi 1.6 return R;
1490 pam-fi 1.4
1491     }
1492     //--------------------------------------
1493     //
1494     //
1495     //--------------------------------------
1496     /**
1497     * Get the Run tree from a file.
1498     * @param f Pointer to a TFile
1499     * @return Pointer to a TTree
1500     */
1501     TTree *PamLevel2::GetRunTree(TFile *f){
1502    
1503 pam-fi 1.20 cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1504 pam-fi 1.4
1505 pam-fi 1.6 TTree *R = (TTree*)f->Get("Run");
1506    
1507 pam-fi 1.20 if(R){
1508     R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1509     cout << "Run : set branch address RunInfo"<<endl;
1510     R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1511     cout << "Software : set branch address SoftInfo"<<endl; // Emiliano
1512     }
1513 mocchiut 1.28
1514     run_tree = (TChain*)R;
1515    
1516 pam-fi 1.6 return R;
1517 pam-fi 1.2
1518     }
1519 mocchiut 1.17 /**
1520     * Update the runinfo informations (to be used to have Run infos event by event basis)
1521     * @param run Pointer to the chain/tree which contains run infos
1522     * @return true if a new run has been read, false if it is still the same run
1523     */
1524     Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev){
1525     //
1526     // check if we have already called once GetEntry, if not call it
1527     //
1528     if ( run->GetEntries() <= 0 ) return(false);
1529     //
1530 pam-fi 1.20
1531 mocchiut 1.17 Int_t oldrun = irun;
1532 pam-fi 1.20 // --------------------------------------
1533     // if it is a full file (not preselected)
1534     // --------------------------------------
1535     if(SELLI==0){
1536     if ( irun < 0 ){
1537     irun = 0;
1538 pam-fi 1.26 run->GetEntry(irun);
1539 pam-fi 1.20 runfirstentry = 0ULL;
1540 mocchiut 1.30 runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1541     if ( (ULong64_t)(this->GetRunInfo()->NEVENTS) > 0ULL ) runlastentry -= 1ULL;
1542 pam-fi 1.26 return(true);
1543 pam-fi 1.24 };
1544    
1545     if( !GetOrbitalInfo() ){
1546     cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1547     return(false);
1548     }
1549     // modificato il controllo sull'aggiornamento del run, per evitare problemi
1550     // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
1551     while ( GetOrbitalInfo()->absTime > GetRunInfo()->RUNTRAILER_TIME && irun < run->GetEntries() ){
1552     // while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1553 mocchiut 1.30 // printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1554 pam-fi 1.20 irun++;
1555     run->GetEntry(irun);
1556 mocchiut 1.30 runfirstentry = runlastentry;
1557     if ( (ULong64_t)(this->GetRunInfo()->NEVENTS) > 0ULL ) runfirstentry += 1ULL;
1558 pam-fi 1.20 runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1559     };
1560 pam-fi 1.24
1561 pam-fi 1.20 //
1562 mocchiut 1.30 if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1563 pam-fi 1.20 //
1564     // printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1565     //
1566     return(true);
1567 mocchiut 1.17 };
1568 pam-fi 1.20 // ----------------------------------------------------
1569     // if it is a preselected file (there is SelectionList)
1570     // NBNB - the event tree MUST be read first
1571     // ----------------------------------------------------
1572     if(SELLI==1){
1573     sel_tree->GetEntry(iev);
1574     if(irun != oldrun){
1575     run->GetEntry(irun);
1576     return true;
1577     }
1578     return false;
1579     }
1580    
1581     return false;
1582 mocchiut 1.17 //
1583     };
1584     /**
1585     * Update the runinfo informations (to be used to have Run infos event by event basis)
1586     * @param run Pointer to the chain/tree which contains run infos
1587     * @return true if a new run has been read, false if it is still the same run
1588     */
1589     Bool_t PamLevel2::UpdateRunInfo(TTree *run, ULong64_t iev){
1590     return(UpdateRunInfo((TChain*)run,iev));
1591     };
1592    
1593 pam-fi 1.2 //--------------------------------------
1594     //
1595     //
1596     //--------------------------------------
1597     /**
1598 pam-fi 1.8 * Set which trees shoul be analysed
1599 pam-fi 1.2 * @param detlist TString containing the sequence of trees required
1600     */
1601     void PamLevel2::SetWhichTrees(TString detlist){
1602    
1603 pam-fi 1.12 if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
1604 pam-fi 1.20 CAL0 = false;
1605 pam-fi 1.8 CAL1 = true;
1606     CAL2 = true;
1607     TRK2 = true;
1608     TRK1 = false;
1609     TRKh = false;
1610 pam-fi 1.20 TRK0 = false;
1611 pam-fi 1.6 TRG = true;
1612     TOF = true;
1613 pam-fi 1.20 TOF0 = false;
1614 pam-fi 1.6 S4 = true;
1615     ND = true;
1616     AC = true;
1617     ORB = true;
1618     }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
1619 pam-fi 1.20 CAL0 = false;
1620 pam-fi 1.8 CAL1 = false;
1621     CAL2 = false;
1622     TRK2 = false;
1623     TRK1 = false;
1624     TRKh = false;
1625 pam-fi 1.20 TRK0 = false;
1626 pam-fi 1.6 TRG = false;
1627     TOF = false;
1628 pam-fi 1.20 TOF0 = false;
1629 pam-fi 1.6 S4 = false;
1630     ND = false;
1631     AC = false;
1632     ORB = false;
1633     };
1634    
1635 pam-fi 1.8 // -------------------------------------------------------------------------
1636     if( detlist.Contains("CAL1", TString::kIgnoreCase) ){
1637     if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1638     if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1639     };
1640 pam-fi 1.20
1641     if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
1642     if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
1643     if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
1644     };
1645 pam-fi 1.8
1646     if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1647     if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
1648     if ( detlist.Contains("+CAL2", TString::kIgnoreCase) )CAL2=true;
1649     };
1650    
1651     if( detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2 )CAL2=true;
1652     if( detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2 ){
1653     CAL2=false;
1654     CAL1=false;
1655     }
1656     // -------------------------------------------------------------------------
1657 pam-fi 1.20 if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
1658     if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
1659     if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
1660     };
1661    
1662 pam-fi 1.8 if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1663     if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1664     if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
1665     };
1666    
1667     if( detlist.Contains("TRK2", TString::kIgnoreCase)){
1668     if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false;
1669     if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true;
1670     };
1671    
1672     if( detlist.Contains("TRKh", TString::kIgnoreCase)){
1673     if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false;
1674     if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true;
1675     };
1676    
1677     if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true;
1678     if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){
1679     TRK2=false;
1680     TRK1=false;
1681     TRKh=false;
1682     }
1683     // -------------------------------------------------------------------------
1684 pam-fi 1.6
1685     if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
1686     else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
1687    
1688     if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
1689     else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
1690 pam-fi 1.20
1691     if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
1692     else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
1693 pam-fi 1.6
1694     if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false;
1695     else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true;
1696    
1697     if( detlist.Contains("-ND", TString::kIgnoreCase) )ND = false;
1698     else if( detlist.Contains("+ND", TString::kIgnoreCase) )ND = true;
1699    
1700     if( detlist.Contains("-AC", TString::kIgnoreCase) )AC = false;
1701     else if( detlist.Contains("+AC", TString::kIgnoreCase) )AC = true;
1702    
1703     if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
1704     else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
1705 pam-fi 1.11
1706 pam-fi 1.12 // cout<< "Set detector list --> ";
1707     // if(TRK1)cout<<"TRK1 ";
1708     // if(TRK2)cout<<"TRK2 ";
1709     // if(TRKh)cout<<"TRKH ";
1710     // if(CAL1)cout<<"CAL1 ";
1711     // if(CAL2)cout<<"CAL2 ";
1712     // if(TOF)cout<<"TOF ";
1713     // if(TRG)cout<<"TRG ";
1714     // if(AC)cout<<"AC ";
1715     // if(ND)cout<<"ND ";
1716     // if(S4)cout<<"S4 ";
1717     // if(ORB)cout<<"ORB ";
1718     // cout << endl;
1719 pam-fi 1.6
1720 pam-fi 1.2 };
1721 pam-fi 1.11
1722    
1723     /**
1724     * Set tree/branch detector flags from the content of a tree
1725     */
1726     void PamLevel2::GetWhichTrees(TFile* f){
1727 pam-fi 1.20
1728    
1729    
1730     cout << "void PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
1731 pam-fi 1.11 // -----------
1732     // reset flags
1733     // -----------
1734 pam-fi 1.12 CAL1 = false;
1735     CAL2 = false;
1736     TRK2 = false;
1737     TRK1 = false;
1738     TRKh = false;
1739     TRG = false;
1740     TOF = false;
1741     S4 = false;
1742     ND = false;
1743     AC = false;
1744     ORB = false;
1745 pam-fi 1.11
1746 pam-fi 1.12 RUN = false;
1747 pam-fi 1.11
1748     cout << "Checking file: "<<f->GetName()<<endl;
1749     if( !f || f->IsZombie() ){
1750     cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
1751     return;
1752     }
1753    
1754     TList *lk = f->GetListOfKeys();
1755     TIter next(lk);
1756     TKey *key =0;
1757    
1758     Int_t nev = 0;
1759    
1760     while( (key = (TKey*)next()) ){
1761    
1762     if( !strcmp(key->GetName(),"Run" ) )RUN = true;
1763    
1764     //=========================================================
1765     if( !strcmp(key->GetName(),"Trigger" ) ){
1766     TRG = true;
1767     Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
1768     if( nev && nevt!=nev){
1769     cout << "File: "<< f->GetName() <<" Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
1770     TRG = false;
1771     }else nev=nevt;
1772     }
1773     //=========================================================
1774     if( !strcmp(key->GetName(),"ToF" ) ){
1775     TOF = true;
1776     Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
1777     if( nev && nevt!=nev){
1778     cout << "File: "<< f->GetName() <<" ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
1779     TOF = false;
1780     }else nev=nevt;
1781     }
1782     //=========================================================
1783     if( !strcmp(key->GetName(),"S4" ) ){
1784     S4 = true;
1785     Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
1786     if( nev && nevt!=nev){
1787     cout << "File: "<< f->GetName() <<" S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
1788     S4 = false;
1789     }else nev=nevt;
1790     }
1791     //=========================================================
1792    
1793     if( !strcmp(key->GetName(),"NeutronD" ) ){
1794     ND = true;
1795     Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
1796     if( nev && nevt!=nev){
1797     cout << "File: "<< f->GetName() <<"NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
1798     ND =false;
1799     }else nev=nevt;
1800     }
1801     //=========================================================
1802     if( !strcmp(key->GetName(),"Anticounter") ){
1803     AC = true;
1804     Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
1805     if( nev && nevt!=nev){
1806     cout << "File: "<< f->GetName() <<" Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
1807     AC =false;
1808     }else nev=nevt;
1809     }
1810     //=========================================================
1811     if( !strcmp(key->GetName(),"OrbitalInfo") ){
1812     ORB = true;
1813     Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
1814     if( nev && nevt!=nev){
1815     cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
1816     ORB = false;
1817     }else nev=nevt;
1818     }
1819     //=========================================================
1820     if( !strcmp(key->GetName(),"Tracker" ) ){
1821     TTree *T = (TTree*)f->Get("Tracker");
1822     for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1823     TString name = T->GetListOfBranches()->At(i)->GetName();
1824     if( !name.CompareTo("TrkLevel1") )TRK1=true;
1825     if( !name.CompareTo("TrkLevel2") )TRK2=true;
1826     if( !name.CompareTo("TrkHough") )TRKh=true;
1827     };
1828     Int_t nevt = T->GetEntries();
1829     if( nev && nevt!=nev){
1830     cout << "File: "<< f->GetName() <<" Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
1831     TRK1 = false;
1832     TRK2 = false;
1833     TRKh = false;
1834     }else nev=nevt;
1835     T->Delete();
1836     };
1837     //=========================================================
1838     if( !strcmp(key->GetName(),"Calorimeter" ) ){
1839     TTree *T = (TTree*)f->Get("Calorimeter");
1840     for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1841     TString name = T->GetListOfBranches()->At(i)->GetName();
1842     if( !name.CompareTo("CaloLevel1") )CAL1=true;
1843     if( !name.CompareTo("CaloLevel2") )CAL2=true;
1844     };
1845     Int_t nevt = T->GetEntries();
1846     if( nev && nevt!=nev){
1847     cout << "File: "<< f->GetName() <<" Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
1848     CAL1 = false;
1849     CAL2 = false;
1850     }else nev=nevt;
1851     T->Delete();
1852     };
1853    
1854     };
1855    
1856 pam-fi 1.13 delete lk;
1857 pam-fi 1.12
1858     // cout<< "Get detector list from input file --> ";
1859     // if(TRK1)cout<<"TRK1 ";
1860     // if(TRK2)cout<<"TRK2 ";
1861     // if(TRKh)cout<<"TRKH ";
1862     // if(CAL1)cout<<"CAL1 ";
1863     // if(CAL2)cout<<"CAL2 ";
1864     // if(TOF)cout<<"TOF ";
1865     // if(TRG)cout<<"TRG ";
1866     // if(AC)cout<<"AC ";
1867     // if(ND)cout<<"ND ";
1868     // if(S4)cout<<"S4 ";
1869     // if(ORB)cout<<"ORB ";
1870     // cout << endl;
1871 pam-fi 1.11
1872     return ;
1873    
1874     };
1875    
1876    
1877 pam-fi 1.2 //--------------------------------------
1878     //
1879     //
1880     //--------------------------------------
1881     /**
1882 pam-fi 1.3 * Check if a file contains selected Pamela Level2 trees.
1883 pam-fi 1.2 * @param name File name
1884 pam-fi 1.4 * @return true if the file is ok.
1885 pam-fi 1.2 */
1886     Bool_t PamLevel2::CheckLevel2File(TString name){
1887    
1888 pam-fi 1.8 Bool_t CAL1__ok = false;
1889     Bool_t CAL2__ok = false;
1890     Bool_t TRK2__ok = false;
1891     Bool_t TRK1__ok = false;
1892     Bool_t TRKh__ok = false;
1893 pam-fi 1.7 Bool_t TRG__ok = false;
1894     Bool_t TOF__ok = false;
1895     Bool_t S4__ok = false;
1896     Bool_t ND__ok = false;
1897     Bool_t AC__ok = false;
1898     Bool_t ORB__ok = false;
1899 pam-fi 1.6
1900 pam-fi 1.7 Bool_t RUN__ok = false;
1901 pam-fi 1.6
1902 pam-fi 1.20 Bool_t SELLI__ok = false;
1903 pam-fi 1.8
1904     cout << "Checking file: "<<name<<endl;
1905 pam-fi 1.6 TFile *f = new TFile(name.Data());
1906     if( !f || f->IsZombie() ){
1907     cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
1908     }
1909 pam-fi 1.7 // cout << "Get list of keys: "<<f<<endl;
1910 pam-fi 1.6 TList *lk = f->GetListOfKeys();
1911 pam-fi 1.8 // lk->Print();
1912 pam-fi 1.6 TIter next(lk);
1913     TKey *key =0;
1914 pam-fi 1.8
1915     Int_t nev = 0;
1916    
1917 pam-fi 1.6 while( (key = (TKey*)next()) ){
1918    
1919 pam-fi 1.20 // cout << key->GetName() << endl;
1920 pam-fi 1.12 // cout << key->GetName() << ""<<key->GetClassName()<<endl;
1921     // cout << " Get tree: " << f->Get(key->GetName())<<endl;
1922 pam-fi 1.7 // nev_previous = nev;
1923     // cout << " n.entries "<< nev <<endl;
1924     // if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
1925     // nev = ((TTree*)f->Get(key->GetName()))->GetEntries();
1926     // cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;
1927     // return false;
1928     // };
1929 pam-fi 1.6
1930 pam-fi 1.20
1931 pam-fi 1.6 if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true;
1932 pam-fi 1.8
1933     //=========================================================
1934 pam-fi 1.20 if( !strcmp(key->GetName(),"SelectionList" ) ){
1935     SELLI__ok = true;
1936     if(SELLI==1){
1937     Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
1938     if( nev && nevt!=nev){
1939     cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
1940     return false;
1941     }
1942     nev=nevt;
1943     }
1944     }
1945    
1946     //=========================================================
1947 pam-fi 1.8 if( !strcmp(key->GetName(),"Trigger" ) ){
1948     TRG__ok = true;
1949     if(TRG){
1950     Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
1951     if( nev && nevt!=nev){
1952     cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
1953     return false;
1954     }
1955     nev=nevt;
1956     }
1957     }
1958     //=========================================================
1959     if( !strcmp(key->GetName(),"ToF" ) ){
1960     TOF__ok = true;
1961     if(TOF){
1962     Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
1963     if( nev && nevt!=nev){
1964     cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
1965     return false;
1966     }
1967     nev=nevt;
1968     }
1969     }
1970     //=========================================================
1971     if( !strcmp(key->GetName(),"S4" ) ){
1972     S4__ok = true;
1973     if(S4){
1974     Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
1975     if( nev && nevt!=nev){
1976     cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
1977     return false;
1978     }
1979     nev=nevt;
1980     }
1981     }
1982     //=========================================================
1983    
1984     if( !strcmp(key->GetName(),"NeutronD" ) ){
1985     ND__ok = true;
1986     if(ND){
1987     Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
1988     if( nev && nevt!=nev){
1989     cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
1990     return false;
1991     }
1992     nev=nevt;
1993     }
1994     }
1995     //=========================================================
1996     if( !strcmp(key->GetName(),"Anticounter") ){
1997     AC__ok = true;
1998     if(AC){
1999     Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
2000     if( nev && nevt!=nev){
2001     cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
2002     return false;
2003     }
2004     nev=nevt;
2005     }
2006     }
2007     //=========================================================
2008     if( !strcmp(key->GetName(),"OrbitalInfo") ){
2009     ORB__ok = true;
2010     if(ORB){
2011     Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
2012     if( nev && nevt!=nev){
2013     cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
2014     return false;
2015     }
2016     nev=nevt;
2017     }
2018     }
2019     //=========================================================
2020 pam-fi 1.6 if( !strcmp(key->GetName(),"Tracker" ) ){
2021     TTree *T = (TTree*)f->Get("Tracker");
2022 pam-fi 1.8 if(TRK1||TRK2||TRKh){
2023     Int_t nevt = T->GetEntries();
2024     if( nev && nevt!=nev){
2025     cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
2026     return false;
2027     }
2028     nev=nevt;
2029     }
2030 pam-fi 1.6 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
2031     TString name = T->GetListOfBranches()->At(i)->GetName();
2032 pam-fi 1.8 if( !name.CompareTo("TrkLevel1") )TRK1__ok=true;
2033     if( !name.CompareTo("TrkLevel2") )TRK2__ok=true;
2034     if( !name.CompareTo("TrkHough") )TRKh__ok=true;
2035     };
2036     T->Delete();
2037 pam-fi 1.2 };
2038 pam-fi 1.8 //=========================================================
2039     if( !strcmp(key->GetName(),"Calorimeter" ) ){
2040     TTree *T = (TTree*)f->Get("Calorimeter");
2041     if(CAL1||CAL2){
2042     Int_t nevt = T->GetEntries();
2043     if( nev && nevt!=nev){
2044     cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
2045     return false;
2046     }
2047     nev=nevt;
2048     }
2049     for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
2050     TString name = T->GetListOfBranches()->At(i)->GetName();
2051     if( !name.CompareTo("CaloLevel1") )CAL1__ok=true;
2052     if( !name.CompareTo("CaloLevel2") )CAL2__ok=true;
2053     };
2054     T->Delete();
2055     };
2056    
2057 pam-fi 1.6 };
2058 pam-fi 1.20
2059     if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
2060     if( SELLI==0 && SELLI__ok ){
2061     cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
2062     return false;
2063     }
2064     if( SELLI==1 && !SELLI__ok ){
2065     cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
2066     return false;
2067     }
2068 pam-fi 1.6
2069 pam-fi 1.20 // cout << "SELLI "<<SELLI<<endl;
2070    
2071 pam-fi 1.12 // cout<< "CheckLevel2File(TString): detector list --> ";
2072     // if(TRK1__ok)cout<<"TRK1 ";
2073     // if(TRK2__ok)cout<<"TRK2 ";
2074     // if(TRKh__ok)cout<<"TRKH ";
2075     // if(CAL1__ok)cout<<"CAL1 ";
2076     // if(CAL2__ok)cout<<"CAL2 ";
2077     // if(TOF__ok)cout<<"TOF ";
2078     // if(TRG__ok)cout<<"TRG ";
2079     // if(AC__ok)cout<<"AC ";
2080     // if(ND__ok)cout<<"ND ";
2081     // if(S4__ok)cout<<"S4 ";
2082     // if(ORB__ok)cout<<"ORB ";
2083     // cout << endl;
2084 pam-fi 1.8
2085    
2086 pam-fi 1.13 if(TRK2 && TRK1__ok)TRK1=1;
2087     // ----------------------------------------------------------------------------
2088     // NOTA
2089     // se c'e` il level1, lo devo necessarimente leggere.
2090     // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
2091     // comunque, ma non vengono disallocati da PamLevel2::Clear()
2092     // ----------------------------------------------------------------------------
2093    
2094    
2095 pam-fi 1.6 if(!RUN__ok) {
2096 pam-fi 1.9 cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;
2097     // return false;
2098 pam-fi 1.8 };
2099    
2100     if(CAL1 && !CAL1__ok){
2101     cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl;
2102     return false;
2103     };
2104     if(CAL2 && !CAL2__ok){
2105     cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl;
2106     return false;
2107     };
2108     if(TRK2 && !TRK2__ok){
2109     cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl;
2110     return false;
2111     };
2112     if(TRK1 && !TRK1__ok){
2113     cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl;
2114     return false;
2115     };
2116     if(TRKh && !TRKh__ok){
2117     cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl;
2118     return false;
2119 pam-fi 1.6 };
2120 pam-fi 1.8 if(ORB && !ORB__ok){
2121     cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl;
2122     return false;
2123 pam-fi 1.6 };
2124 pam-fi 1.8 if(AC && !AC__ok){
2125     cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl;
2126     return false;
2127 pam-fi 1.6 };
2128     if(S4 && !S4__ok){
2129 pam-fi 1.8 cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl;
2130     return false;
2131 pam-fi 1.6 };
2132 pam-fi 1.8 if(TOF && !TOF__ok){
2133     cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl;
2134     return false;
2135 pam-fi 1.6 };
2136 pam-fi 1.8
2137 pam-fi 1.12 if(ND && !ND__ok){
2138     cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
2139     return false;
2140     };
2141     if(TRG && !TRG__ok){
2142     cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
2143     return false;
2144     };
2145    
2146 pam-fi 1.8
2147 pam-fi 1.13 // lk->Delete();
2148     // delete lk;
2149 pam-fi 1.8 f->Close();
2150 pam-fi 1.12
2151     // cout<< "CheckLevel2File(TString): detector list --> ";
2152     // if(TRK1)cout<<"TRK1 ";
2153     // if(TRK2)cout<<"TRK2 ";
2154     // if(TRKh)cout<<"TRKH ";
2155     // if(CAL1)cout<<"CAL1 ";
2156     // if(CAL2)cout<<"CAL2 ";
2157     // if(TOF)cout<<"TOF ";
2158     // if(TRG)cout<<"TRG ";
2159     // if(AC)cout<<"AC ";
2160     // if(ND)cout<<"ND ";
2161     // if(S4)cout<<"S4 ";
2162     // if(ORB)cout<<"ORB ";
2163     // cout << endl;
2164 pam-fi 1.8
2165     return true;
2166 pam-fi 1.2
2167     };
2168    
2169    
2170 pam-fi 1.9 /**
2171     * Create clone-trees
2172     */
2173 pam-fi 1.11 void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){
2174 pam-fi 1.9
2175     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2176     cout << "Create clones of PAMELA trees "<<endl;
2177    
2178     Int_t i=0;
2179 pam-fi 1.20 pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
2180     TString name = pam_tree_clone[i]->GetName();
2181 pam-fi 1.9 name.Append("_clone");
2182 pam-fi 1.20 // pam_tree_clone[i]->SetName(name.Data());
2183     cout << pam_tree_clone[i]->GetName() <<endl;
2184 pam-fi 1.9 i++;
2185    
2186     TList *li = fChain->GetListOfFriends();
2187     TIter next(li);
2188     TFriendElement* T_friend=0;
2189 pam-fi 1.11 ofile->cd();
2190 pam-fi 1.9 while( (T_friend = (TFriendElement*)next()) ){
2191     // cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2192     // cout<<T_friend->GetTree()->GetName()<< endl;
2193 pam-fi 1.20 pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2194     pam_tree_clone[i]->SetAutoSave(1000000);
2195     name = pam_tree_clone[i]->GetName();
2196 pam-fi 1.9 name.Append("_clone");
2197 pam-fi 1.20 // pam_tree_clone[i]->SetName(name.Data());
2198     cout << pam_tree_clone[i]->GetName() << endl;
2199 pam-fi 1.9 i++;
2200     }
2201 pam-fi 1.13
2202     delete li;
2203 pam-fi 1.9
2204     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2205    
2206     }
2207    
2208 pam-fi 1.11 /**
2209     * Create clone-trees
2210     */
2211     void PamLevel2::CreateCloneTrees(TFile *ofile){
2212    
2213     ofile->cd();
2214 pam-fi 1.9
2215 pam-fi 1.11 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2216     cout << "Create new PAMELA trees "<<endl;
2217 pam-fi 1.9
2218 pam-fi 1.20
2219     run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
2220     run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
2221     cout << "Run : branch RunInfo"<<endl;
2222     run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
2223     cout << "Run : branch SoftInfo"<<endl;
2224    
2225    
2226    
2227     sel_tree_clone = new TTree("SelectionList","List of selected events ");
2228     sel_tree_clone->Branch("RunEntry",&irun,"runentry/I");
2229     sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/I");
2230    
2231    
2232 pam-fi 1.11 Int_t i=0;
2233     if(TRK1||TRK2||TRKh){
2234 pam-fi 1.20 pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2235 pam-fi 1.11 if(TRK1) {
2236 pam-fi 1.20 pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2237     pam_tree_clone[i]->BranchRef();
2238 pam-fi 1.11 cout << "Tracker : branch TrkLevel1"<<endl;
2239 pam-fi 1.24 cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
2240 pam-fi 1.11 };
2241     if(TRK2) {
2242 pam-fi 1.20 pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2243 pam-fi 1.11 cout << "Tracker : branch TrkLevel2"<<endl;
2244     };
2245     if(TRKh) {
2246 pam-fi 1.20 pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2247 pam-fi 1.11 cout << "Tracker : branch TrkHough"<<endl;
2248     };
2249     i++;
2250     }
2251 pam-fi 1.9
2252 pam-fi 1.11 // Calorimeter
2253     if(CAL1||CAL2){
2254 pam-fi 1.20 pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2255 pam-fi 1.11 if(CAL1) {
2256 pam-fi 1.20 pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2257 pam-fi 1.11 cout << "Calorimeter : branch CaloLevel1"<<endl;
2258     };
2259     if(CAL2) {
2260 pam-fi 1.20 pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2261 pam-fi 1.11 cout << "Calorimeter : branch CaloLevel2"<<endl;
2262     };
2263     i++;
2264     }
2265 pam-fi 1.9
2266 pam-fi 1.11 // ToF
2267     if(TOF) {
2268 pam-fi 1.20 pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2269     pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2270 pam-fi 1.11 cout << "ToF : branch ToFLevel2"<<endl;
2271     i++;
2272     };
2273     // Trigger
2274     if(TRG) {
2275 pam-fi 1.20 pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2276     pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2277 pam-fi 1.11 cout << "Trigger : branch TrigLevel2"<<endl;
2278     i++;
2279     };
2280     // S4
2281     if(S4) {
2282 pam-fi 1.20 pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");
2283     pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2284 pam-fi 1.11 cout << "S4 : branch S4Level2"<<endl;
2285     i++;
2286     };
2287     // Neutron Detector
2288     if(ND) {
2289 pam-fi 1.20 pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");
2290     pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2291 pam-fi 1.11 cout << "NeutronD : branch NDLevel2"<<endl;
2292     i++;
2293     };
2294     // Anticounters
2295     if(AC) {
2296 pam-fi 1.20 pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");
2297     pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2298 pam-fi 1.11 cout << "Anticounter : branch AcLevel2"<<endl;
2299     i++;
2300     };
2301     // OrbitalInfo
2302     if(ORB) {
2303 pam-fi 1.20 pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info ");
2304     pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2305 pam-fi 1.11 cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
2306     i++;
2307     };
2308     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2309 pam-fi 1.9
2310 pam-fi 1.11 }
2311 pam-fi 1.9
2312    
2313     /**
2314     * Fill tree (created with CreateCloneTrees)
2315     *
2316     */
2317     //void PamLevel2::FillNewPamTree(TTree *T){
2318     void PamLevel2::FillCloneTrees(){
2319 pam-fi 1.20
2320     // cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
2321 pam-fi 1.24
2322 pam-fi 1.20 for(Int_t i=0; i<NCLONES; i++){
2323     if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2324     }
2325     if(sel_tree_clone)sel_tree_clone->Fill();
2326 pam-fi 1.21
2327 pam-fi 1.9 }
2328    
2329    
2330     TTree* PamLevel2::GetCloneTree(TString name){
2331    
2332 pam-fi 1.20 for(Int_t i=0; i<NCLONES; i++){
2333     if(pam_tree_clone[i]){
2334     TString na = pam_tree_clone[i]->GetName();
2335     if(!name.CompareTo(na))return pam_tree_clone[i];
2336 pam-fi 1.9 };
2337     }
2338 pam-fi 1.20 if(run_tree_clone){
2339     TString na = run_tree_clone->GetName();
2340     if(!name.CompareTo(na))return run_tree_clone;
2341     }
2342     if(sel_tree_clone){
2343     TString na = sel_tree_clone->GetName();
2344     if(!name.CompareTo(na))return sel_tree_clone;
2345     }
2346 pam-fi 1.9 return NULL;
2347    
2348     }
2349     void PamLevel2::WriteCloneTrees(){
2350     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2351     cout << "Write clones of PAMELA trees "<<endl;
2352 pam-fi 1.20 cout << run_tree_clone->GetName()<<endl;
2353     run_tree_clone->Write();
2354     cout << sel_tree_clone->GetName()<<endl;
2355     sel_tree_clone->Write();
2356     for(Int_t i=0; i<NCLONES; i++){
2357     if(pam_tree_clone[i]){
2358     cout << pam_tree_clone[i]->GetName()<<endl;
2359     pam_tree_clone[i]->Write();
2360 pam-fi 1.9 };
2361     }
2362     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2363    
2364     }
2365    
2366     /**
2367 pam-fi 1.24 * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
2368 pam-fi 1.9 */
2369 pam-fi 1.20 Int_t PamLevel2::GetEntry(Int_t iee){
2370 pam-fi 1.9
2371 pam-fi 1.20 if(!pam_tree){
2372 mocchiut 1.28 cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
2373 pam-fi 1.20 return 0;
2374     }
2375 mocchiut 1.28
2376    
2377     //
2378     // 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...
2379     //
2380     // if(!run_tree ){
2381     // cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
2382     // return 0;
2383     // }
2384 pam-fi 1.20
2385     Int_t ii=0;
2386     //-------------------------------
2387     ii = iee;
2388     if( !pam_tree->GetEntry(ii) ) return 0;
2389 mocchiut 1.28
2390     //
2391     // ... 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.
2392     // 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
2393     // a problem if you don't check the return code of getentry.
2394     //
2395     if(!run_tree ){
2396 mocchiut 1.29 if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
2397     cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
2398     return 0;
2399     } else {
2400     return 1; //cosi` se non c'e` run esce qua...
2401     }
2402 mocchiut 1.28 }
2403    
2404 pam-fi 1.20 //-------------------------------
2405     ii = iee;
2406 pam-fi 1.21 Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
2407 pam-fi 1.20 if(SELLI==0)irunentry = iee-runfirstentry;
2408 pam-fi 1.21 if(UPDATED && run_tree_clone)run_tree_clone->Fill();
2409 pam-fi 1.20
2410     // cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
2411    
2412     if( TRK0 || CAL0 || TOF0 )GetYodaEntry( );
2413    
2414     return 1;
2415    
2416     }
2417    
2418     /**
2419     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2420     * Given the run ID (...), if needed it query the DB and load the proper file.
2421     * @return Pointer to the tree
2422     */
2423    
2424    
2425     TTree* PamLevel2::GetYodaTree( ){
2426    
2427     // cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
2428     //===================================
2429     // check if iroot has changed
2430     //===================================
2431     if( irun<0 ){
2432     cout << "PamLevel2::GetYodaTree() -- ERROR "<<endl;
2433     cout << "In order to use this method you have to load the RunInfo tree "<<endl;
2434     cout << "with the method TChain* PamLevel2::GetRunTree(TString, TString)"<<endl;
2435     // cout << " - read the event with PamLevel2::GetEntry(Int_t)"<<endl;
2436     return NULL;
2437     }
2438     Int_t irootnew = run_obj->ID_ROOT_L0;
2439 pam-fi 1.24 // cout << "iroot "<<iroot<<endl;
2440     // cout << "irootnew "<<irootnew<<endl;
2441 pam-fi 1.20
2442     //===================================
2443     // load the level0 file
2444     // (if not already loaded)
2445     //===================================
2446     if( iroot != irootnew || !l0_tree){
2447     iroot = irootnew;
2448     //===================================
2449     // open the DB connection
2450     // (if not already opened)
2451     //===================================
2452     if(!dbc || (dbc && !dbc->IsConnected())){
2453     cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2454     cout<<"Connecting to DB"<<endl;
2455     cout<<"HOST "<<host<<endl;
2456     cout<<"USER "<<user<<endl;
2457     cout<<"PSW "<<psw<<endl;
2458     dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
2459     if( !dbc )return NULL;
2460     if( !dbc->IsConnected() )return NULL;
2461     // cout<<"...done"<<endl;
2462     cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2463     }else{
2464     // cout<<"DB already connected"<<endl;
2465     }
2466     GL_ROOT glroot = GL_ROOT();
2467 pam-fi 1.24 if( glroot.Query_GL_ROOT(iroot,dbc) ){
2468     cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
2469     return NULL;
2470     };
2471 pam-fi 1.20 TString filename = glroot.PATH + glroot.NAME;
2472     if(l0_file){
2473     l0_file->Close();
2474     l0_file->Delete();
2475     }
2476     cout << "Opening LEVEL0 file: "<< filename << endl;
2477     FileStat_t t;
2478     if( gSystem->GetPathInfo(filename.Data(),t) ){
2479     cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
2480     return NULL;
2481     }
2482     l0_file = new TFile(filename);
2483     if( !l0_file )return NULL;
2484     l0_tree = (TTree*)l0_file->Get("Physics");
2485     if(!h0_obj)h0_obj = new EventHeader();
2486     l0_tree->SetBranchAddress("Header" ,&h0_obj);
2487 mocchiut 1.30 prevshift = 0;
2488 pam-fi 1.20 //---------------------------------------------------
2489     // TRACKER:
2490     if(TRK0){
2491     if(!trk0_obj){
2492     trk0_obj = new TrkLevel0();
2493     trk0_obj->Set();
2494     };
2495     l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
2496     }
2497     //---------------------------------------------------
2498     // CALORIMETER:
2499     if(CAL0){
2500 mocchiut 1.30 if(!calo0_obj){
2501     calo0_obj = new CaloLevel0();
2502     calo0_obj->Set();
2503     };
2504     l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
2505     // cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
2506 pam-fi 1.20 }
2507     //---------------------------------------------------
2508     // TOF:
2509     if(TOF0){
2510     cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
2511     }
2512    
2513     };
2514    
2515 pam-fi 1.26 if(!dbc || (dbc && !dbc->IsConnected())){
2516     cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
2517     }
2518    
2519 mocchiut 1.30 if ( TRK0 ) TrkParams::SetCalib(run_obj,dbc);
2520 pam-fi 1.26
2521    
2522 pam-fi 1.24 // cout << l0_tree << endl;
2523    
2524 pam-fi 1.20 return l0_tree;
2525 pam-fi 1.9
2526 pam-fi 1.20 }
2527 pam-fi 1.9
2528 pam-fi 1.20 /**
2529     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2530     */
2531     Int_t PamLevel2::GetYodaEntry(){
2532 pam-fi 1.9
2533 pam-fi 1.20 // cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
2534     if(!GetYodaTree())return 0;
2535    
2536 pam-fi 1.27 // patch
2537     if( (Int_t)irunentry < 0){
2538     cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
2539     irunentry=0;
2540     }
2541 pam-fi 1.20 // ---------------------------------
2542     // if file is NOT a preselected file
2543     // ---------------------------------
2544 pam-fi 1.27 UInt_t quellagiusta = irunentry + run_obj->EV_FROM;
2545    
2546 pam-fi 1.24
2547 pam-fi 1.26 // cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
2548     // cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
2549     // cout << " time "<< GetOrbitalInfo()->absTime << endl;
2550     // cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
2551    
2552 pam-fi 1.24 if( !GetOrbitalInfo() ){
2553     cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
2554     return 0;
2555     }
2556    
2557     // ---------------------------------------------------------------------
2558     // ATTENTION!!!
2559     // If data are not pre-processed with cleaner, the level0 tree may contain
2560     // spurious nested physics packets.
2561     // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
2562     // while level2 tree DOES NOT!!
2563     // This means that "quellagiusta" in these cases is not correct.
2564     // In order to retrieve the correct level0 event, I implemented a check
2565     // of the OBT and pkt-number. In case of mismatch, the level0 entry number
2566     // is shift forward until when the packets match.
2567     // ---------------------------------------------------------------------
2568     Int_t answer = 0;
2569     Int_t shift =0;
2570     do{
2571 mocchiut 1.30 if(shift>0){
2572     cout << " level0 <--> level2 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" )"<<endl;
2573 pam-fi 1.26 }
2574 mocchiut 1.30 answer = l0_tree->GetEntry(quellagiusta+shift+prevshift);
2575 pam-fi 1.24 shift++;
2576     if( !GetEventHeader() ){
2577     cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
2578     return 0;
2579     }
2580 pam-fi 1.26 // if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
2581     // cout << " GetOrbitalInfo()->OBT "<< GetOrbitalInfo()->OBT << endl;
2582     // cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
2583     // cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl;
2584     // cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
2585 mocchiut 1.30 if ( prevshift != 0 && (quellagiusta+shift) == GetYodaTree()->GetEntries() ){
2586     prevshift = 0;
2587     shift = -1;
2588     };
2589 pam-fi 1.26
2590     }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+shift) < GetYodaTree()->GetEntries() );
2591 pam-fi 1.9
2592 mocchiut 1.30 if ( (quellagiusta+shift) == GetYodaTree()->GetEntries() ) cout << " Big trouble here, no such event in Level0 data! " <<endl;
2593    
2594 pam-fi 1.20 // cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
2595 pam-fi 1.24 // return GetYodaTree()->GetEntry(quellagiusta);
2596 mocchiut 1.30 if ( shift > 1 ) prevshift += (shift-1);
2597 pam-fi 1.20
2598 pam-fi 1.24 return answer;
2599 pam-fi 1.20
2600     }
2601 mocchiut 1.30
2602    

  ViewVC Help
Powered by ViewVC 1.1.23