Belle II Software  release-06-01-15
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 
15 using namespace std;
16 using namespace Belle2;
17 
18 
19 //-----------------------------------------------------------------
20 // Register the Module
21 //-----------------------------------------------------------------
22 REG_MODULE(SecMapTrainerBase)
23 
24 //-----------------------------------------------------------------
25 // Implementation
26 //-----------------------------------------------------------------
27 
28 
29 SecMapTrainerBaseModule::SecMapTrainerBaseModule() :
31  Module(),
32  m_eventData("EventMetaData", DataStore::c_Event)
33 {
34  InitializeVariables();
35 
36  //Set module properties
37  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  setPropertyFlags(c_ParallelProcessingCertified | c_TerminateInAllProcesses);
39 
40  addParam("spTCarrayName", m_PARAMspTCarrayName,
41  "the name of the storeArray containing the SpacePointTrackCands used for the secMap-generation", string(""));
42 
43  addParam("allowTraining", m_PARAMallowTraining,
44  "If true, training will be executed and filled into rootFiles, if not, only things like basf2 -m work but no training can be done",
45  bool(false));
46 
47 
48  if (m_PARAMallowTraining == false) return;
49 }
50 
51 
53 void SecMapTrainerBaseModule::initialize()
54 {
55  B2INFO("~~~~~~~~~~~SecMapTrainerBaseModule - initialize ~~~~~~~~~~");
56  if (m_PARAMallowTraining == false)
57  B2FATAL("you want to execute SecMapTrainerVXDTF but the parameter 'allowTraining' is false! Aborting...");
58 
59  // small lambda for getting random numbers:
60  auto rngAppendix = []() -> int { return gRandom->Integer(std::numeric_limits<int>::max()); };
61  // What does it mean "Appendix"? E.P.
62 
63 
65  for (auto setup : filtersContainer.getAllSetups()) {
66  auto config = setup.second->getConfig();
67  SecMapTrainer<SelectionVariableFactory<SecMapTrainerHit> > newMap(setup.first, std::to_string(rngAppendix()));
68  m_secMapTrainers.push_back(std::move(newMap));
69  }
70 
71  for (auto& trainer : m_secMapTrainers) {
72  trainer.initialize();
73  }
75 }
76 
77 
80 {
81  //get the data
82  int thisExperiment = m_eventData->getExperiment();
83  int thisRun = m_eventData->getRun();
84  int thisEvent = m_eventData->getEvent();
85  B2DEBUG(5, "~~~~~~~~~~~SecMapTrainerBaseModule - experiment/run/event " << thisExperiment << "/" << thisRun << "/" << thisEvent <<
86  " ~~~~~~~~~~");
87 
88  for (auto& trainer : m_secMapTrainers) {
89  trainer.initializeEvent(thisExperiment, thisRun, thisEvent);
90  }
91 
92  //simulated particles and hits
93  unsigned nSPTCs = m_spacePointTrackCands.getEntries();
94 
95  if (nSPTCs == 0) {
96  B2DEBUG(1, "event " << thisEvent << ": there is no SpacePointTrackCandidate!");
97  return;
98  }
99  B2DEBUG(5, "SecMapTrainerBaseModule, event " << thisEvent << ": size of array nSpacePointTrackCands: " << nSPTCs);
100 
101 
103  unsigned nAccepted = 0;
104  for (unsigned iTC = 0; iTC not_eq nSPTCs; ++ iTC) {
105  const SpacePointTrackCand* currentTC = m_spacePointTrackCands[iTC];
106  B2DEBUG(10, "current SPTC has got " << currentTC->getNHits() << " hits stored");
107 
108  for (auto& trainer : m_secMapTrainers) {
109  B2DEBUG(10, "current SPTC will now be checked with secMap " << trainer.getConfig().secMapName << " hits stored");
110  bool accepted = trainer.storeTC(*currentTC, iTC);
111  nAccepted += (accepted ? 1 : 0);
112  }
113  }
114  B2DEBUG(5, "SecMapTrainerBaseModule, event " << thisEvent << ": number of TCs total/accepted: " << nSPTCs << "/" << nAccepted);
115 
116 
117  // process raw data:
118  for (auto& trainer : m_secMapTrainers) {
119  unsigned nTCsProcessed = trainer.processTracks();
120 
121  B2DEBUG(5, "SecMapTrainerBaseModule, event " << thisEvent << " with mapTrainer " << trainer.getConfig().secMapName <<
122  ": number of TCs processed: " << nTCsProcessed <<
123  ", calculations done!");
124  }
125 }
126 
127 
128 
129 
132 {
133  B2DEBUG(1, " SecMapTrainerBaseModule::terminate:: start.");
134  for (auto& trainer : m_secMapTrainers) {
135  trainer.terminate();
136  }
137  B2INFO(" SecMapTrainerBaseModule, everything is done. Terminating.");
138 }
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
std::string m_PARAMspTCarrayName
Name of storeArray containing the spacePointTrackCands.
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 ...
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
#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.