CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
FitterFuncs::PulseShapeFunctor Class Reference

#include <PulseShapeFunctor.h>

Public Member Functions

double doublePulseShapeFunc (const double *x)
 
double EvalPulse (const double *pars, const unsigned nPar)
 
int getcntNANinfit ()
 
void getPulseShape (std::array< double, HcalConst::maxSamples > &fillPulseShape)
 
double getSiPMDarkCurrent (double darkCurrent, double fcByPE, double lambda)
 
 PulseShapeFunctor (const HcalPulseShapes::Shape &pulse, bool iPedestalConstraint, bool iTimeConstraint, bool iAddPulseJitter, double iPulseJitter, double iTimeMean, double iPedMean, unsigned int nSamplesToFit)
 
void setDefaultcntNANinfit ()
 
void setinvertpedSig2 (double x)
 
void setinverttimeSig2 (double x)
 
void setpsFiterry (double *erry)
 
void setpsFiterry2 (double *erry2)
 
void setpsFitslew (double *slew)
 
void setpsFitx (double *x)
 
void setpsFity (double *y)
 
double singlePulseShapeFunc (const double *x)
 
double triplePulseShapeFunc (const double *x)
 
 ~PulseShapeFunctor ()
 

Private Member Functions

void funcShape (std::array< double, HcalConst::maxSamples > &ntmpbin, const double pulseTime, const double pulseHeight, const double slew)
 

Private Attributes

std::vector< float > acc25nsVec
 
std::vector< float > accVarLenIdxMinusOneVec
 
std::vector< float > accVarLenIdxZEROVec
 
bool addPulseJitter_
 
int cntNANinfit
 
std::vector< float > diff25nsItvlVec
 
std::vector< float > diffVarItvlIdxMinusOneVec
 
std::vector< float > diffVarItvlIdxZEROVec
 
double invertpedSig2_
 
double inverttimeSig2_
 
unsigned nSamplesToFit_
 
bool pedestalConstraint_
 
double pedMean_
 
double psFit_erry [HcalConst::maxSamples]
 
double psFit_erry2 [HcalConst::maxSamples]
 
double psFit_slew [HcalConst::maxSamples]
 
double psFit_x [HcalConst::maxSamples]
 
double psFit_y [HcalConst::maxSamples]
 
std::array< float, HcalConst::maxPSshapeBinpulse_hist
 
std::array< double, HcalConst::maxSamplespulse_shape_
 
std::array< double, HcalConst::maxSamplespulse_shape_sum_
 
double pulseJitter_
 
bool timeConstraint_
 
double timeMean_
 
double timeShift_
 
double timeSig_
 
bool unConstrainedFit_
 

Detailed Description

Definition at line 19 of file PulseShapeFunctor.h.

Constructor & Destructor Documentation

FitterFuncs::PulseShapeFunctor::PulseShapeFunctor ( const HcalPulseShapes::Shape pulse,
bool  iPedestalConstraint,
bool  iTimeConstraint,
bool  iAddPulseJitter,
double  iPulseJitter,
double  iTimeMean,
double  iPedMean,
unsigned int  nSamplesToFit 
)

Definition at line 10 of file PulseShapeFunctor.cc.

References acc25nsVec, accVarLenIdxMinusOneVec, accVarLenIdxZEROVec, addPulseJitter_, diff25nsItvlVec, diffVarItvlIdxMinusOneVec, diffVarItvlIdxZEROVec, mps_fire::i, HcalConst::maxPSshapeBin, HcalConst::maxSamples, nSamplesToFit_, HcalConst::nsPerBX, pedestalConstraint_, pedMean_, psFit_erry, psFit_erry2, psFit_slew, psFit_x, psFit_y, pulse(), pulse_hist, pulseJitter_, timeConstraint_, timeMean_, and timeShift_.

13  :
14  cntNANinfit(0),
18  //The raw pulse
19  for(int i=0;i<HcalConst::maxPSshapeBin;++i) pulse_hist[i] = pulse(i);
20  // Accumulate 25ns for each starting point of 0, 1, 2, 3...
21  for(int i=0; i<HcalConst::maxPSshapeBin; ++i){
22  for(int j=i; j<i+HcalConst::nsPerBX; ++j){ //sum over HcalConst::nsPerBXns from point i
23  acc25nsVec[i] += ( j < HcalConst::maxPSshapeBin? pulse_hist[j] : pulse_hist[HcalConst::maxPSshapeBin-1]);
24  }
25  diff25nsItvlVec[i] = ( i+HcalConst::nsPerBX < HcalConst::maxPSshapeBin? pulse_hist[i+HcalConst::nsPerBX] - pulse_hist[i] : pulse_hist[HcalConst::maxPSshapeBin-1] - pulse_hist[i]);
26  }
27  // Accumulate different ns for starting point of index either 0 or -1
28  for(int i=0; i<HcalConst::nsPerBX; ++i){
29  if( i==0 ){
32  } else{
34  accVarLenIdxMinusOneVec[i] = accVarLenIdxMinusOneVec[i-1] + pulse_hist[i-1];
35  }
37  diffVarItvlIdxMinusOneVec[i] = pulse_hist[i] - pulse_hist[0];
38  }
39  for(int i = 0; i < HcalConst::maxSamples; i++) {
40  psFit_x[i] = 0;
41  psFit_y[i] = 0;
42  psFit_erry[i] = 1.;
43  psFit_erry2[i] = 1.;
44  psFit_slew [i] = 0.;
45  }
46  //Constraints
47  pedestalConstraint_ = iPedestalConstraint;
48  timeConstraint_ = iTimeConstraint;
49  addPulseJitter_ = iAddPulseJitter;
50  pulseJitter_ = iPulseJitter*iPulseJitter;
51 
52  // for M2
53  timeMean_ = iTimeMean;
54  pedMean_ = iPedMean;
55  timeShift_ = 100.;
56  timeShift_ += 12.5;//we are trying to get BX
57 
58  nSamplesToFit_ = nSamplesToFit;
59 
60  }
double psFit_erry[HcalConst::maxSamples]
std::vector< float > acc25nsVec
double psFit_y[HcalConst::maxSamples]
std::vector< float > diffVarItvlIdxZEROVec
std::array< float, HcalConst::maxPSshapeBin > pulse_hist
std::vector< float > diff25nsItvlVec
std::vector< float > accVarLenIdxMinusOneVec
std::vector< float > diffVarItvlIdxMinusOneVec
double pulse(double x, double y, double z, double t)
double psFit_erry2[HcalConst::maxSamples]
double psFit_x[HcalConst::maxSamples]
double psFit_slew[HcalConst::maxSamples]
std::vector< float > accVarLenIdxZEROVec
FitterFuncs::PulseShapeFunctor::~PulseShapeFunctor ( )

Definition at line 103 of file PulseShapeFunctor.cc.

103  {
104  }

Member Function Documentation

double FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc ( const double *  x)

Definition at line 183 of file PulseShapeFunctor.cc.

References EvalPulse().

Referenced by PulseShapeFitOOTPileupCorrection::resetPulseShapeTemplate().

183  {
184  return EvalPulse(x,5);
185  }
double EvalPulse(const double *pars, const unsigned nPar)
double FitterFuncs::PulseShapeFunctor::EvalPulse ( const double *  pars,
const unsigned  nPar 
)

Definition at line 106 of file PulseShapeFunctor.cc.

References addPulseJitter_, cntNANinfit, edmIntegrityCheck::d, funcShape(), mps_fire::i, HcalConst::invertnsPerBx, invertpedSig2_, inverttimeSig2_, edm::isNotFinite(), nSamplesToFit_, HcalConst::nsPerBX, muonCSCDigis_cfi::pedestal, pedestalConstraint_, pedMean_, psFit_erry2, psFit_slew, psFit_y, pulse_shape_, pulse_shape_sum_, pulseJitter_, ntuplemaker::time, timeConstraint_, timeMean_, and timeShift_.

Referenced by doublePulseShapeFunc(), singlePulseShapeFunc(), and triplePulseShapeFunc().

106  {
107 
108  unsigned i =0, j=0;
109 
110  const double pedestal=pars[nPars-1];
111 
112  //Stop crashes
113  for(i =0; i < nPars; ++i ) if( edm::isNotFinite(pars[i]) ){ ++ cntNANinfit; return 1e10; }
114 
115  //calculate chisquare
116  double chisq = 0;
117  const unsigned parBy2=(nPars-1)/2;
118  // std::array<float,HcalConst::maxSamples> pulse_shape_;
119 
120  if(addPulseJitter_) {
122  //Interpolate the fit (Quickly)
123  funcShape(pulse_shape_, pars[0],pars[1],psFit_slew[time]);
124  for (j=0; j<nSamplesToFit_; ++j) {
127  }
128 
129  for (i=1; i<parBy2; ++i) {
130  time = (pars[i*2]+timeShift_-timeMean_)*HcalConst::invertnsPerBx;
131  //Interpolate the fit (Quickly)
132  funcShape(pulse_shape_, pars[i*2],pars[i*2+1],psFit_slew[time]);
133  // add an uncertainty from the pulse (currently noise * pulse height =>Ecal uses full cov)
135  for (j=0; j<nSamplesToFit_; ++j) {
138  }
139  }
140  }
141  else{
142  int time = (pars[0]+timeShift_-timeMean_)*HcalConst::invertnsPerBx;
143  //Interpolate the fit (Quickly)
144  funcShape(pulse_shape_, pars[0],pars[1],psFit_slew[time]);
145  for(j=0; j<nSamplesToFit_; ++j)
146  pulse_shape_sum_[j] = pulse_shape_[j] + pedestal;
147 
148  for (i=1; i<parBy2; ++i) {
149  time = (pars[i*2]+timeShift_-timeMean_)*HcalConst::invertnsPerBx;
150  //Interpolate the fit (Quickly)
151  funcShape(pulse_shape_, pars[i*2],pars[i*2+1],psFit_slew[time]);
152  // add an uncertainty from the pulse (currently noise * pulse height =>Ecal uses full cov)
153  for(j=0; j<nSamplesToFit_; ++j)
155  }
156  }
157 
158  for (i=0;i<nSamplesToFit_; ++i)
159  {
160  const double d = psFit_y[i]- pulse_shape_sum_[i];
161  chisq += d*d/psFit_erry2[i];
162  }
163 
164  if(pedestalConstraint_) {
165  //Add the pedestal Constraint to chi2
166  chisq += invertpedSig2_*(pedestal - pedMean_)*(pedestal - pedMean_);
167  }
168  //Add the time Constraint to chi2
169  if(timeConstraint_) {
170  for(j=0; j< parBy2; ++j ){
171  int time = (pars[j*2]+timeShift_-timeMean_)*(double)HcalConst::invertnsPerBx;
172  double time1 = -100.+time*HcalConst::nsPerBX;
173  chisq += inverttimeSig2_*(pars[j*2] - timeMean_ - time1)*(pars[j*2] - timeMean_ - time1);
174  }
175  }
176  return chisq;
177  }
std::array< double, HcalConst::maxSamples > pulse_shape_
double psFit_y[HcalConst::maxSamples]
bool isNotFinite(T x)
Definition: isFinite.h:10
void funcShape(std::array< double, HcalConst::maxSamples > &ntmpbin, const double pulseTime, const double pulseHeight, const double slew)
double invertnsPerBx
double psFit_erry2[HcalConst::maxSamples]
std::array< double, HcalConst::maxSamples > pulse_shape_sum_
double psFit_slew[HcalConst::maxSamples]
void FitterFuncs::PulseShapeFunctor::funcShape ( std::array< double, HcalConst::maxSamples > &  ntmpbin,
const double  pulseTime,
const double  pulseHeight,
const double  slew 
)
private

Definition at line 62 of file PulseShapeFunctor.cc.

References funct::abs(), acc25nsVec, accVarLenIdxMinusOneVec, accVarLenIdxZEROVec, cntNANinfit, constexpr, diff25nsItvlVec, diffVarItvlIdxMinusOneVec, diffVarItvlIdxZEROVec, f, mps_fire::i, HcalConst::iniTimeShift, createfilelist::int, edm::isNotFinite(), HcalConst::maxSamples, and HcalConst::nsPerBX.

Referenced by EvalPulse().

62  {
63  // pulse shape components over a range of time 0 ns to 255 ns in 1 ns steps
64  constexpr int ns_per_bx = HcalConst::nsPerBX;
66  constexpr int num_bx = num_ns/ns_per_bx;
67  //Get the starting time
68  int i_start = ( -HcalConst::iniTimeShift - pulseTime - slew >0 ? 0 : (int)std::abs(-HcalConst::iniTimeShift-pulseTime-slew) + 1);
69  double offset_start = i_start - HcalConst::iniTimeShift - pulseTime - slew; //-199-2*pars[0]-2.*slew (for pars[0] > 98.5) or just -98.5-pars[0]-slew;
70  // zeroing output binned pulse shape
71  ntmpbin.fill(0.0f);
72 
73  if( edm::isNotFinite(offset_start) ){ //Check for nan
74  ++ cntNANinfit;
75  }else{
76  if( offset_start == 1.0 ){ offset_start = 0.; i_start-=1; } //Deal with boundary
77 
78  const int bin_start = (int) offset_start; //bin off to integer
79  const int bin_0_start = ( offset_start < bin_start + 0.5 ? bin_start -1 : bin_start ); //Round it
80  const int iTS_start = i_start/ns_per_bx; //Time Slice for time shift
81  const int distTo25ns_start = HcalConst::nsPerBX - 1 - i_start%ns_per_bx; //Delta ns
82  const double factor = offset_start - bin_0_start - 0.5; //Small correction?
83 
84  //Build the new pulse
85  ntmpbin[iTS_start] = (bin_0_start == -1 ? // Initial bin (I'm assuming this is ok)
86  accVarLenIdxMinusOneVec[distTo25ns_start] + factor * diffVarItvlIdxMinusOneVec[distTo25ns_start]
87  : accVarLenIdxZEROVec [distTo25ns_start] + factor * diffVarItvlIdxZEROVec [distTo25ns_start]);
88  //Fill the rest of the bins
89  for(int iTS = iTS_start+1; iTS < num_bx; ++iTS){
90  int bin_idx = distTo25ns_start + 1 + (iTS-iTS_start-1)*ns_per_bx + bin_0_start;
91  ntmpbin[iTS] = acc25nsVec[bin_idx] + factor * diff25nsItvlVec[bin_idx];
92  }
93  //Scale the pulse
94  for(int i=iTS_start; i < num_bx; ++i) {
95  ntmpbin[i] *= pulseHeight;
96  }
97 
98  }
99 
100  return;
101  }
std::vector< float > acc25nsVec
#define constexpr
float iniTimeShift
std::vector< float > diffVarItvlIdxZEROVec
bool isNotFinite(T x)
Definition: isFinite.h:10
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
std::vector< float > diff25nsItvlVec
std::vector< float > accVarLenIdxMinusOneVec
std::vector< float > diffVarItvlIdxMinusOneVec
std::vector< float > accVarLenIdxZEROVec
int FitterFuncs::PulseShapeFunctor::getcntNANinfit ( )
inline

Definition at line 29 of file PulseShapeFunctor.h.

void FitterFuncs::PulseShapeFunctor::getPulseShape ( std::array< double, HcalConst::maxSamples > &  fillPulseShape)
inline

Definition at line 44 of file PulseShapeFunctor.h.

44  {
45  fillPulseShape = pulse_shape_;
46  }
std::array< double, HcalConst::maxSamples > pulse_shape_
double FitterFuncs::PulseShapeFunctor::getSiPMDarkCurrent ( double  darkCurrent,
double  fcByPE,
double  lambda 
)
void FitterFuncs::PulseShapeFunctor::setDefaultcntNANinfit ( )
inline

Definition at line 28 of file PulseShapeFunctor.h.

void FitterFuncs::PulseShapeFunctor::setinvertpedSig2 ( double  x)
inline

Definition at line 37 of file PulseShapeFunctor.h.

void FitterFuncs::PulseShapeFunctor::setinverttimeSig2 ( double  x)
inline

Definition at line 38 of file PulseShapeFunctor.h.

void FitterFuncs::PulseShapeFunctor::setpsFiterry ( double *  erry)
inline

Definition at line 33 of file PulseShapeFunctor.h.

References mps_fire::i, and HcalConst::maxSamples.

33 { for(int i=0; i<HcalConst::maxSamples; ++i) psFit_erry [i] = erry [i]; }
double psFit_erry[HcalConst::maxSamples]
void FitterFuncs::PulseShapeFunctor::setpsFiterry2 ( double *  erry2)
inline

Definition at line 34 of file PulseShapeFunctor.h.

References mps_fire::i, and HcalConst::maxSamples.

34 { for(int i=0; i<HcalConst::maxSamples; ++i) psFit_erry2 [i] = erry2[i]; }
double psFit_erry2[HcalConst::maxSamples]
void FitterFuncs::PulseShapeFunctor::setpsFitslew ( double *  slew)
inline

Definition at line 35 of file PulseShapeFunctor.h.

References mps_fire::i, and HcalConst::maxSamples.

35 { for(int i=0; i<HcalConst::maxSamples; ++i) {psFit_slew [i] = slew [i]; } }
double psFit_slew[HcalConst::maxSamples]
void FitterFuncs::PulseShapeFunctor::setpsFitx ( double *  x)
inline

Definition at line 31 of file PulseShapeFunctor.h.

References mps_fire::i, and HcalConst::maxSamples.

31 { for(int i=0; i<HcalConst::maxSamples; ++i) psFit_x[i] = x[i]; }
double psFit_x[HcalConst::maxSamples]
void FitterFuncs::PulseShapeFunctor::setpsFity ( double *  y)
inline

Definition at line 32 of file PulseShapeFunctor.h.

References mps_fire::i, and HcalConst::maxSamples.

32 { for(int i=0; i<HcalConst::maxSamples; ++i) psFit_y[i] = y[i]; }
double psFit_y[HcalConst::maxSamples]
double FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc ( const double *  x)

Definition at line 179 of file PulseShapeFunctor.cc.

References EvalPulse().

Referenced by PulseShapeFitOOTPileupCorrection::resetPulseShapeTemplate(), and MahiFit::resetPulseShapeTemplate().

179  {
180  return EvalPulse(x,3);
181  }
double EvalPulse(const double *pars, const unsigned nPar)
double FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc ( const double *  x)

Definition at line 187 of file PulseShapeFunctor.cc.

References EvalPulse().

Referenced by PulseShapeFitOOTPileupCorrection::resetPulseShapeTemplate().

187  {
188  return EvalPulse(x,7);
189  }
double EvalPulse(const double *pars, const unsigned nPar)

Member Data Documentation

std::vector<float> FitterFuncs::PulseShapeFunctor::acc25nsVec
private

Definition at line 52 of file PulseShapeFunctor.h.

Referenced by funcShape(), and PulseShapeFunctor().

std::vector<float> FitterFuncs::PulseShapeFunctor::accVarLenIdxMinusOneVec
private

Definition at line 54 of file PulseShapeFunctor.h.

Referenced by funcShape(), and PulseShapeFunctor().

std::vector<float> FitterFuncs::PulseShapeFunctor::accVarLenIdxZEROVec
private

Definition at line 53 of file PulseShapeFunctor.h.

Referenced by funcShape(), and PulseShapeFunctor().

bool FitterFuncs::PulseShapeFunctor::addPulseJitter_
private

Definition at line 61 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

int FitterFuncs::PulseShapeFunctor::cntNANinfit
private

Definition at line 51 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and funcShape().

std::vector<float> FitterFuncs::PulseShapeFunctor::diff25nsItvlVec
private

Definition at line 52 of file PulseShapeFunctor.h.

Referenced by funcShape(), and PulseShapeFunctor().

std::vector<float> FitterFuncs::PulseShapeFunctor::diffVarItvlIdxMinusOneVec
private

Definition at line 54 of file PulseShapeFunctor.h.

Referenced by funcShape(), and PulseShapeFunctor().

std::vector<float> FitterFuncs::PulseShapeFunctor::diffVarItvlIdxZEROVec
private

Definition at line 53 of file PulseShapeFunctor.h.

Referenced by funcShape(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::invertpedSig2_
private

Definition at line 70 of file PulseShapeFunctor.h.

Referenced by EvalPulse().

double FitterFuncs::PulseShapeFunctor::inverttimeSig2_
private

Definition at line 69 of file PulseShapeFunctor.h.

Referenced by EvalPulse().

unsigned FitterFuncs::PulseShapeFunctor::nSamplesToFit_
private

Definition at line 58 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

bool FitterFuncs::PulseShapeFunctor::pedestalConstraint_
private

Definition at line 59 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::pedMean_
private

Definition at line 66 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::psFit_erry[HcalConst::maxSamples]
private

Definition at line 56 of file PulseShapeFunctor.h.

Referenced by PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::psFit_erry2[HcalConst::maxSamples]
private

Definition at line 56 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::psFit_slew[HcalConst::maxSamples]
private

Definition at line 56 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::psFit_x[HcalConst::maxSamples]
private

Definition at line 56 of file PulseShapeFunctor.h.

Referenced by PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::psFit_y[HcalConst::maxSamples]
private

Definition at line 56 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

std::array<float,HcalConst::maxPSshapeBin> FitterFuncs::PulseShapeFunctor::pulse_hist
private

Definition at line 49 of file PulseShapeFunctor.h.

Referenced by PulseShapeFunctor().

std::array<double,HcalConst::maxSamples> FitterFuncs::PulseShapeFunctor::pulse_shape_
private

Definition at line 71 of file PulseShapeFunctor.h.

Referenced by EvalPulse().

std::array<double,HcalConst::maxSamples> FitterFuncs::PulseShapeFunctor::pulse_shape_sum_
private

Definition at line 72 of file PulseShapeFunctor.h.

Referenced by EvalPulse().

double FitterFuncs::PulseShapeFunctor::pulseJitter_
private

Definition at line 63 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

bool FitterFuncs::PulseShapeFunctor::timeConstraint_
private

Definition at line 60 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::timeMean_
private

Definition at line 64 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::timeShift_
private

Definition at line 67 of file PulseShapeFunctor.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::timeSig_
private

Definition at line 65 of file PulseShapeFunctor.h.

bool FitterFuncs::PulseShapeFunctor::unConstrainedFit_
private

Definition at line 62 of file PulseShapeFunctor.h.