CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESRecHitSimAlgo.cc
Go to the documentation of this file.
3 
4 #include <iostream>
5 #include <math.h>
6 
8 
9 }
10 
11 double* ESRecHitSimAlgo::EvalAmplitude(const ESDataFrame& digi, const double& ped, const double& w0, const double& w1, const double& w2) const {
12 
13  double *results = new double[4];
14  float energy = 0;
15  double adc[3];
16  float pw[3];
17  pw[0] = w0;
18  pw[1] = w1;
19  pw[2] = w2;
20 
21  for (int i=0; i<digi.size(); i++) {
22  energy += pw[i]*(digi.sample(i).adc()-ped);
23  LogDebug("ESRecHitSimAlgo") << "ESRecHitSimAlgo : Digi "<<i<<" ADC counts "<<digi.sample(i).adc()<<" Ped "<<ped;
24  //std::cout<<i<<" "<<digi.sample(i).adc()<<" "<<ped<<" "<<pw[i]<<std::endl;
25  adc[i] = digi.sample(i).adc() - ped;
26  }
27 
28  double status = 0;
29  if (adc[0] > 20) status = 14;
30  if (adc[1] <= 0 || adc[2] <= 0) status = 10;
31  if (adc[0] > adc[1] && adc[0] > adc[2]) status = 8;
32  if (adc[2] > adc[1] && adc[2] > adc[0]) status = 9;
33  double r12 = (adc[1] != 0) ? adc[0]/adc[1] : 99;
34  double r23 = (adc[2] != 0) ? adc[1]/adc[2] : 99;
35  if (r12 > ratioCuts_->getR12High()) status = 5;
36  if (r23 > ratioCuts_->getR23High()) status = 6;
37  if (r23 < ratioCuts_->getR23Low()) status = 7;
38 
39  double A1 = adc[1];
40  double A2 = adc[2];
41 
42  // t0 from analytical formula:
43  double n = 1.798;
44  double w = 0.07291;
45  double DeltaT = 25.;
46  double aaa = (A2 > 0 && A1 > 0) ? log(A2/A1)/n : 20.; // if A1=0, t0=20
47  double bbb = w/n*DeltaT;
48  double ccc= exp(aaa+bbb);
49 
50  double t0 = (2.-ccc)/(1.-ccc) * DeltaT - 5;
51 
52  // A from analytical formula:
53  double t1 = 20.;
54  double A_1 = pow(w/n*(t1),n) * exp(n-w*(t1));
55  double AA1 = (A_1 != 0.) ? A1 / A_1 : 0.;
56 
57  if (adc[1] > 2800 && adc[2] > 2800) status = 11;
58  else if (adc[1] > 2800) status = 12;
59  else if (adc[2] > 2800) status = 13;
60 
61  results[0] = energy; // energy with weight method
62  results[1] = t0; // timing
63  results[2] = status; // hit status
64  results[3] = AA1; // energy with analytic method
65 
66  return results;
67 }
68 
70 
71  ESPedestals::const_iterator it_ped = peds_->find(digi.id());
72 
75 
77 
78  double* results;
79 
80  results = EvalAmplitude(digi, it_ped->getMean(), w0_, w1_, w2_);
81 
82  double energy = results[0];
83  double t0 = results[1];
84  int status = (int) results[2];
85  double otenergy = results[3] * 1000000.; // set out-of-time energy to keV
86  delete[] results;
87 
88  double mipCalib = (fabs(cos(*it_ang)) != 0.) ? (*it_mip)/fabs(cos(*it_ang)) : 0.;
89  energy *= (mipCalib != 0.) ? MIPGeV_/mipCalib : 0.;
90  otenergy *= (mipCalib != 0.) ? MIPGeV_/mipCalib : 0.;
91 
92  LogDebug("ESRecHitSimAlgo") << "ESRecHitSimAlgo : reconstructed energy "<<energy;
93 
94  EcalRecHit rechit(digi.id(), energy, t0);
95  rechit.setOutOfTimeEnergy(otenergy);
96 
97  if (it_status->getStatusCode() == 1) {
98  rechit.setFlag(EcalRecHit::kESDead);
99  } else {
100  if (status == 0)
101  rechit.setFlag(EcalRecHit::kESGood);
102  else if (status == 5)
103  rechit.setFlag(EcalRecHit::kESBadRatioFor12);
104  else if (status == 6)
105  rechit.setFlag(EcalRecHit::kESBadRatioFor23Upper);
106  else if (status == 7)
107  rechit.setFlag(EcalRecHit::kESBadRatioFor23Lower);
108  else if (status == 8)
109  rechit.setFlag(EcalRecHit::kESTS1Largest);
110  else if (status == 9)
111  rechit.setFlag(EcalRecHit::kESTS3Largest);
112  else if (status == 10)
113  rechit.setFlag(EcalRecHit::kESTS3Negative);
114  else if (status == 11)
115  rechit.setFlag(EcalRecHit::kESSaturated);
116  else if (status == 12)
117  rechit.setFlag(EcalRecHit::kESTS2Saturated);
118  else if (status == 13)
119  rechit.setFlag(EcalRecHit::kESTS3Saturated);
120  else if (status == 14)
121  rechit.setFlag(EcalRecHit::kESTS13Sigmas);
122  }
123 
124  return rechit;
125 }
126 
#define LogDebug(id)
int adc(sample_type sample)
get the ADC sample (12 bits)
int i
Definition: DBlmapReader.cc:9
EcalRecHit reconstruct(const ESDataFrame &digi) const
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
const ESDetId & id() const
Definition: ESDataFrame.h:21
const self & getMap() const
int size() const
Definition: ESDataFrame.h:23
const ESPedestals * peds_
const ESIntercalibConstants * mips_
const ESChannelStatus * channelStatus_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const_iterator find(uint32_t rawId) const
const ESSample & sample(int i) const
Definition: ESDataFrame.h:26
const ESRecHitRatioCuts * ratioCuts_
const ESAngleCorrectionFactors * ang_
std::vector< Item >::const_iterator const_iterator
float getR12High() const
float getR23High() const
void setOutOfTimeEnergy(float energy)
Definition: EcalRecHit.cc:62
int adc() const
get the ADC sample (singed 16 bits)
Definition: ESSample.h:18
T w() const
tuple status
Definition: ntuplemaker.py:245
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double * EvalAmplitude(const ESDataFrame &digi, const double &ped, const double &w0, const double &w1, const double &w2) const