Belle II Software  release-06-02-00
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 
10 #include <ecl/modules/eclTimeShiftsPlottingCollector/eclTimeShiftsPlottingCollectorModule.h>
11 #include <framework/gearbox/Const.h>
12 #include <ecl/dbobjects/ECLCrystalCalib.h>
13 #include <ecl/dbobjects/ECLReferenceCrystalPerCrateCalib.h>
14 #include <ecl/digitization/EclConfiguration.h>
15 #include <ecl/geometry/ECLGeometryPar.h>
16 
17 #include <TH2F.h>
18 #include <TTree.h>
19 #include <TFile.h>
20 
21 using namespace Belle2;
22 using namespace ECL;
23 using namespace std;
24 
25 //-----------------------------------------------------------------
26 // Register the Module
27 //-----------------------------------------------------------------
28 REG_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
42  setPropertyFlags(c_ParallelProcessingCertified);
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];
137  m_crystalTimeConstUnc = m_CrystalTimeUnc[crysID - 1];
138  m_crateTimeConst = m_CrateTime[crysID - 1];
139  m_crateTimeConstUnc = m_CrateTimeUnc[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 
147  m_previousExp = m_exp ;
148  m_previousRun = m_run ;
149  }
150 
151 }
Calibration collector module base class.
General DB object to store one reference crystal per per ECL crate for calibration purposes.
This class provides access to ECL channel map that is either a) Loaded from the database (see ecl/dbo...
This modules looks up crystal and crate time offset constants from the database and saves them to a t...
void collect() override
Select events and crystals and accumulate histograms.
void prepare() override
Define histograms and read payloads from DB.
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.