Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get by token for b-tagging DQM packages. #1206

Merged
merged 3 commits into from Oct 31, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 41 additions & 8 deletions DQMOffline/RecoB/plugins/BTagPerformanceAnalyzerOnData.cc
Expand Up @@ -36,11 +36,42 @@ BTagPerformanceAnalyzerOnData::BTagPerformanceAnalyzerOnData(const edm::Paramete
allHisto(pSet.getParameter<bool>( "allHistograms" )),
finalize(pSet.getParameter< bool >("finalizePlots")),
finalizeOnly(pSet.getParameter< bool >("finalizeOnly")),
slInfoTag(pSet.getParameter<edm::InputTag>("softLeptonInfo")),
moduleConfig(pSet.getParameter< vector<edm::ParameterSet> >("tagConfig")),
mcPlots_(pSet.getParameter< unsigned int >("mcPlots"))
{
if(!finalizeOnly) mcPlots_ = 0; //analyzer not designed to produce flavour histograms but could be used for harvesting

slInfoToken = consumes<SoftLeptonTagInfoCollection>(pSet.getParameter<InputTag>("softLeptonInfo"));
for (vector<edm::ParameterSet>::const_iterator iModule = moduleConfig.begin();
iModule != moduleConfig.end(); ++iModule) {

const string& dataFormatType = iModule->exists("type") ?
iModule->getParameter<string>("type") :
"JetTag";
if (dataFormatType == "JetTag") {
const InputTag& moduleLabel = iModule->getParameter<InputTag>("label");
jetTagToken.push_back(consumes<JetTagCollection>(moduleLabel));
}
else if(dataFormatType == "TagCorrelation") {
const InputTag& label1 = iModule->getParameter<InputTag>("label1");
const InputTag& label2 = iModule->getParameter<InputTag>("label2");
tagCorrelationToken.push_back(std::pair< edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection> >(consumes<JetTagCollection>(label1), consumes<JetTagCollection>(label2)));
}
else {
std::vector< edm::EDGetTokenT<edm::View<reco::BaseTagInfo>> > tokens;
if(dataFormatType == "GenericMVA") {
const InputTag& ipinfo = iModule->getParameter<InputTag>("ipTagInfos");
const InputTag& svinfo = iModule->getParameter<InputTag>("svTagInfos");
tokens.push_back(consumes< View<BaseTagInfo> >(ipinfo));
tokens.push_back(consumes< View<BaseTagInfo> >(svinfo));
}
else {
const InputTag& moduleLabel = iModule->getParameter<InputTag>("label");
tokens.push_back(consumes< View<BaseTagInfo> >(moduleLabel));
}
tagInfoToken.push_back(tokens);
}
}
}

void BTagPerformanceAnalyzerOnData::beginRun(const edm::Run & run, const edm::EventSetup & es){
Expand Down Expand Up @@ -260,13 +291,13 @@ void BTagPerformanceAnalyzerOnData::analyze(const edm::Event& iEvent, const edm:
//no flavour map needed here

edm::Handle<reco::SoftLeptonTagInfoCollection> infoHandle;
iEvent.getByLabel(slInfoTag, infoHandle);
iEvent.getByToken(slInfoToken, infoHandle);

// Look first at the jetTags

for (unsigned int iJetLabel = 0; iJetLabel != jetTagInputTags.size(); ++iJetLabel) {
edm::Handle<reco::JetTagCollection> tagHandle;
iEvent.getByLabel(jetTagInputTags[iJetLabel], tagHandle);
iEvent.getByToken(jetTagToken[iJetLabel], tagHandle);
//
// insert check on the presence of the collections
//
Expand Down Expand Up @@ -298,13 +329,13 @@ void BTagPerformanceAnalyzerOnData::analyze(const edm::Event& iEvent, const edm:

// Now look at Tag Correlations
for (unsigned int iJetLabel = 0; iJetLabel != tagCorrelationInputTags.size(); ++iJetLabel) {
const std::pair<edm::InputTag, edm::InputTag>& inputTags = tagCorrelationInputTags[iJetLabel];
const std::pair< edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection> >& inputTokens = tagCorrelationToken[iJetLabel];
edm::Handle<reco::JetTagCollection> tagHandle1;
iEvent.getByLabel(inputTags.first, tagHandle1);
iEvent.getByToken(inputTokens.first, tagHandle1);
const reco::JetTagCollection& tagColl1 = *(tagHandle1.product());

edm::Handle<reco::JetTagCollection> tagHandle2;
iEvent.getByLabel(inputTags.second, tagHandle2);
iEvent.getByToken(inputTokens.second, tagHandle2);
const reco::JetTagCollection& tagColl2 = *(tagHandle2.product());

int plotterSize = binTagCorrelationPlotters[iJetLabel].size();
Expand Down Expand Up @@ -350,9 +381,11 @@ void BTagPerformanceAnalyzerOnData::analyze(const edm::Event& iEvent, const edm:
vector< edm::Handle< View<BaseTagInfo> > > tagInfoHandles(nInputTags);
edm::ProductID jetProductID;
unsigned int nTagInfos = 0;
for (unsigned int iInputTags = 0; iInputTags < inputTags.size(); ++iInputTags) {
vector<edm::EDGetTokenT<edm::View<reco::BaseTagInfo>> > & tokens = tagInfoToken[iJetLabel];
if(nInputTags!=tokens.size()) throw cms::Exception("Configuration") << "Different number of Tag Infos than expected" << endl;
for (unsigned int iInputTags = 0; iInputTags < tokens.size(); ++iInputTags) {
edm::Handle< View<BaseTagInfo> > & tagInfoHandle = tagInfoHandles[iInputTags];
iEvent.getByLabel(inputTags[iInputTags], tagInfoHandle);
iEvent.getByToken(tokens[iInputTags], tagInfoHandle);
//
// protect against missing products
//
Expand Down
6 changes: 6 additions & 0 deletions DQMOffline/RecoB/plugins/BTagPerformanceAnalyzerOnData.h
Expand Up @@ -82,6 +82,12 @@ class BTagPerformanceAnalyzerOnData : public edm::EDAnalyzer {

unsigned int mcPlots_;

//add consumes
edm::EDGetTokenT<reco::SoftLeptonTagInfoCollection> slInfoToken;
std::vector< edm::EDGetTokenT<reco::JetTagCollection> > jetTagToken;
std::vector< std::pair<edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection>> > tagCorrelationToken;
std::vector<std::vector <edm::EDGetTokenT<edm::View<reco::BaseTagInfo>> >> tagInfoToken;

};


Expand Down
9 changes: 4 additions & 5 deletions DQMOffline/RecoB/plugins/PrimaryVertexMonitor.cc
Expand Up @@ -13,9 +13,8 @@ using namespace edm;

PrimaryVertexMonitor::PrimaryVertexMonitor(const edm::ParameterSet& pSet)
{
moduleLabel = pSet.getParameter<InputTag>("vertexLabel");
beamSpotLabel = pSet.getParameter<InputTag>("beamSpotLabel");

vtxToken = consumes<reco::VertexCollection>(pSet.getParameter<InputTag>("vertexLabel"));
bsToken = consumes<reco::BeamSpot>(pSet.getParameter<InputTag>("beamSpotLabel"));
//
// Book all histograms.
//
Expand Down Expand Up @@ -98,10 +97,10 @@ PrimaryVertexMonitor::~PrimaryVertexMonitor()
void PrimaryVertexMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
Handle<reco::VertexCollection> recVtxs;
iEvent.getByLabel(moduleLabel, recVtxs);
iEvent.getByToken(vtxToken, recVtxs);

edm::Handle<reco::BeamSpot> beamSpotHandle;
iEvent.getByLabel(beamSpotLabel,beamSpotHandle);
iEvent.getByToken(bsToken, beamSpotHandle);

//
// check for absent products and simply "return" in that case
Expand Down
5 changes: 5 additions & 0 deletions DQMOffline/RecoB/plugins/PrimaryVertexMonitor.h
Expand Up @@ -12,6 +12,7 @@
#include "DQMServices/Core/interface/MonitorElement.h"

#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"


Expand Down Expand Up @@ -47,6 +48,10 @@ class PrimaryVertexMonitor : public edm::EDAnalyzer {
MonitorElement *vtxchi2[2] , *vtxndf[2], *vtxprob[2] , *nans[2];
MonitorElement *type[2];
MonitorElement *bsX, *bsY, *bsZ, *bsSigmaZ, *bsDxdz, *bsDydz, *bsBeamWidthX, *bsBeamWidthY, *bsType;

//consume
edm::EDGetTokenT<reco::VertexCollection> vtxToken;
edm::EDGetTokenT<reco::BeamSpot> bsToken;
};


Expand Down
62 changes: 48 additions & 14 deletions Validation/RecoB/plugins/BTagPerformanceAnalyzerMC.cc
Expand Up @@ -39,8 +39,6 @@ BTagPerformanceAnalyzerMC::BTagPerformanceAnalyzerMC(const edm::ParameterSet& pS
finalize(pSet.getParameter< bool >("finalizePlots")),
finalizeOnly(pSet.getParameter< bool >("finalizeOnly")),
ptHatWeight(pSet.getParameter< bool >("applyPtHatWeight")),
jetMCSrc(pSet.getParameter<edm::InputTag>("jetMCSrc")),
slInfoTag(pSet.getParameter<edm::InputTag>("softLeptonInfo")),
moduleConfig(pSet.getParameter< vector<edm::ParameterSet> >("tagConfig")),
flavPlots_(pSet.getParameter< std::string >("flavPlots")),
makeDiffPlots_(pSet.getParameter< bool >("differentialPlots")),
Expand All @@ -65,6 +63,40 @@ BTagPerformanceAnalyzerMC::BTagPerformanceAnalyzerMC(const edm::ParameterSet& pS
case 15: tauPlots = true; electronPlots = false; tauPlots = false; break;
default: electronPlots = false; muonPlots = false; tauPlots = false;
}

genToken = mayConsume<GenEventInfoProduct>(edm::InputTag("generator"));
jetToken = consumes<JetFlavourMatchingCollection>(pSet.getParameter<InputTag>("jetMCSrc"));
slInfoToken = consumes<SoftLeptonTagInfoCollection>(pSet.getParameter<InputTag>("softLeptonInfo"));
for (vector<edm::ParameterSet>::const_iterator iModule = moduleConfig.begin();
iModule != moduleConfig.end(); ++iModule) {

const string& dataFormatType = iModule->exists("type") ?
iModule->getParameter<string>("type") :
"JetTag";
if (dataFormatType == "JetTag") {
const InputTag& moduleLabel = iModule->getParameter<InputTag>("label");
jetTagToken.push_back(consumes<JetTagCollection>(moduleLabel));
}
else if(dataFormatType == "TagCorrelation") {
const InputTag& label1 = iModule->getParameter<InputTag>("label1");
const InputTag& label2 = iModule->getParameter<InputTag>("label2");
tagCorrelationToken.push_back(std::pair< edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection> >(consumes<JetTagCollection>(label1), consumes<JetTagCollection>(label2)));
}
else {
std::vector< edm::EDGetTokenT<edm::View<reco::BaseTagInfo>> > tokens;
if(dataFormatType == "GenericMVA") {
const InputTag& ipinfo = iModule->getParameter<InputTag>("ipTagInfos");
const InputTag& svinfo = iModule->getParameter<InputTag>("svTagInfos");
tokens.push_back(consumes< View<BaseTagInfo> >(ipinfo));
tokens.push_back(consumes< View<BaseTagInfo> >(svinfo));
}
else {
const InputTag& moduleLabel = iModule->getParameter<InputTag>("label");
tokens.push_back(consumes< View<BaseTagInfo> >(moduleLabel));
}
tagInfoToken.push_back(tokens);
}
}
}

void BTagPerformanceAnalyzerMC::beginRun(const edm::Run & run, const edm::EventSetup & es)
Expand Down Expand Up @@ -282,8 +314,8 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
/* APPLY PTHAT EVENT WEIGHT */

edm::Handle<GenEventInfoProduct> genInfoHandle;
iEvent.getByLabel("generator", genInfoHandle);
iEvent.getByToken(genToken, genInfoHandle);

if( genInfoHandle.isValid() ) {
weight = weight*static_cast<float>(genInfoHandle->weight());

Expand All @@ -298,7 +330,7 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
FlavourMap flavours;
LeptonMap leptons;

iEvent.getByLabel(jetMCSrc, jetMC);
iEvent.getByToken(jetToken, jetMC);
for (JetFlavourMatchingCollection::const_iterator iter = jetMC->begin();
iter != jetMC->end(); ++iter) {
unsigned int fl = std::abs(iter->second.getFlavour());
Expand All @@ -308,12 +340,12 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
}

edm::Handle<reco::SoftLeptonTagInfoCollection> infoHandle;
iEvent.getByLabel(slInfoTag, infoHandle);
iEvent.getByToken(slInfoToken, infoHandle);

// Look first at the jetTags
for (unsigned int iJetLabel = 0; iJetLabel != jetTagInputTags.size(); ++iJetLabel) {
edm::Handle<reco::JetTagCollection> tagHandle;
iEvent.getByLabel(jetTagInputTags[iJetLabel], tagHandle);
iEvent.getByToken(jetTagToken[iJetLabel], tagHandle);
const reco::JetTagCollection & tagColl = *(tagHandle.product());
LogDebug("Info") << "Found " << tagColl.size() << " B candidates in collection " << jetTagInputTags[iJetLabel];

Expand Down Expand Up @@ -354,13 +386,13 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve

// Now look at Tag Correlations
for (unsigned int iJetLabel = 0; iJetLabel != tagCorrelationInputTags.size(); ++iJetLabel) {
const std::pair<edm::InputTag, edm::InputTag>& inputTags = tagCorrelationInputTags[iJetLabel];
const std::pair< edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection> >& inputTokens = tagCorrelationToken[iJetLabel];
edm::Handle<reco::JetTagCollection> tagHandle1;
iEvent.getByLabel(inputTags.first, tagHandle1);
iEvent.getByToken(inputTokens.first, tagHandle1);
const reco::JetTagCollection& tagColl1 = *(tagHandle1.product());

edm::Handle<reco::JetTagCollection> tagHandle2;
iEvent.getByLabel(inputTags.second, tagHandle2);
iEvent.getByToken(inputTokens.second, tagHandle2);
const reco::JetTagCollection& tagColl2 = *(tagHandle2.product());

int plotterSize = binTagCorrelationPlotters[iJetLabel].size();
Expand Down Expand Up @@ -402,7 +434,7 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
int plotterSize = binTagInfoPlotters[iJetLabel].size();
for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter)
binTagInfoPlotters[iJetLabel][iPlotter]->setEventSetup(iSetup);

vector<edm::InputTag> & inputTags = tagInfoInputTags[iJetLabel];
if (inputTags.empty()) {
// deferred retrieval of input tags
Expand All @@ -418,14 +450,16 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
inputTags.push_back(inputTag);
}
}

unsigned int nInputTags = inputTags.size();
vector< edm::Handle< View<BaseTagInfo> > > tagInfoHandles(nInputTags);
edm::ProductID jetProductID;
unsigned int nTagInfos = 0;
for (unsigned int iInputTags = 0; iInputTags < inputTags.size(); ++iInputTags) {
vector<edm::EDGetTokenT<edm::View<reco::BaseTagInfo>> > & tokens = tagInfoToken[iJetLabel];
if(nInputTags!=tokens.size()) throw cms::Exception("Configuration") << "Different number of Tag Infos than expected" << endl;
for (unsigned int iInputTags = 0; iInputTags < tokens.size(); ++iInputTags) {
edm::Handle< View<BaseTagInfo> > & tagInfoHandle = tagInfoHandles[iInputTags];
iEvent.getByLabel(inputTags[iInputTags], tagInfoHandle);
iEvent.getByToken(tokens[iInputTags], tagInfoHandle);
unsigned int size = tagInfoHandle->size();
LogDebug("Info") << "Found " << size << " B candidates in collection " << inputTags[iInputTags];

Expand Down
9 changes: 9 additions & 0 deletions Validation/RecoB/plugins/BTagPerformanceAnalyzerMC.h
Expand Up @@ -112,6 +112,15 @@ typedef std::map<edm::RefToBase<reco::Jet>, reco::JetFlavour::Leptons, JetRefCom

bool eventInitialized;
bool electronPlots, muonPlots, tauPlots;

//add consumes
edm::EDGetTokenT<GenEventInfoProduct> genToken;
edm::EDGetTokenT<reco::JetFlavourMatchingCollection> jetToken;
edm::EDGetTokenT<reco::SoftLeptonTagInfoCollection> slInfoToken;
std::vector< edm::EDGetTokenT<reco::JetTagCollection> > jetTagToken;
std::vector< std::pair<edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection>> > tagCorrelationToken;
std::vector<std::vector <edm::EDGetTokenT<edm::View<reco::BaseTagInfo>> >> tagInfoToken;

};


Expand Down
16 changes: 8 additions & 8 deletions Validation/RecoB/plugins/recoBSVTagInfoValidationAnalyzer.cc
Expand Up @@ -85,6 +85,10 @@ class recoBSVTagInfoValidationAnalyzer : public edm::EDAnalyzer
// Histogram handlers
std::map<std::string, MonitorElement *> HistIndex_;

//consumes
edm::EDGetTokenT<reco::SecondaryVertexTagInfoCollection> svInfoToken;
edm::EDGetTokenT<TrackingVertexCollection> tvToken;

};


Expand Down Expand Up @@ -115,11 +119,9 @@ recoBSVTagInfoValidationAnalyzer::recoBSVTagInfoValidationAnalyzer(const edm::Pa


// Get the track collection
svTagInfoProducer_ = config.getUntrackedParameter<edm::InputTag> ( "svTagInfoProducer" );

svInfoToken = consumes<reco::SecondaryVertexTagInfoCollection>(config.getParameter<InputTag>("svTagInfoProducer"));
// Name of the traking pariticle collection
trackingTruth_ = config.getUntrackedParameter<edm::InputTag> ( "trackingTruth" );

tvToken = consumes<TrackingVertexCollection>(config.getParameter<InputTag>("trackingTruth"));
// Number of track categories
numberVertexClassifier_ = VertexCategories::Unknown+1;

Expand Down Expand Up @@ -192,8 +194,7 @@ void recoBSVTagInfoValidationAnalyzer::analyze(const edm::Event& event, const ed

// Vertex collection
edm::Handle<reco::SecondaryVertexTagInfoCollection> svTagInfoCollection;
event.getByLabel(svTagInfoProducer_, svTagInfoCollection);

event.getByToken(svInfoToken, svTagInfoCollection);
// Get a constant reference to the track history associated to the classifier
VertexHistory const & tracer = classifier_.history();

Expand Down Expand Up @@ -305,8 +306,7 @@ void recoBSVTagInfoValidationAnalyzer::analyze(const edm::Event& event, const ed

// Vertex collection
edm::Handle<TrackingVertexCollection> TVCollection;
event.getByLabel(trackingTruth_, TVCollection);

event.getByToken(tvToken, TVCollection);
// Loop over the TV collection.
for (std::size_t index = 0; index < TVCollection->size(); ++index){

Expand Down