CMS 3D CMS Logo

AnotherPrimaryVertexAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Validation/RecoVertex
4 // Class: AnotherPrimaryVertexAnalyzer
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Mon Oct 27 17:37:53 CET 2008
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
23 
24 #include <vector>
25 #include <map>
26 #include <limits>
27 #include <string>
28 
35 
37 
39 
43 
45 
46 //
47 // class decleration
48 //
49 
50 class AnotherPrimaryVertexAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
51 public:
54 
55 private:
56  void beginJob() override;
57  void analyze(const edm::Event&, const edm::EventSetup&) override;
58  void beginRun(const edm::Run&, const edm::EventSetup&) override;
59  void endRun(const edm::Run&, const edm::EventSetup&) override;
60  void endJob() override;
61 
62  // ----------member data ---------------------------
63 
66  bool _firstOnly;
67 
68  std::unique_ptr<PrescaleWeightProvider> _weightprov;
69 };
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
83  : _vhm(iConfig.getParameter<edm::ParameterSet>("vHistogramMakerPSet"), consumesCollector()),
84  _recoVertexCollectionToken(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("pvCollection"))),
85  _firstOnly(iConfig.getUntrackedParameter<bool>("firstOnly", false)),
86  _weightprov(
87  iConfig.getParameter<bool>("usePrescaleWeight")
89  iConfig.getParameter<edm::ParameterSet>("prescaleWeightProviderPSet"), consumesCollector(), *this)
90  : nullptr) {
91  //now do what ever initialization is needed
92  usesResource(TFileService::kSharedResource);
93  //
94  _vhm.book();
95 }
96 
98 
99 //
100 // member functions
101 //
102 
103 // ------------ method called to for each event ------------
105  // compute event weight
106  auto const weight = _weightprov ? _weightprov->prescaleWeight<double>(iEvent, iSetup) : 1.;
107 
108  // get PV
110  iEvent.getByToken(_recoVertexCollectionToken, pvcoll);
111 
112  if (_firstOnly) {
113  reco::VertexCollection firstpv;
114  if (!pvcoll->empty())
115  firstpv.push_back((*pvcoll)[0]);
116  _vhm.fill(iEvent, firstpv, weight);
117  } else {
118  _vhm.fill(iEvent, *pvcoll, weight);
119  }
120 }
121 
122 // ------------ method called once each job just before starting event loop ------------
124 
126  _vhm.beginRun(iRun);
127 
128  if (_weightprov)
129  _weightprov->initRun(iRun, iSetup);
130 }
131 
133 // ------------ method called once each job just after ending the event loop ------------
135 
136 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
AnotherPrimaryVertexAnalyzer(const edm::ParameterSet &)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
Definition: weight.py:1
void fill(const edm::Event &iEvent, const reco::VertexCollection &vertices, const double weight=1.)
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
edm::EDGetTokenT< reco::VertexCollection > _recoVertexCollectionToken
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
std::unique_ptr< PrescaleWeightProvider > _weightprov
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginRun(const edm::Run &, const edm::EventSetup &) override
void book(const std::string dirname="")
void endRun(const edm::Run &, const edm::EventSetup &) override
void beginRun(const edm::Run &iRun)
fixed size matrix
HLT enums.
Definition: Run.h:45