CMS 3D CMS Logo

HcalDeterministicFit.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 #include <climits>
5 
11 
12 using namespace std;
13 
15 }
16 
18 }
19 
20 void HcalDeterministicFit::init(HcalTimeSlew::ParaSource tsParam, HcalTimeSlew::BiasSetting bias, bool iApplyTimeSlew, PedestalSub pedSubFxn_, std::vector<double> pars, double respCorr) {
21  for(int fi=0; fi<9; fi++){
22  fpars[fi] = pars.at(fi);
23  }
24 
25  applyTimeSlew_=iApplyTimeSlew;
26  fTimeSlew=tsParam;
27  fTimeSlewBias=bias;
28  fPedestalSubFxn_=pedSubFxn_;
29  frespCorr=respCorr;
30 
31 }
32 
34 // Landau function integrated in 1 ns intervals
35 //Landau pulse shape from https://indico.cern.ch/event/345283/contribution/3/material/slides/0.pdf
36 //Landau turn on by default at left edge of time slice
37 // normalized to 1 on [0,10000]
38 void HcalDeterministicFit::getLandauFrac(float tStart, float tEnd, float &sum) const{
39 
40  if (std::abs(tStart-tEnd-tsWidth)<0.1) {
41  sum=0;
42  return;
43  }
44  sum= landauFrac[int(ceil(tStart+tsWidth))];
45  return;
46 }
47 
49  float& reconstructedEnergy,
50  float& reconstructedTime) const
51 {
52 
53  std::vector<double> corrCharge;
54  std::vector<double> inputCharge;
55  std::vector<double> inputPedestal;
56  double gainCorr = 0;
57  double respCorr = 0;
58 
59  for(unsigned int ip=0; ip<channelData.nSamples(); ip++){
60 
61  double charge = channelData.tsRawCharge(ip);
62  double ped = channelData.tsPedestal(ip);
63  double gain = channelData.tsGain(ip);
64 
65  gainCorr = gain;
66  inputCharge.push_back(charge);
67  inputPedestal.push_back(ped);
68 
69  }
70 
71  fPedestalSubFxn_.calculate(inputCharge, inputPedestal, corrCharge);
72 
73  const HcalDetId& cell = channelData.id();
74 
75  double fpar0, fpar1, fpar2;
76  if(std::abs(cell.ieta())<HcalRegion[0]){
77  fpar0 = fpars[0];
78  fpar1 = fpars[1];
79  fpar2 = fpars[2];
80  }else if(std::abs(cell.ieta())==HcalRegion[0]||std::abs(cell.ieta())==HcalRegion[1]){
81  fpar0 = fpars[3];
82  fpar1 = fpars[4];
83  fpar2 = fpars[5];
84  }else{
85  fpar0 = fpars[6];
86  fpar1 = fpars[7];
87  fpar2 = fpars[8];
88  }
89 
90  if (fTimeSlew==0)respCorr=1.0;
91  else if (fTimeSlew==1) channelData.hasTimeInfo()?respCorr=rCorrSiPM[0]:respCorr=rCorr[0];
92  else if (fTimeSlew==2) channelData.hasTimeInfo()?respCorr=rCorrSiPM[1]:respCorr=rCorr[1];
93  else if (fTimeSlew==3)respCorr=frespCorr;
94 
95  float tsShift3=0;
96  float tsShift4=0;
97  float tsShift5=0;
98 
99  if(applyTimeSlew_) {
100 
101  tsShift3=HcalTimeSlew::delay(inputCharge[3], fTimeSlew, fTimeSlewBias, fpar0, fpar1 ,fpar2,!channelData.hasTimeInfo());
102  tsShift4=HcalTimeSlew::delay(inputCharge[4], fTimeSlew, fTimeSlewBias, fpar0, fpar1 ,fpar2,!channelData.hasTimeInfo());
103  tsShift5=HcalTimeSlew::delay(inputCharge[5], fTimeSlew, fTimeSlewBias, fpar0, fpar1 ,fpar2,!channelData.hasTimeInfo());
104 
105  }
106 
107  float i3=0;
108  getLandauFrac(-tsShift3,-tsShift3+tsWidth,i3);
109  float n3=0;
110  getLandauFrac(-tsShift3+tsWidth,-tsShift3+tsWidth*2,n3);
111  float nn3=0;
112  getLandauFrac(-tsShift3+tsWidth*2,-tsShift3+tsWidth*3,nn3);
113 
114  float i4=0;
115  getLandauFrac(-tsShift4,-tsShift4+tsWidth,i4);
116  float n4=0;
117  getLandauFrac(-tsShift4+tsWidth,-tsShift4+tsWidth*2,n4);
118 
119  float i5=0;
120  getLandauFrac(-tsShift5,-tsShift5+tsWidth,i5);
121  float n5=0;
122  getLandauFrac(-tsShift5+tsWidth,-tsShift5+tsWidth*2,n5);
123 
124  float ch3=0;
125  float ch4=0;
126  float ch5=0;
127 
128  if (i3 != 0 && i4 != 0 && i5 != 0) {
129 
130  ch3=corrCharge[3]/i3;
131  ch4=(i3*corrCharge[4]-n3*corrCharge[3])/(i3*i4);
132  ch5=(n3*n4*corrCharge[3]-i4*nn3*corrCharge[3]-i3*n4*corrCharge[4]+i3*i4*corrCharge[5])/(i3*i4*i5);
133 
134  if (ch3<negThresh[0]) {
135  ch3=negThresh[0];
136  ch4=corrCharge[4]/i4;
137  ch5=(i4*corrCharge[5]-n4*corrCharge[4])/(i4*i5);
138  }
139  if (ch5<negThresh[0] && ch4>negThresh[1]) {
140  double ratio = (corrCharge[4]-ch3*i3)/(corrCharge[5]-negThresh[0]*i5);
141  if (ratio < 5 && ratio > 0.5) {
142  double invG = invGpar[0]+invGpar[1]*std::sqrt(2*std::log(invGpar[2]/ratio));
143  float iG=0;
144  getLandauFrac(-invG,-invG+tsWidth,iG);
145  if (iG != 0 ) {
146  ch4=(corrCharge[4]-ch3*n3)/(iG);
147  tsShift4=invG;
148  }
149  }
150  }
151  }
152 
153  if (ch4<1) {
154  ch4=0;
155  }
156 
157  reconstructedEnergy=ch4*gainCorr*respCorr;
158  reconstructedTime=tsShift4;
159 }
static constexpr float rCorr[2]
bool hasTimeInfo() const
double tsGain(const unsigned ts) const
static constexpr float rCorrSiPM[2]
static constexpr int HcalRegion[2]
static constexpr float landauFrac[]
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime) const
HcalDetId id() const
#define constexpr
double tsPedestal(const unsigned ts) const
double tsRawCharge(const unsigned ts) const
T sqrt(T t)
Definition: SSEVec.h:18
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void getLandauFrac(float tStart, float tEnd, float &sum) const
void init(HcalTimeSlew::ParaSource tsParam, HcalTimeSlew::BiasSetting bias, bool iApplyTimeSlew, PedestalSub pedSubFxn_, std::vector< double > pars, double respCorr)
static constexpr float negThresh[2]
unsigned nSamples() const
static double delay(double fC, BiasSetting bias=Medium)
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:16
static constexpr float invGpar[3]