From 7b6d0bead15c61a30fcbb5295d919117eb235b21 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Wed, 15 Nov 2023 17:22:46 +0100 Subject: [PATCH] Additional main vertex info --- .../interface/SimpleFlatTableProducer.h | 2 +- .../plugins/SimpleFlatTableProducerPlugins.cc | 4 ++ .../NanoAOD/plugins/VertexTableProducer.cc | 64 +++++++++++++++++++ PhysicsTools/NanoAOD/python/vertices_cff.py | 33 +++++++++- 4 files changed, 100 insertions(+), 3 deletions(-) diff --git a/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h b/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h index 85d63e7ca8948..4b40f12492e9c 100644 --- a/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h +++ b/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h @@ -452,7 +452,7 @@ class FirstObjectSimpleFlatTableProducer : public SimpleFlatTableProducerBase>::baseDescriptions(); + edm::ParameterSetDescription desc = SimpleFlatTableProducerBase>::baseDescriptions(); descriptions.addWithDefaultLabel(desc); } diff --git a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc index f9a2fa3efe213..21b6470232520 100644 --- a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc +++ b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc @@ -57,6 +57,9 @@ typedef SimpleFlatTableProducer SimpleRun3ScoutingElectron #include "DataFormats/Scouting/interface/Run3ScoutingTrack.h" typedef SimpleFlatTableProducer SimpleRun3ScoutingTrackFlatTableProducer; +#include "DataFormats/VertexReco/interface/Vertex.h" +typedef SimpleFlatTableProducer SimpleVertexFlatTableProducer; + #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer); DEFINE_FWK_MODULE(SimpleGenEventFlatTableProducer); @@ -77,3 +80,4 @@ DEFINE_FWK_MODULE(SimpleRun3ScoutingPhotonFlatTableProducer); DEFINE_FWK_MODULE(SimpleRun3ScoutingMuonFlatTableProducer); DEFINE_FWK_MODULE(SimpleRun3ScoutingElectronFlatTableProducer); DEFINE_FWK_MODULE(SimpleRun3ScoutingTrackFlatTableProducer); +DEFINE_FWK_MODULE(SimpleVertexFlatTableProducer); diff --git a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc index e79ecf40450c8..e9f853d30ecb8 100644 --- a/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc @@ -41,6 +41,8 @@ #include "RecoVertex/VertexPrimitives/interface/VertexState.h" #include "DataFormats/Common/interface/ValueMap.h" +#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h" + // // class declaration // @@ -74,6 +76,17 @@ class VertexTableProducer : public edm::stream::EDProducer<> { const std::string svName_; const std::string svDoc_; const double dlenMin_, dlenSigMin_; + + typedef FuncVariable, int32_t> IntVar; + typedef FuncVariable, uint32_t> UIntVar; + typedef FuncVariable, float> FloatVar; + typedef FuncVariable, double> DoubleVar; + typedef FuncVariable, int8_t> Int8Var; + typedef FuncVariable, uint8_t> UInt8Var; + typedef FuncVariable, int16_t> Int16Var; + typedef FuncVariable, uint16_t> UInt16Var; + typedef FuncVariable, bool> BoolVar; + std::vector>> pvVars_; }; // @@ -93,6 +106,34 @@ VertexTableProducer::VertexTableProducer(const edm::ParameterSet& params) dlenSigMin_(params.getParameter("dlenSigMin")) { + if (params.existsAs("optionalPvVariables")) { + edm::ParameterSet const& varsPSet = params.getParameter("optionalPvVariables"); + for (const std::string& vname : varsPSet.getParameterNamesForType()) { + const auto& varPSet = varsPSet.getParameter(vname); + const std::string& type = varPSet.getParameter("type"); + if (type == "int") + pvVars_.push_back(std::make_unique(vname, varPSet)); + else if (type == "uint") + pvVars_.push_back(std::make_unique(vname, varPSet)); + else if (type == "float") + pvVars_.push_back(std::make_unique(vname, varPSet)); + else if (type == "double") + pvVars_.push_back(std::make_unique(vname, varPSet)); + else if (type == "int8") + pvVars_.push_back(std::make_unique(vname, varPSet)); + else if (type == "uint8") + pvVars_.push_back(std::make_unique(vname, varPSet)); + else if (type == "int16") + pvVars_.push_back(std::make_unique(vname, varPSet)); + else if (type == "uint16") + pvVars_.push_back(std::make_unique(vname, varPSet)); + else if (type == "bool") + pvVars_.push_back(std::make_unique(vname, varPSet)); + else + throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname); + } + } + produces("pv"); produces("otherPVs"); produces("svs"); @@ -130,6 +171,9 @@ void VertexTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe "npvsGood", goodPVs, "number of good reconstructed primary vertices. selection:" + goodPvCutString_); pvTable->addColumnValue( "score", pvsScoreProd.get(pvsIn.id(), 0), "main primary vertex score, i.e. sum pt2 of clustered objects", 8); + std::vector pvVec = {&(*pvsIn)[0]}; + for (const auto& var : pvVars_) + var->fill(pvVec, *pvTable); auto otherPVsTable = std::make_unique((*pvsIn).size() > 4 ? 3 : (*pvsIn).size() - 1, "Other" + pvName_, false); @@ -219,6 +263,26 @@ void VertexTableProducer::fillDescriptions(edm::ConfigurationDescriptions& descr desc.add("svName")->setComment("name of the flat table ouput"); desc.add("svDoc")->setComment("a few words of documentation"); + // additional main vertex variables + edm::ParameterSetDescription variable; + variable.add("expr")->setComment("a function to define the content of the branch in the flat table"); + variable.add("doc")->setComment("few words description of the branch content"); + variable.ifValue( + edm::ParameterDescription( + "type", "int", true, edm::Comment("the c++ type of the branch in the flat table")), + edm::allowedValues("int", "uint", "float", "double", "int8", "uint8", "int16", "uint16", "bool")); + variable.addOptionalNode( + edm::ParameterDescription( + "precision", true, edm::Comment("the precision with which to store the value in the flat table")) xor + edm::ParameterDescription( + "precision", true, edm::Comment("the precision with which to store the value in the flat table")), + false); + edm::ParameterSetDescription variables; + variables.setComment("a parameters set to define additional variables describing main vertex"); + variables.addNode(edm::ParameterWildcard("*", edm::RequireZeroOrMore, true, variable)); + desc.addOptional("optionalPvVariables", variables) + ->setComment("Optional variables of the main primary vertex"); + descriptions.addWithDefaultLabel(desc); } diff --git a/PhysicsTools/NanoAOD/python/vertices_cff.py b/PhysicsTools/NanoAOD/python/vertices_cff.py index ddda0ba422c1e..481bb3e614043 100644 --- a/PhysicsTools/NanoAOD/python/vertices_cff.py +++ b/PhysicsTools/NanoAOD/python/vertices_cff.py @@ -1,6 +1,7 @@ import FWCore.ParameterSet.Config as cms from PhysicsTools.NanoAOD.common_cff import * from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi import simpleCandidateFlatTableProducer +from PhysicsTools.NanoAOD.simpleVertexFlatTableProducer_cfi import simpleVertexFlatTableProducer ##################### User floats producers, selectors ########################## @@ -35,9 +36,37 @@ svCandidateTable.variables.pt.precision=10 svCandidateTable.variables.phi.precision=12 +covarianceVars = cms.PSet( + cxx = Var("covariance(0,0)", float, doc="vertex covariance (0,0)", precision = 16), + cyx = Var("covariance(1,0)", float, doc="vertex covariance (1,0)", precision = 16), + czx = Var("covariance(2,0)", float, doc="vertex covariance (2,0)", precision = 16), + cyy = Var("covariance(1,1)", float, doc="vertex covariance (1,1)", precision = 16), + czy = Var("covariance(2,1)", float, doc="vertex covariance (2,1)", precision = 16), + czz = Var("covariance(2,2)", float, doc="vertex covariance (2,2)", precision = 16) +) + +vertexTable.optionalPvVariables = covarianceVars + +verticesWithBS = "offlineSlimmedPrimaryVerticesWithBS" +pvbsTable = simpleVertexFlatTableProducer.clone( + src = verticesWithBS, + name = "PVBS", + doc = "main primary vertex with beam-spot", + maxLen = 1, + variables = cms.PSet( + covarianceVars, + x = Var("position().x()", float, doc = "position x coordinate, in cm", precision = 10), + y = Var("position().y()", float, doc = "position y coordinate, in cm", precision = 10), + z = Var("position().z()", float, doc = "position z coordinate, in cm", precision = 16), + ndof = Var("ndof()", float, doc = "number of degrees of freedom", precision = 8), + chi2 = Var("normalizedChi2()", float, doc = "reduced chi2, i.e. chi2/ndof", precision = 8), + ), + externalVariables = cms.PSet( + score = ExtVar(cms.InputTag(verticesWithBS), float, doc="vertex score, i.e. sum pt2 of clustered objects", precision = 8) + ) +) #before cross linking vertexTask = cms.Task() #after cross linkining -vertexTablesTask = cms.Task( vertexTable, svCandidateTable ) - +vertexTablesTask = cms.Task( vertexTable, svCandidateTable, pvbsTable )