Skip to content

Commit

Permalink
Additional main vertex info
Browse files Browse the repository at this point in the history
  • Loading branch information
mbluj committed Dec 7, 2023
1 parent cc04c97 commit 7b6d0be
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
2 changes: 1 addition & 1 deletion PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class FirstObjectSimpleFlatTableProducer : public SimpleFlatTableProducerBase<T,
~FirstObjectSimpleFlatTableProducer() override {}

static void fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
edm::ParameterSetDescription desc = desc = SimpleFlatTableProducerBase<T, edm::View<T>>::baseDescriptions();
edm::ParameterSetDescription desc = SimpleFlatTableProducerBase<T, edm::View<T>>::baseDescriptions();
descriptions.addWithDefaultLabel(desc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ typedef SimpleFlatTableProducer<Run3ScoutingElectron> SimpleRun3ScoutingElectron
#include "DataFormats/Scouting/interface/Run3ScoutingTrack.h"
typedef SimpleFlatTableProducer<Run3ScoutingTrack> SimpleRun3ScoutingTrackFlatTableProducer;

#include "DataFormats/VertexReco/interface/Vertex.h"
typedef SimpleFlatTableProducer<reco::Vertex> SimpleVertexFlatTableProducer;

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer);
DEFINE_FWK_MODULE(SimpleGenEventFlatTableProducer);
Expand All @@ -77,3 +80,4 @@ DEFINE_FWK_MODULE(SimpleRun3ScoutingPhotonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingMuonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingElectronFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingTrackFlatTableProducer);
DEFINE_FWK_MODULE(SimpleVertexFlatTableProducer);
64 changes: 64 additions & 0 deletions PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "RecoVertex/VertexPrimitives/interface/VertexState.h"
#include "DataFormats/Common/interface/ValueMap.h"

#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h"

//
// class declaration
//
Expand Down Expand Up @@ -74,6 +76,17 @@ class VertexTableProducer : public edm::stream::EDProducer<> {
const std::string svName_;
const std::string svDoc_;
const double dlenMin_, dlenSigMin_;

typedef FuncVariable<reco::Vertex, StringObjectFunction<reco::Vertex>, int32_t> IntVar;
typedef FuncVariable<reco::Vertex, StringObjectFunction<reco::Vertex>, uint32_t> UIntVar;
typedef FuncVariable<reco::Vertex, StringObjectFunction<reco::Vertex>, float> FloatVar;
typedef FuncVariable<reco::Vertex, StringObjectFunction<reco::Vertex>, double> DoubleVar;
typedef FuncVariable<reco::Vertex, StringObjectFunction<reco::Vertex>, int8_t> Int8Var;
typedef FuncVariable<reco::Vertex, StringObjectFunction<reco::Vertex>, uint8_t> UInt8Var;
typedef FuncVariable<reco::Vertex, StringObjectFunction<reco::Vertex>, int16_t> Int16Var;
typedef FuncVariable<reco::Vertex, StringObjectFunction<reco::Vertex>, uint16_t> UInt16Var;
typedef FuncVariable<reco::Vertex, StringCutObjectSelector<reco::Vertex>, bool> BoolVar;
std::vector<std::unique_ptr<Variable<reco::Vertex>>> pvVars_;
};

//
Expand All @@ -93,6 +106,34 @@ VertexTableProducer::VertexTableProducer(const edm::ParameterSet& params)
dlenSigMin_(params.getParameter<double>("dlenSigMin"))

{
if (params.existsAs<edm::ParameterSet>("optionalPvVariables")) {
edm::ParameterSet const& varsPSet = params.getParameter<edm::ParameterSet>("optionalPvVariables");
for (const std::string& vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
const auto& varPSet = varsPSet.getParameter<edm::ParameterSet>(vname);
const std::string& type = varPSet.getParameter<std::string>("type");
if (type == "int")
pvVars_.push_back(std::make_unique<IntVar>(vname, varPSet));
else if (type == "uint")
pvVars_.push_back(std::make_unique<UIntVar>(vname, varPSet));
else if (type == "float")
pvVars_.push_back(std::make_unique<FloatVar>(vname, varPSet));
else if (type == "double")
pvVars_.push_back(std::make_unique<DoubleVar>(vname, varPSet));
else if (type == "int8")
pvVars_.push_back(std::make_unique<Int8Var>(vname, varPSet));
else if (type == "uint8")
pvVars_.push_back(std::make_unique<UInt8Var>(vname, varPSet));
else if (type == "int16")
pvVars_.push_back(std::make_unique<Int16Var>(vname, varPSet));
else if (type == "uint16")
pvVars_.push_back(std::make_unique<UInt16Var>(vname, varPSet));
else if (type == "bool")
pvVars_.push_back(std::make_unique<BoolVar>(vname, varPSet));
else
throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
}
}

produces<nanoaod::FlatTable>("pv");
produces<nanoaod::FlatTable>("otherPVs");
produces<nanoaod::FlatTable>("svs");
Expand Down Expand Up @@ -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<float>(
"score", pvsScoreProd.get(pvsIn.id(), 0), "main primary vertex score, i.e. sum pt2 of clustered objects", 8);
std::vector<const reco::Vertex*> pvVec = {&(*pvsIn)[0]};
for (const auto& var : pvVars_)
var->fill(pvVec, *pvTable);

auto otherPVsTable =
std::make_unique<nanoaod::FlatTable>((*pvsIn).size() > 4 ? 3 : (*pvsIn).size() - 1, "Other" + pvName_, false);
Expand Down Expand Up @@ -219,6 +263,26 @@ void VertexTableProducer::fillDescriptions(edm::ConfigurationDescriptions& descr
desc.add<std::string>("svName")->setComment("name of the flat table ouput");
desc.add<std::string>("svDoc")->setComment("a few words of documentation");

// additional main vertex variables
edm::ParameterSetDescription variable;
variable.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
variable.add<std::string>("doc")->setComment("few words description of the branch content");
variable.ifValue(
edm::ParameterDescription<std::string>(
"type", "int", true, edm::Comment("the c++ type of the branch in the flat table")),
edm::allowedValues<std::string>("int", "uint", "float", "double", "int8", "uint8", "int16", "uint16", "bool"));
variable.addOptionalNode(
edm::ParameterDescription<int>(
"precision", true, edm::Comment("the precision with which to store the value in the flat table")) xor
edm::ParameterDescription<std::string>(
"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::ParameterSetDescription>("*", edm::RequireZeroOrMore, true, variable));
desc.addOptional<edm::ParameterSetDescription>("optionalPvVariables", variables)
->setComment("Optional variables of the main primary vertex");

descriptions.addWithDefaultLabel(desc);
}

Expand Down
33 changes: 31 additions & 2 deletions PhysicsTools/NanoAOD/python/vertices_cff.py
Original file line number Diff line number Diff line change
@@ -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 ##########################
Expand Down Expand Up @@ -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 )

0 comments on commit 7b6d0be

Please sign in to comment.