/[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.2 by pam-fi, Fri Aug 4 13:31:35 2006 UTC revision 1.3 by pam-fi, Mon Aug 7 08:24:49 2006 UTC
# Line 24  PamTrack::PamTrack(TrkTrack* t, CaloTrkV Line 24  PamTrack::PamTrack(TrkTrack* t, CaloTrkV
24      tof_track  = this->ToFTrkVar::GetToFTrkVar();      tof_track  = this->ToFTrkVar::GetToFTrkVar();
25      if(t) *trk_track  = *t;      if(t) *trk_track  = *t;
26      if(c) *calo_track = *c;      if(c) *calo_track = *c;
27      if(o) *tof_track  = *o;      if(o) *tof_track  = *o;    
28  };  };
29    
30  //--------------------------------------  //--------------------------------------
# Line 62  PamLevel2::PamLevel2(){ Line 62  PamLevel2::PamLevel2(){
62   */   */
63  PamLevel2::~PamLevel2(){  PamLevel2::~PamLevel2(){
64                                    
65            TrkLevel2::Clear();
66            CaloLevel2::Clear();
67            ToFLevel2::Clear();
68            TrigLevel2::Clear();
69            S4Level2::Clear();
70            NDLevel2::Clear();
71            AcLevel2::Clear();
72            OrbitalInfo::Clear();
73            
74          delete sorted_tracks;          delete sorted_tracks;
75                    
76  };  };
# Line 69  PamLevel2::~PamLevel2(){ Line 78  PamLevel2::~PamLevel2(){
78   * Clear the event   * Clear the event
79   */   */
80  void PamLevel2::Clear(){  void PamLevel2::Clear(){
81                            
82            
83          sorted_tracks->Delete();          sorted_tracks->Delete();
84                    
85  };  };
# Line 80  void PamLevel2::Clear(){ Line 90  void PamLevel2::Clear(){
90  //  //
91  //--------------------------------------  //--------------------------------------
92  /**  /**
93     * Retrieves the calorimeter track matching the seqno-th tracker stored track.
94     * (If seqno = -1 retrieves the self-trigger calorimeter track)
95     */
96     CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
97            
98             CaloTrkVar *c = 0;
99             Int_t it_calo=0;
100            
101             do{
102                     c = CaloLevel2::GetCaloTrkVar(it_calo);
103                     it_calo++;
104             } while( seqno != c->trkseqno && it_calo < CaloLevel2::ntrk());        
105            
106             if(seqno != c->trkseqno){
107                     c = 0;
108                     if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
109             };
110             return c;
111    
112     };
113    //--------------------------------------
114     //
115     //
116    //--------------------------------------
117    /**
118      * Retrieves the ToF track matching the seqno-th tracker stored track.
119      * (If seqno = -1 retrieves the tracker-independent tof track)
120     */
121     ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
122            
123             ToFTrkVar *c = 0;
124             Int_t it_tof=0;
125            
126             do{
127                     c = ToFLevel2::GetToFTrkVar(it_tof);
128                     it_tof++;
129             } while( seqno != c->trkseqno && it_tof < ToFLevel2::ntrk());  
130            
131             if(seqno != c->trkseqno){
132                     c = 0;
133                     if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
134             };
135             return c;
136    
137     };
138    
139    //--------------------------------------
140     //
141     //
142    //--------------------------------------
143    /**
144     * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.
145     */
146     PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
147            
148             CaloTrkVar *c = 0;
149             ToFTrkVar  *o = 0;
150            
151             c = GetCaloStoredTrack(t->GetSeqNo());
152             o = GetToFStoredTrack(t->GetSeqNo());
153            
154    //    if(t && c && o)track = new PamTrack(t,c,o);
155             PamTrack *track = new PamTrack(t,c,o);
156            
157             return track;
158    
159     };
160    //--------------------------------------
161    //
162    //
163    //--------------------------------------
164    /**
165   * Retrieves the it-th stored track.   * Retrieves the it-th stored track.
166   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
167   * @param itrk Track number, ranging from 0 to GetNTracks().   * @param itrk Track number, ranging from 0 to GetNTracks().
# Line 87  void PamLevel2::Clear(){ Line 169  void PamLevel2::Clear(){
169    
170  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
171            
172      TrkTrack   *t = 0;          PamTrack *track = 0;
173      CaloTrkVar *c = 0;  
174      ToFTrkVar  *o = 0;          if( itrk >=0 && itrk < TrkLevel2::ntrk() ){
175                    
176      if( itrk >=0 && itrk < TrkLevel2::ntrk() ){                  TrkTrack *t = TrkLevel2::GetStoredTrack(itrk);
177                  t = TrkLevel2::GetStoredTrack(itrk);                  track = GetPamTrackAlong(t);
178  /*              c = CaloLevel2::GetCaloTrkVar(t->GetSeqNo());          
                 o = ToFLevel2::GetToFTrkVar(t->GetSeqNo()); */  
                 Int_t it_calo=0;  
                 do{  
                         c = CaloLevel2::GetCaloTrkVar(it_calo);  
                         it_calo++;  
                 } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk());    
                 if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetStoredTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<<endl;  
                   
                 Int_t it_tof=0;  
                 do{  
                         o = ToFLevel2::GetToFTrkVar(it_tof);  
                         it_tof++;  
                 } while(t->GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk());      
                 if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetStoredTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <<endl;  
                   
179          }else{          }else{
180                  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() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
181          };          };
182    
183      // hence create a "PamTrack" object          return track;
     PamTrack *track = 0;  
     if(t && c && o)track = new PamTrack(t,c,o);  
     return track;  
184                    
185  }  }
186  //--------------------------------------  //--------------------------------------
# Line 124  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 188  PamTrack* PamLevel2::GetStoredTrack(Int_
188  //  //
189  //--------------------------------------  //--------------------------------------
190  /**  /**
191   * Sort physical (tracker) tracks and stores them in a TObjectArray (of TrkTrack objects).   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks.
192   * 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).   * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
193     * Sorting cryteria:
194     * TRK: lower chi**2
195     * CAL: lower Y spatial residual on the first calorimeter plane
196     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
197     * The default sorting cryterium is "TOF+CAL".
198     *
199     * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).
200   */   */
201  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks(TString how){
202    
203          sorted_tracks->Delete(); //temporaneo          sorted_tracks->Delete(); //temporaneo
204      // loop over the tracks sorted by the tracker      // loop over the tracks sorted by the tracker
205            Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
206            Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
207            Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
208            
209            
210          for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){          for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){
211    
212                  TrkTrack *ts = 0;                  TrkTrack *ts = 0;
213    
214          // get tracker tracks          // get tracker tracks
215                  TrkTrack   *tp = TrkLevel2::GetTrack(i);                    //tracker                  TrkTrack   *tp = TrkLevel2::GetTrack(i);                    //tracker
216                  CaloTrkVar *cp = CaloLevel2::GetCaloTrkVar(tp->GetSeqNo()); //calorimeter                  CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
217                  ToFTrkVar  *op = ToFLevel2::GetToFTrkVar(tp->GetSeqNo());   //tof                  ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
218    
219          // if track has an image, check image selection          // if track has an image, check image selection
220                  if(tp->HasImage()){                  if(tp->HasImage()){
221                            
222                          TrkTrack   *ti = TrkLevel2::GetTrackImage(i);              //tracker (image)                          TrkTrack   *ti = TrkLevel2::GetTrackImage(i);              //tracker (image)
223                          CaloTrkVar *ci = CaloLevel2::GetCaloTrkVar(ti->GetSeqNo());//calorimeter (image)                          CaloTrkVar *ci = GetCaloStoredTrack(ti->GetSeqNo());
224                          ToFTrkVar  *oi = ToFLevel2::GetToFTrkVar(ti->GetSeqNo());  //tof (image)                          ToFTrkVar  *oi = GetToFStoredTrack(ti->GetSeqNo());
225    
226              //assign starting scores              //assign starting scores
227                          Int_t tp_score = 1;  //"principal" track, sorted by the tracker                          Int_t tp_score = 0;  //main track sorted by the tracker
228                          Int_t ti_score = 0;  //image track                          Int_t ti_score = 0;  //image track
229                                                    
230              // ------------------------              // ------------------------
231              // calorimeter check              // calorimeter check
232              // ------------------------              // ------------------------
233                    // check the Y spatial residual on the first calorimeter plane
234                    // (cut on calorimeter variables from Emiliano)
235                          if(                          if(
236                                                  npcfit[1] > 3   &&  //no. of fit planes on Y view                                  use_CAL            &&
237  //              varcfit[1] < 50.&&  //fit variance on Y view                                  npcfit[1] > 15     &&   //no. of fit planes on Y view
238                                                  true){                                  varcfit[1] < 1000. &&  //fit variance on Y view
239                                    true){
240    
241                                  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;
242                                  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;
243    
244                                  if(resy_p <= resy_i) tp_score++;                                  if(resy_p <= resy_i) tp_score++;
245                                  else                 ti_score++;                                  else                 ti_score++;
# Line 166  void PamLevel2::SortTracks(){ Line 247  void PamLevel2::SortTracks(){
247              // ------------------------              // ------------------------
248              // TOF check              // TOF check
249              // ------------------------                  // ------------------------    
250                    // check the number of hit pmts along the track
251                    // on S12 S21 and S32, where paddles are parallel to Y axis
252                            Int_t nphit_p =0;
253                            Int_t nphit_i =0;
254                                    
255                            for (Int_t ih=0; ih < op->npmtadc; ih++){
256                                    Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) );
257                                    if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
258                            };
259                                                    
260                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
261                                    Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) );
262                                    if(pl == 1 || pl == 2 || pl == 5)nphit_i++;    
263                            };
264                            
265                            if(
266                                    use_TOF            &&
267                                    (nphit_p+nphit_i) !=0 &&        
268                                    true){
269    
270                                    if( nphit_p >= nphit_i) tp_score++;
271                                    else                                              ti_score++;
272                            };
273                
274                            if(tp_score == ti_score) use_TRK = true;
275                    // ------------------------
276                // tracker check
277                // ------------------------
278                    // chi**2 difference is not always large enough to distinguish among
279                    // the real track and its image.
280                    // Tracker check will be applied always when calorimeter and tof information is ambiguous.
281                            if(use_TRK){
282                                    if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
283                                    else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
284                            };
285    
286              // ------------------------              // ------------------------
287              // the winner is....              // the winner is....
288              // ------------------------                  // ------------------------    
289                          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!!
290                          else                    ts = ti;//its image!!                          else if (tp_score < ti_score) ts = ti;//its image!!
291                            else {
292                                    ts = tp;
293    //                              cout << "Warning - track image ambiguity not solved" << endl;
294    //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;
295                            };
296    
297                  }else{                  }else{
298                          ts = tp;                          ts = tp;
# Line 191  void PamLevel2::SortTracks(){ Line 312  void PamLevel2::SortTracks(){
312   * 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.
313   */   */
314   TRefArray *PamLevel2::GetTracks(){   TRefArray *PamLevel2::GetTracks(){
315  //      if(!sorted_tracks->GetEntries()) SortTracks();          SortTracks("+CAL+TOF");
         SortTracks();  
316          return sorted_tracks;          return sorted_tracks;
317   };   };
318  //--------------------------------------  //--------------------------------------
319  //   //
320  //   //
321  //--------------------------------------  //--------------------------------------
322  /**  /**
323   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
# Line 205  void PamLevel2::SortTracks(){ Line 325  void PamLevel2::SortTracks(){
325   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
326   */   */
327  PamTrack *PamLevel2::GetTrack(int it){  PamTrack *PamLevel2::GetTrack(int it){
   
         SortTracks();  
328                    
329          TrkTrack   *t = 0;  //  *-*-*-*-*-*-*
330          CaloTrkVar *c = 0;          SortTracks("+CAL+TOF");
331          ToFTrkVar  *o = 0;  //  *-*-*-*-*-*-*
332    
333            PamTrack *track = 0;
334            
335          if( it >=0 && it < TrkLevel2::GetNTracks() ){          if( it >=0 && it < TrkLevel2::GetNTracks() ){
336                                    TrkTrack   *t = (TrkTrack*)sorted_tracks->At(it);
337                  t = (TrkTrack*)sorted_tracks->At(it);                  track = GetPamTrackAlong(t);
                   
                 Int_t it_calo=0;  
                 do{  
                         c = CaloLevel2::GetCaloTrkVar(it_calo);  
                         it_calo++;  
                 } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk());    
                 if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<<endl;  
                   
                 Int_t it_tof=0;  
                 do{  
                         o = ToFLevel2::GetToFTrkVar(it_tof);  
                         it_tof++;  
                 } while(t->GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk());      
                 if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <<endl;  
                   
338          }else{          }else{
339                  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() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
340          };          };
       
     // hence create a "PamTrack" object  
         PamTrack *track = 0;  
         if(t && c && o)track = new PamTrack(t,c,o);  
341                    
342          return track;          return track;
343    
344  };  };
345    
346  //--------------------------------------  //--------------------------------------
347  //  //
348  //  //
349  //--------------------------------------  //--------------------------------------
350  /**  /**
351   * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::GetTracks().   * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
352   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
353   */   */
354  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
355    
356  //      if(!sorted_tracks->GetEntries()) SortTracks();          SortTracks("+CAL+TOF");
         SortTracks();  
357                    
358      TrkTrack   *t = 0;          PamTrack *image = 0;
     CaloTrkVar *c = 0;  
     ToFTrkVar  *o = 0;  
359    
360      if( it >=0 && it < TrkLevel2::GetNTracks() ){          if( it >=0 && it < TrkLevel2::GetNTracks() ){
361                  TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);                  TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);
362                  if( temp->HasImage() ){                  if( temp->HasImage() ){
363                                                    TrkTrack   *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
364                          t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());                          image = GetPamTrackAlong(t);
   
 /*                      c = CaloLevel2::GetCaloTrkVar(temp->GetImageSeqNo());  
                         o = ToFLevel2::GetToFTrkVar(temp->GetImageSeqNo());*/  
                   
                         Int_t it_calo=0;  
                         do{  
                                 c = CaloLevel2::GetCaloTrkVar(it_calo);  
                                 it_calo++;  
                         } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk());    
                         if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetTrackImage(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<<endl;  
                   
                         Int_t it_tof=0;  
                         do{  
                                 o = ToFLevel2::GetToFTrkVar(it_tof);  
                                 it_tof++;  
                         } while(t->GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk());      
                         if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetTrackImage(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <<endl;  
365                  }else{                  }else{
366                          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;                          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
367                  };                  };
# Line 287  PamTrack *PamLevel2::GetTrackImage(int i Line 369  PamTrack *PamLevel2::GetTrackImage(int i
369                  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() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
370          };          };
371            
     // hence create a "PamTrack" object  
     PamTrack *image = 0;  
     if(t && c && o)image = new PamTrack(t,c,o);  
       
372          return image;          return image;
       
373  }  }
374    
375  //--------------------------------------  //--------------------------------------
# Line 399  TTree *PamLevel2::LoadPamTrees(TFile *f, Line 476  TTree *PamLevel2::LoadPamTrees(TFile *f,
476  //  //
477  //--------------------------------------  //--------------------------------------
478  /**  /**
479   * Get the Pamela detector trees in a single file and make them friends.   * Get all the Pamela detector trees in a single file and make them friends.
480   * @param f TFile pointer   * @param f TFile pointer
481   * @return Pointer to a TTree   * @return Pointer to a TTree
482   */   */
# Line 744  void PamLevel2::SetWhichTrees(TString de Line 821  void PamLevel2::SetWhichTrees(TString de
821  //  //
822  //--------------------------------------  //--------------------------------------
823  /**  /**
824   * Check if a file contains required trees.   * Check if a file contains selected Pamela Level2 trees.
825   * @param name File name   * @param name File name
826   * @return Pointer to a TChain   * @return Pointer to a TChain
827   */   */

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

  ViewVC Help
Powered by ViewVC 1.1.23