Belle II Software  release-06-02-00
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 std;
20 using namespace Belle2;
21 
22 REG_MODULE(VXDTFTrainingDataCollector)
23 
24 
29  Module(),
30  m_eventData("EventMetaData", DataStore::c_Event)
31 {
32 
33  //Set module properties
34  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.");
35  setPropertyFlags(c_ParallelProcessingCertified |
36  c_TerminateInAllProcesses);
37 
38  addParam("SpacePointTrackCandsName", m_PARAMSpacePointTrackCandsName,
39  "the name of the storeArray containing the SpacePointTrackCands used for extracting and collecting the training data.", 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 
49 void VXDTFTrainingDataCollectorModule::initialize()
50 {
51 
53 
54  m_spacePointTrackCands.isRequired(m_PARAMSpacePointTrackCandsName);
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 
82 void VXDTFTrainingDataCollectorModule::event()
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(5,
110  "VXDTFTrainingDataCollectorModule, event " << thisEvent <<
111  " with mapTrainer " << dataCollector.getConfig().secMapName <<
112  ": number of TCs processed: " << nTCsProcessed <<
113  ", calculations done!");
114  }
115 }
116 
120 void VXDTFTrainingDataCollectorModule::terminate()
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
Store event, run, and experiment numbers.
Definition: EventMetaData.h:33
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
This class contains all relevant tools for training a VXDTFFilters.
Definition: SecMapTrainer.h:43
Storage for (VXD) SpacePoint-based track candidates.
#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.