PandaRoot
PndApolloniusTriplet.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 #pragma once
14 
15 #define _USE_MATH_DEFINES
16 
17 #include <math.h>
18 #include <tuple>
19 
20 #include "PndSttGeometryMap.h"
21 #include "FairHit.h"
22 #include "PndSttHit.h"
23 #include "FairLogger.h"
24 #include "PndHoughApollonius.h"
26 #include "PndSttCA.h"
27 // general
28 using std::cout;
29 using std::endl;
30 
31 namespace PndApollonius {
32 
34 struct Thresholds {
37 
40 
45  double fDistanceThresholdGEM = 1.;
46 
47  double fSTTArcLengthCut = 26.;
49  double fMVDArcLengthCutMid = 7.;
50  double fMVDArcLengthCutFar = 10.;
51 };
52 
54 struct Triplet {
55  std::array<PndSttHit *, 3> fTripletHits;
56  friend std::ostream &operator<<(std::ostream &output, const Triplet &t)
57 
58  {
59  output << "Triplet: ";
60  for (auto hit : t.fTripletHits)
61  output << hit->GetTubeID() << "(" << hit->GetX() << "," << hit->GetY() << ") /";
62  output << std::endl;
63 
64  return output;
65  }
66 };
67 
70 
71  enum detID { MVDpixel, MVDstrip, STT, GEM, NOTDEFINED };
72  std::vector<std::string> detID_Names{"MVD_Pixel", "MVD_Strip", "STT", "GEM", "NOTDEFINED"};
73 
76 
81  TripletSolution(TVector3 track) : fTrack(track){};
82 
88  void AddHits(detID detector, std::vector<FairHit *> data)
89  {
90  fHits[detector] = data;
91  fAllHits.insert(fAllHits.end(), data.begin(), data.end());
92  }
93 
98  void AddHits(std::vector<PndSttHit *> sttHits)
99  {
100  fHits[STT].insert(fHits[STT].end(), sttHits.begin(), sttHits.end());
101  fAllHits.insert(fAllHits.end(), sttHits.begin(), sttHits.end());
102  }
103 
109  void AddHit(detID detector, FairHit *data)
110  {
111  if (fHits.count(detector) == 0) {
112  fHits[detector];
113  }
114  if (std::find(fHits[detector].begin(), fHits[detector].end(), data) == fHits[detector].end()) { // add only if hit is not in dataset
115  fHits[detector].push_back(data);
116  fAllHits.push_back(data);
117  }
118  }
119 
121  int GetNHits() { return fHits[MVDpixel].size() + fHits[MVDstrip].size() + fHits[STT].size() + fHits[GEM].size(); }
122 
128  TVector2 HitOnTrack(FairHit *hit) { return TVector2(hit->GetX() - fTrack.X(), hit->GetY() - fTrack.Y()); }
129 
131  void IsClockwise();
132 
138  void SortHits(TVector2 &firstHit, detID detector);
139 
145  void SortStt(PndSttGeometryMap *fGeometryMap);
146 
153  FairHit *GetFirstHit(PndSttGeometryMap *fGeometryMap);
154 
159  void SortAllHits(PndSttGeometryMap *fGeometryMap);
160 
166  bool IsReasonableHit(FairHit *CurrentHit, FairHit *PriviousHit);
167 
168  friend std::ostream &operator<<(std::ostream &output, const TripletSolution &t)
169  {
170  output << "Track x/y/r " << t.fTrack.X() << "/" << t.fTrack.Y() << "/" << t.fTrack.Z() << " ";
171  if (t.fTriplet.fTripletHits[0] != nullptr) {
172  output << " trip: " << t.fTriplet.fTripletHits[0]->GetTubeID() << "/" << t.fTriplet.fTripletHits[1]->GetTubeID() << "/" << t.fTriplet.fTripletHits[2]->GetTubeID() << " ";
173  }
174  if (t.fHits.count(TripletSolution::detID::MVDpixel) > 0) {
175  output << t.detID_Names.at(TripletSolution::detID::MVDpixel) << " : ";
176  for (auto hit : t.fHits.at(TripletSolution::detID::MVDpixel)) {
177  output << hit->GetEntryNr() << "/";
178  }
179  output << " ";
180  }
181  if (t.fHits.count(TripletSolution::detID::MVDstrip) > 0) {
182  output << t.detID_Names.at(TripletSolution::detID::MVDstrip) << " : ";
183  for (auto hit : t.fHits.at(TripletSolution::detID::MVDstrip)) {
184  output << hit->GetEntryNr() << "/";
185  }
186  output << " ";
187  }
188  if (t.fHits.count(TripletSolution::detID::STT) > 0) {
189  output << t.detID_Names.at(TripletSolution::detID::STT) << " : ";
190  for (auto hit : t.fHits.at(TripletSolution::detID::STT)) {
191  PndSttHit *myHit = static_cast<PndSttHit *>(hit);
192  output << myHit->GetTubeID() << "/";
193  }
194  output << " ";
195  }
196  if (t.fHits.count(TripletSolution::detID::GEM) > 0) {
197  output << t.detID_Names.at(TripletSolution::detID::GEM) << " : ";
198  for (auto hit : t.fHits.at(TripletSolution::detID::GEM)) {
199  output << hit->GetEntryNr() << "/";
200  }
201  output << " ";
202  }
203 
204  output << "MSD: " << t.fMeanSquare;
205  return output;
206  }
207 
208  Triplet fTriplet{nullptr, nullptr, nullptr}; //< triplet used to create solution
209  TVector3 fTrack; //< circle coordinates of track in x,y,r in [cm]
210  std::map<detID, std::vector<FairHit *>> fHits;
211  std::vector<FairHit *> fAllHits;
212  double fMeanSquare = 1000000.;
213  bool fClockwise = true;
214 };
215 
218  std::vector<PndSttHit *> fFirstRow;
219  std::vector<PndSttHit *> fMidRow;
220  std::vector<PndSttHit *> fLastRow;
221 
223  {
224  fFirstRow.insert(fFirstRow.end(), right.fFirstRow.begin(), right.fFirstRow.end());
225  fMidRow.insert(fMidRow.end(), right.fMidRow.begin(), right.fMidRow.end());
226  fLastRow.insert(fLastRow.end(), right.fLastRow.begin(), right.fLastRow.end());
227 
228  return *this;
229  }
230 
231  friend std::ostream &operator<<(std::ostream &output, const TripletValues &t)
232  {
233  output << "FirstRow: ";
234  std::for_each(t.fFirstRow.begin(), t.fFirstRow.end(), [](PndSttHit *hit) { std::cout << hit->GetTubeID() << "(" << hit->GetX() << "," << hit->GetY() << ") /"; });
235  output << std::endl;
236  output << "MidRow: ";
237  std::for_each(t.fMidRow.begin(), t.fMidRow.end(), [](PndSttHit *hit) { std::cout << hit->GetTubeID() << "(" << hit->GetX() << "," << hit->GetY() << ") /"; });
238  output << std::endl;
239  output << "LastRow: ";
240  std::for_each(t.fLastRow.begin(), t.fLastRow.end(), [](PndSttHit *hit) { std::cout << hit->GetTubeID() << "(" << hit->GetX() << "," << hit->GetY() << ") /"; });
241  output << std::endl;
242 
243  return output;
244  }
245 };
246 
249  std::map<int, PndSttHit *> fMapCAToMidTube;
250  std::map<int, PndSttHit *> fMapCAToOuterTube;
251  std::map<PndSttHit *, int> fMapInnerTubeToCA;
252  std::map<PndSttHit *, int> fMapMidTubeToCA;
253 
254  void Reset()
255  {
256  fMapCAToMidTube.clear();
257  fMapCAToOuterTube.clear();
258  fMapInnerTubeToCA.clear();
259  fMapMidTubeToCA.clear();
260  }
261 };
262 
273  std::map<int, std::vector<PndSttHit *>> GetAllTubesByRow(std::vector<PndSttHit *> hits, PndSttGeometryMap *fGeometryMap, int &fAllHitsCounter);
274 
285  std::map<int, std::vector<std::vector<PndSttHit *>>>
286  GetTubeStructure(std::vector<PndSttHit *> hits, PndSttGeometryMap *fGeometryMap, int &fAllHitsCounter, bool &fIsStrongCurling);
287 
294  ReductionMaps CreateMaps(TripletValues &triplets, std::map<FairLink, int> &fMapHitstoCATracklet);
295 
308  std::vector<Triplet> ReduceCombinatorics(TripletValues &triplets, std::map<FairLink, int> &fMapHitstoCATracklet, TClonesArray *sttHits, PndSttCA *fCATrackFinder,
309  PndSttGeometryMap *fGeometryMap, double &fMinDistance, bool &fWithCombiReduction);
310 
318  bool IsTripletUsed(std::vector<TripletSolution> &solutions, Triplet &triplet);
319 
328  std::vector<TripletSolution> GenerateTripletTracks(Triplet triplet, std::vector<PndSttHit *> &sttHits, PndSttGeometryMap *fGeometryMap);
329 
339  std::vector<double> calcIntersectionPointCircleLine(std::vector<double> circle, double m, double b, double Ax);
340 
350  TripletSolution FindHitsCloseToCircle(std::vector<PndSttHit *> &sttHits, TVector3 &circle, double &fDistanceThresholdSTTFar, PndSttGeometryMap *fGeometryMap);
351 
358  double MeanSquareDistance(TripletSolution &solution);
359 
367  double DistanceCirclePoint(TVector3 &circle, FairHit *hit);
368 
376  double DistanceCircleSttHit(TVector3 &circle, PndSttHit *sttHit);
377 
386  double DistanceCircleSttHit(TVector3 &circle, PndSttHit *sttHit, double &sqaredDistance);
387 
396  double DistanceLineSttHit(TVector3 &circle, PndSttHit *sttHit, double &squaredDistance) { return sqrt(squaredDistance); };
397 
405  double DistanceLineSttHit(TVector3 &circle, PndSttHit *sttHit);
406 
414  double SquaredDistanceLineSttHit(TVector3 &circle, PndSttHit *sttHit);
415 
423  double DistanceLinePoint(TVector3 &circle, FairHit *hit);
424 
431  void CheckContinuitySolutions(std::vector<TripletSolution> &solutions, PndSttGeometryMap *fGeometryMap);
432 
440  bool IsContinuous(TripletSolution &solution, PndSttGeometryMap *fGeometryMap);
441 
450  void AddOtherDetectors(vector<TripletSolution> &solutions, PndSttStrawMap *fStrawMap, std::map<TString, TClonesArray *> &fBranchMap, TString sttname);
451 
457  std::vector<TripletSolution> FindBestSolutions(std::vector<TripletSolution> &solutions);
458 
466  std::vector<TripletSolution> CheckCombinedSolutions(std::vector<TripletSolution> &solutions, int nExpectedTracks);
467 
475  std::vector<TripletSolution> CheckSolutions(std::vector<TripletSolution> &solutions, std::vector<std::vector<int>> combinations);
476 
484  std::vector<int> GetUniqueTubeIDs(std::vector<TripletSolution> &solutions, std::vector<int> combinations);
485 
493  std::vector<std::vector<int>> GetKOutOfN(int k, int n);
494 
501  std::vector<TripletSolution> CombineIdenticalSolutions(std::vector<TripletSolution> &solutions);
502 
509  bool ContainsTriplet(Triplet &triplet, TripletSolution &solution);
510 
521  std::vector<PndSttHit *> TubeReduction(std::vector<std::pair<int, int>> &Rows, std::map<int, std::vector<std::vector<PndSttHit *>>> &tubeStructure,
522  std::map<FairLink, int> &fMapHitstoCATracklet, int position);
528  std::map<FairLink, int> GetHitsToCAMap(PndSttCA *fCATrackFinder);
529 
538  double CalcRatioSameHits(TripletSolution &sol, std::vector<TripletSolution> &AlreadyFoundSolutions);
546  std::vector<TripletSolution> CombineIdenticalSolutionsFinal(std::vector<TripletSolution> &solutions, Double_t ratioOfSameHits = 0.6);
547 
554  PndTrack FromTripletSolutionToPndTrack(PndApollonius::TripletSolution &sol, Double_t B);
555 
563  PndTrack FromTripletSolutionToPndTrack(PndApollonius::TripletSolution &sol, Double_t B, PndTrackCand &cand);
564 };
565 
566 } // namespace PndApollonius
567 
std::map< int, PndSttHit * > fMapCAToMidTube
Int_t GetTubeID() const
Definition: PndSttHit.h:83
std::array< PndSttHit *, 3 > fTripletHits
friend std::ostream & operator<<(std::ostream &output, const TripletSolution &t)
__m128 m
Definition: P4_F32vec4.h:38
Contains all distance thresholds for different detector hits to be defined as "close to the track and...
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:40
void AddHits(detID detector, std::vector< FairHit *> data)
A vector of hits is added.
friend std::ostream & operator<<(std::ostream &output, const Triplet &t)
TripletValues & operator+=(const TripletValues &right)
A structure that defines all functions used for the Apollonius Triplet track finder.
void AddHit(detID detector, FairHit *data)
One hit of a specific subdetector is added.
A structure that defines a triplet consisting of three STT Hits.
std::map< int, PndSttHit * > fMapCAToOuterTube
friend std::ostream & operator<<(std::ostream &output, const TripletValues &t)
#define GEM
std::map< PndSttHit *, int > fMapInnerTubeToCA
TVector2 HitOnTrack(FairHit *hit)
Determins a vector from the circle center to the corresponding hit.
std::vector< PndSttHit * > fFirstRow
int GetNHits()
Returns the total number of hits in a TripletSolution.
TripletSolution(TVector3 track)
Constructor.
std::map< detID, std::vector< FairHit * > > fHits
A structure that defines a solution of a triplet (an Apollonius Circle and all hits close to the circ...
std::vector< PndSttHit * > fMidRow
void AddHits(std::vector< PndSttHit *> sttHits)
A vector of STT hits is added.
std::vector< PndSttHit * > fLastRow
A structure that defines all maps that are used to reduce to number of possible triplet combinations...
std::map< PndSttHit *, int > fMapMidTubeToCA
double DistanceLineSttHit(TVector3 &circle, PndSttHit *sttHit, double &squaredDistance)
Determines the distance between a STT Hit and a line if the squared distance between the line and hit...
std::vector< FairHit * > fAllHits
std::vector< std::string > detID_Names
A structure that defines the three sets of STT hits (inner, mid, outer STT set), that are used to com...