CMS 3D CMS Logo

MCvsRecoVerticesAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MCvsRecoVerticesAnalyzer
4 // Class: MCvsRecoVerticesAnalyzer
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Thu Dec 16 16:32:56 CEST 2010
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <numeric>
22 
23 #include <vector>
24 
25 // user include files
28 
32 
34 
36 
39 
41 
45 
48 
49 #include "TH1F.h"
50 #include "TH2F.h"
51 #include "TProfile.h"
52 
53 //
54 // class decleration
55 //
56 
57 class MCvsRecoVerticesAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
58 public:
60  ~MCvsRecoVerticesAnalyzer() override;
61 
62 private:
63  void analyze(const edm::Event&, const edm::EventSetup&) override;
64 
65  // ----------member data ---------------------------
66 
67  const bool m_useweight;
74 
84 
88 };
89 
90 //
91 // constants, enums and typedefs
92 //
93 
94 //
95 // static data member definitions
96 //
97 
98 //
99 // constructors and destructor
100 //
102  : m_useweight(iConfig.getParameter<bool>("useWeight")),
103  m_useVisibleVertices(iConfig.getParameter<bool>("useVisibleVertices")),
104  m_histoParameters(iConfig.getUntrackedParameter<edm::ParameterSet>("histoParameters", edm::ParameterSet())),
105  m_doubleToken(consumes<double>(iConfig.getParameter<edm::InputTag>("weightProduct"))),
106  m_vecPileupSummaryInfoToken(
107  consumes<std::vector<PileupSummaryInfo> >(iConfig.getParameter<edm::InputTag>("pileupSummaryCollection"))),
108  m_recoVertexCollectionToken(
109  consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("pvCollection"))),
110  m_hepMCProductToken(consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("mcTruthCollection"))) {
111  //now do what ever initialization is needed
112 
114  edm::LogInfo("UseVisibleVertices") << "Only visible vertices will be used to compute Npileup";
115 
116  usesResource("TFileService");
118 
119  m_hrecovsmcnvtx2d = tfserv->make<TH2F>(
120  "recovsmcnvtx2d", "Number of reco vertices vs pileup interactions", 60, -0.5, 59.5, 60, -0.5, 59.5);
121  m_hrecovsmcnvtx2d->GetXaxis()->SetTitle("Pileup Interactions");
122  m_hrecovsmcnvtx2d->GetYaxis()->SetTitle("Reco Vertices");
124  tfserv->make<TProfile>("recovsmcnvtxprof", "Mean number of reco vs pileup vertices", 60, -0.5, 59.5);
125  m_hrecovsmcnvtxprof->GetXaxis()->SetTitle("Pileup Interactions");
126  m_hrecovsmcnvtxprof->GetYaxis()->SetTitle("Reco Vertices");
127 
128  m_hrecovsmclumi2d = tfserv->make<TH2F>(
129  "recovsmclumi2d", "Number of reco vertices vs ave pileup interactions", 200, 0., 50., 60, -0.5, 59.5);
130  m_hrecovsmclumi2d->GetXaxis()->SetTitle("Average Pileup Interactions");
131  m_hrecovsmclumi2d->GetYaxis()->SetTitle("Reco Vertices");
133  tfserv->make<TProfile>("recovsmclumiprof", "Mean number of reco vs ave pileup vertices", 200, 0., 50.);
134  m_hrecovsmclumiprof->GetXaxis()->SetTitle("Average Pileup Interactions");
135  m_hrecovsmclumiprof->GetYaxis()->SetTitle("Reco Vertices");
136 
137  if (m_useweight) {
138  m_hrecovsmcnvtxweightedprof = tfserv->make<TProfile>(
139  "recovsmcnvtxweightedprof", "Mean number of reco vs pileup vertices (1-w) weight", 60, -0.5, 59.5);
140  m_hrecovsmcnvtxweightedprof->GetXaxis()->SetTitle("Pileup Interactions");
141  m_hrecovsmcnvtxweightedprof->GetYaxis()->SetTitle("Reco Vertices (1-w)");
142 
143  m_hrecovsmclumiweightedprof = tfserv->make<TProfile>(
144  "recovsmclumiweightedprof", "Mean number of reco vs ave pileup vertices (1-w) weight", 200, 0., 50.);
145  m_hrecovsmclumiweightedprof->GetXaxis()->SetTitle("Average Pileup Interactions");
146  m_hrecovsmclumiweightedprof->GetYaxis()->SetTitle("Reco Vertices (1-w)");
147  }
148 
149  m_hdeltazfirst = tfserv->make<TH1F>("deltazfirst",
150  "Reco-MC vertex z position (first vertex)",
151  m_histoParameters.getUntrackedParameter<unsigned int>("zBins", 1000),
152  m_histoParameters.getUntrackedParameter<double>("zMin", -1.),
153  m_histoParameters.getUntrackedParameter<double>("zMax", 1.));
154  m_hdeltazfirst->GetXaxis()->SetTitle("#Delta z (cm)");
155  m_hdeltazfirst->GetYaxis()->SetTitle("Events");
156 
157  m_hdeltazclose = tfserv->make<TH1F>("deltazclose",
158  "Reco-MC vertex z position (closest vertex)",
159  m_histoParameters.getUntrackedParameter<unsigned int>("zBins", 1000),
160  m_histoParameters.getUntrackedParameter<double>("zMin", -1.),
161  m_histoParameters.getUntrackedParameter<double>("zMax", 1.));
162  m_hdeltazclose->GetXaxis()->SetTitle("#Delta z (cm)");
163  m_hdeltazclose->GetYaxis()->SetTitle("Events");
164 
165  m_hclosestvtx = tfserv->make<TH1F>("closestvtx", "Closest reco vtx ID", 30, -0.5, 29.5);
166  m_hclosestvtx->GetXaxis()->SetTitle("Vtx ID");
167  m_hclosestvtx->GetYaxis()->SetTitle("Events");
168 
169  m_hdeltazfirstvsnpu = tfserv->make<TH2F>("deltazfirstvsnpu",
170  "Reco-MC vertex z position (first vertex) vs Npileup",
171  30,
172  -0.5,
173  29.5,
174  m_histoParameters.getUntrackedParameter<unsigned int>("zBins", 1000),
175  m_histoParameters.getUntrackedParameter<double>("zMin", -1.),
176  m_histoParameters.getUntrackedParameter<double>("zMax", 1.));
177  m_hdeltazfirstvsnpu->GetXaxis()->SetTitle("pileup Interactions");
178  m_hdeltazfirstvsnpu->GetYaxis()->SetTitle("#Delta z (cm)");
179 
180  m_hdeltazclosevsnpu = tfserv->make<TH2F>("deltazclosevsnpu",
181  "Reco-MC vertex z position (closest vertex) v Npileup",
182  30,
183  -0.5,
184  29.5,
185  m_histoParameters.getUntrackedParameter<unsigned int>("zBins", 1000),
186  m_histoParameters.getUntrackedParameter<double>("zMin", -1.),
187  m_histoParameters.getUntrackedParameter<double>("zMax", 1.));
188  m_hdeltazclosevsnpu->GetXaxis()->SetTitle("Pileup Interactions");
189  m_hdeltazclosevsnpu->GetYaxis()->SetTitle("#Delta z (cm)");
190 
192  tfserv->make<TH2F>("closestvtxvsnpu", "Closest reco vtx ID vs Npileup", 30, -0.5, 29.5, 30, -0.5, 29.5);
193  m_hclosestvtxvsnpu->GetXaxis()->SetTitle("Pileup Interactions");
194  m_hclosestvtxvsnpu->GetYaxis()->SetTitle("Vtx ID");
195 }
196 
198  // do anything here that needs to be done at desctruction time
199  // (e.g. close files, deallocate resources etc.)
200 }
201 
202 //
203 // member functions
204 //
205 
206 // ------------ method called to for each event ------------
208  double weight = 1.;
209 
210  if (m_useweight) {
211  edm::Handle<double> weightprod;
212  iEvent.getByToken(m_doubleToken, weightprod);
213 
214  weight = *weightprod;
215  }
216 
218  iEvent.getByToken(m_vecPileupSummaryInfoToken, pileupinfos);
219 
220  // look for the intime PileupSummaryInfo
221 
222  std::vector<PileupSummaryInfo>::const_iterator pileupinfo;
223 
224  for (pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end(); ++pileupinfo) {
225  if (pileupinfo->getBunchCrossing() == 0)
226  break;
227  }
228 
229  //
230 
232  iEvent.getByToken(m_recoVertexCollectionToken, pvcoll);
233 
234  //
235 
236  if (pileupinfo->getBunchCrossing() != 0) {
237  edm::LogError("NoInTimePileUpInfo") << "Cannot find the in-time pileup info " << pileupinfo->getBunchCrossing();
238 
239  } else {
240  int npileup = pileupinfo->getPU_NumInteractions();
241 
243  npileup = pileupinfo->getPU_zpositions().size();
244 
245  m_hrecovsmcnvtx2d->Fill(npileup, pvcoll->size(), weight);
246  m_hrecovsmcnvtxprof->Fill(npileup, pvcoll->size(), weight);
247 
248  m_hrecovsmclumi2d->Fill(pileupinfo->getTrueNumInteractions(), pvcoll->size(), weight);
249  m_hrecovsmclumiprof->Fill(pileupinfo->getTrueNumInteractions(), pvcoll->size(), weight);
250 
251  if (m_useweight) {
252  m_hrecovsmcnvtxweightedprof->Fill(npileup, pvcoll->size(), 1. - weight);
253  m_hrecovsmclumiweightedprof->Fill(pileupinfo->getTrueNumInteractions(), pvcoll->size(), 1. - weight);
254  }
255  //
256 
258  iEvent.getByToken(m_hepMCProductToken, EvtHandle);
259 
260  const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
261 
262  // compute the difference between the main interaction vertex z position and the first vertex of the collection
263 
264  if (!pvcoll->empty()) {
265  if (!(*pvcoll)[0].isFake()) {
266  // get the first vertex
267  if (Evt->vertices_begin() != Evt->vertices_end()) {
268  m_hdeltazfirst->Fill((*pvcoll)[0].z() - (*Evt->vertices_begin())->point3d().z() / 10., weight);
269  m_hdeltazfirstvsnpu->Fill(npileup, (*pvcoll)[0].z() - (*Evt->vertices_begin())->point3d().z() / 10., weight);
270  }
271  }
272  }
273 
274  // compute the difference between the main interaction vertex z position and the closest reco vertex
275 
276  double minabsdist = -1.;
277  double mindist = -999.;
278  int closestvtx = -1;
279 
280  for (unsigned int ivtx = 0; ivtx < pvcoll->size(); ++ivtx) {
281  if (closestvtx < 0 ||
282  minabsdist > std::abs((*pvcoll)[ivtx].z() - (*Evt->vertices_begin())->point3d().z() / 10.)) {
283  mindist = (*pvcoll)[ivtx].z() - (*Evt->vertices_begin())->point3d().z() / 10.;
284  closestvtx = ivtx;
285  minabsdist = std::abs(mindist);
286  }
287  }
288  if (closestvtx >= 0) {
289  m_hdeltazclose->Fill(mindist, weight);
290  m_hdeltazclosevsnpu->Fill(npileup, mindist, weight);
291  m_hclosestvtx->Fill(closestvtx, weight);
292  m_hclosestvtxvsnpu->Fill(npileup, closestvtx, weight);
293  }
294  }
295 }
296 
297 //define this as a plug-in
MCvsRecoVerticesAnalyzer::m_hrecovsmclumi2d
TH2F * m_hrecovsmclumi2d
Definition: MCvsRecoVerticesAnalyzer.cc:78
PileupSummaryInfo.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
EDAnalyzer.h
MessageLogger.h
MCvsRecoVerticesAnalyzer::m_hepMCProductToken
edm::EDGetTokenT< edm::HepMCProduct > m_hepMCProductToken
Definition: MCvsRecoVerticesAnalyzer.cc:73
edm::EDGetTokenT< double >
edm
HLT enums.
Definition: AlignableModifier.h:19
mps_merge.weight
weight
Definition: mps_merge.py:88
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::LogInfo
Definition: MessageLogger.h:254
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
MCvsRecoVerticesAnalyzer::m_hdeltazfirst
TH1F * m_hdeltazfirst
Definition: MCvsRecoVerticesAnalyzer.cc:81
edm::Handle< double >
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
MCvsRecoVerticesAnalyzer::m_doubleToken
edm::EDGetTokenT< double > m_doubleToken
Definition: MCvsRecoVerticesAnalyzer.cc:70
MakerMacros.h
MCvsRecoVerticesAnalyzer
Definition: MCvsRecoVerticesAnalyzer.cc:57
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MCvsRecoVerticesAnalyzer::m_recoVertexCollectionToken
edm::EDGetTokenT< reco::VertexCollection > m_recoVertexCollectionToken
Definition: MCvsRecoVerticesAnalyzer.cc:72
MCvsRecoVerticesAnalyzer::m_hrecovsmcnvtx2d
TH2F * m_hrecovsmcnvtx2d
Definition: MCvsRecoVerticesAnalyzer.cc:75
MCvsRecoVerticesAnalyzer::m_hclosestvtxvsnpu
TH2F * m_hclosestvtxvsnpu
Definition: MCvsRecoVerticesAnalyzer.cc:87
MCvsRecoVerticesAnalyzer::MCvsRecoVerticesAnalyzer
MCvsRecoVerticesAnalyzer(const edm::ParameterSet &)
Definition: MCvsRecoVerticesAnalyzer.cc:101
Service.h
DDAxes::z
Run.h
MCvsRecoVerticesAnalyzer::m_hrecovsmclumiprof
TProfile * m_hrecovsmclumiprof
Definition: MCvsRecoVerticesAnalyzer.cc:79
MCvsRecoVerticesAnalyzer::m_hrecovsmcnvtxprof
TProfile * m_hrecovsmcnvtxprof
Definition: MCvsRecoVerticesAnalyzer.cc:76
MCvsRecoVerticesAnalyzer::~MCvsRecoVerticesAnalyzer
~MCvsRecoVerticesAnalyzer() override
Definition: MCvsRecoVerticesAnalyzer.cc:197
MCvsRecoVerticesAnalyzer::m_hrecovsmclumiweightedprof
TProfile * m_hrecovsmclumiweightedprof
Definition: MCvsRecoVerticesAnalyzer.cc:80
Vertex.h
MCvsRecoVerticesAnalyzer::m_useweight
const bool m_useweight
Definition: MCvsRecoVerticesAnalyzer.cc:67
TFileService.h
MCvsRecoVerticesAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: MCvsRecoVerticesAnalyzer.cc:207
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
MCvsRecoVerticesAnalyzer::m_histoParameters
const edm::ParameterSet m_histoParameters
Definition: MCvsRecoVerticesAnalyzer.cc:69
edm::LogError
Definition: MessageLogger.h:183
GenEventInfoProduct.h
Event.h
ParameterSet
Definition: Functions.h:16
MCvsRecoVerticesAnalyzer::m_hdeltazclose
TH1F * m_hdeltazclose
Definition: MCvsRecoVerticesAnalyzer.cc:82
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
InputTag.h
VertexFwd.h
MCvsRecoVerticesAnalyzer::m_hdeltazclosevsnpu
TH2F * m_hdeltazclosevsnpu
Definition: MCvsRecoVerticesAnalyzer.cc:86
std
Definition: JetResolutionObject.h:76
MCvsRecoVerticesAnalyzer::m_useVisibleVertices
const bool m_useVisibleVertices
Definition: MCvsRecoVerticesAnalyzer.cc:68
Frameworkfwd.h
MCvsRecoVerticesAnalyzer::m_hclosestvtx
TH1F * m_hclosestvtx
Definition: MCvsRecoVerticesAnalyzer.cc:83
MCvsRecoVerticesAnalyzer::m_hdeltazfirstvsnpu
TH2F * m_hdeltazfirstvsnpu
Definition: MCvsRecoVerticesAnalyzer.cc:85
MCvsRecoVerticesAnalyzer::m_vecPileupSummaryInfoToken
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken
Definition: MCvsRecoVerticesAnalyzer.cc:71
HepMCProduct
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
MCvsRecoVerticesAnalyzer::m_hrecovsmcnvtxweightedprof
TProfile * m_hrecovsmcnvtxweightedprof
Definition: MCvsRecoVerticesAnalyzer.cc:77
HepMCProduct.h
edm::Event
Definition: Event.h:73
weight
Definition: weight.py:1
PileupSummaryInfo
Definition: PileupSummaryInfo.h:22
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64