Belle II Software development
CDCTriggerRecoHitMatcherModule.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 "trg/cdc/modules/mcmatcher/CDCTriggerRecoHitMatcherModule.h"
9
10#include <cdc/dataobjects/CDCHit.h>
11
12#include <framework/gearbox/Const.h>
13
14namespace {
15 //small anonymous helper construct making converting a pair of iterators usable
16 //with range based for
17 template<class Iter>
18 struct iter_pair_range : std::pair<Iter, Iter> {
19 explicit iter_pair_range(std::pair<Iter, Iter> const& x) : std::pair<Iter, Iter>(x) {}
20 Iter begin() const {return this->first;}
21 Iter end() const {return this->second;}
22 };
23
24 template<class Iter>
25 inline iter_pair_range<Iter> as_range(std::pair<Iter, Iter> const& x)
26 {
27 return iter_pair_range<Iter>(x);
28 }
29
30 typedef int HitId;
31 typedef int TrackId;
32 typedef float Purity;
33 typedef float Efficiency;
34}
35
36
37
38using namespace Belle2;
39using namespace std;
40
41//this line registers the module with the framework and actually makes it available
42//in steering files or the the module list (basf2 -m).
43REG_MODULE(CDCTriggerRecoHitMatcher);
44
46{
47 setDescription("A module to match CDCTriggerTracks to RecoTracks.\n"
48 "First makes relations from RecoTracks to CDCTriggerSegmentHits, "
49 "then makes relations from RecoTracks to CDCTriggerTracks "
50 "and vice-versa.");
51
52 addParam("RecoTrackCollectionName", m_RecoTrackCollectionName,
53 "Name of the RecoTrack StoreArray to be matched.",
54 string("RecoTracks"));
55 addParam("MCParticleCollectionName", m_MCParticleCollectionName,
56 "Name of the MCParticle StoreArray to be matched.",
57 string("MCParticles"));
58 addParam("MCTrackableCollectionName", m_MCTrackableCollectionName,
59 "Name of a new StoreArray holding MCParticles considered as trackable.",
60 string("MCTracks"));
61 addParam("RecoTrackableCollectionName", m_RecoTrackableCollectionName,
62
63 "Name of the StoreArray holding primary MCParticle matched to a RecoTrack, but the vertex and momentum is overridden with the RecoTrack values.",
64 string("RecoTrackable"));
65 addParam("hitCollectionName", m_hitCollectionName,
66 "Name of the StoreArray of CDCTriggerSegmentHits used for the matching.",
67 string(""));
68 addParam("TrackCollectionName", m_TrackCollectionName,
69 "Name of the Track StoreArray.",
70 string("Tracks"));
71}
72
73
74void
76{
81
85}
86
87
88void
90{
91 /*
92 // create relations from RecoTracks to SegmentHits via CDCHits
93 for (int ireco = 0; ireco < m_recoTracks.getEntries(); ++ireco) {
94 RecoTrack* recoTrack = m_recoTracks[ireco];
95 // if relations exist already, skip this step
96 // (matching may be done several times with different trigger tracks)
97 bool relateReco = true;
98 if (recoTrack->getRelationsTo<CDCTriggerSegmentHit>(m_hitCollectionName).size() > 0)
99 relateReco = false;
100 if (recoTrack->getRelationsTo<Track>(m_TrackCollectionName).size() == 0)
101 continue;
102 Track* ttrack = recoTrack->getRelatedFrom<Track>(m_TrackCollectionName);
103 const TrackFitResult* fitres = ttrack->getTrackFitResultWithClosestMass(Belle2::Const::ChargedStable(
104 211));
105 continue;
106 if (fitres) {
107 // double omega = fitres->getOmega();
108 TVector3 mom = fitres->getMomentum();
109 // double pt = mom.Pt();
110 // double phi = mom.Phi();
111 // double theta = mom.theta();
112 TVector3 vtx = fitres->getPosition();
113
114
115 MCParticle* recoTrackable = m_recoTrackable.appendNew();
116 recoTrackable->setProductionVertex(vtx);
117 recoTrackable->setMomentum(mom);
118 recoTrackable->addRelationTo(recoTrack);
119 }
120
121 vector<CDCHit*> cdcHits = recoTrack->getCDCHitList();
122 for (unsigned iHit = 0; iHit < cdcHits.size(); ++iHit) {
123 RelationVector<CDCTriggerSegmentHit> relHits =
124 cdcHits[iHit]->getRelationsFrom<CDCTriggerSegmentHit>(m_hitCollectionName);
125 for (unsigned iTS = 0; iTS < relHits.size(); ++iTS) {
126 // create relations only for priority hits (relation weight 2)
127 if (relHits.weight(iTS) > 1) {
128 if (relateReco)
129 recoTrack->addRelationTo(relHits[iTS]);
130 }
131 }
132 }
133 }
134 */
135}
StoreArray< MCParticle > m_recoTrackable
list of MCParticles where x and p is overriden with the matched RecoTrack values
std::string m_MCParticleCollectionName
Name of the MCParticle StoreArray to be matched.
StoreArray< Track > m_mdstTracks
list of mdst Tracks
std::string m_MCTrackableCollectionName
Name of a new StoreArray holding MCParticles considered as trackable.
virtual void initialize() override
Initialize the module.
CDCTriggerRecoHitMatcherModule()
Constructor, for setting module description and parameters.
std::string m_RecoTrackCollectionName
Name of the RecoTrack StoreArray to be matched.
virtual void event() override
Called once for each event.
StoreArray< CDCTriggerSegmentHit > m_segmentHits
list of hits that are used for the matching
std::string m_RecoTrackableCollectionName
Name of the StoreArray holding primary MCParticle matched to a RecoTrack, but the vertex and momentum...
std::string m_TrackCollectionName
Name of a new StoreArray holding Tracks.
StoreArray< RecoTrack > m_recoTracks
list of RecoTracks to be matched
std::string m_hitCollectionName
Name of the StoreArray containing the hits that are used for the matching.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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 registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
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.
STL namespace.