Belle II Software development
TRGCDCModule.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//-----------------------------------------------------------------------------
10// Description : A trigger module for CDC
11//-----------------------------------------------------------------------------
12
13#define TRGCDC_SHORT_NAMES
14
15#include <iostream>
16#include "G4RunManager.hh"
17
18#include "trg/cdc/modules/trgcdc/TRGCDCModule.h"
19#include "trg/trg/Debug.h"
20
21#include <framework/datastore/StoreArray.h>
22#include <mdst/dataobjects/MCParticle.h>
23#include <cdc/dataobjects/CDCHit.h>
24#include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
25#include <trg/cdc/dataobjects/CDCTriggerTrack.h>
26#include <trg/trg/dataobjects/TRGTiming.h>
27
28#include <cdc/geometry/CDCGeometryPar.h>
29
30using namespace std;
31
32namespace Belle2 {
40
41 string
43 {
44 return string("TRGCDCModule 5.07");
45 }
46
48 : Module::Module(),
49 _debugLevel(0),
50 _configFilename("TRGCDCConfig.dat"),
51 _innerTSLUTFilename("undefined"),
52 _outerTSLUTFilename("undefined"),
53 _rootTRGCDCFilename("undefined"),
54 _rootFitter3DFilename("undefined"),
55 _curlBackStop(0),
56 _simulationMode(1),
57 _fastSimulationMode(0),
58 _firmwareSimulationMode(0),
59 _firmwareSimulationStart(0),
60 _firmwareSimulationStop(32 * 32 - 1),
61 _fileTRGCDC(0),
62 _perfect2DFinder(false),
63 _perfect3DFinder(false),
64 _hFinderPeakMin(5),
65 _hFinderMappingFilePlus("HoughMappingPlus20160223.dat"),
66 _hFinderMappingFileMinus("HoughMappingMinus20160223.dat"),
67 _hFinderDoit(2),
68 _fLogicLUTTSF(1),
69 _fLRLUT(1),
70 _fFitter3Dsmclr(0),
71 _fFitter3Ds2DFit(1),
72 _fFitter3Ds2DFitDrift(0),
73 _wireHitInefficiency(0.),
74 _fileTSF(0),
75 _fileETF(0),
76 _fverETF(0),
77 _fprintFirmETF(0),
78 _fileHough3D(0),
79 _finder3DMode(2),
80 _fileFitter3D(0),
81 _fXtSimpleFitter3D(0),
82 _trgCDCDataInputMode(0),
83 _cdc(0),
84 _sa(0)
85 {
86
87 string desc = "TRGCDCModule(" + version() + ")";
88 setDescription(desc);
90
91 vector<string> emptyvector;
92
93 addParam("DebugLevel", _debugLevel, "TRGCDC debug level", _debugLevel);
94 addParam("ConfigFile",
96 "The filename of CDC trigger config file",
98 addParam("ReturnValueModuleNames", _returnValueModuleNames,
99 "Chooses modules for return value. Can be a list of [TSF, ETF, 2DFind, 2DFit, 3DFind, 3DFit]. If empty list then returnValue will be for all modules.",
100 emptyvector);
101 addParam("InnerTSLUTFile",
103 "The filename of LUT for inner-most track segments",
105 addParam("OuterTSLUTFile",
107 "The filename of LUT for outer track segments",
109 addParam("RootTRGCDCFile",
111 "The filename of root file for TRGCDC",
112 string("TRGCDC.root"));
113 addParam("RootFitter3DFile",
115 "The filename of root file for Fitter3D",
116 string("Fitter3D.root"));
117 addParam("CurlBackStop",
119 "Curl back stop parameter",
121 addParam("SimulationMode",
123 "TRGCDC simulation switch",
125 addParam("FastSimulationMode",
127 "TRGCDC fast simulation mode",
129 addParam("FirmwareSimulationMode",
131 "TRGCDC firmware simulation mode",
133 addParam("FirmwareSimulationStart",
135 "TRGCDC firmware simulation start clock of CDC FE",
137 addParam("FirmwareSimulationStop",
139 "TRGCDC firmware simulation stop clock of CDC FE",
141 addParam("TRGCDCRootFile",
143 "Flag for making TRGCDC.root",
145 addParam("TSFLogicLUT",
147 "Use logic or LUT for TSF",
149 addParam("2DFinderPerfect",
151 "2D finder perfect option",
153 addParam("3DFinderPerfect",
155 "3D finder perfect option",
157 addParam("HoughFinderPeakMin",
159 "Hough finder min. peak height",
161 addParam("HoughFinderMappingFilePlus",
163 "Hough finder cell mapping file for charge plus",
165 addParam("HoughFinderMappingFileMinus",
167 "Hough finder cell mapping file for charge minus",
169 addParam("HoughFinderDoit",
171 "Hough finder doit() version",
173 addParam("Fitter3DsLRLUT",
174 _fLRLUT,
175 "Using L/R LUT in fitter3D",
176 _fLRLUT);
177 addParam("Fitter3DsMcLR",
179 "Using MC L/R information for Fitter3D",
181 addParam("Fitter3Ds2DFit",
183 "Using 1: 2D fit or 0: Hough Finder results for Fitter3D",
185 addParam("Fitter3Ds2DFitDrift",
187 "Using 1: drift 2D fit or 0: wire 2D fit for Fitter3D",
189 addParam("wireHitInefficiency",
191 "wire hit inefficiency",
193 addParam("TSFRootFile",
194 _fileTSF,
195 "Flag for making TSF.root",
196 _fileTSF);
197 addParam("ETFRootFile",
198 _fileETF,
199 "Flag for making ETF.root",
200 _fileETF);
201 addParam("verETF",
202 _fverETF,
203 "Select ETF ver, 0:histogram, 1:old Version, 2:True T0",
204 _fverETF);
205 addParam("printFirmETF",
207 "Flag for printing Firmware inputs for ETF",
209 addParam("Hough3DRootFile",
211 "Flag for making Hough3D.root",
213 addParam("Finder3DMode",
215 "Mode for finder3D",
217 addParam("Fitter3DRootFile",
219 "Flag for making Fitter3D.root",
221 addParam("Fitter3DsXtSimple",
223 "0: Use simple xt curve table. 1: use non-linear xt curve table.",
225 addParam("TRGCDCDataInputMode",
227 "Flag for TRG CDC input mode",
229 addParam("inputCollection", m_inputCollectionName,
230 "Name of the CDCHit StoreArray to be used as input.",
231 string(""));
232 addParam("2DfinderCollection", m_2DfinderCollectionName,
233 "Name of the StoreArray holding the tracks made by the 2D finder.",
234 string("Trg2DFinderTracks"));
235 addParam("2DfitterCollection", m_2DfitterCollectionName,
236 "Name of the StoreArray holding the tracks made by the 2D fitter.",
237 string("Trg2DFitterTracks"));
238 addParam("3DfitterCollection", m_3DfitterCollectionName,
239 "Name of the StoreArray holding the tracks made by the 3D fitter.",
240 string("Trg3DFitterTracks"));
241
242
243 if (TRGDebug::level())
244 cout << "TRGCDCModule ... created" << endl;
245 }
246
248 {
249 if (_cdc)
250 TRGCDC::getTRGCDC("good-bye");
251
252 if (TRGDebug::level())
253 cout << "TRGCDCModule ... destructed " << endl;
254 }
255
256 void
258 {
259
260 //...Stop curl buck...
261 if (_curlBackStop) {
262 G4RunManager* g4rm = G4RunManager::GetRunManager();
263 if (g4rm != 0) {
264 if (g4rm->GetUserPhysicsList() != 0) {
265 _sa = new TCSAction();
266 g4rm->SetUserAction(_sa);
267 }
268 }
269 }
271
272 if (TRGDebug::level()) {
273 cout << "TRGCDCModule::initialize ... options" << endl;
274 cout << TRGDebug::tab(4) << "debug level = " << TRGDebug::level()
275 << endl;
276 cout << TRGDebug::tab(4) << "back stop = " << _curlBackStop << endl;
277 cout << TRGDebug::tab(4) << "2D finder perfect = " << _perfect2DFinder
278 << endl;
279 cout << TRGDebug::tab(4) << "Hough finder Min. Peak = "
281 << endl;
282 }
283
284 // register DataStore elements
286 segmentHits.registerInDataStore();
288 cdcHits.isRequired();
289 StoreArray<MCParticle> mcparticles;
290 segmentHits.registerRelationTo(cdcHits);
291 mcparticles.registerRelationTo(segmentHits);
292 // register tracks only for full simulation (not for TSF simulation)
293 if (!(_fastSimulationMode & 1)) {
300 tracks2Dfinder.registerRelationTo(segmentHits); // hits related over Hough cell
301 tracks2Dfitter.registerRelationTo(segmentHits); // hits used for the 2D fit
302 tracks3Dfitter.registerRelationTo(segmentHits); // hits used for the 2D and 3D fit
303 tracks2Dfinder.registerRelationTo(tracks2Dfitter);
304 tracks2Dfinder.registerRelationTo(tracks3Dfitter);
305 }
306 StoreObjPtr<TRGTiming> eventTime("CDCTriggerEventTime");
307 eventTime.registerInDataStore("CDCTriggerEventTime");
308
309 //...CDC trigger config. name...
310 static string cfn = _configFilename;
311
312 //...CDC trigger...
313 if ((cfn != _configFilename) || (_cdc == 0)) {
333 _fLRLUT,
338 _fileTSF,
339 _fileETF,
340 _fverETF,
346 cdc.getTdcBinWidth(),
349 }
350 }
351
352 void
354 {
355 if (TRGDebug::level())
356 cout << "TRGCDCModule ... beginRun called " << endl;
357 }
358
359 void
361 {
362 // initialize returnValue
364
365 //...CDC trigger simulation...
366 _cdc->update();
367 _cdc->simulate();
368
369 // save the results to DataStore
373
374 // Set return value
375 int returnValue = _cdc->getReturnValue();
376 int mask = 0;
377 for (vector<string>::iterator it = _returnValueModuleNames.begin(); it != _returnValueModuleNames.end(); ++it) {
378 string const& moduleName = *it;
379 if (moduleName == "TSF") mask |= TRGCDC::EReturnValueType::TSF;
380 else if (moduleName == "ETF") mask |= TRGCDC::EReturnValueType::ETF;
381 else if (moduleName == "find2D") mask |= TRGCDC::EReturnValueType::find2D;
382 else if (moduleName == "fit2D") mask |= TRGCDC::EReturnValueType::fit2D;
383 else if (moduleName == "find3D") mask |= TRGCDC::EReturnValueType::find3D;
384 else if (moduleName == "fit3D") mask |= TRGCDC::EReturnValueType::fit3D;
385 }
386 if (mask != 0) returnValue &= mask;
387 setReturnValue(returnValue);
388 }
389
390 void
392 {
393 if (TRGDebug::level())
394 cout << "TRGCDCModule ... endRun called " << endl;
395 }
396
397 void
399 {
400
401 _cdc->terminate();
402
403 if (TRGDebug::level())
404 cout << "TRGCDCModule ... terminate called " << endl;
405 }
406
408} // namespace Belle2
The Class for CDC Geometry Parameters.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
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
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:220
@ 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
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
int _curlBackStop
Curl back stop parameter. 0:do nothing, 1:stop curling. Default is 0.
Definition: TRGCDCModule.h:119
bool _fileFitter3D
Switch for Fitter3D.root file.
Definition: TRGCDCModule.h:194
bool _fFitter3Ds2DFitDrift
Switch to us wire 2D fit or drift 2D fit.
Definition: TRGCDCModule.h:170
bool _fFitter3Ds2DFit
Switch to us 2D fit or Hough finder results.
Definition: TRGCDCModule.h:167
std::string _configFilename
Config. file name.
Definition: TRGCDCModule.h:68
int _trgCDCDataInputMode
Switch for TRG CDC input mode.
Definition: TRGCDCModule.h:200
std::string _hFinderMappingFilePlus
Hough mapping file for charge plus.
Definition: TRGCDCModule.h:149
std::string m_3DfitterCollectionName
Name of the StoreArray holding the tracks made by the 3D fitter.
Definition: TRGCDCModule.h:209
int _debugLevel
Debug level.
Definition: TRGCDCModule.h:65
int _finder3DMode
Sets mode of 3DFinder.
Definition: TRGCDCModule.h:191
bool _fXtSimpleFitter3D
Switch for using simple x-t curve or non-linear x-t curve. 0: non-linear 1: simple.
Definition: TRGCDCModule.h:197
std::string _outerTSLUTFilename
The filename of LUT for outer track segments.(tmp)
Definition: TRGCDCModule.h:83
int _simulationMode
Mode for TRGCDC simulation. 0th bit : fast simulation switch, 1st bit : firmware simulation switch.
Definition: TRGCDCModule.h:122
std::string _innerTSLUTFilename
The filename of LUT for the inner-most track segments.(tmp)
Definition: TRGCDCModule.h:80
bool _fLogicLUTTSF
Switch for the Logic/LUT TSF.
Definition: TRGCDCModule.h:158
TRGCDCSteppingAction * _sa
A pointer to a TRGCDCSteppingAction which stops curl backs.
Definition: TRGCDCModule.h:217
int _fverETF
Switch for selecting ETF version.
Definition: TRGCDCModule.h:182
bool _fileHough3D
Switch for Hough3D.root file.
Definition: TRGCDCModule.h:188
bool _fileTSF
Switch for TSF.root file.
Definition: TRGCDCModule.h:176
bool _fileETF
Switch for ETF.root file.
Definition: TRGCDCModule.h:179
std::string _rootTRGCDCFilename
The filename of root file for TRGCDC.
Definition: TRGCDCModule.h:113
int _hFinderPeakMin
Min. peak height for the Hough finder.
Definition: TRGCDCModule.h:146
bool _fprintFirmETF
Switch for printing Firmware inputs for ETF.
Definition: TRGCDCModule.h:185
std::string m_inputCollectionName
Name of the CDCHit StoreArray used as input.
Definition: TRGCDCModule.h:203
bool _fileTRGCDC
Switch for TRGCDC.root file.
Definition: TRGCDCModule.h:137
std::string m_2DfinderCollectionName
Name of the StoreArray holding the tracks made by the 2D finder.
Definition: TRGCDCModule.h:205
int _firmwareSimulationMode
Switch for the firmware simulation. 0:do nothing, 1:do everything.
Definition: TRGCDCModule.h:128
bool _perfect2DFinder
Switch to activate perfect 2D finder.
Definition: TRGCDCModule.h:140
double _wireHitInefficiency
Parameter for Hit inefficiency.
Definition: TRGCDCModule.h:173
TRGCDC * _cdc
A pointer to a TRGCDC;.
Definition: TRGCDCModule.h:214
int _hFinderDoit
Hough finder doit version.
Definition: TRGCDCModule.h:155
int _firmwareSimulationStop
Stop clock for the firmware simultion. (clock=cdcfe)
Definition: TRGCDCModule.h:134
int _firmwareSimulationStart
Start clock for the firmware simultion. (clock=cdcfe)
Definition: TRGCDCModule.h:131
int _fastSimulationMode
Switch for the fast simulation. 0:do everything, 1:stop after the track segment simulation....
Definition: TRGCDCModule.h:125
bool _perfect3DFinder
Switch to activate perfect 3D finder.
Definition: TRGCDCModule.h:143
std::string m_2DfitterCollectionName
Name of the StoreArray holding the tracks made by the 2D fitter.
Definition: TRGCDCModule.h:207
std::string _rootFitter3DFilename
The filename of root file for Fitter3D.
Definition: TRGCDCModule.h:116
bool _fFitter3Dsmclr
Switch for Fitter3D's MC L/R information.
Definition: TRGCDCModule.h:164
std::vector< std::string > _returnValueModuleNames
returnValue module's name. Can be ["", "TSF", "ETF", "find2D", "fit2D", "find3D", "fit3D"]....
Definition: TRGCDCModule.h:71
bool _fLRLUT
Switch for the LR LUT in Fitter3D.
Definition: TRGCDCModule.h:161
std::string _hFinderMappingFileMinus
Hough mapping file for charge minus.
Definition: TRGCDCModule.h:152
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:69
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 TRGCDCModule.
virtual ~TRGCDCModule()
Destructor.
virtual void event() override
Called event by event.
virtual void endRun() override
Called when run ended.
virtual void terminate() override
Called when processing ended.
TRGCDCModule()
Constructor.
Definition: TRGCDCModule.cc:47
virtual void beginRun() override
Called when new run started.
std::string version(void) const
returns version of TRGCDCModule.
Definition: TRGCDCModule.cc:42
static std::string tab(void)
returns tab spaces.
Definition: Debug.cc:47
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:192
void setReturnValue(EReturnValueType const &moduleName, bool flag)
sets return value for trg cdc module.
Definition: TRGCDC.cc:2748
void terminate(void)
terminates when run is finished
Definition: TRGCDC.cc:739
static int level(void)
returns the debug level.
Definition: Debug.cc:67
int getReturnValue(void) const
gets return value for trg cdc module.
Definition: TRGCDC.h:1098
void update()
updates TRGCDC wire information. clear() is called in this function.
Definition: TRGCDC.cc:984
void simulate(void)
fast trigger simulation.
Definition: TRGCDC.cc:2049
void storeSimulationResults(std::string collection2Dfinder, std::string collection2Dfitter, std::string collection3Dfitter)
Save results of fast simulation to data store (segment hits & tracks).
Definition: TRGCDC.cc:2248
Abstract base class for different kinds of events.
STL namespace.