Belle II Software release-09-00-00
CDCDedxDatabaseImporter.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// DEDX
10#include <cdc/dbobjects/CDCDedxDatabaseImporter.h>
11#include <cdc/dbobjects/CDCDedxScaleFactor.h>
12#include <cdc/dbobjects/CDCDedxHadronCor.h>
13#include <cdc/dbobjects/CDCDedxMeanPars.h>
14#include <cdc/dbobjects/CDCDedxSigmaPars.h>
15
16// FRAMEWORK
17#include <framework/logging/Logger.h>
18#include <framework/database/IntervalOfValidity.h>
19#include <framework/database/Database.h>
20
21// ROOT
22#include <TFile.h>
23#include <TH1F.h>
24#include <TKey.h>
25#include <string>
26#include <vector>
27#include <TClonesArray.h>
28
29// NAMESPACES
30using namespace Belle2;
31
32CDCDedxDatabaseImporter::CDCDedxDatabaseImporter(std::string inputFileName, const std::string& name)
33{
34 m_inputFileNames.push_back(inputFileName);
35 m_name = name;
36}
37
39{
40
41 TClonesArray scaleFactor("Belle2::CDCDedxScaleFactor");
42 new (scaleFactor[0]) CDCDedxScaleFactor(scale);
43
44 IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
45 Database::Instance().storeData(m_name, scaleFactor[0], iov);
46}
47
49{
50
51 TClonesArray hadronCorrection("Belle2::CDCDedxHadronCor");
52
53 TH1F* parhist = 0;
54 int nFiles = 0;
55
56 for (const std::string& inputFile : m_inputFileNames) {
57
58 TFile* f = TFile::Open(inputFile.c_str(), "READ");
59
60 TIter next(f->GetListOfKeys());
61 TKey* key;
62 while ((key = (TKey*) next())) {
63
64 std::string histconstants = key->GetName();
65
66 if (histconstants.compare("CDCDedxHadronCor") == 0) {
67 parhist = (TH1F*)f->Get(histconstants.c_str());
68 B2INFO("Key name matches: " << histconstants);
69 }
70
71 else {
72 B2WARNING("Key name does not match: " << histconstants);
73 continue;
74 }
75 }
76
77 nFiles++;
78 }
79
80 if (nFiles != 1) { B2FATAL("Sorry, you must only import one file at a time for now!"); }
81
82 // loop over the histogram to fill the TClonesArray
83 if (!parhist) B2FATAL("None of the input files contains the histogram called 'CDCDedxHadronCor'!");
84 short version = parhist->GetBinContent(1);
85 std::vector<double> hadroncor;
86 for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
87 hadroncor.push_back(parhist->GetBinContent(bin));
88 }
89 new (hadronCorrection[0]) CDCDedxHadronCor(version, hadroncor);
90
91 IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
92 Database::Instance().storeData(m_name, hadronCorrection[0], iov);
93}
94
96{
97
98 TClonesArray meanParameters("Belle2::CDCDedxMeanPars");
99
100 TH1F* parhist = 0;
101 int nFiles = 0;
102
103 for (const std::string& inputFile : m_inputFileNames) {
104
105 TFile* f = TFile::Open(inputFile.c_str(), "READ");
106
107 TIter next(f->GetListOfKeys());
108 TKey* key;
109 while ((key = (TKey*) next())) {
110
111 std::string histconstants = key->GetName();
112
113 if (histconstants.compare("CDCDedxMeanPars") == 0) {
114 parhist = (TH1F*)f->Get(histconstants.c_str());
115 B2INFO("Key name matches: " << histconstants);
116 }
117
118 else {
119 B2WARNING("Key name does not match: " << histconstants);
120 continue;
121 }
122 }
123
124 nFiles++;
125 }
126
127 if (nFiles != 1) { B2FATAL("Sorry, you must only import one file at a time for now!"); }
128
129 // loop over the histogram to fill the TClonesArray
130 if (!parhist) B2FATAL("None of the input files contains the histogram called 'CDCDedxMeanPars'!");
131 short version = parhist->GetBinContent(1);
132 std::vector<double> meanpars;
133 for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
134 meanpars.push_back(parhist->GetBinContent(bin));
135 }
136 new (meanParameters[0]) CDCDedxMeanPars(version, meanpars);
137
138 IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
139 Database::Instance().storeData(m_name, meanParameters[0], iov);
140}
141
143{
144
145 TClonesArray sigmaParameters("Belle2::CDCDedxSigmaPars");
146
147 TH1F* parhist = 0;
148 int nFiles = 0;
149
150 for (const std::string& inputFile : m_inputFileNames) {
151
152 TFile* f = TFile::Open(inputFile.c_str(), "READ");
153
154 TIter next(f->GetListOfKeys());
155 TKey* key;
156 while ((key = (TKey*) next())) {
157
158 std::string histconstants = key->GetName();
159
160 if (histconstants.compare("CDCDedxSigmaPars") == 0) {
161 parhist = (TH1F*)f->Get(histconstants.c_str());
162 B2INFO("Key name matches: " << histconstants);
163 }
164
165 else {
166 B2WARNING("Key name does not match: " << histconstants);
167 continue;
168 }
169 }
170
171 nFiles++;
172 }
173
174 if (nFiles != 1) { B2FATAL("Sorry, you must only import one file at a time for now!"); }
175
176 // loop over the histogram to fill the TClonesArray
177 if (!parhist) B2FATAL("None of the input files contains the histogram called 'CDCDedxSigmaPars'!");
178 short version = parhist->GetBinContent(1);
179 std::vector<double> sigmapars;
180 for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
181 sigmapars.push_back(parhist->GetBinContent(bin));
182 }
183 new (sigmaParameters[0]) CDCDedxSigmaPars(version, sigmapars);
184
185 IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
186 Database::Instance().storeData(m_name, sigmaParameters[0], iov);
187}
void importScaleFactor(double scale)
Import a scale factor to make electron dE/dx ~ 1.
void importHadronCorrection()
Import parameters for the hadron correction.
void importSigmaParameters()
Import predicted resolution parameters to the database.
std::vector< std::string > m_inputFileNames
Name of input ROOT files.
CDCDedxDatabaseImporter(std::string inputFileName, const std::string &m_name)
Constructor.
void importMeanParameters()
Import predicted mean parameters to the database.
std::string m_name
Name of database ROOT file.
dE/dx hadron saturation parameterization constants
dE/dx mean (curve versus beta-gamma) parameterization constants
dE/dx run gain calibration constants
dE/dx sigma (versus beta-gamma) parameterization constants
A class that describes the interval of experiments/runs for which an object in the database is valid.
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:42
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
Definition: Database.cc:141
Abstract base class for different kinds of events.