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  int iTimeAlgo,
108  double iThEnergeticPulses,
109  double iMeanTime,
110  double iTimeSigmaHPD,
111  double iTimeSigmaSiPM,
112  const std::vector<int>& iActiveBXs,
113  int iNMaxItersMin,
114  int iNMaxItersNNLS,
115  double iDeltaChiSqThresh,
116  double iNnlsThresh);
117 
118  void phase1Apply(const HBHEChannelInfo& channelData,
119  float& reconstructedEnergy,
120  float& soiPlusOneEnergy,
121  float& reconstructedTime,
122  bool& useTriple,
123  float& chi2) const;
124 
125  void phase1Debug(const HBHEChannelInfo& channelData, MahiDebugInfo& mdi) const;
126 
127  void doFit(std::array<float, 4>& correctedOutput, const int nbx) const;
128 
129  void setPulseShapeTemplate(int pulseShapeId,
130  const HcalPulseShapes& ps,
131  bool hasTimeInfo,
132  const HcalTimeSlew* hcalTimeSlewDelay,
133  unsigned int nSamples,
134  const float gain);
135 
136  typedef BXVector::Index Index;
138 
141 
142 private:
143  typedef std::pair<int, std::shared_ptr<FitterFuncs::PulseShapeFunctor> > ShapeWithId;
144 
145  const float minimize() const;
146  void onePulseMinimize() const;
147  void updateCov(const SampleMatrix& invCovMat) const;
148  void resetPulseShapeTemplate(int pulseShapeId, const HcalPulseShapes& ps, unsigned int nSamples);
149 
150  float ccTime(const float itQ) const;
151  void updatePulseShape(const float itQ,
152  FullSampleVector& pulseShape,
153  FullSampleVector& pulseDeriv,
154  FullSampleMatrix& pulseCov) const;
155 
156  float calculateArrivalTime(const unsigned int iBX) const;
157  float calculateChiSq() const;
158  void nnls() const;
159  void resetWorkspace() const;
160 
161  void nnlsUnconstrainParameter(Index idxp) const;
162  void nnlsConstrainParameter(Index minratioidx) const;
163 
164  void solveSubmatrix(PulseMatrix& mat, PulseVector& invec, PulseVector& outvec, unsigned nP) const;
165 
167 
168  //hard coded in initializer
169  static constexpr int pedestalBX_ = 100;
170 
171  // used to restrict returned time value to a 25 ns window centered
172  // on the nominal arrival time
173  static constexpr float timeLimit_ = 12.5f;
174 
175  // Python-configurables
177 
179  float ts4Thresh_;
181 
184  float tsDelay1GeV_ = 0.f;
185  float norm_ = (1.f / std::sqrt(12));
186 
188  float meanTime_;
191 
192  std::vector<int> activeBXs_;
193 
196 
198  float nnlsThresh_;
199 
200  unsigned int bxSizeConf_;
202 
203  //for pulse shapes
204  int currentPulseShapeId_ = INT_MIN;
207  std::vector<ShapeWithId> knownPulseShapes_;
208 };
209 
210 #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:180
Eigen::Matrix< double, SampleVectorSize, Eigen::Dynamic, 0, SampleVectorSize, PulseVectorSize > SamplePulseMatrix
void nnlsUnconstrainParameter(Index idxp) const
Definition: MahiFit.cc:603
float itPulse[MaxSVSize]
Definition: MahiFit.h:92
float thEnergeticPulsesFC_
Definition: MahiFit.h:140
float ootPulse[7][MaxSVSize]
Definition: MahiFit.h:93
SamplePulseMatrix invcovp
Definition: MahiFit.h:58
HcalTimeSlew::BiasSetting slewFlavor_
Definition: MahiFit.h:183
SampleVector amplitudes
Definition: MahiFit.h:31
int currentPulseShapeId_
Definition: MahiFit.h:204
void resetWorkspace() const
Definition: MahiFit.cc:742
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
Eigen::LLT< SampleMatrix > SampleDecompLLT
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:166
void nnlsConstrainParameter(Index minratioidx) const
Definition: MahiFit.cc:615
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
BXVector::Index Index
Definition: MahiFit.h:136
float inDarkCurrent
Definition: MahiFit.h:72
static constexpr int pedestalBX_
Definition: MahiFit.h:169
bool applyTimeSlew_
Definition: MahiFit.h:182
PulseVector ampVec
Definition: MahiFit.h:56
~MahiFit()
Definition: MahiFit.h:99
float norm_
Definition: MahiFit.h:185
std::array< SampleMatrix, MaxPVSize > pulseCovArray
Definition: MahiFit.h:46
SampleDecompLLT covDecomp
Definition: MahiFit.h:62
float meanTime_
Definition: MahiFit.h:188
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:533
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:50
float thEnergeticPulses_
Definition: MahiFit.h:139
float calculateChiSq() const
Definition: MahiFit.cc:543
bool calculateArrivalTime_
Definition: MahiFit.h:187
int bxOffsetConf_
Definition: MahiFit.h:201
PulseVector aTbVec
Definition: MahiFit.h:60
float calculateArrivalTime(const unsigned int iBX) const
Definition: MahiFit.cc:419
float nnlsThresh_
Definition: MahiFit.h:198
float inPedestal[MaxSVSize]
Definition: MahiFit.h:79
int cntsetPulseShape_
Definition: MahiFit.h:205
MahiFit()
Definition: MahiFit.cc:5
T sqrt(T t)
Definition: SSEVec.h:23
unsigned int bxSizeConf_
Definition: MahiFit.h:200
void solveSubmatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned nP) const
Definition: MahiFit.cc:693
const float minimize() const
Definition: MahiFit.cc:229
void phase1Debug(const HBHEChannelInfo &channelData, MahiDebugInfo &mdi) const
Definition: MahiFit.cc:627
int nMaxItersMin_
Definition: MahiFit.h:194
int nSamples
Definition: MahiFit.h:66
float chiSq
Definition: MahiFit.h:84
void nnls() const
Definition: MahiFit.cc:439
std::vector< int > activeBXs_
Definition: MahiFit.h:192
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:173
unsigned int tsOffset
Definition: MahiFit.h:22
float ccTime(const float itQ) const
Definition: MahiFit.cc:354
void setPulseShapeTemplate(int pulseShapeId, const HcalPulseShapes &ps, bool hasTimeInfo, const HcalTimeSlew *hcalTimeSlewDelay, unsigned int nSamples, const float gain)
Definition: MahiFit.cc:548
float tsDelay1GeV_
Definition: MahiFit.h:184
float inPedAvg
Definition: MahiFit.h:73
void resetPulseShapeTemplate(int pulseShapeId, const HcalPulseShapes &ps, unsigned int nSamples)
Definition: MahiFit.cc:578
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:334
SamplePulseMatrix pulseMat
Definition: MahiFit.h:49
void doFit(std::array< float, 4 > &correctedOutput, const int nbx) const
Definition: MahiFit.cc:135
bool dynamicPed_
Definition: MahiFit.h:178
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:190
float inNoisePhoto[MaxSVSize]
Definition: MahiFit.h:78
SampleVector noiseTerms
Definition: MahiFit.h:34
float ts4Thresh_
Definition: MahiFit.h:179
const HcalTimeSlew * hcalTimeSlewDelay_
Definition: MahiFit.h:137
unsigned int tsSize
Definition: MahiFit.h:21
std::pair< int, std::shared_ptr< FitterFuncs::PulseShapeFunctor > > ShapeWithId
Definition: MahiFit.h:143
float deltaChiSqThresh_
Definition: MahiFit.h:197
float timeSigmaHPD_
Definition: MahiFit.h:189
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:195
void updatePulseShape(const float itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv, FullSampleMatrix &pulseCov) const
Definition: MahiFit.cc:274
SampleVector pedVals
Definition: MahiFit.h:37
void setParameters(bool iDynamicPed, double iTS4Thresh, double chiSqSwitch, bool iApplyTimeSlew, HcalTimeSlew::BiasSetting slewFlavor, bool iCalculateArrivalTime, int iTimeAlgo, double iThEnergeticPulses, double iMeanTime, double iTimeSigmaHPD, double iTimeSigmaSiPM, const std::vector< int > &iActiveBXs, int iNMaxItersMin, int iNMaxItersNNLS, double iDeltaChiSqThresh, double iNnlsThresh)
Definition: MahiFit.cc:7
FitterFuncs::PulseShapeFunctor * psfPtr_
Definition: MahiFit.h:206
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix
std::vector< ShapeWithId > knownPulseShapes_
Definition: MahiFit.h:207
int timeAlgo_
Definition: MahiFit.h:176