Belle II Software  release-06-02-00
ECLDigiStudyModule.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/ECLDigiStudyModule.h>
18 
19 // STL
20 #include <algorithm>
21 
22 //ROOT
23 #include <TTree.h>
24 #include <TFile.h>
25 
26 //ECL
27 #include <ecl/dataobjects/ECLDigit.h>
28 #include <ecl/dataobjects/ECLDsp.h>
29 #include <ecl/dataobjects/ECLTrig.h>
30 #include <ecl/dataobjects/ECLHit.h>
31 #include <ecl/geometry/ECLGeometryPar.h>
32 
33 
34 
35 using namespace std;
36 using namespace Belle2;
37 using namespace ECL;
38 //-----------------------------------------------------------------
39 // Register the Module
40 //-----------------------------------------------------------------
41 REG_MODULE(ECLDigiStudy);
42 
43 //-----------------------------------------------------------------
44 // Implementation
45 //-----------------------------------------------------------------
46 ECLDigiStudyModule::ECLDigiStudyModule() : Module()
47 {
48  //Set module properties
49  setDescription("EclCovMatrixNtuple: write ECL waveform and fitted time and amplitude in a root file");
51  //Parameters definition
52  addParam("outputFileName", m_dataOutFileName,
53  "Output root file name of this module", string("digistudy"));
54  addParam("dspArrayName1", m_dspArrayName1, "name of input ECLDsp Array 1", string("ECLDsps"));
55  addParam("digiArrayName1", m_digiArrayName1, "name of input ECLDigit Array 1", string("ECLDigits"));
56  addParam("dspArrayName2", m_dspArrayName2, "name of input ECLDsp Array 2", string("ECLDspsPureCsI"));
57  addParam("digiArrayName2", m_digiArrayName2, "name of input ECLDigit Array 2", string("ECLDigitsPureCsI"));
58 }
59 
61 {
62 
63  m_eclDspArray1.registerInDataStore(m_dspArrayName1);
64  m_eclDspArray2.registerInDataStore(m_dspArrayName2);
65  m_eclDigiArray1.registerInDataStore(m_digiArrayName1);
66  m_eclDigiArray2.registerInDataStore(m_digiArrayName2);
67 
68  B2INFO("[EclCovMatrixNtuple Module]: Starting initialization of EclCovMatrixNtuple Module.");
69 
70  // Initializing the output root file
71  string dataFileName = m_dataOutFileName + ".root";
72 
73  m_rootFile = new TFile(dataFileName.c_str(), "RECREATE");
74  m_tree = new TTree("m_tree", "EclCovMatrixNtuple tree");
75  m_nhits = 8736;
76 
77  m_tree->Branch("nhits", &m_nhits, "nhits/I");
78  m_tree->Branch("cellid", m_cellId, "cellid[nhits]/I");
79  m_tree->Branch("energy", m_energy, "energy[nhits]/D");
80  m_tree->Branch("alle", m_allenergy, "alle[nhits]/D");
81  m_tree->Branch("time", m_time, "time[nhits]/D");
82  m_tree->Branch("theta", m_theta, "theta[nhits]/I");
83  m_tree->Branch("phi", m_phi, "phi[nhits]/I");
84  m_tree->Branch("a1", m_DspHit1, "a1[nhits][31]/I");
85  m_tree->Branch("a2", m_DspHit2, "a2[nhits][31]/I");
86  m_tree->Branch("base1", m_baseline1, "base1[nhits][16]/I");
87  m_tree->Branch("base2", m_baseline2, "base2[nhits][16]/I");
88  m_tree->Branch("baseavg1", m_baselineAvg1, "baseavg1[nhits]/D");
89  m_tree->Branch("baseavg2", m_baselineAvg2, "baseavg2[nhits]/D");
90  m_tree->Branch("mv1", m_maxVal1, "mv1[nhits]/I");
91  m_tree->Branch("mv2", m_maxVal2, "mv2[nhits]/I");
92  m_tree->Branch("t1", m_digiTime1, "t1[nhits]/D");
93  m_tree->Branch("t2", m_digiTime2, "t2[nhits]/D");
94  m_tree->Branch("e1", m_digiE1, "e1[nhits]/D");
95  m_tree->Branch("e2", m_digiE2, "e2[nhits]/D");
96  m_tree->Branch("q1", m_digiQual1, "q1[nhits]/I");
97  m_tree->Branch("q2", m_digiQual2, "q2[nhits]/I");
98 
99  m_tree->Branch("trig1", &m_trig1, "trig1/D");
100  m_tree->Branch("trig2", &m_trig2, "trig2/D");
101  m_tree->Branch("neclhits", &m_neclhits, "neclhits/I");
102 
103  B2INFO("[ECLDigiStudyModule Module]: Finished initialising");
104 }
105 
107 {
108  m_rootFile->cd();
109  m_tree->Write();
110  m_rootFile->Close();
111 }
112 
114 {
115 
117 
118  int i;
119  m_neclhits = m_eclHitsArray.getEntries();
120  fill_n(m_cellId, 8736, 0);
121  fill_n(m_energy, 8736, 0);
122  fill_n(m_allenergy, 8736, 0);
123  fill_n(m_time, 8736, 0);
124  fill_n(m_theta, 8736, 0);
125  fill_n(m_phi, 8736, 0);
126 
127  for (int j = 0; j < 8736; j++) {
128  fill_n(m_DspHit1[j], 31, 0);
129  fill_n(m_DspHit2[j], 31, 0);
130  fill_n(m_baseline1[j], 16, 0);
131  fill_n(m_baseline2[j], 16, 0);
132  }
133 
134  fill_n(m_baselineAvg1, 8736, 0);
135  fill_n(m_baselineAvg2, 8736, 0);
136  fill_n(m_maxVal1, 8736, 0);
137  fill_n(m_maxVal2, 8736, 0);
138 
139  fill_n(m_digiTime1, 8736, 0);
140  fill_n(m_digiTime2, 8736, 0);
141  fill_n(m_digiE1, 8736, 0);
142  fill_n(m_digiE2, 8736, 0);
143  fill_n(m_digiQual1, 8736, 0);
144  fill_n(m_digiQual2, 8736, 0);
145 
146  m_trig1 = m_eclTrigArray[0]->getTimeTrig();
147  m_trig2 = 0;
148 
149  for (const auto& hit : m_eclHitsArray) {
150 
151  i = hit.getCellId() - 1;
152  m_cellId[i] = i;
153  double e = hit.getEnergyDep();
154  if (hit.getBackgroundTag() == BackgroundMetaData::bg_none) {
155  if (m_energy[i] < e)
156  m_time[i] = hit.getTimeAve();
157  m_energy[i] += e;
158  }
159  m_allenergy[i] += e;
160  eclgeo->Mapping(i);
161  m_theta[i] = eclgeo->GetThetaID();
162  m_phi[i] = eclgeo->GetPhiID();
163 
164  m_digiTime1[i] = m_digiTime2[i] = -10000;
165  m_digiE1[i] = m_digiE2[i] = -10.;
166  }
167 
168  for (const auto& digit1 : m_eclDigiArray1) {
169  i = digit1.getCellId() - 1;
170  m_digiTime1[i] = digit1.getTimeFit();
171  m_digiE1[i] = digit1.getAmp() / 20000.;
172  m_digiQual1[i] = digit1.getQuality();
173  }
174 
175  for (const auto& digit2 : m_eclDigiArray2) {
176  i = digit2.getCellId() - 1;
177  m_digiTime2[i] = digit2.getTimeFit() / 1000.;
178  m_digiE2[i] = digit2.getAmp() / 20000.;
179  m_digiQual2[i] = digit2.getQuality();
180  }
181 
182  for (const auto& dsp : m_eclDspArray1) {
183  i = dsp.getCellId() - 1;
184  dsp.getDspA(m_DspHit1[i]);
185  for (int j = 0; j < 16; j++) {
186  m_baseline1[i][j] = m_DspHit1[i][j] - 3000;
187  m_baselineAvg1[i] += m_baseline1[i][j];
188  }
189  m_baselineAvg1[i] /= 16;
190  assert(m_DspHit1[i] == (&m_DspHit1[i][0]));
191  m_maxVal1[i] = * (max_element(& m_DspHit1[i][16] , (& m_DspHit1[i][16]) + 15));
192  }
193 
194  for (const auto& dsp : m_eclDspArray2) {
195  i = dsp.getCellId() - 1;
196  dsp.getDspA(m_DspHit2[i]);
197  for (int j = 0; j < 16; j++) {
198  m_baseline2[i][j] = m_DspHit2[i][j] - 3000;
199  m_baselineAvg2[i] += m_baseline2[i][j];
200  }
201  m_baselineAvg2[i] /= 16;
202  m_maxVal2[i] = * (max_element(& m_DspHit2[i][16] , (& m_DspHit2[i][16]) + 15));
203  }
204 
205  m_tree->Fill();
206 }
int m_phi[8736]
Array of PhiID.
TTree * m_tree
Root tree for saving the output.
int m_maxVal2[8736]
WF maximum for second digit array.
int m_maxVal1[8736]
WF maximum for first digit array.
double m_trig2
Trigger time for array 2.
std::string m_dataOutFileName
output root file name (given as Module parameter)
StoreArray< ECLDigit > m_eclDigiArray2
Store array: ECLDigit.
int m_baseline2[8736][16]
Baseline sampling points for second digit array.
virtual void initialize() override
Initializes the module.
double m_digiTime2[8736]
Digit time for second digit array.
virtual void event() override
Method is called for each event.
double m_time[8736]
Array of digit time.
int m_theta[8736]
Array oh ThetaID.
TFile * m_rootFile
Root file for saving the output.
int m_neclhits
Actual number of hits.
virtual void terminate() override
terminate
std::string m_dspArrayName1
Name of first DSP array.
int m_cellId[8736]
Array of cellIDs.
std::string m_digiArrayName2
Name of second digit array.
std::string m_digiArrayName1
Name of first digit array.
int m_nhits
Maximum number of hits.
double m_digiTime1[8736]
Digit time for first digit array.
StoreArray< ECLTrig > m_eclTrigArray
Store array: ECLTrig.
double m_baselineAvg1[8736]
Baseline energy for first digit array.
double m_baselineAvg2[8736]
Baseline energy for second digit array.
std::string m_dspArrayName2
Name of second DSP array.
int m_digiQual1[8736]
Digit quality for first digit array.
double m_digiE1[8736]
Deposited energy for first digit array.
int m_DspHit1[8736][31]
WF sampling points for first digit array.
StoreArray< ECLDigit > m_eclDigiArray1
Store array: ECLDigit.
double m_energy[8736]
Array of deposited MC energy.
int m_digiQual2[8736]
Digit quality for second digit array.
StoreArray< ECLHit > m_eclHitsArray
Store array: ECLHit.
double m_digiE2[8736]
Deposited energy for second digit array.
StoreArray< ECLDsp > m_eclDspArray1
Store array: ECLDsp.
double m_allenergy[8736]
Array of deposited energy.
double m_trig1
Trigger time for array 1.
StoreArray< ECLDsp > m_eclDspArray2
Store array: ECLDsp.
int m_DspHit2[8736][31]
WF sampling points for second digit array.
int m_baseline1[8736][16]
Baseline sampling points for first digit array.
The Class for ECL Geometry Parameters.
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
void Mapping(int cid)
Mapping theta, phi Id.
int GetThetaID()
Get Theta Id.
Base class for Modules.
Definition: Module.h:72
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
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#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.