CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/PhysicsTools/PatExamples/plugins/PatTriggerAnalyzerPrescale.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/Event.h"
00002 #include "FWCore/Utilities/interface/InputTag.h"
00003 #include "FWCore/Framework/interface/EDAnalyzer.h"
00004 #include "FWCore/Framework/interface/Frameworkfwd.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 
00007 #include "TH1D.h"
00008 
00009 
00010 class PatTriggerAnalyzerPrescale : public edm::EDAnalyzer {
00011 
00012  public:
00014   explicit PatTriggerAnalyzerPrescale( const edm::ParameterSet & iConfig );
00016   ~PatTriggerAnalyzerPrescale(){};
00017 
00018  private:
00020   virtual void beginJob();
00022   virtual void analyze( const edm::Event & iEvent, const edm::EventSetup & iSetup );
00024   virtual void endJob(){};
00025 
00027   TH1D * histo_;
00028 
00030   Int_t bin_;
00031 
00033   std::string pathName_;
00034 
00035 };
00036 
00037 #include "FWCore/ServiceRegistry/interface/Service.h"
00038 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00039 
00040 #include "DataFormats/PatCandidates/interface/TriggerEvent.h"
00041 
00042 
00043 using namespace pat;
00044 
00045 
00046 PatTriggerAnalyzerPrescale::PatTriggerAnalyzerPrescale( const edm::ParameterSet & iConfig )
00047 : bin_( 0 )
00048 , pathName_( iConfig.getParameter< std::string >( "pathName" ) )
00049 {
00050 }
00051 
00052 void PatTriggerAnalyzerPrescale::beginJob()
00053 {
00054   edm::Service< TFileService > fileService;
00055 
00056   // Histogram definition for 100 events on the x-axis
00057   histo_ = fileService->make< TH1D >( "histo_", std::string( "Prescale values of " + pathName_ ).c_str(), 100, 0., 100.);
00058   histo_->SetXTitle( "event" );
00059   histo_->SetYTitle( "prescale" );
00060   histo_->SetMinimum( 0. );
00061 }
00062 
00063 void PatTriggerAnalyzerPrescale::analyze( const edm::Event & iEvent, const edm::EventSetup & iSetup )
00064 {
00065   // PAT trigger event
00066   edm::Handle< TriggerEvent > triggerEvent;
00067   iEvent.getByLabel( "patTriggerEvent", triggerEvent );
00068 
00069   // Get the HLT path
00070   const TriggerPath * path( triggerEvent->path( pathName_ ) );
00071 
00072   // Fill prescale factor into histogram
00073   ++bin_;
00074   if ( path ) histo_->SetBinContent( bin_, path->prescale() );
00075 }
00076 
00077 
00078 #include "FWCore/Framework/interface/MakerMacros.h"
00079 DEFINE_FWK_MODULE( PatTriggerAnalyzerPrescale );