CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/CalibCalorimetry/EcalLaserAnalyzer/src/TAPDPulse.cc

Go to the documentation of this file.
00001 /* 
00002  *  \class TAPDPulse
00003  *
00004  *  $Date: 2012/02/09 10:08:10 $
00005  *  \author: Julie Malcles - CEA/Saclay
00006  */
00007 
00008 #include <CalibCalorimetry/EcalLaserAnalyzer/interface/TAPDPulse.h>
00009 #include <TMath.h>
00010 #include <iostream>
00011 #include <cassert>
00012 using namespace std;
00013 
00014 //ClassImp(TAPDPulse)
00015 
00016 
00017 // Default Constructor...
00018 TAPDPulse::TAPDPulse()
00019 {
00020   init(10,3,1,2,2,9,3,8,0.4,0.95,0.8);
00021 }
00022 
00023 // Constructor...
00024 TAPDPulse::TAPDPulse( int nsamples, int presample, int firstsample, int lastsample, int timingcutlow, int timingcuthigh, int timingquallow, int timingqualhigh, double ratiomincutlow, double ratiomincuthigh, double ratiomaxcutlow)
00025 {
00026   init( nsamples,  presample,  firstsample,  lastsample,  timingcutlow, timingcuthigh,  timingquallow,  timingqualhigh,ratiomincutlow,ratiomincuthigh, ratiomaxcutlow );
00027 }
00028 
00029 // Destructor
00030 TAPDPulse::~TAPDPulse()
00031 {
00032 }
00033 
00034 void TAPDPulse::init(int nsamples, int presample, int firstsample, int lastsample, int timingcutlow, int timingcuthigh, int timingquallow, int timingqualhigh, double ratiomincutlow, double ratiomincuthigh, double ratiomaxcutlow)
00035 {
00036   _nsamples=10;
00037   assert(nsamples==_nsamples);
00038   assert(presample!=0);
00039   adc_ = new double[10];  
00040 
00041   _presample=presample;
00042   _firstsample=firstsample;
00043   _lastsample=lastsample;
00044   
00045   _timingcutlow=timingcutlow;
00046   _timingcuthigh=timingcuthigh;
00047   _timingquallow=timingquallow;
00048   _timingqualhigh=timingqualhigh;
00049   _ratiomincutlow=ratiomincutlow;
00050   _ratiomincuthigh=ratiomincuthigh;
00051   _ratiomaxcutlow=ratiomaxcutlow;
00052 
00053   for(int i=0;i<_nsamples;i++){
00054     adc_[i]=0.0;
00055   }
00056 
00057   adcMax_=0;
00058   iadcMax_=0;
00059   pedestal_=0;
00060   
00061   isMaxFound_=false;
00062   isPedCalc_=false;
00063 }
00064 
00065 bool TAPDPulse::setPulse(double *adc){
00066 
00067   bool done=false;
00068   adc_=adc;
00069   done=true;
00070   isMaxFound_=false;
00071   isPedCalc_=false;
00072   return done;
00073 }
00074 double TAPDPulse::getMax(){
00075 
00076   if(isMaxFound_) return adcMax_; 
00077 
00078   int iadcmax=0;
00079   double adcmax=0.0;
00080   for(int i=0;i<_nsamples;i++){
00081     if(adc_[i]>adcmax){
00082       iadcmax=i;
00083       adcmax=adc_[i];
00084     }
00085   }
00086   iadcMax_=iadcmax;
00087   adcMax_=adcmax;
00088   return adcMax_;  
00089 }
00090 
00091 int TAPDPulse::getMaxSample(){
00092   if(!isMaxFound_) getMax();
00093   return iadcMax_;
00094 
00095 }
00096 double TAPDPulse::getDelta(int n1, int n2){
00097 
00098   assert (n1<_nsamples && n1>=0);
00099   assert (n2<_nsamples && n2>=0);
00100   
00101   double delta=adc_[n1]-adc_[n2];
00102   return delta;
00103 }
00104 double TAPDPulse::getRatio(int n1, int n2){
00105   
00106   assert (n1<_nsamples && n1>=0);
00107   assert (n2<_nsamples && n2>=0);
00108 
00109   double ped=0;
00110   if(isPedCalc_)ped=pedestal_; 
00111   else ped=adc_[0];
00112   
00113   double ratio=(adc_[n1]-ped)/(adc_[n2]-ped);
00114   return ratio; 
00115 }
00116 
00117 bool TAPDPulse::isTimingOK(){
00118 
00119   bool ok=true;
00120   if(!isMaxFound_) getMax();
00121   if(iadcMax_<=_timingcutlow || iadcMax_>=_timingcuthigh) ok=false;
00122   return ok;
00123 }
00124 bool TAPDPulse::isTimingQualOK(){
00125 
00126   bool ok=true;
00127   if(!isMaxFound_) getMax();
00128   if(iadcMax_<=_timingquallow || iadcMax_>=_timingqualhigh) ok=false;
00129   return ok;
00130 }
00131 
00132 bool TAPDPulse::areFitSamplesOK(){
00133   
00134   bool ok=true;
00135   if(!isMaxFound_) getMax();
00136   if ((iadcMax_-_firstsample)<_presample || (iadcMax_+_lastsample)>_nsamples-1) ok=false;
00137   return ok;
00138   
00139 }
00140 bool TAPDPulse::isPulseOK(){
00141 
00142   bool okSamples=areFitSamplesOK();
00143   bool okTiming=isTimingOK();
00144   bool okPulse=arePulseRatioOK();
00145 
00146   bool ok=(okSamples && okTiming && okPulse);
00147 
00148   return ok;
00149 }
00150 bool TAPDPulse::arePulseRatioOK(){
00151 
00152   bool ok=true;
00153 
00154   if(!isMaxFound_) getMax();
00155   if(iadcMax_<1 || iadcMax_>=_nsamples-1) return false;
00156   
00157   double ratioNm1=getRatio(iadcMax_-1,iadcMax_);
00158   double ratioNp1=getRatio(iadcMax_+1,iadcMax_);
00159   double ratioMax=TMath::Max(ratioNm1,ratioNp1);
00160   double ratioMin=TMath::Min(ratioNm1,ratioNp1);
00161   
00162   if(ratioMax<_ratiomaxcutlow) ok=false;
00163   if(ratioMin<_ratiomincutlow || ratioMin>_ratiomincuthigh) ok=false;
00164 
00165   return ok;
00166 
00167 }
00168 bool TAPDPulse::isPulseRatioMaxOK(){
00169 
00170   bool ok=true;
00171 
00172   if(!isMaxFound_) getMax();
00173   if(iadcMax_<1 || iadcMax_>=_nsamples-1) return false;
00174   
00175   double ratioNm1=getRatio(iadcMax_-1,iadcMax_);
00176   double ratioNp1=getRatio(iadcMax_+1,iadcMax_);
00177   double ratioMax=TMath::Max(ratioNm1,ratioNp1);
00178   
00179   if(ratioMax<_ratiomaxcutlow) ok=false;
00180   return ok;
00181 
00182 }
00183 bool TAPDPulse::isPulseRatioMinOK(){
00184 
00185   bool ok=true;
00186   
00187   if(!isMaxFound_) getMax();
00188   if(iadcMax_<1 || iadcMax_>=_nsamples-1) return false;
00189   
00190   double ratioNm1=getRatio(iadcMax_-1,iadcMax_);
00191   double ratioNp1=getRatio(iadcMax_+1,iadcMax_);
00192   double ratioMin=TMath::Min(ratioNm1,ratioNp1);
00193   
00194   if(ratioMin<_ratiomincutlow || ratioMin>_ratiomincuthigh) ok=false;
00195   return ok;  
00196 }
00197 
00198 double TAPDPulse::getPedestal(){
00199   if(isPedCalc_) return pedestal_;
00200   double ped=0;
00201   for(int i=0;i<_presample;i++){
00202     ped+=adc_[i];
00203   }
00204   ped/=double(_presample);
00205   pedestal_=ped;
00206   isPedCalc_=true;
00207   return pedestal_;
00208 }
00209 
00210 double* TAPDPulse::getAdcWithoutPedestal(){
00211   
00212   double ped;
00213   if(!isPedCalc_) ped=getPedestal();
00214   else ped=pedestal_;
00215   
00216   double *adcNoPed= new double[10];
00217   for (int i=0;i<_nsamples;i++){
00218     adcNoPed[i]=adc_[i]-ped;
00219   }
00220   return adcNoPed;  
00221 }
00222 
00223 void TAPDPulse::setPresamples(int presample){
00224   isPedCalc_=false;
00225   _presample=presample;
00226 }