Belle II Software development
eclAutocovarianceCalibrationC1Algorithm.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9/* Own header. */
10#include <ecl/calibration/eclAutocovarianceCalibrationC1Algorithm.h>
11
12/* ECL headers. */
13#include <ecl/dataobjects/ECLElementNumbers.h>
14#include <ecl/dbobjects/ECLCrystalCalib.h>
15
16/* ROOT headers. */
17#include <TFile.h>
18#include <TGraph.h>
19#include <TH2F.h>
20
21using namespace Belle2;
22using namespace ECL;
23
26 CalibrationAlgorithm("eclAutocovarianceCalibrationC1Collector")
27{
29 "Determine noise threshold for waveforms to be used in computing the covariance matrix"
30 );
31}
32
34{
35
37 gROOT->SetBatch();
38
41 auto PPVsCrysID = getObjectPtr<TH2F>("PPVsCrysID");
42
43 std::vector<float> cellIDs;
44 std::vector<float> PPamps;
45 std::vector<float> PPampsErrorVector;
46
47 for (int crysID = 0; crysID < ECLElementNumbers::c_NCrystals; crysID++) {
48
49 TH1F* hPP = (TH1F*)PPVsCrysID->ProjectionY("hPP", crysID + 1, crysID + 1);
50
51 int Total = hPP->GetEntries();
52 float fraction = 0.0;
53 int counter = 0;
54
55 if (Total < m_TotalCountsThreshold) {
56 B2INFO("eclAutocovarianceCalibrationC1Algorithm: warning total entries for cell ID " << crysID + 1 << " is only: " << Total <<
57 " Requirement is m_TotalCountsThreshold: " << m_TotalCountsThreshold);
59 return c_NotEnoughData;
60 } else {
61 int subTotal = 0;
62 while (fraction < m_lowestEnergyFraction) {
63 subTotal += hPP->GetBinContent(counter);
64 fraction = ((float)subTotal) / ((float)Total);
65 counter++;
66 }
67 }
68
69 cellIDs.push_back(crysID + 1);
70 PPamps.push_back(counter);
71 PPampsErrorVector.push_back(0);
72
73 B2INFO("eclAutocovarianceCalibrationC1Algorithm: crysID counter fraction Total " << crysID << " " << counter << " " << fraction <<
74 " " << Total);
75
76 }
77
79 auto gPPVsCellID = new TGraph(cellIDs.size(), cellIDs.data(), PPamps.data());
80 gPPVsCellID->SetName("gPPVsCellID");
81
82 TString fName = m_outputName;
83 TDirectory::TContext context;
84 TFile* histfile = new TFile(fName, "recreate");
85 histfile->cd();
86 PPVsCrysID->Write();
87 gPPVsCellID->Write();
88 histfile->Close();
89 delete histfile;
90
93 ECLCrystalCalib* PPThreshold = new ECLCrystalCalib();
94 PPThreshold->setCalibVector(PPamps, PPampsErrorVector);
95 saveCalibration(PPThreshold, "ECLAutocovarianceCalibrationC1Threshold");
96 B2INFO("eclAutocovarianceCalibrationC1Algorithm: successfully stored ECLAutocovarianceCalibrationC1Threshold constants");
97
98 return c_OK;
99}
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 successfuly =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
General DB object to store one calibration number per ECL crystal.
void setCalibVector(const std::vector< float > &CalibConst, const std::vector< float > &CalibConstUnc)
Set vector of constants with uncertainties.
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.