CMS 3D CMS Logo

EcalUncalibRecHitTimingCCAlgo.cc
Go to the documentation of this file.
2 
4  const float stopTime,
5  const float targetTimePrecision)
6  : startTime_(startTime), stopTime_(stopTime), targetTimePrecision_(targetTimePrecision) {}
7 
9  const std::vector<double>& amplitudes,
10  const EcalPedestals::Item* aped,
11  const EcalMGPAGainRatio* aGain,
12  const FullSampleVector& fullpulse,
13  EcalUncalibratedRecHit& uncalibRecHit,
14  float& errOnTime) 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  int ipulse = -1;
57  for (auto const& amplit : amplitudes) {
58  ipulse++;
59  int bxp3 = ipulse - 2;
60  int firstsamplet = std::max(0, bxp3);
61  int offset = 7 - bxp3;
62 
63  for (unsigned int isample = firstsamplet; isample < nsample; ++isample) {
64  auto const pulse = fullpulse(isample + offset);
65  pedSubSamples[isample] = std::max(0., pedSubSamples[isample] - amplit * pulse / pulsenorm);
66  }
67  }
68 
69  // Start of time computation
70  float tStart = startTime_ + GLOBAL_TIME_SHIFT;
71  float tStop = stopTime_ + GLOBAL_TIME_SHIFT;
72  float tM = (tStart + tStop) / 2;
73 
74  float distStart, distStop;
75  int counter = 0;
76 
77  do {
78  ++counter;
79  distStart = computeCC(pedSubSamples, fullpulse, tStart);
80  distStop = computeCC(pedSubSamples, fullpulse, tStop);
81 
82  if (distStart > distStop) {
83  tStop = tM;
84  } else {
85  tStart = tM;
86  }
87  tM = (tStart + tStop) / 2;
88 
89  } while (tStop - tStart > targetTimePrecision_ && counter < MAX_NUM_OF_ITERATIONS);
90 
91  tM -= GLOBAL_TIME_SHIFT;
92  errOnTime = targetTimePrecision_;
93 
94  if (counter < MIN_NUM_OF_ITERATIONS || counter > MAX_NUM_OF_ITERATIONS - 1) {
96  //Negative error means that there was a problem with the CC
98  }
99 
100  return -tM / ecalPh1::Samp_Period;
101 }
102 
104  const float time) const {
105  // t is in ns
107  if (time < 0)
108  shift -= 1;
109  float tt = time / ecalPh1::Samp_Period - shift;
110 
111  FullSampleVector interpPulse;
112  // 2nd poly with avg
113  unsigned int numberOfSamples = fullpulse.size();
114  auto facM1orP2 = 0.25 * tt * (tt - 1);
115  auto fac = (0.25 * (tt - 2) - 0.5 * (tt + 1)) * (tt - 1);
116  auto facP1 = (0.25 * (tt + 1) - 0.5 * (tt - 2)) * tt;
117  for (unsigned int i = 1; i < numberOfSamples - 2; ++i) {
118  float a =
119  facM1orP2 * fullpulse[i - 1] + fac * fullpulse[i] + facP1 * fullpulse[i + 1] + facM1orP2 * fullpulse[i + 2];
120  if (a > 0)
121  interpPulse[i] = a;
122  else
123  interpPulse[i] = 0;
124  }
125  interpPulse[0] = facM1orP2 * fullpulse[0] + facP1 * fullpulse[1] + facM1orP2 * fullpulse[2];
126  interpPulse[numberOfSamples - 2] = facM1orP2 * fullpulse[numberOfSamples - 3] + fac * fullpulse[numberOfSamples - 2] +
127  facP1 * fullpulse[numberOfSamples - 1];
128  interpPulse[numberOfSamples - 1] = 2 * facM1orP2 * fullpulse[numberOfSamples - 2] -
129  4 * facM1orP2 * fullpulse[numberOfSamples - 1] +
130  facP1 * fullpulse[numberOfSamples - 1];
131 
132  FullSampleVector interpPulseShifted;
133  for (int i = 0; i < interpPulseShifted.size(); ++i) {
134  if (i + shift >= 0 && i + shift < interpPulse.size())
135  interpPulseShifted[i] = interpPulse[i + shift];
136  else
137  interpPulseShifted[i] = 0;
138  }
139  return interpPulseShifted;
140 }
141 
142 float EcalUncalibRecHitTimingCCAlgo::computeCC(const std::vector<float>& samples,
143  const FullSampleVector& signalTemplate,
144  const float time) const {
145  constexpr int exclude = 1;
146  float powerSamples = 0.;
147  float powerTemplate = 0.;
148  float cc = 0.;
149  auto interpolated = interpolatePulse(signalTemplate, time);
150  for (int i = exclude; i < int(samples.size() - exclude); ++i) {
151  powerSamples += std::pow(samples[i], 2);
152  powerTemplate += std::pow(interpolated[i], 2);
153  cc += interpolated[i] * samples[i];
154  }
155 
156  float denominator = std::sqrt(powerTemplate * powerSamples);
157  return cc / denominator;
158 }
EcalDataFrame::MAXSAMPLES
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
EcalUncalibRecHitTimingCCAlgo::computeTimeCC
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
Definition: EcalUncalibRecHitTimingCCAlgo.cc:8
EcalUncalibRecHitTimingCCAlgo::EcalUncalibRecHitTimingCCAlgo
EcalUncalibRecHitTimingCCAlgo(const float startTime, const float stopTime, const float targetTimePrecision)
Definition: EcalUncalibRecHitTimingCCAlgo.cc:3
EcalDataFrame::sample
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
counter
Definition: counter.py:1
ecalLiteDTU::gainId
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
Definition: EcalLiteDTUSample.h:14
mps_fire.i
i
Definition: mps_fire.py:428
CustomPhysics_cfi.amplitude
amplitude
Definition: CustomPhysics_cfi.py:12
ecalPh1::Samp_Period
static constexpr double Samp_Period
Definition: EcalConstants.h:25
EcalUncalibRecHitTimingCCAlgo::stopTime_
const float stopTime_
Definition: EcalUncalibRecHitTimingCCAlgo.h:31
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
simplePhotonAnalyzer_cfi.sample
sample
Definition: simplePhotonAnalyzer_cfi.py:12
pulse
double pulse(double x, double y, double z, double t)
Definition: SiStripPulseShape.cc:49
protons_cff.time
time
Definition: protons_cff.py:35
EcalDataFrame
Definition: EcalDataFrame.h:16
EcalUncalibRecHitTimingCCAlgo::TIME_WHEN_NOT_CONVERGING
static constexpr int TIME_WHEN_NOT_CONVERGING
Definition: EcalUncalibRecHitTimingCCAlgo.h:34
EcalUncalibRecHitTimingCCAlgo::targetTimePrecision_
const float targetTimePrecision_
Definition: EcalUncalibRecHitTimingCCAlgo.h:32
EgammaValidation_cff.samples
samples
Definition: EgammaValidation_cff.py:18
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
EcalMGPAGainRatio::gain12Over6
float gain12Over6() const
Definition: EcalMGPAGainRatio.h:19
EcalUncalibRecHitTimingCCAlgo::computeCC
float computeCC(const std::vector< float > &samples, const FullSampleVector &sigmalTemplate, const float t) const
Definition: EcalUncalibRecHitTimingCCAlgo.cc:142
a
double a
Definition: hdecay.h:119
EcalUncalibRecHitTimingCCAlgo::MAX_NUM_OF_ITERATIONS
static constexpr int MAX_NUM_OF_ITERATIONS
Definition: EcalUncalibRecHitTimingCCAlgo.h:35
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
EcalCondObjectContainer::Item
T Item
Definition: EcalCondObjectContainer.h:15
createfilelist.int
int
Definition: createfilelist.py:10
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:18
EcalCondDBWriter_cfi.pedestal
pedestal
Definition: EcalCondDBWriter_cfi.py:49
cc
EcalMGPASample
Definition: EcalMGPASample.h:22
FullSampleVector
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
Definition: EigenMatrixTypes.h:13
EcalUncalibratedRecHit
Definition: EcalUncalibratedRecHit.h:8
EcalUncalibRecHitTimingCCAlgo::startTime_
const float startTime_
Definition: EcalUncalibRecHitTimingCCAlgo.h:30
HLTTauDQMOffline_cfi.denominator
denominator
Definition: HLTTauDQMOffline_cfi.py:180
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
EcalUncalibRecHitTimingCCAlgo::interpolatePulse
FullSampleVector interpolatePulse(const FullSampleVector &fullpulse, const float t=0) const
Definition: EcalUncalibRecHitTimingCCAlgo.cc:103
EcalUncalibRecHitTimingCCAlgo.h
EcalMGPAGainRatio::gain6Over1
float gain6Over1() const
Definition: EcalMGPAGainRatio.h:20
EcalUncalibRecHitTimingCCAlgo::GLOBAL_TIME_SHIFT
static constexpr float GLOBAL_TIME_SHIFT
Definition: EcalUncalibRecHitTimingCCAlgo.h:37
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
numberOfSamples
Definition: TotemSampicFrame.h:53
EcalMGPAGainRatio
Definition: EcalMGPAGainRatio.h:13