Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:54

0001 /* 
0002  *  \class TPNPulse
0003  *
0004  *  \author: Julie Malcles - CEA/Saclay
0005  */
0006 
0007 #include <CalibCalorimetry/EcalLaserAnalyzer/interface/TPNPulse.h>
0008 
0009 #include <TMath.h>
0010 #include <iostream>
0011 #include <cassert>
0012 using namespace std;
0013 
0014 //ClassImp(TPNPulse)
0015 
0016 // Default Constructor...
0017 TPNPulse::TPNPulse() { init(50, 6); }
0018 
0019 // Constructor...
0020 TPNPulse::TPNPulse(int nsamples, int presample) { init(nsamples, presample); }
0021 
0022 // Destructor
0023 TPNPulse::~TPNPulse() {}
0024 
0025 void TPNPulse::init(int nsamples, int presample) {
0026   _nsamples = 50;
0027   assert(nsamples == _nsamples);
0028   assert(presample != 0);
0029   adc_ = new double[50];
0030 
0031   _presample = presample;
0032 
0033   for (int i = 0; i < _nsamples; i++) {
0034     adc_[i] = 0.0;
0035   }
0036 
0037   adcMax_ = 0;
0038   iadcMax_ = 0;
0039   pedestal_ = 0;
0040 
0041   isMaxFound_ = false;
0042   isPedCalc_ = false;
0043 }
0044 
0045 bool TPNPulse::setPulse(double *adc) {
0046   bool done = false;
0047   adc_ = adc;
0048   done = true;
0049   isMaxFound_ = false;
0050   isPedCalc_ = false;
0051   return done;
0052 }
0053 double TPNPulse::getMax() {
0054   if (isMaxFound_)
0055     return adcMax_;
0056 
0057   int iadcmax = 0;
0058   double adcmax = 0.0;
0059   for (int i = 0; i < _nsamples; i++) {
0060     if (adc_[i] > adcmax) {
0061       iadcmax = i;
0062       adcmax = adc_[i];
0063     }
0064   }
0065   iadcMax_ = iadcmax;
0066   adcMax_ = adcmax;
0067   return adcMax_;
0068 }
0069 
0070 int TPNPulse::getMaxSample() {
0071   if (!isMaxFound_)
0072     getMax();
0073   return iadcMax_;
0074 }
0075 
0076 double TPNPulse::getPedestal() {
0077   if (isPedCalc_)
0078     return pedestal_;
0079   double ped = 0;
0080   for (int i = 0; i < _presample; i++) {
0081     ped += adc_[i];
0082   }
0083   ped /= double(_presample);
0084   pedestal_ = ped;
0085   isPedCalc_ = true;
0086   return pedestal_;
0087 }
0088 
0089 double *TPNPulse::getAdcWithoutPedestal() {
0090   double ped;
0091   if (!isPedCalc_)
0092     ped = getPedestal();
0093   else
0094     ped = pedestal_;
0095 
0096   double *adcNoPed = new double[50];
0097   for (int i = 0; i < _nsamples; i++) {
0098     adcNoPed[i] = adc_[i] - ped;
0099   }
0100   return adcNoPed;
0101 }
0102 
0103 void TPNPulse::setPresamples(int presample) {
0104   isPedCalc_ = false;
0105   _presample = presample;
0106 }