ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimHoughFunctions.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum class  ORAlgo { Normal , InvertGrouping }

Functions

long getVolumeID (const FPGATrackSimHit &hit)
long getCoarseID (const FPGATrackSimHit &hit)
long getFineID (const FPGATrackSimHit &hit)
bool isFineIDInStrip (long ID)
bool isFineIDInPixel (long ID)
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.
StatusCode runOverlapRemoval (std::vector< FPGATrackSimTrack > &tracks, const float minChi2, const int NumOfHitPerGrouping, ORAlgo orAlgo, ToolHandle< GenericMonitoringTool > &monTool, bool compareAllHits=false)
void findMinChi2MaxHit (const std::vector< int > &duplicates, std::vector< FPGATrackSimTrack > &RMtracks, std::vector< int > flags_OR, const float minChi2)
int findNonOverlapHits (const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
int findNCommonHits (const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
int findNCommonHitsGlobal (const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
void roadsToTrack (std::vector< std::shared_ptr< const FPGATrackSimRoad > > &roads, std::vector< FPGATrackSimTrack > &track_cands, const FPGATrackSimPlaneMap *pmap)

Enumeration Type Documentation

◆ ORAlgo

enum class ORAlgo
strong
Enumerator
Normal 
InvertGrouping 

Definition at line 20 of file FPGATrackSimHoughFunctions.h.

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 183 of file FPGATrackSimHoughFunctions.cxx.

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

◆ findNCommonHits()

int findNCommonHits ( const FPGATrackSimTrack & Track1,
const FPGATrackSimTrack & Track2 )

Definition at line 345 of file FPGATrackSimHoughFunctions.cxx.

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

◆ findNCommonHitsGlobal()

int findNCommonHitsGlobal ( const FPGATrackSimTrack & Track1,
const FPGATrackSimTrack & Track2 )

Definition at line 300 of file FPGATrackSimHoughFunctions.cxx.

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

◆ findNonOverlapHits()

int findNonOverlapHits ( const FPGATrackSimTrack & Track1,
const FPGATrackSimTrack & Track2 )

Definition at line 137 of file FPGATrackSimHoughFunctions.cxx.

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

◆ getCoarseID()

long getCoarseID ( const FPGATrackSimHit & hit)

Definition at line 580 of file FPGATrackSimHoughFunctions.cxx.

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

◆ getFineID()

long getFineID ( const FPGATrackSimHit & hit)

Definition at line 617 of file FPGATrackSimHoughFunctions.cxx.

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

◆ 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 394 of file FPGATrackSimHoughFunctions.cxx.

395{
396 int subregion = road.getSubRegion();
397 nMissing = FPGATrackSimMapping->PlaneMap_1st(subregion)->getNCoords(); // init with nCoords and decrement as we find misses
398 missPixel = false;
399 missStrip = false;
400 missing_mask = 0;
401 norecovery_mask = 0;
402 unsigned int wclayers = road.getWCLayers();
403 for (unsigned layer = 0; layer < FPGATrackSimMapping->PlaneMap_1st(subregion)->getNLogiLayers(); layer++)
404 {
405 int nHits = road.getHits(layer).size();
406 if (nHits==0)
407 {
408 if (idealCoordFitType == TrackCorrType::None && ((wclayers >> layer) & 1))
409 {
410 int ix = FPGATrackSimMapping->PlaneMap_1st(subregion)->getCoordOffset(layer);
411 int iy = ix + 1;
412 if (FPGATrackSimMapping->PlaneMap_1st(subregion)->isSCT(layer))
413 {
414 missing_mask |= 1 << ix;
415 nMissing -= 1;
416 }
417 else
418 {
419 missing_mask |= (1<<ix) | (1<<iy);
420 nMissing -= 2;
421 }
422 }
423 else
424 {
425 if (FPGATrackSimMapping->PlaneMap_1st(subregion)->isSCT(layer)) missStrip = true;
426 else missPixel = true;
427 }
428 }
429 else if (!((wclayers >> layer) & 1)) { // we have a hit
430 int ix = FPGATrackSimMapping->PlaneMap_1st(subregion)->getCoordOffset(layer);
431 int iy = ix + 1;
432 if (FPGATrackSimMapping->PlaneMap_1st(subregion)->isSCT(layer))
433 {
434 missing_mask |= 1 << ix;
435 nMissing -= 1;
436 }
437 else
438 {
439 missing_mask |= (1<<ix) | (1<<iy);
440 nMissing -= 2;
441 }
442
443 }
444 }
445}
static const uint32_t nHits
const std::vector< std::shared_ptr< const FPGATrackSimHit > > & getHits(size_t layer) const
int getSubRegion() const
layer_bitmask_t getWCLayers() const
@ layer
Definition HitInfo.h:79

◆ getVolumeID()

long getVolumeID ( const FPGATrackSimHit & hit)

Definition at line 525 of file FPGATrackSimHoughFunctions.cxx.

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

◆ isFineIDInPixel()

bool isFineIDInPixel ( long ID)

Definition at line 612 of file FPGATrackSimHoughFunctions.cxx.

613{
614 return !isFineIDInStrip(ID);
615}
std::vector< Identifier > ID
bool isFineIDInStrip(long ID)

◆ isFineIDInStrip()

bool isFineIDInStrip ( long ID)

Definition at line 607 of file FPGATrackSimHoughFunctions.cxx.

608{
609 return (ID < 16);
610}

◆ 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 456 of file FPGATrackSimHoughFunctions.cxx.

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

◆ roadsToTrack()

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

Definition at line 667 of file FPGATrackSimHoughFunctions.cxx.

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

◆ runOverlapRemoval()

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

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 ntrack_passOR_total = 0;
31 int trackMuon_gt0pt5_passOR = 0;
32 float tmp_TrueTrack_BCF = -999;
33
34
35 // Create tracks to hold and compare
36 for(unsigned int i=0; i<tracks.size();i++)
37 {
38 FPGATrackSimTrack &fit1 = tracks.at(i);
39
40 // Apply Chi2 cut
41 if(fit1.getChi2ndof() > minChi2)
42 {
43 // Only consider track with chi2 smaller than minChi2
44 fit1.setPassedOR(0);
45 continue;
46 }
47
48 // Create vector for holding duplicate track list
49 std::vector<int> duplicates(1,i);
50
51 // Loop through the rest of the tracks
52 for(unsigned int j=0; j<tracks.size(); j++)
53 {
54 if(i!=j)
55 {
56 FPGATrackSimTrack &fit2=tracks.at(j);
57 // Apply Chi2 cut and potentially OR cut if so desired
58 if(fit2.getChi2ndof()>minChi2)
59 {
60 fit2.setPassedOR(0);
61 continue;
62 }
63 // Based on the algorithm choose common hit of non-common hit
64 if(orAlgo == ORAlgo::Normal)
65 {
66 // Find the number of common hits between two tracks. We have two ways to do this:
67 // * only compare hits in the same 'layer', requires tracks to be the same size.
68 // * compare every hit to every other hit; allows for tracks to be different sizes.
69 int nOverlappingHits = 0;
70 nOverlappingHits= (compareAllHits) ? findNCommonHitsGlobal(fit1,fit2) : findNCommonHits(fit1,fit2);
71 // Group overlapping tracks into a vector for removal if at least [NumOfHitPerGrouping] hits are the same
72 if(nOverlappingHits >= NumOfHitPerGrouping)
73 {
74 duplicates.push_back(j);
75 }
76 }
77 else if(orAlgo == ORAlgo::InvertGrouping)
78 {
79 // Find the number of non-common hits between two tracks
80 int nNotOverlappingHits=0;
81 nNotOverlappingHits=findNonOverlapHits(fit1, fit2);
82
83 // If the number of non-overlapping hit is [NumOfHitPerGrouping] or less
84 if(nNotOverlappingHits <= NumOfHitPerGrouping)
85 {
86 duplicates.push_back(j);
87 }
88 }
89 }
90 }
91 findMinChi2MaxHit(duplicates, tracks, flags_OR, minChi2);
92
93
94 // Monitoring
95 ntrack++;
96 track_passOR_counter.push_back(ntrack);
97 // barcodeFrac should be set in the track upstream e.g in FPGATrackSimLogicalHitsProcessAlg.cxx using calculateTruth()
98 if (fit1.getBarcodeFrac() < 0)
99 ANA_MSG_WARNING("barcodeFrac not set!");
100 track_passOR_barcodefrac.push_back(fit1.getBarcodeFrac());
101 // check if the track passes OR and has barcodeFrac > 0.5
102 if(fit1.getBarcodeFrac() > 0.5 && fit1.passedOR()) {
103 // count how many muon tracks satisfy the condition
104 trackMuon_gt0pt5_passOR++;
105 // for the first passing track, record its barcodeFrac
106 if(trackMuon_gt0pt5_passOR == 1) {
107 tmp_TrueTrack_BCF = fit1.getBarcodeFrac();
108 }
109 // for subsequent passing tracks, keep the largest barcodeFrac
110 else if (fit1.getBarcodeFrac() > tmp_TrueTrack_BCF) {
111 tmp_TrueTrack_BCF = fit1.getBarcodeFrac();
112 }
113 }
114
115 }
116
117 // Monitoring histograms
118 ANA_MSG_DEBUG("List of tracks passing OR:: ");
119 for(unsigned int i=0; i<tracks.size();i++){
120 FPGATrackSimTrack &fit1 = tracks.at(i);
121 if(fit1.passedOR()) {
122 ntrack_passOR++;
123 ANA_MSG_DEBUG("track# = " << track_passOR_counter[i] << ": chi2 = " << fit1.getChi2ndof() << " barcodefrac = " << track_passOR_barcodefrac[i]);
124 }
125 }
126 ntrack_passOR_total += ntrack_passOR;
127 auto mon_ntrack_passOR = Monitored::Scalar<int>("ntrack_passOR", ntrack_passOR);
128 auto mon_barcodeFrac_passOR = Monitored::Scalar<int>("barcodeFrac_passOR", tmp_TrueTrack_BCF);
129 Monitored::Group(monTool, mon_ntrack_passOR);
130 Monitored::Group(monTool, mon_barcodeFrac_passOR);
131 ANA_MSG_DEBUG("Number of tracks passing OR (total) = " << ntrack_passOR_total);
132
133
134 return StatusCode::SUCCESS;
135}
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
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 findNCommonHitsGlobal(const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
int findNCommonHits(const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
float getBarcodeFrac() const
void setPassedOR(unsigned int)
unsigned int passedOR() const
float getChi2ndof() const
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.