21using namespace asg::msgUserCode;
26StatusCode
runOverlapRemoval(std::vector<FPGATrackSimTrack>& tracks,
const float minChi2,
const int NumOfHitPerGrouping,
ORAlgo orAlgo, ToolHandle<GenericMonitoringTool> & monTool,
bool compareAllHits)
31 std::vector<int> flags_OR;
35 int ntrack_passOR = 0;
37 std::vector<int> track_passOR_counter(tracks.size(), -1);
38 std::vector<int> track_passOR_barcodefrac(tracks.size(), -1);
39 int ntrack_passOR_total = 0;
40 int trackMuon_gt0pt5_passOR = 0;
41 float tmp_TrueTrack_BCF = -999;
44 std::vector<unsigned int> goodTrackIndices;
45 goodTrackIndices.reserve(tracks.size());
46 for(
unsigned int i = 0; i < tracks.size(); i++)
48 if(tracks[i].getChi2ndof() > minChi2)
50 tracks[i].setPassedOR(0);
54 goodTrackIndices.push_back(i);
59 std::vector<int> track_counter;
60 int ntr_belowMinChi2 = 0;
61 for(
unsigned int i=0; i<tracks.size();i++)
63 if(tracks.at(i).getChi2ndof() > minChi2) {
64 track_counter.push_back(0);
65 flags_OR.push_back(-1);
68 track_counter.push_back(ntr_belowMinChi2);
69 flags_OR.push_back(1);
74 for(
size_t idx = 0; idx < goodTrackIndices.size(); idx++)
76 unsigned int i = goodTrackIndices[idx];
83 std::vector<int> duplicates(1,i);
86 for(
size_t jdx = 0; jdx < goodTrackIndices.size(); jdx++)
88 if(jdx == idx)
continue;
90 unsigned int j = goodTrackIndices[jdx];
99 int nOverlappingHits = 0;
103 if(nOverlappingHits >= NumOfHitPerGrouping)
105 duplicates.push_back(j);
111 int nNotOverlappingHits = 0;
115 if(nNotOverlappingHits <= NumOfHitPerGrouping)
117 duplicates.push_back(j);
126 track_passOR_counter[i] = ntrack;
134 trackMuon_gt0pt5_passOR++;
136 if(trackMuon_gt0pt5_passOR == 1) {
149 for(
unsigned int i=0; i<tracks.size();i++){
153 ANA_MSG_DEBUG(
"track# = " << track_passOR_counter[i] <<
": chi2 = " << fit1.
getChi2ndof() <<
" barcodefrac = " << track_passOR_barcodefrac[i]);
156 ntrack_passOR_total += ntrack_passOR;
161 ANA_MSG_DEBUG(
"Number of tracks passing OR (total) = " << ntrack_passOR_total);
164 return StatusCode::SUCCESS;
169 int nonOverlapHits=0;
175 for(
size_t i = 0; i < hits1.size() && i < hits2.size(); ++i)
177 if (!hits1[i] || !hits2[i])
throw std::runtime_error(
"Null hit pointer in findNonOverlapHits: hit is null, tracks should not have unassigned layers");
214 return nonOverlapHits;
218void findMinChi2MaxHit(
const std::vector<int>& duplicates, std::vector<FPGATrackSimTrack>& RMtracks, std::vector<int>& flags_OR,
const std::vector<int>& track_counter)
222 float head_chi2 = 0.;
225 for(
auto dup: duplicates)
227 float t_chi2 = RMtracks.at(dup).getChi2ndof();
228 const auto& hits = RMtracks.at(dup).getFPGATrackSimHitPtrs();
229 int t_nhitlayers = hits.size();
230 for(
const auto& hit_ptr : hits)
232 if (!hit_ptr)
throw std::runtime_error(
"Null hit pointer in findMinChi2MaxHit: hit is null");
233 const auto& hit = *hit_ptr;
235 ANA_MSG_DEBUG(
"Real hit info (global) = Gphi= " << hit.getGPhi() <<
" Z=" << hit.getZ() <<
" R=" << hit.getR() <<
" chi2=" << t_chi2);
242 if (dup_counter == 0) {
244 head_chi2 = RMtracks.at(head_track).getChi2ndof();
245 head_nhits = t_nhitlayers;
247 if (dup_counter > 0){
248 if(t_nhitlayers>head_nhits)
250 RMtracks.at(head_track).setPassedOR(0);
252 else if(t_nhitlayers==head_nhits)
254 if((head_chi2-t_chi2)>0.000001)
256 RMtracks.at(head_track).setPassedOR(0);
258 if(std::abs(t_chi2-head_chi2)<0.000001)
260 if(track_counter[head_track] < track_counter[dup]) {
261 RMtracks.at(dup).setPassedOR(0);
263 if(track_counter[head_track] > track_counter[dup]) {
264 RMtracks.at(head_track).setPassedOR(0);
270 if(!RMtracks.at(head_track).passedOR()) flags_OR[head_track] = 0;
271 if(RMtracks.at(head_track).passedOR()) flags_OR[head_track] = 1;
282 std::vector<uint8_t> hit2_matched(hits2.size(), 0);
284 for (
const auto& hit1_ptr : hits1)
286 if (!hit1_ptr)
throw std::runtime_error(
"Null hit pointer in findNCommonHits_v2: hit1 is null");
287 if (!hit1_ptr->isReal())
continue;
288 const auto& hit1 = *hit1_ptr;
290 for (
size_t j = 0; j < hits2.size(); ++j)
292 if (!hits2[j])
throw std::runtime_error(
"Null hit pointer in findNCommonHits_v2: hit2 is null");
293 const auto& hit2 = *hits2[j];
295 if (hit2_matched[j])
continue;
296 else if (!hit2.isReal())
continue;
297 else if (hit1.getLayer() != hit2.getLayer())
continue;
298 else if (hit1.getIdentifierHash() != hit2.getIdentifierHash())
continue;
304 if (std::abs(hit1.getX() - hit2.getX()) <
EPSILON &&
305 std::abs(hit1.getY() - hit2.getY()) <
EPSILON &&
306 std::abs(hit1.getZ() - hit2.getZ()) <
EPSILON)
309 hit2_matched[j] =
true;
315 else if (std::abs(hit1.getGPhi() - hit2.getGPhi()) < 0.001 &&
316 std::abs(hit1.getZ() - hit2.getZ()) < 0.001 &&
317 std::abs(hit1.getR() - hit2.getR()) < 0.001)
320 hit2_matched[j] =
true;
335 std::vector<uint8_t> hit2_matched(hits2.size(), 0);
337 for (
const auto& hit1_ptr : hits1)
339 if (!hit1_ptr)
throw std::runtime_error(
"Null hit pointer in findNCommonHitsGlobal: hit1 is null, tracks should not have unassigned layers");
340 if (!hit1_ptr->isReal())
continue;
341 const auto& hit1 = *hit1_ptr;
343 for (
size_t j = 0; j < hits2.size(); ++j)
345 if (!hits2[j])
throw std::runtime_error(
"Null hit pointer in findNCommonHitsGlobal: hit2 is null, tracks should not have unassigned layers");
346 const auto& hit2 = *hits2[j];
348 if (hit2_matched[j])
continue;
349 else if (!hit2.isReal())
continue;
350 else if (hit1.getLayer() != hit2.getLayer())
continue;
351 else if (hit1.getIdentifierHash() != hit2.getIdentifierHash())
continue;
357 if (std::abs(hit1.getX() - hit2.getX()) <
EPSILON &&
358 std::abs(hit1.getY() - hit2.getY()) <
EPSILON &&
359 std::abs(hit1.getZ() - hit2.getZ()) <
EPSILON)
362 hit2_matched[j] =
true;
368 else if (std::abs(hit1.getGPhi() - hit2.getGPhi()) <
EPSILON &&
369 std::abs(hit1.getZ() - hit2.getZ()) <
EPSILON &&
370 std::abs(hit1.getR() - hit2.getR()) <
EPSILON)
373 hit2_matched[j] =
true;
390 for(
unsigned int i = 0; i < hits1.size() && i < hits2.size(); ++i)
392 if (!hits1[i] || !hits2[i])
throw std::runtime_error(
"Null hit pointer in findNCommonHits: tracks should not have unassigned layers");
438 nMissing = FPGATrackSimMapping->PlaneMap_1st(subregion)->getNCoords();
444 for (
unsigned layer = 0; layer < FPGATrackSimMapping->PlaneMap_1st(subregion)->getNLogiLayers(); layer++)
451 int ix = FPGATrackSimMapping->PlaneMap_1st(subregion)->getCoordOffset(layer);
453 if (FPGATrackSimMapping->PlaneMap_1st(subregion)->isSCT(layer))
455 missing_mask |= 1 << ix;
460 missing_mask |= (1<<ix) | (1<<iy);
466 if (FPGATrackSimMapping->PlaneMap_1st(subregion)->isSCT(layer)) missStrip =
true;
467 else missPixel =
true;
470 else if (!((wclayers >> layer) & 1)) {
471 int ix = FPGATrackSimMapping->PlaneMap_1st(subregion)->getCoordOffset(layer);
473 if (FPGATrackSimMapping->PlaneMap_1st(subregion)->isSCT(layer))
475 missing_mask |= 1 << ix;
480 missing_mask |= (1<<ix) | (1<<iy);
501 auto pmap = FPGATrackSimMapping->PlaneMap_2nd(subregion);
504 pmap = FPGATrackSimMapping->PlaneMap_1st(subregion);
508 track_cands.resize(combs.size(), temp);
515 for (
size_t icomb = 0; icomb < combs.size(); icomb++)
518 track_cands[icomb].setTrackID(idbase + icomb);
519 track_cands[icomb].setNLayers(pmap->getNLogiLayers());
522 track_cands[icomb].setIdealRadii(SUBREGIONMAP->
getAvgRadii(subregion));
523 track_cands[icomb].setPassedOR(1);
525 std::vector<int>
const & hit_indices = combs[icomb];
526 for (
unsigned layer = 0; layer < pmap->getNLogiLayers(); layer++)
528 if (hit_indices[layer] < 0)
536 if (wcbits & (1 << layer ) ) {
541 track_cands[icomb].setFPGATrackSimHit(layer, std::make_shared<FPGATrackSimHit>(newhit));
545 const std::shared_ptr<const FPGATrackSimHit> hit = road.
getHitPtrs(layer)[hit_indices[layer]];
551 if (layer == 0)
throw (std::out_of_range(
"makeTrackCandidates: Attempt to access vector at element -1"));
552 auto inner_hit_ptr = track_cands[icomb].getFPGATrackSimHitPtrs().at(layer - 1);
553 if (!inner_hit_ptr)
throw std::runtime_error(
"Null inner hit pointer in makeTrackCandidates: inner layer should have a hit when comparing spacepoints");
556 track_cands[icomb].setValidCand(
false);
559 track_cands[icomb].setFPGATrackSimHit(layer, std::move(hit));
564 idbase += combs.size();
590 if (hit.
getR() == 0.0) {
604 if (hit.
getZ() >= 0.) {
612 if (hit.
getZ() >= 0.) {
639 long offset = -10000;
641 if(volumeID == 10) offset = 0;
642 if(volumeID == 8) offset = 4;
643 if(volumeID == 12) offset = 10;
644 if(volumeID == 0) offset = 16;
645 if(volumeID == -2) offset = 21;
646 if(volumeID == 2) offset = 30;
647 return offset + layerID;
678 if(volumeID == -999)
return -999;
681 if(layerID == 0) offset = 21;
682 if(layerID == 1) offset = 21+15;
683 if(layerID == 2) offset = 21+15+6;
684 if(layerID == 3) offset = 21+15+6+23;
685 if(layerID == 4) offset = 21+15+6+23+6;
686 if(layerID == 5) offset = 21+15+6+23+6+11;
687 if(layerID == 6) offset = 21+15+6+23+6+11+8;
688 if(layerID == 7) offset = 21+15+6+23+6+11+8+8;
689 if(layerID == 8) offset = 21+15+6+23+6+11+8+8+9;
690 return offset + etaID;
694 if(layerID == 0) offset = 116;
695 if(layerID == 1) offset = 116+15;
696 if(layerID == 2) offset = 116+15+6;
697 if(layerID == 3) offset = 116+15+6+23;
698 if(layerID == 4) offset = 116+15+6+23+6;
699 if(layerID == 5) offset = 116+15+6+23+6+11;
700 if(layerID == 6) offset = 116+15+6+23+6+11+8;
701 if(layerID == 7) offset = 116+15+6+23+6+11+8+8;
702 if(layerID == 8) offset = 116+15+6+23+6+11+8+8+9;
703 return offset + etaID;
719 temp.setPatternID(road.getPID());
720 temp.setHoughX(road.getX());
721 temp.setHoughY(road.getY());
722 temp.setQOverPt(road.getY());
724 temp.setSubRegion(road.getSubRegion());
725 temp.setHoughXBin(road.getXBin());
726 temp.setHoughYBin(road.getYBin());
729 temp.setBinIdx(road.getBinIdx());
732 std::vector<std::vector<int>> combs =
getComboIndices(road.getNHits_layer());
733 unsigned existing_size = track_cands.size();
734 track_cands.resize(existing_size + combs.size(), temp);
739 for (
size_t icomb = 0; icomb < combs.size(); icomb++)
741 if ((existing_size + icomb) >= track_cands.size())
continue;
742 track_cands[existing_size + icomb].setNLayers(pmap->
getNLogiLayers());
743 std::vector<int>
const & hit_indices = combs[icomb];
746 if (hit_indices[layer] < 0)
754 if (wcbits & (1 << layer ) ) {
759 track_cands[existing_size + icomb].setFPGATrackSimHit(layer, std::make_shared<FPGATrackSimHit>(newhit));
763 const std::shared_ptr<const FPGATrackSimHit> hit = road.getHitPtrs(layer)[hit_indices[layer]];
768 if (hit->getHitType() ==
HitType::spacepoint && (hit->getPhysLayer() % 2) == 1 && (layer>0)) {
769 auto inner_hit_ptr = track_cands[existing_size + icomb].getFPGATrackSimHitPtrs().at(layer - 1);
770 if (!inner_hit_ptr)
throw std::runtime_error(
"Null inner hit pointer in roadsToTrack: inner layer should have a hit when comparing spacepoints");
772 if ((std::abs(hit->getX() - inner_hit.
getX()) >
EPSILON) || (std::abs(hit->getY() - inner_hit.
getY()) >
EPSILON) || (std::abs(hit->getZ() - inner_hit.
getZ()) >
EPSILON)) {
773 track_cands[existing_size + icomb].setValidCand(
false);
776 track_cands[existing_size + icomb].setFPGATrackSimHit(layer, std::move(hit));
std::vector< Identifier > ID
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...
: FPGATrackSim-specific class to represent an hit in the detector.
void findMinChi2MaxHit(const std::vector< int > &duplicates, std::vector< FPGATrackSimTrack > &RMtracks, std::vector< int > &flags_OR, const std::vector< int > &track_counter)
bool isFineIDInStrip(long ID)
long getFineID(const FPGATrackSimHit &hit)
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)
int findNonOverlapHits(const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
int findNCommonHits_v2(const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
long getCoarseID(const FPGATrackSimHit &hit)
StatusCode runOverlapRemoval(std::vector< FPGATrackSimTrack > &tracks, const float minChi2, const int NumOfHitPerGrouping, ORAlgo orAlgo, ToolHandle< GenericMonitoringTool > &monTool, bool compareAllHits)
long getVolumeID(const FPGATrackSimHit &hit)
int findNCommonHitsGlobal(const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
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.
bool isFineIDInPixel(long ID)
void roadsToTrack(std::vector< FPGATrackSimRoad > &roads, std::vector< FPGATrackSimTrack > &track_cands, const FPGATrackSimPlaneMap *pmap)
int findNCommonHits(const FPGATrackSimTrack &Track1, const FPGATrackSimTrack &Track2)
Maps physical layers to logical layers.
Maps ITK module indices to FPGATrackSim regions.
Defines a class for roads.
Header file to be included by clients of the Monitored infrastructure.
static const uint32_t nHits
void setLayer(unsigned v)
unsigned getIdentifierHash() const
void setHitType(HitType type)
int getEtaModule(bool old=false) const
unsigned getLayerDisk(bool old=false) const
void setSection(unsigned v)
HitType getHitType() const
void setDetType(SiliconTech detType)
uint32_t getNLogiLayers() const
uint32_t getDim(size_t logiLayer) const
const std::vector< double > & getAvgRadii(unsigned region) const
const std::vector< std::shared_ptr< const FPGATrackSimHit > > & getHitPtrs(size_t layer) const
layer_bitmask_t getWCLayers() const
std::vector< size_t > getNHits_layer() const
float getBarcodeFrac() const
unsigned int passedOR() const
const std::vector< std::shared_ptr< const FPGATrackSimHit > > & getFPGATrackSimHitPtrs() const
float getChi2ndof() const
void setNLayers(int)
set the number of layers in the track.
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.