CMS 3D CMS Logo

EcalUncalibRecHitTimingCCAlgo.cc
Go to the documentation of this file.
2 
4  : startTime_(startTime), stopTime_(stopTime) {}
5 
7  const std::vector<double>& amplitudes,
8  const EcalPedestals::Item* aped,
9  const EcalMGPAGainRatio* aGain,
10  const FullSampleVector& fullpulse,
11  EcalUncalibratedRecHit& uncalibRecHit,
12  float& errOnTime,
13  const float targetTimePrecision,
14  const bool correctForOOT) const {
15  constexpr unsigned int nsample = EcalDataFrame::MAXSAMPLES;
16 
17  double maxamplitude = -std::numeric_limits<double>::max();
18  float pulsenorm = 0.;
19 
20  std::vector<float> pedSubSamples(nsample);
21  for (unsigned int iSample = 0; iSample < nsample; iSample++) {
22  const EcalMGPASample& sample = dataFrame.sample(iSample);
23 
24  float amplitude = 0.;
25  int gainId = sample.gainId();
26 
27  double pedestal = 0.;
28  double gainratio = 1.;
29 
30  if (gainId == 0 || gainId == 3) {
31  pedestal = aped->mean_x1;
32  gainratio = aGain->gain6Over1() * aGain->gain12Over6();
33  } else if (gainId == 1) {
34  pedestal = aped->mean_x12;
35  gainratio = 1.;
36  } else if (gainId == 2) {
37  pedestal = aped->mean_x6;
38  gainratio = aGain->gain12Over6();
39  }
40 
41  amplitude = (static_cast<float>(sample.adc()) - pedestal) * gainratio;
42 
43  if (gainId == 0) {
44  //saturation
45  amplitude = (4095. - pedestal) * gainratio;
46  }
47 
48  pedSubSamples[iSample] = amplitude;
49 
50  if (amplitude > maxamplitude) {
51  maxamplitude = amplitude;
52  }
53  pulsenorm += fullpulse(iSample);
54  }
55 
56  if (correctForOOT) {
57  int ipulse = -1;
58  for (auto const& amplit : amplitudes) {
59  ipulse++;
60  int bxp3 = ipulse - 2;
61  int firstsamplet = std::max(0, bxp3);
62  int offset = 7 - bxp3;
63 
64  for (unsigned int isample = firstsamplet; isample < nsample; ++isample) {
65  auto const pulse = fullpulse(isample + offset);
66  pedSubSamples[isample] = std::max(0., pedSubSamples[isample] - amplit * pulse / pulsenorm);
67  }
68  }
69  }
70 
71  // Start of time computation
73  float t3 = stopTime_ + GLOBAL_TIME_SHIFT;
74  float t2 = (t3 + t0) / 2;
75  float t1 = t2 - ONE_MINUS_GOLDEN_RATIO * (t3 - t0);
76 
77  int counter = 0;
78 
79  float cc1 = computeCC(pedSubSamples, fullpulse, t1);
80  ++counter;
81  float cc2 = computeCC(pedSubSamples, fullpulse, t2);
82  ++counter;
83 
84  while (std::abs(t3 - t0) > targetTimePrecision && counter < MAX_NUM_OF_ITERATIONS) {
85  if (cc2 > cc1) {
86  t0 = t1;
87  t1 = t2;
89  cc1 = cc2;
90  cc2 = computeCC(pedSubSamples, fullpulse, t2);
91  ++counter;
92  } else {
93  t3 = t2;
94  t2 = t1;
96  cc2 = cc1;
97  cc1 = computeCC(pedSubSamples, fullpulse, t1);
98  ++counter;
99  }
100  }
101 
102  float tM = (t3 + t0) / 2 - GLOBAL_TIME_SHIFT;
103  errOnTime = std::abs(t3 - t0) / ecalPh1::Samp_Period;
104 
105  if (counter < MIN_NUM_OF_ITERATIONS || counter > MAX_NUM_OF_ITERATIONS - 1) {
107  //Negative error means that there was a problem with the CC
108  errOnTime = -targetTimePrecision / ecalPh1::Samp_Period;
109  }
110  return -tM / ecalPh1::Samp_Period;
111 }
112 
114  const float time) const {
115  // t is in ns
117  if (time < 0)
118  shift -= 1;
119  float tt = time / ecalPh1::Samp_Period - shift;
120 
121  FullSampleVector interpPulse;
122  // 2nd poly with avg
123  unsigned int numberOfSamples = fullpulse.size();
124  auto facM1orP2 = 0.25 * tt * (tt - 1);
125  auto fac = (0.25 * (tt - 2) - 0.5 * (tt + 1)) * (tt - 1);
126  auto facP1 = (0.25 * (tt + 1) - 0.5 * (tt - 2)) * tt;
127  for (unsigned int i = 1; i < numberOfSamples - 2; ++i) {
128  float a =
129  facM1orP2 * fullpulse[i - 1] + fac * fullpulse[i] + facP1 * fullpulse[i + 1] + facM1orP2 * fullpulse[i + 2];
130  if (a > 0)
131  interpPulse[i] = a;
132  else
133  interpPulse[i] = 0;
134  }
135  interpPulse[0] = facM1orP2 * fullpulse[0] + facP1 * fullpulse[1] + facM1orP2 * fullpulse[2];
136  interpPulse[numberOfSamples - 2] = facM1orP2 * fullpulse[numberOfSamples - 3] + fac * fullpulse[numberOfSamples - 2] +
137  facP1 * fullpulse[numberOfSamples - 1];
138  interpPulse[numberOfSamples - 1] = 2 * facM1orP2 * fullpulse[numberOfSamples - 2] -
139  4 * facM1orP2 * fullpulse[numberOfSamples - 1] +
140  facP1 * fullpulse[numberOfSamples - 1];
141 
142  FullSampleVector interpPulseShifted;
143  for (int i = 0; i < interpPulseShifted.size(); ++i) {
144  if (i + shift >= 0 && i + shift < interpPulse.size())
145  interpPulseShifted[i] = interpPulse[i + shift];
146  else
147  interpPulseShifted[i] = 0;
148  }
149  return interpPulseShifted;
150 }
151 
152 float EcalUncalibRecHitTimingCCAlgo::computeCC(const std::vector<float>& samples,
153  const FullSampleVector& signalTemplate,
154  const float time) const {
155  constexpr int exclude = 1;
156  float powerSamples = 0.;
157  float powerTemplate = 0.;
158  float cc = 0.;
159  auto interpolated = interpolatePulse(signalTemplate, time);
160  for (int i = exclude; i < int(samples.size() - exclude); ++i) {
161  powerSamples += std::pow(samples[i], 2);
162  powerTemplate += std::pow(interpolated[i], 2);
163  cc += interpolated[i] * samples[i];
164  }
165 
166  float denominator = std::sqrt(powerTemplate * powerSamples);
167  return cc / denominator;
168 }
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
constexpr int pow(int x)
Definition: conifer.h:24
Definition: TTTypes.h:54
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
static constexpr double Samp_Period
Definition: EcalConstants.h:50
float computeCC(const std::vector< float > &samples, const FullSampleVector &sigmalTemplate, const float t) const
float gain12Over6() const
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
double pulse(double x, double y, double z, double t)
EcalUncalibRecHitTimingCCAlgo(const float startTime, const float stopTime)
float gain6Over1() const
double a
Definition: hdecay.h:121
static std::atomic< unsigned int > counter
static unsigned int const shift
double computeTimeCC(const EcalDataFrame &dataFrame, const std::vector< double > &amplitudes, const EcalPedestals::Item *aped, const EcalMGPAGainRatio *aGain, const FullSampleVector &fullpulse, EcalUncalibratedRecHit &uncalibRecHit, float &errOnTime, const float targetTimePrecision, const bool correctForOOT=true) const
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
FullSampleVector interpolatePulse(const FullSampleVector &fullpulse, const float t=0) const