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