10#include <reconstruction/modules/PIDNtuple/PIDNtupleModule.h>
13#include <framework/datastore/StoreArray.h>
14#include <framework/datastore/StoreObjPtr.h>
17#include <framework/gearbox/Const.h>
18#include <framework/logging/Logger.h>
21#include <framework/dataobjects/EventMetaData.h>
22#include <mdst/dataobjects/Track.h>
23#include <mdst/dataobjects/MCParticle.h>
24#include <mdst/dataobjects/PIDLikelihood.h>
27#include <TDirectory.h>
46 setDescription(
"Writes a flat ntuple of PIDLikelihoods with track info into a root file");
50 std::string(
"PIDNtuple.root"));
52 addParam(
"p1",
m_p1,
"parameter of momentum distribution", 0.90311E-01);
53 addParam(
"p2",
m_p2,
"parameter of momentum distribution", 0.56846);
54 addParam(
"pMax",
m_pMax,
"make distribution flat up to this momentum", 3.0);
73 tracks.optionalRelationTo(mcparticles);
76 TDirectory::TContext context;
78 m_tree =
new TTree(
"pid",
"PID tree");
85 m_tree->Branch(
"pValue", &
m_pid.pValue,
"pValue/F");
87 m_tree->Branch(
"motherPDG", &
m_pid.motherPDG,
"motherPDG/I");
88 m_tree->Branch(
"primary", &
m_pid.primary,
"primary/S");
89 m_tree->Branch(
"rhoProd", &
m_pid.rhoProd,
"rhoProd/F");
91 m_tree->Branch(
"phiProd", &
m_pid.phiProd,
"phiProd/F");
92 m_tree->Branch(
"rhoDec", &
m_pid.rhoDec,
"rhoDec/F");
94 m_tree->Branch(
"phiDec", &
m_pid.phiDec,
"phiDec/F");
95 m_tree->Branch(
"svd", &
m_pid.svddedx,
"le/F:lmu:lpi:lk:lp:ld:flag/S:seen/S");
96 m_tree->Branch(
"cdc", &
m_pid.cdcdedx,
"le/F:lmu:lpi:lk:lp:ld:flag/S:seen/S");
97 m_tree->Branch(
"top", &
m_pid.top,
"le/F:lmu:lpi:lk:lp:ld:flag/S:seen/S");
98 m_tree->Branch(
"arich", &
m_pid.arich,
"le/F:lmu:lpi:lk:lp:ld:flag/S:seen/S");
99 m_tree->Branch(
"ecl", &
m_pid.ecl,
"le/F:lmu:lpi:lk:lp:ld:flag/S:seen/S");
100 m_tree->Branch(
"klm", &
m_pid.klm,
"le/F:lmu:lpi:lk:lp:ld:flag/S:seen/S");
116 for (
const auto& track : tracks) {
120 B2WARNING(
"No track fit result... Skipping.");
126 B2WARNING(
"No track fit result... Skipping.");
132 if (mcParticle) mother = mcParticle->
getMother();
135 m_pid.evt = evtMetaData->getEvent();
136 m_pid.run = evtMetaData->getRun();
137 ROOT::Math::XYZVector momentum = trackFit->
getMomentum();
138 m_pid.p = momentum.R();
142 m_pid.cth = cos(momentum.Theta());
143 m_pid.phi = momentum.Phi();
147 if (mother)
m_pid.motherPDG = mother->getPDG();
150 m_pid.rhoProd = prodVertex.Rho();
151 m_pid.zProd = prodVertex.Z();
152 m_pid.phiProd = prodVertex.Phi();
154 m_pid.rhoDec = decVertex.Rho();
155 m_pid.zDec = decVertex.Z();
156 m_pid.phiDec = decVertex.Phi();
165 m_pid.cdcdedx.flag = pid->isAvailable(Const::CDC);
175 m_pid.svddedx.flag = pid->isAvailable(Const::SVD);
185 m_pid.top.flag = pid->isAvailable(Const::TOP);
195 m_pid.arich.flag = pid->isAvailable(Const::ARICH);
205 m_pid.ecl.flag = pid->isAvailable(Const::ECL);
215 m_pid.klm.flag = pid->isAvailable(Const::KLM);
227 TDirectory::TContext context;
static const ChargedStable muon
muon particle
static const ChargedStable pion
charged pion particle
static const ChargedStable proton
proton particle
static const ChargedStable kaon
charged kaon particle
static const ChargedStable electron
electron particle
static const ChargedStable deuteron
deuteron particle
A Class to store the Monte Carlo particle information.
@ c_PrimaryParticle
bit 0: Particle is primary particle.
ROOT::Math::XYZVector getDecayVertex() const
Return decay vertex.
bool hasSeenInDetector(Const::DetectorSet set) const
Return if the seen-in flag for a specific subdetector is set or not.
ROOT::Math::XYZVector getProductionVertex() const
Return production vertex position.
unsigned int getStatus(unsigned short int bitmask=USHRT_MAX) const
Return status code of particle.
int getPDG() const
Return PDG code of particle.
void setDescription(const std::string &description)
Sets the description of the module.
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
TTree * m_tree
TTree with PIDTree structure.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
bool m_makeFlat
if true, make momentum distribution flat up to m_pMax
virtual void terminate() override
Termination action.
double m_p2
parameter of momentum distribution
PID::PIDTree m_pid
PID tree structure.
PIDNtupleModule()
Constructor.
double momDistribution(double p) const
parameterized momentum distribution
double m_pMax
flatten distribution up to this momentum
double m_p1
parameter of momentum distribution
double m_value
distribution value at m_pMax
double m_norm
distribution normalization
std::string m_outputFileName
output file name
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Accessor to arrays stored in the data store.
Type-safe access to single objects in the data store.
Values of the result of a track fit with a given particle hypothesis.
double getPValue() const
Getter for Chi2 Probability of the track fit.
ROOT::Math::XYZVector getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
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.
MCParticle * getMother() const
Returns a pointer to the mother particle.
Abstract base class for different kinds of events.