Belle II Software development
VXDTFTrainingDataCollectorModule.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#include <tracking/trackFindingVXD/filterMap/map/FiltersContainer.h>
10#include <tracking/trackFindingVXD/sectorMapTools/SecMapTrainer.h>
11
12#include <tracking/modules/vxdtfRedesign/VXDTFTrainingDataCollectorModule.h>
13
14#include <framework/logging/Logger.h>
15#include <framework/datastore/StoreObjPtr.h>
16
17#include <TRandom.h>
18
19using namespace Belle2;
20
21REG_MODULE(VXDTFTrainingDataCollector);
22
28 Module(),
29 m_eventData("EventMetaData", DataStore::c_Event)
30{
31
32 //Set module properties
33 setDescription("This module collect the data needed to train the VXDTF sector map. The data are saved on a root file that eventually will be chained and used by the training module.");
36
37 addParam("SpacePointTrackCandsName", m_PARAMSpacePointTrackCandsName,
38 "the name of the storeArray containing the SpacePointTrackCands used for extracting and collecting the training data.",
39 std::string(""));
40
41 addParam("NameTag", m_PARAMNameTag, "A name tag that will be attached to the name of the output file. If left empty (\"\") a "
42 "random number will be attached!", std::string(""));
43
44 addParam("outputDir", m_PARAMoutputDir,
45 "Name of the output directory. The output file created by this module will be written into that directory.", m_PARAMoutputDir);
46}
47
53{
54
56
58
59 for (auto setup : filtersContainer.getAllSetups()) {
60 auto config = setup.second->getConfig();
61
62 std::string nameAppendix = m_PARAMNameTag;
63 // if the name tag was not set a random number will be attached!
64 if (nameAppendix == std::string("")) {
65 int randomInt = gRandom->Integer(std::numeric_limits<int>::max());
66 nameAppendix = std::to_string(randomInt);
67 }
68
70 newMap(setup.first, nameAppendix, m_PARAMoutputDir);
71
72 m_secMapTrainers.push_back(std::move(newMap));
73
74 }
75
76 for (auto& trainer : m_secMapTrainers) {
77 trainer.initialize();
78 }
79
80
81}
82
83
86{
87 //get the data
88 int thisExperiment = m_eventData->getExperiment();
89 int thisRun = m_eventData->getRun();
90 int thisEvent = m_eventData->getEvent();
91
92 for (auto& collector : m_secMapTrainers)
93 collector.initializeEvent(thisExperiment, thisRun, thisEvent);
94
95
96 // number of space point track candidates from the MC track finder
97 unsigned nSPTCs = m_spacePointTrackCands.getEntries();
98
101
102 for (unsigned iTC = 0; iTC < nSPTCs; ++ iTC) {
103 const SpacePointTrackCand* currentTC = m_spacePointTrackCands[iTC];
104 for (auto& dataCollector : m_secMapTrainers)
105 dataCollector.storeTC(*currentTC, iTC);
106 }
107
108 // process raw data:
109 for (auto& dataCollector : m_secMapTrainers) {
110 unsigned nTCsProcessed = dataCollector.processTracks();
111
112 B2DEBUG(20,
113 "VXDTFTrainingDataCollectorModule, event " << thisEvent <<
114 " with mapTrainer " << dataCollector.getConfig().secMapName <<
115 ": number of TCs processed: " << nTCsProcessed <<
116 ", calculations done!");
117 }
118}
119
124{
125 for (auto& dataCollector : m_secMapTrainers)
126 dataCollector.terminate();
127}
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:51
This class contains everything needed by the VXDTF that is not going to change during a RUN,...
static FiltersContainer & getInstance()
one and only way to access the singleton object
const setupNameToFilters_t & getAllSetups(void)
returns all the available setups.
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
@ c_TerminateInAllProcesses
When using parallel processing, call this module's terminate() function in all processes().
Definition: Module.h:83
This class contains all relevant tools for training a VXDTFFilters.
Definition: SecMapTrainer.h:43
Storage for (VXD) SpacePoint-based track candidates.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
VXDTFTrainingDataCollectorModule()
VXDTFTrainingDataCollectorModule constructor.
std::string m_PARAMSpacePointTrackCandsName
Name of storeArray containing the spacePointTrackCands.
std::string m_PARAMNameTag
Name tag that will be attached to the output file.
StoreObjPtr< EventMetaData > m_eventData
Event meta data of the event.
StoreArray< SpacePointTrackCand > m_spacePointTrackCands
spacePointTrackCands to be digested.
std::vector< SecMapTrainer< SelectionVariableFactory< SecMapTrainerHit > > > m_secMapTrainers
Names of the variables to be produced and collected.
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
Abstract base class for different kinds of events.