Belle II Software development
DebugableSimpleBoxDivisionHoughTree.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/SimpleBoxDivisionHoughTree.h>
10
11#include <Math/Vector3D.h>
12#include <TTree.h>
13#include <TFile.h>
14#include <TGraph.h>
15#include <TF1.h>
16#include <TCanvas.h>
17#include <TAxis.h>
18
19namespace Belle2 {
24 namespace TrackFindingCDC {
25
27 template<class AHitPtr, class AInBoxAlgorithm, size_t divisionX, size_t divisionY>
29 public SimpleBoxDivisionHoughTree<AHitPtr, AInBoxAlgorithm, divisionX, divisionY> {
30 private:
33 public:
35 using Super::Super;
36
43 void writeDebugInfoToFile(const std::string& filename)
44 {
45 fillAll();
46
47 TFile openedRootFile(filename.c_str(), "RECREATE");
48 TTree weightTTree("weightTree", "A tree with the weights of the box items.");
49 TTree eventTTree("eventTree", "A tree with event information.");
50
51 double lowerX, upperX, lowerY, upperY, weight, level;
52 weightTTree.Branch("lowerX", &lowerX);
53 weightTTree.Branch("upperY", &upperY);
54 weightTTree.Branch("lowerY", &lowerY);
55 weightTTree.Branch("upperX", &upperX);
56 weightTTree.Branch("weight", &weight);
57 weightTTree.Branch("level", &level);
58
59 double lowerLimX = -Super::getMaximumX();
60 double upperLimX = Super::getMaximumX();
61 double lowerLimY = -Super::getMaximumY();
62 double upperLimY = Super::getMaximumY();
63 double maxLevel = Super::getMaxLevel();
64 eventTTree.Branch("lowerLimX", &lowerLimX);
65 eventTTree.Branch("upperLimX", &upperLimX);
66 eventTTree.Branch("lowerLimY", &lowerLimY);
67 eventTTree.Branch("upperLimY", &upperLimY);
68 eventTTree.Branch("maxLevel", &maxLevel);
69 eventTTree.Fill();
70 eventTTree.Write();
71
72 auto walker = [&](const typename Super::Node * node) -> bool {
73 lowerX = node->getLowerX();
74 upperX = node->getUpperX();
75 upperY = node->getUpperY();
76 weight = node->getWeight();
77 level = node->getLevel();
78
79 weightTTree.Fill();
80
81 // Always return true, as we want to access every node
82 return true;
83 };
84 Super::getTree()->walk(walker);
85
86 weightTTree.Write();
87 openedRootFile.Write();
88 openedRootFile.Close();
89 }
90
92 static void drawDebugPlot(const std::vector<TrackingUtilities::CDCRecoHit3D>& allHits,
93 const std::vector<TrackingUtilities::CDCRecoHit3D>& foundHits,
94 const typename AInBoxAlgorithm::HoughBox& node)
95 {
96 TGraph* allHitsGraph = new TGraph();
97 allHitsGraph->SetLineWidth(2);
98 allHitsGraph->SetLineColor(9);
99
100 for (const TrackingUtilities::CDCRecoHit3D& recoHit3D : allHits) {
101 const ROOT::Math::XYZVector& recoPos3D = recoHit3D.getRecoPos3D();
102 const double R = std::sqrt(recoPos3D.x() * recoPos3D.x() + recoPos3D.y() * recoPos3D.y());
103 const double Z = recoPos3D.z();
104 allHitsGraph->SetPoint(allHitsGraph->GetN(), R, Z);
105 }
106
107 static int nevent(0);
108 TCanvas canv("trackCanvas", "CDC stereo hits in an event", 0, 0, 1600, 1200);
109 canv.cd();
110 allHitsGraph->Draw("APL*");
111 allHitsGraph->GetXaxis()->SetLimits(0, 120);
112 allHitsGraph->GetYaxis()->SetRangeUser(-180, 180);
113
114 TGraph* foundHitsGraph = new TGraph();
115 foundHitsGraph->SetMarkerStyle(8);
116 foundHitsGraph->SetMarkerColor(2);
117
118 for (const TrackingUtilities::CDCRecoHit3D& recoHit3D : foundHits) {
119 const ROOT::Math::XYZVector& recoPos3D = recoHit3D.getRecoPos3D();
120 const double R = std::sqrt(recoPos3D.x() * recoPos3D.x() + recoPos3D.y() * recoPos3D.y());
121 const double Z = recoPos3D.z();
122 foundHitsGraph->SetPoint(foundHitsGraph->GetN(), R, Z);
123 }
124 foundHitsGraph->Draw("P");
125
126 const double xMean = (node.getLowerX() + node.getUpperX()) / 2.0; //Z0 or Z1
127 const double yMean = (node.getLowerY() + node.getUpperY()) / 2.0; //tanLambda or Z2
128 const double xLow = node.getLowerX();
129 const double yLow = node.getLowerY();
130 const double xHigh = node.getUpperX();
131 const double yHigh = node.getUpperY();
132
133 TF1* candidateLL = new TF1("candLL", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
134 TF1* candidateLH = new TF1("candLH", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
135 TF1* candidateHL = new TF1("candHL", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
136 TF1* candidateHH = new TF1("candHH", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
137 TF1* candidateMean = new TF1("candMean", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
138
139 candidateLL->SetParameters(xLow, yLow);
140 candidateLH->SetParameters(xLow, yHigh);
141 candidateHL->SetParameters(xHigh, yLow);
142 candidateHH->SetParameters(xHigh, yHigh);
143 candidateMean->SetParameters(xMean, yMean);
144
145 candidateLL->SetLineColor(9);
146 candidateLH->SetLineColor(30);
147 candidateHL->SetLineColor(46);
148 candidateHH->SetLineColor(41);
149 candidateMean->SetLineColor(2);
150
151 candidateLL->Draw("same");
152 candidateHL->Draw("same");
153 candidateLH->Draw("same");
154 candidateHH->Draw("same");
155 candidateMean->Draw("same");
156 canv.SaveAs(Form("CDCRLHits_%i.png", nevent));
157 nevent++;
158 }
159
160 private:
165 void fillAll()
166 {
167 AInBoxAlgorithm inBoxAlgorithm;
168
169 auto isLeaf = [this](typename Super::Node * node) {
170 return (node->getLevel() > this->getMaxLevel());
171 };
172
173 this->getTree()->fillWalk(inBoxAlgorithm, isLeaf);
174 }
175 };
176 }
178}
double R
typedef autogenerated by FFTW
A convenience class for adding debug information to a Simple Hough Tree.
static void drawDebugPlot(const std::vector< TrackingUtilities::CDCRecoHit3D > &allHits, const std::vector< TrackingUtilities::CDCRecoHit3D > &foundHits, const typename AInBoxAlgorithm::HoughBox &node)
Draw the results to a ROOT TCanvas.
void writeDebugInfoToFile(const std::string &filename)
Write out some debug information to a ROOT file with the given name.
float getMaximumY() const
Return the maximum value in y direction.
SimpleBoxDivisionHoughTree(float maximumX, float maximumY, Width< 0 > overlapX=0, Width< 1 > overlapY=0)
Constructor using the given maximal level.
BoxDivisionHoughTree< AHitPointerType, typename AHitDecisionAlgorithm::HoughBox, divisionX, divisionY > Super
float getMaximumX() const
Return the maximum value in x direction.
void fillWalk(AItemInDomainMeasure &weightItemInDomain, AIsLeafPredicate &isLeaf)
Walk through the children and fill them if necessary until isLeaf returns true.
Class representing a three dimensional reconstructed hit.
Abstract base class for different kinds of events.