CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CalibCalorimetry/EcalLaserAnalyzer/src/TPNPulse.cc

Go to the documentation of this file.
00001 /* 
00002  *  \class TPNPulse
00003  *
00004  *  $Date: 2012/02/09 10:08:10 $
00005  *  \author: Julie Malcles - CEA/Saclay
00006  */
00007 
00008 #include <CalibCalorimetry/EcalLaserAnalyzer/interface/TPNPulse.h>
00009 
00010 #include <TMath.h>
00011 #include <iostream>
00012 #include <cassert>
00013 using namespace std;
00014 
00015 //ClassImp(TPNPulse)
00016 
00017 
00018 // Default Constructor...
00019 TPNPulse::TPNPulse()
00020 {
00021   init(50,6);
00022 }
00023 
00024 // Constructor...
00025 TPNPulse::TPNPulse( int nsamples, int presample )
00026 {
00027   init( nsamples,  presample);
00028 }
00029 
00030 // Destructor
00031 TPNPulse::~TPNPulse()
00032 {
00033 }
00034 
00035 void TPNPulse::init(int nsamples, int presample )
00036 {
00037   _nsamples=50;
00038   assert(nsamples==_nsamples);
00039   assert(presample!=0);
00040   adc_ = new double[50];  
00041 
00042   _presample=presample;
00043   
00044   for(int i=0;i<_nsamples;i++){
00045     adc_[i]=0.0;
00046   }
00047 
00048   adcMax_=0;
00049   iadcMax_=0;
00050   pedestal_=0;
00051   
00052   isMaxFound_=false;
00053   isPedCalc_=false;
00054 }
00055 
00056 bool TPNPulse::setPulse(double *adc){
00057 
00058   bool done=false;
00059   adc_=adc;
00060   done=true;
00061   isMaxFound_=false;
00062   isPedCalc_=false;
00063   return done;
00064 }
00065 double TPNPulse::getMax(){
00066 
00067   if(isMaxFound_) return adcMax_; 
00068 
00069   int iadcmax=0;
00070   double adcmax=0.0;
00071   for(int i=0;i<_nsamples;i++){
00072     if(adc_[i]>adcmax){
00073       iadcmax=i;
00074       adcmax=adc_[i];
00075     }
00076   }
00077   iadcMax_=iadcmax;
00078   adcMax_=adcmax;
00079   return adcMax_;  
00080 }
00081 
00082 int TPNPulse::getMaxSample(){
00083   if(!isMaxFound_) getMax();
00084   return iadcMax_;
00085 
00086 }
00087 
00088 double TPNPulse::getPedestal(){
00089   if(isPedCalc_) return pedestal_;
00090   double ped=0;
00091   for(int i=0;i<_presample;i++){
00092     ped+=adc_[i];
00093   }
00094   ped/=double(_presample);
00095   pedestal_=ped;
00096   isPedCalc_=true;
00097   return pedestal_;
00098 }
00099 
00100 double* TPNPulse::getAdcWithoutPedestal(){
00101   
00102   double ped;
00103   if(!isPedCalc_) ped=getPedestal();
00104   else ped=pedestal_;
00105   
00106   double *adcNoPed= new double[50];
00107   for (int i=0;i<_nsamples;i++){
00108     adcNoPed[i]=adc_[i]-ped;
00109   }
00110   return adcNoPed;  
00111 }
00112 
00113 void TPNPulse::setPresamples(int presample){
00114   isPedCalc_=false;
00115   _presample=presample;
00116 }