Belle II Software  release-08-01-10
CKFToPXDFindlet.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/ckf/pxd/findlets/CKFToPXDFindlet.h>
10 
11 #include <tracking/ckf/general/findlets/StateCreator.icc.h>
12 #include <tracking/ckf/general/findlets/CKFRelationCreator.icc.h>
13 #include <tracking/ckf/general/findlets/StateCreatorWithReversal.icc.h>
14 #include <tracking/ckf/general/findlets/TreeSearcher.icc.h>
15 #include <tracking/ckf/general/findlets/OverlapResolver.icc.h>
16 #include <tracking/ckf/general/findlets/SpacePointTagger.icc.h>
17 #include <tracking/ckf/general/findlets/ResultStorer.icc.h>
18 #include <tracking/ckf/general/utilities/Helpers.h>
19 
20 #include <tracking/ckf/pxd/entities/CKFToPXDResult.h>
21 #include <tracking/ckf/pxd/entities/CKFToPXDState.h>
22 
23 #include <tracking/dataobjects/RecoTrack.h>
24 #include <tracking/spacePointCreation/SpacePoint.h>
25 #include <pxd/dataobjects/PXDCluster.h>
26 
27 #include <framework/core/ModuleParamList.h>
28 
29 using namespace Belle2;
30 using namespace TrackFindingCDC;
31 
33 
35 {
36  addProcessingSignalListener(&m_dataHandler);
37  addProcessingSignalListener(&m_hitsLoader);
38  addProcessingSignalListener(&m_stateCreatorFromTracks);
39  addProcessingSignalListener(&m_stateCreatorFromHits);
40  addProcessingSignalListener(&m_relationCreator);
41  addProcessingSignalListener(&m_treeSearchFindlet);
42  addProcessingSignalListener(&m_overlapResolver);
43  addProcessingSignalListener(&m_spacePointTagger);
44  addProcessingSignalListener(&m_resultStorer);
45 }
46 
47 void CKFToPXDFindlet::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
48 {
49  Super::exposeParameters(moduleParamList, prefix);
50 
51  m_dataHandler.exposeParameters(moduleParamList, prefix);
52  m_hitsLoader.exposeParameters(moduleParamList, prefix);
53  m_stateCreatorFromTracks.exposeParameters(moduleParamList, prefix);
54  m_stateCreatorFromHits.exposeParameters(moduleParamList, prefix);
55  m_relationCreator.exposeParameters(moduleParamList, prefix);
56  m_treeSearchFindlet.exposeParameters(moduleParamList, prefix);
57  m_overlapResolver.exposeParameters(moduleParamList, prefix);
58  m_spacePointTagger.exposeParameters(moduleParamList, prefix);
59  m_resultStorer.exposeParameters(moduleParamList, prefix);
60 
61  moduleParamList->addParameter("minimalHitRequirement", m_param_minimalHitRequirement,
62  "Minimal Hit requirement for the results (counted in space points)",
63  m_param_minimalHitRequirement);
64  moduleParamList->addParameter("onlyUseTracksWithSVD", m_param_onlyUseTracksWithSVD,
65  "Only use tracks which have an SVD hit associated.",
66  m_param_onlyUseTracksWithSVD);
67  moduleParamList->addParameter("reverseSeedState", m_param_reverseSeed, "Reverse the seed.", m_param_reverseSeed);
68 
69  // Default values
70  moduleParamList->getParameter<std::string>("advanceHighFilter").setDefaultValue("advance");
71  moduleParamList->getParameter<std::string>("updateHighFilter").setDefaultValue("fit");
72 
73  moduleParamList->getParameter<std::string>("firstHighFilter").setDefaultValue("mva_with_direction_check");
74  moduleParamList->getParameter<std::string>("secondHighFilter").setDefaultValue("mva");
75  moduleParamList->getParameter<std::string>("thirdHighFilter").setDefaultValue("mva");
76 
77  moduleParamList->getParameter<bool>("useAssignedHits").setDefaultValue(false);
78 
79  moduleParamList->getParameter<std::string>("hitFilter").setDefaultValue("sensor");
80  moduleParamList->getParameter<std::string>("seedFilter").setDefaultValue("sensor");
81  moduleParamList->getParameter<std::string>("preSeedFilter").setDefaultValue("loose");
82  moduleParamList->getParameter<std::string>("preHitFilter").setDefaultValue("loose");
83 
84  moduleParamList->getParameter<std::string>("hitsSpacePointsStoreArrayName").setDefaultValue("PXDSpacePoints");
85 
86  moduleParamList->getParameter<std::string>("filter").setDefaultValue("mva");
87 }
88 
90 {
91  Super::beginEvent();
92 
93  // If the capacity of a std::vector is very large without being used, it just allocates RAM for no reason, increasing the RAM
94  // usage unnecessarily. In this case, start with a fresh one.
95  // Since std::vector.shrink() or std::vector.shrink_to_fit() not necessarily reduce the capacity in the desired way, create a
96  // temporary vector of the same type, swap them to use the vector at the new location afterwards, and clear the tempoary vector.
97  m_recoTracksVector.clear();
98  checkResizeClear<const SpacePoint*>(m_spacePointVector, 2000);
99 
100  m_seedStates.clear();
101  checkResizeClear<CKFToPXDState>(m_states, 2000);
102 
103  checkResizeClear<TrackFindingCDC::WeightedRelation<CKFToPXDState>>(m_relations, 2000);
104 
105  m_results.clear();
106  m_filteredResults.clear();
107 }
108 
110 {
111  m_dataHandler.apply(m_recoTracksVector);
112  m_hitsLoader.apply(m_spacePointVector);
113 
114  if (m_spacePointVector.empty() or m_recoTracksVector.empty()) {
115  return;
116  }
117 
118  // Delete stuff not from the PXD
119  const auto notFromPXD = [](const SpacePoint * spacePoint) {
120  return spacePoint->getType() != VXD::SensorInfoBase::PXD;
121  };
122  TrackFindingCDC::erase_remove_if(m_spacePointVector, notFromPXD);
123 
124  if (m_param_onlyUseTracksWithSVD) {
125  const auto hasNoSVD = [this](const RecoTrack * recoTrack) {
126  const auto& svdHitList = recoTrack->getSortedSVDHitList();
127  if (svdHitList.empty()) return true;
128  // Require at least one hit in layer 3 or 4
129  return m_param_reverseSeed ? svdHitList.back()->getSensorID().getLayerNumber() > 4
130  : svdHitList.front()->getSensorID().getLayerNumber() > 4;
131  };
132  TrackFindingCDC::erase_remove_if(m_recoTracksVector, hasNoSVD);
133  }
134 
135  B2DEBUG(29, "Now have " << m_spacePointVector.size() << " hits.");
136 
137  m_stateCreatorFromTracks.apply(m_recoTracksVector, m_seedStates);
138  m_stateCreatorFromHits.apply(m_spacePointVector, m_states);
139  m_relationCreator.apply(m_seedStates, m_states, m_relations);
140 
141  B2DEBUG(29, "Created " << m_relations.size() << " relations.");
142 
143  m_treeSearchFindlet.apply(m_seedStates, m_states, m_relations, m_results);
144 
145  B2DEBUG(29, "Having found " << m_results.size() << " results before overlap check");
146 
147  const auto hasLowHitNumber = [this](const CKFResult<RecoTrack, SpacePoint>& result) {
148  return result.getHits().size() < m_param_minimalHitRequirement;
149  };
150  TrackFindingCDC::erase_remove_if(m_results, hasLowHitNumber);
151 
152  m_overlapResolver.apply(m_results, m_filteredResults);
153 
154  B2DEBUG(29, "Having found " << m_filteredResults.size() << " results");
155 
156  m_resultStorer.apply(m_filteredResults);
157  m_spacePointTagger.apply(m_filteredResults, m_spacePointVector);
158 }
CKFToPXDFindlet()
Constructor, for setting module description and parameters.
void beginEvent() override
Clear the object pools.
~CKFToPXDFindlet()
Default desctructor.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
void apply() override
Do the tree search.
The Module parameter list class.
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:42
ModuleParam< T > & getParameter(const std::string &name) const
Returns a reference to a parameter.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.