Skip to content

Commit

Permalink
add pv association quatily to producer and also sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodecm committed Aug 20, 2017
1 parent b640451 commit 3383998
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
4 changes: 2 additions & 2 deletions PhysicsTools/PatAlgos/python/tools/jetTools.py
Expand Up @@ -546,10 +546,10 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
vertices=pvSource,
secondary_vertices=svSource,
puppi_value_map = "", # so it is not used
pvasq_value_map = "", # so it is not used
),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)

acceptedTagInfos.append(btagInfo)
elif hasattr(toptag, btagInfo) :
acceptedTagInfos.append(btagInfo)
Expand Down
41 changes: 32 additions & 9 deletions RecoBTag/DeepFlavour/plugins/DeepFlavourTagInfoProducer.cc
Expand Up @@ -28,6 +28,10 @@
#include "RecoBTag/DeepFlavour/interface/TrackInfoBuilder.h"
#include "RecoBTag/DeepFlavour/interface/sorting_modules.h"

// conversion map from quality flags used in PV association and miniAOD one
constexpr int qualityMap[8] = {1,0,1,1,4,4,5,6};


class DeepFlavourTagInfoProducer : public edm::stream::EDProducer<> {

public:
Expand All @@ -54,11 +58,11 @@ class DeepFlavourTagInfoProducer : public edm::stream::EDProducer<> {
edm::EDGetTokenT<SVCollection> sv_token_;
edm::EDGetTokenT<ShallowTagInfoCollection> shallow_tag_info_token_;
edm::EDGetTokenT<edm::ValueMap<float>> puppi_value_map_token_;
edm::EDGetTokenT<edm::ValueMap<int>> pvasq_value_map_token_;

bool use_puppi_value_map_;
bool use_pvasq_value_map_;



};

DeepFlavourTagInfoProducer::DeepFlavourTagInfoProducer(const edm::ParameterSet& iConfig) :
Expand All @@ -67,7 +71,8 @@ DeepFlavourTagInfoProducer::DeepFlavourTagInfoProducer(const edm::ParameterSet&
vtx_token_(consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))),
sv_token_(consumes<SVCollection>(iConfig.getParameter<edm::InputTag>("secondary_vertices"))),
shallow_tag_info_token_(consumes<ShallowTagInfoCollection>(iConfig.getParameter<edm::InputTag>("shallow_tag_infos"))),
use_puppi_value_map_(false)
use_puppi_value_map_(false),
use_pvasq_value_map_(false)
{
produces<DeepFlavourTagInfoCollection>();

Expand All @@ -76,6 +81,13 @@ DeepFlavourTagInfoProducer::DeepFlavourTagInfoProducer(const edm::ParameterSet&
puppi_value_map_token_ = consumes<edm::ValueMap<float>>(puppi_value_map_tag);
use_puppi_value_map_ = true;
}

const auto & pvasq_value_map_tag = iConfig.getParameter<edm::InputTag>("pvasq_value_map");
if (!pvasq_value_map_tag.label().empty()) {
pvasq_value_map_token_ = consumes<edm::ValueMap<int>>(pvasq_value_map_tag);
use_pvasq_value_map_ = true;
}

}


Expand Down Expand Up @@ -111,6 +123,11 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
iEvent.getByToken(puppi_value_map_token_, puppi_value_map);
}

edm::Handle<edm::ValueMap<int>> pvasq_value_map;
if (use_pvasq_value_map_) {
iEvent.getByToken(pvasq_value_map_token_, pvasq_value_map);
}

edm::ESHandle<TransientTrackBuilder> track_builder;
iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", track_builder);

Expand Down Expand Up @@ -221,8 +238,8 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
// get pointer and check that is correct
auto cand = dynamic_cast<const reco::Candidate *>(jet.daughter(i));
if(!cand) continue;
auto reco_cand = dynamic_cast<const reco::PFCandidate *>(cand);
auto packed_cand = dynamic_cast<const pat::PackedCandidate *>(cand);
auto reco_cand = dynamic_cast<const reco::PFCandidate *>(cand);

float drminpfcandsv = deep::mindrsvpfcand(svs_unsorted, cand);

Expand All @@ -238,12 +255,15 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
deep::c_pf_packed_features_converter(packed_cand, jet, trackinfo,
drminpfcandsv, c_pf_features);
} else if (reco_cand) {
float puppiw = 0.0;
float pv_ass_quality = 0.0;
// need some edm::Ptr or edm::Ref
auto reco_ptr = pf_jet->getPFConstituent(i);
// get PUPPI weight from value map
float puppiw = (*puppi_value_map)[reco_ptr];
int quality = (*pvasq_value_map)[reco_ptr];
int pv_ass_quality = qualityMap[quality];
deep::c_pf_reco_features_converter(reco_cand, jet, trackinfo,
drminpfcandsv, puppiw,
pv_ass_quality,
c_pf_features);
pv_ass_quality, c_pf_features);
}
} else {
// is neutral candidate
Expand All @@ -255,7 +275,10 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
deep::n_pf_packed_features_converter(packed_cand, jet, drminpfcandsv,
n_pf_features);
} else if (reco_cand) {
float puppiw = 0.0;
// need some edm::Ptr or edm::Ref
auto reco_ptr = pf_jet->getPFConstituent(i);
// get PUPPI weight from value map
float puppiw = (*puppi_value_map)[reco_ptr];
deep::n_pf_reco_features_converter(reco_cand, jet,
drminpfcandsv, puppiw,
n_pf_features);
Expand Down
2 changes: 1 addition & 1 deletion RecoBTag/DeepFlavour/python/DeepFlavourTagInfos_cfi.py
Expand Up @@ -7,6 +7,6 @@
secondary_vertices = cms.InputTag("inclusiveCandidateSecondaryVertices"),
shallow_tag_infos = cms.InputTag('pfDeepCSVTagInfos'),
puppi_value_map = cms.InputTag('puppi'),
pvasq_value_map = cms.InputTag('primaryVertexAssociation','original'),
jet_radius = cms.double(0.4)

)
5 changes: 4 additions & 1 deletion RecoBTag/DeepFlavour/python/DeepFlavour_cff.py
Expand Up @@ -2,6 +2,9 @@

from RecoBTag.DeepFlavour.DeepFlavourTagInfos_cfi import pfDeepFlavourTagInfos
from RecoBTag.DeepFlavour.DeepFlavourJetTags_cfi import pfDeepFlavourJetTags
from CommonTools.PileupAlgos.Puppi_cff import puppi
from PhysicsTools.PatAlgos.slimming.primaryVertexAssociation_cfi import primaryVertexAssociation


pfDeepFlavourTaskNew = cms.Task(pfDeepFlavourTagInfos, pfDeepFlavourJetTags)
pfDeepFlavourTaskNew = cms.Task(puppi, primaryVertexAssociation,
pfDeepFlavourTagInfos, pfDeepFlavourJetTags)

0 comments on commit 3383998

Please sign in to comment.