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

Diff of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by pam-fi, Mon Dec 11 17:49:03 2006 UTC revision 1.33 by pam-fi, Wed Mar 21 09:07:32 2007 UTC
# Line 7  Line 7 
7   * Default constructor   * Default constructor
8   */   */
9  PamTrack::PamTrack(){  PamTrack::PamTrack(){
10      trk_track  = this->TrkTrack::GetTrkTrack();      trk_track  = 0;
11      calo_track = this->CaloTrkVar::GetCaloTrkVar();      calo_track = 0;
12      tof_track  = this->ToFTrkVar::GetToFTrkVar();      tof_track  = 0;
13        candeleteobj = 0;
14  };  };
15  //--------------------------------------  //--------------------------------------
16  //  //
# Line 19  PamTrack::PamTrack(){ Line 20  PamTrack::PamTrack(){
20   * Constructor   * Constructor
21   */   */
22  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){
23      trk_track  = this->TrkTrack::GetTrkTrack();  
24      calo_track = this->CaloTrkVar::GetCaloTrkVar();      trk_track  = 0;
25      tof_track  = this->ToFTrkVar::GetToFTrkVar();      calo_track = 0;
26      if(t) *trk_track  = *t;      tof_track  = 0;
27      if(c) *calo_track = *c;  //     if(t)trk_track  = new TrkTrack(*t);
28      if(o) *tof_track  = *o;      //     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  };  };
36    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    
53    //    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  //--------------------------------------  //--------------------------------------
84  //  //
85  //  //
# Line 36  PamTrack::PamTrack(TrkTrack* t, CaloTrkV Line 89  PamTrack::PamTrack(TrkTrack* t, CaloTrkV
89   */   */
90  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
91                    
92      trk2_obj  = TrkLevel2::GetTrkLevel2();  //     trk2_obj  = TrkLevel2::GetTrkLevel2();
93      trk1_obj  = TrkLevel1::GetTrkLevel1();  //     trk1_obj  = TrkLevel1::GetTrkLevel1();
94      trkh_obj  = TrkHough::GetTrkHough();  //     trkh_obj  = TrkHough::GetTrkHough();
95      calo1_obj = CaloLevel1::GetCaloLevel1();  //     calo1_obj = CaloLevel1::GetCaloLevel1();
96      calo2_obj = CaloLevel2::GetCaloLevel2();  //     calo2_obj = CaloLevel2::GetCaloLevel2();
97      tof_obj   = ToFLevel2::GetToFLevel2();  //     tof_obj   = ToFLevel2::GetToFLevel2();
98      trig_obj  = TrigLevel2::GetTrigLevel2();  //     trig_obj  = TrigLevel2::GetTrigLevel2();
99      s4_obj    = S4Level2::GetS4Level2();  //     s4_obj    = S4Level2::GetS4Level2();
100      nd_obj    = NDLevel2::GetNDLevel2();  //     nd_obj    = NDLevel2::GetNDLevel2();
101      ac_obj    = AcLevel2::GetAcLevel2();  //     ac_obj    = AcLevel2::GetAcLevel2();
102      orb_obj   = OrbitalInfo::GetOrbitalInfo();  //     orb_obj   = OrbitalInfo::GetOrbitalInfo();
103        
104      run_obj   = new GL_RUN();      h0_obj    = 0;
105            trk0_obj  = 0;
106  //     trk1_clone  = 0;      calo0_obj  = 0;
107  //     trk2_clone  = 0;  
108  //     trkh_clone  = 0;      trk2_obj  = 0;
109  //     calo1_clone = 0;      trk1_obj  = 0;
110  //     calo2_clone = 0;      trkh_obj  = 0;
111  //     tof_clone   = 0;      calo1_obj = 0;
112  //     trig_clone  = 0;      calo2_obj = 0;
113  //     s4_clone    = 0;      tof_obj   = 0;
114  //     nd_clone    = 0;      trig_obj  = 0;
115  //     ac_clone    = 0;      s4_obj    = 0;
116  //     orb_clone   = 0;      nd_obj    = 0;
117        ac_obj    = 0;
118  //     T_clone  = 0;      orb_obj   = 0;
119  //     C_clone  = 0;  
120  //     O_clone  = 0;      run_obj   = 0;//new GL_RUN();
121  //     R_clone  = 0;      soft_obj   = 0;// Emiliano
122  //     S_clone  = 0;      irun = -1LL;
123  //     N_clone  = 0;      runfirstentry = 0LL;
124  //     A_clone  = 0;      runlastentry = 0LL;
125  //     B_clone  = 0;  
126        l0_file = NULL;
127        l0_tree = NULL;
128        iroot   = -1;
129        dbc     = 0;
130    
131        prevshift = 0;
132        
133        run_tree = NULL;
134        run_tree_clone = NULL;
135        sel_tree = NULL;
136        sel_tree_clone = NULL;
137        
138        irunentry = -1LL;
139        pam_tree = NULL;
140        for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
141    
142        host = "mysql://localhost/pamelaprod";
143        user = "anonymous";
144        psw = "";
145        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
146        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
147        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
148        if ( !pamdbhost ) pamdbhost = "";
149        if ( !pamdbuser ) pamdbuser = "";
150        if ( !pamdbpsw ) pamdbpsw = "";
151        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
152        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
153        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
154    
155      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      
156    
157      sorted_tracks = new TRefArray();  //    sorted_tracks = 0;//new TRefArray();
158            
159        CAL0 = false;
160      CAL1 = true;      CAL1 = true;
161      CAL2 = true;      CAL2 = true;
162      TRK2 = true;      TRK2 = true;
163      TRK1 = false;      TRK1 = false;
164      TRKh = false;      TRKh = false;
165      TRG = true;      TRKh = false;
166      TOF = true;      TRG  = true;
167      S4  = true;      TOF  = true;
168      ND  = true;      TOF0 = false;
169      AC  = true;      S4   = true;
170      ORB = true;      ND   = true;
171        AC   = true;
172        ORB  = true;
173            
174        RUN  = true;
175    
176        SELLI = -1;
177    
178        tsorted=0;
179        timage=0;
180    
181  };  };
182  /**  /**
183   * Destructor   * Delete the event (act as Dtor)
184   */   */
185  PamLevel2::~PamLevel2(){                  void PamLevel2::Delete(){
186      delete run_obj;          
187      Clear();      if(run_obj)delete run_obj;
188        if(soft_obj)delete soft_obj; //Emiliano
189    
190    //    cout << "void PamLevel2::Clear()"<<endl;
191        if(h0_obj)   delete h0_obj;
192        if(trk0_obj) delete trk0_obj;      
193        if(calo0_obj) delete calo0_obj;    
194        if(trk1_obj) delete trk1_obj;      
195        if(trk2_obj) delete trk2_obj;
196        if(trkh_obj) delete trkh_obj;
197        if(calo1_obj)delete calo1_obj;
198        if(calo2_obj)delete calo2_obj;
199        if(tof_obj)  delete tof_obj;
200        if(trig_obj) delete trig_obj;
201        if(s4_obj)   delete s4_obj;
202        if(nd_obj)   delete nd_obj;
203        if(ac_obj)   delete ac_obj;
204        if(orb_obj)  delete orb_obj;
205        
206        if(tsorted){
207            tsorted->Delete();
208            delete tsorted;
209        }
210        if(timage){
211            timage->Delete();
212            delete timage;
213        }
214    
215        if(dbc){
216            dbc->Close();
217            delete dbc;
218        }
219        
220        if(l0_file)l0_file->Close();
221        if(pam_tree)pam_tree->Delete();;
222        if(run_tree)run_tree->Delete();;
223        if(sel_tree)sel_tree->Delete();;
224        for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
225        if(run_tree_clone)run_tree_clone->Delete();;
226        if(sel_tree_clone)sel_tree_clone->Delete();;
227        
228    
229  };  };
230    
231  /**  /**
232   * Clear the event   * Clear the event (NB! does not deallocate objects)
233   */   */
234  void PamLevel2::Clear(){  void PamLevel2::Clear(){
235                    
236      TrkLevel1::Clear();  //    cout << "void PamLevel2::Clear()"<<endl;
237            
238      TrkLevel2::Clear();  //
239      CaloLevel2::Clear();  // 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
240      ToFLevel2::Clear();  // want to load them for each event even if they are the same...
241      TrigLevel2::Clear();  //
242      S4Level2::Clear();  //    if(run_obj)delete run_obj;
243      NDLevel2::Clear();  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
244      AcLevel2::Clear();  //    if(soft_obj) soft_obj->Clear();
245      OrbitalInfo::Clear();  
246        if(h0_obj)   h0_obj->Clear();      
247  //     if(trk1_clone)trk1_clone->Clear();  //    if(trk0_obj) trk0_obj->Clear();  
248  //     if(trk2_clone)trk2_clone->Clear();      if(calo0_obj) calo0_obj->Clear();  
249  //     if(trkh_clone)trkh_clone->Clear();      if(trk1_obj) trk1_obj->Clear();    
250  //     if(calo1_clone)calo1_clone->Clear();      if(trk2_obj) trk2_obj->Clear();
251  //     if(calo2_clone)calo2_clone->Clear();      if(trkh_obj) trkh_obj->Clear();
252  //     if(tof_clone)tof_clone->Clear();      if(calo1_obj)calo1_obj->Clear();
253  //     if(trig_clone)trig_clone->Clear();      if(calo2_obj)calo2_obj->Clear();
254  //     if(s4_clone)s4_clone->Clear();      if(tof_obj)  tof_obj->Clear();
255  //     if(nd_clone)nd_clone->Clear();      if(trig_obj) trig_obj->Clear();
256  //     if(ac_clone)ac_clone->Clear();      if(s4_obj)   s4_obj->Clear();
257  //     if(orb_clone)orb_clone->Clear();      if(nd_obj)   nd_obj->Clear();
258        if(ac_obj)   ac_obj->Clear();
259        if(orb_obj)  orb_obj->Clear();
260            
261      sorted_tracks->Delete(); // clean the reference array  //    if(sorted_tracks)sorted_tracks->Clear();
262    //    sorted_tracks.Clear();
263    
264        if(tsorted){
265            tsorted->Delete();
266        }
267        if(timage){
268            timage->Delete();
269        }
270            
271  };  };
272    
# Line 136  void PamLevel2::Clear(){ Line 278  void PamLevel2::Clear(){
278  void *PamLevel2::GetPointerTo(const char* c ){  void *PamLevel2::GetPointerTo(const char* c ){
279    
280      TString objname = c;      TString objname = c;
281      if(!objname.CompareTo("TrkLevel1"))return &trk1_obj;  
282      if(!objname.CompareTo("TrkLevel2"))return &trk2_obj;      if(!objname.CompareTo("TrkLevel1"))  {
283      if(!objname.CompareTo("TrkHough"))return &trkh_obj;          if(!trk1_obj){
284      if(!objname.CompareTo("CaloLevel1"))return &calo1_obj;              trk1_obj  = new TrkLevel1();
285      if(!objname.CompareTo("CaloLevel2"))return &calo2_obj;              trk1_obj->Set();
286      if(!objname.CompareTo("ToFLevel2"))return &tof_obj;          }
287      if(!objname.CompareTo("TrigLevel2"))return &trig_obj;          return &trk1_obj;
288      if(!objname.CompareTo("S4Level2"))return &s4_obj;      };
289      if(!objname.CompareTo("NDLevel2"))return &nd_obj;      if(!objname.CompareTo("TrkLevel2"))  {
290      if(!objname.CompareTo("AcLevel2"))return &ac_obj;          if(!trk2_obj){  
291      if(!objname.CompareTo("OrbitalInfo"))return &orb_obj;              trk2_obj  = new TrkLevel2();
292                trk2_obj->Set();
293            }
294            return &trk2_obj;
295        };
296        if(!objname.CompareTo("TrkHough"))   {
297            if(!trkh_obj)  trkh_obj  = new TrkHough();
298            return &trkh_obj;
299        };
300        if(!objname.CompareTo("CaloLevel1")) {
301            if(!calo1_obj) calo1_obj = new CaloLevel1();
302            return &calo1_obj;
303        };
304        if(!objname.CompareTo("CaloLevel2")) {
305            if(!calo2_obj){
306                calo2_obj = new CaloLevel2();
307                calo2_obj->Set();
308            };
309            return &calo2_obj;
310        };
311        if(!objname.CompareTo("ToFLevel2"))  {
312            if(!tof_obj){
313                tof_obj   = new ToFLevel2();
314                tof_obj->Set();
315            }
316            return &tof_obj;
317        };
318        if(!objname.CompareTo("TrigLevel2")) {
319            if(!trig_obj)  trig_obj  = new TrigLevel2();
320            return &trig_obj;
321        };
322        if(!objname.CompareTo("S4Level2"))   {
323            if(!s4_obj)    s4_obj    = new S4Level2();
324            return &s4_obj;
325        };
326        if(!objname.CompareTo("NDLevel2"))   {
327            if(!nd_obj)    nd_obj    = new NDLevel2();
328            return &nd_obj;
329        };
330        if(!objname.CompareTo("AcLevel2"))   {
331            if(!ac_obj)    ac_obj    = new AcLevel2();
332            return &ac_obj;
333        };
334        if(!objname.CompareTo("OrbitalInfo")){
335            if(!orb_obj)   orb_obj   = new OrbitalInfo();
336            return &orb_obj;
337        };
338        
339      if(!objname.CompareTo("RunInfo"))return &run_obj;      if(!objname.CompareTo("RunInfo"))return &run_obj;
340    
341        if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
342    
343      return NULL;      return NULL;
344  };  };
345  //--------------------------------------  //--------------------------------------
# Line 159  void *PamLevel2::GetPointerTo(const char Line 351  void *PamLevel2::GetPointerTo(const char
351   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
352   */   */
353   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
354                
355       if( CaloLevel2::ntrk()==0 ){       if( !calo2_obj )return 0;
356    
357         if( calo2_obj->CaloLevel2::ntrk()==0 ){
358           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
359           return NULL;           return NULL;
360       };       };
# Line 169  void *PamLevel2::GetPointerTo(const char Line 363  void *PamLevel2::GetPointerTo(const char
363       Int_t it_calo=0;       Int_t it_calo=0;
364            
365       do{       do{
366           c = CaloLevel2::GetCaloTrkVar(it_calo);           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
367           it_calo++;           it_calo++;
368       } while( c && seqno != c->trkseqno && it_calo < CaloLevel2::ntrk());             } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
369            
370       if(!c || seqno != c->trkseqno){       if(!c || seqno != c->trkseqno){
371           c = 0;           c = 0;
# Line 190  void *PamLevel2::GetPointerTo(const char Line 384  void *PamLevel2::GetPointerTo(const char
384   */   */
385   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
386                    
387       if( ToFLevel2::ntrk()==0 ){       if( !tof_obj )return 0;
388    
389         if( tof_obj->ToFLevel2::ntrk()==0 ){
390           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
391           return NULL;           return NULL;
392       };       };
# Line 199  void *PamLevel2::GetPointerTo(const char Line 395  void *PamLevel2::GetPointerTo(const char
395       Int_t it_tof=0;       Int_t it_tof=0;
396            
397       do{       do{
398           c = ToFLevel2::GetToFTrkVar(it_tof);           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
399           it_tof++;           it_tof++;
400       } while( c && seqno != c->trkseqno && it_tof < ToFLevel2::ntrk());       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());        
401            
402       if(!c || seqno != c->trkseqno){       if(!c || seqno != c->trkseqno){
403           c = 0;           c = 0;
# Line 219  void *PamLevel2::GetPointerTo(const char Line 415  void *PamLevel2::GetPointerTo(const char
415   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.
416   */   */
417   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
418                
419         cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
420         cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
421    
422       CaloTrkVar *c = 0;       CaloTrkVar *c = 0;
423       ToFTrkVar  *o = 0;       ToFTrkVar  *o = 0;
424            
# Line 244  void *PamLevel2::GetPointerTo(const char Line 443  void *PamLevel2::GetPointerTo(const char
443    
444  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
445            
446        cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
447        cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;
448        cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
449      PamTrack *track = 0;      PamTrack *track = 0;
450            
451      if( itrk >=0 && itrk < TrkLevel2::ntrk() ){      if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){
452                    
453          TrkTrack *t = TrkLevel2::GetStoredTrack(itrk);          TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
454          track = GetPamTrackAlong(t);          track = GetPamTrackAlong(t);
455                    
456            
457    
458      }else{      }else{
459          cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;          cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
460      };      };
461            
462      return track;      return track;
# Line 275  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 479  PamTrack* PamLevel2::GetStoredTrack(Int_
479   */   */
480  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
481    
482    //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;
483        if( !trk2_obj ){
484            cout << "void PamLevel2::SortTracks(TString how):  TrkLevel2 not loaded !!!";
485            return;
486        };
487  //    cout << "call SortTracs() "<<endl;  //    cout << "call SortTracs() "<<endl;
488    //Save current Object count    //Save current Object count
489      Int_t ObjectNumber = TProcessID::GetObjectCount();      Int_t ObjectNumber = TProcessID::GetObjectCount();
490    
491  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;
492        
493      sorted_tracks->Delete(); //temporaneo???  //     if(!sorted_tracks)sorted_tracks = new TRefArray();
494            //     sorted_tracks->Clear();
495    //    sorted_tracks.Clear();
496    
497        if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
498        tsorted->Delete();
499        TClonesArray &ttsorted = *tsorted;
500        if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
501        timage->Delete();
502        TClonesArray &ttimage = *timage;
503    
504    
505      // loop over the tracks sorted by the tracker      // loop over the tracks sorted by the tracker
506      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
507      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
# Line 298  void PamLevel2::SortTracks(TString how){ Line 517  void PamLevel2::SortTracks(TString how){
517    
518      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
519            
520      for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
521                    
522          TrkTrack *ts = 0;          TrkTrack   *ts = 0;
523            CaloTrkVar *cs = 0;
524            ToFTrkVar  *os = 0;
525                    
526          // get tracker tracks          // get tracker tracks
527          TrkTrack   *tp = TrkLevel2::GetTrack(i);                    //tracker          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i);                    //tracker
528          CaloTrkVar *cp = 0;          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
529          ToFTrkVar  *op = 0;          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
530    
531            TrkTrack   *ti = 0;              //tracker (image)
532            CaloTrkVar *ci = 0;
533            ToFTrkVar  *oi = 0;
534  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
535          // if track has an image, check image selection          // if track has an image, check image selection
536          if(tp->HasImage()){          if(tp->HasImage()){
537                            
538              TrkTrack   *ti = TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
539              CaloTrkVar *ci = 0;              ci = GetCaloStoredTrack(ti->GetSeqNo());
540              ToFTrkVar  *oi = 0;              oi = GetToFStoredTrack(ti->GetSeqNo());
541                            
542  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
543    
# Line 326  void PamLevel2::SortTracks(TString how){ Line 550  void PamLevel2::SortTracks(TString how){
550              // ------------------------              // ------------------------
551              // check the Y spatial residual on the first calorimeter plane              // check the Y spatial residual on the first calorimeter plane
552              // (cut on calorimeter variables from Emiliano)              // (cut on calorimeter variables from Emiliano)
553                if( use_CAL && !calo2_obj ){
554                    cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but CaloLevel2 not loaded !!!";
555                    return;
556                };
557              if(              if(
558                  use_CAL            &&                  use_CAL            &&
559                  npcfit[1] > 15     &&   //no. of fit planes on Y view                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view
560                  varcfit[1] < 1000. &&  //fit variance on Y view                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
561                    cp && ci &&
562                  true){                  true){
563    
                 cp = GetCaloStoredTrack(tp->GetSeqNo());  
                 ci = GetCaloStoredTrack(ti->GetSeqNo());  
564                                    
565                  Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;                  Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;
566                  Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;                  Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;
567                                    
568                  if(resy_p <= resy_i) tp_score++;                  if(resy_p <= resy_i) tp_score++;
569                  else                 ti_score++;                  else                 ti_score++;
# Line 349  void PamLevel2::SortTracks(TString how){ Line 576  void PamLevel2::SortTracks(TString how){
576              // ------------------------                  // ------------------------    
577              // check the number of hit pmts along the track              // check the number of hit pmts along the track
578              // on S12 S21 and S32, where paddles are parallel to Y axis              // on S12 S21 and S32, where paddles are parallel to Y axis
579              if( use_TOF ){              if( use_TOF && !tof_obj ){
580                    cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";
581                    return;
582                };
583                if( use_TOF && op && oi ){
584                                    
585                  Int_t nphit_p =0;                  Int_t nphit_p =0;
586                  Int_t nphit_i =0;                  Int_t nphit_i =0;
587                                    
                 op = GetToFStoredTrack(tp->GetSeqNo());  
                 oi = GetToFStoredTrack(ti->GetSeqNo());  
588                                    
589  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;
590                                  cout << "track: npmttdc "<< op->npmttdc << endl;                                  cout << "track: npmttdc "<< op->npmttdc << endl;
# Line 363  void PamLevel2::SortTracks(TString how){ Line 592  void PamLevel2::SortTracks(TString how){
592                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
593                                    
594                  for (Int_t ih=0; ih < op->npmtadc; ih++){                  for (Int_t ih=0; ih < op->npmtadc; ih++){
595                      Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) );                      Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
596                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
597                  };                  };
598                                    
599                  for (Int_t ih=0; ih < oi->npmtadc; ih++){                  for (Int_t ih=0; ih < oi->npmtadc; ih++){
600                      Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) );                      Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
601                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
602                  };                  };
603                                    
# Line 398  void PamLevel2::SortTracks(TString how){ Line 627  void PamLevel2::SortTracks(TString how){
627              // ------------------------              // ------------------------
628              // the winner is....              // the winner is....
629              // ------------------------                  // ------------------------    
630              if      (tp_score > ti_score) ts = tp;//the track sorted by the tracker!!              if      (tp_score > ti_score) {
631              else if (tp_score < ti_score) ts = ti;//its image!!  //              ts = tp;//the track sorted by the tracker!!
632              else {  //              cs = cp;
633                  ts = tp;  //              os = op;
634                }else if (tp_score < ti_score) {
635                    ts = ti;//its image!!
636                    cs = ci;
637                    os = oi;
638    
639                    ti = tp;//its image!!
640                    ci = cp;
641                    oi = op;
642    
643                    tp = ts;//its image!!
644                    cp = cs;
645                    op = os;
646    
647                    
648                }else {
649    //              ts = tp;
650    //              cs = cp;
651    //              os = op;
652  //                              cout << "Warning - track image ambiguity not solved" << endl;  //                              cout << "Warning - track image ambiguity not solved" << endl;
653  //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;  //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;
654              };              };
655                            
656          }else{          }else{
657              ts = tp;  //          ts = tp;
658    //          cs = cp;
659    //          os = op;
660          };          };
661                    
662  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
663          sorted_tracks->Add(ts);//save the track in the sorted array  //      sorted_tracks->Add(ts);//save the track in the sorted array
664    //      sorted_tracks.Add(ts);//save the track in the sorted array
665    //      sorted_tracks.Add(tp);//save the track in the sorted array
666  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
667            //      cout<<"o "<<tp<<endl;
668    //      cout<<"o "<<cp<<endl;
669    //      cout<<"o "<<op<<endl;
670            new(ttsorted[i]) PamTrack(tp,cp,op);
671            new(ttimage[i])  PamTrack(ti,ci,oi);
672      };      };
673    
674        if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
675            cout << "void PamLevel2::SortTracks(TString how): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
676            tsorted->Delete(); tsorted=0;
677            timage->Delete(); timage=0;    
678        }
679    
680      //Restore Object count      //Restore Object count
681      //To save space in the table keeping track of all referenced objects      //To save space in the table keeping track of all referenced objects
682      //we assume that our events do not address each other. We reset the      //We reset the object count to what it was at the beginning of the event.
     //object count to what it was at the beginning of the event.  
683      TProcessID::SetObjectCount(ObjectNumber);      TProcessID::SetObjectCount(ObjectNumber);
684            
685  };  };
# Line 430  void PamLevel2::SortTracks(TString how){ Line 691  void PamLevel2::SortTracks(TString how){
691   * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.   * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
692   * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.   * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
693   */   */
694  TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
695    
696    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
697    //     SortTracks("+CAL+TOF");
698    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
699    
700    // //   return  sorted_tracks;
701    //     return &sorted_tracks;
702        
703    //  };
704    TClonesArray *PamLevel2::GetTracks(){
705    
706  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
707      SortTracks("+CAL+TOF");      SortTracks("+CAL+TOF");
708  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
709    
710      return sorted_tracks;      return tsorted;
711        
712   };   };
713  //--------------------------------------  //--------------------------------------
714   //   //
# Line 448  TRefArray *PamLevel2::GetTracks(){ Line 720  TRefArray *PamLevel2::GetTracks(){
720   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
721   */   */
722  PamTrack *PamLevel2::GetTrack(int it){  PamTrack *PamLevel2::GetTrack(int it){
723    
724    //    if(!trk2_obj) return 0;
725                    
726    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
727    //     SortTracks("+CAL+TOF");
728    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
729    // //    if(!sorted_tracks)return 0;
730    //     if(sorted_tracks.IsEmpty())return 0;
731    
732    //     PamTrack *track = 0;
733        
734    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){    
735    //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
736    //      track = GetPamTrackAlong(t);
737    //     }else{
738    //      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
739    //     };
740        
741    //     return track;
742    
743    //    cout << "PamLevel2::GetTrack(int it) "<<endl;
744  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
745      SortTracks("+CAL+TOF");      SortTracks("+CAL+TOF");
746  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
747            if(!tsorted)return 0;
748        if(!tsorted->GetEntries())return 0;
749    
750      PamTrack *track = 0;      PamTrack *track = 0;
751            
752      if( it >=0 && it < TrkLevel2::GetNTracks() && it<sorted_tracks->GetEntriesFast() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){
753          TrkTrack   *t = (TrkTrack*)sorted_tracks->At(it);  //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
754          track = GetPamTrackAlong(t);  //      track = GetPamTrackAlong(t);
755            TClonesArray &t = *(tsorted);
756            track = (PamTrack*)t[it];
757            
758      }else{      }else{
759          cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;          cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
760      };      };
761            
762      return track;      return track;
# Line 476  PamTrack *PamLevel2::GetTrack(int it){ Line 773  PamTrack *PamLevel2::GetTrack(int it){
773   */   */
774  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
775    
776    //     if(!trk2_obj) return 0;
777    
778    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
779    //     SortTracks("+CAL+TOF");
780    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
781    // //    if(!sorted_tracks)return 0;
782    //     if(sorted_tracks.IsEmpty())return 0;
783        
784    //     PamTrack *image = 0;
785        
786    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
787    //      TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);
788    //      if( temp->HasImage() ){
789    //          TrkTrack   *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
790    //          image = GetPamTrackAlong(t);
791    //      }else{
792    //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
793    //      };
794    //     }else{
795    //      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
796    //     };
797        
798    //     return image;
799    
800    
801  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
802      SortTracks("+CAL+TOF");      SortTracks("+CAL+TOF");
803  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
804        if(!timage)return 0;
805        if(!timage->GetEntries())return 0;
806            
807      PamTrack *image = 0;      PamTrack *image = 0;
808            
809      if( it >=0 && it < TrkLevel2::GetNTracks() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
810          TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);          TClonesArray &t = *(tsorted);
811          if( temp->HasImage() ){          PamTrack *temp = (PamTrack*)t[it];
812              TrkTrack   *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());          if( temp->GetTrkTrack()->HasImage() ){
813              image = GetPamTrackAlong(t);              TClonesArray &t = *(timage);
814                image = (PamTrack*)t[it];
815          }else{          }else{
816              cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;  //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
817          };          };
818      }else{      }else{
819          cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;          cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
820      };      };
821            
822      return image;      return image;
# Line 509  PamTrack *PamLevel2::GetTrackImage(int i Line 834  PamTrack *PamLevel2::GetTrackImage(int i
834   */   */
835  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
836    
837      if( !detlist.IsNull() ) SetWhichTrees(detlist);  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);
838      else                    GetWhichTrees(f);  //     else                    GetWhichTrees(f);
839        
840        cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
841    
842        SetWhichTrees(detlist);
843    
844      TTree *Trout =0;      TTree *Trout =0;
845    
846      TString fname = f->GetName();      TString fname = f->GetName();
847      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
848    
849      UInt_t *found=0;      //    UInt_t *found=0;    
850    
851        cout<< "GetPamTree(TFile*,TString): detector list --> ";
852        if(TRK1)cout<<"TRK1 ";
853        if(TRK2)cout<<"TRK2 ";
854        if(TRKh)cout<<"TRKH ";
855        if(CAL1)cout<<"CAL1 ";
856        if(CAL2)cout<<"CAL2 ";
857        if(TOF)cout<<"TOF ";
858        if(TRG)cout<<"TRG ";
859        if(AC)cout<<"AC ";
860        if(ND)cout<<"ND ";
861        if(S4)cout<<"S4 ";
862        if(ORB)cout<<"ORB ";
863        cout << endl;
864        if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
865    
866        f->cd();
867    
868  // Tracker  // Tracker
869      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
870      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
871          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
872          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
873          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
874          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
875          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
876          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
877          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
878          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
879          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
880          if(!Trout)Trout=T;          if(!Trout)Trout=T;
881          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 540  TTree *PamLevel2::GetPamTree(TFile *f, T Line 886  TTree *PamLevel2::GetPamTree(TFile *f, T
886      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
887      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
888          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
889          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
890          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
891          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
892          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
893          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
894          if(!Trout)Trout=C;          if(!Trout)Trout=C;
895          else Trout->AddFriend(C);          else Trout->AddFriend(C);
896      }else{      }else{
897          cout << "Calorimeter  : missing tree"<<endl;          cout << "Calorimeter  : missing tree"<<endl;
898      };      };
899    
900      // ToF          // ToF    
901      TTree *O = (TTree*)f->Get("ToF");      TTree *O = (TTree*)f->Get("ToF");
902      if(O && TOF) {      if(O && TOF) {
# Line 610  TTree *PamLevel2::GetPamTree(TFile *f, T Line 957  TTree *PamLevel2::GetPamTree(TFile *f, T
957      }else{      }else{
958          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
959      };      };
960    
961        TTree *L = (TTree*)f->Get("SelectionList");
962        if(L && SELLI==1) {
963    //      L->SetBranchAddress("RunEntry",&irun);
964    //      cout << "SelectionList: set branch address RunEntry"<<endl;
965    //      L->SetBranchAddress("EventEntry",&irunentry);
966    //      cout << "SelectionList: set branch address EventEntry"<<endl;
967    //      if(!Trout)Trout=O;
968    //      else Trout->AddFriend("SelectionList");
969            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
970            sel_tree = 0;
971        }else{
972            cout << "SelectionList  : missing tree"<<endl;
973        };
974            
975      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
976    
977        pam_tree = (TChain*)Trout;
978            
979      return Trout;      return Trout;
980            
# Line 638  TList*  PamLevel2::GetListOfLevel2Files( Line 1001  TList*  PamLevel2::GetListOfLevel2Files(
1001      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1002      contents->SetOwner();      contents->SetOwner();
1003            
1004      char *fullpath;  //    char *fullpath;
1005    //    const char *fullpath;
1006            
1007      // if no input file list is given:        // if no input file list is given:  
1008      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1009                    
1010          if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){        
1011              cout <<"File "<<flisttxt<<" not found"<<endl;  //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1012              return 0;  //          cout <<"File "<<flisttxt<<" not found"<<endl;
1013          }        //          return 0;
1014  //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));  //      }      
1015          flisttxt = fullpath;  //      flisttxt = fullpath;
1016                  if ( !flisttxt.EndsWith(".root") ){
1017    
1018            flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1019    
1020          if( !gSystem->ChangeDirectory(ddir) ){          if( !gSystem->ChangeDirectory(ddir) ){
1021              cout << "Cannot change directory : "<<ddir<<endl;              cout << "Cannot change directory : "<<ddir<<endl;
1022              return 0;              return 0;
# Line 658  TList*  PamLevel2::GetListOfLevel2Files( Line 1025  TList*  PamLevel2::GetListOfLevel2Files(
1025          cout <<"Input file list : " << flisttxt <<endl;          cout <<"Input file list : " << flisttxt <<endl;
1026          ifstream in;          ifstream in;
1027          in.open(flisttxt, ios::in); //open input file list          in.open(flisttxt, ios::in); //open input file list
1028            if(!in.good()){
1029                cout <<" ERROR opening the file "<<endl;
1030                gSystem->ChangeDirectory(wdir); // back to the working directory
1031                return 0;
1032            }      
1033          int line=0;          int line=0;
1034          while (1) {          while (1) {
1035              TString file;              TString file;
# Line 671  TList*  PamLevel2::GetListOfLevel2Files( Line 1043  TList*  PamLevel2::GetListOfLevel2Files(
1043              }              }
1044              if(file.Contains("#"))file = file(0,file.First("#"));              if(file.Contains("#"))file = file(0,file.First("#"));
1045  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1046              if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1047    //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1048                if( file.EndsWith(".root") ){
1049                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file));
1050                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1051                    delete fullpath;
1052              }else{              }
1053    //          }else{
1054  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1055              };  //          };
1056          };          };
1057          in.close();          in.close();
1058                  } else {
1059              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1060              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1061              delete fullpath;
1062          };        
1063      }else{      }else{
1064                    
1065          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
# Line 699  TList*  PamLevel2::GetListOfLevel2Files( Line 1078  TList*  PamLevel2::GetListOfLevel2Files(
1078          while ( (questo = (TSystemFile*) next()) ) {          while ( (questo = (TSystemFile*) next()) ) {
1079              TString name =  questo-> GetName();              TString name =  questo-> GetName();
1080              if( name.EndsWith(".root") ){              if( name.EndsWith(".root") ){
1081                  char *fullpath;  //              const char *fullpath = gSystem->FindFile(ddir,name);
1082                  gSystem->IsFileInIncludePath(name,&fullpath);  //              char *fullpath;
1083    //              gSystem->IsFileInIncludePath(name,&fullpath);
1084                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1085                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1086                    delete fullpath;
1087              };              };
1088          }          }
1089          delete temp;          delete temp;
# Line 711  TList*  PamLevel2::GetListOfLevel2Files( Line 1093  TList*  PamLevel2::GetListOfLevel2Files(
1093      gSystem->ChangeDirectory(wdir); // back to the working directory      gSystem->ChangeDirectory(wdir); // back to the working directory
1094  //      cout << endl << "Selected files:" << endl;  //      cout << endl << "Selected files:" << endl;
1095  //      contents->Print();  //      contents->Print();
1096      cout << contents->GetEntries()<<" files selected\n";      cout << contents->GetEntries()<<" files \n";
1097  //      cout << endl;  //      cout << endl;
1098  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1099      return contents;      return contents;
# Line 730  TChain *PamLevel2::GetPamTree(TList *fl, Line 1112  TChain *PamLevel2::GetPamTree(TList *fl,
1112            
1113      TChain *Trout =0;      TChain *Trout =0;
1114    
1115      if( !detlist.IsNull() )SetWhichTrees(detlist);  //    if( !detlist.IsNull() )SetWhichTrees(detlist);
1116            SetWhichTrees(detlist);
1117            
1118        cout<< "GetPamTree(TList*,TString): input detector list --> ";
1119        if(TRK1)cout<<"TRK1 ";
1120        if(TRK2)cout<<"TRK2 ";
1121        if(TRKh)cout<<"TRKH ";
1122        if(CAL1)cout<<"CAL1 ";
1123        if(CAL2)cout<<"CAL2 ";
1124        if(TOF)cout<<"TOF ";
1125        if(TRG)cout<<"TRG ";
1126        if(AC)cout<<"AC ";
1127        if(ND)cout<<"ND ";
1128        if(S4)cout<<"S4 ";
1129        if(ORB)cout<<"ORB ";
1130        cout << endl;
1131    
1132      TChain *T = 0;            TChain *T = 0;      
1133      TChain *C = 0;      TChain *C = 0;
1134      TChain *O = 0;      TChain *O = 0;
# Line 741  TChain *PamLevel2::GetPamTree(TList *fl, Line 1137  TChain *PamLevel2::GetPamTree(TList *fl,
1137      TChain *N = 0;      TChain *N = 0;
1138      TChain *A = 0;      TChain *A = 0;
1139      TChain *B = 0;      TChain *B = 0;
1140    
1141        TChain *L = 0;
1142            
1143      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1144      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 750  TChain *PamLevel2::GetPamTree(TList *fl, Line 1148  TChain *PamLevel2::GetPamTree(TList *fl,
1148      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1149      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1150      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1151    
1152         L = new TChain("SelectionList");
1153            
1154      // loop over files and create chains              // loop over files and create chains        
1155      TIter next(fl);      TIter next(fl);
1156      TSystemFile *questo = 0;      TSystemFile *questo = 0;
1157      while ( (questo = (TSystemFile*) next()) ) {      while ( (questo = (TSystemFile*) next()) ) {
1158          TString name =  questo->GetName();          TString name =  questo->GetName();
1159  //      cout << "File: "<< name << endl;          cout << "File: "<< name << endl;
1160          if( CheckLevel2File(name) ){          if( CheckLevel2File(name) ){
1161              if(TRK2||TRK1||TRKh) T->Add(name);              if(TRK2||TRK1||TRKh) T->Add(name);
1162              if(CAL1||CAL2)       C->Add(name);              if(CAL1||CAL2)       C->Add(name);
# Line 766  TChain *PamLevel2::GetPamTree(TList *fl, Line 1166  TChain *PamLevel2::GetPamTree(TList *fl,
1166              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1167              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1168              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1169                if(SELLI==1)         L->Add(name);
1170          };          };
1171      }      }
1172            
1173      cout << "done chain \n";      cout << "done chain \n";
1174    
1175      UInt_t *found=0;  //    UInt_t *found=0;
1176  // Tracker  // Tracker
1177      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1178          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1179          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1180          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1181          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1182          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1183          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1184          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1185          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1186          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1187          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1188          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
# Line 791  TChain *PamLevel2::GetPamTree(TList *fl, Line 1192  TChain *PamLevel2::GetPamTree(TList *fl,
1192      // Calorimeter      // Calorimeter
1193      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1194          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1195          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1196          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1197          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1198          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1199          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1200          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1201          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
# Line 855  TChain *PamLevel2::GetPamTree(TList *fl, Line 1256  TChain *PamLevel2::GetPamTree(TList *fl,
1256      }else{      }else{
1257          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1258      };      };
1259    
1260        // Selection List
1261        if(L && SELLI==1) {
1262            cout<<">>> Found selection-list <<<"<<endl;
1263            L->SetBranchAddress("RunEntry",&irun);
1264            cout << "SelectionList: set branch address RunEntry"<<endl;
1265            L->SetBranchAddress("EventEntry",&irunentry);
1266            cout << "SelectionList: set branch address EventEntry"<<endl;
1267            sel_tree = L;
1268    //      if(!Trout)Trout=O;
1269    //      else Trout->AddFriend("SelectionList");
1270        }else{
1271    //      cout << "SelectionList  : missing tree"<<endl;
1272            if(L)L->Delete();
1273        };
1274            
1275  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1276    
1277            pam_tree = Trout;
1278  //     // Tracker  
 //     if(TRK2||TRK1||TRKh){  
 //      if(!Tout)Tout=T;  
 //      else Tout->AddFriend("Tracker");  
 //     }  
 //     // Calorimeter  
 //     if(CAL2||CAL1) {          
 //      if(!Tout)Tout=C;  
 //      else Tout->AddFriend("Calorimeter");  
 //     };  
 //     // ToF      
 //     if(TOF) {  
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo");  
 //     };  
       
 //    cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;  
       
 //    if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );  
       
1279      return Trout;      return Trout;
1280  }  }
1281    
# Line 985  void PamLevel2::SetBranchAddress(TTree * Line 1357  void PamLevel2::SetBranchAddress(TTree *
1357          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1358          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1359      };      };
1360        // SelectionList
1361        if(SELLI==1) {
1362            t->SetBranchAddress("RunEntry", &irun);
1363            cout << "SelectionList: set branch address RunEntry"<<endl;
1364            t->SetBranchAddress("EventEntry", &irunentry);
1365            cout << "SelectionList: set branch address EventEntry"<<endl;
1366        };
1367            
1368  }  }
1369  /**  /**
# Line 1058  void PamLevel2::SetBranchAddress(TChain Line 1437  void PamLevel2::SetBranchAddress(TChain
1437          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1438          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1439      };      };
1440        // SelectionList
1441        if(SELLI==1) {
1442            t->SetBranchAddress("RunEntry", &irun);
1443            cout << "SelectionList: set branch address RunEntry"<<endl;
1444            t->SetBranchAddress("EventEntry", &irunentry);
1445            cout << "SelectionList: set branch address EventEntry"<<endl;
1446        };
1447            
1448  }  }
1449    
# Line 1085  TChain *PamLevel2::GetRunTree(TList *fl) Line 1471  TChain *PamLevel2::GetRunTree(TList *fl)
1471              R->Add(name);              R->Add(name);
1472          };          };
1473      }      }
1474    
1475        if(R->GetNtrees()){
1476            
1477      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1478      cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
1479                R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1480            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1481        }else{
1482            delete R;
1483            R=0;
1484        }
1485    
1486        run_tree = R;
1487    
1488      return R;      return R;
1489            
1490  }  }
# Line 1103  TChain *PamLevel2::GetRunTree(TList *fl) Line 1499  TChain *PamLevel2::GetRunTree(TList *fl)
1499   */   */
1500  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
1501    
1502        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1503    
1504      TTree *R = (TTree*)f->Get("Run");      TTree *R = (TTree*)f->Get("Run");
1505            
1506      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      if(R){
1507      cout << "Run         : set branch address RunInfo"<<endl;          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1508                cout << "Run         : set branch address RunInfo"<<endl;
1509            R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1510            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1511        }
1512    
1513        run_tree = (TChain*)R;
1514    
1515      return R;      return R;
1516            
1517  }  }
1518    /**
1519     * Update the runinfo informations (to be used to have Run infos event by event basis)
1520     * @param run Pointer to the chain/tree which contains run infos
1521     * @return true if a new run has been read, false if it is still the same run
1522     */
1523    Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
1524      //
1525      // check if we have already called once GetEntry, if not call it
1526      //
1527      if ( run->GetEntries() <= 0 ) return(false);
1528      //
1529      
1530    //  Int_t oldrun = irun;
1531      Long64_t oldrun = irun;
1532      // --------------------------------------
1533      // if it is a full file (not preselected)
1534      // --------------------------------------
1535      if(SELLI==0){
1536    
1537          if( !GetOrbitalInfo() ){
1538              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1539              return(false);
1540          }
1541    
1542          if ( irun < 0 ){
1543              irun = 0;
1544              run->GetEntry(irun);
1545              runfirstentry = 0LL;
1546              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1547              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
1548    //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1549    //        cout << "runfirstentry "<<runfirstentry<<endl;
1550    //        return(true);
1551          };      
1552    
1553          // modificato il controllo sull'aggiornamento del run, per evitare problemi
1554          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
1555          //
1556          bool fromfirst = true;
1557          //
1558          while ( !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1 ){
1559    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1560              irun++;
1561              run->GetEntry(irun);
1562              runfirstentry = runlastentry;
1563              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
1564              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1565    //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1566    //        cout << "runfirstentry "<<runfirstentry<<endl;
1567              //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1568              //      printf(" abstime %u trailertime %u \n",GetOrbitalInfo()->absTime,GetRunInfo()->RUNTRAILER_TIME);
1569              //      printf(" IDRUN %u \n",GetRunInfo()->ID);
1570              //
1571    //        prevshift = 0;
1572              //
1573              if ( irun == run->GetEntries()-1 && fromfirst && !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)){
1574                  printf(" resetting irun  (it should NOT happen!!!)\n");
1575                  fromfirst = false;
1576                  irun = 0;
1577                  run->GetEntry(irun);
1578                  runfirstentry = 0ULL;
1579                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1580                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
1581              };
1582              //
1583          };
1584          //
1585          if ( !fromfirst &&
1586               !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&
1587                 GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)
1588              ) {
1589              printf(" Something very wrong here: cannot find RUN containing absolute time %u \n",GetOrbitalInfo()->absTime);
1590              return false;
1591          }
1592          //
1593          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1594          //
1595          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1596          //
1597          prevshift = 0;
1598          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1599          cout << "runfirstentry "<<runfirstentry<<endl;
1600          return(true);    
1601      };
1602      // ----------------------------------------------------
1603      // if it is a preselected file (there is SelectionList)
1604      // NBNB - the event tree MUST be read first
1605      // ----------------------------------------------------
1606      if(SELLI==1){      
1607          sel_tree->GetEntry(iev);
1608          if(irun != oldrun){
1609              run->GetEntry(irun);
1610              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1611              prevshift = 0;
1612              return true;
1613          }
1614          return false;
1615      }
1616    
1617      return false;
1618      //
1619    };
1620    
1621    // Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev){
1622    //   //
1623    //   // check if we have already called once GetEntry, if not call it
1624    //   //
1625    //     if(!run_tree){
1626    //      cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
1627    //      return false;
1628    //     }
1629    //     if ( run_tree->GetEntries() <= 0 ) {
1630    //      cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
1631    //      return(false);
1632    //     }
1633    //   //
1634      
1635    //   Int_t oldrun = irun;
1636    //   // --------------------------------------
1637    //   // if it is a full file (not preselected)
1638    //   // --------------------------------------
1639    //   if(SELLI==0){
1640    
1641    //       if( !GetOrbitalInfo() ){
1642    //        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1643    //        return(false);
1644    //       }
1645    
1646    //       if ( irun < 0 ){
1647    //        irun = 0;
1648    //        run_tree->GetEntry(irun);
1649    //        runfirstentry = iev;
1650    //        if( iev != 0){
1651    //            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- WARNING -- "<<endl;
1652    //        }
1653    //       };      
1654    
1655    //       bool fromfirst = true;
1656    
1657    //       while ( !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries() ){
1658    //        irun++;
1659    //        if( irun == run->GetEntries() ){
1660    //            if(!fromfirst){
1661    //                cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
1662    //                return false;
1663    //            }
1664    //            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- reached end of run tree. searchin again from beginning (should not happen)" <<endl;
1665    //            fromfirst = false;
1666    //            irun =0;
1667    //        }
1668    //        run_tree->GetEntry(irun);
1669    //        runfirstentry = iev;
1670    //       };
1671    //       //
1672    //       if ( irun == oldrun ) return(false);
1673    //       //
1674    //       cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1675    //       cout << "runfirstentry "<<runfirstentry<<endl;
1676    //       prevshift = 0;
1677    //       return(true);    
1678    //   };
1679    //   // ----------------------------------------------------
1680    //   // if it is a preselected file (there is SelectionList)
1681    //   // NBNB - the event tree MUST be read first
1682    //   // ----------------------------------------------------
1683    //   if(SELLI==1){      
1684    //       sel_tree->GetEntry(iev);
1685    //       if(irun != oldrun){
1686    //        run->GetEntry(irun);
1687    //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1688    //        prevshift = 0;
1689    //        return true;
1690    //       }
1691    //       return false;
1692    //   }
1693    
1694    //   return false;
1695    //   //
1696    // };
1697    /**
1698     * Update the runinfo informations (to be used to have Run infos event by event basis)
1699     * @param run Pointer to the chain/tree which contains run infos
1700     * @return true if a new run has been read, false if it is still the same run
1701     */
1702    Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
1703      return(UpdateRunInfo((TChain*)run,iev));
1704    };
1705    
1706  //--------------------------------------  //--------------------------------------
1707  //  //
1708  //  //
# Line 1122  TTree *PamLevel2::GetRunTree(TFile *f){ Line 1713  TTree *PamLevel2::GetRunTree(TFile *f){
1713  */  */
1714  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
1715                    
1716      if(detlist.Contains("+ALL", TString::kIgnoreCase)){      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
1717            CAL0 = false;
1718          CAL1 = true;          CAL1 = true;
1719          CAL2 = true;          CAL2 = true;
1720          TRK2 = true;          TRK2 = true;
1721          TRK1 = false;          TRK1 = false;
1722          TRKh = false;          TRKh = false;
1723            TRK0 = false;
1724          TRG = true;          TRG = true;
1725          TOF = true;          TOF = true;
1726            TOF0 = false;
1727          S4  = true;          S4  = true;
1728          ND  = true;          ND  = true;
1729          AC  = true;          AC  = true;
1730          ORB = true;          ORB = true;
1731      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
1732            CAL0 = false;
1733          CAL1 = false;          CAL1 = false;
1734          CAL2 = false;          CAL2 = false;
1735          TRK2 = false;          TRK2 = false;
1736          TRK1 = false;          TRK1 = false;
1737          TRKh = false;          TRKh = false;
1738            TRK0 = false;
1739          TRG = false;          TRG = false;
1740          TOF = false;          TOF = false;
1741            TOF0 = false;
1742          S4  = false;          S4  = false;
1743          ND  = false;          ND  = false;
1744          AC  = false;          AC  = false;
# Line 1153  void PamLevel2::SetWhichTrees(TString de Line 1750  void PamLevel2::SetWhichTrees(TString de
1750          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1751          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1752      };      };
1753    
1754        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
1755            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
1756            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
1757        };
1758                    
1759      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1760          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1165  void PamLevel2::SetWhichTrees(TString de Line 1767  void PamLevel2::SetWhichTrees(TString de
1767          CAL1=false;          CAL1=false;
1768      }      }
1769  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
1770        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
1771            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
1772            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
1773        };
1774    
1775      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1776          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1777          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1193  void PamLevel2::SetWhichTrees(TString de Line 1800  void PamLevel2::SetWhichTrees(TString de
1800            
1801      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
1802      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
1803    
1804        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
1805        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
1806            
1807      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
1808      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
# Line 1206  void PamLevel2::SetWhichTrees(TString de Line 1816  void PamLevel2::SetWhichTrees(TString de
1816      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
1817      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
1818    
1819      cout<< "Set detector list --> ";  //     cout<< "Set detector list --> ";
1820      if(TRK1)cout<<"TRK1 ";  //     if(TRK1)cout<<"TRK1 ";
1821      if(TRK2)cout<<"TRK2 ";  //     if(TRK2)cout<<"TRK2 ";
1822      if(TRKh)cout<<"TRKH ";  //     if(TRKh)cout<<"TRKH ";
1823      if(CAL1)cout<<"CAL1 ";  //     if(CAL1)cout<<"CAL1 ";
1824      if(CAL2)cout<<"CAL2 ";  //     if(CAL2)cout<<"CAL2 ";
1825      if(TOF)cout<<"TOF ";  //     if(TOF)cout<<"TOF ";
1826      if(TRG)cout<<"TRG ";  //     if(TRG)cout<<"TRG ";
1827      if(AC)cout<<"AC ";  //     if(AC)cout<<"AC ";
1828      if(ND)cout<<"ND ";  //     if(ND)cout<<"ND ";
1829      if(S4)cout<<"S4 ";  //     if(S4)cout<<"S4 ";
1830      if(ORB)cout<<"ORB ";  //     if(ORB)cout<<"ORB ";
1831      cout << endl;  //     cout << endl;
1832            
1833  };  };
1834    
# Line 1227  void PamLevel2::SetWhichTrees(TString de Line 1837  void PamLevel2::SetWhichTrees(TString de
1837   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
1838   */   */
1839  void  PamLevel2::GetWhichTrees(TFile* f){  void  PamLevel2::GetWhichTrees(TFile* f){
1840                
1841    
1842    
1843        cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
1844      // -----------      // -----------
1845      // reset flags      // reset flags
1846      // -----------      // -----------
1847      Bool_t CAL1   = false;          CAL1   = false;    
1848      Bool_t CAL2   = false;          CAL2   = false;    
1849      Bool_t TRK2   = false;          TRK2   = false;    
1850      Bool_t TRK1   = false;          TRK1   = false;    
1851      Bool_t TRKh   = false;          TRKh   = false;    
1852      Bool_t TRG    = false;          TRG    = false;    
1853      Bool_t TOF    = false;          TOF    = false;    
1854      Bool_t S4     = false;          S4     = false;    
1855      Bool_t ND     = false;          ND     = false;    
1856      Bool_t AC     = false;          AC     = false;    
1857      Bool_t ORB    = false;          ORB    = false;    
1858            
1859      Bool_t RUN    = false;      RUN    = false;
1860                    
1861      cout << "Checking file: "<<f->GetName()<<endl;      cout << "Checking file: "<<f->GetName()<<endl;
1862      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
# Line 1354  void  PamLevel2::GetWhichTrees(TFile* f) Line 1966  void  PamLevel2::GetWhichTrees(TFile* f)
1966    
1967      };      };
1968            
1969      lk->Delete();      delete lk;
1970    
1971    //     cout<< "Get detector list from input file --> ";
1972    //     if(TRK1)cout<<"TRK1 ";
1973    //     if(TRK2)cout<<"TRK2 ";
1974    //     if(TRKh)cout<<"TRKH ";
1975    //     if(CAL1)cout<<"CAL1 ";
1976    //     if(CAL2)cout<<"CAL2 ";
1977    //     if(TOF)cout<<"TOF ";
1978    //     if(TRG)cout<<"TRG ";
1979    //     if(AC)cout<<"AC ";
1980    //     if(ND)cout<<"ND ";
1981    //     if(S4)cout<<"S4 ";
1982    //     if(ORB)cout<<"ORB ";
1983    //     cout << endl;
1984                
1985      return ;      return ;
1986                    
# Line 1386  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2012  Bool_t  PamLevel2::CheckLevel2File(TStri
2012            
2013      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
2014            
2015            Bool_t SELLI__ok  = false;
2016    
2017      cout << "Checking file: "<<name<<endl;      cout << "Checking file: "<<name<<endl;
2018      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
# Line 1404  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2030  Bool_t  PamLevel2::CheckLevel2File(TStri
2030      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
2031                    
2032  //      cout << key->GetName() << endl;  //      cout << key->GetName() << endl;
2033  //      cout << " Get tree: " << f->Get(key->GetName())<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
2034    //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
2035  //      nev_previous = nev;  //      nev_previous = nev;
2036  //      cout << " n.entries  "<< nev <<endl;  //      cout << " n.entries  "<< nev <<endl;
2037  //      if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){  //      if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
# Line 1413  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2040  Bool_t  PamLevel2::CheckLevel2File(TStri
2040  //          return false;  //          return false;
2041  //      };  //      };
2042    
2043    
2044          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
2045    
2046          //=========================================================              //=========================================================    
2047            if( !strcmp(key->GetName(),"SelectionList"    ) ){
2048                SELLI__ok = true;
2049                if(SELLI==1){
2050                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
2051                    if( nev && nevt!=nev){
2052                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
2053                        return false;
2054                    }
2055                    nev=nevt;
2056                }
2057            }
2058    
2059            //=========================================================    
2060          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
2061              TRG__ok = true;              TRG__ok = true;
2062              if(TRG){              if(TRG){
# Line 1527  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2168  Bool_t  PamLevel2::CheckLevel2File(TStri
2168          };                };      
2169    
2170      };      };
2171    
2172        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
2173        if( SELLI==0 && SELLI__ok ){
2174            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
2175            return false;  
2176        }
2177        if( SELLI==1 && !SELLI__ok ){
2178            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
2179            return false;
2180        }
2181            
2182    //    cout << "SELLI "<<SELLI<<endl;
2183    
2184    //     cout<< "CheckLevel2File(TString): detector list --> ";
2185    //     if(TRK1__ok)cout<<"TRK1 ";
2186    //     if(TRK2__ok)cout<<"TRK2 ";
2187    //     if(TRKh__ok)cout<<"TRKH ";
2188    //     if(CAL1__ok)cout<<"CAL1 ";
2189    //     if(CAL2__ok)cout<<"CAL2 ";
2190    //     if(TOF__ok)cout<<"TOF ";
2191    //     if(TRG__ok)cout<<"TRG ";
2192    //     if(AC__ok)cout<<"AC ";
2193    //     if(ND__ok)cout<<"ND ";
2194    //     if(S4__ok)cout<<"S4 ";
2195    //     if(ORB__ok)cout<<"ORB ";
2196    //     cout << endl;
2197    
2198    
2199        if(TRK2 && TRK1__ok)TRK1=1;
2200    // ----------------------------------------------------------------------------
2201    // NOTA
2202    // se c'e` il level1, lo devo necessarimente leggere.
2203    // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
2204    // comunque, ma non vengono disallocati da PamLevel2::Clear()
2205    // ----------------------------------------------------------------------------
2206    
2207    
2208      if(!RUN__ok) {      if(!RUN__ok) {
# Line 1572  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2247  Bool_t  PamLevel2::CheckLevel2File(TStri
2247          return false;          return false;
2248      };      };
2249    
2250          if(ND && !ND__ok){      if(ND && !ND__ok){
2251              cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
2252              return false;          return false;
2253          };      };
2254          if(TRG && !TRG__ok){      if(TRG && !TRG__ok){
2255              cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
2256              return false;          return false;
2257          };      };
2258        
   
   
   
2259    
2260      lk->Delete();  //    lk->Delete();
2261    //    delete lk;
2262      f->Close();      f->Close();
2263    
2264    //     cout<< "CheckLevel2File(TString): detector list --> ";
2265    //     if(TRK1)cout<<"TRK1 ";
2266    //     if(TRK2)cout<<"TRK2 ";
2267    //     if(TRKh)cout<<"TRKH ";
2268    //     if(CAL1)cout<<"CAL1 ";
2269    //     if(CAL2)cout<<"CAL2 ";
2270    //     if(TOF)cout<<"TOF ";
2271    //     if(TRG)cout<<"TRG ";
2272    //     if(AC)cout<<"AC ";
2273    //     if(ND)cout<<"ND ";
2274    //     if(S4)cout<<"S4 ";
2275    //     if(ORB)cout<<"ORB ";
2276    //     cout << endl;
2277                
2278      return true;      return true;
2279                    
# Line 1602  void PamLevel2::CreateCloneTrees0( TChai Line 2289  void PamLevel2::CreateCloneTrees0( TChai
2289      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
2290            
2291      Int_t i=0;      Int_t i=0;
2292      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
2293      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
2294      name.Append("_clone");      name.Append("_clone");
2295  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
2296      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
2297      i++;      i++;
2298    
2299      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
# Line 1616  void PamLevel2::CreateCloneTrees0( TChai Line 2303  void PamLevel2::CreateCloneTrees0( TChai
2303      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
2304  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2305  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
2306          tree_clone[i] = T_friend->GetTree()->CloneTree(0);          pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2307          tree_clone[i]->SetAutoSave(1000000);          pam_tree_clone[i]->SetAutoSave(1000000);
2308          name =  tree_clone[i]->GetName();          name =  pam_tree_clone[i]->GetName();
2309          name.Append("_clone");          name.Append("_clone");
2310  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
2311          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
2312          i++;          i++;
2313      }      }
2314        
2315        delete li;
2316    
2317      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2318    
# Line 1639  void PamLevel2::CreateCloneTrees(TFile * Line 2328  void PamLevel2::CreateCloneTrees(TFile *
2328      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2329      cout << "Create new PAMELA trees "<<endl;      cout << "Create new PAMELA trees "<<endl;
2330                    
     Int_t i=0;  
2331    
2332        run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
2333        run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
2334        cout << "Run          : branch RunInfo"<<endl;
2335        run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
2336        cout << "Run          : branch SoftInfo"<<endl;
2337                
2338    
2339    
2340        sel_tree_clone = new TTree("SelectionList","List of selected events ");
2341        sel_tree_clone->Branch("RunEntry",&irun,"runentry/I");
2342        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/I");
2343        
2344    
2345        Int_t i=0;
2346      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
2347          tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");              pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2348          if(TRK1) {          if(TRK1) {
2349              tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2350              tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
2351              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
2352                cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
2353          };          };
2354          if(TRK2) {          if(TRK2) {
2355              tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2356              cout << "Tracker      : branch TrkLevel2"<<endl;                      cout << "Tracker      : branch TrkLevel2"<<endl;        
2357          };          };
2358          if(TRKh) {          if(TRKh) {
2359              tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));              pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2360              cout << "Tracker      : branch TrkHough"<<endl;              cout << "Tracker      : branch TrkHough"<<endl;
2361          };          };
2362          i++;          i++;
# Line 1661  void PamLevel2::CreateCloneTrees(TFile * Line 2364  void PamLevel2::CreateCloneTrees(TFile *
2364    
2365      // Calorimeter      // Calorimeter
2366      if(CAL1||CAL2){      if(CAL1||CAL2){
2367          tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2368          if(CAL1) {          if(CAL1) {
2369              tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));              pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2370              cout << "Calorimeter  : branch CaloLevel1"<<endl;              cout << "Calorimeter  : branch CaloLevel1"<<endl;
2371          };          };
2372          if(CAL2) {          if(CAL2) {
2373              tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2374              cout << "Calorimeter  : branch CaloLevel2"<<endl;              cout << "Calorimeter  : branch CaloLevel2"<<endl;
2375          };          };
2376          i++;          i++;
# Line 1675  void PamLevel2::CreateCloneTrees(TFile * Line 2378  void PamLevel2::CreateCloneTrees(TFile *
2378    
2379      // ToF          // ToF    
2380      if(TOF) {      if(TOF) {
2381          tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2382          tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2383          cout << "ToF          : branch ToFLevel2"<<endl;          cout << "ToF          : branch ToFLevel2"<<endl;
2384          i++;          i++;
2385      };      };
2386      // Trigger      // Trigger
2387      if(TRG) {      if(TRG) {
2388          tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");              pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2389          tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2390          cout << "Trigger      : branch TrigLevel2"<<endl;          cout << "Trigger      : branch TrigLevel2"<<endl;
2391          i++;          i++;
2392      };      };
2393      // S4      // S4
2394      if(S4) {      if(S4) {
2395          tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");                pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
2396          tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));          pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2397          cout << "S4           : branch S4Level2"<<endl;          cout << "S4           : branch S4Level2"<<endl;
2398          i++;          i++;
2399      };      };
2400      // Neutron Detector      // Neutron Detector
2401      if(ND) {      if(ND) {
2402          tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
2403          tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));          pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2404          cout << "NeutronD     : branch NDLevel2"<<endl;          cout << "NeutronD     : branch NDLevel2"<<endl;
2405          i++;          i++;
2406      };      };
2407      // Anticounters      // Anticounters
2408      if(AC) {      if(AC) {
2409          tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");              pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
2410          tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));          pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2411          cout << "Anticounter  : branch AcLevel2"<<endl;          cout << "Anticounter  : branch AcLevel2"<<endl;
2412          i++;          i++;
2413      };      };
2414      // OrbitalInfo      // OrbitalInfo
2415      if(ORB) {      if(ORB) {
2416          tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");                pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");  
2417          tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2418          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
2419          i++;          i++;
2420      };      };
# Line 1719  void PamLevel2::CreateCloneTrees(TFile * Line 2422  void PamLevel2::CreateCloneTrees(TFile *
2422    
2423  }  }
2424    
 // /**  
 //  * Create clone-trees  
 //  */  
 // void PamLevel2::CreateCloneTrees(){  
   
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
 //     cout << "Create new PAMELA trees "<<endl;  
           
 //     if(TRK1||TRK2||TRKh){  
 //      T_clone = new TTree("Tracker_clone","PAMELA tracker level2 data ");      
 //      if(TRK1) {  
 //          trk1_clone = new TrkLevel1();  
 //          T_clone->Branch("TrkLevel1","TrkLevel1", &trk1_clone);  
 //          T_clone->BranchRef();  
 //          cout << "Tracker      : branch TrkLevel1"<<endl;  
 //      };  
 //      if(TRK2) {  
 //          trk2_clone = new TrkLevel2();  
 //          T_clone->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  
 //          cout << "Tracker      : branch TrkLevel2"<<endl;          
 //      };  
 //      if(TRKh) {  
 //          trkh_clone = new TrkHough();  
 //          T_clone->Branch("TrkHough","TrkHough", &trkh_clone);  
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      cout << hex << T_clone << dec << endl;  
 //     }  
   
 //     // Calorimeter  
 //     if(CAL1||CAL2){  
 //      C_clone = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");      
 //      if(CAL1) {  
 //          calo1_clone = new CaloLevel1();  
 //          C_clone->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);  
 //          cout << "Calorimeter  : branch CaloLevel1"<<endl;  
 //      };  
 //      if(CAL2) {  
 //          calo2_clone = new CaloLevel2();  
 //          C_clone->Branch("CaloLevel2","CaloLevel2", &calo2_clone);  
 //          cout << "Calorimeter  : branch CaloLevel2"<<endl;  
 //      };  
 //     }      
   
 //     // ToF      
 //     if(TOF) {  
 //      O_clone = new TTree("ToF_clone","PAMELA ToF level2 data ");      
 //      tof_clone = new ToFLevel2();  
 //      O_clone->Branch("ToFLevel2","ToFLevel2", &tof_clone);  
 //      cout << "ToF          : branch ToFLevel2"<<endl;  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      R_clone = new TTree("Trigger_clone","PAMELA trigger level2 data ");      
 //      trig_clone = new TrigLevel2();  
 //      R_clone->Branch("TrigLevel2","TrigLevel2", &trig_clone);  
 //      cout << "Trigger      : branch TrigLevel2"<<endl;  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      S_clone = new TTree("S4_clone","PAMELA S4 level2 data ");        
 //      s4_clone = new S4Level2();  
 //      S_clone->Branch("S4Level2","S4Level2", &s4_clone);  
 //      cout << "S4           : branch S4Level2"<<endl;  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      N_clone = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");    
 //      nd_clone = new NDLevel2();  
 //      N_clone->Branch("NDLevel2","NDLevel2", &nd_clone);  
 //      cout << "NeutronD     : branch NDLevel2"<<endl;  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      A_clone = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");      
 //      ac_clone = new AcLevel2();  
 //      A_clone->Branch("AcLevel2","AcLevel2", &ac_clone);  
 //      cout << "Anticounter  : branch AcLevel2"<<endl;  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      B_clone = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");        
 //      orb_clone = new OrbitalInfo();  
 //      B_clone->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
   
 // }  
2425    
2426  /**  /**
2427   * Fill tree (created with CreateCloneTrees)   * Fill tree (created with CreateCloneTrees)
# Line 1815  void PamLevel2::CreateCloneTrees(TFile * Line 2429  void PamLevel2::CreateCloneTrees(TFile *
2429   */   */
2430  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
2431  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
2432                
2433  // //  --------------------------------------  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
 // //  copy the event  
 // //  --------------------------------------  
 //     if(trk1_clone)  *trk1_clone = *trk1_obj;  
 //     if(trk2_clone){  
 //      trk2_clone->Clear();  
 //      trk2_obj->Copy(*trk2_clone);  
 // //   *trk2_clone = *trk2_obj;  
 //     }  
 //     if(trkh_clone)  *trkh_clone = *trkh_obj;  
 //     if(calo1_clone){  
 // //   *calo1_clone = *calo1_obj;  
 //      calo1_clone->Clear();  
 //      calo1_obj->Copy(*calo1_clone);  
 //     }  
 //     if(calo2_clone){  
 // //   *calo2_clone = *calo2_obj;  
 //      calo2_clone->Clear();  
 //      calo2_obj->Copy(*calo2_clone);  
 //     }  
 //     if(tof_clone)   *tof_clone  = *tof_obj;  
 //     if(trig_clone)  *trig_clone = *trig_obj;  
 //     if(s4_clone)    *s4_clone   = *s4_obj;  
 //     if(nd_clone)    *nd_clone   = *nd_obj;  
 //     if(ac_clone)    *ac_clone   = *ac_obj;  
 //     if(orb_clone)   *orb_clone  = *orb_obj;  
   
 //     if(T_clone)T_clone->Fill();  
 //     if(C_clone)C_clone->Fill();  
 //     if(O_clone)O_clone->Fill();  
 //     if(R_clone)R_clone->Fill();  
 //     if(S_clone)S_clone->Fill();  
 //     if(N_clone)N_clone->Fill();  
 //     if(A_clone)A_clone->Fill();  
 //     if(O_clone)O_clone->Fill();  
2434    
2435      for(Int_t i=0; i<8; i++){      for(Int_t i=0; i<NCLONES; i++){
2436          if(tree_clone[i])tree_clone[i]->Fill();          if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2437      }      }
2438        if(sel_tree_clone)sel_tree_clone->Fill();    
2439    
2440  }  }
2441    
2442    
2443  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
2444    
2445      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
2446          if(tree_clone[i]){          if(pam_tree_clone[i]){
2447              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
2448              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
2449          };          };
2450      }      }
2451        if(run_tree_clone){
2452            TString na = run_tree_clone->GetName();
2453            if(!name.CompareTo(na))return run_tree_clone;
2454        }
2455        if(sel_tree_clone){
2456            TString na = sel_tree_clone->GetName();
2457            if(!name.CompareTo(na))return sel_tree_clone;
2458        }
2459      return NULL;      return NULL;
2460    
2461  }  }
2462  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
2463      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2464      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
2465      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;    
2466          if(tree_clone[i]){      run_tree_clone->Write();
2467              cout << tree_clone[i]->GetName()<<endl;      cout << sel_tree_clone->GetName()<<endl;    
2468              tree_clone[i]->Write();      sel_tree_clone->Write();
2469        for(Int_t i=0; i<NCLONES; i++){    
2470            if(pam_tree_clone[i]){
2471                cout << pam_tree_clone[i]->GetName()<<endl;
2472                pam_tree_clone[i]->Write();
2473          };          };
2474      }      }
2475      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 1883  void PamLevel2::WriteCloneTrees(){ Line 2477  void PamLevel2::WriteCloneTrees(){
2477  }  }
2478    
2479  /**  /**
2480   * Create a new (empty) Pamela trees   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
2481   */   */
2482  // TTree* PamLevel2::GetNewPamTree(){  //Int_t PamLevel2::GetEntry(Int_t iee){
2483    Int_t PamLevel2::GetEntry(Long64_t iee){
2484        
2485        if(!pam_tree){
2486            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
2487            return 0;
2488        }
2489    
2490    
2491        //
2492        // This is a sort of bug: if you don't have the run tree you don't want to exit here you want to have loaded the event anyway...
2493        //
2494        //    if(!run_tree ){
2495        //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
2496        //  return 0;
2497        //    }
2498    
2499        Long64_t ii=0;
2500        //-------------------------------
2501        ii = iee;
2502        if( !pam_tree->GetEntry(ii) ){      
2503            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
2504            return 0;
2505        }
2506        //
2507        // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0.
2508        // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not
2509        // a problem if you don't check the return code of getentry.
2510        //
2511        if(!run_tree ){
2512            if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
2513                    cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
2514                    return 0;
2515            }  else {
2516                    return 1; //cosi` se non c'e` run esce qua...
2517            }
2518        }
2519    
2520        //-------------------------------
2521        ii = iee;
2522    //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
2523        Bool_t UPDATED = UpdateRunInfo(ii);
2524        if(SELLI==0)irunentry = iee-runfirstentry;
2525        if(UPDATED && run_tree_clone)run_tree_clone->Fill();
2526    
2527    //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
2528    
2529        if( TRK0 || CAL0 || TOF0 )GetYodaEntry( );
2530    
2531  //     if(tree_clone)return tree_clone;      return 1;
2532    
2533    }
2534    
2535    /**
2536     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2537     * Given the run ID (...), if needed it query the DB and load the proper file.
2538     * @return Pointer to the tree
2539     */
2540    
2541    
2542    TTree* PamLevel2::GetYodaTree( ){
2543        
2544    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
2545        //===================================
2546        // check if iroot has changed
2547        //===================================
2548        if( irun<0 ){
2549            cout << "PamLevel2::GetYodaTree() -- ERROR "<<endl;
2550            cout << "In order to use this method you have to load the RunInfo tree "<<endl;
2551            cout << "with the method TChain* PamLevel2::GetRunTree(TString, TString)"<<endl;
2552    //      cout << " - read the event with PamLevel2::GetEntry(Int_t)"<<endl;
2553            return NULL;
2554        }    
2555        Int_t irootnew = run_obj->ID_ROOT_L0;
2556    //     cout << "iroot    "<<iroot<<endl;
2557    //     cout << "irootnew "<<irootnew<<endl;
2558    
2559        //===================================
2560        // load the level0 file
2561        // (if not already loaded)
2562        //===================================
2563        if( iroot != irootnew || !l0_tree){
2564            iroot = irootnew;
2565            //===================================
2566            // open the DB connection
2567            // (if not already opened)
2568            //===================================
2569            if(!dbc || (dbc && !dbc->IsConnected())){
2570                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2571                cout<<"Connecting to DB"<<endl;
2572                cout<<"HOST "<<host<<endl;
2573                cout<<"USER "<<user<<endl;
2574                cout<<"PSW  "<<psw<<endl;
2575                dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
2576                if( !dbc )return NULL;
2577                if( !dbc->IsConnected() )return NULL;    
2578    //          cout<<"...done"<<endl;
2579                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2580            }else{
2581    //          cout<<"DB already connected"<<endl;
2582            }
2583            GL_ROOT glroot = GL_ROOT();
2584            if( glroot.Query_GL_ROOT(iroot,dbc) ){
2585                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
2586                return NULL;
2587            };
2588            TString filename = glroot.PATH + glroot.NAME;
2589            if(l0_file){
2590                l0_file->Close();
2591                l0_file->Delete();
2592            }
2593            cout << "Opening LEVEL0 file: "<< filename << endl;
2594            FileStat_t t;
2595            if( gSystem->GetPathInfo(filename.Data(),t) ){
2596                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
2597                return NULL;
2598            }
2599            l0_file = new TFile(filename);
2600            if( !l0_file )return NULL;
2601            l0_tree = (TTree*)l0_file->Get("Physics");
2602            if(!h0_obj)h0_obj = new EventHeader();
2603            l0_tree->SetBranchAddress("Header" ,&h0_obj);
2604            prevshift = 0;
2605            //---------------------------------------------------
2606            // TRACKER:
2607            if(TRK0){
2608                if(!trk0_obj){
2609                    trk0_obj = new TrkLevel0();
2610                    trk0_obj->Set();
2611                };
2612                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
2613            }
2614            //---------------------------------------------------
2615            // CALORIMETER:
2616            if(CAL0){
2617                if(!calo0_obj){
2618                    calo0_obj = new CaloLevel0();
2619                    calo0_obj->Set();
2620                };
2621                l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
2622                //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
2623            }
2624            //---------------------------------------------------
2625            // TOF:
2626            if(TOF0){
2627                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
2628            }
2629    
2630        };
2631    
2632  //     TTree *Tout = 0;      if(!dbc || (dbc && !dbc->IsConnected())){
2633            cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
2634        }
2635    
2636        if ( TRK0 ){
2637            TrkParams::Load(6);
2638            if( !TrkParams::IsLoaded(6) ){
2639                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
2640            };
2641            TrkParams::SetCalib(run_obj,dbc);
2642            TrkParams::LoadCalib( );
2643            if( !TrkParams::CalibIsLoaded() ){
2644                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
2645            };
2646        }
2647    
2648    //    cout << l0_tree << endl;
2649            
2650  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      return l0_tree;
2651  //     cout << "Create new PAMELA trees "<<endl;  
2652    }
2653    
2654    /**
2655     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2656     */
2657    Int_t PamLevel2::GetYodaEntry(){
2658    
2659    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
2660        if(!GetYodaTree())return 0;
2661            
2662        // patch
2663        if( irunentry < 0){
2664            cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
2665            irunentry=0LL;
2666        }
2667        //  ---------------------------------
2668        //  if file is NOT a preselected file
2669        //  ---------------------------------
2670        Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
2671            
 //     if(TRK1||TRK2||TRKh){  
 //      TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");      
 //      if(TRK1) {  
 //          trk1_clone = new TrkLevel1();  
 //          T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);  
 //          T->BranchRef();  
 //          cout << "Tracker      : branch TrkLevel1"<<endl;  
 //      };  
 //      if(TRK2) {  
 //          trk2_clone = new TrkLevel2();  
 //          T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  
 //          cout << "Tracker      : branch TrkLevel2"<<endl;          
 //      };  
 //      if(TRKh) {  
 //          trkh_clone = new TrkHough();  
 //          T->Branch("TrkHough","TrkHough", &trkh_clone);  
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      if(!Tout)Tout=T;  
 //      else Tout->AddFriend("Tracker_clone");  
 //     }  
2672    
2673  //     // Calorimeter  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
2674  //     if(CAL1||CAL2){  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
2675  //      TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");      //     cout << " time "<< GetOrbitalInfo()->absTime << endl;
2676  //      if(CAL1) {  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
2677  //          calo1_clone = new CaloLevel1();      
2678  //          C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);      if( !GetOrbitalInfo() ){
2679  //          cout << "Calorimeter  : branch CaloLevel1"<<endl;          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
2680  //      };          return 0;
2681  //      if(CAL2) {      }
2682  //          calo2_clone = new CaloLevel2();  
2683  //          C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);      // ---------------------------------------------------------------------
2684  //          cout << "Calorimeter  : branch CaloLevel2"<<endl;      // ATTENTION!!!
2685  //      };      // If data are not pre-processed with cleaner, the level0 tree may contain
2686  //      if(!Tout)Tout=C;      // spurious nested physics packets.
2687  //      else Tout->AddFriend("Calorimeter_clone");      // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
2688  //     }          // while level2 tree DOES NOT!!
2689        // This means that "quellagiusta" in these cases is not correct.
2690  //     // ToF          // In order to retrieve the correct level0 event, I implemented a check
2691  //     if(TOF) {      // of the OBT and pkt-number. In case of mismatch, the level0 entry number
2692  //      TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data ");          // is shift forward until when the packets match.
2693  //      tof_clone = new ToFLevel2();      // ---------------------------------------------------------------------
2694  //      O->Branch("ToFLevel2","ToFLevel2", &tof_clone);      Int_t answer = 0;
2695  //      cout << "ToF          : branch ToFLevel2"<<endl;      Int_t shift =0;
2696  //      if(!Tout)Tout=O;      //    printf(" siamo qui %i %i \n",shift,prevshift);
2697  //      else Tout->AddFriend("ToF_clone");      do{
2698  //     };          if(shift>0){    
2699  //     // Trigger              cout << " level0 <--> level2 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
2700  //     if(TRG) {          }
2701  //      TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data ");              answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
2702  //      trig_clone = new TrigLevel2();          shift++;
2703  //      R->Branch("TrigLevel2","TrigLevel2", &trig_clone);          if( !GetEventHeader() ){
2704  //      cout << "Trigger      : branch TrigLevel2"<<endl;              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
2705  //      if(!Tout)Tout=R;              return 0;
2706  //      else Tout->AddFriend("Trigger_clone");          }
2707  //     };          cout << "PKTNUM "<<shift<<" ==  L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
2708  //     // S4  //      cout << " L2 --- "<< GetOrbitalInfo()->OBT << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
2709  //     if(S4) {  //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
2710  //      TTree *S = new TTree("S4_clone","PAMELA S4 level2 data ");        //      cout << " GetOrbitalInfo()->OBT "<< GetOrbitalInfo()->OBT << endl;
2711  //      s4_clone = new S4Level2();  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
2712  //      S->Branch("S4Level2","S4Level2", &s4_clone);  //      cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl;
2713  //      cout << "S4           : branch S4Level2"<<endl;  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
2714  //      if(!Tout)Tout=S;  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
2715  //      else Tout->AddFriend("S4_clone");  //
2716  //     };          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
2717  //     // Neutron Detector            prevshift = 0;
2718  //     if(ND) {            shift = -1;
2719  //      TTree *N = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");            };
 //      nd_clone = new NDLevel2();  
 //      N->Branch("NDLevel2","NDLevel2", &nd_clone);  
 //      cout << "NeutronD     : branch NDLevel2"<<endl;  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD_clone");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      TTree *A = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");    
 //      ac_clone = new AcLevel2();  
 //      A->Branch("AcLevel2","AcLevel2", &ac_clone);  
 //      cout << "Anticounter  : branch AcLevel2"<<endl;  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter_clone");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      TTree *B = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");      
 //      orb_clone = new OrbitalInfo();  
 //      B->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo_clone");  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
2720    
2721  //     tree_clone = Tout;      }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() );
 //     tree_clone->SetDirectory(0);  
2722    
2723  //     return Tout;      if ( (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ) cout << " Big trouble here, no such event in Level0 data! " <<endl;
2724  // }  
2725  // /**  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
2726  //  * Fill a tree (created with GetNewPamTree)  //    return GetYodaTree()->GetEntry(quellagiusta);
2727  //  *      if ( shift > 1 ) prevshift += (shift-1);
2728  //  */      
2729  // //void PamLevel2::FillNewPamTree(TTree *T){      return answer;
2730  // void PamLevel2::FillNewPamTree(){      
2731            }
2732    
 //     if(trk1_clone)  *trk1_clone = *trk1_obj;  
 //     if(trk2_clone){  
 //      trk2_clone->Clear();  
 //      trk2_obj->Copy(*trk2_clone);  
 // //   *trk2_clone = *trk2_obj;  
 //     }  
 //     if(trkh_clone)  *trkh_clone = *trkh_obj;  
 //     if(calo1_clone){  
 // //   *calo1_clone = *calo1_obj;  
 //      calo1_clone->Clear();  
 //      calo1_obj->Copy(*calo1_clone);  
 //     }  
 //     if(calo2_clone){  
 // //   *calo2_clone = *calo2_obj;  
 //      calo2_clone->Clear();  
 //      calo2_obj->Copy(*calo2_clone);  
 //     }  
 //     if(tof_clone)   *tof_clone  = *tof_obj;  
 //     if(trig_clone)  *trig_clone = *trig_obj;  
 //     if(s4_clone)    *s4_clone   = *s4_obj;  
 //     if(nd_clone)    *nd_clone   = *nd_obj;  
 //     if(ac_clone)    *ac_clone   = *ac_obj;  
 //     if(orb_clone)   *orb_clone  = *orb_obj;  
   
 //     TTree *T = tree_clone;  
   
 //     T->Fill(); //fill main tree  
 // //    cout<<T->IsA()->GetName()<<" "<<T->GetName()<<endl;  
 //     TList *li = T->GetListOfFriends();  
 //     TIter next(li);  
 //     TFriendElement* T_friend=0;  
 //     while( (T_friend = (TFriendElement*)next()) ){  
 // //   cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  
 //      T_friend->GetTree()->Fill();//fill friends  
 //     }  
2733    
 // }  

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.33

  ViewVC Help
Powered by ViewVC 1.1.23