/[PAMELA software]/DarthVader/CalorimeterLevel2/src/CaloLevel2.cpp
ViewVC logotype

Diff of /DarthVader/CalorimeterLevel2/src/CaloLevel2.cpp

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

revision 1.6 by mocchiut, Fri Aug 4 14:38:46 2006 UTC revision 1.18 by mocchiut, Thu Dec 4 13:50:43 2008 UTC
# Line 5  Line 5 
5  **/  **/
6  #include <TObject.h>  #include <TObject.h>
7  #include <CaloLevel2.h>  #include <CaloLevel2.h>
8    
9    //
10  ClassImp(CaloTrkVar);  ClassImp(CaloTrkVar);
11  ClassImp(CaloLevel2);  ClassImp(CaloLevel2);
12    
# Line 12  ClassImp(CaloLevel2); Line 14  ClassImp(CaloLevel2);
14   * CaloTrkVar constructor   * CaloTrkVar constructor
15  **/  **/
16  CaloTrkVar::CaloTrkVar() {  CaloTrkVar::CaloTrkVar() {
17      this->Clear();
18    }
19    
20    /**
21     * Clear variables
22    **/
23    void CaloTrkVar::Clear(Option_t *t) {
24      //void CaloTrkVar::Clear() {
25    trkseqno = 0;    trkseqno = 0;
26    noint = 0;    noint = 0;
27    ncore = 0;    ncore = 0;
# Line 77  CaloTrkVar::CaloTrkVar(const CaloTrkVar Line 87  CaloTrkVar::CaloTrkVar(const CaloTrkVar
87  **/  **/
88  CaloLevel2::CaloLevel2() {      CaloLevel2::CaloLevel2() {    
89    //    //
90    CaloTrk = new TClonesArray("CaloTrkVar",1);  //  CaloTrk = new TClonesArray("CaloTrkVar",1); //ELENA
91      CaloTrk = 0; //ELENA
92    //    //
93    nstrip = 0;    this->Clear();
94    qtot = 0.;    //
95    impx = 0.;  }
96    impy = 0.;  /**
97    tanx = 0.;   * Create the TClonesArray
98    tany = 0.;  **/
99    qmax = 0.;  void CaloLevel2::Set(){//ELENA
100    nx22 = 0;      if(!CaloTrk)CaloTrk = new TClonesArray("CaloTrkVar",1); //ELENA
101    qx22 = 0.;  }//ELENA
   elen = 0.;  
   selen = 0.;  
   memset(perr, 0, 4*sizeof(Int_t));  
   memset(swerr, 0, 4*sizeof(Int_t));  
   memset(crc, 0, 4*sizeof(Int_t));  
   memset(qq, 0, 4*sizeof(Int_t));  
   memset(varcfit, 0, 2*sizeof(Float_t));  
   memset(npcfit, 0, 2*sizeof(Int_t));  
   memset(planemax, 0, 2*sizeof(Int_t));  
   memset(cibar, 0, 2*22*sizeof(Int_t));  
   memset(cbar, 0, 2*22*sizeof(Float_t));  
   good = 0;  
   selftrigger = 0;  
   estrip = TArrayF(0,NULL);  
 };  
102    
103  void CaloLevel2::Clear() {      /**
104     * Clear the CaloLevel2 object
105     **/
106    void CaloLevel2::Clear(Option_t *t ) {    
107    //    //
108    CaloTrk->Clear();    //  CaloTrk->Clear(); //ELENA
109      if(CaloTrk)CaloTrk->Delete(); //ELENA
110    //    //
111    nstrip = 0;    nstrip = 0;
112      nsatstrip = 0;
113    qtot = 0.;    qtot = 0.;
114    impx = 0.;    //  impx = 0.;
115    impy = 0.;    //  impy = 0.;
   tanx = 0.;  
   tany = 0.;  
116    qmax = 0.;    qmax = 0.;
117    nx22 = 0;    nx22 = 0;
118    qx22 = 0.;    qx22 = 0.;
# Line 123  void CaloLevel2::Clear() {     Line 122  void CaloLevel2::Clear() {    
122    memset(swerr, 0, 4*sizeof(Int_t));    memset(swerr, 0, 4*sizeof(Int_t));
123    memset(crc, 0, 4*sizeof(Int_t));    memset(crc, 0, 4*sizeof(Int_t));
124    memset(qq, 0, 4*sizeof(Int_t));    memset(qq, 0, 4*sizeof(Int_t));
125    memset(varcfit, 0, 2*sizeof(Float_t));    memset(varcfit, 0, 4*sizeof(Float_t));
126    memset(npcfit, 0, 2*sizeof(Int_t));    memset(npcfit, 0, 4*sizeof(Int_t));
127      memset(tanx, 0, 2*sizeof(Int_t));
128      memset(tany, 0, 2*sizeof(Int_t));
129      memset(fitmode, 0, 2*sizeof(Int_t));
130    memset(planemax, 0, 2*sizeof(Int_t));    memset(planemax, 0, 2*sizeof(Int_t));
131      memset(selfdelay, 0, 4*7*sizeof(Int_t));
132    memset(cibar, 0, 2*22*sizeof(Int_t));    memset(cibar, 0, 2*22*sizeof(Int_t));
133    memset(cbar, 0, 2*22*sizeof(Float_t));    memset(cbar, 0, 2*22*sizeof(Float_t));
134    good = 0;    good = 0;
135    selftrigger = 0;    selftrigger = 0;
136    estrip.Reset();    //
137  };  }
138    
139    /**
140     * Delete the CaloLevel2 object
141     **/
142    void CaloLevel2::Delete(Option_t *t) {     //ELENA
143      if(CaloTrk){ //ELENA
144          CaloTrk->Delete(); //ELENA
145          delete CaloTrk; //ELENA
146      }     //ELENA
147    } //ELENA
148    
149    /**
150     * CaloLevel2
151    **/
152    Bool_t CaloLevel2::IsGood(Bool_t strict) {  
153      //
154      if ( strict ){
155        if ( !good ) return(false);
156        if ( !perr[0] ) return(false);
157        if ( !perr[1] ) return(false);
158        if ( !perr[2] ) return(false);
159        if ( !perr[3] ) return(false);
160        if ( !swerr[0] ) return(false);
161        if ( !swerr[1] ) return(false);
162        if ( !swerr[2] ) return(false);
163        if ( !swerr[3] ) return(false);
164        if ( !crc[0] ) return(false);
165        if ( !crc[1] ) return(false);
166        if ( !crc[2] ) return(false);
167        if ( !crc[3] ) return(false);
168      } else {
169        if ( perr[0] == 129 ||  perr[0] == 136 || perr[0] == 142 || perr[0] == 143 ) return(false);
170        if ( perr[1] == 129 ||  perr[1] == 136 || perr[1] == 142 || perr[1] == 143 ) return(false);
171        if ( perr[2] == 129 ||  perr[2] == 136 || perr[2] == 142 || perr[2] == 143 ) return(false);
172        if ( perr[3] == 129 ||  perr[3] == 136 || perr[3] == 142 || perr[3] == 143 ) return(false);
173      };
174      //
175      return(true);
176    }
177    
178  /**  /**
179   * Fills a struct cCaloLevel2 with values from a CaloLevel2 object (to put data into a F77 common).   * Fills a struct cCaloLevel2 with values from a CaloLevel2 object (to put data into a F77 common).
# Line 146  void CaloLevel2::GetLevel2Struct(cCaloLe Line 187  void CaloLevel2::GetLevel2Struct(cCaloLe
187    l2->qtot = qtot;        l2->qtot = qtot;    
188    l2->qx22 = qx22;        l2->qx22 = qx22;    
189    l2->qmax = qmax;        l2->qmax = qmax;    
190    l2->impx = impx;        //  l2->impx = impx;    
191    l2->impy = impy;        //  l2->impy = impy;    
192    l2->tanx = tanx;        //  l2->tanx = tanx;    
193    l2->tany = tany;      //  l2->tany = tany;  
194    l2->elen = elen;          l2->elen = elen;      
195    l2->selen = selen;    l2->selen = selen;
196                    
# Line 165  void CaloLevel2::GetLevel2Struct(cCaloLe Line 206  void CaloLevel2::GetLevel2Struct(cCaloLe
206      l2->qq[i] = qq[i];        l2->qq[i] = qq[i];  
207    }    }
208    
209    l2->calntrk = CaloTrk->GetEntries();    if(CaloTrk){ //ELENA
210            l2->calntrk = CaloTrk->GetEntries();  
211    for(Int_t i=0;i<l2->calntrk;i++){        for(Int_t i=0;i<l2->calntrk;i++){
212      l2->caltrkseqno[i] = ((CaloTrkVar *)CaloTrk->At(i))->trkseqno;              l2->caltrkseqno[i] = ((CaloTrkVar *)CaloTrk->At(i))->trkseqno;  
213      l2->ncore[i] = ((CaloTrkVar *)CaloTrk->At(i))->ncore;                l2->ncore[i] = ((CaloTrkVar *)CaloTrk->At(i))->ncore;    
214      l2->noint[i] = ((CaloTrkVar *)CaloTrk->At(i))->noint;                l2->noint[i] = ((CaloTrkVar *)CaloTrk->At(i))->noint;    
215      l2->ncyl[i] = ((CaloTrkVar *)CaloTrk->At(i))->ncyl;                  l2->ncyl[i] = ((CaloTrkVar *)CaloTrk->At(i))->ncyl;      
216      l2->nlast[i] = ((CaloTrkVar *)CaloTrk->At(i))->nlast;                l2->nlast[i] = ((CaloTrkVar *)CaloTrk->At(i))->nlast;    
217      l2->npre[i] = ((CaloTrkVar *)CaloTrk->At(i))->npre;                  l2->npre[i] = ((CaloTrkVar *)CaloTrk->At(i))->npre;      
218      l2->npresh[i] = ((CaloTrkVar *)CaloTrk->At(i))->npresh;                l2->npresh[i] = ((CaloTrkVar *)CaloTrk->At(i))->npresh;    
219      l2->ntr[i] = ((CaloTrkVar *)CaloTrk->At(i))->ntr;                  l2->ntr[i] = ((CaloTrkVar *)CaloTrk->At(i))->ntr;      
220      l2->planetot[i] = ((CaloTrkVar *)CaloTrk->At(i))->planetot;              l2->planetot[i] = ((CaloTrkVar *)CaloTrk->At(i))->planetot;  
221      l2->nlow[i] = ((CaloTrkVar *)CaloTrk->At(i))->nlow;                  l2->nlow[i] = ((CaloTrkVar *)CaloTrk->At(i))->nlow;      
222      l2->qcore[i] =((CaloTrkVar *)CaloTrk->At(i))->qcore ;              l2->qcore[i] =((CaloTrkVar *)CaloTrk->At(i))->qcore ;  
223      l2->qcyl[i] = ((CaloTrkVar *)CaloTrk->At(i))->qcyl;                l2->qcyl[i] = ((CaloTrkVar *)CaloTrk->At(i))->qcyl;    
224      l2->qlast[i] = ((CaloTrkVar *)CaloTrk->At(i))->qlast;              l2->qlast[i] = ((CaloTrkVar *)CaloTrk->At(i))->qlast;  
225      l2->qpre[i] = ((CaloTrkVar *)CaloTrk->At(i))->qpre;                l2->qpre[i] = ((CaloTrkVar *)CaloTrk->At(i))->qpre;    
226      l2->qpresh[i] = ((CaloTrkVar *)CaloTrk->At(i))->qpresh;              l2->qpresh[i] = ((CaloTrkVar *)CaloTrk->At(i))->qpresh;  
227      l2->qtr[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtr;                l2->qtr[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtr;    
228      l2->qtrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtrack;              l2->qtrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtrack;  
229      l2->qtrackx[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtrackx;            l2->qtrackx[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtrackx;
230      l2->qtracky[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtracky;            l2->qtracky[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtracky;
231      l2->dxtrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->dxtrack;            l2->dxtrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->dxtrack;
232      l2->dytrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->dytrack;            l2->dytrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->dytrack;
233      l2->qmean[i] = ((CaloTrkVar *)CaloTrk->At(i))->qmean;              l2->qmean[i] = ((CaloTrkVar *)CaloTrk->At(i))->qmean;  
234      l2->qlow[i] = ((CaloTrkVar *)CaloTrk->At(i))->qlow;                l2->qlow[i] = ((CaloTrkVar *)CaloTrk->At(i))->qlow;    
235      l2->dX0l[i] = ((CaloTrkVar *)CaloTrk->At(i))->dX0l;              l2->dX0l[i] = ((CaloTrkVar *)CaloTrk->At(i))->dX0l;  
236      for (Int_t j=0; j<2; j++){            for (Int_t j=0; j<2; j++){
237        for (Int_t k=0; k<22; k++){                for (Int_t k=0; k<22; k++){
238          l2->tbar[i][k][j] = ((CaloTrkVar *)CaloTrk->At(i))->tbar[k][j];                    l2->tbar[i][k][j] = ((CaloTrkVar *)CaloTrk->At(i))->tbar[k][j];
239        };                };
240      };            };
241    }          }  
242      } //ELENA
243  }  }
244    
245  /**  /**
246   * Gives the detected energy for the given strip once loaded the event   * Returns the impact position on the top of the calorimeter as determined by the calorimeter itself.
247     * @param tr : if tr = 0 use the calorimeter "normal" fit, if 1 use the calorimeter "selftrigger" fit (if any!)
248  **/  **/
249  Float_t CaloLevel2::GetEstrip(Int_t view, Int_t plane, Int_t strip){  Float_t CaloLevel2::impx(Int_t tr){
250    Int_t splane = 0;    if ( tr == 0 ) return(cbar[0][0]);
251    Int_t sstrip = 0;    if ( tr == 1 ) {
252    //      if ( !CaloTrk ) return(-110.);
253    if ( nstrip == 0 ) return(0.);      TClonesArray &t = *(CaloTrk);
254    //      for (Int_t itrk=0; itrk<ntrk(); itrk++){
255    for (Int_t i = 0; i<nstrip; i++ ){        CaloTrkVar *calotrack = (CaloTrkVar*)t[itrk];
256      if ( view == 0 ){        if ( calotrack->trkseqno == -1 ) return(calotrack->tbar[0][0]);
       if ( estrip.At(i) > 0. ){  
         splane = (Int_t)trunc(estrip.At(i)/1000000.);  
         sstrip = (Int_t)trunc((estrip.At(i)-((Float_t)splane*1000000.))/10000.);  
         if ( splane == plane && sstrip == strip ) return(estrip.At(i)-(Float_t)splane*1000000.-(Float_t)sstrip*10000.);  
       };          
     } else {  
       if ( estrip.At(i) < 0. ){  
         splane = (Int_t)trunc(-estrip.At(i)/1000000.);  
         sstrip = (Int_t)trunc((-estrip.At(i)-((Float_t)splane*1000000.))/10000.);  
         if ( splane == plane && sstrip == strip ) return(-estrip.At(i)-(Float_t)splane*1000000.-(Float_t)sstrip*10000.);          
       };          
257      };      };
258    };    };
259    return(0.);    if ( tr !=0 && tr !=1 ){
260  };      printf(" Cannot get impx for other than calo or selftrigger tracks!\n");
261      } else {
262        printf(" Cannot find selftrigger block\n");
263      };
264      return(-100.);
265    }
266    
267  /**  /**
268   * Given estrip entry returns energy and strip   * Returns the impact position on the top of the calorimeter as determined by the calorimeter itself.
269     * @param tr : if tr = 0 use the calorimeter "normal" fit, if 1 use the calorimeter "selftrigger" fit (if any!)
270  **/  **/
271  Float_t CaloLevel2::DecodeEstrip(Int_t entry, Int_t &view, Int_t &plane, Int_t &strip){  Float_t CaloLevel2::impy(Int_t tr){
272    if ( entry>nstrip ) return(0.);    if ( tr == 0 ) return(cbar[0][1]);
273    //    if ( tr == 1 ) {
274    if ( estrip.At(entry) > 0. ){      if ( !CaloTrk ) return(-110.);
275      view = 0;      TClonesArray &t = *(CaloTrk);
276      plane = (Int_t)trunc(estrip.At(entry)/1000000.);      for (Int_t itrk=0; itrk<ntrk(); itrk++){
277      strip = (Int_t)trunc((estrip.At(entry)-((Float_t)plane*1000000.))/10000.);        CaloTrkVar *calotrack = (CaloTrkVar*)t[itrk];
278      return(estrip.At(entry)-(Float_t)plane*1000000.-(Float_t)strip*10000.);        if ( calotrack->trkseqno == -1 ) return(calotrack->tbar[0][1]);
279        };
280    };    };
281    if ( estrip.At(entry) < 0. ){    if ( tr !=0 && tr !=1 ){
282      view = 1;      printf(" Cannot get impy for other than calo or selftrigger tracks!\n");
283      plane = (Int_t)trunc(-estrip.At(entry)/1000000.);    } else {
284      strip = (Int_t)trunc((-estrip.At(entry)-((Float_t)plane*1000000.))/10000.);      printf(" Cannot find selftrigger block\n");
285      return(-estrip.At(entry)-(Float_t)plane*1000000.-(Float_t)strip*10000.);        };
286    };        return(-100.);
   //  
   printf(" WARNING: problems decoding value %f at entry %i \n",estrip.At(entry),entry);  
   //  
   view = -1;  
   plane = -1;  
   strip = -1;  
   return(0.);    
287  }  }
288    /**
289     * Should return the energy in GeV if the particle would be an electron
290     * using a parametrization taken from Monte Carlo simulation
291    **/
292  void CaloLevel2::GetElectronEnergy(Float_t &energy, Float_t &sigma){  void CaloLevel2::GetElectronEnergy(Float_t &energy, Float_t &sigma){
293    if ( nstrip == 0 ) return;    if ( nstrip == 0 ) return;
294    energy = qtot * 40.82 * 0.000106;    energy = qtot / 260.;
295      //  energy = qtot * 40.82 * 0.000106;
296    sigma = 0.;    sigma = 0.;
297    if ( energy > 0. ) sigma = energy * (0.01183 + 0.121/sqrt(energy));    if ( energy > 0. ) sigma = energy * (0.01183 + 0.121/sqrt(energy));
298    return;    return;
299  };  }
300    
301  /**  /**
302   * Returns pointer to the set of track-related variables "itrk"   * Returns pointer to the set of track-related variables "itrk"
# Line 273  CaloTrkVar *CaloLevel2::GetCaloTrkVar(In Line 308  CaloTrkVar *CaloLevel2::GetCaloTrkVar(In
308      printf("                   stored track related variables = %i \n",ntrk());      printf("                   stored track related variables = %i \n",ntrk());
309      return(NULL);      return(NULL);
310    }    }
311      if(!CaloTrk)return 0; //ELENA
312    TClonesArray &t = *(CaloTrk);    TClonesArray &t = *(CaloTrk);
313    CaloTrkVar *calotrack = (CaloTrkVar*)t[itrk];    CaloTrkVar *calotrack = (CaloTrkVar*)t[itrk];
314    return calotrack;    return calotrack;
315  }  }
316    
317    /**
318     * Retrieves the calorimeter track matching the seqno-th tracker stored track.
319     * (If seqno = -1 retrieves the self-trigger calorimeter track)
320     */
321    CaloTrkVar *CaloLevel2::GetCaloStoredTrack(int seqno){
322    
323      if( ntrk()==0 ){
324        printf("CaloLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo %i but no Calorimeter tracks are stored\n",seqno);
325        return NULL;
326      };
327      
328      CaloTrkVar *c = 0;
329      Int_t it_calo=0;
330        
331      do {
332        c = GetCaloTrkVar(it_calo);
333        it_calo++;
334      } while( c && seqno != c->trkseqno && it_calo < ntrk());      
335      
336      if(!c || seqno != c->trkseqno){
337        c = 0;
338        if(seqno!=-1 && seqno !=-2 && seqno!=-3 ) printf("CaloLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo %i does not match Calorimeter stored tracks\n",seqno);
339      };
340      return c;
341        
342    }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.23