CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ZdcSimpleRecAlgo.cc
Go to the documentation of this file.
4 #include <algorithm> // for "max"
5 #include <iostream>
6 #include <math.h>
7 
8 
9 
10 constexpr double MaximumFractionalError = 0.0005; // 0.05% error allowed from this source
11 
12 ZdcSimpleRecAlgo::ZdcSimpleRecAlgo(bool correctForTimeslew, bool correctForPulse, float phaseNS, int recoMethod, int lowGainOffset, double lowGainFrac) :
13  recoMethod_(recoMethod),
14  correctForTimeslew_(correctForTimeslew),
15  correctForPulse_(correctForPulse),
16  phaseNS_(phaseNS),
17  lowGainOffset_(lowGainOffset),
18  lowGainFrac_(lowGainFrac)
19  {
20 }
21 
23  recoMethod_(recoMethod),
24  correctForTimeslew_(false) {
25 }
27  if (correctForPulse_) {
28  pulseCorr_=std::auto_ptr<HcalPulseContainmentCorrection>(new HcalPulseContainmentCorrection(toadd,phaseNS_,MaximumFractionalError));
29  }
30 }
31 //static float timeshift_ns_zdc(float wpksamp);
32 
33 namespace ZdcSimpleRecAlgoImpl {
34  template<class Digi, class RecHit>
35  inline RecHit reco1(const Digi& digi, const HcalCoder& coder, const HcalCalibrations& calibs,
36  const std::vector<unsigned int>& myNoiseTS, const std::vector<unsigned int>& mySignalTS, int lowGainOffset, double lowGainFrac, bool slewCorrect, const HcalPulseContainmentCorrection* corr, HcalTimeSlew::BiasSetting slewFlavor) {
37  CaloSamples tool;
38  coder.adc2fC(digi,tool);
39  int ifirst = mySignalTS[0];
40  int n = mySignalTS.size();
41  double ampl=0; int maxI = -1; double maxA = -1e10; double ta=0;
42  double fc_ampl=0;
43  double lowGEnergy=0; double lowGfc_ampl=0; double TempLGAmp=0;
44 // TS increment for regular energy to lowGainEnergy
45 // Signal in higher TS (effective "low Gain") has a fraction of the whole signal
46 // This constant for fC --> GeV is dervied from 2010 PbPb analysis of single neutrons
47 // assumed similar fraction for EM and HAD sections
48 // this variable converts from current assumed TestBeam values for fC--> GeV
49 // to the lowGain TS region fraction value (based on 1N Had, assume EM same response)
50 // regular energy
51  for (int i=ifirst; i<tool.size() && i<n+ifirst; i++) {
52  int capid=digi[i].capid();
53  ta = (tool[i]-calibs.pedestal(capid)); // pedestal subtraction
54  fc_ampl+=ta;
55  ta*= calibs.respcorrgain(capid) ; // fC --> GeV
56  ampl+=ta;
57  if(ta>maxA){
58  maxA=ta;
59  maxI=i;
60  }
61  }
62 // calculate low Gain Energy (in 2010 PbPb, signal TS 4,5,6, lowGain TS: 6,7,8)
63  int topLowGain=10;
64  if((n+ifirst+lowGainOffset)<=10){
65  topLowGain=n+ifirst+lowGainOffset;
66  } else {
67  topLowGain=10;
68  }
69  for (int iLG=(ifirst+lowGainOffset); iLG<tool.size() && iLG<topLowGain; iLG++) {
70  int capid=digi[iLG].capid();
71  TempLGAmp = (tool[iLG]-calibs.pedestal(capid)); // pedestal subtraction
72  lowGfc_ampl+=TempLGAmp;
73  TempLGAmp*= calibs.respcorrgain(capid) ; // fC --> GeV
74  TempLGAmp*= lowGainFrac ; // TS (signalRegion) --> TS (lowGainRegion)
75  lowGEnergy+=TempLGAmp;
76  }
77  double time=-9999;
78  // Time based on regular energy (lowGainEnergy signal assumed to happen at same Time)
80  if(maxI==0 || maxI==(tool.size()-1)) {
81  LogDebug("HCAL Pulse") << "ZdcSimpleRecAlgo::reco1 :"
82  << " Invalid max amplitude position, "
83  << " max Amplitude: "<< maxI
84  << " first: "<<ifirst
85  << " last: "<<(tool.size()-1)
86  << std::endl;
87  } else {
88  int capid=digi[maxI-1].capid();
89  double Energy0 = ((tool[maxI-1])*calibs.respcorrgain(capid) );
90 // if any of the energies used in the weight are negative, make them 0 instead
91 // these are actually QIE values, not energy
92  if(Energy0<0){Energy0=0.;}
93  capid=digi[maxI].capid();
94  double Energy1 = ((tool[maxI])*calibs.respcorrgain(capid) ) ;
95  if(Energy1<0){Energy1=0.;}
96  capid=digi[maxI+1].capid();
97  double Energy2 = ((tool[maxI+1])*calibs.respcorrgain(capid) );
98  if(Energy2<0){Energy2=0.;}
99 //
100  double TSWeightEnergy = ((maxI-1)*Energy0 + maxI*Energy1 + (maxI+1)*Energy2);
101  double EnergySum=Energy0+Energy1+Energy2;
102  double AvgTSPos=0.;
103  if (EnergySum!=0) AvgTSPos=TSWeightEnergy/ EnergySum;
104 // If time is zero, set it to the "nonsensical" -99
105 // Time should be between 75ns and 175ns (Timeslices 3-7)
106  if(AvgTSPos==0){
107  time=-99;
108  } else {
109  time = (AvgTSPos*25.0);
110  }
111  if (corr!=0) {
112  // Apply phase-based amplitude correction:
113  ampl *= corr->getCorrection(fc_ampl);
114  }
115  }
116  return RecHit(digi.id(),ampl,time,lowGEnergy);
117  }
118 }
119 
120 namespace ZdcSimpleRecAlgoImpl {
121  template<class Digi, class RecHit>
122  inline RecHit reco2(const Digi& digi, const HcalCoder& coder, const HcalCalibrations& calibs,
123  const std::vector<unsigned int>& myNoiseTS, const std::vector<unsigned int>& mySignalTS, int lowGainOffset, double lowGainFrac, bool slewCorrect, const HcalPulseContainmentCorrection* corr, HcalTimeSlew::BiasSetting slewFlavor) {
124  CaloSamples tool;
125  coder.adc2fC(digi,tool);
126  // Reads noiseTS and signalTS from database
127  int ifirst = mySignalTS[0];
128 // int n = mySignalTS.size();
129  double ampl=0; int maxI = -1; double maxA = -1e10; double ta=0;
130  double fc_ampl=0;
131  double lowGEnergy=0; double lowGfc_ampl=0; double TempLGAmp=0;
132 // TS increment for regular energy to lowGainEnergy
133 // Signal in higher TS (effective "low Gain") has a fraction of the whole signal
134 // This constant for fC --> GeV is dervied from 2010 PbPb analysis of single neutrons
135 // assumed similar fraction for EM and HAD sections
136 // this variable converts from current assumed TestBeam values for fC--> GeV
137 // to the lowGain TS region fraction value (based on 1N Had, assume EM same response)
138  double Allnoise = 0;
139  int noiseslices = 0;
140  int CurrentTS = 0;
141  double noise = 0;
142 // regular energy (both use same noise)
143  for(unsigned int iv = 0; iv<myNoiseTS.size(); ++iv)
144  {
145  CurrentTS = myNoiseTS[iv];
146  Allnoise += tool[CurrentTS];
147  noiseslices++;
148  }
149  if(noiseslices != 0) {
150  noise = (Allnoise)/double(noiseslices);
151  } else {
152  noise = 0;
153  }
154  for(unsigned int ivs = 0; ivs<mySignalTS.size(); ++ivs)
155  {
156  CurrentTS = mySignalTS[ivs];
157  int capid=digi[CurrentTS].capid();
158 // if(noise<0){
159 // // flag hit as having negative noise, and don't subtract anything, because
160 // // it will falsely increase the energy
161 // noisefactor=0.;
162 // }
163  ta = tool[CurrentTS]-noise;
164  fc_ampl+=ta;
165  ta*= calibs.respcorrgain(capid) ; // fC --> GeV
166  ampl+=ta;
167  if(ta>maxA){
168  maxA=ta;
169  maxI=CurrentTS;
170  }
171  }
172 // calculate low Gain Energy (in 2010 PbPb, signal TS 4,5,6, lowGain TS: 6,7,8)
173  for(unsigned int iLGvs = 0; iLGvs<mySignalTS.size(); ++iLGvs)
174  {
175  CurrentTS = mySignalTS[iLGvs]+lowGainOffset;
176  int capid=digi[CurrentTS].capid();
177  TempLGAmp = tool[CurrentTS]-noise;
178  lowGfc_ampl+=TempLGAmp;
179  TempLGAmp*= calibs.respcorrgain(capid) ; // fC --> GeV
180  TempLGAmp*= lowGainFrac ; // TS (signalRegion) --> TS (lowGainRegion)
181  lowGEnergy+=TempLGAmp;
182  }
183 // if(ta<0){
184 // // flag hits that have negative energy
185 // }
186 
187  double time=-9999;
188  // Time based on regular energy (lowGainEnergy signal assumed to happen at same Time)
190  if(maxI==0 || maxI==(tool.size()-1)) {
191  LogDebug("HCAL Pulse") << "ZdcSimpleRecAlgo::reco2 :"
192  << " Invalid max amplitude position, "
193  << " max Amplitude: "<< maxI
194  << " first: "<<ifirst
195  << " last: "<<(tool.size()-1)
196  << std::endl;
197  } else {
198  int capid=digi[maxI-1].capid();
199  double Energy0 = ((tool[maxI-1])*calibs.respcorrgain(capid) );
200 // if any of the energies used in the weight are negative, make them 0 instead
201 // these are actually QIE values, not energy
202  if(Energy0<0){Energy0=0.;}
203  capid=digi[maxI].capid();
204  double Energy1 = ((tool[maxI])*calibs.respcorrgain(capid) ) ;
205  if(Energy1<0){Energy1=0.;}
206  capid=digi[maxI+1].capid();
207  double Energy2 = ((tool[maxI+1])*calibs.respcorrgain(capid) );
208  if(Energy2<0){Energy2=0.;}
209 //
210  double TSWeightEnergy = ((maxI-1)*Energy0 + maxI*Energy1 + (maxI+1)*Energy2);
211  double EnergySum=Energy0+Energy1+Energy2;
212  double AvgTSPos=0.;
213  if (EnergySum!=0) AvgTSPos=TSWeightEnergy/ EnergySum;
214 // If time is zero, set it to the "nonsensical" -99
215 // Time should be between 75ns and 175ns (Timeslices 3-7)
216  if(AvgTSPos==0){
217  time=-99;
218  } else {
219  time = (AvgTSPos*25.0);
220  }
221  if (corr!=0) {
222  // Apply phase-based amplitude correction:
223  ampl *= corr->getCorrection(fc_ampl);
224  }
225  }
226  return RecHit(digi.id(),ampl,time,lowGEnergy);
227  }
228 }
229 
230 ZDCRecHit ZdcSimpleRecAlgo::reconstruct(const ZDCDataFrame& digi, const std::vector<unsigned int>& myNoiseTS, const std::vector<unsigned int>& mySignalTS, const HcalCoder& coder, const HcalCalibrations& calibs) const {
231 
232  if(recoMethod_ == 1)
233  return ZdcSimpleRecAlgoImpl::reco1<ZDCDataFrame,ZDCRecHit>(digi,coder,calibs,
234  myNoiseTS,mySignalTS,lowGainOffset_,lowGainFrac_,false,
235  0,
237  if(recoMethod_ == 2)
238  return ZdcSimpleRecAlgoImpl::reco2<ZDCDataFrame,ZDCRecHit>(digi,coder,calibs,
239  myNoiseTS,mySignalTS,lowGainOffset_,lowGainFrac_,false,
241 
242  edm::LogError("ZDCSimpleRecAlgoImpl::reconstruct, recoMethod was not declared");
243  throw cms::Exception("ZDCSimpleRecoAlgos::exiting process");
244 
245 }
246 
247 static const float wpksamp0_zdc = 0.500053;
248 static const float scale_zdc = 0.999683;
249 static const int num_bins_zdc = 100;
250 
251 static const float actual_ns_zdc[num_bins_zdc] = {
252  0.00250, // 0.000-0.010
253  0.08000, // 0.010-0.020
254  0.16000, // 0.020-0.030
255  0.23750, // 0.030-0.040
256  0.31750, // 0.040-0.050
257  0.39500, // 0.050-0.060
258  0.47500, // 0.060-0.070
259  0.55500, // 0.070-0.080
260  0.63000, // 0.080-0.090
261  0.70000, // 0.090-0.100
262  0.77000, // 0.100-0.110
263  0.84000, // 0.110-0.120
264  0.91000, // 0.120-0.130
265  0.98000, // 0.130-0.140
266  1.05000, // 0.140-0.150
267  1.12000, // 0.150-0.160
268  1.19000, // 0.160-0.170
269  1.26000, // 0.170-0.180
270  1.33000, // 0.180-0.190
271  1.40000, // 0.190-0.200
272  1.47000, // 0.200-0.210
273  1.54000, // 0.210-0.220
274  1.61000, // 0.220-0.230
275  1.68000, // 0.230-0.240
276  1.75000, // 0.240-0.250
277  1.82000, // 0.250-0.260
278  1.89000, // 0.260-0.270
279  1.96000, // 0.270-0.280
280  2.03000, // 0.280-0.290
281  2.10000, // 0.290-0.300
282  2.17000, // 0.300-0.310
283  2.24000, // 0.310-0.320
284  2.31000, // 0.320-0.330
285  2.38000, // 0.330-0.340
286  2.45000, // 0.340-0.350
287  2.52000, // 0.350-0.360
288  2.59000, // 0.360-0.370
289  2.68500, // 0.370-0.380
290  2.79250, // 0.380-0.390
291  2.90250, // 0.390-0.400
292  3.01000, // 0.400-0.410
293  3.11750, // 0.410-0.420
294  3.22500, // 0.420-0.430
295  3.33500, // 0.430-0.440
296  3.44250, // 0.440-0.450
297  3.55000, // 0.450-0.460
298  3.73250, // 0.460-0.470
299  4.02000, // 0.470-0.480
300  4.30750, // 0.480-0.490
301  4.59500, // 0.490-0.500
302  6.97500, // 0.500-0.510
303 10.98750, // 0.510-0.520
304 13.03750, // 0.520-0.530
305 14.39250, // 0.530-0.540
306 15.39500, // 0.540-0.550
307 16.18250, // 0.550-0.560
308 16.85250, // 0.560-0.570
309 17.42750, // 0.570-0.580
310 17.91500, // 0.580-0.590
311 18.36250, // 0.590-0.600
312 18.76500, // 0.600-0.610
313 19.11250, // 0.610-0.620
314 19.46000, // 0.620-0.630
315 19.76500, // 0.630-0.640
316 20.03500, // 0.640-0.650
317 20.30250, // 0.650-0.660
318 20.57250, // 0.660-0.670
319 20.79250, // 0.670-0.680
320 21.00250, // 0.680-0.690
321 21.21000, // 0.690-0.700
322 21.42000, // 0.700-0.710
323 21.62750, // 0.710-0.720
324 21.79000, // 0.720-0.730
325 21.95250, // 0.730-0.740
326 22.11500, // 0.740-0.750
327 22.27750, // 0.750-0.760
328 22.44000, // 0.760-0.770
329 22.60500, // 0.770-0.780
330 22.73250, // 0.780-0.790
331 22.86000, // 0.790-0.800
332 22.98500, // 0.800-0.810
333 23.11250, // 0.810-0.820
334 23.23750, // 0.820-0.830
335 23.36500, // 0.830-0.840
336 23.49000, // 0.840-0.850
337 23.61750, // 0.850-0.860
338 23.71500, // 0.860-0.870
339 23.81250, // 0.870-0.880
340 23.91250, // 0.880-0.890
341 24.01000, // 0.890-0.900
342 24.10750, // 0.900-0.910
343 24.20750, // 0.910-0.920
344 24.30500, // 0.920-0.930
345 24.40500, // 0.930-0.940
346 24.50250, // 0.940-0.950
347 24.60000, // 0.950-0.960
348 24.68250, // 0.960-0.970
349 24.76250, // 0.970-0.980
350 24.84000, // 0.980-0.990
351 24.92000 // 0.990-1.000
352 };
353 
354 /*
355 float timeshift_ns_zdc(float wpksamp) {
356  float flx = (num_bins_zdc*(wpksamp - wpksamp0_zdc)/scale_zdc);
357  int index = (int)flx;
358  float yval;
359 
360  if (index < 0) return actual_ns_zdc[0];
361  else if (index >= num_bins_zdc-1) return actual_ns_zdc[num_bins_zdc-1];
362 
363  // else interpolate:
364  float y1 = actual_ns_zdc[index];
365  float y2 = actual_ns_zdc[index+1];
366 
367  // float delta_x = 1/(float)num_bins_zdc;
368  // yval = y1 + (y2-y1)*(flx-(float)index)/delta_x;
369 
370  yval = y1 + (y2-y1)*(flx-(float)index);
371  return yval;
372 }
373 */
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
RecHit reco1(const Digi &digi, const HcalCoder &coder, const HcalCalibrations &calibs, const std::vector< unsigned int > &myNoiseTS, const std::vector< unsigned int > &mySignalTS, int lowGainOffset, double lowGainFrac, bool slewCorrect, const HcalPulseContainmentCorrection *corr, HcalTimeSlew::BiasSetting slewFlavor)
double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3
static const float scale_zdc
static const float wpksamp0_zdc
double getCorrection(double fc_ampl) const
double pedestal(int fCapId) const
get pedestal for capid=0..3
ZDCRecHit reconstruct(const ZDCDataFrame &digi, const std::vector< unsigned int > &myNoiseTS, const std::vector< unsigned int > &mySignalTS, const HcalCoder &coder, const HcalCalibrations &calibs) const
std::auto_ptr< HcalPulseContainmentCorrection > pulseCorr_
void initPulseCorr(int toadd)
ZdcSimpleRecAlgo(bool correctForTimeslew, bool correctForContainment, float fixedPhaseNs, int recoMethod, int lowGainOffset, double lowGainFrac)
static const float actual_ns_zdc[num_bins_zdc]
JetCorrectorParameters corr
Definition: classes.h:11
constexpr double MaximumFractionalError
int size() const
get the size
Definition: CaloSamples.h:26
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const =0
RecHit reco2(const Digi &digi, const HcalCoder &coder, const HcalCalibrations &calibs, const std::vector< unsigned int > &myNoiseTS, const std::vector< unsigned int > &mySignalTS, int lowGainOffset, double lowGainFrac, bool slewCorrect, const HcalPulseContainmentCorrection *corr, HcalTimeSlew::BiasSetting slewFlavor)
#define constexpr
static const int num_bins_zdc