10 #include <klm/calibration/KLMCalibrationChecker.h>
13 #include <klm/dataobjects/bklm/BKLMElementNumbers.h>
14 #include <klm/dataobjects/eklm/EKLMElementNumbers.h>
15 #include <klm/dataobjects/KLMChannelIndex.h>
16 #include <klm/dbobjects/bklm/BKLMAlignment.h>
17 #include <klm/dbobjects/eklm/EKLMAlignment.h>
18 #include <klm/dbobjects/eklm/EKLMSegmentAlignment.h>
19 #include <klm/dbobjects/KLMStripEfficiency.h>
22 #include <framework/database/Database.h>
23 #include <framework/database/DBStore.h>
24 #include <framework/database/Configuration.h>
25 #include <framework/datastore/DataStore.h>
75 B2FATAL(
"Setting both testing payload and Global Tag or setting no one of them.");
100 if (!bklmAlignment.isValid() ||
101 !eklmAlignment.isValid() ||
102 !eklmSegmentAlignment.isValid() ||
103 !bklmAlignmentErrors.
isValid() ||
104 !eklmAlignmentErrors.
isValid() ||
105 !eklmSegmentAlignmentErrors.
isValid() ||
106 !bklmAlignmentCorrections.
isValid() ||
107 !eklmAlignmentCorrections.
isValid() ||
108 !eklmSegmentAlignmentCorrections.
isValid())
109 B2FATAL(
"Alignment data are not valid.");
122 int section, sector, layer, plane, segment, param;
123 float value, correction, error;
126 TTree* bklmModuleTree =
new TTree(
"bklm_module",
127 "BKLM module alignment data.");
128 bklmModuleTree->Branch(
"experiment", &
m_experiment,
"experiment/I");
129 bklmModuleTree->Branch(
"run", &
m_run,
"run/I");
130 bklmModuleTree->Branch(
"section", §ion,
"section/I");
131 bklmModuleTree->Branch(
"sector", §or,
"sector/I");
132 bklmModuleTree->Branch(
"layer", &layer,
"layer/I");
133 bklmModuleTree->Branch(
"param", ¶m,
"param/I");
134 bklmModuleTree->Branch(
"value", &value,
"value/F");
135 bklmModuleTree->Branch(
"correction", &correction,
"correction/F");
136 bklmModuleTree->Branch(
"error", &error,
"error/F");
137 TTree* eklmModuleTree =
new TTree(
"eklm_module",
138 "EKLM module alignment data.");
139 eklmModuleTree->Branch(
"experiment", &
m_experiment,
"experiment/I");
140 eklmModuleTree->Branch(
"run", &
m_run,
"run/I");
141 eklmModuleTree->Branch(
"section", §ion,
"section/I");
142 eklmModuleTree->Branch(
"sector", §or,
"sector/I");
143 eklmModuleTree->Branch(
"layer", &layer,
"layer/I");
144 eklmModuleTree->Branch(
"param", ¶m,
"param/I");
145 eklmModuleTree->Branch(
"value", &value,
"value/F");
146 eklmModuleTree->Branch(
"correction", &correction,
"correction/F");
147 eklmModuleTree->Branch(
"error", &error,
"error/F");
148 TTree* eklmSegmentTree =
new TTree(
"eklm_segment",
149 "EKLM segment alignment data.");
150 eklmSegmentTree->Branch(
"experiment", &
m_experiment,
"experiment/I");
151 eklmSegmentTree->Branch(
"run", &
m_run,
"run/I");
152 eklmSegmentTree->Branch(
"section", §ion,
"section/I");
153 eklmSegmentTree->Branch(
"sector", §or,
"sector/I");
154 eklmSegmentTree->Branch(
"layer", &layer,
"layer/I");
155 eklmSegmentTree->Branch(
"plane", &plane,
"plane/I");
156 eklmSegmentTree->Branch(
"segment", &segment,
"segment/I");
157 eklmSegmentTree->Branch(
"param", ¶m,
"param/I");
158 eklmSegmentTree->Branch(
"value", &value,
"value/F");
159 eklmSegmentTree->Branch(
"correction", &correction,
"correction/F");
160 eklmSegmentTree->Branch(
"error", &error,
"error/F");
167 alignment = bklmAlignment->getModuleAlignment(module);
168 alignmentError = bklmAlignmentErrors->getModuleAlignment(module);
169 alignmentCorrection =
170 bklmAlignmentCorrections->getModuleAlignment(module);
172 alignment = eklmAlignment->getModuleAlignment(module);
173 alignmentError = eklmAlignmentErrors->getModuleAlignment(module);
174 alignmentCorrection =
175 eklmAlignmentCorrections->getModuleAlignment(module);
177 if (alignment ==
nullptr)
178 B2FATAL(
"Incomplete KLM alignment data.");
179 if ((alignmentError ==
nullptr) && (alignmentCorrection ==
nullptr)) {
180 B2WARNING(
"Alignment is not determined for KLM module."
181 <<
LogVar(
"Module", module));
182 alignmentError = &zeroAlignment;
183 alignmentCorrection = &zeroAlignment;
184 }
else if ((alignmentError ==
nullptr) ||
185 (alignmentCorrection ==
nullptr)) {
186 B2FATAL(
"Inconsistent undtermined parameters.");
188 section = klmModule.getSection();
189 sector = klmModule.getSector();
190 layer = klmModule.getLayer();
192 value = alignment->getDeltaU();
196 correction = alignmentCorrection->
getDeltaU();
198 bklmModuleTree->Fill();
200 eklmModuleTree->Fill();
204 value = alignment->getDeltaV();
208 correction = alignmentCorrection->
getDeltaV();
210 bklmModuleTree->Fill();
212 eklmModuleTree->Fill();
216 value = alignment->getDeltaW();
220 correction = alignmentCorrection->
getDeltaW();
222 bklmModuleTree->Fill();
224 eklmModuleTree->Fill();
228 value = alignment->getDeltaAlpha();
234 bklmModuleTree->Fill();
236 eklmModuleTree->Fill();
240 value = alignment->getDeltaBeta();
246 bklmModuleTree->Fill();
248 eklmModuleTree->Fill();
252 value = alignment->getDeltaGamma();
258 bklmModuleTree->Fill();
260 eklmModuleTree->Fill();
266 for (; eklmSegment != eklmSegments.
endEKLM(); ++eklmSegment) {
268 alignment = eklmSegmentAlignment->getSegmentAlignment(eklmSegmentNumber);
270 eklmSegmentAlignmentErrors->getSegmentAlignment(eklmSegmentNumber);
271 alignmentCorrection =
272 eklmSegmentAlignmentCorrections->getSegmentAlignment(eklmSegmentNumber);
273 if (alignment ==
nullptr)
274 B2FATAL(
"Incomplete KLM alignment data.");
275 if ((alignmentError ==
nullptr) && (alignmentCorrection ==
nullptr)) {
280 alignmentError = &zeroAlignment;
281 alignmentCorrection = &zeroAlignment;
282 }
else if ((alignmentError ==
nullptr) ||
283 (alignmentCorrection ==
nullptr)) {
284 B2FATAL(
"Inconsistent undtermined parameters.");
292 value = alignment->getDeltaU();
294 correction = alignmentCorrection->
getDeltaU();
295 eklmSegmentTree->Fill();
299 value = alignment->getDeltaV();
303 correction = alignmentCorrection->
getDeltaV();
304 eklmSegmentTree->Fill();
308 value = alignment->getDeltaW();
312 correction = alignmentCorrection->
getDeltaW();
313 eklmSegmentTree->Fill();
317 value = alignment->getDeltaAlpha();
322 eklmSegmentTree->Fill();
326 value = alignment->getDeltaBeta();
331 eklmSegmentTree->Fill();
335 value = alignment->getDeltaGamma();
340 eklmSegmentTree->Fill();
342 bklmModuleTree->Write();
343 eklmModuleTree->Write();
344 eklmSegmentTree->Write();
345 delete bklmModuleTree;
346 delete eklmModuleTree;
347 delete eklmSegmentTree;
348 delete alignmentResults;
359 if (!stripEfficiency.isValid())
360 B2FATAL(
"Strip efficiency data are not valid.");
364 int subdetector, section, sector, layer, plane;
365 float efficiency, error;
366 TFile* stripEfficiencyResults =
368 TTree* efficiencyTree =
new TTree(
"efficiency",
"KLM strip efficiency data.");
369 efficiencyTree->Branch(
"experiment", &
m_experiment,
"experiment/I");
370 efficiencyTree->Branch(
"run", &
m_run,
"run/I");
371 efficiencyTree->Branch(
"subdetector", &subdetector,
"subdetector/I");
372 efficiencyTree->Branch(
"section", §ion,
"section/I");
373 efficiencyTree->Branch(
"sector", §or,
"sector/I");
374 efficiencyTree->Branch(
"layer", &layer,
"layer/I");
375 efficiencyTree->Branch(
"plane", &plane,
"plane/I");
376 efficiencyTree->Branch(
"efficiency", &efficiency,
"efficiency/F");
377 efficiencyTree->Branch(
"error", &error,
"error/F");
380 subdetector = klmPlane.getSubdetector();
381 section = klmPlane.getSection();
382 sector = klmPlane.getSector();
383 layer = klmPlane.getLayer();
384 plane = klmPlane.getPlane();
386 subdetector, section, sector, layer, plane, 1);
387 efficiency = stripEfficiency->getEfficiency(channel);
388 error = stripEfficiency->getEfficiencyError(channel);
389 efficiencyTree->Fill();
391 efficiencyTree->Write();
392 delete efficiencyTree;
393 delete stripEfficiencyResults;
404 if (not stripEfficiency.isValid())
405 B2FATAL(
"Strip efficiency data are not valid.");
410 TCanvas* canvas =
new TCanvas();
412 int subdetector = klmSector.getSubdetector();
413 int section = klmSector.getSection();
414 int sector = klmSector.getSector();
416 TH1F* hist =
new TH1F(
"plane_histogram",
"", 30, 0.5, 30.5);
417 hist->GetYaxis()->SetTitle(
"Efficiency");
418 hist->SetMinimum(0.4);
419 hist->SetMaximum(1.);
420 hist->SetMarkerStyle(20);
421 hist->SetMarkerSize(0.5);
425 title.Form(
"BKLM backward sector %d", sector);
427 title.Form(
"BKLM forward sector %d", sector);
428 hist->SetTitle(title.Data());
429 hist->GetXaxis()->SetTitle(
"(Layer - 1) * 2 + plane + 1");
432 int bin = (layer - 1) * 2 + plane + 1;
433 float efficiency = stripEfficiency->getBarrelEfficiency(section, sector, layer, plane, 2);
434 float efficiencyError = stripEfficiency->getBarrelEfficiencyError(section, sector, layer, plane, 2);
435 hist->SetBinContent(bin, efficiency);
436 hist->SetBinError(bin, efficiencyError);
441 hist->SetBins(24, 0.5, 24.5);
442 title.Form(
"EKLM backward sector %d", sector);
444 hist->SetBins(28, 0.5, 28.5);
445 title.Form(
"EKLM forward sector %d", sector);
447 hist->SetTitle(title.Data());
448 hist->GetXaxis()->SetTitle(
"(Layer - 1) * 2 + plane");
452 int bin = (layer - 1) * 2 + plane;
453 float efficiency = stripEfficiency->getEndcapEfficiency(section, sector, layer, plane, 2);
454 float efficiencyError = stripEfficiency->getEndcapEfficiencyError(section, sector, layer, plane, 2);
455 hist->SetBinContent(bin, efficiency);
456 hist->SetBinError(bin, efficiencyError);
462 name.Form(
"efficiency_subdetector_%d_section_%d_sector_%d.pdf", subdetector, section, sector);
463 canvas->Print(name.Data());
static constexpr int getMaximalLayerNumber()
Get maximal layer number (1-based).
@ c_BackwardSection
Backward.
static constexpr int getMaximalPlaneNumber()
Get maximal plane number (0-based).
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
bool isValid() const
Check whether a valid object was obtained from the database.
Class for accessing objects in the database.
Singleton class to cache database objects.
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
int getMaximalDetectorLayerNumber(int section) const
Get maximal detector layer number.
static const EKLMElementNumbers & Instance()
Instantiation.
@ c_BackwardSection
Backward.
static constexpr int getMaximalPlaneNumber()
Get maximal plane number.
float getDeltaU() const
Get shift in U.
float getDeltaV() const
Get shift in V.
@ c_DeltaAlpha
Rotation in alpha.
@ c_DeltaBeta
Rotation in beta.
@ c_DeltaU
Shift in U (EKLM: local X).
@ c_DeltaGamma
Rotation in gamma (EKLM: rotation in local plane).
@ c_DeltaV
Shift in V (EKLM: local Y).
float getDeltaW() const
Get shift in W.
float getDeltaGamma() const
Get rotation in alpha.
float getDeltaAlpha() const
Get rotation in alpha.
float getDeltaBeta() const
Get rotation in alpha.
void checkStripEfficiency()
Check strip efficiency.
void resetDatabase()
Reset the database.
void initializeDatabase()
Initialize the database.
void setExperimentRun(int experiment, int run)
Set experiment and run numbers.
void checkAlignment()
Check alignment.
const KLMElementNumbers * m_ElementNumbers
Element numbers.
std::string m_GlobalTagName
Global Tag name.
std::string m_AlignmentResultsFile
Output file for alignment results.
std::string m_testingPayloadName
Testing payload location.
std::string m_StripEfficiencyResultsFile
Output file for alignment results.
int m_experiment
Experiment number.
void createStripEfficiencyHistograms()
Create strip efficiency histograms.
void printPayloadInformation(DBObjPtr< T > &dbObject)
Print payload information.
KLMCalibrationChecker()
Constructor.
StoreObjPtr< EventMetaData > m_EventMetaData
Event metadata.
~KLMCalibrationChecker()
Destructor.
KLMChannelIndex & endEKLM()
Last channel for EKLM.
int getLayer() const
Get layer.
int getSection() const
Get section.
int getPlane() const
Get plane.
int getStrip() const
Get strip.
int getEKLMSegmentNumber() const
Get EKLM segment number.
int getSector() const
Get sector.
@ c_IndexLevelSector
Sector.
@ c_IndexLevelLayer
Layer.
@ c_IndexLevelStrip
Strip.
@ c_IndexLevelPlane
Plane.
void useEKLMSegments(bool useSegments=true)
Iterate over EKLM segments instead of strips.
KLMChannelIndex beginEKLM()
First channel for EKLM.
KLMChannelNumber channelNumber(int subdetector, int section, int sector, int layer, int plane, int strip) const
Get channel number.
Class to store variables with their name which were sent to the logging service.
void reset(bool keepEntries=false)
Invalidate all payloads.
static Database & Instance()
Instance of a singleton Database.
static DBStore & Instance()
Instance of a singleton DBStore.
void updateEvent()
Updates all intra-run dependent objects.
void update()
Updates all objects that are outside their interval of validity.
static void reset(bool keepConfig=false)
Reset the database instance.
uint16_t KLMChannelNumber
Channel number.
uint16_t KLMModuleNumber
Module number.
Abstract base class for different kinds of events.