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 
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)),
87  iConfig.getParameter<bool>("usePrescaleWeight")
89  iConfig.getParameter<edm::ParameterSet>("prescaleWeightProviderPSet"), consumesCollector(), *this)
90  : nullptr) {
91  //now do what ever initialization is needed
92 
93  //
94 
95  _vhm.book();
96 }
97 
99 
100 //
101 // member functions
102 //
103 
104 // ------------ method called to for each event ------------
106  // compute event weigth
107 
108  double weight = 1.;
109 
110  if (_weightprov)
111  weight = _weightprov->prescaleWeight(iEvent, iSetup);
112 
113  // get PV
114 
116  iEvent.getByToken(_recoVertexCollectionToken, pvcoll);
117 
118  if (_firstOnly) {
119  reco::VertexCollection firstpv;
120  if (!pvcoll->empty())
121  firstpv.push_back((*pvcoll)[0]);
122  _vhm.fill(iEvent, firstpv, weight);
123  } else {
124  _vhm.fill(iEvent, *pvcoll, weight);
125  }
126 }
127 
128 // ------------ method called once each job just before starting event loop ------------
130 
132  _vhm.beginRun(iRun);
133 
134  if (_weightprov)
135  _weightprov->initRun(iRun, iSetup);
136 }
137 
139 // ------------ method called once each job just after ending the event loop ------------
141 
142 //define this as a plug-in
AnotherPrimaryVertexAnalyzer(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
#define nullptr
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.)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< reco::VertexCollection > _recoVertexCollectionToken
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
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