Belle II Software  release-06-00-14
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 
14 using namespace std;
15 using namespace Belle2;
16 
17 
18 //-----------------------------------------------------------------
19 // Register the Module
20 //-----------------------------------------------------------------
21 REG_MODULE(SecMapTrainerVXDTF)
22 
23 //-----------------------------------------------------------------
24 // Implementation
25 //-----------------------------------------------------------------
26 
27 
28 SecMapTrainerVXDTFModule::SecMapTrainerVXDTFModule() :
30  Module(),
31  m_eventData("EventMetaData", DataStore::c_Event)
32 // m_testRootfile(nullptr),
33 // m_testConfig(),
34 // m_testTrainer(m_testConfig)
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. This information will be exported via root files.");
40  setPropertyFlags(c_ParallelProcessingCertified | c_TerminateInAllProcesses);
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  // small lambda for getting random numbers:
52  auto rngAppendix = []() -> int { return gRandom->Integer(std::numeric_limits<int>::max()); };
53 
54 
56  SectorMapConfig testData1;
57 // testData1.pTCuts = {0.02, 3.5};
58  testData1.pTmin = 0.02;
59  testData1.pTmax = 3.5;
60  testData1.pTSmear = 0.;
61  testData1.allowedLayers = {0, 3, 4, 5, 6};
62  testData1.uSectorDivider = { .15, .5, .85, 1.};
63  testData1.vSectorDivider = { .1, .3, .5, .7, .9, 1.};
64  testData1.pdgCodesAllowed = {};
65  testData1.seedMaxDist2IPXY = 23.5;
66  testData1.seedMaxDist2IPZ = 23.5;
67  testData1.nHitsMin = 3;
68  testData1.vIP = B2Vector3D(0, 0, 0);
69  testData1.secMapName = "lowTestVXDTF";
70  testData1.mField = 1.5;
71  testData1.rarenessThreshold = 0.001;
72  testData1.quantiles = {0.005, 0.005};
73 
74  std::string setupName = "testData1";
76  filters->setConfig(testData1);
77 
78  // the filtesrsContainer taked ownership of the filters!
80  filtersContainer.assignFilters(setupName, filters);
81 
82 
83  SecMapTrainer<XHitFilterFactory<SecMapTrainerHit> > newTrainer(setupName, std::to_string(rngAppendix()));
84 
85  m_secMapTrainers.push_back(std::move(newTrainer));
86 }
87 
88 
89 
91 void SecMapTrainerVXDTFModule::initialize()
92 {
93  B2INFO("~~~~~~~~~~~SecMapTrainerVXDTFModule - initialize ~~~~~~~~~~");
94  if (m_PARAMallowTraining == false)
95  B2FATAL("you want to execute SecMapTrainerVXDTF but the parameter 'allowTraining' is false! Aborting...");
96 
97  for (auto& trainer : m_secMapTrainers) {
98  trainer.initialize();
99  }
100 
101  // m_testTrainer.initialize();
103 
104 
105 }
106 
107 
110 {
111  //get the data
112  int thisExperiment = m_eventData->getExperiment();
113  int thisRun = m_eventData->getRun();
114  int thisEvent = m_eventData->getEvent();
115  B2DEBUG(5, "~~~~~~~~~~~SecMapTrainerVXDTFModule - experiment/run/event " << thisExperiment << "/" << thisRun << "/" << thisEvent <<
116  " ~~~~~~~~~~");
117 
118  for (auto& trainer : m_secMapTrainers) {
119  trainer.initializeEvent(thisExperiment, thisRun, thisEvent);
120  }
121  // m_testTrainer.initializeEvent(thisExperiment, thisRun, thisEvent);
122 
123  //simulated particles and hits
124  unsigned nSPTCs = m_spacePointTrackCands.getEntries();
125 
126  if (nSPTCs == 0) {
127  B2DEBUG(1, "event " << thisEvent << ": there is no SpacePointTrackCandidate!");
128  return;
129  }
130  B2DEBUG(5, "SecMapTrainerVXDTFModule, event " << thisEvent << ": size of array nSpacePointTrackCands: " << nSPTCs);
131 
132 
133 
134 
136  unsigned nAccepted = 0;
137  for (unsigned iTC = 0; iTC not_eq nSPTCs; ++ iTC) {
138  const SpacePointTrackCand* currentTC = m_spacePointTrackCands[iTC];
139  B2DEBUG(10, "currens SPTC has got " << currentTC->getNHits() << " hits stored");
140 
141  // bool accepted = m_testTrainer.storeTC(*currentTC, iTC);
142 
143  for (auto& trainer : m_secMapTrainers) {
144  bool accepted = trainer.storeTC(*currentTC, iTC);
145  nAccepted += (accepted ? 1 : 0);
146  }
147  }
148  B2DEBUG(5, "SecMapTrainerVXDTFModule, event " << thisEvent << ": number of TCs total/accepted: " << nSPTCs << "/" << nAccepted);
149 
150 
151  // process raw data:
152  for (auto& trainer : m_secMapTrainers) {
153  unsigned nTCsProcessed = trainer.processTracks();
154 
155  B2DEBUG(5, "SecMapTrainerVXDTFModule, event " << thisEvent << " with mapTrainer " << trainer.getConfig().secMapName <<
156  ": number of TCs processed: " << nTCsProcessed <<
157  ", calculations done!");
158  }
159  // unsigned nTCsProcessed = m_testTrainer.processTracks();
160 
161  // B2DEBUG(5, "SecMapTrainerVXDTFModule, event " << thisEvent << ": number of TCs processed: " << nTCsProcessed <<
162  // ", calculations done!");
163 }
164 
165 
166 
167 
170 {
171  B2DEBUG(1, " SecMapTrainerVXDTFModule::terminate:: start.");
172  for (auto& trainer : m_secMapTrainers) {
173  trainer.terminate();
174  }
175  B2INFO(" SecMapTrainerVXDTFModule, everything is done. Terminating.");
176 }
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.
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 ...
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.
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
Class that contains all the static sectors to which the filters are attached.
Definition: VXDTFFilters.h:63
void setConfig(const SectorMapConfig &config)
set the configuration which is used to create this filter
Definition: VXDTFFilters.h:278
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:493
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).