Belle II Software  release-05-01-25
CDCCKFTracksCombinerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun, Sasha Glazov *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <tracking/modules/relatedTracksCombiner/CDCCKFTracksCombinerModule.h>
12 
13 using namespace Belle2;
14 
15 REG_MODULE(CDCCKFTracksCombiner);
16 
18  Module()
19 {
20  setDescription("Combine related tracks from CDC, determined in SVD->CDC CKF, and VXD (and VXD+CDC) into a single track by copying the hit "
21  "information and combining the seed information. The sign of the weight defines, "
22  "if the hits go before (-1) or after (+1) the CDC track.");
24 
25  addParam("CDCRecoTracksStoreArrayName", m_cdcRecoTracksStoreArrayName , "Name of the input CDC StoreArray.",
27  addParam("VXDRecoTracksStoreArrayName", m_vxdRecoTracksStoreArrayName , "Name of the input VXD (and+CDC) StoreArray.",
29  addParam("recoTracksStoreArrayName", m_recoTracksStoreArrayName, "Name of the output StoreArray.", m_recoTracksStoreArrayName);
30 }
31 
33 {
36 
39 
40  m_recoTracks.registerRelationTo(m_vxdRecoTracks);
41  m_recoTracks.registerRelationTo(m_cdcRecoTracks);
42 }
43 
45 {
46  std::set <RecoTrack*> mergedTracks;
47  // Loop over all CDC reco tracks and add them to the store array if they do not have a match or combined them with
48  // their VXD partner if they do.
49  // For this, the fitted or seed state of the tracks is used - if they are already fitted or not.
50  for (const RecoTrack& cdcRecoTrack : m_cdcRecoTracks) {
51  const RelationVector<RecoTrack>& relatedVXDRecoTracks = cdcRecoTrack.getRelationsWith<RecoTrack>(m_vxdRecoTracksStoreArrayName);
52 
53  B2ASSERT("Can not handle more than 2 relations!", relatedVXDRecoTracks.size() <= 2);
54 
55  RecoTrack* vxdTrackBefore = nullptr;
56  RecoTrack* vxdTrackAfter = nullptr;
57 
58  for (unsigned int index = 0; index < relatedVXDRecoTracks.size(); ++index) {
59  const double weight = relatedVXDRecoTracks.weight(index);
60  if (weight < 0) {
61  vxdTrackBefore = relatedVXDRecoTracks[index];
62  } else if (weight > 0) {
63  vxdTrackAfter = relatedVXDRecoTracks[index];
64  }
65  }
66 
67  // Do not output non-fittable tracks
68  if (not vxdTrackAfter and not vxdTrackBefore) {
69  continue;
70  }
71 
72  RecoTrack* newMergedTrack = nullptr;
73 
74  if (vxdTrackBefore) {
75  mergedTracks.insert(vxdTrackBefore);
76  newMergedTrack = vxdTrackBefore->copyToStoreArray(m_recoTracks);
77  newMergedTrack->addHitsFromRecoTrack(vxdTrackBefore, newMergedTrack->getNumberOfTotalHits());
78  newMergedTrack->addRelationTo(vxdTrackBefore);
79  } else {
80  newMergedTrack = cdcRecoTrack.copyToStoreArray(m_recoTracks);
81  }
82 
83  newMergedTrack->addHitsFromRecoTrack(&cdcRecoTrack, newMergedTrack->getNumberOfTotalHits());
84  newMergedTrack->addRelationTo(&cdcRecoTrack);
85 
86  if (vxdTrackAfter) {
87  mergedTracks.insert(vxdTrackAfter);
88  newMergedTrack->addHitsFromRecoTrack(vxdTrackAfter, newMergedTrack->getNumberOfTotalHits(), true);
89  newMergedTrack->addRelationTo(vxdTrackAfter);
90  }
91  }
92 
93  // Now we have to add remaining tracks
94  for (RecoTrack& vxdRecoTrack : m_vxdRecoTracks) {
95  auto alreadyIncluded = mergedTracks.count(&vxdRecoTrack) ;
96 
97  if (not alreadyIncluded) {
98  RecoTrack* newTrack = vxdRecoTrack.copyToStoreArray(m_recoTracks);
99  newTrack->addHitsFromRecoTrack(&vxdRecoTrack);
100  newTrack->addRelationTo(&vxdRecoTrack);
101  }
102  }
103 }
104 
Belle2::RelationVector::size
size_t size() const
Get number of relations.
Definition: RelationVector.h:98
Belle2::RecoTrack::registerRequiredRelations
static void registerRequiredRelations(StoreArray< RecoTrack > &recoTracks, std::string const &pxdHitsStoreArrayName="", std::string const &svdHitsStoreArrayName="", std::string const &cdcHitsStoreArrayName="", std::string const &bklmHitsStoreArrayName="", std::string const &eklmHitsStoreArrayName="", std::string const &recoHitInformationStoreArrayName="")
Convenience method which registers all relations required to fully use a RecoTrack.
Definition: RecoTrack.cc:42
Belle2::RecoTrack::addHitsFromRecoTrack
size_t addHitsFromRecoTrack(const RecoTrack *recoTrack, unsigned int sortingParameterOffset=0, bool reversed=false, boost::optional< double > optionalMinimalWeight=boost::none)
Add all hits from another RecoTrack to this RecoTrack.
Definition: RecoTrack.cc:230
Belle2::CDCCKFTracksCombinerModule::event
void event() override
Event processing, combine store array.
Definition: CDCCKFTracksCombinerModule.cc:44
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module::c_ParallelProcessingCertified
@ 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:82
Belle2::CDCCKFTracksCombinerModule::m_recoTracksStoreArrayName
std::string m_recoTracksStoreArrayName
Name of the output StoreArray.
Definition: CDCCKFTracksCombinerModule.h:57
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::RecoTrack::copyToStoreArray
RecoTrack * copyToStoreArray(StoreArray< RecoTrack > &storeArray) const
Append a new RecoTrack to the given store array and copy its general properties, but not the hits the...
Definition: RecoTrack.cc:506
Belle2::CDCCKFTracksCombinerModule::m_recoTracks
StoreArray< RecoTrack > m_recoTracks
Store Array of the output tracks.
Definition: CDCCKFTracksCombinerModule.h:64
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::Module::setPropertyFlags
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:210
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::RelationVector
Class for type safe access to objects that are referred to in relations.
Definition: DataStore.h:38
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCCKFTracksCombinerModule::CDCCKFTracksCombinerModule
CDCCKFTracksCombinerModule()
Constructor of the module. Setting up parameters and description.
Definition: CDCCKFTracksCombinerModule.cc:17
Belle2::CDCCKFTracksCombinerModule::m_vxdRecoTracksStoreArrayName
std::string m_vxdRecoTracksStoreArrayName
Name of the input VXD StoreArray.
Definition: CDCCKFTracksCombinerModule.h:55
Belle2::DataStore::c_ErrorIfAlreadyRegistered
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:74
Belle2::Module::addParam
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:562
Belle2::CDCCKFTracksCombinerModule::m_cdcRecoTracks
StoreArray< RecoTrack > m_cdcRecoTracks
Store Array of the input tracks.
Definition: CDCCKFTracksCombinerModule.h:60
Belle2::RelationVector::weight
float weight(int index) const
Get weight with index.
Definition: RelationVector.h:120
Belle2::RecoTrack::getNumberOfTotalHits
unsigned int getNumberOfTotalHits() const
Return the number of cdc + svd + pxd + bklm + eklm hits.
Definition: RecoTrack.h:432
Belle2::CDCCKFTracksCombinerModule::m_cdcRecoTracksStoreArrayName
std::string m_cdcRecoTracksStoreArrayName
Name of the input CDC StoreArray.
Definition: CDCCKFTracksCombinerModule.h:53
Belle2::CDCCKFTracksCombinerModule::initialize
void initialize() override
Declare required StoreArray.
Definition: CDCCKFTracksCombinerModule.cc:32
Belle2::CDCCKFTracksCombinerModule::m_vxdRecoTracks
StoreArray< RecoTrack > m_vxdRecoTracks
Store Array of the input tracks.
Definition: CDCCKFTracksCombinerModule.h:62