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