Belle II Software  release-08-01-10
eclWaveformTemplateCalibrationC1Algorithm.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/eclWaveformTemplateCalibrationC1Algorithm.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 
21 using namespace std;
22 using namespace Belle2;
23 using namespace ECL;
24 
26 eclWaveformTemplateCalibrationC1Algorithm::eclWaveformTemplateCalibrationC1Algorithm():
27  CalibrationAlgorithm("eclWaveformTemplateCalibrationC1Collector")
28 {
30  "Used to determine the baseline noise level of crystals in e+e- --> gamma gamma"
31  );
32 }
33 
35 {
36 
38  gROOT->SetBatch();
39 
42  auto maxResvsCrysID = getObjectPtr<TH2F>("maxResvsCrysID");
43 
44  std::vector<float> cellIDs;
45  std::vector<float> maxResiduals;
46  std::vector<float> Counts;
47  std::vector<float> maxResidualsError(ECLElementNumbers::c_NCrystals);
48 
49  for (int id = 0; id < ECLElementNumbers::c_NCrystals; id++) {
50 
51  TH1F* hMaxResx = (TH1F*)maxResvsCrysID->ProjectionY("hMaxResx", id + 1, id + 1);
52 
53  int Total = hMaxResx->GetEntries();
54 
55  if (Total < m_minWaveformLimit) {
56  B2INFO("eclWaveformTemplateCalibrationC1Algorithm: warning total entries for cell ID " << id + 1 << " is only: " << Total <<
57  " Requirement is : " << m_minWaveformLimit);
59  return c_NotEnoughData;
60  }
61 
62  int subTotal = 0;
63  float fraction = 0.0;
64  int counter = 0;
65 
66  float fractionLimit = m_fractionLimitGeneral;
67 
69  if (Total < m_LowCountThreshold) fractionLimit = m_fractionLimitLowCounts;
70 
71 
73  while (fraction < fractionLimit) {
74  subTotal += hMaxResx->GetBinContent(counter);
75  fraction = ((float)subTotal) / ((float)Total);
76  counter++;
77  }
78 
79  cellIDs.push_back(id + 1);
80  maxResiduals.push_back(hMaxResx->GetBinLowEdge(counter + 1));
81  Counts.push_back(Total);
82 
83  B2INFO("eclWaveformTemplateCalibrationC1Algorithm: id counter fraction Total maxResiduals[id]" << id << " " << counter << " " <<
84  fraction <<
85  " " << Total << " " << maxResiduals[id]);
86 
87  hMaxResx->Delete();
88  }
89 
91  ECLCrystalCalib* PPThreshold = new ECLCrystalCalib();
92  PPThreshold->setCalibVector(maxResiduals, maxResidualsError);
93  saveCalibration(PPThreshold, "eclWaveformTemplateCalibrationC1MaxResLimit");
94  B2INFO("eclWaveformTemplateCalibrationC1Algorithm: successfully stored ECLAutocovarianceCalibrationC1Threshold constants");
95 
97  auto gmaxResvsCellID = new TGraph(cellIDs.size(), cellIDs.data(), maxResiduals.data());
98  gmaxResvsCellID->SetName("gmaxResvsCellID");
99  auto gTotalvsCellID = new TGraph(cellIDs.size(), cellIDs.data(), Counts.data());
100  gTotalvsCellID->SetName("gTotalvsCellID");
101 
102  TString fName = m_outputName;
103  TFile* histfile = new TFile(fName, "recreate");
104  histfile->cd();
105  gmaxResvsCellID->Write();
106  gTotalvsCellID->Write();
107  histfile->Close();
108  delete histfile;
109 
110  return c_OK;
111 }
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_minWaveformLimit
min number of waveforms required per crystal to be considered low counts
float m_fractionLimitLowCounts
fraction of waveforms used for low count crystals
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.