Belle II Software development
FacetCreator.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/trackFindingCDC/findlets/minimal/FacetCreator.h>
9
10#include <tracking/trackFindingCDC/eventdata/segments/CDCWireHitCluster.h>
11#include <tracking/trackFindingCDC/eventdata/hits/CDCFacet.h>
12#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
13
14#include <tracking/trackFindingCDC/filters/base/RelationFilterUtil.h>
15#include <tracking/trackFindingCDC/fitting/FacetFitter.h>
16
17#include <tracking/trackFindingCDC/utilities/VectorRange.h>
18#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
19
20#include <framework/core/ModuleParamList.templateDetails.h>
21
22#include <vector>
23#include <string>
24#include <algorithm>
25
26using namespace Belle2;
27using namespace TrackFindingCDC;
28
30{
33}
34
36{
37 return "Creates hit triplet (facets) from each cluster filtered by a acceptance criterion.";
38}
39
40void FacetCreator::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
41{
42 m_wireHitRelationFilter.exposeParameters(moduleParamList, prefix);
43 m_feasibleRLFacetFilter.exposeParameters(moduleParamList, prefix);
44 m_facetFilter.exposeParameters(moduleParamList, prefix);
45
46 moduleParamList->addParameter(prefixed(prefix, "updateDriftLength"),
48 "Switch to reestimate the drift length",
50
51 moduleParamList->addParameter(prefixed(prefix, "leastSquareFit"),
53 "Switch to fit the facet with the least square method "
54 "for drift length estimation",
56}
57
58void FacetCreator::apply(const std::vector<CDCWireHitCluster>& inputClusters, std::vector<CDCFacet>& facets)
59{
60 int iCluster = -1;
61 for (const CDCWireHitCluster& cluster : inputClusters) {
62 ++iCluster;
63 // Skip clusters that have been detected as background
64 if (cluster.getBackgroundFlag()) {
65 continue;
66 }
67 B2ASSERT("Expect the clusters to be sorted", std::is_sorted(cluster.begin(), cluster.end()));
68
69 // Obtain the set of wire hits as references
70 const std::vector<CDCWireHit*>& wireHits = cluster;
71
72 // Create the neighborhood of wire hits on the cluster
73 m_wireHitRelations.clear();
75
76 B2ASSERT("Wire neighborhood is not symmetric. Check the geometry.",
78
79 // Create the facets
80 std::size_t nBefore = facets.size();
81 createFacets(cluster, m_wireHitRelations, facets);
82 std::size_t nAfter = facets.size();
83
84 VectorRange<CDCFacet> facetsInCluster(facets.begin() + nBefore, facets.begin() + nAfter);
85 // Sort the facets in their cluster
86 std::sort(facetsInCluster.begin(), facetsInCluster.end());
87
88 B2ASSERT("Expected all facets to be different",
89 std::adjacent_find(facetsInCluster.begin(), facetsInCluster.end()) ==
90 facetsInCluster.end());
91
92 for (CDCFacet& facet : facetsInCluster) {
93 facet.setICluster(iCluster);
94 }
95 }
96}
97
98void FacetCreator::createFacets(const std::vector<CDCWireHit*>& wireHits,
99 const std::vector<WeightedRelation<CDCWireHit> >& wireHitRelations,
100 std::vector<CDCFacet>& facets)
101{
102 for (const CDCWireHit* ptrMiddleWireHit : wireHits) {
103 if (not ptrMiddleWireHit) continue;
104 const CDCWireHit& middleWireHit = *ptrMiddleWireHit;
105 if (middleWireHit->hasTakenFlag()) continue;
106
107 const auto neighbors = asRange(
108 std::equal_range(wireHitRelations.begin(), wireHitRelations.end(), ptrMiddleWireHit));
109
110 for (const WeightedRelation<CDCWireHit>& startWireHitRelation : neighbors) {
111 const CDCWireHit* ptrStartWireHit(startWireHitRelation.getTo());
112
113 if (not ptrStartWireHit) continue;
114 const CDCWireHit& startWireHit = *ptrStartWireHit;
115 if (startWireHit->hasTakenFlag()) continue;
116
117 for (const WeightedRelation<CDCWireHit>& endWireHitRelation : neighbors) {
118 const CDCWireHit* ptrEndWireHit(endWireHitRelation.getTo());
119
120 if (not ptrEndWireHit) continue;
121 const CDCWireHit& endWireHit = *ptrEndWireHit;
122 if (endWireHit->hasTakenFlag()) continue;
123
124 // Skip combinations where the facet starts and ends on the same wire
125 if (ptrStartWireHit->isOnWire(ptrEndWireHit->getWire())) continue;
126
127 createFacetsForHitTriple(startWireHit, middleWireHit, endWireHit, facets);
128 } // end for itEndWireHit
129 } // end for itStartWireHit
130 } // end for itMiddleWireHit
131}
132
134 const CDCWireHit& middleWireHit,
135 const CDCWireHit& endWireHit,
136 std::vector<CDCFacet>& facets)
137{
139 CDCRLWireHit startRLWireHit(&startWireHit, ERightLeft::c_Left);
140 CDCRLWireHit middleRLWireHit(&middleWireHit, ERightLeft::c_Left);
141 CDCRLWireHit endRLWireHit(&endWireHit, ERightLeft::c_Left);
142 CDCFacet facet(startRLWireHit, middleRLWireHit, endRLWireHit, UncertainParameterLine2D());
143
144 for (ERightLeft startRLInfo : {ERightLeft::c_Left, ERightLeft::c_Right}) {
145 facet.setStartRLInfo(startRLInfo);
146 for (ERightLeft middleRLInfo : {ERightLeft::c_Left, ERightLeft::c_Right}) {
147 facet.setMiddleRLInfo(middleRLInfo);
148 for (ERightLeft endRLInfo : {ERightLeft::c_Left, ERightLeft::c_Right}) {
149 facet.setEndRLInfo(endRLInfo);
150
151 // Reset the lines
152 // The filter shall do the fitting of the tangent lines if it wants to.
153 // He should set them if he accepts the facet.
154 facet.invalidateFitLine();
155
157 Weight feasibleWeight = m_feasibleRLFacetFilter(facet);
158 if (std::isnan(feasibleWeight)) continue;
159 }
160
162
163 // Reset drift length
167
169 /*double chi2 =*/FacetFitter::fit(facet);
170 } else {
171 facet.adjustFitLine();
172 }
173
174 // Update drift length
176 }
177
178 Weight weight = m_facetFilter(facet);
179
180 if (not std::isnan(weight)) {
181 facet.getAutomatonCell().setCellWeight(weight);
182 facets.insert(facets.end(), facet);
183 }
184 } // end for endRLWireHit
185 } // end for middleRLWireHit
186 } // end for startRLWireHit
187}
The Module parameter list class.
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
void setCellWeight(Weight weight)
Setter for the cell weight.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the set of parameters of the filter to the module parameter list.
Class representing a triple of neighboring oriented wire with additional trajectory information.
Definition: CDCFacet.h:32
void adjustFitLine() const
Adjusts the contained fit line to touch such that it touches the first and third hit.
Definition: CDCFacet.cc:61
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Definition: CDCFacet.h:130
void invalidateFitLine()
Clear all information in the fit.
Definition: CDCFacet.cc:66
void setEndRLInfo(const ERightLeft endRLInfo)
Setter for the right left passage information of the third oriented wire hit.
CDCRLWireHit & getStartRLWireHit()
Getter for the first oriented wire hit.
void setMiddleRLInfo(const ERightLeft middleRLInfo)
Setter for the right left passage information of the second oriented wire hit.
CDCRLWireHit & getEndRLWireHit()
Getter for the third oriented wire hit.
CDCRLWireHit & getMiddleRLWireHit()
Getter for the second oriented wire hit.
void setStartRLInfo(const ERightLeft startRLInfo)
Setter for the right left passage information of the first oriented wire hit.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Definition: CDCRLWireHit.h:41
void setRefDriftLength(double driftLength)
Setter for the drift length at the reference position of the wire.
Definition: CDCRLWireHit.h:210
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
Definition: CDCWireHit.h:224
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the set of parameters of the filter to the module parameter list.
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
DriftLengthEstimator m_driftLengthEstimator
Instance of the drift length estimator to be used.
Definition: FacetCreator.h:99
BridgingWireHitRelationFilter m_wireHitRelationFilter
The filter for the hit neighborhood.
Definition: FacetCreator.h:90
bool m_param_feasibleRLOnly
Parameter : Switch to apply the rl feasibility cut.
Definition: FacetCreator.h:80
void apply(const std::vector< CDCWireHitCluster > &inputClusters, std::vector< CDCFacet > &facets) final
Central function creating the hit triplets from the clusters.
Definition: FacetCreator.cc:58
std::vector< WeightedRelation< CDCWireHit > > m_wireHitRelations
Memory for the wire hit neighborhood in within a cluster.
Definition: FacetCreator.h:103
bool m_param_leastSquareFit
Parameter : Switch to fit the facet with least square method for the drift length update.
Definition: FacetCreator.h:86
std::string getDescription() final
Short description of the findlet.
Definition: FacetCreator.cc:35
ChooseableFacetFilter m_facetFilter
The filter to be used for the facet generation.
Definition: FacetCreator.h:96
bool m_param_updateDriftLength
Parameter : Switch to reestimate the drift length.
Definition: FacetCreator.h:83
void createFacetsForHitTriple(const CDCWireHit &startWireHit, const CDCWireHit &middleWireHit, const CDCWireHit &endWireHit, std::vector< CDCFacet > &facets)
Generates reconstruted facets on the three given wire hits by hypothesizing over the 8 left right pas...
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
Definition: FacetCreator.cc:40
FeasibleRLFacetFilter m_feasibleRLFacetFilter
The feasibility filter for the right left passage information.
Definition: FacetCreator.h:93
void createFacets(const std::vector< CDCWireHit * > &wireHits, const std::vector< WeightedRelation< CDCWireHit > > &wireHitRelations, std::vector< CDCFacet > &facets)
Generates facets on the given wire hits generating neighboring triples of hits.
Definition: FacetCreator.cc:98
FacetCreator()
Constructor adding the filter as a subordinary processing signal listener.
Definition: FacetCreator.cc:29
static double fit(const CDCFacet &facet, int nSteps=100)
Fits a proper line to facet and returns the chi2.
Definition: FacetFitter.cc:166
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the set of parameters of the filter to the module parameter list.
A pair of iterators usable with the range base for loop.
Definition: Range.h:25
Iterator begin() const
Begin of the range for range based for.
Definition: Range.h:64
Iterator end() const
End of the range for range based for.
Definition: Range.h:68
A parameter line including including an line covariance matrix which is interpreted as located in the...
Type for two related objects with a weight.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:25
Abstract base class for different kinds of events.
double updateDriftLength(CDCRecoHit2D &recoHit2D)
Update the drift length of the reconstructed hit in place.
static void appendUsing(ARelationFilter &relationFilter, const std::vector< AObject * > &froms, const std::vector< AObject * > &tos, std::vector< WeightedRelation< AObject > > &weightedRelations, unsigned int maximumNumberOfRelations=std::numeric_limits< unsigned int >::max())
Appends relations between elements in the given AItems using the ARelationFilter.
Utility structure with functions related to weighted relations.