Belle II Software  release-06-00-14
RecoTrackParticleLoaderModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <tracking/modules/recoTrackParticleLoader/RecoTrackParticleLoaderModule.h>
9 
10 #include <framework/datastore/StoreArray.h>
11 
12 #include <analysis/dataobjects/Particle.h>
13 #include <analysis/dataobjects/ParticleList.h>
14 #include <analysis/dataobjects/ParticleExtraInfoMap.h>
15 #include <tracking/dataobjects/RecoTrack.h>
16 
17 #include <TVector3.h>
18 #include <TLorentzVector.h>
19 #include <TMatrixDSym.h>
20 
21 #include <cmath>
22 
23 using namespace Belle2;
24 
25 REG_MODULE(RecoTrackParticleLoader)
26 
28  Module()
29 {
30  setDescription(
31  "Takes fitted RecoTracks and creates Particles from them directly, skipping the step of creating Tracks and TrackFitResults.");
32  setPropertyFlags(c_ParallelProcessingCertified);
33 
34  addParam("recoTrackColName", m_recoTrackColName,
35  "Name of the collection holding the input RecoTrack", m_recoTrackColName);
36  addParam("particleListName", m_particleListName,
37  "Name of the particleList holding the output Particles", m_particleListName);
38  addParam("pdgCode", m_pdgCode,
39  "PDG code of the hypothesis of the output Particles", m_pdgCode);
40 }
41 
43 {
45  recoTracks.isRequired();
46 
47  StoreArray<Particle> particles;
48  particles.registerInDataStore();
49  particles.registerRelationTo(recoTracks);
50 
52  extraInfo.registerInDataStore();
53 
55  pList.registerInDataStore();
56 }
57 
59 {
61  StoreArray<Particle> particles;
63  pList.create();
64  pList->initialize(m_pdgCode, m_particleListName);
65 
66  for (auto& recoTrack : recoTracks) {
67  if (!recoTrack.wasFitSuccessful()) {
68  B2DEBUG(20, "Skipping unfitted RecoTrack.");
69  continue;
70  }
71  auto rep = recoTrack.getCardinalRepresentation();
72  int pdg = rep->getPDG();
73  auto firstHit = recoTrack.getMeasuredStateOnPlaneFromFirstHit(rep);
74  genfit::MeasuredStateOnPlane extrapolatedMSoP = firstHit;
75  try {
76  extrapolatedMSoP.extrapolateToLine(TVector3(0.0, 0.0, 0.0), TVector3(0.0, 0.0, 1.0));
77  } catch (...) {
78  B2WARNING("Could not extrapolate the fit result for pdg " << pdg <<
79  " to the IP. Why, I don't know.");
80  continue;
81  }
82  TVector3 pos;
83  TVector3 mom;
84  TMatrixDSym cov;
85  extrapolatedMSoP.getPosMomCov(pos, mom, cov);
86  double mass = rep->getMass(extrapolatedMSoP);
87  double charge = rep->getCharge(extrapolatedMSoP); // mplTrackRep returns magnetic charge
88  double E = std::sqrt(mom.x() * mom.x() + mom.y() * mom.y() + mom.z() * mom.z() + mass * mass);
89  double pValue = recoTrack.getTrackFitStatus(rep)->getPVal();
90  TLorentzVector lorentzMom(mom.x(), mom.y(), mom.z(), E);
91 
92  Particle* newPart = particles.appendNew(lorentzMom, pdg);
93  newPart->setVertex(pos);
94  newPart->setPValue(pValue);
95  newPart->writeExtraInfo("magCharge", charge);
96  newPart->writeExtraInfo("massFromFit", mass);
97  newPart->addRelationTo(&recoTrack);
98  if (std::abs(pdg) == m_pdgCode) pList->addParticle(newPart);
99  }
100 }
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:74
void setPValue(float pValue)
Sets chi^2 probability of fit.
Definition: Particle.h:320
void writeExtraInfo(const std::string &name, const float value)
Sets the user defined extraInfo.
Definition: Particle.cc:1261
void setVertex(const TVector3 &vertex)
Sets position (decay vertex)
Definition: Particle.h:288
Takes fitted RecoTracks and creates Particles from them directly, skipping the step of creating Track...
std::string m_particleListName
Name of the particleList holding the output Particles.
void initialize() override
Require and register the datastore arrays.
void event() override
Build Particle array.
std::string m_recoTrackColName
Name of the collection holding the input RecoTracks.
int m_pdgCode
PDG code of the hypothesis of the output Particles.
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).
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
#StateOnPlane with additional covariance matrix.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.