Belle II Software development
TrackToMCParticleRelatorModule.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/mcMatcher/TrackToMCParticleRelatorModule.h>
9
10#include <framework/datastore/RelationVector.h>
11#include <mdst/dataobjects/MCParticle.h>
12#include <mdst/dataobjects/Track.h>
13#include <tracking/dataobjects/RecoTrack.h>
14
15using namespace Belle2;
16
17REG_MODULE(TrackToMCParticleRelator);
18
20{
21 setDescription("A module to set relations from Track to MCParticle via the RecoTrack the Track is related to. The functionality is: Take Track, get relation to RecoTrack, from RecoTrack get relation to MCParticle, and finally add a relation from Track to MCParticle.");
23
24 //input
25 addParam("TracksName", m_TracksName,
26 "Name of the Tracks StoreArray to be used.", m_TracksName);
27 addParam("RecoTracksName", m_RecoTracksName,
28 "Name of the RecoTracks StoreArray to be used.", m_RecoTracksName);
29 addParam("MCParticlesName", m_MCParticlesName, "Name of the MCParticles StoreArray to be used.", m_MCParticlesName);
30}
31
33{
34 m_Tracks.isRequired(m_TracksName);
36 // Can't require MCParticles, as this module is also run during data reconstruction
37 StoreArray<MCParticle> mcParticles;
39
41 m_Tracks.registerRelationTo(mcParticles);
42 }
43}
44
46{
47 // Don't do anything if MCParticles aren't present
48 if (not m_mcParticlesPresent) {
49 return;
50 }
51
52 for (const auto& track : m_Tracks) {
53 const RelationVector<RecoTrack>& recoTracks = track.getRelationsTo<RecoTrack>(m_RecoTracksName);
54 const auto& mcParticleWithWeight = recoTracks[0]->getRelatedToWithWeight<MCParticle>(m_MCParticlesName);
55 const MCParticle* mcParticle = mcParticleWithWeight.first;
56 if (mcParticle) {
57 B2DEBUG(28, "Relation to MCParticle set.");
58 track.addRelationTo(mcParticle, mcParticleWithWeight.second);
59 } else {
60 B2DEBUG(28, "Relation to MCParticle not set. No related MCParticle to RecoTrack.");
61 }
62 }
63
64 B2DEBUG(20, "MC matching finished.");
65}
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
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
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
Class for type safe access to objects that are referred to in relations.
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.
Definition: StoreArray.h:113
std::string m_TracksName
Track StoreArray name (input).
void initialize() override
Use this to initialize StoreArrays and relations.
void event() override
Called once for each event.
TrackToMCParticleRelatorModule()
Constructor, for setting module description and parameters.
std::string m_RecoTracksName
RecoTrack StoreArray name (input).
std::string m_MCParticlesName
MCParticle StoreArray name ().
StoreArray< RecoTrack > m_RecoTracks
RecoTracks StoreArray.
StoreArray< Track > m_Tracks
Tracks StoreArray *‍/.
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
#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.