test
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 }
#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
double MaximumFractionalError
double getCorrection(double fc_ampl) const
double pedestal(int fCapId) const
get pedestal for capid=0..3
std::tuple< unsigned int, int, int, DigiType, int, int, int, float > Digi
Definition: GenericDigi.h:30
#define constexpr
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)
JetCorrectorParameters corr
Definition: classes.h:5
int size() const
get the size
Definition: CaloSamples.h:24
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const =0
volatile std::atomic< bool > shutdown_flag false
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)