/[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.1 by pam-fi, Fri Jun 16 16:43:55 2006 UTC revision 1.2 by pam-fi, Fri Aug 4 13:31:35 2006 UTC
# Line 35  PamTrack::PamTrack(TrkTrack* t, CaloTrkV Line 35  PamTrack::PamTrack(TrkTrack* t, CaloTrkV
35   * Constructor   * Constructor
36   */   */
37  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
38            
39      trk_obj  = this->TrkLevel2::GetTrkLevel2();      trk_obj  = this->TrkLevel2::GetTrkLevel2();
40      calo_obj = this->CaloLevel2::GetCaloLevel2();      calo_obj = this->CaloLevel2::GetCaloLevel2();
41      tof_obj  = this->ToFLevel2::GetToFLevel2();      tof_obj  = this->ToFLevel2::GetToFLevel2();
# Line 42  PamLevel2::PamLevel2(){ Line 43  PamLevel2::PamLevel2(){
43      s4_obj   = this->S4Level2::GetS4Level2();      s4_obj   = this->S4Level2::GetS4Level2();
44      nd_obj   = this->NDLevel2::GetNDLevel2();      nd_obj   = this->NDLevel2::GetNDLevel2();
45      ac_obj   = this->AcLevel2::GetAcLevel2();      ac_obj   = this->AcLevel2::GetAcLevel2();
46            orb_obj  = this->OrbitalInfo::GetOrbitalInfo();
47    
48            sorted_tracks = new TRefArray();
49    
50            CAL = true;
51            TRK = true;
52            TRG = true;
53            TOF = true;
54            S4  = true;
55            ND  = true;
56            AC  = true;
57            ORB = true;
58    
59    };
60    /**
61     * Destructor
62     */
63    PamLevel2::~PamLevel2(){
64                    
65            delete sorted_tracks;
66            
67    };
68    /**
69     * Clear the event
70     */
71    void PamLevel2::Clear(){
72                    
73            sorted_tracks->Delete();
74            
75  };  };
76    
77    
78  //--------------------------------------  //--------------------------------------
79  //  //
80  //  //
# Line 55  PamLevel2::PamLevel2(){ Line 87  PamLevel2::PamLevel2(){
87    
88  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
89            
     // retrieve itrk-th tracker stored track  
90      TrkTrack   *t = 0;      TrkTrack   *t = 0;
91      CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
92      ToFTrkVar  *o = 0;      ToFTrkVar  *o = 0;
93    
94      if( itrk >=0 && itrk < TrkLevel2::ntrk() ){      if( itrk >=0 && itrk < TrkLevel2::ntrk() ){
95          t = TrkLevel2::GetStoredTrack(itrk);                      t = TrkLevel2::GetStoredTrack(itrk);
96          c = CaloLevel2::GetCaloTrkVar(t->GetSeqNo());  /*              c = CaloLevel2::GetCaloTrkVar(t->GetSeqNo());
97          o = ToFLevel2::GetToFTrkVar(t->GetSeqNo());                  o = ToFLevel2::GetToFTrkVar(t->GetSeqNo()); */
98      };                  Int_t it_calo=0;
99      //  retrieve related ToF-track                  do{
100                                c = CaloLevel2::GetCaloTrkVar(it_calo);
101                            it_calo++;
102                    } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk());  
103                    if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetStoredTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<<endl;
104                    
105                    Int_t it_tof=0;
106                    do{
107                            o = ToFLevel2::GetToFTrkVar(it_tof);
108                            it_tof++;
109                    } while(t->GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk());    
110                    if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetStoredTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <<endl;
111                    
112            }else{
113                    cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
114            };
115    
116      // hence create a "PamTrack" object      // hence create a "PamTrack" object
117      PamTrack *track = 0;      PamTrack *track = 0;
118      if(t && c && o)track = new PamTrack(t,c,o);      if(t && c && o)track = new PamTrack(t,c,o);
119      return track;      return track;
120                
121  }  }
122  //--------------------------------------  //--------------------------------------
123  //  //
# Line 80  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 126  PamTrack* PamLevel2::GetStoredTrack(Int_
126  /**  /**
127   * Sort physical (tracker) tracks and stores them in a TObjectArray (of TrkTrack objects).   * Sort physical (tracker) tracks and stores them in a TObjectArray (of TrkTrack objects).
128   * The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it).   * The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it).
  * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.  
  * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.  
129   */   */
130  TClonesArray *PamLevel2::GetTracks(){  void PamLevel2::SortTracks(){
   
     // define new array for sorted tracker tracks  
     TClonesArray *aa = new TClonesArray("TrkTrack");  
     TClonesArray &sorted = *aa;  
131    
132            sorted_tracks->Delete(); //temporaneo
133      // loop over the tracks sorted by the tracker      // loop over the tracks sorted by the tracker
134      for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){          for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){
135    
136          TrkTrack *ts=0;                  TrkTrack *ts = 0;
137    
138          // get tracker tracks          // get tracker tracks
139          TrkTrack   *tp = TrkLevel2::GetTrack(i);                    //tracker                  TrkTrack   *tp = TrkLevel2::GetTrack(i);                    //tracker
140          CaloTrkVar *cp = CaloLevel2::GetCaloTrkVar(tp->GetSeqNo()); //calorimeter                  CaloTrkVar *cp = CaloLevel2::GetCaloTrkVar(tp->GetSeqNo()); //calorimeter
141          ToFTrkVar  *op = ToFLevel2::GetToFTrkVar(tp->GetSeqNo());   //tof                  ToFTrkVar  *op = ToFLevel2::GetToFTrkVar(tp->GetSeqNo());   //tof
142    
143          // if track has an image, check image selection          // if track has an image, check image selection
144          if(tp->HasImage()){                  if(tp->HasImage()){
145              TrkTrack   *ti = TrkLevel2::GetTrackImage(i);              //tracker (image)                          TrkTrack   *ti = TrkLevel2::GetTrackImage(i);              //tracker (image)
146              CaloTrkVar *ci = CaloLevel2::GetCaloTrkVar(ti->GetSeqNo());//calorimeter (image)                          CaloTrkVar *ci = CaloLevel2::GetCaloTrkVar(ti->GetSeqNo());//calorimeter (image)
147              ToFTrkVar  *oi = ToFLevel2::GetToFTrkVar(ti->GetSeqNo());  //tof (image)                          ToFTrkVar  *oi = ToFLevel2::GetToFTrkVar(ti->GetSeqNo());  //tof (image)
148    
149              //assign starting scores              //assign starting scores
150              Int_t tp_score = 1;                          Int_t tp_score = 1;  //"principal" track, sorted by the tracker
151              Int_t ti_score = 0;                          Int_t ti_score = 0;  //image track
152              // ------------------------              // ------------------------
153              // calorimeter check              // calorimeter check
154              // ------------------------              // ------------------------
155              if(                          if(
156                        npcfit[1] > 3   &&  //no. of fit planes on Y view                                                  npcfit[1] > 3   &&  //no. of fit planes on Y view
157  //              varcfit[1] < 50.&&  //fit variance on Y view  //              varcfit[1] < 50.&&  //fit variance on Y view
158                        true){                                                  true){
159    
160                  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] - cbar[0][1];if(resy_p < 0)resy_p= - resy_p;
161                  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] - cbar[0][1];if(resy_i < 0)resy_i= - resy_i;
162    
163                  if(resy_p <= resy_i) tp_score++;                                  if(resy_p <= resy_i) tp_score++;
164                  else                 ti_score++;                                  else                 ti_score++;
165                        };                          };
166              // ------------------------              // ------------------------
167              // TOF check              // TOF check
168              // ------------------------                  // ------------------------    
# Line 129  TClonesArray *PamLevel2::GetTracks(){ Line 170  TClonesArray *PamLevel2::GetTracks(){
170              // ------------------------              // ------------------------
171              // the winner is....              // the winner is....
172              // ------------------------                  // ------------------------    
173                        if(tp_score > ti_score) ts = tp;//the track sorted by the tracker!!                          if(tp_score > ti_score) ts = tp;//the track sorted by the tracker!!
174                        else                    ts = ti;//its image!!                          else                    ts = ti;//its image!!
175    
176          }else{                  }else{
177              ts = tp;                          ts = tp;
178                    };
179                            
180                    sorted_tracks->Add(ts);//save the track in the sorted array
181                    
182          };          };
           
         new(sorted[i]) TrkTrack(*ts); //save the track in the sorted array  
     };  
183    
     return aa;  
184  };  };
185  //--------------------------------------  //--------------------------------------
186  //  //
187  //  //
188  //--------------------------------------  //--------------------------------------
189  /**  /**
190     * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
191     * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
192     */
193     TRefArray *PamLevel2::GetTracks(){
194    //      if(!sorted_tracks->GetEntries()) SortTracks();
195            SortTracks();
196            return sorted_tracks;
197     };
198    //--------------------------------------
199    //
200    //
201    //--------------------------------------
202    /**
203   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
204   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
205   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
206   */   */
207  PamTrack *PamLevel2::GetTrack(int it){  PamTrack *PamLevel2::GetTrack(int it){
208    
209      TClonesArray *aa = this->GetTracks();          SortTracks();
210      TClonesArray &sorted = *aa;          
211            TrkTrack   *t = 0;
212      TrkTrack   *t = 0;          CaloTrkVar *c = 0;
213      CaloTrkVar *c = 0;          ToFTrkVar  *o = 0;
214      ToFTrkVar  *o = 0;  
215            if( it >=0 && it < TrkLevel2::GetNTracks() ){
216      if( it >=0 && it < TrkLevel2::GetNTracks() ){                  
217          t = (TrkTrack*)sorted[it];                  t = (TrkTrack*)sorted_tracks->At(it);
218          c = CaloLevel2::GetCaloTrkVar(t->GetSeqNo());                  
219          o = ToFLevel2::GetToFTrkVar(t->GetSeqNo());                  Int_t it_calo=0;
220      };                  do{
221                            c = CaloLevel2::GetCaloTrkVar(it_calo);
222                            it_calo++;
223                    } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk());  
224                    if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<<endl;
225                    
226                    Int_t it_tof=0;
227                    do{
228                            o = ToFLevel2::GetToFTrkVar(it_tof);
229                            it_tof++;
230                    } while(t->GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk());    
231                    if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <<endl;
232                    
233            }else{
234                    cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
235            };
236            
237      // hence create a "PamTrack" object      // hence create a "PamTrack" object
238      PamTrack *track = 0;          PamTrack *track = 0;
239      if(t && c && o)track = new PamTrack(t,c,o);          if(t && c && o)track = new PamTrack(t,c,o);
240      return track;          
241            return track;
242    
243  };  };
244  //--------------------------------------  //--------------------------------------
# Line 181  PamTrack *PamLevel2::GetTrack(int it){ Line 251  PamTrack *PamLevel2::GetTrack(int it){
251   */   */
252  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
253    
254      TClonesArray *aa = this->GetTracks();  //      if(!sorted_tracks->GetEntries()) SortTracks();
255      TClonesArray &sorted = *aa;          SortTracks();
256            
257      TrkTrack   *t = 0;      TrkTrack   *t = 0;
258      CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
259      ToFTrkVar  *o = 0;      ToFTrkVar  *o = 0;
260    
261      if( it >=0 && it < TrkLevel2::GetNTracks() ){      if( it >=0 && it < TrkLevel2::GetNTracks() ){
262          TrkTrack *temp = (TrkTrack*)sorted[it];                  TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);
263          if( temp->HasImage() ){                  if( temp->HasImage() ){
264              t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());                          
265              c = CaloLevel2::GetCaloTrkVar(temp->GetImageSeqNo());                          t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
266              o = ToFLevel2::GetToFTrkVar(temp->GetImageSeqNo());  
267    /*                      c = CaloLevel2::GetCaloTrkVar(temp->GetImageSeqNo());
268                            o = ToFLevel2::GetToFTrkVar(temp->GetImageSeqNo());*/
269                    
270                            Int_t it_calo=0;
271                            do{
272                                    c = CaloLevel2::GetCaloTrkVar(it_calo);
273                                    it_calo++;
274                            } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk());  
275                            if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetTrackImage(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<<endl;
276                    
277                            Int_t it_tof=0;
278                            do{
279                                    o = ToFLevel2::GetToFTrkVar(it_tof);
280                                    it_tof++;
281                            } while(t->GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk());    
282                            if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetTrackImage(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <<endl;
283                    }else{
284                            cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
285                    };
286            }else{
287                    cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
288          };          };
     };  
289            
290      // hence create a "PamTrack" object      // hence create a "PamTrack" object
291      PamTrack *image = 0;      PamTrack *image = 0;
292      if(t && c && o)image = new PamTrack(t,c,o);      if(t && c && o)image = new PamTrack(t,c,o);
293      return image;      
294            return image;
295            
296  }  }
297    
# Line 209  PamTrack *PamLevel2::GetTrackImage(int i Line 300  PamTrack *PamLevel2::GetTrackImage(int i
300  //  //
301  //--------------------------------------  //--------------------------------------
302  /**  /**
303   * Get the Pamela detector trees and make them friends.   * Get the Pamela detector trees in a single file and make them friends.
304     * @param f TFile pointer
305     * @param detlist String to select trees to be included
306     * @return Pointer to a TTree
307   */   */
308  TTree *PamLevel2::LoadPamTrees(TFile *f){  TTree *PamLevel2::LoadPamTrees(TFile *f, TString detlist="+ALL"){
309            
310      TTree *Tout =0;      TTree *Tout =0;
311                
312            SetWhichTrees(detlist);
313            
314      // Tracker      // Tracker
315      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
316      if(T) {      if(T && TRK) {
317          T->SetBranchAddress("TrkLevel2", GetPointerToTrk());          T->SetBranchAddress("TrkLevel2", GetPointerToTrk());
318          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
319          if(!Tout)Tout=T;          if(!Tout)Tout=T;
# Line 226  TTree *PamLevel2::LoadPamTrees(TFile *f) Line 322  TTree *PamLevel2::LoadPamTrees(TFile *f)
322      };      };
323      // Calorimeter      // Calorimeter
324      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
325      if(C) {      if(C && CAL) {
326          C->SetBranchAddress("CaloLevel2", GetPointerToCalo());          C->SetBranchAddress("CaloLevel2", GetPointerToCalo());
327          cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
328          if(!Tout)Tout=C;          if(!Tout)Tout=C;
# Line 236  TTree *PamLevel2::LoadPamTrees(TFile *f) Line 332  TTree *PamLevel2::LoadPamTrees(TFile *f)
332      };      };
333      // ToF          // ToF    
334      TTree *O = (TTree*)f->Get("ToF");      TTree *O = (TTree*)f->Get("ToF");
335      if(O) {      if(O && TOF) {
336          O->SetBranchAddress("ToFLevel2", GetPointerToToF());          O->SetBranchAddress("ToFLevel2", GetPointerToToF());
337          cout << "ToF          : set branch address ToFLevel2"<<endl;          cout << "ToF          : set branch address ToFLevel2"<<endl;
338          if(!Tout)Tout=O;          if(!Tout)Tout=O;
# Line 246  TTree *PamLevel2::LoadPamTrees(TFile *f) Line 342  TTree *PamLevel2::LoadPamTrees(TFile *f)
342      };      };
343      // Trigger      // Trigger
344      TTree *R = (TTree*)f->Get("Trigger");      TTree *R = (TTree*)f->Get("Trigger");
345      if(R) {      if(R && TRG) {
346          R->SetBranchAddress("TrigLevel2", GetPointerToTrig());          R->SetBranchAddress("TrigLevel2", GetPointerToTrig());
347          cout << "Trigger      : set branch address TrigLevel2"<<endl;          cout << "Trigger      : set branch address TrigLevel2"<<endl;
348          if(!Tout)Tout=O;          if(!Tout)Tout=O;
# Line 256  TTree *PamLevel2::LoadPamTrees(TFile *f) Line 352  TTree *PamLevel2::LoadPamTrees(TFile *f)
352      };      };
353      // S4      // S4
354      TTree *S = (TTree*)f->Get("S4");      TTree *S = (TTree*)f->Get("S4");
355      if(S) {      if(S && S4) {
356          S->SetBranchAddress("S4Level2", GetPointerToS4());          S->SetBranchAddress("S4Level2", GetPointerToS4());
357          cout << "S4           : set branch address S4Level2"<<endl;          cout << "S4           : set branch address S4Level2"<<endl;
358          if(!Tout)Tout=O;          if(!Tout)Tout=O;
# Line 266  TTree *PamLevel2::LoadPamTrees(TFile *f) Line 362  TTree *PamLevel2::LoadPamTrees(TFile *f)
362      };      };
363      // Neutron Detector      // Neutron Detector
364      TTree *N = (TTree*)f->Get("NeutronD");      TTree *N = (TTree*)f->Get("NeutronD");
365      if(N) {      if(N && ND) {
366          N->SetBranchAddress("NDLevel2", GetPointerToND());          N->SetBranchAddress("NDLevel2", GetPointerToND());
367          cout << "NeutronD     : set branch address NDLevel2"<<endl;          cout << "NeutronD     : set branch address NDLevel2"<<endl;
368          if(!Tout)Tout=O;          if(!Tout)Tout=O;
# Line 276  TTree *PamLevel2::LoadPamTrees(TFile *f) Line 372  TTree *PamLevel2::LoadPamTrees(TFile *f)
372      };      };
373      // Anticounters      // Anticounters
374      TTree *A = (TTree*)f->Get("Anticounter");      TTree *A = (TTree*)f->Get("Anticounter");
375      if(A) {      if(A && AC) {
376          A->SetBranchAddress("AcLevel2", GetPointerToAc());          A->SetBranchAddress("AcLevel2", GetPointerToAc());
377          cout << "Anticounter  : set branch address AcLevel2"<<endl;          cout << "Anticounter  : set branch address AcLevel2"<<endl;
378          if(!Tout)Tout=O;          if(!Tout)Tout=O;
# Line 284  TTree *PamLevel2::LoadPamTrees(TFile *f) Line 380  TTree *PamLevel2::LoadPamTrees(TFile *f)
380      }else{      }else{
381          cout << "Anticounter  : missing tree"<<endl;          cout << "Anticounter  : missing tree"<<endl;
382      };      };
383        // Orbital Info
384            TTree *B = (TTree*)f->Get("OrbitalInfo");
385            if(B && ORB) {
386                    B->SetBranchAddress("OrbitalInfo", GetPointerToOrb());
387                    cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
388                    if(!Tout)Tout=O;
389                    else Tout->AddFriend(B);
390            }else{
391                    cout << "OrbitalInfo  : missing tree"<<endl;
392            };
393            
394      return Tout;      return Tout;
395            
396  }  }
397    //--------------------------------------
398    //
399    //
400    //--------------------------------------
401    /**
402     * Get the Pamela detector trees in a single file and make them friends.
403     * @param f TFile pointer
404     * @return Pointer to a TTree
405     */
406    TTree *PamLevel2::LoadPamTrees(TFile *f){
407        
408            TTree *Tout =0;
409            
410            SetWhichTrees("+ALL");
411            
412        // Tracker
413            TTree *T = (TTree*)f->Get("Tracker");
414            if(T && TRK) {
415                    T->SetBranchAddress("TrkLevel2", GetPointerToTrk());
416                    cout << "Tracker      : set branch address TrkLevel2"<<endl;
417                    if(!Tout)Tout=T;
418            }else{
419                    cout << "Tracker      : missing tree"<<endl;
420            };
421        // Calorimeter
422            TTree *C = (TTree*)f->Get("Calorimeter");
423            if(C && CAL) {
424                    C->SetBranchAddress("CaloLevel2", GetPointerToCalo());
425                    cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
426                    if(!Tout)Tout=C;
427                    else Tout->AddFriend(C);
428            }else{
429                    cout << "Calorimeter  : missing tree"<<endl;
430            };
431        // ToF    
432            TTree *O = (TTree*)f->Get("ToF");
433            if(O && TOF) {
434                    O->SetBranchAddress("ToFLevel2", GetPointerToToF());
435                    cout << "ToF          : set branch address ToFLevel2"<<endl;
436                    if(!Tout)Tout=O;
437                    else Tout->AddFriend(O);
438            }else{
439                    cout << "ToF         : missing tree"<<endl;
440            };
441        // Trigger
442            TTree *R = (TTree*)f->Get("Trigger");
443            if(R && TRG) {
444                    R->SetBranchAddress("TrigLevel2", GetPointerToTrig());
445                    cout << "Trigger      : set branch address TrigLevel2"<<endl;
446                    if(!Tout)Tout=O;
447                    else Tout->AddFriend(R);
448            }else{
449                    cout << "Trigger      : missing tree"<<endl;
450            };
451        // S4
452            TTree *S = (TTree*)f->Get("S4");
453            if(S && S4) {
454                    S->SetBranchAddress("S4Level2", GetPointerToS4());
455                    cout << "S4           : set branch address S4Level2"<<endl;
456                    if(!Tout)Tout=O;
457                    else Tout->AddFriend(S);
458            }else{
459                    cout << "S4           : missing tree"<<endl;
460            };
461        // Neutron Detector
462            TTree *N = (TTree*)f->Get("NeutronD");
463            if(N && ND) {
464                    N->SetBranchAddress("NDLevel2", GetPointerToND());
465                    cout << "NeutronD     : set branch address NDLevel2"<<endl;
466                    if(!Tout)Tout=O;
467                    else Tout->AddFriend(N);
468            }else{
469                    cout << "NeutronD     : missing tree"<<endl;
470            };
471        // Anticounters
472            TTree *A = (TTree*)f->Get("Anticounter");
473            if(A && AC) {
474                    A->SetBranchAddress("AcLevel2", GetPointerToAc());
475                    cout << "Anticounter  : set branch address AcLevel2"<<endl;
476                    if(!Tout)Tout=O;
477                    else Tout->AddFriend(A);
478            }else{
479                    cout << "Anticounter  : missing tree"<<endl;
480            };
481        // Orbital Info
482            TTree *B = (TTree*)f->Get("OrbitalInfo");
483            if(B && ORB) {
484                    B->SetBranchAddress("OrbitalInfo", GetPointerToOrb());
485                    cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
486                    if(!Tout)Tout=O;
487                    else Tout->AddFriend(B);
488            }else{
489                    cout << "OrbitalInfo  : missing tree"<<endl;
490            };
491        
492            return Tout;
493        
494    }
495    //--------------------------------------
496    //
497    //
498    //--------------------------------------
499    /**
500     * Get list of Level2 files.
501     * @param ddir Level2 data directory.
502     * @param flisttxt Name of txt file containing file list.
503     * @return Pointer to a TList of TSystemFiles
504     * If no input file list is given , all the Level2 files inside the directory are processed.
505     */
506    TList*  PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){
507            
508            TString wdir = gSystem->WorkingDirectory();    
509            
510            if(ddir=="")ddir = wdir;
511            TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
512            cout << "Level2 data directory : "<< endl <<  ddir << endl;
513                    
514            TList *contents  = new TList; // create output list
515            contents->SetOwner();
516                    
517            // if no input file list is given:      
518            if ( flisttxt != "" ){
519                    
520                    if( !gSystem->ChangeDirectory(ddir) )return 0;
521            
522                    flisttxt = gSystem->ConcatFileName(wdir,gSystem->BaseName(flisttxt));
523                    
524                    cout <<"Input file list : "<< endl << flisttxt <<endl;
525                    ifstream in;
526                    in.open(flisttxt, ios::in);
527                    while (1) {
528                            TString file;
529                            in >> file;
530                            if (!in.good()) break;
531                            char *fullpath;
532                            if( gSystem->IsFileInIncludePath(file,&fullpath) ){
533    //                              contents->Add(new TSystemDirectory(fullpath,ddir)); // add file to the list
534    //                              contents->Add(new TSystemFile(fullpath,ddir)); // add file to the list
535                                    contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
536                            }else{
537                                    cout << "warning! --- File "<<file<<" does not exists"<< endl;
538                            };
539                    };
540                    in.close();
541                    
542            }else{
543            
544                    cout << "No input file list given."<<endl;
545                    cout << "Check for existing root files."<<endl;
546    //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
547                    
548                    TList *temp = datadir->GetListOfFiles();
549    //              temp->Print();
550    //              cout << "*************************************" << endl;
551                    
552                    TIter next(temp);
553                    TSystemFile *questo = 0;
554                    
555                    
556                    while ( (questo = (TSystemFile*) next()) ) {
557                            TString name =  questo-> GetName();
558                            if( name.EndsWith(".root") ){
559                                    char *fullpath;
560                                    gSystem->IsFileInIncludePath(name,&fullpath);
561                                    contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
562                            };
563                    }
564                    delete temp;
565            
566            };
567            gSystem->ChangeDirectory(wdir);
568            cout << endl << "Selected files:" << endl;
569            contents->Print();
570            cout << endl;
571    //      cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
572            return contents;
573    };
574    //--------------------------------------
575    //
576    //
577    //--------------------------------------
578    /**
579     * Get the Pamela detector chains from a list of files and make them friends.
580     * @param fl Pointer to a TList of TSystemFiles
581     * @param detlist String to select trees to be included
582     * @return Pointer to a TChain
583     */
584    TChain *PamLevel2::LoadPamTrees(TList *fl, TString detlist="+ALL"){
585    
586            TChain *Tout=0;
587            
588            SetWhichTrees(detlist);
589            
590            TChain *T = 0;  
591            TChain *C = 0;
592            TChain *O = 0;
593            TChain *R = 0;
594            TChain *S = 0;
595            TChain *N = 0;
596            TChain *A = 0;
597            TChain *B = 0;
598            
599            if(TRK) T = new TChain("Tracker");      
600            if(CAL) C = new TChain("Calorimeter");
601            if(TOF) O = new TChain("ToF");
602            if(TRG) R = new TChain("Trigger");
603            if(S4)  S = new TChain("S4");
604            if(ND)  N = new TChain("NeutronD");
605            if(AC)  A = new TChain("Anticounter");
606            if(ORB) B = new TChain("OrbitalInfo");
607            
608            // loop over files and create chains    
609            TIter next(fl);
610            TSystemFile *questo = 0;
611            while ( (questo = (TSystemFile*) next()) ) {
612                    TString name =  questo->GetName();
613    //              cout << "File: "<< name << endl;
614                    if( CheckLevel2File(name) ){
615                            if(TRK) T->Add(name);
616                            if(CAL) C->Add(name);
617                            if(TOF) O->Add(name);
618                            if(TRG) R->Add(name);
619                            if(S4)  S->Add(name);
620                            if(ND)  N->Add(name);
621                            if(AC)  A->Add(name);
622                            if(ORB) B->Add(name);
623                    };
624            }
625            
626        // Tracker
627            if(TRK) {
628                    T->SetBranchAddress("TrkLevel2", GetPointerToTrk());
629                    cout << "Tracker      : set branch address TrkLevel2"<<endl;
630                    if(!Tout)Tout=T;
631            };
632        
633            // Calorimeter
634            if(CAL) {
635                    C->SetBranchAddress("CaloLevel2", GetPointerToCalo());
636                    cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
637                    if(!Tout)Tout=C;
638                    else Tout->AddFriend("Calorimeter");
639            };
640            
641        // ToF    
642            if(TOF) {
643                    O->SetBranchAddress("ToFLevel2", GetPointerToToF());
644                    cout << "ToF          : set branch address ToFLevel2"<<endl;
645                    if(!Tout)Tout=O;
646                    else Tout->AddFriend("ToF");
647            };
648        // Trigger
649            if(TRG) {
650                    R->SetBranchAddress("TrigLevel2", GetPointerToTrig());
651                    cout << "Trigger      : set branch address TrigLevel2"<<endl;
652                    if(!Tout)Tout=O;
653                    else Tout->AddFriend("Trigger");
654            };
655        // S4
656            if(S4) {
657                    S->SetBranchAddress("S4Level2", GetPointerToS4());
658                    cout << "S4           : set branch address S4Level2"<<endl;
659                    if(!Tout)Tout=O;
660                    else Tout->AddFriend("S4");
661            };
662        // Neutron Detector
663            if(ND) {
664                    N->SetBranchAddress("NDLevel2", GetPointerToND());
665                    cout << "NeutronD     : set branch address NDLevel2"<<endl;
666                    if(!Tout)Tout=O;
667                    else Tout->AddFriend("NeutronD");
668            };
669        // Anticounters
670            if(AC) {
671                    A->SetBranchAddress("AcLevel2", GetPointerToAc());
672                    cout << "Anticounter  : set branch address AcLevel2"<<endl;
673                    if(!Tout)Tout=O;
674                    else Tout->AddFriend("Anticounter");
675            };
676        // OrbitalInfo
677            if(ORB) {
678                    B->SetBranchAddress("OrbitalInfo", GetPointerToOrb());
679                    cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
680                    if(!Tout)Tout=O;
681                    else Tout->AddFriend("OrbitalInfo");
682            };
683        
684            return Tout;
685        
686    }
687    //--------------------------------------
688    //
689    //
690    //--------------------------------------
691    /**
692     * Set which trees should be analysed
693     * @param detlist TString containing the sequence of trees required
694    */
695    void PamLevel2::SetWhichTrees(TString detlist){
696            
697            if(detlist.Contains("+ALL", TString::kIgnoreCase)){
698                    CAL = true;
699                    TRK = true;
700                    TRG = true;
701                    TOF = true;
702                    S4  = true;
703                    ND  = true;
704                    AC  = true;
705                    ORB = true;
706            }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
707                    CAL = false;
708                    TRK = false;
709                    TRG = false;
710                    TOF = false;
711                    S4  = false;
712                    ND  = false;
713                    AC  = false;
714                    ORB = false;
715            };
716            
717            if( detlist.Contains("-CAL", TString::kIgnoreCase) )CAL = false;
718            else if( detlist.Contains("+CAL", TString::kIgnoreCase) )CAL = true;
719            
720            if( detlist.Contains("-TRK", TString::kIgnoreCase) )TRK = false;
721            else if( detlist.Contains("+TRK", TString::kIgnoreCase) )TRK = true;
722            
723            if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
724            else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
725            
726            if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
727            else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
728            
729            if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
730            else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
731            
732            if( detlist.Contains("-ND",  TString::kIgnoreCase) )ND  = false;
733            else if( detlist.Contains("+ND",  TString::kIgnoreCase) )ND  = true;
734            
735            if( detlist.Contains("-AC",  TString::kIgnoreCase) )AC  = false;
736            else if( detlist.Contains("+AC",  TString::kIgnoreCase) )AC  = true;
737            
738            if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
739            else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
740            
741    };
742    //--------------------------------------
743    //
744    //
745    //--------------------------------------
746    /**
747     * Check if a file contains required trees.
748     * @param name File name
749     * @return Pointer to a TChain
750     */
751    Bool_t  PamLevel2::CheckLevel2File(TString name){
752            
753            Bool_t CAL__ok = false;
754            Bool_t TRK__ok = false;
755            Bool_t TRG__ok = false;
756            Bool_t TOF__ok = false;
757            Bool_t S4__ok  = false;
758            Bool_t ND__ok  = false;
759            Bool_t AC__ok  = false;
760            Bool_t ORB__ok = false;
761            
762            Bool_t RUN__ok = false;
763            
764            TFile *f = new TFile(name.Data());
765            TList *lk = f->GetListOfKeys();
766    //      lk->Print();
767            TIter next(lk);
768            TKey *key =0;
769            while( (key = (TKey*)next()) ){
770    //              cout << key->GetName() << endl;
771                    if( !strcmp(key->GetName(),"Calorimeter") )CAL__ok = true;
772                    if( !strcmp(key->GetName(),"Tracker"    ) )TRK__ok = true;
773                    if( !strcmp(key->GetName(),"Trigger"    ) )TRG__ok = true;
774                    if( !strcmp(key->GetName(),"ToF"        ) )TOF__ok = true;
775                    if( !strcmp(key->GetName(),"S4"         ) )S4__ok = true;
776                    if( !strcmp(key->GetName(),"NeutronD"   ) )ND__ok = true;
777                    if( !strcmp(key->GetName(),"Anticounter") )AC__ok = true;
778                    if( !strcmp(key->GetName(),"OrbitalInfo") )ORB__ok = true;
779                    if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;
780            };
781                    
782            lk->Delete();
783            f->Close();
784            
785            Bool_t FLAG = true;
786            if(!RUN__ok) {
787                    cout << "File: "<< f->GetName() <<" discarded ---- Missing RunInfo tree"<< endl;
788                    FLAG = false;
789            };
790            if(CAL && !CAL__ok){
791                    cout << "File: "<< f->GetName() <<" discarded ---- Missing Calorimeter tree"<< endl;
792                    FLAG = false;
793            };
794            if(TRK && !TRK__ok){
795                    cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker tree"<< endl;
796                    FLAG = false;
797            };
798            if(TRG && !TRG__ok){
799                    cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
800                    FLAG = false;
801            };
802            if(TOF && !TOF__ok){
803                    cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl;
804                    FLAG = false;
805            };
806            if(S4 && !S4__ok){
807                    cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl;
808                    FLAG = false;
809            };
810            if(ND && !ND__ok){
811                    cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
812                    FLAG = false;
813            };
814            if(AC && !AC__ok){
815                    cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl;
816                    FLAG = false;
817            };
818            if(ORB && !ORB__ok){
819                    cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl;
820                    FLAG = false;
821            };
822            
823            return FLAG;
824            
825    };
826    
827    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.23