10#include <top/modules/TOPNtuple/TOPNtupleModule.h>
13#include <top/geometry/TOPGeometryPar.h>
14#include <top/reconstruction_cpp/TOPRecoManager.h>
17#include <framework/datastore/StoreArray.h>
18#include <framework/datastore/StoreObjPtr.h>
21#include <framework/gearbox/Const.h>
22#include <framework/logging/Logger.h>
25#include <framework/dataobjects/EventMetaData.h>
26#include <framework/dataobjects/MCInitialParticles.h>
27#include <mdst/dataobjects/Track.h>
28#include <mdst/dataobjects/MCParticle.h>
29#include <top/dataobjects/TOPLikelihood.h>
30#include <top/dataobjects/TOPBarHit.h>
31#include <top/dataobjects/TOPDigit.h>
32#include <tracking/dataobjects/ExtHit.h>
35#include <TDirectory.h>
60 setDescription(
"Writes ntuple of TOPLikelihoods with tracking info into a root file");
64 string(
"TOPNtuple.root"));
74 TDirectory::TContext context;
81 m_tree =
new TTree(
"top",
"TOP validation ntuple");
110 m_tree->Branch(
"extHit", &
m_top.
extHit,
"moduleID/I:PDG:x/F:y:z:p:theta:phi:time");
111 m_tree->Branch(
"barHit", &
m_top.
barHit,
"moduleID/I:PDG:x/F:y:z:p:theta:phi:time");
137 double trueEventT0 = 0;
138 if (mcInitialParticles.
isValid()) trueEventT0 = mcInitialParticles->getTime();
142 for (
const auto& track : tracks) {
143 const auto* trackFit = track.getTrackFitResultWithClosestMass(
Const::pion);
144 if (!trackFit)
continue;
147 if (top->getFlag() != 1)
continue;
157 for (
const auto& bHit : barHits) {
158 if (bHit.getModuleID() == extHit->
getCopyID()) barHit = &bHit;
165 m_top.
evt = evtMetaData->getEvent();
168 ROOT::Math::XYZVector mom = trackFit->getMomentum();
178 m_top.
seen = mcParticle->hasSeenInDetector(Const::TOP);
179 ROOT::Math::XYZVector prodVertex = mcParticle->getProductionVertex();
183 ROOT::Math::XYZVector decVertex = mcParticle->getDecayVertex();
187 const auto digits = mcParticle->getRelationsWith<
TOPDigit>();
188 for (
size_t i = 0; i < digits.size(); i++) {
189 double wt = digits.weight(i);
190 if (wt <= 0)
continue;
191 const auto* digit = digits[i];
192 if (digit->getHitQuality() != TOPDigit::c_Good)
continue;
193 if (digit->getModuleID() != top->getModuleID())
continue;
226 auto position =
static_cast<ROOT::Math::XYZPoint
>(extHit->
getPosition());
228 if (geo->isModuleIDValid(moduleID)) {
229 const auto& module = geo->getModule(moduleID);
230 position = module.pointToLocal(position);
231 momentum = module.momentumToLocal(momentum);
245 int moduleID = barHit->getModuleID();
246 auto position = barHit->getPosition();
247 auto momentum = barHit->getMomentum();
248 if (geo->isModuleIDValid(moduleID)) {
249 const auto& module = geo->getModule(moduleID);
250 position = module.pointToLocal(position);
251 momentum = module.momentumToLocal(momentum);
276 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
Store one Ext hit as a ROOT object.
int getPdgCode() const
Get PDG code of this extrapolation's hypothesis.
int getCopyID() const
Get detector-element ID of sensitive element within detector.
ROOT::Math::XYZVector getMomentum() const
Get momentum at this extrapolation hit.
ROOT::Math::XYZVector getPosition() const
Get position of this extrapolation hit.
double getTOF() const
Get time of flight from the point of closest approach near the origin to this hit.
A Class to store the Monte Carlo particle information.
@ c_PrimaryParticle
bit 0: Particle is primary particle.
void setDescription(const std::string &description)
Sets the description of the module.
RelationVector< T > getRelationsWith(const std::string &name="", const std::string &namedRelation="") const
Get the relations between this object and another store array.
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.
bool isValid() const
Check whether the object was created.
Class to store track parameters of incoming MC particles relation to MCParticle filled in top/simulat...
Class to store TOP digitized hits (output of TOPDigitizer or raw data unpacker) relations to TOPSimHi...
Class to store TOP log likelihoods (output of TOPReconstructor).
TTree * m_tree
TTree with TOPTree structure.
TOP::TOPTree m_top
ntuple structure
std::string m_outputFileName
output file name (root file)
const TOPGeometry * getGeometry() const
Returns pointer to geometry object using basf2 units.
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
static double getMaxTime()
Returns time window upper edge.
static double getMinTime()
Returns time window lower edge.
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.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
TOPNtupleModule()
Constructor.
virtual void endRun() override
End-of-run action.
virtual void terminate() override
Termination action.
virtual ~TOPNtupleModule()
Destructor.
virtual void beginRun() override
Called when entering a new run.
Abstract base class for different kinds of events.
Float_t zDec
decay vertex (cylindrical coordinate z) of MCParticle
Float_t p
momentum magnitude of Track
Likelihoods logL
log likelihoods
Float_t rhoDec
decay vertex (cylindrical coordinate r) of MCParticle
Int_t numPhot
number of detected photons
Int_t moduleID
module ID from TOPLikelihoods
Short_t primary
is a primary particle (from related MCParticle)
Likelihoods yield
effective signal yields by sPlot
Float_t phi
azimuthal angle of Track
Float_t numBkg
number of expected background photons
Short_t seen
is seen in TOP (from related MCParticle)
TrackHit extHit
extrapolated Track hit (in local module frame)
Int_t motherPDG
PDG code of related mother MCParticle.
Float_t phiProd
production vertex (cylindrical coordinate phi) of MCParticle
Float_t cth
cosine of polar angle of Track
Float_t rhoProd
production vertex (cylindrical coordinate r) of MCParticle
void clear()
Clear the structure: set elements to zero.
Float_t phiDec
decay vertex (cylindrical coordinate phi) of MCParticle
Int_t PDG
PDG code of related MCParticle.
Float_t pValue
p-value of Track fit
Likelihoods phot
number of expected photons (signal + bkg)
Float_t zProd
production vertex (cylindrical coordinate z) of MCParticle
TrackHit barHit
related MC particle hit (in local module frame)
Int_t yieldMC
signal yield MC truth
Float_t p
momentum magnitude
Float_t z
impact point, z component
Float_t theta
momentum polar angle
Float_t phi
momentum azimuthal angle
Float_t x
impact point, x component
Float_t y
impact point, y component