Belle II Software development
ARICHCalibrationChecker.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 <arich/calibration/ARICHCalibrationChecker.h>
11
12/* ARICH headers. */
13#include <arich/dbobjects/ARICHChannelMask.h>
14
15/* Belle II headers. */
16#include <framework/database/Database.h>
17#include <framework/database/DBStore.h>
18#include <framework/database/Configuration.h>
19#include <framework/datastore/DataStore.h>
20
21/* ROOT headers. */
22#include <TFile.h>
23#include <TTree.h>
24
25using namespace Belle2;
26
28 m_experiment(0),
29 m_run(0)
30{
31}
32
34{
35}
36
37void ARICHCalibrationChecker::setExperimentRun(int experiment, int run)
38{
39 m_experiment = experiment;
40 m_run = run;
41 if (m_EventMetaData.isValid()) {
42 m_EventMetaData->setExperiment(experiment);
43 m_EventMetaData->setRun(run);
44 }
45}
46
48{
49 /* Mimic a module initialization. */
51 m_EventMetaData.registerInDataStore();
53 if (!m_EventMetaData.isValid())
54 m_EventMetaData.construct(1, m_run, m_experiment);
55 /* Database instance and configuration. */
56 DBStore& dbStore = DBStore::Instance();
57 dbStore.update();
58 dbStore.updateEvent();
59 auto& dbConfiguration = Conditions::Configuration::getInstance();
60 if ((m_testingPayloadName != "") and (m_GlobalTagName == ""))
61 dbConfiguration.prependTestingPayloadLocation(m_testingPayloadName);
62 else if ((m_testingPayloadName == "") and (m_GlobalTagName != ""))
63 dbConfiguration.prependGlobalTag(m_GlobalTagName);
64 else
65 B2FATAL("Setting both testing payload and Global Tag or setting no one of them.");
66}
67
69{
70 /* Reset both DataStore and Database. */
73 DBStore::Instance().reset(false);
74}
75
77{
78 if (modID <= 42) return 1;
79 if (modID <= 90) return 2;
80 if (modID <= 144) return 3;
81 if (modID <= 204) return 4;
82 if (modID <= 270) return 5;
83 if (modID <= 342) return 6;
84 if (modID <= 420) return 7;
85 return 0;
86}
87
89{
90 if (getRing(modID) == 1) return (modID - 1) / 7 + 1;
91 if (getRing(modID) == 2) return (modID - 43) / 8 + 1;
92 if (getRing(modID) == 3) return (modID - 91) / 9 + 1;
93 if (getRing(modID) == 4) return (modID - 145) / 10 + 1;
94 if (getRing(modID) == 5) return (modID - 205) / 11 + 1;
95 if (getRing(modID) == 6) return (modID - 271) / 12 + 1;
96 if (getRing(modID) == 7) return (modID - 343) / 13 + 1;
97 return 0;
98}
99
101{
102 /* Initialize the database. */
104 /* Now we can read the payload. */
105 DBObjPtr<ARICHChannelMask> channelMask;
106 if (!channelMask.isValid())
107 B2FATAL("ARICHChannelMask is not valid.");
108 if (m_GlobalTagName != "")
109 printPayloadInformation(channelMask);
110 /* Create tree with fractions of masked channels in each sector. */
111 float frac_masked_sector[6] = {0.};
112 float frac_masked = 0.;
113 TFile* channelMaskResults =
114 new TFile(m_channelMaskResultsFile.c_str(), "recreate");
115 TTree* maskTree = new TTree("arich_masked", "ARICH channel masking");
116 maskTree->Branch("experiment", &m_experiment, "experiment/I");
117 maskTree->Branch("run", &m_run, "run/I");
118 maskTree->Branch("frac_masked_sector", &frac_masked_sector, "frac_masked_sector[6]/F");
119 maskTree->Branch("frac_masked", &frac_masked, "frac_masked/F");
120
121 for (int mod = 1; mod < 421; mod++) {
122 int sector = getSector(mod);
123 for (int chn = 0; chn < 144; chn++) {
124 if (!channelMask->isActive(mod, chn)) { frac_masked_sector[sector - 1]++; frac_masked++;}
125 }
126 }
127
128 for (int sec = 0; sec < 6; sec++) frac_masked_sector[sec] /= 10080.;
129 frac_masked /= 60480.;
130 maskTree->Fill();
131
132 maskTree->Write();
133 delete maskTree;
134 delete channelMaskResults;
135 /* Reset the database. Needed to avoid mess if we call this method multiple times with different GTs. */
137}
void checkChannelMask()
Check channel mask.
void resetDatabase()
Reset the database.
void initializeDatabase()
Initialize the database.
std::string m_channelMaskResultsFile
Output file for channel mask results.
int getRing(int modID)
Get HAPD ring number.
int getSector(int modID)
Get HAPD sector number.
void setExperimentRun(int experiment, int run)
Set experiment and run numbers.
std::string m_GlobalTagName
Global Tag name.
std::string m_testingPayloadName
Testing payload location.
void printPayloadInformation(DBObjPtr< T > &dbObject)
Print payload information.
StoreObjPtr< EventMetaData > m_EventMetaData
Event metadata.
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.
Definition: DBObjPtr.h:21
Singleton class to cache database objects.
Definition: DBStore.h:31
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:53
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:93
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
Definition: DataStore.cc:85
void reset(bool keepEntries=false)
Invalidate all payloads.
Definition: DBStore.cc:175
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:41
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:26
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:140
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:77
static void reset(bool keepConfig=false)
Reset the database instance.
Definition: Database.cc:49
Abstract base class for different kinds of events.