Belle II Software development
eclWaveformTemplateCalibrationC2Collector.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//This module`
10#include <ecl/modules/eclWaveformTemplateCalibrationC2Collector/eclWaveformTemplateCalibrationC2Collector.h>
11
12//Framework
13#include <framework/dataobjects/EventMetaData.h>
14
15//ECL
16#include <ecl/dataobjects/ECLDigit.h>
17#include <ecl/dataobjects/ECLDsp.h>
18#include <ecl/dbobjects/ECLCrystalCalib.h>
19
20using namespace std;
21using namespace Belle2;
22
23//-----------------------------------------------------------------
24// Register the Modules
25//-----------------------------------------------------------------
26REG_MODULE(eclWaveformTemplateCalibrationC2Collector);
27//-----------------------------------------------------------------
28// Implementation
29//-----------------------------------------------------------------
30
31// constructor
33 m_eclWaveformTemplateCalibrationC1MaxResLimit("eclWaveformTemplateCalibrationC1MaxResLimit")
34{
35 // Set module properties
36 setDescription("Module to export waveforms from gamma gamma events for waveform template calibrations");
37 addParam("MinEnergyThreshold", m_MinEnergyThreshold, "Minimum energy threshold of online fit result for Fitting Waveforms (GeV).",
38 2.0);
39 addParam("MaxEnergyThreshold", m_MaxEnergyThreshold, "Maximum energy threshold of online fit result for Fitting Waveforms (GeV).",
40 4.0);
41 addParam("MinCellID", m_MinCellID, "Minimum CellID to run collector on", 0);
42 addParam("MaxCellID", m_MaxCellID, "Maximum CellID to run collector on", 0);
43 addParam("BaselineLimit", m_baselineLimit, "Number of points to compute baseline", 12);
44 addParam("ADCFloorThreshold", m_ADCFloorThreshold, "Used to determine if waveform hit ADC floor", 10);
46}
47
49{
50
51 m_eclDsps.isRequired();
52 m_eclDigits.isRequired();
53
54 // Loading results from C1 stage of the calibration
56
58 auto tree = new TTree("tree", "");
59 tree->Branch("CellID", &m_CellID, "m_CellID/I");
60 tree->Branch("ADC0", &m_ADC0, "m_ADC0/I");
61 tree->Branch("ADC1", &m_ADC1, "m_ADC1/I");
62 tree->Branch("ADC2", &m_ADC2, "m_ADC2/I");
63 tree->Branch("ADC3", &m_ADC3, "m_ADC3/I");
64 tree->Branch("ADC4", &m_ADC4, "m_ADC4/I");
65 tree->Branch("ADC5", &m_ADC5, "m_ADC5/I");
66 tree->Branch("ADC6", &m_ADC6, "m_ADC6/I");
67 tree->Branch("ADC7", &m_ADC7, "m_ADC7/I");
68 tree->Branch("ADC8", &m_ADC8, "m_ADC8/I");
69 tree->Branch("ADC9", &m_ADC9, "m_ADC9/I");
70 tree->Branch("ADC10", &m_ADC10, "m_ADC10/I");
71 tree->Branch("ADC11", &m_ADC11, "m_ADC11/I");
72 tree->Branch("ADC12", &m_ADC12, "m_ADC12/I");
73 tree->Branch("ADC13", &m_ADC13, "m_ADC13/I");
74 tree->Branch("ADC14", &m_ADC14, "m_ADC14/I");
75 tree->Branch("ADC15", &m_ADC15, "m_ADC15/I");
76 tree->Branch("ADC16", &m_ADC16, "m_ADC16/I");
77 tree->Branch("ADC17", &m_ADC17, "m_ADC17/I");
78 tree->Branch("ADC18", &m_ADC18, "m_ADC18/I");
79 tree->Branch("ADC19", &m_ADC19, "m_ADC19/I");
80 tree->Branch("ADC20", &m_ADC20, "m_ADC20/I");
81 tree->Branch("ADC21", &m_ADC21, "m_ADC21/I");
82 tree->Branch("ADC22", &m_ADC22, "m_ADC22/I");
83 tree->Branch("ADC23", &m_ADC23, "m_ADC23/I");
84 tree->Branch("ADC24", &m_ADC24, "m_ADC24/I");
85 tree->Branch("ADC25", &m_ADC25, "m_ADC25/I");
86 tree->Branch("ADC26", &m_ADC26, "m_ADC26/I");
87 tree->Branch("ADC27", &m_ADC27, "m_ADC27/I");
88 tree->Branch("ADC28", &m_ADC28, "m_ADC28/I");
89 tree->Branch("ADC29", &m_ADC29, "m_ADC29/I");
90 tree->Branch("ADC30", &m_ADC30, "m_ADC30/I");
91 registerObject<TTree>("tree", tree);
92
93}
94
96{
98 B2INFO("eclWaveformTemplateCalibrationC2Collector: Experiment = " << m_evtMetaData->getExperiment() << " run = " <<
99 m_evtMetaData->getRun());
100
101 // Loading constants to calibrate crystal energy
103 if (m_CrystalElectronics.isValid()) {
104 for (int i = 0; i < ECLElementNumbers::c_NCrystals; i++)
105 m_ADCtoEnergy[i] = m_CrystalElectronics->getCalibVector()[i];
106 }
107 if (m_CrystalEnergy.isValid()) {
108 for (int i = 0; i < ECLElementNumbers::c_NCrystals; i++)
109 m_ADCtoEnergy[i] *= m_CrystalEnergy->getCalibVector()[i];
110 }
111}
112
114{
115
116 for (auto& aECLDsp : m_eclDsps) {
117
118 const int CellId = aECLDsp.getCellId();
119 if (CellId < m_MinCellID) continue;
120 if (CellId > m_MaxCellID) continue;
121
122 const int id = CellId - 1;
123
124 //get energy
125 double energy = 0.0;
126 for (const auto& aECLDigit : m_eclDigits) {
127 if (aECLDigit.getCellId() - 1 == id) {
128 energy = aECLDigit.getAmp() * m_ADCtoEnergy[id];
129 break;
130 }
131 }
132
133 // estimate crystal energy, only select high energy crystals.
134 if (energy < m_MinEnergyThreshold) continue;
135 // Dont select very high amplitude to avoid diode-crossings
136 if (energy > m_MaxEnergyThreshold) continue;
137
138 // check if waveform has point below m_ADCFloorThreshold (indicates waveform hit ADC floor)
139 bool skipWaveform = false;
140 for (int i = 0; i < m_numberofADCPoints; i++) {
141 if (aECLDsp.getDspA()[i] < m_ADCFloorThreshold) skipWaveform = true;
142 }
143 if (skipWaveform) continue;
144
145 //compute mean of baseline
146 float baseline = 0.0;
147 for (int i = 0; i < m_baselineLimit; i++) baseline += aECLDsp.getDspA()[i];
148 baseline /= ((float) m_baselineLimit);
149
150 //compute max residual in baseline
151 float maxRes = 0.0;
152 for (int i = 0; i < m_baselineLimit; i++) {
153 float temp = fabs(aECLDsp.getDspA()[i] - baseline);
154 if (temp > maxRes) maxRes = temp;
155 }
156
157 // proceed only in below noise limit computed in C1 stage.
158 if (maxRes > m_maxResLimit[id]) continue;
159
160 // saving minimal information needed for fits to tree
161 m_CellID = id + 1;
162
163 m_ADC0 = aECLDsp.getDspA()[0];
164 m_ADC1 = aECLDsp.getDspA()[1];
165 m_ADC2 = aECLDsp.getDspA()[2];
166 m_ADC3 = aECLDsp.getDspA()[3];
167 m_ADC4 = aECLDsp.getDspA()[4];
168 m_ADC5 = aECLDsp.getDspA()[5];
169 m_ADC6 = aECLDsp.getDspA()[6];
170 m_ADC7 = aECLDsp.getDspA()[7];
171 m_ADC8 = aECLDsp.getDspA()[8];
172 m_ADC9 = aECLDsp.getDspA()[9];
173 m_ADC10 = aECLDsp.getDspA()[10];
174 m_ADC11 = aECLDsp.getDspA()[11];
175 m_ADC12 = aECLDsp.getDspA()[12];
176 m_ADC13 = aECLDsp.getDspA()[13];
177 m_ADC14 = aECLDsp.getDspA()[14];
178 m_ADC15 = aECLDsp.getDspA()[15];
179 m_ADC16 = aECLDsp.getDspA()[16];
180 m_ADC17 = aECLDsp.getDspA()[17];
181 m_ADC18 = aECLDsp.getDspA()[18];
182 m_ADC19 = aECLDsp.getDspA()[19];
183 m_ADC20 = aECLDsp.getDspA()[20];
184 m_ADC21 = aECLDsp.getDspA()[21];
185 m_ADC22 = aECLDsp.getDspA()[22];
186 m_ADC23 = aECLDsp.getDspA()[23];
187 m_ADC24 = aECLDsp.getDspA()[24];
188 m_ADC25 = aECLDsp.getDspA()[25];
189 m_ADC26 = aECLDsp.getDspA()[26];
190 m_ADC27 = aECLDsp.getDspA()[27];
191 m_ADC28 = aECLDsp.getDspA()[28];
192 m_ADC29 = aECLDsp.getDspA()[29];
193 m_ADC30 = aECLDsp.getDspA()[30];
194
195 getObjectPtr<TTree>("tree")->Fill();
196
197 }
198}
Calibration collector module base class.
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
StoreArray< ECLDigit > m_eclDigits
Required input array of ECLDigits.
DBObjPtr< ECLCrystalCalib > m_eclWaveformTemplateCalibrationC1MaxResLimit
Baseline noise thresholds compute in stage C1.
void collect() override
Select events and crystals and accumulate histograms.
void prepare() override
Define histograms and read payloads from DB.
int m_CellID
To read ntuple branch, waveform ECL crystal cell ID >
std::vector< float > m_maxResLimit
Vector to store baseline noise thresholds compute in stage C1.
std::vector< float > m_ADCtoEnergy
Crystal energy calibration constants.
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.