Skip to content

Commit

Permalink
Set fallback puppi weight to 1.0 for packed_cand also. throw exceptio…
Browse files Browse the repository at this point in the history
…n when jet is weighted but no ValueMap is set. code-checks formatting.
  • Loading branch information
nurfikri89 committed Feb 15, 2023
1 parent e07e033 commit 79f3a5b
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 45 deletions.
5 changes: 3 additions & 2 deletions RecoBTag/FeatureTools/interface/ChargedCandidateConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ namespace btagbtvdeep {
c_pf_features.deltaR = reco::deltaR(*c_pf, jet);

float constituentWeight = 1.;
if (isWeightedJet) constituentWeight = puppiw;
if (isWeightedJet)
constituentWeight = puppiw;

c_pf_features.ptrel = catch_infs_and_bound((c_pf->pt() * constituentWeight) / jet.pt(), 0, -1, 0, -1);
c_pf_features.ptrel_noclip = (c_pf->pt() * constituentWeight) / jet.pt();
c_pf_features.ptrel_noclip = (c_pf->pt() * constituentWeight) / jet.pt();
c_pf_features.erel = (c_pf->energy() * constituentWeight) / jet.energy();

const float etasign = jet.eta() > 0 ? 1 : -1;
Expand Down
5 changes: 3 additions & 2 deletions RecoBTag/FeatureTools/interface/NeutralCandidateConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ namespace btagbtvdeep {
n_pf_features.drsubjet2 = drSubjetFeatures.second;

float constituentWeight = 1.;
if (isWeightedJet) constituentWeight = puppiw;
if (isWeightedJet)
constituentWeight = puppiw;

// Jet relative vars
n_pf_features.ptrel = catch_infs_and_bound((n_pf->pt() * constituentWeight) / jet.pt(), 0, -1, 0, -1);
Expand All @@ -49,7 +50,7 @@ namespace btagbtvdeep {

n_pf_features.deltaR = catch_infs_and_bound(reco::deltaR(*n_pf, jet), 0, -0.6, 0, -0.6);
n_pf_features.deltaR_noclip = reco::deltaR(*n_pf, jet);

n_pf_features.isGamma = 0;
if (std::abs(n_pf->pdgId()) == 22)
n_pf_features.isGamma = 1;
Expand Down
17 changes: 11 additions & 6 deletions RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ DeepBoostedJetTagInfoProducer::DeepBoostedJetTagInfoProducer(const edm::Paramete
if (!puppi_value_map_tag.label().empty()) {
puppi_value_map_token_ = consumes<edm::ValueMap<float>>(puppi_value_map_tag);
use_puppi_value_map_ = true;
} else if (use_puppiP4_) {
throw edm::Exception(edm::errors::Configuration,
"puppi_value_map is not set but use_puppiP4 is set to True. Must also set puppi_value_map.");
}

const auto &pvas_tag = iConfig.getParameter<edm::InputTag>("vertex_associator");
Expand Down Expand Up @@ -323,14 +326,16 @@ void DeepBoostedJetTagInfoProducer::produce(edm::Event &iEvent, const edm::Event
float DeepBoostedJetTagInfoProducer::puppiWgt(const reco::CandidatePtr &cand) {
const auto *pack_cand = dynamic_cast<const pat::PackedCandidate *>(&(*cand));
const auto *reco_cand = dynamic_cast<const reco::PFCandidate *>(&(*cand));
float wgt = 1.;
if (pack_cand){
//fallback value
wgt = pack_cand->puppiWeight();

//
// Access puppi weight from ValueMap.
//
float wgt = 1.; // Set to fallback value

if (pack_cand) {
if (use_puppi_value_map_)
wgt = (*puppi_value_map_)[cand];
}
else if (reco_cand) {
} else if (reco_cand) {
if (use_puppi_value_map_)
wgt = (*puppi_value_map_)[cand];
} else
Expand Down
59 changes: 40 additions & 19 deletions RecoBTag/FeatureTools/plugins/DeepDoubleXTagInfoProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,19 @@ DeepDoubleXTagInfoProducer::DeepDoubleXTagInfoProducer(const edm::ParameterSet&
shallow_tag_info_token_(
consumes<BoostedDoubleSVTagInfoCollection>(iConfig.getParameter<edm::InputTag>("shallow_tag_infos"))),
track_builder_token_(
esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"))),
esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"))),
use_puppi_value_map_(false),
fallback_puppi_weight_(iConfig.getParameter<bool>("fallback_puppi_weight")),
is_weighted_jet_(iConfig.getParameter<bool>("is_weighted_jet"))
{
is_weighted_jet_(iConfig.getParameter<bool>("is_weighted_jet")) {
produces<DeepDoubleXTagInfoCollection>();

const auto& puppi_value_map_tag = iConfig.getParameter<edm::InputTag>("puppi_value_map");
if (!puppi_value_map_tag.label().empty()) {
puppi_value_map_token_ = consumes<edm::ValueMap<float>>(puppi_value_map_tag);
use_puppi_value_map_ = true;
} else if (is_weighted_jet_) {
throw edm::Exception(edm::errors::Configuration,
"puppi_value_map is not set but jet is weighted. Must set puppi_value_map.");
}
}

Expand Down Expand Up @@ -289,34 +291,37 @@ void DeepDoubleXTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
reco::PFCandidatePtr reco_ptr;
if (pf_jet) {
reco_ptr = pf_jet->getPFConstituent(i);
}
}

reco::CandidatePtr cand_ptr;
if (pat_jet){
if (pat_jet) {
cand_ptr = pat_jet->sourceCandidatePtr(i);
}

float puppiw = 1.0; // fallback value
//
// Access puppi weight from ValueMap.
//
float puppiw = 1.0; // Set to fallback value

if (reco_cand) {
puppiw = 1.0; // fallback value for reco_cand
if (use_puppi_value_map_)
puppiw = (*puppi_value_map)[reco_ptr];
else if (!fallback_puppi_weight_) {
throw edm::Exception(edm::errors::InvalidReference, "PUPPI value map missing")
<< "use fallback_puppi_weight option to use " << puppiw << " for reco_cand as default";
<< "use fallback_puppi_weight option to use " << puppiw << " for reco_cand as default";
}
}
else if(packed_cand){
puppiw = packed_cand->puppiWeight(); // fallback value for packed_cand
} else if (packed_cand) {
if (use_puppi_value_map_)
puppiw = (*puppi_value_map)[cand_ptr];
else if (!fallback_puppi_weight_) {
throw edm::Exception(edm::errors::InvalidReference, "PUPPI value map missing")
<< "use fallback_puppi_weight option to use puppiWeight() for packed_cand as default";
<< "use fallback_puppi_weight option to use " << puppiw << " for packed_cand as default";
}
} else {
throw edm::Exception(edm::errors::InvalidReference)
<< "Cannot convert to either reco::PFCandidate or pat::PackedCandidate";
}


float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_);
if (cand->charge() != 0) {
// is charged candidate
Expand All @@ -326,8 +331,14 @@ void DeepDoubleXTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
// get_ref to vector element
auto& c_pf_features = features.c_pf_features.at(entry);
if (packed_cand) {
btagbtvdeep::packedCandidateToFeatures(
packed_cand, *pat_jet, trackinfo, is_weighted_jet_, drminpfcandsv, static_cast<float>(jet_radius_), puppiw, c_pf_features);
btagbtvdeep::packedCandidateToFeatures(packed_cand,
*pat_jet,
trackinfo,
is_weighted_jet_,
drminpfcandsv,
static_cast<float>(jet_radius_),
puppiw,
c_pf_features);
} else if (reco_cand) {
// get vertex association quality
int pv_ass_quality = 0; // fallback value
Expand Down Expand Up @@ -362,11 +373,21 @@ void DeepDoubleXTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
auto& n_pf_features = features.n_pf_features.at(entry);
// // fill feature structure
if (packed_cand) {
btagbtvdeep::packedCandidateToFeatures(
packed_cand, *pat_jet, is_weighted_jet_, drminpfcandsv, static_cast<float>(jet_radius_), puppiw, n_pf_features);
btagbtvdeep::packedCandidateToFeatures(packed_cand,
*pat_jet,
is_weighted_jet_,
drminpfcandsv,
static_cast<float>(jet_radius_),
puppiw,
n_pf_features);
} else if (reco_cand) {
btagbtvdeep::recoCandidateToFeatures(
reco_cand, jet, is_weighted_jet_, drminpfcandsv, static_cast<float>(jet_radius_), puppiw, n_pf_features);
btagbtvdeep::recoCandidateToFeatures(reco_cand,
jet,
is_weighted_jet_,
drminpfcandsv,
static_cast<float>(jet_radius_),
puppiw,
n_pf_features);
}
}
}
Expand Down
36 changes: 24 additions & 12 deletions RecoBTag/FeatureTools/plugins/DeepFlavourTagInfoProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ DeepFlavourTagInfoProducer::DeepFlavourTagInfoProducer(const edm::ParameterSet&
if (!puppi_value_map_tag.label().empty()) {
puppi_value_map_token_ = consumes<edm::ValueMap<float>>(puppi_value_map_tag);
use_puppi_value_map_ = true;
} else if (is_weighted_jet_) {
throw edm::Exception(edm::errors::Configuration,
"puppi_value_map is not set but jet is weighted. Must set puppi_value_map.");
}

const auto& pvas_tag = iConfig.getParameter<edm::InputTag>("vertex_associator");
Expand Down Expand Up @@ -368,31 +371,33 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
reco_ptr = pat_jet->getPFConstituent(i);
}

reco::CandidatePtr cand_ptr;
if (pat_jet){
reco::CandidatePtr cand_ptr;
if (pat_jet) {
cand_ptr = pat_jet->sourceCandidatePtr(i);
}

// get PUPPI weight from value map
float puppiw = 1.0; // fallback value
//
// Access puppi weight from ValueMap.
//
float puppiw = 1.0; // Set to fallback value

if (reco_cand) {
puppiw = 1.0; // fallback value for reco_cand
if (use_puppi_value_map_)
puppiw = (*puppi_value_map)[reco_ptr];
else if (!fallback_puppi_weight_) {
throw edm::Exception(edm::errors::InvalidReference, "PUPPI value map missing")
<< "use fallback_puppi_weight option to use " << puppiw << " for reco_cand as default";
<< "use fallback_puppi_weight option to use " << puppiw << " for reco_cand as default";
}
}
else if(packed_cand){
puppiw = packed_cand->puppiWeight(); // fallback value for packed_cand
} else if (packed_cand) {
if (use_puppi_value_map_)
puppiw = (*puppi_value_map)[cand_ptr];
else if (!fallback_puppi_weight_) {
throw edm::Exception(edm::errors::InvalidReference, "PUPPI value map missing")
<< "use fallback_puppi_weight option to use puppiWeight() for packed_cand as default";
<< "use fallback_puppi_weight option to use " << puppiw << " for packed_cand as default";
}
} else {
throw edm::Exception(edm::errors::InvalidReference)
<< "Cannot convert to either reco::PFCandidate or pat::PackedCandidate";
}

float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, cand);
Expand All @@ -409,8 +414,15 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
auto& c_pf_features = features.c_pf_features.at(entry);
// fill feature structure
if (packed_cand) {
btagbtvdeep::packedCandidateToFeatures(
packed_cand, jet, trackinfo, is_weighted_jet_, drminpfcandsv, static_cast<float>(jet_radius_), puppiw, c_pf_features, flip_);
btagbtvdeep::packedCandidateToFeatures(packed_cand,
jet,
trackinfo,
is_weighted_jet_,
drminpfcandsv,
static_cast<float>(jet_radius_),
puppiw,
c_pf_features,
flip_);
} else if (reco_cand) {
// get vertex association quality
int pv_ass_quality = 0; // fallback value
Expand Down
4 changes: 2 additions & 2 deletions RecoBTag/FeatureTools/src/ChargedCandidateConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace btagbtvdeep {
void packedCandidateToFeatures(const pat::PackedCandidate* c_pf,
const pat::Jet& jet,
const TrackInfoBuilder& track_info,
const bool isWeightedJet,
const bool isWeightedJet,
const float drminpfcandsv,
const float jetR,
const float puppiw,
Expand Down Expand Up @@ -39,7 +39,7 @@ namespace btagbtvdeep {
void recoCandidateToFeatures(const reco::PFCandidate* c_pf,
const reco::Jet& jet,
const TrackInfoBuilder& track_info,
const bool isWeightedJet,
const bool isWeightedJet,
const float drminpfcandsv,
const float jetR,
const float puppiw,
Expand Down
4 changes: 2 additions & 2 deletions RecoBTag/FeatureTools/src/NeutralCandidateConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace btagbtvdeep {

void packedCandidateToFeatures(const pat::PackedCandidate* n_pf,
const pat::Jet& jet,
const bool isWeightedJet,
const bool isWeightedJet,
const float drminpfcandsv,
const float jetR,
const float puppiw,
Expand All @@ -17,7 +17,7 @@ namespace btagbtvdeep {

void recoCandidateToFeatures(const reco::PFCandidate* n_pf,
const reco::Jet& jet,
const bool isWeightedJet,
const bool isWeightedJet,
const float drminpfcandsv,
const float jetR,
const float puppiw,
Expand Down

0 comments on commit 79f3a5b

Please sign in to comment.