CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
EcalUncalibRecHitTimingCCAlgo Class Reference

#include <EcalUncalibRecHitTimingCCAlgo.h>

Public Member Functions

double computeTimeCC (const EcalDataFrame &dataFrame, const std::vector< double > &amplitudes, const EcalPedestals::Item *aped, const EcalMGPAGainRatio *aGain, const FullSampleVector &fullpulse, const float targetTimePrecision, const bool correctForOOT=true, const bool correctForSlew=true) const
 
 EcalUncalibRecHitTimingCCAlgo (const float startTime, const float stopTime)
 

Private Member Functions

float computeCC (const std::vector< float > &samples, const std::vector< float > &weights, const FullSampleVector &sigmalTemplate, const float t) const
 
FullSampleVector interpolatePulse (const FullSampleVector &fullpulse, const float t=0) const
 

Private Attributes

const float startTime_
 
const float stopTime_
 

Static Private Attributes

static constexpr float GLOBAL_TIME_SHIFT = 100
 
static constexpr float GOLDEN_RATIO = 0.61803399
 
static constexpr int MAX_NUM_OF_ITERATIONS = 60
 
static constexpr int MIN_NUM_OF_ITERATIONS = 2
 
static constexpr float ONE_MINUS_GOLDEN_RATIO = 1.0 - GOLDEN_RATIO
 
static constexpr int TIME_WHEN_NOT_CONVERGING = 100
 

Detailed Description

CrossCorrelation algorithm for timing reconstruction

Author
N. Minafra, J. King, C. Rogan

Definition at line 18 of file EcalUncalibRecHitTimingCCAlgo.h.

Constructor & Destructor Documentation

◆ EcalUncalibRecHitTimingCCAlgo()

EcalUncalibRecHitTimingCCAlgo::EcalUncalibRecHitTimingCCAlgo ( const float  startTime,
const float  stopTime 
)

Member Function Documentation

◆ computeCC()

float EcalUncalibRecHitTimingCCAlgo::computeCC ( const std::vector< float > &  samples,
const std::vector< float > &  weights,
const FullSampleVector sigmalTemplate,
const float  t 
) const
private

Definition at line 157 of file EcalUncalibRecHitTimingCCAlgo.cc.

References gpuPixelDoublets::cc, ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), bTagMiniDQMDeepCSV::denominator, mps_fire::i, createfilelist::int, interpolatePulse(), funct::pow(), EgammaValidation_cff::samples, mathSSE::sqrt(), hcalRecHitTable_cff::time, and hltDeepSecondaryVertexTagInfosPFPuppi_cfi::weights.

Referenced by computeTimeCC().

160  {
161  constexpr int exclude = 1;
162  float powerSamples = 0.;
163  float powerTemplate = 0.;
164  float cc = 0.;
165  auto interpolated = interpolatePulse(signalTemplate, time);
166  for (int i = exclude; i < int(samples.size() - exclude); ++i) {
167  powerSamples += std::pow(samples[i], 2) * weights[i];
168  powerTemplate += std::pow(interpolated[i], 2) * weights[i];
169  cc += interpolated[i] * samples[i] * weights[i];
170  }
171 
172  float denominator = std::sqrt(powerTemplate * powerSamples);
173  return cc / denominator;
174 }
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
T sqrt(T t)
Definition: SSEVec.h:23
FullSampleVector interpolatePulse(const FullSampleVector &fullpulse, const float t=0) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ computeTimeCC()

double EcalUncalibRecHitTimingCCAlgo::computeTimeCC ( const EcalDataFrame dataFrame,
const std::vector< double > &  amplitudes,
const EcalPedestals::Item aped,
const EcalMGPAGainRatio aGain,
const FullSampleVector fullpulse,
const float  targetTimePrecision,
const bool  correctForOOT = true,
const bool  correctForSlew = true 
) const

Definition at line 6 of file EcalUncalibRecHitTimingCCAlgo.cc.

References funct::abs(), CustomPhysics_cfi::amplitude, computeCC(), ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), counter, f, EcalMGPAGainRatio::gain12Over6(), EcalMGPAGainRatio::gain6Over1(), ecalLiteDTU::gainId(), EcalMGPASample::gainId(), GLOBAL_TIME_SHIFT, GOLDEN_RATIO, WZElectronSkims53X_cff::max, MAX_NUM_OF_ITERATIONS, EcalDataFrame::MAXSAMPLES, HLT_IsoTrack_cff::offset, ONE_MINUS_GOLDEN_RATIO, Hcal_Conditions_forGlobalTag_cff::pedestal, pulse(), ecalPh1::Samp_Period, EcalDataFrame::sample(), ecalGpuTask_cfi::sample, startTime_, stopTime_, FrontierCondition_GT_autoExpress_cfi::t0, RandomServiceHelper::t1, RandomServiceHelper::t2, RandomServiceHelper::t3, TIME_WHEN_NOT_CONVERGING, and hltDeepSecondaryVertexTagInfosPFPuppi_cfi::weights.

13  {
14  constexpr unsigned int nsample = EcalDataFrame::MAXSAMPLES;
15 
16  double maxamplitude = -std::numeric_limits<double>::max();
17  float pulsenorm = 0.;
18 
19  std::vector<float> pedSubSamples(nsample);
20  std::vector<float> weights(nsample, 1.f);
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  pulsenorm += fullpulse(iSample);
51 
52  if (amplitude > maxamplitude) {
53  maxamplitude = amplitude;
54  }
55 
56  if (iSample > 0 && correctForSlew) {
57  int GainIdPrev = dataFrame.sample(iSample - 1).gainId();
58  bool GainIdInRange = GainIdPrev >= 1 && GainIdPrev <= 3 && gainId >= 1 && gainId <= 3;
59  bool GainSlew = GainIdPrev < gainId;
60  if (GainIdInRange && GainSlew)
61  weights[iSample - 1] = 0.f;
62  }
63  }
64 
65  if (correctForOOT) {
66  int ipulse = -1;
67  for (auto const& amplit : amplitudes) {
68  ipulse++;
69  int bxp3 = ipulse - 2;
70  int firstsamplet = std::max(0, bxp3);
71  int offset = 7 - bxp3;
72 
73  for (unsigned int isample = firstsamplet; isample < nsample; ++isample) {
74  auto const pulse = fullpulse(isample + offset);
75  pedSubSamples[isample] = pedSubSamples[isample] - (amplit * pulse / pulsenorm);
76  }
77  }
78  }
79 
80  // Start of time computation
82  float t3 = stopTime_ + GLOBAL_TIME_SHIFT;
83  float t2 = (t3 + t0) / 2;
84  float t1 = t2 - ONE_MINUS_GOLDEN_RATIO * (t3 - t0);
85 
86  int counter = 0;
87 
88  float cc1 = computeCC(pedSubSamples, weights, fullpulse, t1);
89  ++counter;
90  float cc2 = computeCC(pedSubSamples, weights, fullpulse, t2);
91  ++counter;
92 
93  while (std::abs(t3 - t0) > targetTimePrecision && counter < MAX_NUM_OF_ITERATIONS) {
94  if (cc2 > cc1) {
95  t0 = t1;
96  t1 = t2;
98  cc1 = cc2;
99  cc2 = computeCC(pedSubSamples, weights, fullpulse, t2);
100  ++counter;
101  } else {
102  t3 = t2;
103  t2 = t1;
105  cc2 = cc1;
106  cc1 = computeCC(pedSubSamples, weights, fullpulse, t1);
107  ++counter;
108  }
109  }
110 
111  float tM = (t3 + t0) / 2 - GLOBAL_TIME_SHIFT;
112  if (counter < MIN_NUM_OF_ITERATIONS || counter > MAX_NUM_OF_ITERATIONS - 1) {
114  }
115  return -tM / ecalPh1::Samp_Period;
116 }
float computeCC(const std::vector< float > &samples, const std::vector< float > &weights, const FullSampleVector &sigmalTemplate, const float t) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
double f[11][100]
static constexpr double Samp_Period
Definition: EcalConstants.h:50
float gain12Over6() const
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
double pulse(double x, double y, double z, double t)
float gain6Over1() const
static std::atomic< unsigned int > counter
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
int gainId() const
get the gainId (2 bits)

◆ interpolatePulse()

FullSampleVector EcalUncalibRecHitTimingCCAlgo::interpolatePulse ( const FullSampleVector fullpulse,
const float  t = 0 
) const
private

Definition at line 118 of file EcalUncalibRecHitTimingCCAlgo.cc.

References a, mps_fire::i, numberOfSamples, ecalPh1::Samp_Period, edm::shift, and hcalRecHitTable_cff::time.

Referenced by computeCC().

119  {
120  // t is in ns
122  if (time < 0)
123  shift -= 1;
124  float tt = time / ecalPh1::Samp_Period - shift;
125 
126  FullSampleVector interpPulse;
127  // 2nd poly with avg
128  unsigned int numberOfSamples = fullpulse.size();
129  auto facM1orP2 = 0.25 * tt * (tt - 1);
130  auto fac = (0.25 * (tt - 2) - 0.5 * (tt + 1)) * (tt - 1);
131  auto facP1 = (0.25 * (tt + 1) - 0.5 * (tt - 2)) * tt;
132  for (unsigned int i = 1; i < numberOfSamples - 2; ++i) {
133  float a =
134  facM1orP2 * fullpulse[i - 1] + fac * fullpulse[i] + facP1 * fullpulse[i + 1] + facM1orP2 * fullpulse[i + 2];
135  if (a > 0)
136  interpPulse[i] = a;
137  else
138  interpPulse[i] = 0;
139  }
140  interpPulse[0] = facM1orP2 * fullpulse[0] + facP1 * fullpulse[1] + facM1orP2 * fullpulse[2];
141  interpPulse[numberOfSamples - 2] = facM1orP2 * fullpulse[numberOfSamples - 3] + fac * fullpulse[numberOfSamples - 2] +
142  facP1 * fullpulse[numberOfSamples - 1];
143  interpPulse[numberOfSamples - 1] = 2 * facM1orP2 * fullpulse[numberOfSamples - 2] -
144  4 * facM1orP2 * fullpulse[numberOfSamples - 1] +
145  facP1 * fullpulse[numberOfSamples - 1];
146 
147  FullSampleVector interpPulseShifted;
148  for (int i = 0; i < interpPulseShifted.size(); ++i) {
149  if (i + shift >= 0 && i + shift < interpPulse.size())
150  interpPulseShifted[i] = interpPulse[i + shift];
151  else
152  interpPulseShifted[i] = 0;
153  }
154  return interpPulseShifted;
155 }
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
Definition: TTTypes.h:54
static constexpr double Samp_Period
Definition: EcalConstants.h:50
double a
Definition: hdecay.h:121
static unsigned int const shift

Member Data Documentation

◆ GLOBAL_TIME_SHIFT

constexpr float EcalUncalibRecHitTimingCCAlgo::GLOBAL_TIME_SHIFT = 100
staticprivate

Definition at line 37 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ GOLDEN_RATIO

constexpr float EcalUncalibRecHitTimingCCAlgo::GOLDEN_RATIO = 0.61803399
staticprivate

Definition at line 38 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ MAX_NUM_OF_ITERATIONS

constexpr int EcalUncalibRecHitTimingCCAlgo::MAX_NUM_OF_ITERATIONS = 60
staticprivate

Definition at line 35 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ MIN_NUM_OF_ITERATIONS

constexpr int EcalUncalibRecHitTimingCCAlgo::MIN_NUM_OF_ITERATIONS = 2
staticprivate

Definition at line 36 of file EcalUncalibRecHitTimingCCAlgo.h.

◆ ONE_MINUS_GOLDEN_RATIO

constexpr float EcalUncalibRecHitTimingCCAlgo::ONE_MINUS_GOLDEN_RATIO = 1.0 - GOLDEN_RATIO
staticprivate

Definition at line 39 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ startTime_

const float EcalUncalibRecHitTimingCCAlgo::startTime_
private

Definition at line 31 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ stopTime_

const float EcalUncalibRecHitTimingCCAlgo::stopTime_
private

Definition at line 32 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ TIME_WHEN_NOT_CONVERGING

constexpr int EcalUncalibRecHitTimingCCAlgo::TIME_WHEN_NOT_CONVERGING = 100
staticprivate

Definition at line 34 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().