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
32
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. */
72 // Database::Instance().reset(false);
73 Database::Instance().reset(true); // keep the configuration
74 DBStore::Instance().reset(false);
75}
76
78{
79 if (modID <= 42) return 1;
80 if (modID <= 90) return 2;
81 if (modID <= 144) return 3;
82 if (modID <= 204) return 4;
83 if (modID <= 270) return 5;
84 if (modID <= 342) return 6;
85 if (modID <= 420) return 7;
86 return 0;
87}
88
90{
91 if (getRing(modID) == 1) return (modID - 1) / 7 + 1;
92 if (getRing(modID) == 2) return (modID - 43) / 8 + 1;
93 if (getRing(modID) == 3) return (modID - 91) / 9 + 1;
94 if (getRing(modID) == 4) return (modID - 145) / 10 + 1;
95 if (getRing(modID) == 5) return (modID - 205) / 11 + 1;
96 if (getRing(modID) == 6) return (modID - 271) / 12 + 1;
97 if (getRing(modID) == 7) return (modID - 343) / 13 + 1;
98 return 0;
99}
100
102{
103 /* Initialize the database. */
105 /* Now we can read the payload. */
106 DBObjPtr<ARICHChannelMask> channelMask;
107 if (!channelMask.isValid())
108 B2FATAL("ARICHChannelMask is not valid.");
109 if (m_GlobalTagName != "")
110 printPayloadInformation(channelMask);
111 /* Create tree with fractions of masked channels in each sector. */
112 float frac_masked_sector[6] = {0.};
113 float frac_masked = 0.;
114 TFile* channelMaskResults =
115 new TFile(m_channelMaskResultsFile.c_str(), "recreate");
116 TTree* maskTree = new TTree("arich_masked", "ARICH channel masking");
117 maskTree->Branch("experiment", &m_experiment, "experiment/I");
118 maskTree->Branch("run", &m_run, "run/I");
119 maskTree->Branch("frac_masked_sector", &frac_masked_sector, "frac_masked_sector[6]/F");
120 maskTree->Branch("frac_masked", &frac_masked, "frac_masked/F");
121
122 for (int mod = 1; mod < 421; mod++) {
123 int sector = getSector(mod);
124 for (int chn = 0; chn < 144; chn++) {
125 if (!channelMask->isActive(mod, chn)) { frac_masked_sector[sector - 1]++; frac_masked++;}
126 }
127 }
128
129 for (int sec = 0; sec < 6; sec++) frac_masked_sector[sec] /= 10080.;
130 frac_masked /= 60480.;
131 maskTree->Fill();
132
133 maskTree->Write();
134 delete maskTree;
135 delete channelMaskResults;
136 /* Reset the database. Needed to avoid mess if we call this method multiple times with different GTs. */
138}
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.