Skip to content

Commit

Permalink
code-format
Browse files Browse the repository at this point in the history
  • Loading branch information
ademoor committed Apr 6, 2024
1 parent 33e534e commit a508a92
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 91 deletions.
2 changes: 0 additions & 2 deletions DataFormats/BTauReco/interface/LostTracksFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace btagbtvdeep {

class LostTracksFeatures {
public:

float btagPf_trackEtaRel;
float btagPf_trackPtRel;
float btagPf_trackPPar;
Expand All @@ -28,7 +27,6 @@ namespace btagbtvdeep {
float eta;
float phi;
float e;

};

} // namespace btagbtvdeep
Expand Down
Binary file not shown.
2 changes: 0 additions & 2 deletions RecoBTag/FeatureTools/interface/ChargedCandidateConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ namespace btagbtvdeep {
c_pf_features.px = c_pf->px();
c_pf_features.py = c_pf->py();
c_pf_features.pz = c_pf->pz();


}

void packedCandidateToFeatures(const pat::PackedCandidate* c_pf,
Expand Down
3 changes: 1 addition & 2 deletions RecoBTag/FeatureTools/interface/TrackInfoBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace btagbtvdeep {
const float getTrackSip2dVal() const { return trackSip2dVal_; }
const float getTrackSip3dSig() const { return trackSip3dSig_; }
const float getTrackSip3dVal() const { return trackSip3dVal_; }
const float getTrackJetDecayLen() const {return trackJetDecayLen_;}
const float getTrackJetDecayLen() const { return trackJetDecayLen_; }

private:
edm::ESHandle<TransientTrackBuilder> builder_;
Expand All @@ -52,7 +52,6 @@ namespace btagbtvdeep {
float trackJetDistVal_;
float trackJetDistSig_;
float trackJetDecayLen_;

};

} // namespace btagbtvdeep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class UnifiedParticleTransformerAK4TagInfoProducer : public edm::stream::EDProdu
const double max_jet_eta_;
};

UnifiedParticleTransformerAK4TagInfoProducer::UnifiedParticleTransformerAK4TagInfoProducer(const edm::ParameterSet& iConfig)
UnifiedParticleTransformerAK4TagInfoProducer::UnifiedParticleTransformerAK4TagInfoProducer(
const edm::ParameterSet& iConfig)
: jet_radius_(iConfig.getParameter<double>("jet_radius")),
min_candidate_pt_(iConfig.getParameter<double>("min_candidate_pt")),
flip_(iConfig.getParameter<bool>("flip")),
Expand Down Expand Up @@ -265,68 +266,71 @@ void UnifiedParticleTransformerAK4TagInfoProducer::produce(edm::Event& iEvent, c
for (size_t i = 0; i < LTs->size(); ++i) {
auto cand = LTs->at(i);
if ((reco::deltaR(cand, jet) < 0.2)) {
const auto *PackedCandidate_ = dynamic_cast<const pat::PackedCandidate*>(&(cand));
if(PackedCandidate_){
if(PackedCandidate_->pt() < 1.0) continue;
const auto* PackedCandidate_ = dynamic_cast<const pat::PackedCandidate*>(&(cand));
if (PackedCandidate_) {
if (PackedCandidate_->pt() < 1.0)
continue;
auto& trackinfo = lt_trackinfos.emplace(i, track_builder).first->second;
trackinfo.buildTrackInfo(PackedCandidate_,jet_dir, jet_ref_track_dir, pv);
trackinfo.buildTrackInfo(PackedCandidate_, jet_dir, jet_ref_track_dir, pv);

lt_sorted.emplace_back(i,
trackinfo.getTrackSip2dSig(),
-btagbtvdeep::mindrsvpfcand(svs_unsorted, PackedCandidate_),
PackedCandidate_->pt() / jet.pt());
trackinfo.getTrackSip2dSig(),
-btagbtvdeep::mindrsvpfcand(svs_unsorted, PackedCandidate_),
PackedCandidate_->pt() / jet.pt());
}
}
}

// sort lt collection
std::sort(lt_sorted.begin(), lt_sorted.end(), btagbtvdeep::SortingClass<std::size_t>::compareByABCInv);
std::vector<size_t> lt_sortedindices;
lt_sortedindices = btagbtvdeep::invertSortingVector(lt_sorted);

// set right size to vectors
// set right size to vectors
features.lt_features.clear();
features.lt_features.resize(lt_sorted.size());

for (size_t i = 0; i < LTs->size(); ++i) {
auto cand = LTs->at(i);
if ((reco::deltaR(cand, jet) < 0.2)) {
const auto *PackedCandidate_ = dynamic_cast<const pat::PackedCandidate*>(&(cand));
if(!PackedCandidate_) continue;
if(PackedCandidate_->pt() < 1.0) continue;

//auto reco_cand = dynamic_cast<const reco::PFCandidate*>(cand);
float puppiw = PackedCandidate_->puppiWeight();

float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, PackedCandidate_);
float distminpfcandsv = 0;

auto entry = lt_sortedindices.at(i);
// get cached track info
auto& trackinfo = lt_trackinfos.at(i);
// get_ref to vector element
auto& lt_features = features.lt_features.at(entry);

if (PackedCandidate_) {
if (PackedCandidate_->hasTrackDetails()) {
const reco::Track& PseudoTrack = PackedCandidate_->pseudoTrack();
reco::TransientTrack transientTrack;
transientTrack = track_builder->build(PseudoTrack);
distminpfcandsv = btagbtvdeep::mindistsvpfcand(svs_unsorted, transientTrack);
}

btagbtvdeep::packedCandidateToFeatures(PackedCandidate_,
jet,
trackinfo,
is_weighted_jet_,
drminpfcandsv,
static_cast<float>(jet_radius_),
puppiw,
lt_features,
flip_,
distminpfcandsv);
}
}
const auto* PackedCandidate_ = dynamic_cast<const pat::PackedCandidate*>(&(cand));
if (!PackedCandidate_)
continue;
if (PackedCandidate_->pt() < 1.0)
continue;

//auto reco_cand = dynamic_cast<const reco::PFCandidate*>(cand);
float puppiw = PackedCandidate_->puppiWeight();

float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, PackedCandidate_);
float distminpfcandsv = 0;

auto entry = lt_sortedindices.at(i);
// get cached track info
auto& trackinfo = lt_trackinfos.at(i);
// get_ref to vector element
auto& lt_features = features.lt_features.at(entry);

if (PackedCandidate_) {
if (PackedCandidate_->hasTrackDetails()) {
const reco::Track& PseudoTrack = PackedCandidate_->pseudoTrack();
reco::TransientTrack transientTrack;
transientTrack = track_builder->build(PseudoTrack);
distminpfcandsv = btagbtvdeep::mindistsvpfcand(svs_unsorted, transientTrack);
}

btagbtvdeep::packedCandidateToFeatures(PackedCandidate_,
jet,
trackinfo,
is_weighted_jet_,
drminpfcandsv,
static_cast<float>(jet_radius_),
puppiw,
lt_features,
flip_,
distminpfcandsv);
}
}
}

// fill collection, from DeepTNtuples plus some styling
Expand Down
32 changes: 13 additions & 19 deletions RecoBTag/FeatureTools/src/ChargedCandidateConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ namespace btagbtvdeep {

c_pf_features.CaloFrac = c_pf->caloFraction();
c_pf_features.HadFrac = c_pf->hcalFraction();
c_pf_features.lostInnerHits = catch_infs(c_pf->lostInnerHits(),2);
c_pf_features.numberOfPixelHits = catch_infs(c_pf->numberOfPixelHits(),-1);
c_pf_features.numberOfStripHits = catch_infs(c_pf->stripLayersWithMeasurement(),-1);
c_pf_features.lostInnerHits = catch_infs(c_pf->lostInnerHits(), 2);
c_pf_features.numberOfPixelHits = catch_infs(c_pf->numberOfPixelHits(), -1);
c_pf_features.numberOfStripHits = catch_infs(c_pf->stripLayersWithMeasurement(), -1);

// if PackedCandidate does not have TrackDetails this gives an Exception
// because unpackCovariance might be called for pseudoTrack/bestTrack
if (c_pf->hasTrackDetails()) {
Expand All @@ -45,28 +45,22 @@ namespace btagbtvdeep {
c_pf_features.dzsig = c_pf->bestTrack() ? catch_infs(c_pf->dz() / c_pf->dzError()) : 0;

float pdgid_;
if (abs(c_pf->pdgId()) == 11 and c_pf->charge() != 0){
if (abs(c_pf->pdgId()) == 11 and c_pf->charge() != 0) {
pdgid_ = 0.0;
}
else if (abs(c_pf->pdgId()) == 13 and c_pf->charge() != 0){
} else if (abs(c_pf->pdgId()) == 13 and c_pf->charge() != 0) {
pdgid_ = 1.0;
}
else if (abs(c_pf->pdgId()) == 22 and c_pf->charge() == 0){
} else if (abs(c_pf->pdgId()) == 22 and c_pf->charge() == 0) {
pdgid_ = 2.0;
}
else if (abs(c_pf->pdgId()) != 22 and c_pf->charge() == 0 and abs(c_pf->pdgId()) != 1 and abs(c_pf->pdgId()) != 2){
} else if (abs(c_pf->pdgId()) != 22 and c_pf->charge() == 0 and abs(c_pf->pdgId()) != 1 and
abs(c_pf->pdgId()) != 2) {
pdgid_ = 3.0;
}
else if (abs(c_pf->pdgId()) != 11 and abs(c_pf->pdgId()) != 13 and c_pf->charge() != 0){
} else if (abs(c_pf->pdgId()) != 11 and abs(c_pf->pdgId()) != 13 and c_pf->charge() != 0) {
pdgid_ = 4.0;
}
else if (c_pf->charge() == 0 and abs(c_pf->pdgId()) == 1){
} else if (c_pf->charge() == 0 and abs(c_pf->pdgId()) == 1) {
pdgid_ = 5.0;
}
else if (c_pf->charge() == 0 and abs(c_pf->pdgId()) == 2){
} else if (c_pf->charge() == 0 and abs(c_pf->pdgId()) == 2) {
pdgid_ = 6.0;
}
else{
} else {
pdgid_ = 7.0;
}
c_pf_features.pdgID = pdgid_;
Expand Down
8 changes: 3 additions & 5 deletions RecoBTag/FeatureTools/src/LostTracksConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace btagbtvdeep {
lt_features.puppiw = puppiw;
lt_features.charge = c_pf->charge();

lt_features.lostInnerHits = catch_infs(c_pf->lostInnerHits(),2);
lt_features.numberOfPixelHits = catch_infs(c_pf->numberOfPixelHits(),-1);
lt_features.numberOfStripHits = catch_infs(c_pf->stripLayersWithMeasurement(),-1);
lt_features.lostInnerHits = catch_infs(c_pf->lostInnerHits(), 2);
lt_features.numberOfPixelHits = catch_infs(c_pf->numberOfPixelHits(), -1);
lt_features.numberOfStripHits = catch_infs(c_pf->stripLayersWithMeasurement(), -1);

// if PackedCandidate does not have TrackDetails this gives an Exception
// because unpackCovariance might be called for pseudoTrack/bestTrack
Expand All @@ -34,7 +34,6 @@ namespace btagbtvdeep {
lt_features.chi2 = catch_infs_and_bound(-1, 300, -1, 300);
lt_features.quality = (1 << reco::TrackBase::loose);
}

}
void recoCandidateToFeatures(const reco::PFCandidate* c_pf,
const reco::Jet& jet,
Expand All @@ -56,7 +55,6 @@ namespace btagbtvdeep {
const auto& pseudo_track = (c_pf->bestTrack()) ? *c_pf->bestTrack() : reco::Track();
lt_features.chi2 = catch_infs_and_bound(std::floor(pseudo_track.normalizedChi2()), 300, -1, 300);
lt_features.quality = quality_from_pfcand(*c_pf);

}

} // namespace btagbtvdeep
6 changes: 3 additions & 3 deletions RecoBTag/FeatureTools/src/TrackInfoBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace btagbtvdeep {
trackSip3dSig_(0),
trackJetDistVal_(0),
trackJetDistSig_(0),
trackJetDecayLen_(0) {}
trackJetDecayLen_(0) {}

void TrackInfoBuilder::buildTrackInfo(const reco::Candidate *candidate,
const math::XYZVector &jetDir,
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace btagbtvdeep {
trackSip3dSig_ = 0.;
trackJetDistVal_ = 0.;
trackJetDistSig_ = 0.;
trackJetDecayLen_=0.;
trackJetDecayLen_ = 0.;
return;
}

Expand Down Expand Up @@ -94,7 +94,7 @@ namespace btagbtvdeep {
trackJetDistVal_ = static_cast<float>(jetdist.value());
trackJetDistSig_ = static_cast<float>(jetdist.significance());

trackJetDecayLen_= static_cast<float>(decayl.value());
trackJetDecayLen_ = static_cast<float>(decayl.value());
}

} // namespace btagbtvdeep
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class UnifiedParticleTransformerAK4ONNXJetTagsProducer : public edm::stream::EDP
FloatArrays data_;
};

UnifiedParticleTransformerAK4ONNXJetTagsProducer::UnifiedParticleTransformerAK4ONNXJetTagsProducer(const edm::ParameterSet& iConfig,
const ONNXRuntime* cache)
UnifiedParticleTransformerAK4ONNXJetTagsProducer::UnifiedParticleTransformerAK4ONNXJetTagsProducer(
const edm::ParameterSet& iConfig, const ONNXRuntime* cache)
: src_(consumes<TagInfoCollection>(iConfig.getParameter<edm::InputTag>("src"))),
flav_names_(iConfig.getParameter<std::vector<std::string>>("flav_names")),
input_names_(iConfig.getParameter<std::vector<std::string>>("input_names")),
Expand All @@ -87,14 +87,18 @@ void UnifiedParticleTransformerAK4ONNXJetTagsProducer::fillDescriptions(edm::Con
// pfUnifiedParticleTransformerAK4JetTags
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("src", edm::InputTag("pfUnifiedParticleTransformerAK4TagInfos"));
desc.add<std::vector<std::string>>("input_names", {"input_1", "input_2", "input_3", "input_4", "input_5", "input_6", "input_7", "input_8"});
desc.add<edm::FileInPath>("model_path",
edm::FileInPath("RecoBTag/Combined/data/UParTAK4/PUPPI/V00/UParTAK4.onnx"));
desc.add<std::vector<std::string>>(
"input_names", {"input_1", "input_2", "input_3", "input_4", "input_5", "input_6", "input_7", "input_8"});
desc.add<edm::FileInPath>("model_path", edm::FileInPath("RecoBTag/Combined/data/UParTAK4/PUPPI/V00/UParTAK4.onnx"));
desc.add<std::vector<std::string>>("output_names", {"softmax"});
desc.add<std::vector<std::string>>(
"flav_names", std::vector<std::string>{"probb", "probbb", "problepb", "probc", "probs", "probu", "probd", "probg", "probele", "probmu",
"probtaup1h0p", "probtaup1h1p", "probtaup1h2p", "probtaup3h0p", "probtaup3h1p", "probtaum1h0p", "probtaum1h1p", "probtaum1h2p", "probtaum3h0p", "probtaum3h1p",
"ptcorr", "ptreshigh", "ptreslow", "ptnu", "probemudata", "probemumc", "probdimudata", "probdimumc", "probmutaudata", "probmutaumc"});
"flav_names",
std::vector<std::string>{"probb", "probbb", "problepb", "probc", "probs",
"probu", "probd", "probg", "probele", "probmu",
"probtaup1h0p", "probtaup1h1p", "probtaup1h2p", "probtaup3h0p", "probtaup3h1p",
"probtaum1h0p", "probtaum1h1p", "probtaum1h2p", "probtaum3h0p", "probtaum3h1p",
"ptcorr", "ptreshigh", "ptreslow", "ptnu", "probemudata",
"probemumc", "probdimudata", "probdimumc", "probmutaudata", "probmutaumc"});

descriptions.add("pfUnifiedParticleTransformerAK4JetTags", desc);
}
Expand Down Expand Up @@ -194,15 +198,16 @@ void UnifiedParticleTransformerAK4ONNXJetTagsProducer::get_input_sizes(
make_inputs(features);
}

void UnifiedParticleTransformerAK4ONNXJetTagsProducer::make_inputs(btagbtvdeep::UnifiedParticleTransformerAK4Features features) {
void UnifiedParticleTransformerAK4ONNXJetTagsProducer::make_inputs(
btagbtvdeep::UnifiedParticleTransformerAK4Features features) {
float* ptr = nullptr;
const float* start = nullptr;
unsigned offset = 0;

// c_pf candidates
auto max_c_pf_n = std::min(features.c_pf_features.size(), (std::size_t)n_cpf_);
for (std::size_t c_pf_n = 0; c_pf_n < max_c_pf_n; c_pf_n++) {
const auto& c_pf_features = features.c_pf_features.at(c_pf_n);
const auto& c_pf_features = features.c_pf_features.at(c_pf_n);
ptr = &data_[kChargedCandidates][offset + c_pf_n * n_features_cpf_];
start = ptr;
*ptr = c_pf_features.btagPf_trackEtaRel;
Expand Down Expand Up @@ -261,7 +266,7 @@ void UnifiedParticleTransformerAK4ONNXJetTagsProducer::make_inputs(btagbtvdeep::
assert(start + n_features_lt_ - 1 == ptr);
}

// n_pf candidates
// n_pf candidates
auto max_n_pf_n = std::min(features.n_pf_features.size(), (std::size_t)n_npf_);
for (std::size_t n_pf_n = 0; n_pf_n < max_n_pf_n; n_pf_n++) {
const auto& n_pf_features = features.n_pf_features.at(n_pf_n);
Expand Down
2 changes: 1 addition & 1 deletion RecoBTag/ONNXRuntime/test/test_deep_flavour_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
from PhysicsTools.PatAlgos.patInputFiles_cff import filesRelValTTbarPileUpMINIAODSIM

process.source.fileNames = filesRelValTTbarPileUpMINIAODSIM
process.source.fileNames = cms.untracked.vstring('/store/mc/PhaseIFall16MiniAOD/TT_TuneCUETP8M2T4_13TeV-powheg-pythia8/MINIAODSIM/PhaseIFall16PUFlat20to50_PhaseIFall16_81X_upgrade2017_realistic_v26-v1/50000/08358A47-61E3-E611-8B77-001E677928AE.root')
process.source.fileNames = cms.untracked.vstring('/store/mc/Run3Summer23BPixMiniAODv4/TTtoLNu2Q_TuneCP5_13p6TeV_powheg-pythia8/MINIAODSIM/130X_mcRun3_2023_realistic_postBPix_v2-v3/2520000/00488681-4f49-4bdc-89e6-198da9e42a17.root')

process.maxEvents.input = 10

Expand Down
Loading

0 comments on commit a508a92

Please sign in to comment.