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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
32 
35 
37 
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 
81 
82 //
83 // constructors and destructor
84 //
86  pvs_(consumes<std::vector<reco::Vertex>>( params.getParameter<edm::InputTag>("pvSrc") )),
87  pvsScore_(consumes<edm::ValueMap<float>>( params.getParameter<edm::InputTag>("pvSrc") )),
88  svs_(consumes<edm::View<reco::VertexCompositePtrCandidate> >( params.getParameter<edm::InputTag>("svSrc") )),
89  svCut_(params.getParameter<std::string>("svCut") , true),
90  goodPvCut_(params.getParameter<std::string>("goodPvCut") , true),
91  goodPvCutString_(params.getParameter<std::string>("goodPvCut") ),
92  pvName_(params.getParameter<std::string>("pvName") ),
93  svName_(params.getParameter<std::string>("svName") ),
94  svDoc_(params.getParameter<std::string>("svDoc") ),
95  dlenMin_(params.getParameter<double>("dlenMin") ),
96  dlenSigMin_(params.getParameter<double>("dlenSigMin") )
97 
98 {
99  produces<nanoaod::FlatTable>("pv");
100  produces<nanoaod::FlatTable>("otherPVs");
101  produces<nanoaod::FlatTable>("svs");
102  produces<edm::PtrVector<reco::Candidate> >();
103 
104 }
105 
106 
108 {
109 
110  // do anything here that needs to be done at destruction time
111  // (e.g. close files, deallocate resources etc.)
112 
113 }
114 
115 
116 //
117 // member functions
118 //
119 
120 // ------------ method called to produce the data ------------
121 
122 
123 void
125 {
126  using namespace edm;
129  iEvent.getByToken(pvs_, pvsIn);
130  iEvent.getByToken(pvsScore_, pvsScoreIn);
131  auto pvTable = std::make_unique<nanoaod::FlatTable>(1,pvName_,true);
132  pvTable->addColumnValue<float>("ndof",(*pvsIn)[0].ndof(),"main primary vertex number of degree of freedom",nanoaod::FlatTable::FloatColumn,8);
133  pvTable->addColumnValue<float>("x",(*pvsIn)[0].position().x(),"main primary vertex position x coordinate",nanoaod::FlatTable::FloatColumn,10);
134  pvTable->addColumnValue<float>("y",(*pvsIn)[0].position().y(),"main primary vertex position y coordinate",nanoaod::FlatTable::FloatColumn,10);
135  pvTable->addColumnValue<float>("z",(*pvsIn)[0].position().z(),"main primary vertex position z coordinate",nanoaod::FlatTable::FloatColumn,16);
136  pvTable->addColumnValue<float>("chi2",(*pvsIn)[0].normalizedChi2(),"main primary vertex reduced chi2",nanoaod::FlatTable::FloatColumn,8);
137  int goodPVs=0;
138  for (const auto & pv : *pvsIn) if (goodPvCut_(pv)) goodPVs++;
139  pvTable->addColumnValue<int>("npvs",(*pvsIn).size(),"total number of reconstructed primary vertices",nanoaod::FlatTable::IntColumn);
140  pvTable->addColumnValue<int>("npvsGood",goodPVs,"number of good reconstructed primary vertices. selection:"+goodPvCutString_,nanoaod::FlatTable::IntColumn);
141  pvTable->addColumnValue<float>("score",(*pvsScoreIn).get(pvsIn.id(),0),"main primary vertex score, i.e. sum pt2 of clustered objects",nanoaod::FlatTable::FloatColumn,8);
142 
143  auto otherPVsTable = std::make_unique<nanoaod::FlatTable>((*pvsIn).size() >4?3:(*pvsIn).size()-1,"Other"+pvName_,false);
144  std::vector<float> pvsz;
145  for(size_t i=1;i < (*pvsIn).size() && i < 4; i++) pvsz.push_back((*pvsIn)[i-1].position().z());
146  otherPVsTable->addColumn<float>("z",pvsz,"Z position of other primary vertices, excluding the main PV",nanoaod::FlatTable::FloatColumn,8);
147 
148 
150  iEvent.getByToken(svs_, svsIn);
151  auto selCandSv = std::make_unique<PtrVector<reco::Candidate>>();
152  std::vector<float> dlen,dlenSig,pAngle;
153  VertexDistance3D vdist;
154 
155  size_t i=0;
156  const auto & PV0 = pvsIn->front();
157  for (const auto & sv : *svsIn) {
158  if (svCut_(sv)) {
160  if(dl.value() > dlenMin_ and dl.significance() > dlenSigMin_){
161  dlen.push_back(dl.value());
162  dlenSig.push_back(dl.significance());
163  edm::Ptr<reco::Candidate> c = svsIn->ptrAt(i);
164  selCandSv->push_back(c);
165  double dx = (PV0.x() - sv.vx()), dy = (PV0.y() - sv.vy()), dz = (PV0.z() - sv.vz());
166  double pdotv = (dx * sv.px() + dy*sv.py() + dz*sv.pz())/sv.p();
167  pAngle.push_back(std::acos(pdotv));
168  }
169  }
170  i++;
171  }
172 
173 
174  auto svsTable = std::make_unique<nanoaod::FlatTable>(selCandSv->size(),svName_,false);
175  // For SV we fill from here only stuff that cannot be created with the SimpleFlatTableProducer
176  svsTable->addColumn<float>("dlen",dlen,"decay length in cm",nanoaod::FlatTable::FloatColumn,10);
177  svsTable->addColumn<float>("dlenSig",dlenSig,"decay length significance",nanoaod::FlatTable::FloatColumn, 10);
178  svsTable->addColumn<float>("pAngle",pAngle,"pointing angle, i.e. acos(p_SV * (SV - PV)) ",nanoaod::FlatTable::FloatColumn,10);
179 
180 
181  iEvent.put(std::move(pvTable),"pv");
182  iEvent.put(std::move(otherPVsTable),"otherPVs");
183  iEvent.put(std::move(svsTable),"svs");
184  iEvent.put(std::move(selCandSv));
185 }
186 
187 // ------------ method called once each stream before processing any runs, lumis or events ------------
188 void
190 {
191 }
192 
193 // ------------ method called once each stream after processing all runs, lumis and events ------------
194 void
196 }
197 
198 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
199 void
201  //The following says we do not know what parameters are allowed so do no validation
202  // Please change this to state exactly what you do use, even if it is no parameters
204  desc.setUnknown();
205  descriptions.addDefault(desc);
206 }
207 
208 //define this as a plug-in
reco::Vertex::Point convertPos(const GlobalPoint &p)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvs_
const std::string pvName_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
const std::string svDoc_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
reco::Vertex::Error convertError(const GlobalError &ge)
Definition: ConvertError.h:8
const edm::EDGetTokenT< edm::ValueMap< float > > pvsScore_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const std::string goodPvCutString_
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
int iEvent
Definition: GenABIO.cc:230
goodPVs
Good Primary Vertex Selection.
void addDefault(ParameterSetDescription const &psetDescription)
VertexTableProducer(const edm::ParameterSet &)
const edm::EDGetTokenT< edm::View< reco::VertexCompositePtrCandidate > > svs_
def pv(vc)
Definition: MetAnalyzer.py:6
double significance() const
Definition: Measurement1D.h:32
void produce(edm::Event &, const edm::EventSetup &) override
double value() const
Definition: Measurement1D.h:28
fixed size matrix
const std::string svName_
HLT enums.
void beginStream(edm::StreamID) override
const StringCutObjectSelector< reco::Vertex > goodPvCut_
const StringCutObjectSelector< reco::Candidate > svCut_
def move(src, dest)
Definition: eostools.py:510