Belle II Software  release-05-02-19
RecoTrackParticleLoaderModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Dmitrii Neverov *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/modules/recoTrackParticleLoader/RecoTrackParticleLoaderModule.h>
11 
12 #include <framework/datastore/StoreArray.h>
13 
14 #include <analysis/dataobjects/Particle.h>
15 #include <analysis/dataobjects/ParticleList.h>
16 #include <analysis/dataobjects/ParticleExtraInfoMap.h>
17 #include <tracking/dataobjects/RecoTrack.h>
18 
19 #include <TVector3.h>
20 #include <TLorentzVector.h>
21 #include <TMatrixDSym.h>
22 
23 #include <cmath>
24 
25 using namespace Belle2;
26 
27 REG_MODULE(RecoTrackParticleLoader)
28 
30  Module()
31 {
32  setDescription(
33  "Takes fitted RecoTracks and creates Particles from them directly, skipping the step of creating Tracks and TrackFitResults.");
34  setPropertyFlags(c_ParallelProcessingCertified);
35 
36  addParam("recoTrackColName", m_recoTrackColName,
37  "Name of the collection holding the input RecoTrack", m_recoTrackColName);
38  addParam("particleListName", m_particleListName,
39  "Name of the particleList holding the output Particles", m_particleListName);
40  addParam("pdgCode", m_pdgCode,
41  "PDG code of the hypothesis of the output Particles", m_pdgCode);
42 }
43 
45 {
47  recoTracks.isRequired();
48 
49  StoreArray<Particle> particles;
50  particles.registerInDataStore();
51  particles.registerRelationTo(recoTracks);
52 
54  extraInfo.registerInDataStore();
55 
57  pList.registerInDataStore();
58 }
59 
61 {
63  StoreArray<Particle> particles;
65  pList.create();
66  pList->initialize(m_pdgCode, m_particleListName);
67 
68  for (auto& recoTrack : recoTracks) {
69  if (!recoTrack.wasFitSuccessful()) {
70  B2DEBUG(20, "Skipping unfitted RecoTrack.");
71  continue;
72  }
73  auto rep = recoTrack.getCardinalRepresentation();
74  int pdg = rep->getPDG();
75  auto firstHit = recoTrack.getMeasuredStateOnPlaneFromFirstHit(rep);
76  genfit::MeasuredStateOnPlane extrapolatedMSoP = firstHit;
77  try {
78  extrapolatedMSoP.extrapolateToLine(TVector3(0.0, 0.0, 0.0), TVector3(0.0, 0.0, 1.0));
79  } catch (...) {
80  B2WARNING("Could not extrapolate the fit result for pdg " << pdg <<
81  " to the IP. Why, I don't know.");
82  continue;
83  }
84  TVector3 pos;
85  TVector3 mom;
86  TMatrixDSym cov;
87  extrapolatedMSoP.getPosMomCov(pos, mom, cov);
88  double mass = rep->getMass(extrapolatedMSoP);
89  double charge = rep->getCharge(extrapolatedMSoP); // mplTrackRep returns magnetic charge
90  double E = std::sqrt(mom.x() * mom.x() + mom.y() * mom.y() + mom.z() * mom.z() + mass * mass);
91  double pValue = recoTrack.getTrackFitStatus(rep)->getPVal();
92  TLorentzVector lorentzMom(mom.x(), mom.y(), mom.z(), E);
93 
94  Particle* newPart = particles.appendNew(lorentzMom, pdg);
95  newPart->setVertex(pos);
96  newPart->setPValue(pValue);
97  newPart->writeExtraInfo("magCharge", charge);
98  newPart->writeExtraInfo("massFromFit", mass);
99  newPart->addRelationTo(&recoTrack);
100  if (std::abs(pdg) == m_pdgCode) pList->addParticle(newPart);
101  }
102 }
Belle2::Particle::writeExtraInfo
void writeExtraInfo(const std::string &name, const float value)
Sets the user defined extraInfo.
Definition: Particle.cc:1196
genfit::MeasuredStateOnPlane
#StateOnPlane with additional covariance matrix.
Definition: MeasuredStateOnPlane.h:39
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::RecoTrackParticleLoaderModule
Takes fitted RecoTracks and creates Particles from them directly, skipping the step of creating Track...
Definition: RecoTrackParticleLoaderModule.h:42
Belle2::RecoTrackParticleLoaderModule::m_pdgCode
int m_pdgCode
PDG code of the hypothesis of the output Particles.
Definition: RecoTrackParticleLoaderModule.h:62
Belle2::RelationsInterface::addRelationTo
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
Definition: RelationsObject.h:144
Belle2::RecoTrackParticleLoaderModule::initialize
void initialize() override
Require and register the datastore arrays.
Definition: RecoTrackParticleLoaderModule.cc:44
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::RecoTrackParticleLoaderModule::m_particleListName
std::string m_particleListName
Name of the particleList holding the output Particles.
Definition: RecoTrackParticleLoaderModule.h:59
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::Particle::setVertex
void setVertex(const TVector3 &vertex)
Sets position (decay vertex)
Definition: Particle.h:291
Belle2::RecoTrackParticleLoaderModule::m_recoTrackColName
std::string m_recoTrackColName
Name of the collection holding the input RecoTracks.
Definition: RecoTrackParticleLoaderModule.h:56
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::RecoTrackParticleLoaderModule::event
void event() override
Build Particle array.
Definition: RecoTrackParticleLoaderModule.cc:60
Belle2::Particle::setPValue
void setPValue(float pValue)
Sets chi^2 probability of fit.
Definition: Particle.h:308