Belle II Software development
VXDCDCTrackMergerModule.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/vxdCDCTrackMerger/VXDCDCTrackMergerModule.h>
9
10#include <tracking/trackFitting/fitter/base/TrackFitter.h>
11
12using namespace Belle2;
13
14REG_MODULE(VXDCDCTrackMerger);
15
17 Module(), m_CDC_wall_radius(16.25)
18{
20 "This module merges tracks which are reconstructed, separately, in the silicon (PXD+VXD) and in the CDC");
22
23 //input
24 addParam("CDCRecoTrackColName", m_CDCRecoTrackColName, "CDC Reco Tracks");
25 addParam("VXDRecoTrackColName", m_VXDRecoTrackColName, "VXD Reco Tracks");
26
27 //merging parameters
28 addParam("merge_radius", m_merge_radius,
29 "Maximum distance between extrapolated tracks on the CDC wall",
30 double(2.0));
31}
32
34{
37
40}
41
43{
44 //get CDC tracks
45 unsigned int nCDCTracks = m_CDCRecoTracks.getEntries();
46 B2DEBUG(29, "VXDCDCTrackMerger: input Number of CDC Tracks: " << nCDCTracks);
47
48 //get VXD tracks
49 unsigned int nVXDTracks = m_VXDRecoTracks.getEntries();
50 B2DEBUG(29,
51 "VXDCDCTrackMerger: input Number of VXD Tracks: " << nVXDTracks);
52
53 // position and momentum used for extrapolations to the CDC Wall
54 B2Vector3D position(0., 0., 0.);
55 B2Vector3D momentum(0., 0., 1.);
56 // position and momentum of the track extrapolated from the CDC fit to the CDC Wall
57 B2Vector3D cdcpos;
58 B2Vector3D cdcmom;
59 // position and momentum of the track extrapolated from the VXD fit to the CDC Wall
60 B2Vector3D vxdpos;
61 B2Vector3D vxdmom;
62
63 // Fit all cdc and vxd tracks
64 TrackFitter fitter;
65 for (auto& cdcTrack : m_CDCRecoTracks) {
66 fitter.fit(cdcTrack);
67 }
68 for (auto& vxdTrack : m_VXDRecoTracks) {
69 fitter.fit(vxdTrack);
70 }
71
72 for (auto& cdcTrack : m_CDCRecoTracks) {
73 // skip CDC Tracks which were not properly fitted
74 if (!cdcTrack.wasFitSuccessful())
75 continue;
76
77 // skip CDC if it has already a match
78 if (cdcTrack.getRelated<RecoTrack>(m_VXDRecoTrackColName)) {
79 continue;
80 }
81
82 bool matched_track = false;
83
84 // start search with worst chi^2 imaginable
85 double this_chi_2 = std::numeric_limits<double>::max();
86 double chi_2_max_this_cdc_track = std::numeric_limits<double>::max();
87 try {
88 genfit::MeasuredStateOnPlane cdc_sop =
89 cdcTrack.getMeasuredStateOnPlaneFromFirstHit();
90 cdc_sop.extrapolateToCylinder(m_CDC_wall_radius, position, momentum);
91 cdcpos = cdc_sop.getPos();
92 cdcmom = cdc_sop.getMom();
93 } catch (...) {
94 B2DEBUG(29, "CDCTrack extrapolation to cylinder failed!");
95 continue;
96 }
97
98 // TODO: this can be done independent of each other ....
99 int currentVxdTrack = -1;
100 int bestMatchedVxdTrack = 0;
101 for (auto& vxdTrack : m_VXDRecoTracks) {
102 currentVxdTrack++;
103 // skip VXD Tracks which were not properly fitted
104 if (!vxdTrack.wasFitSuccessful()) {
105 continue;
106 }
107
108 // skip VXD if it has already a match
109 if (vxdTrack.getRelated<RecoTrack>(m_CDCRecoTrackColName)) {
110 continue;
111 }
112
113 try {
114 genfit::MeasuredStateOnPlane vxd_sop =
115 vxdTrack.getMeasuredStateOnPlaneFromLastHit();
116 vxd_sop.extrapolateToCylinder(m_CDC_wall_radius, position, momentum);
117 vxdpos = vxd_sop.getPos();
118 vxdmom = vxd_sop.getMom();
119 } catch (genfit::Exception const&) {
120 // extrapolation not possible, skip this track
121 B2DEBUG(29, "VXDTrack extrapolation to cylinder failed!");
122 continue;
123 }
124
125 // Extrapolate tracks to same plane & Match Tracks
126 if (TMath::Sqrt((cdcpos - vxdpos) * (cdcpos - vxdpos)) < m_merge_radius) {
127 genfit::MeasuredStateOnPlane vxd_sop;
128 genfit::MeasuredStateOnPlane cdc_sop;
129 try {
130 vxd_sop = vxdTrack.getMeasuredStateOnPlaneFromLastHit();
131 cdc_sop = cdcTrack.getMeasuredStateOnPlaneFromFirstHit();
132 cdc_sop.extrapolateToCylinder(m_CDC_wall_radius, position, momentum);
133 vxd_sop.extrapolateToPlane(cdc_sop.getPlane());
134 } catch (genfit::Exception const&) {
135 // extrapolation not possible, skip this track
136 B2DEBUG(29, "VXDTrack extrapolation to plane failed!");
137 continue;
138 }
139
140 try {
141 TMatrixDSym inv_covmtrx = (vxd_sop.getCov() + cdc_sop.getCov()).Invert();
142 TVectorD state_diff = cdc_sop.getState() - vxd_sop.getState();
143 state_diff *= inv_covmtrx;
144 this_chi_2 = state_diff * (cdc_sop.getState() - vxd_sop.getState());
145 } catch (...) {
146 B2WARNING("Matrix is singular!");
147 continue;
148 }
149
150 if ((this_chi_2 < chi_2_max_this_cdc_track) && (this_chi_2 > 0)) {
151 matched_track = true;
152 chi_2_max_this_cdc_track = this_chi_2;
153 bestMatchedVxdTrack = currentVxdTrack;
154 }
155 } //If on radius
156 } //end loop on VXD tracks
157
158 if (matched_track) {
159 // -1 is the convention for "before the CDC track" in the related tracks combiner
160 m_VXDRecoTracks[bestMatchedVxdTrack]->addRelationTo(&cdcTrack, -1);
161 }
162 }
163}
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
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
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
Algorithm class to handle the fitting of RecoTrack objects.
Definition: TrackFitter.h:121
StoreArray< RecoTrack > m_VXDRecoTracks
StoreArray of the VXD Track collection.
StoreArray< RecoTrack > m_CDCRecoTracks
StoreArray of the CDC Track collection.
void initialize() override
Use this to initialize resources or memory your module needs.
void event() override
Called once for each event.
VXDCDCTrackMergerModule()
Constructor, for setting module description and parameters.
std::string m_VXDRecoTrackColName
StoreArray name of the VXD Track collection.
double m_merge_radius
Maximum distance between extrapolated tracks on the CDC wall.
std::string m_CDCRecoTrackColName
StoreArray name of the CDC Track collection.
double m_CDC_wall_radius
Radius of the inner CDC wall in centimeters.
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.