Belle II Software  release-05-02-19
SecMapTrainerBaseModule.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/modules/VXDTFHelperTools/SecMapTrainerBaseModule.h>
12 #include <tracking/trackFindingVXD/filterMap/map/FiltersContainer.h>
13 #include "framework/datastore/StoreObjPtr.h"
14 
15 #include <TRandom.h>
16 
17 using namespace std;
18 using namespace Belle2;
19 
20 
21 //-----------------------------------------------------------------
22 // Register the Module
23 //-----------------------------------------------------------------
24 REG_MODULE(SecMapTrainerBase)
25 
26 //-----------------------------------------------------------------
27 // Implementation
28 //-----------------------------------------------------------------
29 
30 
31 SecMapTrainerBaseModule::SecMapTrainerBaseModule() :
33  Module(),
34  m_eventData("EventMetaData", DataStore::c_Event)
35 {
36  InitializeVariables();
37 
38  //Set module properties
39  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.");
41 
42  addParam("spTCarrayName", m_PARAMspTCarrayName,
43  "the name of the storeArray containing the SpacePointTrackCands used for the secMap-generation", string(""));
44 
45  addParam("allowTraining", m_PARAMallowTraining,
46  "If true, training will be executed and filled into rootFiles, if not, only things like basf2 -m work but no training can be done",
47  bool(false));
48 
49 
50  if (m_PARAMallowTraining == false) return;
51 }
52 
53 
56 {
57  B2INFO("~~~~~~~~~~~SecMapTrainerBaseModule - initialize ~~~~~~~~~~");
58  if (m_PARAMallowTraining == false)
59  B2FATAL("you want to execute SecMapTrainerVXDTF but the parameter 'allowTraining' is false! Aborting...");
60 
61  // small lambda for getting random numbers:
62  auto rngAppendix = []() -> int { return gRandom->Integer(std::numeric_limits<int>::max()); };
63  // What does it mean "Appendix"? E.P.
64 
65 
67  for (auto setup : filtersContainer.getAllSetups()) {
68  auto config = setup.second->getConfig();
69  SecMapTrainer<SelectionVariableFactory<SecMapTrainerHit> > newMap(setup.first, std::to_string(rngAppendix()));
70  m_secMapTrainers.push_back(std::move(newMap));
71  }
72 
73  for (auto& trainer : m_secMapTrainers) {
74  trainer.initialize();
75  }
77 }
78 
79 
82 {
83  //get the data
84  int thisExperiment = m_eventData->getExperiment();
85  int thisRun = m_eventData->getRun();
86  int thisEvent = m_eventData->getEvent();
87  B2DEBUG(5, "~~~~~~~~~~~SecMapTrainerBaseModule - experiment/run/event " << thisExperiment << "/" << thisRun << "/" << thisEvent <<
88  " ~~~~~~~~~~");
89 
90  for (auto& trainer : m_secMapTrainers) {
91  trainer.initializeEvent(thisExperiment, thisRun, thisEvent);
92  }
93 
94  //simulated particles and hits
95  unsigned nSPTCs = m_spacePointTrackCands.getEntries();
96 
97  if (nSPTCs == 0) {
98  B2DEBUG(1, "event " << thisEvent << ": there is no SpacePointTrackCandidate!");
99  return;
100  }
101  B2DEBUG(5, "SecMapTrainerBaseModule, event " << thisEvent << ": size of array nSpacePointTrackCands: " << nSPTCs);
102 
103 
105  unsigned nAccepted = 0;
106  for (unsigned iTC = 0; iTC not_eq nSPTCs; ++ iTC) {
107  const SpacePointTrackCand* currentTC = m_spacePointTrackCands[iTC];
108  B2DEBUG(10, "current SPTC has got " << currentTC->getNHits() << " hits stored");
109 
110  for (auto& trainer : m_secMapTrainers) {
111  B2DEBUG(10, "current SPTC will now be checked with secMap " << trainer.getConfig().secMapName << " hits stored");
112  bool accepted = trainer.storeTC(*currentTC, iTC);
113  nAccepted += (accepted ? 1 : 0);
114  }
115  }
116  B2DEBUG(5, "SecMapTrainerBaseModule, event " << thisEvent << ": number of TCs total/accepted: " << nSPTCs << "/" << nAccepted);
117 
118 
119  // process raw data:
120  for (auto& trainer : m_secMapTrainers) {
121  unsigned nTCsProcessed = trainer.processTracks();
122 
123  B2DEBUG(5, "SecMapTrainerBaseModule, event " << thisEvent << " with mapTrainer " << trainer.getConfig().secMapName <<
124  ": number of TCs processed: " << nTCsProcessed <<
125  ", calculations done!");
126  }
127 }
128 
129 
130 
131 
134 {
135  B2DEBUG(1, " SecMapTrainerBaseModule::terminate:: start.");
136  for (auto& trainer : m_secMapTrainers) {
137  trainer.terminate();
138  }
139  B2INFO(" SecMapTrainerBaseModule, everything is done. Terminating.");
140 }
setup
Belle2::FiltersContainer
This class contains everything needed by the VXDTF that is not going to change during a RUN,...
Definition: FiltersContainer.h:38
Belle2::SecMapTrainerBaseModule::initialize
void initialize() override
initialize.
Definition: SecMapTrainerBaseModule.cc:55
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
Belle2::SecMapTrainerBaseModule::event
void event() override
event.
Definition: SecMapTrainerBaseModule.cc:81
Belle2::SecMapTrainerBaseModule::m_secMapTrainers
std::vector< SecMapTrainer< SelectionVariableFactory< SecMapTrainerHit > > > m_secMapTrainers
contains the trainers for the secMaps to be trained.
Definition: SecMapTrainerBaseModule.h:83
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module::c_ParallelProcessingCertified
@ 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:82
Belle2::Module::c_TerminateInAllProcesses
@ c_TerminateInAllProcesses
When using parallel processing, call this module's terminate() function in all processes().
Definition: Module.h:85
Belle2::SecMapTrainerBaseModule::m_PARAMspTCarrayName
std::string m_PARAMspTCarrayName
Name of storeArray containing the spacePointTrackCands.
Definition: SecMapTrainerBaseModule.h:90
Belle2::SecMapTrainerBaseModule::m_spacePointTrackCands
StoreArray< SpacePointTrackCand > m_spacePointTrackCands
contains the spacePointTrackCands to be analyzed for the secMap-Training.
Definition: SecMapTrainerBaseModule.h:80
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::SpacePointTrackCand::getNHits
unsigned int getNHits() const
get the number of hits (space points) in the track candidate
Definition: SpacePointTrackCand.h:154
Belle2::Module::setPropertyFlags
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:210
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SecMapTrainerBaseModule::m_eventData
StoreObjPtr< EventMetaData > m_eventData
Event Data for distinguishing events.
Definition: SecMapTrainerBaseModule.h:77
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::Module::addParam
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:562
Belle2::SecMapTrainerBaseModule::m_PARAMallowTraining
bool m_PARAMallowTraining
If true, training will be executed and filled into rootFiles, if not, only things like basf2 -m work ...
Definition: SecMapTrainerBaseModule.h:87
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::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::SpacePointTrackCand
Storage for (VXD) SpacePoint-based track candidates.
Definition: SpacePointTrackCand.h:51
Belle2::SecMapTrainerBaseModule::terminate
void terminate() override
terminate.
Definition: SecMapTrainerBaseModule.cc:133