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
 
 EcalUncalibRecHitTimingCCAlgo (const float startTime, const float stopTime)
 

Private Member Functions

float computeCC (const std::vector< float > &samples, 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 FullSampleVector sigmalTemplate,
const float  t 
) const
private

Definition at line 146 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(), and hcalRecHitTable_cff::time.

Referenced by computeTimeCC().

148  {
149  constexpr int exclude = 1;
150  float powerSamples = 0.;
151  float powerTemplate = 0.;
152  float cc = 0.;
153  auto interpolated = interpolatePulse(signalTemplate, time);
154  for (int i = exclude; i < int(samples.size() - exclude); ++i) {
155  powerSamples += std::pow(samples[i], 2);
156  powerTemplate += std::pow(interpolated[i], 2);
157  cc += interpolated[i] * samples[i];
158  }
159 
160  float denominator = std::sqrt(powerTemplate * powerSamples);
161  return cc / denominator;
162 }
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
T sqrt(T t)
Definition: SSEVec.h:19
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

Definition at line 6 of file EcalUncalibRecHitTimingCCAlgo.cc.

References funct::abs(), CustomPhysics_cfi::amplitude, computeCC(), ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), counter, EcalMGPAGainRatio::gain12Over6(), EcalMGPAGainRatio::gain6Over1(), ecalLiteDTU::gainId(), GLOBAL_TIME_SHIFT, GOLDEN_RATIO, SiStripPI::max, MAX_NUM_OF_ITERATIONS, EcalDataFrame::MAXSAMPLES, hltrates_dqm_sourceclient-live_cfg::offset, ONE_MINUS_GOLDEN_RATIO, EcalCondDBWriter_cfi::pedestal, pulse(), ecalPh1::Samp_Period, EcalDataFrame::sample(), ecalGpuTask_cfi::sample, startTime_, stopTime_, FrontierCondition_GT_autoExpress_cfi::t0, RandomServiceHelper::t1, RandomServiceHelper::t2, RandomServiceHelper::t3, and TIME_WHEN_NOT_CONVERGING.

12  {
13  constexpr unsigned int nsample = EcalDataFrame::MAXSAMPLES;
14 
15  double maxamplitude = -std::numeric_limits<double>::max();
16  float pulsenorm = 0.;
17 
18  std::vector<float> pedSubSamples(nsample);
19  for (unsigned int iSample = 0; iSample < nsample; iSample++) {
20  const EcalMGPASample& sample = dataFrame.sample(iSample);
21 
22  float amplitude = 0.;
23  int gainId = sample.gainId();
24 
25  double pedestal = 0.;
26  double gainratio = 1.;
27 
28  if (gainId == 0 || gainId == 3) {
29  pedestal = aped->mean_x1;
30  gainratio = aGain->gain6Over1() * aGain->gain12Over6();
31  } else if (gainId == 1) {
32  pedestal = aped->mean_x12;
33  gainratio = 1.;
34  } else if (gainId == 2) {
35  pedestal = aped->mean_x6;
36  gainratio = aGain->gain12Over6();
37  }
38 
39  amplitude = (static_cast<float>(sample.adc()) - pedestal) * gainratio;
40 
41  if (gainId == 0) {
42  //saturation
43  amplitude = (4095. - pedestal) * gainratio;
44  }
45 
46  pedSubSamples[iSample] = amplitude;
47 
48  if (amplitude > maxamplitude) {
49  maxamplitude = amplitude;
50  }
51  pulsenorm += fullpulse(iSample);
52  }
53 
54  if (correctForOOT) {
55  int ipulse = -1;
56  for (auto const& amplit : amplitudes) {
57  ipulse++;
58  int bxp3 = ipulse - 2;
59  int firstsamplet = std::max(0, bxp3);
60  int offset = 7 - bxp3;
61 
62  for (unsigned int isample = firstsamplet; isample < nsample; ++isample) {
63  auto const pulse = fullpulse(isample + offset);
64  pedSubSamples[isample] = std::max(0., pedSubSamples[isample] - amplit * pulse / pulsenorm);
65  }
66  }
67  }
68 
69  // Start of time computation
71  float t3 = stopTime_ + GLOBAL_TIME_SHIFT;
72  float t2 = (t3 + t0) / 2;
73  float t1 = t2 - ONE_MINUS_GOLDEN_RATIO * (t3 - t0);
74 
75  int counter = 0;
76 
77  float cc1 = computeCC(pedSubSamples, fullpulse, t1);
78  ++counter;
79  float cc2 = computeCC(pedSubSamples, fullpulse, t2);
80  ++counter;
81 
82  while (std::abs(t3 - t0) > targetTimePrecision && counter < MAX_NUM_OF_ITERATIONS) {
83  if (cc2 > cc1) {
84  t0 = t1;
85  t1 = t2;
87  cc1 = cc2;
88  cc2 = computeCC(pedSubSamples, fullpulse, t2);
89  ++counter;
90  } else {
91  t3 = t2;
92  t2 = t1;
94  cc2 = cc1;
95  cc1 = computeCC(pedSubSamples, fullpulse, t1);
96  ++counter;
97  }
98  }
99 
100  float tM = (t3 + t0) / 2 - GLOBAL_TIME_SHIFT;
101  if (counter < MIN_NUM_OF_ITERATIONS || counter > MAX_NUM_OF_ITERATIONS - 1) {
103  }
104  return -tM / ecalPh1::Samp_Period;
105 }
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)
float gain6Over1() const
static std::atomic< unsigned int > counter
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48

◆ interpolatePulse()

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

Definition at line 107 of file EcalUncalibRecHitTimingCCAlgo.cc.

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

Referenced by computeCC().

108  {
109  // t is in ns
111  if (time < 0)
112  shift -= 1;
113  float tt = time / ecalPh1::Samp_Period - shift;
114 
115  FullSampleVector interpPulse;
116  // 2nd poly with avg
117  unsigned int numberOfSamples = fullpulse.size();
118  auto facM1orP2 = 0.25 * tt * (tt - 1);
119  auto fac = (0.25 * (tt - 2) - 0.5 * (tt + 1)) * (tt - 1);
120  auto facP1 = (0.25 * (tt + 1) - 0.5 * (tt - 2)) * tt;
121  for (unsigned int i = 1; i < numberOfSamples - 2; ++i) {
122  float a =
123  facM1orP2 * fullpulse[i - 1] + fac * fullpulse[i] + facP1 * fullpulse[i + 1] + facM1orP2 * fullpulse[i + 2];
124  if (a > 0)
125  interpPulse[i] = a;
126  else
127  interpPulse[i] = 0;
128  }
129  interpPulse[0] = facM1orP2 * fullpulse[0] + facP1 * fullpulse[1] + facM1orP2 * fullpulse[2];
130  interpPulse[numberOfSamples - 2] = facM1orP2 * fullpulse[numberOfSamples - 3] + fac * fullpulse[numberOfSamples - 2] +
131  facP1 * fullpulse[numberOfSamples - 1];
132  interpPulse[numberOfSamples - 1] = 2 * facM1orP2 * fullpulse[numberOfSamples - 2] -
133  4 * facM1orP2 * fullpulse[numberOfSamples - 1] +
134  facP1 * fullpulse[numberOfSamples - 1];
135 
136  FullSampleVector interpPulseShifted;
137  for (int i = 0; i < interpPulseShifted.size(); ++i) {
138  if (i + shift >= 0 && i + shift < interpPulse.size())
139  interpPulseShifted[i] = interpPulse[i + shift];
140  else
141  interpPulseShifted[i] = 0;
142  }
143  return interpPulseShifted;
144 }
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 36 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ GOLDEN_RATIO

constexpr float EcalUncalibRecHitTimingCCAlgo::GOLDEN_RATIO = 0.61803399
staticprivate

Definition at line 37 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ MAX_NUM_OF_ITERATIONS

constexpr int EcalUncalibRecHitTimingCCAlgo::MAX_NUM_OF_ITERATIONS = 60
staticprivate

Definition at line 34 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ MIN_NUM_OF_ITERATIONS

constexpr int EcalUncalibRecHitTimingCCAlgo::MIN_NUM_OF_ITERATIONS = 2
staticprivate

Definition at line 35 of file EcalUncalibRecHitTimingCCAlgo.h.

◆ ONE_MINUS_GOLDEN_RATIO

constexpr float EcalUncalibRecHitTimingCCAlgo::ONE_MINUS_GOLDEN_RATIO = 1.0 - GOLDEN_RATIO
staticprivate

Definition at line 38 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ startTime_

const float EcalUncalibRecHitTimingCCAlgo::startTime_
private

Definition at line 30 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ stopTime_

const float EcalUncalibRecHitTimingCCAlgo::stopTime_
private

Definition at line 31 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().

◆ TIME_WHEN_NOT_CONVERGING

constexpr int EcalUncalibRecHitTimingCCAlgo::TIME_WHEN_NOT_CONVERGING = 100
staticprivate

Definition at line 33 of file EcalUncalibRecHitTimingCCAlgo.h.

Referenced by computeTimeCC().