Belle II Software  release-05-01-25
SecMapTrainerVXDTFModule.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/SecMapTrainerVXDTFModule.h>
12 
13 #include <TRandom.h>
14 
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 
20 //-----------------------------------------------------------------
21 // Register the Module
22 //-----------------------------------------------------------------
23 REG_MODULE(SecMapTrainerVXDTF)
24 
25 //-----------------------------------------------------------------
26 // Implementation
27 //-----------------------------------------------------------------
28 
29 
30 SecMapTrainerVXDTFModule::SecMapTrainerVXDTFModule() :
32  Module(),
33  m_eventData("EventMetaData", DataStore::c_Event)
34 // m_testRootfile(nullptr),
35 // m_testConfig(),
36 // m_testTrainer(m_testConfig)
37 {
39 
40  //Set module properties
41  setDescription("this module analyzes a big number of events (pGun or evtGen) to create raw sectorMaps which are needed for the VXDTF. This information will be exported via root files.");
43 
44  addParam("spTCarrayName", m_PARAMspTCarrayName,
45  "the name of the storeArray containing the SpacePointTrackCands used for the secMap-generation", string(""));
46 
47  addParam("allowTraining", m_PARAMallowTraining,
48  "If true, training will be executed and filled into rootFiles, if not, only things like basf2 -m work but no training can be done",
49  bool(false));
50 
51 
52  if (m_PARAMallowTraining == false) return;
53  // small lambda for getting random numbers:
54  auto rngAppendix = []() -> int { return gRandom->Integer(std::numeric_limits<int>::max()); };
55 
56 
58  SectorMapConfig testData1;
59 // testData1.pTCuts = {0.02, 3.5};
60  testData1.pTmin = 0.02;
61  testData1.pTmax = 3.5;
62  testData1.pTSmear = 0.;
63  testData1.allowedLayers = {0, 3, 4, 5, 6};
64  testData1.uSectorDivider = { .15, .5, .85, 1.};
65  testData1.vSectorDivider = { .1, .3, .5, .7, .9, 1.};
66  testData1.pdgCodesAllowed = {};
67  testData1.seedMaxDist2IPXY = 23.5;
68  testData1.seedMaxDist2IPZ = 23.5;
69  testData1.nHitsMin = 3;
70  testData1.vIP = B2Vector3D(0, 0, 0);
71  testData1.secMapName = "lowTestVXDTF";
72  testData1.mField = 1.5;
73  testData1.rarenessThreshold = 0.001;
74  testData1.quantiles = {0.005, 0.005};
75 
76  std::string setupName = "testData1";
78  filters->setConfig(testData1);
79 
80  // the filtesrsContainer taked ownership of the filters!
82  filtersContainer.assignFilters(setupName, filters);
83 
84 
85  SecMapTrainer<XHitFilterFactory<SecMapTrainerHit> > newTrainer(setupName, std::to_string(rngAppendix()));
86 
87  m_secMapTrainers.push_back(std::move(newTrainer));
88 }
89 
90 
91 
94 {
95  B2INFO("~~~~~~~~~~~SecMapTrainerVXDTFModule - initialize ~~~~~~~~~~");
96  if (m_PARAMallowTraining == false)
97  B2FATAL("you want to execute SecMapTrainerVXDTF but the parameter 'allowTraining' is false! Aborting...");
98 
99  for (auto& trainer : m_secMapTrainers) {
100  trainer.initialize();
101  }
102 
103  // m_testTrainer.initialize();
105 
106 
107 }
108 
109 
112 {
113  //get the data
114  int thisExperiment = m_eventData->getExperiment();
115  int thisRun = m_eventData->getRun();
116  int thisEvent = m_eventData->getEvent();
117  B2DEBUG(5, "~~~~~~~~~~~SecMapTrainerVXDTFModule - experiment/run/event " << thisExperiment << "/" << thisRun << "/" << thisEvent <<
118  " ~~~~~~~~~~");
119 
120  for (auto& trainer : m_secMapTrainers) {
121  trainer.initializeEvent(thisExperiment, thisRun, thisEvent);
122  }
123  // m_testTrainer.initializeEvent(thisExperiment, thisRun, thisEvent);
124 
125  //simulated particles and hits
126  unsigned nSPTCs = m_spacePointTrackCands.getEntries();
127 
128  if (nSPTCs == 0) {
129  B2DEBUG(1, "event " << thisEvent << ": there is no SpacePointTrackCandidate!");
130  return;
131  }
132  B2DEBUG(5, "SecMapTrainerVXDTFModule, event " << thisEvent << ": size of array nSpacePointTrackCands: " << nSPTCs);
133 
134 
135 
136 
138  unsigned nAccepted = 0;
139  for (unsigned iTC = 0; iTC not_eq nSPTCs; ++ iTC) {
140  const SpacePointTrackCand* currentTC = m_spacePointTrackCands[iTC];
141  B2DEBUG(10, "currens SPTC has got " << currentTC->getNHits() << " hits stored");
142 
143  // bool accepted = m_testTrainer.storeTC(*currentTC, iTC);
144 
145  for (auto& trainer : m_secMapTrainers) {
146  bool accepted = trainer.storeTC(*currentTC, iTC);
147  nAccepted += (accepted ? 1 : 0);
148  }
149  }
150  B2DEBUG(5, "SecMapTrainerVXDTFModule, event " << thisEvent << ": number of TCs total/accepted: " << nSPTCs << "/" << nAccepted);
151 
152 
153  // process raw data:
154  for (auto& trainer : m_secMapTrainers) {
155  unsigned nTCsProcessed = trainer.processTracks();
156 
157  B2DEBUG(5, "SecMapTrainerVXDTFModule, event " << thisEvent << " with mapTrainer " << trainer.getConfig().secMapName <<
158  ": number of TCs processed: " << nTCsProcessed <<
159  ", calculations done!");
160  }
161  // unsigned nTCsProcessed = m_testTrainer.processTracks();
162 
163  // B2DEBUG(5, "SecMapTrainerVXDTFModule, event " << thisEvent << ": number of TCs processed: " << nTCsProcessed <<
164  // ", calculations done!");
165 }
166 
167 
168 
169 
172 {
173  B2DEBUG(1, " SecMapTrainerVXDTFModule::terminate:: start.");
174  for (auto& trainer : m_secMapTrainers) {
175  trainer.terminate();
176  }
177  B2INFO(" SecMapTrainerVXDTFModule, everything is done. Terminating.");
178 }
Belle2::SecMapTrainerVXDTFModule::initialize
void initialize() override
initialize.
Definition: SecMapTrainerVXDTFModule.cc:93
Belle2::SectorMapConfig::allowedLayers
std::vector< int > allowedLayers
stores allowed layers to be used (including virtual IP with layer 0).
Definition: SectorMapConfig.h:54
Belle2::SecMapTrainerVXDTFModule::event
void event() override
event.
Definition: SecMapTrainerVXDTFModule.cc:111
Belle2::SectorMapConfig::quantiles
std::pair< double, double > quantiles
the quantiles to be chosen in the end for determining the cuts first is quantile, second is 1-quantil...
Definition: SectorMapConfig.h:96
Belle2::SectorMapConfig::seedMaxDist2IPXY
double seedMaxDist2IPXY
Stores a cut for maximum distance of the seed in xy of the given virtual IP.
Definition: SectorMapConfig.h:71
Belle2::FiltersContainer
This class contains everything needed by the VXDTF that is not going to change during a RUN,...
Definition: FiltersContainer.h:38
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
Belle2::VXDTFFilters
Class that contains all the static sectors to which the filters are attached.
Definition: VXDTFFilters.h:75
Belle2::SecMapTrainerVXDTFModule::m_PARAMallowTraining
bool m_PARAMallowTraining
If true, training will be executed and filled into rootFiles, if not, only things like basf2 -m work ...
Definition: SecMapTrainerVXDTFModule.h:89
Belle2::SecMapTrainerBaseModule::m_secMapTrainers
std::vector< SecMapTrainer< SelectionVariableFactory< SecMapTrainerHit > > > m_secMapTrainers
contains the trainers for the secMaps to be trained.
Definition: SecMapTrainerBaseModule.h:83
Belle2::SecMapTrainerVXDTFModule::terminate
void terminate() override
terminate.
Definition: SecMapTrainerVXDTFModule.cc:171
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::SecMapTrainerVXDTFModule::m_secMapTrainers
std::vector< SecMapTrainer< XHitFilterFactory< SecMapTrainerHit > > > m_secMapTrainers
contains the trainers for the secMaps to be trained.
Definition: SecMapTrainerVXDTFModule.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::SecMapTrainerVXDTFModule::m_eventData
StoreObjPtr< EventMetaData > m_eventData
Event Data for distinguishing events.
Definition: SecMapTrainerVXDTFModule.h:76
Belle2::SecMapTrainerBaseModule::InitializeVariables
void InitializeVariables()
initialize variables to avoid nondeterministic behavior.
Definition: SecMapTrainerBaseModule.h:71
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::SectorMapConfig::seedMaxDist2IPZ
double seedMaxDist2IPZ
Stores a cut for maximum distance of the seed in z of the given virtual IP.
Definition: SectorMapConfig.h:76
Belle2::B2Vector3D
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:507
Belle2::SecMapTrainerVXDTFModule::m_PARAMspTCarrayName
std::string m_PARAMspTCarrayName
Name of storeArray containing the spacePointTrackCands.
Definition: SecMapTrainerVXDTFModule.h:85
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SectorMapConfig::pTmin
double pTmin
stores pTCuts for min pT allowed for this .
Definition: SectorMapConfig.h:45
Belle2::SectorMapConfig::vSectorDivider
std::vector< double > vSectorDivider
Defines the sectors boundaries in normalized v coordinates (i.e.
Definition: SectorMapConfig.h:62
Belle2::SectorMapConfig::pTSmear
double pTSmear
allows smearing of the cuts.
Definition: SectorMapConfig.h:51
Belle2::SectorMapConfig::pTmax
double pTmax
stores pTCuts for min (.first) and max (.second) ptCut.
Definition: SectorMapConfig.h:47
Belle2::FiltersContainer::assignFilters
void assignFilters(const std::string &setupName, VXDTFFilters< point_t > *filters)
assigns filters.
Definition: FiltersContainer.h:98
Belle2::SecMapTrainerVXDTFModule::m_spacePointTrackCands
StoreArray< SpacePointTrackCand > m_spacePointTrackCands
contains the spacePointTrackCands to be analyzed for the secMap-Training.
Definition: SecMapTrainerVXDTFModule.h:79
Belle2::VXDTFFilters::setConfig
void setConfig(const SectorMapConfig &config)
set the configuration which is used to create this filter
Definition: VXDTFFilters.h:288
Belle2::SectorMapConfig::nHitsMin
unsigned nHitsMin
Stores the minimal number of hits a TC must have to be accepted as TC (vIP-Hits are ignored).
Definition: SectorMapConfig.h:80
Belle2::SectorMapConfig::rarenessThreshold
double rarenessThreshold
defined 1 == 100%, if relative frequency of sec-combi to the outer-sector is less than threshold,...
Definition: SectorMapConfig.h:93
Belle2::FiltersContainer::getInstance
static FiltersContainer & getInstance()
one and only way to access the singleton object
Definition: FiltersContainer.h:64
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::SectorMapConfig
simple struct containing all the configuration data needed for the SecMapTrainer.
Definition: SectorMapConfig.h:36
Belle2::SectorMapConfig::secMapName
std::string secMapName
Sets the human readable proto-name of the sectorMap.
Definition: SectorMapConfig.h:87
Belle2::SectorMapConfig::vIP
B2Vector3D vIP
Stores the position of the assumed position of the interaction point - The virtual IP.
Definition: SectorMapConfig.h:84
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::SectorMapConfig::mField
double mField
Magnetic field value to be set for the filters.
Definition: SectorMapConfig.h:90
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::SectorMapConfig::pdgCodesAllowed
std::vector< int > pdgCodesAllowed
Stores all the pdgCodes which are allowed to be used by the SecMap.
Definition: SectorMapConfig.h:66
Belle2::SpacePointTrackCand
Storage for (VXD) SpacePoint-based track candidates.
Definition: SpacePointTrackCand.h:51
Belle2::SectorMapConfig::uSectorDivider
std::vector< double > uSectorDivider
Defines the sectors boundaries in normalized u coordinates (i.e.
Definition: SectorMapConfig.h:58