CMS 3D CMS Logo

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

#include <EcalUncalibRecHitMultiFitAlgo.h>

Public Member Functions

void disableErrorCalculation ()
 
 EcalUncalibRecHitMultiFitAlgo ()
 
EcalUncalibratedRecHit makeRecHit (const EcalDataFrame &dataFrame, const EcalPedestals::Item *aped, const EcalMGPAGainRatio *aGain, const SampleMatrixGainArray &noisecors, const FullSampleVector &fullpulse, const FullSampleMatrix &fullpulsecov, const BXVector &activeBX)
 compute rechits More...
 
void setAddPedestalUncertainty (double x)
 
void setDoPrefit (bool b)
 
void setDynamicPedestals (bool b)
 
void setGainSwitchUseMaxSample (bool b)
 
void setMitigateBadSamples (bool b)
 
void setPrefitMaxChiSq (double x)
 
void setSelectiveBadSampleCriteria (bool b)
 
void setSimplifiedNoiseModelForGainSwitch (bool b)
 
 ~EcalUncalibRecHitMultiFitAlgo ()
 

Private Attributes

double _addPedestalUncertainty
 
bool _computeErrors
 
bool _doPrefit
 
bool _dynamicPedestals
 
bool _gainSwitchUseMaxSample
 
bool _mitigateBadSamples
 
double _prefitMaxChiSq
 
PulseChiSqSNNLS _pulsefunc
 
PulseChiSqSNNLS _pulsefuncSingle
 
bool _selectiveBadSampleCriteria
 
bool _simplifiedNoiseModelForGainSwitch
 
BXVector _singlebx
 

Detailed Description

Amplitude reconstucted by the multi-template fit

Author
J.Bendavid, E.Di Marco

Definition at line 20 of file EcalUncalibRecHitMultiFitAlgo.h.

Constructor & Destructor Documentation

◆ EcalUncalibRecHitMultiFitAlgo()

EcalUncalibRecHitMultiFitAlgo::EcalUncalibRecHitMultiFitAlgo ( )

Definition at line 8 of file EcalUncalibRecHitMultiFitAlgo.cc.

References _pulsefuncSingle, _singlebx, PulseChiSqSNNLS::disableErrorCalculation(), BXVector< T >::resize(), PulseChiSqSNNLS::setMaxIters(), and PulseChiSqSNNLS::setMaxIterWarnings().

9  : _computeErrors(true),
10  _doPrefit(false),
11  _prefitMaxChiSq(1.0),
12  _dynamicPedestals(false),
13  _mitigateBadSamples(false),
18  _singlebx.resize(1);
19  _singlebx << 0;
20 
24 }
void setMaxIterWarnings(bool b)
void setMaxIters(int n)
void disableErrorCalculation()
void resize(int bx, unsigned size)

◆ ~EcalUncalibRecHitMultiFitAlgo()

EcalUncalibRecHitMultiFitAlgo::~EcalUncalibRecHitMultiFitAlgo ( )
inline

Definition at line 23 of file EcalUncalibRecHitMultiFitAlgo.h.

23 {};

Member Function Documentation

◆ disableErrorCalculation()

void EcalUncalibRecHitMultiFitAlgo::disableErrorCalculation ( )
inline

◆ makeRecHit()

EcalUncalibratedRecHit EcalUncalibRecHitMultiFitAlgo::makeRecHit ( const EcalDataFrame dataFrame,
const EcalPedestals::Item aped,
const EcalMGPAGainRatio aGain,
const SampleMatrixGainArray noisecors,
const FullSampleVector fullpulse,
const FullSampleMatrix fullpulsecov,
const BXVector activeBX 
)

compute rechits

Definition at line 27 of file EcalUncalibRecHitMultiFitAlgo.cc.

References _addPedestalUncertainty, _computeErrors, _doPrefit, _dynamicPedestals, _gainSwitchUseMaxSample, _mitigateBadSamples, _prefitMaxChiSq, _pulsefunc, _pulsefuncSingle, _selectiveBadSampleCriteria, _simplifiedNoiseModelForGainSwitch, _singlebx, funct::abs(), CustomPhysics_cfi::amplitude, nano_mu_digi_cff::bx, PulseChiSqSNNLS::BXs(), PulseChiSqSNNLS::ChiSq(), PulseChiSqSNNLS::disableErrorCalculation(), PulseChiSqSNNLS::DoFit(), PulseChiSqSNNLS::Errors(), HLT_2023v12_cff::flags, EcalMGPAGainRatio::gain12Over6(), EcalMGPAGainRatio::gain6Over1(), ecalLiteDTU::gainId(), EcalDataFrame::hasSwitchToGain1(), EcalDataFrame::hasSwitchToGain6(), EcalDataFrame::id(), EcalDataFrame::isSaturated(), ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::mask, SiStripPI::max, EcalDataFrame::MAXSAMPLES, EcalCondDBWriter_cfi::pedestal, EcalDataFrame::sample(), ecalGpuTask_cfi::sample, EcalUncalibratedRecHit::setAmplitudeError(), mps_update::status, and PulseChiSqSNNLS::X().

Referenced by EcalUncalibRecHitWorkerMultiFit::run().

33  {
34  uint32_t flags = 0;
35 
36  const unsigned int nsample = EcalDataFrame::MAXSAMPLES;
37 
38  double maxamplitude = -std::numeric_limits<double>::max();
39  const unsigned int iSampleMax = 5;
40  const unsigned int iFullPulseMax = 9;
41 
42  double pedval = 0.;
43 
44  SampleVector amplitudes;
45  SampleGainVector gainsNoise;
46  SampleGainVector gainsPedestal;
47  SampleGainVector badSamples = SampleGainVector::Zero();
48  bool hasSaturation = dataFrame.isSaturated();
49  bool hasGainSwitch = hasSaturation || dataFrame.hasSwitchToGain6() || dataFrame.hasSwitchToGain1();
50 
51  //no dynamic pedestal in case of gain switch, since then the fit becomes too underconstrained
52  bool dynamicPedestal = _dynamicPedestals && !hasGainSwitch;
53 
54  for (unsigned int iSample = 0; iSample < nsample; iSample++) {
55  const EcalMGPASample &sample = dataFrame.sample(iSample);
56 
57  double amplitude = 0.;
58  int gainId = sample.gainId();
59 
60  double pedestal = 0.;
61  double gainratio = 1.;
62 
63  if (gainId == 0 || gainId == 3) {
64  pedestal = aped->mean_x1;
65  gainratio = aGain->gain6Over1() * aGain->gain12Over6();
66  gainsNoise[iSample] = 2;
67  gainsPedestal[iSample] = dynamicPedestal ? 2 : -1; //-1 for static pedestal
68  } else if (gainId == 1) {
69  pedestal = aped->mean_x12;
70  gainratio = 1.;
71  gainsNoise[iSample] = 0;
72  gainsPedestal[iSample] = dynamicPedestal ? 0 : -1; //-1 for static pedestal
73  } else if (gainId == 2) {
74  pedestal = aped->mean_x6;
75  gainratio = aGain->gain12Over6();
76  gainsNoise[iSample] = 1;
77  gainsPedestal[iSample] = dynamicPedestal ? 1 : -1; //-1 for static pedestals
78  }
79 
80  if (dynamicPedestal) {
81  amplitude = (double)(sample.adc()) * gainratio;
82  } else {
83  amplitude = ((double)(sample.adc()) - pedestal) * gainratio;
84  }
85 
86  if (gainId == 0) {
87  edm::LogError("EcalUncalibRecHitMultiFitAlgo")
88  << "Saturation encountered. Multifit is not intended to be used for saturated channels.";
89  //saturation
90  if (dynamicPedestal) {
91  amplitude = 4095. * gainratio;
92  } else {
93  amplitude = (4095. - pedestal) * gainratio;
94  }
95  }
96 
97  amplitudes[iSample] = amplitude;
98 
99  if (iSample == iSampleMax) {
100  maxamplitude = amplitude;
101  pedval = pedestal;
102  }
103  }
104 
105  double amplitude, amperr, chisq;
106  bool status = false;
107 
108  //special handling for gain switch, where sample before maximum is potentially affected by slew rate limitation
109  //optionally apply a stricter criteria, assuming slew rate limit is only reached in case where maximum sample has gain switched but previous sample has not
110  //option 1: use simple max-sample algorithm
111  if (hasGainSwitch && _gainSwitchUseMaxSample) {
112  double maxpulseamplitude = maxamplitude / fullpulse[iFullPulseMax];
113  EcalUncalibratedRecHit rh(dataFrame.id(), maxpulseamplitude, pedval, 0., 0., flags);
114  rh.setAmplitudeError(0.);
115  for (unsigned int ipulse = 0; ipulse < _pulsefunc.BXs().rows(); ++ipulse) {
116  int bx = _pulsefunc.BXs().coeff(ipulse);
117  if (bx != 0) {
118  rh.setOutOfTimeAmplitude(bx + 5, 0.0);
119  }
120  }
121  return rh;
122  }
123 
124  //option2: A floating negative single-sample offset is added to the fit
125  //such that the affected sample is treated only as a lower limit for the true amplitude
126  bool mitigateBadSample = _mitigateBadSamples && hasGainSwitch && iSampleMax > 0;
127  mitigateBadSample &=
128  (!_selectiveBadSampleCriteria || (gainsNoise.coeff(iSampleMax - 1) != gainsNoise.coeff(iSampleMax)));
129  if (mitigateBadSample) {
130  badSamples[iSampleMax - 1] = 1;
131  }
132 
133  //compute noise covariance matrix, which depends on the sample gains
134  SampleMatrix noisecov;
135  if (hasGainSwitch) {
136  std::array<double, 3> pedrmss = {{aped->rms_x12, aped->rms_x6, aped->rms_x1}};
137  std::array<double, 3> gainratios = {{1., aGain->gain12Over6(), aGain->gain6Over1() * aGain->gain12Over6()}};
139  int gainidxmax = gainsNoise[iSampleMax];
140  noisecov = gainratios[gainidxmax] * gainratios[gainidxmax] * pedrmss[gainidxmax] * pedrmss[gainidxmax] *
141  noisecors[gainidxmax];
142  if (!dynamicPedestal && _addPedestalUncertainty > 0.) {
143  //add fully correlated component to noise covariance to inflate pedestal uncertainty
144  noisecov += _addPedestalUncertainty * _addPedestalUncertainty * SampleMatrix::Ones();
145  }
146  } else {
147  noisecov = SampleMatrix::Zero();
148  for (unsigned int gainidx = 0; gainidx < noisecors.size(); ++gainidx) {
149  SampleGainVector mask = gainidx * SampleGainVector::Ones();
150  SampleVector pedestal = (gainsNoise.array() == mask.array()).cast<SampleVector::value_type>();
151  if (pedestal.maxCoeff() > 0.) {
152  //select out relevant components of each correlation matrix, and assume no correlation between samples with
153  //different gain
154  noisecov += gainratios[gainidx] * gainratios[gainidx] * pedrmss[gainidx] * pedrmss[gainidx] *
155  pedestal.asDiagonal() * noisecors[gainidx] * pedestal.asDiagonal();
156  if (!dynamicPedestal && _addPedestalUncertainty > 0.) {
157  //add fully correlated component to noise covariance to inflate pedestal uncertainty
158  noisecov += gainratios[gainidx] * gainratios[gainidx] * _addPedestalUncertainty * _addPedestalUncertainty *
159  pedestal.asDiagonal() * SampleMatrix::Ones() * pedestal.asDiagonal();
160  }
161  }
162  }
163  }
164  } else {
165  noisecov = aped->rms_x12 * aped->rms_x12 * noisecors[0];
166  if (!dynamicPedestal && _addPedestalUncertainty > 0.) {
167  //add fully correlated component to noise covariance to inflate pedestal uncertainty
168  noisecov += _addPedestalUncertainty * _addPedestalUncertainty * SampleMatrix::Ones();
169  }
170  }
171 
172  //optimized one-pulse fit for hlt
173  bool usePrefit = false;
174  if (_doPrefit) {
175  status =
176  _pulsefuncSingle.DoFit(amplitudes, noisecov, _singlebx, fullpulse, fullpulsecov, gainsPedestal, badSamples);
177  amplitude = status ? _pulsefuncSingle.X()[0] : 0.;
178  amperr = status ? _pulsefuncSingle.Errors()[0] : 0.;
179  chisq = _pulsefuncSingle.ChiSq();
180 
181  if (chisq < _prefitMaxChiSq) {
182  usePrefit = true;
183  }
184  }
185 
186  if (!usePrefit) {
187  if (!_computeErrors)
189  status = _pulsefunc.DoFit(amplitudes, noisecov, activeBX, fullpulse, fullpulsecov, gainsPedestal, badSamples);
190  chisq = _pulsefunc.ChiSq();
191 
192  if (!status) {
193  edm::LogWarning("EcalUncalibRecHitMultiFitAlgo::makeRecHit") << "Failed Fit" << std::endl;
194  }
195 
196  unsigned int ipulseintime = 0;
197  for (unsigned int ipulse = 0; ipulse < _pulsefunc.BXs().rows(); ++ipulse) {
198  if (_pulsefunc.BXs().coeff(ipulse) == 0) {
199  ipulseintime = ipulse;
200  break;
201  }
202  }
203 
204  amplitude = status ? _pulsefunc.X()[ipulseintime] : 0.;
205  amperr = status ? _pulsefunc.Errors()[ipulseintime] : 0.;
206  }
207 
208  double jitter = 0.;
209 
210  EcalUncalibratedRecHit rh(dataFrame.id(), amplitude, pedval, jitter, chisq, flags);
211  rh.setAmplitudeError(amperr);
212 
213  if (!usePrefit) {
214  for (unsigned int ipulse = 0; ipulse < _pulsefunc.BXs().rows(); ++ipulse) {
215  int bx = _pulsefunc.BXs().coeff(ipulse);
216  if (bx != 0 && std::abs(bx) < 100) {
217  rh.setOutOfTimeAmplitude(bx + 5, status ? _pulsefunc.X().coeff(ipulse) : 0.);
218  } else if (bx == (100 + gainsPedestal[iSampleMax])) {
219  rh.setPedestal(status ? _pulsefunc.X().coeff(ipulse) : 0.);
220  }
221  }
222  }
223 
224  return rh;
225 }
bool isSaturated() const
Definition: EcalDataFrame.h:38
bool hasSwitchToGain1() const
void disableErrorCalculation()
bool hasSwitchToGain6() const
bool DoFit(const SampleVector &samples, const SampleMatrix &samplecov, const BXVector &bxs, const FullSampleVector &fullpulse, const FullSampleMatrix &fullpulsecov, const SampleGainVector &gains=-1 *SampleGainVector::Ones(), const SampleGainVector &badSamples=SampleGainVector::Zero())
Log< level::Error, false > LogError
const BXVector & BXs() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
void setAmplitudeError(float amplitudeerror)
float gain12Over6() const
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
float gain6Over1() const
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
const PulseVector & Errors() const
Eigen::Matrix< char, SampleVectorSize, 1 > SampleGainVector
DetId id() const
Definition: EcalDataFrame.h:24
double ChiSq() const
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
Log< level::Warning, false > LogWarning
const PulseVector & X() const

◆ setAddPedestalUncertainty()

void EcalUncalibRecHitMultiFitAlgo::setAddPedestalUncertainty ( double  x)
inline

◆ setDoPrefit()

void EcalUncalibRecHitMultiFitAlgo::setDoPrefit ( bool  b)
inline

Definition at line 32 of file EcalUncalibRecHitMultiFitAlgo.h.

References _doPrefit, and b.

Referenced by EcalUncalibRecHitWorkerMultiFit::run().

◆ setDynamicPedestals()

void EcalUncalibRecHitMultiFitAlgo::setDynamicPedestals ( bool  b)
inline

◆ setGainSwitchUseMaxSample()

void EcalUncalibRecHitMultiFitAlgo::setGainSwitchUseMaxSample ( bool  b)
inline

◆ setMitigateBadSamples()

void EcalUncalibRecHitMultiFitAlgo::setMitigateBadSamples ( bool  b)
inline

◆ setPrefitMaxChiSq()

void EcalUncalibRecHitMultiFitAlgo::setPrefitMaxChiSq ( double  x)
inline

◆ setSelectiveBadSampleCriteria()

void EcalUncalibRecHitMultiFitAlgo::setSelectiveBadSampleCriteria ( bool  b)
inline

◆ setSimplifiedNoiseModelForGainSwitch()

void EcalUncalibRecHitMultiFitAlgo::setSimplifiedNoiseModelForGainSwitch ( bool  b)
inline

Member Data Documentation

◆ _addPedestalUncertainty

double EcalUncalibRecHitMultiFitAlgo::_addPedestalUncertainty
private

Definition at line 50 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit(), and setAddPedestalUncertainty().

◆ _computeErrors

bool EcalUncalibRecHitMultiFitAlgo::_computeErrors
private

Definition at line 44 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by disableErrorCalculation(), and makeRecHit().

◆ _doPrefit

bool EcalUncalibRecHitMultiFitAlgo::_doPrefit
private

Definition at line 45 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit(), and setDoPrefit().

◆ _dynamicPedestals

bool EcalUncalibRecHitMultiFitAlgo::_dynamicPedestals
private

Definition at line 47 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit(), and setDynamicPedestals().

◆ _gainSwitchUseMaxSample

bool EcalUncalibRecHitMultiFitAlgo::_gainSwitchUseMaxSample
private

Definition at line 52 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit(), and setGainSwitchUseMaxSample().

◆ _mitigateBadSamples

bool EcalUncalibRecHitMultiFitAlgo::_mitigateBadSamples
private

Definition at line 48 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit(), and setMitigateBadSamples().

◆ _prefitMaxChiSq

double EcalUncalibRecHitMultiFitAlgo::_prefitMaxChiSq
private

Definition at line 46 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit(), and setPrefitMaxChiSq().

◆ _pulsefunc

PulseChiSqSNNLS EcalUncalibRecHitMultiFitAlgo::_pulsefunc
private

Definition at line 42 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit().

◆ _pulsefuncSingle

PulseChiSqSNNLS EcalUncalibRecHitMultiFitAlgo::_pulsefuncSingle
private

Definition at line 43 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by EcalUncalibRecHitMultiFitAlgo(), and makeRecHit().

◆ _selectiveBadSampleCriteria

bool EcalUncalibRecHitMultiFitAlgo::_selectiveBadSampleCriteria
private

Definition at line 49 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit(), and setSelectiveBadSampleCriteria().

◆ _simplifiedNoiseModelForGainSwitch

bool EcalUncalibRecHitMultiFitAlgo::_simplifiedNoiseModelForGainSwitch
private

◆ _singlebx

BXVector EcalUncalibRecHitMultiFitAlgo::_singlebx
private

Definition at line 53 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by EcalUncalibRecHitMultiFitAlgo(), and makeRecHit().