CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
FitterFuncs::PulseShapeFunctor Class Reference

#include <PulseShapeFitOOTPileupCorrection.h>

Public Member Functions

double doublePulseShapeFunc (const double *x)
 
double EvalPulse (const double *pars, unsigned int nPar)
 
int getcntNANinfit ()
 
 PulseShapeFunctor (const HcalPulseShapes::Shape &pulse, bool iPedestalConstraint, bool iTimeConstraint, bool iAddPulseJitter, bool iAddTimeSlew, double iPulseJitter, double iTimeMean, double iTimeSig, double iPedMean, double iPedSig, double iNoise)
 
void setDefaultcntNANinfit ()
 
void setpsFiterry (double *erry)
 
void setpsFiterry2 (double *erry2)
 
void setpsFitslew (double *slew)
 
void setpsFitx (double *x)
 
void setpsFity (double *y)
 
double sigma (double ifC)
 
double singlePulseShapeFunc (const double *x)
 
double triplePulseShapeFunc (const double *x)
 
 ~PulseShapeFunctor ()
 

Private Member Functions

void funcHPDShape (std::array< float, 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 invertpedSig_
 
double inverttimeSig2_
 
double inverttimeSig_
 
double noise_
 
bool pedestalConstraint_
 
double pedMean_
 
double pedSig_
 
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::maxPSshapeBin
pulse_hist
 
std::array< float,
HcalConst::maxSamples
pulse_shape_
 
std::array< float,
HcalConst::maxSamples
pulse_shape_sum_
 
double pulseJitter_
 
bool timeConstraint_
 
double timeMean_
 
double timeShift_
 
double timeSig_
 
bool unConstrainedFit_
 

Detailed Description

Definition at line 33 of file PulseShapeFitOOTPileupCorrection.h.

Constructor & Destructor Documentation

FitterFuncs::PulseShapeFunctor::PulseShapeFunctor ( const HcalPulseShapes::Shape pulse,
bool  iPedestalConstraint,
bool  iTimeConstraint,
bool  iAddPulseJitter,
bool  iAddTimeSlew,
double  iPulseJitter,
double  iTimeMean,
double  iTimeSig,
double  iPedMean,
double  iPedSig,
double  iNoise 
)

Definition at line 10 of file PulseShapeFitOOTPileupCorrection.cc.

References acc25nsVec, accVarLenIdxMinusOneVec, accVarLenIdxZEROVec, addPulseJitter_, diff25nsItvlVec, diffVarItvlIdxMinusOneVec, diffVarItvlIdxZEROVec, i, invertpedSig2_, invertpedSig_, inverttimeSig2_, inverttimeSig_, j, HcalConst::maxPSshapeBin, HcalConst::maxSamples, noise_, HcalConst::nsPerBX, pedestalConstraint_, pedMean_, pedSig_, psFit_erry, psFit_erry2, psFit_slew, psFit_x, psFit_y, pulse_hist, pulseJitter_, timeConstraint_, timeMean_, timeShift_, and timeSig_.

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  timeMean_ = iTimeMean;
52  timeSig_ = iTimeSig;
53  pedMean_ = iPedMean;
54  pedSig_ = iPedSig;
55  noise_ = iNoise;
56  timeShift_ = 100.;
57  timeShift_ += 12.5;//we are trying to get BX
58 
63  }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
std::array< float, HcalConst::maxPSshapeBin > pulse_hist
FitterFuncs::PulseShapeFunctor::~PulseShapeFunctor ( )

Definition at line 106 of file PulseShapeFitOOTPileupCorrection.cc.

106  {
107  }

Member Function Documentation

double FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc ( const double *  x)
double FitterFuncs::PulseShapeFunctor::EvalPulse ( const double *  pars,
unsigned int  nPar 
)

Definition at line 109 of file PulseShapeFitOOTPileupCorrection.cc.

References addPulseJitter_, cntNANinfit, constexpr, funcHPDShape(), i, HcalConst::invertnsPerBx, invertpedSig2_, inverttimeSig2_, edm::isNotFinite(), j, HcalConst::maxSamples, pileupCalc::nbins, HcalConst::nsPerBX, pedestalConstraint_, pedMean_, psFit_erry, psFit_erry2, psFit_slew, psFit_y, pulse_shape_, pulse_shape_sum_, pulseJitter_, cond::rpcobgas::time, timeConstraint_, timeMean_, and timeShift_.

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

109  {
110  constexpr unsigned nbins = (unsigned) HcalConst::maxSamples;
111  unsigned i =0, j=0;
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  unsigned int parBy2=(nPars-1)/2;
118  // std::array<float,HcalConst::maxSamples> pulse_shape_;
119 
120  if(addPulseJitter_) {
122  //Interpolate the fit (Quickly)
123  funcHPDShape(pulse_shape_, pars[0],pars[1],psFit_slew[time]);
124  for (j=0; j<nbins; ++j) {
126  pulse_shape_sum_[j] = pulse_shape_[j] + pars[nPars-1];
127  }
128 
129  i=1;
130  while (i<parBy2) {
131  time = (pars[i*2]+timeShift_-timeMean_)*HcalConst::invertnsPerBx;
132  //Interpolate the fit (Quickly)
133  funcHPDShape(pulse_shape_, pars[i+2],pars[i*2+1],psFit_slew[time]);
134  // add an uncertainty from the pulse (currently noise * pulse height =>Ecal uses full cov)
136  for (j=0; j<nbins; ++j) {
139  }
140  i++;
141  }
142  }
143  else{
144  int time = (pars[0]+timeShift_-timeMean_)*HcalConst::invertnsPerBx;
145  //Interpolate the fit (Quickly)
146  funcHPDShape(pulse_shape_, pars[0],pars[1],psFit_slew[time]);
147  for(j=0; j<nbins; ++j)
148  pulse_shape_sum_[j] = pulse_shape_[j] + pars[nPars-1];
149 
150  i=1;
151  while (i<parBy2) {
152  time = (pars[i*2]+timeShift_-timeMean_)*HcalConst::invertnsPerBx;
153  //Interpolate the fit (Quickly)
154  funcHPDShape(pulse_shape_, pars[i*2],pars[i*2+1],psFit_slew[time]);
155  // add an uncertainty from the pulse (currently noise * pulse height =>Ecal uses full cov)
156  for(j=0; j<nbins; ++j)
158  i++;
159  }
160  }
161 
162  for (i=0;i<nbins; ++i)
163  chisq += (psFit_y[i]- pulse_shape_sum_[i])*(psFit_y[i]- pulse_shape_sum_[i])/psFit_erry2[i];
164 
165  if(pedestalConstraint_) {
166  //Add the pedestal Constraint to chi2
167  chisq += invertpedSig2_*(pars[nPars-1] - pedMean_)*(pars[nPars-1]- pedMean_);
168  }
169  //Add the time Constraint to chi2
170  if(timeConstraint_) {
171  for(j=0; j< parBy2; ++j ){
172  int time = (pars[j*2]+timeShift_-timeMean_)*(double)HcalConst::invertnsPerBx;
173  double time1 = -100.+time*HcalConst::nsPerBX;
174  chisq += inverttimeSig2_*(pars[j*2] - timeMean_ - time1)*(pars[j*2] - timeMean_ - time1);
175  }
176  }
177  return chisq;
178  }
int i
Definition: DBlmapReader.cc:9
std::array< float, HcalConst::maxSamples > pulse_shape_sum_
std::array< float, HcalConst::maxSamples > pulse_shape_
#define constexpr
void funcHPDShape(std::array< float, HcalConst::maxSamples > &ntmpbin, const double &pulseTime, const double &pulseHeight, const double &slew)
bool isNotFinite(T x)
Definition: isFinite.h:10
int j
Definition: DBlmapReader.cc:9
void FitterFuncs::PulseShapeFunctor::funcHPDShape ( std::array< float, HcalConst::maxSamples > &  ntmpbin,
const double &  pulseTime,
const double &  pulseHeight,
const double &  slew 
)
private

Definition at line 65 of file PulseShapeFitOOTPileupCorrection.cc.

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

Referenced by EvalPulse().

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

Definition at line 47 of file PulseShapeFitOOTPileupCorrection.h.

References i, HcalConst::maxSamples, and psFit_erry.

47 { for(int i=0; i<HcalConst::maxSamples; ++i) psFit_erry [i] = erry [i]; }
int i
Definition: DBlmapReader.cc:9
void FitterFuncs::PulseShapeFunctor::setpsFiterry2 ( double *  erry2)
inline

Definition at line 48 of file PulseShapeFitOOTPileupCorrection.h.

References i, HcalConst::maxSamples, and psFit_erry2.

48 { for(int i=0; i<HcalConst::maxSamples; ++i) psFit_erry2 [i] = erry2[i]; }
int i
Definition: DBlmapReader.cc:9
void FitterFuncs::PulseShapeFunctor::setpsFitslew ( double *  slew)
inline

Definition at line 49 of file PulseShapeFitOOTPileupCorrection.h.

References i, HcalConst::maxSamples, and psFit_slew.

49 { for(int i=0; i<HcalConst::maxSamples; ++i) {psFit_slew [i] = slew [i]; } }
int i
Definition: DBlmapReader.cc:9
void FitterFuncs::PulseShapeFunctor::setpsFitx ( double *  x)
inline

Definition at line 45 of file PulseShapeFitOOTPileupCorrection.h.

References i, HcalConst::maxSamples, and psFit_x.

45 { for(int i=0; i<HcalConst::maxSamples; ++i) psFit_x[i] = x[i]; }
int i
Definition: DBlmapReader.cc:9
void FitterFuncs::PulseShapeFunctor::setpsFity ( double *  y)
inline

Definition at line 46 of file PulseShapeFitOOTPileupCorrection.h.

References i, HcalConst::maxSamples, and psFit_y.

46 { for(int i=0; i<HcalConst::maxSamples; ++i) psFit_y[i] = y[i]; }
int i
Definition: DBlmapReader.cc:9
double FitterFuncs::PulseShapeFunctor::sigma ( double  ifC)

Definition at line 192 of file PulseShapeFitOOTPileupCorrection.cc.

References alignCSCRings::e.

192  {
193  if(ifC < 75) return (0.577 + 0.0686*ifC)/3.;
194  return (2.75 + 0.0373*ifC + 3e-6*ifC*ifC)/3.;
195  }
double FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc ( const double *  x)
double FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc ( const double *  x)

Member Data Documentation

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

Definition at line 59 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by funcHPDShape(), and PulseShapeFunctor().

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

Definition at line 61 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by funcHPDShape(), and PulseShapeFunctor().

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

Definition at line 60 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by funcHPDShape(), and PulseShapeFunctor().

bool FitterFuncs::PulseShapeFunctor::addPulseJitter_
private

Definition at line 67 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

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

Definition at line 59 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by funcHPDShape(), and PulseShapeFunctor().

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

Definition at line 61 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by funcHPDShape(), and PulseShapeFunctor().

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

Definition at line 60 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by funcHPDShape(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::invertpedSig2_
private

Definition at line 78 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::invertpedSig_
private

Definition at line 78 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::inverttimeSig2_
private

Definition at line 77 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::inverttimeSig_
private

Definition at line 77 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::noise_
private

Definition at line 74 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by PulseShapeFunctor().

bool FitterFuncs::PulseShapeFunctor::pedestalConstraint_
private

Definition at line 65 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::pedMean_
private

Definition at line 72 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::pedSig_
private

Definition at line 73 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by PulseShapeFunctor().

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

Definition at line 63 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), PulseShapeFunctor(), and setpsFiterry().

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

Definition at line 63 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), PulseShapeFunctor(), and setpsFiterry2().

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

Definition at line 63 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), PulseShapeFunctor(), and setpsFitslew().

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

Definition at line 63 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by PulseShapeFunctor(), and setpsFitx().

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

Definition at line 63 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), PulseShapeFunctor(), and setpsFity().

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

Definition at line 56 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by PulseShapeFunctor().

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

Definition at line 79 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse().

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

Definition at line 80 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse().

double FitterFuncs::PulseShapeFunctor::pulseJitter_
private

Definition at line 69 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

bool FitterFuncs::PulseShapeFunctor::timeConstraint_
private

Definition at line 66 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::timeMean_
private

Definition at line 70 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::timeShift_
private

Definition at line 75 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by EvalPulse(), and PulseShapeFunctor().

double FitterFuncs::PulseShapeFunctor::timeSig_
private

Definition at line 71 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by PulseShapeFunctor().

bool FitterFuncs::PulseShapeFunctor::unConstrainedFit_
private

Definition at line 68 of file PulseShapeFitOOTPileupCorrection.h.