8#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
10#include <tracking/trackFindingCDC/eventdata/segments/CDCFacetSegment.h>
11#include <tracking/trackFindingCDC/eventdata/segments/CDCTangentSegment.h>
13#include <tracking/trackFindingCDC/eventdata/segments/CDCRLWireHitSegment.h>
14#include <tracking/trackFindingCDC/eventdata/segments/CDCWireHitSegment.h>
15#include <tracking/trackFindingCDC/eventdata/hits/CDCFacet.h>
16#include <tracking/trackFindingCDC/eventdata/hits/CDCTangent.h>
17#include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit2D.h>
18#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
19#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
21#include <tracking/trackFindingCDC/geometry/Vector2D.h>
23#include <tracking/trackFindingCDC/ca/AutomatonCell.h>
25#include <tracking/trackFindingCDC/numerics/ERightLeft.h>
27#include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
28#include <tracking/trackFindingCDC/utilities/Relation.h>
29#include <tracking/trackFindingCDC/utilities/Algorithms.h>
30#include <tracking/trackFindingCDC/utilities/ReversedRange.h>
31#include <tracking/trackFindingCDC/utilities/GetIterator.h>
33#include <framework/logging/Logger.h>
47 namespace TrackFindingCDC {
55using namespace TrackFindingCDC;
61 size_t nRLWireHits = rlWireHitSegment.size();
62 if (nRLWireHits < 2)
return;
64 tangentSegment.reserve(nRLWireHits - 1);
67 transform_adjacent_pairs(rlWireHitSegment.begin(), rlWireHitSegment.end(),
68 back_inserter(tangentSegment),
71 return CDCTangent(firstRLWireHit, secondRLWireHit);
74 if (tangentSegment.size() + 1 != rlWireHitSegment.size()) {
75 B2ERROR(
"Wrong number of tangents created.");
80 template<
class ATangentRange>
81 CDCSegment2D condenseTangentSegment(
const ATangentRange& tangentSegment)
83 using TangentIt = GetIterator<const ATangentRange&>;
84 TangentIt tangentIt{tangentSegment.begin()};
85 TangentIt endTangentIt{tangentSegment.end()};
86 int nTangents = std::distance(tangentIt, endTangentIt);
89 result.reserve(nTangents + 1);
93 }
else if (nTangents == 1) {
100 TangentIt firstTangentIt = tangentIt++;
101 TangentIt secondTangentIt = tangentIt++;
104 const CDCTangent& firstTangent = *firstTangentIt;
108 while (tangentIt != endTangentIt) {
110 firstTangentIt = secondTangentIt;
111 secondTangentIt = tangentIt++;
113 const CDCTangent& firstTangent = *firstTangentIt;
114 const CDCTangent& secondTangent = *secondTangentIt;
120 const CDCTangent& secondTangent = *secondTangentIt;
125 result.receiveISuperCluster();
129 template<
class AFacetRange>
130 CDCSegment2D condenseFacetSegment(
const AFacetRange& facetSegment)
132 using FacetIt = GetIterator<const AFacetRange&>;
133 FacetIt facetIt = facetSegment.begin();
134 FacetIt endFacetIt = facetSegment.end();
135 int nFacets = std::distance(facetIt, endFacetIt);
138 result.reserve(nFacets + 2);
142 }
else if (nFacets == 1) {
143 FacetIt onlyFacetIt = facetIt;
144 const CDCFacet& onlyFacet = *onlyFacetIt;
149 }
else if (nFacets == 2) {
150 FacetIt firstFacetIt = facetIt++;
151 FacetIt secondFacetIt = facetIt;
153 const CDCFacet& firstFacet = *firstFacetIt;
154 const CDCFacet& secondFacet = *secondFacetIt;
166 FacetIt firstFacetIt = facetIt++;
167 FacetIt secondFacetIt = facetIt++;
168 FacetIt thirdFacetIt = facetIt++;
171 const CDCFacet& firstFacet = *firstFacetIt;
172 const CDCFacet& secondFacet = *secondFacetIt;
173 const CDCFacet& thirdFacet = *thirdFacetIt;
185 while (facetIt != endFacetIt) {
186 firstFacetIt = secondFacetIt;
187 secondFacetIt = thirdFacetIt;
188 thirdFacetIt = facetIt++;
190 const CDCFacet& firstFacet = *firstFacetIt;
191 const CDCFacet& secondFacet = *secondFacetIt;
192 const CDCFacet& thirdFacet = *thirdFacetIt;
199 const CDCFacet& secondFacet = *secondFacetIt;
200 const CDCFacet& thirdFacet = *thirdFacetIt;
209 result.receiveISuperCluster();
217 const std::vector<CDCTangent>& tangents = tangentSegment;
218 CDCSegment2D segment2D = ::condenseTangentSegment(tangents);
227 std::vector<std::reference_wrapper<const CDCTangent> > tangents;
228 tangents.reserve(tangentPath.size());
229 for (
const CDCTangent* tangent : tangentPath) {
230 tangents.push_back(std::ref(*tangent));
233 return ::condenseTangentSegment(tangents);
238 const std::vector<CDCFacet>& facets = facetSegment;
239 CDCSegment2D segment2D = ::condenseFacetSegment(facets);
248 std::vector<std::reference_wrapper<const CDCFacet> > facets;
249 facets.reserve(facetPath.size());
250 for (
const CDCFacet* facet : facetPath) {
251 facets.push_back(std::ref(*facet));
254 return ::condenseFacetSegment(facets);
260 double aliasScore = 0;
262 assert(ptrSegment2D);
264 if (result.empty()) {
268 result.push_back(recoHit2D);
273 result.receiveISuperCluster();
274 result.setAliasScore(aliasScore);
280 if (rlWireHitSegment.size() == 1) {
283 segment2D.emplace_back(rlWireHitSegment.front(), zeroDisp2D);
290 createTangentSegment(rlWireHitSegment, tangentSegment);
299 if (rlWireHitSegment.size() < 3) {
309 return {
this, segment};
314 return {
this, weight, segment};
326 std::vector<const CDCWire*> wireSegment;
328 wireSegment.push_back(&(recoHit2D.
getWire()));
337 wireHitSegment.push_back(&(recoHit2D.
getWireHit()));
341 return wireHitSegment;
348 segment.push_back(recoHit2D.
getAlias());
358 int nRLSwitches = -1;
376 return static_cast<double>(rlSum) / size();
387 return rlWireHitSegment;
393 reverseSegment.reserve(size());
394 for (
const CDCRecoHit2D& recohit : reversedRange(*
this)) {
395 reverseSegment.push_back(recohit.reversed());
402 return reverseSegment;
415 std::reverse(begin(), end());
421 if (not toHits)
return;
431 if (not toHits)
return;
440 if (not fromHits)
return;
452 unsigned int notTakenCounter = 0;
456 if (notTakenCounter > maxNotTaken) {
467 auto getISuperClusterOfHit = [](
const CDCRecoHit2D & recoHit2d) ->
int {
468 return recoHit2d.getWireHit().getISuperCluster();
470 int iSuperCluster = common(*
this, getISuperClusterOfHit, -1);
void setMaskedFlag(bool setTo=true)
Sets the masked flag to the given value. Default value true.
void unsetMaskedFlag()
Resets the masked flag to false.
bool hasMaskedFlag() const
Gets the current state of the masked marker flag.
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
A segment consisting of adjacent facets.
static CDCFacetSegment create(const CDCRLWireHitSegment &rlWireHitSegment)
Construct a train of facets from the given oriented wire hits.
Class representing a triple of neighboring oriented wire with additional trajectory information.
CDCRecoHit2D getEndRecoHit2D() const
Getter for the third reconstructed hit.
CDCRecoHit2D getMiddleRecoHit2D() const
Getter for the second reconstructed hit.
CDCRecoHit2D getStartRecoHit2D() const
Getter for the first reconstructed hit.
A segment consisting of two dimensional reconstructed hits.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Class representing a two dimensional reconstructed hit in the central drift chamber.
const CDCWireHit & getWireHit() const
Getter for the wire hit associated with the reconstructed hit.
const CDCRLWireHit & getRLWireHit() const
Getter for the oriented wire hit associated with the reconstructed hit.
void reverse()
Turns the orientation in place.
CDCRecoHit2D getAlias() const
Getter for the alias version of the reco hit.
const CDCWire & getWire() const
Getter for the wire the reconstructed hit associated to.
static CDCRecoHit2D average(const CDCRecoHit2D &recoHit1, const CDCRecoHit2D &recoHit2)
Constructs the average of two reconstructed hit positions and snaps it to the drift circle.
ERightLeft getRLInfo() const
Getter for the right left passage information.
A reconstructed sequence of two dimensional hits in one super layer.
std::vector< const CDCWire * > getWireSegment() const
Getter for the vector of wires the hits of this segment are based on in the same order.
Relation< const CDCSegment2D, const CDCSegment2D > makeRelation(const CDCSegment2D *segment) const
Helper constructor to create a relation in python.
bool isFullyTaken(unsigned int maxNotTaken=0) const
Returns false, if there are more than N hits in the range which does not have a taken flag.
void unsetAndForwardMaskedFlag(bool toHits=false) const
Unset the masked flag of the automaton cell of this segment and of all contained wire hits.
void reverse()
Reverses the order of hits and their right left passage hypotheses inplace.
double getRLAsymmetry() const
Getter for the sum of right left information relative to the size.
void receiveMaskedFlag(bool fromHits=false) const
Check all contained wire hits if one has the masked flag.
CDCSegment2D getAlias() const
Getter for the alias version of the segment - fit not copied.
bool operator<(const CDCSegment2D &segment2D) const
Comparison of segments up to the super cluster id keeping them close together on sort.
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
void receiveISuperCluster() const
Setter for the super cluster id based on the hit content.
static CDCSegment2D reconstructUsingTangents(const CDCRLWireHitSegment &rlWireHitSegment)
Reconstruct from wire hits with attached right left passage hypotheses by constructing tangents betwe...
void setAndForwardMaskedFlag(bool toHits=false) const
Set the masked flag of the automaton cell of this segment and forward the masked flag to all containe...
static CDCSegment2D reconstructUsingFacets(const CDCRLWireHitSegment &rlWireHitSegment)
Reconstruct from wire hits with attached right left passage hypotheses by constructing facets between...
WeightedRelation< const CDCSegment2D, const CDCSegment2D > makeWeightedRelation(double weight, const CDCSegment2D *segment) const
Helper constructor to create a relation in python.
AutomatonCell m_automatonCell
Memory for the automaton cell.
CDCSegment2D reversed() const
Makes a copy of the segment with the reversed hits in the opposite order.
static CDCSegment2D condense(const CDCTangentSegment &tangentSegment)
Averages the reconstructed positions from hits that overlap in adjacent tangents in the given tangent...
CDCWireHitSegment getWireHitSegment() const
Getter for the vector of the wire hits of this segment are based on in the same order.
int getISuperCluster() const
Getter for the global super cluster id.
void setISuperCluster(int iSuperCluster) const
Setter for the globale super cluster id.
int getNRLSwitches() const
Getter for the number of changes in the right left passage in the segment.
CDCRLWireHitSegment getRLWireHitSegment() const
Getter for the vector of right left oriented the hits of this segment.
void setTrajectory2D(const CDCTrajectory2D &trajectory2D) const
Setter for the two dimensional trajectory fitted to the segment.
ISuperLayer getISuperLayer() const
Returns the common super layer id of all stored tracking hits.
CDCTrajectory2D & getTrajectory2D() const
Getter for the two dimensional trajectory fitted to the segment.
void setAliasScore(double aliasScore)
Setter for the flag that this segment may have an aliased version.
double getAliasScore() const
Getter for the flag that this segment may have an aliased version.
A segment consisting of adjacent tangents.
Class representing a linear track piece between two oriented wire hits.
CDCRecoHit2D getToRecoHit2D() const
Getter for the reconstructed hit on the second oriented wire hit using reconstructed touch point as p...
CDCRecoHit2D getFromRecoHit2D() const
Getter for the reconstructed hit on the first oriented wire hit using reconstructed touch point as po...
void reverse()
Reverses the trajectory in place.
A segment consisting of two dimensional reconstructed hits.
Class representing a hit wire in the central drift chamber.
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Class representing a sense wire in the central drift chamber.
Type for two related objects.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
Type for two related objects with a weight.
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Abstract base class for different kinds of events.