CMS 3D CMS Logo

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

#include <MahiFit.h>

Public Types

typedef BXVector::Index Index
 

Public Member Functions

void doFit (std::array< float, 3 > &correctedOutput, const int nbx) const
 
 MahiFit ()
 
void phase1Apply (const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
 
void phase1Debug (const HBHEChannelInfo &channelData, MahiDebugInfo &mdi) const
 
void resetPulseShapeTemplate (const HcalPulseShapes::Shape &ps, bool hasTimeInfo, unsigned int nSamples)
 
void setParameters (bool iDynamicPed, double iTS4Thresh, double chiSqSwitch, bool iApplyTimeSlew, HcalTimeSlew::BiasSetting slewFlavor, bool iCalculateArrivalTime, double iMeanTime, double iTimeSigmaHPD, double iTimeSigmaSiPM, const std::vector< int > &iActiveBXs, int iNMaxItersMin, int iNMaxItersNNLS, double iDeltaChiSqThresh, double iNnlsThresh)
 
void setPulseShapeTemplate (const HcalPulseShapes::Shape &ps, bool hasTimeInfo, const HcalTimeSlew *hcalTimeSlewDelay, unsigned int nSamples)
 
 ~MahiFit ()
 

Public Attributes

const HcalPulseShapes::ShapecurrentPulseShape_ = 0
 
const HcalTimeSlewhcalTimeSlewDelay_ = 0
 

Private Member Functions

float calculateArrivalTime (unsigned int iBX) const
 
float calculateChiSq () const
 
const float minimize () const
 
void nnls () const
 
void nnlsConstrainParameter (Index minratioidx) const
 
void nnlsUnconstrainParameter (Index idxp) const
 
void onePulseMinimize () const
 
void resetWorkspace () const
 
void solveSubmatrix (PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned nP) const
 
void updateCov (const SampleMatrix &invCovMat) const
 
void updatePulseShape (const float itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv, FullSampleMatrix &pulseCov) const
 

Private Attributes

std::vector< int > activeBXs_
 
bool applyTimeSlew_
 
int bxOffsetConf_
 
unsigned int bxSizeConf_
 
bool calculateArrivalTime_
 
float chiSqSwitch_
 
int cntsetPulseShape_
 
float deltaChiSqThresh_
 
bool dynamicPed_
 
float meanTime_
 
int nMaxItersMin_
 
int nMaxItersNNLS_
 
float nnlsThresh_
 
MahiNnlsWorkspace nnlsWork_
 
float norm_ = (1.f / std::sqrt(12))
 
std::unique_ptr< ROOT::Math::Functor > pfunctor_
 
std::unique_ptr< FitterFuncs::PulseShapeFunctorpsfPtr_
 
HcalTimeSlew::BiasSetting slewFlavor_
 
float timeSigmaHPD_
 
float timeSigmaSiPM_
 
float ts4Thresh_
 
float tsDelay1GeV_ = 0.f
 

Static Private Attributes

static int pedestalBX_ = 100
 
static float timeLimit_ = 12.5f
 

Detailed Description

Definition at line 89 of file MahiFit.h.

Member Typedef Documentation

typedef BXVector::Index MahiFit::Index

Definition at line 125 of file MahiFit.h.

Constructor & Destructor Documentation

MahiFit::MahiFit ( )

Definition at line 5 of file MahiFit.cc.

5 {}
MahiFit::~MahiFit ( )
inline

Definition at line 92 of file MahiFit.h.

References hltPixelTracks_cff::chi2, HLT_2018_cff::chiSqSwitch, and PresampleTask_cfi::nSamples.

92 {};

Member Function Documentation

float MahiFit::calculateArrivalTime ( unsigned int  iBX) const
private

Definition at line 319 of file MahiFit.cc.

References MahiNnlsWorkspace::amplitudes, MahiNnlsWorkspace::ampVec, MahiNnlsWorkspace::bxOffset, MahiNnlsWorkspace::bxs, nnlsWork_, MahiNnlsWorkspace::nPulseTot, MahiNnlsWorkspace::pulseDerivMat, MahiNnlsWorkspace::pulseMat, OrderedSet::t, and timeLimit_.

Referenced by doFit().

319  {
320  if (nnlsWork_.nPulseTot > 1) {
321  SamplePulseMatrix pulseDerivMatTMP = nnlsWork_.pulseDerivMat;
322  for (unsigned int iBX = 0; iBX < nnlsWork_.nPulseTot; ++iBX) {
323  nnlsWork_.pulseDerivMat.col(iBX) = pulseDerivMatTMP.col(nnlsWork_.bxs.coeff(iBX) + nnlsWork_.bxOffset);
324  }
325  }
326 
327  for (unsigned int iBX = 0; iBX < nnlsWork_.nPulseTot; ++iBX) {
328  nnlsWork_.pulseDerivMat.col(iBX) *= nnlsWork_.ampVec.coeff(iBX);
329  }
330 
331  //FIXME: avoid solve full equation for one element
333  PulseVector solution = nnlsWork_.pulseDerivMat.colPivHouseholderQr().solve(residuals);
334  float t = std::clamp((float)solution.coeff(itIndex), -timeLimit_, timeLimit_);
335 
336  return t;
337 }
unsigned int nPulseTot
Definition: MahiFit.h:18
Eigen::Matrix< double, SampleVectorSize, Eigen::Dynamic, 0, SampleVectorSize, PulseVectorSize > SamplePulseMatrix
SampleVector amplitudes
Definition: MahiFit.h:29
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
PulseVector ampVec
Definition: MahiFit.h:49
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
SamplePulseMatrix pulseDerivMat
Definition: MahiFit.h:45
static float timeLimit_
Definition: MahiFit.h:155
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
SamplePulseMatrix pulseMat
Definition: MahiFit.h:42
BXVector bxs
Definition: MahiFit.h:26
float MahiFit::calculateChiSq ( ) const
private

Definition at line 441 of file MahiFit.cc.

References MahiNnlsWorkspace::amplitudes, MahiNnlsWorkspace::ampVec, MahiNnlsWorkspace::covDecomp, nnlsWork_, and MahiNnlsWorkspace::pulseMat.

Referenced by minimize().

441  {
443  .squaredNorm();
444 }
SampleVector amplitudes
Definition: MahiFit.h:29
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
PulseVector ampVec
Definition: MahiFit.h:49
SampleDecompLLT covDecomp
Definition: MahiFit.h:55
SamplePulseMatrix pulseMat
Definition: MahiFit.h:42
void MahiFit::doFit ( std::array< float, 3 > &  correctedOutput,
const int  nbx 
) const

Definition at line 115 of file MahiFit.cc.

References activeBXs_, MahiNnlsWorkspace::amplitudes, MahiNnlsWorkspace::ampVec, MahiNnlsWorkspace::bxOffset, bxOffsetConf_, MahiNnlsWorkspace::bxs, bxSizeConf_, calculateArrivalTime(), calculateArrivalTime_, dynamicPed_, MahiNnlsWorkspace::maxoffset, minimize(), nnlsWork_, MahiNnlsWorkspace::nPulseTot, hltrates_dqm_sourceclient-live_cfg::offset, pedestalBX_, MahiNnlsWorkspace::pulseCovArray, MahiNnlsWorkspace::pulseDerivMat, MahiNnlsWorkspace::pulseMat, MahiNnlsWorkspace::tsOffset, MahiNnlsWorkspace::tsSize, and updatePulseShape().

Referenced by phase1Apply().

115  {
116  unsigned int bxSize = 1;
117 
118  if (nbx == 1) {
119  nnlsWork_.bxOffset = 0;
120  } else {
121  bxSize = bxSizeConf_;
123  }
124 
125  nnlsWork_.nPulseTot = bxSize;
126 
127  if (dynamicPed_)
129  nnlsWork_.bxs.setZero(nnlsWork_.nPulseTot);
130 
131  if (nbx == 1) {
132  nnlsWork_.bxs.coeffRef(0) = 0;
133  } else {
134  for (unsigned int iBX = 0; iBX < bxSize; ++iBX) {
135  nnlsWork_.bxs.coeffRef(iBX) =
136  activeBXs_[iBX] -
137  ((static_cast<int>(nnlsWork_.tsOffset) + activeBXs_[0]) >= 0 ? 0 : (nnlsWork_.tsOffset + activeBXs_[0]));
138  }
139  }
140 
141  nnlsWork_.maxoffset = nnlsWork_.bxs.coeff(bxSize - 1);
142  if (dynamicPed_)
144 
147 
148  FullSampleVector pulseShapeArray;
149  FullSampleVector pulseDerivArray;
150  FullSampleMatrix pulseCov;
151 
152  int offset = 0;
153  for (unsigned int iBX = 0; iBX < nnlsWork_.nPulseTot; ++iBX) {
154  offset = nnlsWork_.bxs.coeff(iBX);
155 
156  if (offset == pedestalBX_) {
157  nnlsWork_.pulseMat.col(iBX) = SampleVector::Ones(nnlsWork_.tsSize);
158  nnlsWork_.pulseDerivMat.col(iBX) = SampleVector::Zero(nnlsWork_.tsSize);
159  } else {
160  pulseShapeArray.setZero(nnlsWork_.tsSize + nnlsWork_.maxoffset + nnlsWork_.bxOffset);
162  pulseDerivArray.setZero(nnlsWork_.tsSize + nnlsWork_.maxoffset + nnlsWork_.bxOffset);
163  pulseCov.setZero(nnlsWork_.tsSize + nnlsWork_.maxoffset + nnlsWork_.bxOffset,
166 
168  nnlsWork_.amplitudes.coeff(nnlsWork_.tsOffset + offset), pulseShapeArray, pulseDerivArray, pulseCov);
169 
170  nnlsWork_.pulseMat.col(iBX) = pulseShapeArray.segment(nnlsWork_.maxoffset - offset, nnlsWork_.tsSize);
172  nnlsWork_.pulseDerivMat.col(iBX) = pulseDerivArray.segment(nnlsWork_.maxoffset - offset, nnlsWork_.tsSize);
173  nnlsWork_.pulseCovArray[iBX] = pulseCov.block(
175  }
176  }
177 
178  const float chiSq = minimize();
179 
180  bool foundintime = false;
181  unsigned int ipulseintime = 0;
182 
183  for (unsigned int iBX = 0; iBX < nnlsWork_.nPulseTot; ++iBX) {
184  if (nnlsWork_.bxs.coeff(iBX) == 0) {
185  ipulseintime = iBX;
186  foundintime = true;
187  break;
188  }
189  }
190 
191  if (foundintime) {
192  correctedOutput.at(0) = nnlsWork_.ampVec.coeff(ipulseintime); //charge
193  if (correctedOutput.at(0) != 0) {
194  // fixME store the timeslew
195  float arrivalTime = 0.f;
197  arrivalTime = calculateArrivalTime(ipulseintime);
198  correctedOutput.at(1) = arrivalTime; //time
199  } else
200  correctedOutput.at(1) = -9999.f; //time
201 
202  correctedOutput.at(2) = chiSq; //chi2
203  }
204 }
unsigned int nPulseTot
Definition: MahiFit.h:18
SampleVector amplitudes
Definition: MahiFit.h:29
void updatePulseShape(const float itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv, FullSampleMatrix &pulseCov) const
Definition: MahiFit.cc:242
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
PulseVector ampVec
Definition: MahiFit.h:49
float calculateArrivalTime(unsigned int iBX) const
Definition: MahiFit.cc:319
std::array< SampleMatrix, MaxPVSize > pulseCovArray
Definition: MahiFit.h:39
SamplePulseMatrix pulseDerivMat
Definition: MahiFit.h:45
bool calculateArrivalTime_
Definition: MahiFit.h:167
int bxOffsetConf_
Definition: MahiFit.h:181
unsigned int bxSizeConf_
Definition: MahiFit.h:180
const float minimize() const
Definition: MahiFit.cc:206
std::vector< int > activeBXs_
Definition: MahiFit.h:172
unsigned int tsOffset
Definition: MahiFit.h:20
SamplePulseMatrix pulseMat
Definition: MahiFit.h:42
bool dynamicPed_
Definition: MahiFit.h:158
unsigned int tsSize
Definition: MahiFit.h:19
BXVector bxs
Definition: MahiFit.h:26
static int pedestalBX_
Definition: MahiFit.h:151
const float MahiFit::minimize ( ) const
private

Definition at line 206 of file MahiFit.cc.

References funct::abs(), MahiNnlsWorkspace::ampVec, calculateChiSq(), deltaChiSqThresh_, MahiNnlsWorkspace::invcovp, nMaxItersMin_, nnls(), nnlsWork_, MahiNnlsWorkspace::noiseTerms, MahiNnlsWorkspace::nPulseTot, onePulseMinimize(), MahiNnlsWorkspace::pedVal, MahiNnlsWorkspace::tsSize, and updateCov().

Referenced by doFit().

206  {
209 
210  SampleMatrix invCovMat;
211  invCovMat.setConstant(nnlsWork_.tsSize, nnlsWork_.tsSize, nnlsWork_.pedVal);
212  invCovMat += nnlsWork_.noiseTerms.asDiagonal();
213 
214  float oldChiSq = 9999;
215  float chiSq = oldChiSq;
216 
217  for (int iter = 1; iter < nMaxItersMin_; ++iter) {
218  updateCov(invCovMat);
219 
220  if (nnlsWork_.nPulseTot > 1) {
221  nnls();
222  } else {
224  }
225 
226  const float newChiSq = calculateChiSq();
227  const float deltaChiSq = newChiSq - chiSq;
228 
229  if (newChiSq == oldChiSq && newChiSq < chiSq) {
230  break;
231  }
232  oldChiSq = chiSq;
233  chiSq = newChiSq;
234 
235  if (std::abs(deltaChiSq) < deltaChiSqThresh_)
236  break;
237  }
238 
239  return chiSq;
240 }
unsigned int nPulseTot
Definition: MahiFit.h:18
void nnls() const
Definition: MahiFit.cc:339
SamplePulseMatrix invcovp
Definition: MahiFit.h:51
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
PulseVector ampVec
Definition: MahiFit.h:49
void onePulseMinimize() const
Definition: MahiFit.cc:431
int nMaxItersMin_
Definition: MahiFit.h:174
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void updateCov(const SampleMatrix &invCovMat) const
Definition: MahiFit.cc:298
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
SampleVector noiseTerms
Definition: MahiFit.h:32
float calculateChiSq() const
Definition: MahiFit.cc:441
unsigned int tsSize
Definition: MahiFit.h:19
float deltaChiSqThresh_
Definition: MahiFit.h:177
void MahiFit::nnls ( ) const
private

Definition at line 339 of file MahiFit.cc.

References MahiNnlsWorkspace::amplitudes, MahiNnlsWorkspace::ampVec, MahiNnlsWorkspace::aTaMat, MahiNnlsWorkspace::aTbVec, MahiNnlsWorkspace::covDecomp, MahiNnlsWorkspace::invcovp, SiStripPI::max, min(), nMaxItersNNLS_, nnlsConstrainParameter(), nnlsThresh_, nnlsUnconstrainParameter(), nnlsWork_, MahiNnlsWorkspace::nP, MahiNnlsWorkspace::nPulseTot, MahiNnlsWorkspace::pulseMat, particleFlowDisplacedVertex_cfi::ratio, solveSubmatrix(), MessageLogger_cff::threshold, and MahiNnlsWorkspace::tsSize.

Referenced by minimize().

339  {
340  const unsigned int npulse = nnlsWork_.nPulseTot;
341  const unsigned int nsamples = nnlsWork_.tsSize;
342 
343  PulseVector updateWork;
344 
347  nnlsWork_.aTbVec = nnlsWork_.invcovp.transpose() * (nnlsWork_.covDecomp.matrixL().solve(nnlsWork_.amplitudes));
348 
349  int iter = 0;
350  Index idxwmax = 0;
351  float wmax = 0.0f;
352  float threshold = nnlsThresh_;
353 
354  while (true) {
355  if (iter > 0 || nnlsWork_.nP == 0) {
356  if (nnlsWork_.nP == std::min(npulse, nsamples))
357  break;
358 
359  const unsigned int nActive = npulse - nnlsWork_.nP;
360  // exit if there are no more pulses to constrain
361  if (nActive == 0)
362  break;
363 
364  updateWork = nnlsWork_.aTbVec - nnlsWork_.aTaMat * nnlsWork_.ampVec;
365 
366  Index idxwmaxprev = idxwmax;
367  float wmaxprev = wmax;
368  wmax = updateWork.tail(nActive).maxCoeff(&idxwmax);
369 
370  if (wmax < threshold || (idxwmax == idxwmaxprev && wmax == wmaxprev)) {
371  break;
372  }
373 
374  if (iter >= nMaxItersNNLS_) {
375  break;
376  }
377 
378  //unconstrain parameter
379  idxwmax += nnlsWork_.nP;
380  nnlsUnconstrainParameter(idxwmax);
381  }
382 
383  while (true) {
384  if (nnlsWork_.nP == 0)
385  break;
386 
387  PulseVector ampvecpermtest = nnlsWork_.ampVec.head(nnlsWork_.nP);
388 
390 
391  //check solution
392  if (ampvecpermtest.head(nnlsWork_.nP).minCoeff() > 0.f) {
393  nnlsWork_.ampVec.head(nnlsWork_.nP) = ampvecpermtest.head(nnlsWork_.nP);
394  break;
395  }
396 
397  //update parameter vector
398  Index minratioidx = 0;
399 
400  // no realizable optimization here (because it autovectorizes!)
401  float minratio = std::numeric_limits<float>::max();
402  for (unsigned int ipulse = 0; ipulse < nnlsWork_.nP; ++ipulse) {
403  if (ampvecpermtest.coeff(ipulse) <= 0.f) {
404  const float c_ampvec = nnlsWork_.ampVec.coeff(ipulse);
405  const float ratio = c_ampvec / (c_ampvec - ampvecpermtest.coeff(ipulse));
406  if (ratio < minratio) {
407  minratio = ratio;
408  minratioidx = ipulse;
409  }
410  }
411  }
412  nnlsWork_.ampVec.head(nnlsWork_.nP) +=
413  minratio * (ampvecpermtest.head(nnlsWork_.nP) - nnlsWork_.ampVec.head(nnlsWork_.nP));
414 
415  //avoid numerical problems with later ==0. check
416  nnlsWork_.ampVec.coeffRef(minratioidx) = 0.f;
417 
418  nnlsConstrainParameter(minratioidx);
419  }
420 
421  ++iter;
422 
423  //adaptive convergence threshold to avoid infinite loops but still
424  //ensure best value is used
425  if (iter % 10 == 0) {
426  threshold *= 10.;
427  }
428  }
429 }
unsigned int nPulseTot
Definition: MahiFit.h:18
SamplePulseMatrix invcovp
Definition: MahiFit.h:51
void nnlsConstrainParameter(Index minratioidx) const
Definition: MahiFit.cc:486
SampleVector amplitudes
Definition: MahiFit.h:29
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
BXVector::Index Index
Definition: MahiFit.h:125
void solveSubmatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned nP) const
Definition: MahiFit.cc:564
PulseVector ampVec
Definition: MahiFit.h:49
SampleDecompLLT covDecomp
Definition: MahiFit.h:55
void nnlsUnconstrainParameter(Index idxp) const
Definition: MahiFit.cc:474
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
PulseVector aTbVec
Definition: MahiFit.h:53
float nnlsThresh_
Definition: MahiFit.h:178
T min(T a, T b)
Definition: MathUtil.h:58
PulseMatrix aTaMat
Definition: MahiFit.h:52
SamplePulseMatrix pulseMat
Definition: MahiFit.h:42
unsigned int tsSize
Definition: MahiFit.h:19
unsigned int nP
Definition: MahiFit.h:48
int nMaxItersNNLS_
Definition: MahiFit.h:175
void MahiFit::nnlsConstrainParameter ( Index  minratioidx) const
private

Definition at line 486 of file MahiFit.cc.

References MahiNnlsWorkspace::ampVec, MahiNnlsWorkspace::aTaMat, MahiNnlsWorkspace::aTbVec, MahiNnlsWorkspace::bxs, nnlsWork_, MahiNnlsWorkspace::nP, MahiNnlsWorkspace::pulseMat, and edm::swap().

Referenced by nnls().

486  {
487  if (minratioidx != (nnlsWork_.nP - 1)) {
488  nnlsWork_.aTaMat.col(nnlsWork_.nP - 1).swap(nnlsWork_.aTaMat.col(minratioidx));
489  nnlsWork_.aTaMat.row(nnlsWork_.nP - 1).swap(nnlsWork_.aTaMat.row(minratioidx));
490  nnlsWork_.pulseMat.col(nnlsWork_.nP - 1).swap(nnlsWork_.pulseMat.col(minratioidx));
491  Eigen::numext::swap(nnlsWork_.aTbVec.coeffRef(nnlsWork_.nP - 1), nnlsWork_.aTbVec.coeffRef(minratioidx));
492  Eigen::numext::swap(nnlsWork_.ampVec.coeffRef(nnlsWork_.nP - 1), nnlsWork_.ampVec.coeffRef(minratioidx));
493  Eigen::numext::swap(nnlsWork_.bxs.coeffRef(nnlsWork_.nP - 1), nnlsWork_.bxs.coeffRef(minratioidx));
494  }
495  --nnlsWork_.nP;
496 }
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
PulseVector ampVec
Definition: MahiFit.h:49
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
PulseVector aTbVec
Definition: MahiFit.h:53
PulseMatrix aTaMat
Definition: MahiFit.h:52
SamplePulseMatrix pulseMat
Definition: MahiFit.h:42
unsigned int nP
Definition: MahiFit.h:48
BXVector bxs
Definition: MahiFit.h:26
void MahiFit::nnlsUnconstrainParameter ( Index  idxp) const
private

Definition at line 474 of file MahiFit.cc.

References MahiNnlsWorkspace::ampVec, MahiNnlsWorkspace::aTaMat, MahiNnlsWorkspace::aTbVec, MahiNnlsWorkspace::bxs, nnlsWork_, MahiNnlsWorkspace::nP, MahiNnlsWorkspace::pulseMat, and edm::swap().

Referenced by nnls().

474  {
475  if (idxp != nnlsWork_.nP) {
476  nnlsWork_.aTaMat.col(nnlsWork_.nP).swap(nnlsWork_.aTaMat.col(idxp));
477  nnlsWork_.aTaMat.row(nnlsWork_.nP).swap(nnlsWork_.aTaMat.row(idxp));
478  nnlsWork_.pulseMat.col(nnlsWork_.nP).swap(nnlsWork_.pulseMat.col(idxp));
479  Eigen::numext::swap(nnlsWork_.aTbVec.coeffRef(nnlsWork_.nP), nnlsWork_.aTbVec.coeffRef(idxp));
480  Eigen::numext::swap(nnlsWork_.ampVec.coeffRef(nnlsWork_.nP), nnlsWork_.ampVec.coeffRef(idxp));
481  Eigen::numext::swap(nnlsWork_.bxs.coeffRef(nnlsWork_.nP), nnlsWork_.bxs.coeffRef(idxp));
482  }
483  ++nnlsWork_.nP;
484 }
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
PulseVector ampVec
Definition: MahiFit.h:49
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
PulseVector aTbVec
Definition: MahiFit.h:53
PulseMatrix aTaMat
Definition: MahiFit.h:52
SamplePulseMatrix pulseMat
Definition: MahiFit.h:42
unsigned int nP
Definition: MahiFit.h:48
BXVector bxs
Definition: MahiFit.h:26
void MahiFit::onePulseMinimize ( ) const
private

Definition at line 431 of file MahiFit.cc.

References MahiNnlsWorkspace::amplitudes, MahiNnlsWorkspace::ampVec, MahiNnlsWorkspace::covDecomp, f, MahiNnlsWorkspace::invcovp, SiStripPI::max, nnlsWork_, and MahiNnlsWorkspace::pulseMat.

Referenced by minimize().

431  {
433 
434  float aTaCoeff = (nnlsWork_.invcovp.transpose() * nnlsWork_.invcovp).coeff(0);
435  float aTbCoeff =
436  (nnlsWork_.invcovp.transpose() * (nnlsWork_.covDecomp.matrixL().solve(nnlsWork_.amplitudes))).coeff(0);
437 
438  nnlsWork_.ampVec.coeffRef(0) = std::max(0.f, aTbCoeff / aTaCoeff);
439 }
SamplePulseMatrix invcovp
Definition: MahiFit.h:51
SampleVector amplitudes
Definition: MahiFit.h:29
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
PulseVector ampVec
Definition: MahiFit.h:49
SampleDecompLLT covDecomp
Definition: MahiFit.h:55
double f[11][100]
SamplePulseMatrix pulseMat
Definition: MahiFit.h:42
void MahiFit::phase1Apply ( const HBHEChannelInfo channelData,
float &  reconstructedEnergy,
float &  reconstructedTime,
bool &  useTriple,
float &  chi2 
) const

Definition at line 46 of file MahiFit.cc.

References CustomPhysics_cfi::amplitude, MahiNnlsWorkspace::amplitudes, chiSqSwitch_, doFit(), f, HBHEChannelInfo::fcByPE(), nnlsWork_, MahiNnlsWorkspace::noiseTerms, norm_, HBHEChannelInfo::nSamples(), MahiNnlsWorkspace::pedVal, resetWorkspace(), HBHEChannelInfo::soi(), mathSSE::sqrt(), ts4Thresh_, HBHEChannelInfo::tsDFcPerADC(), HBHEChannelInfo::tsGain(), MahiNnlsWorkspace::tsOffset, HBHEChannelInfo::tsPedestal(), HBHEChannelInfo::tsPedestalWidth(), HBHEChannelInfo::tsRawCharge(), and MahiNnlsWorkspace::tsSize.

Referenced by phase1Debug(), and SimpleHBHEPhase1Algo::reconstruct().

50  {
51  assert(channelData.nSamples() == 8 || channelData.nSamples() == 10);
52 
54 
55  nnlsWork_.tsOffset = channelData.soi();
56 
57  std::array<float, 3> reconstructedVals{{0.0f, -9999.f, -9999.f}};
58 
59  double tsTOT = 0, tstrig = 0; // in GeV
60  for (unsigned int iTS = 0; iTS < nnlsWork_.tsSize; ++iTS) {
61  auto const amplitude = channelData.tsRawCharge(iTS) - channelData.tsPedestal(iTS);
62 
63  nnlsWork_.amplitudes.coeffRef(iTS) = amplitude;
64 
65  //ADC granularity
66  auto const noiseADC = norm_ * channelData.tsDFcPerADC(iTS);
67 
68  //Electronic pedestal
69  auto const pedWidth = channelData.tsPedestalWidth(iTS);
70 
71  //Photostatistics
72  auto const noisePhoto = (amplitude > pedWidth) ? std::sqrt(amplitude * channelData.fcByPE()) : 0.f;
73 
74  //Total uncertainty from all sources
75  nnlsWork_.noiseTerms.coeffRef(iTS) = noiseADC * noiseADC + noisePhoto * noisePhoto + pedWidth * pedWidth;
76 
77  tsTOT += amplitude;
78  if (iTS == nnlsWork_.tsOffset)
79  tstrig += amplitude;
80  }
81 
82  tsTOT *= channelData.tsGain(0);
83  tstrig *= channelData.tsGain(0);
84 
85  useTriple = false;
86  if (tstrig >= ts4Thresh_ && tsTOT > 0) {
87  //Average pedestal width (for covariance matrix constraint)
88  nnlsWork_.pedVal = 0.25f * (channelData.tsPedestalWidth(0) * channelData.tsPedestalWidth(0) +
89  channelData.tsPedestalWidth(1) * channelData.tsPedestalWidth(1) +
90  channelData.tsPedestalWidth(2) * channelData.tsPedestalWidth(2) +
91  channelData.tsPedestalWidth(3) * channelData.tsPedestalWidth(3));
92 
93  // only do pre-fit with 1 pulse if chiSq threshold is positive
94  if (chiSqSwitch_ > 0) {
95  doFit(reconstructedVals, 1);
96  if (reconstructedVals[2] > chiSqSwitch_) {
97  doFit(reconstructedVals, 0); //nbx=0 means use configured BXs
98  useTriple = true;
99  }
100  } else {
101  doFit(reconstructedVals, 0);
102  useTriple = true;
103  }
104  } else {
105  reconstructedVals.at(0) = 0.f; //energy
106  reconstructedVals.at(1) = -9999.f; //time
107  reconstructedVals.at(2) = -9999.f; //chi2
108  }
109 
110  reconstructedEnergy = reconstructedVals[0] * channelData.tsGain(0);
111  reconstructedTime = reconstructedVals[1];
112  chi2 = reconstructedVals[2];
113 }
float chiSqSwitch_
Definition: MahiFit.h:160
double tsGain(const unsigned ts) const
SampleVector amplitudes
Definition: MahiFit.h:29
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
unsigned soi() const
float norm_
Definition: MahiFit.h:165
double tsPedestal(const unsigned ts) const
double tsRawCharge(const unsigned ts) const
T sqrt(T t)
Definition: SSEVec.h:19
void doFit(std::array< float, 3 > &correctedOutput, const int nbx) const
Definition: MahiFit.cc:115
double fcByPE() const
double f[11][100]
unsigned int tsOffset
Definition: MahiFit.h:20
void resetWorkspace() const
Definition: MahiFit.cc:613
double tsPedestalWidth(const unsigned ts) const
SampleVector noiseTerms
Definition: MahiFit.h:32
float ts4Thresh_
Definition: MahiFit.h:159
unsigned int tsSize
Definition: MahiFit.h:19
unsigned nSamples() const
float tsDFcPerADC(const unsigned ts) const
void MahiFit::phase1Debug ( const HBHEChannelInfo channelData,
MahiDebugInfo mdi 
) const

Definition at line 498 of file MahiFit.cc.

References MahiNnlsWorkspace::amplitudes, MahiNnlsWorkspace::ampVec, MahiDebugInfo::arrivalTime, MahiNnlsWorkspace::bxs, ALCARECOTkAlJpsiMuMu_cff::charge, hltPixelTracks_cff::chi2, MahiDebugInfo::chiSq, MahiDebugInfo::count, MahiNnlsWorkspace::dt, HBHEChannelInfo::fcByPE(), HBHEChannelInfo::hasTimeInfo(), MahiDebugInfo::inGain, MahiDebugInfo::inNoiseADC, MahiDebugInfo::inNoisePhoto, MahiDebugInfo::inPedAvg, MahiDebugInfo::inPedestal, MahiDebugInfo::inputTDC, MahiDebugInfo::inputTS, MahiDebugInfo::inTimeConst, MahiDebugInfo::itPulse, MahiDebugInfo::mahiEnergy, nnlsWork_, MahiNnlsWorkspace::noiseTerms, norm_, MahiNnlsWorkspace::nPulseTot, MahiDebugInfo::nSamples, HBHEChannelInfo::nSamples(), MahiDebugInfo::ootEnergy, MahiDebugInfo::ootPulse, MahiDebugInfo::pedEnergy, pedestalBX_, phase1Apply(), MahiNnlsWorkspace::pulseMat, MahiDebugInfo::soi, HBHEChannelInfo::soi(), mathSSE::sqrt(), MahiDebugInfo::totalUCNoise, HBHEChannelInfo::tsDFcPerADC(), HBHEChannelInfo::tsGain(), HBHEChannelInfo::tsPedestal(), HBHEChannelInfo::tsPedestalWidth(), HBHEChannelInfo::tsRawCharge(), HBHEChannelInfo::tsRiseTime(), MahiNnlsWorkspace::tsSize, and MahiDebugInfo::use3.

498  {
499  float recoEnergy, recoTime, chi2;
500  bool use3;
501  phase1Apply(channelData, recoEnergy, recoTime, use3, chi2);
502 
503  mdi.nSamples = channelData.nSamples();
504  mdi.soi = channelData.soi();
505 
506  mdi.use3 = use3;
507 
508  mdi.inTimeConst = nnlsWork_.dt;
509  mdi.inPedAvg = 0.25 * (channelData.tsPedestalWidth(0) * channelData.tsPedestalWidth(0) +
510  channelData.tsPedestalWidth(1) * channelData.tsPedestalWidth(1) +
511  channelData.tsPedestalWidth(2) * channelData.tsPedestalWidth(2) +
512  channelData.tsPedestalWidth(3) * channelData.tsPedestalWidth(3));
513  mdi.inGain = channelData.tsGain(0);
514 
515  for (unsigned int iTS = 0; iTS < channelData.nSamples(); ++iTS) {
516  double charge = channelData.tsRawCharge(iTS);
517  double ped = channelData.tsPedestal(iTS);
518 
519  mdi.inNoiseADC[iTS] = norm_ * channelData.tsDFcPerADC(iTS);
520 
521  if ((charge - ped) > channelData.tsPedestalWidth(iTS)) {
522  mdi.inNoisePhoto[iTS] = sqrt((charge - ped) * channelData.fcByPE());
523  } else {
524  mdi.inNoisePhoto[iTS] = 0;
525  }
526 
527  mdi.inPedestal[iTS] = channelData.tsPedestalWidth(iTS);
528  mdi.totalUCNoise[iTS] = nnlsWork_.noiseTerms.coeffRef(iTS);
529 
530  if (channelData.hasTimeInfo()) {
531  mdi.inputTDC[iTS] = channelData.tsRiseTime(iTS);
532  } else {
533  mdi.inputTDC[iTS] = -1;
534  }
535  }
536 
537  mdi.arrivalTime = recoTime;
538  mdi.chiSq = chi2;
539 
540  for (unsigned int iBX = 0; iBX < nnlsWork_.nPulseTot; ++iBX) {
541  if (nnlsWork_.bxs.coeff(iBX) == 0) {
542  mdi.mahiEnergy = nnlsWork_.ampVec.coeff(iBX);
543  for (unsigned int iTS = 0; iTS < nnlsWork_.tsSize; ++iTS) {
544  mdi.count[iTS] = iTS;
545  mdi.inputTS[iTS] = nnlsWork_.amplitudes.coeff(iTS);
546  mdi.itPulse[iTS] = nnlsWork_.pulseMat.col(iBX).coeff(iTS);
547  }
548  } else if (nnlsWork_.bxs.coeff(iBX) == pedestalBX_) {
549  mdi.pedEnergy = nnlsWork_.ampVec.coeff(iBX);
550  } else if (nnlsWork_.bxs.coeff(iBX) >= -3 && nnlsWork_.bxs.coeff(iBX) <= 4) {
551  int ootIndex = nnlsWork_.bxs.coeff(iBX);
552  if (ootIndex > 0)
553  ootIndex += 2;
554  else
555  ootIndex += 3;
556  mdi.ootEnergy[ootIndex] = nnlsWork_.ampVec.coeff(iBX);
557  for (unsigned int iTS = 0; iTS < nnlsWork_.tsSize; ++iTS) {
558  mdi.ootPulse[ootIndex][iTS] = nnlsWork_.pulseMat.col(iBX).coeff(iTS);
559  }
560  }
561  }
562 }
unsigned int nPulseTot
Definition: MahiFit.h:18
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
Definition: MahiFit.cc:46
float ootEnergy[7]
Definition: MahiFit.h:80
float itPulse[MaxSVSize]
Definition: MahiFit.h:85
float ootPulse[7][MaxSVSize]
Definition: MahiFit.h:86
bool hasTimeInfo() const
double tsGain(const unsigned ts) const
SampleVector amplitudes
Definition: MahiFit.h:29
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
unsigned soi() const
PulseVector ampVec
Definition: MahiFit.h:49
float norm_
Definition: MahiFit.h:165
float count[MaxSVSize]
Definition: MahiFit.h:82
double tsPedestal(const unsigned ts) const
float totalUCNoise[MaxSVSize]
Definition: MahiFit.h:74
float inNoiseADC[MaxSVSize]
Definition: MahiFit.h:69
float pedEnergy
Definition: MahiFit.h:79
double tsRawCharge(const unsigned ts) const
float inPedestal[MaxSVSize]
Definition: MahiFit.h:72
T sqrt(T t)
Definition: SSEVec.h:19
double fcByPE() const
int nSamples
Definition: MahiFit.h:59
float chiSq
Definition: MahiFit.h:77
bool use3
Definition: MahiFit.h:62
float inGain
Definition: MahiFit.h:67
float arrivalTime
Definition: MahiFit.h:78
float inPedAvg
Definition: MahiFit.h:66
float tsRiseTime(const unsigned ts) const
double tsPedestalWidth(const unsigned ts) const
float mahiEnergy
Definition: MahiFit.h:76
SamplePulseMatrix pulseMat
Definition: MahiFit.h:42
float inputTS[MaxSVSize]
Definition: MahiFit.h:83
int inputTDC[MaxSVSize]
Definition: MahiFit.h:84
float inNoisePhoto[MaxSVSize]
Definition: MahiFit.h:71
SampleVector noiseTerms
Definition: MahiFit.h:32
unsigned int tsSize
Definition: MahiFit.h:19
BXVector bxs
Definition: MahiFit.h:26
float inTimeConst
Definition: MahiFit.h:64
unsigned nSamples() const
static int pedestalBX_
Definition: MahiFit.h:151
float tsDFcPerADC(const unsigned ts) const
void MahiFit::resetPulseShapeTemplate ( const HcalPulseShapes::Shape ps,
bool  hasTimeInfo,
unsigned int  nSamples 
)

Definition at line 459 of file MahiFit.cc.

References MahiNnlsWorkspace::amplitudes, cntsetPulseShape_, MahiNnlsWorkspace::dt, HcalConst::maxSamples, nnlsWork_, MahiNnlsWorkspace::noiseTerms, PresampleTask_cfi::nSamples, psfPtr_, timeSigmaHPD_, timeSigmaSiPM_, and MahiNnlsWorkspace::tsSize.

Referenced by setPulseShapeTemplate().

459  {
461 
462  // only the pulse shape itself from PulseShapeFunctor is used for Mahi
463  // the uncertainty terms calculated inside PulseShapeFunctor are used for Method 2 only
464  psfPtr_.reset(new FitterFuncs::PulseShapeFunctor(ps, false, false, false, 1, 0, 0, HcalConst::maxSamples));
465 
466  // 1 sigma time constraint
467  nnlsWork_.dt = hasTimeInfo ? timeSigmaSiPM_ : timeSigmaHPD_;
468 
472 }
SampleVector amplitudes
Definition: MahiFit.h:29
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
int cntsetPulseShape_
Definition: MahiFit.h:184
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
Definition: MahiFit.h:185
float timeSigmaSiPM_
Definition: MahiFit.h:170
SampleVector noiseTerms
Definition: MahiFit.h:32
unsigned int tsSize
Definition: MahiFit.h:19
float timeSigmaHPD_
Definition: MahiFit.h:169
void MahiFit::resetWorkspace ( ) const
private

Definition at line 613 of file MahiFit.cc.

References MahiNnlsWorkspace::amplitudes, MahiNnlsWorkspace::bxOffset, MahiNnlsWorkspace::maxoffset, nnlsWork_, MahiNnlsWorkspace::noiseTerms, MahiNnlsWorkspace::nP, MahiNnlsWorkspace::nPulseTot, and MahiNnlsWorkspace::tsOffset.

Referenced by phase1Apply().

613  {
614  nnlsWork_.nPulseTot = 0;
615  nnlsWork_.tsOffset = 0;
616  nnlsWork_.bxOffset = 0;
617  nnlsWork_.maxoffset = 0;
618  nnlsWork_.nP = 0;
619 
620  // NOT SURE THIS IS NEEDED
621  nnlsWork_.amplitudes.setZero();
622  nnlsWork_.noiseTerms.setZero();
623 }
unsigned int nPulseTot
Definition: MahiFit.h:18
SampleVector amplitudes
Definition: MahiFit.h:29
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
unsigned int tsOffset
Definition: MahiFit.h:20
SampleVector noiseTerms
Definition: MahiFit.h:32
unsigned int nP
Definition: MahiFit.h:48
void MahiFit::setParameters ( bool  iDynamicPed,
double  iTS4Thresh,
double  chiSqSwitch,
bool  iApplyTimeSlew,
HcalTimeSlew::BiasSetting  slewFlavor,
bool  iCalculateArrivalTime,
double  iMeanTime,
double  iTimeSigmaHPD,
double  iTimeSigmaSiPM,
const std::vector< int > &  iActiveBXs,
int  iNMaxItersMin,
int  iNMaxItersNNLS,
double  iDeltaChiSqThresh,
double  iNnlsThresh 
)

Definition at line 7 of file MahiFit.cc.

References activeBXs_, applyTimeSlew_, bxOffsetConf_, bxSizeConf_, calculateArrivalTime_, HLT_2018_cff::chiSqSwitch, chiSqSwitch_, deltaChiSqThresh_, dynamicPed_, meanTime_, nMaxItersMin_, nMaxItersNNLS_, nnlsThresh_, slewFlavor_, timeSigmaHPD_, timeSigmaSiPM_, and ts4Thresh_.

20  {
21  dynamicPed_ = iDynamicPed;
22 
23  ts4Thresh_ = iTS4Thresh;
25 
26  applyTimeSlew_ = iApplyTimeSlew;
27  slewFlavor_ = slewFlavor;
28 
29  calculateArrivalTime_ = iCalculateArrivalTime;
30  meanTime_ = iMeanTime;
31  timeSigmaHPD_ = iTimeSigmaHPD;
32  timeSigmaSiPM_ = iTimeSigmaSiPM;
33 
34  activeBXs_ = iActiveBXs;
35 
36  nMaxItersMin_ = iNMaxItersMin;
37  nMaxItersNNLS_ = iNMaxItersNNLS;
38 
39  deltaChiSqThresh_ = iDeltaChiSqThresh;
40  nnlsThresh_ = iNnlsThresh;
41 
42  bxOffsetConf_ = -(*std::min_element(activeBXs_.begin(), activeBXs_.end()));
43  bxSizeConf_ = activeBXs_.size();
44 }
float chiSqSwitch_
Definition: MahiFit.h:160
HcalTimeSlew::BiasSetting slewFlavor_
Definition: MahiFit.h:163
bool applyTimeSlew_
Definition: MahiFit.h:162
float meanTime_
Definition: MahiFit.h:168
bool calculateArrivalTime_
Definition: MahiFit.h:167
int bxOffsetConf_
Definition: MahiFit.h:181
float nnlsThresh_
Definition: MahiFit.h:178
unsigned int bxSizeConf_
Definition: MahiFit.h:180
int nMaxItersMin_
Definition: MahiFit.h:174
std::vector< int > activeBXs_
Definition: MahiFit.h:172
bool dynamicPed_
Definition: MahiFit.h:158
float timeSigmaSiPM_
Definition: MahiFit.h:170
float ts4Thresh_
Definition: MahiFit.h:159
float deltaChiSqThresh_
Definition: MahiFit.h:177
float timeSigmaHPD_
Definition: MahiFit.h:169
int nMaxItersNNLS_
Definition: MahiFit.h:175
void MahiFit::setPulseShapeTemplate ( const HcalPulseShapes::Shape ps,
bool  hasTimeInfo,
const HcalTimeSlew hcalTimeSlewDelay,
unsigned int  nSamples 
)

Definition at line 446 of file MahiFit.cc.

References currentPulseShape_, HcalTimeSlew::delay(), hcalTimeSlewDelay_, resetPulseShapeTemplate(), slewFlavor_, and tsDelay1GeV_.

449  {
450  if (!(&ps == currentPulseShape_)) {
451  hcalTimeSlewDelay_ = hcalTimeSlewDelay;
452  tsDelay1GeV_ = hcalTimeSlewDelay->delay(1.0, slewFlavor_);
453 
454  resetPulseShapeTemplate(ps, hasTimeInfo, nSamples);
455  currentPulseShape_ = &ps;
456  }
457 }
HcalTimeSlew::BiasSetting slewFlavor_
Definition: MahiFit.h:163
float tsDelay1GeV_
Definition: MahiFit.h:164
void resetPulseShapeTemplate(const HcalPulseShapes::Shape &ps, bool hasTimeInfo, unsigned int nSamples)
Definition: MahiFit.cc:459
const HcalTimeSlew * hcalTimeSlewDelay_
Definition: MahiFit.h:127
float delay(float fC, BiasSetting bias=Medium) const
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:20
const HcalPulseShapes::Shape * currentPulseShape_
Definition: MahiFit.h:126
void MahiFit::solveSubmatrix ( PulseMatrix mat,
PulseVector invec,
PulseVector outvec,
unsigned  nP 
) const
private

Definition at line 564 of file MahiFit.cc.

References Exception, and groupFilesInBlocks::temp.

Referenced by nnls().

564  {
565  using namespace Eigen;
566  switch (nP) { // pulse matrix is always square.
567  case 10: {
568  Matrix<float, 10, 10> temp = mat;
569  outvec.head<10>() = temp.ldlt().solve(invec.head<10>());
570  } break;
571  case 9: {
572  Matrix<float, 9, 9> temp = mat.topLeftCorner<9, 9>();
573  outvec.head<9>() = temp.ldlt().solve(invec.head<9>());
574  } break;
575  case 8: {
576  Matrix<float, 8, 8> temp = mat.topLeftCorner<8, 8>();
577  outvec.head<8>() = temp.ldlt().solve(invec.head<8>());
578  } break;
579  case 7: {
580  Matrix<float, 7, 7> temp = mat.topLeftCorner<7, 7>();
581  outvec.head<7>() = temp.ldlt().solve(invec.head<7>());
582  } break;
583  case 6: {
584  Matrix<float, 6, 6> temp = mat.topLeftCorner<6, 6>();
585  outvec.head<6>() = temp.ldlt().solve(invec.head<6>());
586  } break;
587  case 5: {
588  Matrix<float, 5, 5> temp = mat.topLeftCorner<5, 5>();
589  outvec.head<5>() = temp.ldlt().solve(invec.head<5>());
590  } break;
591  case 4: {
592  Matrix<float, 4, 4> temp = mat.topLeftCorner<4, 4>();
593  outvec.head<4>() = temp.ldlt().solve(invec.head<4>());
594  } break;
595  case 3: {
596  Matrix<float, 3, 3> temp = mat.topLeftCorner<3, 3>();
597  outvec.head<3>() = temp.ldlt().solve(invec.head<3>());
598  } break;
599  case 2: {
600  Matrix<float, 2, 2> temp = mat.topLeftCorner<2, 2>();
601  outvec.head<2>() = temp.ldlt().solve(invec.head<2>());
602  } break;
603  case 1: {
604  Matrix<float, 1, 1> temp = mat.topLeftCorner<1, 1>();
605  outvec.head<1>() = temp.ldlt().solve(invec.head<1>());
606  } break;
607  default:
608  throw cms::Exception("HcalMahiWeirdState")
609  << "Weird number of pulses encountered in Mahi, module is configured incorrectly!";
610  }
611 }
void MahiFit::updateCov ( const SampleMatrix invCovMat) const
private

Definition at line 298 of file MahiFit.cc.

References MahiNnlsWorkspace::ampVec, MahiNnlsWorkspace::bxOffset, MahiNnlsWorkspace::bxs, MahiNnlsWorkspace::covDecomp, nnlsWork_, MahiNnlsWorkspace::nPulseTot, hltrates_dqm_sourceclient-live_cfg::offset, pedestalBX_, and MahiNnlsWorkspace::pulseCovArray.

Referenced by minimize().

298  {
299  SampleMatrix invCovMat = samplecov;
300 
301  for (unsigned int iBX = 0; iBX < nnlsWork_.nPulseTot; ++iBX) {
302  auto const amp = nnlsWork_.ampVec.coeff(iBX);
303  if (amp == 0)
304  continue;
305 
306  int offset = nnlsWork_.bxs.coeff(iBX);
307 
308  if (offset == pedestalBX_)
309  continue;
310  else {
311  auto const ampsq = amp * amp;
312  invCovMat += ampsq * nnlsWork_.pulseCovArray[offset + nnlsWork_.bxOffset];
313  }
314  }
315 
316  nnlsWork_.covDecomp.compute(invCovMat);
317 }
unsigned int nPulseTot
Definition: MahiFit.h:18
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
PulseVector ampVec
Definition: MahiFit.h:49
std::array< SampleMatrix, MaxPVSize > pulseCovArray
Definition: MahiFit.h:39
SampleDecompLLT covDecomp
Definition: MahiFit.h:55
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
BXVector bxs
Definition: MahiFit.h:26
static int pedestalBX_
Definition: MahiFit.h:151
void MahiFit::updatePulseShape ( const float  itQ,
FullSampleVector pulseShape,
FullSampleVector pulseDeriv,
FullSampleMatrix pulseCov 
) const
private

Definition at line 242 of file MahiFit.cc.

References applyTimeSlew_, calculateArrivalTime_, HcalTimeSlew::delay(), dumpMFGeometry_cfg::delta, MahiNnlsWorkspace::dt, f, hcalTimeSlewDelay_, MahiNnlsWorkspace::maxoffset, meanTime_, nnlsWork_, psfPtr_, slewFlavor_, FrontierCondition_GT_autoExpress_cfi::t0, createJobs::tmp, tsDelay1GeV_, MahiNnlsWorkspace::tsOffset, MahiNnlsWorkspace::tsSize, and geometryCSVtoXML::xx.

Referenced by doFit().

245  {
246  float t0 = meanTime_;
247 
248  if (applyTimeSlew_) {
249  if (itQ <= 1.f)
250  t0 += tsDelay1GeV_;
251  else
252  t0 += hcalTimeSlewDelay_->delay(float(itQ), slewFlavor_);
253  }
254 
255  std::array<double, HcalConst::maxSamples> pulseN;
256  std::array<double, HcalConst::maxSamples> pulseM;
257  std::array<double, HcalConst::maxSamples> pulseP;
258 
259  const float xx = t0;
260  const float xxm = -nnlsWork_.dt + t0;
261  const float xxp = nnlsWork_.dt + t0;
262 
263  psfPtr_->singlePulseShapeFuncMahi(&xx);
264  psfPtr_->getPulseShape(pulseN);
265 
266  psfPtr_->singlePulseShapeFuncMahi(&xxm);
267  psfPtr_->getPulseShape(pulseM);
268 
269  psfPtr_->singlePulseShapeFuncMahi(&xxp);
270  psfPtr_->getPulseShape(pulseP);
271 
272  //in the 2018+ case where the sample of interest (SOI) is in TS3, add an extra offset to align
273  //with previous SOI=TS4 case assumed by psfPtr_->getPulseShape()
274  int delta = 4 - nnlsWork_.tsOffset;
275 
276  auto invDt = 0.5 / nnlsWork_.dt;
277 
278  for (unsigned int iTS = 0; iTS < nnlsWork_.tsSize; ++iTS) {
279  pulseShape(iTS + nnlsWork_.maxoffset) = pulseN[iTS + delta];
281  pulseDeriv(iTS + nnlsWork_.maxoffset) = (pulseM[iTS + delta] - pulseP[iTS + delta]) * invDt;
282 
283  pulseM[iTS + delta] -= pulseN[iTS + delta];
284  pulseP[iTS + delta] -= pulseN[iTS + delta];
285  }
286 
287  for (unsigned int iTS = 0; iTS < nnlsWork_.tsSize; ++iTS) {
288  for (unsigned int jTS = 0; jTS < iTS + 1; ++jTS) {
289  auto const tmp = 0.5 * (pulseP[iTS + delta] * pulseP[jTS + delta] + pulseM[iTS + delta] * pulseM[jTS + delta]);
290 
291  pulseCov(jTS + nnlsWork_.maxoffset, iTS + nnlsWork_.maxoffset) = tmp;
292  if (iTS != jTS)
293  pulseCov(iTS + nnlsWork_.maxoffset, jTS + nnlsWork_.maxoffset) = tmp;
294  }
295  }
296 }
HcalTimeSlew::BiasSetting slewFlavor_
Definition: MahiFit.h:163
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
bool applyTimeSlew_
Definition: MahiFit.h:162
float meanTime_
Definition: MahiFit.h:168
bool calculateArrivalTime_
Definition: MahiFit.h:167
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
Definition: MahiFit.h:185
double f[11][100]
unsigned int tsOffset
Definition: MahiFit.h:20
float tsDelay1GeV_
Definition: MahiFit.h:164
const HcalTimeSlew * hcalTimeSlewDelay_
Definition: MahiFit.h:127
unsigned int tsSize
Definition: MahiFit.h:19
float delay(float fC, BiasSetting bias=Medium) const
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:20
tmp
align.sh
Definition: createJobs.py:716

Member Data Documentation

std::vector<int> MahiFit::activeBXs_
private

Definition at line 172 of file MahiFit.h.

Referenced by doFit(), and setParameters().

bool MahiFit::applyTimeSlew_
private

Definition at line 162 of file MahiFit.h.

Referenced by setParameters(), and updatePulseShape().

int MahiFit::bxOffsetConf_
private

Definition at line 181 of file MahiFit.h.

Referenced by doFit(), and setParameters().

unsigned int MahiFit::bxSizeConf_
private

Definition at line 180 of file MahiFit.h.

Referenced by doFit(), and setParameters().

bool MahiFit::calculateArrivalTime_
private

Definition at line 167 of file MahiFit.h.

Referenced by doFit(), setParameters(), and updatePulseShape().

float MahiFit::chiSqSwitch_
private

Definition at line 160 of file MahiFit.h.

Referenced by phase1Apply(), and setParameters().

int MahiFit::cntsetPulseShape_
private

Definition at line 184 of file MahiFit.h.

Referenced by resetPulseShapeTemplate().

const HcalPulseShapes::Shape* MahiFit::currentPulseShape_ = 0

Definition at line 126 of file MahiFit.h.

Referenced by setPulseShapeTemplate().

float MahiFit::deltaChiSqThresh_
private

Definition at line 177 of file MahiFit.h.

Referenced by minimize(), and setParameters().

bool MahiFit::dynamicPed_
private

Definition at line 158 of file MahiFit.h.

Referenced by doFit(), and setParameters().

const HcalTimeSlew* MahiFit::hcalTimeSlewDelay_ = 0

Definition at line 127 of file MahiFit.h.

Referenced by setPulseShapeTemplate(), and updatePulseShape().

float MahiFit::meanTime_
private

Definition at line 168 of file MahiFit.h.

Referenced by setParameters(), and updatePulseShape().

int MahiFit::nMaxItersMin_
private

Definition at line 174 of file MahiFit.h.

Referenced by minimize(), and setParameters().

int MahiFit::nMaxItersNNLS_
private

Definition at line 175 of file MahiFit.h.

Referenced by nnls(), and setParameters().

float MahiFit::nnlsThresh_
private

Definition at line 178 of file MahiFit.h.

Referenced by nnls(), and setParameters().

MahiNnlsWorkspace MahiFit::nnlsWork_
mutableprivate
float MahiFit::norm_ = (1.f / std::sqrt(12))
private

Definition at line 165 of file MahiFit.h.

Referenced by phase1Apply(), and phase1Debug().

int MahiFit::pedestalBX_ = 100
staticprivate

Definition at line 151 of file MahiFit.h.

Referenced by doFit(), phase1Debug(), and updateCov().

std::unique_ptr<ROOT::Math::Functor> MahiFit::pfunctor_
private

Definition at line 186 of file MahiFit.h.

std::unique_ptr<FitterFuncs::PulseShapeFunctor> MahiFit::psfPtr_
private

Definition at line 185 of file MahiFit.h.

Referenced by resetPulseShapeTemplate(), and updatePulseShape().

HcalTimeSlew::BiasSetting MahiFit::slewFlavor_
private

Definition at line 163 of file MahiFit.h.

Referenced by setParameters(), setPulseShapeTemplate(), and updatePulseShape().

float MahiFit::timeLimit_ = 12.5f
staticprivate

Definition at line 155 of file MahiFit.h.

Referenced by calculateArrivalTime().

float MahiFit::timeSigmaHPD_
private

Definition at line 169 of file MahiFit.h.

Referenced by resetPulseShapeTemplate(), and setParameters().

float MahiFit::timeSigmaSiPM_
private

Definition at line 170 of file MahiFit.h.

Referenced by resetPulseShapeTemplate(), and setParameters().

float MahiFit::ts4Thresh_
private

Definition at line 159 of file MahiFit.h.

Referenced by phase1Apply(), and setParameters().

float MahiFit::tsDelay1GeV_ = 0.f
private

Definition at line 164 of file MahiFit.h.

Referenced by setPulseShapeTemplate(), and updatePulseShape().