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 std::vector< double > &pars)
 
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
 
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;
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 102 of file PulseShapeFitOOTPileupCorrection.cc.

102  {
103  }

Member Function Documentation

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

Definition at line 156 of file PulseShapeFitOOTPileupCorrection.cc.

References EvalPulse().

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

156  {
157  std::vector<double> pars(x, x+5);
158  return EvalPulse(pars);
159  }
double EvalPulse(const std::vector< double > &pars)
Definition: DDAxes.h:10
double FitterFuncs::PulseShapeFunctor::EvalPulse ( const std::vector< double > &  pars)

Definition at line 105 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, pulseJitter_, cond::rpcobgas::time, timeConstraint_, timeMean_, and timeShift_.

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

105  {
106  constexpr unsigned nbins = (unsigned) HcalConst::maxSamples;
107  unsigned i =0, j=0;
108  //Stop crashes
109  for(i =0; i < pars.size(); ++i ) if( edm::isNotFinite(pars[i]) ){ ++ cntNANinfit; return 1e10; }
110 
111  //calculate chisquare
112  double chisq = 0;
113  double delta2 =0;
114  std::array<float,HcalConst::maxSamples> pulse_shape_sum;
115  for(i=0; i < (pars.size()-1)/2; ++i ){
117  //Interpolate the fit (Quickly)
118  std::array<float,HcalConst::maxSamples> pulse_shape;
119  funcHPDShape(pulse_shape, pars[i*2],pars[i*2+1],psFit_slew[time]);
120  // add an uncertainty from the pulse (currently noise * pulse height =>Ecal uses full cov)
121  if(addPulseJitter_) {
122  for (j=0; j<nbins; ++j) {
123  if( i==0 ) psFit_erry2[j] = psFit_erry[j]*psFit_erry[j];
124  psFit_erry2[j] += pulse_shape[j]*pulse_shape[j]*pulseJitter_*pulseJitter_;
125  }
126  }
127  for(j=0; j<nbins; ++j){
128  if( i==0 ) pulse_shape_sum[j] = pulse_shape[j] + pars.back();
129  else pulse_shape_sum[j] += pulse_shape[j];
130  }
131  }
132  for (i=0;i<nbins; ++i) {
133  delta2 = (psFit_y[i]- pulse_shape_sum[i])*(psFit_y[i]- pulse_shape_sum[i])/psFit_erry2[i];
134  chisq += delta2;
135  }
136  //Add the pedestal Constraint to chi2
137  if(pedestalConstraint_) {
138  chisq += invertpedSig2_*(pars.back() - pedMean_)*(pars.back()- pedMean_);
139  }
140  //Add the time Constraint to chi2
141  if(timeConstraint_) {
142  for(j=0; j< (pars.size()-1)/2; ++j ){
143  int time = (pars[j*2]+timeShift_-timeMean_)/(double)HcalConst::nsPerBX;
144  double time1 = -100.+time*HcalConst::nsPerBX;
145  chisq += inverttimeSig2_*(pars[j*2] - timeMean_ - time1)*(pars[j*2] - timeMean_ - time1);
146  }
147  }
148  return chisq;
149  }
int i
Definition: DBlmapReader.cc:9
#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  // zeroing output binned pulse shape
71  ntmpbin = { {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f} };
72  //Get the starting time
73  int i_start = ( -HcalConst::iniTimeShift - pulseTime - slew >0 ? 0 : (int)std::abs(-HcalConst::iniTimeShift-pulseTime-slew) + 1);
74  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;
75  if( offset_start == 1.0 ){ offset_start = 0.; i_start-=1; } //Deal with boundary
76  const int bin_start = (int) offset_start; //bin off to integer
77  const int bin_0_start = ( offset_start < bin_start + 0.5 ? bin_start -1 : bin_start ); //Round it
78  const int iTS_start = i_start/ns_per_bx; //Time Slice for time shift
79  const int distTo25ns_start = HcalConst::nsPerBX - 1 - i_start%ns_per_bx; //Delta ns
80  const double factor = offset_start - bin_0_start - 0.5; //Small correction?
81 
82  if( edm::isNotFinite(offset_start) ){ //Check for nan
83  ++ cntNANinfit;
84  }else{
85  //Build the new pulse
86  ntmpbin[iTS_start] = (bin_0_start == -1 ? // Initial bin (I'm assuming this is ok)
87  accVarLenIdxMinusOneVec[distTo25ns_start] + factor * diffVarItvlIdxMinusOneVec[distTo25ns_start]
88  : accVarLenIdxZEROVec [distTo25ns_start] + factor * diffVarItvlIdxZEROVec [distTo25ns_start]);
89  //Fill the rest of the bins
90  for(int iTS = iTS_start+1; iTS < num_bx; ++iTS){
91  int bin_idx = distTo25ns_start + 1 + (iTS-iTS_start-1)*ns_per_bx + bin_0_start;
92  ntmpbin[iTS] = acc25nsVec[bin_idx] + factor * diff25nsItvlVec[bin_idx];
93  }
94  }
95  //Scale the pulse
96  for(int i=0; i < num_bx; ++i) {
97  ntmpbin[i] *= pulseHeight;
98  }
99  return;
100  }
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
Definition: DDAxes.h:10
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 166 of file PulseShapeFitOOTPileupCorrection.cc.

References alignCSCRings::e.

166  {
167  if(ifC < 75) return (0.577 + 0.0686*ifC)/3.;
168  return (2.75 + 0.0373*ifC + 3e-6*ifC*ifC)/3.;
169  }
double FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc ( const double *  x)

Definition at line 151 of file PulseShapeFitOOTPileupCorrection.cc.

References EvalPulse().

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

151  {
152  std::vector<double> pars(x, x+3);
153  return EvalPulse(pars);
154  }
double EvalPulse(const std::vector< double > &pars)
Definition: DDAxes.h:10
double FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc ( const double *  x)

Definition at line 161 of file PulseShapeFitOOTPileupCorrection.cc.

References EvalPulse().

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

161  {
162  std::vector<double> pars(x, x+7);
163  return EvalPulse(pars);
164  }
double EvalPulse(const std::vector< double > &pars)
Definition: DDAxes.h:10

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().

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.