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