PandaRoot
PndSttCellTrackletGenerator.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 /*
14  * PndSttCellTrackletGenerator.h
15  *
16  * Created on: Jun 13, 2014
17  * Author: schumann
18  */
19 
20 #ifndef PNDSTTCELLTRACKLETGENERATOR_H_
21 #define PNDSTTCELLTRACKLETGENERATOR_H_
22 
24 #include "PndTrackCand.h"
25 #include "PndRiemannTrack.h"
26 #include "PndTrack.h"
27 #include "FairLink.h"
28 #include "MacrosForGPUComputing.h"
29 
30 class PndSttStrawMap;
31 class FairHit;
32 class PndSttSkewedHit;
33 
34 #ifdef RUNCUDA
35 extern "C" int *EvaluateAllStates(int *, int *, int, int, int *);
36 #endif
37 
38 struct TrackletInf_t {
39 
40  TrackletInf_t() : numSkewed(0), startID(0), endID(0), maxID(0), straight(false), error(0.0), numErrHits(0){};
41  std::vector<int> hitIDs; // vector<hit-indices of STTHits of the tracklet>
42  int numSkewed; // number of skewed tubes
43  int startID; // tube-ID of the first tube of the tracklet
44  int endID; // tube-ID of the final tube of the tracklet
45  int maxID; // max tube-ID of all hits of the tracklet
46  bool straight; // indicates whether the tracklet runs straight from the center to border of the STT
47  PndRiemannTrack riemannTrack; // riemannTrack of the tracklet
48  double error; // sum of squared error
49  int numErrHits; // number of hits that deviate from circle by more than radius of a straw tube
50 
51  void Print()
52  {
53  std::cout << "startId: " << startID << ", endId: " << endID << ", maxId: " << maxID << ", straight: " << straight << ", #hits: " << hitIDs.size()
54  << ", numSkewed: " << numSkewed << std::endl;
55 
56  if (riemannTrack.getNumHits() != 0) {
57  std::cout << ", RiemannTrack created error: " << error << ", #wrong hits: " << numErrHits << " ";
58  // std::cout << riemannTrack;
59  std::cout << std::endl;
60  }
61  };
62 };
63 
64 struct Combination_t {
65  std::set<int> tracklets; // status of combined tracklets
66  TrackletInf_t trackletInf; // information about the resulting tracklet
67 
68  void Print()
69  {
70  std::cout << "combined tracklets: ";
71  for (std::set<int>::iterator it = tracklets.begin(); it != tracklets.end(); ++it) {
72  std::cout << *it << ", ";
73  }
74  std::cout << std::endl;
75  trackletInf.Print();
76  }
77 };
78 
80  public:
82  : fTimeStamps(20), fVerbose(0), fBz(2.), fCalcFirstTrackletInf(false), fCalcWithCorrectedHits(false), fTUBE_RADIUS(0.5005), fUseGPU(false), fDev_tubeNeighborings(nullptr),
83  fHits(data->GetHits()), fCombinedSkewedHits(data->GetCombinedSkewedHits()), fStrawMap(data->GetStrawMap()), fMapTubeIdToHit(data->GetMapTubeIdToHit()),
84  fMapTubeIdToPos(data->GetMapTubeIdToPos()), fMapHitToFairLink(data->GetMapHitToFairLink()), fHitNeighbors(data->GetHitNeighbors()), fSeparations(data->GetSeparations())
85  {
86  }
87 
89 
90  void SetUseGPU(Bool_t val) { fUseGPU = val; }
91 
92  void SetDevTubeNeighboringsPointer(int *dev_pointer) { fDev_tubeNeighborings = dev_pointer; }
93 
94  void FindTracks();
95 
96  void SetCorrectedHits(std::map<int, FairHit *> correctedHits);
97 
98  /* For refitting all RiemanTracks with correctedHits (if available)*/
99  void RefitTracks();
100 
101  void PrintInfo();
102 
103  void SetCalcWithCorrectedHits(bool calcWithCorrectedHits = true) { fCalcWithCorrectedHits = calcWithCorrectedHits; }
104 
105  int GetNumPrimaryTracklets() { return fStartTracklets.size(); }
106 
107  /* Get TrackCands of start-tracklets (before combination)*/
108  std::vector<PndTrackCand> GetFirstTrackCands() { return fFirstTrackCand; };
109 
110  /* Get RiemannTracks before combination of tracklets*/
111  std::vector<PndRiemannTrack> GetFirstRiemannTracks() { return fFirstRiemannTrack; };
112 
113  /* Get TrackCands of combinated start-tracklets*/
114  std::vector<PndTrackCand> GetCombiTrackCands() { return fCombiTrackCand; };
115 
116  std::vector<PndTrack> GetCombiTracks() { return fCombiTrack; };
117 
118  bool CalcWithCorrectedHits() { return fCalcWithCorrectedHits; }
119 
120  /* Get RiemannTracks of combinated tracklets*/
121  std::vector<PndRiemannTrack> GetCombiRiemannTracks() { return fCombiRiemannTrack; };
122 
123  void SetCalcFirstTrackletInf(Bool_t val) { fCalcFirstTrackletInf = val; };
124 
125  void SetVerbose(Int_t val) { fVerbose = val; };
126 
127  void SetBz(Double_t val) { fBz = val; };
128 
129  std::vector<Double_t> GetTimeStamps() { return fTimeStamps; };
130 
131  private:
132  std::vector<Double_t> fTimeStamps;
133 
134  Int_t fVerbose;
135  Double_t fBz;
136  bool fCalcFirstTrackletInf;
137  bool fCalcWithCorrectedHits;
138  double fTUBE_RADIUS;
139 
140  bool fUseGPU;
141  int *fDev_tubeNeighborings;
142 
143  std::vector<FairHit *> fHits;
144  std::multimap<int, PndSttSkewedHit *> fCombinedSkewedHits; //<(inner) Tube-ID of combined stt hits of skewed layers, corresponding hit>
145 
146  const PndSttStrawMap *fStrawMap;
147  std::map<int, int> fMapTubeIdToHit;
148  std::map<int, TVector3> fMapTubeIdToPos;
149  std::map<int, FairLink> fMapHitToFairLink;
150 
151  map<int, vector<int>> fHitNeighbors;
152  map<int, vector<int>> fSeparations;
153 
154  map<int, int> fStates; // map<straw id, state id>
155  map<int, std::set<int>> fMultiStates; // map<straw id, set of neighboring state ids for straws with more than two neighbors
156 
157  map<int, TrackletInf_t> fStartTracklets; // map<state of start-tracklets (with more than 2 hits) generated by cellular automaton, TrackletInf>
158  map<int, TrackletInf_t> fShortTracklets; // set<state of tracklets with less than 3 hits>
159 
160  // for first step of trackfinding
161  std::vector<PndTrackCand> fFirstTrackCand; // for saving trackCands after the use of cellular automaton
162  std::vector<PndRiemannTrack> fFirstRiemannTrack; // for saving + plotting the riemann-tracks after the first step
163 
164  // for second step of trackfinding
165  std::vector<std::set<int>> fStateCombinations; // vector< set<state of start-tracklets that should be combined> >
166  std::vector<Combination_t> fCombinedData; // for storing combination of start-tracklets
167  std::vector<int> fTrackletsWithoutCombi; // state of tracklets that were not combined
168 
169  std::vector<PndTrackCand> fCombiTrackCand; // resulting tracks after combination of tracklets (uncombined too)
170  std::vector<PndRiemannTrack> fCombiRiemannTrack; // resulting riemanntracks
171  std::vector<PndTrack> fCombiTrack; // resulting PndTrack
172 
173  std::map<int, FairHit *> fCorrectedHits;
174 
175  /* This Method creates PndTrackCands out of the entries in fCombinedData and
176  * the not combined tracklets with more than 2 hits.*/
177  void CreatePndTrackCands();
178 
179  /* Method creates the tracklets by the means of a cellular automaton.*/
180  void GenerateTracklets();
181 
182  /* Method creates the tracklets by the means of a cellular automaton on the GPU.*/
183  void GenerateTrackletsGPU();
184 
185  /* Method update the states of each until no state change anymore.*/
186  void EvaluateState();
187 
188  /* Method update the states of tubes with more than two neighbors until no state changes anymore. */
189  void EvaluateMultiState();
190 
191  /* Method initialzises fStartTracklets with the states and trackletInf
192  * of the generated tracklets.*/
193  void InitStartTracklets();
194 
195  /* Method searches for reasonable combination of the start-tracklets with a recursive algorithm.
196  * They are stored in fCombinedData. */
197  void CombineTrackletsMultiStages();
198 
199  /* Implementation of the recursive algorithm for finding combination of the start-tracklets.*/
200  void CombineTrackletsMultiStagesRecursive(int stateToCombine, std::set<int> currentCombi);
201 
202  /* Method inserts a combination of states if not existing yet.*/
203  void InsertCombination(std::set<int> combination);
204 
205  /* Method for calculating the trackletInf for a combination of tracklets.*/
206  TrackletInf_t GetTrackletInf(std::set<int> tracklets);
207 
208  /* Method splits the start tracklets in uncombined and short tracklets*/
209  void SplitData();
210 
211  void AssignAmbiguousHits();
212 
213  /* Method adds the unassigned hits and trackCands with 1 and 2 hits to an
214  * appropriate combination (if possible).*/
215  void AddRemainingHits();
216 
217  /* Methods adds the uncared hits with 3 and 4 hit-neighbors to the best combination
218  * of tracklets. If the nearest riemann-circle is found and the distance is
219  * smaller than the radius of a tube, the hit is added.*/
220  bool AddHitToBestCombi(int hitID);
221 
222  /* Method for creating a riemannTrack out of hits.
223  * Hits of skewed tubes were ignored.*/
224  PndRiemannTrack CreateRiemannTrack(std::vector<int> hitIDs);
225 
226  std::set<std::pair<int, int>> CreatePairCombis(int firstState, std::set<int> values);
227 
228  /* Method calculates the mean squared deviation of the hits from the riemann-circle.*/
229  double CalcDeviationOfRiemannTrack(PndRiemannTrack &track);
230 
231  /* Method calculates the deviation of the hit from the riemann-circle.*/
232  double CalcDeviation(PndRiemannTrack &track, int hitID);
233 
234  /* Method counts the hits of the riemannTrack, that had a distance of more
235  * than r (radius of a straw tube) to the riemann-circle.*/
236  int GetDeviationCount(PndRiemannTrack &track);
237 
238  /* Method checks if a tubeID belongs to the end-tube of a tracklet.*/
239  bool IsEndTubeOfTracklet(int tubeID);
240 
241  ClassDef(PndSttCellTrackletGenerator, 1);
242 };
243 
244 #endif /* PNDSTTCELLTRACKLETGENERATOR_H_ */
void SetCalcWithCorrectedHits(bool calcWithCorrectedHits=true)
unsigned int getNumHits()
void SetDevTubeNeighboringsPointer(int *dev_pointer)
std::vector< PndTrackCand > GetFirstTrackCands()
std::vector< PndRiemannTrack > GetCombiRiemannTracks()
int * EvaluateAllStates(int *, int *, int, int, int *)
std::vector< Double_t > GetTimeStamps()
std::vector< int > hitIDs
PndSttCellTrackletGenerator(const PndSttCellTrackFinderData *data)
std::vector< PndTrackCand > GetCombiTrackCands()
PndRiemannTrack riemannTrack
std::vector< PndRiemannTrack > GetFirstRiemannTracks()
std::vector< PndTrack > GetCombiTracks()