11 bool iCalculateArrivalTime,
double iMeanTime,
double iTimeSigmaHPD,
double iTimeSigmaSiPM,
12 const std::vector <int> &iActiveBXs,
int iNMaxItersMin,
int iNMaxItersNNLS,
13 double iDeltaChiSqThresh,
double iNnlsThresh) {
42 float& reconstructedEnergy,
43 float& reconstructedTime,
70 std::array<float,3> reconstructedVals {{ 0.0, -9999, -9999 }};
72 double tsTOT = 0, tstrig = 0;
83 double noisePhoto = 0;
85 noisePhoto =
sqrt((charge-ped)*channelData.
fcByPE());
92 nnlsWork_.
noiseTerms.coeffRef(iTS) = noiseADC*noiseADC + noisePhoto*noisePhoto + pedWidth*pedWidth;
94 tsTOT += (charge - ped)*channelData.
tsGain(0);
96 tstrig += (charge - ped)*channelData.
tsGain(0);
104 doFit(reconstructedVals,1);
106 doFit(reconstructedVals,0);
111 doFit(reconstructedVals,0);
116 reconstructedVals.at(0) = 0.;
117 reconstructedVals.at(1) = -9999.;
118 reconstructedVals.at(2) = -9999.;
121 reconstructedEnergy = reconstructedVals[0]*channelData.
tsGain(0);
122 reconstructedTime = reconstructedVals[1];
123 chi2 = reconstructedVals[2];
129 unsigned int bxSize=1;
148 for (
unsigned int iBX=0; iBX<bxSize; ++iBX) {
188 bool foundintime =
false;
189 unsigned int ipulseintime = 0;
200 if (correctedOutput.at(0)!=0) {
202 float arrivalTime = 0.;
204 correctedOutput.at(1) = arrivalTime;
206 else correctedOutput.at(1) = -9999;
208 correctedOutput.at(2) = chiSq;
222 double oldChiSq=9999;
223 double chiSq=oldChiSq;
237 double deltaChiSq = newChiSq - chiSq;
239 if (newChiSq==oldChiSq && newChiSq<chiSq) {
263 std::array<double, MaxSVSize> pulseN;
264 std::array<double, MaxSVSize> pulseM;
265 std::array<double, MaxSVSize> pulseP;
271 const double xx[4]={
t0, 1.0, 0.0, 3};
275 psfPtr_->singlePulseShapeFuncMahi(&xx[0]);
276 psfPtr_->getPulseShape(pulseN);
278 psfPtr_->singlePulseShapeFuncMahi(&xxm[0]);
279 psfPtr_->getPulseShape(pulseM);
281 psfPtr_->singlePulseShapeFuncMahi(&xxp[0]);
282 psfPtr_->getPulseShape(pulseP);
295 pulseM[iTS] -= pulseN[iTS];
296 pulseP[iTS] -= pulseN[iTS];
300 for (
unsigned int jTS=0; jTS<iTS+1; ++jTS) {
341 if (offset==0) itIndex=iBX;
348 float t = solution.coeff(itIndex);
362 updateWork.setZero(npulse);
365 ampvecpermtest.setZero(npulse);
382 const unsigned int nActive = npulse -
nnlsWork_.
nP;
385 Index idxwmaxprev = idxwmax;
386 double wmaxprev = wmax;
387 wmax = updateWork.tail(nActive).maxCoeff(&idxwmax);
389 if (wmax<threshold || (idxwmax==idxwmaxprev && wmax==wmaxprev)) {
411 bool positive =
true;
413 positive &= (ampvecpermtest(
i) > 0);
424 for (
unsigned int ipulse=0; ipulse<
nnlsWork_.
nP; ++ipulse) {
425 if (ampvecpermtest.coeff(ipulse)<=0.) {
427 const double ratio = c_ampvec/(c_ampvec-ampvecpermtest.coeff(ipulse));
428 if (ratio<minratio) {
430 minratioidx = ipulse;
521 float recoEnergy, recoTime,
chi2;
523 phase1Apply(channelData, recoEnergy, recoTime, use3, chi2);
527 mdi.
soi = channelData.
soi();
538 for (
unsigned int iTS=0; iTS<channelData.
nSamples(); ++iTS) {
567 mdi.
count[iTS] = iTS;
592 using namespace Eigen;
596 Matrix<double,10,10>
temp = mat;
597 outvec.head<10>() = temp.ldlt().solve(invec.head<10>());
602 Matrix<double,9,9>
temp = mat.topLeftCorner<9,9>();
603 outvec.head<9>() = temp.ldlt().solve(invec.head<9>());
608 Matrix<double,8,8>
temp = mat.topLeftCorner<8,8>();
609 outvec.head<8>() = temp.ldlt().solve(invec.head<8>());
614 Matrix<double,7,7>
temp = mat.topLeftCorner<7,7>();
615 outvec.head<7>() = temp.ldlt().solve(invec.head<7>());
620 Matrix<double,6,6>
temp = mat.topLeftCorner<6,6>();
621 outvec.head<6>() = temp.ldlt().solve(invec.head<6>());
626 Matrix<double,5,5>
temp = mat.topLeftCorner<5,5>();
627 outvec.head<5>() = temp.ldlt().solve(invec.head<5>());
632 Matrix<double,4,4>
temp = mat.topLeftCorner<4,4>();
633 outvec.head<4>() = temp.ldlt().solve(invec.head<4>());
638 Matrix<double,3,3>
temp = mat.topLeftCorner<3,3>();
639 outvec.head<3>() = temp.ldlt().solve(invec.head<3>());
644 Matrix<double,2,2>
temp = mat.topLeftCorner<2,2>();
645 outvec.head<2>() = temp.ldlt().solve(invec.head<2>());
650 Matrix<double,1,1>
temp = mat.topLeftCorner<1,1>();
651 outvec.head<1>() = temp.ldlt().solve(invec.head<1>());
656 <<
"Weird number of pulses encountered in Mahi, module is configured incorrectly!";
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
SamplePulseMatrix invcovp
HcalTimeSlew::BiasSetting slewFlavor_
double tsGain(const unsigned ts) const
void nnlsConstrainParameter(Index minratioidx) const
MahiNnlsWorkspace nnlsWork_
void solveSubmatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned nP) const
void resetPulseShapeTemplate(const HcalPulseShapes::Shape &ps)
SampleDecompLLT covDecomp
void nnlsUnconstrainParameter(Index idxp) const
double tsPedestal(const unsigned ts) const
float totalUCNoise[MaxSVSize]
float inNoiseADC[MaxSVSize]
SamplePulseMatrix pulseDerivMat
bool calculateArrivalTime_
double tsRawCharge(const unsigned ts) const
float inPedestal[MaxSVSize]
void onePulseMinimize() const
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
void doFit(std::array< float, 3 > &correctedOutput, const int nbx) const
Eigen::Matrix< double, 1, 1 > SingleVector
Abs< T >::type abs(const T &t)
SampleMatrix pedConstraint
std::vector< int > activeBXs_
const unsigned int fullTSofInterest_
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
void updatePulseShape(double itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv, FullSampleMatrix &pulseCov) const
void resetWorkspace() const
void phase1Debug(const HBHEChannelInfo &channelData, MahiDebugInfo &mdi) const
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
float tsRiseTime(const unsigned ts) const
double tsPedestalWidth(const unsigned ts) const
double calculateChiSq() const
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
unsigned int fullTSOffset
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
SamplePulseMatrix pulseMat
std::array< FullSampleMatrix, MaxPVSize > pulseCovArray
float inNoisePhoto[MaxSVSize]
std::vector< std::vector< double > > tmp
const HcalTimeSlew * hcalTimeSlewDelay_
float delay(float 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...
const HcalPulseShapes::Shape * currentPulseShape_
unsigned nSamples() const
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)
Eigen::Matrix< double, 1, 1 > SingleMatrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix
float calculateArrivalTime() const
float tsDFcPerADC(const unsigned ts) const
void setPulseShapeTemplate(const HcalPulseShapes::Shape &ps, const HcalTimeSlew *hcalTimeSlewDelay)