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 weigth
106 
107  double weight = 1.;
108 
109  if (_weightprov)
110  weight = _weightprov->prescaleWeight(iEvent, iSetup);
111 
112  // get PV
113 
115  iEvent.getByToken(_recoVertexCollectionToken, pvcoll);
116 
117  if (_firstOnly) {
118  reco::VertexCollection firstpv;
119  if (!pvcoll->empty())
120  firstpv.push_back((*pvcoll)[0]);
121  _vhm.fill(iEvent, firstpv, weight);
122  } else {
123  _vhm.fill(iEvent, *pvcoll, weight);
124  }
125 }
126 
127 // ------------ method called once each job just before starting event loop ------------
129 
131  _vhm.beginRun(iRun);
132 
133  if (_weightprov)
134  _weightprov->initRun(iRun, iSetup);
135 }
136 
138 // ------------ method called once each job just after ending the event loop ------------
140 
141 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
AnotherPrimaryVertexAnalyzer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
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)
This class takes a vector of HLT paths and returns a weight based on their HLT and L1 prescales...
fixed size matrix
HLT enums.
Definition: Run.h:45