From 592f3e38ae215e385fa64ee05a3a17f2435c8948 Mon Sep 17 00:00:00 2001 From: Massimiliano Galli Date: Mon, 8 Nov 2021 11:34:08 +0100 Subject: [PATCH 1/4] Add beamspot table and task --- .../plugins/SimpleFlatTableProducerPlugins.cc | 4 ++++ PhysicsTools/NanoAOD/python/globals_cff.py | 17 ++++++++++++++++- PhysicsTools/NanoAOD/test/nano_cfg.py | 3 +++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc index 404b12c6f316c..cf30e060c442b 100644 --- a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc +++ b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc @@ -21,6 +21,9 @@ typedef SimpleFlatTableProducer SimpleLocalTrackFlatTablePr #include "DataFormats/Math/interface/Point3D.h" typedef EventSingletonSimpleFlatTableProducer SimpleXYZPointFlatTableProducer; +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +typedef EventSingletonSimpleFlatTableProducer SimpleBeamspotFlatTableProducer; + #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer); DEFINE_FWK_MODULE(SimpleGenEventFlatTableProducer); @@ -29,3 +32,4 @@ DEFINE_FWK_MODULE(SimpleHTXSFlatTableProducer); DEFINE_FWK_MODULE(SimpleProtonTrackFlatTableProducer); DEFINE_FWK_MODULE(SimpleLocalTrackFlatTableProducer); DEFINE_FWK_MODULE(SimpleXYZPointFlatTableProducer); +DEFINE_FWK_MODULE(SimpleBeamspotFlatTableProducer); diff --git a/PhysicsTools/NanoAOD/python/globals_cff.py b/PhysicsTools/NanoAOD/python/globals_cff.py index c544e11f90522..86706995bceda 100644 --- a/PhysicsTools/NanoAOD/python/globals_cff.py +++ b/PhysicsTools/NanoAOD/python/globals_cff.py @@ -1,6 +1,21 @@ import FWCore.ParameterSet.Config as cms from PhysicsTools.NanoAOD.common_cff import * +beamSpotTable = cms.EDProducer("SimpleBeamspotFlatTableProducer", + src = cms.InputTag("offlineBeamSpot"), + name = cms.string("BeamSpot"), + doc = cms.string("offlineBeamSpot, the offline reconstructed beamspot"), + 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( + type = Var("type()","int8",doc="BeamSpot type (Unknown = -1, Fake = 0, LHC = 1, Tracker = 2)"), + z = Var("position().z()",float,doc="BeamSpot center, z coordinate (cm)",precision=-1), + zError = Var("z0Error()",float,doc="Error on BeamSpot center, z coordinate (cm)",precision=-1), + sigmaZ = Var("sigmaZ()",float,doc="Width of BeamSpot in z (cm)",precision=-1), + sigmaZError = Var("sigmaZ0Error()",float,doc="Error on width of BeamSpot in z (cm)",precision=-1), + ), +) + rhoTable = cms.EDProducer("GlobalVariablesTableProducer", variables = cms.PSet( fixedGridRhoFastjetAll = ExtVar( cms.InputTag("fixedGridRhoFastjetAll"), "double", doc = "rho from all PF Candidates, used e.g. for JECs" ), @@ -53,5 +68,5 @@ ), ) -globalTablesTask = cms.Task(rhoTable) +globalTablesTask = cms.Task(beamSpotTable, rhoTable) globalTablesMCTask = cms.Task(puTable,genTable,genFilterTable) diff --git a/PhysicsTools/NanoAOD/test/nano_cfg.py b/PhysicsTools/NanoAOD/test/nano_cfg.py index cf13fd70ed58b..914e085eb15d0 100644 --- a/PhysicsTools/NanoAOD/test/nano_cfg.py +++ b/PhysicsTools/NanoAOD/test/nano_cfg.py @@ -6,6 +6,9 @@ process.load("FWCore.MessageLogger.MessageLogger_cfi") process.load("Configuration.StandardSequences.GeometryDB_cff") +process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi') +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load('Configuration.StandardSequences.MagneticField_cff') process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") process.load('Configuration.StandardSequences.Services_cff') from Configuration.AlCa.autoCond import autoCond From 0a6d12d612250f64d98041de04e4cc7e3fcfb8df Mon Sep 17 00:00:00 2001 From: Massimiliano Galli Date: Mon, 8 Nov 2021 13:16:38 +0100 Subject: [PATCH 2/4] Add int8 support --- DataFormats/NanoAOD/interface/FlatTable.h | 8 +++++++- DataFormats/NanoAOD/src/FlatTable.cc | 5 +++++ DataFormats/NanoAOD/src/classes_def.xml | 3 ++- PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h | 7 +++++++ PhysicsTools/NanoAOD/plugins/NanoAODDQM.cc | 3 +++ PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc | 3 +++ PhysicsTools/NanoAOD/plugins/TableOutputBranches.h | 1 + 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/DataFormats/NanoAOD/interface/FlatTable.h b/DataFormats/NanoAOD/interface/FlatTable.h index 3ff9f82edbdcd..8a0638e07cd75 100644 --- a/DataFormats/NanoAOD/interface/FlatTable.h +++ b/DataFormats/NanoAOD/interface/FlatTable.h @@ -43,7 +43,8 @@ namespace nanoaod { UInt8, Bool, UInt32, - Double + Double, + Int8 }; // We could have other Float types with reduced mantissa, and similar FlatTable() : size_(0) {} @@ -143,6 +144,8 @@ namespace nanoaod { return ColumnType::Int; else if constexpr (std::is_same()) return ColumnType::UInt8; + else if constexpr (std::is_same()) + return ColumnType::Int8; else if constexpr (std::is_same()) return ColumnType::Bool; else if constexpr (std::is_same()) @@ -191,6 +194,8 @@ namespace nanoaod { return table.ints_; else if constexpr (std::is_same()) return table.uint8s_; + else if constexpr (std::is_same()) + return table.int8s_; else if constexpr (std::is_same()) return table.uint8s_; else if constexpr (std::is_same()) @@ -208,6 +213,7 @@ namespace nanoaod { std::vector floats_; std::vector ints_; std::vector uint8s_; + std::vector int8s_; std::vector uint32s_; std::vector doubles_; }; diff --git a/DataFormats/NanoAOD/src/FlatTable.cc b/DataFormats/NanoAOD/src/FlatTable.cc index 1ba7933773f30..4b8b212c43a44 100644 --- a/DataFormats/NanoAOD/src/FlatTable.cc +++ b/DataFormats/NanoAOD/src/FlatTable.cc @@ -19,6 +19,9 @@ void nanoaod::FlatTable::addExtension(const nanoaod::FlatTable& other) { case ColumnType::Int: addColumn(other.columnName(i), other.columnData(i), other.columnDoc(i)); break; + case ColumnType::Int8: + addColumn(other.columnName(i), other.columnData(i), other.columnDoc(i)); + break; case ColumnType::Bool: addColumn(other.columnName(i), other.columnData(i), other.columnDoc(i)); break; @@ -45,6 +48,8 @@ double nanoaod::FlatTable::getAnyValue(unsigned int row, unsigned int column) co return *(beginData(column) + row); case ColumnType::Int: return *(beginData(column) + row); + case ColumnType::Int8: + return *(beginData(column) + row); case ColumnType::Bool: return *(beginData(column) + row); case ColumnType::UInt8: diff --git a/DataFormats/NanoAOD/src/classes_def.xml b/DataFormats/NanoAOD/src/classes_def.xml index 58f08dfc7e9f8..a4b33b3a87940 100644 --- a/DataFormats/NanoAOD/src/classes_def.xml +++ b/DataFormats/NanoAOD/src/classes_def.xml @@ -3,7 +3,8 @@ - + + diff --git a/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h b/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h index 2c0a0dab8f6d9..90a63f3d63eba 100644 --- a/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h +++ b/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h @@ -127,6 +127,8 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> { vars_.push_back(std::make_unique(vname, varPSet)); else if (type == "float") vars_.push_back(std::make_unique(vname, varPSet)); + else if (type == "int8") + vars_.push_back(std::make_unique(vname, varPSet)); else if (type == "uint8") vars_.push_back(std::make_unique(vname, varPSet)); else if (type == "bool") @@ -164,6 +166,7 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> { typedef FuncVariable, int> IntVar; typedef FuncVariable, unsigned int> UIntVar; typedef FuncVariable, float> FloatVar; + typedef FuncVariable, int8_t> Int8Var; typedef FuncVariable, uint8_t> UInt8Var; typedef FuncVariable, bool> BoolVar; std::vector>> vars_; @@ -192,6 +195,9 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_)); + else if (type == "int8") + extvars_.push_back( + std::make_unique(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_)); else if (type == "uint8") extvars_.push_back( std::make_unique(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_)); @@ -246,6 +252,7 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase FloatExtVar; typedef ValueMapVariable DoubleExtVar; typedef ValueMapVariable BoolExtVar; + typedef ValueMapVariable Int8ExtVar; typedef ValueMapVariable UInt8ExtVar; std::vector>> extvars_; }; diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODDQM.cc b/PhysicsTools/NanoAOD/plugins/NanoAODDQM.cc index 01f98282d825d..59a36ef99456d 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODDQM.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODDQM.cc @@ -92,6 +92,9 @@ class NanoAODDQM : public DQMEDAnalyzer { case FlatTable::ColumnType::Int: vfill(table, icol, rowsel); break; + case FlatTable::ColumnType::Int8: + vfill(table, icol, rowsel); + break; case FlatTable::ColumnType::UInt8: vfill(table, icol, rowsel); break; diff --git a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc index 9e0c46d2f99c9..892bbe0ad7cef 100644 --- a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc +++ b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc @@ -19,6 +19,9 @@ void TableOutputBranches::defineBranchesFromFirstEvent(const nanoaod::FlatTable case nanoaod::FlatTable::ColumnType::Int: m_intBranches.emplace_back(var, tab.columnDoc(i), "I"); break; + case nanoaod::FlatTable::ColumnType::Int8: + m_int8Branches.emplace_back(var, tab.columnDoc(i), "b"); + break; case nanoaod::FlatTable::ColumnType::UInt8: m_uint8Branches.emplace_back(var, tab.columnDoc(i), "b"); break; diff --git a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h index 405eced521dad..f5619e27a3b6c 100644 --- a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h +++ b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h @@ -43,6 +43,7 @@ class TableOutputBranches { TBranch *m_counterBranch = nullptr; std::vector m_floatBranches; std::vector m_intBranches; + std::vector m_int8Branches; std::vector m_uint8Branches; std::vector m_uint32Branches; std::vector m_doubleBranches; From 2c51b2fdc53c84ff1bb708d8f11b3c7770e60ca3 Mon Sep 17 00:00:00 2001 From: lgray Date: Fri, 30 Jul 2021 11:20:27 -0500 Subject: [PATCH 3/4] add missing vars --- DataFormats/NanoAOD/src/classes.h | 2 ++ DataFormats/NanoAOD/src/classes_def.xml | 1 + PhysicsTools/NanoAOD/python/globals_cff.py | 1 + PhysicsTools/NanoAOD/python/photons_cff.py | 4 ++-- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DataFormats/NanoAOD/src/classes.h b/DataFormats/NanoAOD/src/classes.h index acdf6f161f7cb..1e46b90b4acd7 100644 --- a/DataFormats/NanoAOD/src/classes.h +++ b/DataFormats/NanoAOD/src/classes.h @@ -4,3 +4,5 @@ #include "DataFormats/NanoAOD/interface/MergeableCounterTable.h" #include "DataFormats/NanoAOD/interface/UniqueString.h" #include "DataFormats/Common/interface/Wrapper.h" + +std::vector svi8; diff --git a/DataFormats/NanoAOD/src/classes_def.xml b/DataFormats/NanoAOD/src/classes_def.xml index a4b33b3a87940..e6c1551b8fc89 100644 --- a/DataFormats/NanoAOD/src/classes_def.xml +++ b/DataFormats/NanoAOD/src/classes_def.xml @@ -23,6 +23,7 @@ + diff --git a/PhysicsTools/NanoAOD/python/globals_cff.py b/PhysicsTools/NanoAOD/python/globals_cff.py index 86706995bceda..4b711c5cc041e 100644 --- a/PhysicsTools/NanoAOD/python/globals_cff.py +++ b/PhysicsTools/NanoAOD/python/globals_cff.py @@ -18,6 +18,7 @@ rhoTable = cms.EDProducer("GlobalVariablesTableProducer", variables = cms.PSet( + fixedGridRhoAll = ExtVar( cms.InputTag("fixedGridRhoAll"), "double", doc = "rho from all PF Candidates, no foreground removal (for isolation of prompt photons)" ), 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" ), diff --git a/PhysicsTools/NanoAOD/python/photons_cff.py b/PhysicsTools/NanoAOD/python/photons_cff.py index 1a9ef58adc7dd..b6accd751ee54 100644 --- a/PhysicsTools/NanoAOD/python/photons_cff.py +++ b/PhysicsTools/NanoAOD/python/photons_cff.py @@ -189,7 +189,7 @@ def make_bitmapVID_docstring(id_modules_working_points_pset): cutBased = Var( "userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')", int, - doc="cut-based ID bitmap, Fall17V2, (0:fail, 1:loose, 2:medium, 3:tight)" + doc="cut-based ID bitmap, Fall17V2, (0:fail, 1:loose, 2:medium, 3:tight)", ), cutBased_Fall17V1Bitmap = Var( "userInt('cutbasedIDV1_loose')+2*userInt('cutbasedIDV1_medium')+4*userInt('cutbasedIDV1_tight')", @@ -199,7 +199,7 @@ def make_bitmapVID_docstring(id_modules_working_points_pset): vidNestedWPBitmap = Var( "userInt('VIDNestedWPBitmap')", int, - doc="Fall17V2 " + make_bitmapVID_docstring(photon_id_modules_WorkingPoints_nanoAOD) + doc="Fall17V2 " + make_bitmapVID_docstring(photon_id_modules_WorkingPoints_nanoAOD), ), electronVeto = Var("passElectronVeto()",bool,doc="pass electron veto"), pixelSeed = Var("hasPixelSeed()",bool,doc="has pixel seed"), From c31707319cab81cdfc2c653b70feec6613dc4921 Mon Sep 17 00:00:00 2001 From: Massimiliano Galli Date: Tue, 16 Nov 2021 13:48:05 +0100 Subject: [PATCH 4/4] Add rho and beamspot variables to DQM --- PhysicsTools/NanoAOD/python/globals_cff.py | 1 + PhysicsTools/NanoAOD/python/nanoDQM_cfi.py | 35 +++++++++++++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/globals_cff.py b/PhysicsTools/NanoAOD/python/globals_cff.py index 4b711c5cc041e..1fa6dce476586 100644 --- a/PhysicsTools/NanoAOD/python/globals_cff.py +++ b/PhysicsTools/NanoAOD/python/globals_cff.py @@ -17,6 +17,7 @@ ) rhoTable = cms.EDProducer("GlobalVariablesTableProducer", + name = cms.string("Rho"), variables = cms.PSet( fixedGridRhoAll = ExtVar( cms.InputTag("fixedGridRhoAll"), "double", doc = "rho from all PF Candidates, no foreground removal (for isolation of prompt photons)" ), fixedGridRhoFastjetAll = ExtVar( cms.InputTag("fixedGridRhoFastjetAll"), "double", doc = "rho from all PF Candidates, used e.g. for JECs" ), diff --git a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py index 9a2c7572ce5f1..85e17b26b78fb 100644 --- a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py +++ b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py @@ -855,16 +855,31 @@ Plot1D('rawMVAoldDMdR032017v2', 'rawMVAoldDMdR032017v2', 20, -1, 1, 'byIsolationMVArun2017v2DBoldDMdR0p3wLT raw output discriminator (2017v2)'), ) ), - L1PreFiringWeight = cms.PSet( - sels = cms.PSet(), - plots = cms.VPSet( - Plot1D('Nom', 'Nom', 21, 0.8, 1.01, 'L1 prefiring weight nominal'), - Plot1D('Up', 'Up', 21, 0.8, 1.01, 'L1 prefiring weight uncertainy up'), - Plot1D('Dn', 'Dn', 21, 0.8, 1.01, 'L1 prefiring weight uncertainty down'), - Plot1D('ECAL_Nom', 'ECAL_Nom', 21, 0.8, 1.01, 'L1 prefiring weight for ECAL objects nominal'), - Plot1D('Muon_Nom', 'Muon_Nom', 21, 0.8, 1.01, 'L1 prefiring weight for muons nominal'), - ) + L1PreFiringWeight = cms.PSet( + sels = cms.PSet(), + plots = cms.VPSet( + Plot1D('Nom', 'Nom', 21, 0.8, 1.01, 'L1 prefiring weight nominal'), + Plot1D('Up', 'Up', 21, 0.8, 1.01, 'L1 prefiring weight uncertainy up'), + Plot1D('Dn', 'Dn', 21, 0.8, 1.01, 'L1 prefiring weight uncertainty down'), + Plot1D('ECAL_Nom', 'ECAL_Nom', 21, 0.8, 1.01, 'L1 prefiring weight for ECAL objects nominal'), + Plot1D('Muon_Nom', 'Muon_Nom', 21, 0.8, 1.01, 'L1 prefiring weight for muons nominal'), + ) - ), + ), + BeamSpot = cms.PSet( + sels = cms.PSet(), + plots = cms.VPSet( + Plot1D('z', 'z', 20, 0.5, 1.5, 'BeamSpot center, z coordinate (cm)'), + Plot1D('zError', 'zError', 20, 0., 0.01, 'Error on BeamSpot center, z coordinate (cm)'), + Plot1D('sigmaZ', 'sigmaZ', 20, 0., 10, 'Width of BeamSpot in z (cm)'), + Plot1D('sigmaZError', 'sigmaZError', 20, 0., 0.01, 'Error on width of BeamSpot in z (cm)'), + ) + ), + Rho = cms.PSet( + sels = cms.PSet(), + plots = cms.VPSet( + Plot1D('fixedGridRhoAll', 'fixedGridRhoAll', 100, 0, 80, 'rho from all PF Candidates, no foreground removal (for isolation of prompt photons)'), + ) + ), ) )