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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.23