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 // cppcheck-suppress unreadVariable
74 lowerX = node->getLowerX();
75 // cppcheck-suppress unreadVariable
76 upperX = node->getUpperX();
77 // cppcheck-suppress unreadVariable
78 lowerY = node->getLowerY();
79 // cppcheck-suppress unreadVariable
80 upperY = node->getUpperY();
81 // cppcheck-suppress unreadVariable
82 weight = node->getWeight();
83 // cppcheck-suppress unreadVariable
84 level = node->getLevel();
85
86 weightTTree.Fill();
87
88 // Always return true, as we want to access every node
89 return true;
90 };
91 Super::getTree()->walk(walker);
92
93 weightTTree.Write();
94 openedRootFile.Write();
95 openedRootFile.Close();
96 }
97
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 xMean = (node.getLowerX() + node.getUpperX()) / 2.0; //Z0 or Z1
134 const double yMean = (node.getLowerY() + node.getUpperY()) / 2.0; //tanLambda or Z2
135 const double xLow = node.getLowerX();
136 const double yLow = node.getLowerY();
137 const double xHigh = node.getUpperX();
138 const double yHigh = node.getUpperY();
139
140 TF1* candidateLL = new TF1("candLL", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
141 TF1* candidateLH = new TF1("candLH", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
142 TF1* candidateHL = new TF1("candHL", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
143 TF1* candidateHH = new TF1("candHH", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
144 TF1* candidateMean = new TF1("candMean", AInBoxAlgorithm::BoxAlgorithm::debugLine(), 0, 120);
145
146 candidateLL->SetParameters(xLow, yLow);
147 candidateLH->SetParameters(xLow, yHigh);
148 candidateHL->SetParameters(xHigh, yLow);
149 candidateHH->SetParameters(xHigh, yHigh);
150 candidateMean->SetParameters(xMean, yMean);
151
152 candidateLL->SetLineColor(9);
153 candidateLH->SetLineColor(30);
154 candidateHL->SetLineColor(46);
155 candidateHH->SetLineColor(41);
156 candidateMean->SetLineColor(2);
157
158 candidateLL->Draw("same");
159 candidateHL->Draw("same");
160 candidateLH->Draw("same");
161 candidateHH->Draw("same");
162 candidateMean->Draw("same");
163 canv.SaveAs(Form("CDCRLHits_%i.png", nevent));
164 nevent++;
165 }
166
167 private:
172 void fillAll()
173 {
174 AInBoxAlgorithm inBoxAlgorithm;
175
176 auto isLeaf = [this](typename Super::Node * node) {
177 return (node->getLevel() > this->getMaxLevel());
178 };
179
180 this->getTree()->fillWalk(inBoxAlgorithm, isLeaf);
181 }
182 };
183 }
185}
double R
typedef autogenerated by FFTW
A convenience class for adding debug information to a Simple Hough Tree.
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.