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/trackingUtilities/eventdata/segments/CDCWireHitCluster.h>
11#include <tracking/trackingUtilities/eventdata/hits/CDCFacet.h>
12#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
13
14#include <tracking/trackingUtilities/filters/base/RelationFilterUtil.h>
15#include <tracking/trackFindingCDC/fitting/FacetFitter.h>
16
17#include <tracking/trackingUtilities/utilities/VectorRange.h>
18#include <tracking/trackingUtilities/utilities/StringManipulation.h>
19
20#include <framework/core/ModuleParamList.templateDetails.h>
21
22#include <vector>
23#include <string>
24#include <algorithm>
25#include <cstdlib>
26
27using namespace Belle2;
28using namespace TrackFindingCDC;
29using namespace TrackingUtilities;
30
36
38{
39 return "Creates hit triplet (facets) from each cluster filtered by a acceptance criterion.";
40}
41
42void FacetCreator::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
43{
44 m_wireHitRelationFilter.exposeParameters(moduleParamList, prefix);
45 m_feasibleRLFacetFilter.exposeParameters(moduleParamList, prefix);
46 m_facetFilter.exposeParameters(moduleParamList, prefix);
47
48 moduleParamList->addParameter(prefixed(prefix, "updateDriftLength"),
50 "Switch to reestimate the drift length",
52
53 moduleParamList->addParameter(prefixed(prefix, "leastSquareFit"),
55 "Switch to fit the facet with the least square method "
56 "for drift length estimation",
58}
59
60void FacetCreator::apply(const std::vector<CDCWireHitCluster>& inputClusters, std::vector<CDCFacet>& facets)
61{
62 int iCluster = -1;
63 for (const CDCWireHitCluster& cluster : inputClusters) {
64 ++iCluster;
65 // Skip clusters that have been detected as background
66 if (cluster.getBackgroundFlag()) {
67 continue;
68 }
69 B2ASSERT("Expect the clusters to be sorted", std::is_sorted(cluster.begin(), cluster.end()));
70
71 // Obtain the set of wire hits as references
72 const std::vector<CDCWireHit*>& wireHits = cluster;
73
74 // Create the neighborhood of wire hits on the cluster
75 m_wireHitRelations.clear();
76 m_wireHitRelationFilter.prepare(wireHits);
78
79 B2ASSERT("Wire neighborhood is not symmetric. Check the geometry.",
81
82 // Create the facets
83 std::size_t nBefore = facets.size();
84 createFacets(cluster, m_wireHitRelations, facets);
85 std::size_t nAfter = facets.size();
86
87 VectorRange<CDCFacet> facetsInCluster(facets.begin() + nBefore, facets.begin() + nAfter);
88 // Sort the facets in their cluster
89 std::sort(facetsInCluster.begin(), facetsInCluster.end());
90
91 B2ASSERT("Expected all facets to be different",
92 std::adjacent_find(facetsInCluster.begin(), facetsInCluster.end()) ==
93 facetsInCluster.end());
94
95 for (CDCFacet& facet : facetsInCluster) {
96 facet.setICluster(iCluster);
97 }
98 }
99}
100
101void FacetCreator::createFacets(const std::vector<CDCWireHit*>& wireHits,
102 const std::vector<WeightedRelation<CDCWireHit> >& wireHitRelations,
103 std::vector<CDCFacet>& facets)
104{
105 for (const CDCWireHit* ptrMiddleWireHit : wireHits) {
106 if (not ptrMiddleWireHit) continue;
107 const CDCWireHit& middleWireHit = *ptrMiddleWireHit;
108 if (middleWireHit->hasTakenFlag()) continue;
109
110 const auto neighbors = asRange(
111 std::equal_range(wireHitRelations.begin(), wireHitRelations.end(), ptrMiddleWireHit));
112
113 for (const WeightedRelation<CDCWireHit>& startWireHitRelation : neighbors) {
114 const CDCWireHit* ptrStartWireHit(startWireHitRelation.getTo());
115
116 if (not ptrStartWireHit) continue;
117 const CDCWireHit& startWireHit = *ptrStartWireHit;
118 if (startWireHit->hasTakenFlag()) continue;
119
120 for (const WeightedRelation<CDCWireHit>& endWireHitRelation : neighbors) {
121 const CDCWireHit* ptrEndWireHit(endWireHitRelation.getTo());
122
123 if (not ptrEndWireHit) continue;
124 const CDCWireHit& endWireHit = *ptrEndWireHit;
125 if (endWireHit->hasTakenFlag()) continue;
126
127 // Skip combinations where the facet starts and ends on the same wire
128 if (ptrStartWireHit->isOnWire(ptrEndWireHit->getWire())) continue;
129
130 createFacetsForHitTriple(startWireHit, middleWireHit, endWireHit, facets);
131 } // end for itEndWireHit
132 } // end for itStartWireHit
133 } // end for itMiddleWireHit
134}
135
137 const CDCWireHit& middleWireHit,
138 const CDCWireHit& endWireHit,
139 std::vector<CDCFacet>& facets)
140{
142 CDCRLWireHit startRLWireHit(&startWireHit, ERightLeft::c_Left);
143 CDCRLWireHit middleRLWireHit(&middleWireHit, ERightLeft::c_Left);
144 CDCRLWireHit endRLWireHit(&endWireHit, ERightLeft::c_Left);
145 CDCFacet facet(startRLWireHit, middleRLWireHit, endRLWireHit, UncertainParameterLine2D());
146
147 // The shape of the hit triple does not depend on the right left passage hypotheses
148 const CDCRLWireHitTriple::Shape shape = facet.getShape();
150 shape.getCellExtend() + std::abs(shape.getOClockDelta()) > 6) {
151 // No right left passage combination is feasible for this shape - skip all of them
152 return;
153 }
154
155 // The middle right left passage hypothesis is scanned in the innermost loop:
156 // facets that differ only in it share the same start to end fit line, such that
157 // most of the drift length update can be reused between them.
158 for (ERightLeft startRLInfo : {ERightLeft::c_Left, ERightLeft::c_Right}) {
159 facet.setStartRLInfo(startRLInfo);
160 for (ERightLeft endRLInfo : {ERightLeft::c_Left, ERightLeft::c_Right}) {
161 facet.setEndRLInfo(endRLInfo);
162
163 // Results of the drift length update shared between the middle right left passage hypotheses
165
166 for (ERightLeft middleRLInfo : {ERightLeft::c_Left, ERightLeft::c_Right}) {
167 facet.setMiddleRLInfo(middleRLInfo);
168
169 // Reset the lines
170 // The filter shall do the fitting of the tangent lines if it wants to.
171 // He should set them if he accepts the facet.
172 facet.invalidateFitLine();
173
175 // Same check as m_feasibleRLFacetFilter(facet) but reusing the precomputed shape
176 if (not m_feasibleRLFacetFilter.isFeasible(shape, startRLInfo, middleRLInfo, endRLInfo)) continue;
177 }
178
181 // The fitted line depends on the middle hit drift length - no sharing possible
182
183 // Reset drift length
187
188 /*double chi2 =*/FacetFitter::fit(facet);
189
190 // Update drift length
191 m_driftLengthEstimator.updateDriftLength(facet);
192 } else {
193 if (not driftLengthCache.valid) {
194 // Reset drift length
198
199 facet.adjustFitLine();
200 }
201
202 // Update drift length reusing the shareable results of the previous hypothesis
203 m_driftLengthEstimator.updateDriftLength(facet, driftLengthCache);
204 }
205 }
206
207 Weight weight = m_facetFilter(facet);
208
209 if (not std::isnan(weight)) {
210 facet.getAutomatonCell().setCellWeight(weight);
211 facets.insert(facets.end(), facet);
212 }
213 } // end for middleRLWireHit
214 } // end for endRLWireHit
215 } // end for startRLWireHit
216}
The Module parameter list class.
DriftLengthEstimator m_driftLengthEstimator
Instance of the drift length estimator to be used.
void createFacetsForHitTriple(const TrackingUtilities::CDCWireHit &startWireHit, const TrackingUtilities::CDCWireHit &middleWireHit, const TrackingUtilities::CDCWireHit &endWireHit, std::vector< TrackingUtilities::CDCFacet > &facets)
Generates reconstruted facets on the three given wire hits by hypothesizing over the 8 left right pas...
BridgingWireHitRelationFilter m_wireHitRelationFilter
The filter for the hit neighborhood.
bool m_param_feasibleRLOnly
Parameter : Switch to apply the rl feasibility cut.
void apply(const std::vector< TrackingUtilities::CDCWireHitCluster > &inputClusters, std::vector< TrackingUtilities::CDCFacet > &facets) final
Central function creating the hit triplets from the clusters.
bool m_param_leastSquareFit
Parameter : Switch to fit the facet with least square method for the drift length update.
std::string getDescription() final
Short description of the findlet.
std::vector< TrackingUtilities::WeightedRelation< TrackingUtilities::CDCWireHit > > m_wireHitRelations
Memory for the wire hit neighborhood in within a cluster.
ChooseableFacetFilter m_facetFilter
The filter to be used for the facet generation.
bool m_param_updateDriftLength
Parameter : Switch to reestimate the drift length.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
FeasibleRLFacetFilter m_feasibleRLFacetFilter
The feasibility filter for the right left passage information.
void createFacets(const std::vector< TrackingUtilities::CDCWireHit * > &wireHits, const std::vector< TrackingUtilities::WeightedRelation< TrackingUtilities::CDCWireHit > > &wireHitRelations, std::vector< TrackingUtilities::CDCFacet > &facets)
Generates facets on the given wire hits generating neighboring triples of hits.
FacetCreator()
Constructor adding the filter as a subordinary processing signal listener.
static double fit(const TrackingUtilities::CDCFacet &facet, int nSteps=100, double maxChi2=std::numeric_limits< double >::infinity())
Fits a proper line to the facet and returns the chi2.
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
void setCellWeight(Weight weight)
Setter for the cell weight.
Class representing a triple of neighboring oriented wire with additional trajectory information.
Definition CDCFacet.h:33
void adjustFitLine() const
Adjusts the contained fit line to touch such that it touches the first and third hit.
Definition CDCFacet.cc:62
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Definition CDCFacet.h:132
void invalidateFitLine()
Clear all information in the fit.
Definition CDCFacet.cc:67
Type for the different shapes of a triple of neighboring wire hits.
short getCellExtend() const
Getter for the sum of cell distances from start to middle and middle to end.
short getOClockDelta() const
Getter for the o'clock direction difference from start to middle compared to middle to end.
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.
Shape getShape() const
Getter for the shape of this triple if all three oriented wire hits are neighbors....
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 ...
void setRefDriftLength(double driftLength)
Setter for the drift length at the reference position of the wire.
Class representing a hit wire in the central drift chamber.
Definition CDCWireHit.h:56
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
Definition CDCWireHit.h:225
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.
Abstract base class for different kinds of events.
Memory for the results of a facet drift length update that do not depend on the right left passage hy...
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.
static bool areSymmetric(const AWeightedRelations &weightedRelations)
Checks for the symmetry of a range of weighted relations Explicitly checks for each weighted relation...