Skip to content

Commit

Permalink
Removing try/catch pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
borzari committed Jun 8, 2024
1 parent dbbd44f commit 95ecc4b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
3 changes: 3 additions & 0 deletions DataFormats/TrackReco/interface/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ namespace reco {
/// get the residuals
const TrackResiduals& residuals() const { return extra_->residuals(); }

// Check validity of track extra and rechits
bool recHitsOk() const { return extra_.isNonnull() && extra_.isAvailable() && extra_->recHitsOk(); }

private:
/// Reference to additional information stored only on RECO.
TrackExtraRef extra_;
Expand Down
3 changes: 3 additions & 0 deletions DataFormats/TrackReco/interface/TrackExtraBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ namespace reco {
TrajParams const& trajParams() const { return m_trajParams; }
Chi2sFive const& chi2sX5() const { return m_chi2sX5; }

// Check validity of track rechits
bool recHitsOk() const { return m_hitCollection.isNonnull() && m_hitCollection.isAvailable(); }

private:
edm::RefCore m_hitCollection;
unsigned int m_firstHit;
Expand Down
48 changes: 9 additions & 39 deletions RecoTracker/FinalTrackSelectors/plugins/SingleLongTrackProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,66 +151,36 @@ void SingleLongTrackProducer::produce(edm::Event &iEvent, const edm::EventSetup
bool hitIsNotValid{false};

for (const auto &track : selTracks) {
reco::HitPattern hitpattern = track.hitPattern();
int deref{0};

// this checks track recHits
try { // (Un)Comment this line with /* to (not) allow for events with not valid hits
// Check validity of track extra and rechits
if (track.recHitsOk()) {
reco::HitPattern hitpattern = track.hitPattern();
auto hb = track.recHitsBegin();

// Checking if rechits are valid
for (unsigned int h = 0; h < track.recHitsSize(); h++) {
auto recHit = *(hb + h);
auto const &hit = *recHit;

if (onlyValidHits && !hit.isValid()) {
hitIsNotValid = true;
continue;
}
}
} catch (cms::Exception const &e) {
deref += 1;
if (debug)
std::cerr << e.explainSelf() << std::endl;
}

if (hitIsNotValid == true)
break; // (Un)Comment this line with */ to (not) allow for events with not valid hits

int deref2{0};

// this checks track hitPattern hits
try {
auto hb = track.recHitsBegin();
if (hitIsNotValid == true)
break; // (Un)Comment this line to (not) allow for events with not valid hits

// Checking if hitpattern hits are valid
for (unsigned int h = 0; h < track.recHitsSize(); h++) {
uint32_t pHit = hitpattern.getHitPattern(reco::HitPattern::TRACK_HITS, h);

auto recHit = *(hb + h);
auto const &hit = *recHit;

if (onlyValidHits && !hit.isValid()) {
if (debug)
edm::LogPrint("SingleLongTrackProducer") << "hit not valid: " << h;
continue;
}

// loop over the hits of the track.
if (onlyValidHits && !(hitpattern.validHitFilter(pHit))) {
if (debug)
edm::LogPrint("SingleLongTrackProducer") << "hit not valid: " << h;
continue;
}
}
goodTracks->push_back(track);
} catch (cms::Exception const &e) {
deref2 += 1;
if (debug)
std::cerr << e.explainSelf() << std::endl;
}

if (debug)
edm::LogPrint("SingleLongTrackProducer")
<< "found tracks with " << deref << "missing valid hits and " << deref2 << " missing hit pattern";
} else
break;
}

if (debug) {
Expand Down

0 comments on commit 95ecc4b

Please sign in to comment.