Belle II Software  release-08-01-10
TrackInspector.cc
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 #include <tracking/trackFindingCDC/findlets/minimal/TrackInspector.h>
9 
10 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
11 
12 #include <framework/core/ModuleParamList.templateDetails.h>
13 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
14 
15 #include <TMultiGraph.h>
16 #include <TGraph.h>
17 #include <TCanvas.h>
18 #include <TAxis.h>
19 #include <vector>
20 
21 using namespace Belle2;
22 using namespace TrackFindingCDC;
23 
25 {
26  return "Findlet for printing out CDCtracks";
27 }
28 
29 void TrackInspector::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
30 {
31  moduleParamList->addParameter(prefixed(prefix, "debugDraw"),
33  "Draw found hit positions of the track",
35 }
36 
37 void TrackInspector::apply(std::vector<CDCTrack>& tracks)
38 {
39  removeIncompleteTracks(tracks);
40  static int nevent(0);
41  if (tracks.size() == 0) {
42  nevent++;
43  return; //Nothing to draw
44  }
45  if (not m_param_debugDraw) return; //Nothing to draw
46  TCanvas canvA("axialCanvas", "CDC axial hits in an event", 0, 0, 1440, 1080);
47  TCanvas canvS("stereoCanvas", "CDC stereo hits in an event", 0, 0, 1440, 1080);
48  TMultiGraph* mgA = new TMultiGraph("axialTracks", "CDC axial tracks in the event;X, cm;Y, cm");
49  TMultiGraph* mgS = new TMultiGraph("stereoTracks", "CDC stereo tracks in the event;Z, cm;R, cm");
50  for (CDCTrack& track : tracks) {
51  TGraph* grA = new TGraph();
52  TGraph* grS = new TGraph();
53  grA->SetLineWidth(2);
54  grA->SetLineColor(9);
55  grS->SetLineWidth(2);
56  grS->SetLineColor(9);
57  for (CDCRecoHit3D& hit : track) {
58  Vector3D pos = hit.getRecoPos3D();
59  const double R = std::sqrt(pos.x() * pos.x() + pos.y() * pos.y());
60  const double X = pos.x();
61  const double Y = pos.y();
62  const double Z = pos.z();
63  if (Z == 0 and hit.isAxial()) { // axial hits have no z information
64  grA->SetPoint(grA->GetN(), X, Y);
65  } else {
66  grS->SetPoint(grS->GetN(), Z, R);
67  }
68  }
69  mgA->Add(grA);
70  mgS->Add(grS);
71  }
72  canvA.cd();
73  mgA->Draw("APL*");
74  canvS.cd();
75  mgS->Draw("APL*");
76  canvA.Update();
77  canvS.Update();
78  if (mgA->GetXaxis()) {
79  mgA->GetXaxis()->SetLimits(-120, 120);
80  mgA->GetYaxis()->SetRangeUser(-120, 120);
81  canvA.SaveAs(Form("CDCaxialTracks_%i.png", nevent));
82  }
83  if (mgS->GetXaxis()) {
84  mgS->GetXaxis()->SetLimits(-180, 180);
85  mgS->GetYaxis()->SetRangeUser(0, 120);
86  canvS.SaveAs(Form("CDCstereoTracks_%i.png", nevent));
87  }
88  nevent++;
89 }
90 
91 void TrackInspector::removeIncompleteTracks(std::vector<CDCTrack>& tracks)
92 {
93  for (auto it = tracks.begin(); it != tracks.end();) {
94  bool stereoHitsPresent =
95  false; //If stereo hit matcher can't find more hits than its threshold, it doesn't add any, but keeps the track
96  for (CDCRecoHit3D& hit : *it) {
97  if (not hit.isAxial()) stereoHitsPresent = true;
98  }
99  if (not stereoHitsPresent) {
100  it = tracks.erase(it); //TODO mask hits or something?
101  } else {
102  ++it;
103  }
104  }
105 }
double R
typedef autogenerated by FFTW
The Module parameter list class.
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:52
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:41
void apply(std::vector< CDCTrack > &tracks) final
Print the tracks.
std::string getDescription() final
Short description of the findlet.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Access parameters.
void removeIncompleteTracks(std::vector< CDCTrack > &tracks)
Remove tracks with no stereo hits.
bool m_param_debugDraw
Flag to draw the CDCTrack (true) or not (false)
A three dimensional vector.
Definition: Vector3D.h:33
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.