Skip to content

Commit

Permalink
Bug fix in validation:
Browse files Browse the repository at this point in the history
    * drop is_seed_layer as requirement for skipping pixel hits in hit counting
    * add generic seed hit masking based on input seed collection
  • Loading branch information
kmcdermo committed Jul 18, 2018
1 parent 32cfc86 commit 35a1948
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 33 deletions.
7 changes: 6 additions & 1 deletion Event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ void Event::Fit()

void Event::Validate()
{
// special map needed for sim_val_for_cmssw
if (Config::sim_val_for_cmssw) {
validation_.makeRecoTkToSeedTkMapsDumbCMSSW(*this);
}

// standard eff/fr/dr validation
if (Config::sim_val || Config::sim_val_for_cmssw) {
validation_.setTrackExtras(*this);
Expand All @@ -338,6 +343,7 @@ void Event::Validate()

// special cmssw to mkfit validation
if (Config::cmssw_val) {
validation_.makeCMSSWTkToSeedTkMap(*this);
validation_.makeRecoTkToRecoTkMaps(*this);
validation_.setTrackExtras(*this);
validation_.makeCMSSWTkToRecoTksMaps(*this);
Expand Down Expand Up @@ -1104,4 +1110,3 @@ void DataFile::CloseWrite(int n_written){
}
Close();
}

2 changes: 2 additions & 0 deletions Hit.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ struct HitOnTrack
HitOnTrack(int i, int l) : index( i), layer ( l) {}
};

typedef std::vector<HitOnTrack> HoTVec;

void print(std::string label, const MeasurementState& s);

#endif
122 changes: 107 additions & 15 deletions TTreeValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,18 @@ void TTreeValidation::resetValidationMaps()

// reset special map of seed labels to cmssw tracks
seedToCmsswMap_.clear();
cmsswToSeedMap_.clear();

// reset special map of matching build tracks exactly to cmssw tracks through seedIDs
buildToCmsswMap_.clear();

// reset special maps used for pairing build to fit tracks CMSSW only
buildToFitMap_.clear();
fitToBuildMap_.clear();

// reset special maps used for associating seed tracks to reco tracks for sim_val_for_cmssw
candToSeedMapDumbCMSSW_.clear();
fitToSeedMapDumbCMSSW_.clear();
}

void TTreeValidation::setTrackExtras(Event& ev)
Expand All @@ -689,7 +694,8 @@ void TTreeValidation::setTrackExtras(Event& ev)
{
const auto& track = seedtracks[itrack];
auto& extra = seedextras[itrack];


extra.findMatchingSeedHits(track,track,layerhits);
extra.setMCTrackIDInfo(track, layerhits, simhits, simtracks, true, (Config::seedInput == simSeeds)); // otherwise seeds are completely unmatched in ToyMC Sim Seeds
}

Expand All @@ -698,6 +704,15 @@ void TTreeValidation::setTrackExtras(Event& ev)
{
const auto& track = buildtracks[itrack];
auto& extra = buildextras[itrack];

if (Config::sim_val)
{
extra.findMatchingSeedHits(track,seedtracks[track.label()],layerhits);
}
else if (Config::sim_val_for_cmssw)
{
extra.findMatchingSeedHits(track,seedtracks[candToSeedMapDumbCMSSW_[track.label()]],layerhits);
}

extra.setMCTrackIDInfo(track, layerhits, simhits, simtracks, false, (Config::seedInput == simSeeds)); // otherwise seeds are completely unmatched in ToyMC Sim Seeds
}
Expand All @@ -708,6 +723,15 @@ void TTreeValidation::setTrackExtras(Event& ev)
const auto& track = fittracks[itrack];
auto& extra = fitextras[itrack];

if (Config::sim_val)
{
extra.findMatchingSeedHits(track,seedtracks[track.label()],layerhits);
}
else if (Config::sim_val_for_cmssw)
{
extra.findMatchingSeedHits(track,seedtracks[fitToSeedMapDumbCMSSW_[track.label()]],layerhits);
}

extra.setMCTrackIDInfo(track, layerhits, simhits, simtracks, false, (Config::seedInput == simSeeds)); // otherwise seeds are completely unmatched in ToyMC Sim Seeds
}
}
Expand All @@ -718,13 +742,15 @@ void TTreeValidation::setTrackExtras(Event& ev)
storeSeedAndMCID(ev);

const auto& cmsswtracks = ev.cmsswTracks_;
// auto& cmsswextras = ev.cmsswTracksExtra_;
const auto& cmsswextras = ev.cmsswTracksExtra_;
const auto& seedtracks = ev.seedTracks_;
const auto& seedextras = ev.seedTracksExtra_;
const auto& buildtracks = ev.candidateTracks_;
auto& buildextras = ev.candidateTracksExtra_;
const auto& fittracks = ev.fitTracks_;
auto& fitextras = ev.fitTracksExtra_;

// store reduced parameters, hit map of cmssw tracks, and global hit map
// store seed hits, reduced parameters, hit map of cmssw tracks, and global hit map
RedTrackVec reducedCMSSW;
LayIdxIDVecMapMap cmsswHitIDMap;
setupCMSSWMatching(ev,reducedCMSSW,cmsswHitIDMap);
Expand All @@ -734,18 +760,21 @@ void TTreeValidation::setTrackExtras(Event& ev)
{
const auto& track = buildtracks[itrack];
auto& extra = buildextras[itrack];

// set vector of hitsOnTrack for seed
extra.findMatchingSeedHits(track,seedtracks[track.label()],layerhits); // itrack == track.label() == seedtrack index == seedtrack.label()

if (Config::cmsswMatchingFW == trkParamBased)
{
extra.setCMSSWTrackIDInfoByTrkParams(track, layerhits, cmsswtracks, reducedCMSSW, true);
}
else if (Config::cmsswMatchingFW == hitBased)
{
extra.setCMSSWTrackIDInfoByHits(track, cmsswHitIDMap, cmsswtracks, reducedCMSSW, -1); // == -1 for not passing truth info about cmssw tracks
extra.setCMSSWTrackIDInfoByHits(track, cmsswHitIDMap, cmsswtracks, cmsswextras, reducedCMSSW, -1); // == -1 for not passing truth info about cmssw tracks
}
else if (Config::cmsswMatchingFW == labelBased) // can only be used if using pure seeds!
{
extra.setCMSSWTrackIDInfoByHits(track, cmsswHitIDMap, cmsswtracks, reducedCMSSW,
extra.setCMSSWTrackIDInfoByHits(track, cmsswHitIDMap, cmsswtracks, cmsswextras, reducedCMSSW,
reducedCMSSW[cmsswtracks[buildToCmsswMap_[track.label()]].label()].label());
}
else
Expand All @@ -761,17 +790,20 @@ void TTreeValidation::setTrackExtras(Event& ev)
const auto& track = fittracks[itrack];
auto& extra = fitextras[itrack];

// set vector of hitsOnTrack for seed
extra.findMatchingSeedHits(track,seedtracks[track.label()],layerhits); // itrack == track.label() == seedtrack index == seedtrack.label()

if (Config::cmsswMatchingBK == trkParamBased)
{
extra.setCMSSWTrackIDInfoByTrkParams(track, layerhits, cmsswtracks, reducedCMSSW, true);
}
else if (Config::cmsswMatchingBK == hitBased)
{
extra.setCMSSWTrackIDInfoByHits(track, cmsswHitIDMap, cmsswtracks, reducedCMSSW, -1); // == -1 not passing truth info about cmssw
extra.setCMSSWTrackIDInfoByHits(track, cmsswHitIDMap, cmsswtracks, cmsswextras, reducedCMSSW, -1); // == -1 not passing truth info about cmssw
}
else if (Config::cmsswMatchingBK == labelBased) // can only be used if using pure seeds!
{
extra.setCMSSWTrackIDInfoByHits(track, cmsswHitIDMap, cmsswtracks, reducedCMSSW,
extra.setCMSSWTrackIDInfoByHits(track, cmsswHitIDMap, cmsswtracks, cmsswextras, reducedCMSSW,
reducedCMSSW[cmsswtracks[buildToCmsswMap_[fitToBuildMap_[track.label()]]].label()].label());
}
else
Expand Down Expand Up @@ -831,7 +863,7 @@ void TTreeValidation::mapRefTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVe
tmpMatches.emplace_back(evt_tracks[label]);
}
std::sort(tmpMatches.begin(), tmpMatches.end(), sortByHitsChi2); // sort the tracks
for (auto itrack = 0; itrack < (int) tmpMatches.size(); itrack++) // loop over sorted tracks, now make the vector of sorted labels match
for (auto itrack = 0; itrack < (int) tmpMatches.size(); itrack++) // loop over sorted tracks, now set the vector of sorted labels match
{
refTkMatches.second[itrack] = tmpMatches[itrack].label();
}
Expand All @@ -850,7 +882,7 @@ void TTreeValidation::mapRefTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVe
void TTreeValidation::makeSeedTkToRecoTkMaps(Event& ev)
{
std::lock_guard<std::mutex> locker(glock_);
// map seed to reco tracks --> seed track collection assumed to map to itself, unless we make some cuts
// map seed to reco tracks --> seed track collection assumed to map to itself, unless we use some cuts
TTreeValidation::mapSeedTkToRecoTk(ev.candidateTracks_,ev.candidateTracksExtra_,seedToBuildMap_);
TTreeValidation::mapSeedTkToRecoTk(ev.fitTracks_,ev.fitTracksExtra_,seedToFitMap_);
}
Expand Down Expand Up @@ -906,7 +938,57 @@ void TTreeValidation::makeSeedTkToCMSSWTkMap(Event& ev)
{
for (auto&& cmsswtrack : cmsswtracks)
{
if (cmsswtrack.label() == itrack) seedToCmsswMap_[seedtracks[itrack].label()] = cmsswtrack.label();
if (cmsswtrack.label() == itrack)
{
seedToCmsswMap_[seedtracks[itrack].label()] = cmsswtrack.label();
break;
}
}
}
}

void TTreeValidation::makeCMSSWTkToSeedTkMap(Event& ev)
{
const auto& seedtracks = ev.seedTracks_;
const auto& cmsswtracks = ev.cmsswTracks_;
for (const auto & seedToCmsswPair : seedToCmsswMap_)
{
const auto seedlabel = seedToCmsswPair.first; // !! in cmssw validation, seed label != seed index in vector as they are not aligned!! --> need to find itrack!
const auto cmsswlabel = seedToCmsswPair.second; // however, cmssw tracks ARE aligned for label == index

for (int itrack = 0; itrack < seedtracks.size(); itrack++)
{
const auto & seedtrack = seedtracks[itrack];
if (seedtrack.label() == seedlabel)
{
cmsswToSeedMap_[cmsswlabel] = itrack;
break;
}
}
}
}

void TTreeValidation::makeRecoTkToSeedTkMapsDumbCMSSW(Event& ev)
{
std::lock_guard<std::mutex> locker(glock_);
// special functions for matching seeds to reco tracks for sim_val_for_cmssw
TTreeValidation::makeRecoTkToSeedTkMapDumbCMSSW(ev.candidateTracksExtra_,ev.seedTracksExtra_,candToSeedMapDumbCMSSW_);
TTreeValidation::makeRecoTkToSeedTkMapDumbCMSSW(ev.fitTracksExtra_,ev.seedTracksExtra_,fitToSeedMapDumbCMSSW_);
}

void TTreeValidation::makeRecoTkToSeedTkMapDumbCMSSW(const TrackExtraVec& recoextras, const TrackExtraVec& seedextras, TkIDToTkIDMap& recoToSeedMap)
{
for (int itrack = 0; itrack < (int) recoextras.size(); itrack++)
{
const auto reco_seedID = recoextras[itrack].seedID();
for (int jtrack = 0; jtrack < (int) seedextras.size(); jtrack++)
{
const auto seed_seedID = seedextras[jtrack].seedID();
if (reco_seedID == seed_seedID)
{
recoToSeedMap[itrack] = jtrack;
break;
}
}
}
}
Expand Down Expand Up @@ -964,18 +1046,28 @@ void TTreeValidation::storeSeedAndMCID(Event& ev)

void TTreeValidation::setupCMSSWMatching(const Event & ev, RedTrackVec & reducedCMSSW, LayIdxIDVecMapMap & cmsswHitIDMap)
{
// get the cmssw tracks
// get the tracks + hits + extras
const auto& layerhits = ev.layerHits_;
const auto& cmsswtracks = ev.cmsswTracks_;
auto& cmsswextras = ev.cmsswTracksExtra_;
const auto& seedtracks = ev.seedTracks_;

// resize accordingly
reducedCMSSW.resize(cmsswtracks.size());

for (int itrack = 0; itrack < (int) cmsswtracks.size(); itrack++)
{
// get the needed tracks and extras
auto & cmsswextra = cmsswextras[itrack];
const auto & cmsswtrack = cmsswtracks[itrack];
const int seedID = cmsswextras[itrack].seedID();
const SVector6 & params = cmsswtrack.parameters();
const auto & seedtrack = seedtracks[cmsswToSeedMap_[cmsswtrack.label()]]; // since cmsswtrack.label() == itrack

// set seed hits!
cmsswextra.findMatchingSeedHits(cmsswtrack,seedtrack,layerhits);

// get tmp vars
const auto seedID = cmsswextra.seedID();
const auto & params = cmsswtrack.parameters();
SVector2 tmpv(params[3],params[5]);

HitLayerMap tmpmap;
Expand All @@ -984,8 +1076,8 @@ void TTreeValidation::setupCMSSWMatching(const Event & ev, RedTrackVec & reduced
const int lyr = cmsswtrack.getHitLyr(ihit);
const int idx = cmsswtrack.getHitIdx(ihit);

// don't bother with seed layer hits
if (Config::TrkInfo.is_seed_lyr(lyr)) continue;
// don't bother with storing seed layers in reduced cmssw
if (cmsswextra.isSeedHit(lyr,idx)) continue;

if (lyr >= 0 && idx >= 0)
{
Expand Down
8 changes: 8 additions & 0 deletions TTreeValidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class TTreeValidation : public Validation {
const TrackVec& pairtracks, const TrackExtraVec& pairextras);
void makeCMSSWTkToRecoTksMaps(Event& ev) override;
void makeSeedTkToCMSSWTkMap(Event& ev) override;
void makeCMSSWTkToSeedTkMap(Event& ev) override;
void makeRecoTkToSeedTkMapsDumbCMSSW(Event& ev) override;
void makeRecoTkToSeedTkMapDumbCMSSW(const TrackExtraVec& recoextras, const TrackExtraVec& seedextras, TkIDToTkIDMap& recoToSeedMap);

void storeSeedAndMCID(Event& ev);
void setupCMSSWMatching(const Event & ev, RedTrackVec & reducedCMSSW, LayIdxIDVecMapMap & cmsswHitIDMap);
Expand Down Expand Up @@ -87,6 +90,7 @@ class TTreeValidation : public Validation {

// Special map for CMSSW tracks to seed track labels --> NOT used for fake rate!!
TkIDToTkIDMap seedToCmsswMap_;
TkIDToTkIDMap cmsswToSeedMap_;

// Special map for geting exact CMSSW track that originate build track from seed track through seedIDs
TkIDToTkIDMap buildToCmsswMap_;
Expand All @@ -95,6 +99,10 @@ class TTreeValidation : public Validation {
TkIDToTkIDMap buildToFitMap_;
TkIDToTkIDMap fitToBuildMap_;

// Special map for associating reco tracks to seed tracks for sim_val_for_cmssw
TkIDToTkIDMap candToSeedMapDumbCMSSW_;
TkIDToTkIDMap fitToSeedMapDumbCMSSW_;

// Efficiency Tree
TTree* efftree_;
int evtID_eff_=0,mcID_eff_=0;
Expand Down
Loading

0 comments on commit 35a1948

Please sign in to comment.