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