Belle II Software development
eclWaveformCalibCollectorModule.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/eclWaveformCalibCollector/eclWaveformCalibCollectorModule.h>
11
12/* ECL headers. */
13#include <ecl/dataobjects/ECLDigit.h>
14#include <ecl/dataobjects/ECLElementNumbers.h>
15#include <ecl/dbobjects/ECLCrystalCalib.h>
16
17/* Basf2 headers. */
18#include <framework/dataobjects/EventMetaData.h>
19#include <framework/database/DBObjPtr.h>
20
21/* ROOT headers. */
22#include <TTree.h>
23
24using namespace std;
25using namespace Belle2;
26
27//-----------------------------------------------------------------
28// Register the Module
29//-----------------------------------------------------------------
30REG_MODULE(eclWaveformCalibCollector);
31
32//-----------------------------------------------------------------
33// Implementation
34//-----------------------------------------------------------------
35
36//-----------------------------------------------------------------------------------------------------
37
39{
40 // Set module properties
41 setDescription("Module to export waveforms to ntuple for template calibration.");
43 addParam("outputFileName", m_dataOutFileName, "Output root file name of this module", string("digistudy"));
44 addParam("LowEnergyThresholdGeV", m_LowEnergyThresholdGeV, "Low Energy Threshold in GeV.", 1.0);
45 addParam("HighEnergyThresholdGeV", m_HighEnergyThresholdGeV, "High Energy Threshold in GeV.", 5.5);
46 addParam("IncludeWaveforms", m_includeWaveforms, "Flag to save ADC information.", true);
47 addParam("selectCellID", m_selectCellID, "If greater than zero only save that CellID.", -1);
48}
49
50
51
55{
56 // Initializing the output root file
57 string dataFileName = m_dataOutFileName + ".root";
58 m_rootFile = new TFile(dataFileName.c_str(), "RECREATE");
59
60 // ECL dataobjects
61 m_eclDSPs.registerInDataStore();
62 m_eclDigits.registerInDataStore();
63
64 tree = new TTree("tree", "");
65 tree->Branch("CellID", &m_CellID, "m_CellID/I");
66 tree->Branch("runNum", &m_runNum, "m_runNum/I");
67 tree->Branch("expNum", &m_expNum, "m_expNum/I");
68 tree->Branch("OnlineE", &m_OnlineE, "m_OnlineE/F");
69 tree->Branch("OfflineE", &m_OfflineE, "m_OfflineE/F");
70 tree->Branch("OfflineHadE", &m_OfflineHadE, "m_OfflineHadE/F");
71 tree->Branch("FitType", &m_FitType, "m_FitType/I");
72 tree->Branch("Chi2", &m_Chi2, "m_Chi2/F");
73 tree->Branch("Chi2Save0", &m_Chi2Save0, "m_Chi2Save0/F");
74 tree->Branch("Chi2Save1", &m_Chi2Save1, "m_Chi2Save1/F");
75 tree->Branch("Chi2Save2", &m_Chi2Save2, "m_Chi2Save2/F");
76 tree->Branch("m_Baseline", &m_Baseline, "m_Baseline/F");
77 tree->Branch("m_BaselineRMS", &m_BaselineRMS, "m_BaselineRMS/F");
78 tree->Branch("m_calibConst", &m_calibConst, "m_calibConst/F");
79
81 tree->Branch("ADC0", &m_ADC0, "m_ADC0/I");
82 tree->Branch("ADC1", &m_ADC1, "m_ADC1/I");
83 tree->Branch("ADC2", &m_ADC2, "m_ADC2/I");
84 tree->Branch("ADC3", &m_ADC3, "m_ADC3/I");
85 tree->Branch("ADC4", &m_ADC4, "m_ADC4/I");
86 tree->Branch("ADC5", &m_ADC5, "m_ADC5/I");
87 tree->Branch("ADC6", &m_ADC6, "m_ADC6/I");
88 tree->Branch("ADC7", &m_ADC7, "m_ADC7/I");
89 tree->Branch("ADC8", &m_ADC8, "m_ADC8/I");
90 tree->Branch("ADC9", &m_ADC9, "m_ADC9/I");
91 tree->Branch("ADC10", &m_ADC10, "m_ADC10/I");
92 tree->Branch("ADC11", &m_ADC11, "m_ADC11/I");
93 tree->Branch("ADC12", &m_ADC12, "m_ADC12/I");
94 tree->Branch("ADC13", &m_ADC13, "m_ADC13/I");
95 tree->Branch("ADC14", &m_ADC14, "m_ADC14/I");
96 tree->Branch("ADC15", &m_ADC15, "m_ADC15/I");
97 tree->Branch("ADC16", &m_ADC16, "m_ADC16/I");
98 tree->Branch("ADC17", &m_ADC17, "m_ADC17/I");
99 tree->Branch("ADC18", &m_ADC18, "m_ADC18/I");
100 tree->Branch("ADC19", &m_ADC19, "m_ADC19/I");
101 tree->Branch("ADC20", &m_ADC20, "m_ADC20/I");
102 tree->Branch("ADC21", &m_ADC21, "m_ADC21/I");
103 tree->Branch("ADC22", &m_ADC22, "m_ADC22/I");
104 tree->Branch("ADC23", &m_ADC23, "m_ADC23/I");
105 tree->Branch("ADC24", &m_ADC24, "m_ADC24/I");
106 tree->Branch("ADC25", &m_ADC25, "m_ADC25/I");
107 tree->Branch("ADC26", &m_ADC26, "m_ADC26/I");
108 tree->Branch("ADC27", &m_ADC27, "m_ADC27/I");
109 tree->Branch("ADC28", &m_ADC28, "m_ADC28/I");
110 tree->Branch("ADC29", &m_ADC29, "m_ADC29/I");
111 tree->Branch("ADC30", &m_ADC30, "m_ADC30/I");
112 }
113
114 //called at beginning of run
115 //used to convert ADC to GeV
116 DBObjPtr<ECLCrystalCalib> Ael("ECLCrystalElectronics"), Aen("ECLCrystalEnergy");
118 if (Ael) for (int i = 0; i < ECLElementNumbers::c_NCrystals; i++) m_ADCtoEnergy[i] = Ael->getCalibVector()[i];
119 if (Aen) for (int i = 0; i < ECLElementNumbers::c_NCrystals; i++) m_ADCtoEnergy[i] *= Aen->getCalibVector()[i];
120}
121
123{
124 m_rootFile->cd();
125 tree->Write();
126 m_rootFile->Close();
127}
128
132{
133 //intended to run over gamma gamma cdst skim.
134
135 m_runNum = m_EventMetaData->getRun();
136 m_expNum = m_EventMetaData->getExperiment();
137
138 for (auto& aECLDigit : m_eclDigits) {
139
140 int cellid = aECLDigit.getCellId();
141
142 if (m_selectCellID > 0 && cellid != m_selectCellID) continue;
143
144 const int amplitude = aECLDigit.getAmp();
145
146 double energy = amplitude * m_ADCtoEnergy[cellid - 1];
147
148 if (energy > m_LowEnergyThresholdGeV && energy < m_HighEnergyThresholdGeV) {
149 for (auto& aECLDsp : m_eclDSPs) {
150 if (aECLDsp.getCellId() == cellid) {
151 m_Chi2 = aECLDsp.getTwoComponentChi2();
152 m_Chi2Save0 = aECLDsp.getTwoComponentSavedChi2(ECLDsp::photonHadron);
153 m_Chi2Save1 = aECLDsp.getTwoComponentSavedChi2(ECLDsp::photonHadronBackgroundPhoton);
154 m_Chi2Save2 = aECLDsp.getTwoComponentSavedChi2(ECLDsp::photonDiodeCrossing);
155 m_CellID = cellid;
156 m_OnlineE = amplitude;
157 m_OfflineE = aECLDsp.getTwoComponentTotalAmp();
158 m_FitType = aECLDsp.getTwoComponentFitType();
159 m_OfflineHadE = aECLDsp.getTwoComponentHadronAmp();
160 m_calibConst = m_ADCtoEnergy[cellid - 1];
161
162 //computing baseline noise
163 const double BaselineLimit = 10.0;
164 double baselinemean = 0.0;
165 for (int i = 0; i < BaselineLimit; i++) baselinemean += aECLDsp.getDspA()[i];
166 baselinemean /= BaselineLimit;
167 double baselineRMS = 0.0;
168 for (int i = 0; i < BaselineLimit; i++) {
169 double temp = aECLDsp.getDspA()[i] - baselinemean;
170 baselineRMS += (temp * temp);
171 }
172 baselineRMS /= BaselineLimit; //squared
173
174 m_Baseline = baselinemean;
175 m_BaselineRMS = baselineRMS;
176
177 if (m_includeWaveforms) {
178 m_ADC0 = aECLDsp.getDspA()[0];
179 m_ADC1 = aECLDsp.getDspA()[1];
180 m_ADC2 = aECLDsp.getDspA()[2];
181 m_ADC3 = aECLDsp.getDspA()[3];
182 m_ADC4 = aECLDsp.getDspA()[4];
183 m_ADC5 = aECLDsp.getDspA()[5];
184 m_ADC6 = aECLDsp.getDspA()[6];
185 m_ADC7 = aECLDsp.getDspA()[7];
186 m_ADC8 = aECLDsp.getDspA()[8];
187 m_ADC9 = aECLDsp.getDspA()[9];
188 m_ADC10 = aECLDsp.getDspA()[10];
189 m_ADC11 = aECLDsp.getDspA()[11];
190 m_ADC12 = aECLDsp.getDspA()[12];
191 m_ADC13 = aECLDsp.getDspA()[13];
192 m_ADC14 = aECLDsp.getDspA()[14];
193 m_ADC15 = aECLDsp.getDspA()[15];
194 m_ADC16 = aECLDsp.getDspA()[16];
195 m_ADC17 = aECLDsp.getDspA()[17];
196 m_ADC18 = aECLDsp.getDspA()[18];
197 m_ADC19 = aECLDsp.getDspA()[19];
198 m_ADC20 = aECLDsp.getDspA()[20];
199 m_ADC21 = aECLDsp.getDspA()[21];
200 m_ADC22 = aECLDsp.getDspA()[22];
201 m_ADC23 = aECLDsp.getDspA()[23];
202 m_ADC24 = aECLDsp.getDspA()[24];
203 m_ADC25 = aECLDsp.getDspA()[25];
204 m_ADC26 = aECLDsp.getDspA()[26];
205 m_ADC27 = aECLDsp.getDspA()[27];
206 m_ADC28 = aECLDsp.getDspA()[28];
207 m_ADC29 = aECLDsp.getDspA()[29];
208 m_ADC30 = aECLDsp.getDspA()[30];
209 }
210
211 tree->Fill();
212 }
213 }
214 }
215 }
216}
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
@ photonHadronBackgroundPhoton
photon + hadron template + pile-up photon fit
Definition: ECLDsp.h:32
@ photonDiodeCrossing
photon + diode template fit
Definition: ECLDsp.h:33
@ photonHadron
photon + hadron template fit
Definition: ECLDsp.h:31
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
int m_ADC8
To read ntuple branch, ith ADC value of waveform >
float m_OnlineE
To read ntuple branch, waveform energy measured online by FPGA >
int m_ADC9
To read ntuple branch, ith ADC value of waveform >
int m_selectCellID
Root used to select specific CellID to save.
int m_ADC3
To read ntuple branch, ith ADC value of waveform >
float m_Chi2
To read ntuple branch, offline fit chi2 >
int m_ADC13
To read ntuple branch, ith ADC value of waveform >
int m_ADC21
To read ntuple branch, ith ADC value of waveform >
int m_ADC25
To read ntuple branch, ith ADC value of waveform >
float m_Chi2Save0
To read ntuple branch, offline fit chi2 for fit type 0 >
int m_ADC27
To read ntuple branch, ith ADC value of waveform >
float m_Baseline
To read ntuple branch, baseline of waveform >
int m_ADC18
To read ntuple branch, ith ADC value of waveform >
std::string m_dataOutFileName
Root file name for saving the output.
int m_ADC5
To read ntuple branch, ith ADC value of waveform >
int m_ADC20
To read ntuple branch, ith ADC value of waveform >
virtual void initialize() override
Initializes the module.
float m_OfflineHadE
To read ntuple branch, waveform hadron energy measure offline with multi-template fit >
virtual void event() override
Method is called for each event.
double m_LowEnergyThresholdGeV
Low Energy Threshold in GeV.
int m_ADC2
To read ntuple branch, ith ADC value of waveform >
TFile * m_rootFile
Root file for saving the output.
int m_ADC10
To read ntuple branch, ith ADC value of waveform >
eclWaveformCalibCollectorModule()
Constructor: Sets the description, the properties and the parameters of the module.
int m_ADC14
To read ntuple branch, ith ADC value of waveform >
int m_ADC28
To read ntuple branch, ith ADC value of waveform >
StoreArray< ECLDsp > m_eclDSPs
StoreArray ECLDsp.
float m_calibConst
To read ntuple branch, calibration from ADC to GeV >
int m_expNum
To read ntuple branch, waveform ECL crystal cell ID >
StoreArray< ECLDigit > m_eclDigits
StoreArray ECLDigit.
int m_ADC15
To read ntuple branch, ith ADC value of waveform >
int m_ADC22
To read ntuple branch, ith ADC value of waveform >
int m_ADC7
To read ntuple branch, ith ADC value of waveform >
int m_ADC26
To read ntuple branch, ith ADC value of waveform >
int m_ADC30
To read ntuple branch, ith ADC value of waveform >
float m_OfflineE
To read ntuple branch, waveform energy measure offline with multi-template fit >
bool m_includeWaveforms
Flag to save ADC information.
int m_ADC0
To read ntuple branch, ith ADC value of waveform >
int m_ADC29
To read ntuple branch, ith ADC value of waveform >
int m_ADC1
To read ntuple branch, ith ADC value of waveform >
int m_ADC11
To read ntuple branch, ith ADC value of waveform >
int m_ADC24
To read ntuple branch, ith ADC value of waveform >
TTree * tree
Root tree for saving the output.
int m_CellID
To read ntuple branch, waveform ECL crystal cell ID >
int m_ADC16
To read ntuple branch, ith ADC value of waveform >
int m_ADC4
To read ntuple branch, ith ADC value of waveform >
float m_BaselineRMS
To read ntuple branch, RMS squared of waveform baseline >
int m_ADC12
To read ntuple branch, ith ADC value of waveform >
float m_Chi2Save2
To read ntuple branch, offline fit chi2 for fit type 2 >
int m_ADC17
To read ntuple branch, ith ADC value of waveform >
StoreObjPtr< EventMetaData > m_EventMetaData
Event metadata info.
float m_Chi2Save1
To read ntuple branch, offline fit chi2 for fit type 1 >
int m_FitType
To read ntuple branch, offline fit type with best chi2 >
int m_ADC6
To read ntuple branch, ith ADC value of waveform >
int m_ADC23
To read ntuple branch, ith ADC value of waveform >
std::vector< float > m_ADCtoEnergy
calibration vector from adc to energy
double m_HighEnergyThresholdGeV
High Energy Threshold in GeV.
int m_runNum
To read ntuple branch, waveform ECL crystal cell ID >
int m_ADC19
To read ntuple branch, ith ADC value of waveform >
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
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.
STL namespace.