Belle II Software development
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 <reconstruction/dbobjects/CDCDedxDatabaseImporter.h>
11#include <reconstruction/dbobjects/CDCDedxScaleFactor.h>
12#include <reconstruction/dbobjects/CDCDedxHadronCor.h>
13#include <reconstruction/dbobjects/CDCDedxMeanPars.h>
14#include <reconstruction/dbobjects/CDCDedxSigmaPars.h>
15#include <reconstruction/dbobjects/DedxPDFs.h>
16
17// FRAMEWORK
18#include <framework/logging/Logger.h>
19#include <framework/database/IntervalOfValidity.h>
20#include <framework/database/Database.h>
21
22// ROOT
23#include <TFile.h>
24#include <TH1F.h>
25#include <TKey.h>
26#include <string>
27#include <vector>
28#include <TClonesArray.h>
29
30// NAMESPACES
31using namespace Belle2;
32
33CDCDedxDatabaseImporter::CDCDedxDatabaseImporter(std::string inputFileName, const std::string& name)
34{
35 m_inputFileNames.push_back(inputFileName);
36 m_name = name;
37}
38
40{
41 TClonesArray dedxPDFs("Belle2::DedxPDFs");
42 TFile* infile = TFile::Open(m_inputFileNames[0].c_str(), "READ");
43 new (dedxPDFs[0]) DedxPDFs(infile);
44
45 IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
46 Database::Instance().storeData(m_name, dedxPDFs[0], iov);
47}
48
50{
51
52 TClonesArray scaleFactor("Belle2::CDCDedxScaleFactor");
53 new (scaleFactor[0]) CDCDedxScaleFactor(scale);
54
55 IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
56 Database::Instance().storeData(m_name, scaleFactor[0], iov);
57}
58
60{
61
62 TClonesArray hadronCorrection("Belle2::CDCDedxHadronCor");
63
64 TH1F* parhist = 0;
65 int nFiles = 0;
66
67 for (const std::string& inputFile : m_inputFileNames) {
68
69 TFile* f = TFile::Open(inputFile.c_str(), "READ");
70
71 TIter next(f->GetListOfKeys());
72 TKey* key;
73 while ((key = (TKey*) next())) {
74
75 std::string histconstants = key->GetName();
76
77 if (histconstants.compare("CDCDedxHadronCor") == 0) {
78 parhist = (TH1F*)f->Get(histconstants.c_str());
79 B2INFO("Key name matches: " << histconstants);
80 }
81
82 else {
83 B2WARNING("Key name does not match: " << histconstants);
84 continue;
85 }
86 }
87
88 nFiles++;
89 }
90
91 if (nFiles != 1) { B2FATAL("Sorry, you must only import one file at a time for now!"); }
92
93 // loop over the histogram to fill the TClonesArray
94 if (!parhist) B2FATAL("None of the input files contains the histogram called 'CDCDedxHadronCor'!");
95 short version = parhist->GetBinContent(1);
96 std::vector<double> hadroncor;
97 for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
98 hadroncor.push_back(parhist->GetBinContent(bin));
99 }
100 new (hadronCorrection[0]) CDCDedxHadronCor(version, hadroncor);
101
102 IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
103 Database::Instance().storeData(m_name, hadronCorrection[0], iov);
104}
105
107{
108
109 TClonesArray meanParameters("Belle2::CDCDedxMeanPars");
110
111 TH1F* parhist = 0;
112 int nFiles = 0;
113
114 for (const std::string& inputFile : m_inputFileNames) {
115
116 TFile* f = TFile::Open(inputFile.c_str(), "READ");
117
118 TIter next(f->GetListOfKeys());
119 TKey* key;
120 while ((key = (TKey*) next())) {
121
122 std::string histconstants = key->GetName();
123
124 if (histconstants.compare("CDCDedxMeanPars") == 0) {
125 parhist = (TH1F*)f->Get(histconstants.c_str());
126 B2INFO("Key name matches: " << histconstants);
127 }
128
129 else {
130 B2WARNING("Key name does not match: " << histconstants);
131 continue;
132 }
133 }
134
135 nFiles++;
136 }
137
138 if (nFiles != 1) { B2FATAL("Sorry, you must only import one file at a time for now!"); }
139
140 // loop over the histogram to fill the TClonesArray
141 if (!parhist) B2FATAL("None of the input files contains the histogram called 'CDCDedxMeanPars'!");
142 short version = parhist->GetBinContent(1);
143 std::vector<double> meanpars;
144 for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
145 meanpars.push_back(parhist->GetBinContent(bin));
146 }
147 new (meanParameters[0]) CDCDedxMeanPars(version, meanpars);
148
149 IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
150 Database::Instance().storeData(m_name, meanParameters[0], iov);
151}
152
154{
155
156 TClonesArray sigmaParameters("Belle2::CDCDedxSigmaPars");
157
158 TH1F* parhist = 0;
159 int nFiles = 0;
160
161 for (const std::string& inputFile : m_inputFileNames) {
162
163 TFile* f = TFile::Open(inputFile.c_str(), "READ");
164
165 TIter next(f->GetListOfKeys());
166 TKey* key;
167 while ((key = (TKey*) next())) {
168
169 std::string histconstants = key->GetName();
170
171 if (histconstants.compare("CDCDedxSigmaPars") == 0) {
172 parhist = (TH1F*)f->Get(histconstants.c_str());
173 B2INFO("Key name matches: " << histconstants);
174 }
175
176 else {
177 B2WARNING("Key name does not match: " << histconstants);
178 continue;
179 }
180 }
181
182 nFiles++;
183 }
184
185 if (nFiles != 1) { B2FATAL("Sorry, you must only import one file at a time for now!"); }
186
187 // loop over the histogram to fill the TClonesArray
188 if (!parhist) B2FATAL("None of the input files contains the histogram called 'CDCDedxSigmaPars'!");
189 short version = parhist->GetBinContent(1);
190 std::vector<double> sigmapars;
191 for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
192 sigmapars.push_back(parhist->GetBinContent(bin));
193 }
194 new (sigmaParameters[0]) CDCDedxSigmaPars(version, sigmapars);
195
196 IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
197 Database::Instance().storeData(m_name, sigmaParameters[0], iov);
198}
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.
void importPDFs()
Import a set of dedx:momentum pdfs.
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
dE/dx wire gain calibration constants
Definition: DedxPDFs.h:27
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.