Belle II Software  release-05-01-25
VXDTFTrainingDataCollectorModule.cc
1 /**************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2012 - Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: Jakob Lettenbichler *
7 * *
8 * This software is provided "as is" without any warranty. *
9 **************************************************************************/
10 
11 #include <tracking/trackFindingVXD/filterMap/map/FiltersContainer.h>
12 #include <tracking/trackFindingVXD/sectorMapTools/SecMapTrainer.h>
13 
14 #include <tracking/modules/vxdtfRedesign/VXDTFTrainingDataCollectorModule.h>
15 
16 #include <framework/logging/Logger.h>
17 #include <framework/datastore/StoreObjPtr.h>
18 
19 #include <TRandom.h>
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 REG_MODULE(VXDTFTrainingDataCollector)
25 
26 
31  Module(),
32  m_eventData("EventMetaData", DataStore::c_Event)
33 {
34 
35  //Set module properties
36  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.");
37  setPropertyFlags(c_ParallelProcessingCertified |
38  c_TerminateInAllProcesses);
39 
40  addParam("SpacePointTrackCandsName", m_PARAMSpacePointTrackCandsName,
41  "the name of the storeArray containing the SpacePointTrackCands used for extracting and collecting the training data.", string(""));
42 
43  addParam("NameTag", m_PARAMNameTag, "A name tag that will be attached to the name of the output file. If left empty (\"\") a "
44  "random number will be attached!", std::string(""));
45 }
46 
51 void VXDTFTrainingDataCollectorModule::initialize()
52 {
53 
55 
56  m_spacePointTrackCands.isRequired(m_PARAMSpacePointTrackCandsName);
57 
58  for (auto setup : filtersContainer.getAllSetups()) {
59  auto config = setup.second->getConfig();
60 
61  std::string nameAppendix = m_PARAMNameTag;
62  // if the name tag was not set a random number will be attached!
63  if (nameAppendix == std::string("")) {
64  int randomInt = gRandom->Integer(std::numeric_limits<int>::max());
65  nameAppendix = std::to_string(randomInt);
66  }
67 
69  newMap(setup.first, nameAppendix);
70 
71  m_secMapTrainers.push_back(std::move(newMap));
72 
73  }
74 
75  for (auto& trainer : m_secMapTrainers) {
76  trainer.initialize();
77  }
78 
79 
80 }
81 
82 
84 void VXDTFTrainingDataCollectorModule::event()
85 {
86  //get the data
87  int thisExperiment = m_eventData->getExperiment();
88  int thisRun = m_eventData->getRun();
89  int thisEvent = m_eventData->getEvent();
90 
91  for (auto& collector : m_secMapTrainers)
92  collector.initializeEvent(thisExperiment, thisRun, thisEvent);
93 
94 
95  // number of space point track candidates from the MC track finder
96  unsigned nSPTCs = m_spacePointTrackCands.getEntries();
97 
100 
101  for (unsigned iTC = 0; iTC < nSPTCs; ++ iTC) {
102  const SpacePointTrackCand* currentTC = m_spacePointTrackCands[iTC];
103  for (auto& dataCollector : m_secMapTrainers)
104  dataCollector.storeTC(*currentTC, iTC);
105  }
106 
107  // process raw data:
108  for (auto& dataCollector : m_secMapTrainers) {
109  unsigned nTCsProcessed = dataCollector.processTracks();
110 
111  B2DEBUG(5,
112  "VXDTFTrainingDataCollectorModule, event " << thisEvent <<
113  " with mapTrainer " << dataCollector.getConfig().secMapName <<
114  ": number of TCs processed: " << nTCsProcessed <<
115  ", calculations done!");
116  }
117 }
118 
122 void VXDTFTrainingDataCollectorModule::terminate()
123 {
124  for (auto& dataCollector : m_secMapTrainers)
125  dataCollector.terminate();
126 }
setup
Belle2::FiltersContainer
This class contains everything needed by the VXDTF that is not going to change during a RUN,...
Definition: FiltersContainer.h:38
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VXDTFTrainingDataCollectorModule
The VXDTFTrainingDataCollectorModule.
Definition: VXDTFTrainingDataCollectorModule.h:52
Belle2::FiltersContainer::getInstance
static FiltersContainer & getInstance()
one and only way to access the singleton object
Definition: FiltersContainer.h:64
Belle2::FiltersContainer::getAllSetups
const setupNameToFilters_t & getAllSetups(void)
returns all the available setups.
Definition: FiltersContainer.h:91
Belle2::EventMetaData
Store event, run, and experiment numbers.
Definition: EventMetaData.h:43
Belle2::SecMapTrainer
This class contains all relevant tools for training a VXDTFFilters.
Definition: SecMapTrainer.h:53
Belle2::DataStore
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:53
Belle2::SpacePointTrackCand
Storage for (VXD) SpacePoint-based track candidates.
Definition: SpacePointTrackCand.h:51