Belle II Software  release-05-02-19
VXDCDCTrackMergerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Benjamin Oberhof, Thomas Hauth *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/modules/vxdCDCTrackMerger/VXDCDCTrackMergerModule.h>
11 
12 #include <tracking/trackFitting/fitter/base/TrackFitter.h>
13 
14 using namespace Belle2;
15 
16 REG_MODULE(VXDCDCTrackMerger)
17 
19  Module(), m_CDC_wall_radius(16.25)
20 {
21  setDescription(
22  "This module merges tracks which are reconstructed, separately, in the silicon (PXD+VXD) and in the CDC");
23  setPropertyFlags(c_ParallelProcessingCertified);
24 
25  //input
26  addParam("CDCRecoTrackColName", m_CDCRecoTrackColName, "CDC Reco Tracks");
27  addParam("VXDRecoTrackColName", m_VXDRecoTrackColName, "VXD Reco Tracks");
28 
29  //merging parameters
30  addParam("merge_radius", m_merge_radius,
31  "Maximum distance between extrapolated tracks on the CDC wall",
32  double(2.0));
33 }
34 
36 {
39 
40  m_CDCRecoTracks.registerRelationTo(m_VXDRecoTracks);
41  m_VXDRecoTracks.registerRelationTo(m_CDCRecoTracks);
42 }
43 
45 {
46  //get CDC tracks
47  unsigned int nCDCTracks = m_CDCRecoTracks.getEntries();
48  B2DEBUG(9, "VXDCDCTrackMerger: input Number of CDC Tracks: " << nCDCTracks);
49 
50  //get VXD tracks
51  unsigned int nVXDTracks = m_VXDRecoTracks.getEntries();
52  B2DEBUG(9,
53  "VXDCDCTrackMerger: input Number of VXD Tracks: " << nVXDTracks);
54 
55  // position and momentum used for extrapolations to the CDC Wall
56  TVector3 position(0., 0., 0.);
57  TVector3 momentum(0., 0., 1.);
58  // position and momentum of the track extrapolated from the CDC fit to the CDC Wall
59  TVector3 cdcpos;
60  TVector3 cdcmom;
61  // position and momentum of the track extrapolated from the VXD fit to the CDC Wall
62  TVector3 vxdpos;
63  TVector3 vxdmom;
64 
65  // Fit all cdc and vxd tracks
66  TrackFitter fitter;
67  for (auto& cdcTrack : m_CDCRecoTracks) {
68  fitter.fit(cdcTrack);
69  }
70  for (auto& vxdTrack : m_VXDRecoTracks) {
71  fitter.fit(vxdTrack);
72  }
73 
74  for (auto& cdcTrack : m_CDCRecoTracks) {
75  // skip CDC Tracks which were not properly fitted
76  if (!cdcTrack.wasFitSuccessful())
77  continue;
78 
79  // skip CDC if it has already a match
80  if (cdcTrack.getRelated<RecoTrack>(m_VXDRecoTrackColName)) {
81  continue;
82  }
83 
84  bool matched_track = false;
85 
86  // start search with worst chi^2 imaginable
87  double this_chi_2 = std::numeric_limits<double>::max();
88  double chi_2_max_this_cdc_track = std::numeric_limits<double>::max();
89  try {
91  cdcTrack.getMeasuredStateOnPlaneFromFirstHit();
92  cdc_sop.extrapolateToCylinder(m_CDC_wall_radius, position, momentum);
93  cdcpos = cdc_sop.getPos();
94  cdcmom = cdc_sop.getMom();
95  } catch (...) {
96  B2DEBUG(9, "CDCTrack extrapolation to cylinder failed!");
97  continue;
98  }
99 
100  // TODO: this can be done independent of each other ....
101  int currentVxdTrack = -1;
102  int bestMatchedVxdTrack = 0;
103  for (auto& vxdTrack : m_VXDRecoTracks) {
104  currentVxdTrack++;
105  // skip VXD Tracks which were not properly fitted
106  if (!vxdTrack.wasFitSuccessful()) {
107  continue;
108  }
109 
110  // skip VXD if it has already a match
111  if (vxdTrack.getRelated<RecoTrack>(m_CDCRecoTrackColName)) {
112  continue;
113  }
114 
115  try {
117  vxdTrack.getMeasuredStateOnPlaneFromLastHit();
118  vxd_sop.extrapolateToCylinder(m_CDC_wall_radius, position, momentum);
119  vxdpos = vxd_sop.getPos();
120  vxdmom = vxd_sop.getMom();
121  } catch (genfit::Exception const&) {
122  // extrapolation not possible, skip this track
123  B2DEBUG(9, "VXDTrack extrapolation to cylinder failed!");
124  continue;
125  }
126 
127  // Extrapolate tracks to same plane & Match Tracks
128  if (TMath::Sqrt((cdcpos - vxdpos) * (cdcpos - vxdpos)) < m_merge_radius) {
131  try {
132  vxd_sop = vxdTrack.getMeasuredStateOnPlaneFromLastHit();
133  cdc_sop = cdcTrack.getMeasuredStateOnPlaneFromFirstHit();
134  cdc_sop.extrapolateToCylinder(m_CDC_wall_radius, position, momentum);
135  vxd_sop.extrapolateToPlane(cdc_sop.getPlane());
136  } catch (genfit::Exception const&) {
137  // extrapolation not possible, skip this track
138  B2DEBUG(9, "VXDTrack extrapolation to plane failed!");
139  continue;
140  }
141 
142  try {
143  TMatrixDSym inv_covmtrx = (vxd_sop.getCov() + cdc_sop.getCov()).Invert();
144  TVectorD state_diff = cdc_sop.getState() - vxd_sop.getState();
145  state_diff *= inv_covmtrx;
146  this_chi_2 = state_diff * (cdc_sop.getState() - vxd_sop.getState());
147  } catch (...) {
148  B2WARNING("Matrix is singular!");
149  continue;
150  }
151 
152  if ((this_chi_2 < chi_2_max_this_cdc_track) && (this_chi_2 > 0)) {
153  matched_track = true;
154  chi_2_max_this_cdc_track = this_chi_2;
155  bestMatchedVxdTrack = currentVxdTrack;
156  }
157  } //If on radius
158  } //end loop on VXD tracks
159 
160  if (matched_track) {
161  // -1 is the convention for "before the CDC track" in the related tracks combiner
162  m_VXDRecoTracks[bestMatchedVxdTrack]->addRelationTo(&cdcTrack, -1);
163  }
164  }
165 }
genfit::Exception
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition: Exception.h:48
Belle2::VXDCDCTrackMergerModule::m_CDCRecoTracks
StoreArray< RecoTrack > m_CDCRecoTracks
StoreArray of the CDC Track collection.
Definition: VXDCDCTrackMergerModule.h:72
genfit::MeasuredStateOnPlane
#StateOnPlane with additional covariance matrix.
Definition: MeasuredStateOnPlane.h:39
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::VXDCDCTrackMergerModule::m_VXDRecoTracks
StoreArray< RecoTrack > m_VXDRecoTracks
StoreArray of the VXD Track collection.
Definition: VXDCDCTrackMergerModule.h:70
Belle2::VXDCDCTrackMergerModule::m_CDCRecoTrackColName
std::string m_CDCRecoTrackColName
StoreArray name of the CDC Track collection.
Definition: VXDCDCTrackMergerModule.h:67
Belle2::VXDCDCTrackMergerModule::m_VXDRecoTrackColName
std::string m_VXDRecoTrackColName
StoreArray name of the VXD Track collection.
Definition: VXDCDCTrackMergerModule.h:65
Belle2::VXDCDCTrackMergerModule::event
void event() override
Called once for each event.
Definition: VXDCDCTrackMergerModule.cc:44
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::VXDCDCTrackMergerModule
VXDCDCTrackMergerModule a module to merge VXD and CDC tracks.
Definition: VXDCDCTrackMergerModule.h:40
Belle2::TrackFitter
Algorithm class to handle the fitting of RecoTrack objects.
Definition: TrackFitter.h:116
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::VXDCDCTrackMergerModule::m_merge_radius
double m_merge_radius
Maximum distance between extrapolated tracks on the CDC wall.
Definition: VXDCDCTrackMergerModule.h:62
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VXDCDCTrackMergerModule::m_CDC_wall_radius
double m_CDC_wall_radius
Radius of the inner CDC wall in centimeters.
Definition: VXDCDCTrackMergerModule.h:60
Belle2::VXDCDCTrackMergerModule::initialize
void initialize() override
Use this to initialize resources or memory your module needs.
Definition: VXDCDCTrackMergerModule.cc:35