FairRoot/PandaRoot
PndFtsCellTrackletGenerator.cxx
Go to the documentation of this file.
1 /*
2  * PndFtsCellTrackletGenerator.cxx
3  *
4  * Created on: May 24, 2016
5  * Author: kibellus
6  */
7 
9 
10 //ClassImp(PndFtsCellTrackletGenerator);
11 
13  // TODO Auto-generated constructor stub
14 
15 }
16 
18  // TODO Auto-generated destructor stub
19 }
20 
22  fTracklets.clear();
23 }
24 
25 void PndFtsCellTrackletGenerator::setHits(std::vector<PndFtsHit*> hits) {
26  fHits = hits;
27 }
28 
30  std::cout << fHits.size() << " hits Found. " << std::endl;
31  map<Int_t, vector<PndFtsHit*>> splittedHits = splitLayers(fHits);
32  //first module
33  for(int i=0;i<4;i++)
34  findTracks(splittedHits,i);
35  //second module
36  for(int i=4;i<8;i++)
37  findTracks(splittedHits,i);
38  //third module
39  for(int i=8;i<12;i++)
40  findTracks(splittedHits,i);
41  //fourth module
42  for(int i=12;i<16;i++)
43  findTracks(splittedHits,i);
44  //fifth modules
45  for(int i=16;i<20;i++)
46  findTracks(splittedHits,i);
47  //sixth module
48  for(int i=20;i<24;i++)
49  findTracks(splittedHits,i);
50 }
51 
52 void PndFtsCellTrackletGenerator::findTracks(map<Int_t, vector<PndFtsHit*>> splittedHits, Int_t layer){
53  map<Int_t, PndTrackCand> tracks = FindTracklets(splittedHits[layer]);
54  typedef map<Int_t, PndTrackCand>::iterator iterator;
55  for(iterator it = tracks.begin();it!=tracks.end();it++){
56  fTracklets[layer].push_back(it->second);
57  }
58 }
59 
60 map<Int_t, vector<PndFtsHit*>> PndFtsCellTrackletGenerator::splitLayers(
61  vector<PndFtsHit*> hits) {
62  map<Int_t, vector<PndFtsHit*>> map;
63  for (size_t i = 0; i < hits.size(); i++) {
64  PndFtsHit* hit = fHits[i];
65  map[(hit->GetLayerID() - 1) / 2].push_back(hit);
66  }
67  return map;
68 }
69 
71  vector<PndFtsHit*> hits) {
72  //typedef std::map<Int_t, vector<Int_t> >::iterator it_type; //[R.K.03/2017] unused typedef
73  typedef std::map<Int_t, Int_t>::iterator it_type2;
74  map<Int_t, Int_t> states;
75  map<Int_t, PndFtsHit*> hitMap;
76  map<Int_t, vector<Int_t> > neighbors = getNeighbors(hits);
77  //create state Map
78  for (size_t i = 0; i < hits.size(); i++) {
79  PndFtsHit* hit = hits[i];
80  states[hit->GetTubeID()] = hit->GetTubeID();
81  hitMap[hit->GetTubeID()] = hit;
82  }
83 
84  //run the cellular automaton
85  Bool_t changes = kTRUE;
86  while (changes) {
87  changes = kFALSE;
88  //for all hits
89  for (it_type2 it = states.begin(); it != states.end(); it++) {
90  //for all neighbors
91  vector<int> hitNeighbors = neighbors[it->second];
92  for (size_t i = 0; i < hitNeighbors.size(); i++) {
93  Int_t state1 = states[it->first];
94  Int_t state2 = states[hitNeighbors[i]];
95  if (state1 != state2) {
96  changes = kTRUE;
97  Int_t min = std::min(state1, state2);
98  states[it->first] = min;
99  states[hitNeighbors[i]] = min;
100  }
101  }
102  }
103  }
104 
105  //create the TrackCands
106  map<Int_t, PndTrackCand> result;
107  for (it_type2 it = states.begin(); it != states.end(); it++) {
108  Int_t hitNumber = result[it->second].GetNHits()+1;
109  result[it->second].AddHit(hitMap[it->first]->GetEntryNr(),hitNumber);
110  }
111 
112  return result;
113 }
114 
115 map<Int_t, vector<Int_t> > PndFtsCellTrackletGenerator::getNeighbors(
116  vector<PndFtsHit*> hits) {
117  map<Int_t, vector<Int_t> > neighbors;
118  for (size_t i = 0; i < hits.size(); i++) {
119  PndFtsHit* hit1 = hits[i];
120  transform(kTRUE,hit1);
121  for (size_t j = i + 1; j < hits.size(); j++) {
122  PndFtsHit* hit2 = hits[j];
123  transform(kTRUE,hit2);
124  TVector3 p1;
125  hit1->Position(p1);
126  TVector3 p2;
127  hit2->Position(p2);
128  TVector3 diff = p1 - p2;
129  Double_t norm = TMath::Sqrt(diff.X()*diff.X()+diff.Z()*diff.Z());
130  Double_t limit = 1.2;
131  //if(hit1->GetSkewed()) limit=1.5;
132  if (norm < limit) { //are neighbors?
133  neighbors[hit1->GetTubeID()].push_back(hit2->GetTubeID());
134  neighbors[hit2->GetTubeID()].push_back(hit1->GetTubeID());
135  }
136  transform(kTRUE,hit2);
137  }
138  transform(kFALSE,hit1);
139  }
140  return neighbors;
141 }
142 
144  TMatrix a(3,3);
145  a[0][0] = TMath::Cos(angle);
146  a[0][1] = -TMath::Sin(angle);
147  a[0][2] = 0;
148  a[1][0] = TMath::Sin(angle);
149  a[1][1] = TMath::Cos(angle);
150  a[1][2] = 0;
151  a[2][0] = 0;
152  a[2][1] = 0;
153  a[2][2] = 1;
154  return a;
155 }
156 
158  Double_t angle = 0;
159  if(((hit->GetLayerID() - 1) / 2)%4==1) angle = -5;
160  if(((hit->GetLayerID() - 1) / 2)%4==2) angle = 5;
161  if(angle==0) return;
162  if(!transToNewSystem) angle*=-1;
163  TMatrix rotMat = getRotationMatrix(angle*TMath::DegToRad());
164  TMatrix hitMat(3,1);
165  hitMat[0][0] = hit->GetX();
166  hitMat[1][0] = hit->GetY();
167  hitMat[2][0] = hit->GetZ();
168  TMatrix newPos = rotMat*hitMat;
169  hit->SetXYZ(newPos[0][0],newPos[1][0],newPos[2][0]);
170 }
void setHits(std::vector< PndFtsHit * > hits)
map< Int_t, PndTrackCand > FindTracklets(vector< PndFtsHit * > hits)
Int_t i
Definition: run_full.C:25
PndTransMap * map
Definition: sim_emc_apd.C:99
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
map< Int_t, std::vector< Int_t > > getNeighbors(vector< PndFtsHit * > hits)
static T Sin(const T &x)
Definition: PndCAMath.h:42
labels push_back("electron")
static T Cos(const T &x)
Definition: PndCAMath.h:43
Int_t GetTubeID() const
Definition: PndFtsHit.h:70
Int_t GetLayerID() const
Definition: PndFtsHit.h:74
Int_t a
Definition: anaLmdDigi.C:126
Double_t
map< Int_t, vector< PndTrackCand > > fTracklets
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
TPad * p2
Definition: hist-t7.C:117
map< Int_t, vector< PndFtsHit * > > splitLayers(vector< PndFtsHit * > hits)
std::vector< PndFtsHit * > fHits
Int_t layer
Definition: reco_muo.C:36
TPad * p1
Definition: hist-t7.C:116
PndSdsMCPoint * hit
Definition: anasim.C:70
CbmHit * hits[nHits]
Definition: RiemannTest.C:19
Double_t angle
double limit
Definition: dedx_bands.C:18
void transform(Bool_t transToNewSystem, PndFtsHit *hit)