9#include <tracking/modules/standardTrackingPerformance/StandardTrackingPerformanceModule.h>
11#include <framework/datastore/StoreObjPtr.h>
12#include <framework/dataobjects/EventMetaData.h>
13#include <framework/datastore/RelationVector.h>
14#include <framework/gearbox/Const.h>
16#include <tracking/dataobjects/RecoTrack.h>
17#include <genfit/TrackPoint.h>
18#include <genfit/KalmanFitterInfo.h>
20#include <pxd/reconstruction/PXDRecoHit.h>
21#include <svd/reconstruction/SVDRecoHit.h>
22#include <svd/reconstruction/SVDRecoHit2D.h>
23#include <cdc/dataobjects/CDCRecoHit.h>
25#include <root/TFile.h>
26#include <root/TTree.h>
35StandardTrackingPerformanceModule::StandardTrackingPerformanceModule() :
36 Module(), m_outputFile(nullptr), m_dataTree(nullptr), m_trackProperties(-999), m_pValue(-999),
37 m_nGeneratedChargedStableMcParticles(-999), m_nReconstructedChargedStableTracks(-999),
38 m_nFittedChargedStabletracks(-999)
40 setDescription(
"Module to test the tracking efficiency. Writes information about the tracks and MCParticles in a ROOT file.");
41 setPropertyFlags(c_ParallelProcessingCertified);
43 addParam(
"outputFileName", m_outputFileName,
"Name of output root file.",
44 std::string(
"StandardTrackingPerformanceOutput.root"));
45 addParam(
"recoTracksStoreArrayName", m_recoTracksStoreArrayName,
"Name of the RecoTracks StoreArray.",
47 addParam(
"daughterPDGs", m_signalDaughterPDGs,
"PDG codes of B daughters.",
57 TDirectory* oldDir = gDirectory;
68 unsigned long eventNumber = eventMetaData->getEvent();
69 unsigned long runNumber = eventMetaData->getRun();
70 unsigned long expNumber = eventMetaData->getExperiment();
73 "Processes experiment " << expNumber <<
" run " << runNumber <<
" event " << eventNumber);
84 int pdgCode = mcParticle.getPDG();
85 B2DEBUG(29,
"Primary MCParticle has PDG code " << pdgCode);
101 double maximumWeight = -2;
108 for (
unsigned int index = 0; index < relatedRecoTracks.size(); ++index) {
109 const RecoTrack* relatedRecoTrack = relatedRecoTracks.object(index);
110 const double weight = relatedRecoTracks.weight(index);
113 B2ASSERT(
"B2Track <-> RecoTrack is not a 1:1 relation as expected!", numberOfRelatedTracks <= 1);
115 if (numberOfRelatedTracks == 1) {
116 if (weight > maximumWeight) {
117 maximumWeight = weight;
118 recoTrack = relatedRecoTrack;
126 B2ASSERT(
"Related Belle2 Track has no related track fit result for pion!", fitResult);
130 ROOT::Math::XYZVector mom = fitResult->getMomentum();
149 for (genfit::AbsMeasurement* m : tp->getRawMeasurements()) {
159 B2ERROR(
"Unknown AbsMeasurement in track.");
161 std::vector<double> weights;
162 genfit::KalmanFitterInfo* kalmanInfo = tp->getKalmanFitterInfo();
164 weights = kalmanInfo->getWeights();
201 B2FATAL(
"Data tree was not created.");
247 TDirectory* oldDir = gDirectory;
264 if (abs(mcParticle.getPDG()) != 511 && abs(mcParticle.getPDG()) != 521)
276 std::vector<int> daughterPDGs;
277 std::vector<MCParticle*> daughterMcParticles = mcParticle.
getDaughters();
282 for (
auto daughterMCParticle : daughterMcParticles) {
283 daughterPDGs.push_back(daughterMCParticle->getPDG());
286 std::sort(daughterPDGs.begin(), daughterPDGs.end());
300 std::vector<MCParticle*> daughtersWOFSR;
301 for (
unsigned int iDaughter = 0; iDaughter < in_daughters.size(); iDaughter++)
302 if (abs(in_daughters[iDaughter]->getPDG()) !=
Const::photon.getPDGCode())
303 daughtersWOFSR.push_back(in_daughters[iDaughter]);
305 return daughtersWOFSR;
313 std::vector<MCParticle*> daughters = mcParticle.
getDaughters();
314 if (daughters.size() != 0) {
315 for (
auto daughterMcParticle : daughters) {
341 std::stringstream leaf;
342 leaf << varName <<
"/D";
343 m_dataTree->Branch(varName.c_str(), &varReference, leaf.str().c_str());
348 std::stringstream leaf;
349 leaf << varName <<
"/I";
350 m_dataTree->Branch(varName.c_str(), &varReference, leaf.str().c_str());
This class is used to transfer CDC information to the track fit.
const ParticleType & find(int pdg) const
Returns particle in set with given PDG code, or invalidParticle if not found.
static const ParticleSet chargedStableSet
set of charged stable particles
static const ChargedStable pion
charged pion particle
static const ParticleType invalidParticle
Invalid particle, used internally.
static const ParticleType photon
photon particle
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
A Class to store the Monte Carlo particle information.
@ c_PrimaryParticle
bit 0: Particle is primary particle.
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
std::vector< Belle2::MCParticle * > getDaughters() const
Get vector of all daughter particles, empty vector if none.
bool hasStatus(unsigned short int bitmask) const
Return if specific status bit is set.
int getPDG() const
Return PDG code of particle.
PXDRecoHit - an extended form of PXDCluster containing geometry information.
This is the Reconstruction Event-Data Model Track.
const std::vector< genfit::TrackPoint * > & getHitPointsWithMeasurement() const
Return a list of measurements and track points, which can be used e.g. to extrapolate....
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
RelationVector< T > getRelationsWith(const std::string &name="", const std::string &namedRelation="") const
Get the relations between this object and another store array.
SVDRecoHit - an extended form of SVDHit containing geometry information.
SVDRecoHit - an extended form of SVDHit containing geometry information.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Type-safe access to single objects in the data store.
Values of the result of a track fit with a given particle hypothesis.
Class that bundles various TrackFitResults.
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.
double pt
measured transverse momentum
int nCDChits
Number of CDC hits in reconstructed track
double pz
measured momentum in z direction
double x_gen
x value of generated position
float weights[maxNweights]
Weights of the hits in sequence
double pt_gen
generated transverse momentum
double mass_gen
generated mass
double y_gen
y value of generated position
int nPXDhits
Number of PXD hits in reconstructed track
int nSVDhits
Number of SVD hits in reconstructed track
double px
measured momentum in x direction
static const int maxNweights
the maximum number of stored weights
double z
measured z value of position
int nWeights
Number of entries in weights array
double y
measured y value of position
double ptot_gen
generated total momentum
double py
measured momentum in y direction
double cosTheta
polar angle of measured momentum vector
double pz_gen
generated momentum in z direction
double py_gen
generated momentum in y direction
double cosTheta_gen
polar angle of generated momentum vector
double px_gen
generated momentum in x direction
double z_gen
z value of generated position
double x
measured x value of position
double ptot
measured total momentum