Belle II Software development
SecMapTrainerBaseModule.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/modules/VXDTFHelperTools/SecMapTrainerBaseModule.h>
10#include <tracking/trackFindingVXD/filterMap/map/FiltersContainer.h>
11#include "framework/datastore/StoreObjPtr.h"
12
13#include <TRandom.h>
14
15using namespace Belle2;
16
17
18//-----------------------------------------------------------------
19// Register the Module
20//-----------------------------------------------------------------
21REG_MODULE(SecMapTrainerBase);
22
23//-----------------------------------------------------------------
24// Implementation
25//-----------------------------------------------------------------
26
27
30 Module(),
31 m_eventData("EventMetaData", DataStore::c_Event)
32{
34
35 //Set module properties
36 setDescription("this module analyzes a big number of events (pGun or evtGen) to create raw sectorMaps which are needed for the VXDTF 2.0. This information will be exported via root files.");
38
39 addParam("spTCarrayName", m_PARAMspTCarrayName,
40 "the name of the storeArray containing the SpacePointTrackCands used for the secMap-generation", std::string(""));
41
42 addParam("allowTraining", m_PARAMallowTraining,
43 "If true, training will be executed and filled into rootFiles, if not, only things like basf2 -m work but no training can be done",
44 bool(false));
45
46
47 if (m_PARAMallowTraining == false) return;
48}
49
50
53{
54 B2INFO("~~~~~~~~~~~SecMapTrainerBaseModule - initialize ~~~~~~~~~~");
55 if (m_PARAMallowTraining == false)
56 B2FATAL("you want to execute SecMapTrainerVXDTF but the parameter 'allowTraining' is false! Aborting...");
57
58 // small lambda for getting random numbers:
59 auto rngAppendix = []() -> int { return gRandom->Integer(std::numeric_limits<int>::max()); };
60 // What does it mean "Appendix"? E.P.
61
62
64 for (auto setup : filtersContainer.getAllSetups()) {
65 auto config = setup.second->getConfig();
66 SecMapTrainer<SelectionVariableFactory<SecMapTrainerHit> > newMap(setup.first, std::to_string(rngAppendix()));
67 m_secMapTrainers.push_back(std::move(newMap));
68 }
69
70 for (auto& trainer : m_secMapTrainers) {
71 trainer.initialize();
72 }
74}
75
76
79{
80 //get the data
81 int thisExperiment = m_eventData->getExperiment();
82 int thisRun = m_eventData->getRun();
83 int thisEvent = m_eventData->getEvent();
84 B2DEBUG(5, "~~~~~~~~~~~SecMapTrainerBaseModule - experiment/run/event " << thisExperiment << "/" << thisRun << "/" << thisEvent <<
85 " ~~~~~~~~~~");
86
87 for (auto& trainer : m_secMapTrainers) {
88 trainer.initializeEvent(thisExperiment, thisRun, thisEvent);
89 }
90
91 //simulated particles and hits
92 unsigned nSPTCs = m_spacePointTrackCands.getEntries();
93
94 if (nSPTCs == 0) {
95 B2DEBUG(1, "event " << thisEvent << ": there is no SpacePointTrackCandidate!");
96 return;
97 }
98 B2DEBUG(5, "SecMapTrainerBaseModule, event " << thisEvent << ": size of array nSpacePointTrackCands: " << nSPTCs);
99
100
102 unsigned nAccepted = 0;
103 for (unsigned iTC = 0; iTC not_eq nSPTCs; ++ iTC) {
104 const SpacePointTrackCand* currentTC = m_spacePointTrackCands[iTC];
105 B2DEBUG(10, "current SPTC has got " << currentTC->getNHits() << " hits stored");
106
107 for (auto& trainer : m_secMapTrainers) {
108 B2DEBUG(10, "current SPTC will now be checked with secMap " << trainer.getConfig().secMapName << " hits stored");
109 bool accepted = trainer.storeTC(*currentTC, iTC);
110 nAccepted += (accepted ? 1 : 0);
111 }
112 }
113 B2DEBUG(5, "SecMapTrainerBaseModule, event " << thisEvent << ": number of TCs total/accepted: " << nSPTCs << "/" << nAccepted);
114
115
116 // process raw data:
117 for (auto& trainer : m_secMapTrainers) {
118 unsigned nTCsProcessed = trainer.processTracks();
119
120 B2DEBUG(5, "SecMapTrainerBaseModule, event " << thisEvent << " with mapTrainer " << trainer.getConfig().secMapName <<
121 ": number of TCs processed: " << nTCsProcessed <<
122 ", calculations done!");
123 }
124}
125
126
127
128
131{
132 B2DEBUG(1, " SecMapTrainerBaseModule::terminate:: start.");
133 for (auto& trainer : m_secMapTrainers) {
134 trainer.terminate();
135 }
136 B2INFO(" SecMapTrainerBaseModule, everything is done. Terminating.");
137}
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
void initialize() override
initialize.
std::string m_PARAMspTCarrayName
Name of storeArray containing the spacePointTrackCands.
void InitializeVariables()
initialize variables to avoid nondeterministic behavior.
StoreObjPtr< EventMetaData > m_eventData
Event Data for distinguishing events.
bool m_PARAMallowTraining
If true, training will be executed and filled into rootFiles, if not, only things like basf2 -m work ...
SecMapTrainerBaseModule()
SecMapTrainerVXDTFModule constructor.
StoreArray< SpacePointTrackCand > m_spacePointTrackCands
contains the spacePointTrackCands to be analyzed for the secMap-Training.
std::vector< SecMapTrainer< SelectionVariableFactory< SecMapTrainerHit > > > m_secMapTrainers
contains the trainers for the secMaps to be trained.
This class contains all relevant tools for training a VXDTFFilters.
Definition: SecMapTrainer.h:43
Storage for (VXD) SpacePoint-based track candidates.
unsigned int getNHits() const
get the number of hits (space points) in the track candidate
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
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.