CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDeterministicFit.h
Go to the documentation of this file.
1 #ifndef HcalDeterministicFit_h
2 #define HcalDeterministicFit_h 1
3 
4 #include <typeinfo>
5 #include <vector>
6 
9 
21 
22 
24  public:
28 
29  void init(HcalTimeSlew::ParaSource tsParam, HcalTimeSlew::BiasSetting bias, NegStrategy nStrat, PedestalSub pedSubFxn_, std::vector<double> pars);
30 
31  // This is the CMSSW Implementation of the apply function
32  template<class Digi>
33  void apply(const CaloSamples & cs, const std::vector<int> & capidvec, const HcalCalibrations & calibs, const Digi & digi, std::vector<double> & Output) const;
34  void getLandauFrac(float tStart, float tEnd, float &sum) const;
35 
36  private:
41 
42  double fpars[6];
43 
44  static constexpr int HcalRegion[2] = {16, 17};
45  static constexpr int tswidth = 25;
46  static constexpr float negthre[2] = {-3., 15.};
47  static constexpr float invGpar[3] = {-13.11, 11.29, 5.133};
48  static constexpr float landauFrac[] {0, 7.6377e-05, 0.000418655, 0.00153692, 0.00436844, 0.0102076,
49  0.0204177, 0.0360559, 0.057596, 0.0848493, 0.117069, 0.153152, 0.191858, 0.23198, 0.272461, 0.312438,
50  0.351262, 0.388476, 0.423788, 0.457036, 0.488159, 0.517167, 0.54412, 0.569112, 0.592254, 0.613668,
51  0.633402, 0.651391, 0.667242, 0.680131, 0.688868, 0.692188, 0.689122, 0.67928, 0.662924, 0.64087,
52  0.614282, 0.584457, 0.552651, 0.51997, 0.487317, 0.455378, 0.424647, 0.395445, 0.367963, 0.342288,
53  0.318433, 0.29636, 0.275994, 0.257243, 0.24, 0.224155, 0.2096, 0.196227, 0.183937, 0.172635,
54  0.162232, 0.15265, 0.143813, 0.135656, 0.128117, 0.12114, 0.114677, 0.108681, 0.103113, 0.0979354,
55  0.0931145, 0.0886206, 0.0844264, 0.0805074, 0.0768411, 0.0734075, 0.0701881, 0.0671664, 0.0643271,
56  0.0616564, 0.0591418, 0.0567718, 0.054536, 0.0524247, 0.0504292, 0.0485414, 0.046754, 0.0450602,
57  0.0434538, 0.041929, 0.0404806, 0.0391037, 0.0377937, 0.0365465, 0.0353583, 0.0342255, 0.0331447,
58  0.032113, 0.0311274, 0.0301854, 0.0292843, 0.0284221, 0.0275964, 0.0268053, 0.0253052, 0.0238536,
59  0.0224483, 0.0210872, 0.0197684, 0.0184899, 0.01725, 0.0160471, 0.0148795, 0.0137457, 0.0126445,
60  0.0115743, 0.0105341, 0.00952249, 0.00853844, 0.00758086, 0.00664871,0.00574103, 0.00485689, 0.00399541,
61  0.00315576, 0.00233713, 0.00153878, 0.000759962, 0 };
62 };
63 
64 template<class Digi>
65 void HcalDeterministicFit::apply(const CaloSamples & cs, const std::vector<int> & capidvec, const HcalCalibrations & calibs, const Digi & digi, std::vector<double> & Output) const {
66  std::vector<double> corrCharge;
67  std::vector<double> inputCharge;
68  std::vector<double> inputPedestal;
69  double gainCorr = 0;
70 
71  for(int ip=0; ip<cs.size(); ip++){
72  const int capid = capidvec[ip];
73  double charge = cs[ip];
74  double ped = calibs.pedestal(capid);
75  double gain = calibs.respcorrgain(capid);
76  gainCorr = gain;
77  inputCharge.push_back(charge);
78  inputPedestal.push_back(ped);
79  }
80 
81  fPedestalSubFxn_.calculate(inputCharge, inputPedestal, corrCharge);
82 
83  const HcalDetId& cell = digi.id();
84  double fpar0, fpar1;
85  if(std::abs(cell.ieta())<HcalRegion[0]){
86  fpar0 = fpars[0];
87  fpar1 = fpars[1];
88  }else if(std::abs(cell.ieta())==HcalRegion[0]||std::abs(cell.ieta())==HcalRegion[1]){
89  fpar0 = fpars[2];
90  fpar1 = fpars[3];
91  }else{
92  fpar0 = fpars[4];
93  fpar1 = fpars[5];
94  }
95 
96  float tsShift3=HcalTimeSlew::delay(inputCharge[3],fTimeSlew,fTimeSlewBias, fpar0, fpar1);
97  float tsShift4=HcalTimeSlew::delay(inputCharge[4],fTimeSlew,fTimeSlewBias, fpar0, fpar1);
98  float tsShift5=HcalTimeSlew::delay(inputCharge[5],fTimeSlew,fTimeSlewBias, fpar0, fpar1);
99 
100  float i3=0;
101  getLandauFrac(-tsShift3,-tsShift3+tswidth,i3);
102  float n3=0;
103  getLandauFrac(-tsShift3+tswidth,-tsShift3+tswidth*2,n3);
104  float nn3=0;
105  getLandauFrac(-tsShift3+tswidth*2,-tsShift3+tswidth*3,nn3);
106 
107  float i4=0;
108  getLandauFrac(-tsShift4,-tsShift4+tswidth,i4);
109  float n4=0;
110  getLandauFrac(-tsShift4+tswidth,-tsShift4+tswidth*2,n4);
111 
112  float i5=0;
113  getLandauFrac(-tsShift5,-tsShift5+tswidth,i5);
114  float n5=0;
115  getLandauFrac(-tsShift5+tswidth,-tsShift5+tswidth*2,n5);
116 
117  float ch3=corrCharge[3]/i3;
118  float ch4=(i3*corrCharge[4]-n3*corrCharge[3])/(i3*i4);
119  float ch5=(n3*n4*corrCharge[3]-i4*nn3*corrCharge[3]-i3*n4*corrCharge[4]+i3*i4*corrCharge[5])/(i3*i4*i5);
120 
122  ch3=negthre[0];
123  ch4=corrCharge[4]/i4;
124  ch5=(i4*corrCharge[5]-n4*corrCharge[4])/(i4*i5);
125  }
126 
128  ch4=ch4+(ch5-negthre[0]);
129  ch5=negthre[0];
130  }
131 
133  if (ch3<negthre[0]) {
134  ch3=negthre[0];
135  ch4=corrCharge[4]/i4;
136  ch5=(i4*corrCharge[5]-n4*corrCharge[4])/(i4*i5);
137  }
138  if (ch5<negthre[0] && ch4>negthre[1]) {
139  double ratio = (corrCharge[4]-ch3*i3)/(corrCharge[5]-negthre[0]*i5);
140  if (ratio < 5 && ratio > 0.5) {
141  double invG = invGpar[0]+invGpar[1]*std::sqrt(2*std::log(invGpar[2]/ratio));
142  float iG=0;
143  getLandauFrac(-invG,-invG+tswidth,iG);
144  ch4=(corrCharge[4]-ch3*n3)/(iG);
145  ch5=negthre[0];
146  tsShift4=invG;
147  }
148  }
149  }
150 
151  if (ch3<1) {
152  ch3=0;
153  }
154  if (ch4<1) {
155  ch4=0;
156  }
157  if (ch5<1) {
158  ch5=0;
159  }
160  Output.clear();
161  Output.push_back(ch4*gainCorr);// amplitude
162  Output.push_back(tsShift4); // time shift of in-time pulse
163  Output.push_back(ch5); // whatever
164 
165 }
166 
167 
168 #endif // HLTAnalyzer_h
double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3
void apply(const CaloSamples &cs, const std::vector< int > &capidvec, const HcalCalibrations &calibs, const Digi &digi, std::vector< double > &Output) const
auto_ptr< ClusterSequence > cs
void init(HcalTimeSlew::ParaSource tsParam, HcalTimeSlew::BiasSetting bias, NegStrategy nStrat, PedestalSub pedSubFxn_, std::vector< double > pars)
double pedestal(int fCapId) const
get pedestal for capid=0..3
#define constexpr
HcalTimeSlew::ParaSource fTimeSlew
T sqrt(T t)
Definition: SSEVec.h:48
int ieta() const
get the cell ieta
Definition: HcalDetId.h:51
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void getLandauFrac(float tStart, float tEnd, float &sum) const
void calculate(const std::vector< double > &inputCharge, const std::vector< double > &inputPedestal, std::vector< double > &corrCharge) const
Definition: PedestalSub.cc:21
int size() const
get the size
Definition: CaloSamples.h:24
#define Output(cl)
Definition: vmac.h:192
HcalTimeSlew::BiasSetting fTimeSlewBias
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:11