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