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 m_debugLevel(0),
48 m_famMethod(1),
51 m_beambkgtag(0),
52 m_famana(0),
53 m_SetTCEThreshold(100.0),
54 m_FADC(1),
55 m_ConditionDB(false),
57 {
58
59 string desc = "TRGECLFAMModule(" + version() + ")";
60 setDescription(desc);
62
63 addParam("DebugLevel", m_debugLevel, "TRGECL debug level", m_debugLevel);
64 addParam("FAMFitMethod", m_famMethod, "TRGECLFAM fit method", m_famMethod);
65 addParam("FAMBinTimeInterval", m_binTimeInterval, "TRGECLFAM binTimeInterval",
67 addParam("TCWaveform", m_SaveTCWaveForm, "Output the TC waveform ",
69 addParam("FAMAnaTable", m_famana, "Save FAM ana table ",
70 m_famana);
71 addParam("BeamBkgTag", m_beambkgtag, "Save beambackground tag in TRGECLHit table ",
73 addParam("TCThreshold", m_SetTCEThreshold, "Set FAM TC threshold ",
75 addParam("ShapingFunction", m_FADC, "Set function of shaper ", m_FADC);
76 addParam("ConditionDB", m_ConditionDB, "Use conditionDB ", m_ConditionDB);
77 addParam("SourceOfTC", m_SourceOfTC,
78 "Select source of TC data(1:=ECLHit or 2:=ECLSimHit or 3:=ECLHit+TRGECLBGTCHit)",
80
81 if (m_ConditionDB) { //Use global tag
82 m_FAMPara.addCallback(this, &TRGECLFAMModule::beginRun);
83 }
84 B2DEBUG(100, "TRGECLFAMModule ... created");
85 m_TCEThreshold.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 = " << m_famMethod
106 << " ; Bin of Time Interval = " << m_binTimeInterval
107 << " ;output TC waveforml = " << m_SaveTCWaveForm);
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 (!m_ConditionDB) {
135 } else { //Use global tag
136 m_TCEThreshold.resize(576, 0);
137 for (const auto& para : m_FAMPara) {
138 m_TCEThreshold[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(m_SaveTCWaveForm);
168 obj_trgeclDigi->setFADC(m_FADC);
169 obj_trgeclDigi->setup(m_SourceOfTC);
170 if (m_famMethod == 1 || m_famMethod == 2) {
171 // no-fit method = backup method 1
172 obj_trgeclDigi->digitization01(m_TCDigiE, m_TCDigiT);
173 } else if (m_famMethod == 3) {
174 // original method = backup method 2
175 obj_trgeclDigi->digitization02(m_TCDigiE, m_TCDigiT);
176 }
177 obj_trgeclDigi->save(m_nEvent);
178
179
180 // FAM Fitter
181 TrgEclFAMFit* obj_trgeclfit = new TrgEclFAMFit();
182 obj_trgeclfit->setBeamBkgTagFlag(m_beambkgtag);
183 obj_trgeclfit->setAnaTagFlag(m_famana);
184 obj_trgeclfit->setup(m_nEvent);
185 obj_trgeclfit->setThreshold(m_TCEThreshold);
186
187 if (m_famMethod == 1) { obj_trgeclfit->FAMFit01(m_TCDigiE, m_TCDigiT); } // fitting method
188 else if (m_famMethod == 2) { obj_trgeclfit->FAMFit02(m_TCDigiE, m_TCDigiT); } // no-fit method = backup method 1
189 else if (m_famMethod == 3) { obj_trgeclfit->FAMFit03(m_TCDigiE, m_TCDigiT); } // original method = backup method 2
190 obj_trgeclfit-> save(m_nEvent);
191
192 // Count number of trigger cells in each ECL region for EventLevelClusteringInfo
193 uint16_t nTCsPerRegion[3] = {};
194 const double absTimeRequirement = 9999.; // Selection on time to reproduce data
195 const int firstBarrelId = 81; // First TCId in the barrel
196 const int lastBarrelId = 512; // Last TCId in the barrel
197 for (auto& trgeclhit : m_TRGECLHit) {
198 const int tcId = trgeclhit.getTCId();
199 const double tcTime = trgeclhit.getTimeAve();
200 if (std::abs(tcTime) < absTimeRequirement) {
201 if (tcId < firstBarrelId) {
202 nTCsPerRegion[0]++;
203 } else if (tcId > lastBarrelId) {
204 nTCsPerRegion[2]++;
205 } else {
206 nTCsPerRegion[1]++;
207 }
208 }
209 }
210 // Store
212 m_eventLevelClusteringInfo->setNECLTriggerCellsFWD(nTCsPerRegion[0]);
213 m_eventLevelClusteringInfo->setNECLTriggerCellsBarrel(nTCsPerRegion[1]);
214 m_eventLevelClusteringInfo->setNECLTriggerCellsBWD(nTCsPerRegion[2]);
215 //
216 m_nEvent++;
217 delete obj_trgeclDigi;
218 delete obj_trgeclfit;
219 }
220//
221//
222//
223 void
225 {
226 B2DEBUG(200, "TRGECLFAMModule ... endRun called ");
227 }
228//
229//
230//
231 void
233 {
234 B2DEBUG(100, "TRGECLFAMModule ... terminate called ");
235 }
236//
237//
238//
240} // 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
Threshold.
int m_famana
save FAM ana table
int m_binTimeInterval
Time interval.
int m_beambkgtag
save Beam background tag in TRGECLHit table
StoreArray< TRGECLDigi0 > m_TRGECLDigi0
output for TRGECLDigi0
int m_nEvent
Event number.
std::vector< std::vector< double > > m_TCDigiE
Digitized TC E [GeV].
bool m_ConditionDB
Use Condition DB.
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.
DBArray< TRGECLFAMPara > m_FAMPara
FAM Parameters.
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.
std::string version(void) const
returns version of TRGECLFAMModule.
virtual ~TRGECLFAMModule()
Destructor.
Abstract base class for different kinds of events.
STL namespace.