Belle II Software development
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/mapper/ECLChannelMapper.h>
16
17/* ROOT headers. */
18#include <TH2F.h>
19#include <TTree.h>
20
21using namespace Belle2;
22using namespace ECL;
23using namespace std;
24
25//-----------------------------------------------------------------
26// Register the Module
27//-----------------------------------------------------------------
28REG_MODULE(eclTimeShiftsPlottingCollector);
29
30//-----------------------------------------------------------------
31// Implementation
32//-----------------------------------------------------------------
33
35 m_CrystalTimeDB("ECLCrystalTimeOffset"),
36 m_CrateTimeDB("ECLCrateTimeOffset"),
37 m_RefCrystalsCalibDB("ECLReferenceCrystalPerCrateCalib")//,
38{
39 setDescription("This module reads the crystal and crate time offset information from the database");
40
41 // specify this flag if you need parallel processing
43}
44
46{
47}
48
50{
51}
52
54{
55
56 B2INFO("eclTimeShiftsPlottingCollector: Experiment = " << m_evtMetaData->getExperiment() <<
57 " run = " << m_evtMetaData->getRun());
58
59 /* -----------------
60 Store the information about the crystal and crate times
61 -----------------*/
62 string objectName = "tree_perCrystal";
63 TTree* tree_crys = new TTree(objectName.c_str(), "");
64 tree_crys->Branch<int>("run", &m_run);
65 tree_crys->Branch<int>("exp", &m_exp);
66 tree_crys->Branch<double>("crateTimeConst", &m_crateTimeConst);
67 tree_crys->Branch<double>("crystalTimeConst", &m_crystalTimeConst);
68 tree_crys->Branch<double>("crateTimeUnc", &m_crateTimeConstUnc);
69 tree_crys->Branch<double>("crystalTimeUnc", &m_crystalTimeConstUnc);
70 tree_crys->Branch<int>("crystalID", &m_crystalID);
71 tree_crys->Branch<int>("crateID", &m_crateID);
72 tree_crys->Branch<int>("refCrystalID", &m_refCrystalID);
73
74 // We register the objects so that our framework knows about them.
75 // Don't try and hold onto the pointers or fill these objects directly
76 // Use the getObjectPtr functions to access collector objects
77 registerObject<TTree>(objectName, tree_crys);
78
79}
80
82{
83 m_run = m_evtMetaData->getRun();
84 m_exp = m_evtMetaData->getExperiment();
85
86 /* Check if we have looked at this (exp,run). If we have not
87 then store the information to the trees and update the
88 (exp previous, run previous) variables for the next comparison.
89 */
90 if (m_run != m_previousRun or m_exp != m_previousExp or m_exp < 0 or m_run < 0) {
91 /* Use ECLChannelMapper to get other detector indices for the crystals */
92 /* For conversion from CellID to crate, shaper, and channel ids. */
93
94 // Use smart pointer to avoid memory leak when the ECLChannelMapper object needs destroying at the end of the event.
95 shared_ptr< ECL::ECLChannelMapper > crystalMapper(new ECL::ECLChannelMapper());
96 crystalMapper->initFromDB();
97
98 // Get the previous crystal time offset (the same thing that this calibration is meant to calculate).
99 // This can be used for testing purposes, and for the crate time offset.
100 if (m_CrystalTimeDB.hasChanged()) {
101 m_CrystalTime = m_CrystalTimeDB->getCalibVector();
102 m_CrystalTimeUnc = m_CrystalTimeDB->getCalibUncVector();
103 }
104 if (m_CrateTimeDB.hasChanged()) {
105 m_CrateTime = m_CrateTimeDB->getCalibVector();
106 m_CrateTimeUnc = m_CrateTimeDB->getCalibUncVector();
107 }
108 B2DEBUG(29, "Finished checking if previous crate time payload has changed");
109 B2DEBUG(29, "m_CrateTime size = " << m_CrateTime.size());
110 B2DEBUG(25, "Crate time +- uncertainty [0]= " << m_CrateTime[0] << " +- " << m_CrateTimeUnc[0]);
111 B2DEBUG(25, "Crate time +- uncertainty [8735]= " << m_CrateTime[8735] << " +- " << m_CrateTimeUnc[8735]);
112
113 B2DEBUG(29, "Finished checking if previous crate time payload has changed");
114 if (m_RefCrystalsCalibDB.hasChanged()) {
115 m_RefCrystalsCalib = m_RefCrystalsCalibDB->getReferenceCrystals();
116 }
117 B2DEBUG(29, "Finished checking if reference crystal ids payload has changed");
118
119
120 B2DEBUG(25, "eclTimeShiftsPlottingCollector:: loaded ECLCrystalTimeOffset from the database"
121 << LogVar("IoV", m_CrystalTimeDB.getIoV())
122 << LogVar("Checksum", m_CrystalTimeDB.getChecksum()));
123 B2DEBUG(25, "eclTimeShiftsPlottingCollector:: loaded ECLCrateTimeOffset from the database"
124 << LogVar("IoV", m_CrateTimeDB.getIoV())
125 << LogVar("Checksum", m_CrateTimeDB.getChecksum()));
126 B2DEBUG(25, "eclTimeShiftsPlottingCollector:: loaded ECLReferenceCrystalPerCrateCalib from the database"
127 << LogVar("IoV", m_RefCrystalsCalibDB.getIoV())
128 << LogVar("Checksum", m_RefCrystalsCalibDB.getChecksum()));
129
130 string objectName = "tree_perCrystal";
131 auto tree_perCrystal = getObjectPtr<TTree>(objectName);
132
133 /* Loop over all the crystals and store the crystal and crate time information
134 to the root tree for crytals */
135 for (int crysID = 1; crysID <= NUM_CRYSTALS; crysID++) {
136 m_crystalTimeConst = m_CrystalTime[crysID - 1];
138 m_crateTimeConst = m_CrateTime[crysID - 1];
140 m_crystalID = crysID;
141 int crateID_temp = crystalMapper->getCrateID(crysID);
142 m_crateID = crateID_temp;
143 m_refCrystalID = m_RefCrystalsCalib[crateID_temp - 1];
144 tree_perCrystal->Fill();
145 }
146
149 }
150
151}
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.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
STL namespace.