/[PAMELA software]/DarthVader/ToFLevel2/src/ToFLevel2.cpp
ViewVC logotype

Diff of /DarthVader/ToFLevel2/src/ToFLevel2.cpp

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

revision 1.36 by mocchiut, Thu Apr 12 12:27:10 2012 UTC revision 1.42 by pam-fi, Fri Oct 17 07:54:17 2014 UTC
# Line 113  void ToFLevel2::Set(){//ELENA Line 113  void ToFLevel2::Set(){//ELENA
113      if(!PMT)PMT = new TClonesArray("ToFPMT",12); //ELENA      if(!PMT)PMT = new TClonesArray("ToFPMT",12); //ELENA
114      if(!ToFTrk)ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA      if(!ToFTrk)ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
115  }//ELENA  }//ELENA
116    //--------------------------------------
117    //
118    //
119    //--------------------------------------
120    void ToFLevel2::SetTrackArray(TClonesArray *track){//ELENA
121        if(track && strcmp(track->GetClass()->GetName(),"ToFTrkVar")==0){
122            if(ToFTrk)ToFTrk->Clear("C");
123            ToFTrk = track;
124        }
125    }
126    
127  void ToFLevel2::Clear(Option_t *t){  void ToFLevel2::Clear(Option_t *t){
128    //    //
# Line 151  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t Line 161  ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t
161    return toftrack;    return toftrack;
162  }  }
163    
164    /**
165     * Retrieves the tof track matching the seqno-th tracker stored track.
166     *
167     */
168    ToFTrkVar *ToFLevel2::GetToFStoredTrack(int seqno){
169    
170      if( ntrk()==0 ){
171        printf("ToFLevel2::GetToFStoredTrack(int) : requested tracker SeqNo %i but no ToFrimeter tracks are stored\n",seqno);
172        return NULL;
173      };
174      
175      ToFTrkVar *c = 0;
176      Int_t it_tof=0;
177        
178      do {
179        c = GetToFTrkVar(it_tof);
180        it_tof++;
181      } while( c && seqno != c->trkseqno && it_tof < ntrk());      
182      
183      if(!c || seqno != c->trkseqno){
184        c = 0;
185        if(seqno!=-1 ) printf("ToFLevel2::GetToFStoredTrack(int) : requested tracker SeqNo %i does not match ToFrimeter stored tracks\n",seqno);
186      };
187      return c;
188        
189    }
190    
191    
192  ToFPMT *ToFLevel2::GetToFPMT(Int_t ihit){  ToFPMT *ToFLevel2::GetToFPMT(Int_t ihit){
193    //        //    
194    if(ihit >= npmt()){    if(ihit >= npmt()){
# Line 259  Int_t ToFLevel2::GetTrueNHitPaddles(Int_ Line 297  Int_t ToFLevel2::GetTrueNHitPaddles(Int_
297   * @param plane Plane index (0,1,2,3,4,5)   * @param plane Plane index (0,1,2,3,4,5)
298   * @param adcflag in the plane (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )   * @param adcflag in the plane (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
299   */   */
300    Float_t ToFLevel2::GetdEdx(ToFTrkVar *trk, Int_t plane, Int_t adcfl){
301      //  printf("fiffi\n");
302      Float_t dedx = 0.;
303      Float_t PadEdx =0.;
304      Int_t SatWarning;
305      Int_t pad=-1;
306      //
307      if(!trk) return 0; //ELENA
308      //
309      if ( trk->trkseqno == -1 ){ //standalone, only paddles along the track, or about...
310        //    printf("ciccio\n");
311        Float_t xleft=0;
312        Float_t xright=0;
313        Float_t yleft=0;
314        Float_t yright=0;
315        Float_t xtof_temp[6]={100.,100.,100.,100.,100.,100.};
316        Float_t ytof_temp[6]={100.,100.,100.,100.,100.,100.};
317        ToFTrkVar *t_tof = trk;
318        
319        xtof_temp[0]=t_tof->xtofpos[0];
320        ytof_temp[0]=t_tof->ytofpos[0];
321        xtof_temp[1]=t_tof->xtofpos[0];
322        ytof_temp[1]=t_tof->ytofpos[0];
323    
324        xtof_temp[2]=t_tof->xtofpos[1];
325        ytof_temp[2]=t_tof->ytofpos[1];
326        xtof_temp[3]=t_tof->xtofpos[1];
327        ytof_temp[3]=t_tof->ytofpos[1];
328    
329        xtof_temp[4]=t_tof->xtofpos[2];
330        ytof_temp[4]=t_tof->ytofpos[2];
331        xtof_temp[5]=t_tof->xtofpos[2];
332        ytof_temp[5]=t_tof->ytofpos[2];
333    
334        if(t_tof->xtofpos[0]<100. && t_tof->ytofpos[0]<100.){
335          xtof_temp[1]=t_tof->xtofpos[0];
336          ytof_temp[0]=t_tof->ytofpos[0];
337        }else if(t_tof->xtofpos[0]>=100. && t_tof->ytofpos[0]<100.){
338          ytof_temp[0]=t_tof->ytofpos[0];
339          this->GetPaddleGeometry(0,(Int_t)log2(this->tof_j_flag[0]),xleft, xright, yleft, yright);
340          xtof_temp[1]=xleft+2.55;
341        }else if(t_tof->ytofpos[0]>=100. && t_tof->xtofpos[0]<100.){
342          xtof_temp[1]=t_tof->xtofpos[0];
343          this->GetPaddleGeometry(1,(Int_t)log2(this->tof_j_flag[1]),xleft, xright, yleft, yright);
344          ytof_temp[0]=yleft+2.75;
345        }
346        
347        if(t_tof->xtofpos[1]<100. && t_tof->ytofpos[1]<100.){
348          xtof_temp[2]=t_tof->xtofpos[1];
349          ytof_temp[3]=t_tof->ytofpos[1];
350        }else if(t_tof->xtofpos[1]>=100. && t_tof->ytofpos[1]<100.){
351          ytof_temp[3]=t_tof->ytofpos[1];
352          this->GetPaddleGeometry(3,(Int_t)log2(this->tof_j_flag[3]),xleft, xright, yleft, yright);
353          xtof_temp[2]=xleft+4.5;
354        }else if(t_tof->ytofpos[1]>=100. && t_tof->xtofpos[1]<100.){
355          xtof_temp[2]=t_tof->xtofpos[1];
356          this->GetPaddleGeometry(2,(Int_t)log2(this->tof_j_flag[2]),xleft, xright, yleft, yright);
357          ytof_temp[3]=yleft+3.75;
358        }
359        
360        if(t_tof->xtofpos[2]<100. && t_tof->ytofpos[2]<100.){
361          xtof_temp[5]=t_tof->xtofpos[2];
362          ytof_temp[4]=t_tof->ytofpos[2];
363        }else if(t_tof->xtofpos[2]>=100. && t_tof->ytofpos[2]<100.){
364          ytof_temp[4]=t_tof->ytofpos[2];
365          this->GetPaddleGeometry(4,(Int_t)log2(this->tof_j_flag[4]),xleft, xright, yleft, yright);
366          xtof_temp[5]=xleft+3;
367        }else if(t_tof->ytofpos[2]>=100. && t_tof->xtofpos[2]<100.){
368          xtof_temp[5]=t_tof->xtofpos[2];
369          this->GetPaddleGeometry(5,(Int_t)log2(this->tof_j_flag[5]),xleft, xright, yleft, yright);
370          ytof_temp[4]=yleft+2.5;
371        }
372    
373        if ( (xtof_temp[0])> 17.85 && fabs(xtof_temp[0])<17.85+4. ) xtof_temp[0] =17.84;
374        if ( (xtof_temp[1])> 17.85 && fabs(xtof_temp[1])<17.85+4. ) xtof_temp[1] =17.84;
375        if ( (ytof_temp[0])> 13.75 && fabs(ytof_temp[0])<13.75+4. ) ytof_temp[0] =13.74;
376        if ( (ytof_temp[1])> 13.75 && fabs(ytof_temp[1])<13.75+4. ) ytof_temp[1] =13.74;
377        if ( (xtof_temp[0])< -17.85 && fabs(xtof_temp[0])>-(17.85+4.) ) xtof_temp[0] =-17.84;
378        if ( (xtof_temp[1])< -17.85 && fabs(xtof_temp[1])>-(17.85+4.) ) xtof_temp[1] =-17.84;
379        if ( (ytof_temp[0])< -13.75 && fabs(ytof_temp[0])>-(13.75+4.) ) ytof_temp[0] =-13.74;
380        if ( (ytof_temp[1])< -13.75 && fabs(ytof_temp[1])>-(13.75+4.) ) ytof_temp[1] =-13.74;
381    
382        if ( (xtof_temp[2])> 4.5 && (xtof_temp[2])<4.5+4. ) xtof_temp[2] =4.4;
383        if ( (xtof_temp[3])> 4.45 && (xtof_temp[3])<4.5+4. ) xtof_temp[3] =4.4;
384        if ( (ytof_temp[2])> 3.75 && (ytof_temp[2])<3.75+4. ) ytof_temp[2] =3.74;
385        if ( (ytof_temp[3])> 3.75 && (ytof_temp[3])<3.75+4. ) ytof_temp[3] =3.74;
386        if ( (xtof_temp[2])< -4.5 && (xtof_temp[2])>-(4.5+4.) ) xtof_temp[2] =-4.4;
387        if ( (xtof_temp[3])< -4.45 && (xtof_temp[3])>-(4.5+4.) ) xtof_temp[3] =-4.4;
388        if ( (ytof_temp[2])< -3.75 && (ytof_temp[2])>-(3.75+4.) ) ytof_temp[2] =-3.74;
389        if ( (ytof_temp[3])< -3.75 && (ytof_temp[3])>-(3.75+4.) ) ytof_temp[3] =-3.74;
390    
391        if ( (xtof_temp[4])> 6. && (xtof_temp[4])<6.+4. ) xtof_temp[2] =5.9;
392        if ( (xtof_temp[5])> 6. && (xtof_temp[5])<6.+4. ) xtof_temp[3] =5.9;
393        if ( (ytof_temp[4])> 5. && (ytof_temp[4])<5.+4. ) ytof_temp[2] =4.9;
394        if ( (ytof_temp[5])> 5. && (ytof_temp[5])<5.+4. ) ytof_temp[3] =4.9;
395        if ( (xtof_temp[4])< -6. && (xtof_temp[4])>-(6.+4.) ) xtof_temp[2] =-5.9;
396        if ( (xtof_temp[5])< -6. && (xtof_temp[5])>-(6.+4.) ) xtof_temp[3] =-5.9;
397        if ( (ytof_temp[4])< -5. && (ytof_temp[4])>-(5.+4.) ) ytof_temp[2] =-4.9;
398        if ( (ytof_temp[5])< -5. && (ytof_temp[5])>-(5.+4.) ) ytof_temp[3] =-4.9;
399    
400    
401        for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
402          Int_t paddleid=ii;
403          pad = GetPaddleid(plane,paddleid);
404          Int_t IpaddleT=-1;
405          IpaddleT=this->GetPaddleIdOfTrack(xtof_temp[plane],ytof_temp[plane], plane,0.0);
406    //      printf("SSS %i %i %f %f  %f %f \n",IpaddleT,paddleid,xtof_temp[plane],ytof_temp[plane],t_tof->xtofpos[plane],t_tof->ytofpos[plane]);
407          //      if ( IpaddleT == paddleid || IpaddleT-1 == paddleid || IpaddleT+1 == paddleid ){
408          if ( IpaddleT == paddleid || GetTrueNHitPaddles(plane) == 1 ){
409            //IpaddleT-1 == paddleid || IpaddleT+1 == paddleid ){
410            GetdEdxPaddle(trk, pad, adcfl, PadEdx, SatWarning);
411            dedx += PadEdx;
412          }
413        };
414      } else {
415        for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
416          Int_t paddleid=ii;
417          pad = GetPaddleid(plane,paddleid);
418          GetdEdxPaddle(trk, pad, adcfl, PadEdx, SatWarning);
419          dedx += PadEdx;
420    //      printf("TTT %i %i %f\n",paddleid,plane,PadEdx);
421        };
422      }
423      //
424      return(dedx);
425    };
426    
427    
428    //wm Nov 08
429    //gf Apr 07
430    /**
431     * Method to get the mean dEdx from a ToF layer - ATTENTION:
432     * It will sum up the dEdx of all the paddles, but since by definition
433     * only the paddle hitted by the track gets a dEdx value and the other
434     * paddles are set to zero, the output is just the dEdx of the hitted
435     * paddle in each layer!
436     * The "adcfl" option is not very useful (an artificial dEdx is per
437     * definition= 1 mip and not a real measurement), anyway left in the code
438     * @param notrack Track Number
439     * @param plane Plane index (0,1,2,3,4,5)
440     * @param adcflag in the plane (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
441     */
442  Float_t ToFLevel2::GetdEdx(Int_t notrack, Int_t plane, Int_t adcfl){  Float_t ToFLevel2::GetdEdx(Int_t notrack, Int_t plane, Int_t adcfl){
443    //  printf("fiffi\n");    //  printf("fiffi\n");
444    Float_t dedx = 0.;    Float_t dedx = 0.;
# Line 622  void ToFLevel2::GetdEdxPaddle(Int_t notr Line 802  void ToFLevel2::GetdEdxPaddle(Int_t notr
802    if(dEdx[pmtleft]<1000 && dEdx[pmtright]==1000) PadEdx = dEdx[pmtleft];    if(dEdx[pmtleft]<1000 && dEdx[pmtright]==1000) PadEdx = dEdx[pmtleft];
803        
804  };  };
805    
806  //  //
807    //  wm Nov 08 revision - saturation values included
808    /// gf Apr 07
809    /**
810     * Method to get the dEdx from a given ToF paddle.
811     * If two PMTs are good, the mean dEdx of both PMTs is taken, otherwise
812     * just the dEdx of the "good" PMT. If both PMTs are above saturation => dEdx=1000
813     * @param notrack Track Number
814     * @param Paddle index (0,1,...,23).
815     * @param adcflag in the paddle (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
816     * @param PadEdx dEdx from a given ToF paddle
817     * @param SatWarning 1 if the PMT ios near saturation region (adcraw ~3000)
818     */
819    void ToFLevel2::GetdEdxPaddle(ToFTrkVar *trk, Int_t paddleid, Int_t adcfl, Float_t &PadEdx, Int_t &SatWarning){
820    
821      /*
822        Float_t  PMTsat[48] = {
823        3162.14, 3165.48, 3153.85, 3085.73, 3089.65, 3107.64, 3097.52, 3078.37,
824        3130.05, 3087.07, 3112.22, 3102.92, 3080.58, 3092.55, 3087.94, 3125.03,
825        3094.09, 3143.16, 3125.51, 3181.27, 3092.09, 3124.98, 3069.3, 3095.53,
826        3097.11, 3133.53, 3114.73, 3113.01, 3091.19, 3097.99, 3033.84, 3134.98,
827        3081.37, 3111.04, 3066.77, 3108.17, 3133, 3111.06, 3052.52, 3140.66,
828        3106.33, 3094.85, 3150.85, 3118.8, 3096.24, 3118.47,3111.36, 3117.11 } ;
829      */
830    
831      // new values from Napoli dec 2008
832      Float_t  PMTsat[48] = {
833        3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
834        3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
835        3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
836        3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
837        3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
838        3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
839    
840      for (Int_t i=0; i<48;i++) PMTsat[i] = PMTsat[i] - 5.;  // safety margin
841    
842    
843      PadEdx = 0.;
844      //  SatWarning = 1000;
845      SatWarning = 0;   // 0=good, increase for each bad PMT
846    
847      Float_t dEdx[48] = {0};
848      Int_t pmt_id = -1;
849      Float_t adcraw[48];
850      //
851      if(!trk) return; //ELENA
852      //
853    
854      Int_t pmtleft=-1;
855      Int_t pmtright=-1;
856      GetPaddlePMT(paddleid, pmtleft, pmtright);
857    
858      adcraw[pmtleft] = 4095;
859      adcraw[pmtright] = 4095;
860    
861      
862      for (Int_t jj=0; jj<npmt(); jj++){
863        
864        ToFPMT *pmt = GetToFPMT(jj);
865        if(!pmt)break; //ELENA
866        
867        pmt_id = pmt->pmt_id;
868        if(pmt_id==pmtleft){
869          adcraw[pmtleft] = pmt->adc;
870        }
871        
872        if(pmt_id==pmtright){
873          adcraw[pmtright] = pmt->adc;
874        }
875      }
876    
877      
878      for (Int_t i=0; i<trk->npmtadc; i++){
879    
880        if((trk->adcflag).At(i)==0 || adcfl==100){
881          if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = (trk->dedx).At(i);
882          if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = (trk->dedx).At(i);
883        }else{
884          if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = 0.;
885          if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = 0.;
886        }
887      }
888    
889    
890      //  if( adcraw[pmtleft] >3000 || adcraw[pmtright] >3000)SatWarning=1;  //old version
891    
892      // Increase SatWarning Counter for each PMT>Sat
893      if( adcraw[pmtleft] > PMTsat[pmtleft])SatWarning++;  
894      if( adcraw[pmtright] > PMTsat[pmtright])SatWarning++;
895    
896      // if ADC  > sat set dEdx=1000
897      if( adcraw[pmtleft] > PMTsat[pmtleft]) dEdx[pmtleft] = 1000.;
898      if( adcraw[pmtright] > PMTsat[pmtright]) dEdx[pmtright] = 1000. ;
899    
900      // if two PMT are good, take mean dEdx, otherwise only the good dEdx
901      if(dEdx[pmtleft]<1000 && dEdx[pmtright]<1000) PadEdx = (dEdx[pmtleft]+dEdx[pmtright])*0.5;
902      if(dEdx[pmtleft]==1000 && dEdx[pmtright]<1000) PadEdx = dEdx[pmtright];  
903      if(dEdx[pmtleft]<1000 && dEdx[pmtright]==1000) PadEdx = dEdx[pmtleft];
904      
905    };
906    
907  // gf Apr 07  // gf Apr 07
908    
# Line 1309  Int_t ToFLevel2::Process(TrkLevel2 *trk, Line 1588  Int_t ToFLevel2::Process(TrkLevel2 *trk,
1588  //   if ( !dbc->IsConnected() ) return 1;  //   if ( !dbc->IsConnected() ) return 1;
1589  //   stringstream myquery;  //   stringstream myquery;
1590  //   myquery.str("");  //   myquery.str("");
1591  //   myquery << "SET time_zone='+0:00'";  //   myquery << "SET time_zone='+0:00';";
1592  //   dbc->Query(myquery.str().c_str());  //   dbc->Query(myquery.str().c_str());
1593    //   delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';");
1594  //   GL_PARAM *glparam = new GL_PARAM();  //   GL_PARAM *glparam = new GL_PARAM();
1595  //   glparam->Query_GL_PARAM(1,1,dbc); // parameters stored in DB in GL_PRAM table  //   glparam->Query_GL_PARAM(1,1,dbc); // parameters stored in DB in GL_PRAM table
1596  //   trk->LoadField(glparam->PATH+glparam->NAME);  //   trk->LoadField(glparam->PATH+glparam->NAME);
# Line 1784  void ToFdEdx::Init(pamela::tof::TofEvent Line 2064  void ToFdEdx::Init(pamela::tof::TofEvent
2064      for (Int_t hh=0; hh<12;hh++){      for (Int_t hh=0; hh<12;hh++){
2065        //          tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh];                  //          tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh];          
2066        int mm = tf.GetPMTid(gg,hh);                int mm = tf.GetPMTid(gg,hh);        
2067        adc[mm]=tofl0->adc[gg][hh];        adc[mm]= (0xFFF & tofl0->adc[gg][hh]); // EM, exclude warning bits
2068      };            };      
2069    };    };
2070        
# Line 1899  void ToFdEdx::Process(UInt_t atime, Floa Line 2179  void ToFdEdx::Process(UInt_t atime, Floa
2179      //    printf(" e qui? \n");      //    printf(" e qui? \n");
2180      //---------------------------------------------------- Z reconstruction      //---------------------------------------------------- Z reconstruction
2181    
2182      double adcHe, adcnorm, adclin, dEdx, Zeta;      double adcHe, adcnorm, adclin, dEdx;//, Zeta; // EM GCC4.7
2183    
2184      adcHe=-2;      adcHe=-2;
2185      adcnorm=-2;      adcnorm=-2;
2186      adclin=-2;      adclin=-2;
2187      dEdx=-2;      dEdx=-2;
2188      Zeta=-2;      //    Zeta=-2;//EM GCC4.7
2189      Double_t correction = 1.;      Double_t correction = 1.;
2190    
2191      if(Aconn==1 && (ii==0 || ii==20 || ii==22 || ii==24)){      if(Aconn==1 && (ii==0 || ii==20 || ii==22 || ii==24)){

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.42

  ViewVC Help
Powered by ViewVC 1.1.23