Belle II Software development
SimpleBoxDivisionHoughTree3D.h
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#pragma once
9#include <tracking/trackFindingCDC/hough/trees/BoxDivisionHoughTree.h>
10#include <tracking/trackingUtilities/eventdata/hits/CDCRecoHit3D.h>
11
12#include <Math/Vector3D.h>
13#include <TGraph.h>
14#include <TF1.h>
15#include <TCanvas.h>
16#include <TAxis.h>
17
18namespace Belle2 {
23 namespace TrackFindingCDC {
24
27 template<class AHitPtr, class AInBoxAlgorithm, size_t divisionX, size_t divisionY, size_t divisionZ>
29 BoxDivisionHoughTree<AHitPtr, typename AInBoxAlgorithm::HoughBox, divisionX, divisionY, divisionZ> {
30
31 private:
34
36 using HoughBox = typename AInBoxAlgorithm::HoughBox;
37
39 template <size_t I>
40 using Width = typename HoughBox::template Width<I>;
41
42 public:
45 float maximumY,
46 float maximumZ,
47 Width<0> overlapX = 0,
48 Width<1> overlapY = 0,
49 Width<2> overlapZ = 0)
50 : Super(0)
51 , m_maximumX(maximumX)
52 , m_maximumY(maximumY)
53 , m_maximumZ(maximumZ)
54 , m_overlapX(overlapX)
55 , m_overlapY(overlapY)
56 , m_overlapZ(overlapZ)
57 {
58 }
59
61 // cppcheck-suppress duplInheritedMember ; intentionally hides the base class member, which it extends and then calls
63 {
64 Super::template constructArray<0>(-getMaximumX(), getMaximumX(), getOverlapX());
65 Super::template constructArray<1>(-getMaximumY(), getMaximumY(), getOverlapY());
66 Super::template constructArray<2>(-getMaximumZ(), getMaximumZ(), getOverlapZ());
67
69 }
70
72 std::vector<std::pair<HoughBox, std::vector<AHitPtr>>>
73 findSingleBest(const TrackingUtilities::Weight& minWeight)
74 {
75 AInBoxAlgorithm inBoxAlgorithm;
76 auto skipLowWeightNode = [minWeight](const typename Super::Node * node) {
77 return not(node->getWeight() >= minWeight);
78 };
79 auto found = this->getTree()->findHeaviestLeafSingle(inBoxAlgorithm, this->getMaxLevel(), skipLowWeightNode);
80
81 std::vector<std::pair<HoughBox, std::vector<AHitPtr>>> result;
82 if (found) {
83 // Move the found content over. unique_ptr still destroys the left overs.
84 result.push_back(std::move(*found));
85 }
86 return result;
87 }
88
90 static void writeDebugInfoToFile(const std::string& filename __attribute__((unused)))
91 {
92 //do nothing;
93 }
94
100 static void drawDebugPlot(const std::vector<TrackingUtilities::CDCRecoHit3D>& allHits,
101 const std::vector<TrackingUtilities::CDCRecoHit3D>& foundHits,
102 const typename AInBoxAlgorithm::HoughBox& node)
103 {
104 TGraph* allHitsGraph = new TGraph();
105 allHitsGraph->SetLineWidth(2);
106 allHitsGraph->SetLineColor(9);
107
108 for (const TrackingUtilities::CDCRecoHit3D& recoHit3D : allHits) {
109 const ROOT::Math::XYZVector& recoPos3D = recoHit3D.getRecoPos3D();
110 const double R = std::sqrt(recoPos3D.x() * recoPos3D.x() + recoPos3D.y() * recoPos3D.y());
111 const double Z = recoPos3D.z();
112 allHitsGraph->SetPoint(allHitsGraph->GetN(), R, Z);
113 }
114
115 static int nevent(0);
116 TCanvas canv("trackCanvas", "CDC stereo hits in an event", 0, 0, 1600, 1200);
117 canv.cd();
118 allHitsGraph->Draw("APL*");
119 allHitsGraph->GetXaxis()->SetLimits(0, 120);
120 allHitsGraph->GetYaxis()->SetRangeUser(-180, 180);
121
122 TGraph* foundHitsGraph = new TGraph();
123 foundHitsGraph->SetMarkerStyle(8);
124 foundHitsGraph->SetMarkerColor(2);
125
126 for (const TrackingUtilities::CDCRecoHit3D& recoHit3D : foundHits) {
127 const ROOT::Math::XYZVector& recoPos3D = recoHit3D.getRecoPos3D();
128 const double R = std::sqrt(recoPos3D.x() * recoPos3D.x() + recoPos3D.y() * recoPos3D.y());
129 const double Z = recoPos3D.z();
130 foundHitsGraph->SetPoint(foundHitsGraph->GetN(), R, Z);
131 }
132 foundHitsGraph->Draw("P");
133
134 const double centerX = (AInBoxAlgorithm::BoxAlgorithm::centerX(node));
135 const double deltaX = (AInBoxAlgorithm::BoxAlgorithm::deltaX(node));
136 const double centerY = (AInBoxAlgorithm::BoxAlgorithm::centerY(node));
137 const double centerZ = (AInBoxAlgorithm::BoxAlgorithm::centerZ(node));
138
139 TF1* candidateL = new TF1("candL", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
140 TF1* candidateH = new TF1("candH", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
141 TF1* candidateMean = new TF1("candMean", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
142
143 candidateL->SetParameters(centerX - deltaX, centerY, centerZ - 100.0 * deltaX);
144 candidateH->SetParameters(centerX + deltaX, centerY, centerZ + 100.0 * deltaX);
145 candidateMean->SetParameters(centerX, centerY, centerZ);
146
147 candidateL->SetLineColor(9);
148 candidateH->SetLineColor(41);
149 candidateMean->SetLineColor(2);
150
151 candidateL->Draw("same");
152 candidateH->Draw("same");
153 candidateMean->Draw("same");
154 canv.SaveAs(Form("CDCRLHits_%i.png", nevent));
155 nevent++;
156 }
157
159 float getMaximumX() const
160 {
161 return m_maximumX;
162 }
163
165 float getMaximumY() const
166 {
167 return m_maximumY;
168 }
169
171 float getMaximumZ() const
172 {
173 return m_maximumZ;
174 }
175
178 {
179 return m_overlapX;
180 }
181
184 {
185 return m_overlapY;
186 }
187
190 {
191 return m_overlapZ;
192 }
193
194 private:
196 float m_maximumX = 0;
197
199 float m_maximumY = 0;
200
202 float m_maximumZ = 0;
203
206
209
212 };
213 }
215}
double R
typedef autogenerated by FFTW
typename HoughTree::Node Node
Type of the nodes used in the tree for the search.
void constructArray(double lowerBound, double upperBound, Width< I > nBinOverlap=0, Width< I > nBinWidth=0)
SimpleBoxDivisionHoughTree3D(float maximumX, float maximumY, float maximumZ, Width< 0 > overlapX=0, Width< 1 > overlapY=0, Width< 2 > overlapZ=0)
Constructor using the given maximal level.
float getMaximumZ() const
Return the maximum value in Z direction.
void initialize()
Initialize the tree with the given values.
float getMaximumY() const
Return the maximum value in y direction.
Width< 0 > getOverlapX() const
Return the overlap in x direction.
std::vector< std::pair< HoughBox, std::vector< AHitPtr > > > findSingleBest(const TrackingUtilities::Weight &minWeight)
Find only the leaf with the highest weight (~= number of items)
static void drawDebugPlot(const std::vector< TrackingUtilities::CDCRecoHit3D > &allHits, const std::vector< TrackingUtilities::CDCRecoHit3D > &foundHits, const typename AInBoxAlgorithm::HoughBox &node)
Draws found hits and node boundaries FIXME this is a copy-paste from DebugableSimpleBoxDivisionHoughT...
float getMaximumX() const
Return the maximum value in x direction.
Width< 1 > getOverlapY() const
Return the overlap in y direction.
BoxDivisionHoughTree< AHitPointerType, typename AHitDecisionAlgorithm::HoughBox, divisionX, divisionY, divisionZ > Super
static void writeDebugInfoToFile(const std::string &filename)
Write debug information into a ROOT file; not implemented.
Width< 2 > getOverlapZ() const
Return the overlap in y direction.
std::unique_ptr< std::pair< ADomain, std::vector< T > > > findHeaviestLeafSingle(AItemInDomainMeasure &weightItemInDomain, int maxLevel, ASkipNodePredicate &skipNode)
Go through all children until the maxLevel is reached and find the leaf with the highest weight.
Class representing a three dimensional reconstructed hit.
Abstract base class for different kinds of events.