CMS 3D CMS Logo

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

#include <TrackingPFG/PileUp/src/MCvsRecoVerticesAnalyzer.cc>

Inheritance diagram for MCvsRecoVerticesAnalyzer:
edm::one::EDAnalyzer< edm::one::SharedResources > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 MCvsRecoVerticesAnalyzer (const edm::ParameterSet &)
 
 ~MCvsRecoVerticesAnalyzer () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::SharedResources >
 EDAnalyzer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 

Private Attributes

edm::EDGetTokenT< double > m_doubleToken
 
TH1F * m_hclosestvtx
 
TH2F * m_hclosestvtxvsnpu
 
TH1F * m_hdeltazclose
 
TH2F * m_hdeltazclosevsnpu
 
TH1F * m_hdeltazfirst
 
TH2F * m_hdeltazfirstvsnpu
 
edm::EDGetTokenT< edm::HepMCProductm_hepMCProductToken
 
const edm::ParameterSet m_histoParameters
 
TH2F * m_hrecovsmclumi2d
 
TProfile * m_hrecovsmclumiprof
 
TProfile * m_hrecovsmclumiweightedprof
 
TH2F * m_hrecovsmcnvtx2d
 
TProfile * m_hrecovsmcnvtxprof
 
TProfile * m_hrecovsmcnvtxweightedprof
 
edm::EDGetTokenT< reco::VertexCollectionm_recoVertexCollectionToken
 
const bool m_useVisibleVertices
 
const bool m_useweight
 
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 57 of file MCvsRecoVerticesAnalyzer.cc.

Constructor & Destructor Documentation

MCvsRecoVerticesAnalyzer::MCvsRecoVerticesAnalyzer ( const edm::ParameterSet iConfig)
explicit

Definition at line 101 of file MCvsRecoVerticesAnalyzer.cc.

References edm::ParameterSet::getUntrackedParameter(), m_hclosestvtx, m_hclosestvtxvsnpu, m_hdeltazclose, m_hdeltazclosevsnpu, m_hdeltazfirst, m_hdeltazfirstvsnpu, m_histoParameters, m_hrecovsmclumi2d, m_hrecovsmclumiprof, m_hrecovsmclumiweightedprof, m_hrecovsmcnvtx2d, m_hrecovsmcnvtxprof, m_hrecovsmcnvtxweightedprof, m_useVisibleVertices, m_useweight, and TFileService::make().

102  : m_useweight(iConfig.getParameter<bool>("useWeight")),
103  m_useVisibleVertices(iConfig.getParameter<bool>("useVisibleVertices")),
105  m_doubleToken(consumes<double>(iConfig.getParameter<edm::InputTag>("weightProduct"))),
107  consumes<std::vector<PileupSummaryInfo> >(iConfig.getParameter<edm::InputTag>("pileupSummaryCollection"))),
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 }
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::HepMCProduct > m_hepMCProductToken
T getUntrackedParameter(std::string const &, T const &) const
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< double > m_doubleToken
const edm::ParameterSet m_histoParameters
edm::EDGetTokenT< reco::VertexCollection > m_recoVertexCollectionToken
MCvsRecoVerticesAnalyzer::~MCvsRecoVerticesAnalyzer ( )
override

Definition at line 197 of file MCvsRecoVerticesAnalyzer.cc.

197  {
198  // do anything here that needs to be done at desctruction time
199  // (e.g. close files, deallocate resources etc.)
200 }

Member Function Documentation

void MCvsRecoVerticesAnalyzer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 207 of file MCvsRecoVerticesAnalyzer.cc.

References funct::abs(), DEFINE_FWK_MODULE, edm::Event::getByToken(), edm::HepMCProduct::GetEvent(), m_doubleToken, m_hclosestvtx, m_hclosestvtxvsnpu, m_hdeltazclose, m_hdeltazclosevsnpu, m_hdeltazfirst, m_hdeltazfirstvsnpu, m_hepMCProductToken, m_hrecovsmclumi2d, m_hrecovsmclumiprof, m_hrecovsmclumiweightedprof, m_hrecovsmcnvtx2d, m_hrecovsmcnvtxprof, m_hrecovsmcnvtxweightedprof, m_recoVertexCollectionToken, m_useVisibleVertices, m_useweight, m_vecPileupSummaryInfoToken, mps_merge::weight, and z.

207  {
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 }
edm::EDGetTokenT< edm::HepMCProduct > m_hepMCProductToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
Definition: weight.py:1
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
edm::EDGetTokenT< double > m_doubleToken
edm::EDGetTokenT< reco::VertexCollection > m_recoVertexCollectionToken

Member Data Documentation

edm::EDGetTokenT<double> MCvsRecoVerticesAnalyzer::m_doubleToken
private

Definition at line 70 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze().

TH1F* MCvsRecoVerticesAnalyzer::m_hclosestvtx
private

Definition at line 83 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

TH2F* MCvsRecoVerticesAnalyzer::m_hclosestvtxvsnpu
private

Definition at line 87 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

TH1F* MCvsRecoVerticesAnalyzer::m_hdeltazclose
private

Definition at line 82 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

TH2F* MCvsRecoVerticesAnalyzer::m_hdeltazclosevsnpu
private

Definition at line 86 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

TH1F* MCvsRecoVerticesAnalyzer::m_hdeltazfirst
private

Definition at line 81 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

TH2F* MCvsRecoVerticesAnalyzer::m_hdeltazfirstvsnpu
private

Definition at line 85 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

edm::EDGetTokenT<edm::HepMCProduct> MCvsRecoVerticesAnalyzer::m_hepMCProductToken
private

Definition at line 73 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze().

const edm::ParameterSet MCvsRecoVerticesAnalyzer::m_histoParameters
private

Definition at line 69 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by MCvsRecoVerticesAnalyzer().

TH2F* MCvsRecoVerticesAnalyzer::m_hrecovsmclumi2d
private

Definition at line 78 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

TProfile* MCvsRecoVerticesAnalyzer::m_hrecovsmclumiprof
private

Definition at line 79 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

TProfile* MCvsRecoVerticesAnalyzer::m_hrecovsmclumiweightedprof
private

Definition at line 80 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

TH2F* MCvsRecoVerticesAnalyzer::m_hrecovsmcnvtx2d
private

Definition at line 75 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

TProfile* MCvsRecoVerticesAnalyzer::m_hrecovsmcnvtxprof
private

Definition at line 76 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

TProfile* MCvsRecoVerticesAnalyzer::m_hrecovsmcnvtxweightedprof
private

Definition at line 77 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

edm::EDGetTokenT<reco::VertexCollection> MCvsRecoVerticesAnalyzer::m_recoVertexCollectionToken
private

Definition at line 72 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze().

const bool MCvsRecoVerticesAnalyzer::m_useVisibleVertices
private

Definition at line 68 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

const bool MCvsRecoVerticesAnalyzer::m_useweight
private

Definition at line 67 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze(), and MCvsRecoVerticesAnalyzer().

edm::EDGetTokenT<std::vector<PileupSummaryInfo> > MCvsRecoVerticesAnalyzer::m_vecPileupSummaryInfoToken
private

Definition at line 71 of file MCvsRecoVerticesAnalyzer.cc.

Referenced by analyze().