Belle II Software  release-06-02-00
EclCovMatrixNtupleModule.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  * *
11  * Description: This module write ECL digi information in a root tuple *
12  * to study amplitude and time info *
13  * *
14  **************************************************************************/
15 
16 //This module
17 #include <ecl/modules/eclDataAnalysis/EclCovMatrixNtupleModule.h>
18 
19 //ROOT
20 #include <TTree.h>
21 #include <TFile.h>
22 
23 //ECL
24 #include <ecl/dataobjects/ECLDigit.h>
25 #include <ecl/dataobjects/ECLDsp.h>
26 #include <ecl/dataobjects/ECLTrig.h>
27 #include <ecl/geometry/ECLGeometryPar.h>
28 
29 
30 
31 using namespace std;
32 using namespace Belle2;
33 using namespace ECL;
34 //-----------------------------------------------------------------
35 // Register the Module
36 //-----------------------------------------------------------------
37 REG_MODULE(EclCovMatrixNtuple)
38 
39 //-----------------------------------------------------------------
40 // Implementation
41 //-----------------------------------------------------------------
43 {
44  //Set module properties
45  setDescription("EclCovMatrixNtuple: write ECL waveform and fitted time and amplitude in a root file");
46  setPropertyFlags(c_ParallelProcessingCertified);
47  //Parameters definition
48  addParam("outputFileName", m_dataOutFileName,
49  "Output root file name of this module", string("EclCovMatrixNtuple"));
50  addParam("dspArrayName", m_dspArrayName, "name of input ECLDsp Array", string("ECLDsps"));
51  addParam("digiArrayName", m_digiArrayName, "name of input ECLDigit Array", string("ECLDigits"));
52 }
53 
54 void EclCovMatrixNtupleModule::initialize()
55 {
56  m_eclDspArray.registerInDataStore(m_dspArrayName);
57  m_eclDigiArray.registerInDataStore(m_digiArrayName);
58  B2INFO("[EclCovMatrixNtuple Module]: Starting initialization of EclCovMatrixNtuple Module.");
59 
60  // Initializing the output root file
61  string dataFileName = m_dataOutFileName + ".root";
62 
63  m_rootFile = new TFile(dataFileName.c_str(), "RECREATE");
64  m_tree = new TTree("m_tree", "EclCovMatrixNtuple tree");
65 
66  m_tree->Branch("energy", &m_energy, "energy/D");
67  m_tree->Branch("nhits", &m_nhits, "nhits/I");
68  m_tree->Branch("cellID", m_cellID, "cellID[nhits]/I");
69  m_tree->Branch("theta", m_theta, "theta[nhits]/I");
70  m_tree->Branch("phi", m_phi, "phi[nhits]/I");
71  m_tree->Branch("hitA", m_DspHit, "hitA[nhits][31]/I");
72  m_tree->Branch("hitT", m_hitTime, "hitT[nhits]/D");
73  m_tree->Branch("deltaT", m_DeltaT, "deltaT[nhits]/D");
74 
75  m_tree->Branch("digiE", m_hitE, "hitE[nhits]/D");
76  m_tree->Branch("digiT", m_DigiTime, "digiT[nhits]/I");
77 
78 
79  B2INFO("[EclCovMatrixNtuple Module]: Finished initialising the Time Information Study in Gamma Reconstruction Module.");
80 }
81 
82 void EclCovMatrixNtupleModule::terminate()
83 {
84  m_rootFile->cd();
85  m_tree->Write();
86  m_rootFile->Close();
87 }
88 
89 void EclCovMatrixNtupleModule::event()
90 {
91 
92 
93  m_nevt++;
94  m_energy = 0;
95 
96 
97 
98  m_nhits = 0;
99 
100  for (int i = 0; i < 8736; i++) {
101  m_cellID[i] = 0;
102  m_theta[i] = 0;
103  m_phi[i] = 0;
104  m_hitTime[i] = 0;
105  m_hitE[i] = 0.0;
106  m_hitTime[i] = 0.0;
107  m_DigiTime[i] = 0;
108  m_DeltaT[i] = 0.0;
109  for (int j = 0; j < 31; j++) {
110  m_DspHit[i][j] = 0;
111  }
112  }
113 
114 
115  m_nhits = m_eclDigiArray.getEntries();
116 
117  // There is only 1 ECLTrig per event
118  assert(m_eclTrigArray.getEntries() == 1);
119  ECLGeometryPar* eclgeo = ECLGeometryPar::Instance();
120  for (const auto& adigit : m_eclDigiArray) {
121  size_t cellIndex = static_cast<size_t>(adigit.getCellId() - 1);
122  eclgeo->Mapping(cellIndex);
123  m_theta[cellIndex] = eclgeo->GetThetaID();
124  m_phi[cellIndex] = eclgeo->GetPhiID();
125  /*
126  cout << "cid : " << cellIndex
127  << " theta: " << m_theta[cellIndex]
128  << " phi: " << m_phi[cellIndex]
129  << endl;
130  */
131  m_cellID[cellIndex] = cellIndex;
132  m_hitE[cellIndex] = adigit.getAmp();
133  m_DigiTime[cellIndex] = adigit.getTimeFit();
134  // The following DeltaT IS DIFFERENT DeltaT in igitizer by the last factor 12.!
135  double deltaT = m_eclTrigArray[0]->getTimeTrig() * 508.0 / 12.0;
136  m_DeltaT[cellIndex] = deltaT;
137  m_hitTime[cellIndex] = 1520 - adigit.getTimeFit() - 64 * deltaT * 12.0 * 24.0 / 508.0 / 1536.0;
138  }
139 
140  //The following works only because position of an ECLDigit in the ECLDigiArray
141  //is the same of position of the corresponding ECLDsp in the ECLDspArray
142  //Since the two a tightly related this must be enforced in a safer way
143  //in the ecl data objects model (Guglielmo De Nardo)
144  assert(m_eclDspArray.getEntries() == m_eclDigiArray.getEntries());
145  for (const auto& eclDsp : m_eclDspArray) {
146  size_t cellIndex = static_cast<size_t>(eclDsp.getCellId() - 1);
147  eclDsp.getDspA(m_DspHit[cellIndex]);
148  }
149  m_tree->Fill();
150 }
The Class for ECL Geometry Parameters.
void Mapping(int cid)
Mapping theta, phi Id.
int GetThetaID()
Get Theta Id.
a module to write ECL waveform and fitted time and amplitude information in a root ntuple
Base class for Modules.
Definition: Module.h:72
#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.