Belle II Software  release-08-01-10
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 
19 using namespace Belle2;
20 
21 REG_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 
50 {
51 
53 
55 
56  for (auto setup : filtersContainer.getAllSetups()) {
57  auto config = setup.second->getConfig();
58 
59  std::string nameAppendix = m_PARAMNameTag;
60  // if the name tag was not set a random number will be attached!
61  if (nameAppendix == std::string("")) {
62  int randomInt = gRandom->Integer(std::numeric_limits<int>::max());
63  nameAppendix = std::to_string(randomInt);
64  }
65 
67  newMap(setup.first, nameAppendix);
68 
69  m_secMapTrainers.push_back(std::move(newMap));
70 
71  }
72 
73  for (auto& trainer : m_secMapTrainers) {
74  trainer.initialize();
75  }
76 
77 
78 }
79 
80 
83 {
84  //get the data
85  int thisExperiment = m_eventData->getExperiment();
86  int thisRun = m_eventData->getRun();
87  int thisEvent = m_eventData->getEvent();
88 
89  for (auto& collector : m_secMapTrainers)
90  collector.initializeEvent(thisExperiment, thisRun, thisEvent);
91 
92 
93  // number of space point track candidates from the MC track finder
94  unsigned nSPTCs = m_spacePointTrackCands.getEntries();
95 
98 
99  for (unsigned iTC = 0; iTC < nSPTCs; ++ iTC) {
100  const SpacePointTrackCand* currentTC = m_spacePointTrackCands[iTC];
101  for (auto& dataCollector : m_secMapTrainers)
102  dataCollector.storeTC(*currentTC, iTC);
103  }
104 
105  // process raw data:
106  for (auto& dataCollector : m_secMapTrainers) {
107  unsigned nTCsProcessed = dataCollector.processTracks();
108 
109  B2DEBUG(20,
110  "VXDTFTrainingDataCollectorModule, event " << thisEvent <<
111  " with mapTrainer " << dataCollector.getConfig().secMapName <<
112  ": number of TCs processed: " << nTCsProcessed <<
113  ", calculations done!");
114  }
115 }
116 
121 {
122  for (auto& dataCollector : m_secMapTrainers)
123  dataCollector.terminate();
124 }
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.
REG_MODULE(arichBtest)
Register the Module.
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
Abstract base class for different kinds of events.