/[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.12 by pam-fi, Wed Dec 13 09:57:29 2006 UTC revision 1.22 by mocchiut, Thu Mar 8 13:46:34 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;  
107  //     trk2_clone  = 0;      trk2_obj  = 0;
108  //     trkh_clone  = 0;      trk1_obj  = 0;
109  //     calo1_clone = 0;      trkh_obj  = 0;
110  //     calo2_clone = 0;      calo1_obj = 0;
111  //     tof_clone   = 0;      calo2_obj = 0;
112  //     trig_clone  = 0;      tof_obj   = 0;
113  //     s4_clone    = 0;      trig_obj  = 0;
114  //     nd_clone    = 0;      s4_obj    = 0;
115  //     ac_clone    = 0;      nd_obj    = 0;
116  //     orb_clone   = 0;      ac_obj    = 0;
117        orb_obj   = 0;
118  //     T_clone  = 0;  
119  //     C_clone  = 0;      run_obj   = 0;//new GL_RUN();
120  //     O_clone  = 0;      soft_obj   = 0;// Emiliano
121  //     R_clone  = 0;      irun = -1;
122  //     S_clone  = 0;      runfirstentry = 0ULL;
123  //     N_clone  = 0;      runlastentry = 0ULL;
124  //     A_clone  = 0;  
125  //     B_clone  = 0;      l0_file = NULL;
126        l0_tree = NULL;
127        iroot   = -1;
128        dbc     = 0;
129        
130        irun = -1;
131        run_tree = NULL;
132        run_tree_clone = NULL;
133        sel_tree = NULL;
134        sel_tree_clone = NULL;
135        
136        irunentry = -1;
137        pam_tree = NULL;
138        for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
139    
140        host = "mysql://localhost/pamelaprod";
141        user = "anonymous";
142        psw = "";
143        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
144        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
145        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
146        if ( !pamdbhost ) pamdbhost = "";
147        if ( !pamdbuser ) pamdbuser = "";
148        if ( !pamdbpsw ) pamdbpsw = "";
149        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
150        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
151        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
152    
153      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      
154    
155      sorted_tracks = new TRefArray();  //    sorted_tracks = 0;//new TRefArray();
156            
157        CAL0 = false;
158      CAL1 = true;      CAL1 = true;
159      CAL2 = true;      CAL2 = true;
160      TRK2 = true;      TRK2 = true;
161      TRK1 = false;      TRK1 = false;
162      TRKh = false;      TRKh = false;
163      TRG = true;      TRKh = false;
164      TOF = true;      TRG  = true;
165      S4  = true;      TOF  = true;
166      ND  = true;      TOF0 = false;
167      AC  = true;      S4   = true;
168      ORB = true;      ND   = true;
169        AC   = true;
170        ORB  = true;
171            
172      RUN = true;      RUN  = true;
173    
174        SELLI = -1;
175    
176        tsorted=0;
177        timage=0;
178    
179  };  };
180  /**  /**
181   * Destructor   * Delete the event (act as Dtor)
182   */   */
183  PamLevel2::~PamLevel2(){                  void PamLevel2::Delete(){
184      delete run_obj;          
185      Clear();      if(run_obj)delete run_obj;
186        if(soft_obj)delete soft_obj; //Emiliano
187    
188    //    cout << "void PamLevel2::Clear()"<<endl;
189        if(h0_obj)   delete h0_obj;
190        if(trk0_obj) delete trk0_obj;      
191        if(trk1_obj) delete trk1_obj;      
192        if(trk2_obj) delete trk2_obj;
193        if(trkh_obj) delete trkh_obj;
194        if(calo1_obj)delete calo1_obj;
195        if(calo2_obj)delete calo2_obj;
196        if(tof_obj)  delete tof_obj;
197        if(trig_obj) delete trig_obj;
198        if(s4_obj)   delete s4_obj;
199        if(nd_obj)   delete nd_obj;
200        if(ac_obj)   delete ac_obj;
201        if(orb_obj)  delete orb_obj;
202        
203        if(tsorted){
204            tsorted->Delete();
205            delete tsorted;
206        }
207        if(timage){
208            timage->Delete();
209            delete timage;
210        }
211    
212        if(dbc){
213            dbc->Close();
214            delete dbc;
215        }
216        
217        if(l0_file)l0_file->Close();
218        if(pam_tree)pam_tree->Delete();;
219        if(run_tree)run_tree->Delete();;
220        if(sel_tree)sel_tree->Delete();;
221        for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
222        if(run_tree_clone)run_tree_clone->Delete();;
223        if(sel_tree_clone)sel_tree_clone->Delete();;
224        
225    
226  };  };
227    
228  /**  /**
229   * Clear the event   * Clear the event (NB! does not deallocate objects)
230   */   */
231  void PamLevel2::Clear(){  void PamLevel2::Clear(){
232                    
233      TrkLevel1::Clear();  //    cout << "void PamLevel2::Clear()"<<endl;
234            
235      TrkLevel2::Clear();  //
236      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
237      ToFLevel2::Clear();  // want to load them for each event even if they are the same...
238      TrigLevel2::Clear();  //
239      S4Level2::Clear();  //    if(run_obj)delete run_obj;
240      NDLevel2::Clear();  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
241      AcLevel2::Clear();  //    if(soft_obj) soft_obj->Clear();
242      OrbitalInfo::Clear();  
243        if(h0_obj)   h0_obj->Clear();      
244  //     if(trk1_clone)trk1_clone->Clear();      if(trk0_obj) trk0_obj->Clear();    
245  //     if(trk2_clone)trk2_clone->Clear();      if(trk1_obj) trk1_obj->Clear();    
246  //     if(trkh_clone)trkh_clone->Clear();      if(trk2_obj) trk2_obj->Clear();
247  //     if(calo1_clone)calo1_clone->Clear();      if(trkh_obj) trkh_obj->Clear();
248  //     if(calo2_clone)calo2_clone->Clear();      if(calo1_obj)calo1_obj->Clear();
249  //     if(tof_clone)tof_clone->Clear();      if(calo2_obj)calo2_obj->Clear();
250  //     if(trig_clone)trig_clone->Clear();      if(tof_obj)  tof_obj->Clear();
251  //     if(s4_clone)s4_clone->Clear();      if(trig_obj) trig_obj->Clear();
252  //     if(nd_clone)nd_clone->Clear();      if(s4_obj)   s4_obj->Clear();
253  //     if(ac_clone)ac_clone->Clear();      if(nd_obj)   nd_obj->Clear();
254  //     if(orb_clone)orb_clone->Clear();      if(ac_obj)   ac_obj->Clear();
255        if(orb_obj)  orb_obj->Clear();
256            
257      sorted_tracks->Delete(); // clean the reference array  //    if(sorted_tracks)sorted_tracks->Clear();
258    //    sorted_tracks.Clear();
259    
260        if(tsorted){
261            tsorted->Delete();
262        }
263        if(timage){
264            timage->Delete();
265        }
266            
267  };  };
268    
# Line 137  void PamLevel2::Clear(){ Line 274  void PamLevel2::Clear(){
274  void *PamLevel2::GetPointerTo(const char* c ){  void *PamLevel2::GetPointerTo(const char* c ){
275    
276      TString objname = c;      TString objname = c;
277      if(!objname.CompareTo("TrkLevel1"))return &trk1_obj;  
278      if(!objname.CompareTo("TrkLevel2"))return &trk2_obj;      if(!objname.CompareTo("TrkLevel1"))  {
279      if(!objname.CompareTo("TrkHough"))return &trkh_obj;          if(!trk1_obj){
280      if(!objname.CompareTo("CaloLevel1"))return &calo1_obj;              trk1_obj  = new TrkLevel1();
281      if(!objname.CompareTo("CaloLevel2"))return &calo2_obj;              trk1_obj->Set();
282      if(!objname.CompareTo("ToFLevel2"))return &tof_obj;          }
283      if(!objname.CompareTo("TrigLevel2"))return &trig_obj;          return &trk1_obj;
284      if(!objname.CompareTo("S4Level2"))return &s4_obj;      };
285      if(!objname.CompareTo("NDLevel2"))return &nd_obj;      if(!objname.CompareTo("TrkLevel2"))  {
286      if(!objname.CompareTo("AcLevel2"))return &ac_obj;          if(!trk2_obj){  
287      if(!objname.CompareTo("OrbitalInfo"))return &orb_obj;              trk2_obj  = new TrkLevel2();
288                trk2_obj->Set();
289            }
290            return &trk2_obj;
291        };
292        if(!objname.CompareTo("TrkHough"))   {
293            if(!trkh_obj)  trkh_obj  = new TrkHough();
294            return &trkh_obj;
295        };
296        if(!objname.CompareTo("CaloLevel1")) {
297            if(!calo1_obj) calo1_obj = new CaloLevel1();
298            return &calo1_obj;
299        };
300        if(!objname.CompareTo("CaloLevel2")) {
301            if(!calo2_obj){
302                calo2_obj = new CaloLevel2();
303                calo2_obj->Set();
304            };
305            return &calo2_obj;
306        };
307        if(!objname.CompareTo("ToFLevel2"))  {
308            if(!tof_obj){
309                tof_obj   = new ToFLevel2();
310                tof_obj->Set();
311            }
312            return &tof_obj;
313        };
314        if(!objname.CompareTo("TrigLevel2")) {
315            if(!trig_obj)  trig_obj  = new TrigLevel2();
316            return &trig_obj;
317        };
318        if(!objname.CompareTo("S4Level2"))   {
319            if(!s4_obj)    s4_obj    = new S4Level2();
320            return &s4_obj;
321        };
322        if(!objname.CompareTo("NDLevel2"))   {
323            if(!nd_obj)    nd_obj    = new NDLevel2();
324            return &nd_obj;
325        };
326        if(!objname.CompareTo("AcLevel2"))   {
327            if(!ac_obj)    ac_obj    = new AcLevel2();
328            return &ac_obj;
329        };
330        if(!objname.CompareTo("OrbitalInfo")){
331            if(!orb_obj)   orb_obj   = new OrbitalInfo();
332            return &orb_obj;
333        };
334        
335      if(!objname.CompareTo("RunInfo"))return &run_obj;      if(!objname.CompareTo("RunInfo"))return &run_obj;
336    
337        if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
338    
339      return NULL;      return NULL;
340  };  };
341  //--------------------------------------  //--------------------------------------
# Line 160  void *PamLevel2::GetPointerTo(const char Line 347  void *PamLevel2::GetPointerTo(const char
347   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
348   */   */
349   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
350                
351       if( CaloLevel2::ntrk()==0 ){       if( !calo2_obj )return 0;
352    
353         if( calo2_obj->CaloLevel2::ntrk()==0 ){
354           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;
355           return NULL;           return NULL;
356       };       };
# Line 170  void *PamLevel2::GetPointerTo(const char Line 359  void *PamLevel2::GetPointerTo(const char
359       Int_t it_calo=0;       Int_t it_calo=0;
360            
361       do{       do{
362           c = CaloLevel2::GetCaloTrkVar(it_calo);           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
363           it_calo++;           it_calo++;
364       } while( c && seqno != c->trkseqno && it_calo < CaloLevel2::ntrk());             } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
365            
366       if(!c || seqno != c->trkseqno){       if(!c || seqno != c->trkseqno){
367           c = 0;           c = 0;
# Line 191  void *PamLevel2::GetPointerTo(const char Line 380  void *PamLevel2::GetPointerTo(const char
380   */   */
381   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
382                    
383       if( ToFLevel2::ntrk()==0 ){       if( !tof_obj )return 0;
384    
385         if( tof_obj->ToFLevel2::ntrk()==0 ){
386           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;
387           return NULL;           return NULL;
388       };       };
# Line 200  void *PamLevel2::GetPointerTo(const char Line 391  void *PamLevel2::GetPointerTo(const char
391       Int_t it_tof=0;       Int_t it_tof=0;
392            
393       do{       do{
394           c = ToFLevel2::GetToFTrkVar(it_tof);           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
395           it_tof++;           it_tof++;
396       } while( c && seqno != c->trkseqno && it_tof < ToFLevel2::ntrk());       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());        
397            
398       if(!c || seqno != c->trkseqno){       if(!c || seqno != c->trkseqno){
399           c = 0;           c = 0;
# Line 220  void *PamLevel2::GetPointerTo(const char Line 411  void *PamLevel2::GetPointerTo(const char
411   * 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.
412   */   */
413   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
414                
415         cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
416         cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
417    
418       CaloTrkVar *c = 0;       CaloTrkVar *c = 0;
419       ToFTrkVar  *o = 0;       ToFTrkVar  *o = 0;
420            
# Line 245  void *PamLevel2::GetPointerTo(const char Line 439  void *PamLevel2::GetPointerTo(const char
439    
440  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
441            
442        cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
443        cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;
444        cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
445      PamTrack *track = 0;      PamTrack *track = 0;
446            
447      if( itrk >=0 && itrk < TrkLevel2::ntrk() ){      if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){
448                    
449          TrkTrack *t = TrkLevel2::GetStoredTrack(itrk);          TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
450          track = GetPamTrackAlong(t);          track = GetPamTrackAlong(t);
451                    
452            
453    
454      }else{      }else{
455          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;
456      };      };
457            
458      return track;      return track;
# Line 276  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 475  PamTrack* PamLevel2::GetStoredTrack(Int_
475   */   */
476  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
477    
478    //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;
479        if( !trk2_obj ){
480            cout << "void PamLevel2::SortTracks(TString how):  TrkLevel2 not loaded !!!";
481            return;
482        };
483  //    cout << "call SortTracs() "<<endl;  //    cout << "call SortTracs() "<<endl;
484    //Save current Object count    //Save current Object count
485      Int_t ObjectNumber = TProcessID::GetObjectCount();      Int_t ObjectNumber = TProcessID::GetObjectCount();
486    
487  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;
488        
489      sorted_tracks->Delete(); //temporaneo???  //     if(!sorted_tracks)sorted_tracks = new TRefArray();
490            //     sorted_tracks->Clear();
491    //    sorted_tracks.Clear();
492    
493        if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
494        tsorted->Delete();
495        TClonesArray &ttsorted = *tsorted;
496        if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
497        timage->Delete();
498        TClonesArray &ttimage = *timage;
499    
500    
501      // loop over the tracks sorted by the tracker      // loop over the tracks sorted by the tracker
502      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
503      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
# Line 299  void PamLevel2::SortTracks(TString how){ Line 513  void PamLevel2::SortTracks(TString how){
513    
514      //   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;
515            
516      for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
517                    
518          TrkTrack *ts = 0;          TrkTrack   *ts = 0;
519            CaloTrkVar *cs = 0;
520            ToFTrkVar  *os = 0;
521                    
522          // get tracker tracks          // get tracker tracks
523          TrkTrack   *tp = TrkLevel2::GetTrack(i);                    //tracker          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i);                    //tracker
524          CaloTrkVar *cp = 0;          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
525          ToFTrkVar  *op = 0;          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
526    
527            TrkTrack   *ti = 0;              //tracker (image)
528            CaloTrkVar *ci = 0;
529            ToFTrkVar  *oi = 0;
530  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
531          // if track has an image, check image selection          // if track has an image, check image selection
532          if(tp->HasImage()){          if(tp->HasImage()){
533                            
534              TrkTrack   *ti = TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
535              CaloTrkVar *ci = 0;              ci = GetCaloStoredTrack(ti->GetSeqNo());
536              ToFTrkVar  *oi = 0;              oi = GetToFStoredTrack(ti->GetSeqNo());
537                            
538  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
539    
# Line 327  void PamLevel2::SortTracks(TString how){ Line 546  void PamLevel2::SortTracks(TString how){
546              // ------------------------              // ------------------------
547              // check the Y spatial residual on the first calorimeter plane              // check the Y spatial residual on the first calorimeter plane
548              // (cut on calorimeter variables from Emiliano)              // (cut on calorimeter variables from Emiliano)
549                if( use_CAL && !calo2_obj ){
550                    cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but CaloLevel2 not loaded !!!";
551                    return;
552                };
553              if(              if(
554                  use_CAL            &&                  use_CAL            &&
555                  npcfit[1] > 15     &&   //no. of fit planes on Y view                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view
556                  varcfit[1] < 1000. &&  //fit variance on Y view                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
557                  true){                  true){
558    
                 cp = GetCaloStoredTrack(tp->GetSeqNo());  
                 ci = GetCaloStoredTrack(ti->GetSeqNo());  
559                                    
560                  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;
561                  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;
562                                    
563                  if(resy_p <= resy_i) tp_score++;                  if(resy_p <= resy_i) tp_score++;
564                  else                 ti_score++;                  else                 ti_score++;
# Line 350  void PamLevel2::SortTracks(TString how){ Line 571  void PamLevel2::SortTracks(TString how){
571              // ------------------------                  // ------------------------    
572              // check the number of hit pmts along the track              // check the number of hit pmts along the track
573              // on S12 S21 and S32, where paddles are parallel to Y axis              // on S12 S21 and S32, where paddles are parallel to Y axis
574                if( use_TOF && !tof_obj ){
575                    cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";
576                    return;
577                };
578              if( use_TOF ){              if( use_TOF ){
579                                    
580                  Int_t nphit_p =0;                  Int_t nphit_p =0;
581                  Int_t nphit_i =0;                  Int_t nphit_i =0;
582                                    
                 op = GetToFStoredTrack(tp->GetSeqNo());  
                 oi = GetToFStoredTrack(ti->GetSeqNo());  
583                                    
584  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;
585                                  cout << "track: npmttdc "<< op->npmttdc << endl;                                  cout << "track: npmttdc "<< op->npmttdc << endl;
# Line 364  void PamLevel2::SortTracks(TString how){ Line 587  void PamLevel2::SortTracks(TString how){
587                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
588                                    
589                  for (Int_t ih=0; ih < op->npmtadc; ih++){                  for (Int_t ih=0; ih < op->npmtadc; ih++){
590                      Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) );                      Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
591                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
592                  };                  };
593                                    
594                  for (Int_t ih=0; ih < oi->npmtadc; ih++){                  for (Int_t ih=0; ih < oi->npmtadc; ih++){
595                      Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) );                      Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
596                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
597                  };                  };
598                                    
# Line 399  void PamLevel2::SortTracks(TString how){ Line 622  void PamLevel2::SortTracks(TString how){
622              // ------------------------              // ------------------------
623              // the winner is....              // the winner is....
624              // ------------------------                  // ------------------------    
625              if      (tp_score > ti_score) ts = tp;//the track sorted by the tracker!!              if      (tp_score > ti_score) {
626              else if (tp_score < ti_score) ts = ti;//its image!!  //              ts = tp;//the track sorted by the tracker!!
627              else {  //              cs = cp;
628                  ts = tp;  //              os = op;
629                }else if (tp_score < ti_score) {
630                    ts = ti;//its image!!
631                    cs = ci;
632                    os = oi;
633    
634                    ti = tp;//its image!!
635                    ci = cp;
636                    oi = op;
637    
638                    tp = ts;//its image!!
639                    cp = cs;
640                    op = os;
641    
642                    
643                }else {
644    //              ts = tp;
645    //              cs = cp;
646    //              os = op;
647  //                              cout << "Warning - track image ambiguity not solved" << endl;  //                              cout << "Warning - track image ambiguity not solved" << endl;
648  //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;  //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;
649              };              };
650                            
651          }else{          }else{
652              ts = tp;  //          ts = tp;
653    //          cs = cp;
654    //          os = op;
655          };          };
656                    
657  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
658          sorted_tracks->Add(ts);//save the track in the sorted array  //      sorted_tracks->Add(ts);//save the track in the sorted array
659    //      sorted_tracks.Add(ts);//save the track in the sorted array
660    //      sorted_tracks.Add(tp);//save the track in the sorted array
661  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
662            //      cout<<"o "<<tp<<endl;
663    //      cout<<"o "<<cp<<endl;
664    //      cout<<"o "<<op<<endl;
665            new(ttsorted[i]) PamTrack(tp,cp,op);
666            new(ttimage[i])  PamTrack(ti,ci,oi);
667      };      };
668    
669        if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
670            cout << "void PamLevel2::SortTracks(TString how): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
671            tsorted->Delete(); tsorted=0;
672            timage->Delete(); timage=0;    
673        }
674    
675      //Restore Object count      //Restore Object count
676      //To save space in the table keeping track of all referenced objects      //To save space in the table keeping track of all referenced objects
677      //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.  
678      TProcessID::SetObjectCount(ObjectNumber);      TProcessID::SetObjectCount(ObjectNumber);
679            
680  };  };
# Line 431  void PamLevel2::SortTracks(TString how){ Line 686  void PamLevel2::SortTracks(TString how){
686   * 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.
687   * 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.
688   */   */
689  TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
690    
691    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
692    //     SortTracks("+CAL+TOF");
693    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
694    
695    // //   return  sorted_tracks;
696    //     return &sorted_tracks;
697        
698    //  };
699    TClonesArray *PamLevel2::GetTracks(){
700    
701  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
702      SortTracks("+CAL+TOF");      SortTracks("+CAL+TOF");
703  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
704    
705      return sorted_tracks;      return tsorted;
706        
707   };   };
708  //--------------------------------------  //--------------------------------------
709   //   //
# Line 449  TRefArray *PamLevel2::GetTracks(){ Line 715  TRefArray *PamLevel2::GetTracks(){
715   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
716   */   */
717  PamTrack *PamLevel2::GetTrack(int it){  PamTrack *PamLevel2::GetTrack(int it){
718    
719    //    if(!trk2_obj) return 0;
720                    
721    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
722    //     SortTracks("+CAL+TOF");
723    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
724    // //    if(!sorted_tracks)return 0;
725    //     if(sorted_tracks.IsEmpty())return 0;
726    
727    //     PamTrack *track = 0;
728        
729    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){    
730    //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
731    //      track = GetPamTrackAlong(t);
732    //     }else{
733    //      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
734    //     };
735        
736    //     return track;
737    
738    //    cout << "PamLevel2::GetTrack(int it) "<<endl;
739  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
740      SortTracks("+CAL+TOF");      SortTracks("+CAL+TOF");
741  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
742            if(!tsorted)return 0;
743        if(!tsorted->GetEntries())return 0;
744    
745      PamTrack *track = 0;      PamTrack *track = 0;
746            
747      if( it >=0 && it < TrkLevel2::GetNTracks() && it<sorted_tracks->GetEntriesFast() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){
748          TrkTrack   *t = (TrkTrack*)sorted_tracks->At(it);  //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
749          track = GetPamTrackAlong(t);  //      track = GetPamTrackAlong(t);
750            TClonesArray &t = *(tsorted);
751            track = (PamTrack*)t[it];
752            
753      }else{      }else{
754          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;
755      };      };
756            
757      return track;      return track;
# Line 477  PamTrack *PamLevel2::GetTrack(int it){ Line 768  PamTrack *PamLevel2::GetTrack(int it){
768   */   */
769  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
770    
771    //     if(!trk2_obj) return 0;
772    
773    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
774    //     SortTracks("+CAL+TOF");
775    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
776    // //    if(!sorted_tracks)return 0;
777    //     if(sorted_tracks.IsEmpty())return 0;
778        
779    //     PamTrack *image = 0;
780        
781    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
782    //      TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);
783    //      if( temp->HasImage() ){
784    //          TrkTrack   *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
785    //          image = GetPamTrackAlong(t);
786    //      }else{
787    //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
788    //      };
789    //     }else{
790    //      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
791    //     };
792        
793    //     return image;
794    
795    
796  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
797      SortTracks("+CAL+TOF");      SortTracks("+CAL+TOF");
798  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
799        if(!timage)return 0;
800        if(!timage->GetEntries())return 0;
801            
802      PamTrack *image = 0;      PamTrack *image = 0;
803            
804      if( it >=0 && it < TrkLevel2::GetNTracks() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
805          TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);          TClonesArray &t = *(tsorted);
806          if( temp->HasImage() ){          PamTrack *temp = (PamTrack*)t[it];
807              TrkTrack   *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());          if( temp->GetTrkTrack()->HasImage() ){
808              image = GetPamTrackAlong(t);              TClonesArray &t = *(timage);
809                image = (PamTrack*)t[it];
810          }else{          }else{
811              cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;  //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
812          };          };
813      }else{      }else{
814          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;
815      };      };
816            
817      return image;      return image;
# Line 512  TTree *PamLevel2::GetPamTree(TFile *f, T Line 831  TTree *PamLevel2::GetPamTree(TFile *f, T
831    
832  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);
833  //     else                    GetWhichTrees(f);  //     else                    GetWhichTrees(f);
834        
835        cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
836    
837      SetWhichTrees(detlist);      SetWhichTrees(detlist);
838    
839      TTree *Trout =0;      TTree *Trout =0;
# Line 519  TTree *PamLevel2::GetPamTree(TFile *f, T Line 841  TTree *PamLevel2::GetPamTree(TFile *f, T
841      TString fname = f->GetName();      TString fname = f->GetName();
842      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
843    
844      UInt_t *found=0;      //    UInt_t *found=0;    
845    
846      cout<< "GetPamTree(TFile*,TString): detector list --> ";      cout<< "GetPamTree(TFile*,TString): detector list --> ";
847      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
# Line 534  TTree *PamLevel2::GetPamTree(TFile *f, T Line 856  TTree *PamLevel2::GetPamTree(TFile *f, T
856      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
857      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
858      cout << endl;      cout << endl;
859        if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
860    
861      f->cd();      f->cd();
862    
# Line 541  TTree *PamLevel2::GetPamTree(TFile *f, T Line 864  TTree *PamLevel2::GetPamTree(TFile *f, T
864      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
865      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
866          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
867          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
868          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
869          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
870          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
871          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
872          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
873          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
874          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
875          if(!Trout)Trout=T;          if(!Trout)Trout=T;
876          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 558  TTree *PamLevel2::GetPamTree(TFile *f, T Line 881  TTree *PamLevel2::GetPamTree(TFile *f, T
881      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
882      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
883          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
884          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
885          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
886          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
887          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
888          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
889          if(!Trout)Trout=C;          if(!Trout)Trout=C;
890          else Trout->AddFriend(C);          else Trout->AddFriend(C);
# Line 629  TTree *PamLevel2::GetPamTree(TFile *f, T Line 952  TTree *PamLevel2::GetPamTree(TFile *f, T
952      }else{      }else{
953          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
954      };      };
955    
956        TTree *L = (TTree*)f->Get("SelectionList");
957        if(L && SELLI==1) {
958    //      L->SetBranchAddress("RunEntry",&irun);
959    //      cout << "SelectionList: set branch address RunEntry"<<endl;
960    //      L->SetBranchAddress("EventEntry",&irunentry);
961    //      cout << "SelectionList: set branch address EventEntry"<<endl;
962    //      if(!Trout)Trout=O;
963    //      else Trout->AddFriend("SelectionList");
964            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
965            sel_tree = 0;
966        }else{
967            cout << "SelectionList  : missing tree"<<endl;
968        };
969            
970      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
971            
972        pam_tree = (TChain*)Trout;
973    
974      return Trout;      return Trout;
975            
976  }  }
# Line 657  TList*  PamLevel2::GetListOfLevel2Files( Line 996  TList*  PamLevel2::GetListOfLevel2Files(
996      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
997      contents->SetOwner();      contents->SetOwner();
998            
999      char *fullpath;  //    char *fullpath;
1000    //    const char *fullpath;
1001            
1002      // if no input file list is given:        // if no input file list is given:  
1003      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1004                    
1005          if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){        
1006              cout <<"File "<<flisttxt<<" not found"<<endl;  //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1007              return 0;  //          cout <<"File "<<flisttxt<<" not found"<<endl;
1008          }        //          return 0;
1009  //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));  //      }      
1010          flisttxt = fullpath;  //      flisttxt = fullpath;
1011            
1012            flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1013    
1014          if( !gSystem->ChangeDirectory(ddir) ){          if( !gSystem->ChangeDirectory(ddir) ){
1015              cout << "Cannot change directory : "<<ddir<<endl;              cout << "Cannot change directory : "<<ddir<<endl;
1016              return 0;              return 0;
# Line 677  TList*  PamLevel2::GetListOfLevel2Files( Line 1019  TList*  PamLevel2::GetListOfLevel2Files(
1019          cout <<"Input file list : " << flisttxt <<endl;          cout <<"Input file list : " << flisttxt <<endl;
1020          ifstream in;          ifstream in;
1021          in.open(flisttxt, ios::in); //open input file list          in.open(flisttxt, ios::in); //open input file list
1022            if(!in.good()){
1023                cout <<" ERROR opening the file "<<endl;
1024                gSystem->ChangeDirectory(wdir); // back to the working directory
1025                return 0;
1026            }      
1027          int line=0;          int line=0;
1028          while (1) {          while (1) {
1029              TString file;              TString file;
# Line 690  TList*  PamLevel2::GetListOfLevel2Files( Line 1037  TList*  PamLevel2::GetListOfLevel2Files(
1037              }              }
1038              if(file.Contains("#"))file = file(0,file.First("#"));              if(file.Contains("#"))file = file(0,file.First("#"));
1039  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1040              if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1041    //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1042                if( file.EndsWith(".root") ){
1043                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file));
1044                  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
1045                    delete fullpath;
1046              }else{              }
1047    //          }else{
1048  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1049              };  //          };
1050          };          };
1051          in.close();          in.close();
1052                    
# Line 718  TList*  PamLevel2::GetListOfLevel2Files( Line 1068  TList*  PamLevel2::GetListOfLevel2Files(
1068          while ( (questo = (TSystemFile*) next()) ) {          while ( (questo = (TSystemFile*) next()) ) {
1069              TString name =  questo-> GetName();              TString name =  questo-> GetName();
1070              if( name.EndsWith(".root") ){              if( name.EndsWith(".root") ){
1071                  char *fullpath;  //              const char *fullpath = gSystem->FindFile(ddir,name);
1072                  gSystem->IsFileInIncludePath(name,&fullpath);  //              char *fullpath;
1073    //              gSystem->IsFileInIncludePath(name,&fullpath);
1074                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1075                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1076                    delete fullpath;
1077              };              };
1078          }          }
1079          delete temp;          delete temp;
# Line 730  TList*  PamLevel2::GetListOfLevel2Files( Line 1083  TList*  PamLevel2::GetListOfLevel2Files(
1083      gSystem->ChangeDirectory(wdir); // back to the working directory      gSystem->ChangeDirectory(wdir); // back to the working directory
1084  //      cout << endl << "Selected files:" << endl;  //      cout << endl << "Selected files:" << endl;
1085  //      contents->Print();  //      contents->Print();
1086      cout << contents->GetEntries()<<" files selected\n";      cout << contents->GetEntries()<<" files \n";
1087  //      cout << endl;  //      cout << endl;
1088  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1089      return contents;      return contents;
# Line 752  TChain *PamLevel2::GetPamTree(TList *fl, Line 1105  TChain *PamLevel2::GetPamTree(TList *fl,
1105  //    if( !detlist.IsNull() )SetWhichTrees(detlist);  //    if( !detlist.IsNull() )SetWhichTrees(detlist);
1106      SetWhichTrees(detlist);      SetWhichTrees(detlist);
1107            
1108      cout<< "GetPamTree(TList*,TString): detector list --> ";      cout<< "GetPamTree(TList*,TString): input detector list --> ";
1109      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
1110      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
1111      if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
# Line 766  TChain *PamLevel2::GetPamTree(TList *fl, Line 1119  TChain *PamLevel2::GetPamTree(TList *fl,
1119      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1120      cout << endl;      cout << endl;
1121    
   
       
1122      TChain *T = 0;            TChain *T = 0;      
1123      TChain *C = 0;      TChain *C = 0;
1124      TChain *O = 0;      TChain *O = 0;
# Line 776  TChain *PamLevel2::GetPamTree(TList *fl, Line 1127  TChain *PamLevel2::GetPamTree(TList *fl,
1127      TChain *N = 0;      TChain *N = 0;
1128      TChain *A = 0;      TChain *A = 0;
1129      TChain *B = 0;      TChain *B = 0;
1130    
1131        TChain *L = 0;
1132            
1133      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1134      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 785  TChain *PamLevel2::GetPamTree(TList *fl, Line 1138  TChain *PamLevel2::GetPamTree(TList *fl,
1138      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1139      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1140      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1141    
1142         L = new TChain("SelectionList");
1143            
1144      // loop over files and create chains              // loop over files and create chains        
1145      TIter next(fl);      TIter next(fl);
1146      TSystemFile *questo = 0;      TSystemFile *questo = 0;
1147      while ( (questo = (TSystemFile*) next()) ) {      while ( (questo = (TSystemFile*) next()) ) {
1148          TString name =  questo->GetName();          TString name =  questo->GetName();
1149  //      cout << "File: "<< name << endl;          cout << "File: "<< name << endl;
1150          if( CheckLevel2File(name) ){          if( CheckLevel2File(name) ){
1151              if(TRK2||TRK1||TRKh) T->Add(name);              if(TRK2||TRK1||TRKh) T->Add(name);
1152              if(CAL1||CAL2)       C->Add(name);              if(CAL1||CAL2)       C->Add(name);
# Line 801  TChain *PamLevel2::GetPamTree(TList *fl, Line 1156  TChain *PamLevel2::GetPamTree(TList *fl,
1156              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1157              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1158              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1159                if(SELLI==1)         L->Add(name);
1160          };          };
1161      }      }
1162            
1163      cout << "done chain \n";      cout << "done chain \n";
1164    
1165      UInt_t *found=0;  //    UInt_t *found=0;
1166  // Tracker  // Tracker
1167      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1168          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1169          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1170          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1171          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1172          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1173          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1174          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1175          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1176          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1177          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1178          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
# Line 826  TChain *PamLevel2::GetPamTree(TList *fl, Line 1182  TChain *PamLevel2::GetPamTree(TList *fl,
1182      // Calorimeter      // Calorimeter
1183      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1184          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1185          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1186          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1187          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1188          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1189          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1190          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1191          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
# Line 890  TChain *PamLevel2::GetPamTree(TList *fl, Line 1246  TChain *PamLevel2::GetPamTree(TList *fl,
1246      }else{      }else{
1247          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1248      };      };
1249    
1250        // Selection List
1251        if(L && SELLI==1) {
1252            cout<<">>> Found selection-list <<<"<<endl;
1253            L->SetBranchAddress("RunEntry",&irun);
1254            cout << "SelectionList: set branch address RunEntry"<<endl;
1255            L->SetBranchAddress("EventEntry",&irunentry);
1256            cout << "SelectionList: set branch address EventEntry"<<endl;
1257            sel_tree = L;
1258    //      if(!Trout)Trout=O;
1259    //      else Trout->AddFriend("SelectionList");
1260        }else{
1261    //      cout << "SelectionList  : missing tree"<<endl;
1262            if(L)L->Delete();
1263        };
1264            
1265  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1266    
1267            pam_tree = Trout;
1268  //     // 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 );  
       
1269      return Trout;      return Trout;
1270  }  }
1271    
# Line 1020  void PamLevel2::SetBranchAddress(TTree * Line 1347  void PamLevel2::SetBranchAddress(TTree *
1347          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1348          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1349      };      };
1350        // SelectionList
1351        if(SELLI==1) {
1352            t->SetBranchAddress("RunEntry", &irun);
1353            cout << "SelectionList: set branch address RunEntry"<<endl;
1354            t->SetBranchAddress("EventEntry", &irunentry);
1355            cout << "SelectionList: set branch address EventEntry"<<endl;
1356        };
1357            
1358  }  }
1359  /**  /**
# Line 1093  void PamLevel2::SetBranchAddress(TChain Line 1427  void PamLevel2::SetBranchAddress(TChain
1427          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1428          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1429      };      };
1430        // SelectionList
1431        if(SELLI==1) {
1432            t->SetBranchAddress("RunEntry", &irun);
1433            cout << "SelectionList: set branch address RunEntry"<<endl;
1434            t->SetBranchAddress("EventEntry", &irunentry);
1435            cout << "SelectionList: set branch address EventEntry"<<endl;
1436        };
1437            
1438  }  }
1439    
# Line 1120  TChain *PamLevel2::GetRunTree(TList *fl) Line 1461  TChain *PamLevel2::GetRunTree(TList *fl)
1461              R->Add(name);              R->Add(name);
1462          };          };
1463      }      }
1464    
1465        if(R->GetNtrees()){
1466            
1467      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1468      cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
1469                R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1470            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1471        }else{
1472            delete R;
1473            R=0;
1474        }
1475    
1476        run_tree = R;
1477    
1478      return R;      return R;
1479            
1480  }  }
# Line 1138  TChain *PamLevel2::GetRunTree(TList *fl) Line 1489  TChain *PamLevel2::GetRunTree(TList *fl)
1489   */   */
1490  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
1491    
1492        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1493    
1494      TTree *R = (TTree*)f->Get("Run");      TTree *R = (TTree*)f->Get("Run");
1495            
1496      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      if(R){
1497      cout << "Run         : set branch address RunInfo"<<endl;          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1498                cout << "Run         : set branch address RunInfo"<<endl;
1499            R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1500            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1501        }
1502    
1503        run_tree = (TChain*)R;
1504    
1505      return R;      return R;
1506            
1507  }  }
1508    /**
1509     * Update the runinfo informations (to be used to have Run infos event by event basis)
1510     * @param run Pointer to the chain/tree which contains run infos
1511     * @return true if a new run has been read, false if it is still the same run
1512     */
1513    Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev){
1514      //
1515      // check if we have already called once GetEntry, if not call it
1516      //
1517      if ( run->GetEntries() <= 0 ) return(false);
1518      //
1519      
1520      Int_t oldrun = irun;
1521      // --------------------------------------
1522      // if it is a full file (not preselected)
1523      // --------------------------------------
1524      if(SELLI==0){
1525          if ( irun < 0 ){
1526              irun = 0;
1527              run->GetEntry(0);
1528              runfirstentry = 0ULL;
1529              runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;
1530          };
1531          while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1532              //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1533              irun++;
1534              run->GetEntry(irun);
1535              runfirstentry = runlastentry+1ULL;
1536              runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1537          };
1538          //
1539          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1540          //
1541          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1542          //
1543          return(true);    
1544      };
1545      // ----------------------------------------------------
1546      // if it is a preselected file (there is SelectionList)
1547      // NBNB - the event tree MUST be read first
1548      // ----------------------------------------------------
1549      if(SELLI==1){      
1550          sel_tree->GetEntry(iev);
1551          if(irun != oldrun){
1552              run->GetEntry(irun);
1553              return true;
1554          }
1555          return false;
1556      }
1557    
1558      return false;
1559      //
1560    };
1561    /**
1562     * Update the runinfo informations (to be used to have Run infos event by event basis)
1563     * @param run Pointer to the chain/tree which contains run infos
1564     * @return true if a new run has been read, false if it is still the same run
1565     */
1566    Bool_t PamLevel2::UpdateRunInfo(TTree *run, ULong64_t iev){
1567      return(UpdateRunInfo((TChain*)run,iev));
1568    };
1569    
1570  //--------------------------------------  //--------------------------------------
1571  //  //
1572  //  //
# Line 1158  TTree *PamLevel2::GetRunTree(TFile *f){ Line 1578  TTree *PamLevel2::GetRunTree(TFile *f){
1578  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
1579                    
1580      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
1581            CAL0 = false;
1582          CAL1 = true;          CAL1 = true;
1583          CAL2 = true;          CAL2 = true;
1584          TRK2 = true;          TRK2 = true;
1585          TRK1 = false;          TRK1 = false;
1586          TRKh = false;          TRKh = false;
1587            TRK0 = false;
1588          TRG = true;          TRG = true;
1589          TOF = true;          TOF = true;
1590            TOF0 = false;
1591          S4  = true;          S4  = true;
1592          ND  = true;          ND  = true;
1593          AC  = true;          AC  = true;
1594          ORB = true;          ORB = true;
1595      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
1596            CAL0 = false;
1597          CAL1 = false;          CAL1 = false;
1598          CAL2 = false;          CAL2 = false;
1599          TRK2 = false;          TRK2 = false;
1600          TRK1 = false;          TRK1 = false;
1601          TRKh = false;          TRKh = false;
1602            TRK0 = false;
1603          TRG = false;          TRG = false;
1604          TOF = false;          TOF = false;
1605            TOF0 = false;
1606          S4  = false;          S4  = false;
1607          ND  = false;          ND  = false;
1608          AC  = false;          AC  = false;
# Line 1188  void PamLevel2::SetWhichTrees(TString de Line 1614  void PamLevel2::SetWhichTrees(TString de
1614          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1615          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1616      };      };
1617    
1618        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
1619            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
1620            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
1621        };
1622                    
1623      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1624          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1200  void PamLevel2::SetWhichTrees(TString de Line 1631  void PamLevel2::SetWhichTrees(TString de
1631          CAL1=false;          CAL1=false;
1632      }      }
1633  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
1634        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
1635            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
1636            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
1637        };
1638    
1639      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1640          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1641          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1228  void PamLevel2::SetWhichTrees(TString de Line 1664  void PamLevel2::SetWhichTrees(TString de
1664            
1665      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
1666      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
1667    
1668        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
1669        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
1670            
1671      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
1672      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
# Line 1262  void PamLevel2::SetWhichTrees(TString de Line 1701  void PamLevel2::SetWhichTrees(TString de
1701   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
1702   */   */
1703  void  PamLevel2::GetWhichTrees(TFile* f){  void  PamLevel2::GetWhichTrees(TFile* f){
1704                
1705    
1706    
1707        cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
1708      // -----------      // -----------
1709      // reset flags      // reset flags
1710      // -----------      // -----------
# Line 1389  void  PamLevel2::GetWhichTrees(TFile* f) Line 1830  void  PamLevel2::GetWhichTrees(TFile* f)
1830    
1831      };      };
1832            
1833      lk->Delete();      delete lk;
1834    
1835  //     cout<< "Get detector list from input file --> ";  //     cout<< "Get detector list from input file --> ";
1836  //     if(TRK1)cout<<"TRK1 ";  //     if(TRK1)cout<<"TRK1 ";
# Line 1435  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1876  Bool_t  PamLevel2::CheckLevel2File(TStri
1876            
1877      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
1878            
1879            Bool_t SELLI__ok  = false;
1880    
1881      cout << "Checking file: "<<name<<endl;      cout << "Checking file: "<<name<<endl;
1882      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
# Line 1452  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1893  Bool_t  PamLevel2::CheckLevel2File(TStri
1893    
1894      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
1895                    
1896    //      cout << key->GetName() << endl;
1897  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
1898  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
1899  //      nev_previous = nev;  //      nev_previous = nev;
# Line 1462  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1904  Bool_t  PamLevel2::CheckLevel2File(TStri
1904  //          return false;  //          return false;
1905  //      };  //      };
1906    
1907    
1908          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
1909    
1910          //=========================================================              //=========================================================    
1911            if( !strcmp(key->GetName(),"SelectionList"    ) ){
1912                SELLI__ok = true;
1913                if(SELLI==1){
1914                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
1915                    if( nev && nevt!=nev){
1916                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
1917                        return false;
1918                    }
1919                    nev=nevt;
1920                }
1921            }
1922    
1923            //=========================================================    
1924          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
1925              TRG__ok = true;              TRG__ok = true;
1926              if(TRG){              if(TRG){
# Line 1576  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2032  Bool_t  PamLevel2::CheckLevel2File(TStri
2032          };                };      
2033    
2034      };      };
2035    
2036        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
2037        if( SELLI==0 && SELLI__ok ){
2038            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
2039            return false;  
2040        }
2041        if( SELLI==1 && !SELLI__ok ){
2042            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
2043            return false;
2044        }
2045            
2046    //    cout << "SELLI "<<SELLI<<endl;
2047    
2048  //     cout<< "CheckLevel2File(TString): detector list --> ";  //     cout<< "CheckLevel2File(TString): detector list --> ";
2049  //     if(TRK1__ok)cout<<"TRK1 ";  //     if(TRK1__ok)cout<<"TRK1 ";
2050  //     if(TRK2__ok)cout<<"TRK2 ";  //     if(TRK2__ok)cout<<"TRK2 ";
# Line 1592  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2060  Bool_t  PamLevel2::CheckLevel2File(TStri
2060  //     cout << endl;  //     cout << endl;
2061    
2062    
2063        if(TRK2 && TRK1__ok)TRK1=1;
2064    // ----------------------------------------------------------------------------
2065    // NOTA
2066    // se c'e` il level1, lo devo necessarimente leggere.
2067    // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
2068    // comunque, ma non vengono disallocati da PamLevel2::Clear()
2069    // ----------------------------------------------------------------------------
2070    
2071    
2072      if(!RUN__ok) {      if(!RUN__ok) {
2073          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;
2074  //      return false;  //      return false;
# Line 1644  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2121  Bool_t  PamLevel2::CheckLevel2File(TStri
2121      };      };
2122            
2123    
2124      lk->Delete();  //    lk->Delete();
2125    //    delete lk;
2126      f->Close();      f->Close();
2127    
2128  //     cout<< "CheckLevel2File(TString): detector list --> ";  //     cout<< "CheckLevel2File(TString): detector list --> ";
# Line 1675  void PamLevel2::CreateCloneTrees0( TChai Line 2153  void PamLevel2::CreateCloneTrees0( TChai
2153      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
2154            
2155      Int_t i=0;      Int_t i=0;
2156      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
2157      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
2158      name.Append("_clone");      name.Append("_clone");
2159  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
2160      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
2161      i++;      i++;
2162    
2163      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
# Line 1689  void PamLevel2::CreateCloneTrees0( TChai Line 2167  void PamLevel2::CreateCloneTrees0( TChai
2167      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
2168  //      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;
2169  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
2170          tree_clone[i] = T_friend->GetTree()->CloneTree(0);          pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2171          tree_clone[i]->SetAutoSave(1000000);          pam_tree_clone[i]->SetAutoSave(1000000);
2172          name =  tree_clone[i]->GetName();          name =  pam_tree_clone[i]->GetName();
2173          name.Append("_clone");          name.Append("_clone");
2174  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
2175          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
2176          i++;          i++;
2177      }      }
2178        
2179        delete li;
2180    
2181      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2182    
# Line 1712  void PamLevel2::CreateCloneTrees(TFile * Line 2192  void PamLevel2::CreateCloneTrees(TFile *
2192      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2193      cout << "Create new PAMELA trees "<<endl;      cout << "Create new PAMELA trees "<<endl;
2194                    
     Int_t i=0;  
2195    
2196        run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
2197        run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
2198        cout << "Run          : branch RunInfo"<<endl;
2199        run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
2200        cout << "Run          : branch SoftInfo"<<endl;
2201                
2202    
2203    
2204        sel_tree_clone = new TTree("SelectionList","List of selected events ");
2205        sel_tree_clone->Branch("RunEntry",&irun,"runentry/I");
2206        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/I");
2207        
2208    
2209        Int_t i=0;
2210      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
2211          tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");              pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2212          if(TRK1) {          if(TRK1) {
2213              tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2214              tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
2215              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
2216          };          };
2217          if(TRK2) {          if(TRK2) {
2218              tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2219              cout << "Tracker      : branch TrkLevel2"<<endl;                      cout << "Tracker      : branch TrkLevel2"<<endl;        
2220          };          };
2221          if(TRKh) {          if(TRKh) {
2222              tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));              pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2223              cout << "Tracker      : branch TrkHough"<<endl;              cout << "Tracker      : branch TrkHough"<<endl;
2224          };          };
2225          i++;          i++;
# Line 1734  void PamLevel2::CreateCloneTrees(TFile * Line 2227  void PamLevel2::CreateCloneTrees(TFile *
2227    
2228      // Calorimeter      // Calorimeter
2229      if(CAL1||CAL2){      if(CAL1||CAL2){
2230          tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2231          if(CAL1) {          if(CAL1) {
2232              tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));              pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2233              cout << "Calorimeter  : branch CaloLevel1"<<endl;              cout << "Calorimeter  : branch CaloLevel1"<<endl;
2234          };          };
2235          if(CAL2) {          if(CAL2) {
2236              tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2237              cout << "Calorimeter  : branch CaloLevel2"<<endl;              cout << "Calorimeter  : branch CaloLevel2"<<endl;
2238          };          };
2239          i++;          i++;
# Line 1748  void PamLevel2::CreateCloneTrees(TFile * Line 2241  void PamLevel2::CreateCloneTrees(TFile *
2241    
2242      // ToF          // ToF    
2243      if(TOF) {      if(TOF) {
2244          tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2245          tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2246          cout << "ToF          : branch ToFLevel2"<<endl;          cout << "ToF          : branch ToFLevel2"<<endl;
2247          i++;          i++;
2248      };      };
2249      // Trigger      // Trigger
2250      if(TRG) {      if(TRG) {
2251          tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");              pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2252          tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2253          cout << "Trigger      : branch TrigLevel2"<<endl;          cout << "Trigger      : branch TrigLevel2"<<endl;
2254          i++;          i++;
2255      };      };
2256      // S4      // S4
2257      if(S4) {      if(S4) {
2258          tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");                pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
2259          tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));          pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2260          cout << "S4           : branch S4Level2"<<endl;          cout << "S4           : branch S4Level2"<<endl;
2261          i++;          i++;
2262      };      };
2263      // Neutron Detector      // Neutron Detector
2264      if(ND) {      if(ND) {
2265          tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
2266          tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));          pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2267          cout << "NeutronD     : branch NDLevel2"<<endl;          cout << "NeutronD     : branch NDLevel2"<<endl;
2268          i++;          i++;
2269      };      };
2270      // Anticounters      // Anticounters
2271      if(AC) {      if(AC) {
2272          tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");              pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
2273          tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));          pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2274          cout << "Anticounter  : branch AcLevel2"<<endl;          cout << "Anticounter  : branch AcLevel2"<<endl;
2275          i++;          i++;
2276      };      };
2277      // OrbitalInfo      // OrbitalInfo
2278      if(ORB) {      if(ORB) {
2279          tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");                pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");  
2280          tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2281          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
2282          i++;          i++;
2283      };      };
# Line 1792  void PamLevel2::CreateCloneTrees(TFile * Line 2285  void PamLevel2::CreateCloneTrees(TFile *
2285    
2286  }  }
2287    
 // /**  
 //  * 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;  
   
 // }  
2288    
2289  /**  /**
2290   * Fill tree (created with CreateCloneTrees)   * Fill tree (created with CreateCloneTrees)
# Line 1888  void PamLevel2::CreateCloneTrees(TFile * Line 2292  void PamLevel2::CreateCloneTrees(TFile *
2292   */   */
2293  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
2294  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
2295                
2296  // //  --------------------------------------  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
2297  // //  copy the event      for(Int_t i=0; i<NCLONES; i++){
2298  // //  --------------------------------------          if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2299  //     if(trk1_clone)  *trk1_clone = *trk1_obj;      }
2300  //     if(trk2_clone){      if(sel_tree_clone)sel_tree_clone->Fill();    
2301  //      trk2_clone->Clear();  //    if( irunentry == 0 || run_tree_clone->GetEntries()==0 )run_tree_clone->Fill();
2302  //      trk2_obj->Copy(*trk2_clone);  //    Int_t nstoredruns = run_tree_clone->GetEntries();
2303  // //   *trk2_clone = *trk2_obj;  //     if( irun ==  nstoredruns )run_tree_clone->Fill();
2304  //     }  //     else if( irun > nstoredruns || irun < nstoredruns-1){
2305  //     if(trkh_clone)  *trkh_clone = *trkh_obj;  //      cout << " PamLevel2::FillCloneTrees() -- ERROR -- current run "<< irun <<" stored runs "<< nstoredruns <<endl;
 //     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);  
2306  //     }  //     }
 //     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();  
2307    
     for(Int_t i=0; i<8; i++){  
         if(tree_clone[i])tree_clone[i]->Fill();  
     }  
2308  }  }
2309    
2310    
2311  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
2312    
2313      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
2314          if(tree_clone[i]){          if(pam_tree_clone[i]){
2315              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
2316              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
2317          };          };
2318      }      }
2319        if(run_tree_clone){
2320            TString na = run_tree_clone->GetName();
2321            if(!name.CompareTo(na))return run_tree_clone;
2322        }
2323        if(sel_tree_clone){
2324            TString na = sel_tree_clone->GetName();
2325            if(!name.CompareTo(na))return sel_tree_clone;
2326        }
2327      return NULL;      return NULL;
2328    
2329  }  }
2330  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
2331      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2332      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
2333      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;    
2334          if(tree_clone[i]){      run_tree_clone->Write();
2335              cout << tree_clone[i]->GetName()<<endl;      cout << sel_tree_clone->GetName()<<endl;    
2336              tree_clone[i]->Write();      sel_tree_clone->Write();
2337        for(Int_t i=0; i<NCLONES; i++){    
2338            if(pam_tree_clone[i]){
2339                cout << pam_tree_clone[i]->GetName()<<endl;
2340                pam_tree_clone[i]->Write();
2341          };          };
2342      }      }
2343      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 1956  void PamLevel2::WriteCloneTrees(){ Line 2345  void PamLevel2::WriteCloneTrees(){
2345  }  }
2346    
2347  /**  /**
2348   * Create a new (empty) Pamela trees   * Method to get both level2-trees entry and corresponding run entry.
2349   */   */
 // TTree* PamLevel2::GetNewPamTree(){  
2350    
 //     if(tree_clone)return tree_clone;  
2351    
2352  //     TTree *Tout = 0;  Int_t PamLevel2::GetEntry(Int_t iee){
       
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
 //     cout << "Create new PAMELA trees "<<endl;  
2353            
2354            if(!pam_tree){
2355  //     if(TRK1||TRK2||TRKh){          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
2356  //      TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");              return 0;
2357  //      if(TRK1) {      }
2358  //          trk1_clone = new TrkLevel1();      if(!run_tree ){
2359  //          T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
2360  //          T->BranchRef();          return 0;
2361  //          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");  
 //     }  
2362    
2363  //     // Calorimeter      Int_t ii=0;
2364  //     if(CAL1||CAL2){      //-------------------------------
2365  //      TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");          ii = iee;
2366  //      if(CAL1) {      if( !pam_tree->GetEntry(ii) ) return 0;
2367  //          calo1_clone = new CaloLevel1();      //-------------------------------
2368  //          C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);      ii = iee;
2369  //          cout << "Calorimeter  : branch CaloLevel1"<<endl;      Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
2370  //      };      if(SELLI==0)irunentry = iee-runfirstentry;
2371  //      if(CAL2) {      if(UPDATED && run_tree_clone)run_tree_clone->Fill();
 //          calo2_clone = new CaloLevel2();  
 //          C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);  
 //          cout << "Calorimeter  : branch CaloLevel2"<<endl;  
 //      };  
 //      if(!Tout)Tout=C;  
 //      else Tout->AddFriend("Calorimeter_clone");  
 //     }      
   
 //     // ToF      
 //     if(TOF) {  
 //      TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data ");      
 //      tof_clone = new ToFLevel2();  
 //      O->Branch("ToFLevel2","ToFLevel2", &tof_clone);  
 //      cout << "ToF          : branch ToFLevel2"<<endl;  
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF_clone");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data ");      
 //      trig_clone = new TrigLevel2();  
 //      R->Branch("TrigLevel2","TrigLevel2", &trig_clone);  
 //      cout << "Trigger      : branch TrigLevel2"<<endl;  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger_clone");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      TTree *S = new TTree("S4_clone","PAMELA S4 level2 data ");        
 //      s4_clone = new S4Level2();  
 //      S->Branch("S4Level2","S4Level2", &s4_clone);  
 //      cout << "S4           : branch S4Level2"<<endl;  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4_clone");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      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;  
2372    
2373  //     tree_clone = Tout;  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
 //     tree_clone->SetDirectory(0);  
2374    
2375  //     return Tout;      if( TRK0 || CAL0 || TOF0 )GetYodaEntry( );
2376  // }  
2377  // /**      return 1;
2378  //  * Fill a tree (created with GetNewPamTree)  
2379  //  *  }
2380  //  */  
2381  // //void PamLevel2::FillNewPamTree(TTree *T){  /**
2382  // void PamLevel2::FillNewPamTree(){   * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2383             * Given the run ID (...), if needed it query the DB and load the proper file.
2384     * @return Pointer to the tree
2385     */
2386    
 //     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  
 //     }  
2387    
2388  // }  TTree* PamLevel2::GetYodaTree( ){
2389        
2390    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
2391        //===================================
2392        // check if iroot has changed
2393        //===================================
2394        if( irun<0 ){
2395            cout << "PamLevel2::GetYodaTree() -- ERROR "<<endl;
2396            cout << "In order to use this method you have to load the RunInfo tree "<<endl;
2397            cout << "with the method TChain* PamLevel2::GetRunTree(TString, TString)"<<endl;
2398    //      cout << " - read the event with PamLevel2::GetEntry(Int_t)"<<endl;
2399            return NULL;
2400        }    
2401        Int_t irootnew = run_obj->ID_ROOT_L0;
2402    //    cout << "iroot    "<<iroot<<endl;
2403    //    cout << "irootnew "<<irootnew<<endl;
2404    
2405        //===================================
2406        // load the level0 file
2407        // (if not already loaded)
2408        //===================================
2409        if( iroot != irootnew || !l0_tree){
2410            iroot = irootnew;
2411            //===================================
2412            // open the DB connection
2413            // (if not already opened)
2414            //===================================
2415            if(!dbc || (dbc && !dbc->IsConnected())){
2416                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2417                cout<<"Connecting to DB"<<endl;
2418                cout<<"HOST "<<host<<endl;
2419                cout<<"USER "<<user<<endl;
2420                cout<<"PSW  "<<psw<<endl;
2421                dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
2422                if( !dbc )return NULL;
2423                if( !dbc->IsConnected() )return NULL;    
2424    //          cout<<"...done"<<endl;
2425                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2426            }else{
2427    //          cout<<"DB already connected"<<endl;
2428            }
2429            GL_ROOT glroot = GL_ROOT();
2430            if( glroot.Query_GL_ROOT(iroot,dbc) )return NULL;
2431            TString filename = glroot.PATH + glroot.NAME;
2432            if(l0_file){
2433                l0_file->Close();
2434                l0_file->Delete();
2435            }
2436            cout << "Opening LEVEL0 file: "<< filename << endl;
2437            FileStat_t t;
2438            if( gSystem->GetPathInfo(filename.Data(),t) ){
2439                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
2440                return NULL;
2441            }
2442            l0_file = new TFile(filename);
2443            if( !l0_file )return NULL;
2444            l0_tree = (TTree*)l0_file->Get("Physics");
2445            if(!h0_obj)h0_obj = new EventHeader();
2446            l0_tree->SetBranchAddress("Header" ,&h0_obj);
2447            //---------------------------------------------------
2448            // TRACKER:
2449            if(TRK0){
2450                if(!trk0_obj){
2451                    trk0_obj = new TrkLevel0();
2452                    trk0_obj->Set();
2453                };
2454                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
2455                TrkParams::SetCalib(run_obj,dbc);
2456            }
2457            //---------------------------------------------------
2458            // CALORIMETER:
2459            if(CAL0){
2460                cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
2461            }
2462            //---------------------------------------------------
2463            // TOF:
2464            if(TOF0){
2465                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
2466            }
2467    
2468        };
2469    
2470        return l0_tree;
2471    
2472    }
2473    
2474    /**
2475     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2476     */
2477    Int_t PamLevel2::GetYodaEntry(){
2478    
2479    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
2480        if(!GetYodaTree())return 0;
2481        
2482        //  ---------------------------------
2483        //  if file is NOT a preselected file
2484        //  ---------------------------------
2485        Int_t quellagiusta = irunentry + run_obj->EV_FROM;
2486        //  ------------------------------------------
2487        //  otherwise read the "preselected-list" tree
2488        //  ------------------------------------------
2489    
2490    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
2491        return GetYodaTree()->GetEntry(quellagiusta);
2492        
2493        return 1;
2494        
2495    }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.22

  ViewVC Help
Powered by ViewVC 1.1.23