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