Belle II Software  release-08-01-10
RelatedTracksCombinerModule.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 
9 #include <tracking/modules/relatedTracksCombiner/RelatedTracksCombinerModule.h>
10 #include <tracking/trackFitting/fitter/base/TrackFitter.h>
11 
12 using namespace Belle2;
13 
14 REG_MODULE(RelatedTracksCombiner);
15 
17  Module()
18 {
19  setDescription("Combine related tracks from CDC and VXD into a single track by copying the hit "
20  "information and combining the seed information. The sign of the weight defines, "
21  "if the hits go before (-1) or after (+1) the CDC track.");
23 
24  addParam("CDCRecoTracksStoreArrayName", m_cdcRecoTracksStoreArrayName, "Name of the input CDC StoreArray.",
26  addParam("VXDRecoTracksStoreArrayName", m_vxdRecoTracksStoreArrayName, "Name of the input VXD StoreArray.",
28  addParam("recoTracksStoreArrayName", m_recoTracksStoreArrayName, "Name of the output StoreArray.", m_recoTracksStoreArrayName);
29 }
30 
32 {
35 
38 
41 }
42 
44 {
45  TrackFitter trackFitter;
46 
47  // Loop over all CDC reco tracks and add them to the store array of 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 (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 and not trackFitter.fit(cdcRecoTrack)) {
69  continue;
70  }
71 
72  RecoTrack* newMergedTrack = nullptr;
73 
74  if (vxdTrackBefore) {
75  newMergedTrack = vxdTrackBefore->copyToStoreArray(m_recoTracks);
76  newMergedTrack->addHitsFromRecoTrack(vxdTrackBefore, newMergedTrack->getNumberOfTotalHits());
77  newMergedTrack->addRelationTo(vxdTrackBefore);
78  } else {
79  newMergedTrack = cdcRecoTrack.copyToStoreArray(m_recoTracks);
80  }
81 
82  newMergedTrack->addHitsFromRecoTrack(&cdcRecoTrack, newMergedTrack->getNumberOfTotalHits());
83  newMergedTrack->addRelationTo(&cdcRecoTrack);
84 
85  if (vxdTrackAfter) {
86  newMergedTrack->addHitsFromRecoTrack(vxdTrackAfter, newMergedTrack->getNumberOfTotalHits(), true);
87  newMergedTrack->addRelationTo(vxdTrackAfter);
88  }
89  }
90 
91  // Now we only have to add the VXD tracks without a match
92  for (RecoTrack& vxdRecoTrack : m_vxdRecoTracks) {
93  const RecoTrack* cdcRecoTrack = vxdRecoTrack.getRelated<RecoTrack>(m_cdcRecoTracksStoreArrayName);
94  if (not cdcRecoTrack and trackFitter.fit(vxdRecoTrack)) {
95  RecoTrack* newTrack = vxdRecoTrack.copyToStoreArray(m_recoTracks);
96  newTrack->addHitsFromRecoTrack(&vxdRecoTrack);
97  newTrack->addRelationTo(&vxdRecoTrack);
98  }
99  }
100 }
101 
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:72
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
size_t addHitsFromRecoTrack(const RecoTrack *recoTrack, unsigned int sortingParameterOffset=0, bool reversed=false, std::optional< double > optionalMinimalWeight=std::nullopt)
Add all hits from another RecoTrack to this RecoTrack.
Definition: RecoTrack.cc:240
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:529
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:53
unsigned int getNumberOfTotalHits() const
Return the number of cdc + svd + pxd + bklm + eklm hits.
Definition: RecoTrack.h:436
void initialize() override
Declare required StoreArray.
void event() override
Event processing, combine store array.
StoreArray< RecoTrack > m_vxdRecoTracks
Store Array of the input tracks.
RelatedTracksCombinerModule()
Constructor of the module. Setting up parameters and description.
std::string m_cdcRecoTracksStoreArrayName
Name of the input CDC StoreArray.
StoreArray< RecoTrack > m_recoTracks
Store Array of the output tracks.
StoreArray< RecoTrack > m_cdcRecoTracks
Store Array of the input tracks.
std::string m_recoTracksStoreArrayName
Name of the output StoreArray.
std::string m_vxdRecoTracksStoreArrayName
Name of the input VXD StoreArray.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
float weight(int index) const
Get weight with index.
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).
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
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
Algorithm class to handle the fitting of RecoTrack objects.
Definition: TrackFitter.h:116
bool fit(RecoTrack &recoTrack, genfit::AbsTrackRep *trackRepresentation) const
Fit a reco track with a given non-default track representation.
Definition: TrackFitter.cc:107
REG_MODULE(arichBtest)
Register the Module.
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
Abstract base class for different kinds of events.