ATLAS Offline Software
Functions | Variables
FPGATrackSimHoughFunctions.cxx File Reference
#include "FPGATrackSimHough/FPGATrackSimHoughFunctions.h"
#include "FPGATrackSimObjects/FPGATrackSimFunctions.h"
#include <stdexcept>
#include <AsgMessaging/MessageCheck.h>
Include dependency graph for FPGATrackSimHoughFunctions.cxx:

Go to the source code of this file.

Functions

StatusCode runOverlapRemoval (std::vector< FPGATrackSimTrack > &tracks, const float minChi2, const int NumOfHitPerGrouping, ORAlgo orAlgo, ToolHandle< GenericMonitoringTool > &monTool, bool compareAllHits)
 
int findNonOverlapHits (const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
 
void findMinChi2MaxHit (const std::vector< int > &duplicates, std::vector< FPGATrackSimTrack > &RMtracks, std::vector< int > flags_OR, const float minChi2)
 
int findNCommonHits_v2 (const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
 
int findNCommonHitsGlobal (const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
 
int findNCommonHits (const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
 
void getMissingInfo (const FPGATrackSimRoad &road, int &nMissing, bool &missPixel, bool &missStrip, layer_bitmask_t &missing_mask, layer_bitmask_t &norecovery_mask, const ServiceHandle< IFPGATrackSimMappingSvc > &FPGATrackSimMapping, const TrackCorrType idealCoordFitType)
 
void makeTrackCandidates (const FPGATrackSimRoad &road, const FPGATrackSimTrack &temp, std::vector< FPGATrackSimTrack > &track_cands, const ServiceHandle< IFPGATrackSimMappingSvc > &FPGATrackSimMapping)
 Creates a list of track candidates by taking all possible combination of hits in road. More...
 
long getVolumeID (const FPGATrackSimHit &hit)
 
long getCoarseID (const FPGATrackSimHit &hit)
 
bool isFineIDInStrip (long ID)
 
bool isFineIDInPixel (long ID)
 
long getFineID (const FPGATrackSimHit &hit)
 
void roadsToTrack (std::vector< std::shared_ptr< const FPGATrackSimRoad >> &roads, std::vector< FPGATrackSimTrack > &track_cands, const FPGATrackSimPlaneMap *pmap)
 

Variables

constexpr float EPSILON = 1e-5
 

Function Documentation

◆ findMinChi2MaxHit()

void findMinChi2MaxHit ( const std::vector< int > &  duplicates,
std::vector< FPGATrackSimTrack > &  RMtracks,
std::vector< int >  flags_OR,
const float  minChi2 
)

Definition at line 190 of file FPGATrackSimHoughFunctions.cxx.

191 {
192  int ntr_belowMinChi2 = 0;
193  std::vector<int> track_counter;
194 
195  for(unsigned int i=0; i<RMtracks.size();i++)
196  {
197  if(RMtracks.at(i).getChi2ndof() > minChi2) {
198  track_counter.push_back(0);
199  flags_OR.push_back(-1);
200  continue;
201  }
202  ntr_belowMinChi2++;
203  track_counter.push_back(ntr_belowMinChi2);
204  flags_OR.push_back(1);
205  }
206 
207  int dup_counter = 0;
208  int head_track = 1;
209  float head_chi2 = 0.;
210  int head_nhits = 0;
211 
212  for(auto dup: duplicates)
213  {
214  float t_chi2 = RMtracks.at(dup).getChi2ndof();
215  int t_nhitlayers = RMtracks.at(dup).getFPGATrackSimHits().size();
216  for(auto& hit : RMtracks.at(dup).getFPGATrackSimHits())
217  {
218  ANA_MSG_DEBUG("Real hit info = " << hit);
219  ANA_MSG_DEBUG("Real hit info (global) = Gphi= " << hit.getGPhi() << " Z=" << hit.getZ() << " R=" << hit.getR() << " chi2=" << t_chi2);
220 
221  if(!hit.isReal())
222  {
223  t_nhitlayers--;
224  }
225  }
226  if (dup_counter == 0) {
227  head_track = dup;
228  head_chi2 = RMtracks.at(head_track).getChi2ndof();
229  head_nhits = t_nhitlayers;
230  }
231  if (dup_counter > 0){
232  if(t_nhitlayers>head_nhits)
233  {
234  RMtracks.at(head_track).setPassedOR(0);
235  }
236  else if(t_nhitlayers==head_nhits)
237  {
238  if((head_chi2-t_chi2)>0.000001)
239  {
240  RMtracks.at(head_track).setPassedOR(0);
241  }
242  if(std::abs(t_chi2-head_chi2)<0.000001)
243  {
244  if(track_counter[head_track] < track_counter[dup]) {
245  RMtracks.at(dup).setPassedOR(0);
246  }
247  if(track_counter[head_track] > track_counter[dup]) {
248  RMtracks.at(head_track).setPassedOR(0);
249  }
250  }
251  }
252  }
253 
254  if(!RMtracks.at(head_track).passedOR()) flags_OR[head_track] = 0;
255  if(RMtracks.at(head_track).passedOR()) flags_OR[head_track] = 1;
256  dup_counter++;
257 
258  }
259 }

◆ findNCommonHits()

int findNCommonHits ( const FPGATrackSimTrack Track1,
const FPGATrackSimTrack Track2 
)

Definition at line 352 of file FPGATrackSimHoughFunctions.cxx.

353 {
354  int nCommHits=0;
355 
356  // Loop through all layers
357  for(unsigned int i = 0; i < Track1.getFPGATrackSimHits().size(); ++i)
358  {
359  const FPGATrackSimHit& hit1 = Track1.getFPGATrackSimHits().at(i);
360  const FPGATrackSimHit& hit2 = Track2.getFPGATrackSimHits().at(i);
361 
362  // Check if hit is missing
363  if(!hit1.isReal() || !hit2.isReal())
364  {
365  continue;
366  }
367  // Check if hit on the same plane
368  else if(hit1.getLayer() != hit2.getLayer())
369  {
370  continue;
371  }
372  // Check if two hits have the same hashID
373  else if(hit1.getIdentifierHash() != hit2.getIdentifierHash())
374  {
375  continue;
376  }
377  // Check if two hits have same coordinate. this is difficult due to spacepoints,
378  // since the same hit can be used to make multiple spacepoints.
379  else if (hit1.getHitType() == HitType::spacepoint && hit2.getHitType() == HitType::spacepoint) {
380 
381  if ((std::abs(hit1.getX() - hit2.getX()) < EPSILON) && (std::abs(hit1.getY() - hit2.getY()) < EPSILON) && (std::abs(hit1.getZ() - hit2.getZ()) < EPSILON)) {
382  nCommHits++;
383  } else {
384  continue;
385  }
386  }
387  // If both hits aren't spacepoints, we should be able to do this comparison.
388  else if (std::abs(hit1.getGPhi()-hit2.getGPhi())<0.001 && std::abs(hit1.getZ()-hit2.getZ())<0.001 && std::abs(hit1.getR()-hit2.getR())<0.001) {
389  nCommHits++;
390  }
391  else
392  {
393  continue;
394  }
395  }
396  return nCommHits;
397 }

◆ findNCommonHits_v2()

int findNCommonHits_v2 ( const FPGATrackSimTrack Track1,
const FPGATrackSimTrack Track2 
)

Definition at line 261 of file FPGATrackSimHoughFunctions.cxx.

262 {
263  int nCommHits = 0;
264  std::vector<bool> hit2_matched(Track2.getFPGATrackSimHits().size(), false);
265 
266  for (const auto& hit1 : Track1.getFPGATrackSimHits())
267  {
268  for (size_t j = 0; j < Track2.getFPGATrackSimHits().size(); ++j)
269  {
270  const auto& hit2 = Track2.getFPGATrackSimHits()[j];
271 
272  if (hit2_matched[j]) continue; // already used this hit
273  else if (!hit1.isReal() || !hit2.isReal()) continue; // Check if hit is missing
274  else if (hit1.getLayer() != hit2.getLayer()) continue; // Check if hit on the same plane
275  else if (hit1.getIdentifierHash() != hit2.getIdentifierHash()) continue; // Check if two hits have the same hashID
276 
277  // Check if two hits have same coordinate. this is difficult due to spacepoints,
278  // since the same hit can be used to make multiple spacepoints.
279  else if (hit1.getHitType() == HitType::spacepoint && hit2.getHitType() == HitType::spacepoint)
280  {
281  if (std::abs(hit1.getX() - hit2.getX()) < EPSILON &&
282  std::abs(hit1.getY() - hit2.getY()) < EPSILON &&
283  std::abs(hit1.getZ() - hit2.getZ()) < EPSILON)
284  {
285  nCommHits++;
286  hit2_matched[j] = true;
287  break;
288  }
289  }
290 
291  // If both hits aren't spacepoints, we should be able to do this comparison.
292  else if (std::abs(hit1.getGPhi() - hit2.getGPhi()) < 0.001 &&
293  std::abs(hit1.getZ() - hit2.getZ()) < 0.001 &&
294  std::abs(hit1.getR() - hit2.getR()) < 0.001)
295  {
296  nCommHits++;
297  hit2_matched[j] = true;
298  break;
299  }
300  }
301  }
302 
303  return nCommHits;
304 }

◆ findNCommonHitsGlobal()

int findNCommonHitsGlobal ( const FPGATrackSimTrack Track1,
const FPGATrackSimTrack Track2 
)

Definition at line 307 of file FPGATrackSimHoughFunctions.cxx.

308 {
309  int nCommHits = 0;
310  std::vector<bool> hit2_matched(Track2.getFPGATrackSimHits().size(), false);
311 
312  for (const auto& hit1 : Track1.getFPGATrackSimHits())
313  {
314  for (size_t j = 0; j < Track2.getFPGATrackSimHits().size(); ++j)
315  {
316  const auto& hit2 = Track2.getFPGATrackSimHits()[j];
317 
318  if (hit2_matched[j]) continue; // already used this hit
319  else if (!hit1.isReal() || !hit2.isReal()) continue; // Check if hit is missing
320  else if (hit1.getLayer() != hit2.getLayer()) continue; // Check if hit on the same plane
321  else if (hit1.getIdentifierHash() != hit2.getIdentifierHash()) continue; // Check if two hits have the same hashID
322 
323  // Check if two hits have same coordinate. this is difficult due to spacepoints,
324  // since the same hit can be used to make multiple spacepoints.
325  else if (hit1.getHitType() == HitType::spacepoint && hit2.getHitType() == HitType::spacepoint)
326  {
327  if (std::abs(hit1.getX() - hit2.getX()) < EPSILON &&
328  std::abs(hit1.getY() - hit2.getY()) < EPSILON &&
329  std::abs(hit1.getZ() - hit2.getZ()) < EPSILON)
330  {
331  nCommHits++;
332  hit2_matched[j] = true;
333  break;
334  }
335  }
336 
337  // If both hits aren't spacepoints, we should be able to do this comparison.
338  else if (std::abs(hit1.getGPhi() - hit2.getGPhi()) < EPSILON &&
339  std::abs(hit1.getZ() - hit2.getZ()) < EPSILON &&
340  std::abs(hit1.getR() - hit2.getR()) < EPSILON)
341  {
342  nCommHits++;
343  hit2_matched[j] = true;
344  break;
345  }
346  }
347  }
348 
349  return nCommHits;
350 }

◆ findNonOverlapHits()

int findNonOverlapHits ( const FPGATrackSimTrack Track1,
const FPGATrackSimTrack Track2 
)

Definition at line 144 of file FPGATrackSimHoughFunctions.cxx.

145 {
146  int nonOverlapHits=0;
147 
148  // Loop through all layers
149  for(unsigned int i = 0; i < Track1.getFPGATrackSimHits().size(); ++i)
150  {
151  const FPGATrackSimHit& hit1 = Track1.getFPGATrackSimHits().at(i);
152  const FPGATrackSimHit& hit2 = Track2.getFPGATrackSimHits().at(i);
153  // First make sure we are looking at real hits
154  if(!hit1.isReal() || !hit2.isReal())
155  {
156  continue;
157  }
158  // Check if two hits are on the same plane
159  else if(hit1.getLayer() != hit2.getLayer())
160  {
161  nonOverlapHits++;
162  }
163  // Check if two hits have the same hashID
164  else if(hit1.getIdentifierHash() != hit2.getIdentifierHash())
165  {
166  nonOverlapHits++;
167  }
168  // Check if two hits have same coordinate. this is difficult due to spacepoints,
169  // since the same hit can be used to make multiple spacepoints.
170  else if (hit1.getHitType() == HitType::spacepoint && hit2.getHitType() == HitType::spacepoint) {
171  if ((abs(hit1.getX() - hit2.getX()) > EPSILON) || (abs(hit1.getY() - hit2.getY()) < EPSILON) || (abs(hit1.getZ() - hit2.getZ()) < EPSILON)) {
172  nonOverlapHits++;
173  } else {
174  continue;
175  }
176  }
177  else if (std::abs(hit1.getGPhi()-hit2.getGPhi())>0.001 && std::abs(hit1.getZ()-hit2.getZ())>0.001 && std::abs(hit1.getR()-hit2.getR())>0.001)
178  {
179  nonOverlapHits++;
180  }
181  else
182  {
183  continue;
184  }
185  }
186  return nonOverlapHits;
187 }

◆ getCoarseID()

long getCoarseID ( const FPGATrackSimHit hit)

Definition at line 587 of file FPGATrackSimHoughFunctions.cxx.

588 {
589  // Custom labelling for the detector layers
590  // to be used in NN training.
591  // This aims at providing a continuous numbering according to this convention:
592  // strip barrel layers in [0,3]
593  // strip C-side end cap layers in [4,9]
594  // strip A-side end cap layers in [10,15]
595  // pixel barrel layers in [16,20]
596  // pixel C-side end cap layers in [21,29]
597  // pixel A-side end cap layers > 30
598  // returns large negative value if no layer
599 
600  long volumeID = getVolumeID(hit);
601  unsigned layerID = hit.getLayerDisk(true);
602 
603  long offset = -10000;
604 
605  if(volumeID == 10) offset = 0; //strip barrel
606  if(volumeID == 8) offset = 4; //strip -ve EC
607  if(volumeID == 12) offset = 10; //strip +ve EC
608  if(volumeID == 0) offset = 16; // pix barrel
609  if(volumeID == -2) offset = 21; //pix -ve EC
610  if(volumeID == 2) offset = 30; //pix +ve EC
611  return offset + layerID;
612 }

◆ getFineID()

long getFineID ( const FPGATrackSimHit hit)

Definition at line 624 of file FPGATrackSimHoughFunctions.cxx.

625 {
626  // Custom labelling for the detector layers
627  // to be used in NN training.
628  // Returns a labelling of non-barrel pixel hits similar to a hit's eta index,
629  // but with a continuous numbering.
630  // Otherwise return convention defined in getCoarseID.
631 
632  long volumeID = getVolumeID(hit);
633  unsigned layerID = hit.getLayerDisk(true);
634  int etaID = hit.getEtaModule(true);
635 
636  long offset = -1000;
637 
638  if(volumeID == 10) return getCoarseID(hit); //strip barrel
639  if(volumeID == 8) return getCoarseID(hit); //strip -ve EC
640  if(volumeID == 12) return getCoarseID(hit); //strip +ve EC
641  if(volumeID == 0) return getCoarseID(hit); //pix barrel
642  if(volumeID == -999) return -999; //hit not in any physical layer
643  if(volumeID == -2)
644  {
645  if(layerID == 0) offset = 21;
646  if(layerID == 1) offset = 21+15;
647  if(layerID == 2) offset = 21+15+6;
648  if(layerID == 3) offset = 21+15+6+23;
649  if(layerID == 4) offset = 21+15+6+23+6;
650  if(layerID == 5) offset = 21+15+6+23+6+11;
651  if(layerID == 6) offset = 21+15+6+23+6+11+8;
652  if(layerID == 7) offset = 21+15+6+23+6+11+8+8;
653  if(layerID == 8) offset = 21+15+6+23+6+11+8+8+9;
654  return offset + etaID;
655  }
656  if(volumeID == 2)
657  {
658  if(layerID == 0) offset = 116;
659  if(layerID == 1) offset = 116+15;
660  if(layerID == 2) offset = 116+15+6;
661  if(layerID == 3) offset = 116+15+6+23;
662  if(layerID == 4) offset = 116+15+6+23+6;
663  if(layerID == 5) offset = 116+15+6+23+6+11;
664  if(layerID == 6) offset = 116+15+6+23+6+11+8;
665  if(layerID == 7) offset = 116+15+6+23+6+11+8+8;
666  if(layerID == 8) offset = 116+15+6+23+6+11+8+8+9;
667  return offset + etaID;
668  }
669 
670  return -1;
671 }

◆ getMissingInfo()

void getMissingInfo ( const FPGATrackSimRoad road,
int &  nMissing,
bool &  missPixel,
bool &  missStrip,
layer_bitmask_t missing_mask,
layer_bitmask_t norecovery_mask,
const ServiceHandle< IFPGATrackSimMappingSvc > &  FPGATrackSimMapping,
const TrackCorrType  idealCoordFitType 
)

Definition at line 401 of file FPGATrackSimHoughFunctions.cxx.

402 {
403  int subregion = road.getSubRegion();
404  nMissing = FPGATrackSimMapping->PlaneMap_1st(subregion)->getNCoords(); // init with nCoords and decrement as we find misses
405  missPixel = false;
406  missStrip = false;
407  missing_mask = 0;
408  norecovery_mask = 0;
409  unsigned int wclayers = road.getWCLayers();
410  for (unsigned layer = 0; layer < FPGATrackSimMapping->PlaneMap_1st(subregion)->getNLogiLayers(); layer++)
411  {
412  int nHits = road.getHits(layer).size();
413  if (nHits==0)
414  {
415  if (idealCoordFitType == TrackCorrType::None && ((wclayers >> layer) & 1))
416  {
417  int ix = FPGATrackSimMapping->PlaneMap_1st(subregion)->getCoordOffset(layer);
418  int iy = ix + 1;
419  if (FPGATrackSimMapping->PlaneMap_1st(subregion)->isSCT(layer))
420  {
421  missing_mask |= 1 << ix;
422  nMissing -= 1;
423  }
424  else
425  {
426  missing_mask |= (1<<ix) | (1<<iy);
427  nMissing -= 2;
428  }
429  }
430  else
431  {
432  if (FPGATrackSimMapping->PlaneMap_1st(subregion)->isSCT(layer)) missStrip = true;
433  else missPixel = true;
434  }
435  }
436  else if (!((wclayers >> layer) & 1)) { // we have a hit
437  int ix = FPGATrackSimMapping->PlaneMap_1st(subregion)->getCoordOffset(layer);
438  int iy = ix + 1;
439  if (FPGATrackSimMapping->PlaneMap_1st(subregion)->isSCT(layer))
440  {
441  missing_mask |= 1 << ix;
442  nMissing -= 1;
443  }
444  else
445  {
446  missing_mask |= (1<<ix) | (1<<iy);
447  nMissing -= 2;
448  }
449 
450  }
451  }
452 }

◆ getVolumeID()

long getVolumeID ( const FPGATrackSimHit hit)

Definition at line 532 of file FPGATrackSimHoughFunctions.cxx.

533 {
534  // Custom labelling for the detector volumes
535  // to be used in NN training.
536  // Convention:
537  // barrel | else
538  //-------------------------------------
539  // Pixel | 0 | 2*sign(z)
540  // Strip | 10 | 10 + 2*sign(z)
541  //
542  // Explicitly:
543  // -2: C-side (-z) end cap pixel
544  // 0: barrel pixel
545  // 2: A-side (+z) end cap pixel
546  // 8: C-side end cap strip
547  // 10: barrel strip
548  // 12: A-sde end cap strip
549  // returns -999 if not a real hit
550 
551 
552  long volumeID = -1;
553 
554  if (hit.getR() == 0.0) {
555  return -999; //hit not in any physical layer
556  }
557 
558  if(hit.isBarrel()) {
559  if (hit.isPixel()) {
560  volumeID = 0;
561  }
562  if (hit.isStrip()) {
563  volumeID = 10;
564  }
565  }
566  else {
567  if (hit.isPixel()) {
568  if (hit.getZ() >= 0.) {
569  volumeID = 2;
570  }
571  else {
572  volumeID = -2;
573  }
574  }
575  else if (hit.isStrip()) {
576  if (hit.getZ() >= 0.) {
577  volumeID = 12;
578  }
579  else {
580  volumeID = 8;
581  }
582  }
583  }
584  return volumeID;
585 }

◆ isFineIDInPixel()

bool isFineIDInPixel ( long  ID)

Definition at line 619 of file FPGATrackSimHoughFunctions.cxx.

620 {
621  return !isFineIDInStrip(ID);
622 }

◆ isFineIDInStrip()

bool isFineIDInStrip ( long  ID)

Definition at line 614 of file FPGATrackSimHoughFunctions.cxx.

615 {
616  return (ID < 16);
617 }

◆ makeTrackCandidates()

void makeTrackCandidates ( const FPGATrackSimRoad road,
const FPGATrackSimTrack temp,
std::vector< FPGATrackSimTrack > &  track_cands,
const ServiceHandle< IFPGATrackSimMappingSvc > &  FPGATrackSimMapping 
)

Creates a list of track candidates by taking all possible combination of hits in road.

Sets basic ID info and hits.

NB: If the number of combinations becomes large and memory is a concern, it may be worth turning this function into a sort of iterator over combs, return a single track each call.

Definition at line 463 of file FPGATrackSimHoughFunctions.cxx.

464 {
465  int idbase = 0; // offset for new track ids
466  int subregion = road.getSubRegion();
467  auto pmap = FPGATrackSimMapping->PlaneMap_2nd(subregion);
468 
469  if (temp.getTrackStage() == TrackStage::FIRST) {
470  pmap = FPGATrackSimMapping->PlaneMap_1st(subregion);
471  }
472 
473  std::vector<std::vector<int>> combs = ::getComboIndices(road.getNHits_layer());
474  track_cands.resize(combs.size(), temp);
475 
476  const FPGATrackSimRegionMap* SUBREGIONMAP = FPGATrackSimMapping->SubRegionMap_2nd();
477  //
478  //get the WC hits:
479  layer_bitmask_t wcbits= road.getWCLayers();
480  // Add the hits from each combination to the track, and set ID
481  for (size_t icomb = 0; icomb < combs.size(); icomb++)
482  {
483  //Need to set the ID and the hits size of this track
484  track_cands[icomb].setTrackID(idbase + icomb);
485  track_cands[icomb].setNLayers(pmap->getNLogiLayers());
486 
487  // If this is an idealized coordinate fit; keep references to the idealized radii.
488  track_cands[icomb].setIdealRadii(SUBREGIONMAP->getAvgRadii(subregion));
489  track_cands[icomb].setPassedOR(1);
490 
491  std::vector<int> const & hit_indices = combs[icomb]; // size nLayers
492  for (unsigned layer = 0; layer < pmap->getNLogiLayers(); layer++)
493  {
494  if (hit_indices[layer] < 0) // Set a dummy hit if road has no hits in this layer
495  {
497  newhit.setLayer(layer);
498  newhit.setSection(0);
499  if (pmap->getDim(layer) == 2) newhit.setDetType(SiliconTech::pixel);
500  else newhit.setDetType(SiliconTech::strip);
501 
502  if (wcbits & (1 << layer ) ) {
504  newhit.setLayer(layer);
505  }
506 
507  track_cands[icomb].setFPGATrackSimHit(layer, newhit);
508  }
509  else
510  {
511  const std::shared_ptr<const FPGATrackSimHit> hit = road.getHits(layer)[hit_indices[layer]];
512  // If this is an outer spacepoint, and it is not the same as the inner spacepoint, reject it.
513  // Here we "reject" it by marking the candidate as "invalid", to be rejected later.
514  // That require another field on the track object, but it avoids having to change the sizes
515  // of arrays computed above.
516  if (hit->getHitType() == HitType::spacepoint && (hit->getPhysLayer(true) % 2) == 1) {
517  if (layer == 0) throw (std::out_of_range("makeTrackCandidates: Attempt to access vector at element -1"));
518  const FPGATrackSimHit & inner_hit = track_cands[icomb].getFPGATrackSimHits().at(layer - 1);
519  if ((abs(hit->getX() - inner_hit.getX()) > EPSILON) || (abs(hit->getY() - inner_hit.getY()) > EPSILON) || (abs(hit->getZ() - inner_hit.getZ()) > EPSILON)) {
520  track_cands[icomb].setValidCand(false);
521  }
522  }
523  track_cands[icomb].setFPGATrackSimHit(layer, *hit);
524  }
525  }
526  }
527 
528  idbase += combs.size();
529 }

◆ roadsToTrack()

void roadsToTrack ( std::vector< std::shared_ptr< const FPGATrackSimRoad >> &  roads,
std::vector< FPGATrackSimTrack > &  track_cands,
const FPGATrackSimPlaneMap pmap 
)

Definition at line 674 of file FPGATrackSimHoughFunctions.cxx.

675 {
676 
677 
678  for (const std::shared_ptr<const FPGATrackSimRoad>& road : roads) {
679 
681  temp.setNLayers(pmap->getNLogiLayers());
682  temp.setBankID(-1);
683  temp.setPatternID(road->getPID());
684  temp.setHoughX(road->getX());
685  temp.setHoughY(road->getY());
686  temp.setQOverPt(road->getY());
687 
688  temp.setSubRegion(road->getSubRegion());
689  temp.setHoughXBin(road->getXBin());
690  temp.setHoughYBin(road->getYBin());
691  temp.setChi2(0);
692 
693  // This comes from FPGATrackSimFunctions
694  std::vector<std::vector<int>> combs = getComboIndices(road->getNHits_layer());
695  unsigned existing_size = track_cands.size();
696  track_cands.resize(existing_size + combs.size(), temp);
697 
698  //get the WC hits:
699  layer_bitmask_t wcbits= road->getWCLayers();
700  // Add the hits from each combination to the track, and set ID
701  for (size_t icomb = 0; icomb < combs.size(); icomb++)
702  {
703  if ((existing_size + icomb) >= track_cands.size()) continue;
704  track_cands[existing_size + icomb].setNLayers(pmap->getNLogiLayers());
705  std::vector<int> const & hit_indices = combs[icomb]; // size nLayers
706  for (unsigned layer = 0; layer < pmap->getNLogiLayers(); layer++)
707  {
708  if (hit_indices[layer] < 0) // Set a dummy hit if road has no hits in this layer
709  {
711  newhit.setLayer(layer);
712  newhit.setSection(0);
713  if (pmap->getDim(layer) == 2) newhit.setDetType(SiliconTech::pixel);
714  else newhit.setDetType(SiliconTech::strip);
715 
716  if (wcbits & (1 << layer ) ) {
718  newhit.setLayer(layer);
719  }
720 
721  track_cands[existing_size + icomb].setFPGATrackSimHit(layer, newhit);
722  }
723  else
724  {
725  const std::shared_ptr<const FPGATrackSimHit> hit = road->getHits(layer)[hit_indices[layer]];
726  // If this is an outer spacepoint, and it is not the same as the inner spacepoint, reject it.
727  // Here we "reject" it by marking the candidate as "invalid", to be rejected later.
728  // That require another field on the track object, but it avoids having to change the sizes
729  // of arrays computed above.
730  if (hit->getHitType() == HitType::spacepoint && (hit->getPhysLayer() % 2) == 1 && (layer>0)) {
731  const FPGATrackSimHit inner_hit = track_cands[existing_size + icomb].getFPGATrackSimHits().at(layer - 1);
732  if ((hit->getX() != inner_hit.getX()) || (hit->getY() != inner_hit.getY()) || (hit->getZ() != inner_hit.getZ())) {
733  track_cands[existing_size + icomb].setValidCand(false);
734  }
735  }
736  track_cands[existing_size + icomb].setFPGATrackSimHit(layer, *hit);
737  }
738  }
739  }
740  }
741 }

◆ runOverlapRemoval()

StatusCode runOverlapRemoval ( std::vector< FPGATrackSimTrack > &  tracks,
const float  minChi2,
const int  NumOfHitPerGrouping,
ORAlgo  orAlgo,
ToolHandle< GenericMonitoringTool > &  monTool,
bool  compareAllHits 
)

Definition at line 15 of file FPGATrackSimHoughFunctions.cxx.

16 {
17  ANA_MSG_DEBUG("Beginning runOverlapRemoval()");
18  ANA_MSG_DEBUG("Tracks in event: " << tracks.size());
19 
20  std::vector<int> flags_OR;
21  flags_OR.clear();
22 
23  // Debug variables
24  int ntrack_passOR = 0;
25  int ntrack = 0;
26  std::vector<int> track_passOR_counter;
27  std::vector<int> track_passOR_barcodefrac;
28  track_passOR_counter.clear();
29  track_passOR_barcodefrac.clear();
30  int track_barcodefrac_num;
31  int track_barcodefrac_den;
32  float track_barcodefrac = -999;
33  int ntrack_passOR_total = 0;
34  int trackMuon_gt0pt5_passOR = 0;
35  float tmp_TrueTrack_BCF = -999;
36 
37 
38  // Create tracks to hold and compare
39  for(unsigned int i=0; i<tracks.size();i++)
40  {
41  FPGATrackSimTrack &fit1 = tracks.at(i);
42 
43  // Apply Chi2 cut
44  if(fit1.getChi2ndof() > minChi2)
45  {
46  // Only consider track with chi2 smaller than minChi2
47  fit1.setPassedOR(0);
48  continue;
49  }
50 
51  // Create vector for holding duplicate track list
52  std::vector<int> duplicates(1,i);
53 
54  // Loop through the rest of the tracks
55  for(unsigned int j=0; j<tracks.size(); j++)
56  {
57  if(i!=j)
58  {
59  FPGATrackSimTrack &fit2=tracks.at(j);
60  // Apply Chi2 cut and potentially OR cut if so desired
61  if(fit2.getChi2ndof()>minChi2)
62  {
63  fit2.setPassedOR(0);
64  continue;
65  }
66  // Based on the algorithm choose common hit of non-common hit
67  if(orAlgo == ORAlgo::Normal)
68  {
69  // Find the number of common hits between two tracks. We have two ways to do this:
70  // * only compare hits in the same 'layer', requires tracks to be the same size.
71  // * compare every hit to every other hit; allows for tracks to be different sizes.
72  int nOverlappingHits = 0;
73  nOverlappingHits= (compareAllHits) ? findNCommonHitsGlobal(fit1,fit2) : findNCommonHits(fit1,fit2);
74  // Group overlapping tracks into a vector for removal if at least [NumOfHitPerGrouping] hits are the same
75  if(nOverlappingHits >= NumOfHitPerGrouping)
76  {
77  duplicates.push_back(j);
78  }
79  }
80  else if(orAlgo == ORAlgo::InvertGrouping)
81  {
82  // Find the number of non-common hits between two tracks
83  int nNotOverlappingHits=0;
84  nNotOverlappingHits=findNonOverlapHits(fit1, fit2);
85 
86  // If the number of non-overlapping hit is [NumOfHitPerGrouping] or less
87  if(nNotOverlappingHits <= NumOfHitPerGrouping)
88  {
89  duplicates.push_back(j);
90  }
91  }
92  }
93  }
94  findMinChi2MaxHit(duplicates, tracks, flags_OR, minChi2);
95 
96  // Monitoring
97  ntrack++;
98  track_passOR_counter.push_back(ntrack);
99  track_barcodefrac_num = 0;
100  for(auto& hit : fit1.getFPGATrackSimHits())
101  {
102  if(hit.getBarcode() == 10001) track_barcodefrac_num++;
103  }
104  track_barcodefrac_den = fit1.getFPGATrackSimHits().size();
105  if (track_barcodefrac_den > 0){
106  track_barcodefrac = (float)track_barcodefrac_num/(float)track_barcodefrac_den;
107  }
108  fit1.setBarcodeFrac(track_barcodefrac);
109  track_passOR_barcodefrac.push_back(track_barcodefrac);
110  if(fit1.getBarcodeFrac() > 0.5 && fit1.passedOR()) {
111  trackMuon_gt0pt5_passOR++;
112  if(trackMuon_gt0pt5_passOR == 1) {
113  tmp_TrueTrack_BCF = fit1.getBarcodeFrac();
114  }
115  if(trackMuon_gt0pt5_passOR > 1) {
116  if (fit1.getBarcodeFrac() > tmp_TrueTrack_BCF) {
117  tmp_TrueTrack_BCF = fit1.getBarcodeFrac();
118  }
119  }
120  }
121 
122  }
123 
124  // Monitoring histograms
125  ANA_MSG_DEBUG("List of tracks passing OR:: ");
126  for(unsigned int i=0; i<tracks.size();i++){
127  FPGATrackSimTrack &fit1 = tracks.at(i);
128  if(fit1.passedOR()) {
129  ntrack_passOR++;
130  ANA_MSG_DEBUG("track# = " << track_passOR_counter[i] << ": chi2 = " << fit1.getChi2ndof() << " barcodefrac = " << track_passOR_barcodefrac[i]);
131  }
132  }
133  ntrack_passOR_total += ntrack_passOR;
134  auto mon_ntrack_passOR = Monitored::Scalar<int>("ntrack_passOR", ntrack_passOR);
135  auto mon_barcodeFrac_passOR = Monitored::Scalar<int>("barcodeFrac_passOR", tmp_TrueTrack_BCF);
136  Monitored::Group(monTool, mon_ntrack_passOR);
137  Monitored::Group(monTool, mon_barcodeFrac_passOR);
138  ANA_MSG_DEBUG("Number of tracks passing OR (total) = " << ntrack_passOR_total);
139 
140 
141  return StatusCode::SUCCESS;
142 }

Variable Documentation

◆ EPSILON

constexpr float EPSILON = 1e-5
constexpr

Definition at line 13 of file FPGATrackSimHoughFunctions.cxx.

temp
Definition: JetEventDict.h:21
findNCommonHits
int findNCommonHits(const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
Definition: FPGATrackSimHoughFunctions.cxx:352
FPGATrackSimHit::setSection
void setSection(unsigned v)
Definition: FPGATrackSimHit.h:93
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
FPGATrackSimPlaneMap::getNLogiLayers
uint32_t getNLogiLayers() const
Definition: FPGATrackSimPlaneMap.h:75
SiliconTech::strip
@ strip
FPGATrackSimHit::getEtaModule
int getEtaModule(bool old=false) const
Definition: FPGATrackSimHit.h:87
FPGATrackSimHit::isStrip
bool isStrip() const
Definition: FPGATrackSimHit.h:65
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
getCoarseID
long getCoarseID(const FPGATrackSimHit &hit)
Definition: FPGATrackSimHoughFunctions.cxx:587
FPGATrackSimRoad::getSubRegion
int getSubRegion() const
Definition: FPGATrackSimRoad.h:86
FPGATrackSimTrack
Definition: FPGATrackSimTrack.h:18
findNonOverlapHits
int findNonOverlapHits(const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
Definition: FPGATrackSimHoughFunctions.cxx:144
FPGATrackSimHit::getLayerDisk
unsigned getLayerDisk(bool old=false) const
Definition: FPGATrackSimHit.h:82
FPGATrackSimRoad::getHits
const std::vector< std::shared_ptr< const FPGATrackSimHit > > & getHits(size_t layer) const
Definition: FPGATrackSimRoad.h:102
FPGATrackSimHit::getX
float getX() const
Definition: FPGATrackSimHit.h:149
findMinChi2MaxHit
void findMinChi2MaxHit(const std::vector< int > &duplicates, std::vector< FPGATrackSimTrack > &RMtracks, std::vector< int > flags_OR, const float minChi2)
Definition: FPGATrackSimHoughFunctions.cxx:190
ORAlgo::Normal
@ Normal
FPGATrackSimHit::isReal
bool isReal() const
Definition: FPGATrackSimHit.cxx:40
FPGATrackSimTrack::setPassedOR
void setPassedOR(unsigned int)
Definition: FPGATrackSimTrack.cxx:259
HitType::spacepoint
@ spacepoint
FPGATrackSimHit::getLayer
int getLayer() const
Definition: FPGATrackSimHit.cxx:87
FPGATrackSimTrack::passedOR
unsigned int passedOR() const
Definition: FPGATrackSimTrack.h:139
FPGATrackSimRoad::getNHits_layer
std::vector< size_t > getNHits_layer() const
Definition: FPGATrackSimRoad.cxx:27
FPGATrackSimHit
Definition: FPGATrackSimHit.h:41
FPGATrackSimHit::getGPhi
float getGPhi() const
Definition: FPGATrackSimHit.h:153
FPGATrackSimPlaneMap::getDim
uint32_t getDim(size_t logiLayer) const
Definition: FPGATrackSimPlaneMap.h:78
EPSILON
constexpr float EPSILON
Definition: FPGATrackSimHoughFunctions.cxx:13
HitType::wildcard
@ wildcard
FPGATrackSimTrack::getFPGATrackSimHits
const std::vector< FPGATrackSimHit > & getFPGATrackSimHits() const
Definition: FPGATrackSimTrack.h:63
getVolumeID
long getVolumeID(const FPGATrackSimHit &hit)
Definition: FPGATrackSimHoughFunctions.cxx:532
FPGATrackSimTrack::getBarcodeFrac
float getBarcodeFrac() const
Definition: FPGATrackSimTrack.h:61
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
FPGATrackSimHit::setDetType
void setDetType(SiliconTech detType)
Definition: FPGATrackSimHit.h:55
FPGATrackSimTrack::getChi2ndof
float getChi2ndof() const
Definition: FPGATrackSimTrack.h:45
lumiFormat.i
int i
Definition: lumiFormat.py:85
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
TrackStage::FIRST
@ FIRST
findNCommonHitsGlobal
int findNCommonHitsGlobal(const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
Definition: FPGATrackSimHoughFunctions.cxx:307
FPGATrackSimHit::getY
float getY() const
Definition: FPGATrackSimHit.h:150
FPGATrackSimHit::getIdentifierHash
unsigned getIdentifierHash() const
Definition: FPGATrackSimHit.h:81
FPGATrackSimHit::isPixel
bool isPixel() const
Definition: FPGATrackSimHit.h:64
FPGATrackSimTrack::setBarcodeFrac
void setBarcodeFrac(const float &v)
Definition: FPGATrackSimTrack.h:105
FPGATrackSimHit::getZ
float getZ() const
Definition: FPGATrackSimHit.h:151
getComboIndices
std::vector< std::vector< int > > getComboIndices(std::vector< size_t > const &sizes)
Given a vector of sizes (of arrays), generates a vector of all combinations of indices to index one e...
Definition: FPGATrackSimFunctions.cxx:21
isFineIDInStrip
bool isFineIDInStrip(long ID)
Definition: FPGATrackSimHoughFunctions.cxx:614
TrackCorrType::None
@ None
FPGATrackSimRoad::getWCLayers
layer_bitmask_t getWCLayers() const
Definition: FPGATrackSimRoad.h:98
FPGATrackSimRegionMap::getAvgRadii
const std::vector< double > & getAvgRadii(unsigned region) const
Definition: FPGATrackSimRegionMap.h:104
ORAlgo::InvertGrouping
@ InvertGrouping
FPGATrackSimHit::getR
float getR() const
Definition: FPGATrackSimHit.h:152
FPGATrackSimHit::setLayer
void setLayer(unsigned v)
Definition: FPGATrackSimHit.h:92
layer_bitmask_t
uint32_t layer_bitmask_t
Definition: FPGATrackSimTypes.h:22
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
FPGATrackSimRegionMap
Definition: FPGATrackSimRegionMap.h:62
FPGATrackSimHit::getPhysLayer
unsigned getPhysLayer(bool old=false) const
Definition: FPGATrackSimHit.cxx:72
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
FPGATrackSimHit::isBarrel
bool isBarrel() const
Definition: FPGATrackSimHit.h:66
generateReferenceFile.duplicates
duplicates
Definition: generateReferenceFile.py:24
SiliconTech::pixel
@ pixel
FPGATrackSimHit::getHitType
HitType getHitType() const
Definition: FPGATrackSimHit.h:57
FPGATrackSimHit::setHitType
void setHitType(HitType type)
Definition: FPGATrackSimHit.h:54
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288