Belle II Software  release-08-01-10
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/geometry/B2Vector3.h>
11 #include <TVector3.h>
12 #include <TMatrixDSym.h>
13 
14 #include <cmath>
15 
16 using namespace Belle2;
17 
18 REG_MODULE(RecoTrackParticleLoader);
19 
21  Module()
22 {
24  "Takes fitted RecoTracks and creates Particles from them directly, skipping the step of creating Tracks and TrackFitResults.");
26 
27  addParam("recoTrackColName", m_recoTrackColName,
28  "Name of the collection holding the input RecoTrack", m_recoTrackColName);
29  addParam("particleListName", m_particleListName,
30  "Name of the particleList holding the output Particles", m_particleListName);
31  addParam("pdgCode", m_pdgCode,
32  "PDG code of the hypothesis of the output Particles", m_pdgCode);
33 }
34 
36 {
38 
39  m_Particles.registerInDataStore();
40  m_Particles.registerRelationTo(m_RecoTracks);
41 
42  // Seems to not be needed anywhere, no idea why it's here
44  extraInfo.registerInDataStore();
45 
46  m_ParticleList.registerInDataStore(m_particleListName);
47 }
48 
50 {
51  m_ParticleList.create();
53 
54  for (auto& recoTrack : m_RecoTracks) {
55  if (!recoTrack.wasFitSuccessful()) {
56  B2DEBUG(20, "Skipping unfitted RecoTrack.");
57  continue;
58  }
59  auto rep = recoTrack.getCardinalRepresentation();
60  int pdg = rep->getPDG();
61  auto firstHit = recoTrack.getMeasuredStateOnPlaneFromFirstHit(rep);
62  genfit::MeasuredStateOnPlane extrapolatedMSoP = firstHit;
63  try {
64  extrapolatedMSoP.extrapolateToLine(B2Vector3D(0.0, 0.0, 0.0), B2Vector3D(0.0, 0.0, 1.0));
65  } catch (...) {
66  B2WARNING("Could not extrapolate the fit result for pdg " << pdg <<
67  " to the IP. Why, I don't know.");
68  continue;
69  }
70  TVector3 pos;
71  TVector3 mom;
72  TMatrixDSym cov;
73  extrapolatedMSoP.getPosMomCov(pos, mom, cov);
74  double mass = rep->getMass(extrapolatedMSoP);
75  double charge = rep->getCharge(extrapolatedMSoP); // mplTrackRep returns magnetic charge
76  double E = std::sqrt(mom.x() * mom.x() + mom.y() * mom.y() + mom.z() * mom.z() + mass * mass);
77  double pValue = recoTrack.getTrackFitStatus(rep)->getPVal();
78  ROOT::Math::PxPyPzEVector lorentzMom(mom.x(), mom.y(), mom.z(), E);
79 
80  Particle* newPart = m_Particles.appendNew(lorentzMom, pdg);
81  newPart->setVertex(ROOT::Math::XYZVector(pos));
82  newPart->setPValue(pValue);
83  newPart->writeExtraInfo("magCharge", charge);
84  newPart->writeExtraInfo("massFromFit", mass);
85  newPart->addRelationTo(&recoTrack);
86  if (std::abs(pdg) == m_pdgCode) m_ParticleList->addParticle(newPart);
87  }
88 }
R E
internal precision of FFTW codelets
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
Class to store reconstructed particles.
Definition: Particle.h:75
void writeExtraInfo(const std::string &name, const double value)
Sets the user defined extraInfo.
Definition: Particle.cc:1309
void setVertex(const ROOT::Math::XYZVector &vertex)
Sets position (decay vertex)
Definition: Particle.h:295
void setPValue(double pValue)
Sets chi^2 probability of fit.
Definition: Particle.h:338
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.
StoreArray< Particle > m_Particles
Particles StoreArray.
std::string m_recoTrackColName
Name of the collection holding the input RecoTracks.
StoreObjPtr< ParticleList > m_ParticleList
ParticleList StoreObjPtr.
int m_pdgCode
PDG code of the hypothesis of the output Particles.
StoreArray< RecoTrack > m_RecoTracks
RecoTracks StoreArray.
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.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
#StateOnPlane with additional covariance matrix.
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:516
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.