Belle II Software  release-08-01-10
eclAutocovarianceCalibrationC4Algorithm.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/eclAutocovarianceCalibrationC4Algorithm.h>
11 
12 /* ECL headers. */
13 #include <ecl/dataobjects/ECLElementNumbers.h>
14 
15 /* ROOT headers. */
16 #include <TFile.h>
17 #include <TGraph.h>
18 #include <TH2.h>
19 
20 using namespace Belle2;
21 using namespace ECL;
22 
25  CalibrationAlgorithm("eclAutocovarianceCalibrationC4Collector")
26 {
28  "Perform validation of coveriance matrix calibration"
29  );
30 }
31 
33 {
34 
35 
37  gROOT->SetBatch();
38 
41  auto Chi2VsCrysID = getObjectPtr<TH2F>("Chi2VsCrysID");
42 
43  std::vector<double> cryIDs;
44  std::vector<double> means;
45  std::vector<double> RMSs;
46  std::vector<double> counts;
47 
48  for (int crysID = 0; crysID < ECLElementNumbers::c_NCrystals; crysID++) {
49 
50  TH1F* hChi2 = (TH1F*)Chi2VsCrysID->ProjectionY("hChi2", crysID + 1, crysID + 1);
51 
52  int totalCounts = hChi2->GetEntries();
53 
54  if (totalCounts < m_minEntries) {
55  B2INFO("eclAutocovarianceCalibrationC4Algorithm: Warning Below Count Limit: crysID totalCounts m_minEntries: " << crysID << " " <<
56  totalCounts << " " << m_minEntries);
57  }
58 
59  float mean = hChi2->GetMean();
60 
61  cryIDs.push_back(crysID + 1);
62  means.push_back(mean);
63  RMSs.push_back(hChi2->GetRMS());
64  counts.push_back(totalCounts);
65 
66  }
67 
69  auto gMeanVsCrysID = new TGraph(cryIDs.size(), cryIDs.data(), means.data());
70  gMeanVsCrysID->SetName("gMeanVsCrysID");
71  gMeanVsCrysID->SetMarkerStyle(20);
72  auto gRMSVsCrysID = new TGraph(cryIDs.size(), cryIDs.data(), RMSs.data());
73  gRMSVsCrysID->SetName("gRMSVsCrysID");
74  gRMSVsCrysID->SetMarkerStyle(20);
75  auto gCountsVsCrysID = new TGraph(cryIDs.size(), cryIDs.data(), counts.data());
76  gCountsVsCrysID->SetName("gCountsVsCrysID");
77  gCountsVsCrysID->SetMarkerStyle(20);
78 
80  TString fName = m_outputName;
81  TDirectory::TContext context;
82  TFile* histfile = new TFile(fName, "recreate");
83  histfile->cd();
84  gMeanVsCrysID->Write();
85  gRMSVsCrysID->Write();
86  gCountsVsCrysID->Write();
87  Chi2VsCrysID->Write();
88  histfile->Close();
89  delete histfile;
90 
91  return c_OK;
92 }
Base class for calibration algorithms.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
EResult
The result of calibration.
@ c_OK
Finished successfuly =0 in Python.
virtual EResult calibrate() override
..Run algorithm on events
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.