CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 // system include files
21 #include <memory>
22 
23 // user include files
24 
25 #include <vector>
26 #include <map>
27 #include <limits>
28 #include <string>
29 
36 
38 
40 
44 
46 
47 
48 //
49 // class decleration
50 //
51 
53  public:
56 
57 
58 private:
59  virtual void beginJob() ;
60  virtual void analyze(const edm::Event&, const edm::EventSetup&);
61  virtual void beginRun(const edm::Run&, const edm::EventSetup&);
62  virtual void endRun(const edm::Run&, const edm::EventSetup&);
63  virtual void endJob() ;
64 
65  // ----------member data ---------------------------
66 
69  bool _firstOnly;
70 
71  std::unique_ptr<PrescaleWeightProvider> _weightprov;
72 };
73 
74 //
75 // constants, enums and typedefs
76 //
77 
78 //
79 // static data member definitions
80 //
81 
82 //
83 // constructors and destructor
84 //
86  : _vhm(iConfig.getParameter<edm::ParameterSet>("vHistogramMakerPSet"), consumesCollector())
87  , _recoVertexCollectionToken(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("pvCollection")))
88  , _firstOnly(iConfig.getUntrackedParameter<bool>("firstOnly",false))
89  , _weightprov(iConfig.getParameter<bool>("usePrescaleWeight")
90  ? new PrescaleWeightProvider(iConfig.getParameter<edm::ParameterSet>("prescaleWeightProviderPSet"), consumesCollector(), *this)
91  : 0
92  )
93 {
94  //now do what ever initialization is needed
95 
96  //
97 
98  _vhm.book();
99 
100 }
101 
102 
104 {
105 }
106 
107 
108 //
109 // member functions
110 //
111 
112 // ------------ method called to for each event ------------
113 void
115 {
116 
117  // compute event weigth
118 
119  double weight = 1.;
120 
121  if(_weightprov) weight = _weightprov->prescaleWeight(iEvent,iSetup);
122 
123  // get PV
124 
126  iEvent.getByToken(_recoVertexCollectionToken,pvcoll);
127 
128  if(_firstOnly) {
129  reco::VertexCollection firstpv;
130  if(pvcoll->size()) firstpv.push_back((*pvcoll)[0]);
131  _vhm.fill(iEvent,firstpv,weight);
132  }
133  else {
134  _vhm.fill(iEvent,*pvcoll,weight);
135  }
136 }
137 
138 
139 // ------------ method called once each job just before starting event loop ------------
140 void
142 { }
143 
144 void
146 
147  _vhm.beginRun(iRun);
148 
149  if(_weightprov) _weightprov->initRun(iRun,iSetup);
150 
151 }
152 
153 void
155 
156 }
157 // ------------ method called once each job just after ending the event loop ------------
158 void
160 }
161 
162 
163 //define this as a plug-in
virtual void analyze(const edm::Event &, const edm::EventSetup &)
AnotherPrimaryVertexAnalyzer(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
void fill(const edm::Event &iEvent, const reco::VertexCollection &vertices, const double weight=1.)
edm::EDGetTokenT< reco::VertexCollection > _recoVertexCollectionToken
int iEvent
Definition: GenABIO.cc:230
std::unique_ptr< PrescaleWeightProvider > _weightprov
void book(const std::string dirname="")
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...
virtual void endRun(const edm::Run &, const edm::EventSetup &)
volatile std::atomic< bool > shutdown_flag false
int weight
Definition: histoStyle.py:50
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: Run.h:41