10 #include <tracking/trackFindingCDC/collectors/matchers/StereoHitTrackQuadTreeMatcher.h>
12 #include <tracking/trackFindingCDC/hough/z0_tanLambda/HitZ0TanLambdaLegendre.h>
13 #include <tracking/trackFindingCDC/hough/quadratic/HitQuadraticLegendre.h>
14 #include <tracking/trackFindingCDC/hough/hyperbolic/HitHyperHough.h>
16 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
18 #include <tracking/trackFindingCDC/eventdata/hits/CDCRLWireHit.h>
19 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
20 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
22 #include <tracking/trackFindingCDC/ca/AutomatonCell.h>
24 #include <framework/core/ModuleParamList.templateDetails.h>
26 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
31 using namespace TrackFindingCDC;
33 template <
class AQuadTree>
35 const std::string& prefix)
37 Super::exposeParameters(moduleParamList, prefix);
39 moduleParamList->
addParameter(prefixed(prefix,
"level"), m_param_quadTreeLevel,
40 "The number of levels for the quad tree search.",
41 m_param_quadTreeLevel);
43 moduleParamList->
addParameter(prefixed(prefix,
"minimumNumberOfHits"), m_param_minimumNumberOfHits,
44 "The minimum number of hits in a quad tree bin to be called as result.",
45 m_param_minimumNumberOfHits);
47 moduleParamList->
addParameter(prefixed(prefix,
"writeDebugInformation"), m_param_writeDebugInformation,
48 "Set to true to output debug information.",
49 m_param_writeDebugInformation);
51 moduleParamList->
addParameter(prefixed(prefix,
"checkForB2BTracks"),
52 m_param_checkForB2BTracks,
53 "Set to false to skip the check for back-2-back tracks "
54 "(good for cosmics).",
55 m_param_checkForB2BTracks);
57 moduleParamList->
addParameter(prefixed(prefix,
"checkForInWireBoundsFactor"),
58 m_param_checkForInWireBoundsFactor,
59 "Used to scale the CDC before checking "
60 "whether hits are in the CDC z bounds.",
61 m_param_checkForInWireBoundsFactor);
65 template <
class AQuadTree>
70 m_quadTreeInstance.setMaxLevel(m_param_quadTreeLevel);
71 m_quadTreeInstance.initialize();
75 template <
class AQuadTree>
80 m_quadTreeInstance.raze();
83 template <
class AQuadTree>
85 std::vector<Super::WeightedRelationItem>& relationsForCollector)
93 const CDCTrajectory2D& trajectory2D = track.getStartTrajectory3D().getTrajectory2D();
94 const bool isCurler = trajectory2D.
isCurler();
96 using CDCRecoHitWithRLPointer = std::pair<CDCRecoHit3D, const CDCRLWireHit*>;
97 std::vector<CDCRecoHitWithRLPointer> recoHits;
98 recoHits.reserve(rlWireHits.size() + track.size());
105 if (rlWireHit.getWireHit().getAutomatonCell().hasTakenFlag())
continue;
107 const CDCWire& wire = rlWireHit.getWire();
109 double signedDriftLength = rlWireHit.getSignedRefDriftLength();
112 if (not wire.
isInCellZBounds(recoPos3D, m_param_checkForInWireBoundsFactor)) {
122 }
else if (m_param_checkForB2BTracks) {
126 recoHits.emplace_back(
CDCRecoHit3D(rlWireHit, recoPos3D, perpS), &rlWireHit);
132 if (not recoHit.isAxial()) {
133 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
135 recoHits.emplace_back(recoHit, &rlWireHit);
140 m_quadTreeInstance.seed(recoHits);
142 if (m_param_writeDebugInformation) {
143 writeDebugInformation();
146 const auto& foundStereoHitsWithNode = m_quadTreeInstance.findSingleBest(m_param_minimumNumberOfHits);
147 m_quadTreeInstance.fell();
149 if (foundStereoHitsWithNode.size() != 1) {
154 auto foundStereoHits = foundStereoHitsWithNode[0].second;
155 const auto& node = foundStereoHitsWithNode[0].first;
157 if (m_param_writeDebugInformation) {
158 std::vector<CDCRecoHit3D> allHits;
159 std::vector<CDCRecoHit3D> foundHits;
161 for (
const CDCRecoHitWithRLPointer recoHitWithRL : recoHits) {
163 allHits.push_back(recoHit3D);
165 for (
const CDCRecoHitWithRLPointer recoHitWithRL : foundStereoHits) {
167 foundHits.push_back(recoHit3D);
169 m_quadTreeInstance.drawDebugPlot(allHits, foundHits, node);
173 const auto& isAssignedHit = [](
const CDCRecoHitWithRLPointer & recoHitWithRLPointer) {
174 const CDCRecoHit3D& recoHit3D = recoHitWithRLPointer.first;
179 foundStereoHits.erase(std::remove_if(foundStereoHits.begin(),
180 foundStereoHits.end(),
182 foundStereoHits.end());
185 auto sortByHitAndNodeCenterDistance = [node](
const CDCRecoHitWithRLPointer & lhs,
186 const CDCRecoHitWithRLPointer & rhs) {
195 if (lhsWireHit < rhsWireHit) {
197 }
else if (rhsWireHit < lhsWireHit) {
200 return AQuadTree::DecisionAlgorithm::BoxAlgorithm::compareDistances(node, lhsRecoHit, rhsRecoHit);
204 const auto& sameHitComparer = [](
const CDCRecoHitWithRLPointer & lhs,
205 const CDCRecoHitWithRLPointer & rhs) {
212 std::sort(foundStereoHits.begin(),
213 foundStereoHits.end(),
214 sortByHitAndNodeCenterDistance);
217 foundStereoHits.erase(std::unique(foundStereoHits.begin(),
218 foundStereoHits.end(),
220 foundStereoHits.end());
223 for (
const CDCRecoHitWithRLPointer& recoHitWithRLPointer : foundStereoHits) {
224 const CDCRLWireHit* rlWireHit = recoHitWithRLPointer.second;
225 relationsForCollector.emplace_back(&track, foundStereoHits.size(), rlWireHit);
229 template <
class AQuadTree>
232 std::string outputFileName =
"quadTreeContent_call_" + std::to_string(m_numberOfPassedDebugCalls) +
".root";
233 m_quadTreeInstance.writeDebugInfoToFile(outputFileName);
235 m_numberOfPassedDebugCalls++;