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& reconstructedTime,
119  bool& useTriple,
120  float& chi2) const;
121 
122  void phase1Debug(const HBHEChannelInfo& channelData, MahiDebugInfo& mdi) const;
123 
124  void doFit(std::array<float, 3>& correctedOutput, const int nbx) const;
125 
126  void setPulseShapeTemplate(int pulseShapeId,
127  const HcalPulseShapes& ps,
128  bool hasTimeInfo,
129  const HcalTimeSlew* hcalTimeSlewDelay,
130  unsigned int nSamples);
131 
132  typedef BXVector::Index Index;
134 
135 private:
136  typedef std::pair<int, std::shared_ptr<FitterFuncs::PulseShapeFunctor> > ShapeWithId;
137 
138  const float minimize() const;
139  void onePulseMinimize() const;
140  void updateCov(const SampleMatrix& invCovMat) const;
141  void resetPulseShapeTemplate(int pulseShapeId, const HcalPulseShapes& ps, unsigned int nSamples);
142  void updatePulseShape(const float itQ,
143  FullSampleVector& pulseShape,
144  FullSampleVector& pulseDeriv,
145  FullSampleMatrix& pulseCov) const;
146 
147  float calculateArrivalTime(const unsigned int iBX) const;
148  float calculateChiSq() const;
149  void nnls() const;
150  void resetWorkspace() const;
151 
152  void nnlsUnconstrainParameter(Index idxp) const;
153  void nnlsConstrainParameter(Index minratioidx) const;
154 
155  void solveSubmatrix(PulseMatrix& mat, PulseVector& invec, PulseVector& outvec, unsigned nP) const;
156 
158 
159  //hard coded in initializer
160  static constexpr int pedestalBX_ = 100;
161 
162  // used to restrict returned time value to a 25 ns window centered
163  // on the nominal arrival time
164  static constexpr float timeLimit_ = 12.5f;
165 
166  // Python-configurables
168  float ts4Thresh_;
170 
173  float tsDelay1GeV_ = 0.f;
174  float norm_ = (1.f / std::sqrt(12));
175 
177  float meanTime_;
180 
181  std::vector<int> activeBXs_;
182 
185 
187  float nnlsThresh_;
188 
189  unsigned int bxSizeConf_;
191 
192  //for pulse shapes
193  int currentPulseShapeId_ = INT_MIN;
196  std::vector<ShapeWithId> knownPulseShapes_;
197 };
198 
199 #endif
MahiFit::updatePulseShape
void updatePulseShape(const float itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv, FullSampleMatrix &pulseCov) const
Definition: MahiFit.cc:258
MahiFit::nnlsWork_
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:157
HcalCalibrations.h
MahiDebugInfo::ootEnergy
float ootEnergy[7]
Definition: MahiFit.h:87
MahiNnlsWorkspace::maxoffset
int maxoffset
Definition: MahiFit.h:24
MahiDebugInfo::itPulse
float itPulse[MaxSVSize]
Definition: MahiFit.h:92
MahiFit::timeSigmaSiPM_
float timeSigmaSiPM_
Definition: MahiFit.h:179
MahiFit::applyTimeSlew_
bool applyTimeSlew_
Definition: MahiFit.h:171
MahiDebugInfo::totalUCNoise
float totalUCNoise[MaxSVSize]
Definition: MahiFit.h:81
MahiDebugInfo
Definition: MahiFit.h:65
MahiFit
Definition: MahiFit.h:96
MahiDebugInfo::mahiEnergy
float mahiEnergy
Definition: MahiFit.h:83
FullSampleMatrix
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
Definition: EigenMatrixTypes.h:18
SampleMatrix
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
Definition: EigenMatrixTypes.h:17
HcalPulseShapes
Definition: HcalPulseShapes.h:22
HcalPulseShapes.h
MahiNnlsWorkspace::aTaMat
PulseMatrix aTaMat
Definition: MahiFit.h:59
FitterFuncs::PulseShapeFunctor
Definition: PulseShapeFunctor.h:9
MahiDebugInfo::inNoiseDC
float inNoiseDC[MaxSVSize]
Definition: MahiFit.h:77
HcalCoder.h
MahiFit::resetPulseShapeTemplate
void resetPulseShapeTemplate(int pulseShapeId, const HcalPulseShapes &ps, unsigned int nSamples)
Definition: MahiFit.cc:493
MahiNnlsWorkspace::pedVals
SampleVector pedVals
Definition: MahiFit.h:37
MahiDebugInfo::count
float count[MaxSVSize]
Definition: MahiFit.h:89
HcalTimeSlew.h
MahiFit::bxSizeConf_
unsigned int bxSizeConf_
Definition: MahiFit.h:189
MahiFit::phase1Apply
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
Definition: MahiFit.cc:46
MahiFit::resetWorkspace
void resetWorkspace() const
Definition: MahiFit.cc:657
MahiNnlsWorkspace::ampVec
PulseVector ampVec
Definition: MahiFit.h:56
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
MahiFit::nnlsConstrainParameter
void nnlsConstrainParameter(Index minratioidx) const
Definition: MahiFit.cc:530
MahiNnlsWorkspace::bxs
BXVector bxs
Definition: MahiFit.h:28
MahiDebugInfo::pedEnergy
float pedEnergy
Definition: MahiFit.h:86
PresampleTask_cfi.nSamples
nSamples
Definition: PresampleTask_cfi.py:7
HcalTimeSlew::BiasSetting
BiasSetting
Definition: HcalTimeSlew.h:71
HcalTimeSlew
Definition: HcalTimeSlew.h:19
MahiFit::calculateChiSq
float calculateChiSq() const
Definition: MahiFit.cc:462
MahiDebugInfo::inPedAvg
float inPedAvg
Definition: MahiFit.h:73
MahiFit::bxOffsetConf_
int bxOffsetConf_
Definition: MahiFit.h:190
MahiFit::nnlsThresh_
float nnlsThresh_
Definition: MahiFit.h:187
MahiNnlsWorkspace::tsOffset
unsigned int tsOffset
Definition: MahiFit.h:22
BXVector
Definition: BXVector.h:15
MahiNnlsWorkspace::aTbVec
PulseVector aTbVec
Definition: MahiFit.h:60
PulseVector
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
Definition: EigenMatrixTypes.h:14
MahiFit::~MahiFit
~MahiFit()
Definition: MahiFit.h:99
MahiFit::timeLimit_
static constexpr float timeLimit_
Definition: MahiFit.h:164
MahiNnlsWorkspace
Definition: MahiFit.h:19
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HLT_FULL_cff.chiSqSwitch
chiSqSwitch
Definition: HLT_FULL_cff.py:8419
MahiFit::setParameters
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
MahiNnlsWorkspace::noiseTerms
SampleVector noiseTerms
Definition: MahiFit.h:34
MahiDebugInfo::inNoisePhoto
float inNoisePhoto[MaxSVSize]
Definition: MahiFit.h:78
SampleDecompLLT
Eigen::LLT< SampleMatrix > SampleDecompLLT
Definition: EigenMatrixTypes.h:21
MahiDebugInfo::use3
bool use3
Definition: MahiFit.h:69
MahiFit::knownPulseShapes_
std::vector< ShapeWithId > knownPulseShapes_
Definition: MahiFit.h:196
MahiDebugInfo::nSamples
int nSamples
Definition: MahiFit.h:66
MahiDebugInfo::arrivalTime
float arrivalTime
Definition: MahiFit.h:85
MahiFit::calculateArrivalTime_
bool calculateArrivalTime_
Definition: MahiFit.h:176
MahiDebugInfo::ootPulse
float ootPulse[7][MaxSVSize]
Definition: MahiFit.h:93
MahiNnlsWorkspace::invcovp
SamplePulseMatrix invcovp
Definition: MahiFit.h:58
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
MahiNnlsWorkspace::pedVal
float pedVal
Definition: MahiFit.h:40
MahiDebugInfo::soi
int soi
Definition: MahiFit.h:67
MahiFit::MahiFit
MahiFit()
Definition: MahiFit.cc:5
MahiFit::pedestalBX_
static constexpr int pedestalBX_
Definition: MahiFit.h:160
HBHEChannelInfo.h
MahiNnlsWorkspace::dt
float dt
Definition: MahiFit.h:25
MahiFit::cntsetPulseShape_
int cntsetPulseShape_
Definition: MahiFit.h:194
MahiFit::solveSubmatrix
void solveSubmatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned nP) const
Definition: MahiFit.cc:608
MahiNnlsWorkspace::tsSize
unsigned int tsSize
Definition: MahiFit.h:21
MahiFit::timeSigmaHPD_
float timeSigmaHPD_
Definition: MahiFit.h:178
MahiFit::minimize
const float minimize() const
Definition: MahiFit.cc:213
MahiNnlsWorkspace::amplitudes
SampleVector amplitudes
Definition: MahiFit.h:31
HcalDetId.h
MahiFit::phase1Debug
void phase1Debug(const HBHEChannelInfo &channelData, MahiDebugInfo &mdi) const
Definition: MahiFit.cc:542
MahiFit::chiSqSwitch_
float chiSqSwitch_
Definition: MahiFit.h:169
MahiFit::tsDelay1GeV_
float tsDelay1GeV_
Definition: MahiFit.h:173
MahiNnlsWorkspace::pulseCovArray
std::array< SampleMatrix, MaxPVSize > pulseCovArray
Definition: MahiFit.h:46
MahiFit::nMaxItersNNLS_
int nMaxItersNNLS_
Definition: MahiFit.h:184
EigenMatrixTypes.h
MahiDebugInfo::inputTDC
int inputTDC[MaxSVSize]
Definition: MahiFit.h:91
HcalSubdetector.h
MahiFit::updateCov
void updateCov(const SampleMatrix &invCovMat) const
Definition: MahiFit.cc:318
SamplePulseMatrix
Eigen::Matrix< double, SampleVectorSize, Eigen::Dynamic, 0, SampleVectorSize, PulseVectorSize > SamplePulseMatrix
Definition: EigenMatrixTypes.h:20
MahiFit::ts4Thresh_
float ts4Thresh_
Definition: MahiFit.h:168
MahiNnlsWorkspace::pulseMat
SamplePulseMatrix pulseMat
Definition: MahiFit.h:49
MahiFit::onePulseMinimize
void onePulseMinimize() const
Definition: MahiFit.cc:452
SampleVector
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
Definition: EigenMatrixTypes.h:12
MahiNnlsWorkspace::nP
unsigned int nP
Definition: MahiFit.h:55
FullSampleVector
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
Definition: EigenMatrixTypes.h:13
MahiDebugInfo::inTimeConst
float inTimeConst
Definition: MahiFit.h:71
MahiFit::nnls
void nnls() const
Definition: MahiFit.cc:358
MahiNnlsWorkspace::bxOffset
int bxOffset
Definition: MahiFit.h:23
MahiFit::hcalTimeSlewDelay_
const HcalTimeSlew * hcalTimeSlewDelay_
Definition: MahiFit.h:133
MahiFit::norm_
float norm_
Definition: MahiFit.h:174
MahiFit::meanTime_
float meanTime_
Definition: MahiFit.h:177
MahiDebugInfo::inGain
float inGain
Definition: MahiFit.h:74
MahiFit::deltaChiSqThresh_
float deltaChiSqThresh_
Definition: MahiFit.h:186
PulseMatrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix
Definition: EigenMatrixTypes.h:19
MaxSVSize
constexpr int MaxSVSize
Definition: EigenMatrixTypes.h:6
PulseShapeFunctor.h
MahiNnlsWorkspace::noisecorr
float noisecorr
Definition: MahiFit.h:42
MahiFit::setPulseShapeTemplate
void setPulseShapeTemplate(int pulseShapeId, const HcalPulseShapes &ps, bool hasTimeInfo, const HcalTimeSlew *hcalTimeSlewDelay, unsigned int nSamples)
Definition: MahiFit.cc:467
MahiNnlsWorkspace::covDecomp
SampleDecompLLT covDecomp
Definition: MahiFit.h:62
MahiFit::slewFlavor_
HcalTimeSlew::BiasSetting slewFlavor_
Definition: MahiFit.h:172
MahiDebugInfo::inputTS
float inputTS[MaxSVSize]
Definition: MahiFit.h:90
MahiDebugInfo::inNoiseADC
float inNoiseADC[MaxSVSize]
Definition: MahiFit.h:76
MahiFit::currentPulseShapeId_
int currentPulseShapeId_
Definition: MahiFit.h:193
MahiFit::dynamicPed_
bool dynamicPed_
Definition: MahiFit.h:167
MahiFit::doFit
void doFit(std::array< float, 3 > &correctedOutput, const int nbx) const
Definition: MahiFit.cc:122
MahiFit::psfPtr_
FitterFuncs::PulseShapeFunctor * psfPtr_
Definition: MahiFit.h:195
MahiFit::Index
BXVector::Index Index
Definition: MahiFit.h:132
MahiDebugInfo::chiSq
float chiSq
Definition: MahiFit.h:84
MahiFit::calculateArrivalTime
float calculateArrivalTime(const unsigned int iBX) const
Definition: MahiFit.cc:338
MahiFit::ShapeWithId
std::pair< int, std::shared_ptr< FitterFuncs::PulseShapeFunctor > > ShapeWithId
Definition: MahiFit.h:136
MahiFit::activeBXs_
std::vector< int > activeBXs_
Definition: MahiFit.h:181
MahiDebugInfo::inPedestal
float inPedestal[MaxSVSize]
Definition: MahiFit.h:79
MahiDebugInfo::inDarkCurrent
float inDarkCurrent
Definition: MahiFit.h:72
MahiNnlsWorkspace::nPulseTot
unsigned int nPulseTot
Definition: MahiFit.h:20
MahiFit::nMaxItersMin_
int nMaxItersMin_
Definition: MahiFit.h:183
MahiNnlsWorkspace::pulseDerivMat
SamplePulseMatrix pulseDerivMat
Definition: MahiFit.h:52
HBHEChannelInfo
Definition: HBHEChannelInfo.h:15
MahiFit::nnlsUnconstrainParameter
void nnlsUnconstrainParameter(Index idxp) const
Definition: MahiFit.cc:518