Belle II Software  release-05-02-19
CDCTriggerRecoHitMatcherModule.cc
1 #include "trg/cdc/modules/mcmatcher/CDCTriggerRecoHitMatcherModule.h"
2 
3 #include <cdc/dataobjects/CDCHit.h>
4 
5 #include <framework/gearbox/Const.h>
6 
7 namespace {
8  //small anonymous helper construct making converting a pair of iterators usable
9  //with range based for
10  template<class Iter>
11  struct iter_pair_range : std::pair<Iter, Iter> {
12  iter_pair_range(std::pair<Iter, Iter> const& x) : std::pair<Iter, Iter>(x) {}
13  Iter begin() const {return this->first;}
14  Iter end() const {return this->second;}
15  };
16 
17  template<class Iter>
18  inline iter_pair_range<Iter> as_range(std::pair<Iter, Iter> const& x)
19  {
20  return iter_pair_range<Iter>(x);
21  }
22 
23  typedef int HitId;
24  typedef int TrackId;
25  typedef float Purity;
26  typedef float Efficiency;
27 }
28 
29 
30 
31 using namespace Belle2;
32 using namespace std;
33 
34 //this line registers the module with the framework and actually makes it available
35 //in steering files or the the module list (basf2 -m).
36 REG_MODULE(CDCTriggerRecoHitMatcher)
37 
39 {
40  setDescription("A module to match CDCTriggerTracks to RecoTracks.\n"
41  "First makes relations from RecoTracks to CDCTriggerSegmentHits, "
42  "then makes relations from RecoTracks to CDCTriggerTracks "
43  "and vice-versa.");
44 
45  addParam("RecoTrackCollectionName", m_RecoTrackCollectionName,
46  "Name of the RecoTrack StoreArray to be matched.",
47  string("RecoTracks"));
48  addParam("MCParticleCollectionName", m_MCParticleCollectionName,
49  "Name of the MCParticle StoreArray to be matched.",
50  string("MCParticles"));
51  addParam("MCTrackableCollectionName", m_MCTrackableCollectionName,
52  "Name of a new StoreArray holding MCParticles considered as trackable.",
53  string("MCTracks"));
54  addParam("RecoTrackableCollectionName", m_RecoTrackableCollectionName,
55 
56  "Name of the StoreArray holding primary MCParticle matched to a RecoTrack, but the vertex and momentum is overridden with the RecoTrack values.",
57  string("RecoTrackable"));
58  addParam("hitCollectionName", m_hitCollectionName,
59  "Name of the StoreArray of CDCTriggerSegmentHits used for the matching.",
60  string(""));
61  addParam("TrackCollectionName", m_TrackCollectionName,
62  "Name of the Track StoreArray.",
63  string("Tracks"));
64 }
65 
66 
67 void
69 {
70  m_segmentHits.isRequired(m_hitCollectionName);
71  m_recoTracks.isRequired(m_RecoTrackCollectionName);
72  m_recoTrackable.registerInDataStore(m_RecoTrackableCollectionName);
73  m_mdstTracks.isRequired(m_TrackCollectionName);
74 
75  m_recoTracks.registerRelationTo(m_segmentHits);
76  m_recoTrackable.registerRelationTo(m_segmentHits);
77  m_recoTrackable.registerRelationTo(m_recoTracks);
78 }
79 
80 
81 void
83 {
84  // create relations from RecoTracks to SegmentHits via CDCHits
85  for (int ireco = 0; ireco < m_recoTracks.getEntries(); ++ireco) {
86  RecoTrack* recoTrack = m_recoTracks[ireco];
87  // if relations exist already, skip this step
88  // (matching may be done several times with different trigger tracks)
89  bool relateReco = true;
90  if (recoTrack->getRelationsTo<CDCTriggerSegmentHit>(m_hitCollectionName).size() > 0)
91  relateReco = false;
92  if (recoTrack->getRelationsTo<Track>(m_TrackCollectionName).size() == 0)
93  continue;
94  Track* ttrack = recoTrack->getRelatedFrom<Track>(m_TrackCollectionName);
96  211));
97  continue;
98  if (fitres) {
99  // double omega = fitres->getOmega();
100  TVector3 mom = fitres->getMomentum();
101  // double pt = mom.Pt();
102  // double phi = mom.Phi();
103  // double theta = mom.theta();
104  TVector3 vtx = fitres->getPosition();
105 
106 
107  MCParticle* recoTrackable = m_recoTrackable.appendNew();
108  recoTrackable->setProductionVertex(vtx);
109  recoTrackable->setMomentum(mom);
110  recoTrackable->addRelationTo(recoTrack);
111  }
112 
113  vector<CDCHit*> cdcHits = recoTrack->getCDCHitList();
114  for (unsigned iHit = 0; iHit < cdcHits.size(); ++iHit) {
116  cdcHits[iHit]->getRelationsFrom<CDCTriggerSegmentHit>(m_hitCollectionName);
117  for (unsigned iTS = 0; iTS < relHits.size(); ++iTS) {
118  // create relations only for priority hits (relation weight 2)
119  if (relHits.weight(iTS) > 1) {
120  if (relateReco)
121  recoTrack->addRelationTo(relHits[iTS]);
122  }
123  }
124  }
125  }
126 }
Belle2::RelationVector::size
size_t size() const
Get number of relations.
Definition: RelationVector.h:98
Belle2::TrackFitResult::getMomentum
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
Definition: TrackFitResult.h:116
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::RecoTrack::getCDCHitList
std::vector< Belle2::RecoTrack::UsedCDCHit * > getCDCHitList() const
Return an unsorted list of cdc hits.
Definition: RecoTrack.h:446
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::TrackFitResult
Values of the result of a track fit with a given particle hypothesis.
Definition: TrackFitResult.h:59
Belle2::RelationsInterface::getRelationsTo
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Definition: RelationsObject.h:199
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::CDCTriggerRecoHitMatcherModule
A module to match CDCTriggerTracks to RecoTracks.
Definition: CDCTriggerRecoHitMatcherModule.h:24
Belle2::RelationVector
Class for type safe access to objects that are referred to in relations.
Definition: DataStore.h:38
Belle2::Track::getTrackFitResultWithClosestMass
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
Definition: Track.cc:70
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MCParticle::setProductionVertex
void setProductionVertex(const TVector3 &vertex)
Set production vertex position.
Definition: MCParticle.h:404
Belle2::CDCTriggerRecoHitMatcherModule::initialize
virtual void initialize() override
Initialize the module.
Definition: CDCTriggerRecoHitMatcherModule.cc:68
Belle2::RelationVector::weight
float weight(int index) const
Get weight with index.
Definition: RelationVector.h:120
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::CDCTriggerRecoHitMatcherModule::event
virtual void event() override
Called once for each event.
Definition: CDCTriggerRecoHitMatcherModule.cc:82
Belle2::MCParticle::setMomentum
void setMomentum(const TVector3 &momentum)
Set particle momentum.
Definition: MCParticle.h:425
Belle2::CDCTriggerSegmentHit
Combination of several CDCHits to a track segment hit for the trigger.
Definition: CDCTriggerSegmentHit.h:16
Belle2::RelationsInterface::getRelatedFrom
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
Definition: RelationsObject.h:265