Belle II Software  release-08-00-10
eclTimeShiftsPlottingCollectorModule.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 <ecl/modules/eclTimeShiftsPlottingCollector/eclTimeShiftsPlottingCollectorModule.h>
11 
12 /* ECL headers. */
13 #include <ecl/dbobjects/ECLCrystalCalib.h>
14 #include <ecl/dbobjects/ECLReferenceCrystalPerCrateCalib.h>
15 #include <ecl/digitization/EclConfiguration.h>
16 #include <ecl/geometry/ECLGeometryPar.h>
17 
18 /* Basf2 headers. */
19 #include <framework/gearbox/Const.h>
20 
21 /* ROOT headers. */
22 #include <TFile.h>
23 #include <TH2F.h>
24 #include <TTree.h>
25 
26 using namespace Belle2;
27 using namespace ECL;
28 using namespace std;
29 
30 //-----------------------------------------------------------------
31 // Register the Module
32 //-----------------------------------------------------------------
33 REG_MODULE(eclTimeShiftsPlottingCollector);
34 
35 //-----------------------------------------------------------------
36 // Implementation
37 //-----------------------------------------------------------------
38 
40  m_CrystalTimeDB("ECLCrystalTimeOffset"),
41  m_CrateTimeDB("ECLCrateTimeOffset"),
42  m_RefCrystalsCalibDB("ECLReferenceCrystalPerCrateCalib")//,
43 {
44  setDescription("This module reads the crystal and crate time offset information from the database");
45 
46  // specify this flag if you need parallel processing
48 }
49 
51 {
52 }
53 
55 {
56 }
57 
59 {
60 
61  B2INFO("eclTimeShiftsPlottingCollector: Experiment = " << m_evtMetaData->getExperiment() <<
62  " run = " << m_evtMetaData->getRun());
63 
64  /* -----------------
65  Store the information about the crystal and crate times
66  -----------------*/
67  string objectName = "tree_perCrystal";
68  TTree* tree_crys = new TTree(objectName.c_str(), "");
69  tree_crys->Branch<int>("run", &m_run);
70  tree_crys->Branch<int>("exp", &m_exp);
71  tree_crys->Branch<double>("crateTimeConst", &m_crateTimeConst);
72  tree_crys->Branch<double>("crystalTimeConst", &m_crystalTimeConst);
73  tree_crys->Branch<double>("crateTimeUnc", &m_crateTimeConstUnc);
74  tree_crys->Branch<double>("crystalTimeUnc", &m_crystalTimeConstUnc);
75  tree_crys->Branch<int>("crystalID", &m_crystalID);
76  tree_crys->Branch<int>("crateID", &m_crateID);
77  tree_crys->Branch<int>("refCrystalID", &m_refCrystalID);
78 
79  // We register the objects so that our framework knows about them.
80  // Don't try and hold onto the pointers or fill these objects directly
81  // Use the getObjectPtr functions to access collector objects
82  registerObject<TTree>(objectName, tree_crys);
83 
84 }
85 
87 {
88  m_run = m_evtMetaData->getRun();
89  m_exp = m_evtMetaData->getExperiment();
90 
91  /* Check if we have looked at this (exp,run). If we have not
92  then store the information to the trees and update the
93  (exp previous, run previous) variables for the next comparison.
94  */
95  if (m_run != m_previousRun or m_exp != m_previousExp or m_exp < 0 or m_run < 0) {
96  /* Use ECLChannelMapper to get other detector indices for the crystals */
97  /* For conversion from CellID to crate, shaper, and channel ids. */
98 
99  // Use smart pointer to avoid memory leak when the ECLChannelMapper object needs destroying at the end of the event.
100  shared_ptr< ECL::ECLChannelMapper > crystalMapper(new ECL::ECLChannelMapper());
101  crystalMapper->initFromDB();
102 
103  // Get the previous crystal time offset (the same thing that this calibration is meant to calculate).
104  // This can be used for testing purposes, and for the crate time offset.
105  if (m_CrystalTimeDB.hasChanged()) {
106  m_CrystalTime = m_CrystalTimeDB->getCalibVector();
107  m_CrystalTimeUnc = m_CrystalTimeDB->getCalibUncVector();
108  }
109  if (m_CrateTimeDB.hasChanged()) {
110  m_CrateTime = m_CrateTimeDB->getCalibVector();
111  m_CrateTimeUnc = m_CrateTimeDB->getCalibUncVector();
112  }
113  B2DEBUG(29, "Finished checking if previous crate time payload has changed");
114  B2DEBUG(29, "m_CrateTime size = " << m_CrateTime.size());
115  B2DEBUG(25, "Crate time +- uncertainty [0]= " << m_CrateTime[0] << " +- " << m_CrateTimeUnc[0]);
116  B2DEBUG(25, "Crate time +- uncertainty [8735]= " << m_CrateTime[8735] << " +- " << m_CrateTimeUnc[8735]);
117 
118  B2DEBUG(29, "Finished checking if previous crate time payload has changed");
119  if (m_RefCrystalsCalibDB.hasChanged()) {
120  m_RefCrystalsCalib = m_RefCrystalsCalibDB->getReferenceCrystals();
121  }
122  B2DEBUG(29, "Finished checking if reference crystal ids payload has changed");
123 
124 
125  B2DEBUG(25, "eclTimeShiftsPlottingCollector:: loaded ECLCrystalTimeOffset from the database"
126  << LogVar("IoV", m_CrystalTimeDB.getIoV())
127  << LogVar("Checksum", m_CrystalTimeDB.getChecksum()));
128  B2DEBUG(25, "eclTimeShiftsPlottingCollector:: loaded ECLCrateTimeOffset from the database"
129  << LogVar("IoV", m_CrateTimeDB.getIoV())
130  << LogVar("Checksum", m_CrateTimeDB.getChecksum()));
131  B2DEBUG(25, "eclTimeShiftsPlottingCollector:: loaded ECLReferenceCrystalPerCrateCalib from the database"
132  << LogVar("IoV", m_RefCrystalsCalibDB.getIoV())
133  << LogVar("Checksum", m_RefCrystalsCalibDB.getChecksum()));
134 
135  string objectName = "tree_perCrystal";
136  auto tree_perCrystal = getObjectPtr<TTree>(objectName);
137 
138  /* Loop over all the crystals and store the crystal and crate time information
139  to the root tree for crytals */
140  for (int crysID = 1; crysID <= NUM_CRYSTALS; crysID++) {
141  m_crystalTimeConst = m_CrystalTime[crysID - 1];
143  m_crateTimeConst = m_CrateTime[crysID - 1];
144  m_crateTimeConstUnc = m_CrateTimeUnc[crysID - 1];
145  m_crystalID = crysID;
146  int crateID_temp = crystalMapper->getCrateID(crysID);
147  m_crateID = crateID_temp;
148  m_refCrystalID = m_RefCrystalsCalib[crateID_temp - 1];
149  tree_perCrystal->Fill();
150  }
151 
152  m_previousExp = m_exp ;
153  m_previousRun = m_run ;
154  }
155 
156 }
Calibration collector module base class.
This class provides access to ECL channel map that is either a) Loaded from the database (see ecl/dbo...
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
std::vector< float > m_CrateTime
vector obtained from DB object
DBObjPtr< ECLCrystalCalib > m_CrateTimeDB
Time offset from crate time calibration (also this calibration) from database.
int m_previousRun
Previous run number, in case we run over several runs.
std::vector< float > m_CrystalTimeUnc
vector obtained from DB object
DBObjPtr< ECLCrystalCalib > m_CrystalTimeDB
Time offset from previous crystal time calibration (this calibration) from database.
DBObjPtr< ECLReferenceCrystalPerCrateCalib > m_RefCrystalsCalibDB
Crystal IDs of the one reference crystal per crate from database.
std::vector< short > m_RefCrystalsCalib
vector obtained from DB object
double m_crystalTimeConstUnc
crystal time uncertainty in ticks
void collect() override
Select events and crystals and accumulate histograms.
std::vector< float > m_CrateTimeUnc
uncertainty vector obtained from DB object
StoreObjPtr< EventMetaData > m_evtMetaData
Event meta data.
int m_refCrystalID
reference crystal identification number
void prepare() override
Define histograms and read payloads from DB.
std::vector< float > m_CrystalTime
vector obtained from DB object
int m_previousExp
Previous experiment number, in case we run over several runs.
void inDefineHisto() override
Replacement for defineHisto() in CalibrationCollector modules.
Class to store variables with their name which were sent to the logging service.
REG_MODULE(arichBtest)
Register the Module.
Abstract base class for different kinds of events.