Belle II Software  release-08-00-05
eclAutocovarianceCalibrationC2Algorithm.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/eclAutocovarianceCalibrationC2Algorithm.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 <TH1D.h>
20 #include <TDirectory.h>
21 
22 using namespace Belle2;
23 using namespace ECL;
24 
27  CalibrationAlgorithm("eclAutocovarianceCalibrationC2Collector")
28 {
30  "Determine baseline for waveforms to be used in computing the covariance matrix"
31  );
32 }
33 
35 {
38  auto m_BaselineVsCrysID = getObjectPtr<TH1D>("m_BaselineVsCrysID");
39  auto m_CounterVsCrysID = getObjectPtr<TH1D>("m_CounterVsCrysID");
40 
41  std::vector<float> cryIDs;
42  std::vector<float> baselines;
43  std::vector<float> baselinesError;
44 
45  for (int crysID = 0; crysID < ECLElementNumbers::c_NCrystals; crysID++) {
46 
47  double totalCounts = m_CounterVsCrysID->GetBinContent(m_CounterVsCrysID->GetBin(crysID + 1));
48 
49  if (totalCounts < m_TotalCountsThreshold) {
50  B2INFO("eclAutocovarianceCalibrationC2Algorithm: warning total entries for cell ID " << crysID + 1 << " is only: " << totalCounts <<
51  " Requirement is m_TotalCountsThreshold: " << m_TotalCountsThreshold);
53  return c_NotEnoughData;
54  }
55 
56  double baseline = m_BaselineVsCrysID->GetBinContent(m_BaselineVsCrysID->GetBin(crysID + 1));;
57  baseline /= float(m_numberofADCPoints);
58  baseline /= totalCounts;
59 
60  B2INFO("crysID " << crysID << " baseline: " << baseline);
61 
62  cryIDs.push_back(crysID);
63  baselines.push_back(baseline);
64  baselinesError.push_back(0);
65 
66  B2INFO("eclAutocovarianceCalibrationC2Algorithm crysID baseline totalCounts " << crysID << " " << baseline << " " << totalCounts);
67 
68  }
69 
70  auto gBaselineVsCrysID = new TGraph(cryIDs.size(), cryIDs.data(), baselines.data());
71  gBaselineVsCrysID->SetName("gBaselineVsCrysID");
72 
74  TString fName = m_outputName;
75  TDirectory::TContext context;
76  TFile* histfile = new TFile(fName, "recreate");
77  histfile->cd();
78  m_BaselineVsCrysID->Write();
79  gBaselineVsCrysID->Write();
80  histfile->Close();
81  delete histfile;
82 
84  ECLCrystalCalib* PPThreshold = new ECLCrystalCalib();
85  PPThreshold->setCalibVector(baselines, baselinesError);
86  saveCalibration(PPThreshold, "ECLAutocovarianceCalibrationC2Baseline");
87 
88  return c_OK;
89 }
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.