10 double mu = darkCurrent * 25 / fcByPE;
11 return sqrt(mu/
pow(1-lambda,3)) * fcByPE;
16 double iMeanTime,
double iTimeSigmaHPD,
double iTimeSigmaSiPM,
17 const std::vector <int> &iActiveBXs,
int iNMaxItersMin,
int iNMaxItersNNLS,
18 double iDeltaChiSqThresh,
double iNnlsThresh) {
46 float& reconstructedEnergy,
47 float& reconstructedTime,
79 std::array<float,3> reconstructedVals {{ 0.0, -9999, -9999 }};
81 double tsTOT = 0, tstrig = 0;
94 noiseDC = darkCurrent;
98 double noisePhoto = 0;
100 noisePhoto =
sqrt((charge-ped)*channelData.
fcByPE());
107 nnlsWork_.
noiseTerms.coeffRef(iTS) = noiseADC*noiseADC + noiseDC*noiseDC + noisePhoto*noisePhoto + pedWidth*pedWidth;
109 tsTOT += (charge - ped)*channelData.
tsGain(0);
111 tstrig += (charge - ped)*channelData.
tsGain(0);
121 doFit(reconstructedVals,1,hcalTimeSlew_delay);
123 doFit(reconstructedVals,0,hcalTimeSlew_delay);
128 doFit(reconstructedVals,0,hcalTimeSlew_delay);
133 reconstructedVals.at(0) = 0.;
134 reconstructedVals.at(1) = -9999.;
135 reconstructedVals.at(2) = -9999.;
138 reconstructedEnergy = reconstructedVals[0]*channelData.
tsGain(0);
139 reconstructedTime = reconstructedVals[1];
140 chi2 = reconstructedVals[2];
146 unsigned int bxSize=1;
162 for (
unsigned int iBX=0; iBX<bxSize; iBX++) {
214 bool foundintime =
false;
215 unsigned int ipulseintime = 0;
227 correctedOutput.at(1) = arrivalTime;
228 correctedOutput.at(2) = chiSq;
237 double oldChiSq=9999;
238 double chiSq=oldChiSq;
255 double deltaChiSq = newChiSq - chiSq;
257 if (newChiSq==oldChiSq && newChiSq<chiSq) {
284 const double xx[4]={
t0, 1.0, 0.0, 3};
288 (*pfunctor_)(&xx[0]);
291 (*pfunctor_)(&xxm[0]);
294 (*pfunctor_)(&xxp[0]);
316 pulseCov(iTS,jTS) +=
tmp;
317 pulseCov(jTS,iTS) +=
tmp;
354 if (offset==0) itIndex=iBX;
373 for (
unsigned int iBX=0; iBX<npulse; iBX++) {
398 const unsigned int nActive = npulse -
nnlsWork_.
nP;
401 Index idxwmaxprev = idxwmax;
402 double wmaxprev = wmax;
405 if (wmax<threshold || (idxwmax==idxwmaxprev && wmax==wmaxprev)) {
427 bool positive =
true;
440 for (
unsigned int ipulse=0; ipulse<
nnlsWork_.
nP; ++ipulse) {
444 if (ratio<minratio) {
446 minratioidx = ipulse;
502 1,0,2.5,0,0.00065,1,10));
529 using namespace Eigen;
533 Matrix<double,10,10>
temp = mat;
534 outvec.head<10>() = temp.ldlt().solve(invec.head<10>());
539 Matrix<double,9,9>
temp = mat.topLeftCorner<9,9>();
540 outvec.head<9>() = temp.ldlt().solve(invec.head<9>());
545 Matrix<double,8,8>
temp = mat.topLeftCorner<8,8>();
546 outvec.head<8>() = temp.ldlt().solve(invec.head<8>());
551 Matrix<double,7,7>
temp = mat.topLeftCorner<7,7>();
552 outvec.head<7>() = temp.ldlt().solve(invec.head<7>());
557 Matrix<double,6,6>
temp = mat.topLeftCorner<6,6>();
558 outvec.head<6>() = temp.ldlt().solve(invec.head<6>());
563 Matrix<double,5,5>
temp = mat.topLeftCorner<5,5>();
564 outvec.head<5>() = temp.ldlt().solve(invec.head<5>());
569 Matrix<double,4,4>
temp = mat.topLeftCorner<4,4>();
570 outvec.head<4>() = temp.ldlt().solve(invec.head<4>());
575 Matrix<double,3,3>
temp = mat.topLeftCorner<3,3>();
576 outvec.head<3>() = temp.ldlt().solve(invec.head<3>());
581 Matrix<double,2,2>
temp = mat.topLeftCorner<2,2>();
582 outvec.head<2>() = temp.ldlt().solve(invec.head<2>());
587 Matrix<double,1,1>
temp = mat.topLeftCorner<1,1>();
588 outvec.head<1>() = temp.ldlt().solve(invec.head<1>());
593 <<
"Weird number of pulses encountered in Mahi, module is configured incorrectly!";
SamplePulseMatrix invcovp
HcalTimeSlew::BiasSetting slewFlavor_
double tsGain(const unsigned ts) const
void nnlsConstrainParameter(Index minratioidx) const
MahiNnlsWorkspace nnlsWork_
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2, const HcalTimeSlew *hcalTimeSlew_delay) const
double singlePulseShapeFunc(const double *x)
void solveSubmatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned nP) const
double delay(double fC, BiasSetting bias=Medium) const
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
static constexpr int pedestalBX_
void resetPulseShapeTemplate(const HcalPulseShapes::Shape &ps)
SampleDecompLLT covDecomp
PulseVector ampvecpermtest
std::array< FullSampleVector, MaxPVSize > pulseShapeArray
void nnlsUnconstrainParameter(Index idxp) const
std::array< double, MaxSVSize > pulseM
bool hasEffectivePedestals() const
double tsPedestal(const unsigned ts) const
void doFit(std::array< float, 3 > &correctedOutput, int nbx, const HcalTimeSlew *hcalTimeSlew_delay) const
SamplePulseMatrix pulseDerivMat
std::array< double, MaxSVSize > pulseN
double tsRawCharge(const unsigned ts) const
void onePulseMinimize() const
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
double getSiPMDarkCurrent(double darkCurrent, double fcByPE, double lambda) const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Eigen::Matrix< double, 1, 1 > SingleVector
Abs< T >::type abs(const T &t)
void setPulseShapeTemplate(const HcalPulseShapes::Shape &ps)
double calculateArrivalTime() const
SampleMatrix pedConstraint
std::vector< int > activeBXs_
std::array< FullSampleVector, MaxPVSize > pulseDerivArray
double darkCurrent() const
const unsigned int fullTSofInterest_
SampleMatrix covDecompLinv
void resetWorkspace() const
std::unique_ptr< ROOT::Math::Functor > pfunctor_
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
void resize(int bx, unsigned size)
double tsPedestalWidth(const unsigned ts) const
double calculateChiSq() const
void updatePulseShape(double itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv, FullSampleMatrix &pulseCov, const HcalTimeSlew *hcalTimeSlew_delay) const
unsigned int fullTSOffset
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
SamplePulseMatrix pulseMat
std::array< FullSampleMatrix, MaxPVSize > pulseCovArray
std::vector< std::vector< double > > tmp
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)
const HcalPulseShapes::Shape * currentPulseShape_
unsigned nSamples() const
std::array< double, MaxSVSize > pulseP
Eigen::Matrix< double, 1, 1 > SingleMatrix
Power< A, B >::type pow(const A &a, const B &b)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix
float tsDFcPerADC(const unsigned ts) const