PandaRoot
PndApolloniusTriplet.h
Go to the documentation of this file.
1 #pragma once
2 
3 #define _USE_MATH_DEFINES
4 
5 #include <math.h>
6 #include <tuple>
7 
8 #include "PndSttGeometryMap.h"
9 #include "FairHit.h"
10 #include "PndSttHit.h"
11 #include "FairLogger.h"
12 #include "PndHoughApollonius.h"
14 #include "PndSttCA.h"
15 // general
16 using std::cout;
17 using std::endl;
18 
19 namespace PndApollonius {
20 
22 struct Thresholds {
25 
28 
33  double fDistanceThresholdGEM = 1.;
34 
35  double fSTTArcLengthCut = 26.;
37  double fMVDArcLengthCutMid = 7.;
38  double fMVDArcLengthCutFar = 10.;
39 };
40 
42 struct Triplet {
43  std::array<PndSttHit *, 3> fTripletHits;
44  friend std::ostream &operator<<(std::ostream &output, const Triplet &t)
45 
46  {
47  output << "Triplet: ";
48  for (auto hit : t.fTripletHits)
49  output << hit->GetTubeID() << "(" << hit->GetX() << "," << hit->GetY() << ") /";
50  output << std::endl;
51 
52  return output;
53  }
54 };
55 
58 
59  enum detID { MVDpixel, MVDstrip, STT, GEM, NOTDEFINED };
60  std::vector<std::string> detID_Names{"MVD_Pixel", "MVD_Strip", "STT", "GEM", "NOTDEFINED"};
61 
64 
69  TripletSolution(TVector3 track) : fTrack(track){};
70 
76  void AddHits(detID detector, std::vector<FairHit *> data)
77  {
78  fHits[detector] = data;
79  fAllHits.insert(fAllHits.end(), data.begin(), data.end());
80  }
81 
86  void AddHits(std::vector<PndSttHit *> sttHits)
87  {
88  fHits[STT].insert(fHits[STT].end(), sttHits.begin(), sttHits.end());
89  fAllHits.insert(fAllHits.end(), sttHits.begin(), sttHits.end());
90  }
91 
97  void AddHit(detID detector, FairHit *data)
98  {
99  if (fHits.count(detector) == 0) {
100  fHits[detector];
101  }
102  if (std::find(fHits[detector].begin(), fHits[detector].end(), data) == fHits[detector].end()) { // add only if hit is not in dataset
103  fHits[detector].push_back(data);
104  fAllHits.push_back(data);
105  }
106  }
107 
109  int GetNHits() { return fHits[MVDpixel].size() + fHits[MVDstrip].size() + fHits[STT].size() + fHits[GEM].size(); }
110 
116  TVector2 HitOnTrack(FairHit *hit) { return TVector2(hit->GetX() - fTrack.X(), hit->GetY() - fTrack.Y()); }
117 
119  void IsClockwise();
120 
126  void SortHits(TVector2 &firstHit, detID detector);
127 
133  void SortStt(PndSttGeometryMap *fGeometryMap);
134 
141  FairHit *GetFirstHit(PndSttGeometryMap *fGeometryMap);
142 
147  void SortAllHits(PndSttGeometryMap *fGeometryMap);
148 
154  bool IsReasonableHit(FairHit *CurrentHit, FairHit *PriviousHit);
155 
156  friend std::ostream &operator<<(std::ostream &output, const TripletSolution &t)
157  {
158  output << "Track x/y/r " << t.fTrack.X() << "/" << t.fTrack.Y() << "/" << t.fTrack.Z() << " ";
159  if (t.fTriplet.fTripletHits[0] != nullptr) {
160  output << " trip: " << t.fTriplet.fTripletHits[0]->GetTubeID() << "/" << t.fTriplet.fTripletHits[1]->GetTubeID() << "/" << t.fTriplet.fTripletHits[2]->GetTubeID() << " ";
161  }
162  if (t.fHits.count(TripletSolution::detID::MVDpixel) > 0) {
163  output << t.detID_Names.at(TripletSolution::detID::MVDpixel) << " : ";
164  for (auto hit : t.fHits.at(TripletSolution::detID::MVDpixel)) {
165  output << hit->GetEntryNr() << "/";
166  }
167  output << " ";
168  }
169  if (t.fHits.count(TripletSolution::detID::MVDstrip) > 0) {
170  output << t.detID_Names.at(TripletSolution::detID::MVDstrip) << " : ";
171  for (auto hit : t.fHits.at(TripletSolution::detID::MVDstrip)) {
172  output << hit->GetEntryNr() << "/";
173  }
174  output << " ";
175  }
176  if (t.fHits.count(TripletSolution::detID::STT) > 0) {
177  output << t.detID_Names.at(TripletSolution::detID::STT) << " : ";
178  for (auto hit : t.fHits.at(TripletSolution::detID::STT)) {
179  PndSttHit *myHit = static_cast<PndSttHit *>(hit);
180  output << myHit->GetTubeID() << "/";
181  }
182  output << " ";
183  }
184  if (t.fHits.count(TripletSolution::detID::GEM) > 0) {
185  output << t.detID_Names.at(TripletSolution::detID::GEM) << " : ";
186  for (auto hit : t.fHits.at(TripletSolution::detID::GEM)) {
187  output << hit->GetEntryNr() << "/";
188  }
189  output << " ";
190  }
191 
192  output << "MSD: " << t.fMeanSquare;
193  return output;
194  }
195 
196  Triplet fTriplet{nullptr, nullptr, nullptr}; //< triplet used to create solution
197  TVector3 fTrack; //< circle coordinates of track in x,y,r in [cm]
198  std::map<detID, std::vector<FairHit *>> fHits;
199  std::vector<FairHit *> fAllHits;
200  double fMeanSquare = 1000000.;
201  bool fClockwise = true;
202 };
203 
206  std::vector<PndSttHit *> fFirstRow;
207  std::vector<PndSttHit *> fMidRow;
208  std::vector<PndSttHit *> fLastRow;
209 
211  {
212  fFirstRow.insert(fFirstRow.end(), right.fFirstRow.begin(), right.fFirstRow.end());
213  fMidRow.insert(fMidRow.end(), right.fMidRow.begin(), right.fMidRow.end());
214  fLastRow.insert(fLastRow.end(), right.fLastRow.begin(), right.fLastRow.end());
215 
216  return *this;
217  }
218 
219  friend std::ostream &operator<<(std::ostream &output, const TripletValues &t)
220  {
221  output << "FirstRow: ";
222  std::for_each(t.fFirstRow.begin(), t.fFirstRow.end(), [](PndSttHit *hit) { std::cout << hit->GetTubeID() << "(" << hit->GetX() << "," << hit->GetY() << ") /"; });
223  output << std::endl;
224  output << "MidRow: ";
225  std::for_each(t.fMidRow.begin(), t.fMidRow.end(), [](PndSttHit *hit) { std::cout << hit->GetTubeID() << "(" << hit->GetX() << "," << hit->GetY() << ") /"; });
226  output << std::endl;
227  output << "LastRow: ";
228  std::for_each(t.fLastRow.begin(), t.fLastRow.end(), [](PndSttHit *hit) { std::cout << hit->GetTubeID() << "(" << hit->GetX() << "," << hit->GetY() << ") /"; });
229  output << std::endl;
230 
231  return output;
232  }
233 };
234 
237  std::map<int, PndSttHit *> fMapCAToMidTube;
238  std::map<int, PndSttHit *> fMapCAToOuterTube;
239  std::map<PndSttHit *, int> fMapInnerTubeToCA;
240  std::map<PndSttHit *, int> fMapMidTubeToCA;
241 
242  void Reset()
243  {
244  fMapCAToMidTube.clear();
245  fMapCAToOuterTube.clear();
246  fMapInnerTubeToCA.clear();
247  fMapMidTubeToCA.clear();
248  }
249 };
250 
261  std::map<int, std::vector<PndSttHit *>> GetAllTubesByRow(std::vector<PndSttHit *> hits, PndSttGeometryMap *fGeometryMap, int &fAllHitsCounter);
262 
273  std::map<int, std::vector<std::vector<PndSttHit *>>>
274  GetTubeStructure(std::vector<PndSttHit *> hits, PndSttGeometryMap *fGeometryMap, int &fAllHitsCounter, bool &fIsStrongCurling);
275 
282  ReductionMaps CreateMaps(TripletValues &triplets, std::map<FairLink, int> &fMapHitstoCATracklet);
283 
296  std::vector<Triplet> ReduceCombinatorics(TripletValues &triplets, std::map<FairLink, int> &fMapHitstoCATracklet, TClonesArray *sttHits, PndSttCA *fCATrackFinder,
297  PndSttGeometryMap *fGeometryMap, double &fMinDistance, bool &fWithCombiReduction);
298 
306  bool IsTripletUsed(std::vector<TripletSolution> &solutions, Triplet &triplet);
307 
316  std::vector<TripletSolution> GenerateTripletTracks(Triplet triplet, std::vector<PndSttHit *> &sttHits, PndSttGeometryMap *fGeometryMap);
317 
327  std::vector<double> calcIntersectionPointCircleLine(std::vector<double> circle, double m, double b, double Ax);
328 
338  TripletSolution FindHitsCloseToCircle(std::vector<PndSttHit *> &sttHits, TVector3 &circle, double &fDistanceThresholdSTTFar, PndSttGeometryMap *fGeometryMap);
339 
346  double MeanSquareDistance(TripletSolution &solution);
347 
355  double DistanceCirclePoint(TVector3 &circle, FairHit *hit);
356 
364  double DistanceCircleSttHit(TVector3 &circle, PndSttHit *sttHit);
365 
374  double DistanceCircleSttHit(TVector3 &circle, PndSttHit *sttHit, double &sqaredDistance);
375 
384  double DistanceLineSttHit(TVector3 &circle, PndSttHit *sttHit, double &squaredDistance) { return sqrt(squaredDistance); };
385 
393  double DistanceLineSttHit(TVector3 &circle, PndSttHit *sttHit);
394 
402  double SquaredDistanceLineSttHit(TVector3 &circle, PndSttHit *sttHit);
403 
411  double DistanceLinePoint(TVector3 &circle, FairHit *hit);
412 
419  void CheckContinuitySolutions(std::vector<TripletSolution> &solutions, PndSttGeometryMap *fGeometryMap);
420 
428  bool IsContinuous(TripletSolution &solution, PndSttGeometryMap *fGeometryMap);
429 
438  void AddOtherDetectors(vector<TripletSolution> &solutions, PndSttStrawMap *fStrawMap, std::map<TString, TClonesArray *> &fBranchMap, TString sttname);
439 
445  std::vector<TripletSolution> FindBestSolutions(std::vector<TripletSolution> &solutions);
446 
454  std::vector<TripletSolution> CheckCombinedSolutions(std::vector<TripletSolution> &solutions, int nExpectedTracks);
455 
463  std::vector<TripletSolution> CheckSolutions(std::vector<TripletSolution> &solutions, std::vector<std::vector<int>> combinations);
464 
472  std::vector<int> GetUniqueTubeIDs(std::vector<TripletSolution> &solutions, std::vector<int> combinations);
473 
481  std::vector<std::vector<int>> GetKOutOfN(int k, int n);
482 
489  std::vector<TripletSolution> CombineIdenticalSolutions(std::vector<TripletSolution> &solutions);
490 
497  bool ContainsTriplet(Triplet &triplet, TripletSolution &solution);
498 
509  std::vector<PndSttHit *> TubeReduction(std::vector<std::pair<int, int>> &Rows, std::map<int, std::vector<std::vector<PndSttHit *>>> &tubeStructure,
510  std::map<FairLink, int> &fMapHitstoCATracklet, int position);
516  std::map<FairLink, int> GetHitsToCAMap(PndSttCA *fCATrackFinder);
517 
526  double CalcRatioSameHits(TripletSolution &sol, std::vector<TripletSolution> &AlreadyFoundSolutions);
534  std::vector<TripletSolution> CombineIdenticalSolutionsFinal(std::vector<TripletSolution> &solutions, Double_t ratioOfSameHits = 0.6);
535 
542  PndTrack FromTripletSolutionToPndTrack(PndApollonius::TripletSolution &sol, Double_t B);
543 
551  PndTrack FromTripletSolutionToPndTrack(PndApollonius::TripletSolution &sol, Double_t B, PndTrackCand &cand);
552 };
553 
554 } // namespace PndApollonius
555 
std::map< int, PndSttHit * > fMapCAToMidTube
Int_t GetTubeID() const
Definition: PndSttHit.h:71
std::array< PndSttHit *, 3 > fTripletHits
friend std::ostream & operator<<(std::ostream &output, const TripletSolution &t)
__m128 m
Definition: P4_F32vec4.h:26
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:28
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...