Belle II Software  release-08-01-10
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
31 using namespace Belle2;
32 
33 CDCDedxDatabaseImporter::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  short version = parhist->GetBinContent(1);
95  std::vector<double> hadroncor;
96  for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
97  hadroncor.push_back(parhist->GetBinContent(bin));
98  }
99  new (hadronCorrection[0]) CDCDedxHadronCor(version, hadroncor);
100 
101  IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
102  Database::Instance().storeData(m_name, hadronCorrection[0], iov);
103 }
104 
106 {
107 
108  TClonesArray meanParameters("Belle2::CDCDedxMeanPars");
109 
110  TH1F* parhist = 0;
111  int nFiles = 0;
112 
113  for (const std::string& inputFile : m_inputFileNames) {
114 
115  TFile* f = TFile::Open(inputFile.c_str(), "READ");
116 
117  TIter next(f->GetListOfKeys());
118  TKey* key;
119  while ((key = (TKey*) next())) {
120 
121  std::string histconstants = key->GetName();
122 
123  if (histconstants.compare("CDCDedxMeanPars") == 0) {
124  parhist = (TH1F*)f->Get(histconstants.c_str());
125  B2INFO("Key name matches: " << histconstants);
126  }
127 
128  else {
129  B2WARNING("Key name does not match: " << histconstants);
130  continue;
131  }
132  }
133 
134  nFiles++;
135  }
136 
137  if (nFiles != 1) { B2FATAL("Sorry, you must only import one file at a time for now!"); }
138 
139  // loop over the histogram to fill the TClonesArray
140  short version = parhist->GetBinContent(1);
141  std::vector<double> meanpars;
142  for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
143  meanpars.push_back(parhist->GetBinContent(bin));
144  }
145  new (meanParameters[0]) CDCDedxMeanPars(version, meanpars);
146 
147  IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
148  Database::Instance().storeData(m_name, meanParameters[0], iov);
149 }
150 
152 {
153 
154  TClonesArray sigmaParameters("Belle2::CDCDedxSigmaPars");
155 
156  TH1F* parhist = 0;
157  int nFiles = 0;
158 
159  for (const std::string& inputFile : m_inputFileNames) {
160 
161  TFile* f = TFile::Open(inputFile.c_str(), "READ");
162 
163  TIter next(f->GetListOfKeys());
164  TKey* key;
165  while ((key = (TKey*) next())) {
166 
167  std::string histconstants = key->GetName();
168 
169  if (histconstants.compare("CDCDedxSigmaPars") == 0) {
170  parhist = (TH1F*)f->Get(histconstants.c_str());
171  B2INFO("Key name matches: " << histconstants);
172  }
173 
174  else {
175  B2WARNING("Key name does not match: " << histconstants);
176  continue;
177  }
178  }
179 
180  nFiles++;
181  }
182 
183  if (nFiles != 1) { B2FATAL("Sorry, you must only import one file at a time for now!"); }
184 
185  // loop over the histogram to fill the TClonesArray
186  short version = parhist->GetBinContent(1);
187  std::vector<double> sigmapars;
188  for (int bin = 2; bin <= parhist->GetNbinsX(); ++bin) {
189  sigmapars.push_back(parhist->GetBinContent(bin));
190  }
191  new (sigmaParameters[0]) CDCDedxSigmaPars(version, sigmapars);
192 
193  IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
194  Database::Instance().storeData(m_name, sigmaParameters[0], iov);
195 }
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.