Belle II Software  release-05-01-25
CDCDedxDatabaseImporter.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jake Bennett *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 // DEDX
12 #include <reconstruction/dbobjects/CDCDedxDatabaseImporter.h>
13 #include <reconstruction/dbobjects/CDCDedxScaleFactor.h>
14 #include <reconstruction/dbobjects/CDCDedxHadronCor.h>
15 #include <reconstruction/dbobjects/CDCDedxMeanPars.h>
16 #include <reconstruction/dbobjects/CDCDedxSigmaPars.h>
17 #include <reconstruction/dbobjects/DedxPDFs.h>
18 
19 // FRAMEWORK
20 #include <framework/logging/Logger.h>
21 #include <framework/database/IntervalOfValidity.h>
22 #include <framework/database/Database.h>
23 
24 // ROOT
25 #include <TFile.h>
26 #include <TH1F.h>
27 #include <TKey.h>
28 #include <string>
29 #include <vector>
30 #include <TClonesArray.h>
31 
32 // NAMESPACES
33 using namespace Belle2;
34 
35 CDCDedxDatabaseImporter::CDCDedxDatabaseImporter(std::string inputFileName, const std::string& name)
36 {
37  m_inputFileNames.push_back(inputFileName);
38  m_name = name;
39 }
40 
42 {
43  TClonesArray dedxPDFs("Belle2::DedxPDFs");
44  TFile* infile = TFile::Open(m_inputFileNames[0].c_str(), "READ");
45  new(dedxPDFs[0]) DedxPDFs(infile);
46 
47  IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
48  Database::Instance().storeData(m_name, dedxPDFs[0], iov);
49 }
50 
52 {
53 
54  TClonesArray scaleFactor("Belle2::CDCDedxScaleFactor");
55  new(scaleFactor[0]) CDCDedxScaleFactor(scale);
56 
57  IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
58  Database::Instance().storeData(m_name, scaleFactor[0], iov);
59 }
60 
62 {
63 
64  TClonesArray hadronCorrection("Belle2::CDCDedxHadronCor");
65 
66  TH1F* parhist = 0;
67  int nFiles = 0;
68 
69  for (const std::string& inputFile : m_inputFileNames) {
70 
71  TFile* f = TFile::Open(inputFile.c_str(), "READ");
72 
73  TIter next(f->GetListOfKeys());
74  TKey* key;
75  while ((key = (TKey*) next())) {
76 
77  std::string histconstants = key->GetName();
78 
79  if (histconstants.compare("CDCDedxHadronCor") == 0) {
80  parhist = (TH1F*)f->Get(histconstants.c_str());
81  B2INFO("Key name matches: " << histconstants);
82  }
83 
84  else {
85  B2WARNING("Key name does not match: " << histconstants);
86  continue;
87  }
88  }
89 
90  nFiles++;
91  }
92 
93  if (nFiles != 1) { B2FATAL("Sorry, you must only import one file at a time for now!"); }
94 
95  // loop over the histogram to fill the TClonesArray
96  short version = parhist->GetBinContent(1);
97  std::vector<double> hadroncor;
98  for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
99  hadroncor.push_back(parhist->GetBinContent(bin));
100  }
101  new(hadronCorrection[0]) CDCDedxHadronCor(version, hadroncor);
102 
103  IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
104  Database::Instance().storeData(m_name, hadronCorrection[0], iov);
105 }
106 
108 {
109 
110  TClonesArray meanParameters("Belle2::CDCDedxMeanPars");
111 
112  TH1F* parhist = 0;
113  int nFiles = 0;
114 
115  for (const std::string& inputFile : m_inputFileNames) {
116 
117  TFile* f = TFile::Open(inputFile.c_str(), "READ");
118 
119  TIter next(f->GetListOfKeys());
120  TKey* key;
121  while ((key = (TKey*) next())) {
122 
123  std::string histconstants = key->GetName();
124 
125  if (histconstants.compare("CDCDedxMeanPars") == 0) {
126  parhist = (TH1F*)f->Get(histconstants.c_str());
127  B2INFO("Key name matches: " << histconstants);
128  }
129 
130  else {
131  B2WARNING("Key name does not match: " << histconstants);
132  continue;
133  }
134  }
135 
136  nFiles++;
137  }
138 
139  if (nFiles != 1) { B2FATAL("Sorry, you must only import one file at a time for now!"); }
140 
141  // loop over the histogram to fill the TClonesArray
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  short version = parhist->GetBinContent(1);
189  std::vector<double> sigmapars;
190  for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
191  sigmapars.push_back(parhist->GetBinContent(bin));
192  }
193  new(sigmaParameters[0]) CDCDedxSigmaPars(version, sigmapars);
194 
195  IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
196  Database::Instance().storeData(m_name, sigmaParameters[0], iov);
197 }
Belle2::IntervalOfValidity
A class that describes the interval of experiments/runs for which an object in the database is valid.
Definition: IntervalOfValidity.h:35
Belle2::CDCDedxDatabaseImporter::importMeanParameters
void importMeanParameters()
Import predicted mean parameters to the database.
Definition: CDCDedxDatabaseImporter.cc:107
Belle2::CDCDedxMeanPars
dE/dx mean (curve versus beta-gamma) parameterization constants
Definition: CDCDedxMeanPars.h:34
Belle2::CDCDedxDatabaseImporter::importScaleFactor
void importScaleFactor(double scale)
Import a scale factor to make electron dE/dx ~ 1.
Definition: CDCDedxDatabaseImporter.cc:51
Belle2::CDCDedxSigmaPars
dE/dx sigma (versus beta-gamma) parameterization constants
Definition: CDCDedxSigmaPars.h:34
Belle2::Database::storeData
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
Definition: Database.cc:152
Belle2::CDCDedxDatabaseImporter::importSigmaParameters
void importSigmaParameters()
Import predicted resolution parameters to the database.
Definition: CDCDedxDatabaseImporter.cc:153
Belle2::CDCDedxDatabaseImporter::CDCDedxDatabaseImporter
CDCDedxDatabaseImporter(std::string inputFileName, const std::string &m_name)
Constructor.
Definition: CDCDedxDatabaseImporter.cc:35
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DedxPDFs
dE/dx wire gain calibration constants
Definition: DedxPDFs.h:37
Belle2::CDCDedxDatabaseImporter::importHadronCorrection
void importHadronCorrection()
Import parameters for the hadron correction.
Definition: CDCDedxDatabaseImporter.cc:61
Belle2::CDCDedxScaleFactor
dE/dx run gain calibration constants
Definition: CDCDedxScaleFactor.h:33
Belle2::CDCDedxDatabaseImporter::m_inputFileNames
std::vector< std::string > m_inputFileNames
Name of input ROOT files.
Definition: CDCDedxDatabaseImporter.h:74
Belle2::CDCDedxDatabaseImporter::m_name
std::string m_name
Name of database ROOT file.
Definition: CDCDedxDatabaseImporter.h:75
Belle2::CDCDedxHadronCor
dE/dx hadron saturation parameterization constants
Definition: CDCDedxHadronCor.h:34
Belle2::Database::Instance
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:54
Belle2::CDCDedxDatabaseImporter::importPDFs
void importPDFs()
Import a set of dedx:momentum pdfs.
Definition: CDCDedxDatabaseImporter.cc:41