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