CMS 3D CMS Logo

VertexTableProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: VertexTableProducer
5 //
13 //
14 // Original Author: Andrea Rizzi
15 // Created: Mon, 28 Aug 2017 09:26:39 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
34 
36 
43 
44 //
45 // class declaration
46 //
47 
49 public:
50  explicit VertexTableProducer(const edm::ParameterSet&);
51  ~VertexTableProducer() override;
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55 private:
56  void beginStream(edm::StreamID) override;
57  void produce(edm::Event&, const edm::EventSetup&) override;
58  void endStream() override;
59 
60  //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
61  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
62  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
63  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
64 
65  // ----------member data ---------------------------
66 
76  const double dlenMin_, dlenSigMin_;
77 };
78 
79 //
80 // constructors and destructor
81 //
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 }
101 
103  // do anything here that needs to be done at destruction time
104  // (e.g. close files, deallocate resources etc.)
105 }
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called to produce the data ------------
112 
114  using namespace edm;
117  iEvent.getByToken(pvs_, pvsIn);
118  iEvent.getByToken(pvsScore_, pvsScoreIn);
119  auto pvTable = std::make_unique<nanoaod::FlatTable>(1, pvName_, true);
120  pvTable->addColumnValue<float>("ndof", (*pvsIn)[0].ndof(), "main primary vertex number of degree of freedom", 8);
121  pvTable->addColumnValue<float>("x", (*pvsIn)[0].position().x(), "main primary vertex position x coordinate", 10);
122  pvTable->addColumnValue<float>("y", (*pvsIn)[0].position().y(), "main primary vertex position y coordinate", 10);
123  pvTable->addColumnValue<float>("z", (*pvsIn)[0].position().z(), "main primary vertex position z coordinate", 16);
124  pvTable->addColumnValue<float>("chi2", (*pvsIn)[0].normalizedChi2(), "main primary vertex reduced chi2", 8);
125  int goodPVs = 0;
126  for (const auto& pv : *pvsIn)
127  if (goodPvCut_(pv))
128  goodPVs++;
129  pvTable->addColumnValue<int>("npvs", pvsIn->size(), "total number of reconstructed primary vertices");
130  pvTable->addColumnValue<int>(
131  "npvsGood", goodPVs, "number of good reconstructed primary vertices. selection:" + goodPvCutString_);
132  pvTable->addColumnValue<float>(
133  "score", pvsScoreIn->get(pvsIn.id(), 0), "main primary vertex score, i.e. sum pt2 of clustered objects", 8);
134 
135  auto otherPVsTable =
136  std::make_unique<nanoaod::FlatTable>((*pvsIn).size() > 4 ? 3 : (*pvsIn).size() - 1, "Other" + pvName_, false);
137  std::vector<float> pvsz;
138  for (size_t i = 1; i < (*pvsIn).size() && i < 4; i++)
139  pvsz.push_back((*pvsIn)[i - 1].position().z());
140  otherPVsTable->addColumn<float>("z", pvsz, "Z position of other primary vertices, excluding the main PV", 8);
141 
143  iEvent.getByToken(svs_, svsIn);
144  auto selCandSv = std::make_unique<PtrVector<reco::Candidate>>();
145  std::vector<float> dlen, dlenSig, pAngle, dxy, dxySig;
146  std::vector<int> charge;
147  VertexDistance3D vdist;
148  VertexDistanceXY vdistXY;
149 
150  size_t i = 0;
151  const auto& PV0 = pvsIn->front();
152  for (const auto& sv : *svsIn) {
153  if (svCut_(sv)) {
154  Measurement1D dl =
155  vdist.distance(PV0, VertexState(RecoVertex::convertPos(sv.position()), RecoVertex::convertError(sv.error())));
156  if (dl.value() > dlenMin_ and dl.significance() > dlenSigMin_) {
157  dlen.push_back(dl.value());
158  dlenSig.push_back(dl.significance());
159  edm::Ptr<reco::Candidate> c = svsIn->ptrAt(i);
160  selCandSv->push_back(c);
161  double dx = (PV0.x() - sv.vx()), dy = (PV0.y() - sv.vy()), dz = (PV0.z() - sv.vz());
162  double pdotv = (dx * sv.px() + dy * sv.py() + dz * sv.pz()) / sv.p() / sqrt(dx * dx + dy * dy + dz * dz);
163  pAngle.push_back(std::acos(pdotv));
164  Measurement1D d2d = vdistXY.distance(
165  PV0, VertexState(RecoVertex::convertPos(sv.position()), RecoVertex::convertError(sv.error())));
166  dxy.push_back(d2d.value());
167  dxySig.push_back(d2d.significance());
168 
169  int sum_charge = 0;
170  for (unsigned int id = 0; id < sv.numberOfDaughters(); ++id) {
171  const reco::Candidate* daughter = sv.daughter(id);
172  sum_charge += daughter->charge();
173  }
174  charge.push_back(sum_charge);
175  }
176  }
177  i++;
178  }
179 
180  auto svsTable = std::make_unique<nanoaod::FlatTable>(selCandSv->size(), svName_, false);
181  // For SV we fill from here only stuff that cannot be created with the SimpleFlatTableProducer
182  svsTable->addColumn<float>("dlen", dlen, "decay length in cm", 10);
183  svsTable->addColumn<float>("dlenSig", dlenSig, "decay length significance", 10);
184  svsTable->addColumn<float>("dxy", dxy, "2D decay length in cm", 10);
185  svsTable->addColumn<float>("dxySig", dxySig, "2D decay length significance", 10);
186  svsTable->addColumn<float>("pAngle", pAngle, "pointing angle, i.e. acos(p_SV * (SV - PV)) ", 10);
187  svsTable->addColumn<int>("charge", charge, "sum of the charge of the SV tracks", 10);
188 
189  iEvent.put(std::move(pvTable), "pv");
190  iEvent.put(std::move(otherPVsTable), "otherPVs");
191  iEvent.put(std::move(svsTable), "svs");
192  iEvent.put(std::move(selCandSv));
193 }
194 
195 // ------------ method called once each stream before processing any runs, lumis or events ------------
197 
198 // ------------ method called once each stream after processing all runs, lumis and events ------------
200 
201 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
203  //The following says we do not know what parameters are allowed so do no validation
204  // Please change this to state exactly what you do use, even if it is no parameters
206  desc.setUnknown();
207  descriptions.addDefault(desc);
208 }
209 
210 //define this as a plug-in
edm::StreamID
Definition: StreamID.h:30
VertexTableProducer::goodPvCut_
const StringCutObjectSelector< reco::Vertex > goodPvCut_
Definition: VertexTableProducer.cc:71
Measurement1D
Definition: Measurement1D.h:11
mps_fire.i
i
Definition: mps_fire.py:428
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
sistrip::View
View
Definition: ConstantsForView.h:26
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Measurement1D::value
double value() const
Definition: Measurement1D.h:25
VertexTableProducer::VertexTableProducer
VertexTableProducer(const edm::ParameterSet &)
Definition: VertexTableProducer.cc:82
VertexDistance3D::distance
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
Definition: VertexDistance3D.cc:17
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
VertexTableProducer::pvs_
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvs_
Definition: VertexTableProducer.cc:67
EDProducer.h
VertexTableProducer::svCut_
const StringCutObjectSelector< reco::Candidate > svCut_
Definition: VertexTableProducer.cc:70
ConvertToFromReco.h
VertexDistance3D.h
VertexTableProducer::svs_
const edm::EDGetTokenT< edm::View< reco::VertexCompositePtrCandidate > > svs_
Definition: VertexTableProducer.cc:69
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::Handle
Definition: AssociativeIterator.h:50
VertexTableProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: VertexTableProducer.cc:202
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
VertexDistanceXY.h
VertexTableProducer::beginStream
void beginStream(edm::StreamID) override
Definition: VertexTableProducer.cc:196
reco::Candidate::charge
virtual int charge() const =0
electric charge
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:352
VertexCompositePtrCandidate.h
VertexState.h
VertexDistance3D
Definition: VertexDistance3D.h:13
VertexTableProducer::dlenSigMin_
const double dlenSigMin_
Definition: VertexTableProducer.cc:76
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
VertexTableProducer::~VertexTableProducer
~VertexTableProducer() override
Definition: VertexTableProducer.cc:102
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
VertexTableProducer::svName_
const std::string svName_
Definition: VertexTableProducer.cc:74
funct::true
true
Definition: Factorize.h:173
Measurement1D::significance
double significance() const
Definition: Measurement1D.h:29
edm::ParameterSet
Definition: ParameterSet.h:47
RecoVertex::convertError
reco::Vertex::Error convertError(const GlobalError &ge)
Definition: ConvertError.h:8
Event.h
VertexTableProducer::pvName_
const std::string pvName_
Definition: VertexTableProducer.cc:73
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::stream::EDProducer
Definition: EDProducer.h:36
PVValHelper::dy
Definition: PVValidationHelpers.h:50
edm::EventSetup
Definition: EventSetup.h:58
VertexDistanceXY
Definition: VertexDistanceXY.h:11
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
VertexTableProducer::dlenMin_
const double dlenMin_
Definition: VertexTableProducer.cc:76
VertexTableProducer::endStream
void endStream() override
Definition: VertexTableProducer.cc:199
FlatTable.h
edm::Ptr< reco::Candidate >
reco::Candidate
Definition: Candidate.h:27
ValueMap.h
VertexTableProducer::goodPvCutString_
const std::string goodPvCutString_
Definition: VertexTableProducer.cc:72
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
AlcaRecoSelection_cff.goodPVs
goodPVs
Good Primary Vertex Selection.
Definition: AlcaRecoSelection_cff.py:54
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
StringCutObjectSelector.h
HltBtagValidation_cff.Vertex
Vertex
Definition: HltBtagValidation_cff.py:32
VertexDistanceXY::distance
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
Definition: VertexDistanceXY.cc:19
PVValHelper::dxy
Definition: PVValidationHelpers.h:48
Vertex.h
PVValHelper::dz
Definition: PVValidationHelpers.h:51
Frameworkfwd.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
VertexState
Definition: VertexState.h:13
StringCutObjectSelector< reco::Candidate >
RecoVertex::convertPos
reco::Vertex::Point convertPos(const GlobalPoint &p)
Definition: ConvertToFromReco.h:7
ParameterSet.h
VertexTableProducer::pvsScore_
const edm::EDGetTokenT< edm::ValueMap< float > > pvsScore_
Definition: VertexTableProducer.cc:68
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
StreamID.h
VertexTableProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: VertexTableProducer.cc:113
PVValHelper::dx
Definition: PVValidationHelpers.h:49
VertexTableProducer::svDoc_
const std::string svDoc_
Definition: VertexTableProducer.cc:75
VertexTableProducer
Definition: VertexTableProducer.cc:48