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