FairRoot/PandaRoot
PndSttCellTrackletGenerator.cxx
Go to the documentation of this file.
1 /*
2  * PndSttCellTrackletGenerator.cxx
3  *
4  * Created on: Jun 13, 2014
5  * Author: schumann
6  */
7 
9 #include "FairHit.h"
10 #include "PndSttStrawMap.h"
11 #include "PndRiemannHit.h"
12 #include "PndSttSkewedHit.h"
13 #include "TTimeStamp.h"
14 
16 
17 using namespace std;
18 
20  map<int, FairHit*> correctedHits) {
21 
22  if (fVerbose > 3)
23  cout << "PndSttCellTrackletGenerator::SetCorrectedHits" << endl;
24  fCorrectedHits.clear();
25 
26  if (correctedHits.size() != 0) {
27 
28  fCalcWithCorrectedHits = true;
29  fCorrectedHits = correctedHits;
30 
31  } else {
32  fCalcWithCorrectedHits = false;
33  }
34 
35 }
36 
38 
39  if (fVerbose > 2)
40  cout << "PndSttCellTrackletGenerator::RefitTracks()" << endl;
41 
42  fCombiRiemannTrack.clear();
43  fCombiTrack.clear();
44  fCombiTrackCand.clear();
45 
46  if (fCalcFirstTrackletInf) {
47  fFirstTrackCand.clear();
48  fFirstRiemannTrack.clear();
49 
50  for (map<int, TrackletInf_t>::iterator trackIt =
51  fStartTracklets.begin(); trackIt != fStartTracklets.end();
52  ++trackIt) {
53 
54  TrackletInf_t trackletInf = trackIt->second;
55  // calc riemannTrack
56  PndRiemannTrack riemannTrack = CreateRiemannTrack(
57  trackletInf.hitIDs);
58 
59  // add riemannTrack to trackletInf if possible
60  if (riemannTrack.getNumHits() > 2) {
61  //riemannTrack.refit(false);
62  trackletInf.riemannTrack = riemannTrack;
63  trackletInf.error = CalcDeviationOfRiemannTrack(riemannTrack);
64  trackletInf.numErrHits = GetDeviationCount(riemannTrack);
65  fFirstRiemannTrack.push_back(riemannTrack);
66 
67  }
68 
69  PndTrackCand trackCand;
70  for (size_t i = 0; i < trackletInf.hitIDs.size(); ++i) {
71  // add hits to TrackCand
72  if (fCalcWithCorrectedHits
73  && (fCorrectedHits.find(trackletInf.hitIDs.at(i))
74  != fCorrectedHits.end())) {
75 
76  trackCand.AddHit(
77  fCorrectedHits[trackletInf.hitIDs.at(i)]->GetEntryNr(),
78  i);
79  } else {
80  trackCand.AddHit(
81  fMapHitToFairLink[trackletInf.hitIDs.at(i)], i);
82  }
83 
84  }
85 
86  fFirstTrackCand.push_back(trackCand);
87  }
88  }
89 
90  //update TrackletInf of combinations --> Hits of RiemannTracks changed
91  for (size_t i = 0; i < fCombinedData.size(); i++) {
92  fCombinedData[i].trackletInf = GetTrackletInf(
93  fCombinedData[i].tracklets);
94  }
95 
96  //Track refit
97  CreatePndTrackCands();
98 
99 }
100 
102 
103  cout << "PndSttCellTrackletGenerator::PrintInfo()" << endl;
104 
105  cout << "#Start Tracklets: " << fStartTracklets.size() << endl;
106 
107  for (map<int, TrackletInf_t>::iterator i = fStartTracklets.begin();
108  i != fStartTracklets.end(); ++i) {
109  cout << "state: " << i->first << ", tubeIDs: ";
110  for (size_t j = 0; j < i->second.hitIDs.size(); ++j)
111  cout << ((PndSttHit*) fHits[i->second.hitIDs.at(j)])->GetTubeID()
112  << ", ";
113  cout << endl;
114  }
115 
116  int maxNumMultiState = 0, averageNumMultiState = 0;
117 
118  cout << "#Tubes with multistate: " << fMultiStates.size() << endl;
119  for (map<int, set<int> >::iterator it = fMultiStates.begin();
120  it != fMultiStates.end(); ++it) {
121  cout << it->first << ": ";
122  for (set<int>::iterator setIt = it->second.begin();
123  setIt != it->second.end(); ++setIt) {
124  cout << *setIt << ", ";
125  }
126  if (maxNumMultiState < (int)it->second.size())
127  maxNumMultiState = it->second.size();
128  averageNumMultiState += it->second.size();
129  cout << endl;
130  }
131 
132  if (fMultiStates.size() != 0) {
133  averageNumMultiState = averageNumMultiState / fMultiStates.size();
134  cout << "Max #MultiState: " << maxNumMultiState
135  << ", Avergage #MultiState: " << averageNumMultiState << endl;
136  }
137 
138  cout << "#Found Combinations (recursive): " << fStateCombinations.size()
139  << endl;
140 
141  cout << "#Accepted Combination of Tracklets: " << fCombinedData.size()
142  << endl;
143  for (size_t i = 0; i < fCombinedData.size(); ++i) {
144  cout << "Combination #" << i << endl;
145  cout << "state of tracklets: ";
146  for (set<int>::iterator iter = fCombinedData[i].tracklets.begin();
147  iter != fCombinedData[i].tracklets.end(); iter++) {
148  cout << *iter << ", ";
149  }
150  cout << endl;
151 
152  }
153 }
154 
156 
157  //Time stamps for runtime analysis
158 
159  //start time for FindTracks()
160  fTimeStamps[18] = TTimeStamp();
161 
162  if (fVerbose > 0) {
163  cout << "PndSttCellTrackletGenerator::FindTracks()" << endl;
164  }
165 
166  if (fUseGPU) {
167  GenerateTrackletsGPU();
168  } else {
169  fTimeStamps[6] = TTimeStamp();
170  GenerateTracklets();
171  fTimeStamps[7] = TTimeStamp();
172  }
173 
174  fTimeStamps[8] = fTimeStamps[7];
175  CombineTrackletsMultiStages();
176  fTimeStamps[9] = TTimeStamp();
177 
178  fTimeStamps[10] = fTimeStamps[9];
179  AssignAmbiguousHits();
180  fTimeStamps[11] = TTimeStamp();
181 
182  //Update trackletInf
183  for (size_t i = 0; i < fCombinedData.size(); i++) {
184  fCombinedData[i].trackletInf = GetTrackletInf(
185  fCombinedData[i].tracklets);
186  }
187 
188  fTimeStamps[12] = TTimeStamp();
189  SplitData();
190  fTimeStamps[13] = TTimeStamp();
191 
192  fTimeStamps[14] = fTimeStamps[13];
193  AddRemainingHits();
194  fTimeStamps[15] = TTimeStamp();
195 
196  fTimeStamps[16] = fTimeStamps[15];
197  CreatePndTrackCands();
198  fTimeStamps[17] = TTimeStamp();
199 
200  //ending time of FindTracks()
201  fTimeStamps[19] = fTimeStamps[17];
202 
203 }
204 
206  if (fVerbose > 1) {
207  cout << "PndSttCellTrackletGenerator::CreatePndTrackCands()" << endl;
208  }
209 
210  int numHits; // state, //[R.K. 01/2017] unused variable?
211 
212 //create TrackCands for each combination of tracklets
213  for (size_t i = 0; i < fCombinedData.size(); ++i) {
214  PndTrackCand trackCand;
215 
216  //add all hits of combined tracklets to trackCand
217  for (size_t j = 0; j < fCombinedData[i].trackletInf.hitIDs.size(); ++j) {
218 
219  int hitIndex = fCombinedData[i].trackletInf.hitIDs.at(j);
220 
221  if (fCalcWithCorrectedHits
222  && (fCorrectedHits.find(hitIndex) != fCorrectedHits.end())) {
223 
224  trackCand.AddHit(fCorrectedHits[hitIndex]->GetEntryNr(), j);
225  } else {
226  trackCand.AddHit(fMapHitToFairLink[hitIndex], j);
227  }
228  }
229 
230  fCombiTrackCand.push_back(trackCand);
231  fCombiRiemannTrack.push_back(fCombinedData[i].trackletInf.riemannTrack);
232  fCombiTrack.push_back(
233  fCombinedData[i].trackletInf.riemannTrack.getPndTrack(fBz));
234  fCombiTrack.back().SetLinks(*(trackCand.GetPointerToLinks()));
235  //fCombinedData[i].trackletInf.riemannTrack.getPndTrack(2.0)); //TODO replace fixed magnetic field with info from simulation
236 
237  if (fVerbose > 2) {
238  cout << "TrackletInf of tracklet-combination: ";
239  fCombinedData[i].trackletInf.Print();
240  cout << endl;
241 
242  cout << "Created PndTrack " << i << " :"
243  << fCombinedData[i].trackletInf.riemannTrack.getPndTrack(
244  fBz) << endl;
245  }
246  }
247 
248  // create TrackCands for tracklets without a combi and more than 2 hits
249  for (size_t i = 0; i < fTrackletsWithoutCombi.size(); ++i) {
250  PndTrackCand trackCand;
251  numHits = fStartTracklets[fTrackletsWithoutCombi[i]].hitIDs.size();
252 
253  if (numHits > 2) {
254 
255  for (int j = 0; j < numHits; ++j) {
256 
257  int hitIndex =
258  fStartTracklets[fTrackletsWithoutCombi[i]].hitIDs[j];
259 
260  if (fCalcWithCorrectedHits
261  && (fCorrectedHits.find(hitIndex) != fCorrectedHits.end())) {
262  trackCand.AddHit(fCorrectedHits[hitIndex]->GetEntryNr(), j);
263  } else {
264  trackCand.AddHit(fMapHitToFairLink[hitIndex], j);
265  }
266 
267  }
268 
269  PndRiemannTrack trackRefit = CreateRiemannTrack(
270  fStartTracklets[fTrackletsWithoutCombi[i]].hitIDs);
271 
272  fCombiTrackCand.push_back(trackCand);
273  fCombiRiemannTrack.push_back(trackRefit);
274  fCombiTrack.push_back(trackRefit.getPndTrack(fBz));
275  fCombiTrack.back().SetLinks(*(trackCand.GetPointerToLinks()));
276 
277  if (fVerbose > 2) {
278  cout << "TrackletInf of tracklet without combination: ";
279  fStartTracklets[fTrackletsWithoutCombi[i]].Print();
280  cout << endl;
281 
282  cout << "Created PndTrack " << fCombiTrack.size() - 1 << " :"
283  << trackRefit.getPndTrack(fBz) << endl;
284  }
285  }
286  }
287 }
289 
290  //initialize hits with 0, means no hit for that tube
291  int *sttHits = (int*) calloc(NUM_STRAWS, sizeof(int));
292  int *hitIndices = (int*) malloc((NUM_STRAWS + 1) * sizeof(int));
293  //initialize hitIndices with -1 to signal there's no hit
294  //
295  for (int i = 0; i < NUM_STRAWS + 1; ++i) {
296  hitIndices[i] = -1;
297  }
298 
299  //form hits into necessary data structure
300  set<int> skewedHits;
301  set<int> unskewedHits;
302  PndSttHit* sttHit;
303  int tubeID;
304 
305  //fill sets with hits of skewed and unskewed tubes --> no more multiple hits per tube
306  for (size_t i = 0; i < fHits.size(); ++i) {
307  sttHit = (PndSttHit*) fHits[i];
308  tubeID = sttHit->GetTubeID();
309 
310  if (tubeID >= START_TUBE_ID_SKEWED && tubeID <= END_TUBE_ID_SKEWED) {
311  skewedHits.insert(tubeID);
312  } else {
313  unskewedHits.insert(tubeID);
314  }
315  }
316 
317  //fill sttHits at first with unskewed hits, set hitIndices
318  int indexCounter = 0;
319  for (set<int>::iterator it = unskewedHits.begin(); it != unskewedHits.end();
320  ++it) {
321  sttHits[indexCounter] = *it;
322  hitIndices[*it] = indexCounter;
323  ++indexCounter;
324  }
325 
326  for (set<int>::iterator it = skewedHits.begin(); it != skewedHits.end();
327  ++it) {
328  sttHits[indexCounter] = *it;
329  hitIndices[*it] = indexCounter;
330  ++indexCounter;
331  }
332 
333  int* states = EvaluateAllStates(fDev_tubeNeighborings, sttHits,
334  unskewedHits.size(), skewedHits.size(), hitIndices);
335 
336  //extract result of gpu and store it in fStates and fMultiStates
337  int numSttHits = unskewedHits.size() + skewedHits.size();
338 
339  for (int i = 0; i < numSttHits; ++i) {
340  if (states[i] != NUM_STRAWS + 1) {
341  fStates[sttHits[i]] = states[i];
342  }
343  }
344 
345  InitStartTracklets();
346 
347  if (fVerbose > 1) {
348 
349  cout << "#Start-Tracklets: " << fStartTracklets.size() << endl;
350 
351  cout << "Tracklet-Information: " << endl;
352  for (map<int, TrackletInf_t>::iterator it = fStartTracklets.begin();
353  it != fStartTracklets.end(); ++it) {
354  int state = it->first;
355  TrackletInf_t inf = it->second;
356 
357  cout << "State: " << state << " ";
358  inf.Print();
359  cout << endl;
360  }
361 
362  cout << "#Short-Tracklets: " << fShortTracklets.size() << endl;
363 
364  cout << "Tracklet-Information: " << endl;
365  for (map<int, TrackletInf_t>::iterator it = fShortTracklets.begin();
366  it != fShortTracklets.end(); ++it) {
367  int state = it->first;
368  TrackletInf_t inf = it->second;
369 
370  cout << "State: " << state << " ";
371  inf.Print();
372  cout << endl;
373  }
374  }
375 
376  int multiStateOffset = numSttHits;
377  int multiStateTubeID;
378 
379  for (int i = 0; i < numSttHits; ++i) {
380 
381  if (states[i] == NUM_STRAWS + 1) {
382 
383  set<int> multiStates;
384  for (int j = 0; j < MAX_MULTISTATE_NUM; ++j) {
385  if (states[multiStateOffset + j * numSttHits + i] != 0) {
386  //insert state not tubeID!
387  multiStateTubeID=sttHits[states[multiStateOffset + j * numSttHits + i]];
388  multiStates.insert(fStates[multiStateTubeID]);
389  } else {
390  break;
391  }
392  }
393  if(multiStates.size()!=0)
394  fMultiStates[sttHits[i]] = multiStates;
395  }
396 
397  }
398 
399  if (fVerbose > 2) {
400  cout << "MultiStates: " << endl;
401  for (map<int, set<int> >::iterator iter = fMultiStates.begin();
402  iter != fMultiStates.end(); iter++) {
403  cout << iter->first << " : ";
404  for (set<int>::iterator iter2 = iter->second.begin();
405  iter2 != iter->second.end(); iter2++) {
406  cout << *iter2 << " ";
407  }
408  cout << endl;
409  }
410  }
411 
412  //free memory
413  free(sttHits);
414  free(hitIndices);
415  free(states);
416 
417 }
418 
420 
421  if (fVerbose > 1) {
422  cout << "PndSttCellTrackletGenerator::GenerateTracklets()" << endl;
423  }
424 
425 //initialize states of cells with the id of the tube
426  PndSttHit* sttHit;
427  for (size_t i = 0; i < fHits.size(); ++i) {
428  sttHit = (PndSttHit*) fHits[i];
429  fStates[sttHit->GetTubeID()] = sttHit->GetTubeID();
430  }
431 
432  fTimeStamps[0] = TTimeStamp();
433  EvaluateState();
434  fTimeStamps[1] = TTimeStamp();
435 
436  if (fVerbose > 2) {
437  cout << "States of start-tracklets: " << endl;
438  for (map<int, int>::iterator iter = fStates.begin();
439  iter != fStates.end(); iter++) {
440  cout << iter->first << " : " << iter->second << endl;
441  }
442  }
443 
444  fTimeStamps[2] = TTimeStamp();
445  InitStartTracklets();
446  fTimeStamps[3] = TTimeStamp();
447 
448  if (fVerbose > 1) {
449 
450  cout << "#Start-Tracklets: " << fStartTracklets.size() << endl;
451 
452  cout << "Tracklet-Information: " << endl;
453  for (map<int, TrackletInf_t>::iterator it = fStartTracklets.begin();
454  it != fStartTracklets.end(); ++it) {
455  int state = it->first;
456  TrackletInf_t inf = it->second;
457 
458  cout << "State: " << state << " ";
459  inf.Print();
460  cout << endl;
461  }
462 
463  cout << "#Short-Tracklets: " << fShortTracklets.size() << endl;
464 
465  cout << "Tracklet-Information: " << endl;
466  for (map<int, TrackletInf_t>::iterator it = fShortTracklets.begin();
467  it != fShortTracklets.end(); ++it) {
468  int state = it->first;
469  TrackletInf_t inf = it->second;
470 
471  cout << "State: " << state << " ";
472  inf.Print();
473  cout << endl;
474  }
475  }
476 
477  fTimeStamps[4] = TTimeStamp();
478  EvaluateMultiState();
479  fTimeStamps[5] = TTimeStamp();
480 
481  if (fVerbose > 2) {
482  cout << "MultiStates: " << endl;
483  for (map<int, set<int> >::iterator iter = fMultiStates.begin();
484  iter != fMultiStates.end(); iter++) {
485  cout << iter->first << " : ";
486  for (set<int>::iterator iter2 = iter->second.begin();
487  iter2 != iter->second.end(); iter2++) {
488  cout << *iter2 << " ";
489  }
490  cout << endl;
491  }
492  }
493 
494 }
495 
497 
498  if (fVerbose > 2) {
499  cout << "PndSttCellTrackletGenerator::EvaluateState()" << endl;
500  }
501 
502  /* Approach: The state has to be calculated for cells with 1 or 2 hit-neighbors (no ambiguities).
503  * Each cell starts with an unique state-ID (tubeID). At each step the cells analyzes similar cells
504  * (1/2 hit-neighbors) and calculate the minimum of all states. The states will be changed to
505  * this minimum simultaneously after the calculation. If there are no changes at consecutive steps,
506  * the evaluation of the states is finished. Cells with the same state-ID belongs to the same track
507  * and form a tracklet.*/
508 
509  int currentSum = 0;
510  int priorSum = -1;
511  int newState;
512  set<int> plainHitIds;
513  vector<int>::iterator it;
514  map<int, int>::iterator itStates;
515  vector<int> neighbors;
516  map<int, int> tmpStates;
517 
518 // set with tube-ids of hits without ambiguity
519  plainHitIds.insert(fSeparations[1].begin(), fSeparations[1].end());
520  plainHitIds.insert(fSeparations[2].begin(), fSeparations[2].end());
521 
522 // calculate for tubes with only one or two hits in neighborings until the sum of states does not change anymore
523  while (currentSum != priorSum) {
524 
525  priorSum = currentSum;
526  currentSum = 0;
527 
528  // calculate new state of tubes with one hit in neighboring
529  for (it = fSeparations[1].begin(); it < fSeparations[1].end(); ++it) {
530  neighbors = fHitNeighbors[(*it)];
531 
532  // include only state of hits without ambiguity
533  if (plainHitIds.find(neighbors[0]) != plainHitIds.end()) {
534  newState = min(fStates[(*it)], fStates[neighbors[0]]);
535  tmpStates[(*it)] = newState;
536  currentSum += newState;
537  } else {
538  // no hit neighboring to consider
539  tmpStates[(*it)] = fStates[(*it)];
540  currentSum += newState;
541  }
542 
543  }
544  // calculate new state of tubes with two hits in neighboring
545  for (it = fSeparations[2].begin(); it < fSeparations[2].end(); ++it) {
546  neighbors = fHitNeighbors[(*it)];
547 
548  // include only state of hits without ambiguity
549  if (plainHitIds.find(neighbors[1]) == plainHitIds.end())
550  neighbors.erase(neighbors.begin() + 1);
551  if (plainHitIds.find(neighbors[0]) == plainHitIds.end())
552  neighbors.erase(neighbors.begin());
553 
554  // calculate minimum
555  switch (neighbors.size()) {
556  case 2:
557  newState = min(fStates[(*it)],
558  min(fStates[neighbors[0]], fStates[neighbors[1]]));
559  break;
560  case 1:
561  newState = min(fStates[(*it)], fStates[neighbors[0]]);
562  break;
563  case 0:
564  newState = fStates[(*it)];
565  }
566 
567  tmpStates[(*it)] = newState;
568  currentSum += newState;
569  }
570 
571  // update states simultaneously
572  fStates.clear();
573  fStates.insert(tmpStates.begin(), tmpStates.end());
574 
575  }
576 }
577 
579 
580  if (fVerbose > 2) {
581  cout << "PndSttCellTrackletGenerator::EvaluateMultiState()" << endl;
582  }
583 
584  /* Approach: For unambiguous hit-neighbors the cell value is a copy of all indices of the neighboring cells.
585  * The copying is repeated until the values do not change anymore. In this way the cell content is a collection
586  * of all unique tracklets touching the cluster of ambiguous cells.*/
587 
588  int currentSum = 0;
589  int priorSum = -1;
590  set<int> newState;
591  set<int> ambiguousHitIds;
592  set<int>::iterator it;
593  map<int, int>::iterator itStates;
594  vector<int> neighbors;
595  map<int, set<int> > tmpStates;
596  map<int, TrackletInf_t>::iterator trackletIt;
597 
598  // set with tube-ids of hits with ambiguities
599  ambiguousHitIds.insert(fSeparations[3].begin(), fSeparations[3].end());
600  ambiguousHitIds.insert(fSeparations[4].begin(), fSeparations[4].end());
601  ambiguousHitIds.insert(fSeparations[5].begin(), fSeparations[5].end());
602  ambiguousHitIds.insert(fSeparations[6].begin(), fSeparations[6].end());
603  ambiguousHitIds.insert(fSeparations[7].begin(), fSeparations[7].end());
604 
605  //TODO generate multistate for short tracklets too?
606 // for (trackletIt = fShortTracklets.begin();
607 // trackletIt != fShortTracklets.end(); ++trackletIt) {
608 //
609 // for (int i = 0; i < trackletIt->second.hitIDs.size(); ++i) {
610 // PndSttHit* sttHit = (PndSttHit*) fHits[trackletIt->second.hitIDs[i]];
611 // int tubeID = sttHit->GetTubeID();
612 // ambiguousHitIds.insert(tubeID);
613 // }
614 // }
615 
616  if (fVerbose > 3) {
617  cout << "EvaluateMultiState: AmbiguousHitIds: ";
618  for (it = ambiguousHitIds.begin(); it != ambiguousHitIds.end(); it++) {
619  cout << *it << " ";
620  }
621  cout << endl;
622  }
623 
624  int loopcount = 0;
625  // while sum of all states changes
626  while (currentSum != priorSum) {
627  if (fVerbose > 3) {
628  cout << endl;
629  cout << "LoopCount: " << loopcount++ << " currentSum: "
630  << currentSum << " priorSum: " << priorSum << endl;
631  }
632 
633  priorSum = currentSum;
634  currentSum = 0;
635 
636  for (it = ambiguousHitIds.begin(); it != ambiguousHitIds.end(); ++it) {
637  neighbors = fHitNeighbors[(*it)];
638  newState.clear();
639  if (fVerbose > 3) {
640  cout << "AmbiguousHitId: " << *it << endl;
641  cout << "Neighbors: " << endl;
642  }
643 
644  for (size_t i = 0; i < neighbors.size(); i++) {
645  if (fVerbose > 3)
646  cout << neighbors[i] << " : ";
647 
648  if (fStates.count(neighbors[i]) > 0) {
649  // if unambiguous neighbor copy one state
650  newState.insert(fStates[neighbors[i]]);
651 
652  if (fVerbose > 3)
653  cout << fStates[neighbors[i]];
654  } else if (fMultiStates.count(neighbors[i]) > 0) {
655  // if multistate-neighbor copy all states
656  newState.insert(fMultiStates[neighbors[i]].begin(),
657  fMultiStates[neighbors[i]].end());
658  if (fVerbose > 3) {
659  for (set<int>::iterator iter =
660  fMultiStates[neighbors[i]].begin();
661  iter != fMultiStates[neighbors[i]].end();
662  iter++) {
663  cout << *iter << "/";
664  }
665  }
666  }
667  if (fVerbose > 3)
668  cout << " | ";
669  }
670  if (fVerbose > 3)
671  cout << endl;
672 
673  // keep new one
674  if (newState.size() > 0 && newState.size() > tmpStates[(*it)].size())
675  tmpStates[(*it)] = newState;
676 
677  if (fVerbose > 3)
678  cout << "NewState for " << *it << " : ";
679 
680  // calculate sum of all states
681  for (set<int>::iterator stateIter = newState.begin();
682  stateIter != newState.end(); stateIter++) {
683  if (fVerbose > 3)
684  cout << *stateIter << " | ";
685  currentSum += *stateIter;
686  }
687  if (fVerbose > 3)
688  cout << endl;
689  }
690 
691  // update states simultaneously
692  fMultiStates.clear();
693  fMultiStates.insert(tmpStates.begin(), tmpStates.end());
694  }
695 
696 }
697 
699 
700  if (fVerbose > 3)
701  cout << "void PndSttCellTrackletGenerator::InitStartTracklets()"
702  << endl;
703 
704  vector<int>::iterator it;
705  map<int, vector<int> > tmpStartTracklets;
706  map<int, vector<int> >::iterator trackIt;
707 
708 //get states + hitIDs of tracklets with 1 or 2 hit-neighbors
709  for (it = fSeparations[1].begin(); it < fSeparations[1].end(); ++it) {
710  tmpStartTracklets[fStates[(*it)]].push_back(fMapTubeIdToHit[(*it)]);
711  }
712 
713  for (it = fSeparations[2].begin(); it < fSeparations[2].end(); ++it) {
714  tmpStartTracklets[fStates[(*it)]].push_back(fMapTubeIdToHit[(*it)]);
715  }
716 
717  vector<int> hitIDs;
718  int state;
719  PndSttHit* sttHit;
720  int tubeID;
721 
722  if (fVerbose > 3)
723  cout << "Calculation of StartTracklets: " << endl;
724  for (trackIt = tmpStartTracklets.begin();
725  trackIt != tmpStartTracklets.end(); ++trackIt) {
726 
727  state = trackIt->first;
728  TrackletInf_t trackletInf;
729  trackletInf.hitIDs.insert(trackletInf.hitIDs.begin(),
730  trackIt->second.begin(), trackIt->second.end());
731 
732  hitIDs = trackletInf.hitIDs;
733  PndTrackCand trackCand;
734  trackletInf.startID = state;
735  trackletInf.maxID = 0;
736  trackletInf.endID = state;
737  trackletInf.straight = false;
738  trackletInf.numSkewed = 0;
739  bool IsEndID;
740 
741  for (size_t i = 0; i < hitIDs.size(); ++i) {
742 
743  sttHit = (PndSttHit*) fHits[hitIDs[i]];
744  tubeID = sttHit->GetTubeID();
745 
746  if (fStrawMap->IsSkewedStraw(tubeID)) {
747  ++trackletInf.numSkewed;
748  }
749 
750  IsEndID = IsEndTubeOfTracklet(tubeID);
751 
752  // found tubeID that's bigger than maxID of tracklet?
753  if (tubeID > trackletInf.maxID) {
754 
755  // if tube is end of tracklet --> straight tracklet
756  if (fStrawMap->GetRow(tubeID)
757  == fStrawMap->GetRow(trackletInf.maxID)) {
758  // Hits in same row --> not a straight track
759  trackletInf.straight = false;
760  }
761  if (IsEndID) {
762  // no hits in same row and hit in end-tube
763  trackletInf.straight = true;
764  } else {
765  // hit was not in end-tube
766  trackletInf.straight = false;
767  }
768 
769  trackletInf.maxID = tubeID;
770  }
771 
772  // safe ID of end-tube
773  if (IsEndID && tubeID != state) {
774  trackletInf.endID = tubeID;
775  }
776 
777  if (fCalcFirstTrackletInf) {
778  // add hits to TrackCand
779  trackCand.AddHit(fMapHitToFairLink[hitIDs[i]], 0);
780  }
781 
782  }
783 
784  if (fCalcFirstTrackletInf) {
785  // calc riemannTrack
786  PndRiemannTrack riemannTrack = CreateRiemannTrack(hitIDs);
787 
788  // add riemannTrack to trackletInf if possible
789  if (riemannTrack.getNumHits() > 2) {
790  //riemannTrack.refit(false);
791  trackletInf.riemannTrack = riemannTrack;
792  trackletInf.error = CalcDeviationOfRiemannTrack(riemannTrack);
793  trackletInf.numErrHits = GetDeviationCount(riemannTrack);
794  fFirstRiemannTrack.push_back(riemannTrack);
795 
796  }
797  fFirstTrackCand.push_back(trackCand);
798  }
799 
800  if (fVerbose > 3)
801  cout << "RiemannTrack for startTracklet: " << state << " - "
802  << trackletInf.riemannTrack << endl;
803 
804  // tracklet with enough hits
805  fStartTracklets[state] = trackletInf;
806 
807  }
808 }
809 
811 
812  if (fVerbose > 1)
813  cout
814  << "void PndSttCellTrackletGenerator::CombineTrackletsMultiStages()"
815  << endl;
816 
817  map<int, TrackletInf_t>::iterator trackletIt;
818 
819  // try to combine start- and short-tracklets that begin in the first row
820  for (trackletIt = fStartTracklets.begin();
821  trackletIt != fStartTracklets.end(); ++trackletIt) {
822 
823  // only for tracklets that starts in the first row
824  if (trackletIt->first <= 104) {
825  set<int> combi;
826  CombineTrackletsMultiStagesRecursive(trackletIt->first, combi);
827  }
828  }
829 
830  vector<set<int> >::iterator combiIt;
831  set<int>::iterator setIt;
832 
833  if (fVerbose > 0)
834  cout << "Found combinations: " << endl;
835 
836  // fit combinations
837  for (combiIt = fStateCombinations.begin();
838  combiIt != fStateCombinations.end(); ++combiIt) {
839 
840  TrackletInf_t trackletInf;
841 
842  trackletInf = GetTrackletInf(*combiIt);
843 
844  if (fVerbose > 0) {
845  for (setIt = (*combiIt).begin(); setIt != (*combiIt).end();
846  ++setIt) {
847  cout << (*setIt) << " ";
848  }
849  }
850 
851  // store combinations with more than 3 hits only
852  if (trackletInf.riemannTrack.getNumHits() > 2
853  && trackletInf.numErrHits == 0) {
855  combi.tracklets = *combiIt;
856  combi.trackletInf = trackletInf;
857 
858  fCombinedData.push_back(combi);
859 
860  if (fVerbose > 0)
861  cout << "--> keep";
862  }
863 
864  if (fVerbose > 0)
865  cout << endl;
866  }
867 
868 }
869 
871  int stateToCombine, set<int> currentCombi) {
872 
873  if (fVerbose > 2)
874  cout << "CombineTrackletsMultiStagesRecursive, tracklet: "
875  << stateToCombine << endl;
876 
877  set<int> newCombi;
878  newCombi.insert(currentCombi.begin(), currentCombi.end());
879  newCombi.insert(stateToCombine);
880 
881  int ambiguousID = 0;
882  int endID;
883 
884  endID = fStartTracklets[stateToCombine].endID;
885 
886  set<int>::iterator it;
887 
888  if (fVerbose > 2) {
889  cout << "neighbors of end-tube " << endID << ": ";
890  for (size_t i = 0; i < fHitNeighbors[endID].size(); ++i) {
891  cout << fHitNeighbors[endID].at(i) << " ";
892  }
893  cout << endl;
894  }
895 
896  // tubes that are already included in a tracklet can only have one or two neighbors.
897  // check if the tracklet could be continued
898 
899  if (fHitNeighbors[endID].size() == 2) {
900  // ending tube of tracklet has an ambiguous neighbor --> could be combined
901 
902  // find neighbor with multistate to get information for possible combination
903  if (fMultiStates.count(fHitNeighbors[endID].at(0))) {
904  ambiguousID = fHitNeighbors[endID].at(0);
905 
906  } else if (fMultiStates.count(fHitNeighbors[endID].at(1))) {
907  ambiguousID = fHitNeighbors[endID].at(1);
908  }
909  // multistate must be found because neighbor of end-tube lies next to the tracklet
910  //--> should have been adapted
911 
912  } else if (fMultiStates.count(fHitNeighbors[endID].at(0))) {
913  ambiguousID = fHitNeighbors[endID].at(0);
914  }
915 
916  if (ambiguousID != 0) {
917  // way was already chosen? only possible for strong bended tracks.
918  // to avoid that combination goes "backwards" (definition of end-tube)
919 
920  for (it = currentCombi.begin(); it != currentCombi.end(); ++it) {
921  if (fMultiStates[ambiguousID].count(*it)) {
922  ambiguousID = 0;
923  break;
924  }
925  }
926  }
927 
928  if (ambiguousID == 0) {
929  // no ambiguous neighbor found --> end of track
930  if (fVerbose > 2) {
931  cout << "ambiguous id was not found. finish combi: ";
932  for (it = newCombi.begin(); it != newCombi.end(); ++it) {
933  cout << *it << ", ";
934  }
935  cout << endl;
936  }
937 
938  if (newCombi.size() > 1)
939  InsertCombination(newCombi);
940  return;
941  }
942 
943  if (fVerbose > 2)
944  cout << "found ambiguous tube: " << ambiguousID << endl;
945 
946  set<pair<int, int> > pairCombinations;
947  set<pair<int, int> >::iterator pairIt;
948  int combiPartner;
949 
950  // get possible combination
951  pairCombinations = CreatePairCombis(stateToCombine,
952  fMultiStates[ambiguousID]);
953 
954  if (fVerbose > 2) {
955  cout << "StateToCombine " << stateToCombine << " with: ";
956  for (set<int>::iterator iter = fMultiStates[ambiguousID].begin();
957  iter != fMultiStates[ambiguousID].end(); iter++) {
958  cout << *iter << " ";
959  }
960  cout << endl;
961  cout << "results in PairCombinations: ";
962  for (set<pair<int, int> >::iterator iter = pairCombinations.begin();
963  iter != pairCombinations.end(); iter++) {
964  cout << iter->first << "/" << iter->second << " ";
965  }
966  cout << endl;
967  }
968 
969  // find pair with curState
970  for (pairIt = pairCombinations.begin(); pairIt != pairCombinations.end();
971  ++pairIt) {
972  combiPartner = pairIt->second;
973 
974  if (fVerbose > 2)
975  cout << "found combipartner: " << combiPartner << endl;
976 
977  if (!newCombi.count(combiPartner))
978  CombineTrackletsMultiStagesRecursive(combiPartner, newCombi);
979  }
980 
981 }
982 
984 
985  if (fVerbose > 4) {
986  cout
987  << "void PndSttCellTrackletGenerator::InsertCombination(set<int> combination)"
988  << endl;
989  }
990 
991  bool found = false;
992  set<int>::iterator oldIt;
993  set<int>::iterator newIt;
994 
995  for (size_t i = 0; i < fStateCombinations.size(); ++i) {
996 
997  if (fStateCombinations[i] == combination) {
998  found = true;
999  break;
1000  }
1001  }
1002 
1003  if (!found)
1004  fStateCombinations.push_back(combination);
1005 }
1006 
1007 // es wird davon ausgegangen, dass nur hintereinanderliegende tracklets kombiniert werden
1009 
1010  if (fVerbose > 4) {
1011  cout
1012  << "TrackletInf_t PndSttCellTrackletGenerator::GetTrackletInf(set<int> tracklets)"
1013  << endl;
1014  }
1015 
1016  TrackletInf_t inf;
1017 
1018  if (tracklets.size() > 1) {
1019  //update trackletInf
1020 
1021  int state = 5000, maxID = 0;//, endID = 0; //[R.K. 01/2017] unused variable?
1022  bool straight = false;
1023 
1024  //state of combined tracklet equals min state of all
1025  for (set<int>::iterator iter = tracklets.begin();
1026  iter != tracklets.end(); ++iter) {
1027  state = TMath::Min(state, *iter);
1028  }
1029 
1030  inf.startID = state;
1031 
1032  straight = true;
1033  //combined tracklet is straight if each particular tracklets are straight
1034  for (set<int>::iterator iter = tracklets.begin();
1035  iter != tracklets.end(); ++iter) {
1036  if (!fStartTracklets[*iter].straight) {
1037  straight = false;
1038  break;
1039  }
1040  }
1041 
1042  inf.straight = straight;
1043 
1044  if (straight) {
1045  //maxID equals the data of the last tracklet
1046  maxID = fStartTracklets[*(--tracklets.end())].maxID;
1047 
1048  } else {
1049  //maxID is the maximum of all maxID
1050  maxID = 0;
1051  for (set<int>::iterator iter = tracklets.begin();
1052  iter != tracklets.end(); ++iter) {
1053  maxID = TMath::Max(maxID, fStartTracklets[*iter].maxID);
1054  }
1055  }
1056 
1057  inf.maxID = maxID;
1058 
1059  //endID equals the endID of last tracklet
1060  inf.endID = fStartTracklets[*(--tracklets.end())].endID;
1061 
1062  //update hitIDs
1063  for (set<int>::iterator iter = tracklets.begin();
1064  iter != tracklets.end(); ++iter) {
1065  inf.hitIDs.insert(inf.hitIDs.end(),
1066  fStartTracklets[*iter].hitIDs.begin(),
1067  fStartTracklets[*iter].hitIDs.end());
1068  inf.numSkewed += fStartTracklets[*iter].numSkewed;
1069  }
1070 
1071  }
1072 
1073  inf.riemannTrack = CreateRiemannTrack(inf.hitIDs);
1074 
1075  if (inf.riemannTrack.getNumHits() > 2) {
1076  inf.error = CalcDeviationOfRiemannTrack(inf.riemannTrack);
1077  inf.numErrHits = GetDeviationCount(inf.riemannTrack);
1078  }
1079 
1080  return inf;
1081 }
1082 
1084 
1085  if (fVerbose > 1) {
1086  cout << "void PndSttCellTrackletGenerator::SplitData" << endl;
1087  }
1088 
1089  set<int> combinedTracklets;
1090 
1091  // fill set with states of combined tracklets
1092  for (size_t i = 0; i < fCombinedData.size(); ++i) {
1093  for (set<int>::iterator iter = fCombinedData[i].tracklets.begin();
1094  iter != fCombinedData[i].tracklets.end(); iter++) {
1095  combinedTracklets.insert(*iter);
1096 
1097  }
1098  }
1099 
1100  map<int, TrackletInf_t>::iterator it;
1101  for (it = fStartTracklets.begin(); it != fStartTracklets.end(); ++it) {
1102 
1103  if (combinedTracklets.find(it->first) == combinedTracklets.end()) {
1104  // tracklet was not combined
1105 
1106  if (it->second.hitIDs.size() - it->second.numSkewed > 2) {
1107  // enough hits for riemann fit
1108  fTrackletsWithoutCombi.push_back(it->first);
1109  } else {
1110  fShortTracklets[it->first] = fStartTracklets[it->first];
1111  }
1112 
1113  }
1114  }
1115 
1116 }
1117 
1119 
1120  if (fVerbose > 1) {
1121  cout << "void PndSttCellTrackletGenerator::AssignAmbiguousHits()"
1122  << endl;
1123  }
1124 
1125  for (map<int, set<int> >::iterator multistateIt = fMultiStates.begin();
1126  multistateIt != fMultiStates.end(); multistateIt++) {
1127  if (multistateIt->second.size() == 1) {
1128  // hit can be assigned to only one possible tracklet
1129 
1130  fStartTracklets[*(multistateIt->second.begin())].hitIDs.push_back(
1131  fMapTubeIdToHit[multistateIt->first]);
1132 
1133  if (fVerbose > 1)
1134  cout << "add " << multistateIt->first
1135  << " to (only possible) tracklet "
1136  << *(multistateIt->second.begin()) << endl;
1137 
1138  } else if (multistateIt->second.size() == 2) {
1139 
1140  PndRiemannHit hit(fHits[fMapTubeIdToHit[multistateIt->first]]);
1141 
1142  // check if RiemannTrack was calculated
1143  if (fStartTracklets[*(multistateIt->second.begin())].riemannTrack.getNumHits()
1144  == 0) {
1145  fStartTracklets[*(multistateIt->second.begin())].riemannTrack =
1146  CreateRiemannTrack(
1147  fStartTracklets[*(multistateIt->second.begin())].hitIDs);
1148  }
1149  // check if RiemannTrack has at least 3 hits and distance to the hit
1150  if (fStartTracklets[*(multistateIt->second.begin())].riemannTrack.getNumHits()
1151  > 2
1152  && abs(
1153  fStartTracklets[*(multistateIt->second.begin())].riemannTrack.dist(
1154  &hit)) < fTUBE_RADIUS) {
1155  fStartTracklets[*(multistateIt->second.begin())].hitIDs.push_back(
1156  fMapTubeIdToHit[multistateIt->first]);
1157 
1158  if (fVerbose > 1)
1159  cout << "add " << multistateIt->first << " to tracklet "
1160  << *(multistateIt->second.begin()) << endl;
1161  }
1162  }
1163  }
1164 }
1165 
1167 
1168  if (fVerbose > 1) {
1169  cout << "void PndSttCellTrackletGenerator::AddRemainingHits()" << endl;
1170  }
1171 
1172  // add hits of short tracklets to the best combination
1173  int state;
1174  PndSttHit* sttHit;
1175  map<int, TrackletInf_t>::iterator it;
1176  for (it = fShortTracklets.begin(); it != fShortTracklets.end(); ++it) {
1177  state = it->first;
1178 
1179  for (size_t j = 0; j < fShortTracklets[state].hitIDs.size(); ++j) {
1180  sttHit = (PndSttHit*) fHits[fShortTracklets[state].hitIDs[j]];
1181  if (!fStrawMap->IsSkewedStraw(sttHit->GetTubeID())) {
1182  AddHitToBestCombi(fShortTracklets[state].hitIDs[j]);
1183 
1184  }
1185  }
1186 
1187  }
1188 }
1189 
1191 
1192  if (fVerbose > 3) {
1193  cout << "bool PndSttCellTrackletGenerator::AddHitToBestCombi(int hitID)"
1194  << endl;
1195  }
1196 
1197  double minDistance = 100, tmpDistance;
1198  PndSttHit* sttHit = (PndSttHit*) fHits[hitID];
1199  int tubeID = sttHit->GetTubeID();
1200  int sector = fStrawMap->GetSector(tubeID);
1201  int sectorOfCombi, foundCombi;
1202 
1203  for (size_t i = 0; i < fCombinedData.size(); ++i) {
1204 
1205  sectorOfCombi = fStrawMap->GetSector(
1206  *(fCombinedData[i].tracklets.begin()));
1207 
1208  if (sector / 3 == sectorOfCombi / 3) {
1209  // combi and hit are in the same half of the STT (integer division)
1210  tmpDistance = CalcDeviation(
1211  fCombinedData[i].trackletInf.riemannTrack, hitID);
1212  if (tmpDistance < minDistance) {
1213  minDistance = tmpDistance;
1214  foundCombi = i;
1215  }
1216  }
1217  }
1218 
1219 //min distance smaller than radius of a tube?
1220  if (minDistance < fTUBE_RADIUS) {
1221  //add hit to combi
1222  fCombinedData[foundCombi].trackletInf.hitIDs.push_back(hitID);
1223  if (fVerbose > 2) {
1224  cout << "AddHitToBestCombi(): add " << tubeID << " to Combi #"
1225  << foundCombi << ", distance: " << minDistance << endl;
1226  }
1227  return true;
1228  } else {
1229  return false;
1230  }
1231 }
1232 
1234  vector<int> hitIDs) {
1235 
1236  if (fVerbose > 3)
1237  cout
1238  << "PndSttCellTrackletGenerator::CreateRiemannTrack with correction "
1239  << fCalcWithCorrectedHits << endl;
1240 
1241  PndRiemannTrack riemannTrack;
1242  PndSttHit* sttHit;
1243  set<int> skewedTubeIdsInTrack;
1244 
1245 // add hits to riemannTrack (if unskewed)
1246  for (size_t i = 0; i < hitIDs.size(); ++i) {
1247 
1248  sttHit = (PndSttHit*) fHits[hitIDs[i]];
1249  if (!fStrawMap->IsSkewedStraw(sttHit->GetTubeID())) {
1250 
1251  if (fCalcWithCorrectedHits
1252  && fCorrectedHits.find(hitIDs[i]) != fCorrectedHits.end()) {
1253 
1254  PndRiemannHit riemannHit(fCorrectedHits[hitIDs[i]], hitIDs[i]);
1255  riemannTrack.addHit(riemannHit);
1256 
1257  } else {
1258  PndRiemannHit riemannHit(fHits[hitIDs[i]], hitIDs[i]);
1259  riemannHit.setDXYZ(1, 1, 100);
1260  riemannTrack.addHit(riemannHit);
1261  }
1262  } else {
1263  skewedTubeIdsInTrack.insert(sttHit->GetTubeID());
1264  }
1265  }
1266 
1267  if (fVerbose > 3)
1268  cout << "#hits: " << riemannTrack.getNumHits() << endl;
1269 
1270 // fit riemannTrack if it contains more than 2 hits
1271  if (riemannTrack.getNumHits() > 2) {
1272 
1273  if (fVerbose > 3) {
1274  vector<PndRiemannHit> hits = riemannTrack.getHits();
1275  cout << endl << "RiemannTrack, Input: " << endl;
1276  for (size_t i = 0; i < hits.size(); ++i) {
1277  const FairHit* hit = hits[i].hit();
1278  cout << "(" << hit->GetX() << "|" << hit->GetY() << "), ";
1279  }
1280  cout << endl;
1281  }
1282 
1283  riemannTrack.refit(false);
1284 
1285  if (fVerbose > 3) {
1286  cout << "Calculated RiemannTrack: " << riemannTrack << endl
1287  << "End of Calculation" << endl;
1288  }
1289 
1290  for (set<int>::iterator tubeIter = skewedTubeIdsInTrack.begin();
1291  tubeIter != skewedTubeIdsInTrack.end(); tubeIter++) {
1292  multimap<int, PndSttSkewedHit*>::iterator it, itlow, itup, itbest;
1293  itlow = fCombinedSkewedHits.lower_bound(*tubeIter);
1294  itup = fCombinedSkewedHits.upper_bound(*tubeIter);
1295  itbest = fCombinedSkewedHits.end();
1296  Double_t minDist = 1000;
1297  for (it = itlow; it != itup; ++it) {
1298  PndRiemannHit skewedRiemann(it->second);
1299  Double_t actDist = riemannTrack.dist(&skewedRiemann);
1300  if (actDist < minDist) {
1301  itbest = it;
1302  minDist = actDist;
1303  }
1304  }
1305  if (itbest != fCombinedSkewedHits.end()) {
1306  PndRiemannHit skewedRiemann(itbest->second);
1307  riemannTrack.addHit(skewedRiemann);
1308  }
1309  }
1310  riemannTrack.refit(false);
1311  }
1312 
1313  return riemannTrack;
1314 }
1315 
1316 /*################
1317  * Help functions
1318  * ##############*/
1319 
1321  int firstState, set<int> values) {
1322 
1323  if (fVerbose > 3) {
1324  cout
1325  << "set<pair<int, int> > PndSttCellTrackletGenerator::CreatePairCombis(...)"
1326  << endl;
1327  }
1328 
1329  set<pair<int, int> > result;
1330 
1331  if (values.count(firstState) > 0) {
1332  for (set<int>::iterator iter = values.begin(); iter != values.end();
1333  iter++) {
1334  pair<int, int> actualPair;
1335  actualPair.first = firstState;
1336  if (firstState != *iter) {
1337  actualPair.second = *iter;
1338  result.insert(actualPair);
1339  }
1340  }
1341  } else if (fVerbose > 3) {
1342  cout << "-E- PndSttCellTrackletGenerator::CreatePairCombis Value "
1343  << firstState << " is not in set: ";
1344  for (set<int>::iterator iter = values.begin(); iter != values.end();
1345  iter++) {
1346  cout << *iter << " ";
1347  }
1348  cout << endl;
1349  }
1350 
1351  return result;
1352 
1353 }
1354 
1357 
1358  if (fVerbose > 3) {
1359  cout
1360  << "double PndSttCellTrackletGenerator::CalcDeviationOfRiemannTrack(...)"
1361  << endl;
1362  }
1363 
1364  vector<PndRiemannHit> hits = track.getHits();
1365  TVector2 pos;
1366  TVectorD orig(2);
1367  orig = track.orig();
1368  TVector2 diff;
1369  double r = track.r();
1370  double sum = 0;
1371 
1372  for (size_t i = 0; i < track.getNumHits(); ++i) {
1373 
1374  //get x- and y-coordinate of the hit
1375  pos.Set(hits[i].x()[0], hits[i].x()[1]);
1376  //calc diff-vector to origin
1377  diff.Set(pos.X() - orig[0], pos.Y() - orig[1]);
1378  //calc distance to circle
1379  sum += (diff.Mod() - r) * (diff.Mod() - r);
1380  }
1381 
1382  return sum / track.getNumHits();
1383 }
1384 
1386  int hitID) {
1387 
1388  if (fVerbose > 3) {
1389  cout << "double PndSttCellTrackletGenerator::CalcDeviation(...)"
1390  << endl;
1391  }
1392 
1393  PndSttHit* sttHit = (PndSttHit*) fHits[hitID];
1394  TVector3 pos = fMapTubeIdToPos[sttHit->GetTubeID()];
1395  TVector2 diff;
1396  TVectorD orig(2);
1397  double r = track.r();
1398  orig = track.orig();
1399 
1400  diff.Set(pos.X() - orig[0], pos.Y() - orig[1]);
1401 
1402  return TMath::Abs(diff.Mod() - r);
1403 
1404 }
1405 
1407 
1408  if (fVerbose > 3) {
1409  cout
1410  << "int PndSttCellTrackletGenerator::GetDeviationCount(PndRiemannTrack& track)"
1411  << endl;
1412  }
1413 
1414  int counter = 0;
1415 
1416  vector<PndRiemannHit> hits = track.getHits();
1417  TVector2 pos;
1418  TVectorD orig(2);
1419  orig = track.orig();
1420  TVector2 diff;
1421  double r = track.r();
1422 
1423  for (size_t i = 0; i < track.getNumHits(); ++i) {
1424 
1425  //get x- and y-coordinate of the hit
1426  pos.Set(hits[i].x()[0], hits[i].x()[1]);
1427  diff.Set(pos.X() - orig[0], pos.Y() - orig[1]);
1428 
1429  if (TMath::Abs(diff.Mod() - r) > fTUBE_RADIUS) {
1430  ++counter;
1431  }
1432  }
1433  return counter;
1434 }
1435 
1437 
1438  if (fVerbose > 4) {
1439  cout
1440  << "bool PndSttCellTrackletGenerator::IsEndTubeOfTracklet(int tubeID)"
1441  << endl;
1442  }
1443 
1444 // tube is end of tracklet if there's only one hit-neighbor or if it has neighbors with ambiguity hits
1445  if (fHitNeighbors[tubeID].size() == 1
1446  || fHitNeighbors[fHitNeighbors[tubeID][0]].size() > 2
1447  || fHitNeighbors[fHitNeighbors[tubeID][1]].size() > 2) {
1448  return true;
1449  }
1450 
1451  return false;
1452 }
1453 
int * EvaluateAllStates(int *, int *, int, int, int *)
TVector3 pos
unsigned int getNumHits()
int fVerbose
Definition: poormantracks.C:24
int GetDeviationCount(PndRiemannTrack &track)
double CalcDeviation(PndRiemannTrack &track, int hitID)
std::set< std::pair< int, int > > CreatePairCombis(int firstState, std::set< int > values)
double r
Definition: RiemannTest.C:14
Int_t i
Definition: run_full.C:25
#define NUM_STRAWS
#define MAX_MULTISTATE_NUM
PndTransMap * map
Definition: sim_emc_apd.C:99
PndRiemannTrack track
Definition: RiemannTest.C:33
void CombineTrackletsMultiStagesRecursive(int stateToCombine, std::set< int > currentCombi)
void SetCorrectedHits(std::map< int, FairHit * > correctedHits)
double dist(PndRiemannHit *hit)
#define START_TUBE_ID_SKEWED
void setDXYZ(double dx, double dy, double dz)
void InsertCombination(std::set< int > combination)
static T Abs(const T &x)
Definition: PndCAMath.h:39
std::vector< int > hitIDs
void AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
int counter
Definition: ZeeAnalysis.C:59
static T Min(const T &x, const T &y)
Definition: PndCAMath.h:35
Double_t
void refit(bool withErrorCalc=true)
Int_t GetTubeID() const
Definition: PndSttHit.h:75
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
TGeoCombiTrans * combi
ClassImp(PndSttCellTrackletGenerator)
PndRiemannTrack riemannTrack
#define END_TUBE_ID_SKEWED
double r() const
static T Max(const T &x, const T &y)
Definition: PndCAMath.h:36
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
Double_t x
TrackletInf_t GetTrackletInf(std::set< int > tracklets)
TVectorD orig() const
void addHit(PndRiemannHit &hit)
int count
CbmHit * hits[nHits]
Definition: RiemannTest.C:19
PndRiemannTrack CreateRiemannTrack(std::vector< int > hitIDs)
std::vector< PndRiemannHit > getHits() const
PndTrack getPndTrack(Double_t B)
double CalcDeviationOfRiemannTrack(PndRiemannTrack &track)