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