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
62 {
63 Super::template constructArray<0>(-getMaximumX(), getMaximumX(), getOverlapX());
64 Super::template constructArray<1>(-getMaximumY(), getMaximumY(), getOverlapY());
65 Super::template constructArray<2>(-getMaximumZ(), getMaximumZ(), getOverlapZ());
66
68 }
69
71 std::vector<std::pair<HoughBox, std::vector<AHitPtr>>>
72 findSingleBest(const TrackingUtilities::Weight& minWeight)
73 {
74 AInBoxAlgorithm inBoxAlgorithm;
75 auto skipLowWeightNode = [minWeight](const typename Super::Node * node) {
76 return not(node->getWeight() >= minWeight);
77 };
78 auto found = this->getTree()->findHeaviestLeafSingle(inBoxAlgorithm, this->getMaxLevel(), skipLowWeightNode);
79
80 std::vector<std::pair<HoughBox, std::vector<AHitPtr>>> result;
81 if (found) {
82 // Move the found content over. unique_ptr still destroys the left overs.
83 result.push_back(std::move(*found));
84 }
85 return result;
86 }
87
89 void writeDebugInfoToFile(const std::string& filename __attribute__((unused)))
90 {
91 //do nothing;
92 }
93
99 void drawDebugPlot(const std::vector<TrackingUtilities::CDCRecoHit3D>& allHits,
100 const std::vector<TrackingUtilities::CDCRecoHit3D>& foundHits,
101 const typename AInBoxAlgorithm::HoughBox& node)
102 {
103 TGraph* allHitsGraph = new TGraph();
104 allHitsGraph->SetLineWidth(2);
105 allHitsGraph->SetLineColor(9);
106
107 for (const TrackingUtilities::CDCRecoHit3D& recoHit3D : allHits) {
108 const ROOT::Math::XYZVector& recoPos3D = recoHit3D.getRecoPos3D();
109 const double R = std::sqrt(recoPos3D.x() * recoPos3D.x() + recoPos3D.y() * recoPos3D.y());
110 const double Z = recoPos3D.z();
111 allHitsGraph->SetPoint(allHitsGraph->GetN(), R, Z);
112 }
113
114 static int nevent(0);
115 TCanvas canv("trackCanvas", "CDC stereo hits in an event", 0, 0, 1600, 1200);
116 canv.cd();
117 allHitsGraph->Draw("APL*");
118 allHitsGraph->GetXaxis()->SetLimits(0, 120);
119 allHitsGraph->GetYaxis()->SetRangeUser(-180, 180);
120
121 TGraph* foundHitsGraph = new TGraph();
122 foundHitsGraph->SetMarkerStyle(8);
123 foundHitsGraph->SetMarkerColor(2);
124
125 for (const TrackingUtilities::CDCRecoHit3D& recoHit3D : foundHits) {
126 const ROOT::Math::XYZVector& recoPos3D = recoHit3D.getRecoPos3D();
127 const double R = std::sqrt(recoPos3D.x() * recoPos3D.x() + recoPos3D.y() * recoPos3D.y());
128 const double Z = recoPos3D.z();
129 foundHitsGraph->SetPoint(foundHitsGraph->GetN(), R, Z);
130 }
131 foundHitsGraph->Draw("P");
132
133 const double centerX = (AInBoxAlgorithm::BoxAlgorithm::centerX(node));
134 const double deltaX = (AInBoxAlgorithm::BoxAlgorithm::deltaX(node));
135 const double centerY = (AInBoxAlgorithm::BoxAlgorithm::centerY(node));
136 const double centerZ = (AInBoxAlgorithm::BoxAlgorithm::centerZ(node));
137
138 TF1* candidateL = new TF1("candL", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
139 TF1* candidateH = new TF1("candH", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
140 TF1* candidateMean = new TF1("candMean", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
141
142 candidateL->SetParameters(centerX - deltaX, centerY, centerZ - 100.0 * deltaX);
143 candidateH->SetParameters(centerX + deltaX, centerY, centerZ + 100.0 * deltaX);
144 candidateMean->SetParameters(centerX, centerY, centerZ);
145
146 candidateL->SetLineColor(9);
147 candidateH->SetLineColor(41);
148 candidateMean->SetLineColor(2);
149
150 candidateL->Draw("same");
151 candidateH->Draw("same");
152 candidateMean->Draw("same");
153 canv.SaveAs(Form("CDCRLHits_%i.png", nevent));
154 nevent++;
155 }
156
158 float getMaximumX() const
159 {
160 return m_maximumX;
161 }
162
164 float getMaximumY() const
165 {
166 return m_maximumY;
167 }
168
170 float getMaximumZ() const
171 {
172 return m_maximumZ;
173 }
174
177 {
178 return m_overlapX;
179 }
180
183 {
184 return m_overlapY;
185 }
186
189 {
190 return m_overlapZ;
191 }
192
193 private:
195 float m_maximumX = 0;
196
198 float m_maximumY = 0;
199
201 float m_maximumZ = 0;
202
205
208
211 };
212 }
214}
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)
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.
void writeDebugInfoToFile(const std::string &filename)
Write debug information into a ROOT file; not implemented.
Width< 1 > getOverlapY() const
Return the overlap in y direction.
BoxDivisionHoughTree< AHitPointerType, typename AHitDecisionAlgorithm::HoughBox, divisionX, divisionY, divisionZ > Super
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.