CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Validation/RecoVertex/src/AnotherPrimaryVertexAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    Validation/RecoVertex
00004 // Class:      AnotherPrimaryVertexAnalyzer
00005 // 
00013 //
00014 // Original Author:  Andrea Venturi
00015 //         Created:  Mon Oct 27 17:37:53 CET 2008
00016 // $Id: AnotherPrimaryVertexAnalyzer.cc,v 1.2 2011/12/11 10:51:49 venturia Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 
00026 #include <vector>
00027 #include <map>
00028 #include <limits>
00029 #include <string>
00030 
00031 #include "FWCore/Framework/interface/Frameworkfwd.h"
00032 #include "FWCore/Framework/interface/EDAnalyzer.h"
00033 
00034 #include "FWCore/Framework/interface/Event.h"
00035 #include "FWCore/Framework/interface/Run.h"
00036 #include "FWCore/Framework/interface/MakerMacros.h"
00037 
00038 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00039 
00040 #include "FWCore/Utilities/interface/InputTag.h"
00041 
00042 #include "Validation/RecoVertex/interface/VertexHistogramMaker.h"
00043 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00044 #include "DataFormats/VertexReco/interface/Vertex.h"
00045 
00046 #include "CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h"
00047 
00048 
00049 //
00050 // class decleration
00051 //
00052 
00053 class AnotherPrimaryVertexAnalyzer : public edm::EDAnalyzer {
00054    public:
00055       explicit AnotherPrimaryVertexAnalyzer(const edm::ParameterSet&);
00056       ~AnotherPrimaryVertexAnalyzer();
00057 
00058 
00059 private:
00060   virtual void beginJob() ;
00061   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00062   virtual void beginRun(const edm::Run&, const edm::EventSetup&);
00063   virtual void endRun(const edm::Run&, const edm::EventSetup&);
00064   virtual void endJob() ;
00065 
00066       // ----------member data ---------------------------
00067 
00068   VertexHistogramMaker _vhm;
00069   edm::InputTag _pvcollection;
00070   bool _firstOnly;
00071 
00072   PrescaleWeightProvider* _weightprov;
00073 };
00074 
00075 //
00076 // constants, enums and typedefs
00077 //
00078 
00079 //
00080 // static data member definitions
00081 //
00082 
00083 //
00084 // constructors and destructor
00085 //
00086 AnotherPrimaryVertexAnalyzer::AnotherPrimaryVertexAnalyzer(const edm::ParameterSet& iConfig):
00087   _vhm(iConfig.getParameter<edm::ParameterSet>("vHistogramMakerPSet")),
00088   _pvcollection(iConfig.getParameter<edm::InputTag>("pvCollection")),
00089   _firstOnly(iConfig.getUntrackedParameter<bool>("firstOnly",false)),
00090   _weightprov(iConfig.getParameter<bool>("usePrescaleWeight") ? 
00091               new PrescaleWeightProvider(iConfig.getParameter<edm::ParameterSet>("prescaleWeightProviderPSet")) : 0)
00092 {
00093    //now do what ever initialization is needed
00094 
00095   //
00096 
00097   _vhm.book();
00098 
00099 }
00100 
00101 
00102 AnotherPrimaryVertexAnalyzer::~AnotherPrimaryVertexAnalyzer()
00103 {
00104  
00105    // do anything here that needs to be done at desctruction time
00106    // (e.g. close files, deallocate resources etc.)
00107 
00108   delete _weightprov;
00109 
00110 }
00111 
00112 
00113 //
00114 // member functions
00115 //
00116 
00117 // ------------ method called to for each event  ------------
00118 void
00119 AnotherPrimaryVertexAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00120 {
00121   using namespace edm;
00122   
00123   // compute event weigth
00124 
00125   double weight = 1.;
00126 
00127   if(_weightprov) weight = _weightprov->prescaleWeight(iEvent,iSetup);
00128 
00129   // get PV
00130 
00131   Handle<reco::VertexCollection> pvcoll;
00132   iEvent.getByLabel(_pvcollection,pvcoll);
00133 
00134   if(_firstOnly) {
00135     reco::VertexCollection firstpv;
00136     if(pvcoll->size()) firstpv.push_back((*pvcoll)[0]);
00137     _vhm.fill(iEvent,firstpv,weight);
00138   }
00139   else {
00140     _vhm.fill(iEvent,*pvcoll,weight);
00141   }
00142 }
00143 
00144 
00145 // ------------ method called once each job just before starting event loop  ------------
00146 void 
00147 AnotherPrimaryVertexAnalyzer::beginJob()
00148 { }
00149 
00150 void
00151 AnotherPrimaryVertexAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
00152 
00153   _vhm.beginRun(iRun);
00154 
00155   if(_weightprov) _weightprov->initRun(iRun,iSetup);
00156 
00157 }
00158 
00159 void
00160 AnotherPrimaryVertexAnalyzer::endRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
00161 
00162 }
00163 // ------------ method called once each job just after ending the event loop  ------------
00164 void 
00165 AnotherPrimaryVertexAnalyzer::endJob() {
00166 }
00167 
00168 
00169 //define this as a plug-in
00170 DEFINE_FWK_MODULE(AnotherPrimaryVertexAnalyzer);