FairRoot/PandaRoot
PndSttCellTrackFinderData.cxx
Go to the documentation of this file.
1 /*
2  * PndSttCellTrackFinderData.cpp
3  *
4  *
5  * Created on: May 8, 2014
6  * Author: schumann
7  */
8 
9 #include "PndSttCellTrackFinderTask.h" // J.R. 20/04-2018
11 #include "PndSttStrawMap.h"
12 #include "PndSttGeometryMap.h"
13 #include "PndSttTube.h"
14 #include "PndSttHit.h"
15 #include "PndSttSkewedHit.h"
16 #include <cmath>
17 #include <stdio.h>
18 
19 //macro for printing tubes + neighbors to a file called tubeNeighborings.txt
20 //#define PRINT_STT_NEIGHBORS
21 
22 using namespace std;
23 
25 
27  TClonesArray* sttTubeArray):fAllowDoubleHits(kFALSE),fNumHits(0),fNumHitsWithoutDouble(0),fRunTimeBased(kFALSE){
28 
29  // Generate information of Straw- and GeometryMap.
30  // It is always the same data for all events.
31 
32  fStrawMap = new PndSttStrawMap(sttTubeArray);
33  fGeometryMap = new PndSttGeometryMap(sttTubeArray, 1);
34 
35  PndSttTube* tube;
36  TVector3 pos;
37 
38 #ifdef PRINT_STT_NEIGHBORS
39  TArrayI neighbors;
40  FILE* fp = fopen("tubeNeighborings.txt", "w");
41  int minNumNeigh=100, maxNumNeigh=0, numSkewed=0, numSkewedLessNeig=0;
42  bool skewed;
43 #endif
44 
45  for (int i = 1; i < sttTubeArray->GetEntriesFast(); ++i) {
46  tube = (PndSttTube*) sttTubeArray->At(i);
47  pos = tube->GetPosition();
49 
50 #ifdef PRINT_STT_NEIGHBORS
51  neighbors=fGeometryMap->GetNeighboringsByMap(tube->GetTubeID());
52  skewed=fGeometryMap->IsSkewedStraw(tube->GetTubeID());
53  if(skewed) ++numSkewed;
54  if(skewed && neighbors.GetSize()<7) ++numSkewedLessNeig;
55  fprintf(fp, "%d %4i:",skewed, tube->GetTubeID());
56  for(int j=0; j<neighbors.GetSize(); ++j) {
57  fprintf(fp, " %4i", neighbors[j]);
58  }
59  fprintf(fp, "\n");
60 
61  if(minNumNeigh>neighbors.GetSize()) minNumNeigh=neighbors.GetSize();
62  if(maxNumNeigh<neighbors.GetSize()) maxNumNeigh=neighbors.GetSize();
63 #endif
64  }
65 
66 #ifdef PRINT_STT_NEIGHBORS
67  fprintf(fp, "max/min number of neighbors: %3i / %3i\n", maxNumNeigh, minNumNeigh);
68  fprintf(fp, "number of skewed straws: %3i \n", numSkewed);
69  fprintf(fp, "number of skewed straws with less than 7 neighbors: %3i \n", numSkewedLessNeig);
70  fclose(fp);
71 #endif
72 
73 }
74 
75 void PndSttCellTrackFinderData::AddHits(TClonesArray* hits, TString branchName) {
76 
77  PndSttHit* myHit;
78  FairLink myID;
79  Int_t branchId = FairRootManager::Instance()->GetBranchId("STTHit");
80 // only STTHits are passed to this functions, but we have to check if SkewedHits are present.
81 
82  if (branchName.Contains("skewed", TString::kIgnoreCase)){
83  // I'm not sure if this part of the code really does what it should!
84  // since skewed straw tubes are not really used at the moment I can not tell.
85 
86  fCombinedSkewedHits.clear();
87 
88  for (int i = 0; i < hits->GetEntries(); i++) {
89  PndSttSkewedHit* skewedHit = (PndSttSkewedHit*) (hits->At(i));
90  int tubeId = skewedHit->GetTubeIDs().first;
91  fCombinedSkewedHits.insert(
92  std::pair<int, PndSttSkewedHit*>(tubeId, skewedHit));
93  if (skewedHit->GetEntryNr().GetIndex() < 0) {
94  myID = FairLink(branchId, i);
95  skewedHit->SetEntryNr(FairLink(branchId, i));
96  } else
97  myID = skewedHit->GetEntryNr();
98  }
99 
100  }
101  else { //"normal" stt htis are added to the Data map
102 
103  fMapHitToFairLinkOrig.clear();
104  fHitsOrig.clear();
105 
106  for (int i = 0; i < hits->GetEntries(); i++) {
107  myHit = (PndSttHit*) (hits->At(i));
108 
109  if (myHit->GetEntryNr().GetIndex() < 0) {
110  myID = FairLink(branchId, i);
111  myHit->SetEntryNr(FairLink(branchId, i));
112  } else
113  myID = myHit->GetEntryNr();
114  myHit->SetDxyz(myHit->GetIsochrone(), myHit->GetIsochrone(), 100);
115  fMapHitToFairLinkOrig[i] = myID;
116  fHitsOrig.push_back((FairHit*) myHit);
117  }
118  }
119 
120 }
121 
123 
124  //fill set with tubeIDs to remove double hits
125  int tubeId;
126  set<int> sttHits;
127  vector<FairHit*> hitsWithoutDouble;
128  map<int, FairLink> mapWithoutDouble;
129  int hitIndex=0;
130 
131  for(size_t i=0; i<fHitsOrig.size(); ++i){
132  tubeId=((PndSttHit*) fHitsOrig[i])->GetTubeID();
133  if(sttHits.find(tubeId)==sttHits.end()){
134  sttHits.insert(tubeId);
135  hitsWithoutDouble.push_back(fHitsOrig[i]);
136  mapWithoutDouble[hitIndex]=fMapHitToFairLinkOrig[i];
137  ++hitIndex;
138  }
139  }
140 
141  fNumHits=fHitsOrig.size();
142  fNumHitsWithoutDouble=sttHits.size();
143 
144  if (!fAllowDoubleHits) {
145  fHits = hitsWithoutDouble;
146  fMapHitToFairLink=mapWithoutDouble;
147 
148  } else {
149  fHits = fHitsOrig;
151  }
152 
153  PndSttHit* sttHit;
154  for (size_t i = 0; i < fHits.size(); ++i) {
155  sttHit = (PndSttHit*) fHits[i];
156 
157  fMapTubeIdToHit[sttHit->GetTubeID()] = i;
158  }
159 
160  if(fRunTimeBased == kFALSE) {
162  } else {
164  }
165 
167 }
168 
169 void PndSttCellTrackFinderData::FindHitNeighborsEventBased() { // if not def RunTimeBased
170 
171  /* Approach: At first create a set of the tubeIDs of all hits.
172  * Then get the neighbors of each hit/tube and store only those
173  * that are included in the set.*/
174 
175  PndSttHit* sttHit;
176  int tubeId;
177  set<int> hitIds;
178 
179  //initialize set with straw-ids of hits
180  for (size_t i = 0; i < fHits.size(); ++i) {
181  sttHit = (PndSttHit*) fHits[i];
182  hitIds.insert(sttHit->GetTubeID());
183  }
184 
185  //fill fHitNeighbors
186  for (size_t i = 0; i < fHits.size(); ++i) {
187  sttHit = (PndSttHit*) fHits[i];
188  tubeId = sttHit->GetTubeID();
189  //get neighbors
190  TArrayI neighbors = fGeometryMap->GetNeighboringsByMap(tubeId);
191 
192  for (int j = 0; j < neighbors.GetSize(); ++j) {
193 
194  //set contains neighbor?
195  if (hitIds.find(neighbors[j]) != hitIds.end()) {
196 
197  //add to map with all neighbors
198  fHitNeighbors[tubeId].push_back(neighbors[j]);
199 
200  //actual tube and neighbor are not both on the edge of the stt?
201  if (!(fStrawMap->IsEdgeStraw(tubeId)
202  && fStrawMap->IsEdgeStraw(neighbors[j]))) {
203 
204  //add to the other map
205  fHitNeighborsWithoutEdges[tubeId].push_back(neighbors[j]);
206  }
207  }
208  }
209 
210  if (fHitNeighbors.find(tubeId) == fHitNeighbors.end()) {
211  //no hitNeighbor was found
212  vector<int> tmp;
213  fHitNeighbors[tubeId] = tmp;
214  }
215 
216  if (fHitNeighborsWithoutEdges.find(tubeId)
217  == fHitNeighborsWithoutEdges.end()) {
218  //no hitNeighbor was found
219  vector<int> tmp;
220  fHitNeighborsWithoutEdges[tubeId] = tmp;
221  }
222 
223  if (!fStrawMap->IsSkewedStraw(tubeId)) {
224  for (int j = 0; j < neighbors.GetSize(); ++j) {
225  if (hitIds.find(neighbors[j]) != hitIds.end()
226  && !fStrawMap->IsSkewedStraw(neighbors[j])) {
227  fHitNeighborsWithoutSkewed[tubeId].push_back(neighbors[j]);
228  }
229  }
230  }
231  }
232 }
233 
235 
236  /* J.R. Adopted from PndSttCellTrackFinderData::FindHitNeighborsEventBased
237  * Added conditions to check timestamps and perform
238  * time clustering. 28/03-2018*/
239 
240  PndSttHit* sttHit;
241  int tubeId;
242  set<int> hitIds;
243 
244  // Time difference chosen since drift time of electrons is 200 ns so signals in neighboring subes can have tis delay
245  double sttHitTimeStamp; // J.R. 28/03-2018 // Timestamp of stt hit for time clustering
246  double sttNeighborTimeStamp; // J.R. 28/03-2018 // Timestamp of neighbor for time clustering
247 
248  //initialize set with straw-ids of hits
249  for (size_t i = 0; i < fHits.size(); ++i) {
250  sttHit = (PndSttHit*) fHits[i];
251 
252  hitIds.insert(sttHit->GetTubeID());
253  }
254 
255  //fill fHitNeighbors
256  for (size_t i = 0; i < fHits.size(); ++i) {
257 
258  sttHit = (PndSttHit*) fHits[i];
259  tubeId = sttHit->GetTubeID();
260 
261  //sttHitTimestamp=9999;
262  sttHitTimeStamp=sttHit->GetTimeStamp(); // JR 28/03-2018 // Timestamp for time clustering
263  sttNeighborTimeStamp=-9999; // JR 23/04-2018 // Timestamp for time clustering
264  //get neighbors
265  TArrayI neighbors = fGeometryMap->GetNeighboringsByMap(tubeId);
266 
267  for (int j = 0; j < neighbors.GetSize(); ++j) {
268 
269  //set contains neighbor?
270  if (hitIds.find(neighbors[j]) != hitIds.end()) {
271 
272  sttHit = (PndSttHit*) fHits[fMapTubeIdToHit[neighbors.At(j)]]; // J.R. 28/03-2018 // Get neighboring STT hit
273  sttNeighborTimeStamp = sttHit->GetTimeStamp();
274 
275  if(std::abs(sttHitTimeStamp - sttNeighborTimeStamp) < fClusterTime){ // J.R. 28/03-2018 // check difference in timestam [ns]
276 
277  fHitNeighbors[tubeId].push_back(neighbors.At(j)); // J.R. 28/03-2018 // add neighbor separately to set, not entire set of neighbors as obtained by SttGeometryMap
278  } // J.R. Difference timestamp end
279 
280  //actual tube and neighbor are not both on the edge of the stt?
281  if (!(fStrawMap->IsEdgeStraw(tubeId)
282  && fStrawMap->IsEdgeStraw(neighbors[j]))) {
283  if(std::abs(sttHitTimeStamp - sttNeighborTimeStamp) < fClusterTime){ // J.R. 28/03-2018 // check difference in timestam [ns]
284  //add to the other map
285  fHitNeighborsWithoutEdges[tubeId].push_back(neighbors.At(j));
286  } // J.R. Difference timestamp end
287  }
288  }
289  }
290 
291  if (fHitNeighbors.find(tubeId) == fHitNeighbors.end()) {
292  //no hitNeighbor was found
293  vector<int> tmp;
294  fHitNeighbors[tubeId] = tmp;
295  }
296 
297  if (fHitNeighborsWithoutEdges.find(tubeId)
298  == fHitNeighborsWithoutEdges.end()) {
299  //no hitNeighbor was found
300  vector<int> tmp;
301  fHitNeighborsWithoutEdges[tubeId] = tmp;
302  }
303 
304  if (!fStrawMap->IsSkewedStraw(tubeId)) {
305  for (int j = 0; j < neighbors.GetSize(); ++j) {
306  if (hitIds.find(neighbors[j]) != hitIds.end()
307  && !fStrawMap->IsSkewedStraw(neighbors[j])) {
308  // J.R. get neighbors to check timestamps
309 
310  sttHit = (PndSttHit*) fHits[fMapTubeIdToHit[neighbors.At(j)]]; // J.R. 28/03-2018 // Get neighboring STT hit
311  sttNeighborTimeStamp = sttHit->GetTimeStamp();
312 
313  if(std::abs(sttHitTimeStamp - sttNeighborTimeStamp) < fClusterTime){ // J.R. 28/03-2018 // check difference in timestam [ns]
314 
315  fHitNeighborsWithoutSkewed[tubeId].push_back(neighbors.At(j));
316  } // J.R. Difference timestamp end
317  }
318  }
319  }
320  }
321 }
322 
324 
325  /* Separate the hits/active cells concerning the number of neighbors that made a signal, too.*/
326 
327  map<int, vector<int> >::iterator it;
328 
329  for (int i = 0; i < 8; ++i) {
330  fSeparations[i].clear();
331  fSeparationsWithoutEdges[i].clear();
332  }
333 
334  for (it = fHitNeighbors.begin(); it != fHitNeighbors.end(); ++it) {
335 
336  if (it->second.size() > 6) {
337  // store cells with more than 6 neighbors in the same entry
338  fSeparations[7].push_back(it->first);
339  } else {
340  // separation concerning 0-6 hit-neighbors
341  fSeparations[it->second.size()].push_back(it->first);
342  }
343  }
344 
345  for (it = fHitNeighborsWithoutEdges.begin();
346  it != fHitNeighborsWithoutEdges.end(); ++it) {
347 
348  if (it->second.size() > 6) {
349  // store cells with more than 6 neighbors in the same entry
350  fSeparationsWithoutEdges[7].push_back(it->first);
351  } else {
352  // separation concerning 0-6 hit-neighbors
353  fSeparationsWithoutEdges[it->second.size()].push_back(it->first);
354  }
355  }
356 
357  for (it = fHitNeighborsWithoutSkewed.begin();
358  it != fHitNeighborsWithoutSkewed.end(); ++it) {
359 
360  if (it->second.size() > 6) {
361  // store cells with more than 6 neighbors in the same entry
362  fSeparationsWithoutSkewed[7].push_back(it->first);
363  } else {
364  // separation concerning 0-6 hit-neighbors
365  fSeparationsWithoutSkewed[it->second.size()].push_back(it->first);
366  }
367  }
368 }
369 
371  cout << "PndSttCellTrackFinderData::PrintInfo()" << endl;
372  cout << "#hits: " << fHits.size() << ", #unambiguous: "
373  << fSeparations[0].size() + fSeparations[1].size()
374  + fSeparations[2].size() << ", #ambiguous: "
375  << fSeparations[3].size() + fSeparations[4].size()
376  + fSeparations[5].size() + fSeparations[6].size()
377  + fSeparations[7].size() << endl;
378 
379  cout << "fHits (*-skewed): ";
380  int tubeID;
381  for (size_t i = 0; i < fHits.size(); ++i) {
382  tubeID = ((PndSttHit*) fHits.at(i))->GetTubeID();
383  cout << tubeID;
384  if (fStrawMap->IsSkewedStraw(tubeID))
385  cout << "*";
386  cout << ", ";
387  }
388  cout << endl;
389 
390  cout << "fSeparations: " << endl;
391  for (int i = 0; i < 8; ++i) {
392  cout << "#" << i << ": ";
393  for (size_t j = 0; j < fSeparations[i].size(); ++j) {
394  cout << fSeparations[i].at(j);
395  if (fStrawMap->IsSkewedStraw(tubeID))
396  cout << "*";
397  cout << ", ";
398  }
399  cout << endl;
400  }
401 
402  cout << "fHitNeighbors: " << endl;
403  for (map<int, vector<int> >::iterator it = fHitNeighbors.begin();
404  it != fHitNeighbors.end(); ++it) {
405  cout << it->first << ": ";
406  for (size_t i = 0; i < it->second.size(); ++i) {
407  cout << it->second.at(i) << " ";
408  }
409  cout << endl;
410  }
411 }
TVector3 pos
std::map< int, std::vector< int > > fHitNeighbors
Int_t i
Definition: run_full.C:25
PndTransMap * map
Definition: sim_emc_apd.C:99
std::map< int, std::vector< int > > fHitNeighborsWithoutSkewed
std::map< int, std::vector< int > > fHitNeighborsWithoutEdges
std::vector< FairHit * > fHits
std::map< int, FairLink > fMapHitToFairLink
std::map< int, std::vector< int > > fSeparationsWithoutEdges
Int_t GetTubeID()
Definition: PndSttTube.cxx:103
Double_t GetIsochrone() const
Definition: PndSttHit.h:62
std::multimap< int, PndSttSkewedHit * > fCombinedSkewedHits
bool IsSkewedStraw(int strawindex) const
TVector3 GetPosition()
Definition: PndSttTube.cxx:87
bool IsSkewedStraw(int strawindex) const
Int_t GetTubeID() const
Definition: PndSttHit.h:75
bool IsEdgeStraw(int strawindex) const
void AddHits(TClonesArray *hits, TString branchName)
PndSttCellTrackFinderData(TClonesArray *fTubeArray)
ClassImp(PndSttCellTrackFinderData)
std::vector< FairHit * > fHitsOrig
std::map< int, TVector3 > fMapTubeIdToPos
CbmHit * hits[nHits]
Definition: RiemannTest.C:19
std::map< int, std::vector< int > > fSeparations
std::map< int, std::vector< int > > fSeparationsWithoutSkewed
std::map< int, FairLink > fMapHitToFairLinkOrig
TArrayI GetNeighboringsByMap(int tubeId)
std::pair< Int_t, Int_t > GetTubeIDs() const