1 #define EIGEN_NO_DEBUG // kill throws in eigen code 12 bool iCalculateArrivalTime,
14 double iThEnergeticPulses,
17 double iTimeSigmaSiPM,
18 const std::vector<int>& iActiveBXs,
21 double iDeltaChiSqThresh,
51 float& reconstructedEnergy,
52 float& soiPlusOneEnergy,
53 float& reconstructedTime,
57 const unsigned soi = channelData.
soi();
69 std::array<float, 4> reconstructedVals{{0.f, -9999.f, -9999.f, 0.f}};
71 double tsTOT = 0, tstrig = 0;
87 nnlsWork_.
noiseTerms.coeffRef(iTS) = noiseADC * noiseADC + noisePhotoSq + pedWidth * pedWidth;
98 const float gain0 = channelData.
tsGain(0);
118 doFit(reconstructedVals, 1);
120 doFit(reconstructedVals, 0);
124 doFit(reconstructedVals, 0);
129 reconstructedEnergy = reconstructedVals[0] * gain0;
130 soiPlusOneEnergy = reconstructedVals[3] * gain0;
131 reconstructedTime = reconstructedVals[1];
132 chi2 = reconstructedVals[2];
136 unsigned int bxSize = 1;
154 for (
unsigned int iBX = 0; iBX < bxSize; ++iBX) {
200 bool foundintime =
false;
201 unsigned int ipulseintime = 0;
214 if (correctedOutput.at(0) != 0) {
216 float arrivalTime = 0.f;
221 correctedOutput.at(1) = arrivalTime;
223 correctedOutput.at(1) = -9999.f;
225 correctedOutput.at(2) = chiSq;
241 invCovMat(
i - 1,
i) += noiseCorrTerm;
242 invCovMat(
i,
i - 1) += noiseCorrTerm;
246 float oldChiSq = 9999;
247 float chiSq = oldChiSq;
259 const float deltaChiSq = newChiSq - chiSq;
261 if (newChiSq == oldChiSq && newChiSq < chiSq) {
291 std::array<double, hcal::constants::maxSamples> pulseN;
292 std::array<double, hcal::constants::maxSamples> pulseM;
293 std::array<double, hcal::constants::maxSamples> pulseP;
324 for (
unsigned int jTS = 0; jTS < iTS + 1; ++jTS) {
325 auto const tmp = 0.5 * (pulseP[iTS +
delta] * pulseP[jTS +
delta] + pulseM[iTS +
delta] * pulseM[jTS +
delta]);
378 float distance_delta_max = 0.f;
380 std::array<double, hcal::constants::maxSamples> pulseN;
386 for (
int deltaNS = TS_beforeSOI; deltaNS < TS_SOIandAfter; ++deltaNS) {
387 const float xx =
t0 + deltaNS;
405 pulse2 += pulseN[iTS +
delta] * pulseN[iTS +
delta];
406 norm2 += norm * norm;
410 if (
distance > distance_delta_max) {
461 const unsigned int nActive = npulse -
nnlsWork_.
nP;
468 Index idxwmaxprev = idxwmax;
469 float wmaxprev =
wmax;
470 wmax = updateWork.tail(nActive).maxCoeff(&idxwmax);
494 if (ampvecpermtest.head(
nnlsWork_.
nP).minCoeff() > 0.f) {
500 Index minratioidx = 0;
504 for (
unsigned int ipulse = 0; ipulse <
nnlsWork_.
nP; ++ipulse) {
505 if (ampvecpermtest.coeff(ipulse) <= 0.f) {
507 const float ratio = c_ampvec / (c_ampvec - ampvecpermtest.coeff(ipulse));
508 if (
ratio < minratio) {
510 minratioidx = ipulse;
527 if (iter % 10 == 0) {
550 const bool hasTimeInfo,
555 assert(hcalTimeSlewDelay);
580 const unsigned int ) {
585 if (elem.first == pulseShapeId) {
594 auto p = std::make_shared<FitterFuncs::PulseShapeFunctor>(
628 float recoEnergy, soiPlus1Energy, recoTime,
chi2;
630 phase1Apply(channelData, recoEnergy, soiPlus1Energy, recoTime, use3,
chi2);
633 mdi.
soi = channelData.
soi();
644 for (
unsigned int iTS = 0; iTS < channelData.
nSamples(); ++iTS) {
673 mdi.
count[iTS] = iTS;
694 using namespace Eigen;
697 Matrix<float, 10, 10>
temp = mat;
698 outvec.head<10>() =
temp.ldlt().solve(invec.head<10>());
701 Matrix<float, 9, 9>
temp = mat.topLeftCorner<9, 9>();
702 outvec.head<9>() =
temp.ldlt().solve(invec.head<9>());
705 Matrix<float, 8, 8>
temp = mat.topLeftCorner<8, 8>();
706 outvec.head<8>() =
temp.ldlt().solve(invec.head<8>());
709 Matrix<float, 7, 7>
temp = mat.topLeftCorner<7, 7>();
710 outvec.head<7>() =
temp.ldlt().solve(invec.head<7>());
713 Matrix<float, 6, 6>
temp = mat.topLeftCorner<6, 6>();
714 outvec.head<6>() =
temp.ldlt().solve(invec.head<6>());
717 Matrix<float, 5, 5>
temp = mat.topLeftCorner<5, 5>();
718 outvec.head<5>() =
temp.ldlt().solve(invec.head<5>());
721 Matrix<float, 4, 4>
temp = mat.topLeftCorner<4, 4>();
722 outvec.head<4>() =
temp.ldlt().solve(invec.head<4>());
725 Matrix<float, 3, 3>
temp = mat.topLeftCorner<3, 3>();
726 outvec.head<3>() =
temp.ldlt().solve(invec.head<3>());
729 Matrix<float, 2, 2>
temp = mat.topLeftCorner<2, 2>();
730 outvec.head<2>() =
temp.ldlt().solve(invec.head<2>());
733 Matrix<float, 1, 1>
temp = mat.topLeftCorner<1, 1>();
734 outvec.head<1>() =
temp.ldlt().solve(invec.head<1>());
738 <<
"Weird number of pulses encountered in Mahi, module is configured incorrectly!";
constexpr double noisecorr() const
constexpr double fcByPE() const
Eigen::Matrix< double, SampleVectorSize, Eigen::Dynamic, 0, SampleVectorSize, PulseVectorSize > SamplePulseMatrix
void nnlsUnconstrainParameter(Index idxp) const
float thEnergeticPulsesFC_
float ootPulse[7][MaxSVSize]
SamplePulseMatrix invcovp
HcalTimeSlew::BiasSetting slewFlavor_
constexpr float tsDFcPerADC(const unsigned ts) const
constexpr double tsRawCharge(const unsigned ts) const
void resetWorkspace() const
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
MahiNnlsWorkspace nnlsWork_
void nnlsConstrainParameter(Index minratioidx) const
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
constexpr float tsRiseTime(const unsigned ts) const
void singlePulseShapeFuncMahi(const float *x)
static constexpr int pedestalBX_
std::array< SampleMatrix, MaxPVSize > pulseCovArray
SampleDecompLLT covDecomp
void getPulseShape(std::array< double, hcal::constants::maxSamples > &fillPulseShape)
constexpr double tsPedestalWidth(const unsigned ts) 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]
void onePulseMinimize() const
SamplePulseMatrix pulseDerivMat
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &soiPlusOneEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
float calculateChiSq() const
bool calculateArrivalTime_
float calculateArrivalTime(const unsigned int iBX) const
float inPedestal[MaxSVSize]
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 solveSubmatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned nP) const
const float minimize() const
void phase1Debug(const HBHEChannelInfo &channelData, MahiDebugInfo &mdi) const
constexpr double tsGain(const unsigned ts) const
Abs< T >::type abs(const T &t)
constexpr unsigned soi() const
std::vector< int > activeBXs_
const Shape & getShape(int shapeType) const
static constexpr float timeLimit_
float ccTime(const float itQ) const
void setPulseShapeTemplate(int pulseShapeId, const HcalPulseShapes &ps, bool hasTimeInfo, const HcalTimeSlew *hcalTimeSlewDelay, unsigned int nSamples, const float gain)
void resetPulseShapeTemplate(int pulseShapeId, const HcalPulseShapes &ps, unsigned int nSamples)
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
void updateCov(const SampleMatrix &invCovMat) const
SamplePulseMatrix pulseMat
void doFit(std::array< float, 4 > &correctedOutput, const int nbx) const
constexpr bool hasTimeInfo() const
constexpr unsigned nSamples() const
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
float inNoisePhoto[MaxSVSize]
constexpr double tsPedestal(const unsigned ts) const
const HcalTimeSlew * hcalTimeSlewDelay_
void updatePulseShape(const float itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv, FullSampleMatrix &pulseCov) const
constexpr float DEFAULT_ccTIME
void setParameters(bool iDynamicPed, double iTS4Thresh, double chiSqSwitch, bool iApplyTimeSlew, HcalTimeSlew::BiasSetting slewFlavor, bool iCalculateArrivalTime, int iTimeAlgo, double iThEnergeticPulses, double iMeanTime, double iTimeSigmaHPD, double iTimeSigmaSiPM, const std::vector< int > &iActiveBXs, int iNMaxItersMin, int iNMaxItersNNLS, double iDeltaChiSqThresh, double iNnlsThresh)
FitterFuncs::PulseShapeFunctor * psfPtr_
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix
std::vector< ShapeWithId > knownPulseShapes_
__host__ __device__ V V wmax