11#include <tracking/trackFindingVXD/filterMap/map/FiltersContainer.h>
12#include "tracking/trackFindingVXD/environment/VXDTFFilters.h"
13#include "tracking/modules/vxdtfRedesign/SectorMapBootstrapModule.h"
15#include "tracking/dataobjects/SectorMapConfig.h"
16#include <tracking/spacePointCreation/SpacePoint.h>
19#include <framework/core/ModuleParam.templateDetails.h>
21#include <vxd/geometry/GeoCache.h>
22#include <vxd/geometry/SensorInfoBase.h>
41 setDescription(
"Create the VXDTF SectorMap for the following modules."
45 "File from which the SectorMaps will be retrieved if\
49 "File into which the SectorMaps will be written if\
53retrieve the SectorMaps from SectorMapsInputFile during initialize.",
m_readSectorMap);
59 " from the from the root file. All other will be ignored. If empty \"\" (default) all setups are read. Will "
60 "only used if sectormap is retrieved from root file. Case will be ignored!",
63 addParam(
"ReadSecMapFromDB",
m_readSecMapFromDB,
"If set to true the sector map will be read from the Data Base. NOTE: this will "
64 "override the parameter ReadSectorMap (reading sector map from file)!!!",
m_readSecMapFromDB);
68 std::vector< std::pair<char, void*> > dummyVector = {};
72 std::string structure2HitFilter = empty2HitFilter.getNameAndReference(&dummyVector);
75 "Vector of vectors containing expressions used to "
76 "alter the 2-hit filters. The inner vector should contain exactly two strings. The first entry is interpreted as index (integer). "
77 "The second entry is interpreted as function used to create a TF1. The variable to be altered will be assumed to be called \"x\" "
78 "and in addition one can use \"[0]\" can be used which will be interpreted as FullSecID of the static sector the filter is attached to. "
79 "No other parameter is allowed. The structure of the 2-hit filter is as follows: " + structure2HitFilter +
80 " Example: [(1, \"12\"), (3, \"sin(x)\"), (4, \"x + [0]\")] PS: use this feature only if you know what you are doing!",
85 std::string structure3HitFilter = empty3HitFilter.getNameAndReference(&dummyVector);
88 "Vector of vectors containing expressions used to "
89 "alter the 3-hit filters. The inner vector should contain exactly two strings. The first entry is interpreted as index (integer). "
90 "The second entry is interpreted as function used to create a TF1. The variable to be altered will be assumed to be called \"x\" "
91 "and in addition \"[0]\" can be used which will be interpreted as FullSecID of the static sector the filter is attached to. No other "
92 "parameter is allowed. The structure of the 2-hit filter is as follows: " + structure3HitFilter +
93 " Example: [(1, \"12\"), (3, \"sin(x)\"), (4, \"x + [0]\")] PS: use this feature only if you know what you are doing!",
103 B2DEBUG(29,
"SectorMapBootstrapModule: Retrieving sectormap from DB. Filename: " <<
m_sectorMapsInputFile);
105 if (
m_ptrDBObjPtr ==
nullptr) B2FATAL(
"SectorMapBootstrapModule: the DBObjPtr is not initialized");
118 B2FATAL(
"Detected existing output file! Please delete or move before proceeding! File name: " <<
m_sectorMapsOutputFile);
120 B2DEBUG(29,
"Checked that output file does not exist!");
149 config1.
pTmin = 0.02;
215 std::vector< double > uDividersMinusLastOne = config.uSectorDivider;
216 uDividersMinusLastOne.pop_back();
217 std::vector< double > vDividersMinusLastOne = config.vSectorDivider;
218 vDividersMinusLastOne.pop_back();
221 std::vector< std::vector< FullSecID > > sectors;
223 sectors.resize(config.uSectorDivider.size());
224 unsigned nSectorsInU = config.uSectorDivider.size(),
225 nSectorsInV = config.vSectorDivider.size();
229 std::vector<VxdID> listOfSensors =
geometry.getListOfSensors();
230 for (
VxdID aSensorId : listOfSensors) {
233 if (std::find(config.allowedLayers.begin(), config.allowedLayers.end(),
234 aSensorId.getLayerNumber()) == config.allowedLayers.end())
continue;
239 B2WARNING(
"Found sensor which is not PXD or SVD with VxdID: " << aSensorId <<
" ! Will skip that sensor ");
244 for (
unsigned int i = 0; i < nSectorsInU; i++) {
245 sectors.at(i).resize(nSectorsInV);
246 for (
unsigned int j = 0; j < nSectorsInV ; j++) {
247 sectors.at(i).at(j) =
FullSecID(aSensorId,
false, counter);
252 vDividersMinusLastOne,
258 if (std::find(config.allowedLayers.begin(), config.allowedLayers.end(), 0) != config.allowedLayers.end()) {
259 std::vector<double> uCuts4vIP = {}, vCuts4vIP = {};
278 if (!rootFile.IsOpen()) B2FATAL(
"Unable to open rootfile! This could be caused by an already existing file of the same name: "
284 TString setupKeyName;
290 for (
auto singleSetupFilters : allSetupsFilters) {
292 setupKeyName = TString(singleSetupFilters.first.c_str());
296 rootFile.mkdir(setupKeyName, setupKeyName);
297 rootFile.cd(setupKeyName);
299 singleSetupFilters.second->persistOnRootFile();
320 if (
m_ptrDBObjPtr ==
nullptr) B2FATAL(
"SectorMapBootstrapModule: the pointer to the DB payload is not set!");
321 if (!(*m_ptrDBObjPtr).isValid()) B2FATAL(
"SectorMapBootstrapModule the DB object is not valid!");
323 rootFileName = (*m_ptrDBObjPtr)->getFileName();
326 B2DEBUG(29,
"SectorMapBootstrapModule: retrieving new SectorMap. New file name: " << rootFileName);
327 TFile rootFile(rootFileName.c_str());
330 if (!rootFile.IsOpen()) B2FATAL(
"The root file: " << rootFileName <<
" was not found.");
332 TTree* tree =
nullptr;
334 if (tree ==
nullptr) B2FATAL(
"SectorMapBootstrapModule: tree not found! tree name: " <<
c_setupKeyNameTTreeName.c_str());
336 TString* setupKeyName =
nullptr;
339 if (setupKeyName ==
nullptr) B2FATAL(
"SectorMapBootstrapModule: setupKeyName not found");
343 setupToRead_upper.ToUpper();
346 bool read_something =
false;
349 auto nEntries = tree->GetEntriesFast();
350 for (
int i = 0; i < nEntries ; i++) {
354 if (setupToRead_upper !=
"") {
355 TString buff = setupKeyName->Data();
357 if (buff != setupToRead_upper)
continue;
360 rootFile.cd(setupKeyName->Data());
362 B2DEBUG(29,
"Retrieving SectorMap with name " << setupKeyName->Data());
366 std::string setupKeyNameStd = std::string(setupKeyName->Data());
371 B2WARNING(
"The 2-hit filters will be altered from the default!");
372 B2INFO(
"The following set of indizes and functions will be used to alter the 2-hit filters:");
374 B2INFO(
"index=" << std::get<0>(entry) <<
" function=" << std::get<1>(entry));
379 B2WARNING(
"The 3-hit filters will be altered from the default!");
380 B2INFO(
"The following set of indizes and functions will be used to alter the 3-hit filters:");
382 B2INFO(
"index=" << std::get<0>(entry) <<
" function=" << std::get<1>(entry));
390 B2DEBUG(29,
"Retrieved map with name: " << setupKeyNameStd <<
" from rootfie.");
391 filtersContainer.
assignFilters(setupKeyNameStd, segmentFilters);
395 setupKeyName->Clear();
397 read_something =
true;
400 if (!read_something) B2FATAL(
"SectorMapBootstrapModule: No setup was read from the root file! " <<
406 if (setupKeyName !=
nullptr) {
Class for accessing objects in the database.
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.
const setupNameToFilters_t & getAllSetups(void)
returns all the available setups.
Class to identify a sector inside of the VXD.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
bool m_readSecMapFromDB
if true the sector map will be read from the DB. NOTE: this will override m_readSectorMap (read from ...
std::string m_sectorMapsInputFile
the name of the input root file the sectormaps are read from
void initialize() override
Initializer.
void endRun() override
This method is called if the current run ends.
std::vector< std::tuple< int, std::string > > m_twoHitFilterAdjustFunctions
vector of tuple<int, string> specifying how 2-hit filters are altered.
SectorMapBootstrapModule()
Constructor.
static void bootstrapSectorMap(void)
puts several empty sectormaps into the framework
bool m_readSectorMap
if true a sectormap will be read from a file. NOTE: this will be overridden by m_readSecMapFromDB!
DBObjPtr< PayloadFile > * m_ptrDBObjPtr
pointer to the DBObjPtr for the payloadfile from which the sectormap is read
const std::string c_setupKeyNameBranchName
the name of the branch the setupt are stored in the tree
std::vector< std::tuple< int, std::string > > m_threeHitFilterAdjustFunctions
vector of tuple<int, string> specifying how 3-hit filters are altered.
const std::string c_setupKeyNameTTreeName
the name of the tree the setups are stored in in the root file
std::string m_setupToRead
if specified (non "") ONLY the setup with this name will be read. Else all setups in the root file wi...
std::string m_sectorMapsOutputFile
the name of the output root file the sectormaps are written to
void persistSectorMap(void)
writes a sectormap to a root file
void retrieveSectorMap(void)
retrieves SectorMap from file or from the DB
bool m_writeSectorMap
if true the sectormap will be written to an output file
Class that contains all the static sectors to which the filters are attached.
int addSectorsOnSensor(const std::vector< double > &normalizedUsup, const std::vector< double > &normalizedVsup, const std::vector< std::vector< FullSecID > > §orIds)
To add an array of sectors on a sensor.
bool retrieveFromRootFile(const TString *dirName)
Retrieves from the current TDirectory all the VXDTFFilters.
decltype((0.<=DistanceInTimeUside< point_t >()<=0. &&0.<=DistanceInTimeVside< point_t >()<=0. &&0.<=Distance3DSquared< point_t >()<=0.&&0.<=Distance2DXYSquared< point_t >()<=0.&&0.<=Distance1DZ< point_t >()<=0.&&0.<=SlopeRZ< point_t >()<=0.&&0.<=Distance3DNormed< point_t >()<=0.)) twoHitFilter_t
minimal working 2-hits-example used for redesign of VXDTF.
void modify2SPFilters(const std::vector< std::tuple< int, std::string > > &adjustFunctions)
modifies the 2SP-filters according to the functions given
void lockFilters()
This function should be called only AFTER all adjustments to the filters have been performed.
void setConfig(const SectorMapConfig &config)
set the configuration which is used to create this filter
decltype((0.<=DistanceInTime< point_t >()<=0. &&0.<=Angle3DSimple< point_t >()<=0.&&0.<=CosAngleXY< point_t >()<=0.&&0.<=AngleRZSimple< point_t >()<=0.&&CircleDist2IP< point_t >()<=0.&&0.<=DeltaSlopeRZ< point_t >()<=0.&&0.<=DeltaSlopeZoverS< point_t >()<=0.&&0.<=DeltaSoverZ< point_t >()<=0.&&0.<=HelixParameterFit< point_t >()<=0.&&0.<=Pt< point_t >()<=0.&&0.<=CircleRadius< point_t >()<=0.)) threeHitFilter_t
minimal working example for 3-hits:
void modify3SPFilters(const std::vector< std::tuple< int, std::string > > &adjustFunctions)
modifies the 3SP-filters according to the functions given
Class to facilitate easy access to sensor information of the VXD like coordinate transformations or p...
static GeoCache & getInstance()
Return a reference to the singleton instance.
SensorType
Enum specifying the type of sensor the SensorInfo represents.
Class to uniquely identify a any structure of the PXD and SVD.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
B2Vector3< double > B2Vector3D
typedef for common usage with double
Common code concerning the geometry representation of the detector.
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).