10#include <ecl/calibration/eclAutocovarianceCalibrationC3Algorithm.h>
13#include <ecl/dataobjects/ECLElementNumbers.h>
14#include <ecl/dbobjects/ECLAutoCovariance.h>
20#include"TMatrixDSym.h"
21#include"TDecompChol.h"
31 "Computes the covariance matrix for each crystal"
43 std::vector<double> cryIDs;
44 std::vector<double> noiseMatrix00Vector;
45 std::vector<double> autoCov00Vector;
46 std::vector<double> totalCountsVector;
47 std::vector<double> invertAttempts;
51 auto CovarianceMatrixInfoVsCrysID = getObjectPtr<TH2F>(
"CovarianceMatrixInfoVsCrysID");
59 double totalCounts = CovarianceMatrixInfoVsCrysID->GetBinContent(CovarianceMatrixInfoVsCrysID->GetBin(ID + 1,
63 B2INFO(
"eclAutocovarianceCalibrationC3Algorithm: warning total entries for cell ID " << ID + 1 <<
" is only: " << totalCounts <<
69 TMatrixDSym NoiseMatrix;
73 int index = abs(i - j);
74 NoiseMatrix(i, j) = double(CovarianceMatrixInfoVsCrysID->GetBinContent(CovarianceMatrixInfoVsCrysID->GetBin(ID + 1,
82 NoiseMatrixReduced(i, j) = (NoiseMatrix(0, abs(i - j)));
86 bool invert_successful = 0;
87 int invert_attempt = 0;
91 while (invert_successful == 0) {
99 NoiseMatrix_check(i, j) = buf[abs(i - j)];
103 TDecompChol dc(NoiseMatrix_check);
104 invert_successful = dc.Invert(NoiseMatrix_check);
105 if (invert_successful == 0) {
107 if (invert_attempt > 4) {
108 B2INFO(
"eclAutocovarianceCalibrationC3Algorithm iD " << ID <<
" invert_attempt limit reached " << invert_attempt);
109 B2INFO(
"eclAutocovarianceCalibrationC3Algorithm setting m_u2 to zero");
112 if (invert_attempt > 100) {
113 B2INFO(
"eclAutocovarianceCalibrationC3Algorithm unable to invert!");
117 B2INFO(
"eclAutocovarianceCalibrationC3Algorithm iD " << ID <<
" invert_attempt " << invert_attempt);
119 for (
int i = 0; i <
m_numberofADCPoints; i++) B2INFO(
"old[" << i <<
"] = " << tempAutoCov[i]);
121 for (
int i = 0; i <
m_numberofADCPoints; i++) B2INFO(
"new[" << i <<
"] = " << tempAutoCov[i]);
124 noiseMatrix00Vector.push_back(NoiseMatrix_check(0, 0));
129 cryIDs.push_back(ID + 1);
130 autoCov00Vector.push_back(tempAutoCov[0]);
131 totalCountsVector.push_back(totalCounts);
132 invertAttempts.push_back(invert_attempt);
140 auto gautoCov00Vector =
new TGraph(cryIDs.size(), cryIDs.data(), autoCov00Vector.data());
141 gautoCov00Vector->SetName(
"gautoCov00Vector");
142 gautoCov00Vector->SetMarkerStyle(20);
143 auto gnoiseMatrix00Vector =
new TGraph(cryIDs.size(), cryIDs.data(), noiseMatrix00Vector.data());
144 gnoiseMatrix00Vector->SetName(
"gnoiseMatrix00Vector");
145 gnoiseMatrix00Vector->SetMarkerStyle(20);
146 auto gtotalCountsVector =
new TGraph(cryIDs.size(), cryIDs.data(), totalCountsVector.data());
147 gtotalCountsVector->SetName(
"gtotalCountsVector");
148 gtotalCountsVector->SetMarkerStyle(20);
149 auto ginvertAttempts =
new TGraph(cryIDs.size(), cryIDs.data(), invertAttempts.data());
150 ginvertAttempts->SetName(
"ginvertAttempts");
151 ginvertAttempts->SetMarkerStyle(20);
155 TDirectory::TContext context;
156 TFile* histfile =
new TFile(fName,
"recreate");
158 gautoCov00Vector->Write();
159 gnoiseMatrix00Vector->Write();
160 gtotalCountsVector->Write();
161 ginvertAttempts->Write();
Base class for calibration algorithms.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
EResult
The result of calibration.
@ c_OK
Finished successfully =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
Covariance matrices for offline ECL waveform fit.
void getAutoCovariance(const int cellID, double acov[31]) const
Get auto covariance for a channel.
void setAutoCovariance(const int cellID, const double acov[31])
Set auto covariance for a channel.
eclAutocovarianceCalibrationC3Algorithm()
..Constructor
double m_u2
Regularization Function Parameter 2.
double m_u0
Regularization Function Parameter 0.
std::string m_outputName
file name for histogram output
double m_u1
Regularization Function Parameter 1.
static constexpr int m_numberofADCPoints
length of ECLDsp waveform
int m_TotalCountsThreshold
min number of counts needed to compute calibration
virtual EResult calibrate() override
..Run algorithm on events
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.