CMS 3D CMS Logo

MahiFit.h
Go to the documentation of this file.
1 #ifndef RecoLocalCalo_HcalRecAlgos_MahiFit_HH
2 #define RecoLocalCalo_HcalRecAlgos_MahiFit_HH
3 
10 
14 
15 #include <Math/Functor.h>
16 
18  unsigned int nPulseTot;
19  unsigned int tsSize;
20  unsigned int tsOffset;
21  int bxOffset;
22  int maxoffset;
23  float dt;
24 
25  //holds active bunch crossings
27 
28  //holds data samples
30 
31  //holds diagonal noise terms
33 
34  //holds flat pedestal uncertainty
35  float pedVal;
36 
37  //holds full covariance matrix for a pulse shape
38  //varied in time
39  std::array<SampleMatrix, MaxPVSize> pulseCovArray;
40 
41  //holds matrix of pulse shape templates for each BX
43 
44  //holds matrix of pulse shape derivatives for each BX
46 
47  //for FNNLS algorithm
48  unsigned int nP;
50 
52  PulseMatrix aTaMat; // A-transpose A (matrix)
53  PulseVector aTbVec; // A-transpose b (vector)
54 
56 };
57 
58 struct MahiDebugInfo {
59  int nSamples;
60  int soi;
61 
62  bool use3;
63 
64  float inTimeConst;
66  float inPedAvg;
67  float inGain;
68 
73 
75 
76  float mahiEnergy;
77  float chiSq;
78  float arrivalTime;
79  float pedEnergy;
80  float ootEnergy[7];
81 
82  float count[MaxSVSize];
86  float ootPulse[7][MaxSVSize];
87 };
88 
89 class MahiFit {
90 public:
91  MahiFit();
92  ~MahiFit(){};
93 
94  void setParameters(bool iDynamicPed,
95  double iTS4Thresh,
96  double chiSqSwitch,
97  bool iApplyTimeSlew,
98  HcalTimeSlew::BiasSetting slewFlavor,
99  bool iCalculateArrivalTime,
100  double iMeanTime,
101  double iTimeSigmaHPD,
102  double iTimeSigmaSiPM,
103  const std::vector<int>& iActiveBXs,
104  int iNMaxItersMin,
105  int iNMaxItersNNLS,
106  double iDeltaChiSqThresh,
107  double iNnlsThresh);
108 
109  void phase1Apply(const HBHEChannelInfo& channelData,
110  float& reconstructedEnergy,
111  float& reconstructedTime,
112  bool& useTriple,
113  float& chi2) const;
114 
115  void phase1Debug(const HBHEChannelInfo& channelData, MahiDebugInfo& mdi) const;
116 
117  void doFit(std::array<float, 3>& correctedOutput, const int nbx) const;
118 
120  bool hasTimeInfo,
121  const HcalTimeSlew* hcalTimeSlewDelay,
122  unsigned int nSamples);
123  void resetPulseShapeTemplate(const HcalPulseShapes::Shape& ps, bool hasTimeInfo, unsigned int nSamples);
124 
125  typedef BXVector::Index Index;
128 
129 private:
130  const float minimize() const;
131  void onePulseMinimize() const;
132  void updateCov(const SampleMatrix& invCovMat) const;
133  void updatePulseShape(const float itQ,
134  FullSampleVector& pulseShape,
135  FullSampleVector& pulseDeriv,
136  FullSampleMatrix& pulseCov) const;
137 
138  float calculateArrivalTime(unsigned int iBX) const;
139  float calculateChiSq() const;
140  void nnls() const;
141  void resetWorkspace() const;
142 
143  void nnlsUnconstrainParameter(Index idxp) const;
144  void nnlsConstrainParameter(Index minratioidx) const;
145 
146  void solveSubmatrix(PulseMatrix& mat, PulseVector& invec, PulseVector& outvec, unsigned nP) const;
147 
149 
150  //hard coded in initializer
151  static constexpr int pedestalBX_ = 100;
152 
153  // used to restrict returned time value to a 25 ns window centered
154  // on the nominal arrival time
155  static constexpr float timeLimit_ = 12.5f;
156 
157  // Python-configurables
159  float ts4Thresh_;
161 
164  float tsDelay1GeV_ = 0.f;
165  float norm_ = (1.f / std::sqrt(12));
166 
168  float meanTime_;
171 
172  std::vector<int> activeBXs_;
173 
176 
178  float nnlsThresh_;
179 
180  unsigned int bxSizeConf_;
182 
183  //for pulse shapes
185  std::unique_ptr<FitterFuncs::PulseShapeFunctor> psfPtr_;
186  std::unique_ptr<ROOT::Math::Functor> pfunctor_;
187 };
188 #endif
MahiFit::pfunctor_
std::unique_ptr< ROOT::Math::Functor > pfunctor_
Definition: MahiFit.h:186
MahiFit::updatePulseShape
void updatePulseShape(const float itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv, FullSampleMatrix &pulseCov) const
Definition: MahiFit.cc:242
MahiFit::nnlsWork_
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:148
HcalCalibrations.h
MahiDebugInfo::ootEnergy
float ootEnergy[7]
Definition: MahiFit.h:80
HLT_2018_cff.chiSqSwitch
chiSqSwitch
Definition: HLT_2018_cff.py:7102
MahiNnlsWorkspace::maxoffset
int maxoffset
Definition: MahiFit.h:22
MahiDebugInfo::itPulse
float itPulse[MaxSVSize]
Definition: MahiFit.h:85
MahiFit::timeSigmaSiPM_
float timeSigmaSiPM_
Definition: MahiFit.h:170
MahiFit::applyTimeSlew_
bool applyTimeSlew_
Definition: MahiFit.h:162
MahiDebugInfo::totalUCNoise
float totalUCNoise[MaxSVSize]
Definition: MahiFit.h:74
MahiDebugInfo
Definition: MahiFit.h:58
MahiFit
Definition: MahiFit.h:89
MahiFit::setPulseShapeTemplate
void setPulseShapeTemplate(const HcalPulseShapes::Shape &ps, bool hasTimeInfo, const HcalTimeSlew *hcalTimeSlewDelay, unsigned int nSamples)
Definition: MahiFit.cc:446
MahiDebugInfo::mahiEnergy
float mahiEnergy
Definition: MahiFit.h:76
FullSampleMatrix
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
Definition: EigenMatrixTypes.h:18
SampleMatrix
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
Definition: EigenMatrixTypes.h:17
HcalPulseShapes.h
MahiNnlsWorkspace::aTaMat
PulseMatrix aTaMat
Definition: MahiFit.h:52
MahiDebugInfo::inNoiseDC
float inNoiseDC[MaxSVSize]
Definition: MahiFit.h:70
HcalCoder.h
MahiDebugInfo::count
float count[MaxSVSize]
Definition: MahiFit.h:82
HcalTimeSlew.h
MahiFit::bxSizeConf_
unsigned int bxSizeConf_
Definition: MahiFit.h:180
MahiFit::phase1Apply
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
Definition: MahiFit.cc:46
MahiFit::resetWorkspace
void resetWorkspace() const
Definition: MahiFit.cc:613
MahiNnlsWorkspace::ampVec
PulseVector ampVec
Definition: MahiFit.h:49
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
MahiFit::nnlsConstrainParameter
void nnlsConstrainParameter(Index minratioidx) const
Definition: MahiFit.cc:486
MahiNnlsWorkspace::bxs
BXVector bxs
Definition: MahiFit.h:26
MahiDebugInfo::pedEnergy
float pedEnergy
Definition: MahiFit.h:79
PresampleTask_cfi.nSamples
nSamples
Definition: PresampleTask_cfi.py:7
HcalTimeSlew::BiasSetting
BiasSetting
Definition: HcalTimeSlew.h:71
HcalTimeSlew
Definition: HcalTimeSlew.h:19
MahiFit::calculateChiSq
float calculateChiSq() const
Definition: MahiFit.cc:441
MahiDebugInfo::inPedAvg
float inPedAvg
Definition: MahiFit.h:66
MahiFit::bxOffsetConf_
int bxOffsetConf_
Definition: MahiFit.h:181
MahiFit::nnlsThresh_
float nnlsThresh_
Definition: MahiFit.h:178
MahiNnlsWorkspace::tsOffset
unsigned int tsOffset
Definition: MahiFit.h:20
BXVector
Definition: BXVector.h:15
MahiNnlsWorkspace::aTbVec
PulseVector aTbVec
Definition: MahiFit.h:53
MahiFit::psfPtr_
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
Definition: MahiFit.h:185
PulseVector
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
Definition: EigenMatrixTypes.h:14
MahiFit::~MahiFit
~MahiFit()
Definition: MahiFit.h:92
MahiFit::timeLimit_
static constexpr float timeLimit_
Definition: MahiFit.h:155
MahiNnlsWorkspace
Definition: MahiFit.h:17
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
MahiFit::setParameters
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)
Definition: MahiFit.cc:7
MahiNnlsWorkspace::noiseTerms
SampleVector noiseTerms
Definition: MahiFit.h:32
MahiDebugInfo::inNoisePhoto
float inNoisePhoto[MaxSVSize]
Definition: MahiFit.h:71
SampleDecompLLT
Eigen::LLT< SampleMatrix > SampleDecompLLT
Definition: EigenMatrixTypes.h:21
MahiDebugInfo::use3
bool use3
Definition: MahiFit.h:62
MahiDebugInfo::nSamples
int nSamples
Definition: MahiFit.h:59
MahiDebugInfo::arrivalTime
float arrivalTime
Definition: MahiFit.h:78
MahiFit::calculateArrivalTime_
bool calculateArrivalTime_
Definition: MahiFit.h:167
MahiDebugInfo::ootPulse
float ootPulse[7][MaxSVSize]
Definition: MahiFit.h:86
MahiNnlsWorkspace::invcovp
SamplePulseMatrix invcovp
Definition: MahiFit.h:51
MahiNnlsWorkspace::pedVal
float pedVal
Definition: MahiFit.h:35
MahiDebugInfo::soi
int soi
Definition: MahiFit.h:60
MahiFit::MahiFit
MahiFit()
Definition: MahiFit.cc:5
MahiFit::pedestalBX_
static constexpr int pedestalBX_
Definition: MahiFit.h:151
HBHEChannelInfo.h
MahiNnlsWorkspace::dt
float dt
Definition: MahiFit.h:23
MahiFit::cntsetPulseShape_
int cntsetPulseShape_
Definition: MahiFit.h:184
MahiFit::solveSubmatrix
void solveSubmatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned nP) const
Definition: MahiFit.cc:564
MahiNnlsWorkspace::tsSize
unsigned int tsSize
Definition: MahiFit.h:19
MahiFit::timeSigmaHPD_
float timeSigmaHPD_
Definition: MahiFit.h:169
MahiFit::minimize
const float minimize() const
Definition: MahiFit.cc:206
MahiNnlsWorkspace::amplitudes
SampleVector amplitudes
Definition: MahiFit.h:29
HcalDetId.h
MahiFit::phase1Debug
void phase1Debug(const HBHEChannelInfo &channelData, MahiDebugInfo &mdi) const
Definition: MahiFit.cc:498
MahiFit::chiSqSwitch_
float chiSqSwitch_
Definition: MahiFit.h:160
MahiFit::tsDelay1GeV_
float tsDelay1GeV_
Definition: MahiFit.h:164
MahiNnlsWorkspace::pulseCovArray
std::array< SampleMatrix, MaxPVSize > pulseCovArray
Definition: MahiFit.h:39
MahiFit::nMaxItersNNLS_
int nMaxItersNNLS_
Definition: MahiFit.h:175
EigenMatrixTypes.h
MahiDebugInfo::inputTDC
int inputTDC[MaxSVSize]
Definition: MahiFit.h:84
HcalSubdetector.h
MahiFit::updateCov
void updateCov(const SampleMatrix &invCovMat) const
Definition: MahiFit.cc:298
SamplePulseMatrix
Eigen::Matrix< double, SampleVectorSize, Eigen::Dynamic, 0, SampleVectorSize, PulseVectorSize > SamplePulseMatrix
Definition: EigenMatrixTypes.h:20
MahiFit::ts4Thresh_
float ts4Thresh_
Definition: MahiFit.h:159
MahiNnlsWorkspace::pulseMat
SamplePulseMatrix pulseMat
Definition: MahiFit.h:42
MahiFit::onePulseMinimize
void onePulseMinimize() const
Definition: MahiFit.cc:431
SampleVector
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
Definition: EigenMatrixTypes.h:12
MahiNnlsWorkspace::nP
unsigned int nP
Definition: MahiFit.h:48
HcalPulseShape
Definition: HcalPulseShape.h:6
FullSampleVector
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
Definition: EigenMatrixTypes.h:13
MahiDebugInfo::inTimeConst
float inTimeConst
Definition: MahiFit.h:64
MahiFit::nnls
void nnls() const
Definition: MahiFit.cc:339
MahiNnlsWorkspace::bxOffset
int bxOffset
Definition: MahiFit.h:21
MahiFit::hcalTimeSlewDelay_
const HcalTimeSlew * hcalTimeSlewDelay_
Definition: MahiFit.h:127
MahiFit::norm_
float norm_
Definition: MahiFit.h:165
MahiFit::meanTime_
float meanTime_
Definition: MahiFit.h:168
MahiDebugInfo::inGain
float inGain
Definition: MahiFit.h:67
MahiFit::resetPulseShapeTemplate
void resetPulseShapeTemplate(const HcalPulseShapes::Shape &ps, bool hasTimeInfo, unsigned int nSamples)
Definition: MahiFit.cc:459
MahiFit::deltaChiSqThresh_
float deltaChiSqThresh_
Definition: MahiFit.h:177
PulseMatrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix
Definition: EigenMatrixTypes.h:19
MaxSVSize
constexpr int MaxSVSize
Definition: EigenMatrixTypes.h:6
MahiFit::currentPulseShape_
const HcalPulseShapes::Shape * currentPulseShape_
Definition: MahiFit.h:126
PulseShapeFunctor.h
MahiNnlsWorkspace::covDecomp
SampleDecompLLT covDecomp
Definition: MahiFit.h:55
MahiFit::slewFlavor_
HcalTimeSlew::BiasSetting slewFlavor_
Definition: MahiFit.h:163
MahiDebugInfo::inputTS
float inputTS[MaxSVSize]
Definition: MahiFit.h:83
MahiDebugInfo::inNoiseADC
float inNoiseADC[MaxSVSize]
Definition: MahiFit.h:69
MahiFit::dynamicPed_
bool dynamicPed_
Definition: MahiFit.h:158
MahiFit::doFit
void doFit(std::array< float, 3 > &correctedOutput, const int nbx) const
Definition: MahiFit.cc:115
MahiFit::Index
BXVector::Index Index
Definition: MahiFit.h:125
MahiDebugInfo::chiSq
float chiSq
Definition: MahiFit.h:77
MahiFit::activeBXs_
std::vector< int > activeBXs_
Definition: MahiFit.h:172
MahiDebugInfo::inPedestal
float inPedestal[MaxSVSize]
Definition: MahiFit.h:72
MahiDebugInfo::inDarkCurrent
float inDarkCurrent
Definition: MahiFit.h:65
MahiNnlsWorkspace::nPulseTot
unsigned int nPulseTot
Definition: MahiFit.h:18
MahiFit::calculateArrivalTime
float calculateArrivalTime(unsigned int iBX) const
Definition: MahiFit.cc:319
MahiFit::nMaxItersMin_
int nMaxItersMin_
Definition: MahiFit.h:174
MahiNnlsWorkspace::pulseDerivMat
SamplePulseMatrix pulseDerivMat
Definition: MahiFit.h:45
HBHEChannelInfo
Definition: HBHEChannelInfo.h:15
MahiFit::nnlsUnconstrainParameter
void nnlsUnconstrainParameter(Index idxp) const
Definition: MahiFit.cc:474