Belle II Software development
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 "trg/ecl/dbobjects/TRGECLFAMPara.h"
20
21#include <iostream>
22
23using namespace std;
24
25namespace Belle2 {
30//
31//
33 REG_MODULE(TRGECLFAM);
34//
35//
36//
37 string
39 {
40 return string("TRGECLFAMModule 1.00");
41 }
42//
43//
44//
46 : Module::Module(),
47 _debugLevel(0),
48 _famMethod(1),
49 _binTimeInterval(125),
50 _waveform(0),
51 _beambkgtag(0),
52 _famana(0),
53 _threshold(100.0),
54 _FADC(1),
55 _ConditionDB(0),
56 m_SourceOfTC(3)
57 {
58
59 string desc = "TRGECLFAMModule(" + version() + ")";
60 setDescription(desc);
62
63 addParam("DebugLevel", _debugLevel, "TRGECL debug level", _debugLevel);
64 addParam("FAMFitMethod", _famMethod, "TRGECLFAM fit method", _famMethod);
65 addParam("FAMBinTimeInterval", _binTimeInterval, "TRGECLFAM binTimeInterval",
67 addParam("TCWaveform", _waveform, "Output the TC waveform ",
68 _waveform);
69 addParam("FAMAnaTable", _famana, "Save FAM ana table ",
70 _famana);
71 addParam("BeamBkgTag", _beambkgtag, "Save beambackground tag in TRGECLHit table ",
73 addParam("TCThreshold", _threshold, "Set FAM TC threshold ",
75 addParam("ShapingFunction", _FADC, "Set function of shaper ", _FADC);
76 addParam("ConditionDB", _ConditionDB, "Use conditionDB ", _ConditionDB);
77 addParam("SourceOfTC", m_SourceOfTC,
78 "Select source of TC data(1:=ECLHit or 2:=ECLSimHit or 3:=ECLHit+TRGECLBGTCHit)",
80
81 if (_ConditionDB == 1) { //Use global tag
82 m_FAMPara.addCallback(this, &TRGECLFAMModule::beginRun);
83 }
84 B2DEBUG(100, "TRGECLFAMModule ... created");
85 Threshold.clear();
86
87 }
88//
89//
90//
92 {
93
94 B2DEBUG(100, "TRGECLFAMModule ... destructed ");
95
96 }
97//
98//
99//
100 void
102 {
103
104 B2DEBUG(100, "TRGECLFAMModule::initialize ... options");
105 B2DEBUG(100, "TRGECLFAMModule::initialize> FAM Fit Method = " << _famMethod
106 << " ; Bin of Time Interval = " << _binTimeInterval
107 << " ;output TC waveforml = " << _waveform);
108 if (m_SourceOfTC <= 0 ||
109 m_SourceOfTC >= 4) {
110 B2FATAL("TRGECLFAMModule::initialize> SourceOfTC must be 1 or 2 or 3");
111 }
112
113 m_nRun = 0;
114 m_nEvent = 1;
115
116 m_TRGECLDigi0.registerInDataStore();
117 m_TRGECLWaveform.registerInDataStore();
118 m_TRGECLHit.registerInDataStore();
119 m_TRGECLFAMAna.registerInDataStore();
120 // This object is registered by few packages. Let's be agnostic about the
121 // execution order of the modules: the first package run registers the module
122 m_eventLevelClusteringInfo.isOptional() ? m_eventLevelClusteringInfo.isRequired() :
123 m_eventLevelClusteringInfo.registerInDataStore();
124
125 // m_FAMPara = new DBObjPtr<TRGECLFAMPara>;
126 }
127//
128//
129//
130 void
132 {
133 if (_ConditionDB == 0) {
134 Threshold.resize(576, _threshold);
135 } else if (_ConditionDB == 1) { //Use global tag
136 Threshold.resize(576, 0);
137 for (const auto& para : m_FAMPara) {
138 Threshold[para.getTCId() - 1] = (int)((para.getThreshold()) * (para.getConversionFactor()));
139 }
140 }
141
142 B2DEBUG(200, "TRGECLFAMModule ... beginRun called ");
143
144 }
145//
146//
147//
148 void
150 {
151
152 B2DEBUG(200, "TRGECLFAMMoudle ... event called");
153 //
154 //
155 if (m_nEvent < 1e2) {if (m_nEvent % 10 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
156 else if (m_nEvent < 1e3) {if (m_nEvent % 100 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
157 else if (m_nEvent < 1e4) {if (m_nEvent % 1000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
158 else if (m_nEvent < 1e5) {if (m_nEvent % 10000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
159 else if (m_nEvent < 1e6) {if (m_nEvent % 100000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
160
161
162 //
163 //
164 //
165 // FAM Digitizer
166 TrgEclDigitizer* obj_trgeclDigi = new TrgEclDigitizer();
167 obj_trgeclDigi->setWaveform(_waveform);
168 obj_trgeclDigi->setFADC(_FADC);
169 obj_trgeclDigi->setup(m_SourceOfTC);
170 if (_famMethod == 1 || _famMethod == 2) {
171 // no-fit method = backup method 1
172 obj_trgeclDigi->digitization01(TCDigiE, TCDigiT);
173 } else if (_famMethod == 3) {
174 // orignal method = backup method 2
175 obj_trgeclDigi->digitization02(TCDigiE, TCDigiT);
176 }
177 obj_trgeclDigi-> save(m_nEvent);
178
179
180 // FAM Fitter
181 TrgEclFAMFit* obj_trgeclfit = new TrgEclFAMFit();
182 obj_trgeclfit-> SetBeamBkgTagFlag(_beambkgtag);
183 obj_trgeclfit-> SetAnaTagFlag(_famana);
184 obj_trgeclfit-> setup(m_nEvent);
185 obj_trgeclfit-> SetThreshold(Threshold);
186
187 if (_famMethod == 1) {obj_trgeclfit-> FAMFit01(TCDigiE, TCDigiT); } // fitting method
188 else if (_famMethod == 2) {obj_trgeclfit-> FAMFit02(TCDigiE, TCDigiT); } // no-fit method = backup method 1
189 else if (_famMethod == 3) { obj_trgeclfit-> FAMFit03(TCDigiE, TCDigiT); } // orignal method = backup method 2
190 obj_trgeclfit-> save(m_nEvent);
191
192
193 // Count number of trigger cells in each ECL region for EventLevelClusteringInfo
194 uint16_t nTCsPerRegion[3] = {};
195 const double absTimeRequirement = 9999.; // Selection on time to reproduce data
196 const int firstBarrelId = 81; // First TCId in the barrel
197 const int lastBarrelId = 512; // Last TCId in the barrel
198 for (auto& trgeclhit : m_TRGECLHit) {
199 const int tcId = trgeclhit.getTCId();
200 const double tcTime = trgeclhit.getTimeAve();
201 if (std::abs(tcTime) < absTimeRequirement) {
202 if (tcId < firstBarrelId) {
203 nTCsPerRegion[0]++;
204 } else if (tcId > lastBarrelId) {
205 nTCsPerRegion[2]++;
206 } else {
207 nTCsPerRegion[1]++;
208 }
209 }
210 }
211
212 // Store
214 m_eventLevelClusteringInfo->setNECLTriggerCellsFWD(nTCsPerRegion[0]);
215 m_eventLevelClusteringInfo->setNECLTriggerCellsBarrel(nTCsPerRegion[1]);
216 m_eventLevelClusteringInfo->setNECLTriggerCellsBWD(nTCsPerRegion[2]);
217
218
219 //
220 //
221 //
222 m_nEvent++;
223 delete obj_trgeclDigi;
224 delete obj_trgeclfit;
225 //
226 //
227 //
228 }
229//
230//
231//
232 void
234 {
235 B2DEBUG(200, "TRGECLFAMModule ... endRun called ");
236 }
237//
238//
239//
240 void
242 {
243 B2DEBUG(100, "TRGECLFAMModule ... terminate called ");
244 }
245//
246//
247//
249} // namespace Belle2
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 _FADC
Set Shaping Function.
int m_SourceOfTC
Set source of TC data (1:=ECLHit or 2:=ECLSimHit or 3:=ECLHit+TRGECLBGTCHit)
int _famana
save FAM ana table
std::vector< std::vector< double > > TCDigiT
Digitized TC T [ns].
int _ConditionDB
Use Condition DB.
StoreArray< TRGECLFAMAna > m_TRGECLFAMAna
output for TRGECLFAMAna
int _debugLevel
Parameters.
int _beambkgtag
save Beam background tag in TRGECLHit table
int _binTimeInterval
Time interval.
std::vector< std::vector< double > > TCDigiE
Digitized TC E [GeV].
StoreArray< TRGECLDigi0 > m_TRGECLDigi0
output for TRGECLDigi0
int m_nEvent
Event number.
int _threshold
Threshold input.
StoreArray< TRGECLWaveform > m_TRGECLWaveform
output for TRGECLWaveform
StoreArray< TRGECLHit > m_TRGECLHit
output for TRGECLHit
std::vector< int > Threshold
Threshold.
StoreObjPtr< EventLevelClusteringInfo > m_eventLevelClusteringInfo
EventLevelClusteringInfo.
DBArray< TRGECLFAMPara > m_FAMPara
FAM Parameters.
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 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
virtual void initialize() override
Initilizes TRGECLFAMModule.
TRGECLFAMModule()
Constructor.
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.
std::string version(void) const
returns version of TRGECLFAMModule.
virtual ~TRGECLFAMModule()
Destructor.
Abstract base class for different kinds of events.
STL namespace.