CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
VertexTableProducer Class Reference

#include <PhysicsTools/VertexTableProducer/plugins/VertexTableProducer.cc>

Inheritance diagram for VertexTableProducer:
edm::stream::EDProducer<>

Public Member Functions

 VertexTableProducer (const edm::ParameterSet &)
 
 ~VertexTableProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void beginStream (edm::StreamID) override
 
void endStream () override
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

const double dlenMin_
 
const double dlenSigMin_
 
const StringCutObjectSelector< reco::VertexgoodPvCut_
 
const std::string goodPvCutString_
 
const std::string pvName_
 
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvs_
 
const edm::EDGetTokenT< edm::ValueMap< float > > pvsScore_
 
const StringCutObjectSelector< reco::CandidatesvCut_
 
const std::string svDoc_
 
const std::string svName_
 
const edm::EDGetTokenT< edm::View< reco::VertexCompositePtrCandidate > > svs_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 48 of file VertexTableProducer.cc.

Constructor & Destructor Documentation

◆ VertexTableProducer()

VertexTableProducer::VertexTableProducer ( const edm::ParameterSet params)
explicit

Definition at line 82 of file VertexTableProducer.cc.

83  : pvs_(consumes<std::vector<reco::Vertex>>(params.getParameter<edm::InputTag>("pvSrc"))),
84  pvsScore_(consumes<edm::ValueMap<float>>(params.getParameter<edm::InputTag>("pvSrc"))),
85  svs_(consumes<edm::View<reco::VertexCompositePtrCandidate>>(params.getParameter<edm::InputTag>("svSrc"))),
86  svCut_(params.getParameter<std::string>("svCut"), true),
87  goodPvCut_(params.getParameter<std::string>("goodPvCut"), true),
88  goodPvCutString_(params.getParameter<std::string>("goodPvCut")),
89  pvName_(params.getParameter<std::string>("pvName")),
90  svName_(params.getParameter<std::string>("svName")),
91  svDoc_(params.getParameter<std::string>("svDoc")),
92  dlenMin_(params.getParameter<double>("dlenMin")),
93  dlenSigMin_(params.getParameter<double>("dlenSigMin"))
94 
95 {
96  produces<nanoaod::FlatTable>("pv");
97  produces<nanoaod::FlatTable>("otherPVs");
98  produces<nanoaod::FlatTable>("svs");
99  produces<edm::PtrVector<reco::Candidate>>();
100 }
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvs_
const std::string pvName_
const std::string svDoc_
const edm::EDGetTokenT< edm::ValueMap< float > > pvsScore_
const std::string goodPvCutString_
const edm::EDGetTokenT< edm::View< reco::VertexCompositePtrCandidate > > svs_
const std::string svName_
const StringCutObjectSelector< reco::Vertex > goodPvCut_
const StringCutObjectSelector< reco::Candidate > svCut_

◆ ~VertexTableProducer()

VertexTableProducer::~VertexTableProducer ( )
override

Definition at line 102 of file VertexTableProducer.cc.

102  {
103  // do anything here that needs to be done at destruction time
104  // (e.g. close files, deallocate resources etc.)
105 }

Member Function Documentation

◆ beginStream()

void VertexTableProducer::beginStream ( edm::StreamID  )
overrideprivate

Definition at line 199 of file VertexTableProducer.cc.

199 {}

◆ endStream()

void VertexTableProducer::endStream ( )
overrideprivate

Definition at line 202 of file VertexTableProducer.cc.

202 {}

◆ fillDescriptions()

void VertexTableProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 205 of file VertexTableProducer.cc.

References edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, and AlCaHLTBitMon_QueryRunRegistry::string.

205  {
207 
208  desc.add<edm::InputTag>("pvSrc")->setComment(
209  "std::vector<reco::Vertex> and ValueMap<float> primary vertex input collections");
210  desc.add<std::string>("goodPvCut")->setComment("selection on the primary vertex");
211  desc.add<edm::InputTag>("svSrc")->setComment(
212  "reco::VertexCompositePtrCandidate compatible secondary vertex input collection");
213  desc.add<std::string>("svCut")->setComment("selection on the secondary vertex");
214 
215  desc.add<double>("dlenMin")->setComment("minimum value of dl to select secondary vertex");
216  desc.add<double>("dlenSigMin")->setComment("minimum value of dl significance to select secondary vertex");
217 
218  desc.add<std::string>("pvName")->setComment("name of the flat table ouput");
219  desc.add<std::string>("svName")->setComment("name of the flat table ouput");
220  desc.add<std::string>("svDoc")->setComment("a few words of documentation");
221 
222  descriptions.addWithDefaultLabel(desc);
223 }
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)

◆ produce()

void VertexTableProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 113 of file VertexTableProducer.cc.

References HltBtagPostValidation_cff::c, ALCARECOTkAlJpsiMuMu_cff::charge, reco::Candidate::charge(), RecoVertex::convertError(), RecoVertex::convertPos(), VertexDistanceXY::distance(), VertexDistance3D::distance(), dlenMin_, dlenSigMin_, PVValHelper::dx, PVValHelper::dxy, PVValHelper::dy, PVValHelper::dz, goodPvCut_, goodPvCutString_, AlcaRecoSelection_cff::goodPVs, mps_fire::i, l1ctLayer2EG_cff::id, iEvent, eostools::move(), position, pvName_, pvs_, pvsScore_, Measurement1D::significance(), mathSSE::sqrt(), pfDeepBoostedJetPreprocessParams_cfi::sv, svCut_, svDoc_, svName_, svs_, Measurement1D::value(), and z.

113  {
114  using namespace edm;
115  const auto& pvsScoreProd = iEvent.get(pvsScore_);
116  auto pvsIn = iEvent.getHandle(pvs_);
117 
118  auto pvTable = std::make_unique<nanoaod::FlatTable>(1, pvName_, true);
119  pvTable->addColumnValue<float>("ndof", (*pvsIn)[0].ndof(), "main primary vertex number of degree of freedom", 8);
120  pvTable->addColumnValue<float>("x", (*pvsIn)[0].position().x(), "main primary vertex position x coordinate", 10);
121  pvTable->addColumnValue<float>("y", (*pvsIn)[0].position().y(), "main primary vertex position y coordinate", 10);
122  pvTable->addColumnValue<float>("z", (*pvsIn)[0].position().z(), "main primary vertex position z coordinate", 16);
123  pvTable->addColumnValue<float>("chi2", (*pvsIn)[0].normalizedChi2(), "main primary vertex reduced chi2", 8);
124  int goodPVs = 0;
125  for (const auto& pv : *pvsIn)
126  if (goodPvCut_(pv))
127  goodPVs++;
128  pvTable->addColumnValue<uint8_t>("npvs", pvsIn->size(), "total number of reconstructed primary vertices");
129  pvTable->addColumnValue<uint8_t>(
130  "npvsGood", goodPVs, "number of good reconstructed primary vertices. selection:" + goodPvCutString_);
131  pvTable->addColumnValue<float>(
132  "score", pvsScoreProd.get(pvsIn.id(), 0), "main primary vertex score, i.e. sum pt2 of clustered objects", 8);
133 
134  auto otherPVsTable =
135  std::make_unique<nanoaod::FlatTable>((*pvsIn).size() > 4 ? 3 : (*pvsIn).size() - 1, "Other" + pvName_, false);
136  std::vector<float> pvsz;
137  std::vector<float> pvscores;
138  for (size_t i = 1; i < (*pvsIn).size() && i < 4; i++) {
139  pvsz.push_back((*pvsIn)[i].position().z());
140  pvscores.push_back(pvsScoreProd.get(pvsIn.id(), i));
141  }
142  otherPVsTable->addColumn<float>("z", pvsz, "Z position of other primary vertices, excluding the main PV", 8);
143  otherPVsTable->addColumn<float>("score", pvscores, "scores of other primary vertices, excluding the main PV", 8);
144 
145  const auto& svsProd = iEvent.get(svs_);
146  auto selCandSv = std::make_unique<PtrVector<reco::Candidate>>();
147  std::vector<float> dlen, dlenSig, pAngle, dxy, dxySig;
148  std::vector<int16_t> charge;
149  VertexDistance3D vdist;
150  VertexDistanceXY vdistXY;
151 
152  size_t i = 0;
153  const auto& PV0 = pvsIn->front();
154  for (const auto& sv : svsProd) {
155  if (svCut_(sv)) {
156  Measurement1D dl =
157  vdist.distance(PV0, VertexState(RecoVertex::convertPos(sv.position()), RecoVertex::convertError(sv.error())));
158  if (dl.value() > dlenMin_ and dl.significance() > dlenSigMin_) {
159  dlen.push_back(dl.value());
160  dlenSig.push_back(dl.significance());
161  edm::Ptr<reco::Candidate> c = svsProd.ptrAt(i);
162  selCandSv->push_back(c);
163  double dx = (PV0.x() - sv.vx()), dy = (PV0.y() - sv.vy()), dz = (PV0.z() - sv.vz());
164  double pdotv = (dx * sv.px() + dy * sv.py() + dz * sv.pz()) / sv.p() / sqrt(dx * dx + dy * dy + dz * dz);
165  pAngle.push_back(std::acos(pdotv));
166  Measurement1D d2d = vdistXY.distance(
167  PV0, VertexState(RecoVertex::convertPos(sv.position()), RecoVertex::convertError(sv.error())));
168  dxy.push_back(d2d.value());
169  dxySig.push_back(d2d.significance());
170 
171  int sum_charge = 0;
172  for (unsigned int id = 0; id < sv.numberOfDaughters(); ++id) {
173  const reco::Candidate* daughter = sv.daughter(id);
174  sum_charge += daughter->charge();
175  }
176  charge.push_back(sum_charge);
177  }
178  }
179  i++;
180  }
181 
182  auto svsTable = std::make_unique<nanoaod::FlatTable>(selCandSv->size(), svName_, false);
183  svsTable->setDoc(svDoc_);
184  // For SV we fill from here only stuff that cannot be created with the SimpleFlatTableProducer
185  svsTable->addColumn<float>("dlen", dlen, "decay length in cm", 10);
186  svsTable->addColumn<float>("dlenSig", dlenSig, "decay length significance", 10);
187  svsTable->addColumn<float>("dxy", dxy, "2D decay length in cm", 10);
188  svsTable->addColumn<float>("dxySig", dxySig, "2D decay length significance", 10);
189  svsTable->addColumn<float>("pAngle", pAngle, "pointing angle, i.e. acos(p_SV * (SV - PV)) ", 10);
190  svsTable->addColumn<int16_t>("charge", charge, "sum of the charge of the SV tracks", 10);
191 
192  iEvent.put(std::move(pvTable), "pv");
193  iEvent.put(std::move(otherPVsTable), "otherPVs");
194  iEvent.put(std::move(svsTable), "svs");
195  iEvent.put(std::move(selCandSv));
196 }
reco::Vertex::Point convertPos(const GlobalPoint &p)
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvs_
const std::string pvName_
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
const std::string svDoc_
reco::Vertex::Error convertError(const GlobalError &ge)
Definition: ConvertError.h:8
const edm::EDGetTokenT< edm::ValueMap< float > > pvsScore_
const std::string goodPvCutString_
int iEvent
Definition: GenABIO.cc:224
goodPVs
Good Primary Vertex Selection.
T sqrt(T t)
Definition: SSEVec.h:19
const edm::EDGetTokenT< edm::View< reco::VertexCompositePtrCandidate > > svs_
virtual int charge() const =0
electric charge
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
double value() const
Definition: Measurement1D.h:25
double significance() const
Definition: Measurement1D.h:29
const std::string svName_
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:289
const StringCutObjectSelector< reco::Vertex > goodPvCut_
const StringCutObjectSelector< reco::Candidate > svCut_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ dlenMin_

const double VertexTableProducer::dlenMin_
private

Definition at line 76 of file VertexTableProducer.cc.

Referenced by produce().

◆ dlenSigMin_

const double VertexTableProducer::dlenSigMin_
private

Definition at line 76 of file VertexTableProducer.cc.

Referenced by produce().

◆ goodPvCut_

const StringCutObjectSelector<reco::Vertex> VertexTableProducer::goodPvCut_
private

Definition at line 71 of file VertexTableProducer.cc.

Referenced by produce().

◆ goodPvCutString_

const std::string VertexTableProducer::goodPvCutString_
private

Definition at line 72 of file VertexTableProducer.cc.

Referenced by produce().

◆ pvName_

const std::string VertexTableProducer::pvName_
private

Definition at line 73 of file VertexTableProducer.cc.

Referenced by produce().

◆ pvs_

const edm::EDGetTokenT<std::vector<reco::Vertex> > VertexTableProducer::pvs_
private

Definition at line 67 of file VertexTableProducer.cc.

Referenced by produce().

◆ pvsScore_

const edm::EDGetTokenT<edm::ValueMap<float> > VertexTableProducer::pvsScore_
private

Definition at line 68 of file VertexTableProducer.cc.

Referenced by produce().

◆ svCut_

const StringCutObjectSelector<reco::Candidate> VertexTableProducer::svCut_
private

Definition at line 70 of file VertexTableProducer.cc.

Referenced by produce().

◆ svDoc_

const std::string VertexTableProducer::svDoc_
private

Definition at line 75 of file VertexTableProducer.cc.

Referenced by produce().

◆ svName_

const std::string VertexTableProducer::svName_
private

Definition at line 74 of file VertexTableProducer.cc.

Referenced by produce().

◆ svs_

const edm::EDGetTokenT<edm::View<reco::VertexCompositePtrCandidate> > VertexTableProducer::svs_
private

Definition at line 69 of file VertexTableProducer.cc.

Referenced by produce().