1 #define EIGEN_NO_DEBUG // kill throws in eigen code
12 bool iCalculateArrivalTime,
15 double iTimeSigmaSiPM,
16 const std::vector<int>& iActiveBXs,
19 double iDeltaChiSqThresh,
47 float& reconstructedEnergy,
48 float& soiPlusOneEnergy,
49 float& reconstructedTime,
53 const unsigned soi = channelData.
soi();
56 assert(nSamples == 8 || nSamples == 10);
65 std::array<float, 4> reconstructedVals{{0.f, -9999.f, -9999.f, 0.f}};
67 double tsTOT = 0, tstrig = 0;
80 auto const noisePhotoSq = (amplitude > pedWidth) ? (amplitude * channelData.
fcByPE()) : 0.
f;
83 nnlsWork_.
noiseTerms.coeffRef(iTS) = noiseADC * noiseADC + noisePhotoSq + pedWidth * pedWidth;
94 const float gain0 = channelData.
tsGain(0);
114 doFit(reconstructedVals, 1);
116 doFit(reconstructedVals, 0);
120 doFit(reconstructedVals, 0);
125 reconstructedEnergy = reconstructedVals[0] * gain0;
126 soiPlusOneEnergy = reconstructedVals[3] * gain0;
127 reconstructedTime = reconstructedVals[1];
128 chi2 = reconstructedVals[2];
132 unsigned int bxSize = 1;
150 for (
unsigned int iBX = 0; iBX < bxSize; ++iBX) {
196 bool foundintime =
false;
197 unsigned int ipulseintime = 0;
210 if (correctedOutput.at(0) != 0) {
212 float arrivalTime = 0.f;
215 correctedOutput.at(1) = arrivalTime;
217 correctedOutput.at(1) = -9999.f;
219 correctedOutput.at(2) = chiSq;
235 invCovMat(
i - 1,
i) += noiseCorrTerm;
236 invCovMat(
i,
i - 1) += noiseCorrTerm;
240 float oldChiSq = 9999;
241 float chiSq = oldChiSq;
253 const float deltaChiSq = newChiSq - chiSq;
255 if (newChiSq == oldChiSq && newChiSq < chiSq) {
285 std::array<double, hcal::constants::maxSamples> pulseN;
286 std::array<double, hcal::constants::maxSamples> pulseM;
287 std::array<double, hcal::constants::maxSamples> pulseP;
318 for (
unsigned int jTS = 0; jTS < iTS + 1; ++jTS) {
319 auto const tmp = 0.5 * (pulseP[iTS +
delta] * pulseP[jTS +
delta] + pulseM[iTS +
delta] * pulseM[jTS +
delta]);
390 const unsigned int nActive = npulse -
nnlsWork_.
nP;
397 Index idxwmaxprev = idxwmax;
398 float wmaxprev =
wmax;
399 wmax = updateWork.tail(nActive).maxCoeff(&idxwmax);
401 if (wmax < threshold || (idxwmax == idxwmaxprev && wmax == wmaxprev)) {
423 if (ampvecpermtest.head(
nnlsWork_.
nP).minCoeff() > 0.f) {
429 Index minratioidx = 0;
433 for (
unsigned int ipulse = 0; ipulse <
nnlsWork_.
nP; ++ipulse) {
434 if (ampvecpermtest.coeff(ipulse) <= 0.f) {
436 const float ratio = c_ampvec / (c_ampvec - ampvecpermtest.coeff(ipulse));
437 if (ratio < minratio) {
439 minratioidx = ipulse;
456 if (iter % 10 == 0) {
479 const bool hasTimeInfo,
483 assert(hcalTimeSlewDelay);
505 const unsigned int ) {
510 if (elem.first == pulseShapeId) {
519 auto p = std::make_shared<FitterFuncs::PulseShapeFunctor>(
521 knownPulseShapes_.emplace_back(pulseShapeId,
p);
553 float recoEnergy, soiPlus1Energy, recoTime,
chi2;
555 phase1Apply(channelData, recoEnergy, soiPlus1Energy, recoTime, use3, chi2);
558 mdi.
soi = channelData.
soi();
569 for (
unsigned int iTS = 0; iTS < channelData.
nSamples(); ++iTS) {
598 mdi.
count[iTS] = iTS;
619 using namespace Eigen;
622 Matrix<float, 10, 10>
temp = mat;
623 outvec.head<10>() = temp.ldlt().solve(invec.head<10>());
626 Matrix<float, 9, 9>
temp = mat.topLeftCorner<9, 9>();
627 outvec.head<9>() = temp.ldlt().solve(invec.head<9>());
630 Matrix<float, 8, 8>
temp = mat.topLeftCorner<8, 8>();
631 outvec.head<8>() = temp.ldlt().solve(invec.head<8>());
634 Matrix<float, 7, 7>
temp = mat.topLeftCorner<7, 7>();
635 outvec.head<7>() = temp.ldlt().solve(invec.head<7>());
638 Matrix<float, 6, 6>
temp = mat.topLeftCorner<6, 6>();
639 outvec.head<6>() = temp.ldlt().solve(invec.head<6>());
642 Matrix<float, 5, 5>
temp = mat.topLeftCorner<5, 5>();
643 outvec.head<5>() = temp.ldlt().solve(invec.head<5>());
646 Matrix<float, 4, 4>
temp = mat.topLeftCorner<4, 4>();
647 outvec.head<4>() = temp.ldlt().solve(invec.head<4>());
650 Matrix<float, 3, 3>
temp = mat.topLeftCorner<3, 3>();
651 outvec.head<3>() = temp.ldlt().solve(invec.head<3>());
654 Matrix<float, 2, 2>
temp = mat.topLeftCorner<2, 2>();
655 outvec.head<2>() = temp.ldlt().solve(invec.head<2>());
658 Matrix<float, 1, 1>
temp = mat.topLeftCorner<1, 1>();
659 outvec.head<1>() = temp.ldlt().solve(invec.head<1>());
663 <<
"Weird number of pulses encountered in Mahi, module is configured incorrectly!";
constexpr unsigned nSamples() const
const Shape & getShape(int shapeType) const
Eigen::Matrix< double, SampleVectorSize, Eigen::Dynamic, 0, SampleVectorSize, PulseVectorSize > SamplePulseMatrix
void setPulseShapeTemplate(int pulseShapeId, const HcalPulseShapes &ps, bool hasTimeInfo, const HcalTimeSlew *hcalTimeSlewDelay, unsigned int nSamples)
float ootPulse[7][MaxSVSize]
constexpr bool hasTimeInfo() const
SamplePulseMatrix invcovp
HcalTimeSlew::BiasSetting slewFlavor_
void nnlsConstrainParameter(Index minratioidx) const
void updatePulseShape(const float itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv, FullSampleMatrix &pulseCov) const
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &soiPlusOneEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
constexpr double tsGain(const unsigned ts) const
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
MahiNnlsWorkspace nnlsWork_
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
void singlePulseShapeFuncMahi(const float *x)
void solveSubmatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned nP) const
static constexpr int pedestalBX_
std::array< SampleMatrix, MaxPVSize > pulseCovArray
SampleDecompLLT covDecomp
void getPulseShape(std::array< double, hcal::constants::maxSamples > &fillPulseShape)
void nnlsUnconstrainParameter(Index idxp) const
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
float totalUCNoise[MaxSVSize]
void swap(Association< C > &lhs, Association< C > &rhs)
float inNoiseADC[MaxSVSize]
SamplePulseMatrix pulseDerivMat
bool calculateArrivalTime_
float inPedestal[MaxSVSize]
void onePulseMinimize() const
constexpr double tsPedestalWidth(const unsigned ts) const
const float minimize() const
Abs< T >::type abs(const T &t)
float calculateArrivalTime(const unsigned int iBX) const
void doFit(std::array< float, 4 > &correctedOutput, const int nbx) const
void updateCov(const SampleMatrix &invCovMat) const
constexpr double noisecorr() const
constexpr size_t nSamples
std::vector< int > activeBXs_
constexpr unsigned soi() const
constexpr double tsPedestal(const unsigned ts) const
constexpr float tsDFcPerADC(const unsigned ts) const
static constexpr float timeLimit_
void resetWorkspace() const
void phase1Debug(const HBHEChannelInfo &channelData, MahiDebugInfo &mdi) const
void resetPulseShapeTemplate(int pulseShapeId, const HcalPulseShapes &ps, unsigned int nSamples)
constexpr double fcByPE() const
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
SamplePulseMatrix pulseMat
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
float inNoisePhoto[MaxSVSize]
constexpr float tsRiseTime(const unsigned ts) const
float calculateChiSq() const
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...
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)
constexpr double tsRawCharge(const unsigned ts) const
FitterFuncs::PulseShapeFunctor * psfPtr_
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix
std::vector< ShapeWithId > knownPulseShapes_
__host__ __device__ V V wmax