10#include <reconstruction/modules/KLMMuonIDDNNExpert/KLMMuonIDDNNExpertModule.h>
12#include <klm/bklm/geometry/GeometryPar.h>
13#include <klm/bklm/geometry/Module.h>
14#include <klm/eklm/geometry/TransformDataGlobalAligned.h>
15#include <klm/dataobjects/KLMHit2d.h>
16#include <klm/dataobjects/KLMMuidLikelihood.h>
18#include <reconstruction/dataobjects/KLMMuonIDDNNInputVariable.h>
20#include <CLHEP/Units/SystemOfUnits.h>
22#include <framework/logging/Logger.h>
23#include <framework/gearbox/Const.h>
25#include <tracking/dataobjects/ExtHit.h>
27#include <mdst/dataobjects/PIDLikelihood.h>
29#include <mdst/dataobjects/Track.h>
31#include <mva/interface/Interface.h>
32#include <mva/dataobjects/DatabaseRepresentationOfWeightfile.h>
33#include <mva/interface/Expert.h>
34#include <mva/interface/Weightfile.h>
101 weightfile.getOptions(general_options);
102 m_expert = supported_interfaces.at(general_options.m_method)->getExpert();
104 std::vector<float> dummy;
105 int nInputVariables = general_options.m_variables.size();
110 dummy.resize(nInputVariables, 0);
121 if (!klmll)
continue;
129 bool hasExtInKLM =
false;
130 for (
const ExtHit& exthit : track.getRelationsTo<
ExtHit>()) {
132 if (exthit.getDetectorID() != Const::EDetector::BKLM
133 and exthit.getDetectorID() != Const::EDetector::EKLM)
continue;
136 bool inBKLM = (exthit.getDetectorID() == Const::EDetector::BKLM);
137 int copyid = exthit.getCopyID();
139 int section, sector, plane, strip;
158 if (not(hasExtInKLM || KLMHit2drelation.
size()))
continue;
160 std::map<int, int> Hit2dMap;
161 for (
long unsigned int ii = 0; ii < KLMHit2drelation.
size(); ii++) {
162 const KLMHit2d* klmhit = KLMHit2drelation[ii];
164 unsigned long int hit_layer = klmhit->getLayer();
168 Hit2dMap.insert(std::pair<int, int> {index, ii});
172 ROOT::Math::XYZVector previousPosition(0., 0., 0.);
173 for (
auto itermap = Hit2dMap.begin(); itermap != Hit2dMap.end(); itermap ++) {
177 const KLMHit2d* klmhit = KLMHit2drelation[itermap->second];
179 float KFchi2 = KLMHit2drelation.
weight(itermap->second);
182 ROOT::Math::XYZVector hitPosition = klmhit->getPosition();
183 float steplength = 0.;
185 steplength = (hitPosition - previousPosition).
R();
187 previousPosition = hitPosition;
190 int hitpatternindex = itermap->first;
200 pid->addPreOfficialLikelihood(
"klmMuonIDDNN", muprob_nn);
210 m_dataset->m_input[4] = track->getTrackFitResultWithClosestMass(
Const::muon)->getTransverseMomentum();
221 track->addRelationTo(inputVariable);
229 float stripwidth1 = 0;
230 float stripwidth2 = 0;
231 float stripdiff1 = 0;
232 float stripdiff2 = 0;
236 stripdiff1 = (klmhit->getPhiStripMax() - klmhit->getPhiStripMin() + 1) * 0.5;
237 stripdiff2 = (klmhit->getZStripMax() - klmhit->getZStripMin() + 1) * 0.5;
241 stripdiff1 = (klmhit->getXStripMax() - klmhit->getXStripMin() + 1) * 0.5;
242 stripdiff2 = (klmhit->getYStripMax() - klmhit->getYStripMin() + 1) * 0.5;
244 float width1 = stripwidth1 * stripdiff1;
245 float width2 = stripwidth2 * stripdiff2;
246 return std::sqrt(width1 * width1 + width2 * width2);
@ c_ForwardSection
Forward.
static void moduleNumberToElementNumbers(KLMModuleNumber module, int *section, int *sector, int *layer)
Get element numbers by module number.
static const ChargedStable muon
muon particle
static const EKLMElementNumbers & Instance()
Instantiation.
void stripNumberToElementNumbers(int stripGlobal, int *section, int *layer, int *sector, int *plane, int *strip) const
Get element numbers by strip global number.
double getWidth() const
Get width.
const StripGeometry * getStripGeometry() const
Get strip geometry data.
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
Store one Ext hit as a ROOT object.
Class to store the likelihoods from KLM with additional information related to the extrapolation.
int getDegreesOfFreedom() const
Get the number of degrees of freedom (= 2 times the number of KLM hits) for the chi-squared computati...
int getHitLayer() const
Get the outermost KLM layer actually crossed by the track.
int getExtLayer() const
Get the outermost KLM layer crossed in the extrapolation.
double getChiSquared() const
Get the chi-squared of the extrapolation.
std::array< float, m_maxBKLMLayers+m_maxEKLMLayers > m_hitpattern_width
Container of hit widths of one track.
std::unique_ptr< MVA::SingleDataset > m_dataset
Pointer to the current dataset.
void initialize() override
Initializer.
float getHitWidth(const KLMHit2d *klmhit)
Get Hit width (cluster size) of a KLMHit2d.
void event() override
This method is called for each event.
KLMMuonIDDNNExpertModule()
Constructor.
float m_EndcapScintWidth
EKLM scintillator strip width (cm).
static constexpr int m_maxBKLMLayers
Total BKLM layers.
std::array< float, m_maxBKLMLayers+m_maxEKLMLayers > m_hitpattern_chi2
Container of hit chi2 of one track.
void terminate() override
This method is called at the end of the event processing.
std::unique_ptr< MVA::Expert > m_expert
Pointer to the current MVA expert.
void beginRun() override
Called when entering a new run.
StoreArray< Track > m_tracks
Required array for Tracks.
std::array< float, m_maxBKLMLayers+m_maxEKLMLayers > m_hitpattern_steplength
Container of hit steplength of one track.
float getNNmuProbability(const Track *track, const KLMMuidLikelihood *klmll)
Get the NN-based muon probability.
std::array< float, m_maxBKLMLayers > m_BarrelPhiStripWidth
BKLM phi-measuring strip width (cm) by layer.
DBObjPtr< DatabaseRepresentationOfWeightfile > m_weightfile_representation
Database pointer to the database representation of the weightfile.
void initializeMVA(MVA::Weightfile &weightfile)
Initialize mva expert, dataset and features.
~KLMMuonIDDNNExpertModule() override
Destructor.
std::array< float, m_maxBKLMLayers > m_BarrelZStripWidth
BKLM Z-measuring strip width (cm) by layer.
std::array< bool, m_maxBKLMLayers+m_maxEKLMLayers > m_hitpattern_hasext
Container of extrapolation situation at each KLM layer of one track.
const std::string m_identifier
Database identifier or file used to load the weights.
StoreArray< KLMMuonIDDNNInputVariable > m_inputVariable
Input variables of DNN.
static constexpr int m_maxEKLMLayers
Total EKLM layers.
static void initSupportedInterfaces()
Static function which initializes all supported interfaces, has to be called once before getSupported...
static const std::map< std::string, AbstractInterface * > & getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
General options which are shared by all MVA trainings.
Wraps the data of a single event into a Dataset.
The Weightfile class serializes all information about a training into an xml tree.
static Weightfile loadFromStream(std::istream &stream)
Static function which deserializes a Weightfile from a stream.
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...
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
float weight(int index) const
Get weight with index.
Class that bundles various TrackFitResults.
Provides BKLM geometry parameters for simulation, reconstruction etc (from Gearbox or DataBase)
const Module * findModule(int section, int sector, int layer) const
Get the pointer to the definition of a module.
static GeometryPar * instance(void)
Static method to get a reference to the singleton GeometryPar instance.
Define the geometry of a BKLM module Each sector [octant] contains Modules.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.