Skip to content

Commit

Permalink
Merged master from repository cms-nanoAOD with cms-merge-topic
Browse files Browse the repository at this point in the history
  • Loading branch information
mseidel42 committed Nov 27, 2017
2 parents 1fed070 + 5e4e9dc commit 96d227b
Show file tree
Hide file tree
Showing 42 changed files with 2,110 additions and 425 deletions.
2 changes: 1 addition & 1 deletion Configuration/PyReleaseValidation/python/relval_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def identitySim(wf):
#input for a NANOAOD from MINIAOD workflow
steps['ZEE_13_80XNanoAODINPUT']={'INPUT':InputInfo(dataSet='/RelValZEE_13/CMSSW_8_0_21-PU25ns_80X_mcRun2_asymptotic_2016_TrancheIV_v6_Tr4GT_v6-v1/MINIAODSIM',label='nanoaod80X',location='STD')}
steps['TTbar_13_92XNanoAODINPUT']={'INPUT':InputInfo(dataSet='/RelValTTbar_13/CMSSW_9_2_12-PU25ns_92X_upgrade2017_realistic_v11-v1/MINIAODSIM',label='nanoaod92X',location='STD')}
steps['TTbar_13_94XNanoAODINPUT']={'INPUT':InputInfo(dataSet='/RelValTTbar_13/CMSSW_9_4_0_pre1-PU25ns_93X_mc2017_realistic_v3-v1/MINIAODSIM',label='nanoaod94X',location='STD')}
steps['TTbar_13_94XNanoAODINPUT']={'INPUT':InputInfo(dataSet='/RelValTTbar_13/CMSSW_9_4_0_pre3-PU25ns_94X_mc2017_realistic_v4-v1/MINIAODSIM',label='nanoaod94X',location='STD')}

# 13 TeV recycle GEN-SIM input
steps['MinBias_13INPUT']={'INPUT':InputInfo(dataSet='/RelValMinBias_13/%s/GEN-SIM'%(baseDataSetRelease[3],),location='STD')}
Expand Down
3 changes: 3 additions & 0 deletions DQMOffline/Configuration/python/DQMOfflineMC_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
label = 'TrackerCollisionSelectedTrackMonMB' + str(tracks)
locals()[label].doEffFromHitPatternVsBX = False

from PhysicsTools.NanoAOD.nanoDQM_cff import nanoDQMMC
DQMOfflineNanoAOD.replace(nanoDQM, nanoDQMMC)
#PostDQMOfflineNanoAOD.replace(nanoDQM, nanoDQMMC)
3 changes: 3 additions & 0 deletions DQMOffline/Configuration/python/DQMOffline_SecondStep_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from DQMOffline.Hcal.HcalDQMOfflinePostProcessor_cff import *
from DQMOffline.L1Trigger.L1TriggerDqmOffline_cff import *
from DQM.HcalTasks.OfflineHarvestingSequence_pp import *
from PhysicsTools.NanoAOD.nanoDQM_cff import *

DQMOffline_SecondStep_PreDPG = cms.Sequence( dqmDcsInfoClient *
ecal_dqm_client_offline *
Expand Down Expand Up @@ -145,3 +146,5 @@
DQMHarvestBTag = cms.Sequence( bTagCollectorSequenceDATA )

DQMHarvestMiniAOD = cms.Sequence( dataCertificationJetMETSequence * muonQualityTests_miniAOD)
DQMHarvestNanoAOD = cms.Sequence( nanoHarvest )

6 changes: 6 additions & 0 deletions DQMOffline/Configuration/python/DQMOffline_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,9 @@
phase2_hcal.toReplaceWith( PostDQMOfflineMiniAOD, PostDQMOfflineMiniAOD.copyAndExclude([
pfMetDQMAnalyzerMiniAOD, pfPuppiMetDQMAnalyzerMiniAOD # No hcalnoise yet
]))


from PhysicsTools.NanoAOD.nanoDQM_cff import nanoDQM
DQMOfflineNanoAOD = cms.Sequence(nanoDQM)
#PostDQMOfflineNanoAOD = cms.Sequence(nanoDQM)

3 changes: 3 additions & 0 deletions DQMOffline/Configuration/python/autoDQM.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
'miniAODDQM': ['DQMOfflineMiniAOD',
'PostDQMOfflineMiniAOD',
'DQMHarvestMiniAOD'],
'nanoAODDQM': ['DQMOfflineNanoAOD',
'PostDQMOffline',
'DQMHarvestNanoAOD'],
'standardDQM': ['DQMOffline',
'PostDQMOffline',
'dqmHarvesting'],
Expand Down
20 changes: 19 additions & 1 deletion DataFormats/NanoAOD/interface/FlatTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ class FlatTable {
return * beginData<T>(column);
}

double getAnyValue(unsigned int row, unsigned int column) const ;

class RowView {
public:
RowView() {}
RowView(const FlatTable & table, unsigned int row) : table_(&table), row_(row) {}
double getAnyValue(unsigned int column) const { return table_->getAnyValue(row_, column); }
double getAnyValue(const std::string & column) const { return table_->getAnyValue(row_, table_->columnIndex(column)); }
const FlatTable & table() const { return *table_; }
unsigned int row() const { return row_; }
private:
const FlatTable * table_;
unsigned int row_;
};
RowView row(unsigned int row) const { return RowView(*this, row); }

template<typename T, typename C = std::vector<T>>
void addColumn(const std::string & name, const C & values, const std::string & docString, ColumnType type = defaultColumnType<T>(),int mantissaBits=-1) {
if (columnIndex(name) != -1) throw cms::Exception("LogicError", "Duplicated column: "+name);
Expand All @@ -94,7 +110,9 @@ class FlatTable {
vec.push_back( value );
}
}


void addExtension(const FlatTable & extension) ;

template<typename T> static ColumnType defaultColumnType() { throw cms::Exception("unsupported type"); }

// this below needs to be public for ROOT, but it is to be considered private otherwise
Expand Down
29 changes: 29 additions & 0 deletions DataFormats/NanoAOD/src/FlatTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,32 @@ int nanoaod::FlatTable::columnIndex(const std::string & name) const {
}
return -1;
}

void nanoaod::FlatTable::addExtension(const nanoaod::FlatTable & other) {
if (extension() || !other.extension() || name() != other.name() || size() != other.size()) throw cms::Exception("LogicError", "Mismatch in adding extension");
for (unsigned int i = 0, n = other.nColumns(); i < n; ++i) {
switch(other.columnType(i)) {
case FloatColumn:
addColumn<float>(other.columnName(i), other.columnData<float>(i), other.columnDoc(i), other.columnType(i));
break;
case IntColumn:
addColumn<int>(other.columnName(i), other.columnData<int>(i), other.columnDoc(i), other.columnType(i));
break;
case BoolColumn: // as UInt8
case UInt8Column:
addColumn<uint8_t>(other.columnName(i), other.columnData<uint8_t>(i), other.columnDoc(i), other.columnType(i));
break;
}
}
}

double nanoaod::FlatTable::getAnyValue(unsigned int row, unsigned int column) const {
if (column >= nColumns()) throw cms::Exception("LogicError","Invalid column");
switch(columnType(column)) {
case FloatColumn: return *(beginData<float>(column)+row);
case IntColumn: return *(beginData<int>(column)+row);
case BoolColumn: return *(beginData<uint8_t>(column)+row);
case UInt8Column: return *(beginData<uint8_t>(column)+row);
}
throw cms::Exception("LogicError", "Unsupported type");
}
1 change: 1 addition & 0 deletions DataFormats/NanoAOD/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace DataFormats_NanoAOD {
struct dictionary {
nanoaod::FlatTable table;
edm::Wrapper<nanoaod::FlatTable> w_table;
nanoaod::FlatTable::RowView table_cursor;
edm::Wrapper<nanoaod::MergeableCounterTable> w_mtable;
edm::Wrapper<nanoaod::UniqueString> w_ustr;
};
Expand Down
1 change: 1 addition & 0 deletions DataFormats/NanoAOD/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<class name="nanoaod::FlatTable" ClassVersion="3">
<version ClassVersion="3" checksum="2443023556"/>
</class>
<class name="nanoaod::FlatTable::RowView" transient="true" />
<class name="edm::Wrapper<nanoaod::FlatTable>" />

<class name="nanoaod::MergeableCounterTable::FloatColumn" ClassVersion="3">
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/NanoAOD/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<use name="RecoVertex/VertexPrimitives"/>
<use name="DataFormats/L1TGlobal"/>
<use name="IOPool/Provenance"/>

<use name="DQMServices/Core"/>
<library file="*.cc" name="PhysicsToolsNanoAODPlugins">
<flags EDM_PLUGIN="1"/>
</library>
100 changes: 100 additions & 0 deletions PhysicsTools/NanoAOD/plugins/GenJetFlavourTableProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "DataFormats/JetReco/interface/GenJet.h"
#include "SimDataFormats/JetMatching/interface/JetFlavourInfo.h"
#include "SimDataFormats/JetMatching/interface/JetFlavourInfoMatching.h"
#include "DataFormats/Math/interface/deltaR.h"

#include "DataFormats/NanoAOD/interface/FlatTable.h"

#include "CommonTools/Utils/interface/StringCutObjectSelector.h"
#include "CommonTools/Utils/interface/StringObjectFunction.h"

class GenJetFlavourTableProducer : public edm::stream::EDProducer<> {
public:
explicit GenJetFlavourTableProducer(const edm::ParameterSet &iConfig) :
name_(iConfig.getParameter<std::string>("name")),
src_(consumes<std::vector<reco::GenJet> >(iConfig.getParameter<edm::InputTag>("src"))),
cut_(iConfig.getParameter<std::string>("cut"), true),
deltaR_(iConfig.getParameter<double>("deltaR")),
jetFlavourInfosToken_(consumes<reco::JetFlavourInfoMatchingCollection>(iConfig.getParameter<edm::InputTag>("jetFlavourInfos")))
{
produces<nanoaod::FlatTable>();
}

~GenJetFlavourTableProducer() override {};

static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("src")->setComment("input genJet collection");
desc.add<edm::InputTag>("jetFlavourInfos")->setComment("input flavour info collection");
desc.add<std::string>("name")->setComment("name of the genJet FlatTable we are extending with flavour information");
desc.add<std::string>("cut")->setComment("cut on input genJet collection");
desc.add<double>("deltaR")->setComment("deltaR to match genjets");
descriptions.add("genJetFlavourTable", desc);
}

private:
void produce(edm::Event&, edm::EventSetup const&) override ;

std::string name_;
edm::EDGetTokenT<std::vector<reco::GenJet> > src_;
const StringCutObjectSelector<reco::GenJet> cut_;
const double deltaR_;
edm::EDGetTokenT<reco::JetFlavourInfoMatchingCollection> jetFlavourInfosToken_;

};

// ------------ method called to produce the data ------------
void
GenJetFlavourTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
{
edm::Handle<reco::GenJetCollection> jets;
iEvent.getByToken(src_, jets);

edm::Handle<reco::JetFlavourInfoMatchingCollection> jetFlavourInfos;
iEvent.getByToken(jetFlavourInfosToken_, jetFlavourInfos);

unsigned int ncand = 0;
std::vector<int> partonFlavour;
std::vector<uint8_t> hadronFlavour;

for (const reco::GenJet & jet : *jets) {
if (!cut_(jet)) continue;
++ncand;
bool matched = false;
for (const reco::JetFlavourInfoMatching & jetFlavourInfoMatching : *jetFlavourInfos) {
if (deltaR(jet.p4(), jetFlavourInfoMatching.first->p4()) < deltaR_) {
partonFlavour.push_back(jetFlavourInfoMatching.second.getPartonFlavour());
hadronFlavour.push_back(jetFlavourInfoMatching.second.getHadronFlavour());
matched = true;
break;
}
}
if (!matched) {
partonFlavour.push_back(0);
hadronFlavour.push_back(0);
}
}

auto tab = std::make_unique<nanoaod::FlatTable>(ncand, name_, false, true);
tab->addColumn<int>("partonFlavour", partonFlavour, "flavour from parton matching", nanoaod::FlatTable::IntColumn);
tab->addColumn<uint8_t>("hadronFlavour", hadronFlavour, "flavour from hadron ghost clustering", nanoaod::FlatTable::UInt8Column);

iEvent.put(std::move(tab));
}

#include "FWCore/Framework/interface/MakerMacros.h"
//define this as a plug-in
DEFINE_FWK_MODULE(GenJetFlavourTableProducer);
26 changes: 23 additions & 3 deletions PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,11 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
std::vector<ScaleVarWeight> scaleVariationIDs;
std::vector<PDFSetWeights> pdfSetWeightIDs;

std::regex weightgroup("<weightgroup\\s+combine=\"(.*)\"\\s+name=\"(.*)\"\\s*>");
std::regex weightgroup("<weightgroup\\s+combine=\"(.*)\"\\s+(?:name|type)=\"(.*)\"\\s*>");
std::regex endweightgroup("</weightgroup>");
std::regex scalew("<weight\\s+id=\"(\\d+)\">\\s*(muR=(\\S+)\\s+muF=(\\S+)(\\s+.*)?)</weight>");
std::regex scalew("<weight\\s+id=\"(\\d+)\">\\s*(mu[rR]=(\\S+)\\s+mu[Ff]=(\\S+)(\\s+.*)?)</weight>");
std::regex pdfw("<weight\\s+id=\"(\\d+)\">\\s*PDF set\\s*=\\s*(\\d+)\\s*</weight>");
std::regex pdfwOld("<weight\\s+id=\"(\\d+)\">\\s*Member \\s*(\\d+)\\s*</weight>");
std::smatch groups;
for (auto iter=lheInfo->headers_begin(), end = lheInfo->headers_end(); iter != end; ++iter) {
if (iter->tag() != "initrwgt") {
Expand All @@ -243,7 +244,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
if (lheDebug) std::cout << lines[iLine];
if (std::regex_search(lines[iLine], groups, weightgroup)) {
if (lheDebug) std::cout << ">>> Looks like the beginning of a weight group for " << groups.str(2) << std::endl;
if (groups.str(2) == "scale_variation") {
if (groups.str(2) == "scale_variation" || groups.str(2) == "Central scale variation") {
for ( ++iLine; iLine < nLines; ++iLine) {
if (lheDebug) std::cout << " " << lines[iLine];
if (std::regex_search(lines[iLine], groups, scalew)) {
Expand Down Expand Up @@ -276,6 +277,25 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
break;
}
}
} else if (groups.str(2) == "NNPDF30_lo_as_0130.LHgrid") {
for ( ++iLine; iLine < nLines; ++iLine) {
if (lheDebug) std::cout << " " << lines[iLine];
if (std::regex_search(lines[iLine], groups, pdfwOld)) {
unsigned int lhaID = std::stoi(groups.str(2))+262000;
if (lheDebug) std::cout << " >>> PDF weight " << groups.str(1) << " for " << groups.str(2) << " = " << lhaID << std::endl;
if (lhaID == 262000) continue;
if (pdfSetWeightIDs.empty() || ! pdfSetWeightIDs.back().maybe_add(groups.str(1),lhaID)) {
pdfSetWeightIDs.emplace_back(groups.str(1),lhaID);
}
} else if (std::regex_search(lines[iLine], endweightgroup)) {
if (lheDebug) std::cout << ">>> Looks like the end of a weight group" << std::endl;
break;
} else if (std::regex_search(lines[iLine], weightgroup)) {
if (lheDebug) std::cout << ">>> Looks like the beginning of a new weight group, I will assume I missed the end of the group." << std::endl;
--iLine; // rewind by one, and go back to the outer loop
break;
}
}
} else {
for ( ++iLine; iLine < nLines; ++iLine) {
if (lheDebug) std::cout << " " << lines[iLine];
Expand Down
2 changes: 2 additions & 0 deletions PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class LHETablesProducer : public edm::global::EDProducer<> {
out.addColumnValue<float>("HT", lheHT, "HT, scalar sum of parton pTs at LHE step", nanoaod::FlatTable::FloatColumn);
out.addColumnValue<float>("HTIncoming", lheHTIncoming, "HT, scalar sum of parton pTs at LHE step, restricted to partons", nanoaod::FlatTable::FloatColumn);
out.addColumnValue<float>("Vpt", lheVpt, "pT of the W or Z boson at LHE step", nanoaod::FlatTable::FloatColumn);
out.addColumnValue<uint8_t>("NpNLO", lheProd.npNLO(), "number of partons at NLO", nanoaod::FlatTable::UInt8Column);
out.addColumnValue<uint8_t>("NpLO", lheProd.npLO(), "number of partons at LO", nanoaod::FlatTable::UInt8Column);
}

static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
Expand Down
3 changes: 1 addition & 2 deletions PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ MuonIDTableProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::Event
const pat::Muon & mu = (*muons)[i];
tight[i] = muon::isTightMuon(mu, pv);
highPt[i] = muon::isHighPtMuon(mu, pv) ? 2 : isTrackerHighPt(mu,pv);
soft[i] = isRun2016BCDEF ? isSoftMuonHIP(mu,pv) : muon::isTightMuon(mu, pv);
soft[i] = isRun2016BCDEF ? isSoftMuonHIP(mu,pv) : muon::isSoftMuon(mu, pv);
medium[i] = isRun2016BCDEF ? isMediumMuonHIP(mu) : muon::isMediumMuon(mu);
}

Expand Down Expand Up @@ -97,7 +97,6 @@ bool MuonIDTableProducer::isSoftMuonHIP(const pat::Muon& mu, const reco::Vertex&
return muon::isGoodMuon(mu, muon::TMOneStationTight) &&
mu.innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5 &&
mu.innerTrack()->hitPattern().pixelLayersWithMeasurement() > 0 &&
mu.innerTrack()->quality(reco::Track::highPurity) &&
std::abs(mu.innerTrack()->dxy(vtx.position())) < 0.3 &&
std::abs(mu.innerTrack()->dz(vtx.position())) < 20.;
}
Expand Down
Loading

0 comments on commit 96d227b

Please sign in to comment.