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>
20#include <klm/dbobjects/KLMTimeCableDelay.h>
21#include <klm/dbobjects/KLMTimeConstants.h>
24#include <framework/database/Database.h>
25#include <framework/database/DBStore.h>
26#include <framework/database/Configuration.h>
27#include <framework/datastore/DataStore.h>
77 B2FATAL(
"Setting both testing payload and Global Tag or setting no one of them.");
102 if (!bklmAlignment.isValid() ||
103 !eklmAlignment.isValid() ||
104 !eklmSegmentAlignment.isValid() ||
105 !bklmAlignmentErrors.
isValid() ||
106 !eklmAlignmentErrors.
isValid() ||
107 !eklmSegmentAlignmentErrors.
isValid() ||
108 !bklmAlignmentCorrections.
isValid() ||
109 !eklmAlignmentCorrections.
isValid() ||
110 !eklmSegmentAlignmentCorrections.
isValid())
111 B2FATAL(
"Alignment data are not valid.");
124 int section, sector, layer, plane, segment, param;
125 float value, correction, error;
128 TTree* bklmModuleTree =
new TTree(
"bklm_module",
129 "BKLM module alignment data.");
130 bklmModuleTree->Branch(
"experiment", &
m_experiment,
"experiment/I");
131 bklmModuleTree->Branch(
"run", &
m_run,
"run/I");
132 bklmModuleTree->Branch(
"section", §ion,
"section/I");
133 bklmModuleTree->Branch(
"sector", §or,
"sector/I");
134 bklmModuleTree->Branch(
"layer", &layer,
"layer/I");
135 bklmModuleTree->Branch(
"param", ¶m,
"param/I");
136 bklmModuleTree->Branch(
"value", &value,
"value/F");
137 bklmModuleTree->Branch(
"correction", &correction,
"correction/F");
138 bklmModuleTree->Branch(
"error", &error,
"error/F");
139 TTree* eklmModuleTree =
new TTree(
"eklm_module",
140 "EKLM module alignment data.");
141 eklmModuleTree->Branch(
"experiment", &
m_experiment,
"experiment/I");
142 eklmModuleTree->Branch(
"run", &
m_run,
"run/I");
143 eklmModuleTree->Branch(
"section", §ion,
"section/I");
144 eklmModuleTree->Branch(
"sector", §or,
"sector/I");
145 eklmModuleTree->Branch(
"layer", &layer,
"layer/I");
146 eklmModuleTree->Branch(
"param", ¶m,
"param/I");
147 eklmModuleTree->Branch(
"value", &value,
"value/F");
148 eklmModuleTree->Branch(
"correction", &correction,
"correction/F");
149 eklmModuleTree->Branch(
"error", &error,
"error/F");
150 TTree* eklmSegmentTree =
new TTree(
"eklm_segment",
151 "EKLM segment alignment data.");
152 eklmSegmentTree->Branch(
"experiment", &
m_experiment,
"experiment/I");
153 eklmSegmentTree->Branch(
"run", &
m_run,
"run/I");
154 eklmSegmentTree->Branch(
"section", §ion,
"section/I");
155 eklmSegmentTree->Branch(
"sector", §or,
"sector/I");
156 eklmSegmentTree->Branch(
"layer", &layer,
"layer/I");
157 eklmSegmentTree->Branch(
"plane", &plane,
"plane/I");
158 eklmSegmentTree->Branch(
"segment", &segment,
"segment/I");
159 eklmSegmentTree->Branch(
"param", ¶m,
"param/I");
160 eklmSegmentTree->Branch(
"value", &value,
"value/F");
161 eklmSegmentTree->Branch(
"correction", &correction,
"correction/F");
162 eklmSegmentTree->Branch(
"error", &error,
"error/F");
169 alignment = bklmAlignment->getModuleAlignment(module);
170 alignmentError = bklmAlignmentErrors->getModuleAlignment(module);
171 alignmentCorrection =
172 bklmAlignmentCorrections->getModuleAlignment(module);
174 alignment = eklmAlignment->getModuleAlignment(module);
175 alignmentError = eklmAlignmentErrors->getModuleAlignment(module);
176 alignmentCorrection =
177 eklmAlignmentCorrections->getModuleAlignment(module);
179 if (alignment ==
nullptr)
180 B2FATAL(
"Incomplete KLM alignment data.");
181 if ((alignmentError ==
nullptr) && (alignmentCorrection ==
nullptr)) {
182 B2WARNING(
"Alignment is not determined for KLM module."
183 <<
LogVar(
"Module", module));
184 alignmentError = &zeroAlignment;
185 alignmentCorrection = &zeroAlignment;
186 }
else if ((alignmentError ==
nullptr) ||
187 (alignmentCorrection ==
nullptr)) {
188 B2FATAL(
"Inconsistent undtermined parameters.");
190 section = klmModule.getSection();
191 sector = klmModule.getSector();
192 layer = klmModule.getLayer();
194 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());
479 if (!timeCableDelay.isValid())
480 B2FATAL(
"Time Cable delay data are not valid.");
484 int subdetector, section, sector, layer, plane, strip, channelNumber;
486 TFile* timeCableDelayResults =
488 TTree* cableDelayTree =
new TTree(
"cabledelay",
"KLM timecabledelay data");
489 cableDelayTree->Branch(
"experiment", &
m_experiment,
"experiment/I");
490 cableDelayTree->Branch(
"run", &
m_run,
"run/I");
491 cableDelayTree->Branch(
"subdetector", &subdetector,
"subdetector/I");
492 cableDelayTree->Branch(
"section", §ion,
"section/I");
493 cableDelayTree->Branch(
"sector", §or,
"sector/I");
494 cableDelayTree->Branch(
"layer", &layer,
"layer/I");
495 cableDelayTree->Branch(
"plane", &plane,
"plane/I");
496 cableDelayTree->Branch(
"strip", &strip,
"strip/I");
497 cableDelayTree->Branch(
"channelNumber", &channelNumber,
"channelNumber/I");
498 cableDelayTree->Branch(
"timeDelay", &timeDelay,
"timeDelay/D");
501 subdetector = klmStrip.getSubdetector();
502 section = klmStrip.getSection();
503 sector = klmStrip.getSector();
504 layer = klmStrip.getLayer();
505 plane = klmStrip.getPlane();
506 strip = klmStrip.getStrip();
508 subdetector, section, sector, layer, plane, strip);
509 timeDelay = timeCableDelay->getTimeDelay(channel);
511 cableDelayTree->Fill();
513 cableDelayTree->Write();
514 delete cableDelayTree;
515 delete timeCableDelayResults;
526 if (!timeConstants.isValid())
527 B2FATAL(
"Time Constants data are not valid.");
531 int subdetector, section, sector, layer, plane, strip, module, channelNumber;
532 float delayEKLM, delayBKLM, delayRPCPhi, delayRPCZ;
533 TFile* timeConstantsResults =
535 TTree* constantsTree =
new TTree(
"constants",
"KLM timeConstants data");
536 constantsTree->Branch(
"experiment", &
m_experiment,
"experiment/I");
537 constantsTree->Branch(
"run", &
m_run,
"run/I");
538 constantsTree->Branch(
"subdetector", &subdetector,
"subdetector/I");
539 constantsTree->Branch(
"section", §ion,
"section/I");
540 constantsTree->Branch(
"sector", §or,
"sector/I");
541 constantsTree->Branch(
"layer", &layer,
"layer/I");
542 constantsTree->Branch(
"plane", &plane,
"plane/I");
543 constantsTree->Branch(
"strip", &strip,
"strip/I");
544 constantsTree->Branch(
"module", &module,
"module/I");
545 constantsTree->Branch(
"channelNumber", &channelNumber,
"channelNumber/I");
546 constantsTree->Branch(
"delayEKLM", &delayEKLM,
"delayEKLM/F");
547 constantsTree->Branch(
"delayBKLM", &delayBKLM,
"delayBKLM/F");
548 constantsTree->Branch(
"delayRPCPhi", &delayRPCPhi,
"delayRPCPhi/F");
549 constantsTree->Branch(
"delayRPCZ", &delayRPCZ,
"delayRPCZ/F");
552 subdetector = klmStrip.getSubdetector();
553 section = klmStrip.getSection();
554 sector = klmStrip.getSector();
555 layer = klmStrip.getLayer();
556 plane = klmStrip.getPlane();
557 strip = klmStrip.getStrip();
564 constantsTree->Fill();
566 constantsTree->Write();
567 delete constantsTree;
568 delete timeConstantsResults;
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 checkTimeCableDelay()
Check time cable delay.
void checkTimeConstants()
Check time constants.
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_TimeCableDelayResultsFile
Output file for time cable delay results.
std::string m_StripEfficiencyResultsFile
Output file for alignment results.
std::string m_TimeConstantsResultsFile
Output file for time constants 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.
KLMModuleNumber moduleNumber(int subdetector, int section, int sector, int layer) const
Get module number.
@ c_BKLM
BKLM scintillator.
@ c_EKLM
EKLM scintillator.
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.