TrdMCClusterR Fit Classifier
AMSTrdMCTrack.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "TRDConstants.h"
4 #include "EventGenTRDConsts.h"
5 
6 #include <TGraph2D.h>
7 #include <TH3D.h>
8 
9 #include <cmath>
10 #include <vector>
11 #include <iostream>
12 
13 
14 namespace AMSTrdMCTrack
15 {
16  //______________________________________________________________________________________
18  {
19  X,
20  Y,
21  Z
22  };
23 
24 
25  //______________________________________________________________________________________
26  struct Cluster
27  {
28  double x;
29  double y;
30  double z;
31  };
32 
33 
34  //______________________________________________________________________________________
36  {
37  double x;
38  double y;
39  double z;
40  int Layer;
41  int Ladder;
42  int Tube;
43  double Edep;
44  };
45 
46 
47  //______________________________________________________________________________________
48  struct Track
49  {
50  int trkID;
51  int g3PID;
52  std::vector<Cluster> clusters;
53  };
54 
55 
56  //______________________________________________________________________________________
57  struct TRDTrack
58  {
59  int trkID;
60  int g3PID;
61  std::vector<TRDHitCluster> clusters;
62  };
63 
64 
65  //______________________________________________________________________________________
66  template <typename T>
67  double GetDistance(const T& P1, const T& P2)
68  {
70  return std::sqrt((P2.x - P1.x) * (P2.x - P1.x) +
71  (P2.y - P1.y) * (P2.y - P1.y) +
72  (P2.z - P1.z) * (P2.z - P1.z));
73  }
74 
75 
76  //______________________________________________________________________________________
77  bool IsClusterInsideTRD(const TH2F * h2D_TRDMap_XZ,
78  const TH2F * h2D_TRDMap_YZ,
79  const TH2F * h2D_TRDMap_XY,
80  double x,
81  double y,
82  double z)
83  {
85  static TH2D * histogramXZ = nullptr;
86  static TH2D * histogramYZ = nullptr;
87 
89  if (!histogramXZ || !histogramYZ)
90  {
93  std::cerr<<"\n\n[INFO] Static histogramXZ and histogramYZ were created in AMSTrdMCTrack::IsClusterInsideTRD().\n";
94  }
95 
97  for (int x_bin = 1; x_bin <= 18; ++x_bin) {
98  for (int z_bin = 1; z_bin <= 20; ++z_bin) {
99  histogramXZ->SetBinContent(x_bin, z_bin, 0);
100  if (4 < z_bin && z_bin <= 16)
101  histogramXZ->SetBinContent(x_bin, z_bin, 1);
102  if ((x_bin == 1 || x_bin == 18) && z_bin <= 12)
103  histogramXZ->SetBinContent(x_bin, z_bin, 0);
104  }
105  }
106 
108  for (int y_bin = 1; y_bin <= 18; ++y_bin) {
109  for (int z_bin = 1; z_bin <= 20; ++z_bin) {
110  histogramYZ->SetBinContent(y_bin, z_bin, 0);
111  if (z_bin <= 4 || z_bin > 16)
112  histogramYZ->SetBinContent(y_bin, z_bin, 1);
113  if ((y_bin <= 2 || y_bin >= 17) && z_bin <= 4)
114  histogramYZ->SetBinContent(y_bin, z_bin, 0);
115  }
116  }
117 
118 
120  int bin_XZ = histogramXZ->FindBin(x, z);
121  if (histogramXZ->GetBinContent(bin_XZ) <= 0)
122  {
123  // return false; /// this isn't working right now
124  }
125 
127  int bin_YZ = histogramYZ->FindBin(y, z);
128  if (histogramYZ->GetBinContent(bin_YZ) <= 0)
129  {
130  // return false; /// this isn't working right now
131  }
132 
133 
134 
135 
137  if (!h2D_TRDMap_XZ || !h2D_TRDMap_YZ || !h2D_TRDMap_XY)
138  {
139  std::cerr << "\n\n[ERROR]: Unable to open XZ, YZ and XY histograms.\n\n";
140  throw std::runtime_error("\n\nh2D_TRDMap histograms not found\n\n");
141  }
142 
144  int bin_XY = const_cast<TH2F*>(h2D_TRDMap_XY)->FindBin(x, y);
145  if (h2D_TRDMap_XY->GetBinContent(bin_XY) <= 0)
146  {
147  return false;
148  }
149 
151  bin_XZ = const_cast<TH2F*>(h2D_TRDMap_XZ)->FindBin(x, z);
152  if (h2D_TRDMap_XZ->GetBinContent(bin_XZ) <= 0)
153  {
154  return false;
155  }
156 
158  bin_YZ = const_cast<TH2F*>(h2D_TRDMap_YZ)->FindBin(y, z);
159  if (h2D_TRDMap_YZ->GetBinContent(bin_YZ) <= 0)
160  {
161  return false;
162  }
163 
165  return true;
166  }
167 
168 
169  //______________________________________________________________________________________
170  void printTRDTrackInfo(const std::vector<TRDTrack>& vTracks)
171  {
172  for (const auto& track : vTracks)
173  {
174  printf("\ntrkID: %5d, g3PID: %5d", track.trkID, track.g3PID);
175 
176  for (const auto& cluster : track.clusters)
177  printf("\n (x, y, z, Edep): %8.3f, %8.3f, %8.3f, %8.4f | Estimated (Layer, Ladder): %5d, %5d.", cluster.x, cluster.y, cluster.z, cluster.Edep, cluster.Layer, cluster.Ladder);
178  }
179  }
180 
181 
182  //______________________________________________________________________________________
183  std::vector<double> GetAllPosValues(const std::vector<Track>& allTracks, Coordinate coord)
184  {
185  std::vector<double> allValues;
186 
187  for (const Track& track : allTracks)
188  {
189  for (const Cluster& cluster : track.clusters)
190  {
191  switch (coord)
192  {
193  case X:
194  allValues.push_back(cluster.x);
195  break;
196  case Y:
197  allValues.push_back(cluster.y);
198  break;
199  case Z:
200  allValues.push_back(cluster.z);
201  break;
202  }
203  }
204  }
205 
206  return allValues;
207  }
208 
209 
210  //______________________________________________________________________________________
211  std::vector<double> GetTrkPosValues(const Track& track, Coordinate coord)
212  {
213  std::vector<double> values;
214 
215  for (const Cluster& cluster : track.clusters) {
216  switch (coord) {
217  case X:
218  values.push_back(cluster.x);
219  break;
220  case Y:
221  values.push_back(cluster.y);
222  break;
223  case Z:
224  values.push_back(cluster.z);
225  break;
226  }
227  }
228 
229  return values;
230  }
231 
232 
235  {
237 
238  TGraph2D *graph = new TGraph2D();
239  for (const auto &cluster : track.clusters)
240  graph->SetPoint(graph->GetN(), cluster.x, cluster.y, cluster.z);
241 
242  graph->SetMarkerColor(kRed); // Set cluster color to red
243  graph->SetMarkerStyle(20); // Set marker style
244  return graph;
245  }
246 
247 
250  {
252 
254  TH3D* hist = new TH3D("clustersHist", "Clusters;X;Y;Z", 100, TRD_XYMIN, TRD_XYMAX, 100, TRD_XYMIN, TRD_XYMAX, nZBins, TRD_ZMIN, TRD_ZMAX);
255 
257  for (const AMSTrdMCTrack::Cluster &cluster : track.clusters)
258  hist->Fill(cluster.x, cluster.y, cluster.z);
259 
260  return hist;
261  }
262 }
const int TRD_ZMAX
for plotting TH2Ds
Definition: TRDConstants.h:4
const int TRD_XYMAX
Definition: TRDConstants.h:8
const int TRD_ZMIN
cm
Definition: TRDConstants.h:5
const int nZBins
cm
Definition: TRDConstants.h:6
const int TRD_XYMIN
cm
Definition: TRDConstants.h:9
Definition: AMSTrdMCTrack.h:15
TGraph2D * SetTrackClustersToGraph(const AMSTrdMCTrack::Track &track)
Definition: AMSTrdMCTrack.h:234
Coordinate
Definition: AMSTrdMCTrack.h:18
@ Z
Definition: AMSTrdMCTrack.h:21
@ X
Definition: AMSTrdMCTrack.h:19
@ Y
Definition: AMSTrdMCTrack.h:20
double GetDistance(const T &P1, const T &P2)
Definition: AMSTrdMCTrack.h:67
std::vector< double > GetTrkPosValues(const Track &track, Coordinate coord)
Definition: AMSTrdMCTrack.h:211
void printTRDTrackInfo(const std::vector< TRDTrack > &vTracks)
Definition: AMSTrdMCTrack.h:170
TH3D * SetTrackClustersInTH3D(const AMSTrdMCTrack::Track &track)
Definition: AMSTrdMCTrack.h:249
bool IsClusterInsideTRD(const TH2F *h2D_TRDMap_XZ, const TH2F *h2D_TRDMap_YZ, const TH2F *h2D_TRDMap_XY, double x, double y, double z)
Definition: AMSTrdMCTrack.h:77
std::vector< double > GetAllPosValues(const std::vector< Track > &allTracks, Coordinate coord)
Definition: AMSTrdMCTrack.h:183
const double SIM_TRD_ZMIN
Definition: EventGenTRDConsts.h:28
const double SIM_TRD_YMAX
Definition: EventGenTRDConsts.h:27
const double SIM_TRD_YMIN
Definition: EventGenTRDConsts.h:26
const double SIM_TRD_XMAX
Definition: EventGenTRDConsts.h:25
const double SIM_TRD_ZMAX
Definition: EventGenTRDConsts.h:29
const double SIM_TRD_XMIN
Angle of track from the vertical Z-axis in radians. | (1.0 rad ~ 57 degrees) (1.3 rad ~ 75 degrees)
Definition: EventGenTRDConsts.h:24
Definition: AMSTrdMCTrack.h:27
double y
Definition: AMSTrdMCTrack.h:29
double z
Definition: AMSTrdMCTrack.h:30
double x
Definition: AMSTrdMCTrack.h:28
Definition: AMSTrdMCTrack.h:36
int Tube
Definition: AMSTrdMCTrack.h:42
int Ladder
Definition: AMSTrdMCTrack.h:41
double z
Definition: AMSTrdMCTrack.h:39
int Layer
Definition: AMSTrdMCTrack.h:40
double y
Definition: AMSTrdMCTrack.h:38
double x
Definition: AMSTrdMCTrack.h:37
double Edep
Definition: AMSTrdMCTrack.h:43
Definition: AMSTrdMCTrack.h:58
std::vector< TRDHitCluster > clusters
Definition: AMSTrdMCTrack.h:61
int g3PID
Definition: AMSTrdMCTrack.h:60
int trkID
Definition: AMSTrdMCTrack.h:59
Definition: AMSTrdMCTrack.h:49
int trkID
Definition: AMSTrdMCTrack.h:50
std::vector< Cluster > clusters
Definition: AMSTrdMCTrack.h:52
int g3PID
Definition: AMSTrdMCTrack.h:51