CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDeterministicFit.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 #include <climits>
5 #include "TMath.h"
6 
7 using namespace std;
8 
10 }
11 
13 }
14 
16  fTimeSlew=tsParam;
17  fTimeSlewBias=bias;
18  fNegStrat=nStrat;
19  fPedestalSubFxn_=pedSubFxn_;
20 }
21 void HcalDeterministicFit::apply(const CaloSamples & cs, const std::vector<int> & capidvec, const HcalCalibrations & calibs, std::vector<double> & HLTOutput) const {
22  std::vector<double> corrCharge;
23  std::vector<double> inputCharge;
24  std::vector<double> inputPedestal;
25  const unsigned int cssize = cs.size();
26  double gainCorr = 0;
27  for(unsigned int ip=0; ip<cssize; ++ip){
28  if( ip >= (unsigned) 10 ) continue; // Too many samples than what we wanna fit (10 is enough...) -> skip them
29  const int capid = capidvec[ip];
30  double charge = cs[ip];
31  double ped = calibs.pedestal(capid);
32  double gain = calibs.respcorrgain(capid);
33  gainCorr = gain;
34  inputCharge.push_back(charge);
35  inputPedestal.push_back(ped);
36  }
37 
38  fPedestalSubFxn_.calculate(inputCharge, inputPedestal, corrCharge);
39 
40  float tsShift3=HcalTimeSlew::delay(inputCharge[3],HcalTimeSlew::MC,fTimeSlewBias);
41  float tsShift4=HcalTimeSlew::delay(inputCharge[4],HcalTimeSlew::MC,fTimeSlewBias);
42  float tsShift5=HcalTimeSlew::delay(inputCharge[5],HcalTimeSlew::MC,fTimeSlewBias);
43 
44  // pulses are delayed by tshift. e.g. tshift = 10 means pulse is 10 seconds later
45  // landau frac moves limits of integration to the left by tsshift, which is equivalent
46  // to moving the pulse to the right
47  float i3=0;
48  getLandauFrac(-tsShift3,-tsShift3+25,i3);
49  float n3=0;
50  getLandauFrac(-tsShift3+25,-tsShift3+50,n3);
51  float nn3=0;
52  getLandauFrac(-tsShift3+50,-tsShift3+75,nn3);
53 
54  float i4=0;
55  getLandauFrac(-tsShift4,-tsShift4+25,i4);
56  float n4=0;
57  getLandauFrac(-tsShift4+25,-tsShift4+50,n4);
58 
59  float i5=0;
60  getLandauFrac(-tsShift5,-tsShift5+25,i5);
61  float n5=0;
62  getLandauFrac(-tsShift5+25,-tsShift5+50,n5);
63 
64  float ch3=corrCharge[3]/i3;
65  float ch4=(i3*corrCharge[4]-n3*corrCharge[3])/(i3*i4);
66  float ch5=(n3*n4*corrCharge[3]-i4*nn3*corrCharge[3]-i3*n4*corrCharge[4]+i3*i4*corrCharge[5])/(i3*i4*i5);
67 
68  if (ch3<-3 && fNegStrat==HcalDeterministicFit::ReqPos) {
69  ch3=-3;
70  ch4=corrCharge[4]/i4;
71  ch5=(i4*corrCharge[5]-n4*corrCharge[4])/(i4*i5);
72  }
73 
74  if (ch5<-3 && fNegStrat==HcalDeterministicFit::ReqPos) {
75  ch4=ch4+(ch5+3);
76  ch5=-3;
77  }
78 
79  if (fNegStrat==HcalDeterministicFit::FromGreg) {
80  if (ch3<-3) {
81  ch3=-3;
82  ch4=corrCharge[4]/i4;
83  ch5=(i4*corrCharge[5]-n4*corrCharge[4])/(i4*i5);
84  }
85  if (ch5<-3 && ch4>15) {
86  double ratio = (corrCharge[4]-ch3*i3)/(corrCharge[5]+3*i5);
87  if (ratio < 5 && ratio > 0.5) {
88  double invG = -13.11+11.29*TMath::Sqrt(2*TMath::Log(5.133/ratio));
89  float iG=0;
90  getLandauFrac(-invG,-invG+25,iG);
91  ch4=(corrCharge[4]-ch3*n3)/(iG);
92  ch5=-3;
93  tsShift4=invG;
94  }
95  }
96  }
97 
98  if (ch3<1) {// && (fNegStrat==HcalDeterministicFit::ReqPos || fNegStrat==HcalDeterministicFit::FromGreg)) {
99  ch3=0;
100  }
101  if (ch4<1) {// && (fNegStrat==HcalDeterministicFit::ReqPos || fNegStrat==HcalDeterministicFit::FromGreg)) {
102  ch4=0;
103  }
104  if (ch5<1) {// && (fNegStrat==HcalDeterministicFit::ReqPos || fNegStrat==HcalDeterministicFit::FromGreg)) {
105  ch5=0;
106  }
107 
108  // Print out
109  HLTOutput.clear();
110  HLTOutput.push_back(ch4*gainCorr);// amplitude
111  HLTOutput.push_back(tsShift4); // time shift of in-time pulse
112  HLTOutput.push_back(ch5); // whatever
113 
114 }
115 
116 void HcalDeterministicFit::applyXM(const std::vector<double> & inputCharge, const std::vector<double> & inputPedestal, std::vector<double> & HLTOutput) const {
117 
118  std::vector<double> corrCharge;
119  fPedestalSubFxn_.calculate(inputCharge, inputPedestal, corrCharge);
120 
121  double TS35[3];
122  double TS46[3];
123  double TS57[3];
124  pulseFraction(inputCharge[3], TS35);
125  pulseFraction(inputCharge[4], TS46);
126  pulseFraction(inputCharge[5], TS57);
127 
128  double a3[3] = {TS35[0], TS35[1], TS35[2]};
129  double b3[3] = {0., TS46[0], TS46[1]};
130  double c3[3] = {0., 0., TS57[0]};
131  double d3[3] = {corrCharge[3], corrCharge[4], corrCharge[5]};
132 
133  double deno3 = det3(a3, b3, c3);
134 
135  double A3 = det3(d3, b3, c3) / deno3;
136  double A4 = det3(a3, d3, c3) / deno3;
137  double A5 = det3(a3, b3, d3) / deno3;
138 
139  HLTOutput.clear();
140  HLTOutput.push_back(A3);
141  HLTOutput.push_back(A4);
142  HLTOutput.push_back(A5);
143 
144 }
145 
147 // Landau function integrated in 1 ns intervals
148 //Landau pulse shape from https://indico.cern.ch/event/345283/contribution/3/material/slides/0.pdf
149 //Landau turn on by default at left edge of time slice
150 // normalized to 1 on [0,10000]
151 void HcalDeterministicFit::getLandauFrac(float tStart, float tEnd, float &sum) const{
152 
153  if (std::abs(tStart-tEnd-25)<0.1) {
154  sum=0;
155  return;
156  }
157  sum= landauFrac[int(ceil(tStart+25))];
158  return;
159 }
160 
164 
165 void HcalDeterministicFit::pulseFraction(const double fC, double *TS46) const{
166 
167  double tslew = -HcalTimeSlew::delay(fC,HcalTimeSlew::MC,fTimeSlewBias);
168 
169  TS46[0] = TS4par[0] * TMath::Gaus(tslew,TS4par[1],TS4par[2]); // fraction of pulse in the TS4
170  TS46[1] = TS5par[0] + TS5par[1]*tslew + TS5par[2]*tslew*tslew; // fraction of pulse in the T5S
171  TS46[2] = TS6par[0] + TS6par[1]*tslew + TS6par[2]*tslew*tslew + TS6par[3]*tslew*tslew*tslew; //fraction of pulse in the TS6
172 
173  return;
174 }
175 
176 double HcalDeterministicFit::det2(double *b, double *c) const{
177  return b[1]*c[2]-b[2]*c[1];
178 }
179 
180 double HcalDeterministicFit::det3(double *a, double *b, double *c) const{
181  return a[0]*(b[1]*c[2]-b[2]*c[1])-a[1]*(b[0]*c[2]-b[2]*c[0])+a[2]*(b[0]*c[1]-b[1]*c[0]);
182 }
double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3
auto_ptr< ClusterSequence > cs
double pedestal(int fCapId) const
get pedestal for capid=0..3
void applyXM(const std::vector< double > &inputCharge, const std::vector< double > &inputPedestal, std::vector< double > &HLTOutput) const
#define constexpr
double det2(double *b, double *c) const
void apply(const CaloSamples &cs, const std::vector< int > &capidvec, const HcalCalibrations &calibs, std::vector< double > &HLTOutput) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void getLandauFrac(float tStart, float tEnd, float &sum) const
double det3(double *a, double *b, double *c) const
void init(HcalTimeSlew::ParaSource tsParam, HcalTimeSlew::BiasSetting bias, NegStrategy nStrat, PedestalSub pedSubFxn_)
void pulseFraction(const double fC, double *TS46) const
int size() const
get the size
Definition: CaloSamples.h:24
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
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:8