Belle II Software  release-05-02-19
TRGCDCModule.cc
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : Module.cc
5 // Section : TRG CDC
6 // Owner : Yoshihito Iwasaki
7 // Email : yoshihito.iwasaki@kek.jp
8 //-----------------------------------------------------------------------------
9 // Description : A trigger module for CDC
10 //-----------------------------------------------------------------------------
11 // 0.00 : 2010/10/08 : First version
12 //-----------------------------------------------------------------------------
13 
14 #define TRGCDC_SHORT_NAMES
15 
16 #include <iostream>
17 #include "G4RunManager.hh"
18 
19 #include "trg/cdc/modules/trgcdc/TRGCDCModule.h"
20 #include "trg/trg/Debug.h"
21 
22 #include <framework/datastore/StoreArray.h>
23 #include <mdst/dataobjects/MCParticle.h>
24 #include <cdc/dataobjects/CDCHit.h>
25 #include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
26 #include <trg/cdc/dataobjects/CDCTriggerTrack.h>
27 #include <trg/trg/dataobjects/TRGTiming.h>
28 
29 #include <cdc/geometry/CDCGeometryPar.h>
30 
31 using namespace std;
32 
33 namespace Belle2 {
39  REG_MODULE(TRGCDC);
41 
42  string
43  TRGCDCModule::version() const
44  {
45  return string("TRGCDCModule 5.07");
46  }
47 
48  TRGCDCModule::TRGCDCModule()
49  : Module::Module(),
50  _debugLevel(0),
51  _configFilename("TRGCDCConfig.dat"),
52  _innerTSLUTFilename("undefined"),
53  _outerTSLUTFilename("undefined"),
54  _rootTRGCDCFilename("undefined"),
55  _rootFitter3DFilename("undefined"),
56  _curlBackStop(0),
57  _simulationMode(1),
58  _fastSimulationMode(0),
59  _firmwareSimulationMode(0),
60  _firmwareSimulationStart(0),
61  _firmwareSimulationStop(32 * 32 - 1),
62  _fileTRGCDC(0),
63  _perfect2DFinder(false),
64  _perfect3DFinder(false),
65  _hFinderPeakMin(5),
66  _hFinderMappingFilePlus("HoughMappingPlus20160223.dat"),
67  _hFinderMappingFileMinus("HoughMappingMinus20160223.dat"),
68  _hFinderDoit(2),
69  _fLogicLUTTSF(1),
70  _fLRLUT(1),
71  _fFitter3Dsmclr(0),
72  _fFitter3Ds2DFit(1),
73  _fFitter3Ds2DFitDrift(0),
74  _wireHitInefficiency(0.),
75  _fileTSF(0),
76  _fileETF(0),
77  _fverETF(0),
78  _fprintFirmETF(0),
79  _fileHough3D(0),
80  _finder3DMode(2),
81  _fileFitter3D(0),
82  _fXtSimpleFitter3D(0),
83  _trgCDCDataInputMode(0),
84  _cdc(0),
85  _sa(0)
86  {
87 
88  string desc = "TRGCDCModule(" + version() + ")";
89  setDescription(desc);
91 
92  vector<string> emptyvector;
93 
94  addParam("DebugLevel", _debugLevel, "TRGCDC debug level", _debugLevel);
95  addParam("ConfigFile",
97  "The filename of CDC trigger config file",
99  addParam("ReturnValueModuleNames", _returnValueModuleNames,
100  "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.",
101  emptyvector);
102  addParam("InnerTSLUTFile",
104  "The filename of LUT for inner-most track segments",
106  addParam("OuterTSLUTFile",
108  "The filename of LUT for outer track segments",
110  addParam("RootTRGCDCFile",
112  "The filename of root file for TRGCDC",
113  string("TRGCDC.root"));
114  addParam("RootFitter3DFile",
116  "The filename of root file for Fitter3D",
117  string("Fitter3D.root"));
118  addParam("CurlBackStop",
120  "Curl back stop parameter",
121  _curlBackStop);
122  addParam("SimulationMode",
124  "TRGCDC simulation switch",
126  addParam("FastSimulationMode",
128  "TRGCDC fast simulation mode",
130  addParam("FirmwareSimulationMode",
132  "TRGCDC firmware simulation mode",
134  addParam("FirmwareSimulationStart",
136  "TRGCDC firmware simulation start clock of CDC FE",
138  addParam("FirmwareSimulationStop",
140  "TRGCDC firmware simulation stop clock of CDC FE",
142  addParam("TRGCDCRootFile",
143  _fileTRGCDC,
144  "Flag for making TRGCDC.root",
145  _fileTRGCDC);
146  addParam("TSFLogicLUT",
148  "Use logic or LUT for TSF",
149  _fLogicLUTTSF);
150  addParam("2DFinderPerfect",
152  "2D finder perfect option",
154  addParam("3DFinderPerfect",
156  "3D finder perfect option",
158  addParam("HoughFinderPeakMin",
160  "Hough finder min. peak height",
162  addParam("HoughFinderMappingFilePlus",
164  "Hough finder cell mapping file for charge plus",
166  addParam("HoughFinderMappingFileMinus",
168  "Hough finder cell mapping file for charge minus",
170  addParam("HoughFinderDoit",
171  _hFinderDoit,
172  "Hough finder doit() version",
173  _hFinderDoit);
174  addParam("Fitter3DsLRLUT",
175  _fLRLUT,
176  "Using L/R LUT in fitter3D",
177  _fLRLUT);
178  addParam("Fitter3DsMcLR",
180  "Using MC L/R information for Fitter3D",
182  addParam("Fitter3Ds2DFit",
184  "Using 1: 2D fit or 0: Hough Finder results for Fitter3D",
186  addParam("Fitter3Ds2DFitDrift",
188  "Using 1: drift 2D fit or 0: wire 2D fit for Fitter3D",
190  addParam("wireHitInefficiency",
192  "wire hit inefficiency",
194  addParam("TSFRootFile",
195  _fileTSF,
196  "Flag for making TSF.root",
197  _fileTSF);
198  addParam("ETFRootFile",
199  _fileETF,
200  "Flag for making ETF.root",
201  _fileETF);
202  addParam("verETF",
203  _fverETF,
204  "Select ETF ver, 0:histogram, 1:old Version, 2:True T0",
205  _fverETF);
206  addParam("printFirmETF",
208  "Flag for printing Firmware inputs for ETF",
210  addParam("Hough3DRootFile",
211  _fileHough3D,
212  "Flag for making Hough3D.root",
213  _fileHough3D);
214  addParam("Finder3DMode",
216  "Mode for finder3D",
217  _finder3DMode);
218  addParam("Fitter3DRootFile",
220  "Flag for making Fitter3D.root",
221  _fileFitter3D);
222  addParam("Fitter3DsXtSimple",
224  "0: Use simple xt curve table. 1: use non-linear xt curve table.",
226  addParam("TRGCDCDataInputMode",
228  "Flag for TRG CDC input mode",
230  addParam("inputCollection", m_inputCollectionName,
231  "Name of the CDCHit StoreArray to be used as input.",
232  string(""));
233  addParam("2DfinderCollection", m_2DfinderCollectionName,
234  "Name of the StoreArray holding the tracks made by the 2D finder.",
235  string("Trg2DFinderTracks"));
236  addParam("2DfitterCollection", m_2DfitterCollectionName,
237  "Name of the StoreArray holding the tracks made by the 2D fitter.",
238  string("Trg2DFitterTracks"));
239  addParam("3DfitterCollection", m_3DfitterCollectionName,
240  "Name of the StoreArray holding the tracks made by the 3D fitter.",
241  string("Trg3DFitterTracks"));
242 
243 
244  if (TRGDebug::level())
245  cout << "TRGCDCModule ... created" << endl;
246  }
247 
249  {
250  if (_cdc)
251  TRGCDC::getTRGCDC("good-bye");
252 
253  if (TRGDebug::level())
254  cout << "TRGCDCModule ... destructed " << endl;
255  }
256 
257  void
259  {
260 
261  //...Stop curl buck...
262  if (_curlBackStop) {
263  G4RunManager* g4rm = G4RunManager::GetRunManager();
264  if (g4rm != 0) {
265  if (g4rm->GetUserPhysicsList() != 0) {
266  _sa = new TCSAction();
267  g4rm->SetUserAction(_sa);
268  }
269  }
270  }
272 
273  if (TRGDebug::level()) {
274  cout << "TRGCDCModule::initialize ... options" << endl;
275  cout << TRGDebug::tab(4) << "debug level = " << TRGDebug::level()
276  << endl;
277  cout << TRGDebug::tab(4) << "back stop = " << _curlBackStop << endl;
278  cout << TRGDebug::tab(4) << "2D finder perfect = " << _perfect2DFinder
279  << endl;
280  cout << TRGDebug::tab(4) << "Hough finder Min. Peak = "
281  << _hFinderPeakMin
282  << endl;
283  }
284 
285  // register DataStore elements
287  segmentHits.registerInDataStore();
289  cdcHits.isRequired();
290  StoreArray<MCParticle> mcparticles;
291  segmentHits.registerRelationTo(cdcHits);
292  mcparticles.registerRelationTo(segmentHits);
293  // register tracks only for full simulation (not for TSF simulation)
294  if (!(_fastSimulationMode & 1)) {
298  tracks2Dfinder.registerInDataStore(m_2DfinderCollectionName);
299  tracks2Dfitter.registerInDataStore(m_2DfitterCollectionName);
300  tracks3Dfitter.registerInDataStore(m_3DfitterCollectionName);
301  tracks2Dfinder.registerRelationTo(segmentHits); // hits related over Hough cell
302  tracks2Dfitter.registerRelationTo(segmentHits); // hits used for the 2D fit
303  tracks3Dfitter.registerRelationTo(segmentHits); // hits used for the 2D and 3D fit
304  tracks2Dfinder.registerRelationTo(tracks2Dfitter);
305  tracks2Dfinder.registerRelationTo(tracks3Dfitter);
306  }
307  StoreObjPtr<TRGTiming> eventTime("CDCTriggerEventTime");
308  eventTime.registerInDataStore("CDCTriggerEventTime");
309 
310  //...CDC trigger config. name...
311  static string cfn = _configFilename;
312 
313  //...CDC trigger...
314  if ((cfn != _configFilename) || (_cdc == 0)) {
322  _fileTRGCDC,
332  _hFinderDoit,
334  _fLRLUT,
339  _fileTSF,
340  _fileETF,
341  _fverETF,
343  _fileHough3D,
347  cdc.getTdcBinWidth(),
350  }
351  }
352 
353  void
355  {
356  if (TRGDebug::level())
357  cout << "TRGCDCModule ... beginRun called " << endl;
358  }
359 
360  void
362  {
363  // initialize returnValue
364  _cdc->setReturnValue(0);
365 
366  //...CDC trigger simulation...
367  _cdc->update();
368  _cdc->simulate();
369 
370  // save the results to DataStore
374 
375  // Set return value
376  int returnValue = _cdc->getReturnValue();
377  int mask = 0;
378  for (vector<string>::iterator it = _returnValueModuleNames.begin(); it != _returnValueModuleNames.end(); ++it) {
379  string const& moduleName = *it;
380  if (moduleName == "TSF") mask |= TRGCDC::EReturnValueType::TSF;
381  else if (moduleName == "ETF") mask |= TRGCDC::EReturnValueType::ETF;
382  else if (moduleName == "find2D") mask |= TRGCDC::EReturnValueType::find2D;
383  else if (moduleName == "fit2D") mask |= TRGCDC::EReturnValueType::fit2D;
384  else if (moduleName == "find3D") mask |= TRGCDC::EReturnValueType::find3D;
385  else if (moduleName == "fit3D") mask |= TRGCDC::EReturnValueType::fit3D;
386  }
387  if (mask != 0) returnValue &= mask;
388  setReturnValue(returnValue);
389  }
390 
391  void
393  {
394  if (TRGDebug::level())
395  cout << "TRGCDCModule ... endRun called " << endl;
396  }
397 
398  void
400  {
401 
402  _cdc->terminate();
403 
404  if (TRGDebug::level())
405  cout << "TRGCDCModule ... terminate called " << endl;
406  }
407 
409 } // namespace Belle2
Belle2::TRGCDCModule::_trgCDCDataInputMode
int _trgCDCDataInputMode
Switch for TRG CDC input mode.
Definition: TRGCDCModule.h:201
Belle2::TRGCDCModule::_fFitter3Ds2DFitDrift
bool _fFitter3Ds2DFitDrift
Switch to us wire 2D fit or drift 2D fit.
Definition: TRGCDCModule.h:171
Belle2::TRGCDCModule::_firmwareSimulationMode
int _firmwareSimulationMode
Switch for the firmware simulation. 0:do nothing, 1:do everything.
Definition: TRGCDCModule.h:129
Belle2::TRGCDCModule::_fLRLUT
bool _fLRLUT
Switch for the LR LUT in Fitter3D.
Definition: TRGCDCModule.h:162
Belle2::StoreArray::registerRelationTo
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:150
Belle2::TRGCDCModule::_hFinderDoit
int _hFinderDoit
Hough finder doit version.
Definition: TRGCDCModule.h:156
Belle2::TRGCDCModule::~TRGCDCModule
virtual ~TRGCDCModule()
Destructor.
Definition: TRGCDCModule.cc:248
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
Belle2::TRGDebug::level
static int level(void)
returns the debug level.
Definition: Debug.cc:72
Belle2::TRGCDC::storeSimulationResults
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:2246
Belle2::TRGCDCModule::_fLogicLUTTSF
bool _fLogicLUTTSF
Switch for the Logic/LUT TSF.
Definition: TRGCDCModule.h:159
Belle2::TRGCDCModule::m_inputCollectionName
std::string m_inputCollectionName
Name of the CDCHit StoreArray used as input.
Definition: TRGCDCModule.h:204
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module::c_ParallelProcessingCertified
@ 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:82
Belle2::TRGCDC::simulate
void simulate(void)
fast trigger simulation.
Definition: TRGCDC.cc:2047
Belle2::TRGCDCModule::_perfect2DFinder
bool _perfect2DFinder
Switch to activate perfect 2D finder.
Definition: TRGCDCModule.h:141
Belle2::TRGCDCModule::_curlBackStop
int _curlBackStop
Curl back stop parameter. 0:do nothing, 1:stop curling. Default is 0.
Definition: TRGCDCModule.h:120
Belle2::TRGCDCModule::_wireHitInefficiency
double _wireHitInefficiency
Parameter for Hit inefficiency.
Definition: TRGCDCModule.h:174
Belle2::TRGCDCModule::_returnValueModuleNames
std::vector< std::string > _returnValueModuleNames
returnValue module's name. Can be ["", "TSF", "ETF", "find2D", "fit2D", "find3D", "fit3D"]....
Definition: TRGCDCModule.h:72
Belle2::TRGCDCModule::_fverETF
int _fverETF
Switch for selecting ETF version.
Definition: TRGCDCModule.h:183
Belle2::TRGCDCModule::_fastSimulationMode
int _fastSimulationMode
Switch for the fast simulation. 0:do everything, 1:stop after the track segment simulation....
Definition: TRGCDCModule.h:126
Belle2::TRGCDCModule::version
std::string version(void) const
returns version of TRGCDCModule.
Definition: TRGCDCModule.cc:43
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::TRGCDCModule::_fileTSF
bool _fileTSF
Switch for TSF.root file.
Definition: TRGCDCModule.h:177
Belle2::Module::setPropertyFlags
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:210
Belle2::TRGCDCModule::m_2DfinderCollectionName
std::string m_2DfinderCollectionName
Name of the StoreArray holding the tracks made by the 2D finder.
Definition: TRGCDCModule.h:206
Belle2::TRGCDCModule::_rootFitter3DFilename
std::string _rootFitter3DFilename
The filename of root file for Fitter3D.
Definition: TRGCDCModule.h:117
Belle2::CDC::CDCGeometryPar
The Class for CDC Geometry Parameters.
Definition: CDCGeometryPar.h:75
Belle2::TRGCDC::getReturnValue
int getReturnValue(void) const
gets return value for trg cdc module.
Definition: TRGCDC.h:1099
Belle2::TRGCDCModule::m_2DfitterCollectionName
std::string m_2DfitterCollectionName
Name of the StoreArray holding the tracks made by the 2D fitter.
Definition: TRGCDCModule.h:208
Belle2::TRGCDCModule::initialize
virtual void initialize() override
Initilizes TRGCDCModule.
Definition: TRGCDCModule.cc:258
Belle2::TRGCDCModule::_configFilename
std::string _configFilename
Config. file name.
Definition: TRGCDCModule.h:69
Belle2::CDC::CDCGeometryPar::Instance
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
Definition: CDCGeometryPar.cc:41
Belle2::TRGCDCModule::terminate
virtual void terminate() override
Called when processing ended.
Definition: TRGCDCModule.cc:399
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TRGCDCModule::_debugLevel
int _debugLevel
Debug level.
Definition: TRGCDCModule.h:66
Belle2::TRGCDCModule::_fileFitter3D
bool _fileFitter3D
Switch for Fitter3D.root file.
Definition: TRGCDCModule.h:195
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::TRGCDCModule::_rootTRGCDCFilename
std::string _rootTRGCDCFilename
The filename of root file for TRGCDC.
Definition: TRGCDCModule.h:114
Belle2::TRGCDC::getTRGCDC
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:190
Belle2::TRGCDCModule::_cdc
TRGCDC * _cdc
A pointer to a TRGCDC;.
Definition: TRGCDCModule.h:215
Belle2::TRGCDCModule::m_3DfitterCollectionName
std::string m_3DfitterCollectionName
Name of the StoreArray holding the tracks made by the 3D fitter.
Definition: TRGCDCModule.h:210
Belle2::TRGCDCModule::_sa
TRGCDCSteppingAction * _sa
A pointer to a TRGCDCSteppingAction which stops curl backs.
Definition: TRGCDCModule.h:218
Belle2::TRGCDCModule::_fileTRGCDC
bool _fileTRGCDC
Switch for TRGCDC.root file.
Definition: TRGCDCModule.h:138
Belle2::Module::setReturnValue
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:222
Belle2::TRGCDC::setReturnValue
void setReturnValue(EReturnValueType const &moduleName, bool flag)
sets return value for trg cdc module.
Definition: TRGCDC.cc:2745
Belle2::TRGCDCModule::_hFinderMappingFileMinus
std::string _hFinderMappingFileMinus
Hough mapping file for charge minus.
Definition: TRGCDCModule.h:153
Belle2::TRGCDCModule::endRun
virtual void endRun() override
Called when run ended.
Definition: TRGCDCModule.cc:392
Belle2::TRGCDC::update
void update()
updates TRGCDC wire information. clear() is called in this function.
Definition: TRGCDC.cc:982
Belle2::TRGCDCModule::_fXtSimpleFitter3D
bool _fXtSimpleFitter3D
Switch for using simple x-t curve or non-linear x-t curve. 0: non-linear 1: simple.
Definition: TRGCDCModule.h:198
Belle2::Module::addParam
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:562
Belle2::TRGCDCModule::_perfect3DFinder
bool _perfect3DFinder
Switch to activate perfect 3D finder.
Definition: TRGCDCModule.h:144
Belle2::TRGCDCModule::_fprintFirmETF
bool _fprintFirmETF
Switch for printing Firmware inputs for ETF.
Definition: TRGCDCModule.h:186
Belle2::TRGCDCModule::_fileETF
bool _fileETF
Switch for ETF.root file.
Definition: TRGCDCModule.h:180
Belle2::TRGDebug::tab
static std::string tab(void)
returns tab spaces.
Definition: Debug.cc:52
Belle2::TRGCDCModule::_fFitter3Dsmclr
bool _fFitter3Dsmclr
Switch for Fitter3D's MC L/R information.
Definition: TRGCDCModule.h:165
Belle2::TRGCDCModule::_innerTSLUTFilename
std::string _innerTSLUTFilename
The filename of LUT for the inner-most track segments.(tmp)
Definition: TRGCDCModule.h:81
Belle2::TRGCDCModule::_hFinderMappingFilePlus
std::string _hFinderMappingFilePlus
Hough mapping file for charge plus.
Definition: TRGCDCModule.h:150
Belle2::TRGCDCModule::_firmwareSimulationStop
int _firmwareSimulationStop
Stop clock for the firmware simultion. (clock=cdcfe)
Definition: TRGCDCModule.h:135
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::TRGCDC::terminate
void terminate(void)
terminates when run is finished
Definition: TRGCDC.cc:737
Belle2::TRGCDCModule::_outerTSLUTFilename
std::string _outerTSLUTFilename
The filename of LUT for outer track segments.(tmp)
Definition: TRGCDCModule.h:84
Belle2::TRGCDCModule::_fileHough3D
bool _fileHough3D
Switch for Hough3D.root file.
Definition: TRGCDCModule.h:189
Belle2::TRGCDCModule::beginRun
virtual void beginRun() override
Called when new run started.
Definition: TRGCDCModule.cc:354
Belle2::TRGCDCModule::_firmwareSimulationStart
int _firmwareSimulationStart
Start clock for the firmware simultion. (clock=cdcfe)
Definition: TRGCDCModule.h:132
Belle2::TRGCDCModule::event
virtual void event() override
Called event by event.
Definition: TRGCDCModule.cc:361
Belle2::TRGCDCModule::_finder3DMode
int _finder3DMode
Sets mode of 3DFinder.
Definition: TRGCDCModule.h:192
Belle2::TRGCDCModule::_hFinderPeakMin
int _hFinderPeakMin
Min. peak height for the Hough finder.
Definition: TRGCDCModule.h:147
Belle2::TRGCDCModule::_fFitter3Ds2DFit
bool _fFitter3Ds2DFit
Switch to us 2D fit or Hough finder results.
Definition: TRGCDCModule.h:168
Belle2::TRGCDCModule::_simulationMode
int _simulationMode
Mode for TRGCDC simulation. 0th bit : fast simulation switch, 1st bit : firmware simulation switch.
Definition: TRGCDCModule.h:123