Belle II Software prerelease-11-00-00a
TRGECLFAMModule.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#define TRGECLFAM_SHORT_NAMES
10
11//framework headers
12#include <framework/logging/Logger.h>
13
14//trg package headers
15#include <trg/ecl/modules/trgecl/TRGECLFAMModule.h>
16#include <trg/ecl/TrgEclDigitizer.h>
17#include <trg/ecl/TrgEclFAMFit.h>
18
19#include <iostream>
20
21using namespace std;
22
23namespace Belle2 {
28//
29//
31 REG_MODULE(TRGECLFAM);
32//
33//
34//
35 string
37 {
38 return string("TRGECLFAMModule 1.00");
39 }
40//
41//
42//
44 : Module::Module(),
45 m_debugLevel(0),
46 m_famMethod(1),
49 m_beambkgtag(0),
50 m_famana(0),
51 m_SetTCEThreshold(100.0),
52 m_FADC(1),
53 m_ConditionDBFAM(true),
55 {
56
57 string desc = "TRGECLFAMModule(" + version() + ")";
58 setDescription(desc);
60
61 addParam("DebugLevel", m_debugLevel, "TRGECL debug level", m_debugLevel);
62 addParam("FAMFitMethod", m_famMethod, "TRGECLFAM fit method", m_famMethod);
63 addParam("FAMBinTimeInterval", m_binTimeInterval, "TRGECLFAM binTimeInterval",
65 addParam("TCWaveform", m_SaveTCWaveForm, "Output the TC waveform ",
67 addParam("FAMAnaTable", m_famana, "Save FAM ana table ",
68 m_famana);
69 addParam("BeamBkgTag", m_beambkgtag, "Save beambackground tag in TRGECLHit table ",
71 addParam("TCThreshold", m_SetTCEThreshold, "Set FAM TC threshold ",
73 addParam("ShapingFunction", m_FADC, "Set function of shaper ", m_FADC);
74 addParam("ConditionDBFAM", m_ConditionDBFAM, "Use conditionDB for FAM", m_ConditionDBFAM);
75 addParam("SourceOfTC", m_SourceOfTC,
76 "Select source of TC data(1:=ECLHit or 2:=ECLSimHit or 3:=ECLHit+TRGECLBGTCHit)",
78
79 B2DEBUG(100, "TRGECLFAMModule ... created");
80 m_TCEThreshold.clear();
81
82 }
83//
84//
85//
87 {
88
89 B2DEBUG(100, "TRGECLFAMModule ... destructed ");
90
91 }
92//
93//
94//
95 void
97 {
98 B2DEBUG(100, "TRGECLFAMModule::initialize ... options");
99 B2DEBUG(100, "TRGECLFAMModule::initialize> FAM Fit Method = " << m_famMethod
100 << " ; Bin of Time Interval = " << m_binTimeInterval
101 << " ;output TC waveforml = " << m_SaveTCWaveForm);
102 if (m_SourceOfTC <= 0 ||
103 m_SourceOfTC >= 4) {
104 B2FATAL("TRGECLFAMModule::initialize> SourceOfTC must be 1 or 2 or 3");
105 }
106
107 m_nRun = 0;
108 m_nEvent = 1;
109
110 m_TRGECLDigi0.registerInDataStore();
111 m_TRGECLWaveform.registerInDataStore();
112 m_TRGECLHit.registerInDataStore();
113 m_TRGECLFAMAna.registerInDataStore();
114 // This object is registered by few packages. Let's be agnostic about the
115 // execution order of the modules: the first package run registers the module
116 m_eventLevelClusteringInfo.isOptional() ? m_eventLevelClusteringInfo.isRequired() :
117 m_eventLevelClusteringInfo.registerInDataStore();
118
119 }
120//
121//
122//
123 void
125 {
126 if (!m_ConditionDBFAM) {
128 } else {
129 //Use global tag
130 // get TC ADC-to-Eneryg converion factor from conditionDB
131 const auto& dbParmap = m_ETMParameters->getparMap();
132 m_TCADCtoEnergy = getDBparmap(dbParmap, "adc2energy", 0) * 1000; // (MeV)
133 // get TC Energy Threshold from TC ADC Threshold and ADC-to-Energy conversion factor
134 m_TCEThreshold.resize(576, 0);
135 for (const auto& para : m_FAMTCADCThreshold) {
136 int tc_id = (int) para.getTCId();
137 m_TCEThreshold[tc_id - 1] = floor(para.getTCADCThreshold() * m_TCADCtoEnergy);
138 }
139 }
140
141 B2DEBUG(200, "TRGECLFAMModule ... beginRun called ");
142
143 }
144//
145//
146//
147 void
149 {
150
151 B2DEBUG(200, "TRGECLFAMMoudle ... event called");
152 //
153 //
154 if (m_nEvent < 1e2) {if (m_nEvent % 10 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
155 else if (m_nEvent < 1e3) {if (m_nEvent % 100 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
156 else if (m_nEvent < 1e4) {if (m_nEvent % 1000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
157 else if (m_nEvent < 1e5) {if (m_nEvent % 10000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
158 else if (m_nEvent < 1e6) {if (m_nEvent % 100000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
159
160
161 //
162 //
163 //
164 // FAM Digitizer
165 TrgEclDigitizer* obj_trgeclDigi = new TrgEclDigitizer();
166 obj_trgeclDigi->setWaveform(m_SaveTCWaveForm);
167 obj_trgeclDigi->setFADC(m_FADC);
168 obj_trgeclDigi->setup(m_SourceOfTC);
169 if (m_famMethod == 1 || m_famMethod == 2) {
170 // no-fit method = backup method 1
171 obj_trgeclDigi->digitization01(m_TCDigiE, m_TCDigiT);
172 } else if (m_famMethod == 3) {
173 // original method = backup method 2
174 obj_trgeclDigi->digitization02(m_TCDigiE, m_TCDigiT);
175 }
176 obj_trgeclDigi->save(m_nEvent);
177
178
179 // FAM Fitter
180 TrgEclFAMFit* obj_trgeclfit = new TrgEclFAMFit();
181 obj_trgeclfit->setBeamBkgTagFlag(m_beambkgtag);
182 obj_trgeclfit->setAnaTagFlag(m_famana);
183 obj_trgeclfit->setup(m_nEvent);
184 obj_trgeclfit->setThreshold(m_TCEThreshold);
185
186 if (m_famMethod == 1) { obj_trgeclfit->FAMFit01(m_TCDigiE, m_TCDigiT); } // fitting method
187 else if (m_famMethod == 2) { obj_trgeclfit->FAMFit02(m_TCDigiE, m_TCDigiT); } // no-fit method = backup method 1
188 else if (m_famMethod == 3) { obj_trgeclfit->FAMFit03(m_TCDigiE, m_TCDigiT); } // original method = backup method 2
189 obj_trgeclfit-> save(m_nEvent);
190
191 // Count number of trigger cells in each ECL region for EventLevelClusteringInfo
192 uint16_t nTCsPerRegion[3] = {};
193 const double absTimeRequirement = 9999.; // Selection on time to reproduce data
194 const int firstBarrelId = 81; // First TCId in the barrel
195 const int lastBarrelId = 512; // Last TCId in the barrel
196 for (auto& trgeclhit : m_TRGECLHit) {
197 const int tcId = trgeclhit.getTCId();
198 const double tcTime = trgeclhit.getTimeAve();
199 if (std::abs(tcTime) < absTimeRequirement) {
200 if (tcId < firstBarrelId) {
201 nTCsPerRegion[0]++;
202 } else if (tcId > lastBarrelId) {
203 nTCsPerRegion[2]++;
204 } else {
205 nTCsPerRegion[1]++;
206 }
207 }
208 }
209 // Store
211 m_eventLevelClusteringInfo->setNECLTriggerCellsFWD(nTCsPerRegion[0]);
212 m_eventLevelClusteringInfo->setNECLTriggerCellsBarrel(nTCsPerRegion[1]);
213 m_eventLevelClusteringInfo->setNECLTriggerCellsBWD(nTCsPerRegion[2]);
214 //
215 m_nEvent++;
216 delete obj_trgeclDigi;
217 delete obj_trgeclfit;
218 }
219//
220//
221//
222 double
223 TRGECLFAMModule::getDBparmap(const std::map<std::string, double> dbParmap,
224 std::string parName,
225 double parAlternativeValue)
226 {
227 double par;
228 if (dbParmap.count(parName)) {
229 par = dbParmap.at(parName);
230 } else {
231 par = parAlternativeValue;
232 B2WARNING("No key(\"" + parName +
233 "\") for map in DB and set alternative value(" + parAlternativeValue +
234 ")");
235 }
236
237 return par;
238 }
239 //
240 //
241 //
242 void
244 {
245 B2DEBUG(200, "TRGECLFAMModule ... endRun called ");
246 // m_TCEThreshold.clear();
247 }
248//
249//
250//
251 void
253 {
254 B2DEBUG(100, "TRGECLFAMModule ... terminate called ");
255 }
256//
257//
258//
260} // namespace Belle2
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
Module()
Constructor.
Definition Module.cc:30
@ 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_SourceOfTC
Set source of TC data (1:=ECLHit or 2:=ECLSimHit or 3:=ECLHit+TRGECLBGTCHit)
int m_debugLevel
Parameters.
StoreArray< TRGECLFAMAna > m_TRGECLFAMAna
output for TRGECLFAMAna
std::vector< int > m_TCEThreshold
TC Energy Threshold [MeV].
DBArray< TRGECLFAMTCADCThreshold > m_FAMTCADCThreshold
FAM TC ADC Thresholds.
int m_famana
save FAM ana table
int m_binTimeInterval
Time interval.
double m_TCADCtoEnergy
TC ADC Energy conversion factor [MeV].
int m_beambkgtag
save Beam background tag in TRGECLHit table
StoreArray< TRGECLDigi0 > m_TRGECLDigi0
output for TRGECLDigi0
bool m_ConditionDBFAM
Use Condition DB.
int m_nEvent
Event number.
DBObjPtr< TRGECLETMParameters > m_ETMParameters
ETM Parameters.
std::vector< std::vector< double > > m_TCDigiE
Digitized TC E [GeV].
StoreArray< TRGECLWaveform > m_TRGECLWaveform
output for TRGECLWaveform
int m_SetTCEThreshold
Threshold input.
StoreArray< TRGECLHit > m_TRGECLHit
output for TRGECLHit
std::vector< std::vector< double > > m_TCDigiT
Digitized TC T [ns].
StoreObjPtr< EventLevelClusteringInfo > m_eventLevelClusteringInfo
EventLevelClusteringInfo.
int m_FADC
Set Shaping Function.
void save(int)
save fitting result into tables
void setup(int)
setup fam module
void setFADC(int fadc)
Set flag of waveform table.
void setWaveform(int wave)
Set flag of waveform table.
void digitization01(std::vector< std::vector< double > > &, std::vector< std::vector< double > > &)
fit method, digi with 125ns interval
void digitization02(std::vector< std::vector< double > > &, std::vector< std::vector< double > > &)
original no fit method, digi with 12ns interval
void setup(int)
setup fam module
void setThreshold(const std::vector< int > &tcethreshold)
set Threshold
void FAMFit02(std::vector< std::vector< double > >, std::vector< std::vector< double > >)
function for backup 1
void FAMFit01(std::vector< std::vector< double > >, std::vector< std::vector< double > >)
function for fitting
void setBeamBkgTagFlag(int beambkgtagflag)
set Beam Background Tag flag
void FAMFit03(std::vector< std::vector< double > >, std::vector< std::vector< double > >)
function for backup2
void setAnaTagFlag(int anatagflag)
set flag for saving analysis table
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
virtual void initialize() override
Initializes TRGECLFAMModule.
virtual void event() override
Called event by event.
virtual void endRun() override
Called when run ended.
virtual void terminate() override
Called when processing ended.
virtual void beginRun() override
Called when new run started.
double getDBparmap(const std::map< std::string, double >, std::string, double)
get payload from conditionDB (TRGECLETMParameters)
std::string version(void) const
returns version of TRGECLFAMModule.
virtual ~TRGECLFAMModule()
Destructor.
Abstract base class for different kinds of events.
STL namespace.