Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21664 from jaylawhorn/MahiCleanForPR_10_0_X
[HCAL] Mahi for HBHE local reconstruction
- Loading branch information
Showing
11 changed files
with
962 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef RecoLocalCalo_HcalRecAlgos_EigenMatrixTypes_h | ||
#define RecoLocalCalo_HcalRecAlgos_EigenMatrixTypes_h | ||
|
||
#include <Eigen/Dense> | ||
|
||
constexpr int MaxSVSize=10; | ||
constexpr int MaxFSVSize=19; | ||
constexpr int MaxPVSize=10; | ||
|
||
typedef Eigen::Matrix<double,Eigen::Dynamic,1,0,MaxSVSize,1> SampleVector; | ||
typedef Eigen::Matrix<double,Eigen::Dynamic,1,0,MaxPVSize,1> PulseVector; | ||
typedef Eigen::Matrix<int,Eigen::Dynamic,1,0,MaxPVSize,1> BXVector; | ||
|
||
typedef Eigen::Matrix<double,MaxFSVSize,1> FullSampleVector; | ||
typedef Eigen::Matrix<double,MaxFSVSize,MaxFSVSize> FullSampleMatrix; | ||
|
||
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,0,MaxSVSize,MaxSVSize> SampleMatrix; | ||
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,0,MaxPVSize,MaxPVSize> PulseMatrix; | ||
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,0,MaxSVSize,MaxPVSize> SamplePulseMatrix; | ||
|
||
typedef Eigen::LLT<SampleMatrix> SampleDecompLLT; | ||
typedef Eigen::LLT<PulseMatrix> PulseDecompLLT; | ||
typedef Eigen::LDLT<PulseMatrix> PulseDecompLDLT; | ||
|
||
typedef Eigen::Matrix<double,1,1> SingleMatrix; | ||
typedef Eigen::Matrix<double,1,1> SingleVector; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
#ifndef RecoLocalCalo_HcalRecAlgos_MahiFit_HH | ||
#define RecoLocalCalo_HcalRecAlgos_MahiFit_HH | ||
|
||
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h" | ||
#include "DataFormats/HcalDetId/interface/HcalDetId.h" | ||
#include "CalibFormats/HcalObjects/interface/HcalCalibrations.h" | ||
#include "CalibFormats/HcalObjects/interface/HcalCoder.h" | ||
#include "RecoLocalCalo/HcalRecAlgos/interface/EigenMatrixTypes.h" | ||
#include "DataFormats/HcalRecHit/interface/HBHEChannelInfo.h" | ||
|
||
#include "CalibCalorimetry/HcalAlgos/interface/HcalPulseShapes.h" | ||
#include "CalibCalorimetry/HcalAlgos/interface/HcalTimeSlew.h" | ||
#include "RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFunctor.h" | ||
|
||
#include <Math/Functor.h> | ||
|
||
struct MahiNnlsWorkspace { | ||
|
||
unsigned int nPulseTot; | ||
unsigned int tsSize; | ||
unsigned int tsOffset; | ||
unsigned int fullTSOffset; | ||
int bxOffset; | ||
double dt; | ||
|
||
//holds active bunch crossings | ||
BXVector bxs; | ||
|
||
//holds data samples | ||
SampleVector amplitudes; | ||
|
||
//holds inverse covariance matrix | ||
SampleMatrix invCovMat; | ||
|
||
//holds diagonal noise terms | ||
SampleVector noiseTerms; | ||
|
||
//holds flat pedestal uncertainty | ||
SampleMatrix pedConstraint; | ||
|
||
//holds full covariance matrix for a pulse shape | ||
//varied in time | ||
std::array<FullSampleMatrix, MaxPVSize> pulseCovArray; | ||
|
||
//holds full pulse shape template | ||
std::array<FullSampleVector, MaxPVSize> pulseShapeArray; | ||
|
||
//holds full pulse shape derivatives | ||
std::array<FullSampleVector, MaxPVSize> pulseDerivArray; | ||
|
||
//holders for calculating pulse shape & covariance matrices | ||
std::array<double, MaxSVSize> pulseN; | ||
std::array<double, MaxSVSize> pulseM; | ||
std::array<double, MaxSVSize> pulseP; | ||
|
||
//holds matrix of pulse shape templates for each BX | ||
SamplePulseMatrix pulseMat; | ||
|
||
//holds matrix of pulse shape derivatives for each BX | ||
SamplePulseMatrix pulseDerivMat; | ||
|
||
//holds residual vector | ||
PulseVector residuals; | ||
|
||
//for FNNLS algorithm | ||
unsigned int nP; | ||
PulseVector ampVec; | ||
|
||
PulseVector errVec; | ||
PulseVector ampvecpermtest; | ||
|
||
SamplePulseMatrix invcovp; | ||
PulseMatrix aTaMat; // A-transpose A (matrix) | ||
PulseVector aTbVec; // A-transpose b (vector) | ||
PulseVector updateWork; // w (vector) | ||
|
||
SampleDecompLLT covDecomp; | ||
SampleMatrix covDecompLinv; | ||
PulseMatrix topleft_work; | ||
PulseDecompLDLT pulseDecomp; | ||
|
||
}; | ||
|
||
class MahiFit | ||
{ | ||
public: | ||
MahiFit(); | ||
~MahiFit() { }; | ||
|
||
void setParameters(bool iDynamicPed, double iTS4Thresh, double chiSqSwitch, | ||
bool iApplyTimeSlew, HcalTimeSlew::BiasSetting slewFlavor, | ||
double iMeanTime, double iTimeSigmaHPD, double iTimeSigmaSiPM, | ||
const std::vector <int> &iActiveBXs, int iNMaxItersMin, int iNMaxItersNNLS, | ||
double iDeltaChiSqThresh, double iNnlsThresh); | ||
|
||
void phase1Apply(const HBHEChannelInfo& channelData, | ||
float& reconstructedEnergy, | ||
float& reconstructedTime, | ||
bool& useTriple, | ||
float& chi2) const; | ||
|
||
void doFit(std::array<float,3> &correctedOutput, int nbx) const; | ||
|
||
void setPulseShapeTemplate (const HcalPulseShapes::Shape& ps); | ||
void resetPulseShapeTemplate(const HcalPulseShapes::Shape& ps); | ||
|
||
typedef BXVector::Index Index; | ||
const HcalPulseShapes::Shape* currentPulseShape_=nullptr; | ||
|
||
private: | ||
|
||
double minimize() const; | ||
void onePulseMinimize() const; | ||
void updateCov() const; | ||
void updatePulseShape(double itQ, FullSampleVector &pulseShape, | ||
FullSampleVector &pulseDeriv, | ||
FullSampleMatrix &pulseCov) const; | ||
double calculateArrivalTime() const; | ||
double calculateChiSq() const; | ||
void nnls() const; | ||
void resetWorkspace() const; | ||
|
||
void nnlsUnconstrainParameter(Index idxp) const; | ||
void nnlsConstrainParameter(Index minratioidx) const; | ||
|
||
void solveSubmatrix(PulseMatrix& mat, PulseVector& invec, PulseVector& outvec, unsigned nP) const; | ||
|
||
double getSiPMDarkCurrent(double darkCurrent, double fcByPE, double lambda) const; | ||
|
||
mutable MahiNnlsWorkspace nnlsWork_; | ||
|
||
//hard coded in initializer | ||
const unsigned int fullTSSize_; | ||
const unsigned int fullTSofInterest_; | ||
|
||
static constexpr int pedestalBX_ = 100; | ||
|
||
// Python-configurables | ||
bool dynamicPed_; | ||
float ts4Thresh_; | ||
float chiSqSwitch_; | ||
|
||
bool applyTimeSlew_; | ||
HcalTimeSlew::BiasSetting slewFlavor_; | ||
|
||
float meanTime_; | ||
float timeSigmaHPD_; | ||
float timeSigmaSiPM_; | ||
|
||
std::vector <int> activeBXs_; | ||
|
||
int nMaxItersMin_; | ||
int nMaxItersNNLS_; | ||
|
||
float deltaChiSqThresh_; | ||
float nnlsThresh_; | ||
|
||
unsigned int bxSizeConf_; | ||
int bxOffsetConf_; | ||
|
||
//for pulse shapes | ||
int cntsetPulseShape_; | ||
std::unique_ptr<FitterFuncs::PulseShapeFunctor> psfPtr_; | ||
std::unique_ptr<ROOT::Math::Functor> pfunctor_; | ||
|
||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.