From edae6c2315f840972f3184f425338c618d174bc1 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 18 Sep 2017 16:47:12 +0200 Subject: [PATCH 01/36] Import NanoAOD prototype code @ https://github.com/gpetruc/NanoAOD.git tag v1.0 except data files --- PhysicsTools/NanoAOD/BuildFile.xml | 11 + PhysicsTools/NanoAOD/interface/FlatTable.h | 159 +++++++ .../NanoAOD/interface/MatchingUtils.h | 54 +++ .../NanoAOD/interface/MergableCounterTable.h | 103 +++++ PhysicsTools/NanoAOD/interface/UniqueString.h | 18 + .../plugins/BJetEnergyRegressionMVA.cc | 109 +++++ .../plugins/BaseMVAValueMapProducer.cc | 36 ++ .../NanoAOD/plugins/BaseMVAValueMapProducer.h | 156 +++++++ PhysicsTools/NanoAOD/plugins/BuildFile.xml | 19 + .../plugins/CandMCMatchTableProducer.cc | 151 +++++++ .../NanoAOD/plugins/EGMEnergyVarProducer.cc | 131 ++++++ .../NanoAOD/plugins/FilterValueMapWrapper.h | 61 +++ .../NanoAOD/plugins/GenVisTauProducer.cc | 98 +++++ .../plugins/GenWeightsTableProducer.cc | 409 ++++++++++++++++++ .../plugins/GlobalVariablesTableProducer.cc | 134 ++++++ .../NanoAOD/plugins/IsoValueMapProducer.cc | 318 ++++++++++++++ .../NanoAOD/plugins/IsolatedTrackCleaner.cc | 67 +++ PhysicsTools/NanoAOD/plugins/JetIDValueMap.cc | 7 + .../plugins/L1TriggerResultsConverter.cc | 168 +++++++ .../NanoAOD/plugins/LHETablesProducer.cc | 98 +++++ .../NanoAOD/plugins/LeptonJetVarProducer.cc | 210 +++++++++ PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc | 89 ++++ .../NanoAOD/plugins/MuonIDTableProducer.cc | 116 +++++ .../plugins/NanoAODBaseCrossCleaner.cc | 144 ++++++ .../NanoAOD/plugins/NanoAODBaseCrossCleaner.h | 93 ++++ .../NanoAOD/plugins/NanoAODOutputModule.cc | 339 +++++++++++++++ .../plugins/NanoAODSimpleCrossCleaner.cc | 26 ++ .../plugins/NativeArrayTableProducer.cc | 48 ++ .../NanoAOD/plugins/PATObjectCrossLinker.cc | 225 ++++++++++ .../plugins/PATObjectUserDataEmbedder.cc | 134 ++++++ .../plugins/SimpleFlatTableProducer.cc | 213 +++++++++ .../plugins/SummaryTableOutputBranches.cc | 78 ++++ .../plugins/SummaryTableOutputBranches.h | 53 +++ .../NanoAOD/plugins/TableOutputBranches.cc | 93 ++++ .../NanoAOD/plugins/TableOutputBranches.h | 56 +++ .../plugins/TriggerObjectTableProducer.cc | 152 +++++++ .../NanoAOD/plugins/TriggerOutputBranches.cc | 86 ++++ .../NanoAOD/plugins/TriggerOutputBranches.h | 53 +++ .../NanoAOD/plugins/UniqueStringProducer.cc | 34 ++ .../plugins/VIDNestedWPBitmapProducer.cc | 173 ++++++++ .../NanoAOD/plugins/VertexTableProducer.cc | 197 +++++++++ .../python/NanoAODEDMEventContent_cff.py | 11 + .../NanoAOD/python/adaptFrom92X_cff.py | 12 + PhysicsTools/NanoAOD/python/common_cff.py | 60 +++ PhysicsTools/NanoAOD/python/electrons_cff.py | 187 ++++++++ .../NanoAOD/python/genparticles_cff.py | 69 +++ PhysicsTools/NanoAOD/python/globals_cff.py | 13 + PhysicsTools/NanoAOD/python/isotracks_cff.py | 41 ++ PhysicsTools/NanoAOD/python/jets_cff.py | 237 ++++++++++ PhysicsTools/NanoAOD/python/met_cff.py | 67 +++ PhysicsTools/NanoAOD/python/muons_cff.py | 117 +++++ PhysicsTools/NanoAOD/python/nano_cff.py | 73 ++++ PhysicsTools/NanoAOD/python/photons_cff.py | 133 ++++++ PhysicsTools/NanoAOD/python/taus_cff.py | 139 ++++++ .../NanoAOD/python/triggerObjects_cff.py | 82 ++++ PhysicsTools/NanoAOD/python/vertices_cff.py | 44 ++ PhysicsTools/NanoAOD/src/FlatTable.cc | 8 + .../NanoAOD/src/MergeableCounterTable.cc | 1 + PhysicsTools/NanoAOD/src/classes.h | 14 + PhysicsTools/NanoAOD/src/classes_def.xml | 36 ++ PhysicsTools/NanoAOD/test/crab_mc.py | 22 + PhysicsTools/NanoAOD/test/nano_cfg.py | 57 +++ PhysicsTools/NanoAOD/test/treeSize.py | 243 +++++++++++ 63 files changed, 6585 insertions(+) create mode 100644 PhysicsTools/NanoAOD/BuildFile.xml create mode 100644 PhysicsTools/NanoAOD/interface/FlatTable.h create mode 100644 PhysicsTools/NanoAOD/interface/MatchingUtils.h create mode 100644 PhysicsTools/NanoAOD/interface/MergableCounterTable.h create mode 100644 PhysicsTools/NanoAOD/interface/UniqueString.h create mode 100644 PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc create mode 100644 PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h create mode 100644 PhysicsTools/NanoAOD/plugins/BuildFile.xml create mode 100644 PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/FilterValueMapWrapper.h create mode 100644 PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/IsolatedTrackCleaner.cc create mode 100644 PhysicsTools/NanoAOD/plugins/JetIDValueMap.cc create mode 100644 PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc create mode 100644 PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc create mode 100644 PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc create mode 100644 PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h create mode 100644 PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc create mode 100644 PhysicsTools/NanoAOD/plugins/NanoAODSimpleCrossCleaner.cc create mode 100644 PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc create mode 100644 PhysicsTools/NanoAOD/plugins/PATObjectUserDataEmbedder.cc create mode 100644 PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc create mode 100644 PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h create mode 100644 PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc create mode 100644 PhysicsTools/NanoAOD/plugins/TableOutputBranches.h create mode 100644 PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc create mode 100644 PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.h create mode 100644 PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/VIDNestedWPBitmapProducer.cc create mode 100644 PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc create mode 100644 PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py create mode 100644 PhysicsTools/NanoAOD/python/adaptFrom92X_cff.py create mode 100644 PhysicsTools/NanoAOD/python/common_cff.py create mode 100644 PhysicsTools/NanoAOD/python/electrons_cff.py create mode 100644 PhysicsTools/NanoAOD/python/genparticles_cff.py create mode 100644 PhysicsTools/NanoAOD/python/globals_cff.py create mode 100644 PhysicsTools/NanoAOD/python/isotracks_cff.py create mode 100644 PhysicsTools/NanoAOD/python/jets_cff.py create mode 100644 PhysicsTools/NanoAOD/python/met_cff.py create mode 100644 PhysicsTools/NanoAOD/python/muons_cff.py create mode 100644 PhysicsTools/NanoAOD/python/nano_cff.py create mode 100644 PhysicsTools/NanoAOD/python/photons_cff.py create mode 100644 PhysicsTools/NanoAOD/python/taus_cff.py create mode 100644 PhysicsTools/NanoAOD/python/triggerObjects_cff.py create mode 100644 PhysicsTools/NanoAOD/python/vertices_cff.py create mode 100644 PhysicsTools/NanoAOD/src/FlatTable.cc create mode 100644 PhysicsTools/NanoAOD/src/MergeableCounterTable.cc create mode 100644 PhysicsTools/NanoAOD/src/classes.h create mode 100644 PhysicsTools/NanoAOD/src/classes_def.xml create mode 100644 PhysicsTools/NanoAOD/test/crab_mc.py create mode 100644 PhysicsTools/NanoAOD/test/nano_cfg.py create mode 100644 PhysicsTools/NanoAOD/test/treeSize.py diff --git a/PhysicsTools/NanoAOD/BuildFile.xml b/PhysicsTools/NanoAOD/BuildFile.xml new file mode 100644 index 0000000000000..fa73a54e575a2 --- /dev/null +++ b/PhysicsTools/NanoAOD/BuildFile.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/PhysicsTools/NanoAOD/interface/FlatTable.h b/PhysicsTools/NanoAOD/interface/FlatTable.h new file mode 100644 index 0000000000000..a1ebbacc1e731 --- /dev/null +++ b/PhysicsTools/NanoAOD/interface/FlatTable.h @@ -0,0 +1,159 @@ +#ifndef PhysicsTools_NanoAOD_FlatTable_h +#define PhysicsTools_NanoAOD_FlatTable_h + +#include +#include +#include +#include +#include +#include + +namespace flatTableHelper { + template struct MaybeMantissaReduce { + MaybeMantissaReduce(int mantissaBits) {} + inline T one(const T &val) const { return val; } + inline void bulk(boost::sub_range> data) const { } + }; + template<> struct MaybeMantissaReduce { + int bits_; + MaybeMantissaReduce(int mantissaBits) : bits_(mantissaBits) {} + inline float one(const float &val) const { return (bits_ > 0 ? MiniFloatConverter::reduceMantissaToNbitsRounding(val, bits_) : val); } + inline void bulk(boost::sub_range> data) const { if (bits_ > 0) MiniFloatConverter::reduceMantissaToNbitsRounding(bits_, data.begin(), data.end(), data.begin()); } + }; +} +class FlatTable { + public: + enum ColumnType { FloatColumn, IntColumn, UInt8Column, BoolColumn }; // We could have other Float types with reduced mantissa, and similar + + FlatTable() : size_(0) {} + FlatTable(unsigned int size, const std::string & name, bool singleton, bool extension=false) : size_(size), name_(name), singleton_(singleton), extension_(extension) {} + ~FlatTable() {} + + unsigned int nColumns() const { return columns_.size(); }; + unsigned int nRows() const { return size_; }; + unsigned int size() const { return size_; } + bool singleton() const { return singleton_; } + bool extension() const { return extension_; } + const std::string & name() const { return name_; } + + const std::string & columnName(unsigned int col) const { return columns_[col].name; } + int columnIndex(const std::string & name) const ; + + ColumnType columnType(unsigned int col) const { return columns_[col].type; } + + void setDoc(const std::string & doc) { doc_ = doc; } + const std::string & doc() const { return doc_; } + const std::string & columnDoc(unsigned int col) const { return columns_[col].doc; } + + /// get a column by index (const) + template + boost::sub_range> columnData(unsigned int column) const { + auto begin = beginData(column); + return boost::sub_range>(begin, begin+size_); + } + + /// get a column by index (non-const) + template + boost::sub_range> columnData(unsigned int column) { + auto begin = beginData(column); + return boost::sub_range>(begin, begin+size_); + } + + /// get a column value for singleton (const) + template + const T & columValue(unsigned int column) const { + if (!singleton()) throw cms::Exception("LogicError", "columnValue works only for singleton tables"); + return * beginData(column); + } + + template> + void addColumn(const std::string & name, const C & values, const std::string & docString, ColumnType type = defaultColumnType(),int mantissaBits=-1) { + if (columnIndex(name) != -1) throw cms::Exception("LogicError", "Duplicated column: "+name); + if (values.size() != size()) throw cms::Exception("LogicError", "Mismatched size for "+name); + check_type(type); // throws if type is wrong + auto & vec = bigVector(); + columns_.emplace_back(name,docString,type,vec.size()); + vec.insert(vec.end(), values.begin(), values.end()); + if (type == FloatColumn) { + flatTableHelper::MaybeMantissaReduce(mantissaBits).bulk(columnData(columns_.size()-1)); + } + } + template + void addColumnValue(const std::string & name, const C & value, const std::string & docString, ColumnType type = defaultColumnType(),int mantissaBits=-1) { + if (!singleton()) throw cms::Exception("LogicError", "addColumnValue works only for singleton tables"); + if (columnIndex(name) != -1) throw cms::Exception("LogicError", "Duplicated column: "+name); + check_type(type); // throws if type is wrong + auto & vec = bigVector(); + columns_.emplace_back(name,docString,type,vec.size()); + if (type == FloatColumn) { + vec.push_back( flatTableHelper::MaybeMantissaReduce(mantissaBits).one(value) ); + } else { + vec.push_back( value ); + } + } + + template static ColumnType defaultColumnType() { throw cms::Exception("unsupported type"); } + + // this below needs to be public for ROOT, but it is to be considered private otherwise + struct Column { + std::string name, doc; + ColumnType type; + unsigned int firstIndex; + Column() {} // for ROOT + Column(const std::string & aname, const std::string & docString, ColumnType atype, unsigned int anIndex) : name(aname), doc(docString), type(atype), firstIndex(anIndex) {} + }; + + private: + + template + typename std::vector::const_iterator beginData(unsigned int column) const { + const Column & col = columns_[column]; + check_type(col.type); // throws if type is wrong + return bigVector().begin() + col.firstIndex; + } + template + typename std::vector::iterator beginData(unsigned int column) { + const Column & col = columns_[column]; + check_type(col.type); // throws if type is wrong + return bigVector().begin() + col.firstIndex; + } + + template + const std::vector & bigVector() const { throw cms::Exception("unsupported type"); } + template + std::vector & bigVector() { throw cms::Exception("unsupported type"); } + + + unsigned int size_; + std::string name_, doc_; + bool singleton_, extension_; + std::vector columns_; + std::vector floats_; + std::vector ints_; + std::vector uint8s_; + + template + static void check_type(FlatTable::ColumnType type) { throw cms::Exception("unsupported type"); } +}; + +template<> inline void FlatTable::check_type(FlatTable::ColumnType type) { + if (type != FlatTable::FloatColumn) throw cms::Exception("mismatched type"); +} +template<> inline void FlatTable::check_type(FlatTable::ColumnType type) { + if (type != FlatTable::IntColumn) throw cms::Exception("mismatched type"); +} +template<> inline void FlatTable::check_type(FlatTable::ColumnType type) { + if (type != FlatTable::UInt8Column && type != FlatTable::BoolColumn) throw cms::Exception("mismatched type"); +} + + + +template<> inline const std::vector & FlatTable::bigVector() const { return floats_; } +template<> inline const std::vector & FlatTable::bigVector() const { return ints_; } +template<> inline const std::vector & FlatTable::bigVector() const { return uint8s_; } +template<> inline std::vector & FlatTable::bigVector() { return floats_; } +template<> inline std::vector & FlatTable::bigVector() { return ints_; } +template<> inline std::vector & FlatTable::bigVector() { return uint8s_; } + + +#endif diff --git a/PhysicsTools/NanoAOD/interface/MatchingUtils.h b/PhysicsTools/NanoAOD/interface/MatchingUtils.h new file mode 100644 index 0000000000000..9fe55e7e6b1cf --- /dev/null +++ b/PhysicsTools/NanoAOD/interface/MatchingUtils.h @@ -0,0 +1,54 @@ +#ifndef NanoAOD_MatchingUtils_h +#define NanoAOD_MatchingUtils_h + +/*#include +#include +#include "CommonTools/Utils/interface/StringCutObjectSelector.h" +*/ +bool matchByCommonSourceCandidatePtr(const auto & c1, const auto & c2) { + for(unsigned int i1 = 0 ; i1 < c1.numberOfSourceCandidatePtrs();i1++){ + auto c1s=c1.sourceCandidatePtr(i1); + for(unsigned int i2 = 0 ; i2 < c2.numberOfSourceCandidatePtrs();i2++) { + if(c2.sourceCandidatePtr(i2)==c1s) return true; + } + } + return false; +} + +bool matchByCommonParentSuperClusterRef(const auto & c1, const auto & c2) { + auto c1s = c1.parentSuperCluster(); + auto c2s = c2.parentSuperCluster(); + return (c1s == c2s); +} + +/* +template +std::pair bestMatch(auto item, auto targetColl,const StringCutObjectSelector & cut="1") { + float deltaR2Min = 9e99; + const I & bm; + for(const auto & t : targetColl){ + if(cut(t)) { + float dR2 = deltaR2(item,t); + if(dR2 < deltaR2Min){ + deltaR2Min = dR2; + bm = t; + } + } + } + return std::pair(bm, deltaR2Min); +} + + +template +std::vector> matchCollections(auto coll, auto targetColl,const StringCutObjectSelector & cut="1") { + std::vector> pairs; + if(coll.empty()) return pairs; + for(auto & p : coll){ + pairs.push_back(bestMatch(p,targetColl,cut)); + } + return pairs; +} + +*/ + +#endif diff --git a/PhysicsTools/NanoAOD/interface/MergableCounterTable.h b/PhysicsTools/NanoAOD/interface/MergableCounterTable.h new file mode 100644 index 0000000000000..6ae4febea7329 --- /dev/null +++ b/PhysicsTools/NanoAOD/interface/MergableCounterTable.h @@ -0,0 +1,103 @@ +#ifndef PhysicsTools_NanoAOD_MergableCounterTable_h +#define PhysicsTools_NanoAOD_MergableCounterTable_h + +#include +#include +#include + +class MergableCounterTable { + public: + MergableCounterTable() {} + typedef long long int_accumulator; // we accumulate in long long int, to avoid overflow + typedef double float_accumulator; // we accumulate in double, to preserve precision + + template + struct SingleColumn { + typedef T value_type; + SingleColumn() {} + SingleColumn(const std::string & aname, const std::string & adoc, T avalue = T()) : name(aname), doc(adoc), value(avalue) {} + std::string name, doc; + T value; + void operator+=(const SingleColumn & other) { + //if (name != other.name) throw cms::Exception("LogicError", "Trying to merge "+name+" with "+other.name+"\n"); + value += other.value; + } + bool compatible(const SingleColumn & other) { + return name == other.name; // we don't check the doc, not needed + } + }; + typedef SingleColumn FloatColumn; + typedef SingleColumn IntColumn; + + template + struct VectorColumn { + typedef T element_type; + VectorColumn() {} + VectorColumn(const std::string & aname, const std::string & adoc, unsigned int size) : name(aname), doc(adoc), values(size, T()) {} + VectorColumn(const std::string & aname, const std::string & adoc, const std::vector & somevalues) : name(aname), doc(adoc), values(somevalues) {} + std::string name, doc; + std::vector values; + void operator+=(const VectorColumn & other) { + //if (name != other.name) throw cms::Exception("LogicError", "Trying to merge "+name+" with "+other.name+"\n"); + //if (values.size() != other.values.size()) throw cms::Exception("LogicError", "Trying to merge "+name+" with different number of values!\n"); + for (unsigned int i = 0, n = values.size(); i < n; ++i) { + values[i] += other.values[i]; + } + } + bool compatible(const VectorColumn & other) { + return name == other.name && values.size() == other.values.size(); // we don't check the doc, not needed + } + }; + typedef VectorColumn VFloatColumn; + typedef VectorColumn VIntColumn; + + const std::vector & floatCols() const { return floatCols_; } + const std::vector & vfloatCols() const { return vfloatCols_; } + const std::vector & intCols() const { return intCols_; } + const std::vector & vintCols() const { return vintCols_; } + + template + void addFloat(const std::string & name, const std::string & doc, F value) { floatCols_.push_back(FloatColumn(name, doc, value)); } + + template + void addInt(const std::string & name, const std::string & doc, I value) { intCols_.push_back(IntColumn(name, doc, value)); } + + template + void addVFloat(const std::string & name, const std::string & doc, const std::vector values) { + vfloatCols_.push_back(VFloatColumn(name, doc, values.size())); + std::copy(values.begin(), values.end(), vfloatCols_.back().values.begin()); + } + + template + void addVInt(const std::string & name, const std::string & doc, const std::vector values) { + vintCols_.push_back(VIntColumn(name, doc, values.size())); + std::copy(values.begin(), values.end(), vintCols_.back().values.begin()); + } + + + bool mergeProduct(const MergableCounterTable & other) { + if (!tryMerge(intCols_, other.intCols_)) return false; + if (!tryMerge(vintCols_, other.vintCols_)) return false; + if (!tryMerge(floatCols_, other.floatCols_)) return false; + if (!tryMerge(vfloatCols_, other.vfloatCols_)) return false; + return true; + } + + private: + std::vector floatCols_; + std::vector vfloatCols_; + std::vector intCols_; + std::vector vintCols_; + + template + bool tryMerge(std::vector & one, const std::vector & two) { + if (one.size() != two.size()) return false; + for (unsigned int i = 0, n = one.size(); i < n; ++i) { + if (!one[i].compatible(two[i])) return false; + one[i] += two[i]; + } + return true; + } +}; + +#endif diff --git a/PhysicsTools/NanoAOD/interface/UniqueString.h b/PhysicsTools/NanoAOD/interface/UniqueString.h new file mode 100644 index 0000000000000..be0090da5b20e --- /dev/null +++ b/PhysicsTools/NanoAOD/interface/UniqueString.h @@ -0,0 +1,18 @@ +#ifndef PhysicsTools_NanoAOD_UniqueString_h +#define PhysicsTools_NanoAOD_UniqueString_h + +#include + +class UniqueString { + public: + UniqueString() {} + UniqueString(const std::string & str) : str_(str) {} + const std::string & str() const { return str_; } + bool operator==(const std::string & other) const { return str_ == other; } + bool operator==(const UniqueString & other) const { return str_ == other.str_; } + bool isProductEqual(const UniqueString & other) const { return (*this) == other; } + private: + std::string str_; +}; + +#endif diff --git a/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc b/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc new file mode 100644 index 0000000000000..de32ac6e7ad5f --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc @@ -0,0 +1,109 @@ +// +// Original Author: Andre Rizzi +// Created: Mon, 07 Sep 2017 09:18:03 GMT +// +// + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + + +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/PatCandidates/interface/Electron.h" +#include "DataFormats/PatCandidates/interface/Jet.h" + +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" + +#include "RecoVertex/VertexTools/interface/VertexDistance3D.h" +#include "RecoVertex/VertexPrimitives/interface/ConvertToFromReco.h" +#include "RecoVertex/VertexPrimitives/interface/VertexState.h" + +#include "PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h" +#include + +class BJetEnergyRegressionMVA : public BaseMVAValueMapProducer { + public: + explicit BJetEnergyRegressionMVA(const edm::ParameterSet &iConfig): + BaseMVAValueMapProducer(iConfig), + pvsrc_(edm::stream::EDProducer<>::consumes>(iConfig.getParameter("pvsrc"))), + svsrc_(edm::stream::EDProducer<>::consumes> (iConfig.getParameter("svsrc"))) + + { + + + } + virtual void readAdditionalCollections(edm::Event&iEvent, const edm::EventSetup&) override { + iEvent.getByToken(pvsrc_, pvs_); + iEvent.getByToken(svsrc_, svs_); + } + + virtual void fillAdditionalVariables(const pat::Jet&j) override { + this->setValue("nPVs",pvs_->size()); + BaseMVAValueMapProducer::setValue("Jet_leptonPtRel",0); + + if(j.overlaps("muons").size() >0) { + const auto *lep=dynamic_cast(&*j.overlaps("muons")[0]); + if(lep!=nullptr) {BaseMVAValueMapProducer::setValue("Jet_leptonPtRel",lep->userFloat("ptRel"));} + } + else if(j.overlaps("electrons").size() >0) { + const auto *lep=dynamic_cast(&*j.overlaps("electrons")[0]); + if(lep!=nullptr) {BaseMVAValueMapProducer::setValue("Jet_leptonPtRel",lep->userFloat("ptRel"));} + } + + float ptMax=0; + for(const auto & d : j.daughterPtrVector()){if(d->pt()>ptMax) ptMax=d->pt();} + BaseMVAValueMapProducer::setValue("Jet_leadTrackPt",ptMax); + + //Fill vertex properties + VertexDistance3D vdist; + float maxFoundSignificance=0; + const auto & pv = (*pvs_)[0]; + this->setValue("Jet_vtxPt",0); + this->setValue("Jet_vtxMass",0); + this->setValue("Jet_vtx3dL",0); + this->setValue("Jet_vtx3deL",0); + this->setValue("Jet_vtxNtrk",0); + + for(const auto &sv: *svs_){ + GlobalVector flightDir(sv.vertex().x() - pv.x(), sv.vertex().y() - pv.y(),sv.vertex().z() - pv.z()); + GlobalVector jetDir(j.px(),j.py(),j.pz()); + if( Geom::deltaR2( flightDir, jetDir ) < 0.09 ){ + Measurement1D dl= vdist.distance(pv,VertexState(RecoVertex::convertPos(sv.position()),RecoVertex::convertError(sv.error()))); + if(dl.significance() > maxFoundSignificance){ + maxFoundSignificance=dl.significance(); + this->setValue("Jet_vtxPt",sv.pt()); + this->setValue("Jet_vtxMass",sv.p4().M()); + this->setValue("Jet_vtx3dL",dl.value()); + this->setValue("Jet_vtx3deL",dl.error()); + this->setValue("Jet_vtxNtrk",sv.numberOfSourceCandidatePtrs()); + } + } + } + + } + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc = BaseMVAValueMapProducer::getDescription(); + desc.add("pvsrc")->setComment("primary vertices input collection"); + desc.add("svsrc")->setComment("secondary vertices input collection"); + descriptions.add("BJetEnergyRegressionMVA",desc); + } + + private: + const edm::EDGetTokenT> pvsrc_; + edm::Handle> pvs_; + const edm::EDGetTokenT > svsrc_; + edm::Handle> svs_; + +}; + +//define this as a plug-in +DEFINE_FWK_MODULE(BJetEnergyRegressionMVA); + diff --git a/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc b/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc new file mode 100644 index 0000000000000..94de717fb2b42 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc @@ -0,0 +1,36 @@ +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: BaseMVAValueMapProducer +// +/**\class BaseMVAValueMapProducer BaseMVAValueMapProducer.cc PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Andre Rizzi +// Created: Mon, 07 Sep 2017 09:18:03 GMT +// +// + + + +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/PatCandidates/interface/Electron.h" +#include "DataFormats/PatCandidates/interface/Jet.h" + + +#include "PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h" + +typedef BaseMVAValueMapProducer JetBaseMVAValueMapProducer; +typedef BaseMVAValueMapProducer MuonBaseMVAValueMapProducer; +typedef BaseMVAValueMapProducer EleBaseMVAValueMapProducer; + +//define this as a plug-in +DEFINE_FWK_MODULE(JetBaseMVAValueMapProducer); +DEFINE_FWK_MODULE(MuonBaseMVAValueMapProducer); +DEFINE_FWK_MODULE(EleBaseMVAValueMapProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h b/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h new file mode 100644 index 0000000000000..e7e45da4871e7 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h @@ -0,0 +1,156 @@ +#ifndef PhysicsTools_NanoAOD_BaseMVAValueMapProducer +#define PhysicsTools_NanoAOD_BaseMVAValueMapProducer + +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: BaseMVAValueMapProducer +// +/**\class BaseMVAValueMapProducer BaseMVAValueMapProducer.cc PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Andre Rizzi +// Created: Mon, 07 Sep 2017 09:18:03 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + + +#include "TMVA/Factory.h" +#include "TMVA/Reader.h" + +#include "CommonTools/Utils/interface/StringObjectFunction.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include +// +// class declaration +// + +template +class BaseMVAValueMapProducer : public edm::stream::EDProducer<> { + public: + explicit BaseMVAValueMapProducer(const edm::ParameterSet &iConfig): + src_(consumes>(iConfig.getParameter("src"))), + variablesOrder_(iConfig.getParameter>("variablesOrder")), + name_(iConfig.getParameter("name")), + isClassifier_(iConfig.getParameter("isClassifier")) + { + edm::ParameterSet const & varsPSet = iConfig.getParameter("variables"); + for (const std::string & vname : varsPSet.getParameterNamesForType()) { + funcs_.emplace_back(std::pair>(vname,varsPSet.getParameter(vname))); + } + + values_.resize(variablesOrder_.size()); + size_t i=0; + for(const auto & v : variablesOrder_){ + positions_[v]=i; + reader_.AddVariable(v,(&values_.front())+i); + i++; + } + reader_.BookMVA(name_,iConfig.getParameter("weightFile").fullPath() ); + produces>(); + + } + ~BaseMVAValueMapProducer() {} + + void setValue(const std::string var,float val) { + values_[positions_[var]]=val; + } + + static edm::ParameterSetDescription getDescription(); + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + virtual void beginStream(edm::StreamID) override {}; + virtual void produce(edm::Event&, const edm::EventSetup&) override; + virtual void endStream() override {}; + + ///to be implemented in derived classes, filling values for additional variables + virtual void readAdditionalCollections(edm::Event&, const edm::EventSetup&) {} + virtual void fillAdditionalVariables(const T&) {} + + + edm::EDGetTokenT> src_; + std::map positions_; + std::vector>> funcs_; + std::vector variablesOrder_; + std::vector values_; + TMVA::Reader reader_; + std::string name_; + bool isClassifier_; + +}; + +template +void +BaseMVAValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + edm::Handle> src; + iEvent.getByToken(src_, src); + readAdditionalCollections(iEvent,iSetup); + + std::vector mvaOut; + mvaOut.reserve(src->size()); + for(auto const & o: *src) { + for(auto const & p : funcs_ ){ + values_[positions_[p.first]]=p.second(o); + } + fillAdditionalVariables(o); + mvaOut.push_back(isClassifier_ ? reader_.EvaluateMVA(name_) : reader_.EvaluateRegression(name_)[0]); + } + std::unique_ptr> mvaV(new edm::ValueMap()); + edm::ValueMap::Filler filler(*mvaV); + filler.insert(src,mvaOut.begin(),mvaOut.end()); + filler.fill(); + iEvent.put(std::move(mvaV)); + +} + +template +edm::ParameterSetDescription +BaseMVAValueMapProducer::getDescription(){ + edm::ParameterSetDescription desc; + desc.add("src")->setComment("input physics object collection"); + desc.add>("variablesOrder")->setComment("ordered list of MVA input variable names"); + desc.add("name")->setComment("output score variable name"); + desc.add("isClassifier")->setComment("is a classifier discriminator"); + edm::ParameterSetDescription variables; + variables.setAllowAnything(); + desc.add("variables", variables)->setComment("list of input variable definitions"); + desc.add("weightFile")->setComment("xml weight file"); + return desc; +} + +template +void +BaseMVAValueMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc = getDescription(); + std::string modname; + if (typeid(T) == typeid(pat::Jet)) modname+="Jet"; + else if (typeid(T) == typeid(pat::Muon)) modname+="Muon"; + else if (typeid(T) == typeid(pat::Electron)) modname+="Ele"; + modname+="BaseMVAValueMapProducer"; + descriptions.add(modname,desc); +} + + + +#endif diff --git a/PhysicsTools/NanoAOD/plugins/BuildFile.xml b/PhysicsTools/NanoAOD/plugins/BuildFile.xml new file mode 100644 index 0000000000000..d2c613c0a138b --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/BuildFile.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc b/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc new file mode 100644 index 0000000000000..15a02356a2fa3 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc @@ -0,0 +1,151 @@ +#include "FWCore/Framework/interface/global/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 "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/Common/interface/View.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" + +#include +#include + + +class CandMCMatchTableProducer : public edm::global::EDProducer<> { + public: + CandMCMatchTableProducer( edm::ParameterSet const & params ) : + objName_(params.getParameter("objName")), + branchName_(params.getParameter("branchName")), + doc_(params.getParameter("docString")), + src_(consumes(params.getParameter("src"))), + candMap_(consumes>(params.getParameter("mcMap"))) + { + produces(); + const std::string & type = params.getParameter("objType"); + if (type == "Muon") type_ = MMuon; + else if (type == "Electron") type_ = MElectron; + else if (type == "Tau") type_ = MTau; + else if (type == "Photon") type_ = MPhoton; + else if (type == "Other") type_ = MOther; + else throw cms::Exception("Configuration", "Unsupported objType '"+type+"'\n"); + + switch(type_) { + case MMuon: flavDoc_ = "1 = prompt muon (including gamma*->mu mu), 15 = muon from prompt tau, " // continues below + "5 = muon from b, 4 = muon from c, 3 = muon from light or unknown, 0 = unmatched"; break; + case MElectron: flavDoc_ = "1 = prompt electron (including gamma*->mu mu), 15 = electron from prompt tau, 22 = prompt photon (likely conversion), " // continues below + "5 = electron from b, 4 = electron from c, 3 = electron from light or unknown, 0 = unmatched"; break; + case MPhoton: flavDoc_ = "1 = prompt photon, 13 = prompt electron, 0 = unknown or unmatched"; break; + case MTau: flavDoc_ = "1 = prompt electron, 2 = prompt muon, 3 = tau->e decay, 4 = tau->mu decay, 5 = hadronic tau decay, 0 = unknown or unmatched"; break; + case MOther: flavDoc_ = "1 = from hard scatter, 0 = unknown or unmatched"; break; + } + + if ( type_ == MTau ) { + candMapVisTau_ = consumes>(params.getParameter("mcMapVisTau")); + } + } + + virtual ~CandMCMatchTableProducer() {} + + void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { + + edm::Handle cands; + iEvent.getByToken(src_, cands); + unsigned int ncand = cands->size(); + + auto tab = std::make_unique(ncand, objName_, false, true); + + edm::Handle> map; + iEvent.getByToken(candMap_, map); + + edm::Handle> mapVisTau; + if ( type_ == MTau ) { + iEvent.getByToken(candMapVisTau_, mapVisTau); + } + + std::vector key(ncand, -1), flav(ncand, 0); + for (unsigned int i = 0; i < ncand; ++i) { + //std::cout << "cand #" << i << ": pT = " << cands->ptrAt(i)->pt() << ", eta = " << cands->ptrAt(i)->eta() << ", phi = " << cands->ptrAt(i)->phi() << std::endl; + reco::GenParticleRef match = (*map)[cands->ptrAt(i)]; + reco::GenParticleRef matchVisTau; + if ( type_ == MTau ) { + matchVisTau = (*mapVisTau)[cands->ptrAt(i)]; + } + if ( match.isNonnull() ) key[i] = match.key(); + else if ( matchVisTau.isNonnull() ) key[i] = matchVisTau.key(); + else continue; + switch(type_) { + case MMuon: + if (match->isPromptFinalState()) flav[i] = 1; // prompt + else if (match->isDirectPromptTauDecayProductFinalState()) flav[i] = 15; // tau + else flav[i] = getParentHadronFlag(match); // 3 = light, 4 = charm, 5 = b + break; + case MElectron: + if (match->isPromptFinalState()) flav[i] = (match->pdgId() == 22 ? 22 : 1); // prompt electron or photon + else if (match->isDirectPromptTauDecayProductFinalState()) flav[i] = 15; // tau + else flav[i] = getParentHadronFlag(match); // 3 = light, 4 = charm, 5 = b + break; + case MPhoton: + if (match->isPromptFinalState()) flav[i] = (match->pdgId() == 22 ? 1 : 13); // prompt electron or photon + break; + case MTau: + // CV: assignment of status codes according to https://twiki.cern.ch/twiki/bin/viewauth/CMS/HiggsToTauTauWorking2016#MC_Matching + if ( match.isNonnull() && match->isPromptFinalState() && abs(match->pdgId()) == 11 ) flav[i] = 1; + else if ( match.isNonnull() && match->isPromptFinalState() && abs(match->pdgId()) == 13 ) flav[i] = 2; + else if ( match.isNonnull() && match->isDirectPromptTauDecayProductFinalState() && abs(match->pdgId()) == 11 ) flav[i] = 3; + else if ( match.isNonnull() && match->isDirectPromptTauDecayProductFinalState() && abs(match->pdgId()) == 13 ) flav[i] = 4; + else if ( matchVisTau.isNonnull() ) flav[i] = 5; + break; + default: + flav[i] = match->statusFlags().fromHardProcess(); + }; + } + + tab->addColumn(branchName_+"Idx", key, "Index into genParticle list for "+doc_, FlatTable::IntColumn); + tab->addColumn(branchName_+"Flav", flav, "Flavour of genParticle for "+doc_+": "+flavDoc_, FlatTable::UInt8Column); + + iEvent.put(std::move(tab)); + } + + static int getParentHadronFlag(const reco::GenParticleRef match) { + bool has4 = false; + for (unsigned int im = 0, nm = match->numberOfMothers(); im < nm; ++im) { + reco::GenParticleRef mom = match->motherRef(im); + assert(mom.isNonnull() && mom.isAvailable()); // sanity + if (mom.key() >= match.key()) continue; // prevent circular refs + int id = std::abs(mom->pdgId()); + if (id / 1000 == 5 || id / 100 == 5 || id == 5) return 5; + if (id / 1000 == 4 || id / 100 == 4 || id == 4) has4 = true; + if (mom->status() == 2) { + id = getParentHadronFlag(mom); + if (id == 5) return 5; + else if (id == 4) has4 = true; + } + } + return has4 ? 4 : 3; + } + + static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { + edm::ParameterSetDescription desc; + desc.add("objName")->setComment("name of the FlatTable to extend with this table"); + desc.add("branchName")->setComment("name of the column to write (the final branch in the nanoaod will be _Idx and _Flav"); + desc.add("docString")->setComment("documentation to forward to the output"); + desc.add("src")->setComment("physics object collection for the reconstructed objects (e.g. leptons)"); + desc.add("mcMap")->setComment("tag to an edm::Association mapping src to gen, such as the one produced by MCMatcher"); + desc.add("objType")->setComment("type of object to match (Muon, Electron, Tau, Photon, Other), taylors what's in t Flav branch"); + desc.addOptional("mcMapVisTau")->setComment("as mcMap, but pointing to the visible gen taus (only if objType == Tau)"); + descriptions.add("candMcMatchTable", desc); + } + + protected: + const std::string objName_, branchName_, doc_; + const edm::EDGetTokenT src_; + const edm::EDGetTokenT> candMap_; + edm::EDGetTokenT> candMapVisTau_; + enum MatchType { MMuon, MElectron, MTau, MPhoton, MOther } type_; + std::string flavDoc_; +}; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(CandMCMatchTableProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc b/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc new file mode 100644 index 0000000000000..f13c700eb6808 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc @@ -0,0 +1,131 @@ +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: EGMEnergyVarProducer +// +/**\class EGMEnergyVarProducer EGMEnergyVarProducer.cc PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc + Description: [one line class summary] + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Emanuele Di Marco +// Created: Wed, 06 Sep 2017 12:34:38 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/global/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/PatCandidates/interface/Electron.h" +#include "DataFormats/PatCandidates/interface/Photon.h" + +#include "TLorentzVector.h" +#include "DataFormats/Common/interface/View.h" + +#include "PhysicsTools/NanoAOD/interface/MatchingUtils.h" + +// +// class declaration +// + +template +class EGMEnergyVarProducer : public edm::global::EDProducer<> { +public: + explicit EGMEnergyVarProducer(const edm::ParameterSet &iConfig): + srcRaw_(consumes>(iConfig.getParameter("srcRaw"))), + srcCorr_(consumes>(iConfig.getParameter("srcCorr"))) + { + produces>("eCorr"); + } + ~EGMEnergyVarProducer() {}; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + + // ----------member data --------------------------- + + edm::EDGetTokenT> srcRaw_; + edm::EDGetTokenT> srcCorr_; +}; + +// +// constants, enums and typedefs +// + + +// +// static data member definitions +// + +// +// member functions +// + +// ------------ method called to produce the data ------------ +template +void +EGMEnergyVarProducer::produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const +{ + edm::Handle> srcRaw; + iEvent.getByToken(srcRaw_, srcRaw); + edm::Handle> srcCorr; + iEvent.getByToken(srcCorr_, srcCorr); + + unsigned nSrcRaw = srcRaw->size(); + unsigned nSrcCorr = srcCorr->size(); + + std::vector eCorr(nSrcCorr,-1); + + for (uint ir = 0; irptrAt(ir); + for (uint ic = 0; icptrAt(ic); + if(matchByCommonParentSuperClusterRef(*egm_raw,*egm_corr)){ + eCorr[ir] = egm_corr->energy()/egm_raw->energy(); + break; + } + } + } + + std::unique_ptr> eCorrV(new edm::ValueMap()); + edm::ValueMap::Filler fillerCorr(*eCorrV); + fillerCorr.insert(srcRaw,eCorr.begin(),eCorr.end()); + fillerCorr.fill(); + iEvent.put(std::move(eCorrV),"eCorr"); + +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +template +void +EGMEnergyVarProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("srcRaw")->setComment("input raw physics object collection"); + desc.add("srcCorr")->setComment("input corrected physics object collection"); + std::string modname; + if (typeid(T) == typeid(pat::Electron)) modname+="Electron"; + else if (typeid(T) == typeid(pat::Photon)) modname+="Photon"; + modname+="EnergyVarProducer"; + descriptions.add(modname,desc); +} + +typedef EGMEnergyVarProducer ElectronEnergyVarProducer; +typedef EGMEnergyVarProducer PhotonEnergyVarProducer; + +//define this as a plug-in +DEFINE_FWK_MODULE(ElectronEnergyVarProducer); +DEFINE_FWK_MODULE(PhotonEnergyVarProducer); diff --git a/PhysicsTools/NanoAOD/plugins/FilterValueMapWrapper.h b/PhysicsTools/NanoAOD/plugins/FilterValueMapWrapper.h new file mode 100644 index 0000000000000..669b7bc3ed28c --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/FilterValueMapWrapper.h @@ -0,0 +1,61 @@ +#ifndef PhysicsTools_UtilAlgos_interface_EDFilterValueMapWrapper_h +#define PhysicsTools_UtilAlgos_interface_EDFilterValueMapWrapper_h + +/** + This is derived from EDFilterValueMapWrapper but rather than filtering it just stores a valuemap with the result +*/ + +#include "DataFormats/Common/interface/ValueMap.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Common/interface/EventBase.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include + +namespace edm { + + template + class FilterValueMapWrapper : public edm::stream::EDProducer<> { + + public: + /// some convenient typedefs. Recall that C is a container class. + typename C::iterator iterator; + typename C::const_iterator const_iterator; + + /// default contructor. Declares the output (type "C") and the filter (of type T, operates on C::value_type) + FilterValueMapWrapper(const edm::ParameterSet& cfg) : src_( consumes(cfg.getParameter("src"))) + { + filter_ = boost::shared_ptr( new T(cfg.getParameter("filterParams")) ); + produces>(); + } + /// default destructor + virtual ~FilterValueMapWrapper(){} + /// everything which has to be done during the event loop. NOTE: We can't use the eventSetup in FWLite so ignore it + virtual void produce(edm::Event& event, const edm::EventSetup& eventSetup) override { + // create a collection of the objects to put into the event + auto objsToPut = std::make_unique(); + // get the handle to the objects in the event. + edm::Handle h_c; + event.getByToken( src_, h_c ); + std::vector bitOut; + // loop through and add passing value_types to the output vector + for ( typename C::const_iterator ibegin = h_c->begin(), iend = h_c->end(), i = ibegin; i != iend; ++i ){ + bitOut.push_back((*filter_)(*i)); + } + std::unique_ptr> o(new edm::ValueMap()); + edm::ValueMap::Filler filler(*o); + filler.insert(h_c,bitOut.begin(),bitOut.end()); + filler.fill(); + event.put(std::move(o)); + } + + protected: + /// InputTag of the input source + edm::EDGetTokenT src_; + /// shared pointer to analysis class of type BasicAnalyzer + boost::shared_ptr filter_; + }; + +} + +#endif diff --git a/PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc b/PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc new file mode 100644 index 0000000000000..3faefaf961c35 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc @@ -0,0 +1,98 @@ +#include "FWCore/Framework/interface/global/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/Common/interface/View.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" +#include "DataFormats/JetReco/interface/GenJet.h" +#include "DataFormats/JetReco/interface/GenJetCollection.h" +#include "PhysicsTools/JetMCUtils/interface/JetMCTag.h" +#include "DataFormats/TauReco/interface/PFTau.h" +#include "DataFormats/Math/interface/deltaR.h" + +#include +#include + +class GenVisTauProducer : public edm::global::EDProducer<> +{ + public: + GenVisTauProducer(const edm::ParameterSet& params) + : src_(consumes(params.getParameter("src"))) + , srcGenParticles_(consumes(params.getParameter("srcGenParticles"))) + { + produces(); + } + + virtual ~GenVisTauProducer() {} + + void produce(edm::StreamID id, edm::Event& evt, const edm::EventSetup& es) const override + { + edm::Handle genTauJets; + evt.getByToken(src_, genTauJets); + + edm::Handle genParticles; + evt.getByToken(srcGenParticles_, genParticles); + size_t numGenParticles = genParticles->size(); + + auto genVisTaus = std::make_unique(); + + for (const auto & genTauJet : *genTauJets) { + std::string decayMode_string = JetMCTagUtils::genTauDecayMode(genTauJet); + // CV: store hadronic tau decays only + if ( decayMode_string == "electron" || decayMode_string == "muon" ) continue; + int decayMode = reco::PFTau::kNull; + if ( decayMode_string == "oneProng0Pi0" ) decayMode = reco::PFTau::kOneProng0PiZero; + else if ( decayMode_string == "oneProng1Pi0" ) decayMode = reco::PFTau::kOneProng1PiZero; + else if ( decayMode_string == "oneProng2Pi0" ) decayMode = reco::PFTau::kOneProng2PiZero; + else if ( decayMode_string == "threeProng0Pi0" ) decayMode = reco::PFTau::kThreeProng0PiZero; + else if ( decayMode_string == "threeProng1Pi0" ) decayMode = reco::PFTau::kThreeProng1PiZero; + else decayMode = reco::PFTau::kRareDecayMode; + + int pdgId = ( genTauJet.charge() > 0 ) ? -15 : +15; + + // CV: store decayMode in status flag of GenParticle object + reco::GenParticle genVisTau(genTauJet.charge(), genTauJet.p4(), genTauJet.vertex(), pdgId, decayMode, true); + + // CV: find tau lepton "mother" particle + for ( size_t idxGenParticle = 0; idxGenParticle < numGenParticles; ++idxGenParticle ) { + const reco::GenParticle & genTau = (*genParticles)[idxGenParticle]; + if ( abs(genTau.pdgId()) == 15 && genTau.status() == 2 ) { + reco::Candidate::LorentzVector daughterVisP4; + for (const reco::GenParticleRef & daughter : genTau.daughterRefVector()) { + int abs_pdgId = abs(daughter->pdgId()); + // CV: skip neutrinos + if ( abs_pdgId == 12 || abs_pdgId == 14 || abs_pdgId == 16 ) continue; + daughterVisP4 += daughter->p4(); + } + double dR2 = deltaR2(daughterVisP4, genVisTau); + if ( dR2 < 1.e-4 ) { + genVisTau.addMother(reco::GenParticleRef(genParticles, idxGenParticle)); + break; + } + } + } + + genVisTaus->push_back(genVisTau); + } + + evt.put(std::move(genVisTaus)); + } + + static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { + edm::ParameterSetDescription desc; + desc.add("src")->setComment("collection of visible gen taus (as reco::GenJetCollection)"); + desc.add("srcGenParticles")->setComment("collections of gen particles"); + descriptions.add("genVisTaus", desc); + } + + + private: + const edm::EDGetTokenT src_; + const edm::EDGetTokenT srcGenParticles_; +}; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(GenVisTauProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc new file mode 100644 index 0000000000000..a7dbc7ee02e1e --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc @@ -0,0 +1,409 @@ +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "PhysicsTools/NanoAOD/interface/MergableCounterTable.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include +#include +#include + +namespace { + /// ---- Cache object for running sums of weights ---- + struct Counter { + Counter() : + num(0), sumw(0), sumw2(0), sumPDF(), sumScale(), sumNamed() {} + + // the counters + long long num; + long double sumw; + long double sumw2; + std::vector sumPDF, sumScale, sumNamed; + + void clear() { + num = 0; sumw = 0; sumw2 = 0; + sumPDF.clear(); sumScale.clear(); sumNamed.clear(); + } + + // inc the counters + void incGenOnly(double w) { + num++; sumw += w; sumw2 += (w*w); + } + void incLHE(double w0, const std::vector & wScale, const std::vector & wPDF, const std::vector & wNamed) { + // add up weights + incGenOnly(w0); + // then add up variations + if (!wScale.empty()) { + if (sumScale.empty()) sumScale.resize(wScale.size(), 0); + for (unsigned int i = 0, n = wScale.size(); i < n; ++i) sumScale[i] += (w0 * wScale[i]); + } + if (!wPDF.empty()) { + if (sumPDF.empty()) sumPDF.resize(wPDF.size(), 0); + for (unsigned int i = 0, n = wPDF.size(); i < n; ++i) sumPDF[i] += (w0 * wPDF[i]); + } + if (!wNamed.empty()) { + if (sumNamed.empty()) sumNamed.resize(wNamed.size(), 0); + for (unsigned int i = 0, n = wNamed.size(); i < n; ++i) sumNamed[i] += (w0 * wNamed[i]); + } + } + + void merge(const Counter & other) { + num += other.num; sumw += other.sumw; sumw2 += other.sumw2; + if (sumScale.empty() && !other.sumScale.empty()) sumScale.resize(other.sumScale.size(),0); + if (sumPDF.empty() && !other.sumPDF.empty()) sumPDF.resize(other.sumPDF.size(),0); + if (sumNamed.empty() && !other.sumNamed.empty()) sumNamed.resize(other.sumNamed.size(),0); + for (unsigned int i = 0, n = sumScale.size(); i < n; ++i) sumScale[i] += other.sumScale[i]; + for (unsigned int i = 0, n = sumPDF.size(); i < n; ++i) sumPDF[i] += other.sumPDF[i]; + for (unsigned int i = 0, n = sumNamed.size(); i < n; ++i) sumNamed[i] += other.sumNamed[i]; + } + }; + + /// ---- RunCache object for dynamic choice of LHE IDs ---- + struct DynamicWeightChoice { + // choice of LHE weights + // ---- scale ---- + std::vector scaleWeightIDs; + std::string scaleWeightsDoc; + // ---- pdf ---- + std::vector pdfWeightIDs; + std::string pdfWeightsDoc; + }; + + /// -------------- temporary objects -------------- + struct ScaleVarWeight { + std::string wid, label; + std::pair scales; + ScaleVarWeight(const std::string & id, const std::string & text, const std::string & muR, const std::string & muF) : + wid(id), label(text), scales(std::stof(muR), std::stof(muF)) {} + bool operator<(const ScaleVarWeight & other) { return (scales == other.scales ? wid < other.wid : scales < other.scales); } + }; + struct PDFSetWeights { + std::vector wids; + std::pair lhaIDs; + PDFSetWeights(const std::string & wid, unsigned int lhaID) : wids(1,wid), lhaIDs(lhaID,lhaID) {} + bool operator<(const PDFSetWeights & other) const { return lhaIDs < other.lhaIDs; } + bool maybe_add(const std::string & wid, unsigned int lhaID) { + if (lhaID == lhaIDs.second+1) { + lhaIDs.second++; + wids.push_back(wid); + return true; + } else { + return false; + } + } + }; +} + +class GenWeightsTableProducer : public edm::global::EDProducer, edm::RunCache, edm::RunSummaryCache, edm::EndRunProducer> { + public: + GenWeightsTableProducer( edm::ParameterSet const & params ) : + genTag_(consumes(params.getParameter("genEvent"))), + lheLabel_(params.getParameter("lheInfo")), + lheTag_(consumes(lheLabel_)), + lheRunTag_(consumes(lheLabel_)), + preferredPDFLHAIDs_(params.getParameter>("preferredPDFs")), + namedWeightIDs_(params.getParameter>("namedWeightIDs")), + namedWeightLabels_(params.getParameter>("namedWeightLabels")), + lheWeightPrecision_(params.getParameter("lheWeightPrecision")), + maxPdfWeights_(params.getParameter("maxPdfWeights")), + debug_(params.getUntrackedParameter("debug",false)), debugRun_(debug_.load()), + hasIssuedWarning_(false) + { + produces(); + produces("LHEScale"); + produces("LHEPdf"); + produces("LHENamed"); + produces(); + if (namedWeightIDs_.size() != namedWeightLabels_.size()) { + throw cms::Exception("Configuration", "Size mismatch between namedWeightIDs & namedWeightLabels"); + } + } + + virtual ~GenWeightsTableProducer() {} + + void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { + // get my counter for weights + Counter * counter = streamCache(id); + + // generator information (always available) + edm::Handle genInfo; + iEvent.getByToken(genTag_, genInfo); + double weight = genInfo->weight(); + + // table for gen info, always available + auto out = std::make_unique(1, "genWeight", true); + out->setDoc("generator weight"); + out->addColumnValue("", weight, "generator weight", FlatTable::FloatColumn); + iEvent.put(std::move(out)); + + // tables for LHE weights, may not be filled + std::unique_ptr lheScaleTab, lhePdfTab, lheNamedTab; + + edm::Handle lheInfo; + if (iEvent.getByToken(lheTag_, lheInfo)) { + // get the dynamic choice of weights + const DynamicWeightChoice * weightChoice = runCache(iEvent.getRun().index()); + // go fill tables + fillLHEWeightTables(counter, weightChoice, weight, *lheInfo, lheScaleTab, lhePdfTab, lheNamedTab); + } else { + // minimal book-keeping of weights + counter->incGenOnly(weight); + // make dummy values + lheScaleTab.reset(new FlatTable(1, "LHEScaleWeights", true)); + lhePdfTab.reset(new FlatTable(1, "LHEPdfWeights", true)); + lheNamedTab.reset(new FlatTable(1, "LHENamedWeights", true)); + if (!hasIssuedWarning_.exchange(true)) { + edm::LogWarning("LHETablesProducer") << "No LHEEventProduct, so there will be no LHE Tables\n"; + } + } + + iEvent.put(std::move(lheScaleTab), "LHEScale"); + iEvent.put(std::move(lhePdfTab), "LHEPdf"); + iEvent.put(std::move(lheNamedTab), "LHENamed"); + } + + void fillLHEWeightTables( + Counter * counter, + const DynamicWeightChoice * weightChoice, + double genWeight, + const LHEEventProduct & lheProd, + std::unique_ptr & outScale, + std::unique_ptr & outPdf, + std::unique_ptr & outNamed ) const + { + bool lheDebug = debug_.exchange(false); // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind) + + const std::vector & scaleWeightIDs = weightChoice->scaleWeightIDs; + const std::vector & pdfWeightIDs = weightChoice->pdfWeightIDs; + + double w0 = lheProd.originalXWGTUP(); + + std::vector wScale(scaleWeightIDs.size(), 1), wPDF(pdfWeightIDs.size(), 1), wNamed(namedWeightIDs_.size(), 1); + for (auto & weight : lheProd.weights()) { + if (lheDebug) printf("Weight %+9.5f rel %+9.5f for id %s\n", weight.wgt, weight.wgt/w0, weight.id.c_str()); + // now we do it slowly, can be optimized + auto mScale = std::find(scaleWeightIDs.begin(), scaleWeightIDs.end(), weight.id); + if (mScale != scaleWeightIDs.end()) wScale[mScale-scaleWeightIDs.begin()] = weight.wgt/w0; + + auto mPDF = std::find(pdfWeightIDs.begin(), pdfWeightIDs.end(), weight.id); + if (mPDF != pdfWeightIDs.end()) wPDF[mPDF-pdfWeightIDs.begin()] = weight.wgt/w0; + + auto mNamed = std::find(namedWeightIDs_.begin(), namedWeightIDs_.end(), weight.id); + if (mNamed != namedWeightIDs_.end()) wNamed[mNamed-namedWeightIDs_.begin()] = weight.wgt/w0; + } + + outScale.reset(new FlatTable(wScale.size(), "LHEScaleWeight", false)); + outScale->addColumn("", wScale, weightChoice->scaleWeightsDoc, FlatTable::FloatColumn, lheWeightPrecision_); + + outPdf.reset(new FlatTable(wPDF.size(), "LHEPdfWeight", false)); + outPdf->addColumn("", wPDF, weightChoice->pdfWeightsDoc, FlatTable::FloatColumn, lheWeightPrecision_); + + outNamed.reset(new FlatTable(1, "LHEWeight", true)); + outNamed->addColumnValue("originalXWGTUP", lheProd.originalXWGTUP(), "Nominal event weight in the LHE file", FlatTable::FloatColumn); + for (unsigned int i = 0, n = wNamed.size(); i < n; ++i) { + outNamed->addColumnValue(namedWeightLabels_[i], wNamed[i], "LHE weight for id "+namedWeightIDs_[i]+", relative to nominal", FlatTable::FloatColumn, lheWeightPrecision_); + } + + counter->incLHE(genWeight, wScale, wPDF, wNamed); + } + + // create an empty counter + std::shared_ptr globalBeginRun(edm::Run const& iRun, edm::EventSetup const&) const override { + edm::Handle lheInfo; + + bool lheDebug = debugRun_.exchange(false); // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind) + auto weightChoice = std::make_shared(); + + // getByToken throws since we're not in the endRun (see https://github.com/cms-sw/cmssw/pull/18499) + //if (iRun.getByToken(lheRunTag_, lheInfo)) { + if (iRun.getByLabel(lheLabel_, lheInfo)) { + std::vector scaleVariationIDs; + std::vector pdfSetWeightIDs; + + std::regex weightgroup(""); + std::regex endweightgroup(""); + std::regex scalew("\\s*(muR=(\\S+)\\s+muF=(\\S+)(\\s+.*)?)"); + std::regex pdfw("\\s*PDF set\\s*=\\s*(\\d+)\\s*"); + std::smatch groups; + for (auto iter=lheInfo->headers_begin(), end = lheInfo->headers_end(); iter != end; ++iter) { + if (iter->tag() != "initrwgt") { + if (lheDebug) std::cout << "Skipping LHE header with tag" << iter->tag() << std::endl; + continue; + } + if (lheDebug) std::cout << "Found LHE header with tag" << iter->tag() << std::endl; + const std::vector & lines = iter->lines(); + for (unsigned int iLine = 0, nLines = lines.size(); iLine < nLines; ++iLine) { + 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") { + for ( ++iLine; iLine < nLines; ++iLine) { + if (lheDebug) std::cout << " " << lines[iLine]; + if (std::regex_search(lines[iLine], groups, scalew)) { + if (lheDebug) std::cout << " >>> Scale weight " << groups[1].str() << " for " << groups[3].str() << " , " << groups[4].str() << " , " << groups[5].str() << std::endl; + scaleVariationIDs.emplace_back(groups.str(1), groups.str(2), groups.str(3), groups.str(4)); + } 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 if (groups.str(2) == "PDF_variation") { + for ( ++iLine; iLine < nLines; ++iLine) { + if (lheDebug) std::cout << " " << lines[iLine]; + if (std::regex_search(lines[iLine], groups, pdfw)) { + unsigned int lhaID = std::stoi(groups.str(2)); + if (lheDebug) std::cout << " >>> PDF weight " << groups.str(1) << " for " << groups.str(2) << " = " << lhaID << std::endl; + 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]; + if (std::regex_search(lines[iLine], groups, 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; + } + } + } + } + } + //std::cout << "============= END [ " << iter->tag() << " ] ============ \n\n" << std::endl; + + // ----- SCALE VARIATIONS ----- + std::sort(scaleVariationIDs.begin(), scaleVariationIDs.end()); + if (lheDebug) std::cout << "Found " << scaleVariationIDs.size() << " scale variations: " << std::endl; + std::stringstream scaleDoc("LHE scale variation weights (w_var / w_nominal); "); + for (unsigned int isw = 0, nsw = scaleVariationIDs.size(); isw < nsw; ++isw) { + const auto & sw = scaleVariationIDs[isw]; + if (isw) scaleDoc << "; "; + scaleDoc << "[" << isw << "] is " << sw.label; + weightChoice->scaleWeightIDs.push_back(sw.wid); + if (lheDebug) printf(" id %s: scales ren = % .2f fact = % .2f text = %s\n", sw.wid.c_str(), sw.scales.first, sw.scales.second, sw.label.c_str()); + } + if (!scaleVariationIDs.empty()) weightChoice->scaleWeightsDoc = scaleDoc.str(); + + // ------ PDF VARIATIONS (take the preferred one) ----- + if (lheDebug) { + std::cout << "Found " << pdfSetWeightIDs.size() << " PDF set errors: " << std::endl; + for (const auto & pw : pdfSetWeightIDs) printf("lhaIDs %6d - %6d (%3lu weights: %s, ... )\n", pw.lhaIDs.first, pw.lhaIDs.second, pw.wids.size(), pw.wids.front().c_str()); + } + + std::stringstream pdfDoc("LHE pdf variation weights (w_var / w_nominal) for LHA IDs "); + bool found = false; + for (uint32_t lhaid : preferredPDFLHAIDs_) { + for (const auto & pw : pdfSetWeightIDs) { + if (pw.lhaIDs.first != lhaid) continue; + pdfDoc << pw.lhaIDs.first << " - " << pw.lhaIDs.second; + weightChoice->pdfWeightIDs = pw.wids; + if (maxPdfWeights_ < pw.wids.size()) { + weightChoice->pdfWeightIDs.resize(maxPdfWeights_); // drop some replicas + pdfDoc << ", truncated to the first " << maxPdfWeights_ << " replicas"; + } + weightChoice->pdfWeightsDoc = pdfDoc.str(); + found = true; break; + } + if (found) break; + } + } + } + return weightChoice; + } + + + // create an empty counter + std::unique_ptr beginStream(edm::StreamID) const override { + return std::make_unique(); + } + // inizialize to zero at begin run + void streamBeginRun(edm::StreamID id, edm::Run const&, edm::EventSetup const&) const override { + streamCache(id)->clear(); + } + // create an empty counter + std::shared_ptr globalBeginRunSummary(edm::Run const&, edm::EventSetup const&) const override { + return std::make_shared(); + } + // add this stream to the summary + void streamEndRunSummary(edm::StreamID id, edm::Run const&, edm::EventSetup const&, Counter* runCounter) const override { + runCounter->merge(*streamCache(id)); + } + // nothing to do per se + void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, Counter* runCounter) const override { + } + // write the total to the run + void globalEndRunProduce(edm::Run& iRun, edm::EventSetup const&, Counter const* runCounter) const override { + auto out = std::make_unique(); + out->addInt("genEventCount", "event count", runCounter->num); + out->addFloat("genEventSumw", "sum of gen weights", runCounter->sumw); + out->addFloat("genEventSumw2", "sum of gen (weight^2)", runCounter->sumw2); + + double norm = runCounter->sumw ? 1.0/runCounter->sumw : 1; + auto sumScales = runCounter->sumScale; for (auto & val : sumScales) val *= norm; + out->addVFloat("LHEScaleSumw", "Sum of genEventWeight * LHEScaleWeight[i], divided by genEventSumw", sumScales); + auto sumPDFs = runCounter->sumPDF; for (auto & val : sumPDFs) val *= norm; + out->addVFloat("LHEPdfSumw", "Sum of genEventWeight * LHEPdfWeight[i], divided by genEventSumw", sumPDFs); + if (!runCounter->sumNamed.empty()) { // it could be empty if there's no LHE info in the sample + for (unsigned int i = 0, n = namedWeightLabels_.size(); i < n; ++i) { + out->addFloat("LHESumw_"+namedWeightLabels_[i], "Sum of genEventWeight * LHEWeight_"+namedWeightLabels_[i]+", divided by genEventSumw", runCounter->sumNamed[i] * norm); + } + } + iRun.put(std::move(out)); + } + // nothing to do here + void globalEndRun(edm::Run const&, edm::EventSetup const&) const override { } + + static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { + edm::ParameterSetDescription desc; + desc.add("genEvent", edm::InputTag("generator"))->setComment("tag for the GenEventInfoProduct, to get the main weight"); + desc.add("lheInfo", edm::InputTag("externalLHEProducer"))->setComment("tag for the LHE information (LHEEventProduct and LHERunInfoProduct)"); + desc.add>("preferredPDFs")->setComment("LHA PDF Ids of the preferred PDF sets, in order of preference (the first matching one will be used)"); + desc.add>("namedWeightIDs")->setComment("set of LHA weight IDs for named LHE weights"); + desc.add>("namedWeightLabels")->setComment("output names for the namedWeightIDs (in the same order)"); + desc.add("lheWeightPrecision")->setComment("Number of bits in the mantissa for LHE weights"); + desc.add("maxPdfWeights")->setComment("Maximum number of PDF weights to save (to crop NN replicas)"); + desc.addOptionalUntracked("debug")->setComment("dump out all LHE information for one event"); + descriptions.add("genWeightsTable", desc); + } + + + protected: + const edm::EDGetTokenT genTag_; + const edm::InputTag lheLabel_; + const edm::EDGetTokenT lheTag_; + const edm::EDGetTokenT lheRunTag_; + + std::vector preferredPDFLHAIDs_; + std::vector namedWeightIDs_; + std::vector namedWeightLabels_; + int lheWeightPrecision_; + unsigned int maxPdfWeights_; + + mutable std::atomic debug_, debugRun_, hasIssuedWarning_; +}; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(GenWeightsTableProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc new file mode 100644 index 0000000000000..299df7dec74b7 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc @@ -0,0 +1,134 @@ +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "DataFormats/Candidate/interface/Candidate.h" + +#include +#include +#include + +class GlobalVariablesTableProducer : public edm::stream::EDProducer<> { + public: + + GlobalVariablesTableProducer( edm::ParameterSet const & params ) + { + edm::ParameterSet const & varsPSet = params.getParameter("variables"); + for (const std::string & vname : varsPSet.getParameterNamesForType()) { + const auto & varPSet = varsPSet.getParameter(vname); + const std::string & type = varPSet.getParameter("type"); + if (type == "int") vars_.push_back(new IntVar(vname, FlatTable::IntColumn, varPSet, consumesCollector())); + else if (type == "float") vars_.push_back(new FloatVar(vname, FlatTable::FloatColumn, varPSet, consumesCollector())); + else if (type == "double") vars_.push_back(new DoubleVar(vname, FlatTable::FloatColumn, varPSet, consumesCollector())); + else if (type == "bool") vars_.push_back(new BoolVar(vname, FlatTable::UInt8Column, varPSet, consumesCollector())); + else if (type == "candidatescalarsum") vars_.push_back(new CandidateScalarSumVar(vname, FlatTable::FloatColumn, varPSet, consumesCollector())); + else if (type == "candidatesize") vars_.push_back(new CandidateSizeVar(vname, FlatTable::IntColumn, varPSet, consumesCollector())); + else throw cms::Exception("Configuration", "unsupported type "+type+" for variable "+vname); + } + + produces(); + } + + virtual ~GlobalVariablesTableProducer() {} + + void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override { + auto out = std::make_unique(1, "", true); + + for (const auto & var : vars_) var.fill(iEvent, *out); + + iEvent.put(std::move(out)); + } + + protected: + class Variable { + public: + Variable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : + name_(aname), doc_(cfg.getParameter("doc")), type_(atype) {} + virtual void fill(const edm::Event &iEvent, FlatTable & out) const = 0; + virtual ~Variable() {} + const std::string & name() const { return name_; } + const FlatTable::ColumnType & type() const { return type_; } + protected: + std::string name_, doc_; + FlatTable::ColumnType type_; + }; + template + class Identity { + public: + static ValType convert(ValType x){return x;} + + }; + template + class Size { + public: + static int convert(ValType x){return x.size();} + + }; + + template + class Max { + public: + static ColType convert(ValType x){ + ColType v=std::numeric_limits::min(); + for(const auto & i : x) if(i>v) v=i; + return v; + } + }; + template + class Min { + public: + static ColType convert(ValType x){ + ColType v=std::numeric_limits::max(); + for(const auto & i : x) if(i + class ScalarPtSum { + public: + static ColType convert(ValType x){ + ColType v=0; + for(const auto & i : x) v+=i.pt(); + return v; + } + }; + template + class PtVectorSum { + public: + static ColType convert(ValType x){ + if(x.size()==0) return 0; + auto v=x[0].p4(); + v-=x[0].p4(); + for(const auto & i : x) v+=i.p4(); + return v.pt(); + } + }; + + + + template > + class VariableT : public Variable { + public: + VariableT(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg, edm::ConsumesCollector && cc) : + Variable(aname, atype, cfg), src_(cc.consumes(cfg.getParameter("src"))) {} + ~VariableT() {} + void fill(const edm::Event &iEvent, FlatTable & out) const override { + edm::Handle handle; + iEvent.getByToken(src_, handle); + out.template addColumnValue(this->name_, Converter::convert(*handle), this->doc_, this->type_); + } + protected: + edm::EDGetTokenT src_; + }; + typedef VariableT IntVar; + typedef VariableT FloatVar; + typedef VariableT DoubleVar; + typedef VariableT BoolVar; + typedef VariableT,float,ScalarPtSum>> CandidateScalarSumVar; + typedef VariableT,int,Size>> CandidateSizeVar; + boost::ptr_vector vars_; +}; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(GlobalVariablesTableProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc b/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc new file mode 100644 index 0000000000000..ff359a2834be2 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc @@ -0,0 +1,318 @@ +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: IsoValueMapProducer +// +/**\class IsoValueMapProducer IsoValueMapProducer.cc PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Marco Peruzzi +// Created: Mon, 04 Sep 2017 22:43:53 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/global/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "RecoEgamma/EgammaTools/interface/EffectiveAreas.h" + +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/PatCandidates/interface/Electron.h" +#include "DataFormats/PatCandidates/interface/Photon.h" +#include "DataFormats/PatCandidates/interface/IsolatedTrack.h" + +// +// class declaration +// + +template +class IsoValueMapProducer : public edm::global::EDProducer<> { + public: + explicit IsoValueMapProducer(const edm::ParameterSet &iConfig): + src_(consumes>(iConfig.getParameter("src"))) + { + if ((typeid(T) == typeid(pat::Muon)) || (typeid(T) == typeid(pat::Electron)) || typeid(T) == typeid(pat::IsolatedTrack)) { + produces>("miniIsoChg"); + produces>("miniIsoAll"); + ea_miniiso_.reset(new EffectiveAreas((iConfig.getParameter("EAFile_MiniIso")).fullPath())); + rho_miniiso_ = consumes(iConfig.getParameter("rho_MiniIso")); + } + if ((typeid(T) == typeid(pat::Electron))) { + produces>("PFIsoChg"); + produces>("PFIsoAll"); + ea_pfiso_.reset(new EffectiveAreas((iConfig.getParameter("EAFile_PFIso")).fullPath())); + rho_pfiso_ = consumes(iConfig.getParameter("rho_PFIso")); + } + if ((typeid(T) == typeid(pat::Photon))) { + produces>("PFIsoChg"); + produces>("PFIsoAll"); + mapIsoChg_ = consumes >(iConfig.getParameter("mapIsoChg")); + mapIsoNeu_ = consumes >(iConfig.getParameter("mapIsoNeu")); + mapIsoPho_ = consumes >(iConfig.getParameter("mapIsoPho")); + ea_pfiso_chg_.reset(new EffectiveAreas((iConfig.getParameter("EAFile_PFIso_Chg")).fullPath())); + ea_pfiso_neu_.reset(new EffectiveAreas((iConfig.getParameter("EAFile_PFIso_Neu")).fullPath())); + ea_pfiso_pho_.reset(new EffectiveAreas((iConfig.getParameter("EAFile_PFIso_Pho")).fullPath())); + rho_pfiso_ = consumes(iConfig.getParameter("rho_PFIso")); + } + } + ~IsoValueMapProducer() {} + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + + virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + + // ----------member data --------------------------- + + edm::EDGetTokenT> src_; + edm::EDGetTokenT rho_miniiso_; + edm::EDGetTokenT rho_pfiso_; + edm::EDGetTokenT> mapIsoChg_; + edm::EDGetTokenT> mapIsoNeu_; + edm::EDGetTokenT> mapIsoPho_; + std::unique_ptr ea_miniiso_; + std::unique_ptr ea_pfiso_; + std::unique_ptr ea_pfiso_chg_; + std::unique_ptr ea_pfiso_neu_; + std::unique_ptr ea_pfiso_pho_; + float getEtaForEA(const T*) const; + void doMiniIso(edm::Event&) const; + void doPFIsoEle(edm::Event&) const; + void doPFIsoPho(edm::Event&) const; + +}; + +// +// constants, enums and typedefs +// + + +// +// static data member definitions +// + +template float IsoValueMapProducer::getEtaForEA(const T *obj) const{ + return obj->eta(); +} +template<> float IsoValueMapProducer::getEtaForEA(const pat::Electron *el) const{ + return el->superCluster()->eta(); +} +template<> float IsoValueMapProducer::getEtaForEA(const pat::Photon *ph) const{ + return ph->superCluster()->eta(); +} + +template +void +IsoValueMapProducer::produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const +{ + + if ((typeid(T) == typeid(pat::Muon)) || (typeid(T) == typeid(pat::Electron)) || typeid(T) == typeid(pat::IsolatedTrack)) { doMiniIso(iEvent); }; + if ((typeid(T) == typeid(pat::Electron))) { doPFIsoEle(iEvent); } + if ((typeid(T) == typeid(pat::Photon))) { doPFIsoPho(iEvent); } + +} + +template +void +IsoValueMapProducer::doMiniIso(edm::Event& iEvent) const{ + + edm::Handle> src; + iEvent.getByToken(src_, src); + edm::Handle rho; + iEvent.getByToken(rho_miniiso_,rho); + + unsigned nInput = src->size(); + + std::vector miniIsoChg, miniIsoAll; + miniIsoChg.reserve(nInput); + miniIsoAll.reserve(nInput); + + for (uint i=0; i(src->ptrAt(i).get()); // temporarily needed + auto iso = obj->miniPFIsolation(); + auto chg = iso.chargedHadronIso(); + auto neu = iso.neutralHadronIso(); + auto pho = iso.photonIso(); + auto ea = ea_miniiso_->getEffectiveArea(fabs(getEtaForEA(obj))); + float R = 10.0/std::min(std::max(obj->pt(), 50.0),200.0); + ea *= std::pow(R/0.3,2); + miniIsoChg.push_back(chg); + miniIsoAll.push_back(chg+std::max(0.0,neu+pho-(*rho)*ea)); + } + + std::unique_ptr> miniIsoChgV(new edm::ValueMap()); + edm::ValueMap::Filler fillerChg(*miniIsoChgV); + fillerChg.insert(src,miniIsoChg.begin(),miniIsoChg.end()); + fillerChg.fill(); + std::unique_ptr> miniIsoAllV(new edm::ValueMap()); + edm::ValueMap::Filler fillerAll(*miniIsoAllV); + fillerAll.insert(src,miniIsoAll.begin(),miniIsoAll.end()); + fillerAll.fill(); + + iEvent.put(std::move(miniIsoChgV),"miniIsoChg"); + iEvent.put(std::move(miniIsoAllV),"miniIsoAll"); +} + +template<> +void +IsoValueMapProducer::doMiniIso(edm::Event& iEvent) const {} + + +template +void +IsoValueMapProducer::doPFIsoEle(edm::Event& iEvent) const {} + +template<> +void +IsoValueMapProducer::doPFIsoEle(edm::Event& iEvent) const{ + + edm::Handle> src; + iEvent.getByToken(src_, src); + edm::Handle rho; + iEvent.getByToken(rho_pfiso_,rho); + + unsigned nInput = src->size(); + + std::vector PFIsoChg, PFIsoAll; + PFIsoChg.reserve(nInput); + PFIsoAll.reserve(nInput); + + for (uint i=0; iptrAt(i).get(); + auto iso = obj->pfIsolationVariables(); + auto chg = iso.sumChargedHadronPt; + auto neu = iso.sumNeutralHadronEt; + auto pho = iso.sumPhotonEt; + auto ea = ea_pfiso_->getEffectiveArea(fabs(getEtaForEA(obj))); + PFIsoChg.push_back(chg); + PFIsoAll.push_back(chg+std::max(0.0,neu+pho-(*rho)*ea)); + } + + std::unique_ptr> PFIsoChgV(new edm::ValueMap()); + edm::ValueMap::Filler fillerChg(*PFIsoChgV); + fillerChg.insert(src,PFIsoChg.begin(),PFIsoChg.end()); + fillerChg.fill(); + std::unique_ptr> PFIsoAllV(new edm::ValueMap()); + edm::ValueMap::Filler fillerAll(*PFIsoAllV); + fillerAll.insert(src,PFIsoAll.begin(),PFIsoAll.end()); + fillerAll.fill(); + + iEvent.put(std::move(PFIsoChgV),"PFIsoChg"); + iEvent.put(std::move(PFIsoAllV),"PFIsoAll"); + +} + +template +void +IsoValueMapProducer::doPFIsoPho(edm::Event& iEvent) const {} + +template<> +void +IsoValueMapProducer::doPFIsoPho(edm::Event& iEvent) const { + + edm::Handle> src; + iEvent.getByToken(src_, src); + edm::Handle rho; + iEvent.getByToken(rho_pfiso_,rho); + edm::Handle > mapIsoChg; + iEvent.getByToken(mapIsoChg_, mapIsoChg); + edm::Handle > mapIsoNeu; + iEvent.getByToken(mapIsoNeu_, mapIsoNeu); + edm::Handle > mapIsoPho; + iEvent.getByToken(mapIsoPho_, mapIsoPho); + + unsigned nInput = src->size(); + + std::vector PFIsoChg, PFIsoAll; + PFIsoChg.reserve(nInput); + PFIsoAll.reserve(nInput); + + for (uint i=0; iptrAt(i); + auto chg = (*mapIsoChg)[obj]; + auto neu = (*mapIsoNeu)[obj]; + auto pho = (*mapIsoPho)[obj]; + auto ea_chg = ea_pfiso_chg_->getEffectiveArea(fabs(getEtaForEA(obj.get()))); + auto ea_neu = ea_pfiso_neu_->getEffectiveArea(fabs(getEtaForEA(obj.get()))); + auto ea_pho = ea_pfiso_pho_->getEffectiveArea(fabs(getEtaForEA(obj.get()))); + PFIsoChg.push_back(std::max(0.0,chg-(*rho)*ea_chg)); + PFIsoAll.push_back(PFIsoChg.back()+std::max(0.0,neu-(*rho)*ea_neu)+std::max(0.0,pho-(*rho)*ea_pho)); + } + + std::unique_ptr> PFIsoChgV(new edm::ValueMap()); + edm::ValueMap::Filler fillerChg(*PFIsoChgV); + fillerChg.insert(src,PFIsoChg.begin(),PFIsoChg.end()); + fillerChg.fill(); + std::unique_ptr> PFIsoAllV(new edm::ValueMap()); + edm::ValueMap::Filler fillerAll(*PFIsoAllV); + fillerAll.insert(src,PFIsoAll.begin(),PFIsoAll.end()); + fillerAll.fill(); + + iEvent.put(std::move(PFIsoChgV),"PFIsoChg"); + iEvent.put(std::move(PFIsoAllV),"PFIsoAll"); + +} + + + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +template +void +IsoValueMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("src")->setComment("input physics object collection"); + if ((typeid(T) == typeid(pat::Muon)) || (typeid(T) == typeid(pat::Electron)) || typeid(T) == typeid(pat::IsolatedTrack)) { + desc.add("EAFile_MiniIso")->setComment("txt file containing effective areas to be used for mini-isolation pileup subtraction"); + desc.add("rho_MiniIso")->setComment("rho to be used for effective-area based mini-isolation pileup subtraction"); + } + if ((typeid(T) == typeid(pat::Electron))) { + desc.add("EAFile_PFIso")->setComment("txt file containing effective areas to be used for PF-isolation pileup subtraction for electrons"); + desc.add("rho_PFIso")->setComment("rho to be used for effective-area based PF-isolation pileup subtraction for electrons"); + } + if ((typeid(T) == typeid(pat::Photon))) { + desc.add("mapIsoChg")->setComment("input charged PF isolation calculated in VID for photons"); + desc.add("mapIsoNeu")->setComment("input neutral PF isolation calculated in VID for photons"); + desc.add("mapIsoPho")->setComment("input photon PF isolation calculated in VID for photons"); + desc.add("EAFile_PFIso_Chg")->setComment("txt file containing effective areas to be used for charged PF-isolation pileup subtraction for photons"); + desc.add("EAFile_PFIso_Neu")->setComment("txt file containing effective areas to be used for neutral PF-isolation pileup subtraction for photons"); + desc.add("EAFile_PFIso_Pho")->setComment("txt file containing effective areas to be used for photon PF-isolation pileup subtraction for photons"); + desc.add("rho_PFIso")->setComment("rho to be used for effective-area based PF-isolation pileup subtraction for photons"); + } + std::string modname; + if (typeid(T) == typeid(pat::Muon)) modname+="Muon"; + else if (typeid(T) == typeid(pat::Electron)) modname+="Ele"; + else if (typeid(T) == typeid(pat::Photon)) modname+="Pho"; + else if (typeid(T) == typeid(pat::IsolatedTrack)) modname+="IsoTrack"; + modname+="IsoValueMapProducer"; + descriptions.add(modname,desc); +} + + +typedef IsoValueMapProducer MuonIsoValueMapProducer; +typedef IsoValueMapProducer EleIsoValueMapProducer; +typedef IsoValueMapProducer PhoIsoValueMapProducer; +typedef IsoValueMapProducer IsoTrackIsoValueMapProducer; + +//define this as a plug-in +DEFINE_FWK_MODULE(MuonIsoValueMapProducer); +DEFINE_FWK_MODULE(EleIsoValueMapProducer); +DEFINE_FWK_MODULE(PhoIsoValueMapProducer); +DEFINE_FWK_MODULE(IsoTrackIsoValueMapProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/IsolatedTrackCleaner.cc b/PhysicsTools/NanoAOD/plugins/IsolatedTrackCleaner.cc new file mode 100644 index 0000000000000..67f384d7dae3c --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/IsolatedTrackCleaner.cc @@ -0,0 +1,67 @@ +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/PatCandidates/interface/IsolatedTrack.h" +#include "DataFormats/Common/interface/RefToPtr.h" +#include "CommonTools/Utils/interface/StringCutObjectSelector.h" + +#include + + +class IsolatedTrackCleaner : public edm::global::EDProducer<> { + public: + IsolatedTrackCleaner( edm::ParameterSet const & params ) : + tracks_(consumes>(params.getParameter("tracks"))), + cut_(params.getParameter("cut")) + { + for (const edm::InputTag & tag : params.getParameter>("finalLeptons")) { + leptons_.push_back(consumes(tag)); + } + produces>(); + } + + virtual ~IsolatedTrackCleaner() {} + + void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { + auto out = std::make_unique>(); + + std::vector leptonPfCands; + edm::Handle leptons; + for (const auto & token : leptons_) { + iEvent.getByToken(token, leptons); + for (const auto & lep : *leptons) { + for (unsigned int i = 0, n = lep.numberOfSourceCandidatePtrs(); i < n; ++i) { + auto ptr = lep.sourceCandidatePtr(i); + if (ptr.isNonnull()) leptonPfCands.push_back(ptr); + } + } + } + std::sort(leptonPfCands.begin(), leptonPfCands.end()); + + edm::Handle> tracks; + iEvent.getByToken(tracks_, tracks); + for (const auto & track : *tracks) { + if (!cut_(track)) continue; + if (track.packedCandRef().isNonnull()) { + reco::CandidatePtr pfCand(edm::refToPtr(track.packedCandRef())); + if (std::binary_search(leptonPfCands.begin(), leptonPfCands.end(), pfCand)) { + continue; + } + } + out->push_back(track); + } + + iEvent.put(std::move(out)); + } + + protected: + edm::EDGetTokenT> tracks_; + StringCutObjectSelector cut_; + std::vector> leptons_; +}; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(IsolatedTrackCleaner); + diff --git a/PhysicsTools/NanoAOD/plugins/JetIDValueMap.cc b/PhysicsTools/NanoAOD/plugins/JetIDValueMap.cc new file mode 100644 index 0000000000000..545e79e2f65ec --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/JetIDValueMap.cc @@ -0,0 +1,7 @@ +#include "PhysicsTools/NanoAOD/plugins/FilterValueMapWrapper.h" +#include "PhysicsTools/SelectorUtils/interface/PFJetIDSelectionFunctor.h" + +typedef edm::FilterValueMapWrapper > PatJetIDValueMapProducer; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(PatJetIDValueMapProducer); diff --git a/PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc b/PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc new file mode 100644 index 0000000000000..05618b4d92578 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc @@ -0,0 +1,168 @@ +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: L1TriggerResultsConverter +// +/**\class L1TriggerResultsConverter L1TriggerResultsConverter.cc PhysicsTools/L1TriggerResultsConverter/plugins/L1TriggerResultsConverter.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Andrea Rizzi +// Created: Mon, 11 Aug 2017 11:20:30 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h" +#include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h" +#include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h" +#include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h" +#include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h" +#include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h" + +#include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "FWCore/Common/interface/TriggerNames.h" +#include "DataFormats/Common/interface/TriggerResults.h" + +#include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtils.h" +// +// class declaration +// + +class L1TriggerResultsConverter : public edm::global::EDProducer<> { + public: + explicit L1TriggerResultsConverter(const edm::ParameterSet&); + ~L1TriggerResultsConverter(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + virtual void beginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&); + + // ----------member data --------------------------- + const bool legacyL1_; + const edm::EDGetTokenT tokenLegacy_; + const edm::EDGetTokenT token_; + std::vector names_; + std::vector mask_; + std::vector indices_; +}; + + + +// +// constructors and destructor +// +L1TriggerResultsConverter::L1TriggerResultsConverter(const edm::ParameterSet& params): + legacyL1_( params.getParameter("legacyL1") ), + tokenLegacy_(legacyL1_?consumes( params.getParameter("src") ): edm::EDGetTokenT()), + token_(!legacyL1_?consumes( params.getParameter("src") ): edm::EDGetTokenT()) +{ + produces(); +} + + +L1TriggerResultsConverter::~L1TriggerResultsConverter() +{ + + // do anything here that needs to be done at destruction time + // (e.g. close files, deallocate resources etc.) + +} + + +// +// member functions +// + +void L1TriggerResultsConverter::beginRun(edm::StreamID streamID, edm::Run const&, edm::EventSetup const&setup) { + mask_.clear(); + names_.clear(); + indices_.clear(); + if(legacyL1_){ + edm::ESHandle handleMenu; + edm::ESHandle handleAlgoMask; + setup.get().get(handleMenu); + auto const & mapping = handleMenu->gtAlgorithmAliasMap(); + for (auto const & keyval: mapping) { + names_.push_back(keyval.first); + indices_.push_back(keyval.second.algoBitNumber()); + } + setup.get().get(handleAlgoMask); + mask_ = handleAlgoMask->gtTriggerMask(); + } else { + edm::ESHandle menu; + setup.get().get(menu); + auto const & mapping = menu->getAlgorithmMap(); + for (auto const & keyval: mapping) { + names_.push_back(keyval.first); + indices_.push_back(keyval.second.getIndex()); + } + + } +} + +// ------------ method called to produce the data ------------ + + +void +L1TriggerResultsConverter::produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const +{ + using namespace edm; + const std::vector * wordp=nullptr; + if (!legacyL1_){ + edm::Handle handleResults; + iEvent.getByToken(token_, handleResults); + wordp= & handleResults->at(0,0).getAlgoDecisionFinal() ; + } else { +// Legacy access + edm::Handle handleResults; + iEvent.getByToken(tokenLegacy_, handleResults); + wordp = & handleResults->decisionWord(); + } + auto const &word = *wordp; + HLTGlobalStatus l1bitsAsHLTStatus(names_.size()); +// std::cout << word.size() << " " << names_.size() << " " << mask_.size() << std::endl; + unsigned indices_size = indices_.size(); + for(size_t nidx=0;nidx(l1bitsAsHLTStatus,names_); + iEvent.put(std::move(out)); + +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +L1TriggerResultsConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("legacyL1")->setComment("is legacy L1"); + desc.add("src")->setComment("L1 input (L1GlobalTriggerReadoutRecord if legacy, GlobalAlgBlkBxCollection otherwise)"); + descriptions.add("L1TriggerResultsConverter",desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(L1TriggerResultsConverter); diff --git a/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc b/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc new file mode 100644 index 0000000000000..af0fe2baa99b1 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc @@ -0,0 +1,98 @@ +#include "FWCore/Framework/interface/global/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 "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" + +#include +#include + + +class LHETablesProducer : public edm::global::EDProducer<> { + public: + LHETablesProducer( edm::ParameterSet const & params ) : + lheTag_(consumes(params.getParameter("lheInfo"))) + { + produces(); + } + + virtual ~LHETablesProducer() {} + + void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { + auto lheTab = std::make_unique(1, "LHE", true); + + edm::Handle lheInfo; + if (iEvent.getByToken(lheTag_, lheInfo)) { + fillLHEObjectTable(*lheInfo, *lheTab); + } + + iEvent.put(std::move(lheTab)); + } + + void fillLHEObjectTable(const LHEEventProduct & lheProd, FlatTable & out) const { + double lheHT = 0, lheHTIncoming = 0; + unsigned int lheNj = 0, lheNb = 0, lheNc = 0, lheNuds = 0, lheNglu = 0; + double lheVpt = 0; + + const auto & hepeup = lheProd.hepeup(); + const auto & pup = hepeup.PUP; + int lep = -1, lepBar = -1, nu = -1, nuBar = -1; + for (unsigned int i = 0, n = pup.size(); i < n; ++i) { + int status = hepeup.ISTUP[i]; + int idabs = std::abs(hepeup.IDUP[i]); + if ( (status == 1) && ( ( idabs == 21 ) || (idabs > 0 && idabs < 7) ) ) { //# gluons and quarks + // object counters + lheNj++; + if (idabs==5) lheNb++; + else if (idabs==4) lheNc++; + else if (idabs <= 3 ) lheNuds++; + else if (idabs == 21) lheNglu++; + // HT + double pt = std::hypot( pup[i][0], pup[i][1] ); // first entry is px, second py + lheHT += pt; + int mothIdx = std::max(hepeup.MOTHUP[i].first-1,0); //first and last mother as pair; first entry has index 1 in LHE; incoming particles return motherindex 0 + int mothIdxTwo = std::max(hepeup.MOTHUP[i].second-1,0); + int mothStatus = hepeup.ISTUP[mothIdx]; + int mothStatusTwo = hepeup.ISTUP[mothIdxTwo]; + bool hasIncomingAsMother = mothStatus<0 || mothStatusTwo<0; + if (hasIncomingAsMother) lheHTIncoming += pt; + } else if (idabs == 12 || idabs == 14 || idabs == 16) { + (hepeup.IDUP[i] > 0 ? nu : nuBar) = i; + } else if (idabs == 11 || idabs == 13 || idabs == 15) { + (hepeup.IDUP[i] > 0 ? lep : lepBar) = i; + } + } + std::pair v(0,0); + if (lep != -1 && lepBar != -1) v = std::make_pair(lep,lepBar); + else if (lep != -1 && nuBar != -1) v = std::make_pair(lep, nuBar); + else if (nu != -1 && lepBar != -1) v = std::make_pair(nu ,lepBar); + else if (nu != -1 && nuBar != -1) v = std::make_pair(nu , nuBar); + if (v.first != -1 && v.second != -1) { + lheVpt = std::hypot( pup[v.first][0] + pup[v.second][0], pup[v.first][1] + pup[v.second][1] ); + } + + out.addColumnValue("Njets", lheNj, "Number of jets (partons) at LHE step", FlatTable::UInt8Column); + out.addColumnValue("Nb", lheNb, "Number of b partons at LHE step", FlatTable::UInt8Column); + out.addColumnValue("Nc", lheNc, "Number of c partons at LHE step", FlatTable::UInt8Column); + out.addColumnValue("Nuds", lheNuds, "Number of u,d,s partons at LHE step", FlatTable::UInt8Column); + out.addColumnValue("Nglu", lheNglu, "Number of gluon partons at LHE step", FlatTable::UInt8Column); + out.addColumnValue("HT", lheHT, "HT, scalar sum of parton pTs at LHE step", FlatTable::FloatColumn); + out.addColumnValue("HTIncoming", lheHTIncoming, "HT, scalar sum of parton pTs at LHE step, restricted to partons", FlatTable::FloatColumn); + out.addColumnValue("Vpt", lheVpt, "pT of the W or Z boson at LHE step", FlatTable::FloatColumn); + } + + static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { + edm::ParameterSetDescription desc; + desc.add("lheInfo", edm::InputTag("externalLHEProducer"))->setComment("tag for the LHE information (LHEEventProduct)"); + descriptions.add("lheInfoTable", desc); + } + + protected: + const edm::EDGetTokenT lheTag_; +}; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(LHETablesProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc b/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc new file mode 100644 index 0000000000000..681ded875fc04 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc @@ -0,0 +1,210 @@ +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: LeptonJetVarProducer +// +/**\class LeptonJetVarProducer LeptonJetVarProducer.cc PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Marco Peruzzi +// Created: Tue, 05 Sep 2017 12:24:38 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/global/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/PatCandidates/interface/Jet.h" +#include "DataFormats/PatCandidates/interface/Electron.h" +#include "DataFormats/VertexReco/interface/Vertex.h" + +#include "TLorentzVector.h" +#include "DataFormats/Common/interface/View.h" + +#include "PhysicsTools/NanoAOD/interface/MatchingUtils.h" + +// +// class declaration +// + +template +class LeptonJetVarProducer : public edm::global::EDProducer<> { + public: + explicit LeptonJetVarProducer(const edm::ParameterSet &iConfig): + srcJet_(consumes>(iConfig.getParameter("srcJet"))), + srcLep_(consumes>(iConfig.getParameter("srcLep"))), + srcVtx_(consumes>(iConfig.getParameter("srcVtx"))) + { + produces>("ptRatio"); + produces>("ptRel"); + produces>("jetNDauChargedMVASel"); + produces>("jetForLepJetVar"); + } + ~LeptonJetVarProducer() {}; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + + std::tuple calculatePtRatioRel(auto &lep, auto &jet, auto &vtx) const; + + // ----------member data --------------------------- + + edm::EDGetTokenT> srcJet_; + edm::EDGetTokenT> srcLep_; + edm::EDGetTokenT> srcVtx_; +}; + +// +// constants, enums and typedefs +// + + +// +// static data member definitions +// + +// +// member functions +// + +// ------------ method called to produce the data ------------ +template +void +LeptonJetVarProducer::produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const +{ + + edm::Handle> srcJet; + iEvent.getByToken(srcJet_, srcJet); + edm::Handle> srcLep; + iEvent.getByToken(srcLep_, srcLep); + edm::Handle> srcVtx; + iEvent.getByToken(srcVtx_, srcVtx); + + unsigned nJet = srcJet->size(); + unsigned nLep = srcLep->size(); + + std::vector ptRatio(nLep,-1); + std::vector ptRel(nLep,-1); + std::vector jetNDauChargedMVASel(nLep,0); + std::vector jetForLepJetVar(nLep,reco::CandidatePtr()); + + const auto & pv = (*srcVtx)[0]; + + for (uint il = 0; ilptrAt(il); + auto jet = srcJet->ptrAt(ij); + if(matchByCommonSourceCandidatePtr(*lep,*jet)){ + auto res = calculatePtRatioRel(lep,jet,pv); + ptRatio[il] = std::get<0>(res); + ptRel[il] = std::get<1>(res); + jetNDauChargedMVASel[il] = std::get<2>(res); + jetForLepJetVar[il] = jet; + break; // take leading jet with shared source candidates + } + } + } + + std::unique_ptr> ptRatioV(new edm::ValueMap()); + edm::ValueMap::Filler fillerRatio(*ptRatioV); + fillerRatio.insert(srcLep,ptRatio.begin(),ptRatio.end()); + fillerRatio.fill(); + iEvent.put(std::move(ptRatioV),"ptRatio"); + + std::unique_ptr> ptRelV(new edm::ValueMap()); + edm::ValueMap::Filler fillerRel(*ptRelV); + fillerRel.insert(srcLep,ptRel.begin(),ptRel.end()); + fillerRel.fill(); + iEvent.put(std::move(ptRelV),"ptRel"); + + std::unique_ptr> jetNDauChargedMVASelV(new edm::ValueMap()); + edm::ValueMap::Filler fillerNDau(*jetNDauChargedMVASelV); + fillerNDau.insert(srcLep,jetNDauChargedMVASel.begin(),jetNDauChargedMVASel.end()); + fillerNDau.fill(); + iEvent.put(std::move(jetNDauChargedMVASelV),"jetNDauChargedMVASel"); + + std::unique_ptr> jetForLepJetVarV(new edm::ValueMap()); + edm::ValueMap::Filler fillerjetForLepJetVar(*jetForLepJetVarV); + fillerjetForLepJetVar.insert(srcLep,jetForLepJetVar.begin(),jetForLepJetVar.end()); + fillerjetForLepJetVar.fill(); + iEvent.put(std::move(jetForLepJetVarV),"jetForLepJetVar"); + + +} + +template +std::tuple +LeptonJetVarProducer::calculatePtRatioRel(auto &lep, auto &jet, auto &vtx) const { + + auto rawp4_ = jet->correctedP4("Uncorrected"); + auto rawp4 = TLorentzVector(rawp4_.pt(),rawp4_.eta(),rawp4_.phi(),rawp4_.energy()); + auto lepp4 = TLorentzVector(lep->pt(),lep->eta(),lep->phi(),lep->energy()); + + if ((rawp4-lepp4).Rho()<1e-4) return std::tuple(1.0,0.0,0.0); + + auto jetp4 = (rawp4 - lepp4*(1.0/jet->jecFactor("L1FastJet")))*(jet->pt()/rawp4.Pt())+lepp4; + auto ptratio = lepp4.Pt()/jetp4.Pt(); + auto ptrel = lepp4.Perp((jetp4-lepp4).Vect()); + + unsigned jndau = 0; + for(const auto _d : jet->daughterPtrVector()) { + const auto d = dynamic_cast(_d.get()); + if (d->charge()==0) continue; + if (d->fromPV()<=1) continue; + if (deltaR(*d,*lep)>0.4) continue; + if (!(d->hasTrackDetails())) continue; + auto tk = d->pseudoTrack(); + if(tk.pt()>1 && + tk.hitPattern().numberOfValidHits()>=8 && + tk.hitPattern().numberOfValidPixelHits()>=2 && + tk.normalizedChi2()<5 && + fabs(tk.dxy(vtx.position()))<0.2 && + fabs(tk.dz(vtx.position()))<17 + ) jndau++; + } + + return std::tuple(ptratio,ptrel,float(jndau)); +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +template +void +LeptonJetVarProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.add("srcJet")->setComment("jet input collection"); + desc.add("srcLep")->setComment("lepton input collection"); + desc.add("srcVtx")->setComment("primary vertex input collection"); + std::string modname; + if (typeid(T) == typeid(pat::Muon)) modname+="Muon"; + else if (typeid(T) == typeid(pat::Electron)) modname+="Electron"; + modname+="JetVarProducer"; + descriptions.add(modname,desc); +} + +typedef LeptonJetVarProducer MuonJetVarProducer; +typedef LeptonJetVarProducer ElectronJetVarProducer; + +//define this as a plug-in +DEFINE_FWK_MODULE(MuonJetVarProducer); +DEFINE_FWK_MODULE(ElectronJetVarProducer); diff --git a/PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc b/PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc new file mode 100644 index 0000000000000..9df1c4f08fee0 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc @@ -0,0 +1,89 @@ +#include "FWCore/Framework/interface/global/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 "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/Common/interface/View.h" + +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/PatCandidates/interface/Electron.h" + +namespace pat { + + + template + class LeptonUpdater : public edm::global::EDProducer<> { + + public: + + explicit LeptonUpdater(const edm::ParameterSet & iConfig) : + src_(consumes>(iConfig.getParameter("src"))), + vertices_(consumes>(iConfig.getParameter("vertices"))) + { + produces>(); + } + + ~LeptonUpdater() {} + + void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const ; + + static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { + edm::ParameterSetDescription desc; + desc.add("src")->setComment("Lepton collection"); + desc.add("vertices")->setComment("Vertex collection"); + if (typeid(T) == typeid(pat::Muon)) descriptions.add("muonsUpdated", desc); + else if (typeid(T) == typeid(pat::Electron)) descriptions.add("electronsUpdated", desc); + } + + void setDZ(T & lep, const reco::Vertex & pv) const {} + + private: + // configurables + edm::EDGetTokenT> src_; + edm::EDGetTokenT> vertices_; + }; + + // must do the specialization within the namespace otherwise gcc complains + // + template<> + void LeptonUpdater::setDZ(pat::Electron & anElectron, const reco::Vertex & pv) const { + auto track = anElectron.gsfTrack(); + anElectron.setDB( track->dz(pv.position()), std::hypot(track->dzError(), pv.zError()), pat::Electron::PVDZ ); + } + + template<> + void LeptonUpdater::setDZ(pat::Muon & aMuon, const reco::Vertex & pv) const { + auto track = aMuon.muonBestTrack(); + aMuon.setDB( track->dz(pv.position()), std::hypot(track->dzError(), pv.zError()), pat::Muon::PVDZ ); + } + +} // namespace + +template +void pat::LeptonUpdater::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const { + edm::Handle> src; + iEvent.getByToken(src_, src); + + edm::Handle> vertices; + iEvent.getByToken(vertices_, vertices); + const reco::Vertex & pv = vertices->front(); + + std::unique_ptr> out(new std::vector(*src)); + + for (unsigned int i = 0, n = src->size(); i < n; ++i) { + T & lep = (*out)[i]; + setDZ(lep, pv); + } + + iEvent.put(std::move(out)); +} + + + +typedef pat::LeptonUpdater PATElectronUpdater; +typedef pat::LeptonUpdater PATMuonUpdater; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(PATElectronUpdater); +DEFINE_FWK_MODULE(PATMuonUpdater); diff --git a/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc b/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc new file mode 100644 index 0000000000000..709296cc97314 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc @@ -0,0 +1,116 @@ +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/global/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/PatCandidates/interface/Muon.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/MuonReco/interface/MuonSelectors.h" +#include "PhysicsTools/NanoAOD/interface/FlatTable.h" + + +class MuonIDTableProducer : public edm::global::EDProducer<> { + public: + explicit MuonIDTableProducer(const edm::ParameterSet &iConfig) : + name_(iConfig.getParameter("name")), + src_(consumes>(iConfig.getParameter("muons"))), + srcVtx_(consumes>(iConfig.getParameter("vertices"))) + { + produces(); + } + + ~MuonIDTableProducer() {}; + + static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { + edm::ParameterSetDescription desc; + desc.add("muons")->setComment("input muon collection"); + desc.add("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"))->setComment("input vertex collection, for dxy/dz"); + desc.add("name")->setComment("name of the muon FlatTable we are extending with IDs"); + descriptions.add("muonIDTable", desc); + } + + private: + void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override ; + + std::string name_; + edm::EDGetTokenT> src_; + edm::EDGetTokenT> srcVtx_; + + static bool isMediumMuonHIP(const pat::Muon& muon) ; + static bool isSoftMuonHIP(const pat::Muon& muon, const reco::Vertex& vtx) ; + static bool isTrackerHighPt(const pat::Muon & mu, const reco::Vertex & primaryVertex) ; +}; + +// ------------ method called to produce the data ------------ +void +MuonIDTableProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const +{ + + edm::Handle> muons; + iEvent.getByToken(src_, muons); + edm::Handle> vertices; + iEvent.getByToken(srcVtx_, vertices); + + unsigned int ncand = muons->size(); + + const reco::Vertex & pv = vertices->front(); // consistent with IP information in slimmedLeptons. + + bool isRun2016BCDEF = (272007 <= iEvent.run() && iEvent.run() <= 278808); + std::vector tight(ncand, 0), highPt(ncand, 0), soft(ncand, 0), medium(ncand, 0); + for (unsigned int i = 0; i < ncand; ++i) { + 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); + medium[i] = isRun2016BCDEF ? isMediumMuonHIP(mu) : muon::isMediumMuon(mu); + } + + auto tab = std::make_unique(ncand, name_, false, true); + tab->addColumn("tightId", tight, "POG Tight muon ID", FlatTable::BoolColumn); + tab->addColumn("highPtId", highPt, "POG highPt muon ID (1 = tracker high pT, 2 = global high pT, which includes tracker high pT)", FlatTable::UInt8Column); + tab->addColumn("softId", soft, "POG Soft muon ID (using the relaxed cuts in the data Run 2016 B-F periods, and standard cuts elsewhere)", FlatTable::BoolColumn); + tab->addColumn("mediumId", medium, "POG Medium muon ID (using the relaxed cuts in the data Run 2016 B-F periods, and standard cuts elsewhere)", FlatTable::BoolColumn); + + iEvent.put(std::move(tab)); +} + +bool MuonIDTableProducer::isMediumMuonHIP(const pat::Muon& mu) { + bool goodGlob = mu.isGlobalMuon() && + mu.globalTrack()->normalizedChi2() < 3 && + mu.combinedQuality().chi2LocalPosition < 12 && + mu.combinedQuality().trkKink < 20; + bool isMedium = muon::isLooseMuon(mu) && + mu.innerTrack()->validFraction() > 0.49 && + muon::segmentCompatibility(mu) > (goodGlob ? 0.303 : 0.451); + return isMedium; +} + +bool MuonIDTableProducer::isSoftMuonHIP(const pat::Muon& mu, const reco::Vertex& vtx) { + 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.; +} + +bool MuonIDTableProducer::isTrackerHighPt(const pat::Muon & mu, const reco::Vertex & primaryVertex) { + return ( mu.numberOfMatchedStations() > 1 + && (mu.muonBestTrack()->ptError()/mu.muonBestTrack()->pt()) < 0.3 + && std::abs(mu.muonBestTrack()->dxy(primaryVertex.position())) < 0.2 + && std::abs(mu.muonBestTrack()->dz(primaryVertex.position())) < 0.5 + && mu.innerTrack()->hitPattern().numberOfValidPixelHits() > 0 + && mu.innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5 ); +} + +#include "FWCore/Framework/interface/MakerMacros.h" +//define this as a plug-in +DEFINE_FWK_MODULE(MuonIDTableProducer); diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc b/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc new file mode 100644 index 0000000000000..b1ce12973e1d2 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc @@ -0,0 +1,144 @@ +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: NanoAODBaseCrossCleaner +// +/**\class NanoAODBaseCrossCleaner NanoAODBaseCrossCleaner.cc PhysicsTools/NanoAODBaseCrossCleaner/plugins/NanoAODBaseCrossCleaner.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Andrea Rizzi +// Created: Mon, 28 Aug 2017 09:26:39 GMT +// +// + +#include "PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h" +#include "PhysicsTools/NanoAOD/interface/FlatTable.h" + +// +// constructors and destructor +// +NanoAODBaseCrossCleaner::NanoAODBaseCrossCleaner(const edm::ParameterSet& params): + name_(params.getParameter("name") ), + doc_(params.getParameter("doc") ), + jets_(consumes>( params.getParameter("jets") )), + muons_(consumes>( params.getParameter("muons") )), + electrons_(consumes>( params.getParameter("electrons") )), + taus_(consumes>( params.getParameter("taus") )), + photons_(consumes>( params.getParameter("photons") )), + jetSel_(params.getParameter("jetSel") ), + muonSel_(params.getParameter("muonSel") ), + electronSel_(params.getParameter("electronSel") ), + tauSel_(params.getParameter("tauSel") ), + photonSel_(params.getParameter("photonSel") ), + jetName_(params.getParameter("jetName") ), + muonName_(params.getParameter("muonName") ), + electronName_(params.getParameter("electronName") ), + tauName_(params.getParameter("tauName") ), + photonName_(params.getParameter("photonName") ) + +{ + produces("jets"); + produces("muons"); + produces("electrons"); + produces("taus"); + produces("photons"); + +} + + +NanoAODBaseCrossCleaner::~NanoAODBaseCrossCleaner() +{ + + // do anything here that needs to be done at destruction time + // (e.g. close files, deallocate resources etc.) + +} + + +// +// member functions +// + +// ------------ method called to produce the data ------------ + + +void +NanoAODBaseCrossCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + edm::Handle> jetsIn; + iEvent.getByToken(jets_, jetsIn); + std::vector jets; + for (const auto & j: *jetsIn) {jets.push_back(jetSel_(j));} + auto jetsTable = std::make_unique(jetsIn->size(),jetName_,false,true); + + edm::Handle> muonsIn; + iEvent.getByToken(muons_, muonsIn); + std::vector muons; + for (const auto & m: *muonsIn) {muons.push_back(muonSel_(m));} + auto muonsTable = std::make_unique(muonsIn->size(),muonName_,false,true); + + + edm::Handle> electronsIn; + iEvent.getByToken(electrons_, electronsIn); + std::vector eles; + for (const auto & e: *electronsIn) {eles.push_back(electronSel_(e));} + auto electronsTable = std::make_unique(electronsIn->size(),electronName_,false,true); + + edm::Handle> tausIn; + iEvent.getByToken(taus_, tausIn); + std::vector taus; + for (const auto & t: *tausIn) {taus.push_back(tauSel_(t));} + auto tausTable = std::make_unique(tausIn->size(),tauName_,false,true); + + edm::Handle> photonsIn; + iEvent.getByToken(photons_, photonsIn); + std::vector photons; + for (const auto & p: *photonsIn) {photons.push_back(photonSel_(p));} + auto photonsTable = std::make_unique(photonsIn->size(),photonName_,false,true); + + + objectSelection(*jetsIn,*muonsIn,*electronsIn,*tausIn,*photonsIn,jets,muons,eles,taus,photons); + + muonsTable->addColumn(name_,muons,doc_,FlatTable::UInt8Column); + jetsTable->addColumn(name_,jets,doc_,FlatTable::UInt8Column); + electronsTable->addColumn(name_,eles,doc_,FlatTable::UInt8Column); + tausTable->addColumn(name_,taus,doc_,FlatTable::UInt8Column); + photonsTable->addColumn(name_,photons,doc_,FlatTable::UInt8Column); + + iEvent.put(std::move(jetsTable),"jets"); + iEvent.put(std::move(muonsTable),"muons"); + iEvent.put(std::move(electronsTable),"electrons"); + iEvent.put(std::move(tausTable),"taus"); + iEvent.put(std::move(photonsTable),"photons"); + +} + +// ------------ method called once each stream before processing any runs, lumis or events ------------ +void +NanoAODBaseCrossCleaner::beginStream(edm::StreamID) +{ +} + +// ------------ method called once each stream after processing all runs, lumis and events ------------ +void +NanoAODBaseCrossCleaner::endStream() { +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +NanoAODBaseCrossCleaner::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(NanoAODBaseCrossCleaner); diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h b/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h new file mode 100644 index 0000000000000..3c8d697b1e407 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h @@ -0,0 +1,93 @@ +#ifndef PhysicsTools_NanoAOD_NanoAODBaseCrossCleaner_h +#define PhysicsTools_NanoAOD_NanoAODBaseCrossCleaner_h + +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: NanoAODBaseCrossCleaner +// +/**\class NanoAODBaseCrossCleaner NanoAODBaseCrossCleaner.cc PhysicsTools/NanoAODBaseCrossCleaner/plugins/NanoAODBaseCrossCleaner.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Andrea Rizzi +// Created: Mon, 28 Aug 2017 09:26:39 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/PatCandidates/interface/Jet.h" +#include "DataFormats/PatCandidates/interface/Electron.h" +#include "DataFormats/PatCandidates/interface/Photon.h" +#include "DataFormats/PatCandidates/interface/Tau.h" + +#include "DataFormats/Common/interface/View.h" +#include "CommonTools/Utils/interface/StringCutObjectSelector.h" + +// +// class declaration +// + +class NanoAODBaseCrossCleaner : public edm::stream::EDProducer<> { + public: + explicit NanoAODBaseCrossCleaner(const edm::ParameterSet&); + ~NanoAODBaseCrossCleaner(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + virtual void beginStream(edm::StreamID) override; + virtual void produce(edm::Event&, const edm::EventSetup&) override; + virtual void endStream() override; + virtual void objectSelection( const edm::View & jets, const edm::View & muons, const edm::View & eles, + const edm::View & taus, const edm::View & photons, + std::vector & jetBits, std::vector & muonBits, std::vector & eleBits, + std::vector & tauBits, std::vector & photonBits) {}; + + //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + + // ----------member data --------------------------- + const std::string name_; + const std::string doc_; + + const edm::EDGetTokenT> jets_; + const edm::EDGetTokenT> muons_; + const edm::EDGetTokenT> electrons_; + const edm::EDGetTokenT> taus_; + const edm::EDGetTokenT> photons_; + const StringCutObjectSelector jetSel_; + const StringCutObjectSelector muonSel_; + const StringCutObjectSelector electronSel_; + const StringCutObjectSelector tauSel_; + const StringCutObjectSelector photonSel_; + const std::string jetName_; + const std::string muonName_; + const std::string electronName_; + const std::string tauName_; + const std::string photonName_; + + +}; + +#endif diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc new file mode 100644 index 0000000000000..9c3f8a9ecb5a3 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc @@ -0,0 +1,339 @@ +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAODOutput +// Class : NanoAODOutputModule +// +// Implementation: +// [Notes on implementation] +// +// Original Author: Christopher Jones +// Created: Mon, 07 Aug 2017 14:21:41 GMT +// + +// system include files +#include +#include "TFile.h" +#include "TTree.h" +#include "TROOT.h" +#include "TObjString.h" +#include "Compression.h" + +// user include files +#include "FWCore/Framework/interface/OutputModule.h" +#include "FWCore/Framework/interface/one/OutputModule.h" +#include "FWCore/Framework/interface/RunForOutput.h" +#include "FWCore/Framework/interface/LuminosityBlockForOutput.h" +#include "FWCore/Framework/interface/EventForOutput.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/MessageLogger/interface/JobReport.h" +#include "FWCore/Utilities/interface/GlobalIdentifier.h" +#include "FWCore/Utilities/interface/Digest.h" +#include "IOPool/Provenance/interface/CommonProvenanceFiller.h" +#include "DataFormats/Provenance/interface/BranchType.h" +#include "DataFormats/Provenance/interface/BranchDescription.h" +#include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h" +#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "PhysicsTools/NanoAOD/interface/UniqueString.h" +#include "PhysicsTools/NanoAOD/plugins/TableOutputBranches.h" +#include "PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.h" +#include "PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h" + +#include + +class NanoAODOutputModule : public edm::one::OutputModule<> { +public: + NanoAODOutputModule(edm::ParameterSet const& pset); + virtual ~NanoAODOutputModule(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + virtual void write(edm::EventForOutput const& e) override; + virtual void writeLuminosityBlock(edm::LuminosityBlockForOutput const&) override; + virtual void writeRun(edm::RunForOutput const&) override; + virtual bool isFileOpen() const override; + virtual void openFile(edm::FileBlock const&) override; + virtual void reallyCloseFile() override; + + std::string m_fileName; + std::string m_logicalFileName; + int m_compressionLevel; + std::string m_compressionAlgorithm; + bool m_writeProvenance; + bool m_fakeName; //crab workaround, remove after crab is fixed + edm::ProcessHistoryRegistry m_processHistoryRegistry; + edm::JobReport::Token m_jrToken; + std::unique_ptr m_file; + std::unique_ptr m_tree, m_lumiTree, m_runTree, m_metaDataTree, m_parameterSetsTree; + + class CommonEventBranches { + public: + void branch(TTree &tree) { + tree.Branch("run", & m_run, "run/i"); + tree.Branch("luminosityBlock", & m_luminosityBlock, "luminosityBlock/i"); + tree.Branch("event", & m_event, "event/l"); + } + void fill(const edm::EventID & id) { + m_run = id.run(); m_luminosityBlock = id.luminosityBlock(); m_event = id.event(); + } + private: + UInt_t m_run; UInt_t m_luminosityBlock; ULong64_t m_event; + } m_commonBranches; + + class CommonLumiBranches { + public: + void branch(TTree &tree) { + tree.Branch("run", & m_run, "run/i"); + tree.Branch("luminosityBlock", & m_luminosityBlock, "luminosityBlock/i"); + } + void fill(const edm::LuminosityBlockID & id) { + m_run = id.run(); + m_luminosityBlock = id.value(); + } + private: + UInt_t m_run; UInt_t m_luminosityBlock; + } m_commonLumiBranches; + + class CommonRunBranches { + public: + void branch(TTree &tree) { + tree.Branch("run", & m_run, "run/i"); + } + void fill(const edm::RunID & id) { + m_run = id.run(); + } + private: + UInt_t m_run; + } m_commonRunBranches; + + + std::vector m_tables; + std::vector m_triggers; + + std::vector m_runTables; + + std::vector> m_nanoMetadata; + +}; + + +// +// constants, enums and typedefs +// + +// +// static data member definitions +// + +// +// constructors and destructor +// +NanoAODOutputModule::NanoAODOutputModule(edm::ParameterSet const& pset): + edm::one::OutputModuleBase::OutputModuleBase(pset), + edm::one::OutputModule<>(pset), + m_fileName(pset.getUntrackedParameter("fileName")), + m_logicalFileName(pset.getUntrackedParameter("logicalFileName")), + m_compressionLevel(pset.getUntrackedParameter("compressionLevel")), + m_compressionAlgorithm(pset.getUntrackedParameter("compressionAlgorithm")), + m_writeProvenance(pset.getUntrackedParameter("saveProvenance", true)), + m_fakeName(pset.getUntrackedParameter("fakeNameForCrab", false)), + m_processHistoryRegistry() +{ +} + +NanoAODOutputModule::~NanoAODOutputModule() +{ +} + +void +NanoAODOutputModule::write(edm::EventForOutput const& iEvent) { + //Get data from 'e' and write it to the file + edm::Service jr; + jr->eventWrittenToFile(m_jrToken, iEvent.id().run(), iEvent.id().event()); + + m_commonBranches.fill(iEvent.id()); + // fill all tables, starting from main tables and then doing extension tables + for (unsigned int extensions = 0; extensions <= 1; ++extensions) { + for (auto & t : m_tables) t.fill(iEvent,*m_tree,extensions); + } + // fill triggers + for (auto & t : m_triggers) t.fill(iEvent,*m_tree); + m_tree->Fill(); + + m_processHistoryRegistry.registerProcessHistory(iEvent.processHistory()); +} + +void +NanoAODOutputModule::writeLuminosityBlock(edm::LuminosityBlockForOutput const& iLumi) { + edm::Service jr; + jr->reportLumiSection(m_jrToken, iLumi.id().run(), iLumi.id().value()); + + m_commonLumiBranches.fill(iLumi.id()); + m_lumiTree->Fill(); + + m_processHistoryRegistry.registerProcessHistory(iLumi.processHistory()); +} + +void +NanoAODOutputModule::writeRun(edm::RunForOutput const& iRun) { + edm::Service jr; + jr->reportRunNumber(m_jrToken, iRun.id().run()); + + m_commonRunBranches.fill(iRun.id()); + + for (auto & t : m_runTables) t.fill(iRun,*m_runTree); + + edm::Handle hstring; + for (const auto & p : m_nanoMetadata) { + iRun.getByToken(p.second, hstring); + TObjString *tos = dynamic_cast(m_file->Get(p.first.c_str())); + if (tos) { + if (hstring->str() != tos->GetString()) throw cms::Exception("LogicError", "Inconsistent nanoMetadata " + p.first + " (" + hstring->str() +")"); + } else { + auto ostr = std::make_unique(hstring->str().c_str()); + m_file->WriteTObject(ostr.release(), p.first.c_str()); + } + } + + m_runTree->Fill(); + + m_processHistoryRegistry.registerProcessHistory(iRun.processHistory()); +} + +bool +NanoAODOutputModule::isFileOpen() const { + return nullptr != m_file.get(); +} + +void +NanoAODOutputModule::openFile(edm::FileBlock const&) { + m_file = std::make_unique(m_fileName.c_str(),"RECREATE","",m_compressionLevel); + edm::Service jr; + cms::Digest branchHash; + m_jrToken = jr->outputFileOpened(m_fileName, + m_logicalFileName, + std::string(), + m_fakeName?"PoolOutputModule":"NanoAODOutputModule", + description().moduleLabel(), + edm::createGlobalIdentifier(), + std::string(), + branchHash.digest().toString(), + std::vector() + ); + + if (m_compressionAlgorithm == std::string("ZLIB")) { + m_file->SetCompressionAlgorithm(ROOT::kZLIB); + } else if (m_compressionAlgorithm == std::string("LZMA")) { + m_file->SetCompressionAlgorithm(ROOT::kLZMA); + } else { + throw cms::Exception("Configuration") << "NanoAODOutputModule configured with unknown compression algorithm '" << m_compressionAlgorithm << "'\n" + << "Allowed compression algorithms are ZLIB and LZMA\n"; + } + /* Setup file structure here */ + m_tables.clear(); + m_triggers.clear(); + m_runTables.clear(); + const auto & keeps = keptProducts(); + for (const auto & keep : keeps[edm::InEvent]) { + if(keep.first->className() == "FlatTable" ) + m_tables.emplace_back(keep.first, keep.second); + else if(keep.first->className() == "edm::TriggerResults" ) + { + m_triggers.emplace_back(keep.first, keep.second); + } + else throw cms::Exception("Configuration", "NanoAODOutputModule cannot handle class " + keep.first->className()); + } + + for (const auto & keep : keeps[edm::InRun]) { + if(keep.first->className() == "MergableCounterTable" ) + m_runTables.push_back(SummaryTableOutputBranches(keep.first, keep.second)); + else if(keep.first->className() == "UniqueString" && keep.first->moduleLabel() == "nanoMetadata") + m_nanoMetadata.emplace_back(keep.first->productInstanceName(), keep.second); + else throw cms::Exception("Configuration", "NanoAODOutputModule cannot handle class " + keep.first->className() + " in Run branch"); + } + + + // create the trees + m_tree.reset(new TTree("Events","Events")); + m_tree->SetAutoSave(std::numeric_limits::max()); + m_commonBranches.branch(*m_tree); + + m_lumiTree.reset(new TTree("LuminosityBlocks","LuminosityBlocks")); + m_lumiTree->SetAutoSave(std::numeric_limits::max()); + m_commonLumiBranches.branch(*m_lumiTree); + + m_runTree.reset(new TTree("Runs","Runs")); + m_runTree->SetAutoSave(std::numeric_limits::max()); + m_commonRunBranches.branch(*m_runTree); + + if (m_writeProvenance) { + m_metaDataTree.reset(new TTree(edm::poolNames::metaDataTreeName().c_str(),"Job metadata")); + m_metaDataTree->SetAutoSave(std::numeric_limits::max()); + m_parameterSetsTree.reset(new TTree(edm::poolNames::parameterSetsTreeName().c_str(),"Parameter sets")); + m_parameterSetsTree->SetAutoSave(std::numeric_limits::max()); + } +} +void +NanoAODOutputModule::reallyCloseFile() { + if (m_writeProvenance) { + int basketSize = 16384; // fixme configurable? + edm::fillParameterSetBranch(m_parameterSetsTree.get(), basketSize); + edm::fillProcessHistoryBranch(m_metaDataTree.get(), basketSize, m_processHistoryRegistry); + if (m_metaDataTree->GetNbranches() != 0) { + m_metaDataTree->SetEntries(-1); + } + if (m_parameterSetsTree->GetNbranches() != 0) { + m_parameterSetsTree->SetEntries(-1); + } + } + m_file->Write(); + m_file->Close(); + m_file.reset(); + m_tree.release(); // apparently root has ownership + m_lumiTree.release(); // + m_runTree.release(); // + m_metaDataTree.release(); // + m_parameterSetsTree.release(); // + edm::Service jr; + jr->outputFileClosed(m_jrToken); +} + +void +NanoAODOutputModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + + desc.addUntracked("fileName"); + desc.addUntracked("logicalFileName",""); + + desc.addUntracked("compressionLevel", 9) + ->setComment("ROOT compression level of output file."); + desc.addUntracked("compressionAlgorithm", "ZLIB") + ->setComment("Algorithm used to compress data in the ROOT output file, allowed values are ZLIB and LZMA"); + desc.addUntracked("saveProvenance", true) + ->setComment("Save process provenance information, e.g. for edmProvDump"); + desc.addUntracked("fakeNameForCrab", false) + ->setComment("Change the OutputModule name in the fwk job report to fake PoolOutputModule. This is needed to run on cran (and publish) till crab is fixed"); + + //replace with whatever you want to get from the EDM by default + const std::vector keep = {"drop *", "keep FlatTable_*_*_*"}; + edm::OutputModule::fillDescription(desc, keep); + + //Used by Workflow management for their own meta data + edm::ParameterSetDescription dataSet; + dataSet.setAllowAnything(); + desc.addUntracked("dataset", dataSet) + ->setComment("PSet is only used by Data Operations and not by this module."); + + edm::ParameterSetDescription branchSet; + branchSet.setAllowAnything(); + desc.add("branches", branchSet); + + + + descriptions.addDefault(desc); + +} + +DEFINE_FWK_MODULE(NanoAODOutputModule); diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODSimpleCrossCleaner.cc b/PhysicsTools/NanoAOD/plugins/NanoAODSimpleCrossCleaner.cc new file mode 100644 index 0000000000000..c76dd5c6821fd --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/NanoAODSimpleCrossCleaner.cc @@ -0,0 +1,26 @@ +#include "PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h" + +class NanoAODSimpleCrossCleaner : public NanoAODBaseCrossCleaner { +public: + NanoAODSimpleCrossCleaner(const edm::ParameterSet&p):NanoAODBaseCrossCleaner(p){} + ~NanoAODSimpleCrossCleaner(){} + + virtual void objectSelection( const edm::View & jets, const edm::View & muons, const edm::View & eles, + const edm::View & taus, const edm::View & photons, + std::vector & jetBits, std::vector & muonBits, std::vector & eleBits, + std::vector & tauBits, std::vector & photonBits) override { + + for(size_t i=0;i + +template +class NativeArrayTableProducer : public edm::stream::EDProducer<> { + public: + + NativeArrayTableProducer( edm::ParameterSet const & params ) : + name_( params.getParameter("name") ), + doc_(params.existsAs("doc") ? params.getParameter("doc") : ""), + src_(consumes( params.getParameter("src") )) + { + produces(); + } + + virtual ~NativeArrayTableProducer() {} + + void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override { + edm::Handle src; + iEvent.getByToken(src_, src); + + const auto & in = *src; + auto out = std::make_unique(in.size(), name_, false, false); + out->setDoc(doc_); + (*out).template addColumn(this->name_, in, this->doc_, CT); + iEvent.put(std::move(out)); + } + + protected: + const std::string name_; + const std::string doc_; + const edm::EDGetTokenT src_; +}; + +typedef NativeArrayTableProducer,float,FlatTable::FloatColumn> FloatArrayTableProducer; +typedef NativeArrayTableProducer,float,FlatTable::FloatColumn> DoubleArrayTableProducer; +typedef NativeArrayTableProducer,int,FlatTable::IntColumn> IntArrayTableProducer; +typedef NativeArrayTableProducer,uint8_t,FlatTable::UInt8Column> BoolArrayTableProducer; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(FloatArrayTableProducer); +DEFINE_FWK_MODULE(DoubleArrayTableProducer); +DEFINE_FWK_MODULE(IntArrayTableProducer); +DEFINE_FWK_MODULE(BoolArrayTableProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc b/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc new file mode 100644 index 0000000000000..8b96b7608d898 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc @@ -0,0 +1,225 @@ +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: PATObjectCrossLinker +// +/**\class PATObjectCrossLinker PATObjectCrossLinker.cc PhysicsTools/PATObjectCrossLinker/plugins/PATObjectCrossLinker.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Andrea Rizzi +// Created: Mon, 28 Aug 2017 09:26:39 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/PatCandidates/interface/Jet.h" +#include "DataFormats/PatCandidates/interface/Electron.h" +#include "DataFormats/PatCandidates/interface/Photon.h" +#include "DataFormats/PatCandidates/interface/Tau.h" + +#include "DataFormats/Common/interface/View.h" + +#include "PhysicsTools/NanoAOD/interface/MatchingUtils.h" +// +// class declaration +// + +class PATObjectCrossLinker : public edm::stream::EDProducer<> { + public: + explicit PATObjectCrossLinker(const edm::ParameterSet&); + ~PATObjectCrossLinker(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + virtual void beginStream(edm::StreamID) override; + virtual void produce(edm::Event&, const edm::EventSetup&) override; + virtual void endStream() override; + + void matchOneToMany(const auto & refProdOne, auto & itemsOne, const std::string & nameOne, + const auto & refProdMany, auto& itemsMany, const std::string & nameMany); + + void matchElectronToPhoton(const auto & refProdOne, auto & itemsOne, const std::string & nameOne, + const auto & refProdMany, auto& itemsMany, const std::string & nameMany); + + //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + + // ----------member data --------------------------- + const edm::EDGetTokenT> jets_; + const edm::EDGetTokenT> muons_; + const edm::EDGetTokenT> electrons_; + const edm::EDGetTokenT> taus_; + const edm::EDGetTokenT> photons_; + + +}; + +// +// constructors and destructor +// +PATObjectCrossLinker::PATObjectCrossLinker(const edm::ParameterSet& params): + jets_(consumes>( params.getParameter("jets") )), + muons_(consumes>( params.getParameter("muons") )), + electrons_(consumes>( params.getParameter("electrons") )), + taus_(consumes>( params.getParameter("taus") )), + photons_(consumes>( params.getParameter("photons") )) + +{ + produces>("jets"); + produces>("muons"); + produces>("electrons"); + produces>("taus"); + produces>("photons"); + +} + + +PATObjectCrossLinker::~PATObjectCrossLinker() +{ + + // do anything here that needs to be done at destruction time + // (e.g. close files, deallocate resources etc.) + +} + + +// +// member functions +// + +// ------------ method called to produce the data ------------ + +/// +void PATObjectCrossLinker::matchOneToMany(const auto & refProdOne, auto & itemsOne, const std::string & nameOne, + const auto & refProdMany, auto& itemsMany, const std::string & nameMany) +{ + size_t ji=0; + for(auto & j: itemsOne) { + edm::PtrVector overlaps(refProdMany.id()); + size_t mi=0; + for(auto & m: itemsMany){ + if(matchByCommonSourceCandidatePtr(j,m) && (!m.hasUserCand(nameOne))){ + m.addUserCand(nameOne,reco::CandidatePtr(refProdOne.id(), ji, refProdOne.productGetter())); + overlaps.push_back(reco::CandidatePtr(refProdMany.id(), mi, refProdMany.productGetter())); + } + mi++; + } + j.setOverlaps(nameMany,overlaps); + ji++; + } +} + +void PATObjectCrossLinker::matchElectronToPhoton(const auto & refProdOne, auto & itemsOne, const std::string & nameOne, + const auto & refProdMany, auto& itemsMany, const std::string & nameMany) +{ + size_t ji=0; + for(auto & j: itemsOne) { + edm::PtrVector overlaps(refProdMany.id()); + size_t mi=0; + for(auto & m: itemsMany){ + if(matchByCommonParentSuperClusterRef(j,m) && (!m.hasUserCand(nameOne))){ + m.addUserCand(nameOne,reco::CandidatePtr(refProdOne.id(), ji, refProdOne.productGetter())); + overlaps.push_back(reco::CandidatePtr(refProdMany.id(), mi, refProdMany.productGetter())); + } + mi++; + } + j.setOverlaps(nameMany,overlaps); + ji++; + } +} + + +void +PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + edm::Handle> jetsIn; + iEvent.getByToken(jets_, jetsIn); + auto jets = std::make_unique>(); + for(const auto & j : *jetsIn) jets->push_back(j); + auto jetRefProd = iEvent.getRefBeforePut< std::vector >("jets"); + + edm::Handle> muonsIn; + iEvent.getByToken(muons_, muonsIn); + auto muons = std::make_unique>(); + for(const auto & m : *muonsIn) muons->push_back(m); + auto muRefProd = iEvent.getRefBeforePut< std::vector >("muons"); + + edm::Handle> electronsIn; + iEvent.getByToken(electrons_, electronsIn); + auto electrons = std::make_unique>(); + for(const auto & e : *electronsIn) electrons->push_back(e); + auto eleRefProd = iEvent.getRefBeforePut< std::vector >("electrons"); + + edm::Handle> tausIn; + iEvent.getByToken(taus_, tausIn); + auto taus = std::make_unique>(); + for(const auto & t : *tausIn) taus->push_back(t); + auto tauRefProd = iEvent.getRefBeforePut< std::vector >("taus"); + + edm::Handle> photonsIn; + iEvent.getByToken(photons_, photonsIn); + auto photons = std::make_unique>(); + for(const auto & p : *photonsIn) photons->push_back(p); + auto phRefProd = iEvent.getRefBeforePut< std::vector >("photons"); + + matchOneToMany(jetRefProd,*jets,"jet",muRefProd,*muons,"muons"); + matchOneToMany(jetRefProd,*jets,"jet",eleRefProd,*electrons,"electrons"); + matchOneToMany(jetRefProd,*jets,"jet",tauRefProd,*taus,"taus"); + matchOneToMany(jetRefProd,*jets,"jet",phRefProd,*photons,"photons"); + + matchElectronToPhoton(eleRefProd,*electrons,"electron",phRefProd,*photons,"photons"); + + iEvent.put(std::move(jets),"jets"); + iEvent.put(std::move(muons),"muons"); + iEvent.put(std::move(electrons),"electrons"); + iEvent.put(std::move(taus),"taus"); + iEvent.put(std::move(photons),"photons"); + +} + +// ------------ method called once each stream before processing any runs, lumis or events ------------ +void +PATObjectCrossLinker::beginStream(edm::StreamID) +{ +} + +// ------------ method called once each stream after processing all runs, lumis and events ------------ +void +PATObjectCrossLinker::endStream() { +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +PATObjectCrossLinker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(PATObjectCrossLinker); diff --git a/PhysicsTools/NanoAOD/plugins/PATObjectUserDataEmbedder.cc b/PhysicsTools/NanoAOD/plugins/PATObjectUserDataEmbedder.cc new file mode 100644 index 0000000000000..2cfdbaeffb54b --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/PATObjectUserDataEmbedder.cc @@ -0,0 +1,134 @@ +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/Common/interface/View.h" + +#include "DataFormats/PatCandidates/interface/UserData.h" +#include "PhysicsTools/PatAlgos/interface/PATUserDataMerger.h" + +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/PatCandidates/interface/Electron.h" +#include "DataFormats/PatCandidates/interface/Photon.h" +#include "DataFormats/PatCandidates/interface/Tau.h" +#include "DataFormats/PatCandidates/interface/Jet.h" + +namespace pat { + + namespace helper { + + struct AddUserIntFromBool { + typedef bool value_type; + typedef edm::ValueMap product_type; + template + void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserInt(key, val); } + }; + + template + class NamedUserDataLoader { + public: + NamedUserDataLoader(const edm::ParameterSet & iConfig, const std::string & main, edm::ConsumesCollector && cc) { + if (iConfig.existsAs(main)) { + edm::ParameterSet const & srcPSet = iConfig.getParameter(main); + for (const std::string & label : srcPSet.getParameterNamesForType()) { + labelsAndTokens_.emplace_back(label, cc.consumes(srcPSet.getParameter(label))); + } + } + } + template + void addData(const edm::Event &iEvent, const std::vector> & ptrs, std::vector & out) const { + A adder; + unsigned int n = ptrs.size(); + edm::Handle handle; + for (const auto & pair : labelsAndTokens_) { + iEvent.getByToken(pair.second, handle); + for (unsigned int i = 0; i < n; ++i) { + adder.addData(out[i], pair.first, (*handle)[ptrs[i]]); + } + } + } + private: + std::vector>> labelsAndTokens_; + }; // class NamedUserDataLoader + } // namespace helper + + template + class PATObjectUserDataEmbedder : public edm::stream::EDProducer<> { + + public: + + explicit PATObjectUserDataEmbedder(const edm::ParameterSet & iConfig) : + src_(consumes>(iConfig.getParameter("src"))), + userFloats_(iConfig, "userFloats", consumesCollector()), + userInts_(iConfig, "userInts", consumesCollector()), + userIntFromBools_(iConfig, "userIntFromBools", consumesCollector()), + userCands_(iConfig, "userCands", consumesCollector()) + { + produces>(); + } + + ~PATObjectUserDataEmbedder() {} + + virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override; + + static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { + edm::ParameterSetDescription desc; + desc.add("src"); + for (const std::string & what : { "userFloats", "userInts", "userIntFromBools", "userCands" }) { + edm::ParameterSetDescription descNested; + descNested.addWildcard("*"); + desc.add(what, descNested); + } + if (typeid(T) == typeid(pat::Muon)) descriptions.add("muonsWithUserData", desc); + else if (typeid(T) == typeid(pat::Electron)) descriptions.add("electronsWithUserData", desc); + else if (typeid(T) == typeid(pat::Photon)) descriptions.add("photonsWithUserData", desc); + else if (typeid(T) == typeid(pat::Tau)) descriptions.add("tausWithUserData", desc); + else if (typeid(T) == typeid(pat::Jet)) descriptions.add("jetsWithUserData", desc); + } + + private: + // configurables + edm::EDGetTokenT> src_; + helper::NamedUserDataLoader userFloats_; + helper::NamedUserDataLoader userInts_; + helper::NamedUserDataLoader userIntFromBools_; + helper::NamedUserDataLoader userCands_; + }; + +} + +template +void pat::PATObjectUserDataEmbedder::produce(edm::Event & iEvent, const edm::EventSetup& iSetup) { + edm::Handle> src; + iEvent.getByToken(src_, src); + + std::unique_ptr> out(new std::vector()); + out->reserve(src->size()); + + std::vector> ptrs; + ptrs.reserve(src->size()); + for (unsigned int i = 0, n = src->size(); i < n; ++i) { + // copy by value, save the ptr + out->push_back((*src)[i]); + ptrs.push_back(src->ptrAt(i)); + } + userFloats_.addData(iEvent, ptrs, *out); + userInts_.addData(iEvent, ptrs, *out); + userIntFromBools_.addData(iEvent, ptrs, *out); + userCands_.addData(iEvent, ptrs, *out); + + iEvent.put(std::move(out)); +} + +typedef pat::PATObjectUserDataEmbedder PATElectronUserDataEmbedder; +typedef pat::PATObjectUserDataEmbedder PATMuonUserDataEmbedder; +typedef pat::PATObjectUserDataEmbedder PATPhotonUserDataEmbedder; +typedef pat::PATObjectUserDataEmbedder PATTauUserDataEmbedder; +typedef pat::PATObjectUserDataEmbedder PATJetUserDataEmbedder; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(PATElectronUserDataEmbedder); +DEFINE_FWK_MODULE(PATMuonUserDataEmbedder); +DEFINE_FWK_MODULE(PATPhotonUserDataEmbedder); +DEFINE_FWK_MODULE(PATTauUserDataEmbedder); +DEFINE_FWK_MODULE(PATJetUserDataEmbedder); diff --git a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc new file mode 100644 index 0000000000000..adc5ccc3fda59 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc @@ -0,0 +1,213 @@ +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "DataFormats/Common/interface/View.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "PhysicsTools/NanoAOD/interface/FlatTable.h" + +#include "CommonTools/Utils/interface/StringCutObjectSelector.h" +#include "CommonTools/Utils/interface/StringObjectFunction.h" + +#include +#include + +template +class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> { + public: + + SimpleFlatTableProducerBase( edm::ParameterSet const & params ): + name_( params.getParameter("name") ), + doc_(params.existsAs("doc") ? params.getParameter("doc") : ""), + extension_(params.existsAs("extension") ? params.getParameter("extension") : false), + src_(consumes( params.getParameter("src") )) + { + edm::ParameterSet const & varsPSet = params.getParameter("variables"); + for (const std::string & vname : varsPSet.getParameterNamesForType()) { + const auto & varPSet = varsPSet.getParameter(vname); + const std::string & type = varPSet.getParameter("type"); + if (type == "int") vars_.push_back(new IntVar(vname, FlatTable::IntColumn, varPSet)); + else if (type == "float") vars_.push_back(new FloatVar(vname, FlatTable::FloatColumn, varPSet)); + else if (type == "uint8") vars_.push_back(new BoolVar(vname, FlatTable::UInt8Column, varPSet)); + else if (type == "bool") vars_.push_back(new BoolVar(vname, FlatTable::BoolColumn, varPSet)); + else throw cms::Exception("Configuration", "unsupported type "+type+" for variable "+vname); + } + + produces(); + } + + virtual ~SimpleFlatTableProducerBase() {} + + // this is to be overriden by the child class + virtual std::unique_ptr fillTable(const edm::Event &iEvent, const edm::Handle & prod) const = 0; + + + void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override { + edm::Handle src; + iEvent.getByToken(src_, src); + + std::unique_ptr out = fillTable(iEvent, src); + out->setDoc(doc_); + + iEvent.put(std::move(out)); + } + + protected: + const std::string name_; + const std::string doc_; + const bool extension_; + const edm::EDGetTokenT src_; + + class VariableBase { + public: + VariableBase(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : + name_(aname), doc_(cfg.getParameter("doc")), type_(atype), + precision_(cfg.existsAs("precision") ? cfg.getParameter("precision") : -1) + { + } + virtual ~VariableBase() {} + const std::string & name() const { return name_; } + const FlatTable::ColumnType & type() const { return type_; } + protected: + std::string name_, doc_; + FlatTable::ColumnType type_; + int precision_; + }; + class Variable : public VariableBase { + public: + Variable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : + VariableBase(aname, atype, cfg) {} + virtual void fill(std::vector selobjs, FlatTable & out) const = 0; + }; + template + class FuncVariable : public Variable { + public: + FuncVariable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : + Variable(aname, atype, cfg), func_(cfg.getParameter("expr"), true) {} + ~FuncVariable() {} + void fill(std::vector selobjs, FlatTable & out) const override { + std::vector vals(selobjs.size()); + for (unsigned int i = 0, n = vals.size(); i < n; ++i) { + vals[i] = func_(*selobjs[i]); + } + out.template addColumn(this->name_, vals, this->doc_, this->type_,this->precision_); + } + protected: + StringFunctor func_; + + }; + typedef FuncVariable,int> IntVar; + typedef FuncVariable,float> FloatVar; + typedef FuncVariable,uint8_t> BoolVar; + boost::ptr_vector vars_; +}; + +template +class SimpleFlatTableProducer : public SimpleFlatTableProducerBase> { + public: + typedef SimpleFlatTableProducerBase> base; + + SimpleFlatTableProducer( edm::ParameterSet const & params ) : + SimpleFlatTableProducerBase>(params), + singleton_(params.getParameter("singleton")), + maxLen_(params.existsAs("maxLen") ? params.getParameter("maxLen") : std::numeric_limits::max()), + cut_(!singleton_ ? params.getParameter("cut") : "", true) + { + if (params.existsAs("externalVariables")) { + edm::ParameterSet const & extvarsPSet = params.getParameter("externalVariables"); + for (const std::string & vname : extvarsPSet.getParameterNamesForType()) { + const auto & varPSet = extvarsPSet.getParameter(vname); + const std::string & type = varPSet.getParameter("type"); + if (type == "int") extvars_.push_back(new IntExtVar(vname, FlatTable::IntColumn, varPSet, this->consumesCollector())); + else if (type == "float") extvars_.push_back(new FloatExtVar(vname, FlatTable::FloatColumn, varPSet, this->consumesCollector())); + else if (type == "double") extvars_.push_back(new DoubleExtVar(vname, FlatTable::FloatColumn, varPSet, this->consumesCollector())); + else if (type == "uint8") extvars_.push_back(new UInt8ExtVar(vname, FlatTable::UInt8Column, varPSet, this->consumesCollector())); + else if (type == "bool") extvars_.push_back(new BoolExtVar(vname, FlatTable::BoolColumn, varPSet, this->consumesCollector())); + else throw cms::Exception("Configuration", "unsupported type "+type+" for variable "+vname); + } + } + } + + virtual ~SimpleFlatTableProducer() {} + + std::unique_ptr fillTable(const edm::Event &iEvent, const edm::Handle> & prod) const override { + std::vector selobjs; + std::vector> selptrs; // for external variables + if (singleton_) { + assert(prod->size() == 1); + selobjs.push_back(& (*prod)[0] ); + if (!extvars_.empty()) selptrs.emplace_back(prod->ptrAt(0)); + } else { + for (unsigned int i = 0, n = prod->size(); i < n; ++i) { + const auto & obj = (*prod)[i]; + if (cut_(obj)) { + selobjs.push_back(&obj); + if (!extvars_.empty()) selptrs.emplace_back(prod->ptrAt(i)); + } + if(selobjs.size()>=maxLen_) break; + } + } + auto out = std::make_unique(selobjs.size(), this->name_, singleton_, this->extension_); + for (const auto & var : this->vars_) var.fill(selobjs, *out); + for (const auto & var : this->extvars_) var.fill(iEvent, selptrs, *out); + return out; + } + + protected: + bool singleton_; + const unsigned int maxLen_; + const StringCutObjectSelector cut_; + + class ExtVariable : public base::VariableBase { + public: + ExtVariable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : + base::VariableBase(aname, atype, cfg) {} + virtual void fill(const edm::Event & iEvent, std::vector> selptrs, FlatTable & out) const = 0; + }; + template + class ValueMapVariable : public ExtVariable { + public: + ValueMapVariable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg, edm::ConsumesCollector && cc) : + ExtVariable(aname, atype, cfg), token_(cc.consumes>(cfg.getParameter("src"))) {} + virtual void fill(const edm::Event & iEvent, std::vector> selptrs, FlatTable & out) const override { + edm::Handle> vmap; + iEvent.getByToken(token_, vmap); + std::vector vals(selptrs.size()); + for (unsigned int i = 0, n = vals.size(); i < n; ++i) { + vals[i] = (*vmap)[selptrs[i]]; + } + out.template addColumn(this->name_, vals, this->doc_, this->type_, this->precision_); + } + protected: + edm::EDGetTokenT> token_; + }; + typedef ValueMapVariable IntExtVar; + typedef ValueMapVariable FloatExtVar; + typedef ValueMapVariable DoubleExtVar; + typedef ValueMapVariable BoolExtVar; + typedef ValueMapVariable UInt8ExtVar; + boost::ptr_vector extvars_; + +}; + +template +class EventSingletonSimpleFlatTableProducer : public SimpleFlatTableProducerBase { + public: + EventSingletonSimpleFlatTableProducer( edm::ParameterSet const & params ): + SimpleFlatTableProducerBase(params) {} + + virtual ~EventSingletonSimpleFlatTableProducer() {} + + std::unique_ptr fillTable(const edm::Event &, const edm::Handle & prod) const override { + auto out = std::make_unique(1, this->name_, true, this->extension_); + std::vector selobjs(1, prod->product()); + for (const auto & var : this->vars_) var.fill(selobjs, *out); + return out; + } +}; + +#include "DataFormats/Candidate/interface/Candidate.h" +typedef SimpleFlatTableProducer SimpleCandidateFlatTableProducer; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc new file mode 100644 index 0000000000000..356ac139823cd --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc @@ -0,0 +1,78 @@ +#include "PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h" + +template +void +SummaryTableOutputBranches::makeScalarBranches(const std::vector & tabcols, TTree & tree, const std::string & rootType, std::vector & branches ) { + for (const auto & col : tabcols) { + auto * br = tree.Branch(col.name.c_str(), (void*)nullptr, (col.name+"/"+rootType).c_str()); + br->SetTitle(col.doc.c_str()); + branches.emplace_back(col.name, br); + } +} + +template +void +SummaryTableOutputBranches::makeVectorBranches(const std::vector & tabcols, TTree & tree, const std::string & rootType, std::vector & branches ) { + for (const auto & col : tabcols) { + auto * cbr = tree.Branch(("n"+col.name).c_str(), (void*)nullptr, ("n"+col.name+"/i").c_str()); + auto * vbr = tree.Branch(col.name.c_str(), (void*)nullptr, (col.name+"[n"+col.name+"]/"+rootType).c_str()); + cbr->SetTitle(("Number of entries in "+col.name).c_str()); + vbr->SetTitle(col.doc.c_str()); + branches.emplace_back(col.name, cbr, vbr); + } +} + +template +void +SummaryTableOutputBranches::fillScalarBranches(const std::vector & tabcols, std::vector & branches ) { + if (tabcols.size() != branches.size()) throw cms::Exception("LogicError", "Mismatch in table columns"); + for (unsigned int i = 0, n = tabcols.size(); i < n; ++i) { + if (tabcols[i].name != branches[i].name) throw cms::Exception("LogicError", "Mismatch in table columns"); + branches[i].branch->SetAddress( const_cast(& tabcols[i].value) ); + } +} + +template +void +SummaryTableOutputBranches::fillVectorBranches(const std::vector & tabcols, std::vector & branches ) { + if (tabcols.size() != branches.size()) throw cms::Exception("LogicError", "Mismatch in table columns"); + for (unsigned int i = 0, n = tabcols.size(); i < n; ++i) { + if (tabcols[i].name != branches[i].name) throw cms::Exception("LogicError", "Mismatch in table columns"); + branches[i].count = tabcols[i].values.size(); + branches[i].branch->SetAddress( const_cast(& tabcols[i].values.front()) ); + } +} + + + +void +SummaryTableOutputBranches::defineBranchesFromFirstEvent(const MergableCounterTable & tab, TTree & tree) +{ + makeScalarBranches(tab.intCols(), tree, "L", m_intBranches); + makeScalarBranches(tab.floatCols(), tree, "D", m_floatBranches); + makeVectorBranches(tab.vintCols(), tree, "L", m_vintBranches); + makeVectorBranches(tab.vfloatCols(), tree, "D", m_vfloatBranches); + + // now we go set the pointers for the counter branches + for (auto & vbp : m_vintBranches) vbp.counterBranch->SetAddress( & vbp.count ); + for (auto & vbp : m_vfloatBranches) vbp.counterBranch->SetAddress( & vbp.count ); +} + + +void SummaryTableOutputBranches::fill(const edm::OccurrenceForOutput &iWhatever, TTree & tree) +{ + edm::Handle handle; + iWhatever.getByToken(m_token, handle); + const MergableCounterTable & tab = *handle; + + if(!m_branchesBooked) { + defineBranchesFromFirstEvent(tab, tree); + m_branchesBooked=true; + } + fillScalarBranches(tab.intCols(), m_intBranches); + fillScalarBranches(tab.floatCols(), m_floatBranches); + fillVectorBranches(tab.vintCols(), m_vintBranches); + fillVectorBranches(tab.vfloatCols(), m_vfloatBranches); +} + + diff --git a/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h new file mode 100644 index 0000000000000..f11c403b2c747 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h @@ -0,0 +1,53 @@ +#ifndef PhysicsTools_NanoAOD_SummaryTableOutputBranches_h +#define PhysicsTools_NanoAOD_SummaryTableOutputBranches_h + +#include +#include +#include +#include "FWCore/Framework/interface/OccurrenceForOutput.h" +#include "PhysicsTools/NanoAOD/interface/MergableCounterTable.h" +#include "DataFormats/Provenance/interface/BranchDescription.h" +#include "FWCore/Utilities/interface/EDGetToken.h" + +class SummaryTableOutputBranches { + public: + SummaryTableOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken & token ) : + m_token(token), m_branchesBooked(false) + { + if (desc->className() != "MergableCounterTable") throw cms::Exception("Configuration", "NanoAODOutputModule can only write out MergableCounterTable objects"); + } + + void fill(const edm::OccurrenceForOutput &iWhatever, TTree & tree) ; + + private: + edm::EDGetToken m_token; + + struct NamedBranchPtr { + std::string name; + TBranch * branch; + NamedBranchPtr(const std::string & aname, TBranch *branchptr = nullptr) : + name(aname), branch(branchptr) {} + }; + std::vector m_intBranches, m_floatBranches; + + struct NamedVectorBranchPtr : public NamedBranchPtr { + UInt_t count; + TBranch * counterBranch; + NamedVectorBranchPtr(const std::string & aname, TBranch *counterBranchptr = nullptr, TBranch *valueBranchptr = nullptr) : + NamedBranchPtr(aname,valueBranchptr), counterBranch(counterBranchptr) {} + }; + std::vector m_vintBranches, m_vfloatBranches; + + bool m_branchesBooked; + + void defineBranchesFromFirstEvent(const MergableCounterTable & tab, TTree & tree) ; + + template void makeScalarBranches(const std::vector & tabcols, TTree & tree, const std::string & rootType, std::vector & branches); + template void makeVectorBranches(const std::vector & tabcols, TTree & tree, const std::string & rootType, std::vector & branches ); + + template void fillScalarBranches(const std::vector & tabcols, std::vector & branches); + template void fillVectorBranches(const std::vector & tabcols, std::vector & branches ); +}; + +#endif + diff --git a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc new file mode 100644 index 0000000000000..690e101373839 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc @@ -0,0 +1,93 @@ +#include "PhysicsTools/NanoAOD/plugins/TableOutputBranches.h" + +#include + +namespace { + std::string makeBranchName(const std::string & baseName, const std::string & leafName) { + return baseName.empty() ? leafName : + ( leafName.empty() ? baseName : + baseName + "_" + leafName); + } +} + +void +TableOutputBranches::defineBranchesFromFirstEvent(const FlatTable & tab) +{ + m_baseName=tab.name(); + for(size_t i=0;iSetTitle(m_doc.c_str()); + } + } + std::string varsize = m_singleton ? "" : "[n" + m_baseName + "]"; + for ( std::vector * branches : { & m_floatBranches, & m_intBranches, & m_uint8Branches } ) { + for (auto & pair : *branches) { + std::string branchName = makeBranchName(m_baseName, pair.name); + pair.branch = tree.Branch(branchName.c_str(), (void*)nullptr, (branchName + varsize + "/" + pair.rootTypeCode).c_str()); + pair.branch->SetTitle(pair.title.c_str()); + } + } +} + +void TableOutputBranches::fill(const edm::EventForOutput &iEvent, TTree & tree, bool extensions) +{ + if (m_extension != DontKnowYetIfMainOrExtension) { + if (extensions != m_extension) return; // do nothing, wait to be called with the proper flag + } + + edm::Handle handle; + iEvent.getByToken(m_token, handle); + const FlatTable & tab = *handle; + m_counter = tab.size(); + m_singleton = tab.singleton(); + if(!m_branchesBooked) { + m_extension = tab.extension() ? IsExtension : IsMain; + if (extensions != m_extension) return; // do nothing, wait to be called with the proper flag + defineBranchesFromFirstEvent(tab); + m_doc = tab.doc(); + m_branchesBooked=true; + branch(tree); + } + if (!m_singleton && m_extension == IsExtension) { + if (m_counter != *reinterpret_cast(m_counterBranch->GetAddress())) { + throw cms::Exception("LogicError", "Mismatch in number of entries between extension and main table for " + tab.name()); + } + } + for (auto & pair : m_floatBranches) fillColumn(pair, tab); + for (auto & pair : m_intBranches) fillColumn(pair, tab); + for (auto & pair : m_uint8Branches) fillColumn(pair, tab); +} + + diff --git a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h new file mode 100644 index 0000000000000..b951a5b1f06a9 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h @@ -0,0 +1,56 @@ +#ifndef PhysicsTools_NanoAOD_TableOutputBranches_h +#define PhysicsTools_NanoAOD_TableOutputBranches_h + +#include +#include +#include +#include "FWCore/Framework/interface/EventForOutput.h" +#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/Provenance/interface/BranchDescription.h" +#include "FWCore/Utilities/interface/EDGetToken.h" + +class TableOutputBranches { + public: + TableOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken & token ) : + m_token(token), m_extension(DontKnowYetIfMainOrExtension), m_branchesBooked(false) + { + if (desc->className() != "FlatTable") throw cms::Exception("Configuration", "NanoAODOutputModule can only write out FlatTable objects"); + } + + void defineBranchesFromFirstEvent(const FlatTable & tab) ; + void branch(TTree &tree) ; + + /// Fill the current table, if extensions == table.extension(). + /// This parameter is used so that the fill is called first for non-extensions and then for extensions + void fill(const edm::EventForOutput &iEvent, TTree & tree, bool extensions) ; + + private: + edm::EDGetToken m_token; + std::string m_baseName; + bool m_singleton; + enum { IsMain=0, IsExtension=1, DontKnowYetIfMainOrExtension=2 } m_extension; + std::string m_doc; + UInt_t m_counter; + struct NamedBranchPtr { + std::string name, title, rootTypeCode; + TBranch * branch; + NamedBranchPtr(const std::string & aname, const std::string & atitle, const std::string & rootType, TBranch *branchptr = nullptr) : + name(aname), title(atitle), rootTypeCode(rootType), branch(branchptr) {} + }; + TBranch * m_counterBranch; + std::vector m_floatBranches; + std::vector m_intBranches; + std::vector m_uint8Branches; + bool m_branchesBooked; + + template + void fillColumn(NamedBranchPtr & pair, const FlatTable & tab) { + int idx = tab.columnIndex(pair.name); + if (idx == -1) throw cms::Exception("LogicError", "Missing column in input for "+m_baseName+"_"+pair.name); + pair.branch->SetAddress( const_cast(& tab.columnData(idx).front() ) ); // SetAddress should take a const * ! + } + +}; + +#endif + diff --git a/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc b/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc new file mode 100644 index 0000000000000..babc443673b8d --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc @@ -0,0 +1,152 @@ +// system include files +#include +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/global/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h" +#include "CommonTools/Utils/interface/StringCutObjectSelector.h" +#include "CommonTools/Utils/interface/StringObjectFunction.h" +#include "DataFormats/Math/interface/deltaR.h" +#include "PhysicsTools/NanoAOD/interface/FlatTable.h" + +class TriggerObjectTableProducer : public edm::global::EDProducer<> { + public: + explicit TriggerObjectTableProducer(const edm::ParameterSet &iConfig) : + name_(iConfig.getParameter("name")), + src_(consumes>(iConfig.getParameter("src"))) + { + std::vector selPSets = iConfig.getParameter>("selections"); + sels_.reserve(selPSets.size()); + std::stringstream idstr, qualitystr; + idstr << "ID of the object: "; + for (auto & pset : selPSets) { + sels_.emplace_back(pset); + idstr << sels_.back().id << " = " << sels_.back().name; + if (sels_.size() < selPSets.size()) idstr << ", "; + if (!sels_.back().qualityBitsDoc.empty()) { + qualitystr << sels_.back().qualityBitsDoc << " for " << sels_.back().name << "; "; + } + } + idDoc_ = idstr.str(); + bitsDoc_ = qualitystr.str(); + + produces(); + } + + ~TriggerObjectTableProducer() {} + + private: + void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override ; + + std::string name_; + edm::EDGetTokenT> src_; + std::string idDoc_, bitsDoc_; + + struct SelectedObject { + std::string name; + int id; + StringCutObjectSelector cut; + StringCutObjectSelector l1cut, l2cut; + float l1DR2, l2DR2; + StringObjectFunction qualityBits; + std::string qualityBitsDoc; + + SelectedObject(const edm::ParameterSet & pset) : + name(pset.getParameter("name")), + id(pset.getParameter("id")), + cut(pset.getParameter("sel")), + l1cut(""), l2cut(""), + l1DR2(-1), l2DR2(-1), + qualityBits(pset.getParameter("qualityBits")), + qualityBitsDoc(pset.getParameter("qualityBitsDoc")) + { + if (pset.existsAs("l1seed")) { + l1cut = StringCutObjectSelector(pset.getParameter("l1seed")); + l1DR2 = std::pow(pset.getParameter("l1deltaR"), 2); + } + if (pset.existsAs("l2seed")) { + l2cut = StringCutObjectSelector(pset.getParameter("l2seed")); + l2DR2 = std::pow(pset.getParameter("l2deltaR"), 2); + } + } + + bool match(const pat::TriggerObjectStandAlone & obj) const { + return cut(obj); + } + }; + + std::vector sels_; +}; + +// ------------ method called to produce the data ------------ +void +TriggerObjectTableProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const +{ + + edm::Handle> src; + iEvent.getByToken(src_, src); + + std::vector> selected; + for (const auto & obj : *src) { + for (const auto & sel : sels_) { + if (sel.match(obj)) { + selected.emplace_back(&obj,&sel); + break; + } + } + } + + unsigned int nobj = selected.size(); + std::vector pt(nobj,0), eta(nobj,0), phi(nobj,0), l1pt(nobj, 0), l2pt(nobj, 0); + std::vector id(nobj,0), bits(nobj, 0); + for (unsigned int i = 0; i < nobj; ++i) { + const auto & obj = *selected[i].first; + const auto & sel = *selected[i].second; + pt[i] = obj.pt(); + eta[i] = obj.eta(); + phi[i] = obj.phi(); + id[i] = sel.id; + bits[i] = sel.qualityBits(obj); + if (sel.l1DR2 > 0) { + float best = sel.l1DR2; + for (const auto & seed : *src) { + float dr2 = deltaR2(seed, obj); + if (dr2 < best && sel.l1cut(seed)) { + l2pt[i] = seed.pt(); + } + } + } + if (sel.l2DR2 > 0) { + float best = sel.l2DR2; + for (const auto & seed : *src) { + float dr2 = deltaR2(seed, obj); + if (dr2 < best && sel.l2cut(seed)) { + l2pt[i] = seed.pt(); + } + } + } + } + + auto tab = std::make_unique(nobj, name_, false, false); + tab->addColumn("id", id, idDoc_, FlatTable::IntColumn); + tab->addColumn("pt", pt, "pt", FlatTable::FloatColumn, 12); + tab->addColumn("eta", eta, "eta", FlatTable::FloatColumn, 12); + tab->addColumn("phi", phi, "phi", FlatTable::FloatColumn, 12); + tab->addColumn("l1pt", l1pt, "pt of associated L1 seed", FlatTable::FloatColumn, 10); + tab->addColumn("l2pt", l2pt, "pt of associated 'L2' seed (i.e. HLT before tracking/PF)", FlatTable::FloatColumn, 10); + tab->addColumn("filterBits", bits, "extra bits of associated information: "+bitsDoc_, FlatTable::FloatColumn, 10); + iEvent.put(std::move(tab)); +} + + +//define this as a plug-in +DEFINE_FWK_MODULE(TriggerObjectTableProducer); diff --git a/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc new file mode 100644 index 0000000000000..7a886ac5b4171 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc @@ -0,0 +1,86 @@ +#include "PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/Registry.h" + +#include + +void +TriggerOutputBranches::updateTriggerNames(TTree & tree, const edm::TriggerNames & names, const edm::TriggerResults & triggers) +{ + std::vector newNames(triggers.getTriggerNames()); + if(newNames.size()==0) { + for(unsigned int j=0;jSetTitle(nb.title.c_str()); + nb.idx=j; + m_triggerBranches.push_back(nb); + for(size_t i=0;iFill(); // Back fill + } + } + } +} + +edm::TriggerNames TriggerOutputBranches::triggerNames(const edm::TriggerResults triggerResults){ + edm::pset::Registry* psetRegistry = edm::pset::Registry::instance(); + edm::ParameterSet const* pset=0; + if (0!=(pset=psetRegistry->getMapped(triggerResults.parameterSetID()))) { + + if (pset->existsAs >("@trigger_paths", true)) { + edm::TriggerNames triggerNames(*pset); + + // This should never happen + if (triggerNames.size() != triggerResults.size()) { + throw cms::Exception("LogicError") + << "edm::EventBase::triggerNames_ Encountered vector\n" + "of trigger names and a TriggerResults object with\n" + "different sizes. This should be impossible.\n" + "Please send information to reproduce this problem to\n" + "the edm developers.\n"; + } + return triggerNames; + } + } + return edm::TriggerNames(); +} + +void TriggerOutputBranches::fill(const edm::EventForOutput &iEvent,TTree & tree) +{ + edm::Handle handle; + iEvent.getByToken(m_token, handle); + const edm::TriggerResults & triggers = *handle; + const edm::TriggerNames &names = triggerNames(triggers); + + if(m_lastRun!=iEvent.id().run()) { + m_lastRun=iEvent.id().run(); + updateTriggerNames(tree,names,triggers); + } + for (auto & pair : m_triggerBranches) fillColumn(pair, triggers); + m_fills++; +} + + + diff --git a/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.h b/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.h new file mode 100644 index 0000000000000..395d74db8eb42 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.h @@ -0,0 +1,53 @@ +#ifndef PhysicsTools_NanoAOD_TriggerOutputBranches_h +#define PhysicsTools_NanoAOD_TriggerOutputBranches_h + +#include +#include +#include +#include "FWCore/Framework/interface/EventForOutput.h" +#include "DataFormats/Common/interface/TriggerResults.h" +#include "FWCore/Common/interface/TriggerNames.h" +#include "DataFormats/Provenance/interface/BranchDescription.h" +#include "FWCore/Utilities/interface/EDGetToken.h" + +class TriggerOutputBranches { + public: + TriggerOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken & token ) : + m_token(token), m_lastRun(-1),m_fills(0) + { + if (desc->className() != "edm::TriggerResults") throw cms::Exception("Configuration", "NanoAODOutputModule/TriggerOutputBranches can only write out edm::TriggerResults objects"); + } + + void updateTriggerNames(TTree &tree,const edm::TriggerNames & names, const edm::TriggerResults & ta); + void fill(const edm::EventForOutput &iEvent,TTree & tree) ; + + private: + edm::TriggerNames triggerNames(const edm::TriggerResults triggerResults); //FIXME: if we have to keep it local we may use PsetID check per event instead of run boundary + + edm::EDGetToken m_token; + std::string m_baseName; + bool m_singleton; + UInt_t m_counter; + struct NamedBranchPtr { + std::string name, title; + int idx; + TBranch * branch; + uint8_t buffer; + NamedBranchPtr(const std::string & aname, const std::string & atitle, TBranch *branchptr = nullptr) : + name(aname), title(atitle), branch(branchptr), buffer(-1) {} + }; + std::vector m_triggerBranches; + long m_lastRun; + unsigned long m_fills; + + template + void fillColumn(NamedBranchPtr & nb, const edm::TriggerResults & triggers) { + if(nb.idx>=0) nb.buffer=triggers.accept(nb.idx); + nb.branch->SetAddress(&(nb.buffer)); // Can be improved: this is not reallt needed at each event + //but we should be sure that resize of vectors of TriggerOutputBranches do not mess up things + } + +}; + +#endif + diff --git a/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc b/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc new file mode 100644 index 0000000000000..66b961f86933d --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc @@ -0,0 +1,34 @@ +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "PhysicsTools/NanoAOD/interface/UniqueString.h" + +#include + +class UniqueStringProducer : public edm::global::EDProducer { + public: + UniqueStringProducer( edm::ParameterSet const & iConfig ) { + const edm::ParameterSet & strings = iConfig.getParameter("strings"); + for (const std::string & vname : strings.getParameterNamesForType()) { + strings_.emplace_back(vname, strings.getParameter(vname)); + produces(vname); + } + } + + virtual ~UniqueStringProducer() {} + + void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {} // do nothing + + void globalBeginRunProduce(edm::Run& iRun, edm::EventSetup const&) const override { + for (const auto & pair : strings_) { + iRun.put(std::make_unique(pair.second), pair.first); + } + } + + protected: + std::vector> strings_; +}; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(UniqueStringProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/VIDNestedWPBitmapProducer.cc b/PhysicsTools/NanoAOD/plugins/VIDNestedWPBitmapProducer.cc new file mode 100644 index 0000000000000..bb3a0a97c0c0e --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/VIDNestedWPBitmapProducer.cc @@ -0,0 +1,173 @@ +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: VIDNestedWPBitmapProducer +// +/**\class VIDNestedWPBitmapProducer VIDNestedWPBitmapProducer.cc PhysicsTools/NanoAOD/plugins/VIDNestedWPBitmapProducer.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Marco Peruzzi +// Created: Mon, 04 Sep 2017 22:43:53 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/PatCandidates/interface/Electron.h" +#include "DataFormats/PatCandidates/interface/Photon.h" + +#include "DataFormats/PatCandidates/interface/VIDCutFlowResult.h" + +// +// class declaration +// + +template +class VIDNestedWPBitmapProducer : public edm::stream::EDProducer<> { + public: + explicit VIDNestedWPBitmapProducer(const edm::ParameterSet &iConfig): + src_(consumes>(iConfig.getParameter("src"))), + isInit_(false) + { + auto vwp = iConfig.getParameter>("WorkingPoints"); + for (auto wp : vwp) { + src_bitmaps_.push_back(consumes >(edm::InputTag(wp+std::string("Bitmap")))); + src_cutflows_.push_back(consumes >(edm::InputTag(wp))); + } + nWP = src_bitmaps_.size(); + produces>(); + } + ~VIDNestedWPBitmapProducer() {} + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + virtual void beginStream(edm::StreamID) override {}; + virtual void produce(edm::Event&, const edm::EventSetup&) override; + virtual void endStream() override {}; + + //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + + // ----------member data --------------------------- + + edm::EDGetTokenT> src_; + std::vector > > src_bitmaps_; + std::vector > > src_cutflows_; + + unsigned nWP; + unsigned nBits; + unsigned nCuts; + std::vector res_; + bool isInit_; + + void initNCuts(unsigned); + +}; + +// +// constants, enums and typedefs +// + + +// +// static data member definitions +// + +template +void +VIDNestedWPBitmapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + + edm::Handle> src; + iEvent.getByToken(src_, src); + std::vector>> src_bitmaps(nWP); + for (uint i=0; i>> src_cutflows(nWP); + for (uint i=0; i res; + + auto npho = src->size(); + for (uint i=0; iptrAt(i); + for (uint j=0; j>k & 1) { + if (res_[k]!=j) throw cms::Exception("Configuration","Trying to compress VID bitmaps which are not nested in the correct order for all cuts"); + res_[k]++; + } + } + } + + int out = 0; + for (uint k=0; k> resV(new edm::ValueMap()); + edm::ValueMap::Filler filler(*resV); + filler.insert(src,res.begin(),res.end()); + filler.fill(); + + iEvent.put(std::move(resV)); + +} + +template +void +VIDNestedWPBitmapProducer::initNCuts(uint n){ + nCuts = n; + nBits = ceil(log2(nWP+1)); + if (nBits*nCuts>sizeof(int)*8) throw cms::Exception("Configuration","Integer cannot contain the compressed VID bitmap information"); + res_.resize(nCuts,0); + isInit_ = true; +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +template +void +VIDNestedWPBitmapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("src")->setComment("input physics object collection"); + desc.add>("WorkingPoints")->setComment("working points to be saved in the bitmask"); + std::string modname; + if (typeid(T) == typeid(pat::Electron)) modname+="Ele"; + else if (typeid(T) == typeid(pat::Photon)) modname+="Pho"; + modname+="VIDNestedWPBitmapProducer"; + descriptions.add(modname,desc); +} + + +typedef VIDNestedWPBitmapProducer EleVIDNestedWPBitmapProducer; +typedef VIDNestedWPBitmapProducer PhoVIDNestedWPBitmapProducer; + +//define this as a plug-in +DEFINE_FWK_MODULE(EleVIDNestedWPBitmapProducer); +DEFINE_FWK_MODULE(PhoVIDNestedWPBitmapProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc new file mode 100644 index 0000000000000..fa51da621feaf --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc @@ -0,0 +1,197 @@ +// -*- C++ -*- +// +// Package: PhysicsTools/NanoAOD +// Class: VertexTableProducer +// +/**\class VertexTableProducer VertexTableProducer.cc PhysicsTools/VertexTableProducer/plugins/VertexTableProducer.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Andrea Rizzi +// Created: Mon, 28 Aug 2017 09:26:39 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" + +#include "CommonTools/Utils/interface/StringCutObjectSelector.h" + +#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "RecoVertex/VertexTools/interface/VertexDistance3D.h" +#include "RecoVertex/VertexPrimitives/interface/ConvertToFromReco.h" +#include "RecoVertex/VertexPrimitives/interface/VertexState.h" +#include "DataFormats/Common/interface/ValueMap.h" + +// +// class declaration +// + +class VertexTableProducer : public edm::stream::EDProducer<> { + public: + explicit VertexTableProducer(const edm::ParameterSet&); + ~VertexTableProducer(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + virtual void beginStream(edm::StreamID) override; + virtual void produce(edm::Event&, const edm::EventSetup&) override; + virtual void endStream() override; + + //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + + // ----------member data --------------------------- + + const edm::EDGetTokenT> pvs_; + const edm::EDGetTokenT> pvsScore_; + const edm::EDGetTokenT > svs_; + const StringCutObjectSelector svCut_; + const std::string pvName_; + const std::string svName_; + const std::string svDoc_; + const double dlenMin_,dlenSigMin_; + +}; + + + +// +// constructors and destructor +// +VertexTableProducer::VertexTableProducer(const edm::ParameterSet& params): + pvs_(consumes>( params.getParameter("pvSrc") )), + pvsScore_(consumes>( params.getParameter("pvSrc") )), + svs_(consumes >( params.getParameter("svSrc") )), + svCut_(params.getParameter("svCut") , true), + pvName_(params.getParameter("pvName") ), + svName_(params.getParameter("svName") ), + svDoc_(params.getParameter("svDoc") ), + dlenMin_(params.getParameter("dlenMin") ), + dlenSigMin_(params.getParameter("dlenSigMin") ) + +{ + produces("pv"); + produces("otherPVs"); + produces("svs"); + produces >(); + +} + + +VertexTableProducer::~VertexTableProducer() +{ + + // do anything here that needs to be done at destruction time + // (e.g. close files, deallocate resources etc.) + +} + + +// +// member functions +// + +// ------------ method called to produce the data ------------ + + +void +VertexTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + edm::Handle> pvsScoreIn; + edm::Handle> pvsIn; + iEvent.getByToken(pvs_, pvsIn); + iEvent.getByToken(pvsScore_, pvsScoreIn); + auto pvTable = std::make_unique(1,pvName_,true); + pvTable->addColumnValue("ndof",(*pvsIn)[0].ndof(),"main primary vertex number of degree of freedom",FlatTable::FloatColumn,8); + pvTable->addColumnValue("x",(*pvsIn)[0].position().x(),"main primary vertex position x coordinate",FlatTable::FloatColumn,10); + pvTable->addColumnValue("y",(*pvsIn)[0].position().y(),"main primary vertex position y coordinate",FlatTable::FloatColumn,10); + pvTable->addColumnValue("z",(*pvsIn)[0].position().z(),"main primary vertex position z coordinate",FlatTable::FloatColumn,16); + pvTable->addColumnValue("chi2",(*pvsIn)[0].normalizedChi2(),"main primary vertex reduced chi2",FlatTable::FloatColumn,8); + pvTable->addColumnValue("npvs",(*pvsIn).size(),"total number of reconstructed primary vertices",FlatTable::IntColumn); + pvTable->addColumnValue("score",(*pvsScoreIn).get(pvsIn.id(),0),"main primary vertex score, i.e. sum pt2 of clustered objects",FlatTable::FloatColumn,8); + + auto otherPVsTable = std::make_unique((*pvsIn).size() >4?3:(*pvsIn).size()-1,"Other"+pvName_,false); + std::vector pvsz; + for(size_t i=1;i < (*pvsIn).size() && i < 4; i++) pvsz.push_back((*pvsIn)[i-1].position().z()); + otherPVsTable->addColumn("z",pvsz,"Z position of other primary vertices, excluding the main PV",FlatTable::FloatColumn,8); + + + edm::Handle > svsIn; + iEvent.getByToken(svs_, svsIn); + auto selCandSv = std::make_unique>(); + std::vector dlen,dlenSig; + VertexDistance3D vdist; + + size_t i=0; + for (const auto & sv : *svsIn) { + if (svCut_(sv)) { + Measurement1D dl= vdist.distance((*pvsIn)[0],VertexState(RecoVertex::convertPos(sv.position()),RecoVertex::convertError(sv.error()))); + if(dl.value() > dlenMin_ and dl.significance() > dlenSigMin_){ + dlen.push_back(dl.value()); + dlenSig.push_back(dl.significance()); + edm::Ptr c = svsIn->ptrAt(i); + selCandSv->push_back(c); + } + } + i++; + } + + + auto svsTable = std::make_unique(selCandSv->size(),svName_,false); + // For SV we fill from here only stuff that cannot be created with the SimpleFlatTableProducer + svsTable->addColumn("dlen",dlen,"decay length in cm",FlatTable::FloatColumn,10); + svsTable->addColumn("dlenSig",dlenSig,"decay length significance",FlatTable::FloatColumn, 10); + + + iEvent.put(std::move(pvTable),"pv"); + iEvent.put(std::move(otherPVsTable),"otherPVs"); + iEvent.put(std::move(svsTable),"svs"); + iEvent.put(std::move(selCandSv)); +} + +// ------------ method called once each stream before processing any runs, lumis or events ------------ +void +VertexTableProducer::beginStream(edm::StreamID) +{ +} + +// ------------ method called once each stream after processing all runs, lumis and events ------------ +void +VertexTableProducer::endStream() { +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +VertexTableProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(VertexTableProducer); diff --git a/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py b/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py new file mode 100644 index 0000000000000..9308729e5f226 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py @@ -0,0 +1,11 @@ +import FWCore.ParameterSet.Config as cms + +NanoAODEDMEventContent = cms.PSet( + outputCommands = cms.untracked.vstring( + 'drop *', + "keep FlatTable_*Table_*_*", # event data + "keep edmTriggerResults_*_*_*", # event data + "keep MergableCounterTable_*Table_*_*", # accumulated per/run or per/lumi data + "keep UniqueString_nanoMetadata_*_*", # basic metadata + ) +) diff --git a/PhysicsTools/NanoAOD/python/adaptFrom92X_cff.py b/PhysicsTools/NanoAOD/python/adaptFrom92X_cff.py new file mode 100644 index 0000000000000..551ea99409c79 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/adaptFrom92X_cff.py @@ -0,0 +1,12 @@ +import FWCore.ParameterSet.Config as cms + +slimmedMuons = cms.EDProducer("PATMuonUpdater", + src = cms.InputTag("slimmedMuons", processName = cms.InputTag.skipCurrentProcess()), + vertices = cms.InputTag("offlineSlimmedPrimaryVertices") +) +slimmedElectrons = cms.EDProducer("PATElectronUpdater", + src = cms.InputTag("slimmedElectrons", processName = cms.InputTag.skipCurrentProcess()), + vertices = cms.InputTag("offlineSlimmedPrimaryVertices") +) + +adapt_nano = cms.Sequence( slimmedMuons + slimmedElectrons ) diff --git a/PhysicsTools/NanoAOD/python/common_cff.py b/PhysicsTools/NanoAOD/python/common_cff.py new file mode 100644 index 0000000000000..d091487be85ac --- /dev/null +++ b/PhysicsTools/NanoAOD/python/common_cff.py @@ -0,0 +1,60 @@ +import FWCore.ParameterSet.Config as cms +def OVar(valtype, compression=None, doc=None, mcOnly=False,precision=-1): + """ Create a PSet for a variable in the tree (without specifying how it is computed) + + valtype is the type of the value (float, int, bool, or a string that the table producer understands), + compression is not currently used, + doc is a docstring, that will be passed to the table producer, + mcOnly can be set to True for variables that exist only in MC samples and not in data ones. + """ + if valtype == float: valtype = "float" + elif valtype == int: valtype = "int" + elif valtype == bool: valtype = "bool" + return cms.PSet( + type = cms.string(valtype), + compression = cms.string(compression if compression else "none"), + doc = cms.string(doc if doc else expr), + mcOnly = cms.bool(mcOnly), + precision=cms.int32(precision) + ) +def Var(expr, valtype, compression=None, doc=None, mcOnly=False,precision=-1): + """Create a PSet for a variable computed with the string parser + + expr is the expression to evaluate to compute the variable + (in case of bools, it's a cut and not a function) + + see OVar above for all the other arguments + """ + return OVar(valtype, compression=compression, doc=(doc if doc else expr), mcOnly=mcOnly,precision=precision).clone( + expr = cms.string(expr)) + +def ExtVar(tag, valtype, compression=None, doc=None, mcOnly=False,precision=-1): + """Create a PSet for a variable read from the event + + tag is the InputTag to the variable. + + see OVar in common_cff for all the other arguments + """ + return OVar(valtype, compression=compression,precision=precision, doc=(doc if doc else tag.encode()), mcOnly=mcOnly).clone( + src = tag if type(tag) == cms.InputTag else cms.InputTag(tag), + ) + + +PTVars = cms.PSet( + pt = Var("pt", float, precision=-1), + phi = Var("phi", float, precision=12), +) +P3Vars = cms.PSet(PTVars, + eta = Var("eta", float,precision=12), +) +P4Vars = cms.PSet(P3Vars, + mass = Var("mass", float,precision=10), +) +CandVars = cms.PSet(P4Vars, + pdgId = Var("pdgId", int, doc="PDG code assigned by the event reconstruction (not by MC truth)"), + charge = Var("charge", int, doc="electric charge"), +) + + + + diff --git a/PhysicsTools/NanoAOD/python/electrons_cff.py b/PhysicsTools/NanoAOD/python/electrons_cff.py new file mode 100644 index 0000000000000..1faa862480c85 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/electrons_cff.py @@ -0,0 +1,187 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * +from math import ceil,log + +from PhysicsTools.SelectorUtils.tools.vid_id_tools import setupVIDSelection +from RecoEgamma.ElectronIdentification.egmGsfElectronIDs_cff import * +electronMVAValueMapProducer.srcMiniAOD = cms.InputTag("slimmedElectrons") +egmGsfElectronIDs.physicsObjectIDs = cms.VPSet() +egmGsfElectronIDs.physicsObjectSrc = cms.InputTag('slimmedElectrons') +_electron_id_vid_modules=[ +'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff', +'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronHLTPreselecition_Summer16_V1_cff', +#'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff', # add heepIDVarValueMaps to sequence when uncomment +'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff', +'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff', +] +_bitmapVIDForEle_WorkingPoints = cms.vstring( + "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose", + "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium", + "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight", +) +_bitmapVIDForEle_docstring = '' +for modname in _electron_id_vid_modules: + ids= __import__(modname, globals(), locals(), ['idName','cutFlow']) + for name in dir(ids): + _id = getattr(ids,name) + if hasattr(_id,'idName') and hasattr(_id,'cutFlow'): + setupVIDSelection(egmGsfElectronIDs,_id) + if (len(_bitmapVIDForEle_WorkingPoints)>0 and _id.idName==_bitmapVIDForEle_WorkingPoints[0].split(':')[-1]): + _bitmapVIDForEle_docstring = 'VID compressed bitmap (%s), %d bits per cut'%(','.join([cut.cutName.value() for cut in _id.cutFlow]),int(ceil(log(len(_bitmapVIDForEle_WorkingPoints)+1,2)))) +from RecoEgamma.ElectronIdentification.heepIdVarValueMapProducer_cfi import * + +bitmapVIDForEle = cms.EDProducer("EleVIDNestedWPBitmapProducer", + src = cms.InputTag("slimmedElectrons"), + WorkingPoints = _bitmapVIDForEle_WorkingPoints, +) + +isoForEle = cms.EDProducer("EleIsoValueMapProducer", + src = cms.InputTag("slimmedElectrons"), + rho_MiniIso = cms.InputTag("fixedGridRhoFastjetCentralNeutral"), + rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"), + EAFile_MiniIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Spring15/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_25ns.txt"), + EAFile_PFIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Summer16/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_80X.txt"), +) + +ptRatioRelForEle = cms.EDProducer("ElectronJetVarProducer", + srcJet = cms.InputTag("slimmedJets"), + srcLep = cms.InputTag("slimmedElectrons"), + srcVtx = cms.InputTag("offlineSlimmedPrimaryVertices"), +) + +from EgammaAnalysis.ElectronTools.calibratedElectronsRun2_cfi import calibratedPatElectrons +calibratedPatElectrons.correctionFile = cms.string("PhysicsTools/NanoAOD/data/80X_ichepV1_2016_ele") # hack, should go somewhere in EgammaAnalysis + +energyCorrForEle = cms.EDProducer("ElectronEnergyVarProducer", + srcRaw = cms.InputTag("slimmedElectrons"), + srcCorr = cms.InputTag("calibratedPatElectrons"), +) + +finalElectrons = cms.EDFilter("PATElectronRefSelector", + src = cms.InputTag("slimmedElectronsWithUserData"), + cut = cms.string("pt > 5 ") +) + +slimmedElectronsWithUserData = cms.EDProducer("PATElectronUserDataEmbedder", + src = cms.InputTag("slimmedElectrons"), + userFloats = cms.PSet( + mvaSpring16GP = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values"), + mvaSpring16HZZ = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16HZZV1Values"), + miniIsoChg = cms.InputTag("isoForEle:miniIsoChg"), + miniIsoAll = cms.InputTag("isoForEle:miniIsoAll"), + PFIsoChg = cms.InputTag("isoForEle:PFIsoChg"), + PFIsoAll = cms.InputTag("isoForEle:PFIsoAll"), + ptRatio = cms.InputTag("ptRatioRelForEle:ptRatio"), + ptRel = cms.InputTag("ptRatioRelForEle:ptRel"), + jetNDauChargedMVASel = cms.InputTag("ptRatioRelForEle:jetNDauChargedMVASel"), + eCorr = cms.InputTag("energyCorrForEle:eCorr"), + ), + userIntFromBools = cms.PSet( + mvaSpring16GP_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp90"), + mvaSpring16GP_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp80"), + mvaSpring16HZZ_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-HZZ-V1-wpLoose"), + cutbasedID_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-veto"), + cutbasedID_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose"), + cutbasedID_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium"), + cutbasedID_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight"), + cutbasedID_HLT = cms.InputTag("egmGsfElectronIDs:cutBasedElectronHLTPreselection-Summer16-V1"), + ), + userInts = cms.PSet( + VIDNestedWPBitmap = cms.InputTag("bitmapVIDForEle"), + ), + userCands = cms.PSet( + jetForLepJetVar = cms.InputTag("ptRatioRelForEle:jetForLepJetVar") # warning: Ptr is null if no match is found + ), +) + +electronMVATTH= cms.EDProducer("EleBaseMVAValueMapProducer", + src = cms.InputTag("linkedObjects","electrons"), + weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/el_BDTG.weights.xml"), + name = cms.string("electronMVATTH"), + isClassifier = cms.bool(True), + variablesOrder = cms.vstring(["LepGood_pt","LepGood_eta","LepGood_jetNDauChargedMVASel","LepGood_miniRelIsoCharged","LepGood_miniRelIsoNeutral","LepGood_jetPtRelv2","LepGood_jetPtRatio","LepGood_jetBTagCSV","LepGood_sip3d","LepGood_dxy","LepGood_dz","LepGood_mvaIdSpring16HZZ"]), + variables = cms.PSet( + LepGood_pt = cms.string("pt"), + LepGood_eta = cms.string("eta"), + LepGood_jetNDauChargedMVASel = cms.string("userFloat('jetNDauChargedMVASel')"), + LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg')/pt"), + LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"), + LepGood_jetPtRelv2 = cms.string("userFloat('ptRel')"), + LepGood_jetPtRatio = cms.string("min(userFloat('ptRatio'),1.5)"), + LepGood_jetBTagCSV = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags'),0.0):-99.0"), + LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"), + LepGood_dxy = cms.string("log(abs(dB('PV2D')))"), + LepGood_dz = cms.string("log(abs(dB('PVDZ')))"), + LepGood_mvaIdSpring16HZZ = cms.string("userFloat('mvaSpring16HZZ')"), + ) +) + +electronTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("linkedObjects","electrons"), + cut = cms.string(""), #we should not filter on cross linked collections + name= cms.string("Electron"), + doc = cms.string("slimmedElectrons after basic selection (" + finalElectrons.cut.value()+")"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the electrons + variables = cms.PSet(CandVars, + jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), + photonIdx = Var("?overlaps('photons').size()>0?overlaps('photons')[0].key():-1", int, doc="index of the associated photon (-1 if none)"), + #ptErr = Var("gsfTrack().ptError()",float,doc="pt error of the GSF track",precision=6), + energyErr = Var("p4Error('P4_COMBINATION')*userFloat('eCorr')",float,doc="energy error of the cluster-track combination",precision=6), + eCorr = Var("userFloat('eCorr')",float,doc="ratio of the calibrated energy/miniaod energy"), + dz = Var("abs(dB('PVDZ'))",float,doc="dz (with sign) wrt first PV, in cm",precision=10), + dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6), + dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10), + dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6), + ip3d = Var("abs(dB('PV3D'))",float,doc="3D impact parameter wrt first PV, in cm",precision=10), + sip3d = Var("abs(dB('PV3D')/edB('PV3D'))",float,doc="3D impact parameter significance wrt first PV, in cm",precision=10), + deltaEtaSC = Var("superCluster().eta()-eta()",float,doc="delta eta (SC,ele) with sign",precision=10), + r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=10), + sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10), + mvaSpring16GP = Var("userFloat('mvaSpring16GP')",float,doc="MVA general-purpose ID score"), + mvaSpring16GP_WP80 = Var("userInt('mvaSpring16GP_WP80')",bool,doc="MVA general-purpose ID WP80"), + mvaSpring16GP_WP90 = Var("userInt('mvaSpring16GP_WP90')",bool,doc="MVA general-purpose ID WP90"), + mvaSpring16HZZ = Var("userFloat('mvaSpring16HZZ')",float,doc="MVA HZZ ID score"), + mvaSpring16HZZ_WPL = Var("userInt('mvaSpring16HZZ_WPL')",bool,doc="MVA HZZ ID loose WP"), + cutBased = Var("userInt('cutbasedID_veto')+userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",int,doc="cut-based ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"), + VIDNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')",int,doc=_bitmapVIDForEle_docstring), + cutBased_HLTPreSel = Var("userInt('cutbasedID_HLT')",int,doc="cut-based HLT pre-selection ID"), + miniPFIso_chg = Var("userFloat('miniIsoChg')",float,doc="mini PF isolation, charged component"), + miniPFIso_all = Var("userFloat('miniIsoAll')",float,doc="mini PF isolation, total (with scaled rho*EA PU corrections)"), + PFIso03_chg = Var("userFloat('PFIsoChg')",float,doc="PF isolation dR=0.3, charged component"), + PFIso03_all = Var("userFloat('PFIsoAll')",float,doc="PF isolation dR=0.3, total (with rho*EA PU corrections)"), + hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8), + tightCharge = Var("isGsfCtfScPixChargeConsistent() + isGsfScPixChargeConsistent()",int,doc="Tight charge criteria (0:none, 1:isGsfScPixChargeConsistent, 2:isGsfCtfScPixChargeConsistent)"), + convVeto = Var("passConversionVeto()",bool,doc="pass conversion veto"), + lostHits = Var("gsfTrack.hitPattern.numberOfLostHits('MISSING_INNER_HITS')","uint8",doc="number of missing inner hits"), + ), + externalVariables = cms.PSet( + mvaTTH = ExtVar(cms.InputTag("electronMVATTH"),float, doc="TTH MVA lepton ID score",precision=14), + ), +) +electronTable.variables.pt = Var("pt*userFloat('eCorr')", float, precision=-1) + +electronsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR + src = electronTable.src, # final reco collection + matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection + mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below) + checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge + mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering) + maxDeltaR = cms.double(0.3), # Minimum deltaR for the match + maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match + resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object + resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first +) + +electronMCTable = cms.EDProducer("CandMCMatchTableProducer", + src = electronTable.src, + mcMap = cms.InputTag("electronsMCMatchForTable"), + objName = electronTable.name, + objType = electronTable.name, #cms.string("Electron"), + branchName = cms.string("mcMatch"), + docString = cms.string("MC matching to status==1 electrons or photons"), +) + +electronSequence = cms.Sequence(egmGsfElectronIDSequence + bitmapVIDForEle + isoForEle + ptRatioRelForEle + calibratedPatElectrons + energyCorrForEle + slimmedElectronsWithUserData + finalElectrons) +electronTables = cms.Sequence (electronMVATTH + electronTable) +electronMC = cms.Sequence(electronsMCMatchForTable + electronMCTable) diff --git a/PhysicsTools/NanoAOD/python/genparticles_cff.py b/PhysicsTools/NanoAOD/python/genparticles_cff.py new file mode 100644 index 0000000000000..cfdbe9f020b46 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/genparticles_cff.py @@ -0,0 +1,69 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * + + + +##################### User floats producers, selectors ########################## + +finalGenParticles = cms.EDProducer("GenParticlePruner", + src = cms.InputTag("prunedGenParticles"), + select = cms.vstring( + "drop *", # this is the default + "++keep abs(pdgId) == 11 || abs(pdgId) == 13 || abs(pdgId) == 15", # keep leptons, with history + "drop status == 2", # drop the shower part of the history + "keep (400 < abs(pdgId) < 600) || (4000 < abs(pdgId) < 6000)", + "keep abs(pdgId) == 11 || abs(pdgId) == 13 || abs(pdgId) == 15", # keep leptons (also status1) + "keep abs(pdgId) == 12 || abs(pdgId) == 14 || abs(pdgId) == 16", # keep neutrinos + "+keep pdgId == 22 && status == 1 && (pt > 10 || isPromptFinalState())", # keep gamma above 10 GeV (or all prompt) and its first parent + "+keep abs(pdgId) == 11 && status == 1 && (pt > 3 || isPromptFinalState())", # keep first parent of electrons above 3 GeV (or prompt) + "keep++ abs(pdgId) == 15", # but keep keep taus with decays + "drop status > 30 && status < 70 ", # remove pythia8 garbage + "drop pdgId == 21 && pt < 5", # remove pythia8 garbage + "drop status == 2 && abs(pdgId) == 21", # but remove again gluons in the inheritance chain + "keep abs(pdgId) == 23 || abs(pdgId) == 24 || abs(pdgId) == 25 || abs(pdgId) == 6 || abs(pdgId) == 37 ", # keep VIP(articles)s + "keep abs(pdgId) == 310 && abs(eta) < 2.5 && pt > 1 ", # keep K0 + "+keep abs(pdgId) == 13 && status == 1", # keep muon parents + "keep (4 <= abs(pdgId) <= 5) && ( status <30 || status > 70)", + "keep (1 <= abs(pdgId) <= 3 || pdgId = 21) & (status = 2 || status = 11 || status = 71 || status = 72) && pt>15", #increased to 15GeV wrt miniAOD +# keep onia states, phi, X(3872), Z(4430)+ and psi(4040) +# "keep+ abs(pdgId) == 333", +# "keep+ abs(pdgId) == 9920443 || abs(pdgId) == 9042413 || abs(pdgId) == 9000443", +# "keep+ abs(pdgId) == 443 || abs(pdgId) == 100443 || abs(pdgId) == 10441 || abs(pdgId) == 20443 || abs(pdgId) == 445 || abs(pdgId) == 30443", +# "keep+ abs(pdgId) == 553 || abs(pdgId) == 100553 || abs(pdgId) == 200553 || abs(pdgId) == 10551 || abs(pdgId) == 20553 || abs(pdgId) == 555", +# additional c hadrons for jet fragmentation studies +# "keep abs(pdgId) = 10411 || abs(pdgId) = 10421 || abs(pdgId) = 10413 || abs(pdgId) = 10423 || abs(pdgId) = 20413 || abs(pdgId) = 20423 || abs(pdgId) = 10431 || abs(pdgId) = 10433 || abs(pdgId) = 20433", +# additional b hadrons for jet fragmentation studies +# "keep abs(pdgId) = 10511 || abs(pdgId) = 10521 || abs(pdgId) = 10513 || abs(pdgId) = 10523 || abs(pdgId) = 20513 || abs(pdgId) = 20523 || abs(pdgId) = 10531 || abs(pdgId) = 10533 || abs(pdgId) = 20533 || abs(pdgId) = 10541 || abs(pdgId) = 10543 || abs(pdgId) = 20543", +#keep SUSY particles + "keep (1000001 <= abs(pdgId) <= 1000039 ) || ( 2000001 <= abs(pdgId) <= 2000015)", +## keep protons +# "keep pdgId = 2212", + "keep status == 3 || ( 21 <= status <= 29) || ( 11 <= status <= 19)", #keep event summary (status=3 for pythia6, 21 <= status <= 29 for pythia8) + "keep isHardProcess() || fromHardProcessFinalState() || fromHardProcessDecayed() || fromHardProcessBeforeFSR() || (statusFlags().fromHardProcess() && statusFlags().isLastCopy())", #keep event summary based on status flags + ) +) + + + +##################### Tables for final output and docs ########################## +genParticleTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("finalGenParticles"), + cut = cms.string(""), #we should not filter after pruning + name= cms.string("GenPart"), + doc = cms.string("interesting gen particles "), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the taus + variables = cms.PSet( + pt = Var("pt", float,precision=8), + phi = Var("phi", float,precision=8), + eta = Var("eta", float,precision=8), + pdgId = Var("pdgId", int, doc="PDG id"), + status = Var("status", int, doc="Particle status. 1=stable"), + genPartIdxMother = Var("?numberOfMothers>0?motherRef(0).key():-1", int, doc="index of the mother particle"), + + ) +) + +genParticleSequence = cms.Sequence(finalGenParticles) +genParticleTables = cms.Sequence(genParticleTable) + diff --git a/PhysicsTools/NanoAOD/python/globals_cff.py b/PhysicsTools/NanoAOD/python/globals_cff.py new file mode 100644 index 0000000000000..6b9fe530f4f66 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/globals_cff.py @@ -0,0 +1,13 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * + +rhoTable = cms.EDProducer("GlobalVariablesTableProducer", + variables = cms.PSet( + fixedGridRhoFastjetAll = ExtVar( cms.InputTag("fixedGridRhoFastjetAll"), "double", doc = "rho from all PF Candidates, used e.g. for JECs" ), + fixedGridRhoFastjetCentralNeutral = ExtVar( cms.InputTag("fixedGridRhoFastjetCentralNeutral"), "double", doc = "rho from neutral PF Candidates with |eta| < 2.5, used e.g. for rho corrections of some lepton isolations" ), + fixedGridRhoFastjetCentralCalo = ExtVar( cms.InputTag("fixedGridRhoFastjetCentralCalo"), "double", doc = "rho from calo towers with |eta| < 2.5, used e.g. egamma PFCluster isolation" ), + ) +) + +globalTables = cms.Sequence(rhoTable) + diff --git a/PhysicsTools/NanoAOD/python/isotracks_cff.py b/PhysicsTools/NanoAOD/python/isotracks_cff.py new file mode 100644 index 0000000000000..4a252509a4620 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/isotracks_cff.py @@ -0,0 +1,41 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * + +finalIsolatedTracks = cms.EDProducer("IsolatedTrackCleaner", + tracks = cms.InputTag("isolatedTracks"), + cut = cms.string("pt > 10 && abs(dxy) < 0.02 && abs(dz) < 0.1 && isHighPurityTrack && miniPFIsolation.chargedHadronIso/pt < 0.2"), + finalLeptons = cms.VInputTag( + cms.InputTag("finalElectrons"), + cms.InputTag("finalMuons"), + cms.InputTag("finalTaus"), + ), +) + +isoForIsoTk = cms.EDProducer("IsoTrackIsoValueMapProducer", + src = cms.InputTag("finalIsolatedTracks"), + rho_MiniIso = cms.InputTag("fixedGridRhoFastjetCentralNeutral"), + EAFile_MiniIso = cms.FileInPath("PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt"), +) + +isoTrackTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("finalIsolatedTracks"), + cut = cms.string(""), # filtered already above + name = cms.string("IsoTrack"), + doc = cms.string("isolated tracks after basic selection (" + finalIsolatedTracks.cut.value() + ") and lepton veto"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the muons + variables = cms.PSet(P3Vars, + dz = Var("dz",float,doc="dz (with sign) wrt first PV, in cm",precision=10), + dxy = Var("dxy",float,doc="dxy (with sign) wrt first PV, in cm",precision=10), + PFIso03_chg = Var("pfIsolationDR03().chargedHadronIso",float,doc="PF isolation dR=0.3, charged component",precision=10), + PFIso03_all = Var("(pfIsolationDR03().chargedHadronIso + max(pfIsolationDR03().neutralHadronIso + pfIsolationDR03().photonIso - pfIsolationDR03().puChargedHadronIso/2,0.0))",float,doc="PF isolation dR=0.3, total (deltaBeta corrections)",precision=10), + ), + externalVariables = cms.PSet( + miniPFIso_chg = ExtVar("isoForIsoTk:miniIsoChg",float,doc="mini PF isolation, charged component",precision=10), + miniPFIso_all = ExtVar("isoForIsoTk:miniIsoAll",float,doc="mini PF isolation, total (with scaled rho*EA PU corrections)",precision=10), + ), +) + +isoTrackSequence = cms.Sequence(finalIsolatedTracks + isoForIsoTk) +isoTrackTables = cms.Sequence(isoTrackTable) + diff --git a/PhysicsTools/NanoAOD/python/jets_cff.py b/PhysicsTools/NanoAOD/python/jets_cff.py new file mode 100644 index 0000000000000..245e5e8f4f577 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/jets_cff.py @@ -0,0 +1,237 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * + + + +##################### User floats producers, selectors ########################## +from RecoJets.JetProducers.ak4PFJets_cfi import ak4PFJets + +chsForSATkJets = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string('charge()!=0 && pvAssociationQuality()>=5 && vertexRef().key()==0')) +#chsForSATkJets = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string('charge()!=0 && fromPV && vertexRef().key()==0')) +softActivityJets = ak4PFJets.clone(src = 'chsForSATkJets', doAreaFastjet = False, jetPtMin=1) +softActivityJets10 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("chsForSATkJets"), cut = cms.string('pt>10')) +softActivityJets5 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("chsForSATkJets"), cut = cms.string('pt>5')) +softActivityJets2 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("chsForSATkJets"), cut = cms.string('pt>2')) + +looseJetId = cms.EDProducer("PatJetIDValueMapProducer", + filterParams=cms.PSet( + version = cms.string('WINTER16'), + quality = cms.string('LOOSE'), + ), + src = cms.InputTag("slimmedJets") +) +tightJetId = cms.EDProducer("PatJetIDValueMapProducer", + filterParams=cms.PSet( + version = cms.string('WINTER16'), + quality = cms.string('TIGHT'), + ), + src = cms.InputTag("slimmedJets") +) + +slimmedJetsWithUserData = cms.EDProducer("PATJetUserDataEmbedder", + src = cms.InputTag("slimmedJets"), + userInts = cms.PSet( + tightId = cms.InputTag("tightJetId"), + looseId = cms.InputTag("looseJetId"), + ), +) + + +finalJets = cms.EDFilter("PATJetRefSelector", + src = cms.InputTag("slimmedJetsWithUserData"), + cut = cms.string("pt > 15") +) + + + + +##################### Tables for final output and docs ########################## + + + +jetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("linkedObjects","jets"), + cut = cms.string(""), #we should not filter on cross linked collections + name = cms.string("Jet"), + doc = cms.string("slimmedJets, i.e. ak4 PFJets CHS with JECs applied, after basic selection (" + finalJets.cut.value()+")"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the jets + externalVariables = cms.PSet( + bReg = ExtVar(cms.InputTag("bjetMVA"),float, doc="pt corrected with b-jet regression",precision=14), + ), + variables = cms.PSet(P4Vars, + area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10), + nMuons = Var("?hasOverlaps('muons')?overlaps('muons').size():0", int, doc="number of muons in the jet"), + muonIdx1 = Var("?overlaps('muons').size()>0?overlaps('muons')[0].key():-1", int, doc="index of first matching muon"), + muonIdx2 = Var("?overlaps('muons').size()>1?overlaps('muons')[1].key():-1", int, doc="index of second matching muon"), + electronIdx1 = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of first matching electron"), + electronIdx2 = Var("?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1", int, doc="index of second matching electron"), + nElectrons = Var("?hasOverlaps('electrons')?overlaps('electrons').size():0", int, doc="number of electrons in the jet"), + btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10), + btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')",float,doc="CMVA V2 btag discriminator",precision=10), + btagDeepBB = Var("bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="CMVA V2 btag discriminator",precision=10), + btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="CMVA V2 btag discriminator",precision=10), +#puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pilup ID discriminant",precision=10), + puId = Var("userInt('pileupJetId:fullId')",int,doc="Pilup ID flags"), + jetId = Var("userInt('tightId')*2+userInt('looseId')",int,doc="Jet ID flags bit1 is loose, bit2 is tight"), + qgl = Var("userFloat('QGTagger:qgLikelihood')",float,doc="Quark vs Gluon likelihood discriminator",precision=10), + nConstituents = Var("numberOfDaughters()",int,doc="Number of particles in the jet"), + rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6), + chHEF = Var("chargedHadronEnergy()/energy()", float, doc="charged Hadron Energy Fraction", precision= 6), + neHEF = Var("neutralHadronEnergy()/energy()", float, doc="neutral Hadron Energy Fraction", precision= 6), + chEmEF = Var("chargedEmEnergy()/energy()", float, doc="charged Electromagnetic Energy Fraction", precision= 6), + neEmEF = Var("neutralEmEnergy()/energy()", float, doc="charged Electromagnetic EnergyFraction", precision= 6), + + ) +) +#jets are not as precise as muons +jetTable.variables.pt.precision=10 + + +bjetMVA= cms.EDProducer("BJetEnergyRegressionMVA", + src = cms.InputTag("linkedObjects","jets"), + pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"), + svsrc = cms.InputTag("slimmedSecondaryVertices"), + weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/bjet-regression.xml"), + name = cms.string("JetReg"), + isClassifier = cms.bool(False), + variablesOrder = cms.vstring(["Jet_pt","nPVs","Jet_eta","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonPt","Jet_leptonDeltaR","Jet_neHEF","Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL"]), + variables = cms.PSet( + Jet_pt = cms.string("pt"), + Jet_eta = cms.string("eta"), + Jet_mt = cms.string("mt"), + Jet_leptonPt = cms.string("?overlaps('muons').size()>0?overlaps('muons')[0].pt():(?overlaps('electrons').size()>0?overlaps('electrons')[0].pt():0)"), + Jet_neHEF = cms.string("neutralHadronEnergy()/energy()"), + Jet_neEmEF = cms.string("neutralEmEnergy()/energy()"), + Jet_leptonDeltaR = cms.string('''?overlaps('muons').size()>0?deltaR(eta,phi,overlaps('muons')[0].eta,overlaps('muons')[0].phi): + (?overlaps('electrons').size()>0?deltaR(eta,phi,overlaps('electrons')[0].eta,overlaps('electrons')[0].phi): + 0)'''), + ) + +) + +##### Soft Activity tables +saJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("softActivityJets"), + cut = cms.string(""), + maxLen = cms.uint32(6), + name = cms.string("SoftActivityJet"), + doc = cms.string("jets clustered from charged candidates compatible with primary vertex (" + chsForSATkJets.cut.value()+")"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the jets + variables = cms.PSet(P3Vars, + ) +) + +saJetTable.variables.pt.precision=10 +saJetTable.variables.eta.precision=8 +saJetTable.variables.phi.precision=8 + +saTable = cms.EDProducer("GlobalVariablesTableProducer", + variables = cms.PSet( + SoftActivityJetHT = ExtVar( cms.InputTag("softActivityJets"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt, pt>1" ), + SoftActivityJetHT10 = ExtVar( cms.InputTag("softActivityJets10"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt , pt >10" ), + SoftActivityJetHT5 = ExtVar( cms.InputTag("softActivityJets5"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt, pt>5" ), + SoftActivityJetHT2 = ExtVar( cms.InputTag("softActivityJets2"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt, pt >2" ), + SoftActivityJetNjets10 = ExtVar( cms.InputTag("softActivityJets10"), "candidatesize", doc = "number of soft activity jet pt, pt >2" ), + SoftActivityJetNjets5 = ExtVar( cms.InputTag("softActivityJets5"), "candidatesize", doc = "number of soft activity jet pt, pt >5" ), + SoftActivityJetNjets2 = ExtVar( cms.InputTag("softActivityJets2"), "candidatesize", doc = "number of soft activity jet pt, pt >10" ), + + ) +) + + + +## BOOSTED STUFF ################# +fatJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("slimmedJetsAK8"), + cut = cms.string(" pt > 170"), #probably already applied in miniaod + name = cms.string("FatJet"), + doc = cms.string("slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the jets + variables = cms.PSet(P4Vars, + area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10), + tau1 = Var("userFloat('ak8PFJetsCHSValueMap:NjettinessAK8CHSTau1')",float, doc="Nsubjettiness (1 axis)",precision=10), + tau2 = Var("userFloat('ak8PFJetsCHSValueMap:NjettinessAK8CHSTau2')",float, doc="Nsubjettiness (2 axis)",precision=10), + tau3 = Var("userFloat('ak8PFJetsCHSValueMap:NjettinessAK8CHSTau3')",float, doc="Nsubjettiness (3 axis)",precision=10), + msoftdrop = Var("userFloat('ak8PFJetsCHSValueMap:ak8PFJetsCHSSoftDropMass')",float, doc="Soft drop mass",precision=10), + mpruned = Var("userFloat('ak8PFJetsCHSValueMap:ak8PFJetsCHSPrunedMass')", float, doc="Pruned mass",precision=10), + + + btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10), + btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')",float,doc="CMVA V2 btag discriminator",precision=10), + btagDeepBB = Var("bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="CMVA V2 btag discriminator",precision=10), + + subJetIdx1 = Var("?numberOfSourceCandidatePtrs()>0 && sourceCandidatePtr(0).numberOfSourceCandidatePtrs()>0?sourceCandidatePtr(0).key():-1", int, + doc="index of first subjet"), + subJetIdx2 = Var("?numberOfSourceCandidatePtrs()>1 && sourceCandidatePtr(1).numberOfSourceCandidatePtrs()>0?sourceCandidatePtr(1).key():-1", int, + doc="index of second subjet"), + subJetIdx3 = Var("?numberOfSourceCandidatePtrs()>2 && sourceCandidatePtr(2).numberOfSourceCandidatePtrs()>0?sourceCandidatePtr(2).key():-1", int, + doc="index of third subjet"), + +# btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="CMVA V2 btag discriminator",precision=10), +#puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pilup ID discriminant",precision=10), +# nConstituents = Var("numberOfDaughters()",int,doc="Number of particles in the jet"), +# rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6), + ) +) + +subJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("slimmedJetsAK8PFPuppiSoftDropPacked","SubJets"), + cut = cms.string(""), #probably already applied in miniaod + name = cms.string("SubJet"), + doc = cms.string("slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the jets + variables = cms.PSet(P4Vars, + btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10), + btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')",float,doc="CMVA V2 btag discriminator",precision=10), + btagDeepBB = Var("bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="CMVA V2 btag discriminator",precision=10), + ) +) + +#jets are not as precise as muons +fatJetTable.variables.pt.precision=10 + + + + + + + +## MC STUFF ###################### +jetMCTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("linkedObjects","jets"), + cut = cms.string(""), #we should not filter on cross linked collections + name = cms.string("Jet"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(True), # this is an extension table for the jets + variables = cms.PSet( + partonFlavour = Var("partonFlavour()", int, doc="flavour from parton matching"), + hadronFlavour = Var("hadronFlavour()", int, doc="flavour from hadron ghost clustering"), + genJetIdx = Var("?genJetFwdRef().backRef().isNonnull()?genJetFwdRef().backRef().key():-1", int, doc="index of matched gen jet"), + ) +) +genJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("slimmedGenJets"), + cut = cms.string("pt > 10"), + name = cms.string("GenJet"), + doc = cms.string("slimmedGenJets, i.e. ak4 Jets made with visible genparticles"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the genjets + variables = cms.PSet(P4Vars, + #anything else? + ) +) + + + +#before cross linking +jetSequence = cms.Sequence(looseJetId+tightJetId+slimmedJetsWithUserData+chsForSATkJets+softActivityJets+softActivityJets2+softActivityJets5+softActivityJets10+finalJets) +#after cross linkining +jetTables = cms.Sequence(bjetMVA+ jetTable+fatJetTable+subJetTable+saJetTable+saTable) + +#MC only producers and tables +jetMC = cms.Sequence(jetMCTable+genJetTable) + diff --git a/PhysicsTools/NanoAOD/python/met_cff.py b/PhysicsTools/NanoAOD/python/met_cff.py new file mode 100644 index 0000000000000..a93a5a08d844a --- /dev/null +++ b/PhysicsTools/NanoAOD/python/met_cff.py @@ -0,0 +1,67 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * + + + +##################### User floats producers, selectors ########################## + + + +##################### Tables for final output and docs ########################## +metTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("slimmedMETs"), + name = cms.string("MET"), + doc = cms.string("slimmedMET, type-1 corrected PF MET"), + singleton = cms.bool(True), # there's always exactly one MET per event + extension = cms.bool(False), # this is the main table for the MET + variables = cms.PSet(PTVars, + sumEt = Var("sumEt()", float, doc="scalar sum of Et",precision=10), + rawEt = Var("uncorPt", float, doc="raw (uncorrected) scalar sum of Et",precision=10), + covXX = Var("getSignificanceMatrix().At(0,0)",float,doc="xx element of met covariance matrix", precision=8), + covXY = Var("getSignificanceMatrix().At(0,1)",float,doc="xy element of met covariance matrix", precision=8), + covYY = Var("getSignificanceMatrix().At(1,1)",float,doc="yy element of met covariance matrix", precision=8), + significance = Var("metSignificance()", float, doc="MET significance",precision=10), + + ), +) + +caloMetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = metTable.src, + name = cms.string("METCalo"), + doc = cms.string("Calo MET"), + singleton = cms.bool(True), # there's always exactly one MET per event + extension = cms.bool(False), # this is the main table for the MET + variables = cms.PSet(#NOTA BENE: we don't copy PTVars here! + pt = Var("caloMETPt", float, precision=10), + phi = Var("caloMETPhi", float, precision=10), + sumEt = Var("caloMETSumEt", float, doc="scalar sum of Et", precision=10), + ), +) + +puppiMetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("slimmedMETsPuppi"), + name = cms.string("METpuppi"), + doc = cms.string("PUPPI MET"), + singleton = cms.bool(True), # there's always exactly one MET per event + extension = cms.bool(False), # this is the main table for the MET + variables = cms.PSet(PTVars, + sumEt = Var("sumEt()", float, doc="scalar sum of Et",precision=10), + ), +) + +metMCTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = metTable.src, + name = cms.string("MET"), + doc = cms.string("Calo MET"), + singleton = cms.bool(True), # there's always exactly one MET per event + extension = cms.bool(True), # we add variables to the MET + variables = cms.PSet( + genPt = Var("genMET.pt", float, precision=10), + genPhi = Var("genMET.phi", float, precision=10), + ), +) + +#metSequence = cms.Sequence() +metTables = cms.Sequence( metTable + caloMetTable + puppiMetTable ) +metMC = cms.Sequence( metMCTable ) + diff --git a/PhysicsTools/NanoAOD/python/muons_cff.py b/PhysicsTools/NanoAOD/python/muons_cff.py new file mode 100644 index 0000000000000..db7cdbadc5e76 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/muons_cff.py @@ -0,0 +1,117 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * + +isoForMu = cms.EDProducer("MuonIsoValueMapProducer", + src = cms.InputTag("slimmedMuons"), + rho_MiniIso = cms.InputTag("fixedGridRhoFastjetCentralNeutral"), + EAFile_MiniIso = cms.FileInPath("PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt"), +) + +ptRatioRelForMu = cms.EDProducer("MuonJetVarProducer", + srcJet = cms.InputTag("slimmedJets"), + srcLep = cms.InputTag("slimmedMuons"), + srcVtx = cms.InputTag("offlineSlimmedPrimaryVertices"), +) + +slimmedMuonsWithUserData = cms.EDProducer("PATMuonUserDataEmbedder", + src = cms.InputTag("slimmedMuons"), + userFloats = cms.PSet( + miniIsoChg = cms.InputTag("isoForMu:miniIsoChg"), + miniIsoAll = cms.InputTag("isoForMu:miniIsoAll"), + ptRatio = cms.InputTag("ptRatioRelForMu:ptRatio"), + ptRel = cms.InputTag("ptRatioRelForMu:ptRel"), + jetNDauChargedMVASel = cms.InputTag("ptRatioRelForMu:jetNDauChargedMVASel"), + ), + userCands = cms.PSet( + jetForLepJetVar = cms.InputTag("ptRatioRelForMu:jetForLepJetVar") # warning: Ptr is null if no match is found + ), +) + +finalMuons = cms.EDFilter("PATMuonRefSelector", + src = cms.InputTag("slimmedMuonsWithUserData"), + cut = cms.string("pt > 3 && track.isNonnull && isLooseMuon") +) + +muonMVATTH= cms.EDProducer("MuonBaseMVAValueMapProducer", + src = cms.InputTag("linkedObjects","muons"), + weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG.weights.xml"), + name = cms.string("muonMVATTH"), + isClassifier = cms.bool(True), + variablesOrder = cms.vstring(["LepGood_pt","LepGood_eta","LepGood_jetNDauChargedMVASel","LepGood_miniRelIsoCharged","LepGood_miniRelIsoNeutral","LepGood_jetPtRelv2","LepGood_jetPtRatio","LepGood_jetBTagCSV","LepGood_sip3d","LepGood_dxy","LepGood_dz","LepGood_segmentCompatibility"]), + variables = cms.PSet( + LepGood_pt = cms.string("pt"), + LepGood_eta = cms.string("eta"), + LepGood_jetNDauChargedMVASel = cms.string("userFloat('jetNDauChargedMVASel')"), + LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg')/pt"), + LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"), + LepGood_jetPtRelv2 = cms.string("userFloat('ptRel')"), + LepGood_jetPtRatio = cms.string("min(userFloat('ptRatio'),1.5)"), + LepGood_jetBTagCSV = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags'),0.0):-99.0"), + LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"), + LepGood_dxy = cms.string("log(abs(dB('PV2D')))"), + LepGood_dz = cms.string("log(abs(dB('PVDZ')))"), + LepGood_segmentCompatibility = cms.string("segmentCompatibility"), + ) +) + +muonTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("linkedObjects","muons"), + cut = cms.string(""), #we should not filter on cross linked collections + name = cms.string("Muon"), + doc = cms.string("slimmedMuons after basic selection (" + finalMuons.cut.value()+")"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the muons + variables = cms.PSet(CandVars, + ptErr = Var("bestTrack().ptError()", float, doc = "ptError of the muon track", precision=6), + dz = Var("abs(dB('PVDZ'))",float,doc="dz (with sign) wrt first PV, in cm",precision=10), + dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6), + dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10), + dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6), + ip3d = Var("abs(dB('PV3D'))",float,doc="3D impact parameter wrt first PV, in cm",precision=10), + sip3d = Var("abs(dB('PV3D')/edB('PV3D'))",float,doc="3D impact parameter significance wrt first PV",precision=10), + segmentComp = Var("segmentCompatibility()", float, doc = "muon segment compatibility", precision=14), # keep higher precision since people have cuts with 3 digits on this + nStations = Var("numberOfMatchedStations", int, doc = "number of matched stations with default arbitration (segment & track)"), + jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), + miniPFIso_chg = Var("userFloat('miniIsoChg')",float,doc="mini PF isolation, charged component"), + miniPFIso_all = Var("userFloat('miniIsoAll')",float,doc="mini PF isolation, total (with scaled rho*EA PU corrections)"), + PFIso03_chg = Var("pfIsolationR03().sumChargedHadronPt",float,doc="PF isolation dR=0.3, charged component"), + PFIso03_all = Var("(pfIsolationR03().sumChargedHadronPt + max(pfIsolationR03().sumNeutralHadronEt + pfIsolationR03().sumPhotonEt - pfIsolationR03().sumPUPt/2,0.0))",float,doc="PF isolation dR=0.3, total (deltaBeta corrections)"), + tightCharge = Var("?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0",int,doc="Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"), + ), + externalVariables = cms.PSet( + mvaTTH = ExtVar(cms.InputTag("muonMVATTH"),float, doc="TTH MVA lepton ID score",precision=14), + ), +) + +muonIDTable = cms.EDProducer("MuonIDTableProducer", + name = muonTable.name, + muons = muonTable.src, # final reco collection + vertices = cms.InputTag("offlineSlimmedPrimaryVertices"), +) + + +muonsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR + src = muonTable.src, # final reco collection + matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection + mcPdgId = cms.vint32(13), # one or more PDG ID (13 = mu); absolute values (see below) + checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge + mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering) + maxDeltaR = cms.double(0.3), # Minimum deltaR for the match + maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match + resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object + resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first +) + +muonMCTable = cms.EDProducer("CandMCMatchTableProducer", + src = muonTable.src, + mcMap = cms.InputTag("muonsMCMatchForTable"), + objName = muonTable.name, + objType = muonTable.name, #cms.string("Muon"), + branchName = cms.string("mcMatch"), + docString = cms.string("MC matching to status==1 muons"), +) + +muonSequence = cms.Sequence(isoForMu + ptRatioRelForMu + slimmedMuonsWithUserData + finalMuons) +muonMC = cms.Sequence(muonsMCMatchForTable + muonMCTable) +muonTables = cms.Sequence(muonMVATTH + muonTable + muonIDTable) + diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py new file mode 100644 index 0000000000000..f7ffb6e50d13e --- /dev/null +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -0,0 +1,73 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * +from PhysicsTools.NanoAOD.jets_cff import * +from PhysicsTools.NanoAOD.muons_cff import * +from PhysicsTools.NanoAOD.taus_cff import * +from PhysicsTools.NanoAOD.electrons_cff import * +from PhysicsTools.NanoAOD.photons_cff import * +from PhysicsTools.NanoAOD.globals_cff import * +from PhysicsTools.NanoAOD.genparticles_cff import * +from PhysicsTools.NanoAOD.vertices_cff import * +from PhysicsTools.NanoAOD.met_cff import * +from PhysicsTools.NanoAOD.triggerObjects_cff import * +from PhysicsTools.NanoAOD.isotracks_cff import * +from PhysicsTools.NanoAOD.NanoAODEDMEventContent_cff import * +from PhysicsTools.NanoAOD.adaptFrom92X_cff import * # remove when 94X MC becomes available + +nanoMetadata = cms.EDProducer("UniqueStringProducer", + strings = cms.PSet( + tag = cms.string("untagged"), + ) +) + +linkedObjects = cms.EDProducer("PATObjectCrossLinker", + jets=cms.InputTag("finalJets"), + muons=cms.InputTag("finalMuons"), + electrons=cms.InputTag("finalElectrons"), + taus=cms.InputTag("finalTaus"), + photons=cms.InputTag("finalPhotons"), +) + +simpleCleanerTable = cms.EDProducer("NanoAODSimpleCrossCleaner", + name=cms.string("cleanmask"), + doc=cms.string("simple cleaning mask with priority to leptons"), + jets=cms.InputTag("linkedObjects","jets"), + muons=cms.InputTag("linkedObjects","muons"), + electrons=cms.InputTag("linkedObjects","electrons"), + taus=cms.InputTag("linkedObjects","taus"), + photons=cms.InputTag("linkedObjects","photons"), + jetSel=cms.string("pt>15"), + muonSel=cms.string("isPFMuon && innerTrack.validFraction >= 0.49 && ( isGlobalMuon && globalTrack.normalizedChi2 < 3 && combinedQuality.chi2LocalPosition < 12 && combinedQuality.trkKink < 20 && segmentCompatibility >= 0.303 || segmentCompatibility >= 0.451 )"), + electronSel=cms.string(""), + tauSel=cms.string(""), + photonSel=cms.string(""), + jetName=cms.string("Jet"),muonName=cms.string("Muon"),electronName=cms.string("Electron"), + tauName=cms.string("Tau"),photonName=cms.string("Photon") +) + + +genWeightsTable = cms.EDProducer("GenWeightsTableProducer", + genEvent = cms.InputTag("generator"), + lheInfo = cms.InputTag("externalLHEProducer"), + preferredPDFs = cms.vuint32(91400,260001), + namedWeightIDs = cms.vstring(), + namedWeightLabels = cms.vstring(), + lheWeightPrecision = cms.int32(14), + maxPdfWeights = cms.uint32(50), # for NNPDF, keep only the first 50 replicas (save space) + debug = cms.untracked.bool(False), +) +lheInfoTable = cms.EDProducer("LHETablesProducer", + lheInfo = cms.InputTag("externalLHEProducer"), +) + +l1bits=cms.EDProducer("L1TriggerResultsConverter", src=cms.InputTag("gtStage2Digis"), legacyL1=cms.bool(False)) + +nanoSequence = cms.Sequence( + adapt_nano + # remove when 94X MC becomes available + nanoMetadata + muonSequence + jetSequence + tauSequence + electronSequence+photonSequence+vertexSequence+#metSequence+ + isoTrackSequence + # must be after all the leptons + linkedObjects + + jetTables + muonTables + tauTables + electronTables + photonTables + globalTables +vertexTables+ metTables+simpleCleanerTable + triggerObjectTables + isoTrackTables + + l1bits) + +nanoSequenceMC = cms.Sequence(genParticleSequence + nanoSequence + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + genWeightsTable + genParticleTables + lheInfoTable) diff --git a/PhysicsTools/NanoAOD/python/photons_cff.py b/PhysicsTools/NanoAOD/python/photons_cff.py new file mode 100644 index 0000000000000..53ed6a6b4303c --- /dev/null +++ b/PhysicsTools/NanoAOD/python/photons_cff.py @@ -0,0 +1,133 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * +from math import ceil,log + +from PhysicsTools.SelectorUtils.tools.vid_id_tools import setupVIDSelection +from RecoEgamma.PhotonIdentification.egmPhotonIDs_cfi import * +from RecoEgamma.PhotonIdentification.PhotonIDValueMapProducer_cfi import * +from RecoEgamma.PhotonIdentification.PhotonMVAValueMapProducer_cfi import * +from RecoEgamma.PhotonIdentification.PhotonRegressionValueMapProducer_cfi import * +from RecoEgamma.EgammaIsolationAlgos.egmPhotonIsolationMiniAOD_cff import * +egmPhotonIDSequence = cms.Sequence(cms.Task(egmPhotonIsolationMiniAODTask,photonIDValueMapProducer,photonMVAValueMapProducer,egmPhotonIDs,photonRegressionValueMapProducer)) +egmPhotonIDs.physicsObjectIDs = cms.VPSet() +egmPhotonIDs.physicsObjectSrc = cms.InputTag('slimmedPhotons') +_photon_id_vid_modules=[ +'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff', +'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff', +] +_bitmapVIDForPho_WorkingPoints = cms.vstring( + "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose", + "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium", + "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight", +) +_bitmapVIDForPho_docstring = '' +for modname in _photon_id_vid_modules: + ids= __import__(modname, globals(), locals(), ['idName','cutFlow']) + for name in dir(ids): + _id = getattr(ids,name) + if hasattr(_id,'idName') and hasattr(_id,'cutFlow'): + setupVIDSelection(egmPhotonIDs,_id) + if (len(_bitmapVIDForPho_WorkingPoints)>0 and _id.idName==_bitmapVIDForPho_WorkingPoints[0].split(':')[-1]): + _bitmapVIDForPho_docstring = 'VID compressed bitmap (%s), %d bits per cut'%(','.join([cut.cutName.value() for cut in _id.cutFlow]),int(ceil(log(len(_bitmapVIDForPho_WorkingPoints)+1,2)))) + +bitmapVIDForPho = cms.EDProducer("PhoVIDNestedWPBitmapProducer", + src = cms.InputTag("slimmedPhotons"), + WorkingPoints = _bitmapVIDForPho_WorkingPoints, +) + +isoForPho = cms.EDProducer("PhoIsoValueMapProducer", + src = cms.InputTag("slimmedPhotons"), + rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"), + mapIsoChg = cms.InputTag("photonIDValueMapProducer:phoChargedIsolation"), + mapIsoNeu = cms.InputTag("photonIDValueMapProducer:phoNeutralHadronIsolation"), + mapIsoPho = cms.InputTag("photonIDValueMapProducer:phoPhotonIsolation"), + EAFile_PFIso_Chg = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfChargedHadrons_90percentBased.txt"), + EAFile_PFIso_Neu = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased.txt"), + EAFile_PFIso_Pho = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfPhotons_90percentBased.txt"), +) + +from EgammaAnalysis.ElectronTools.calibratedPhotonsRun2_cfi import calibratedPatPhotons +calibratedPatPhotons.correctionFile = cms.string("PhysicsTools/NanoAOD/data/80X_ichepV2_2016_pho") # hack, should go somewhere in EgammaAnalysis + +energyCorrForPhoton = cms.EDProducer("PhotonEnergyVarProducer", + srcRaw = cms.InputTag("slimmedPhotons"), + srcCorr = cms.InputTag("calibratedPatPhotons"), +) + +slimmedPhotonsWithUserData = cms.EDProducer("PATPhotonUserDataEmbedder", + src = cms.InputTag("slimmedPhotons"), + userFloats = cms.PSet( + mvaID = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRun2Spring16NonTrigV1Values"), + PFIsoChg = cms.InputTag("isoForPho:PFIsoChg"), + PFIsoAll = cms.InputTag("isoForPho:PFIsoAll"), + eCorr = cms.InputTag("energyCorrForPhoton:eCorr"), + ), + userIntFromBools = cms.PSet( + cutbasedID_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose"), + cutbasedID_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium"), + cutbasedID_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight"), + mvaID_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp90"), + mvaID_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp80"), + ), + userInts = cms.PSet( + VIDNestedWPBitmap = cms.InputTag("bitmapVIDForPho"), + ), +) + +finalPhotons = cms.EDFilter("PATPhotonRefSelector", + src = cms.InputTag("slimmedPhotonsWithUserData"), + cut = cms.string("pt > 5 ") +) + +photonTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("linkedObjects","photons"), + cut = cms.string(""), #we should not filter on cross linked collections + name= cms.string("Photon"), + doc = cms.string("slimmedPhotons after basic selection (" + finalPhotons.cut.value()+")"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the photons + variables = cms.PSet(CandVars, + jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), + electronIdx = Var("?hasUserCand('electron')?userCand('electron').key():-1", int, doc="index of the associated electron (-1 if none)"), + energyErr = Var("getCorrectedEnergyError('regression2')*userFloat('eCorr')",float,doc="energy error of the cluster from regression",precision=6), + eCorr = Var("userFloat('eCorr')",float,doc="ratio of the calibrated energy/miniaod energy"), + r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=10), + sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10), + cutBased = Var("userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",int,doc="cut-based ID (0:fail, 1::loose, 2:medium, 3:tight)"), + VIDNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')",int,doc=_bitmapVIDForPho_docstring), + electronVeto = Var("passElectronVeto()",bool,doc="pass electron veto"), + pixelSeed = Var("hasPixelSeed()",bool,doc="has pixel seed"), + mvaID = Var("userFloat('mvaID')",float,doc="MVA ID score",precision=10), + mvaID_WP90 = Var("userInt('mvaID_WP90')",bool,doc="MVA ID WP90"), + mvaID_WP80 = Var("userInt('mvaID_WP90')",bool,doc="MVA ID WP80"), + PFIso03_chg = Var("userFloat('PFIsoChg')",float,doc="PF isolation dR=0.3, charged component (with rho*EA PU corrections)"), + PFIso03_all = Var("userFloat('PFIsoAll')",float,doc="PF isolation dR=0.3, total (with rho*EA PU corrections)"), + hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8), + ) +) +photonTable.variables.pt = Var("pt*userFloat('eCorr')", float, precision=-1) + +photonsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR + src = photonTable.src, # final reco collection + matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection + mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below) + checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge + mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering) + maxDeltaR = cms.double(0.3), # Minimum deltaR for the match + maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match + resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object + resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first +) + +photonMCTable = cms.EDProducer("CandMCMatchTableProducer", + src = photonTable.src, + mcMap = cms.InputTag("photonsMCMatchForTable"), + objName = photonTable.name, + objType = photonTable.name, #cms.string("Photon"), + branchName = cms.string("mcMatch"), + docString = cms.string("MC matching to status==1 photons or electrons"), +) + +photonSequence = cms.Sequence(egmPhotonIDSequence + bitmapVIDForPho + isoForPho + calibratedPatPhotons + energyCorrForPhoton + slimmedPhotonsWithUserData + finalPhotons) +photonTables = cms.Sequence ( photonTable) +photonMC = cms.Sequence(photonsMCMatchForTable + photonMCTable) diff --git a/PhysicsTools/NanoAOD/python/taus_cff.py b/PhysicsTools/NanoAOD/python/taus_cff.py new file mode 100644 index 0000000000000..31f98270fc8f9 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/taus_cff.py @@ -0,0 +1,139 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * +from PhysicsTools.JetMCAlgos.TauGenJets_cfi import tauGenJets +from PhysicsTools.JetMCAlgos.TauGenJetsDecayModeSelectorAllHadrons_cfi import tauGenJetsSelectorAllHadrons + + +##################### User floats producers, selectors ########################## + + +finalTaus = cms.EDFilter("PATTauRefSelector", + src = cms.InputTag("slimmedTaus"), + cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || tauID('byVLooseIsolationMVArun2v1DBoldDMwLT') || tauID('byVLooseIsolationMVArun2v1DBnewDMwLT') || tauID('byVLooseIsolationMVArun2v1DBdR03oldDMwLT'))") +) + +##################### Tables for final output and docs ########################## +def _tauIdWPMask(pattern, choices, doc=""): + return Var(" + ".join(["%d * tauID('%s')" % (pow(2,i), pattern % c) for (i,c) in enumerate(choices)]), "uint8", + doc=doc+": bitmask "+", ".join(["%d = %s" % (pow(2,i),c) for (i,c) in enumerate(choices)])) +def _tauId2WPMask(pattern,doc): + return _tauIdWPMask(pattern,choices=("Loose","Tight"),doc=doc) +def _tauId5WPMask(pattern,doc): + return _tauIdWPMask(pattern,choices=("VLoose","Loose","Medium","Tight","VTight"),doc=doc) +def _tauId6WPMask(pattern,doc): + return _tauIdWPMask(pattern,choices=("VLoose","Loose","Medium","Tight","VTight","VVTight"),doc=doc) + + +tauTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("linkedObjects","taus"), + cut = cms.string(""), #we should not filter on cross linked collections + name= cms.string("Tau"), + doc = cms.string("slimmedTaus after basic selection (" + finalTaus.cut.value()+")"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the taus + variables = cms.PSet(P4Vars, + charge = Var("charge", int, doc="electric charge"), + jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), + decayMode = Var("decayMode()",int), + idDecayMode = Var("tauID('decayModeFinding')", bool), + idDecayModeNewDMs = Var("tauID('decayModeFindingNewDMs')", bool), + + leadTkPtOverTauPt = Var("leadChargedHadrCand.pt/pt ",float, doc="pt of the leading track divided by tau pt",precision=10), + leadTkDeltaEta = Var("leadChargedHadrCand.eta - eta ",float, doc="eta of the leading track, minus tau eta",precision=8), + leadTkDeltaPhi = Var("deltaPhi(leadChargedHadrCand.phi, phi) ",float, doc="phi of the leading track, minus tau phi",precision=8), + + dxy = Var("dxy()",float, doc="d_{xy} of lead track with respect to PV, in cm (with sign)",precision=10), + dz = Var("leadChargedHadrCand().dz() ",float, doc="d_{z} of lead track with respect to PV, in cm (with sign)",precision=14), + + # these are too many, we may have to suppress some + rawIso = Var( "tauID('byCombinedIsolationDeltaBetaCorrRaw3Hits')", float, doc = "combined isolation (deltaBeta corrections)", precision=10), + chargedIso = Var( "tauID('chargedIsoPtSum')", float, doc = "charged isolation", precision=10), + neutralIso = Var( "tauID('neutralIsoPtSum')", float, doc = "neutral (photon) isolation", precision=10), + puCorr = Var( "tauID('puCorrPtSum')", float, doc = "pileup correction", precision=10), + footprintCorr = Var( "tauID('footprintCorrection')", float, doc = "footprint correction", precision=10), + photonsOutsideSignalCone = Var( "tauID('photonPtSumOutsideSignalCone')", float, doc = "sum of photons outside signal cone", precision=10), + + rawMVAnewDM = Var( "tauID('byIsolationMVArun2v1DBnewDMwLTraw')",float, doc="byIsolationMVArun2v1DBnewDMwLT raw output discriminator",precision=10), + rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator",precision=10), + rawMVAoldDMdR03 = Var( "tauID('byIsolationMVArun2v1DBdR03oldDMwLTraw')",float, doc="byIsolationMVArun2v1DBdR03oldDMwLT raw output discriminator",precision=10), + rawAntiEle = Var("tauID('againstElectronMVA6Raw')", float, doc= "Anti-electron MVA discriminator V6 raw output discriminator", precision=10), + rawAntiEleCat = Var("tauID('againstElectronMVA6category')", int, doc="Anti-electron MVA discriminator V6 category"), + + idAntiMu = _tauId2WPMask("againstMuon%s3", doc= "Anti-muon discriminator V3: "), + idAntiEle = _tauId5WPMask("againstElectron%sMVA6", doc= "Anti-electron MVA discriminator V6"), + idMVAnewDM = _tauId6WPMask( "by%sIsolationMVArun2v1DBnewDMwLT", doc="IsolationMVArun2v1DBnewDMwLT ID working point"), + idMVAoldDM = _tauId6WPMask( "by%sIsolationMVArun2v1DBoldDMwLT", doc="IsolationMVArun2v1DBoldDMwLT ID working point"), + idMVAoldDMdR03 = _tauId6WPMask( "by%sIsolationMVArun2v1DBdR03oldDMwLT", doc="IsolationMVArun2v1DBdR03oldDMwLT ID working point"), + + +# isoCI3hit = Var( "tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits")" doc="byCombinedIsolationDeltaBetaCorrRaw3Hits raw output discriminator"), +# photonOutsideSigCone = Var( "tauID("photonPtSumOutsideSignalCone")" doc="photonPtSumOutsideSignalCone raw output discriminator"), + + + ) +) + +tauGenJets.GenParticles = cms.InputTag("prunedGenParticles") +tauGenJets.includeNeutrinos = cms.bool(False) + +genVisTaus = cms.EDProducer("GenVisTauProducer", + src = cms.InputTag("tauGenJetsSelectorAllHadrons"), + srcGenParticles = cms.InputTag("prunedGenParticles") +) + +genVisTauTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("genVisTaus"), + cut = cms.string("pt > 10."), + name= cms.string("GenVisTau"), + doc = cms.string("gen hadronic taus "), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for generator level hadronic tau decays + variables = cms.PSet( + pt = Var("pt", float,precision=8), + phi = Var("phi", float,precision=8), + eta = Var("eta", float,precision=8), + pdgId = Var("pdgId", int, doc="PDG id"), + status = Var("status", int, doc="Hadronic tau decay mode. 0=OneProng0PiZero, 1=OneProng1PiZero, 2=OneProng2PiZero, 10=ThreeProng0PiZero, 11=ThreeProng1PiZero, 15=Other"), + genPartIdxMother = Var("?numberOfMothers>0?motherRef(0).key():-1", int, doc="index of the mother particle"), + ) +) + +tausMCMatchLepTauForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR + src = tauTable.src, # final reco collection + matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection + mcPdgId = cms.vint32(11,13), # one or more PDG ID (11 = electron, 13 = muon); absolute values (see below) + checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge + mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering) + maxDeltaR = cms.double(0.3), # Minimum deltaR for the match + maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match + resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object + resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first +) + +tausMCMatchHadTauForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR + src = tauTable.src, # final reco collection + matched = cms.InputTag("genVisTaus"), # generator level hadronic tau decays + mcPdgId = cms.vint32(15), # one or more PDG ID (15 = tau); absolute values (see below) + checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge + mcStatus = cms.vint32(), # CV: no *not* require certain status code for matching (status code corresponds to decay mode for hadronic tau decays) + maxDeltaR = cms.double(0.3), # Maximum deltaR for the match + maxDPtRel = cms.double(1.), # Maximum deltaPt/Pt for the match + resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object + resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first +) + +tauMCTable = cms.EDProducer("CandMCMatchTableProducer", + src = tauTable.src, + mcMap = cms.InputTag("tausMCMatchLepTauForTable"), + mcMapVisTau = cms.InputTag("tausMCMatchHadTauForTable"), + objName = tauTable.name, + objType = tauTable.name, #cms.string("Tau"), + branchName = cms.string("mcMatch"), + docString = cms.string("MC matching to status==2 taus"), +) + + +tauSequence = cms.Sequence(finalTaus) +tauTables = cms.Sequence(tauTable) +tauMC = cms.Sequence(tauGenJets + tauGenJetsSelectorAllHadrons + genVisTaus + genVisTauTable + tausMCMatchLepTauForTable + tausMCMatchHadTauForTable + tauMCTable) + diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py new file mode 100644 index 0000000000000..3ac7bb1da9449 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -0,0 +1,82 @@ +import FWCore.ParameterSet.Config as cms + +unpackedPatTrigger = cms.EDProducer("PATTriggerObjectStandAloneUnpacker", + patTriggerObjectsStandAlone = cms.InputTag('slimmedPatTrigger'), + triggerResults = cms.InputTag('TriggerResults::HLT'), + unpackFilterLabels = cms.bool(True) +) + +triggerObjectTable = cms.EDProducer("TriggerObjectTableProducer", + name= cms.string("TrigObj"), + src = cms.InputTag("unpackedPatTrigger"), + selections = cms.VPSet( + cms.PSet( + name = cms.string("Electron (PixelMatched e/gamma)"), # this selects also photons for the moment! + id = cms.int32(11), + sel = cms.string("type(92) && pt > 7 && coll('hltEgammaCandidates') && filter('*PixelMatchFilter')"), + l1seed = cms.string("type(-98) && coll('hltGtStage2Digis:EGamma')"), l1deltaR = cms.double(0.3), + #l2seed = cms.string("type(92) && coll('')"), l2deltaR = cms.double(0.5), + qualityBits = cms.string("filter('*CaloIdLTrackIdLIsoVL*TrackIso*Filter') + 2*filter('hltEle*WPTight*TrackIsoFilter') + 4*filter('hltEle*WPLoose*TrackIsoFilter')"), + qualityBitsDoc = cms.string("1 = CaloIdL_TrackIdL_IsoVL, 2 = WPLoose, 4 = WPTight"), + ), + cms.PSet( + name = cms.string("Photon (PixelMatch-vetoed e/gamma)"), + id = cms.int32(22), + sel = cms.string("type(92) && pt > 20 && coll('hltEgammaCandidates') && !filter('*PixelMatchFilter')"), + l1seed = cms.string("type(-98) && coll('hltGtStage2Digis:EGamma')"), l1deltaR = cms.double(0.3), + #l2seed = cms.string("type(92) && coll('')"), l2deltaR = cms.double(0.5), + qualityBits = cms.string("0"), qualityBitsDoc = cms.string(""), + ), + cms.PSet( + name = cms.string("Muon"), + id = cms.int32(13), + sel = cms.string("type(83) && pt > 5 && coll('hltIterL3MuonCandidates')"), + l1seed = cms.string("type(-81) && coll('hltGtStage2Digis:Muon')"), l1deltaR = cms.double(0.5), + l2seed = cms.string("type(83) && coll('hltL2MuonCandidates')"), l2deltaR = cms.double(0.3), + qualityBits = cms.string("filter('*RelTrkIsoVVLFiltered0p4') + 2*filter('hltL3crIso*Filtered')"), qualityBitsDoc = cms.string("1 = TrkIsoVVL, 2 = Iso"), + ), + cms.PSet( + name = cms.string("Tau"), + id = cms.int32(14), + sel = cms.string("type(84) && pt > 5 && coll('hltPFTaus')"), + l1seed = cms.string("type(-100) && coll('hltGtStage2Digis:Tau')"), l1deltaR = cms.double(0.3), + l2seed = cms.string("type(84) && coll('hltL2TauJetsL1IsoTauSeeded')"), l2deltaR = cms.double(0.3), + qualityBits = cms.string("0"), qualityBitsDoc = cms.string(""), + ), + cms.PSet( + name = cms.string("Jet"), + id = cms.int32(1), + sel = cms.string("type(85) && pt > 30 && coll('hltAK4PFJetsCorrected')"), + l1seed = cms.string("type(-99) && coll('hltGtStage2Digis:Jet')"), l1deltaR = cms.double(0.3), + l2seed = cms.string("type(85) && coll('hltAK4CaloJetsCorrectedIDPassed')"), l2deltaR = cms.double(0.3), + qualityBits = cms.string("0"), qualityBitsDoc = cms.string(""), + ), + cms.PSet( + name = cms.string("MET"), + id = cms.int32(2), + sel = cms.string("type(87) && pt > 30 && coll('hltPFMETProducer')"), + l1seed = cms.string("type(-87) && coll('hltGtStage2Digis:EtSum')"), l1deltaR = cms.double(9999), + l2seed = cms.string("type( 87) && coll('hltMetClean')"), l2deltaR = cms.double(9999), + qualityBits = cms.string("0"), qualityBitsDoc = cms.string(""), + ), + cms.PSet( + name = cms.string("HT"), + id = cms.int32(3), + sel = cms.string("type(89) && pt > 100 && coll('hltPFHTJet30')"), + l1seed = cms.string("type(-89) && coll('hltGtStage2Digis:EtSum')"), l1deltaR = cms.double(9999), + #l2seed = cms.string("type(89) && coll('hltHtMhtJet30')"), l2deltaR = cms.double(9999), + qualityBits = cms.string("0"), qualityBitsDoc = cms.string(""), + ), + cms.PSet( + name = cms.string("MHT"), + id = cms.int32(4), + sel = cms.string("type(90) && pt > 30 && coll('hltPFMHTTightID')"), + l1seed = cms.string("type(-90) && coll('hltGtStage2Digis:EtSum')"), l1deltaR = cms.double(9999), + #l2seed = cms.string("type(90) && coll('hltHtMhtJet30')"), l2deltaR = cms.double(9999), + qualityBits = cms.string("0"), qualityBitsDoc = cms.string(""), + ), + + ), +) + +triggerObjectTables = cms.Sequence( unpackedPatTrigger + triggerObjectTable ) diff --git a/PhysicsTools/NanoAOD/python/vertices_cff.py b/PhysicsTools/NanoAOD/python/vertices_cff.py new file mode 100644 index 0000000000000..bfb261f8ecd7b --- /dev/null +++ b/PhysicsTools/NanoAOD/python/vertices_cff.py @@ -0,0 +1,44 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * + + + +##################### User floats producers, selectors ########################## + + + +##################### Tables for final output and docs ########################## +vertexTable = cms.EDProducer("VertexTableProducer", + pvSrc = cms.InputTag("offlineSlimmedPrimaryVertices"), + svSrc = cms.InputTag("slimmedSecondaryVertices"), + svCut = cms.string(""), + dlenMin = cms.double(0), + dlenSigMin = cms.double(3), + pvName = cms.string("PV"), + svName = cms.string("SV"), + svDoc = cms.string("secondary vertices from IVF algorithm"), +) + +svCandidateTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("vertexTable"), + cut = cms.string(""), #DO NOT further cut here, use vertexTable.svCut + name = cms.string("SV"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(True), + variables = cms.PSet(P4Vars, + x = Var("position().x()", float, doc = "secondary vertex X position, in cm",precision=10), + y = Var("position().y()", float, doc = "secondary vertex Y position, in cm",precision=10), + z = Var("position().z()", float, doc = "secondary vertex Z position, in cm",precision=14), + ndof = Var("vertexNdof()", float, doc = "number of degrees of freedom",precision=8), + chi2 = Var("vertexNormalizedChi2()", float, doc = "reduced chi2, i.e. chi/ndof",precision=8), + ), +) +svCandidateTable.variables.pt.precision=10 +svCandidateTable.variables.phi.precision=12 + + +#before cross linking +vertexSequence = cms.Sequence() +#after cross linkining +vertexTables = cms.Sequence( vertexTable+svCandidateTable) + diff --git a/PhysicsTools/NanoAOD/src/FlatTable.cc b/PhysicsTools/NanoAOD/src/FlatTable.cc new file mode 100644 index 0000000000000..1064a88a755fd --- /dev/null +++ b/PhysicsTools/NanoAOD/src/FlatTable.cc @@ -0,0 +1,8 @@ +#include + +int FlatTable::columnIndex(const std::string & name) const { + for (unsigned int i = 0, n = columns_.size(); i < n; ++i) { + if (columns_[i].name == name) return i; + } + return -1; +} diff --git a/PhysicsTools/NanoAOD/src/MergeableCounterTable.cc b/PhysicsTools/NanoAOD/src/MergeableCounterTable.cc new file mode 100644 index 0000000000000..8cce957930955 --- /dev/null +++ b/PhysicsTools/NanoAOD/src/MergeableCounterTable.cc @@ -0,0 +1 @@ +#include "PhysicsTools/NanoAOD/interface/MergableCounterTable.h" diff --git a/PhysicsTools/NanoAOD/src/classes.h b/PhysicsTools/NanoAOD/src/classes.h new file mode 100644 index 0000000000000..38e742bf9d2f5 --- /dev/null +++ b/PhysicsTools/NanoAOD/src/classes.h @@ -0,0 +1,14 @@ +#include "Rtypes.h" + +#include +#include +#include +#include "DataFormats/Common/interface/Wrapper.h" + +namespace PhysicsTools_NanoAOD { + struct dictionary { + edm::Wrapper w_table; + edm::Wrapper w_mtable; + edm::Wrapper w_ustr; + }; +} diff --git a/PhysicsTools/NanoAOD/src/classes_def.xml b/PhysicsTools/NanoAOD/src/classes_def.xml new file mode 100644 index 0000000000000..3a0e14a1457be --- /dev/null +++ b/PhysicsTools/NanoAOD/src/classes_def.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PhysicsTools/NanoAOD/test/crab_mc.py b/PhysicsTools/NanoAOD/test/crab_mc.py new file mode 100644 index 0000000000000..b619ff4b4a3fa --- /dev/null +++ b/PhysicsTools/NanoAOD/test/crab_mc.py @@ -0,0 +1,22 @@ +from CRABClient.UserUtilities import config, getUsernameFromSiteDB +config = config() + +config.General.requestName = 'nano6' +config.General.workArea = 'crab_projects' +config.General.transferOutputs = True +config.General.transferLogs = True + +config.JobType.pluginName = 'Analysis' +config.JobType.psetName = 'nano_80x_cfg.py' +#config.JobType.outputFiles = ['lzma.root'] + +config.Data.inputDataset = '/TT_TuneCUETP8M2T4_13TeV-powheg-pythia8/RunIISummer16MiniAODv2-PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6-v1/MINIAODSIM' +config.Data.inputDBS = 'global' +config.Data.splitting = 'EventAwareLumiBased' +config.Data.unitsPerJob = 2000 +config.Data.totalUnits = 6000 +config.Data.outLFNDirBase = '/store/user/%s/NanoTest/' % (getUsernameFromSiteDB()) +config.Data.publication = True +config.Data.outputDatasetTag = 'NanoTest2' + +config.Site.storageSite = 'T2_IT_Pisa' diff --git a/PhysicsTools/NanoAOD/test/nano_cfg.py b/PhysicsTools/NanoAOD/test/nano_cfg.py new file mode 100644 index 0000000000000..343582537975a --- /dev/null +++ b/PhysicsTools/NanoAOD/test/nano_cfg.py @@ -0,0 +1,57 @@ +import FWCore.ParameterSet.Config as cms +process = cms.Process('NANO') + +process.load("FWCore.MessageLogger.MessageLogger_cfi") + +process.load("Configuration.StandardSequences.GeometryDB_cff") +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") +process.load('Configuration.StandardSequences.Services_cff') +from Configuration.AlCa.autoCond import autoCond +process.GlobalTag.globaltag = autoCond['run2_mc'] + +process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) ) +process.MessageLogger.cerr.FwkReport.reportEvery = 100 +process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(10000)) + +process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring()) +process.source.fileNames = [ +#relvals: +# '/store/relval/CMSSW_9_3_0_pre4/RelValTTbar_13/MINIAODSIM/93X_mc2017_realistic_v1-v1/00000/1CFF7C9C-6A86-E711-A1F2-0CC47A7C35F4.root', +# '/store/relval/CMSSW_9_3_0_pre4/RelValTTbar_13/MINIAODSIM/93X_mc2017_realistic_v1-v1/00000/107D499F-6A86-E711-8A51-0025905B8592.root', + +#sample with LHE + '/store/mc/RunIISummer17MiniAOD/TT_TuneCUETP8M2T4_13TeV-powheg-pythia8/MINIAODSIM/92X_upgrade2017_realistic_v10_ext1-v1/110000/187F7EDA-0986-E711-ABB3-02163E014C21.root' +] + +process.load("PhysicsTools.NanoAOD.nano_cff") + +process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService", + calibratedPatElectrons = cms.PSet(initialSeed = cms.untracked.uint32(81), + engineName = cms.untracked.string('TRandom3'), + ), + calibratedPatPhotons = cms.PSet(initialSeed = cms.untracked.uint32(81), + engineName = cms.untracked.string('TRandom3'), + ), +) +process.nanoPath = cms.Path(process.nanoSequenceMC) +process.calibratedPatElectrons.isMC = cms.bool(True) +process.calibratedPatPhotons.isMC = cms.bool(True) +#for data: +#process.nanoPath = cms.Path(process.nanoSequence) +#process.GlobalTag.globaltag = autoCond['run2_data'] + +process.out = cms.OutputModule("NanoAODOutputModule", + fileName = cms.untracked.string('nano.root'), + outputCommands = process.NanoAODEDMEventContent.outputCommands, + #compressionLevel = cms.untracked.int32(9), + #compressionAlgorithm = cms.untracked.string("LZMA"), + +) +process.out1 = cms.OutputModule("NanoAODOutputModule", + fileName = cms.untracked.string('lzma.root'), + outputCommands = process.NanoAODEDMEventContent.outputCommands, + compressionLevel = cms.untracked.int32(9), + compressionAlgorithm = cms.untracked.string("LZMA"), + +) +process.end = cms.EndPath(process.out+process.out1) diff --git a/PhysicsTools/NanoAOD/test/treeSize.py b/PhysicsTools/NanoAOD/test/treeSize.py new file mode 100644 index 0000000000000..17e34d5d05dc1 --- /dev/null +++ b/PhysicsTools/NanoAOD/test/treeSize.py @@ -0,0 +1,243 @@ +#!/usr/bin/env python + +import sys, os.path +from collections import defaultdict +import ROOT +ROOT.PyConfig.IgnoreCommandLineOptions = True +ROOT.gROOT.SetBatch(True) + +## Tool to dig out information about the event size in NanoAOD +## +## Please run this giving as argument the root file, and redirecting the output on an HTML file +## Notes: +## - you must have a correctly initialized environment, and FWLite auto-loading with ROOT +## - you must put in the same folder of the html also these three files: +## http://cern.ch/gpetrucc/patsize.css +## http://cern.ch/gpetrucc/blue-dot.gif +## http://cern.ch/gpetrucc/red-dot.gif +## otherwise you will get an unreadable output file + +infile = sys.argv[1] +if not os.path.isfile(infile): raise RuntimeError +filesize = os.path.getsize(infile)/1024.0 +class Branch: + def __init__(self, tree, branch): + self.tree = tree + self.branch = branch + self.name = branch.GetName() + self.tot = branch.GetZipBytes()/1024.0 + self.entries = None; + self.single = True + self.kind = "Unknown" + if branch.GetNleaves() != 1: + sys.stderr.write("Cannot parse branch '%s' in tree %s (%d leaves)\n", tree.GetName(), branch.GetName(), branch.GetNleaves()) + return + self.leaf = branch.FindLeaf(branch.GetName()) + if not self.leaf: + sys.stderr.write("Cannot parse branch '%s' in tree %s (no leaf)\n", tree.GetName(), branch.GetName()) + return + self.kind = self.leaf.GetTypeName() + if self.leaf.GetLen() == 0 and self.leaf.GetLeafCount() != None: + self.single = False + self.counter = self.leaf.GetLeafCount().GetName() + +class BranchGroup: + def __init__(self, name): + self.name = name + self.tot = 0 + self.entries = None; + self.subs = [] + self.kind = None + def append(self, sub): + self.subs.append(sub) + self.tot += sub.tot + def getKind(self): + if self.kind: return self.kind + if len(self.subs) == 1: + if self.subs[0].single: self.kind = "Variable" + else: + self.kind = "Vector" + self.counter = self.subs[0].counter + else: + allsingles, commonCounter = True, True + counter = None + for s in self.subs: + if not s.single: + allsingles = False + if counter == None: counter = s.counter + elif counter != s.counter: + commonCounter = False + if allsingles: + self.kind = "Singleton" + elif commonCounter: + self.kind = "Collection" + self.counter = counter + else: + self.kind = "ItsComplicated" + return self.kind +tfile = ROOT.TFile.Open(infile) +trees = {} +branches = {} +for treeName in "Events", "Runs", "Lumis": + tree = tfile.Get(treeName) + entries = tree.GetEntries() + trees[treeName] = tree + branchList = tree.GetListOfBranches() + allbranches = [ Branch(tree,branchList.At(i)) for i in xrange(branchList.GetSize()) ] + branchmap = dict((b.name,b) for b in allbranches) + branchgroups = {} + # make list of counters and countees + counters = defaultdict(list) + for b in allbranches: + if not b.single: + counters[b.counter].append(b.name) + else: + b.entries = entries + c1 = ROOT.TCanvas("c1","c1") + for counter,countees in counters.iteritems(): + n = tree.Draw(counter+">>htemp") + if n != 0: + htemp = ROOT.gROOT.FindObject("htemp") + n = htemp.GetEntries() * htemp.GetMean() + htemp.Delete() + branchmap[counter]._entries = entries + for c in countees: + br = branchmap[c] + br.entries = n + # now we start to create branch groups + for b in allbranches: + if b.name in counters: continue # skip counters + if "_" in b.name: + head, tail = b.name.split("_",1) + else: + head = b.name + if head not in branchgroups: + branchgroups[head] = BranchGroup(head) + branchgroups[head].append(b) + for bg in branchgroups.itervalues(): + kind = bg.getKind() + bg.entries = bg.subs[0].entries + if kind == "Vector" or kind == "Collection": + bg.append(branchmap[bg.counter]) + elif kind == "ItsComplicated": + for counter in set(s.counter for s in bg.subs if not s.single): + bg.append(branchmap[counter]) + allsize_c = sum(b.tot for b in allbranches) + allsize = sum(b.tot for b in branchgroups.itervalues()) + if abs(allsize_c - allsize) > 1e-6*(allsize_c+allsize): + sys.stderr.write("Total size mismatch for tree %s: %10.4f kb vs %10.4f kb\n" % (treeName, allsize, allsize_c)) + tree.allsize = allsize + tree.entries = entries + tree.survey = list(branchgroups.itervalues()) + tree.survey.sort(key = lambda bg : - bg.tot) + scriptdata = [] + runningtotal = 0 + unit = treeName[:-1].lower() + for s in tree.survey: + if s.tot < 0.01*allsize: + tag = "Others
Size: %.0f b/%s (%.1f%%)" % ((allsize - runningtotal)/entries*1024, unit, (allsize-runningtotal)/allsize*100) + scriptdata.append( "{ 'label':'others', 'tag':'top', 'size':%s, 'tip':'%s' }" % ((allsize-runningtotal)/entries, tag) ) + break + else: + tag = "%s
" % (s.name, s.name); + tag += "Size: %.0f b/%s (%.1f%%)" % (s.tot/entries*1024, unit, s.tot/allsize*100); + if (s.getKind() in ("Vector","Collection")): + tag += "
Items/%s: %.1f, %.0f b/item" %(unit, float(s.entries)/entries, s.tot/s.entries*1024); + scriptdata.append( "{ 'label':'%s', 'tag':'%s', 'size':%s, 'tip':'%s' }" % ( s.name, s.name, s.tot/entries, tag) ) + runningtotal += s.tot + tree.scriptdata = "\n,\t".join(scriptdata) + break # let's do only Events for now + +events = trees["Events"].entries +sizeline = "%.3f Mb, %d events, %.2f kb/event" % ( filesize/1024.0, events, filesize/events) +print """ + + + {filename} : size ({allsize}) + + + + + + + + +

Summary ({allsize})

+[No canvas support] + +

Event data

+ +""" +print ""; +grandtotal = trees["Events"].allsize; runningtotal = 0 +for s in trees["Events"].survey: + print "" % (s.name,s.name,s.getKind().lower(),len(s.subs)), + print "" % (s.entries/events, s.tot/events, s.tot/s.entries*1024 if s.entries else 0), + print "" % (s.tot/grandtotal*200,10), + print "" % ( s.tot/grandtotal * 100.0), + print "" % ( (runningtotal+s.tot)/grandtotal * 100.0), + print "" % ( (grandtotal-runningtotal)/grandtotal * 100.0), + print ""; + runningtotal += s.tot; + +# all known data +print "", +print "" % (grandtotal/events), +print "" % (grandtotal/filesize*100.0), +print ""; + +# other, unknown overhead +print "", +print "" % ( (filesize-grandtotal)/events), +print "" % ( (filesize-grandtotal)/filesize * 100, 10 ), +print "" % ( (filesize-grandtotal)/filesize * 100.0 ), +print "" + +# all file +print "", +print "" % (filesize/events), +print "\n"; + +print """ +
" + "".join([ "collection", "kind", "vars", "items/evt", "kb/evt", "b/item", "plot", "%" ]) + "cumulative %
%s%s%d%.2f%.3f%.1f%.1f%%%.1f%%%.1f%%
All Event data   %.2f " % ( grandtotal/filesize*100.0), +print "%.1f%%a
Non per-event data or overhead   %.2f %.1f%%a
File size   %.2f   
+Note: size percentages of individual event products are relative to the total size of Event data only.
+Percentages with a are instead relative to the full file size. +

Events detail

+""" +for s in sorted(trees["Events"].survey, key = lambda s : s.name): + print "

%s (%.1f items/evt, %.3f kb/evt)

" % (s.name, s.name, s.name, s.entries/events, s.tot/events) + print "" + print "" + for b in sorted(s.subs, key = lambda s : - s.tot): + print "" % (b.name, b.kind, b.tot/events*1024, b.tot/s.entries*1024), + print "" % ( b.tot/s.tot*200, 10 ), + print "" % (b.tot/s.tot * 100.0), + print "" + print "
" + "".join( [ "branch", "kind", "b/event", "b/item", "plot", "%" ]) + "
%s%s%.1f%.1f%.1f%%
" +print """ + +""" From 06da61b76e625cb99df601a68e0070932928c768 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 18 Sep 2017 17:03:03 +0200 Subject: [PATCH 02/36] scram code-checks of PhysicsTools/NanoAOD --- .../NanoAOD/plugins/BJetEnergyRegressionMVA.cc | 8 ++++---- .../NanoAOD/plugins/BaseMVAValueMapProducer.h | 8 ++++---- .../NanoAOD/plugins/CandMCMatchTableProducer.cc | 2 +- .../NanoAOD/plugins/EGMEnergyVarProducer.cc | 4 ++-- .../NanoAOD/plugins/FilterValueMapWrapper.h | 4 ++-- PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc | 2 +- .../NanoAOD/plugins/GenWeightsTableProducer.cc | 2 +- .../plugins/GlobalVariablesTableProducer.cc | 4 ++-- .../NanoAOD/plugins/IsoValueMapProducer.cc | 4 ++-- .../NanoAOD/plugins/IsolatedTrackCleaner.cc | 2 +- .../NanoAOD/plugins/L1TriggerResultsConverter.cc | 4 ++-- PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc | 2 +- .../NanoAOD/plugins/LeptonJetVarProducer.cc | 4 ++-- PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc | 4 ++-- .../NanoAOD/plugins/MuonIDTableProducer.cc | 2 +- .../NanoAOD/plugins/NanoAODBaseCrossCleaner.h | 8 ++++---- .../NanoAOD/plugins/NanoAODOutputModule.cc | 14 +++++++------- .../NanoAOD/plugins/NanoAODSimpleCrossCleaner.cc | 4 ++-- .../NanoAOD/plugins/NativeArrayTableProducer.cc | 2 +- .../NanoAOD/plugins/PATObjectCrossLinker.cc | 8 ++++---- .../NanoAOD/plugins/PATObjectUserDataEmbedder.cc | 4 ++-- .../NanoAOD/plugins/SimpleFlatTableProducer.cc | 8 ++++---- .../NanoAOD/plugins/TriggerObjectTableProducer.cc | 2 +- .../NanoAOD/plugins/TriggerOutputBranches.cc | 6 +++--- .../NanoAOD/plugins/UniqueStringProducer.cc | 2 +- .../NanoAOD/plugins/VIDNestedWPBitmapProducer.cc | 8 ++++---- .../NanoAOD/plugins/VertexTableProducer.cc | 8 ++++---- 27 files changed, 65 insertions(+), 65 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc b/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc index de32ac6e7ad5f..fd8ca8cb9228c 100644 --- a/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc +++ b/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc @@ -39,20 +39,20 @@ class BJetEnergyRegressionMVA : public BaseMVAValueMapProducer { } - virtual void readAdditionalCollections(edm::Event&iEvent, const edm::EventSetup&) override { + void readAdditionalCollections(edm::Event&iEvent, const edm::EventSetup&) override { iEvent.getByToken(pvsrc_, pvs_); iEvent.getByToken(svsrc_, svs_); } - virtual void fillAdditionalVariables(const pat::Jet&j) override { + void fillAdditionalVariables(const pat::Jet&j) override { this->setValue("nPVs",pvs_->size()); BaseMVAValueMapProducer::setValue("Jet_leptonPtRel",0); - if(j.overlaps("muons").size() >0) { + if(!j.overlaps("muons").empty()) { const auto *lep=dynamic_cast(&*j.overlaps("muons")[0]); if(lep!=nullptr) {BaseMVAValueMapProducer::setValue("Jet_leptonPtRel",lep->userFloat("ptRel"));} } - else if(j.overlaps("electrons").size() >0) { + else if(!j.overlaps("electrons").empty()) { const auto *lep=dynamic_cast(&*j.overlaps("electrons")[0]); if(lep!=nullptr) {BaseMVAValueMapProducer::setValue("Jet_leptonPtRel",lep->userFloat("ptRel"));} } diff --git a/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h b/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h index e7e45da4871e7..8818ad25427cc 100644 --- a/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h +++ b/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h @@ -69,7 +69,7 @@ class BaseMVAValueMapProducer : public edm::stream::EDProducer<> { produces>(); } - ~BaseMVAValueMapProducer() {} + ~BaseMVAValueMapProducer() override {} void setValue(const std::string var,float val) { values_[positions_[var]]=val; @@ -79,9 +79,9 @@ class BaseMVAValueMapProducer : public edm::stream::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void beginStream(edm::StreamID) override {}; - virtual void produce(edm::Event&, const edm::EventSetup&) override; - virtual void endStream() override {}; + void beginStream(edm::StreamID) override {}; + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override {}; ///to be implemented in derived classes, filling values for additional variables virtual void readAdditionalCollections(edm::Event&, const edm::EventSetup&) {} diff --git a/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc b/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc index 15a02356a2fa3..517bb9b24cbdf 100644 --- a/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc @@ -45,7 +45,7 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> { } } - virtual ~CandMCMatchTableProducer() {} + ~CandMCMatchTableProducer() override {} void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { diff --git a/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc b/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc index f13c700eb6808..6e111542be19d 100644 --- a/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc @@ -49,12 +49,12 @@ class EGMEnergyVarProducer : public edm::global::EDProducer<> { { produces>("eCorr"); } - ~EGMEnergyVarProducer() {}; + ~EGMEnergyVarProducer() override {}; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; // ----------member data --------------------------- diff --git a/PhysicsTools/NanoAOD/plugins/FilterValueMapWrapper.h b/PhysicsTools/NanoAOD/plugins/FilterValueMapWrapper.h index 669b7bc3ed28c..4c13752d5faa1 100644 --- a/PhysicsTools/NanoAOD/plugins/FilterValueMapWrapper.h +++ b/PhysicsTools/NanoAOD/plugins/FilterValueMapWrapper.h @@ -29,9 +29,9 @@ namespace edm { produces>(); } /// default destructor - virtual ~FilterValueMapWrapper(){} + ~FilterValueMapWrapper() override{} /// everything which has to be done during the event loop. NOTE: We can't use the eventSetup in FWLite so ignore it - virtual void produce(edm::Event& event, const edm::EventSetup& eventSetup) override { + void produce(edm::Event& event, const edm::EventSetup& eventSetup) override { // create a collection of the objects to put into the event auto objsToPut = std::make_unique(); // get the handle to the objects in the event. diff --git a/PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc b/PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc index 3faefaf961c35..2da65fa1344f7 100644 --- a/PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc @@ -25,7 +25,7 @@ class GenVisTauProducer : public edm::global::EDProducer<> produces(); } - virtual ~GenVisTauProducer() {} + ~GenVisTauProducer() override {} void produce(edm::StreamID id, edm::Event& evt, const edm::EventSetup& es) const override { diff --git a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc index a7dbc7ee02e1e..4dc8f10774554 100644 --- a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc @@ -126,7 +126,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer { produces(); } - virtual ~GlobalVariablesTableProducer() {} + ~GlobalVariablesTableProducer() override {} void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override { auto out = std::make_unique(1, "", true); @@ -111,7 +111,7 @@ class GlobalVariablesTableProducer : public edm::stream::EDProducer<> { public: VariableT(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg, edm::ConsumesCollector && cc) : Variable(aname, atype, cfg), src_(cc.consumes(cfg.getParameter("src"))) {} - ~VariableT() {} + ~VariableT() override {} void fill(const edm::Event &iEvent, FlatTable & out) const override { edm::Handle handle; iEvent.getByToken(src_, handle); diff --git a/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc b/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc index ff359a2834be2..c6a27d76457bf 100644 --- a/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc @@ -71,13 +71,13 @@ class IsoValueMapProducer : public edm::global::EDProducer<> { rho_pfiso_ = consumes(iConfig.getParameter("rho_PFIso")); } } - ~IsoValueMapProducer() {} + ~IsoValueMapProducer() override {} static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; // ----------member data --------------------------- diff --git a/PhysicsTools/NanoAOD/plugins/IsolatedTrackCleaner.cc b/PhysicsTools/NanoAOD/plugins/IsolatedTrackCleaner.cc index 67f384d7dae3c..1c67c9b84e1e0 100644 --- a/PhysicsTools/NanoAOD/plugins/IsolatedTrackCleaner.cc +++ b/PhysicsTools/NanoAOD/plugins/IsolatedTrackCleaner.cc @@ -22,7 +22,7 @@ class IsolatedTrackCleaner : public edm::global::EDProducer<> { produces>(); } - virtual ~IsolatedTrackCleaner() {} + ~IsolatedTrackCleaner() override {} void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { auto out = std::make_unique>(); diff --git a/PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc b/PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc index 05618b4d92578..050975781e41a 100644 --- a/PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc +++ b/PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc @@ -50,12 +50,12 @@ class L1TriggerResultsConverter : public edm::global::EDProducer<> { public: explicit L1TriggerResultsConverter(const edm::ParameterSet&); - ~L1TriggerResultsConverter(); + ~L1TriggerResultsConverter() override; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; virtual void beginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&); // ----------member data --------------------------- diff --git a/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc b/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc index af0fe2baa99b1..2f71de009459d 100644 --- a/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc @@ -18,7 +18,7 @@ class LHETablesProducer : public edm::global::EDProducer<> { produces(); } - virtual ~LHETablesProducer() {} + ~LHETablesProducer() override {} void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { auto lheTab = std::make_unique(1, "LHE", true); diff --git a/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc b/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc index 681ded875fc04..43c598e36be84 100644 --- a/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc @@ -57,12 +57,12 @@ class LeptonJetVarProducer : public edm::global::EDProducer<> { produces>("jetNDauChargedMVASel"); produces>("jetForLepJetVar"); } - ~LeptonJetVarProducer() {}; + ~LeptonJetVarProducer() override {}; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; std::tuple calculatePtRatioRel(auto &lep, auto &jet, auto &vtx) const; diff --git a/PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc b/PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc index 9df1c4f08fee0..14a65009304b7 100644 --- a/PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc +++ b/PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc @@ -24,9 +24,9 @@ namespace pat { produces>(); } - ~LeptonUpdater() {} + ~LeptonUpdater() override {} - void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const ; + void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override ; static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { edm::ParameterSetDescription desc; diff --git a/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc b/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc index 709296cc97314..966a46a1335f9 100644 --- a/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc @@ -27,7 +27,7 @@ class MuonIDTableProducer : public edm::global::EDProducer<> { produces(); } - ~MuonIDTableProducer() {}; + ~MuonIDTableProducer() override {}; static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { edm::ParameterSetDescription desc; diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h b/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h index 3c8d697b1e407..b94a86baedf25 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h +++ b/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h @@ -49,14 +49,14 @@ class NanoAODBaseCrossCleaner : public edm::stream::EDProducer<> { public: explicit NanoAODBaseCrossCleaner(const edm::ParameterSet&); - ~NanoAODBaseCrossCleaner(); + ~NanoAODBaseCrossCleaner() override; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void beginStream(edm::StreamID) override; - virtual void produce(edm::Event&, const edm::EventSetup&) override; - virtual void endStream() override; + void beginStream(edm::StreamID) override; + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override; virtual void objectSelection( const edm::View & jets, const edm::View & muons, const edm::View & eles, const edm::View & taus, const edm::View & photons, std::vector & jetBits, std::vector & muonBits, std::vector & eleBits, diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc index 9c3f8a9ecb5a3..0ef828d6e4dcb 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc @@ -45,17 +45,17 @@ class NanoAODOutputModule : public edm::one::OutputModule<> { public: NanoAODOutputModule(edm::ParameterSet const& pset); - virtual ~NanoAODOutputModule(); + ~NanoAODOutputModule() override; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void write(edm::EventForOutput const& e) override; - virtual void writeLuminosityBlock(edm::LuminosityBlockForOutput const&) override; - virtual void writeRun(edm::RunForOutput const&) override; - virtual bool isFileOpen() const override; - virtual void openFile(edm::FileBlock const&) override; - virtual void reallyCloseFile() override; + void write(edm::EventForOutput const& e) override; + void writeLuminosityBlock(edm::LuminosityBlockForOutput const&) override; + void writeRun(edm::RunForOutput const&) override; + bool isFileOpen() const override; + void openFile(edm::FileBlock const&) override; + void reallyCloseFile() override; std::string m_fileName; std::string m_logicalFileName; diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODSimpleCrossCleaner.cc b/PhysicsTools/NanoAOD/plugins/NanoAODSimpleCrossCleaner.cc index c76dd5c6821fd..665cf91cd2e9e 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODSimpleCrossCleaner.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODSimpleCrossCleaner.cc @@ -3,9 +3,9 @@ class NanoAODSimpleCrossCleaner : public NanoAODBaseCrossCleaner { public: NanoAODSimpleCrossCleaner(const edm::ParameterSet&p):NanoAODBaseCrossCleaner(p){} - ~NanoAODSimpleCrossCleaner(){} + ~NanoAODSimpleCrossCleaner() override{} - virtual void objectSelection( const edm::View & jets, const edm::View & muons, const edm::View & eles, + void objectSelection( const edm::View & jets, const edm::View & muons, const edm::View & eles, const edm::View & taus, const edm::View & photons, std::vector & jetBits, std::vector & muonBits, std::vector & eleBits, std::vector & tauBits, std::vector & photonBits) override { diff --git a/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc b/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc index dcac0fb402001..90ca3f34a17a1 100644 --- a/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc @@ -16,7 +16,7 @@ class NativeArrayTableProducer : public edm::stream::EDProducer<> { produces(); } - virtual ~NativeArrayTableProducer() {} + ~NativeArrayTableProducer() override {} void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override { edm::Handle src; diff --git a/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc b/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc index 8b96b7608d898..d93c52d0a0538 100644 --- a/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc @@ -46,14 +46,14 @@ class PATObjectCrossLinker : public edm::stream::EDProducer<> { public: explicit PATObjectCrossLinker(const edm::ParameterSet&); - ~PATObjectCrossLinker(); + ~PATObjectCrossLinker() override; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void beginStream(edm::StreamID) override; - virtual void produce(edm::Event&, const edm::EventSetup&) override; - virtual void endStream() override; + void beginStream(edm::StreamID) override; + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override; void matchOneToMany(const auto & refProdOne, auto & itemsOne, const std::string & nameOne, const auto & refProdMany, auto& itemsMany, const std::string & nameMany); diff --git a/PhysicsTools/NanoAOD/plugins/PATObjectUserDataEmbedder.cc b/PhysicsTools/NanoAOD/plugins/PATObjectUserDataEmbedder.cc index 2cfdbaeffb54b..d2868e12865e0 100644 --- a/PhysicsTools/NanoAOD/plugins/PATObjectUserDataEmbedder.cc +++ b/PhysicsTools/NanoAOD/plugins/PATObjectUserDataEmbedder.cc @@ -67,9 +67,9 @@ namespace pat { produces>(); } - ~PATObjectUserDataEmbedder() {} + ~PATObjectUserDataEmbedder() override {} - virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override; + void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override; static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { edm::ParameterSetDescription desc; diff --git a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc index adc5ccc3fda59..fea31a6214ce9 100644 --- a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc @@ -35,7 +35,7 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> { produces(); } - virtual ~SimpleFlatTableProducerBase() {} + ~SimpleFlatTableProducerBase() override {} // this is to be overriden by the child class virtual std::unique_ptr fillTable(const edm::Event &iEvent, const edm::Handle & prod) const = 0; @@ -83,7 +83,7 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> { public: FuncVariable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : Variable(aname, atype, cfg), func_(cfg.getParameter("expr"), true) {} - ~FuncVariable() {} + ~FuncVariable() override {} void fill(std::vector selobjs, FlatTable & out) const override { std::vector vals(selobjs.size()); for (unsigned int i = 0, n = vals.size(); i < n; ++i) { @@ -127,7 +127,7 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase fillTable(const edm::Event &iEvent, const edm::Handle> & prod) const override { std::vector selobjs; @@ -168,7 +168,7 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase>(cfg.getParameter("src"))) {} - virtual void fill(const edm::Event & iEvent, std::vector> selptrs, FlatTable & out) const override { + void fill(const edm::Event & iEvent, std::vector> selptrs, FlatTable & out) const override { edm::Handle> vmap; iEvent.getByToken(token_, vmap); std::vector vals(selptrs.size()); diff --git a/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc b/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc index babc443673b8d..0828130a802cf 100644 --- a/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc @@ -42,7 +42,7 @@ class TriggerObjectTableProducer : public edm::global::EDProducer<> { produces(); } - ~TriggerObjectTableProducer() {} + ~TriggerObjectTableProducer() override {} private: void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override ; diff --git a/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc index 7a886ac5b4171..54aa22a1213cf 100644 --- a/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc +++ b/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc @@ -8,7 +8,7 @@ void TriggerOutputBranches::updateTriggerNames(TTree & tree, const edm::TriggerNames & names, const edm::TriggerResults & triggers) { std::vector newNames(triggers.getTriggerNames()); - if(newNames.size()==0) { + if(newNames.empty()) { for(unsigned int j=0;jgetMapped(triggerResults.parameterSetID()))) { + edm::ParameterSet const* pset=nullptr; + if (nullptr!=(pset=psetRegistry->getMapped(triggerResults.parameterSetID()))) { if (pset->existsAs >("@trigger_paths", true)) { edm::TriggerNames triggerNames(*pset); diff --git a/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc b/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc index 66b961f86933d..2bbaa70535a3d 100644 --- a/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc @@ -15,7 +15,7 @@ class UniqueStringProducer : public edm::global::EDProducer { nWP = src_bitmaps_.size(); produces>(); } - ~VIDNestedWPBitmapProducer() {} + ~VIDNestedWPBitmapProducer() override {} static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void beginStream(edm::StreamID) override {}; - virtual void produce(edm::Event&, const edm::EventSetup&) override; - virtual void endStream() override {}; + void beginStream(edm::StreamID) override {}; + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override {}; //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; diff --git a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc index fa51da621feaf..0d4e418ab5d66 100644 --- a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc @@ -48,14 +48,14 @@ class VertexTableProducer : public edm::stream::EDProducer<> { public: explicit VertexTableProducer(const edm::ParameterSet&); - ~VertexTableProducer(); + ~VertexTableProducer() override; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void beginStream(edm::StreamID) override; - virtual void produce(edm::Event&, const edm::EventSetup&) override; - virtual void endStream() override; + void beginStream(edm::StreamID) override; + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override; //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; From 29879a4e063071f1e09fe0b0a0933526327bff67 Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 19 Sep 2017 12:18:28 +0200 Subject: [PATCH 03/36] add support for gzipped xml --- PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h b/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h index 8818ad25427cc..3582dd58f5d60 100644 --- a/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h +++ b/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h @@ -39,6 +39,8 @@ #include "CommonTools/Utils/interface/StringObjectFunction.h" #include "DataFormats/Common/interface/ValueMap.h" +#include "CommonTools/Utils/interface/TMVAZipReader.h" + #include // // class declaration @@ -65,7 +67,8 @@ class BaseMVAValueMapProducer : public edm::stream::EDProducer<> { reader_.AddVariable(v,(&values_.front())+i); i++; } - reader_.BookMVA(name_,iConfig.getParameter("weightFile").fullPath() ); +// reader_.BookMVA(name_,iConfig.getParameter("weightFile").fullPath() ); + reco::details::loadTMVAWeights(&reader_, name_, iConfig.getParameter("weightFile").fullPath()); produces>(); } From 010e33331935ff96c2d8ef977470b63be94af6d3 Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 19 Sep 2017 18:46:35 +0200 Subject: [PATCH 04/36] aply JECs before flight --- PhysicsTools/NanoAOD/python/jets_cff.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/jets_cff.py b/PhysicsTools/NanoAOD/python/jets_cff.py index 245e5e8f4f577..d58582536d3a3 100644 --- a/PhysicsTools/NanoAOD/python/jets_cff.py +++ b/PhysicsTools/NanoAOD/python/jets_cff.py @@ -7,7 +7,6 @@ from RecoJets.JetProducers.ak4PFJets_cfi import ak4PFJets chsForSATkJets = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string('charge()!=0 && pvAssociationQuality()>=5 && vertexRef().key()==0')) -#chsForSATkJets = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string('charge()!=0 && fromPV && vertexRef().key()==0')) softActivityJets = ak4PFJets.clone(src = 'chsForSATkJets', doAreaFastjet = False, jetPtMin=1) softActivityJets10 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("chsForSATkJets"), cut = cms.string('pt>10')) softActivityJets5 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("chsForSATkJets"), cut = cms.string('pt>5')) @@ -28,6 +27,7 @@ src = cms.InputTag("slimmedJets") ) + slimmedJetsWithUserData = cms.EDProducer("PATJetUserDataEmbedder", src = cms.InputTag("slimmedJets"), userInts = cms.PSet( @@ -36,9 +36,22 @@ ), ) +from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cfi import * +from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import * +updatedJets = updatedPatJets.clone( + addBTagInfo=False, + jetSource='slimmedJetsWithUserData', + jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactors") ), +) +jetCorrFactors = patJetCorrFactors.clone(src='slimmedJetsWithUserData', + levels = cms.vstring('L1FastJet', + 'L2Relative', + 'L3Absolute'), + primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"), +) finalJets = cms.EDFilter("PATJetRefSelector", - src = cms.InputTag("slimmedJetsWithUserData"), + src = cms.InputTag("updatedJets"), cut = cms.string("pt > 15") ) @@ -228,7 +241,7 @@ #before cross linking -jetSequence = cms.Sequence(looseJetId+tightJetId+slimmedJetsWithUserData+chsForSATkJets+softActivityJets+softActivityJets2+softActivityJets5+softActivityJets10+finalJets) +jetSequence = cms.Sequence(looseJetId+tightJetId+slimmedJetsWithUserData+jetCorrFactors+updatedJets+chsForSATkJets+softActivityJets+softActivityJets2+softActivityJets5+softActivityJets10+finalJets) #after cross linkining jetTables = cms.Sequence(bjetMVA+ jetTable+fatJetTable+subJetTable+saJetTable+saTable) From 372bb171ad3bdd6eaf4cf1e15f67dbc9eaea1a45 Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 19 Sep 2017 19:14:03 +0200 Subject: [PATCH 05/36] add L2L3 and sort the mess --- PhysicsTools/NanoAOD/python/jets_cff.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/jets_cff.py b/PhysicsTools/NanoAOD/python/jets_cff.py index d58582536d3a3..4ebec88a89241 100644 --- a/PhysicsTools/NanoAOD/python/jets_cff.py +++ b/PhysicsTools/NanoAOD/python/jets_cff.py @@ -36,19 +36,21 @@ ), ) -from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cfi import * + from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import * -updatedJets = updatedPatJets.clone( - addBTagInfo=False, - jetSource='slimmedJetsWithUserData', - jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactors") ), -) jetCorrFactors = patJetCorrFactors.clone(src='slimmedJetsWithUserData', levels = cms.vstring('L1FastJet', 'L2Relative', - 'L3Absolute'), + 'L3Absolute', + 'L2L3Residual'), primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"), ) +from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cfi import * +updatedJets = updatedPatJets.clone( + addBTagInfo=False, + jetSource='slimmedJetsWithUserData', + jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactors") ), +) finalJets = cms.EDFilter("PATJetRefSelector", src = cms.InputTag("updatedJets"), From 1f8f91df35764c3a9bd90eda8b9f4ab8a395f1fc Mon Sep 17 00:00:00 2001 From: Emanuele Di Marco Date: Fri, 22 Sep 2017 11:01:24 +0200 Subject: [PATCH 06/36] add some basic in-time pileup info --- .../plugins/SimpleFlatTableProducer.cc | 20 +++++++++++++++++++ PhysicsTools/NanoAOD/python/globals_cff.py | 15 +++++++++++++- PhysicsTools/NanoAOD/python/nano_cff.py | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc index fea31a6214ce9..335e5516db90f 100644 --- a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc @@ -205,9 +205,29 @@ class EventSingletonSimpleFlatTableProducer : public SimpleFlatTableProducerBase } }; +template +class FirstObjectSimpleFlatTableProducer : public SimpleFlatTableProducerBase> { + public: + FirstObjectSimpleFlatTableProducer( edm::ParameterSet const & params ): + SimpleFlatTableProducerBase>(params) {} + + ~FirstObjectSimpleFlatTableProducer() override {} + + std::unique_ptr fillTable(const edm::Event &iEvent, const edm::Handle> & prod) const override { + auto out = std::make_unique(1, this->name_, true, this->extension_); + std::vector selobjs(1, & (*prod)[0]); + for (const auto & var : this->vars_) var.fill(selobjs, *out); + return out; + } +}; + #include "DataFormats/Candidate/interface/Candidate.h" typedef SimpleFlatTableProducer SimpleCandidateFlatTableProducer; +#include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h" +typedef FirstObjectSimpleFlatTableProducer SimplePileupFlatTableProducer; + #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer); +DEFINE_FWK_MODULE(SimplePileupFlatTableProducer); diff --git a/PhysicsTools/NanoAOD/python/globals_cff.py b/PhysicsTools/NanoAOD/python/globals_cff.py index 6b9fe530f4f66..471b44dec9807 100644 --- a/PhysicsTools/NanoAOD/python/globals_cff.py +++ b/PhysicsTools/NanoAOD/python/globals_cff.py @@ -9,5 +9,18 @@ ) ) -globalTables = cms.Sequence(rhoTable) +puTable = cms.EDProducer("SimplePileupFlatTableProducer", + src = cms.InputTag("slimmedAddPileupInfo"), + cut = cms.string("getBunchCrossing()==0"), # save only the pileup of the in-time bunch crossing + name= cms.string("Pileup"), + doc = cms.string("pileup information for bunch crossing 0"), + singleton = cms.bool(False), # slimmedAddPileupInfo collection has all the BXs, but only BX=0 is saved + extension = cms.bool(False), + variables = cms.PSet( + nTrueInt = Var( "getTrueNumInteractions()", int, doc="the true mean number of the poisson distribution for this event from which the number of interactions each bunch crossing has been sampled" ), + nPU = Var( "getPU_NumInteractions()", int, doc="the number of pileup interactions that have been added to the event in the current bunch crossing" ), + ), +) +globalTables = cms.Sequence(rhoTable) +globalTablesMC = cms.Sequence(puTable) diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index f7ffb6e50d13e..9288f20dea2c6 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -70,4 +70,4 @@ jetTables + muonTables + tauTables + electronTables + photonTables + globalTables +vertexTables+ metTables+simpleCleanerTable + triggerObjectTables + isoTrackTables + l1bits) -nanoSequenceMC = cms.Sequence(genParticleSequence + nanoSequence + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + genWeightsTable + genParticleTables + lheInfoTable) +nanoSequenceMC = cms.Sequence(genParticleSequence + nanoSequence + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + globalTablesMC + genWeightsTable + genParticleTables + lheInfoTable) From f27f976114dfbda0fd0be563734161791b762677 Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 20 Sep 2017 14:33:26 +0200 Subject: [PATCH 07/36] reduce the number of genparticles --- .../NanoAOD/python/genparticles_cff.py | 48 +++++++------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/genparticles_cff.py b/PhysicsTools/NanoAOD/python/genparticles_cff.py index cfdbe9f020b46..fec90b4d1e484 100644 --- a/PhysicsTools/NanoAOD/python/genparticles_cff.py +++ b/PhysicsTools/NanoAOD/python/genparticles_cff.py @@ -8,39 +8,23 @@ finalGenParticles = cms.EDProducer("GenParticlePruner", src = cms.InputTag("prunedGenParticles"), select = cms.vstring( - "drop *", # this is the default - "++keep abs(pdgId) == 11 || abs(pdgId) == 13 || abs(pdgId) == 15", # keep leptons, with history - "drop status == 2", # drop the shower part of the history - "keep (400 < abs(pdgId) < 600) || (4000 < abs(pdgId) < 6000)", - "keep abs(pdgId) == 11 || abs(pdgId) == 13 || abs(pdgId) == 15", # keep leptons (also status1) - "keep abs(pdgId) == 12 || abs(pdgId) == 14 || abs(pdgId) == 16", # keep neutrinos + "drop *", + "keep++ abs(pdgId) == 15 & (pt > 15 || isPromptDecayed() )",# keep full tau decay chain for some taus + #"drop status==1 & pt < 1", #drop soft stable particle in tau decay + "keep+ abs(pdgId) == 15 ", # keep first gen decay product for all tau "+keep pdgId == 22 && status == 1 && (pt > 10 || isPromptFinalState())", # keep gamma above 10 GeV (or all prompt) and its first parent - "+keep abs(pdgId) == 11 && status == 1 && (pt > 3 || isPromptFinalState())", # keep first parent of electrons above 3 GeV (or prompt) - "keep++ abs(pdgId) == 15", # but keep keep taus with decays - "drop status > 30 && status < 70 ", # remove pythia8 garbage - "drop pdgId == 21 && pt < 5", # remove pythia8 garbage - "drop status == 2 && abs(pdgId) == 21", # but remove again gluons in the inheritance chain - "keep abs(pdgId) == 23 || abs(pdgId) == 24 || abs(pdgId) == 25 || abs(pdgId) == 6 || abs(pdgId) == 37 ", # keep VIP(articles)s - "keep abs(pdgId) == 310 && abs(eta) < 2.5 && pt > 1 ", # keep K0 - "+keep abs(pdgId) == 13 && status == 1", # keep muon parents - "keep (4 <= abs(pdgId) <= 5) && ( status <30 || status > 70)", - "keep (1 <= abs(pdgId) <= 3 || pdgId = 21) & (status = 2 || status = 11 || status = 71 || status = 72) && pt>15", #increased to 15GeV wrt miniAOD -# keep onia states, phi, X(3872), Z(4430)+ and psi(4040) -# "keep+ abs(pdgId) == 333", -# "keep+ abs(pdgId) == 9920443 || abs(pdgId) == 9042413 || abs(pdgId) == 9000443", -# "keep+ abs(pdgId) == 443 || abs(pdgId) == 100443 || abs(pdgId) == 10441 || abs(pdgId) == 20443 || abs(pdgId) == 445 || abs(pdgId) == 30443", -# "keep+ abs(pdgId) == 553 || abs(pdgId) == 100553 || abs(pdgId) == 200553 || abs(pdgId) == 10551 || abs(pdgId) == 20553 || abs(pdgId) == 555", -# additional c hadrons for jet fragmentation studies -# "keep abs(pdgId) = 10411 || abs(pdgId) = 10421 || abs(pdgId) = 10413 || abs(pdgId) = 10423 || abs(pdgId) = 20413 || abs(pdgId) = 20423 || abs(pdgId) = 10431 || abs(pdgId) = 10433 || abs(pdgId) = 20433", -# additional b hadrons for jet fragmentation studies -# "keep abs(pdgId) = 10511 || abs(pdgId) = 10521 || abs(pdgId) = 10513 || abs(pdgId) = 10523 || abs(pdgId) = 20513 || abs(pdgId) = 20523 || abs(pdgId) = 10531 || abs(pdgId) = 10533 || abs(pdgId) = 20533 || abs(pdgId) = 10541 || abs(pdgId) = 10543 || abs(pdgId) = 20543", -#keep SUSY particles - "keep (1000001 <= abs(pdgId) <= 1000039 ) || ( 2000001 <= abs(pdgId) <= 2000015)", -## keep protons -# "keep pdgId = 2212", - "keep status == 3 || ( 21 <= status <= 29) || ( 11 <= status <= 19)", #keep event summary (status=3 for pythia6, 21 <= status <= 29 for pythia8) - "keep isHardProcess() || fromHardProcessFinalState() || fromHardProcessDecayed() || fromHardProcessBeforeFSR() || (statusFlags().fromHardProcess() && statusFlags().isLastCopy())", #keep event summary based on status flags - ) + "+keep abs(pdgId) == 11 || abs(pdgId) == 13 || abs(pdgId) == 15", #keep leptons, with at most one mother back in the history + "drop abs(pdgId)= 2212 && abs(pz) > 1000", #drop LHC protons accidentally added by previous keeps + "keep (400 < abs(pdgId) < 600) || (4000 < abs(pdgId) < 6000)", #keep all B and C hadrons + "keep abs(pdgId) == 12 || abs(pdgId) == 14 || abs(pdgId) == 16", # keep neutrinos + "keep status == 3 || (status > 20 && status < 30)", #keep matrix element summary + "keep isHardProcess() || fromHardProcessFinalState() || (statusFlags().fromHardProcess() && statusFlags().isLastCopy())", #keep event summary based on status flags + "keep (status > 70 && status < 80 && pt > 15) ", # keep high pt partons right before hadronization + "keep abs(pdgId) == 23 || abs(pdgId) == 24 || abs(pdgId) == 25 || abs(pdgId) == 37 ", # keep VIP(articles)s + #"keep abs(pdgId) == 310 && abs(eta) < 2.5 && pt > 1 ", # keep K0 + "keep (1000001 <= abs(pdgId) <= 1000039 ) || ( 2000001 <= abs(pdgId) <= 2000015)", #keep SUSY fiction particles + + ) ) From 89d6897f5be8d1f715d0909c64556e89d64aae81 Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 20 Sep 2017 15:31:03 +0200 Subject: [PATCH 08/36] include suggestion from @bendavid --- PhysicsTools/NanoAOD/python/genparticles_cff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhysicsTools/NanoAOD/python/genparticles_cff.py b/PhysicsTools/NanoAOD/python/genparticles_cff.py index fec90b4d1e484..8d5dddafab239 100644 --- a/PhysicsTools/NanoAOD/python/genparticles_cff.py +++ b/PhysicsTools/NanoAOD/python/genparticles_cff.py @@ -18,7 +18,7 @@ "keep (400 < abs(pdgId) < 600) || (4000 < abs(pdgId) < 6000)", #keep all B and C hadrons "keep abs(pdgId) == 12 || abs(pdgId) == 14 || abs(pdgId) == 16", # keep neutrinos "keep status == 3 || (status > 20 && status < 30)", #keep matrix element summary - "keep isHardProcess() || fromHardProcessFinalState() || (statusFlags().fromHardProcess() && statusFlags().isLastCopy())", #keep event summary based on status flags + "keep isHardProcess() || fromHardProcessDecayed() || fromHardProcessFinalState() || (statusFlags().fromHardProcess() && statusFlags().isLastCopy())", #keep event summary based on status flags "keep (status > 70 && status < 80 && pt > 15) ", # keep high pt partons right before hadronization "keep abs(pdgId) == 23 || abs(pdgId) == 24 || abs(pdgId) == 25 || abs(pdgId) == 37 ", # keep VIP(articles)s #"keep abs(pdgId) == 310 && abs(eta) < 2.5 && pt > 1 ", # keep K0 From c09afb6311f074eb3bdcb0dcf003e9c1a2fcdc09 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Tue, 19 Sep 2017 10:43:57 +0200 Subject: [PATCH 09/36] Set the default NanoAOD outputCommands to be the right ones --- PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc index 0ef828d6e4dcb..c6b84b69c8e60 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc @@ -317,7 +317,7 @@ NanoAODOutputModule::fillDescriptions(edm::ConfigurationDescriptions& descriptio ->setComment("Change the OutputModule name in the fwk job report to fake PoolOutputModule. This is needed to run on cran (and publish) till crab is fixed"); //replace with whatever you want to get from the EDM by default - const std::vector keep = {"drop *", "keep FlatTable_*_*_*"}; + const std::vector keep = {"drop *", "keep FlatTable_*Table_*_*", "keep edmTriggerResults_*_*_*", "keep MergableCounterTable_*Table_*_*", "keep UniqueString_nanoMetadata_*_*"}; edm::OutputModule::fillDescription(desc, keep); //Used by Workflow management for their own meta data From d7dc162ccf1a2cfe896ff56e836586f68730a54f Mon Sep 17 00:00:00 2001 From: Giovanni Date: Fri, 22 Sep 2017 12:48:45 +0200 Subject: [PATCH 10/36] Minimalistic cmsDriver integration: * new step -s NANO * new event contents NANOAOD, NANOAODSIM * use NanoAODOutputModule if datatier == "NANO", otherwise use PoolOutputModule --- .../Applications/python/ConfigBuilder.py | 14 +++++++++ .../python/NanoAODEDMEventContent_cff.py | 9 ++++++ PhysicsTools/NanoAOD/python/nano_cff.py | 29 +++++++++++++++++-- PhysicsTools/NanoAOD/test/nano_cfg.py | 3 +- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/Configuration/Applications/python/ConfigBuilder.py b/Configuration/Applications/python/ConfigBuilder.py index b1ba1630e0594..adf1b21365c08 100644 --- a/Configuration/Applications/python/ConfigBuilder.py +++ b/Configuration/Applications/python/ConfigBuilder.py @@ -626,6 +626,7 @@ def doNotInlineEventContent(instance,label = "cms.untracked.vstring(process."+th if self._options.timeoutOutput: CppType='TimeoutPoolOutputModule' if streamType=='DQM' and tier=='DQMIO': CppType='DQMRootOutputModule' + if "NANOAOD" in streamType and tier=='NANO': CppType='NanoAODOutputModule' output = cms.OutputModule(CppType, theEventContent, fileName = cms.untracked.string(theFileName), @@ -921,6 +922,7 @@ def define_Configs(self): self.L1TrackTriggerDefaultCFF="Configuration/StandardSequences/L1TrackTrigger_cff" self.RECODefaultCFF="Configuration/StandardSequences/Reconstruction_Data_cff" self.PATDefaultCFF="Configuration/StandardSequences/PAT_cff" + self.NANODefaultCFF="PhysicsTools/NanoAOD/nano_cff" self.EIDefaultCFF=None self.SKIMDefaultCFF="Configuration/StandardSequences/Skims_cff" self.POSTRECODefaultCFF="Configuration/StandardSequences/PostRecoGenerator_cff" @@ -980,6 +982,7 @@ def define_Configs(self): self.REPACKDefaultSeq='DigiToRawRepack' self.PATDefaultSeq='miniAOD' self.PATGENDefaultSeq='miniGEN' + self.NANODefaultSeq='nanoSequence' self.EVTCONTDefaultCFF="Configuration/EventContent/EventContent_cff" @@ -994,6 +997,7 @@ def define_Configs(self): self.PATGENDefaultCFF="Configuration/StandardSequences/PATGEN_cff" self.DQMOFFLINEDefaultCFF="DQMOffline/Configuration/DQMOfflineMC_cff" self.ALCADefaultCFF="Configuration/StandardSequences/AlCaRecoStreamsMC_cff" + self.NANODefaultSeq='nanoSequenceMC' else: self._options.beamspot = None @@ -1687,6 +1691,16 @@ def prepare_PATGEN(self, sequence = "miniGEN"): raise Exception("PATGEN step can only run on MC") return + def prepare_NANO(self, sequence = "nanoAOD"): + ''' Enrich the schedule with NANO ''' + self.loadDefaultOrSpecifiedCFF(sequence,self.NANODefaultCFF) + self.scheduleSequence(sequence.split('.')[-1],'nanoAOD_step') + custom = "nanoAOD_customizeData" if self._options.isData else "nanoAOD_customizeMC" + if self._options.runUnscheduled: + self._options.customisation_file_unsch.insert(0,"PhysicsTools/NanoAOD/nano_cff."+custom) + else: + self._options.customisation_file.insert(0,"PhysicsTools/NanoAOD/nano_cff."+custom) + def prepare_EI(self, sequence = None): ''' Enrich the schedule with event interpretation ''' from Configuration.StandardSequences.EventInterpretation import EventInterpretation diff --git a/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py b/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py index 9308729e5f226..b095368d92620 100644 --- a/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py +++ b/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py @@ -9,3 +9,12 @@ "keep UniqueString_nanoMetadata_*_*", # basic metadata ) ) + +NANOAODEventContent = NanoAODEDMEventContent.clone( + compressionLevel = cms.untracked.int32(9), + compressionAlgorithm = cms.untracked.string("LZMA"), +) +NANOAODSIMEventContent = NanoAODEDMEventContent.clone( + compressionLevel = cms.untracked.int32(9), + compressionAlgorithm = cms.untracked.string("LZMA"), +) diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index 9288f20dea2c6..2efeb98e04e94 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -12,7 +12,6 @@ from PhysicsTools.NanoAOD.triggerObjects_cff import * from PhysicsTools.NanoAOD.isotracks_cff import * from PhysicsTools.NanoAOD.NanoAODEDMEventContent_cff import * -from PhysicsTools.NanoAOD.adaptFrom92X_cff import * # remove when 94X MC becomes available nanoMetadata = cms.EDProducer("UniqueStringProducer", strings = cms.PSet( @@ -63,7 +62,6 @@ l1bits=cms.EDProducer("L1TriggerResultsConverter", src=cms.InputTag("gtStage2Digis"), legacyL1=cms.bool(False)) nanoSequence = cms.Sequence( - adapt_nano + # remove when 94X MC becomes available nanoMetadata + muonSequence + jetSequence + tauSequence + electronSequence+photonSequence+vertexSequence+#metSequence+ isoTrackSequence + # must be after all the leptons linkedObjects + @@ -71,3 +69,30 @@ l1bits) nanoSequenceMC = cms.Sequence(genParticleSequence + nanoSequence + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + globalTablesMC + genWeightsTable + genParticleTables + lheInfoTable) + +def nanoAOD_customizeCommon(process): + ## FIXME: make era-dependent? + if not hasattr(process, 'miniAOD'): + # assume we're reading old miniAOD for the moment + process.load("PhysicsTools.NanoAOD.adaptFrom92X_cff") + process.nanoSequence.insert(0, process.adapt_nano) + return process + +def nanoAOD_customizeData(process): + process = nanoAOD_customizeCommon(process) + process.calibratedPatElectrons.isMC = cms.bool(False) + process.calibratedPatPhotons.isMC = cms.bool(False) + return process + +def nanoAOD_customizeMC(process): + process = nanoAOD_customizeCommon(process) + ## FIXME: THIS SHOULD PROBABLY GO INTO Services_cff + if not hasattr(process,'RandomNumberGeneratorService'): + process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService") + for X in 'calibratedPatElectrons','calibratedPatPhotons': + if not hasattr(process.RandomNumberGeneratorService,X): + setattr(process.RandomNumberGeneratorService, X, + cms.PSet(initialSeed = cms.untracked.uint32(81), engineName = cms.untracked.string('TRandom3'))) + process.calibratedPatElectrons.isMC = cms.bool(True) + process.calibratedPatPhotons.isMC = cms.bool(True) + return process diff --git a/PhysicsTools/NanoAOD/test/nano_cfg.py b/PhysicsTools/NanoAOD/test/nano_cfg.py index 343582537975a..425655dc38cd8 100644 --- a/PhysicsTools/NanoAOD/test/nano_cfg.py +++ b/PhysicsTools/NanoAOD/test/nano_cfg.py @@ -24,6 +24,7 @@ ] process.load("PhysicsTools.NanoAOD.nano_cff") +process.load("PhysicsTools.NanoAOD.adaptFrom92X_cff") process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService", calibratedPatElectrons = cms.PSet(initialSeed = cms.untracked.uint32(81), @@ -33,7 +34,7 @@ engineName = cms.untracked.string('TRandom3'), ), ) -process.nanoPath = cms.Path(process.nanoSequenceMC) +process.nanoPath = cms.Path(process.adapt_nano + process.nanoSequenceMC) process.calibratedPatElectrons.isMC = cms.bool(True) process.calibratedPatPhotons.isMC = cms.bool(True) #for data: From 22ee0e20e9dbb0422648ffab42ec7236086413f2 Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 20 Sep 2017 22:55:13 +0200 Subject: [PATCH 11/36] add tooltip to treesize.py and option to print doc stuff --- PhysicsTools/NanoAOD/test/treeSize.py | 219 ++++++++++++++++---------- 1 file changed, 133 insertions(+), 86 deletions(-) diff --git a/PhysicsTools/NanoAOD/test/treeSize.py b/PhysicsTools/NanoAOD/test/treeSize.py index 17e34d5d05dc1..44ff996682453 100644 --- a/PhysicsTools/NanoAOD/test/treeSize.py +++ b/PhysicsTools/NanoAOD/test/treeSize.py @@ -18,6 +18,8 @@ ## otherwise you will get an unreadable output file infile = sys.argv[1] +docMode= (sys.argv[2] == "doc") if len(sys.argv) >2 else False + if not os.path.isfile(infile): raise RuntimeError filesize = os.path.getsize(infile)/1024.0 class Branch: @@ -25,6 +27,7 @@ def __init__(self, tree, branch): self.tree = tree self.branch = branch self.name = branch.GetName() + self.doc = branch.GetTitle() self.tot = branch.GetZipBytes()/1024.0 self.entries = None; self.single = True @@ -37,6 +40,8 @@ def __init__(self, tree, branch): sys.stderr.write("Cannot parse branch '%s' in tree %s (no leaf)\n", tree.GetName(), branch.GetName()) return self.kind = self.leaf.GetTypeName() + if docMode and "Idx" in self.name: + self.kind+="(index to %s)"%((self.name[self.name.find("_")+1:self.name.find("Idx")]).title()) if self.leaf.GetLen() == 0 and self.leaf.GetLeafCount() != None: self.single = False self.counter = self.leaf.GetLeafCount().GetName() @@ -78,6 +83,7 @@ def getKind(self): tfile = ROOT.TFile.Open(infile) trees = {} branches = {} +toplevelDoc={} for treeName in "Events", "Runs", "Lumis": tree = tfile.Get(treeName) entries = tree.GetEntries() @@ -106,7 +112,9 @@ def getKind(self): br.entries = n # now we start to create branch groups for b in allbranches: - if b.name in counters: continue # skip counters + if b.name in counters: + toplevelDoc[b.name[1:]]=b.doc + continue # skip counters if "_" in b.name: head, tail = b.name.split("_",1) else: @@ -150,94 +158,133 @@ def getKind(self): events = trees["Events"].entries sizeline = "%.3f Mb, %d events, %.2f kb/event" % ( filesize/1024.0, events, filesize/events) -print """ - - - {filename} : size ({allsize}) - - - - - - - - -

Summary ({allsize})

-[No canvas support] - + + + + + + +

Summary ({allsize})

+ [No canvas support] + -

Event data

- -""" -print ""; -grandtotal = trees["Events"].allsize; runningtotal = 0 -for s in trees["Events"].survey: - print "" % (s.name,s.name,s.getKind().lower(),len(s.subs)), - print "" % (s.entries/events, s.tot/events, s.tot/s.entries*1024 if s.entries else 0), - print "" % (s.tot/grandtotal*200,10), - print "" % ( s.tot/grandtotal * 100.0), - print "" % ( (runningtotal+s.tot)/grandtotal * 100.0), - print "" % ( (grandtotal-runningtotal)/grandtotal * 100.0), + +

Event data

+
" + "".join([ "collection", "kind", "vars", "items/evt", "kb/evt", "b/item", "plot", "%" ]) + "cumulative %
%s%s%d%.2f%.3f%.1f%.1f%%%.1f%%%.1f%%
+ """ + print ""; + grandtotal = trees["Events"].allsize; runningtotal = 0 + for s in trees["Events"].survey: + print "" % ((toplevelDoc[s.name] if s.name in toplevelDoc else ""),s.name,s.name,s.getKind().lower(),len(s.subs)), + print "" % (s.entries/events, s.tot/events, s.tot/s.entries*1024 if s.entries else 0), + print "" % (s.tot/grandtotal*200,10), + print "" % ( s.tot/grandtotal * 100.0), + print "" % ( (runningtotal+s.tot)/grandtotal * 100.0), + print "" % ( (grandtotal-runningtotal)/grandtotal * 100.0), + print ""; + runningtotal += s.tot; + + # all known data + print "", + print "" % (grandtotal/events), + print "" % (grandtotal/filesize*100.0), print ""; - runningtotal += s.tot; -# all known data -print "", -print "" % (grandtotal/events), -print "" % (grandtotal/filesize*100.0), -print ""; + # other, unknown overhead + print "", + print "" % ( (filesize-grandtotal)/events), + print "" % ( (filesize-grandtotal)/filesize * 100, 10 ), + print "" % ( (filesize-grandtotal)/filesize * 100.0 ), + print "" -# other, unknown overhead -print "", -print "" % ( (filesize-grandtotal)/events), -print "" % ( (filesize-grandtotal)/filesize * 100, 10 ), -print "" % ( (filesize-grandtotal)/filesize * 100.0 ), -print "" + # all file + print "", + print "" % (filesize/events), + print "\n"; -# all file -print "", -print "" % (filesize/events), -print "\n"; + print """ +
" + "".join([ "collection", "kind", "vars", "items/evt", "kb/evt", "b/item", "plot", "%" ]) + "cumulative %
%s%s%d%.2f%.3f%.1f%.1f%%%.1f%%%.1f%%
All Event data   %.2f " % ( grandtotal/filesize*100.0), + print "%.1f%%a
All Event data   %.2f " % ( grandtotal/filesize*100.0), -print "%.1f%%a
Non per-event data or overhead   %.2f %.1f%%a
Non per-event data or overhead   %.2f %.1f%%a
File size   %.2f   
File size   %.2f   
+ Note: size percentages of individual event products are relative to the total size of Event data only.
+ Percentages with a are instead relative to the full file size. +

Events detail

+ """ + for s in sorted(trees["Events"].survey, key = lambda s : s.name): + print "

%s (%.1f items/evt, %.3f kb/evt)

" % (s.name, s.name, s.name, s.entries/events, s.tot/events) + print "" + print "" + for b in sorted(s.subs, key = lambda s : - s.tot): + print "" % (b.doc,b.name, b.kind, b.tot/events*1024, b.tot/s.entries*1024), + print "" % ( b.tot/s.tot*200, 10 ), + print "" % (b.tot/s.tot * 100.0), + print "" + print "
" + "".join( [ "branch", "kind", "b/event", "b/item", "plot", "%" ]) + "
%s%s%.1f%.1f%.1f%%
" + print """ + + """ +else: + print """ + + + Documentation for {filename} + + + + + + + + +

Content

+ + """ + print "" + grandtotal = trees["Events"].allsize; runningtotal = 0 + for s in trees["Events"].survey: + print "" % (s.name,s.name,(toplevelDoc[s.name] if s.name in toplevelDoc else "no documentation available")) + print "" + runningtotal += s.tot; -print """ -
CollectionDescription
%s%s
-Note: size percentages of individual event products are relative to the total size of Event data only.
-Percentages with a are instead relative to the full file size. -

Events detail

-""" -for s in sorted(trees["Events"].survey, key = lambda s : s.name): - print "

%s (%.1f items/evt, %.3f kb/evt)

" % (s.name, s.name, s.name, s.entries/events, s.tot/events) - print "" - print "" - for b in sorted(s.subs, key = lambda s : - s.tot): - print "" % (b.name, b.kind, b.tot/events*1024, b.tot/s.entries*1024), - print "" % ( b.tot/s.tot*200, 10 ), - print "" % (b.tot/s.tot * 100.0), - print "" - print "
" + "".join( [ "branch", "kind", "b/event", "b/item", "plot", "%" ]) + "
%s%s%.1f%.1f%.1f%%
" -print """ - -""" + print """ + +

Events detail

+ """ + for s in sorted(trees["Events"].survey, key = lambda s : s.name): + print "

%s (%.1f items/evt, %.3f kb/evt)

" % (s.name, s.name, s.name, s.entries/events, s.tot/events) + print "" + print "" + for b in sorted(s.subs, key = lambda s : - s.tot): + print "" % (b.name, b.kind, b.doc), + print "" + print "
Object propertyTypeDescription
%s%s%s
" + print """ + + """ From 19d62c4bc227206a3f64382355ab530fdf188e45 Mon Sep 17 00:00:00 2001 From: Andrea Date: Thu, 21 Sep 2017 00:35:37 +0200 Subject: [PATCH 12/36] better treesize.py doc --- PhysicsTools/NanoAOD/python/jets_cff.py | 6 +++--- PhysicsTools/NanoAOD/test/treeSize.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/jets_cff.py b/PhysicsTools/NanoAOD/python/jets_cff.py index 4ebec88a89241..8b9bd92a8c4fc 100644 --- a/PhysicsTools/NanoAOD/python/jets_cff.py +++ b/PhysicsTools/NanoAOD/python/jets_cff.py @@ -83,9 +83,9 @@ electronIdx2 = Var("?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1", int, doc="index of second matching electron"), nElectrons = Var("?hasOverlaps('electrons')?overlaps('electrons').size():0", int, doc="number of electrons in the jet"), btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10), - btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')",float,doc="CMVA V2 btag discriminator",precision=10), - btagDeepBB = Var("bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="CMVA V2 btag discriminator",precision=10), - btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="CMVA V2 btag discriminator",precision=10), + btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')",float,doc="DeepCSV b tag discriminator",precision=10), + btagDeepBB = Var("bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="DeepCSV bb tag discriminator",precision=10), + btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="DeepCSV charm btag discriminator",precision=10), #puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pilup ID discriminant",precision=10), puId = Var("userInt('pileupJetId:fullId')",int,doc="Pilup ID flags"), jetId = Var("userInt('tightId')*2+userInt('looseId')",int,doc="Jet ID flags bit1 is loose, bit2 is tight"), diff --git a/PhysicsTools/NanoAOD/test/treeSize.py b/PhysicsTools/NanoAOD/test/treeSize.py index 44ff996682453..f23982861bb5e 100644 --- a/PhysicsTools/NanoAOD/test/treeSize.py +++ b/PhysicsTools/NanoAOD/test/treeSize.py @@ -113,12 +113,15 @@ def getKind(self): # now we start to create branch groups for b in allbranches: if b.name in counters: - toplevelDoc[b.name[1:]]=b.doc + if len(b.doc) > 0: + toplevelDoc[b.name[1:]]=b.doc continue # skip counters if "_" in b.name: head, tail = b.name.split("_",1) else: head = b.name + toplevelDoc[b.name]=b.doc + if head not in branchgroups: branchgroups[head] = BranchGroup(head) branchgroups[head].append(b) From 6faa025d3bc64ae1f34f228f97b8f70e46a3bb03 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Fri, 22 Sep 2017 13:26:47 +0200 Subject: [PATCH 13/36] Relocate dataformats in DataFormats/NanoAOD --- DataFormats/NanoAOD/BuildFile.xml | 10 ++++++ .../NanoAOD/interface/FlatTable.h | 4 +-- .../NanoAOD/interface/MergeableCounterTable.h | 10 +++--- .../NanoAOD/interface/UniqueString.h | 0 .../NanoAOD/src/FlatTable.cc | 2 +- .../NanoAOD/src/MergeableCounterTable.cc | 1 + DataFormats/NanoAOD/src/classes.h | 14 ++++++++ DataFormats/NanoAOD/src/classes_def.xml | 36 +++++++++++++++++++ PhysicsTools/NanoAOD/BuildFile.xml | 1 + PhysicsTools/NanoAOD/plugins/BuildFile.xml | 2 +- .../plugins/CandMCMatchTableProducer.cc | 2 +- .../plugins/GenWeightsTableProducer.cc | 8 ++--- .../plugins/GlobalVariablesTableProducer.cc | 2 +- .../NanoAOD/plugins/LHETablesProducer.cc | 2 +- .../NanoAOD/plugins/MuonIDTableProducer.cc | 2 +- .../plugins/NanoAODBaseCrossCleaner.cc | 2 +- .../NanoAOD/plugins/NanoAODOutputModule.cc | 8 ++--- .../plugins/NativeArrayTableProducer.cc | 2 +- .../plugins/SimpleFlatTableProducer.cc | 2 +- .../plugins/SummaryTableOutputBranches.cc | 6 ++-- .../plugins/SummaryTableOutputBranches.h | 6 ++-- .../NanoAOD/plugins/TableOutputBranches.h | 2 +- .../plugins/TriggerObjectTableProducer.cc | 2 +- .../NanoAOD/plugins/UniqueStringProducer.cc | 2 +- .../NanoAOD/plugins/VertexTableProducer.cc | 2 +- .../python/NanoAODEDMEventContent_cff.py | 2 +- .../NanoAOD/src/MergeableCounterTable.cc | 1 - PhysicsTools/NanoAOD/src/classes.h | 14 -------- PhysicsTools/NanoAOD/src/classes_def.xml | 36 ------------------- 29 files changed, 97 insertions(+), 86 deletions(-) create mode 100644 DataFormats/NanoAOD/BuildFile.xml rename {PhysicsTools => DataFormats}/NanoAOD/interface/FlatTable.h (98%) rename PhysicsTools/NanoAOD/interface/MergableCounterTable.h => DataFormats/NanoAOD/interface/MergeableCounterTable.h (95%) rename {PhysicsTools => DataFormats}/NanoAOD/interface/UniqueString.h (100%) rename {PhysicsTools => DataFormats}/NanoAOD/src/FlatTable.cc (78%) create mode 100644 DataFormats/NanoAOD/src/MergeableCounterTable.cc create mode 100644 DataFormats/NanoAOD/src/classes.h create mode 100644 DataFormats/NanoAOD/src/classes_def.xml delete mode 100644 PhysicsTools/NanoAOD/src/MergeableCounterTable.cc delete mode 100644 PhysicsTools/NanoAOD/src/classes.h delete mode 100644 PhysicsTools/NanoAOD/src/classes_def.xml diff --git a/DataFormats/NanoAOD/BuildFile.xml b/DataFormats/NanoAOD/BuildFile.xml new file mode 100644 index 0000000000000..178475a1a9d39 --- /dev/null +++ b/DataFormats/NanoAOD/BuildFile.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/PhysicsTools/NanoAOD/interface/FlatTable.h b/DataFormats/NanoAOD/interface/FlatTable.h similarity index 98% rename from PhysicsTools/NanoAOD/interface/FlatTable.h rename to DataFormats/NanoAOD/interface/FlatTable.h index a1ebbacc1e731..8fda70f7992d7 100644 --- a/PhysicsTools/NanoAOD/interface/FlatTable.h +++ b/DataFormats/NanoAOD/interface/FlatTable.h @@ -1,5 +1,5 @@ -#ifndef PhysicsTools_NanoAOD_FlatTable_h -#define PhysicsTools_NanoAOD_FlatTable_h +#ifndef DataFormats_NanoAOD_FlatTable_h +#define DataFormats_NanoAOD_FlatTable_h #include #include diff --git a/PhysicsTools/NanoAOD/interface/MergableCounterTable.h b/DataFormats/NanoAOD/interface/MergeableCounterTable.h similarity index 95% rename from PhysicsTools/NanoAOD/interface/MergableCounterTable.h rename to DataFormats/NanoAOD/interface/MergeableCounterTable.h index 6ae4febea7329..3b7606813c071 100644 --- a/PhysicsTools/NanoAOD/interface/MergableCounterTable.h +++ b/DataFormats/NanoAOD/interface/MergeableCounterTable.h @@ -1,13 +1,13 @@ -#ifndef PhysicsTools_NanoAOD_MergableCounterTable_h -#define PhysicsTools_NanoAOD_MergableCounterTable_h +#ifndef DataFormats_NanoAOD_MergeableCounterTable_h +#define DataFormats_NanoAOD_MergeableCounterTable_h #include #include #include -class MergableCounterTable { +class MergeableCounterTable { public: - MergableCounterTable() {} + MergeableCounterTable() {} typedef long long int_accumulator; // we accumulate in long long int, to avoid overflow typedef double float_accumulator; // we accumulate in double, to preserve precision @@ -75,7 +75,7 @@ class MergableCounterTable { } - bool mergeProduct(const MergableCounterTable & other) { + bool mergeProduct(const MergeableCounterTable & other) { if (!tryMerge(intCols_, other.intCols_)) return false; if (!tryMerge(vintCols_, other.vintCols_)) return false; if (!tryMerge(floatCols_, other.floatCols_)) return false; diff --git a/PhysicsTools/NanoAOD/interface/UniqueString.h b/DataFormats/NanoAOD/interface/UniqueString.h similarity index 100% rename from PhysicsTools/NanoAOD/interface/UniqueString.h rename to DataFormats/NanoAOD/interface/UniqueString.h diff --git a/PhysicsTools/NanoAOD/src/FlatTable.cc b/DataFormats/NanoAOD/src/FlatTable.cc similarity index 78% rename from PhysicsTools/NanoAOD/src/FlatTable.cc rename to DataFormats/NanoAOD/src/FlatTable.cc index 1064a88a755fd..e3015ed6df007 100644 --- a/PhysicsTools/NanoAOD/src/FlatTable.cc +++ b/DataFormats/NanoAOD/src/FlatTable.cc @@ -1,4 +1,4 @@ -#include +#include int FlatTable::columnIndex(const std::string & name) const { for (unsigned int i = 0, n = columns_.size(); i < n; ++i) { diff --git a/DataFormats/NanoAOD/src/MergeableCounterTable.cc b/DataFormats/NanoAOD/src/MergeableCounterTable.cc new file mode 100644 index 0000000000000..198dc90966422 --- /dev/null +++ b/DataFormats/NanoAOD/src/MergeableCounterTable.cc @@ -0,0 +1 @@ +#include "DataFormats/NanoAOD/interface/MergeableCounterTable.h" diff --git a/DataFormats/NanoAOD/src/classes.h b/DataFormats/NanoAOD/src/classes.h new file mode 100644 index 0000000000000..e98cbc8ab12ab --- /dev/null +++ b/DataFormats/NanoAOD/src/classes.h @@ -0,0 +1,14 @@ +#include "Rtypes.h" + +#include +#include +#include +#include "DataFormats/Common/interface/Wrapper.h" + +namespace DataFormats_NanoAOD { + struct dictionary { + edm::Wrapper w_table; + edm::Wrapper w_mtable; + edm::Wrapper w_ustr; + }; +} diff --git a/DataFormats/NanoAOD/src/classes_def.xml b/DataFormats/NanoAOD/src/classes_def.xml new file mode 100644 index 0000000000000..c53c27cac0d61 --- /dev/null +++ b/DataFormats/NanoAOD/src/classes_def.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PhysicsTools/NanoAOD/BuildFile.xml b/PhysicsTools/NanoAOD/BuildFile.xml index fa73a54e575a2..d01dc83a278a4 100644 --- a/PhysicsTools/NanoAOD/BuildFile.xml +++ b/PhysicsTools/NanoAOD/BuildFile.xml @@ -3,6 +3,7 @@ + diff --git a/PhysicsTools/NanoAOD/plugins/BuildFile.xml b/PhysicsTools/NanoAOD/plugins/BuildFile.xml index d2c613c0a138b..1125b15bc0007 100644 --- a/PhysicsTools/NanoAOD/plugins/BuildFile.xml +++ b/PhysicsTools/NanoAOD/plugins/BuildFile.xml @@ -7,7 +7,7 @@ - + diff --git a/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc b/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc index 517bb9b24cbdf..cfb0c2205ef37 100644 --- a/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc @@ -3,7 +3,7 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" #include "DataFormats/Common/interface/View.h" #include "DataFormats/Candidate/interface/Candidate.h" #include "DataFormats/HepMCCandidate/interface/GenParticle.h" diff --git a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc index 4dc8f10774554..1a7794b82c701 100644 --- a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc @@ -2,8 +2,8 @@ #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/Run.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" -#include "PhysicsTools/NanoAOD/interface/MergableCounterTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/MergeableCounterTable.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" @@ -120,7 +120,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer("LHEScale"); produces("LHEPdf"); produces("LHENamed"); - produces(); + produces(); if (namedWeightIDs_.size() != namedWeightLabels_.size()) { throw cms::Exception("Configuration", "Size mismatch between namedWeightIDs & namedWeightLabels"); } @@ -355,7 +355,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer(); + auto out = std::make_unique(); out->addInt("genEventCount", "event count", runCounter->num); out->addFloat("genEventSumw", "sum of gen weights", runCounter->sumw); out->addFloat("genEventSumw2", "sum of gen (weight^2)", runCounter->sumw2); diff --git a/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc index 33fbc08df0618..59c26d2a9282f 100644 --- a/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc @@ -1,6 +1,6 @@ #include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" #include "FWCore/Framework/interface/ConsumesCollector.h" #include "DataFormats/Candidate/interface/Candidate.h" diff --git a/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc b/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc index 2f71de009459d..d3f89e1ad3ac8 100644 --- a/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc @@ -3,7 +3,7 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" #include diff --git a/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc b/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc index 966a46a1335f9..b6ae1c19d4445 100644 --- a/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc @@ -14,7 +14,7 @@ #include "DataFormats/PatCandidates/interface/Muon.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/MuonReco/interface/MuonSelectors.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" class MuonIDTableProducer : public edm::global::EDProducer<> { diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc b/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc index b1ce12973e1d2..0c4e7df51ff51 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc @@ -17,7 +17,7 @@ // #include "PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" // // constructors and destructor diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc index c6b84b69c8e60..f605147323cc2 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc @@ -34,8 +34,8 @@ #include "DataFormats/Provenance/interface/BranchType.h" #include "DataFormats/Provenance/interface/BranchDescription.h" #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" -#include "PhysicsTools/NanoAOD/interface/UniqueString.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/UniqueString.h" #include "PhysicsTools/NanoAOD/plugins/TableOutputBranches.h" #include "PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.h" #include "PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h" @@ -247,7 +247,7 @@ NanoAODOutputModule::openFile(edm::FileBlock const&) { } for (const auto & keep : keeps[edm::InRun]) { - if(keep.first->className() == "MergableCounterTable" ) + if(keep.first->className() == "MergeableCounterTable" ) m_runTables.push_back(SummaryTableOutputBranches(keep.first, keep.second)); else if(keep.first->className() == "UniqueString" && keep.first->moduleLabel() == "nanoMetadata") m_nanoMetadata.emplace_back(keep.first->productInstanceName(), keep.second); @@ -317,7 +317,7 @@ NanoAODOutputModule::fillDescriptions(edm::ConfigurationDescriptions& descriptio ->setComment("Change the OutputModule name in the fwk job report to fake PoolOutputModule. This is needed to run on cran (and publish) till crab is fixed"); //replace with whatever you want to get from the EDM by default - const std::vector keep = {"drop *", "keep FlatTable_*Table_*_*", "keep edmTriggerResults_*_*_*", "keep MergableCounterTable_*Table_*_*", "keep UniqueString_nanoMetadata_*_*"}; + const std::vector keep = {"drop *", "keep FlatTable_*Table_*_*", "keep edmTriggerResults_*_*_*", "keep MergeableCounterTable_*Table_*_*", "keep UniqueString_nanoMetadata_*_*"}; edm::OutputModule::fillDescription(desc, keep); //Used by Workflow management for their own meta data diff --git a/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc b/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc index 90ca3f34a17a1..96bda47e3c1e9 100644 --- a/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc @@ -1,6 +1,6 @@ #include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" #include diff --git a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc index 335e5516db90f..05ce64638e86a 100644 --- a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc @@ -3,7 +3,7 @@ #include "FWCore/Framework/interface/ConsumesCollector.h" #include "DataFormats/Common/interface/View.h" #include "DataFormats/Common/interface/ValueMap.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" #include "CommonTools/Utils/interface/StringCutObjectSelector.h" #include "CommonTools/Utils/interface/StringObjectFunction.h" diff --git a/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc index 356ac139823cd..811c485610411 100644 --- a/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc +++ b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc @@ -46,7 +46,7 @@ SummaryTableOutputBranches::fillVectorBranches(const std::vector & tabcols, void -SummaryTableOutputBranches::defineBranchesFromFirstEvent(const MergableCounterTable & tab, TTree & tree) +SummaryTableOutputBranches::defineBranchesFromFirstEvent(const MergeableCounterTable & tab, TTree & tree) { makeScalarBranches(tab.intCols(), tree, "L", m_intBranches); makeScalarBranches(tab.floatCols(), tree, "D", m_floatBranches); @@ -61,9 +61,9 @@ SummaryTableOutputBranches::defineBranchesFromFirstEvent(const MergableCounterTa void SummaryTableOutputBranches::fill(const edm::OccurrenceForOutput &iWhatever, TTree & tree) { - edm::Handle handle; + edm::Handle handle; iWhatever.getByToken(m_token, handle); - const MergableCounterTable & tab = *handle; + const MergeableCounterTable & tab = *handle; if(!m_branchesBooked) { defineBranchesFromFirstEvent(tab, tree); diff --git a/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h index f11c403b2c747..99dda07f4bb2a 100644 --- a/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h +++ b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h @@ -5,7 +5,7 @@ #include #include #include "FWCore/Framework/interface/OccurrenceForOutput.h" -#include "PhysicsTools/NanoAOD/interface/MergableCounterTable.h" +#include "DataFormats/NanoAOD/interface/MergeableCounterTable.h" #include "DataFormats/Provenance/interface/BranchDescription.h" #include "FWCore/Utilities/interface/EDGetToken.h" @@ -14,7 +14,7 @@ class SummaryTableOutputBranches { SummaryTableOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken & token ) : m_token(token), m_branchesBooked(false) { - if (desc->className() != "MergableCounterTable") throw cms::Exception("Configuration", "NanoAODOutputModule can only write out MergableCounterTable objects"); + if (desc->className() != "MergeableCounterTable") throw cms::Exception("Configuration", "NanoAODOutputModule can only write out MergableCounterTable objects"); } void fill(const edm::OccurrenceForOutput &iWhatever, TTree & tree) ; @@ -40,7 +40,7 @@ class SummaryTableOutputBranches { bool m_branchesBooked; - void defineBranchesFromFirstEvent(const MergableCounterTable & tab, TTree & tree) ; + void defineBranchesFromFirstEvent(const MergeableCounterTable & tab, TTree & tree) ; template void makeScalarBranches(const std::vector & tabcols, TTree & tree, const std::string & rootType, std::vector & branches); template void makeVectorBranches(const std::vector & tabcols, TTree & tree, const std::string & rootType, std::vector & branches ); diff --git a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h index b951a5b1f06a9..e461760366f78 100644 --- a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h +++ b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h @@ -5,7 +5,7 @@ #include #include #include "FWCore/Framework/interface/EventForOutput.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" #include "DataFormats/Provenance/interface/BranchDescription.h" #include "FWCore/Utilities/interface/EDGetToken.h" diff --git a/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc b/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc index 0828130a802cf..5dc83dbff801b 100644 --- a/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc @@ -16,7 +16,7 @@ #include "CommonTools/Utils/interface/StringCutObjectSelector.h" #include "CommonTools/Utils/interface/StringObjectFunction.h" #include "DataFormats/Math/interface/deltaR.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" class TriggerObjectTableProducer : public edm::global::EDProducer<> { public: diff --git a/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc b/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc index 2bbaa70535a3d..266bb1239dcb3 100644 --- a/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/UniqueStringProducer.cc @@ -1,7 +1,7 @@ #include "FWCore/Framework/interface/global/EDProducer.h" #include "FWCore/Framework/interface/Run.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "PhysicsTools/NanoAOD/interface/UniqueString.h" +#include "DataFormats/NanoAOD/interface/UniqueString.h" #include diff --git a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc index 0d4e418ab5d66..de1835b314e13 100644 --- a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc @@ -35,7 +35,7 @@ #include "CommonTools/Utils/interface/StringCutObjectSelector.h" -#include "PhysicsTools/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" #include "RecoVertex/VertexTools/interface/VertexDistance3D.h" #include "RecoVertex/VertexPrimitives/interface/ConvertToFromReco.h" #include "RecoVertex/VertexPrimitives/interface/VertexState.h" diff --git a/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py b/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py index b095368d92620..c059641b07e48 100644 --- a/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py +++ b/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py @@ -5,7 +5,7 @@ 'drop *', "keep FlatTable_*Table_*_*", # event data "keep edmTriggerResults_*_*_*", # event data - "keep MergableCounterTable_*Table_*_*", # accumulated per/run or per/lumi data + "keep MergeableCounterTable_*Table_*_*", # accumulated per/run or per/lumi data "keep UniqueString_nanoMetadata_*_*", # basic metadata ) ) diff --git a/PhysicsTools/NanoAOD/src/MergeableCounterTable.cc b/PhysicsTools/NanoAOD/src/MergeableCounterTable.cc deleted file mode 100644 index 8cce957930955..0000000000000 --- a/PhysicsTools/NanoAOD/src/MergeableCounterTable.cc +++ /dev/null @@ -1 +0,0 @@ -#include "PhysicsTools/NanoAOD/interface/MergableCounterTable.h" diff --git a/PhysicsTools/NanoAOD/src/classes.h b/PhysicsTools/NanoAOD/src/classes.h deleted file mode 100644 index 38e742bf9d2f5..0000000000000 --- a/PhysicsTools/NanoAOD/src/classes.h +++ /dev/null @@ -1,14 +0,0 @@ -#include "Rtypes.h" - -#include -#include -#include -#include "DataFormats/Common/interface/Wrapper.h" - -namespace PhysicsTools_NanoAOD { - struct dictionary { - edm::Wrapper w_table; - edm::Wrapper w_mtable; - edm::Wrapper w_ustr; - }; -} diff --git a/PhysicsTools/NanoAOD/src/classes_def.xml b/PhysicsTools/NanoAOD/src/classes_def.xml deleted file mode 100644 index 3a0e14a1457be..0000000000000 --- a/PhysicsTools/NanoAOD/src/classes_def.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 1eabc06aa46d380071af7f3fcdf8227a20d1e54f Mon Sep 17 00:00:00 2001 From: Andrea Date: Mon, 25 Sep 2017 10:05:12 +0200 Subject: [PATCH 14/36] remove auto in function decl --- .../NanoAOD/interface/MatchingUtils.h | 6 ++++-- .../NanoAOD/plugins/LeptonJetVarProducer.cc | 5 +++-- .../NanoAOD/plugins/PATObjectCrossLinker.cc | 20 +++++++++++-------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/PhysicsTools/NanoAOD/interface/MatchingUtils.h b/PhysicsTools/NanoAOD/interface/MatchingUtils.h index 9fe55e7e6b1cf..886a710bb0e46 100644 --- a/PhysicsTools/NanoAOD/interface/MatchingUtils.h +++ b/PhysicsTools/NanoAOD/interface/MatchingUtils.h @@ -5,7 +5,8 @@ #include #include "CommonTools/Utils/interface/StringCutObjectSelector.h" */ -bool matchByCommonSourceCandidatePtr(const auto & c1, const auto & c2) { +template +bool matchByCommonSourceCandidatePtr(const C1 & c1, const C2 & c2) { for(unsigned int i1 = 0 ; i1 < c1.numberOfSourceCandidatePtrs();i1++){ auto c1s=c1.sourceCandidatePtr(i1); for(unsigned int i2 = 0 ; i2 < c2.numberOfSourceCandidatePtrs();i2++) { @@ -15,7 +16,8 @@ bool matchByCommonSourceCandidatePtr(const auto & c1, const auto & c2) { return false; } -bool matchByCommonParentSuperClusterRef(const auto & c1, const auto & c2) { +template +bool matchByCommonParentSuperClusterRef(const C1 & c1, const C2 & c2) { auto c1s = c1.parentSuperCluster(); auto c2s = c2.parentSuperCluster(); return (c1s == c2s); diff --git a/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc b/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc index 43c598e36be84..f05abb454cf1e 100644 --- a/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc @@ -37,6 +37,7 @@ #include "TLorentzVector.h" #include "DataFormats/Common/interface/View.h" +#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" #include "PhysicsTools/NanoAOD/interface/MatchingUtils.h" @@ -64,7 +65,7 @@ class LeptonJetVarProducer : public edm::global::EDProducer<> { private: void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; - std::tuple calculatePtRatioRel(auto &lep, auto &jet, auto &vtx) const; + std::tuple calculatePtRatioRel(edm::Ptr lep, edm::Ptr jet, const reco::Vertex &vtx) const; // ----------member data --------------------------- @@ -153,7 +154,7 @@ LeptonJetVarProducer::produce(edm::StreamID streamID, edm::Event& iEvent, con template std::tuple -LeptonJetVarProducer::calculatePtRatioRel(auto &lep, auto &jet, auto &vtx) const { +LeptonJetVarProducer::calculatePtRatioRel(edm::Ptr lep, edm::Ptr jet, const reco::Vertex &vtx) const { auto rawp4_ = jet->correctedP4("Uncorrected"); auto rawp4 = TLorentzVector(rawp4_.pt(),rawp4_.eta(),rawp4_.phi(),rawp4_.energy()); diff --git a/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc b/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc index d93c52d0a0538..6a9c108f01010 100644 --- a/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc @@ -55,11 +55,13 @@ class PATObjectCrossLinker : public edm::stream::EDProducer<> { void produce(edm::Event&, const edm::EventSetup&) override; void endStream() override; - void matchOneToMany(const auto & refProdOne, auto & itemsOne, const std::string & nameOne, - const auto & refProdMany, auto& itemsMany, const std::string & nameMany); + template < class C1, class C2,class C3, class C4> + void matchOneToMany(const C1 & refProdOne, C2 & itemsOne, const std::string & nameOne, + const C3 & refProdMany, C4& itemsMany, const std::string & nameMany); - void matchElectronToPhoton(const auto & refProdOne, auto & itemsOne, const std::string & nameOne, - const auto & refProdMany, auto& itemsMany, const std::string & nameMany); + template < class C1, class C2,class C3,class C4> + void matchElectronToPhoton(const C1 & refProdOne, C2 & itemsOne, const std::string & nameOne, + const C3 & refProdMany, C4& itemsMany, const std::string & nameMany); //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; @@ -112,8 +114,9 @@ PATObjectCrossLinker::~PATObjectCrossLinker() // ------------ method called to produce the data ------------ /// -void PATObjectCrossLinker::matchOneToMany(const auto & refProdOne, auto & itemsOne, const std::string & nameOne, - const auto & refProdMany, auto& itemsMany, const std::string & nameMany) +template < class C1, class C2,class C3,class C4> +void PATObjectCrossLinker::matchOneToMany(const C1 & refProdOne, C2 & itemsOne, const std::string & nameOne, + const C3 & refProdMany, C4& itemsMany, const std::string & nameMany) { size_t ji=0; for(auto & j: itemsOne) { @@ -131,8 +134,9 @@ void PATObjectCrossLinker::matchOneToMany(const auto & refProdOne, auto & itemsO } } -void PATObjectCrossLinker::matchElectronToPhoton(const auto & refProdOne, auto & itemsOne, const std::string & nameOne, - const auto & refProdMany, auto& itemsMany, const std::string & nameMany) +template < class C1, class C2,class C3,class C4> +void PATObjectCrossLinker::matchElectronToPhoton(const C1 & refProdOne, C2 & itemsOne, const std::string & nameOne, + const C3 & refProdMany, C4& itemsMany, const std::string & nameMany) { size_t ji=0; for(auto & j: itemsOne) { From 4c8d6a78ed6d0a6e524a182b69a0f5f0a45ab68c Mon Sep 17 00:00:00 2001 From: Andrea Date: Mon, 25 Sep 2017 17:10:22 +0200 Subject: [PATCH 15/36] add track met --- PhysicsTools/NanoAOD/python/met_cff.py | 27 +++++++++++++++++++++++-- PhysicsTools/NanoAOD/python/nano_cff.py | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/met_cff.py b/PhysicsTools/NanoAOD/python/met_cff.py index a93a5a08d844a..59d2b430392f7 100644 --- a/PhysicsTools/NanoAOD/python/met_cff.py +++ b/PhysicsTools/NanoAOD/python/met_cff.py @@ -4,6 +4,15 @@ ##################### User floats producers, selectors ########################## +## this can be merged with chsFor soft activity if we keep the same selection +chsForTkMet = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string('charge()!=0 && pvAssociationQuality()>=5 && vertexRef().key()==0')) +tkMet = cms.EDProducer( + "PFMETProducer", + src = cms.InputTag("chsForTkMet"), + alias = cms.string('tkMet'), + globalThreshold = cms.double(0.0), + calculateSignificance = cms.bool(False), +) @@ -49,6 +58,18 @@ ), ) +tkMetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("tkMet"), + name = cms.string("TkMET"), + doc = cms.string("Track MET computed with tracks from PV0 ( pvAssociationQuality()>=5 ) "), + singleton = cms.bool(True), # there's always exactly one MET per event + extension = cms.bool(True), # this is the main table for the MET + variables = cms.PSet(PTVars, + sumEt = Var("sumEt()", float, doc="scalar sum of Et",precision=10), + ), +) + + metMCTable = cms.EDProducer("SimpleCandidateFlatTableProducer", src = metTable.src, name = cms.string("MET"), @@ -61,7 +82,9 @@ ), ) -#metSequence = cms.Sequence() -metTables = cms.Sequence( metTable + caloMetTable + puppiMetTable ) + + +metSequence = cms.Sequence(chsForTkMet+tkMet) +metTables = cms.Sequence( metTable + caloMetTable + puppiMetTable +tkMetTable) metMC = cms.Sequence( metMCTable ) diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index 2efeb98e04e94..58bea6481d0a1 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -62,7 +62,7 @@ l1bits=cms.EDProducer("L1TriggerResultsConverter", src=cms.InputTag("gtStage2Digis"), legacyL1=cms.bool(False)) nanoSequence = cms.Sequence( - nanoMetadata + muonSequence + jetSequence + tauSequence + electronSequence+photonSequence+vertexSequence+#metSequence+ + nanoMetadata + muonSequence + jetSequence + tauSequence + electronSequence+photonSequence+vertexSequence+metSequence+ isoTrackSequence + # must be after all the leptons linkedObjects + jetTables + muonTables + tauTables + electronTables + photonTables + globalTables +vertexTables+ metTables+simpleCleanerTable + triggerObjectTables + isoTrackTables + From c27a59bb9023a3431965792abd3a98158f28b3c2 Mon Sep 17 00:00:00 2001 From: Andrea Date: Mon, 25 Sep 2017 21:58:56 +0200 Subject: [PATCH 16/36] add hbb tagger, fix doc strings --- PhysicsTools/NanoAOD/python/jets_cff.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/jets_cff.py b/PhysicsTools/NanoAOD/python/jets_cff.py index 8b9bd92a8c4fc..0c02cc2a03085 100644 --- a/PhysicsTools/NanoAOD/python/jets_cff.py +++ b/PhysicsTools/NanoAOD/python/jets_cff.py @@ -173,10 +173,10 @@ msoftdrop = Var("userFloat('ak8PFJetsCHSValueMap:ak8PFJetsCHSSoftDropMass')",float, doc="Soft drop mass",precision=10), mpruned = Var("userFloat('ak8PFJetsCHSValueMap:ak8PFJetsCHSPrunedMass')", float, doc="Pruned mass",precision=10), - btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10), - btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')",float,doc="CMVA V2 btag discriminator",precision=10), - btagDeepBB = Var("bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="CMVA V2 btag discriminator",precision=10), + btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')",float,doc="DeepCSV B btag discriminator",precision=10), + btagDeepBB = Var("bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="DeepCSV BB btag discriminator",precision=10), + btagHbb = Var("bDiscriminator('pfBoostedDoubleSecondaryVertexAK8BJetTags')",float,doc="Higgs to BB tagger discriminator",precision=10), subJetIdx1 = Var("?numberOfSourceCandidatePtrs()>0 && sourceCandidatePtr(0).numberOfSourceCandidatePtrs()>0?sourceCandidatePtr(0).key():-1", int, doc="index of first subjet"), From fae71a4157a1b2aab3fb95d79bf7ac9f5eba918b Mon Sep 17 00:00:00 2001 From: Giovanni Date: Tue, 26 Sep 2017 17:02:54 +0200 Subject: [PATCH 17/36] Cleanup MET naming conventions --- PhysicsTools/NanoAOD/python/met_cff.py | 45 +++++++++++++++++--------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/met_cff.py b/PhysicsTools/NanoAOD/python/met_cff.py index 59d2b430392f7..df33266b41b8e 100644 --- a/PhysicsTools/NanoAOD/python/met_cff.py +++ b/PhysicsTools/NanoAOD/python/met_cff.py @@ -6,8 +6,7 @@ ##################### User floats producers, selectors ########################## ## this can be merged with chsFor soft activity if we keep the same selection chsForTkMet = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string('charge()!=0 && pvAssociationQuality()>=5 && vertexRef().key()==0')) -tkMet = cms.EDProducer( - "PFMETProducer", +tkMet = cms.EDProducer("PFMETProducer", src = cms.InputTag("chsForTkMet"), alias = cms.string('tkMet'), globalThreshold = cms.double(0.0), @@ -25,7 +24,6 @@ extension = cms.bool(False), # this is the main table for the MET variables = cms.PSet(PTVars, sumEt = Var("sumEt()", float, doc="scalar sum of Et",precision=10), - rawEt = Var("uncorPt", float, doc="raw (uncorrected) scalar sum of Et",precision=10), covXX = Var("getSignificanceMatrix().At(0,0)",float,doc="xx element of met covariance matrix", precision=8), covXY = Var("getSignificanceMatrix().At(0,1)",float,doc="xy element of met covariance matrix", precision=8), covYY = Var("getSignificanceMatrix().At(1,1)",float,doc="yy element of met covariance matrix", precision=8), @@ -34,22 +32,37 @@ ), ) + +rawMetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = metTable.src, + name = cms.string("RawMET"), + doc = cms.string("raw PF MET"), + singleton = cms.bool(True), # there's always exactly one MET per event + extension = cms.bool(False), # this is the main table for the MET + variables = cms.PSet(#NOTA BENE: we don't copy PTVars here! + pt = Var("uncorPt", float, doc="pt", precision=10), + phi = Var("uncorPhi", float, doc="phi", precision=10), + sumEt = Var("uncorSumEt", float, doc="scalar sum of Et", precision=10), + ), +) + + caloMetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", src = metTable.src, - name = cms.string("METCalo"), - doc = cms.string("Calo MET"), + name = cms.string("CaloMET"), + doc = cms.string("CaloMET"), singleton = cms.bool(True), # there's always exactly one MET per event extension = cms.bool(False), # this is the main table for the MET variables = cms.PSet(#NOTA BENE: we don't copy PTVars here! - pt = Var("caloMETPt", float, precision=10), - phi = Var("caloMETPhi", float, precision=10), + pt = Var("caloMETPt", float, doc="pt", precision=10), + phi = Var("caloMETPhi", float, doc="phi", precision=10), sumEt = Var("caloMETSumEt", float, doc="scalar sum of Et", precision=10), ), ) puppiMetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", src = cms.InputTag("slimmedMETsPuppi"), - name = cms.string("METpuppi"), + name = cms.string("PuppiMET"), doc = cms.string("PUPPI MET"), singleton = cms.bool(True), # there's always exactly one MET per event extension = cms.bool(False), # this is the main table for the MET @@ -63,7 +76,7 @@ name = cms.string("TkMET"), doc = cms.string("Track MET computed with tracks from PV0 ( pvAssociationQuality()>=5 ) "), singleton = cms.bool(True), # there's always exactly one MET per event - extension = cms.bool(True), # this is the main table for the MET + extension = cms.bool(False), # this is the main table for the TkMET variables = cms.PSet(PTVars, sumEt = Var("sumEt()", float, doc="scalar sum of Et",precision=10), ), @@ -72,19 +85,19 @@ metMCTable = cms.EDProducer("SimpleCandidateFlatTableProducer", src = metTable.src, - name = cms.string("MET"), - doc = cms.string("Calo MET"), - singleton = cms.bool(True), # there's always exactly one MET per event - extension = cms.bool(True), # we add variables to the MET + name = cms.string("GenMET"), + doc = cms.string("Gen MET"), + singleton = cms.bool(True), + extension = cms.bool(False), variables = cms.PSet( - genPt = Var("genMET.pt", float, precision=10), - genPhi = Var("genMET.phi", float, precision=10), + pt = Var("genMET.pt", float, doc="pt", precision=10), + phi = Var("genMET.phi", float, doc="phi", precision=10), ), ) metSequence = cms.Sequence(chsForTkMet+tkMet) -metTables = cms.Sequence( metTable + caloMetTable + puppiMetTable +tkMetTable) +metTables = cms.Sequence( metTable + rawMetTable + caloMetTable + puppiMetTable + tkMetTable) metMC = cms.Sequence( metMCTable ) From 70e3238ce9caef9fe083437515f745fb87561ad5 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Tue, 26 Sep 2017 17:40:53 +0200 Subject: [PATCH 18/36] * save relative isolation instead of absolute one * add Iso(R=0.4) for muons (recommended by POG) * make variable names all start with a lowercase letter --- .../NanoAOD/plugins/IsoValueMapProducer.cc | 38 ++++++++++--------- PhysicsTools/NanoAOD/python/electrons_cff.py | 11 +++--- PhysicsTools/NanoAOD/python/isotracks_cff.py | 9 +++-- PhysicsTools/NanoAOD/python/muons_cff.py | 10 +++-- PhysicsTools/NanoAOD/python/photons_cff.py | 7 ++-- 5 files changed, 42 insertions(+), 33 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc b/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc index c6a27d76457bf..ef0af50659638 100644 --- a/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc @@ -45,7 +45,8 @@ template class IsoValueMapProducer : public edm::global::EDProducer<> { public: explicit IsoValueMapProducer(const edm::ParameterSet &iConfig): - src_(consumes>(iConfig.getParameter("src"))) + src_(consumes>(iConfig.getParameter("src"))), + relative_(iConfig.getParameter("relative")) { if ((typeid(T) == typeid(pat::Muon)) || (typeid(T) == typeid(pat::Electron)) || typeid(T) == typeid(pat::IsolatedTrack)) { produces>("miniIsoChg"); @@ -82,6 +83,7 @@ class IsoValueMapProducer : public edm::global::EDProducer<> { // ----------member data --------------------------- edm::EDGetTokenT> src_; + bool relative_; edm::EDGetTokenT rho_miniiso_; edm::EDGetTokenT rho_pfiso_; edm::EDGetTokenT> mapIsoChg_; @@ -143,18 +145,18 @@ IsoValueMapProducer::doMiniIso(edm::Event& iEvent) const{ std::vector miniIsoChg, miniIsoAll; miniIsoChg.reserve(nInput); miniIsoAll.reserve(nInput); - - for (uint i=0; i(src->ptrAt(i).get()); // temporarily needed - auto iso = obj->miniPFIsolation(); + + for (const auto & obj : *src) { + auto iso = obj.miniPFIsolation(); auto chg = iso.chargedHadronIso(); auto neu = iso.neutralHadronIso(); auto pho = iso.photonIso(); - auto ea = ea_miniiso_->getEffectiveArea(fabs(getEtaForEA(obj))); - float R = 10.0/std::min(std::max(obj->pt(), 50.0),200.0); + auto ea = ea_miniiso_->getEffectiveArea(fabs(getEtaForEA(&obj))); + float R = 10.0/std::min(std::max(obj.pt(), 50.0),200.0); ea *= std::pow(R/0.3,2); - miniIsoChg.push_back(chg); - miniIsoAll.push_back(chg+std::max(0.0,neu+pho-(*rho)*ea)); + float scale = relative_ ? 1.0/obj.pt() : 1; + miniIsoChg.push_back(scale*chg); + miniIsoAll.push_back(scale*(chg+std::max(0.0,neu+pho-(*rho)*ea))); } std::unique_ptr> miniIsoChgV(new edm::ValueMap()); @@ -194,15 +196,15 @@ IsoValueMapProducer::doPFIsoEle(edm::Event& iEvent) const{ PFIsoChg.reserve(nInput); PFIsoAll.reserve(nInput); - for (uint i=0; iptrAt(i).get(); - auto iso = obj->pfIsolationVariables(); + for (const auto & obj : *src) { + auto iso = obj.pfIsolationVariables(); auto chg = iso.sumChargedHadronPt; auto neu = iso.sumNeutralHadronEt; auto pho = iso.sumPhotonEt; - auto ea = ea_pfiso_->getEffectiveArea(fabs(getEtaForEA(obj))); - PFIsoChg.push_back(chg); - PFIsoAll.push_back(chg+std::max(0.0,neu+pho-(*rho)*ea)); + auto ea = ea_pfiso_->getEffectiveArea(fabs(getEtaForEA(&obj))); + float scale = relative_ ? 1.0/obj.pt() : 1; + PFIsoChg.push_back(scale*chg); + PFIsoAll.push_back(scale*(chg+std::max(0.0,neu+pho-(*rho)*ea))); } std::unique_ptr> PFIsoChgV(new edm::ValueMap()); @@ -252,8 +254,9 @@ IsoValueMapProducer::doPFIsoPho(edm::Event& iEvent) const { auto ea_chg = ea_pfiso_chg_->getEffectiveArea(fabs(getEtaForEA(obj.get()))); auto ea_neu = ea_pfiso_neu_->getEffectiveArea(fabs(getEtaForEA(obj.get()))); auto ea_pho = ea_pfiso_pho_->getEffectiveArea(fabs(getEtaForEA(obj.get()))); - PFIsoChg.push_back(std::max(0.0,chg-(*rho)*ea_chg)); - PFIsoAll.push_back(PFIsoChg.back()+std::max(0.0,neu-(*rho)*ea_neu)+std::max(0.0,pho-(*rho)*ea_pho)); + float scale = relative_ ? 1.0/obj->pt() : 1; + PFIsoChg.push_back(scale*std::max(0.0,chg-(*rho)*ea_chg)); + PFIsoAll.push_back(PFIsoChg.back()+scale*(std::max(0.0,neu-(*rho)*ea_neu)+std::max(0.0,pho-(*rho)*ea_pho))); } std::unique_ptr> PFIsoChgV(new edm::ValueMap()); @@ -278,6 +281,7 @@ void IsoValueMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("src")->setComment("input physics object collection"); + desc.add("relative")->setComment("compute relative isolation instead of absolute one"); if ((typeid(T) == typeid(pat::Muon)) || (typeid(T) == typeid(pat::Electron)) || typeid(T) == typeid(pat::IsolatedTrack)) { desc.add("EAFile_MiniIso")->setComment("txt file containing effective areas to be used for mini-isolation pileup subtraction"); desc.add("rho_MiniIso")->setComment("rho to be used for effective-area based mini-isolation pileup subtraction"); diff --git a/PhysicsTools/NanoAOD/python/electrons_cff.py b/PhysicsTools/NanoAOD/python/electrons_cff.py index 1faa862480c85..26255e597699c 100644 --- a/PhysicsTools/NanoAOD/python/electrons_cff.py +++ b/PhysicsTools/NanoAOD/python/electrons_cff.py @@ -37,6 +37,7 @@ isoForEle = cms.EDProducer("EleIsoValueMapProducer", src = cms.InputTag("slimmedElectrons"), + relative = cms.bool(False), rho_MiniIso = cms.InputTag("fixedGridRhoFastjetCentralNeutral"), rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"), EAFile_MiniIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Spring15/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_25ns.txt"), @@ -144,12 +145,12 @@ mvaSpring16HZZ = Var("userFloat('mvaSpring16HZZ')",float,doc="MVA HZZ ID score"), mvaSpring16HZZ_WPL = Var("userInt('mvaSpring16HZZ_WPL')",bool,doc="MVA HZZ ID loose WP"), cutBased = Var("userInt('cutbasedID_veto')+userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",int,doc="cut-based ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"), - VIDNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')",int,doc=_bitmapVIDForEle_docstring), + vidNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')",int,doc=_bitmapVIDForEle_docstring), cutBased_HLTPreSel = Var("userInt('cutbasedID_HLT')",int,doc="cut-based HLT pre-selection ID"), - miniPFIso_chg = Var("userFloat('miniIsoChg')",float,doc="mini PF isolation, charged component"), - miniPFIso_all = Var("userFloat('miniIsoAll')",float,doc="mini PF isolation, total (with scaled rho*EA PU corrections)"), - PFIso03_chg = Var("userFloat('PFIsoChg')",float,doc="PF isolation dR=0.3, charged component"), - PFIso03_all = Var("userFloat('PFIsoAll')",float,doc="PF isolation dR=0.3, total (with rho*EA PU corrections)"), + miniPFRelIso_chg = Var("userFloat('miniIsoChg')/pt",float,doc="mini PF relative isolation, charged component"), + miniPFRelIso_all = Var("userFloat('miniIsoAll')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)"), + pfRelIso03_chg = Var("userFloat('PFIsoChg')/pt",float,doc="PF relative isolation dR=0.3, charged component"), + pfRelIso03_all = Var("userFloat('PFIsoAll')/pt",float,doc="PF relative isolation dR=0.3, total (with rho*EA PU corrections)"), hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8), tightCharge = Var("isGsfCtfScPixChargeConsistent() + isGsfScPixChargeConsistent()",int,doc="Tight charge criteria (0:none, 1:isGsfScPixChargeConsistent, 2:isGsfCtfScPixChargeConsistent)"), convVeto = Var("passConversionVeto()",bool,doc="pass conversion veto"), diff --git a/PhysicsTools/NanoAOD/python/isotracks_cff.py b/PhysicsTools/NanoAOD/python/isotracks_cff.py index 4a252509a4620..98194503e9b7a 100644 --- a/PhysicsTools/NanoAOD/python/isotracks_cff.py +++ b/PhysicsTools/NanoAOD/python/isotracks_cff.py @@ -13,6 +13,7 @@ isoForIsoTk = cms.EDProducer("IsoTrackIsoValueMapProducer", src = cms.InputTag("finalIsolatedTracks"), + relative = cms.bool(True), rho_MiniIso = cms.InputTag("fixedGridRhoFastjetCentralNeutral"), EAFile_MiniIso = cms.FileInPath("PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt"), ) @@ -27,12 +28,12 @@ variables = cms.PSet(P3Vars, dz = Var("dz",float,doc="dz (with sign) wrt first PV, in cm",precision=10), dxy = Var("dxy",float,doc="dxy (with sign) wrt first PV, in cm",precision=10), - PFIso03_chg = Var("pfIsolationDR03().chargedHadronIso",float,doc="PF isolation dR=0.3, charged component",precision=10), - PFIso03_all = Var("(pfIsolationDR03().chargedHadronIso + max(pfIsolationDR03().neutralHadronIso + pfIsolationDR03().photonIso - pfIsolationDR03().puChargedHadronIso/2,0.0))",float,doc="PF isolation dR=0.3, total (deltaBeta corrections)",precision=10), + pfRelIso03_chg = Var("pfIsolationDR03().chargedHadronIso/pt",float,doc="PF relative isolation dR=0.3, charged component",precision=10), + pfRelIso03_all = Var("(pfIsolationDR03().chargedHadronIso + max(pfIsolationDR03().neutralHadronIso + pfIsolationDR03().photonIso - pfIsolationDR03().puChargedHadronIso/2,0.0))/pt",float,doc="PF relative isolation dR=0.3, total (deltaBeta corrections)",precision=10), ), externalVariables = cms.PSet( - miniPFIso_chg = ExtVar("isoForIsoTk:miniIsoChg",float,doc="mini PF isolation, charged component",precision=10), - miniPFIso_all = ExtVar("isoForIsoTk:miniIsoAll",float,doc="mini PF isolation, total (with scaled rho*EA PU corrections)",precision=10), + miniPFRelIso_chg = ExtVar("isoForIsoTk:miniIsoChg",float,doc="mini PF relative isolation, charged component",precision=10), + miniPFRelIso_all = ExtVar("isoForIsoTk:miniIsoAll",float,doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)",precision=10), ), ) diff --git a/PhysicsTools/NanoAOD/python/muons_cff.py b/PhysicsTools/NanoAOD/python/muons_cff.py index db7cdbadc5e76..7565652b1bf7d 100644 --- a/PhysicsTools/NanoAOD/python/muons_cff.py +++ b/PhysicsTools/NanoAOD/python/muons_cff.py @@ -3,6 +3,7 @@ isoForMu = cms.EDProducer("MuonIsoValueMapProducer", src = cms.InputTag("slimmedMuons"), + relative = cms.bool(False), rho_MiniIso = cms.InputTag("fixedGridRhoFastjetCentralNeutral"), EAFile_MiniIso = cms.FileInPath("PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt"), ) @@ -72,10 +73,11 @@ segmentComp = Var("segmentCompatibility()", float, doc = "muon segment compatibility", precision=14), # keep higher precision since people have cuts with 3 digits on this nStations = Var("numberOfMatchedStations", int, doc = "number of matched stations with default arbitration (segment & track)"), jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), - miniPFIso_chg = Var("userFloat('miniIsoChg')",float,doc="mini PF isolation, charged component"), - miniPFIso_all = Var("userFloat('miniIsoAll')",float,doc="mini PF isolation, total (with scaled rho*EA PU corrections)"), - PFIso03_chg = Var("pfIsolationR03().sumChargedHadronPt",float,doc="PF isolation dR=0.3, charged component"), - PFIso03_all = Var("(pfIsolationR03().sumChargedHadronPt + max(pfIsolationR03().sumNeutralHadronEt + pfIsolationR03().sumPhotonEt - pfIsolationR03().sumPUPt/2,0.0))",float,doc="PF isolation dR=0.3, total (deltaBeta corrections)"), + miniPFRelIso_chg = Var("userFloat('miniIsoChg')/pt",float,doc="mini PF relative isolation, charged component"), + miniPFRelIso_all = Var("userFloat('miniIsoAll')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)"), + pfRelIso03_chg = Var("pfIsolationR03().sumChargedHadronPt/pt",float,doc="PF relative isolation dR=0.3, charged component"), + pfRelIso03_all = Var("(pfIsolationR03().sumChargedHadronPt + max(pfIsolationR03().sumNeutralHadronEt + pfIsolationR03().sumPhotonEt - pfIsolationR03().sumPUPt/2,0.0))/pt",float,doc="PF relative isolation dR=0.3, total (deltaBeta corrections)"), + pfRelIso04_all = Var("(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))/pt",float,doc="PF relative isolation dR=0.4, total (deltaBeta corrections)"), tightCharge = Var("?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0",int,doc="Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"), ), externalVariables = cms.PSet( diff --git a/PhysicsTools/NanoAOD/python/photons_cff.py b/PhysicsTools/NanoAOD/python/photons_cff.py index 53ed6a6b4303c..bc6d639170181 100644 --- a/PhysicsTools/NanoAOD/python/photons_cff.py +++ b/PhysicsTools/NanoAOD/python/photons_cff.py @@ -37,6 +37,7 @@ isoForPho = cms.EDProducer("PhoIsoValueMapProducer", src = cms.InputTag("slimmedPhotons"), + relative = cms.bool(False), rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"), mapIsoChg = cms.InputTag("photonIDValueMapProducer:phoChargedIsolation"), mapIsoNeu = cms.InputTag("photonIDValueMapProducer:phoNeutralHadronIsolation"), @@ -94,14 +95,14 @@ r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=10), sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10), cutBased = Var("userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",int,doc="cut-based ID (0:fail, 1::loose, 2:medium, 3:tight)"), - VIDNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')",int,doc=_bitmapVIDForPho_docstring), + vidNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')",int,doc=_bitmapVIDForPho_docstring), electronVeto = Var("passElectronVeto()",bool,doc="pass electron veto"), pixelSeed = Var("hasPixelSeed()",bool,doc="has pixel seed"), mvaID = Var("userFloat('mvaID')",float,doc="MVA ID score",precision=10), mvaID_WP90 = Var("userInt('mvaID_WP90')",bool,doc="MVA ID WP90"), mvaID_WP80 = Var("userInt('mvaID_WP90')",bool,doc="MVA ID WP80"), - PFIso03_chg = Var("userFloat('PFIsoChg')",float,doc="PF isolation dR=0.3, charged component (with rho*EA PU corrections)"), - PFIso03_all = Var("userFloat('PFIsoAll')",float,doc="PF isolation dR=0.3, total (with rho*EA PU corrections)"), + pfRelIso03_chg = Var("userFloat('PFIsoChg')/pt",float,doc="PF relative isolation dR=0.3, charged component (with rho*EA PU corrections)"), + pfRelIso03_all = Var("userFloat('PFIsoAll')/pt",float,doc="PF relative isolation dR=0.3, total (with rho*EA PU corrections)"), hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8), ) ) From 860a578fbd6e5a45f0d5e4e807e28c86cea45c01 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Tue, 26 Sep 2017 17:49:03 +0200 Subject: [PATCH 19/36] mcMatchIdx -> genPartIdx (and the same for the flavour), to respect naming conventions on indices --- PhysicsTools/NanoAOD/python/electrons_cff.py | 2 +- PhysicsTools/NanoAOD/python/muons_cff.py | 2 +- PhysicsTools/NanoAOD/python/photons_cff.py | 2 +- PhysicsTools/NanoAOD/python/taus_cff.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/electrons_cff.py b/PhysicsTools/NanoAOD/python/electrons_cff.py index 26255e597699c..ab19dcfdbd640 100644 --- a/PhysicsTools/NanoAOD/python/electrons_cff.py +++ b/PhysicsTools/NanoAOD/python/electrons_cff.py @@ -179,7 +179,7 @@ mcMap = cms.InputTag("electronsMCMatchForTable"), objName = electronTable.name, objType = electronTable.name, #cms.string("Electron"), - branchName = cms.string("mcMatch"), + branchName = cms.string("genPart"), docString = cms.string("MC matching to status==1 electrons or photons"), ) diff --git a/PhysicsTools/NanoAOD/python/muons_cff.py b/PhysicsTools/NanoAOD/python/muons_cff.py index 7565652b1bf7d..ef9db95ed0351 100644 --- a/PhysicsTools/NanoAOD/python/muons_cff.py +++ b/PhysicsTools/NanoAOD/python/muons_cff.py @@ -109,7 +109,7 @@ mcMap = cms.InputTag("muonsMCMatchForTable"), objName = muonTable.name, objType = muonTable.name, #cms.string("Muon"), - branchName = cms.string("mcMatch"), + branchName = cms.string("genPart"), docString = cms.string("MC matching to status==1 muons"), ) diff --git a/PhysicsTools/NanoAOD/python/photons_cff.py b/PhysicsTools/NanoAOD/python/photons_cff.py index bc6d639170181..b367b65b87e32 100644 --- a/PhysicsTools/NanoAOD/python/photons_cff.py +++ b/PhysicsTools/NanoAOD/python/photons_cff.py @@ -125,7 +125,7 @@ mcMap = cms.InputTag("photonsMCMatchForTable"), objName = photonTable.name, objType = photonTable.name, #cms.string("Photon"), - branchName = cms.string("mcMatch"), + branchName = cms.string("genPart"), docString = cms.string("MC matching to status==1 photons or electrons"), ) diff --git a/PhysicsTools/NanoAOD/python/taus_cff.py b/PhysicsTools/NanoAOD/python/taus_cff.py index 31f98270fc8f9..9e6de49a2c0b3 100644 --- a/PhysicsTools/NanoAOD/python/taus_cff.py +++ b/PhysicsTools/NanoAOD/python/taus_cff.py @@ -128,7 +128,7 @@ def _tauId6WPMask(pattern,doc): mcMapVisTau = cms.InputTag("tausMCMatchHadTauForTable"), objName = tauTable.name, objType = tauTable.name, #cms.string("Tau"), - branchName = cms.string("mcMatch"), + branchName = cms.string("genPart"), docString = cms.string("MC matching to status==2 taus"), ) From dcd0f32c10d8cc807310ef0b34b1ae1a78347bac Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 27 Sep 2017 10:53:11 +0200 Subject: [PATCH 20/36] 80x compatible config via era switch --- PhysicsTools/NanoAOD/python/nano_cff.py | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index 2efeb98e04e94..2325120af99aa 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -70,6 +70,7 @@ nanoSequenceMC = cms.Sequence(genParticleSequence + nanoSequence + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + globalTablesMC + genWeightsTable + genParticleTables + lheInfoTable) + def nanoAOD_customizeCommon(process): ## FIXME: make era-dependent? if not hasattr(process, 'miniAOD'): @@ -96,3 +97,43 @@ def nanoAOD_customizeMC(process): process.calibratedPatElectrons.isMC = cms.bool(True) process.calibratedPatPhotons.isMC = cms.bool(True) return process + +### Era dependent customization +from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy +run2_miniAOD_80XLegacy.toModify( + jetTable.variables.qgl, + expr="-1" +) +run2_miniAOD_80XLegacy.toModify( + unpackedPatTrigger, + patTriggerObjectsStandAlone = "selectedPatTrigger", + unpackFilterLabels = False +) +run2_miniAOD_80XLegacy.toModify( + fatJetTable.variables.mpruned, + expr = cms.string("userFloat(\'ak8PFJetsCHSPrunedMass\')"), +) +run2_miniAOD_80XLegacy.toModify( + fatJetTable.variables.msoftdrop, + expr = cms.string("userFloat(\'ak8PFJetsCHSSoftDropMass\')"), +) +run2_miniAOD_80XLegacy.toModify( + fatJetTable.variables.tau1, + expr = cms.string("userFloat(\'NjettinessAK8:tau1\')"), +) +run2_miniAOD_80XLegacy.toModify( + fatJetTable.variables.tau2, + expr = cms.string("userFloat(\'NjettinessAK8:tau2\')"), +) +run2_miniAOD_80XLegacy.toModify( + fatJetTable.variables.tau3, + expr = cms.string("userFloat(\'NjettinessAK8:tau3\')"), +) +#remove stuff +_80x_sequence = nanoSequence.copy() +_80x_sequence.remove(isoTrackTable) +_80x_sequence.remove(isoTrackSequence) +run2_miniAOD_80XLegacy.toReplaceWith( nanoSequence, _80x_sequence) + + + From ceacf76739df7aee8ff417b7a54c5d0231791584 Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 27 Sep 2017 10:52:34 +0200 Subject: [PATCH 21/36] missing entry in lookup to run cmsDriver --- Configuration/Applications/python/cmsDriverOptions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Configuration/Applications/python/cmsDriverOptions.py b/Configuration/Applications/python/cmsDriverOptions.py index 09b1ec27d7372..32151464d8969 100755 --- a/Configuration/Applications/python/cmsDriverOptions.py +++ b/Configuration/Applications/python/cmsDriverOptions.py @@ -101,6 +101,7 @@ def OptionsFromItems(items): "HARVESTING":"RECO", "ALCAHARVEST":"RECO", "PAT":"RECO", + "NANO":"PAT", "PATGEN":"GEN"} trimmedEvtType=options.evt_type.split('/')[-1] From 097fd2690acca5d5d5f1472146fceb3b831e18db Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 27 Sep 2017 18:05:02 +0200 Subject: [PATCH 22/36] Define a run2_nanoAOD_92X modifier --- Configuration/Eras/python/Modifier_run2_nanoAOD_92X_cff.py | 3 +++ Configuration/StandardSequences/python/Eras.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 Configuration/Eras/python/Modifier_run2_nanoAOD_92X_cff.py diff --git a/Configuration/Eras/python/Modifier_run2_nanoAOD_92X_cff.py b/Configuration/Eras/python/Modifier_run2_nanoAOD_92X_cff.py new file mode 100644 index 0000000000000..fb23bdb06d796 --- /dev/null +++ b/Configuration/Eras/python/Modifier_run2_nanoAOD_92X_cff.py @@ -0,0 +1,3 @@ +import FWCore.ParameterSet.Config as cms + +run2_nanoAOD_92X = cms.Modifier() diff --git a/Configuration/StandardSequences/python/Eras.py b/Configuration/StandardSequences/python/Eras.py index 8da896789fbbe..7f4837606f7a6 100644 --- a/Configuration/StandardSequences/python/Eras.py +++ b/Configuration/StandardSequences/python/Eras.py @@ -41,7 +41,7 @@ def __init__(self): 'phase2_hgcal', 'phase2_muon', 'phase2_timing', 'phase2_timing_layer','phase2_hcal', 'trackingLowPU', 'trackingPhase1', 'trackingPhase1QuadProp', 'ctpps_2016', 'trackingPhase2PU140', - 'tracker_apv_vfp30_2016', 'run2_miniAOD_80XLegacy', + 'tracker_apv_vfp30_2016', 'run2_miniAOD_80XLegacy', 'run2_nanoAOD_92X', 'hcalHardcodeConditions', 'hcalSkipPacker'] internalUseModChains = ['run2_2017_noTrackingModifier'] From 58986b11e11f663799dc9dba6b609190a60cd815 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 27 Sep 2017 18:51:50 +0200 Subject: [PATCH 23/36] Update config to 80X and 92X eras --- .../NanoAOD/python/adaptFrom92X_cff.py | 12 ------- PhysicsTools/NanoAOD/python/electrons_cff.py | 26 +++++++++++--- PhysicsTools/NanoAOD/python/jets_cff.py | 10 ++++++ PhysicsTools/NanoAOD/python/muons_cff.py | 15 +++++++- PhysicsTools/NanoAOD/python/nano_cff.py | 36 +------------------ .../NanoAOD/python/triggerObjects_cff.py | 7 ++++ PhysicsTools/NanoAOD/test/nano_cfg.py | 8 ++--- 7 files changed, 57 insertions(+), 57 deletions(-) delete mode 100644 PhysicsTools/NanoAOD/python/adaptFrom92X_cff.py diff --git a/PhysicsTools/NanoAOD/python/adaptFrom92X_cff.py b/PhysicsTools/NanoAOD/python/adaptFrom92X_cff.py deleted file mode 100644 index 551ea99409c79..0000000000000 --- a/PhysicsTools/NanoAOD/python/adaptFrom92X_cff.py +++ /dev/null @@ -1,12 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -slimmedMuons = cms.EDProducer("PATMuonUpdater", - src = cms.InputTag("slimmedMuons", processName = cms.InputTag.skipCurrentProcess()), - vertices = cms.InputTag("offlineSlimmedPrimaryVertices") -) -slimmedElectrons = cms.EDProducer("PATElectronUpdater", - src = cms.InputTag("slimmedElectrons", processName = cms.InputTag.skipCurrentProcess()), - vertices = cms.InputTag("offlineSlimmedPrimaryVertices") -) - -adapt_nano = cms.Sequence( slimmedMuons + slimmedElectrons ) diff --git a/PhysicsTools/NanoAOD/python/electrons_cff.py b/PhysicsTools/NanoAOD/python/electrons_cff.py index 1faa862480c85..553c7bb6b2f48 100644 --- a/PhysicsTools/NanoAOD/python/electrons_cff.py +++ b/PhysicsTools/NanoAOD/python/electrons_cff.py @@ -1,4 +1,6 @@ import FWCore.ParameterSet.Config as cms +from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy +from Configuration.Eras.Modifier_run2_nanoAOD_92X_cff import run2_nanoAOD_92X from PhysicsTools.NanoAOD.common_cff import * from math import ceil,log @@ -57,10 +59,6 @@ srcCorr = cms.InputTag("calibratedPatElectrons"), ) -finalElectrons = cms.EDFilter("PATElectronRefSelector", - src = cms.InputTag("slimmedElectronsWithUserData"), - cut = cms.string("pt > 5 ") -) slimmedElectronsWithUserData = cms.EDProducer("PATElectronUserDataEmbedder", src = cms.InputTag("slimmedElectrons"), @@ -94,6 +92,19 @@ ), ) +# this below is used only in some eras +slimmedElectronsWithDZ = cms.EDProducer("PATElectronUpdater", + src = cms.InputTag("slimmedElectronsWithUserData"), + vertices = cms.InputTag("offlineSlimmedPrimaryVertices") +) + +finalElectrons = cms.EDFilter("PATElectronRefSelector", + src = cms.InputTag("slimmedElectronsWithUserData"), + cut = cms.string("pt > 5 ") +) +run2_miniAOD_80XLegacy.toModify(finalElectrons, src = "slimmedElectronsWithDZ") +run2_nanoAOD_92X.toModify(finalElectrons, src = "slimmedElectronsWithDZ") + electronMVATTH= cms.EDProducer("EleBaseMVAValueMapProducer", src = cms.InputTag("linkedObjects","electrons"), weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/el_BDTG.weights.xml"), @@ -129,7 +140,7 @@ #ptErr = Var("gsfTrack().ptError()",float,doc="pt error of the GSF track",precision=6), energyErr = Var("p4Error('P4_COMBINATION')*userFloat('eCorr')",float,doc="energy error of the cluster-track combination",precision=6), eCorr = Var("userFloat('eCorr')",float,doc="ratio of the calibrated energy/miniaod energy"), - dz = Var("abs(dB('PVDZ'))",float,doc="dz (with sign) wrt first PV, in cm",precision=10), + dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10), dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6), dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10), dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6), @@ -185,3 +196,8 @@ electronSequence = cms.Sequence(egmGsfElectronIDSequence + bitmapVIDForEle + isoForEle + ptRatioRelForEle + calibratedPatElectrons + energyCorrForEle + slimmedElectronsWithUserData + finalElectrons) electronTables = cms.Sequence (electronMVATTH + electronTable) electronMC = cms.Sequence(electronsMCMatchForTable + electronMCTable) + +_withDZ_sequence = electronSequence.copy() +_withDZ_sequence.replace(finalElectrons, slimmedElectronsWithDZ+finalElectrons) +run2_nanoAOD_92X.toReplaceWith(electronSequence, _withDZ_sequence) +run2_miniAOD_80XLegacy.toReplaceWith(electronSequence, _withDZ_sequence) diff --git a/PhysicsTools/NanoAOD/python/jets_cff.py b/PhysicsTools/NanoAOD/python/jets_cff.py index 8b9bd92a8c4fc..07148cd6ac4d0 100644 --- a/PhysicsTools/NanoAOD/python/jets_cff.py +++ b/PhysicsTools/NanoAOD/python/jets_cff.py @@ -1,4 +1,6 @@ import FWCore.ParameterSet.Config as cms +from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy + from PhysicsTools.NanoAOD.common_cff import * @@ -102,6 +104,8 @@ #jets are not as precise as muons jetTable.variables.pt.precision=10 +### Era dependent customization +run2_miniAOD_80XLegacy.toModify( jetTable.variables.qgl, expr="-1" ) bjetMVA= cms.EDProducer("BJetEnergyRegressionMVA", src = cms.InputTag("linkedObjects","jets"), @@ -191,6 +195,12 @@ # rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6), ) ) +### Era dependent customization +run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.mpruned, expr = cms.string("userFloat(\'ak8PFJetsCHSPrunedMass\')"),) +run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.msoftdrop, expr = cms.string("userFloat(\'ak8PFJetsCHSSoftDropMass\')"),) +run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau1, expr = cms.string("userFloat(\'NjettinessAK8:tau1\')"),) +run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau2, expr = cms.string("userFloat(\'NjettinessAK8:tau2\')"),) +run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau3, expr = cms.string("userFloat(\'NjettinessAK8:tau3\')"),) subJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer", src = cms.InputTag("slimmedJetsAK8PFPuppiSoftDropPacked","SubJets"), diff --git a/PhysicsTools/NanoAOD/python/muons_cff.py b/PhysicsTools/NanoAOD/python/muons_cff.py index db7cdbadc5e76..aaa8b24e28d00 100644 --- a/PhysicsTools/NanoAOD/python/muons_cff.py +++ b/PhysicsTools/NanoAOD/python/muons_cff.py @@ -1,4 +1,6 @@ import FWCore.ParameterSet.Config as cms +from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy +from Configuration.Eras.Modifier_run2_nanoAOD_92X_cff import run2_nanoAOD_92X from PhysicsTools.NanoAOD.common_cff import * isoForMu = cms.EDProducer("MuonIsoValueMapProducer", @@ -26,11 +28,18 @@ jetForLepJetVar = cms.InputTag("ptRatioRelForMu:jetForLepJetVar") # warning: Ptr is null if no match is found ), ) +# this below is used only in some eras +slimmedMuonsWithDZ = cms.EDProducer("PATMuonUpdater", + src = cms.InputTag("slimmedMuonsWithUserData"), + vertices = cms.InputTag("offlineSlimmedPrimaryVertices") +) finalMuons = cms.EDFilter("PATMuonRefSelector", src = cms.InputTag("slimmedMuonsWithUserData"), cut = cms.string("pt > 3 && track.isNonnull && isLooseMuon") ) +run2_miniAOD_80XLegacy.toModify(finalMuons, src = "slimmedMuonsWithDZ") +run2_nanoAOD_92X.toModify(finalMuons, src = "slimmedMuonsWithDZ") muonMVATTH= cms.EDProducer("MuonBaseMVAValueMapProducer", src = cms.InputTag("linkedObjects","muons"), @@ -63,7 +72,7 @@ extension = cms.bool(False), # this is the main table for the muons variables = cms.PSet(CandVars, ptErr = Var("bestTrack().ptError()", float, doc = "ptError of the muon track", precision=6), - dz = Var("abs(dB('PVDZ'))",float,doc="dz (with sign) wrt first PV, in cm",precision=10), + dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10), dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6), dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10), dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6), @@ -115,3 +124,7 @@ muonMC = cms.Sequence(muonsMCMatchForTable + muonMCTable) muonTables = cms.Sequence(muonMVATTH + muonTable + muonIDTable) +_withDZ_sequence = muonSequence.copy() +_withDZ_sequence.replace(finalMuons, slimmedMuonsWithDZ+finalMuons) +run2_nanoAOD_92X.toReplaceWith(muonSequence, _withDZ_sequence) +run2_miniAOD_80XLegacy.toReplaceWith(muonSequence, _withDZ_sequence) diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index 2325120af99aa..2c055f05d573e 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -72,11 +72,6 @@ def nanoAOD_customizeCommon(process): - ## FIXME: make era-dependent? - if not hasattr(process, 'miniAOD'): - # assume we're reading old miniAOD for the moment - process.load("PhysicsTools.NanoAOD.adaptFrom92X_cff") - process.nanoSequence.insert(0, process.adapt_nano) return process def nanoAOD_customizeData(process): @@ -87,7 +82,7 @@ def nanoAOD_customizeData(process): def nanoAOD_customizeMC(process): process = nanoAOD_customizeCommon(process) - ## FIXME: THIS SHOULD PROBABLY GO INTO Services_cff + ## FIXME: WILL NO LONGER NEED RANDOM SEEDS WHEN DETERMINISTIC SMEARING WILL BE IMPLEMENTED if not hasattr(process,'RandomNumberGeneratorService'): process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService") for X in 'calibratedPatElectrons','calibratedPatPhotons': @@ -100,35 +95,6 @@ def nanoAOD_customizeMC(process): ### Era dependent customization from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy -run2_miniAOD_80XLegacy.toModify( - jetTable.variables.qgl, - expr="-1" -) -run2_miniAOD_80XLegacy.toModify( - unpackedPatTrigger, - patTriggerObjectsStandAlone = "selectedPatTrigger", - unpackFilterLabels = False -) -run2_miniAOD_80XLegacy.toModify( - fatJetTable.variables.mpruned, - expr = cms.string("userFloat(\'ak8PFJetsCHSPrunedMass\')"), -) -run2_miniAOD_80XLegacy.toModify( - fatJetTable.variables.msoftdrop, - expr = cms.string("userFloat(\'ak8PFJetsCHSSoftDropMass\')"), -) -run2_miniAOD_80XLegacy.toModify( - fatJetTable.variables.tau1, - expr = cms.string("userFloat(\'NjettinessAK8:tau1\')"), -) -run2_miniAOD_80XLegacy.toModify( - fatJetTable.variables.tau2, - expr = cms.string("userFloat(\'NjettinessAK8:tau2\')"), -) -run2_miniAOD_80XLegacy.toModify( - fatJetTable.variables.tau3, - expr = cms.string("userFloat(\'NjettinessAK8:tau3\')"), -) #remove stuff _80x_sequence = nanoSequence.copy() _80x_sequence.remove(isoTrackTable) diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index 3ac7bb1da9449..d1e75d9cd67da 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -1,10 +1,17 @@ import FWCore.ParameterSet.Config as cms +from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy unpackedPatTrigger = cms.EDProducer("PATTriggerObjectStandAloneUnpacker", patTriggerObjectsStandAlone = cms.InputTag('slimmedPatTrigger'), triggerResults = cms.InputTag('TriggerResults::HLT'), unpackFilterLabels = cms.bool(True) ) +# ERA-dependent configuration +run2_miniAOD_80XLegacy.toModify( + unpackedPatTrigger, + patTriggerObjectsStandAlone = "selectedPatTrigger", + unpackFilterLabels = False +) triggerObjectTable = cms.EDProducer("TriggerObjectTableProducer", name= cms.string("TrigObj"), diff --git a/PhysicsTools/NanoAOD/test/nano_cfg.py b/PhysicsTools/NanoAOD/test/nano_cfg.py index 425655dc38cd8..082f4c14f0cbf 100644 --- a/PhysicsTools/NanoAOD/test/nano_cfg.py +++ b/PhysicsTools/NanoAOD/test/nano_cfg.py @@ -1,5 +1,6 @@ import FWCore.ParameterSet.Config as cms -process = cms.Process('NANO') +from Configuration.StandardSequences.Eras import eras +process = cms.Process('NANO',eras.Run2_2017,eras.run2_nanoAOD_92X) process.load("FWCore.MessageLogger.MessageLogger_cfi") @@ -7,7 +8,7 @@ process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") process.load('Configuration.StandardSequences.Services_cff') from Configuration.AlCa.autoCond import autoCond -process.GlobalTag.globaltag = autoCond['run2_mc'] +process.GlobalTag.globaltag = autoCond['phase1_2017_realistic'] process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) ) process.MessageLogger.cerr.FwkReport.reportEvery = 100 @@ -24,7 +25,6 @@ ] process.load("PhysicsTools.NanoAOD.nano_cff") -process.load("PhysicsTools.NanoAOD.adaptFrom92X_cff") process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService", calibratedPatElectrons = cms.PSet(initialSeed = cms.untracked.uint32(81), @@ -34,7 +34,7 @@ engineName = cms.untracked.string('TRandom3'), ), ) -process.nanoPath = cms.Path(process.adapt_nano + process.nanoSequenceMC) +process.nanoPath = cms.Path(process.nanoSequenceMC) process.calibratedPatElectrons.isMC = cms.bool(True) process.calibratedPatPhotons.isMC = cms.bool(True) #for data: From 3f52220232e34d88b3115f2048ffcd1b5fce8564 Mon Sep 17 00:00:00 2001 From: peruzzim Date: Mon, 2 Oct 2017 10:42:11 +0200 Subject: [PATCH 24/36] Relocate BaseMVAValueMapProducer to PhysicsTools/PatAlgos --- PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc | 2 +- .../plugins/BaseMVAValueMapProducer.cc | 6 +++--- .../plugins/BaseMVAValueMapProducer.h | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) rename PhysicsTools/{NanoAOD => PatAlgos}/plugins/BaseMVAValueMapProducer.cc (84%) rename PhysicsTools/{NanoAOD => PatAlgos}/plugins/BaseMVAValueMapProducer.h (96%) diff --git a/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc b/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc index fd8ca8cb9228c..d32d0458953af 100644 --- a/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc +++ b/PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc @@ -25,7 +25,7 @@ #include "RecoVertex/VertexPrimitives/interface/ConvertToFromReco.h" #include "RecoVertex/VertexPrimitives/interface/VertexState.h" -#include "PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h" +#include "PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.h" #include class BJetEnergyRegressionMVA : public BaseMVAValueMapProducer { diff --git a/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc b/PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.cc similarity index 84% rename from PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc rename to PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.cc index 94de717fb2b42..9f13f2f5f62cc 100644 --- a/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.cc @@ -1,9 +1,9 @@ // -*- C++ -*- // -// Package: PhysicsTools/NanoAOD +// Package: PhysicsTools/PatAlgos // Class: BaseMVAValueMapProducer // -/**\class BaseMVAValueMapProducer BaseMVAValueMapProducer.cc PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc +/**\class BaseMVAValueMapProducer BaseMVAValueMapProducer.cc PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.cc Description: [one line class summary] @@ -23,7 +23,7 @@ #include "DataFormats/PatCandidates/interface/Jet.h" -#include "PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h" +#include "PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.h" typedef BaseMVAValueMapProducer JetBaseMVAValueMapProducer; typedef BaseMVAValueMapProducer MuonBaseMVAValueMapProducer; diff --git a/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h b/PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.h similarity index 96% rename from PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h rename to PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.h index 3582dd58f5d60..2944b638dafef 100644 --- a/PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h +++ b/PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.h @@ -1,12 +1,12 @@ -#ifndef PhysicsTools_NanoAOD_BaseMVAValueMapProducer -#define PhysicsTools_NanoAOD_BaseMVAValueMapProducer +#ifndef PhysicsTools_PatAlgos_BaseMVAValueMapProducer +#define PhysicsTools_PatAlgos_BaseMVAValueMapProducer // -*- C++ -*- // -// Package: PhysicsTools/NanoAOD +// Package: PhysicsTools/PatAlgos // Class: BaseMVAValueMapProducer // -/**\class BaseMVAValueMapProducer BaseMVAValueMapProducer.cc PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.cc +/**\class BaseMVAValueMapProducer BaseMVAValueMapProducer.cc PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.cc Description: [one line class summary] From 7d6154b4cb5ae275d44f70fca7d1843a71ed18d8 Mon Sep 17 00:00:00 2001 From: peruzzim Date: Mon, 2 Oct 2017 10:49:55 +0200 Subject: [PATCH 25/36] Use unsigned int spec and minor optimization --- .../NanoAOD/plugins/IsoValueMapProducer.cc | 10 +++--- .../NanoAOD/plugins/LeptonJetVarProducer.cc | 10 +++--- .../plugins/VIDNestedWPBitmapProducer.cc | 32 +++++++++---------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc b/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc index ef0af50659638..bc2300f133dfe 100644 --- a/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/IsoValueMapProducer.cc @@ -60,7 +60,7 @@ class IsoValueMapProducer : public edm::global::EDProducer<> { ea_pfiso_.reset(new EffectiveAreas((iConfig.getParameter("EAFile_PFIso")).fullPath())); rho_pfiso_ = consumes(iConfig.getParameter("rho_PFIso")); } - if ((typeid(T) == typeid(pat::Photon))) { + else if ((typeid(T) == typeid(pat::Photon))) { produces>("PFIsoChg"); produces>("PFIsoAll"); mapIsoChg_ = consumes >(iConfig.getParameter("mapIsoChg")); @@ -140,7 +140,7 @@ IsoValueMapProducer::doMiniIso(edm::Event& iEvent) const{ edm::Handle rho; iEvent.getByToken(rho_miniiso_,rho); - unsigned nInput = src->size(); + unsigned int nInput = src->size(); std::vector miniIsoChg, miniIsoAll; miniIsoChg.reserve(nInput); @@ -190,7 +190,7 @@ IsoValueMapProducer::doPFIsoEle(edm::Event& iEvent) const{ edm::Handle rho; iEvent.getByToken(rho_pfiso_,rho); - unsigned nInput = src->size(); + unsigned int nInput = src->size(); std::vector PFIsoChg, PFIsoAll; PFIsoChg.reserve(nInput); @@ -240,13 +240,13 @@ IsoValueMapProducer::doPFIsoPho(edm::Event& iEvent) const { edm::Handle > mapIsoPho; iEvent.getByToken(mapIsoPho_, mapIsoPho); - unsigned nInput = src->size(); + unsigned int nInput = src->size(); std::vector PFIsoChg, PFIsoAll; PFIsoChg.reserve(nInput); PFIsoAll.reserve(nInput); - for (uint i=0; iptrAt(i); auto chg = (*mapIsoChg)[obj]; auto neu = (*mapIsoNeu)[obj]; diff --git a/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc b/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc index f05abb454cf1e..215df7612eb42 100644 --- a/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc @@ -100,8 +100,8 @@ LeptonJetVarProducer::produce(edm::StreamID streamID, edm::Event& iEvent, con edm::Handle> srcVtx; iEvent.getByToken(srcVtx_, srcVtx); - unsigned nJet = srcJet->size(); - unsigned nLep = srcLep->size(); + unsigned int nJet = srcJet->size(); + unsigned int nLep = srcLep->size(); std::vector ptRatio(nLep,-1); std::vector ptRel(nLep,-1); @@ -110,8 +110,8 @@ LeptonJetVarProducer::produce(edm::StreamID streamID, edm::Event& iEvent, con const auto & pv = (*srcVtx)[0]; - for (uint il = 0; ilptrAt(il); auto jet = srcJet->ptrAt(ij); if(matchByCommonSourceCandidatePtr(*lep,*jet)){ @@ -166,7 +166,7 @@ LeptonJetVarProducer::calculatePtRatioRel(edm::Ptr lep, edm: auto ptratio = lepp4.Pt()/jetp4.Pt(); auto ptrel = lepp4.Perp((jetp4-lepp4).Vect()); - unsigned jndau = 0; + unsigned int jndau = 0; for(const auto _d : jet->daughterPtrVector()) { const auto d = dynamic_cast(_d.get()); if (d->charge()==0) continue; diff --git a/PhysicsTools/NanoAOD/plugins/VIDNestedWPBitmapProducer.cc b/PhysicsTools/NanoAOD/plugins/VIDNestedWPBitmapProducer.cc index 4774d9298dd34..51f41b400b82d 100644 --- a/PhysicsTools/NanoAOD/plugins/VIDNestedWPBitmapProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/VIDNestedWPBitmapProducer.cc @@ -48,7 +48,7 @@ class VIDNestedWPBitmapProducer : public edm::stream::EDProducer<> { { auto vwp = iConfig.getParameter>("WorkingPoints"); for (auto wp : vwp) { - src_bitmaps_.push_back(consumes >(edm::InputTag(wp+std::string("Bitmap")))); + src_bitmaps_.push_back(consumes >(edm::InputTag(wp+std::string("Bitmap")))); src_cutflows_.push_back(consumes >(edm::InputTag(wp))); } nWP = src_bitmaps_.size(); @@ -71,16 +71,16 @@ class VIDNestedWPBitmapProducer : public edm::stream::EDProducer<> { // ----------member data --------------------------- edm::EDGetTokenT> src_; - std::vector > > src_bitmaps_; + std::vector > > src_bitmaps_; std::vector > > src_cutflows_; - unsigned nWP; - unsigned nBits; - unsigned nCuts; - std::vector res_; + unsigned int nWP; + unsigned int nBits; + unsigned int nCuts; + std::vector res_; bool isInit_; - void initNCuts(unsigned); + void initNCuts(unsigned int); }; @@ -100,22 +100,22 @@ VIDNestedWPBitmapProducer::produce(edm::Event& iEvent, const edm::EventSetup& edm::Handle> src; iEvent.getByToken(src_, src); - std::vector>> src_bitmaps(nWP); - for (uint i=0; i>> src_bitmaps(nWP); + for (unsigned int i=0; i>> src_cutflows(nWP); - for (uint i=0; i res; + std::vector res; auto npho = src->size(); - for (uint i=0; iptrAt(i); - for (uint j=0; j>k & 1) { if (res_[k]!=j) throw cms::Exception("Configuration","Trying to compress VID bitmaps which are not nested in the correct order for all cuts"); @@ -125,7 +125,7 @@ VIDNestedWPBitmapProducer::produce(edm::Event& iEvent, const edm::EventSetup& } int out = 0; - for (uint k=0; k::produce(edm::Event& iEvent, const edm::EventSetup& template void -VIDNestedWPBitmapProducer::initNCuts(uint n){ +VIDNestedWPBitmapProducer::initNCuts(unsigned int n){ nCuts = n; nBits = ceil(log2(nWP+1)); if (nBits*nCuts>sizeof(int)*8) throw cms::Exception("Configuration","Integer cannot contain the compressed VID bitmap information"); From fae6ee6f5b237d3f8a3c6cd357b25c45d5e1ef0d Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 2 Oct 2017 10:53:30 +0200 Subject: [PATCH 26/36] EGMEnergyVarProducer: uint -> unsigned int --- PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc b/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc index 6e111542be19d..44c9114f69f45 100644 --- a/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc @@ -90,9 +90,9 @@ EGMEnergyVarProducer::produce(edm::StreamID streamID, edm::Event& iEvent, con std::vector eCorr(nSrcCorr,-1); - for (uint ir = 0; irptrAt(ir); - for (uint ic = 0; icptrAt(ic); if(matchByCommonParentSuperClusterRef(*egm_raw,*egm_corr)){ eCorr[ir] = egm_corr->energy()/egm_raw->energy(); From 80d72849d2e65d5f071018fa8ee6c17144dee24c Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 2 Oct 2017 11:01:04 +0200 Subject: [PATCH 27/36] TriggerOutputBranches, VertexTableProducer: Use const & and fix indentation --- .../NanoAOD/plugins/TriggerOutputBranches.cc | 26 +++++++++---------- .../NanoAOD/plugins/VertexTableProducer.cc | 12 ++++----- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc index 54aa22a1213cf..82999a3cd10a5 100644 --- a/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc +++ b/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc @@ -10,7 +10,7 @@ TriggerOutputBranches::updateTriggerNames(TTree & tree, const edm::TriggerNames std::vector newNames(triggers.getTriggerNames()); if(newNames.empty()) { for(unsigned int j=0;jSetTitle(nb.title.c_str()); - nb.idx=j; + nb.idx=j; m_triggerBranches.push_back(nb); - for(size_t i=0;iFill(); // Back fill + for(size_t i=0;iFill(); // Back fill } - } + } } } @@ -75,8 +75,8 @@ void TriggerOutputBranches::fill(const edm::EventForOutput &iEvent,TTree & tree) const edm::TriggerNames &names = triggerNames(triggers); if(m_lastRun!=iEvent.id().run()) { - m_lastRun=iEvent.id().run(); - updateTriggerNames(tree,names,triggers); + m_lastRun=iEvent.id().run(); + updateTriggerNames(tree,names,triggers); } for (auto & pair : m_triggerBranches) fillColumn(pair, triggers); m_fills++; diff --git a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc index de1835b314e13..adc52daffc4db 100644 --- a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc @@ -149,12 +149,12 @@ VertexTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) for (const auto & sv : *svsIn) { if (svCut_(sv)) { Measurement1D dl= vdist.distance((*pvsIn)[0],VertexState(RecoVertex::convertPos(sv.position()),RecoVertex::convertError(sv.error()))); - if(dl.value() > dlenMin_ and dl.significance() > dlenSigMin_){ - dlen.push_back(dl.value()); - dlenSig.push_back(dl.significance()); - edm::Ptr c = svsIn->ptrAt(i); - selCandSv->push_back(c); - } + if(dl.value() > dlenMin_ and dl.significance() > dlenSigMin_){ + dlen.push_back(dl.value()); + dlenSig.push_back(dl.significance()); + edm::Ptr c = svsIn->ptrAt(i); + selCandSv->push_back(c); + } } i++; } From 6d3685588ee01a74c283532d777afa06ebf03632 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 2 Oct 2017 11:01:56 +0200 Subject: [PATCH 28/36] Remove LCG_DICT from BuildFiles --- DataFormats/NanoAOD/BuildFile.xml | 2 -- PhysicsTools/NanoAOD/BuildFile.xml | 2 -- 2 files changed, 4 deletions(-) diff --git a/DataFormats/NanoAOD/BuildFile.xml b/DataFormats/NanoAOD/BuildFile.xml index 178475a1a9d39..02ec339df90e2 100644 --- a/DataFormats/NanoAOD/BuildFile.xml +++ b/DataFormats/NanoAOD/BuildFile.xml @@ -3,8 +3,6 @@ - - diff --git a/PhysicsTools/NanoAOD/BuildFile.xml b/PhysicsTools/NanoAOD/BuildFile.xml index d01dc83a278a4..c36ed4184624a 100644 --- a/PhysicsTools/NanoAOD/BuildFile.xml +++ b/PhysicsTools/NanoAOD/BuildFile.xml @@ -5,8 +5,6 @@ - - From 6fc5d71232e0e7f3c46b0b2b9c7435aad5b9c8a3 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 2 Oct 2017 11:08:08 +0200 Subject: [PATCH 29/36] DataFormats/NanoAOD: include syntax and adding comments --- DataFormats/NanoAOD/interface/FlatTable.h | 4 ++-- DataFormats/NanoAOD/interface/MergeableCounterTable.h | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DataFormats/NanoAOD/interface/FlatTable.h b/DataFormats/NanoAOD/interface/FlatTable.h index 8fda70f7992d7..c9532daf8c525 100644 --- a/DataFormats/NanoAOD/interface/FlatTable.h +++ b/DataFormats/NanoAOD/interface/FlatTable.h @@ -5,8 +5,8 @@ #include #include #include -#include -#include +#include "FWCore/Utilities/interface/Exception.h" +#include "DataFormats/PatCandidates/interface/libminifloat.h" namespace flatTableHelper { template struct MaybeMantissaReduce { diff --git a/DataFormats/NanoAOD/interface/MergeableCounterTable.h b/DataFormats/NanoAOD/interface/MergeableCounterTable.h index 3b7606813c071..e6b583181ae72 100644 --- a/DataFormats/NanoAOD/interface/MergeableCounterTable.h +++ b/DataFormats/NanoAOD/interface/MergeableCounterTable.h @@ -19,6 +19,8 @@ class MergeableCounterTable { std::string name, doc; T value; void operator+=(const SingleColumn & other) { + //// if one arrives here from tryMerge the checks are already done in the compatible() function before. + //// you may however want to enable these and remove the 'return false' in tryMerge in order to see what's incompatible between the tables. //if (name != other.name) throw cms::Exception("LogicError", "Trying to merge "+name+" with "+other.name+"\n"); value += other.value; } @@ -38,6 +40,8 @@ class MergeableCounterTable { std::string name, doc; std::vector values; void operator+=(const VectorColumn & other) { + //// if one arrives here from tryMerge the checks are already done in the compatible() function before. + //// you may however want to enable these and remove the 'return false' in tryMerge in order to see what's incompatible between the tables. //if (name != other.name) throw cms::Exception("LogicError", "Trying to merge "+name+" with "+other.name+"\n"); //if (values.size() != other.values.size()) throw cms::Exception("LogicError", "Trying to merge "+name+" with different number of values!\n"); for (unsigned int i = 0, n = values.size(); i < n; ++i) { From b6ecbc3a64fb81225f8b384a877b6da4dcc1000d Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 2 Oct 2017 11:13:30 +0200 Subject: [PATCH 30/36] Relocate some modules to PatAlgos or HepMCCandAlgos --- .../{NanoAOD => HepMCCandAlgos}/plugins/GenVisTauProducer.cc | 0 .../{NanoAOD => PatAlgos}/plugins/IsolatedTrackCleaner.cc | 0 PhysicsTools/{NanoAOD => PatAlgos}/plugins/LeptonUpdater.cc | 0 .../{NanoAOD => PatAlgos}/plugins/PATObjectCrossLinker.cc | 0 .../{NanoAOD => PatAlgos}/plugins/PATObjectUserDataEmbedder.cc | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename PhysicsTools/{NanoAOD => HepMCCandAlgos}/plugins/GenVisTauProducer.cc (100%) rename PhysicsTools/{NanoAOD => PatAlgos}/plugins/IsolatedTrackCleaner.cc (100%) rename PhysicsTools/{NanoAOD => PatAlgos}/plugins/LeptonUpdater.cc (100%) rename PhysicsTools/{NanoAOD => PatAlgos}/plugins/PATObjectCrossLinker.cc (100%) rename PhysicsTools/{NanoAOD => PatAlgos}/plugins/PATObjectUserDataEmbedder.cc (100%) diff --git a/PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc b/PhysicsTools/HepMCCandAlgos/plugins/GenVisTauProducer.cc similarity index 100% rename from PhysicsTools/NanoAOD/plugins/GenVisTauProducer.cc rename to PhysicsTools/HepMCCandAlgos/plugins/GenVisTauProducer.cc diff --git a/PhysicsTools/NanoAOD/plugins/IsolatedTrackCleaner.cc b/PhysicsTools/PatAlgos/plugins/IsolatedTrackCleaner.cc similarity index 100% rename from PhysicsTools/NanoAOD/plugins/IsolatedTrackCleaner.cc rename to PhysicsTools/PatAlgos/plugins/IsolatedTrackCleaner.cc diff --git a/PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc b/PhysicsTools/PatAlgos/plugins/LeptonUpdater.cc similarity index 100% rename from PhysicsTools/NanoAOD/plugins/LeptonUpdater.cc rename to PhysicsTools/PatAlgos/plugins/LeptonUpdater.cc diff --git a/PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc similarity index 100% rename from PhysicsTools/NanoAOD/plugins/PATObjectCrossLinker.cc rename to PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc diff --git a/PhysicsTools/NanoAOD/plugins/PATObjectUserDataEmbedder.cc b/PhysicsTools/PatAlgos/plugins/PATObjectUserDataEmbedder.cc similarity index 100% rename from PhysicsTools/NanoAOD/plugins/PATObjectUserDataEmbedder.cc rename to PhysicsTools/PatAlgos/plugins/PATObjectUserDataEmbedder.cc From c43e136d09dcd5f693626b16e97cedbc11d864a8 Mon Sep 17 00:00:00 2001 From: peruzzim Date: Mon, 2 Oct 2017 11:32:52 +0200 Subject: [PATCH 31/36] Rewrite ptrel using LorentzVector (also fixes bug in usage of TLorentzVector constructor) --- .../NanoAOD/plugins/LeptonJetVarProducer.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc b/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc index 215df7612eb42..a671e8650a98f 100644 --- a/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc @@ -35,7 +35,6 @@ #include "DataFormats/PatCandidates/interface/Electron.h" #include "DataFormats/VertexReco/interface/Vertex.h" -#include "TLorentzVector.h" #include "DataFormats/Common/interface/View.h" #include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" @@ -156,15 +155,14 @@ template std::tuple LeptonJetVarProducer::calculatePtRatioRel(edm::Ptr lep, edm::Ptr jet, const reco::Vertex &vtx) const { - auto rawp4_ = jet->correctedP4("Uncorrected"); - auto rawp4 = TLorentzVector(rawp4_.pt(),rawp4_.eta(),rawp4_.phi(),rawp4_.energy()); - auto lepp4 = TLorentzVector(lep->pt(),lep->eta(),lep->phi(),lep->energy()); + auto rawp4 = jet->correctedP4("Uncorrected"); + auto lepp4 = lep->p4(); - if ((rawp4-lepp4).Rho()<1e-4) return std::tuple(1.0,0.0,0.0); + if ((rawp4-lepp4).R()<1e-4) return std::tuple(1.0,0.0,0.0); - auto jetp4 = (rawp4 - lepp4*(1.0/jet->jecFactor("L1FastJet")))*(jet->pt()/rawp4.Pt())+lepp4; - auto ptratio = lepp4.Pt()/jetp4.Pt(); - auto ptrel = lepp4.Perp((jetp4-lepp4).Vect()); + auto jetp4 = (rawp4 - lepp4*(1.0/jet->jecFactor("L1FastJet")))*(jet->pt()/rawp4.pt())+lepp4; + auto ptratio = lepp4.pt()/jetp4.pt(); + auto ptrel = lepp4.Vect().Cross((jetp4-lepp4).Vect().Unit()).R(); unsigned int jndau = 0; for(const auto _d : jet->daughterPtrVector()) { From 711bfda7bc69ba35014e6c155a9b415ecaf471f8 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 2 Oct 2017 12:27:13 +0200 Subject: [PATCH 32/36] Move nanoaod dataformats to nanoaod namespace --- DataFormats/NanoAOD/interface/FlatTable.h | 4 ++ .../NanoAOD/interface/MergeableCounterTable.h | 6 +- DataFormats/NanoAOD/interface/UniqueString.h | 4 ++ DataFormats/NanoAOD/src/FlatTable.cc | 4 +- DataFormats/NanoAOD/src/classes.h | 13 +++-- DataFormats/NanoAOD/src/classes_def.xml | 48 +++++++-------- .../plugins/CandMCMatchTableProducer.cc | 10 ++-- .../plugins/GenWeightsTableProducer.cc | 44 +++++++------- .../plugins/GlobalVariablesTableProducer.cc | 28 ++++----- .../NanoAOD/plugins/LHETablesProducer.cc | 22 +++---- .../NanoAOD/plugins/MuonIDTableProducer.cc | 14 ++--- .../plugins/NanoAODBaseCrossCleaner.cc | 30 +++++----- .../NanoAOD/plugins/NanoAODOutputModule.cc | 8 +-- .../plugins/NativeArrayTableProducer.cc | 14 ++--- .../plugins/SimpleFlatTableProducer.cc | 58 +++++++++---------- .../plugins/SummaryTableOutputBranches.cc | 6 +- .../plugins/SummaryTableOutputBranches.h | 4 +- .../NanoAOD/plugins/TableOutputBranches.cc | 14 ++--- .../NanoAOD/plugins/TableOutputBranches.h | 6 +- .../plugins/TriggerObjectTableProducer.cc | 18 +++--- .../NanoAOD/plugins/TriggerOutputBranches.cc | 2 +- .../NanoAOD/plugins/UniqueStringProducer.cc | 4 +- .../NanoAOD/plugins/VertexTableProducer.cc | 34 +++++------ 23 files changed, 204 insertions(+), 191 deletions(-) diff --git a/DataFormats/NanoAOD/interface/FlatTable.h b/DataFormats/NanoAOD/interface/FlatTable.h index c9532daf8c525..8a1a5909dc13b 100644 --- a/DataFormats/NanoAOD/interface/FlatTable.h +++ b/DataFormats/NanoAOD/interface/FlatTable.h @@ -8,6 +8,8 @@ #include "FWCore/Utilities/interface/Exception.h" #include "DataFormats/PatCandidates/interface/libminifloat.h" +namespace nanoaod { + namespace flatTableHelper { template struct MaybeMantissaReduce { MaybeMantissaReduce(int mantissaBits) {} @@ -21,6 +23,7 @@ namespace flatTableHelper { inline void bulk(boost::sub_range> data) const { if (bits_ > 0) MiniFloatConverter::reduceMantissaToNbitsRounding(bits_, data.begin(), data.end(), data.begin()); } }; } + class FlatTable { public: enum ColumnType { FloatColumn, IntColumn, UInt8Column, BoolColumn }; // We could have other Float types with reduced mantissa, and similar @@ -155,5 +158,6 @@ template<> inline std::vector & FlatTable::bigVector() { retur template<> inline std::vector & FlatTable::bigVector() { return ints_; } template<> inline std::vector & FlatTable::bigVector() { return uint8s_; } +} // nanoaod #endif diff --git a/DataFormats/NanoAOD/interface/MergeableCounterTable.h b/DataFormats/NanoAOD/interface/MergeableCounterTable.h index e6b583181ae72..cfd99d399b0b9 100644 --- a/DataFormats/NanoAOD/interface/MergeableCounterTable.h +++ b/DataFormats/NanoAOD/interface/MergeableCounterTable.h @@ -1,10 +1,12 @@ #ifndef DataFormats_NanoAOD_MergeableCounterTable_h #define DataFormats_NanoAOD_MergeableCounterTable_h -#include +#include "FWCore/Utilities/interface/Exception.h" #include #include +namespace nanoaod { + class MergeableCounterTable { public: MergeableCounterTable() {} @@ -104,4 +106,6 @@ class MergeableCounterTable { } }; +} // namespace nanoaod + #endif diff --git a/DataFormats/NanoAOD/interface/UniqueString.h b/DataFormats/NanoAOD/interface/UniqueString.h index be0090da5b20e..8f2ad35c1c56f 100644 --- a/DataFormats/NanoAOD/interface/UniqueString.h +++ b/DataFormats/NanoAOD/interface/UniqueString.h @@ -3,6 +3,8 @@ #include +namespace nanoaod { + class UniqueString { public: UniqueString() {} @@ -15,4 +17,6 @@ class UniqueString { std::string str_; }; +} // namespace nanoaod + #endif diff --git a/DataFormats/NanoAOD/src/FlatTable.cc b/DataFormats/NanoAOD/src/FlatTable.cc index e3015ed6df007..bffa199ed8f95 100644 --- a/DataFormats/NanoAOD/src/FlatTable.cc +++ b/DataFormats/NanoAOD/src/FlatTable.cc @@ -1,6 +1,6 @@ -#include +#include "DataFormats/NanoAOD/interface/FlatTable.h" -int FlatTable::columnIndex(const std::string & name) const { +int nanoaod::FlatTable::columnIndex(const std::string & name) const { for (unsigned int i = 0, n = columns_.size(); i < n; ++i) { if (columns_[i].name == name) return i; } diff --git a/DataFormats/NanoAOD/src/classes.h b/DataFormats/NanoAOD/src/classes.h index e98cbc8ab12ab..cd21de1d1e072 100644 --- a/DataFormats/NanoAOD/src/classes.h +++ b/DataFormats/NanoAOD/src/classes.h @@ -1,14 +1,15 @@ #include "Rtypes.h" -#include -#include -#include +#include "DataFormats/NanoAOD/interface/FlatTable.h" +#include "DataFormats/NanoAOD/interface/MergeableCounterTable.h" +#include "DataFormats/NanoAOD/interface/UniqueString.h" #include "DataFormats/Common/interface/Wrapper.h" namespace DataFormats_NanoAOD { struct dictionary { - edm::Wrapper w_table; - edm::Wrapper w_mtable; - edm::Wrapper w_ustr; + nanoaod::FlatTable table; + edm::Wrapper w_table; + edm::Wrapper w_mtable; + edm::Wrapper w_ustr; }; } diff --git a/DataFormats/NanoAOD/src/classes_def.xml b/DataFormats/NanoAOD/src/classes_def.xml index c53c27cac0d61..7c85fe046b919 100644 --- a/DataFormats/NanoAOD/src/classes_def.xml +++ b/DataFormats/NanoAOD/src/classes_def.xml @@ -1,36 +1,36 @@ - - + + - - - + + + - + - - + + - - + + - - + + - - + + - - - - - - + + + + + + - - - + + + - + diff --git a/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc b/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc index cfb0c2205ef37..e0de5e212ae47 100644 --- a/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc @@ -21,7 +21,7 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> { src_(consumes(params.getParameter("src"))), candMap_(consumes>(params.getParameter("mcMap"))) { - produces(); + produces(); const std::string & type = params.getParameter("objType"); if (type == "Muon") type_ = MMuon; else if (type == "Electron") type_ = MElectron; @@ -53,7 +53,7 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> { iEvent.getByToken(src_, cands); unsigned int ncand = cands->size(); - auto tab = std::make_unique(ncand, objName_, false, true); + auto tab = std::make_unique(ncand, objName_, false, true); edm::Handle> map; iEvent.getByToken(candMap_, map); @@ -101,8 +101,8 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> { }; } - tab->addColumn(branchName_+"Idx", key, "Index into genParticle list for "+doc_, FlatTable::IntColumn); - tab->addColumn(branchName_+"Flav", flav, "Flavour of genParticle for "+doc_+": "+flavDoc_, FlatTable::UInt8Column); + tab->addColumn(branchName_+"Idx", key, "Index into genParticle list for "+doc_, nanoaod::FlatTable::IntColumn); + tab->addColumn(branchName_+"Flav", flav, "Flavour of genParticle for "+doc_+": "+flavDoc_, nanoaod::FlatTable::UInt8Column); iEvent.put(std::move(tab)); } @@ -127,7 +127,7 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { edm::ParameterSetDescription desc; - desc.add("objName")->setComment("name of the FlatTable to extend with this table"); + desc.add("objName")->setComment("name of the nanoaod::FlatTable to extend with this table"); desc.add("branchName")->setComment("name of the column to write (the final branch in the nanoaod will be _Idx and _Flav"); desc.add("docString")->setComment("documentation to forward to the output"); desc.add("src")->setComment("physics object collection for the reconstructed objects (e.g. leptons)"); diff --git a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc index 1a7794b82c701..7e25fe71db49a 100644 --- a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc @@ -116,11 +116,11 @@ class GenWeightsTableProducer : public edm::global::EDProducer("debug",false)), debugRun_(debug_.load()), hasIssuedWarning_(false) { - produces(); - produces("LHEScale"); - produces("LHEPdf"); - produces("LHENamed"); - produces(); + produces(); + produces("LHEScale"); + produces("LHEPdf"); + produces("LHENamed"); + produces(); if (namedWeightIDs_.size() != namedWeightLabels_.size()) { throw cms::Exception("Configuration", "Size mismatch between namedWeightIDs & namedWeightLabels"); } @@ -138,13 +138,13 @@ class GenWeightsTableProducer : public edm::global::EDProducerweight(); // table for gen info, always available - auto out = std::make_unique(1, "genWeight", true); + auto out = std::make_unique(1, "genWeight", true); out->setDoc("generator weight"); - out->addColumnValue("", weight, "generator weight", FlatTable::FloatColumn); + out->addColumnValue("", weight, "generator weight", nanoaod::FlatTable::FloatColumn); iEvent.put(std::move(out)); // tables for LHE weights, may not be filled - std::unique_ptr lheScaleTab, lhePdfTab, lheNamedTab; + std::unique_ptr lheScaleTab, lhePdfTab, lheNamedTab; edm::Handle lheInfo; if (iEvent.getByToken(lheTag_, lheInfo)) { @@ -156,9 +156,9 @@ class GenWeightsTableProducer : public edm::global::EDProducerincGenOnly(weight); // make dummy values - lheScaleTab.reset(new FlatTable(1, "LHEScaleWeights", true)); - lhePdfTab.reset(new FlatTable(1, "LHEPdfWeights", true)); - lheNamedTab.reset(new FlatTable(1, "LHENamedWeights", true)); + lheScaleTab.reset(new nanoaod::FlatTable(1, "LHEScaleWeights", true)); + lhePdfTab.reset(new nanoaod::FlatTable(1, "LHEPdfWeights", true)); + lheNamedTab.reset(new nanoaod::FlatTable(1, "LHENamedWeights", true)); if (!hasIssuedWarning_.exchange(true)) { edm::LogWarning("LHETablesProducer") << "No LHEEventProduct, so there will be no LHE Tables\n"; } @@ -174,9 +174,9 @@ class GenWeightsTableProducer : public edm::global::EDProducer & outScale, - std::unique_ptr & outPdf, - std::unique_ptr & outNamed ) const + std::unique_ptr & outScale, + std::unique_ptr & outPdf, + std::unique_ptr & outNamed ) const { bool lheDebug = debug_.exchange(false); // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind) @@ -199,16 +199,16 @@ class GenWeightsTableProducer : public edm::global::EDProduceraddColumn("", wScale, weightChoice->scaleWeightsDoc, FlatTable::FloatColumn, lheWeightPrecision_); + outScale.reset(new nanoaod::FlatTable(wScale.size(), "LHEScaleWeight", false)); + outScale->addColumn("", wScale, weightChoice->scaleWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); - outPdf.reset(new FlatTable(wPDF.size(), "LHEPdfWeight", false)); - outPdf->addColumn("", wPDF, weightChoice->pdfWeightsDoc, FlatTable::FloatColumn, lheWeightPrecision_); + outPdf.reset(new nanoaod::FlatTable(wPDF.size(), "LHEPdfWeight", false)); + outPdf->addColumn("", wPDF, weightChoice->pdfWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); - outNamed.reset(new FlatTable(1, "LHEWeight", true)); - outNamed->addColumnValue("originalXWGTUP", lheProd.originalXWGTUP(), "Nominal event weight in the LHE file", FlatTable::FloatColumn); + outNamed.reset(new nanoaod::FlatTable(1, "LHEWeight", true)); + outNamed->addColumnValue("originalXWGTUP", lheProd.originalXWGTUP(), "Nominal event weight in the LHE file", nanoaod::FlatTable::FloatColumn); for (unsigned int i = 0, n = wNamed.size(); i < n; ++i) { - outNamed->addColumnValue(namedWeightLabels_[i], wNamed[i], "LHE weight for id "+namedWeightIDs_[i]+", relative to nominal", FlatTable::FloatColumn, lheWeightPrecision_); + outNamed->addColumnValue(namedWeightLabels_[i], wNamed[i], "LHE weight for id "+namedWeightIDs_[i]+", relative to nominal", nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); } counter->incLHE(genWeight, wScale, wPDF, wNamed); @@ -355,7 +355,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer(); + auto out = std::make_unique(); out->addInt("genEventCount", "event count", runCounter->num); out->addFloat("genEventSumw", "sum of gen weights", runCounter->sumw); out->addFloat("genEventSumw2", "sum of gen (weight^2)", runCounter->sumw2); diff --git a/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc index 59c26d2a9282f..83418b2e05c49 100644 --- a/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc @@ -17,22 +17,22 @@ class GlobalVariablesTableProducer : public edm::stream::EDProducer<> { for (const std::string & vname : varsPSet.getParameterNamesForType()) { const auto & varPSet = varsPSet.getParameter(vname); const std::string & type = varPSet.getParameter("type"); - if (type == "int") vars_.push_back(new IntVar(vname, FlatTable::IntColumn, varPSet, consumesCollector())); - else if (type == "float") vars_.push_back(new FloatVar(vname, FlatTable::FloatColumn, varPSet, consumesCollector())); - else if (type == "double") vars_.push_back(new DoubleVar(vname, FlatTable::FloatColumn, varPSet, consumesCollector())); - else if (type == "bool") vars_.push_back(new BoolVar(vname, FlatTable::UInt8Column, varPSet, consumesCollector())); - else if (type == "candidatescalarsum") vars_.push_back(new CandidateScalarSumVar(vname, FlatTable::FloatColumn, varPSet, consumesCollector())); - else if (type == "candidatesize") vars_.push_back(new CandidateSizeVar(vname, FlatTable::IntColumn, varPSet, consumesCollector())); + if (type == "int") vars_.push_back(new IntVar(vname, nanoaod::FlatTable::IntColumn, varPSet, consumesCollector())); + else if (type == "float") vars_.push_back(new FloatVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, consumesCollector())); + else if (type == "double") vars_.push_back(new DoubleVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, consumesCollector())); + else if (type == "bool") vars_.push_back(new BoolVar(vname, nanoaod::FlatTable::UInt8Column, varPSet, consumesCollector())); + else if (type == "candidatescalarsum") vars_.push_back(new CandidateScalarSumVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, consumesCollector())); + else if (type == "candidatesize") vars_.push_back(new CandidateSizeVar(vname, nanoaod::FlatTable::IntColumn, varPSet, consumesCollector())); else throw cms::Exception("Configuration", "unsupported type "+type+" for variable "+vname); } - produces(); + produces(); } ~GlobalVariablesTableProducer() override {} void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override { - auto out = std::make_unique(1, "", true); + auto out = std::make_unique(1, "", true); for (const auto & var : vars_) var.fill(iEvent, *out); @@ -42,15 +42,15 @@ class GlobalVariablesTableProducer : public edm::stream::EDProducer<> { protected: class Variable { public: - Variable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : + Variable(const std::string & aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : name_(aname), doc_(cfg.getParameter("doc")), type_(atype) {} - virtual void fill(const edm::Event &iEvent, FlatTable & out) const = 0; + virtual void fill(const edm::Event &iEvent, nanoaod::FlatTable & out) const = 0; virtual ~Variable() {} const std::string & name() const { return name_; } - const FlatTable::ColumnType & type() const { return type_; } + const nanoaod::FlatTable::ColumnType & type() const { return type_; } protected: std::string name_, doc_; - FlatTable::ColumnType type_; + nanoaod::FlatTable::ColumnType type_; }; template class Identity { @@ -109,10 +109,10 @@ class GlobalVariablesTableProducer : public edm::stream::EDProducer<> { template > class VariableT : public Variable { public: - VariableT(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg, edm::ConsumesCollector && cc) : + VariableT(const std::string & aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet & cfg, edm::ConsumesCollector && cc) : Variable(aname, atype, cfg), src_(cc.consumes(cfg.getParameter("src"))) {} ~VariableT() override {} - void fill(const edm::Event &iEvent, FlatTable & out) const override { + void fill(const edm::Event &iEvent, nanoaod::FlatTable & out) const override { edm::Handle handle; iEvent.getByToken(src_, handle); out.template addColumnValue(this->name_, Converter::convert(*handle), this->doc_, this->type_); diff --git a/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc b/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc index d3f89e1ad3ac8..4ffaeb2eb5b7b 100644 --- a/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHETablesProducer.cc @@ -15,13 +15,13 @@ class LHETablesProducer : public edm::global::EDProducer<> { LHETablesProducer( edm::ParameterSet const & params ) : lheTag_(consumes(params.getParameter("lheInfo"))) { - produces(); + produces(); } ~LHETablesProducer() override {} void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { - auto lheTab = std::make_unique(1, "LHE", true); + auto lheTab = std::make_unique(1, "LHE", true); edm::Handle lheInfo; if (iEvent.getByToken(lheTag_, lheInfo)) { @@ -31,7 +31,7 @@ class LHETablesProducer : public edm::global::EDProducer<> { iEvent.put(std::move(lheTab)); } - void fillLHEObjectTable(const LHEEventProduct & lheProd, FlatTable & out) const { + void fillLHEObjectTable(const LHEEventProduct & lheProd, nanoaod::FlatTable & out) const { double lheHT = 0, lheHTIncoming = 0; unsigned int lheNj = 0, lheNb = 0, lheNc = 0, lheNuds = 0, lheNglu = 0; double lheVpt = 0; @@ -73,14 +73,14 @@ class LHETablesProducer : public edm::global::EDProducer<> { lheVpt = std::hypot( pup[v.first][0] + pup[v.second][0], pup[v.first][1] + pup[v.second][1] ); } - out.addColumnValue("Njets", lheNj, "Number of jets (partons) at LHE step", FlatTable::UInt8Column); - out.addColumnValue("Nb", lheNb, "Number of b partons at LHE step", FlatTable::UInt8Column); - out.addColumnValue("Nc", lheNc, "Number of c partons at LHE step", FlatTable::UInt8Column); - out.addColumnValue("Nuds", lheNuds, "Number of u,d,s partons at LHE step", FlatTable::UInt8Column); - out.addColumnValue("Nglu", lheNglu, "Number of gluon partons at LHE step", FlatTable::UInt8Column); - out.addColumnValue("HT", lheHT, "HT, scalar sum of parton pTs at LHE step", FlatTable::FloatColumn); - out.addColumnValue("HTIncoming", lheHTIncoming, "HT, scalar sum of parton pTs at LHE step, restricted to partons", FlatTable::FloatColumn); - out.addColumnValue("Vpt", lheVpt, "pT of the W or Z boson at LHE step", FlatTable::FloatColumn); + out.addColumnValue("Njets", lheNj, "Number of jets (partons) at LHE step", nanoaod::FlatTable::UInt8Column); + out.addColumnValue("Nb", lheNb, "Number of b partons at LHE step", nanoaod::FlatTable::UInt8Column); + out.addColumnValue("Nc", lheNc, "Number of c partons at LHE step", nanoaod::FlatTable::UInt8Column); + out.addColumnValue("Nuds", lheNuds, "Number of u,d,s partons at LHE step", nanoaod::FlatTable::UInt8Column); + out.addColumnValue("Nglu", lheNglu, "Number of gluon partons at LHE step", nanoaod::FlatTable::UInt8Column); + out.addColumnValue("HT", lheHT, "HT, scalar sum of parton pTs at LHE step", nanoaod::FlatTable::FloatColumn); + out.addColumnValue("HTIncoming", lheHTIncoming, "HT, scalar sum of parton pTs at LHE step, restricted to partons", nanoaod::FlatTable::FloatColumn); + out.addColumnValue("Vpt", lheVpt, "pT of the W or Z boson at LHE step", nanoaod::FlatTable::FloatColumn); } static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { diff --git a/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc b/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc index b6ae1c19d4445..3970ca344db86 100644 --- a/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/MuonIDTableProducer.cc @@ -24,7 +24,7 @@ class MuonIDTableProducer : public edm::global::EDProducer<> { src_(consumes>(iConfig.getParameter("muons"))), srcVtx_(consumes>(iConfig.getParameter("vertices"))) { - produces(); + produces(); } ~MuonIDTableProducer() override {}; @@ -33,7 +33,7 @@ class MuonIDTableProducer : public edm::global::EDProducer<> { edm::ParameterSetDescription desc; desc.add("muons")->setComment("input muon collection"); desc.add("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"))->setComment("input vertex collection, for dxy/dz"); - desc.add("name")->setComment("name of the muon FlatTable we are extending with IDs"); + desc.add("name")->setComment("name of the muon nanoaod::FlatTable we are extending with IDs"); descriptions.add("muonIDTable", desc); } @@ -73,11 +73,11 @@ MuonIDTableProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::Event medium[i] = isRun2016BCDEF ? isMediumMuonHIP(mu) : muon::isMediumMuon(mu); } - auto tab = std::make_unique(ncand, name_, false, true); - tab->addColumn("tightId", tight, "POG Tight muon ID", FlatTable::BoolColumn); - tab->addColumn("highPtId", highPt, "POG highPt muon ID (1 = tracker high pT, 2 = global high pT, which includes tracker high pT)", FlatTable::UInt8Column); - tab->addColumn("softId", soft, "POG Soft muon ID (using the relaxed cuts in the data Run 2016 B-F periods, and standard cuts elsewhere)", FlatTable::BoolColumn); - tab->addColumn("mediumId", medium, "POG Medium muon ID (using the relaxed cuts in the data Run 2016 B-F periods, and standard cuts elsewhere)", FlatTable::BoolColumn); + auto tab = std::make_unique(ncand, name_, false, true); + tab->addColumn("tightId", tight, "POG Tight muon ID", nanoaod::FlatTable::BoolColumn); + tab->addColumn("highPtId", highPt, "POG highPt muon ID (1 = tracker high pT, 2 = global high pT, which includes tracker high pT)", nanoaod::FlatTable::UInt8Column); + tab->addColumn("softId", soft, "POG Soft muon ID (using the relaxed cuts in the data Run 2016 B-F periods, and standard cuts elsewhere)", nanoaod::FlatTable::BoolColumn); + tab->addColumn("mediumId", medium, "POG Medium muon ID (using the relaxed cuts in the data Run 2016 B-F periods, and standard cuts elsewhere)", nanoaod::FlatTable::BoolColumn); iEvent.put(std::move(tab)); } diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc b/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc index 0c4e7df51ff51..cc41a35563882 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.cc @@ -42,11 +42,11 @@ NanoAODBaseCrossCleaner::NanoAODBaseCrossCleaner(const edm::ParameterSet& params photonName_(params.getParameter("photonName") ) { - produces("jets"); - produces("muons"); - produces("electrons"); - produces("taus"); - produces("photons"); + produces("jets"); + produces("muons"); + produces("electrons"); + produces("taus"); + produces("photons"); } @@ -75,41 +75,41 @@ NanoAODBaseCrossCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSet iEvent.getByToken(jets_, jetsIn); std::vector jets; for (const auto & j: *jetsIn) {jets.push_back(jetSel_(j));} - auto jetsTable = std::make_unique(jetsIn->size(),jetName_,false,true); + auto jetsTable = std::make_unique(jetsIn->size(),jetName_,false,true); edm::Handle> muonsIn; iEvent.getByToken(muons_, muonsIn); std::vector muons; for (const auto & m: *muonsIn) {muons.push_back(muonSel_(m));} - auto muonsTable = std::make_unique(muonsIn->size(),muonName_,false,true); + auto muonsTable = std::make_unique(muonsIn->size(),muonName_,false,true); edm::Handle> electronsIn; iEvent.getByToken(electrons_, electronsIn); std::vector eles; for (const auto & e: *electronsIn) {eles.push_back(electronSel_(e));} - auto electronsTable = std::make_unique(electronsIn->size(),electronName_,false,true); + auto electronsTable = std::make_unique(electronsIn->size(),electronName_,false,true); edm::Handle> tausIn; iEvent.getByToken(taus_, tausIn); std::vector taus; for (const auto & t: *tausIn) {taus.push_back(tauSel_(t));} - auto tausTable = std::make_unique(tausIn->size(),tauName_,false,true); + auto tausTable = std::make_unique(tausIn->size(),tauName_,false,true); edm::Handle> photonsIn; iEvent.getByToken(photons_, photonsIn); std::vector photons; for (const auto & p: *photonsIn) {photons.push_back(photonSel_(p));} - auto photonsTable = std::make_unique(photonsIn->size(),photonName_,false,true); + auto photonsTable = std::make_unique(photonsIn->size(),photonName_,false,true); objectSelection(*jetsIn,*muonsIn,*electronsIn,*tausIn,*photonsIn,jets,muons,eles,taus,photons); - muonsTable->addColumn(name_,muons,doc_,FlatTable::UInt8Column); - jetsTable->addColumn(name_,jets,doc_,FlatTable::UInt8Column); - electronsTable->addColumn(name_,eles,doc_,FlatTable::UInt8Column); - tausTable->addColumn(name_,taus,doc_,FlatTable::UInt8Column); - photonsTable->addColumn(name_,photons,doc_,FlatTable::UInt8Column); + muonsTable->addColumn(name_,muons,doc_,nanoaod::FlatTable::UInt8Column); + jetsTable->addColumn(name_,jets,doc_,nanoaod::FlatTable::UInt8Column); + electronsTable->addColumn(name_,eles,doc_,nanoaod::FlatTable::UInt8Column); + tausTable->addColumn(name_,taus,doc_,nanoaod::FlatTable::UInt8Column); + photonsTable->addColumn(name_,photons,doc_,nanoaod::FlatTable::UInt8Column); iEvent.put(std::move(jetsTable),"jets"); iEvent.put(std::move(muonsTable),"muons"); diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc index f605147323cc2..9db6aa7d21033 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc @@ -185,7 +185,7 @@ NanoAODOutputModule::writeRun(edm::RunForOutput const& iRun) { for (auto & t : m_runTables) t.fill(iRun,*m_runTree); - edm::Handle hstring; + edm::Handle hstring; for (const auto & p : m_nanoMetadata) { iRun.getByToken(p.second, hstring); TObjString *tos = dynamic_cast(m_file->Get(p.first.c_str())); @@ -237,7 +237,7 @@ NanoAODOutputModule::openFile(edm::FileBlock const&) { m_runTables.clear(); const auto & keeps = keptProducts(); for (const auto & keep : keeps[edm::InEvent]) { - if(keep.first->className() == "FlatTable" ) + if(keep.first->className() == "nanoaod::FlatTable" ) m_tables.emplace_back(keep.first, keep.second); else if(keep.first->className() == "edm::TriggerResults" ) { @@ -247,9 +247,9 @@ NanoAODOutputModule::openFile(edm::FileBlock const&) { } for (const auto & keep : keeps[edm::InRun]) { - if(keep.first->className() == "MergeableCounterTable" ) + if(keep.first->className() == "nanoaod::MergeableCounterTable" ) m_runTables.push_back(SummaryTableOutputBranches(keep.first, keep.second)); - else if(keep.first->className() == "UniqueString" && keep.first->moduleLabel() == "nanoMetadata") + else if(keep.first->className() == "nanoaod::UniqueString" && keep.first->moduleLabel() == "nanoMetadata") m_nanoMetadata.emplace_back(keep.first->productInstanceName(), keep.second); else throw cms::Exception("Configuration", "NanoAODOutputModule cannot handle class " + keep.first->className() + " in Run branch"); } diff --git a/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc b/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc index 96bda47e3c1e9..6ce265f7e2638 100644 --- a/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/NativeArrayTableProducer.cc @@ -4,7 +4,7 @@ #include -template +template class NativeArrayTableProducer : public edm::stream::EDProducer<> { public: @@ -13,7 +13,7 @@ class NativeArrayTableProducer : public edm::stream::EDProducer<> { doc_(params.existsAs("doc") ? params.getParameter("doc") : ""), src_(consumes( params.getParameter("src") )) { - produces(); + produces(); } ~NativeArrayTableProducer() override {} @@ -23,7 +23,7 @@ class NativeArrayTableProducer : public edm::stream::EDProducer<> { iEvent.getByToken(src_, src); const auto & in = *src; - auto out = std::make_unique(in.size(), name_, false, false); + auto out = std::make_unique(in.size(), name_, false, false); out->setDoc(doc_); (*out).template addColumn(this->name_, in, this->doc_, CT); iEvent.put(std::move(out)); @@ -35,10 +35,10 @@ class NativeArrayTableProducer : public edm::stream::EDProducer<> { const edm::EDGetTokenT src_; }; -typedef NativeArrayTableProducer,float,FlatTable::FloatColumn> FloatArrayTableProducer; -typedef NativeArrayTableProducer,float,FlatTable::FloatColumn> DoubleArrayTableProducer; -typedef NativeArrayTableProducer,int,FlatTable::IntColumn> IntArrayTableProducer; -typedef NativeArrayTableProducer,uint8_t,FlatTable::UInt8Column> BoolArrayTableProducer; +typedef NativeArrayTableProducer,float,nanoaod::FlatTable::FloatColumn> FloatArrayTableProducer; +typedef NativeArrayTableProducer,float,nanoaod::FlatTable::FloatColumn> DoubleArrayTableProducer; +typedef NativeArrayTableProducer,int,nanoaod::FlatTable::IntColumn> IntArrayTableProducer; +typedef NativeArrayTableProducer,uint8_t,nanoaod::FlatTable::UInt8Column> BoolArrayTableProducer; #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(FloatArrayTableProducer); diff --git a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc index 05ce64638e86a..68a96105d6b3f 100644 --- a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducer.cc @@ -25,27 +25,27 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> { for (const std::string & vname : varsPSet.getParameterNamesForType()) { const auto & varPSet = varsPSet.getParameter(vname); const std::string & type = varPSet.getParameter("type"); - if (type == "int") vars_.push_back(new IntVar(vname, FlatTable::IntColumn, varPSet)); - else if (type == "float") vars_.push_back(new FloatVar(vname, FlatTable::FloatColumn, varPSet)); - else if (type == "uint8") vars_.push_back(new BoolVar(vname, FlatTable::UInt8Column, varPSet)); - else if (type == "bool") vars_.push_back(new BoolVar(vname, FlatTable::BoolColumn, varPSet)); + if (type == "int") vars_.push_back(new IntVar(vname, nanoaod::FlatTable::IntColumn, varPSet)); + else if (type == "float") vars_.push_back(new FloatVar(vname, nanoaod::FlatTable::FloatColumn, varPSet)); + else if (type == "uint8") vars_.push_back(new BoolVar(vname, nanoaod::FlatTable::UInt8Column, varPSet)); + else if (type == "bool") vars_.push_back(new BoolVar(vname, nanoaod::FlatTable::BoolColumn, varPSet)); else throw cms::Exception("Configuration", "unsupported type "+type+" for variable "+vname); } - produces(); + produces(); } ~SimpleFlatTableProducerBase() override {} // this is to be overriden by the child class - virtual std::unique_ptr fillTable(const edm::Event &iEvent, const edm::Handle & prod) const = 0; + virtual std::unique_ptr fillTable(const edm::Event &iEvent, const edm::Handle & prod) const = 0; void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override { edm::Handle src; iEvent.getByToken(src_, src); - std::unique_ptr out = fillTable(iEvent, src); + std::unique_ptr out = fillTable(iEvent, src); out->setDoc(doc_); iEvent.put(std::move(out)); @@ -59,32 +59,32 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> { class VariableBase { public: - VariableBase(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : + VariableBase(const std::string & aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : name_(aname), doc_(cfg.getParameter("doc")), type_(atype), precision_(cfg.existsAs("precision") ? cfg.getParameter("precision") : -1) { } virtual ~VariableBase() {} const std::string & name() const { return name_; } - const FlatTable::ColumnType & type() const { return type_; } + const nanoaod::FlatTable::ColumnType & type() const { return type_; } protected: std::string name_, doc_; - FlatTable::ColumnType type_; + nanoaod::FlatTable::ColumnType type_; int precision_; }; class Variable : public VariableBase { public: - Variable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : + Variable(const std::string & aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : VariableBase(aname, atype, cfg) {} - virtual void fill(std::vector selobjs, FlatTable & out) const = 0; + virtual void fill(std::vector selobjs, nanoaod::FlatTable & out) const = 0; }; template class FuncVariable : public Variable { public: - FuncVariable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : + FuncVariable(const std::string & aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet & cfg) : Variable(aname, atype, cfg), func_(cfg.getParameter("expr"), true) {} ~FuncVariable() override {} - void fill(std::vector selobjs, FlatTable & out) const override { + void fill(std::vector selobjs, nanoaod::FlatTable & out) const override { std::vector vals(selobjs.size()); for (unsigned int i = 0, n = vals.size(); i < n; ++i) { vals[i] = func_(*selobjs[i]); @@ -117,11 +117,11 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase()) { const auto & varPSet = extvarsPSet.getParameter(vname); const std::string & type = varPSet.getParameter("type"); - if (type == "int") extvars_.push_back(new IntExtVar(vname, FlatTable::IntColumn, varPSet, this->consumesCollector())); - else if (type == "float") extvars_.push_back(new FloatExtVar(vname, FlatTable::FloatColumn, varPSet, this->consumesCollector())); - else if (type == "double") extvars_.push_back(new DoubleExtVar(vname, FlatTable::FloatColumn, varPSet, this->consumesCollector())); - else if (type == "uint8") extvars_.push_back(new UInt8ExtVar(vname, FlatTable::UInt8Column, varPSet, this->consumesCollector())); - else if (type == "bool") extvars_.push_back(new BoolExtVar(vname, FlatTable::BoolColumn, varPSet, this->consumesCollector())); + if (type == "int") extvars_.push_back(new IntExtVar(vname, nanoaod::FlatTable::IntColumn, varPSet, this->consumesCollector())); + else if (type == "float") extvars_.push_back(new FloatExtVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, this->consumesCollector())); + else if (type == "double") extvars_.push_back(new DoubleExtVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, this->consumesCollector())); + else if (type == "uint8") extvars_.push_back(new UInt8ExtVar(vname, nanoaod::FlatTable::UInt8Column, varPSet, this->consumesCollector())); + else if (type == "bool") extvars_.push_back(new BoolExtVar(vname, nanoaod::FlatTable::BoolColumn, varPSet, this->consumesCollector())); else throw cms::Exception("Configuration", "unsupported type "+type+" for variable "+vname); } } @@ -129,7 +129,7 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase fillTable(const edm::Event &iEvent, const edm::Handle> & prod) const override { + std::unique_ptr fillTable(const edm::Event &iEvent, const edm::Handle> & prod) const override { std::vector selobjs; std::vector> selptrs; // for external variables if (singleton_) { @@ -146,7 +146,7 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase=maxLen_) break; } } - auto out = std::make_unique(selobjs.size(), this->name_, singleton_, this->extension_); + auto out = std::make_unique(selobjs.size(), this->name_, singleton_, this->extension_); for (const auto & var : this->vars_) var.fill(selobjs, *out); for (const auto & var : this->extvars_) var.fill(iEvent, selptrs, *out); return out; @@ -159,16 +159,16 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase> selptrs, FlatTable & out) const = 0; + virtual void fill(const edm::Event & iEvent, std::vector> selptrs, nanoaod::FlatTable & out) const = 0; }; template class ValueMapVariable : public ExtVariable { public: - ValueMapVariable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg, edm::ConsumesCollector && cc) : + ValueMapVariable(const std::string & aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet & cfg, edm::ConsumesCollector && cc) : ExtVariable(aname, atype, cfg), token_(cc.consumes>(cfg.getParameter("src"))) {} - void fill(const edm::Event & iEvent, std::vector> selptrs, FlatTable & out) const override { + void fill(const edm::Event & iEvent, std::vector> selptrs, nanoaod::FlatTable & out) const override { edm::Handle> vmap; iEvent.getByToken(token_, vmap); std::vector vals(selptrs.size()); @@ -197,8 +197,8 @@ class EventSingletonSimpleFlatTableProducer : public SimpleFlatTableProducerBase virtual ~EventSingletonSimpleFlatTableProducer() {} - std::unique_ptr fillTable(const edm::Event &, const edm::Handle & prod) const override { - auto out = std::make_unique(1, this->name_, true, this->extension_); + std::unique_ptr fillTable(const edm::Event &, const edm::Handle & prod) const override { + auto out = std::make_unique(1, this->name_, true, this->extension_); std::vector selobjs(1, prod->product()); for (const auto & var : this->vars_) var.fill(selobjs, *out); return out; @@ -213,8 +213,8 @@ class FirstObjectSimpleFlatTableProducer : public SimpleFlatTableProducerBase fillTable(const edm::Event &iEvent, const edm::Handle> & prod) const override { - auto out = std::make_unique(1, this->name_, true, this->extension_); + std::unique_ptr fillTable(const edm::Event &iEvent, const edm::Handle> & prod) const override { + auto out = std::make_unique(1, this->name_, true, this->extension_); std::vector selobjs(1, & (*prod)[0]); for (const auto & var : this->vars_) var.fill(selobjs, *out); return out; diff --git a/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc index 811c485610411..4fa92cc6a6679 100644 --- a/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc +++ b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.cc @@ -46,7 +46,7 @@ SummaryTableOutputBranches::fillVectorBranches(const std::vector & tabcols, void -SummaryTableOutputBranches::defineBranchesFromFirstEvent(const MergeableCounterTable & tab, TTree & tree) +SummaryTableOutputBranches::defineBranchesFromFirstEvent(const nanoaod::MergeableCounterTable & tab, TTree & tree) { makeScalarBranches(tab.intCols(), tree, "L", m_intBranches); makeScalarBranches(tab.floatCols(), tree, "D", m_floatBranches); @@ -61,9 +61,9 @@ SummaryTableOutputBranches::defineBranchesFromFirstEvent(const MergeableCounterT void SummaryTableOutputBranches::fill(const edm::OccurrenceForOutput &iWhatever, TTree & tree) { - edm::Handle handle; + edm::Handle handle; iWhatever.getByToken(m_token, handle); - const MergeableCounterTable & tab = *handle; + const nanoaod::MergeableCounterTable & tab = *handle; if(!m_branchesBooked) { defineBranchesFromFirstEvent(tab, tree); diff --git a/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h index 99dda07f4bb2a..1bbd5ecaef2dc 100644 --- a/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h +++ b/PhysicsTools/NanoAOD/plugins/SummaryTableOutputBranches.h @@ -14,7 +14,7 @@ class SummaryTableOutputBranches { SummaryTableOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken & token ) : m_token(token), m_branchesBooked(false) { - if (desc->className() != "MergeableCounterTable") throw cms::Exception("Configuration", "NanoAODOutputModule can only write out MergableCounterTable objects"); + if (desc->className() != "nanoaod::MergeableCounterTable") throw cms::Exception("Configuration", "NanoAODOutputModule can only write out MergableCounterTable objects"); } void fill(const edm::OccurrenceForOutput &iWhatever, TTree & tree) ; @@ -40,7 +40,7 @@ class SummaryTableOutputBranches { bool m_branchesBooked; - void defineBranchesFromFirstEvent(const MergeableCounterTable & tab, TTree & tree) ; + void defineBranchesFromFirstEvent(const nanoaod::MergeableCounterTable & tab, TTree & tree) ; template void makeScalarBranches(const std::vector & tabcols, TTree & tree, const std::string & rootType, std::vector & branches); template void makeVectorBranches(const std::vector & tabcols, TTree & tree, const std::string & rootType, std::vector & branches ); diff --git a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc index 690e101373839..6687c23980778 100644 --- a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc +++ b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc @@ -11,22 +11,22 @@ namespace { } void -TableOutputBranches::defineBranchesFromFirstEvent(const FlatTable & tab) +TableOutputBranches::defineBranchesFromFirstEvent(const nanoaod::FlatTable & tab) { m_baseName=tab.name(); for(size_t i=0;i handle; + edm::Handle handle; iEvent.getByToken(m_token, handle); - const FlatTable & tab = *handle; + const nanoaod::FlatTable & tab = *handle; m_counter = tab.size(); m_singleton = tab.singleton(); if(!m_branchesBooked) { diff --git a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h index e461760366f78..684cf8cfeddc8 100644 --- a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h +++ b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h @@ -14,10 +14,10 @@ class TableOutputBranches { TableOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken & token ) : m_token(token), m_extension(DontKnowYetIfMainOrExtension), m_branchesBooked(false) { - if (desc->className() != "FlatTable") throw cms::Exception("Configuration", "NanoAODOutputModule can only write out FlatTable objects"); + if (desc->className() != "nanoaod::FlatTable") throw cms::Exception("Configuration", "NanoAODOutputModule can only write out nanoaod::FlatTable objects"); } - void defineBranchesFromFirstEvent(const FlatTable & tab) ; + void defineBranchesFromFirstEvent(const nanoaod::FlatTable & tab) ; void branch(TTree &tree) ; /// Fill the current table, if extensions == table.extension(). @@ -44,7 +44,7 @@ class TableOutputBranches { bool m_branchesBooked; template - void fillColumn(NamedBranchPtr & pair, const FlatTable & tab) { + void fillColumn(NamedBranchPtr & pair, const nanoaod::FlatTable & tab) { int idx = tab.columnIndex(pair.name); if (idx == -1) throw cms::Exception("LogicError", "Missing column in input for "+m_baseName+"_"+pair.name); pair.branch->SetAddress( const_cast(& tab.columnData(idx).front() ) ); // SetAddress should take a const * ! diff --git a/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc b/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc index 5dc83dbff801b..4dc5def91ada0 100644 --- a/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc @@ -39,7 +39,7 @@ class TriggerObjectTableProducer : public edm::global::EDProducer<> { idDoc_ = idstr.str(); bitsDoc_ = qualitystr.str(); - produces(); + produces(); } ~TriggerObjectTableProducer() override {} @@ -136,14 +136,14 @@ TriggerObjectTableProducer::produce(edm::StreamID, edm::Event& iEvent, const edm } } - auto tab = std::make_unique(nobj, name_, false, false); - tab->addColumn("id", id, idDoc_, FlatTable::IntColumn); - tab->addColumn("pt", pt, "pt", FlatTable::FloatColumn, 12); - tab->addColumn("eta", eta, "eta", FlatTable::FloatColumn, 12); - tab->addColumn("phi", phi, "phi", FlatTable::FloatColumn, 12); - tab->addColumn("l1pt", l1pt, "pt of associated L1 seed", FlatTable::FloatColumn, 10); - tab->addColumn("l2pt", l2pt, "pt of associated 'L2' seed (i.e. HLT before tracking/PF)", FlatTable::FloatColumn, 10); - tab->addColumn("filterBits", bits, "extra bits of associated information: "+bitsDoc_, FlatTable::FloatColumn, 10); + auto tab = std::make_unique(nobj, name_, false, false); + tab->addColumn("id", id, idDoc_, nanoaod::FlatTable::IntColumn); + tab->addColumn("pt", pt, "pt", nanoaod::FlatTable::FloatColumn, 12); + tab->addColumn("eta", eta, "eta", nanoaod::FlatTable::FloatColumn, 12); + tab->addColumn("phi", phi, "phi", nanoaod::FlatTable::FloatColumn, 12); + tab->addColumn("l1pt", l1pt, "pt of associated L1 seed", nanoaod::FlatTable::FloatColumn, 10); + tab->addColumn("l2pt", l2pt, "pt of associated 'L2' seed (i.e. HLT before tracking/PF)", nanoaod::FlatTable::FloatColumn, 10); + tab->addColumn("filterBits", bits, "extra bits of associated information: "+bitsDoc_, nanoaod::FlatTable::FloatColumn, 10); iEvent.put(std::move(tab)); } diff --git a/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc index 82999a3cd10a5..efa9adf312335 100644 --- a/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc +++ b/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc @@ -23,7 +23,7 @@ TriggerOutputBranches::updateTriggerNames(TTree & tree, const edm::TriggerNames } // Find new ones for(unsigned int j=0;j("strings"); for (const std::string & vname : strings.getParameterNamesForType()) { strings_.emplace_back(vname, strings.getParameter(vname)); - produces(vname); + produces(vname); } } @@ -21,7 +21,7 @@ class UniqueStringProducer : public edm::global::EDProducer(pair.second), pair.first); + iRun.put(std::make_unique(pair.second), pair.first); } } diff --git a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc index adc52daffc4db..6cde1a339f5c4 100644 --- a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc @@ -92,9 +92,9 @@ VertexTableProducer::VertexTableProducer(const edm::ParameterSet& params): dlenSigMin_(params.getParameter("dlenSigMin") ) { - produces("pv"); - produces("otherPVs"); - produces("svs"); + produces("pv"); + produces("otherPVs"); + produces("svs"); produces >(); } @@ -124,19 +124,19 @@ VertexTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) edm::Handle> pvsIn; iEvent.getByToken(pvs_, pvsIn); iEvent.getByToken(pvsScore_, pvsScoreIn); - auto pvTable = std::make_unique(1,pvName_,true); - pvTable->addColumnValue("ndof",(*pvsIn)[0].ndof(),"main primary vertex number of degree of freedom",FlatTable::FloatColumn,8); - pvTable->addColumnValue("x",(*pvsIn)[0].position().x(),"main primary vertex position x coordinate",FlatTable::FloatColumn,10); - pvTable->addColumnValue("y",(*pvsIn)[0].position().y(),"main primary vertex position y coordinate",FlatTable::FloatColumn,10); - pvTable->addColumnValue("z",(*pvsIn)[0].position().z(),"main primary vertex position z coordinate",FlatTable::FloatColumn,16); - pvTable->addColumnValue("chi2",(*pvsIn)[0].normalizedChi2(),"main primary vertex reduced chi2",FlatTable::FloatColumn,8); - pvTable->addColumnValue("npvs",(*pvsIn).size(),"total number of reconstructed primary vertices",FlatTable::IntColumn); - pvTable->addColumnValue("score",(*pvsScoreIn).get(pvsIn.id(),0),"main primary vertex score, i.e. sum pt2 of clustered objects",FlatTable::FloatColumn,8); - - auto otherPVsTable = std::make_unique((*pvsIn).size() >4?3:(*pvsIn).size()-1,"Other"+pvName_,false); + auto pvTable = std::make_unique(1,pvName_,true); + pvTable->addColumnValue("ndof",(*pvsIn)[0].ndof(),"main primary vertex number of degree of freedom",nanoaod::FlatTable::FloatColumn,8); + pvTable->addColumnValue("x",(*pvsIn)[0].position().x(),"main primary vertex position x coordinate",nanoaod::FlatTable::FloatColumn,10); + pvTable->addColumnValue("y",(*pvsIn)[0].position().y(),"main primary vertex position y coordinate",nanoaod::FlatTable::FloatColumn,10); + pvTable->addColumnValue("z",(*pvsIn)[0].position().z(),"main primary vertex position z coordinate",nanoaod::FlatTable::FloatColumn,16); + pvTable->addColumnValue("chi2",(*pvsIn)[0].normalizedChi2(),"main primary vertex reduced chi2",nanoaod::FlatTable::FloatColumn,8); + pvTable->addColumnValue("npvs",(*pvsIn).size(),"total number of reconstructed primary vertices",nanoaod::FlatTable::IntColumn); + pvTable->addColumnValue("score",(*pvsScoreIn).get(pvsIn.id(),0),"main primary vertex score, i.e. sum pt2 of clustered objects",nanoaod::FlatTable::FloatColumn,8); + + auto otherPVsTable = std::make_unique((*pvsIn).size() >4?3:(*pvsIn).size()-1,"Other"+pvName_,false); std::vector pvsz; for(size_t i=1;i < (*pvsIn).size() && i < 4; i++) pvsz.push_back((*pvsIn)[i-1].position().z()); - otherPVsTable->addColumn("z",pvsz,"Z position of other primary vertices, excluding the main PV",FlatTable::FloatColumn,8); + otherPVsTable->addColumn("z",pvsz,"Z position of other primary vertices, excluding the main PV",nanoaod::FlatTable::FloatColumn,8); edm::Handle > svsIn; @@ -160,10 +160,10 @@ VertexTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) } - auto svsTable = std::make_unique(selCandSv->size(),svName_,false); + auto svsTable = std::make_unique(selCandSv->size(),svName_,false); // For SV we fill from here only stuff that cannot be created with the SimpleFlatTableProducer - svsTable->addColumn("dlen",dlen,"decay length in cm",FlatTable::FloatColumn,10); - svsTable->addColumn("dlenSig",dlenSig,"decay length significance",FlatTable::FloatColumn, 10); + svsTable->addColumn("dlen",dlen,"decay length in cm",nanoaod::FlatTable::FloatColumn,10); + svsTable->addColumn("dlenSig",dlenSig,"decay length significance",nanoaod::FlatTable::FloatColumn, 10); iEvent.put(std::move(pvTable),"pv"); From 53674c07e73da4d554fe9f75828af8d70c60f1d4 Mon Sep 17 00:00:00 2001 From: Andrea Date: Mon, 2 Oct 2017 15:49:24 +0200 Subject: [PATCH 33/36] add autoflush options, default -10MB --- PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc index f605147323cc2..245e4b033066a 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc @@ -63,6 +63,7 @@ class NanoAODOutputModule : public edm::one::OutputModule<> { std::string m_compressionAlgorithm; bool m_writeProvenance; bool m_fakeName; //crab workaround, remove after crab is fixed + int m_autoFlush; edm::ProcessHistoryRegistry m_processHistoryRegistry; edm::JobReport::Token m_jrToken; std::unique_ptr m_file; @@ -139,6 +140,7 @@ NanoAODOutputModule::NanoAODOutputModule(edm::ParameterSet const& pset): m_compressionAlgorithm(pset.getUntrackedParameter("compressionAlgorithm")), m_writeProvenance(pset.getUntrackedParameter("saveProvenance", true)), m_fakeName(pset.getUntrackedParameter("fakeNameForCrab", false)), + m_autoFlush(pset.getUntrackedParameter("autoFlush", -10000000)), m_processHistoryRegistry() { } @@ -258,6 +260,7 @@ NanoAODOutputModule::openFile(edm::FileBlock const&) { // create the trees m_tree.reset(new TTree("Events","Events")); m_tree->SetAutoSave(std::numeric_limits::max()); + m_tree->SetAutoFlush(m_autoFlush); m_commonBranches.branch(*m_tree); m_lumiTree.reset(new TTree("LuminosityBlocks","LuminosityBlocks")); From a23e5547cbc28ae81eb26e924c63555f9ec4dc3e Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 4 Oct 2017 17:44:19 +0200 Subject: [PATCH 34/36] Fix event content (namespace nanoaod missing in the nanoaod dataformats) --- PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc | 2 +- PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc index 2b74f0f36f837..79df422028930 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc @@ -320,7 +320,7 @@ NanoAODOutputModule::fillDescriptions(edm::ConfigurationDescriptions& descriptio ->setComment("Change the OutputModule name in the fwk job report to fake PoolOutputModule. This is needed to run on cran (and publish) till crab is fixed"); //replace with whatever you want to get from the EDM by default - const std::vector keep = {"drop *", "keep FlatTable_*Table_*_*", "keep edmTriggerResults_*_*_*", "keep MergeableCounterTable_*Table_*_*", "keep UniqueString_nanoMetadata_*_*"}; + const std::vector keep = {"drop *", "keep nanoaodFlatTable_*Table_*_*", "keep edmTriggerResults_*_*_*", "keep nanoaodMergeableCounterTable_*Table_*_*", "keep nanoaodUniqueString_nanoMetadata_*_*"}; edm::OutputModule::fillDescription(desc, keep); //Used by Workflow management for their own meta data diff --git a/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py b/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py index c059641b07e48..e72edd9cfec73 100644 --- a/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py +++ b/PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py @@ -3,10 +3,10 @@ NanoAODEDMEventContent = cms.PSet( outputCommands = cms.untracked.vstring( 'drop *', - "keep FlatTable_*Table_*_*", # event data + "keep nanoaodFlatTable_*Table_*_*", # event data "keep edmTriggerResults_*_*_*", # event data - "keep MergeableCounterTable_*Table_*_*", # accumulated per/run or per/lumi data - "keep UniqueString_nanoMetadata_*_*", # basic metadata + "keep nanoaodMergeableCounterTable_*Table_*_*", # accumulated per/run or per/lumi data + "keep nanoaodUniqueString_nanoMetadata_*_*", # basic metadata ) ) From 3e9aab9a9e82c50b9df5df88455fdeb942629297 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 4 Oct 2017 18:13:19 +0200 Subject: [PATCH 35/36] Call produces<> with edm::Transition::EndRun instead of edm::InRun (the latter doesn't work anymore as of 940pre2) --- PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc index 7e25fe71db49a..08e812ee4447b 100644 --- a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc @@ -120,7 +120,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer("LHEScale"); produces("LHEPdf"); produces("LHENamed"); - produces(); + produces(); if (namedWeightIDs_.size() != namedWeightLabels_.size()) { throw cms::Exception("Configuration", "Size mismatch between namedWeightIDs & namedWeightLabels"); } From 4d5e095d854df45cf51b674f7e41ffb2a3dd6360 Mon Sep 17 00:00:00 2001 From: Andrea Date: Thu, 5 Oct 2017 16:34:04 +0200 Subject: [PATCH 36/36] add integration tests --- PhysicsTools/NanoAOD/test/BuildFile.xml | 8 ++++++++ .../NanoAOD/test/runtestPhysicsToolsNanoAOD.cpp | 3 +++ PhysicsTools/NanoAOD/test/runtests.sh | 11 +++++++++++ 3 files changed, 22 insertions(+) create mode 100644 PhysicsTools/NanoAOD/test/BuildFile.xml create mode 100644 PhysicsTools/NanoAOD/test/runtestPhysicsToolsNanoAOD.cpp create mode 100755 PhysicsTools/NanoAOD/test/runtests.sh diff --git a/PhysicsTools/NanoAOD/test/BuildFile.xml b/PhysicsTools/NanoAOD/test/BuildFile.xml new file mode 100644 index 0000000000000..4f87df362191e --- /dev/null +++ b/PhysicsTools/NanoAOD/test/BuildFile.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/PhysicsTools/NanoAOD/test/runtestPhysicsToolsNanoAOD.cpp b/PhysicsTools/NanoAOD/test/runtestPhysicsToolsNanoAOD.cpp new file mode 100644 index 0000000000000..b2991bd18ae57 --- /dev/null +++ b/PhysicsTools/NanoAOD/test/runtestPhysicsToolsNanoAOD.cpp @@ -0,0 +1,3 @@ +#include "FWCore/Utilities/interface/TestHelper.h" + +RUNTEST() diff --git a/PhysicsTools/NanoAOD/test/runtests.sh b/PhysicsTools/NanoAOD/test/runtests.sh new file mode 100755 index 0000000000000..bb43e5a0e5912 --- /dev/null +++ b/PhysicsTools/NanoAOD/test/runtests.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +function die { echo $1: status $2 ; exit $2; } + +#to be enabled with the right files +#cmsDriver.py test80X -s NANO --mc --eventcontent NANOAODSIM --datatier NANO --filein /store/relval/CMSSW_8_0_0/RelValTTbar_13/MINIAODSIM/PU25ns_80X_mcRun2_asymptotic_v4-v1/10000/A65CD249-BFDA-E511-813A-0025905A6066.root --conditions auto:run2_mc -n 100 --era Run2_2016,run2_miniAOD_80XLegacy || die 'Failure using cmsdriver 80X' $? +cmsDriver.py test92X -s NANO --mc --eventcontent NANOAODSIM --datatier NANO --filein /store/relval/CMSSW_9_2_12/RelValTTbar_13/MINIAODSIM/PU25ns_92X_upgrade2017_realistic_v11-v1/00000/080E2624-F59D-E711-ACEE-0CC47A7C35A4.root --conditions auto:phase1_2017_realistic -n 100 --era Run2_2017,run2_nanoAOD_92X || die 'Failure using cmsdriver 92X' $? + +cmsDriver.py test94X -s NANO --mc --eventcontent NANOAODSIM --datatier NANO --filein /store/relval/CMSSW_9_4_0_pre1/RelValTTbar_13/MINIAODSIM/PU25ns_93X_mc2017_realistic_v3-v1/00000/92FD5642-509D-E711-ADAB-0025905B85C6.root --conditions auto:phase1_2017_realistic -n 100 --era Run2_2017 || die 'Failure using cmsdriver 94X' $? + +