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  double dt;
25 
26  //holds active bunch crossings
28 
29  //holds data samples
31 
32  //holds inverse covariance matrix
34 
35  //holds diagonal noise terms
37 
38  //holds flat pedestal uncertainty
40 
41  //holds full covariance matrix for a pulse shape
42  //varied in time
43  std::array<FullSampleMatrix, MaxPVSize> pulseCovArray;
44 
45  //holds full pulse shape template
46  std::array<FullSampleVector, MaxPVSize> pulseShapeArray;
47 
48  //holds full pulse shape derivatives
49  std::array<FullSampleVector, MaxPVSize> pulseDerivArray;
50 
51  //holders for calculating pulse shape & covariance matrices
52  std::array<double, MaxSVSize> pulseN;
53  std::array<double, MaxSVSize> pulseM;
54  std::array<double, MaxSVSize> pulseP;
55 
56  //holds matrix of pulse shape templates for each BX
58 
59  //holds matrix of pulse shape derivatives for each BX
61 
62  //holds residual vector
64 
65  //for FNNLS algorithm
66  unsigned int nP;
68 
71 
73  PulseMatrix aTaMat; // A-transpose A (matrix)
74  PulseVector aTbVec; // A-transpose b (vector)
75  PulseVector updateWork; // w (vector)
76 
81 
82 };
83 
84 class MahiFit
85 {
86  public:
87  MahiFit();
88  ~MahiFit() { };
89 
90  void setParameters(bool iDynamicPed, double iTS4Thresh, double chiSqSwitch,
91  bool iApplyTimeSlew, HcalTimeSlew::BiasSetting slewFlavor,
92  double iMeanTime, double iTimeSigmaHPD, double iTimeSigmaSiPM,
93  const std::vector <int> &iActiveBXs, int iNMaxItersMin, int iNMaxItersNNLS,
94  double iDeltaChiSqThresh, double iNnlsThresh);
95 
96  void phase1Apply(const HBHEChannelInfo& channelData,
97  float& reconstructedEnergy,
98  float& reconstructedTime,
99  bool& useTriple,
100  float& chi2,
101  const HcalTimeSlew* hcalTimeSlew_delay) const;
102 
103  void doFit(std::array<float,3> &correctedOutput, int nbx, const HcalTimeSlew* hcalTimeSlew_delay) const;
104 
105  void setPulseShapeTemplate (const HcalPulseShapes::Shape& ps);
106  void resetPulseShapeTemplate(const HcalPulseShapes::Shape& ps);
107 
108  typedef BXVector::Index Index;
109  const HcalPulseShapes::Shape* currentPulseShape_=nullptr;
110 
111  private:
112 
113  double minimize() const;
114  void onePulseMinimize() const;
115  void updateCov() const;
116  void updatePulseShape(double itQ, FullSampleVector &pulseShape,
117  FullSampleVector &pulseDeriv,
118  FullSampleMatrix &pulseCov,
119  const HcalTimeSlew* hcalTimeSlew_delay) const;
120  double calculateArrivalTime() const;
121  double calculateChiSq() const;
122  void nnls() const;
123  void resetWorkspace() const;
124 
125  void nnlsUnconstrainParameter(Index idxp) const;
126  void nnlsConstrainParameter(Index minratioidx) const;
127 
128  void solveSubmatrix(PulseMatrix& mat, PulseVector& invec, PulseVector& outvec, unsigned nP) const;
129 
130  double getSiPMDarkCurrent(double darkCurrent, double fcByPE, double lambda) const;
131 
133 
134  //hard coded in initializer
135  const unsigned int fullTSSize_;
136  const unsigned int fullTSofInterest_;
137 
138  static constexpr int pedestalBX_ = 100;
139 
140  // Python-configurables
142  float ts4Thresh_;
143  float chiSqSwitch_;
144 
147 
148  float meanTime_;
151 
152  std::vector <int> activeBXs_;
153 
156 
158  float nnlsThresh_;
159 
160  unsigned int bxSizeConf_;
162 
163  //for pulse shapes
165  std::unique_ptr<FitterFuncs::PulseShapeFunctor> psfPtr_;
166  std::unique_ptr<ROOT::Math::Functor> pfunctor_;
167 
168 };
169 #endif
unsigned int nPulseTot
Definition: MahiFit.h:19
float chiSqSwitch_
Definition: MahiFit.h:143
SamplePulseMatrix invcovp
Definition: MahiFit.h:72
HcalTimeSlew::BiasSetting slewFlavor_
Definition: MahiFit.h:146
SampleVector amplitudes
Definition: MahiFit.h:30
Eigen::LLT< SampleMatrix > SampleDecompLLT
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:132
BXVector::Index Index
Definition: MahiFit.h:108
bool applyTimeSlew_
Definition: MahiFit.h:145
PulseVector ampVec
Definition: MahiFit.h:67
~MahiFit()
Definition: MahiFit.h:88
SampleDecompLLT covDecomp
Definition: MahiFit.h:77
PulseVector ampvecpermtest
Definition: MahiFit.h:70
Eigen::LDLT< PulseMatrix > PulseDecompLDLT
std::array< FullSampleVector, MaxPVSize > pulseShapeArray
Definition: MahiFit.h:46
float meanTime_
Definition: MahiFit.h:148
std::array< double, MaxSVSize > pulseM
Definition: MahiFit.h:53
PulseMatrix topleft_work
Definition: MahiFit.h:79
#define constexpr
SamplePulseMatrix pulseDerivMat
Definition: MahiFit.h:60
std::array< double, MaxSVSize > pulseN
Definition: MahiFit.h:52
int bxOffsetConf_
Definition: MahiFit.h:161
PulseVector aTbVec
Definition: MahiFit.h:74
float nnlsThresh_
Definition: MahiFit.h:158
int cntsetPulseShape_
Definition: MahiFit.h:164
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
Definition: MahiFit.h:165
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
unsigned int bxSizeConf_
Definition: MahiFit.h:160
int nMaxItersMin_
Definition: MahiFit.h:154
PulseVector residuals
Definition: MahiFit.h:63
SampleMatrix pedConstraint
Definition: MahiFit.h:39
std::vector< int > activeBXs_
Definition: MahiFit.h:152
std::array< FullSampleVector, MaxPVSize > pulseDerivArray
Definition: MahiFit.h:49
const unsigned int fullTSofInterest_
Definition: MahiFit.h:136
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
SampleMatrix covDecompLinv
Definition: MahiFit.h:78
SampleMatrix invCovMat
Definition: MahiFit.h:33
unsigned int tsOffset
Definition: MahiFit.h:21
std::unique_ptr< ROOT::Math::Functor > pfunctor_
Definition: MahiFit.h:166
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
PulseMatrix aTaMat
Definition: MahiFit.h:73
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
unsigned int fullTSOffset
Definition: MahiFit.h:22
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
SamplePulseMatrix pulseMat
Definition: MahiFit.h:57
bool dynamicPed_
Definition: MahiFit.h:141
std::array< FullSampleMatrix, MaxPVSize > pulseCovArray
Definition: MahiFit.h:43
float timeSigmaSiPM_
Definition: MahiFit.h:150
SampleVector noiseTerms
Definition: MahiFit.h:36
Eigen::Matrix< double, SampleVectorSize, Eigen::Dynamic, 0, SampleVectorSize, PulseVectorSize > SamplePulseMatrix
float ts4Thresh_
Definition: MahiFit.h:142
PulseDecompLDLT pulseDecomp
Definition: MahiFit.h:80
unsigned int tsSize
Definition: MahiFit.h:20
float deltaChiSqThresh_
Definition: MahiFit.h:157
float timeSigmaHPD_
Definition: MahiFit.h:149
unsigned int nP
Definition: MahiFit.h:66
BXVector bxs
Definition: MahiFit.h:27
PulseVector errVec
Definition: MahiFit.h:69
int nMaxItersNNLS_
Definition: MahiFit.h:155
std::array< double, MaxSVSize > pulseP
Definition: MahiFit.h:54
const unsigned int fullTSSize_
Definition: MahiFit.h:135
PulseVector updateWork
Definition: MahiFit.h:75
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix