CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorSimpleRecAlgo.cc
Go to the documentation of this file.
4 #include <algorithm> // for "max"
5 #include <math.h>
6 
7 static double MaximumFractionalError = 0.0005; // 0.05% error allowed from this source
8 
9 CastorSimpleRecAlgo::CastorSimpleRecAlgo(int firstSample, int samplesToAdd, bool correctForTimeslew, bool correctForPulse, float phaseNS) :
10  firstSample_(firstSample),
11  samplesToAdd_(samplesToAdd),
12  correctForTimeslew_(correctForTimeslew) {
13  if (correctForPulse)
14  pulseCorr_=std::auto_ptr<CastorPulseContainmentCorrection>(new CastorPulseContainmentCorrection(samplesToAdd_,phaseNS,MaximumFractionalError));
15 }
16 
18  firstSample_(firstSample),
19  samplesToAdd_(samplesToAdd),
20  correctForTimeslew_(false) {
21 }
22 
28 //static float timeshift_ns_hbheho(float wpksamp);
29 
31 static float timeshift_ns_hf(float wpksamp);
32 
33 
34 namespace CastorSimpleRecAlgoImpl {
35  template<class Digi, class RecHit>
36  inline RecHit reco(const Digi& digi, const CastorCoder& coder, const CastorCalibrations& calibs,
37  int ifirst, int n, bool slewCorrect, const CastorPulseContainmentCorrection* corr, CastorTimeSlew::BiasSetting slewFlavor) {
38  CaloSamples tool;
39  coder.adc2fC(digi,tool);
40 
41  double ampl=0; int maxI = -1; double maxA = -1e10; float ta=0;
42  double fc_ampl=0;
43  for (int i=ifirst; i<tool.size() && i<n+ifirst; i++) {
44  int capid=digi[i].capid();
45  ta = (tool[i]-calibs.pedestal(capid)); // pedestal subtraction
46  fc_ampl+=ta;
47  ta*=calibs.gain(capid); // fC --> GeV
48  ampl+=ta;
49  if(ta>maxA){
50  maxA=ta;
51  maxI=i;
52  }
53  }
54 
55  float time=-9999;
57  if(maxI==0 || maxI==(tool.size()-1)) {
58  // supress warning and use dummy time value for 2009 data
59  /*
60  edm::LogWarning("HCAL/CASTOR Pulse") << "CastorSimpleRecAlgo::reconstruct :"
61  << " Invalid max amplitude position, "
62  << " max Amplitude: "<< maxI
63  << " first: "<<ifirst
64  << " last: "<<(tool.size()-1)
65  << std::endl;
66  */
67  } else {
68  maxA=fabs(maxA);
69  int capid=digi[maxI-1].capid();
70  float t0 = fabs((tool[maxI-1]-calibs.pedestal(capid))*calibs.gain(capid));
71  capid=digi[maxI+1].capid();
72  float t2 = fabs((tool[maxI+1]-calibs.pedestal(capid))*calibs.gain(capid));
73  float wpksamp = (t0 + maxA + t2);
74  if (wpksamp!=0) wpksamp=(maxA + 2.0*t2) / wpksamp;
75  time = (maxI - digi.presamples())*25.0 + timeshift_ns_hf(wpksamp);
76 
77  if (corr!=0) {
78  // Apply phase-based amplitude correction:
79  ampl *= corr->getCorrection(fc_ampl);
80  // std::cout << fc_ampl << " --> " << corr->getCorrection(fc_ampl) << std::endl;
81  }
82 
83 
84  if (slewCorrect) time-=CastorTimeSlew::delay(std::max(1.0,fc_ampl),slewFlavor);
85  }
86  return RecHit(digi.id(),ampl,time);
87  }
88 }
89 
91  return CastorSimpleRecAlgoImpl::reco<CastorDataFrame,CastorRecHit>(digi,coder,calibs,
93  0,
95 }
96 
97 // timeshift implementation
98 
99 static const float wpksamp0_hf = 0.500635;
100 static const float scale_hf = 0.999301;
101 static const int num_bins_hf = 100;
102 
103 static const float actual_ns_hf[num_bins_hf] = {
104  0.00000, // 0.000-0.010
105  0.03750, // 0.010-0.020
106  0.07250, // 0.020-0.030
107  0.10750, // 0.030-0.040
108  0.14500, // 0.040-0.050
109  0.18000, // 0.050-0.060
110  0.21500, // 0.060-0.070
111  0.25000, // 0.070-0.080
112  0.28500, // 0.080-0.090
113  0.32000, // 0.090-0.100
114  0.35500, // 0.100-0.110
115  0.39000, // 0.110-0.120
116  0.42500, // 0.120-0.130
117  0.46000, // 0.130-0.140
118  0.49500, // 0.140-0.150
119  0.53000, // 0.150-0.160
120  0.56500, // 0.160-0.170
121  0.60000, // 0.170-0.180
122  0.63500, // 0.180-0.190
123  0.67000, // 0.190-0.200
124  0.70750, // 0.200-0.210
125  0.74250, // 0.210-0.220
126  0.78000, // 0.220-0.230
127  0.81500, // 0.230-0.240
128  0.85250, // 0.240-0.250
129  0.89000, // 0.250-0.260
130  0.92750, // 0.260-0.270
131  0.96500, // 0.270-0.280
132  1.00250, // 0.280-0.290
133  1.04250, // 0.290-0.300
134  1.08250, // 0.300-0.310
135  1.12250, // 0.310-0.320
136  1.16250, // 0.320-0.330
137  1.20500, // 0.330-0.340
138  1.24500, // 0.340-0.350
139  1.29000, // 0.350-0.360
140  1.33250, // 0.360-0.370
141  1.38000, // 0.370-0.380
142  1.42500, // 0.380-0.390
143  1.47500, // 0.390-0.400
144  1.52500, // 0.400-0.410
145  1.57750, // 0.410-0.420
146  1.63250, // 0.420-0.430
147  1.69000, // 0.430-0.440
148  1.75250, // 0.440-0.450
149  1.82000, // 0.450-0.460
150  1.89250, // 0.460-0.470
151  1.97500, // 0.470-0.480
152  2.07250, // 0.480-0.490
153  2.20000, // 0.490-0.500
154 19.13000, // 0.500-0.510
155 21.08750, // 0.510-0.520
156 21.57750, // 0.520-0.530
157 21.89000, // 0.530-0.540
158 22.12250, // 0.540-0.550
159 22.31000, // 0.550-0.560
160 22.47000, // 0.560-0.570
161 22.61000, // 0.570-0.580
162 22.73250, // 0.580-0.590
163 22.84500, // 0.590-0.600
164 22.94750, // 0.600-0.610
165 23.04250, // 0.610-0.620
166 23.13250, // 0.620-0.630
167 23.21500, // 0.630-0.640
168 23.29250, // 0.640-0.650
169 23.36750, // 0.650-0.660
170 23.43750, // 0.660-0.670
171 23.50500, // 0.670-0.680
172 23.57000, // 0.680-0.690
173 23.63250, // 0.690-0.700
174 23.69250, // 0.700-0.710
175 23.75000, // 0.710-0.720
176 23.80500, // 0.720-0.730
177 23.86000, // 0.730-0.740
178 23.91250, // 0.740-0.750
179 23.96500, // 0.750-0.760
180 24.01500, // 0.760-0.770
181 24.06500, // 0.770-0.780
182 24.11250, // 0.780-0.790
183 24.16000, // 0.790-0.800
184 24.20500, // 0.800-0.810
185 24.25000, // 0.810-0.820
186 24.29500, // 0.820-0.830
187 24.33750, // 0.830-0.840
188 24.38000, // 0.840-0.850
189 24.42250, // 0.850-0.860
190 24.46500, // 0.860-0.870
191 24.50500, // 0.870-0.880
192 24.54500, // 0.880-0.890
193 24.58500, // 0.890-0.900
194 24.62500, // 0.900-0.910
195 24.66500, // 0.910-0.920
196 24.70250, // 0.920-0.930
197 24.74000, // 0.930-0.940
198 24.77750, // 0.940-0.950
199 24.81500, // 0.950-0.960
200 24.85250, // 0.960-0.970
201 24.89000, // 0.970-0.980
202 24.92750, // 0.980-0.990
203 24.96250, // 0.990-1.000
204 };
205 
206 
207 float timeshift_ns_hf(float wpksamp) {
208  float flx = (num_bins_hf*(wpksamp - wpksamp0_hf)/scale_hf);
209  int index = (int)flx;
210  float yval;
211 
212  if (index < 0) return actual_ns_hf[0];
213  else if (index >= num_bins_hf-1) return actual_ns_hf[num_bins_hf-1];
214 
215  // else interpolate:
216  float y1 = actual_ns_hf[index];
217  float y2 = actual_ns_hf[index+1];
218 
219  // float delta_x = 1/(float)num_bins_hf;
220  // yval = y1 + (y2-y1)*(flx-(float)index)/delta_x;
221 
222  yval = y1 + (y2-y1)*(flx-(float)index);
223  return yval;
224 }
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...
int i
Definition: DBlmapReader.cc:9
static double MaximumFractionalError
CastorSimpleRecAlgo(int firstSample, int samplesToAdd, bool correctForTimeslew, bool correctForContainment, float fixedPhaseNs)
virtual void adc2fC(const CastorDataFrame &df, CaloSamples &lf) const =0
CastorRecHit reconstruct(const CastorDataFrame &digi, const CastorCoder &coder, const CastorCalibrations &calibs) const
static const float wpksamp0_hf
const T & max(const T &a, const T &b)
static const float actual_ns_hf[num_bins_hf]
static const float scale_hf
JetCorrectorParameters corr
Definition: classes.h:9
double pedestal(int fCapId) const
get pedestal for capid=0..3
double gain(int fCapId) const
get gain for capid=0..3
int size() const
get the size
Definition: CaloSamples.h:24
static float timeshift_ns_hf(float wpksamp)
Same as above, but for the HF PMTs.
static const int num_bins_hf
RecHit reco(const Digi &digi, const CastorCoder &coder, const CastorCalibrations &calibs, int ifirst, int n, bool slewCorrect, const CastorPulseContainmentCorrection *corr, CastorTimeSlew::BiasSetting slewFlavor)
std::auto_ptr< CastorPulseContainmentCorrection > pulseCorr_