Belle II Software  release-08-01-10
KLMDatabaseImporter.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 <klm/calibration/KLMDatabaseImporter.h>
11 
12 /* Basf2 headers. */
13 #include <framework/database/DBImportObjPtr.h>
14 #include <framework/database/IntervalOfValidity.h>
15 #include <framework/logging/Logger.h>
16 
17 /* ROOT headers. */
18 #include <TFile.h>
19 #include <TTree.h>
20 
21 /* C++ headers. */
22 #include <string>
23 
24 using namespace Belle2;
25 
27 {
28 }
29 
31 {
32 }
33 
34 void KLMDatabaseImporter::setIOV(int experimentLow, int runLow,
35  int experimentHigh, int runHigh)
36 {
37  m_ExperimentLow = experimentLow;
38  m_RunLow = runLow;
39  m_ExperimentHigh = experimentHigh;
40  m_RunHigh = runHigh;
41 }
42 
44  const KLMChannelStatus* channelStatus)
45 {
46  DBImportObjPtr<KLMChannelStatus> channelStatusImport;
47  channelStatusImport.construct(*channelStatus);
50  channelStatusImport.import(iov);
51 }
52 
54  const KLMReconstructionParameters* digitizationParameters)
55 {
57  digPar.construct(*digitizationParameters);
60  digPar.import(iov);
61 }
62 
64  const KLMScintillatorDigitizationParameters* digitizationParameters)
65 {
67  digPar.construct(*digitizationParameters);
70  digPar.import(iov);
71 }
72 
74  const KLMTimeConversion* timeConversion)
75 {
76  DBImportObjPtr<KLMTimeConversion> timeConversionImport;
77  timeConversionImport.construct(*timeConversion);
80  timeConversionImport.import(iov);
81 }
82 
84 {
85  DBImportObjPtr<KLMTimeWindow> timeWindowImport;
86  timeWindowImport.construct(*timeWindow);
89  timeWindowImport.import(iov);
90 }
91 
93  KLMStripEfficiency* stripEfficiency, std::string fileName)
94 {
95  TFile* file = TFile::Open(fileName.c_str(), "r");
96  if (!file) {
97  B2ERROR("KLMDatabaseImporter: calibration file " << fileName << " *** failed to open");
98  } else {
99  TTree* tree = (TTree*)file->Get("tree");
100  if (!tree) {
101  B2ERROR("KLMDatabaseImporter: calibration file " << fileName << " *** no tree named 'tree' found");
102  file->Close();
103  } else {
104  int isBarrel = 0;
105  tree->SetBranchAddress("isBarrel", &isBarrel);
106  int section = 0;
107  tree->SetBranchAddress("isForward", &section);
108  int sector = 0;
109  tree->SetBranchAddress("sector", &sector);
110  int layer = 0;
111  tree->SetBranchAddress("layer", &layer);
112  int plane = 0;
113  tree->SetBranchAddress("plane", &plane);
114  int strip = 0;
115  tree->SetBranchAddress("strip", &strip);
116  float efficiency = 1.;
117  tree->SetBranchAddress("efficiency", &efficiency);
118  float efficiencyError = 0.;
119  tree->SetBranchAddress("efficiencyError", &efficiencyError);
120 
121  for (int i = 0; i < tree->GetEntries(); i++) {
122  tree->GetEntry(i);
123  if (isBarrel)
124  stripEfficiency->setBarrelEfficiency(section, sector, layer, plane, strip, efficiency, efficiencyError);
125  else
126  stripEfficiency->setEndcapEfficiency(section, sector, layer, plane, strip, efficiency, efficiencyError);
127  }
128  }
129  file->Close();
130  }
131 }
132 
134  const KLMStripEfficiency* stripEfficiency)
135 {
136  DBImportObjPtr<KLMStripEfficiency> stripEfficiencyImport;
137  stripEfficiencyImport.construct(*stripEfficiency);
140  stripEfficiencyImport.import(iov);
141 }
142 
144  const BKLMAlignment* bklmAlignment, bool displacement)
145 {
146  std::string payloadName;
147  if (displacement)
148  payloadName = "BKLMDisplacement";
149  else
150  payloadName = "BKLMAlignment";
151  DBImportObjPtr<BKLMAlignment> bklmAlignmentImport(payloadName);
152  bklmAlignmentImport.construct(*bklmAlignment);
155  bklmAlignmentImport.import(iov);
156 }
157 
159  const EKLMAlignment* eklmAlignment, bool displacement)
160 {
161  std::string payloadName;
162  if (displacement)
163  payloadName = "EKLMDisplacement";
164  else
165  payloadName = "EKLMAlignment";
166  DBImportObjPtr<EKLMAlignment> eklmAlignmentImport(payloadName);
167  eklmAlignmentImport.construct(*eklmAlignment);
170  eklmAlignmentImport.import(iov);
171 }
172 
174  const EKLMSegmentAlignment* eklmSegmentAlignment, bool displacement)
175 {
176  std::string payloadName;
177  if (displacement)
178  payloadName = "EKLMSegmentDisplacement";
179  else
180  payloadName = "EKLMSegmentAlignment";
181  DBImportObjPtr<EKLMSegmentAlignment> eklmSegmentAlignmentImport(payloadName);
182  eklmSegmentAlignmentImport.construct(*eklmSegmentAlignment);
185  eklmSegmentAlignmentImport.import(iov);
186 }
187 
189  const BKLMAlignment* bklmAlignment, const EKLMAlignment* eklmAlignment,
190  const EKLMSegmentAlignment* eklmSegmentAlignment, bool displacement)
191 {
192  importBKLMAlignment(bklmAlignment, displacement);
193  importEKLMAlignment(eklmAlignment, displacement);
194  importEKLMSegmentAlignment(eklmSegmentAlignment, displacement);
195 }
Class to store BKLM alignment data in the database.
Definition: BKLMAlignment.h:30
bool import(const IntervalOfValidity &iov)
Import the object to database.
Definition: DBImportBase.cc:36
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
Class to store EKLM alignment data in the database.
Definition: EKLMAlignment.h:30
Class to store EKLM alignment data in the database.
A class that describes the interval of experiments/runs for which an object in the database is valid.
KLM channel status.
void importTimeWindow(KLMTimeWindow *timeWindow)
Import KLM time window parameters.
int m_ExperimentHigh
High experiment.
void importEKLMSegmentAlignment(const EKLMSegmentAlignment *eklmSegmentAlignment, bool displacement=false)
Import EKLM segment alignment.
void importReconstructionParameters(const KLMReconstructionParameters *digitizationParameters)
Import reconstruction parameters.
void importScintillatorDigitizationParameters(const KLMScintillatorDigitizationParameters *digitizationParameters)
Import scintillator simulation parameters.
int m_ExperimentLow
Low experiment.
void importChannelStatus(const KLMChannelStatus *channelStatus)
Import channel status.
void setIOV(int experimentLow, int runLow, int experimentHigh, int runHigh)
Set interval of validity.
void importTimeConversion(const KLMTimeConversion *timeConversion)
Import time conversion parameters.
void importStripEfficiency(const KLMStripEfficiency *stripEfficiency)
Import strip efficiencies.
void importEKLMAlignment(const EKLMAlignment *eklmAlignment, bool displacement=false)
Import EKLM alignment.
void importAlignment(const BKLMAlignment *bklmAlignment, const EKLMAlignment *eklmAlignment, const EKLMSegmentAlignment *eklmSegmentAlignment, bool displacement=false)
Import alignment.
void loadStripEfficiency(KLMStripEfficiency *stripEfficiency, std::string fileName)
Load strip efficiencies.
void importBKLMAlignment(const BKLMAlignment *bklmAlignment, bool displacement=false)
Import BKLM alignment.
Class to store KLM reconstruction parameters in the database.
Class to store KLM scintillator simulation parameters in the database.
DBObject used to store the efficiencies of KLM strips.
KLM time conversion.
DBObject containing KLM time window parameters used in KLMReconstructor module.
Definition: KLMTimeWindow.h:24
Abstract base class for different kinds of events.