00001 #include <map>
00002 #include <string>
00003
00004 #include "TH1D.h"
00005 #include "TH2D.h"
00006
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Utilities/interface/InputTag.h"
00009 #include "FWCore/Framework/interface/EDAnalyzer.h"
00010 #include "FWCore/Framework/interface/Frameworkfwd.h"
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 #include "DataFormats/PatCandidates/interface/Muon.h"
00013 #include "DataFormats/PatCandidates/interface/TriggerEvent.h"
00014
00015
00016 class PatTriggerAnalyzer : public edm::EDAnalyzer {
00017
00018 public:
00020 explicit PatTriggerAnalyzer( const edm::ParameterSet & iConfig );
00022 ~PatTriggerAnalyzer();
00023
00024 private:
00026 virtual void beginJob();
00028 virtual void analyze( const edm::Event & iEvent, const edm::EventSetup & iSetup );
00030 virtual void endJob();
00031
00033 edm::InputTag trigger_;
00035 edm::InputTag triggerEvent_;
00037 edm::InputTag muons_;
00039 std::string muonMatch_;
00041 unsigned nBins_;
00042 double binWidth_;
00044 unsigned minID_;
00046 unsigned maxID_;
00047
00049 std::map< std::string, TH1D* > histos1D_;
00050 std::map< std::string, TH2D* > histos2D_;
00051
00053 std::map< unsigned, unsigned > sumN_;
00054 std::map< unsigned, double > sumPt_;
00055 };
00056
00057
00058 #include "TMath.h"
00059 #include "FWCore/ServiceRegistry/interface/Service.h"
00060 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00061 #include "PhysicsTools/PatUtils/interface/TriggerHelper.h"
00062
00063
00064 using namespace pat;
00065
00066
00067 PatTriggerAnalyzer::PatTriggerAnalyzer( const edm::ParameterSet & iConfig ) :
00068
00069 trigger_( iConfig.getParameter< edm::InputTag >( "trigger" ) ),
00070
00071 triggerEvent_( iConfig.getParameter< edm::InputTag >( "triggerEvent" ) ),
00072
00073 muons_( iConfig.getParameter< edm::InputTag >( "muons" ) ),
00074
00075 muonMatch_( iConfig.getParameter< std::string >( "muonMatch" ) ),
00076
00077 nBins_( iConfig.getParameter< unsigned >( "nBins" ) ),
00078 binWidth_( iConfig.getParameter< double >( "binWidth" ) ),
00079
00080 minID_( iConfig.getParameter< unsigned >( "minID" ) ),
00081
00082 maxID_( iConfig.getParameter< unsigned >( "maxID" ) ),
00083 histos1D_(), histos2D_()
00084 {
00085 }
00086
00087 PatTriggerAnalyzer::~PatTriggerAnalyzer()
00088 {
00089 }
00090
00091 void PatTriggerAnalyzer::beginJob()
00092 {
00093 edm::Service< TFileService > fileService;
00094
00095
00096 histos2D_[ "ptTrigCand" ] = fileService->make< TH2D >( "ptTrigCand", "Object vs. candidate p_{T} (GeV)", 60, 0., 300., 60, 0., 300. );
00097 histos2D_[ "ptTrigCand" ]->SetXTitle( "candidate p_{T} (GeV)" );
00098 histos2D_[ "ptTrigCand" ]->SetYTitle( "object p_{T} (GeV)" );
00099
00100 histos2D_[ "etaTrigCand" ] = fileService->make< TH2D >( "etaTrigCand", "Object vs. candidate #eta", 50, -2.5, 2.5, 50, -2.5, 2.5 );
00101 histos2D_[ "etaTrigCand" ]->SetXTitle( "candidate #eta" );
00102 histos2D_[ "etaTrigCand" ]->SetYTitle( "object #eta" );
00103
00104 histos2D_[ "phiTrigCand" ] = fileService->make< TH2D >( "phiTrigCand", "Object vs. candidate #phi", 60, -TMath::Pi(), TMath::Pi(), 60, -TMath::Pi(), TMath::Pi() );
00105 histos2D_[ "phiTrigCand" ]->SetXTitle( "candidate #phi" );
00106 histos2D_[ "phiTrigCand" ]->SetYTitle( "object #phi" );
00107
00108 histos1D_[ "countCand" ] = fileService->make< TH1D >( "countCand", "p_{T} (GeV) of candidate", nBins_, 20., 20. + nBins_ * binWidth_ );
00109 histos1D_[ "countCand" ]->SetXTitle( "candidate p_{T} (GeV)" );
00110 histos1D_[ "countCand" ]->SetYTitle( "# of candidates" );
00111
00112 histos1D_[ "turnOn" ] = fileService->make< TH1D >( "turnOn", "p_{T} (GeV) of candidate", nBins_, 20., 20. + nBins_ * binWidth_ );
00113 histos1D_[ "turnOn" ]->SetXTitle( "candidate p_{T} (GeV)" );
00114 histos1D_[ "turnOn" ]->SetYTitle( "efficiency" );
00115
00116 histos1D_[ "ptMean" ] = fileService->make< TH1D >( "ptMean", "Mean p_{T} (GeV) per trigger object type", maxID_ - minID_ + 1, minID_ - 0.5, maxID_ + 0.5);
00117 histos1D_[ "ptMean" ]->SetXTitle( "trigger object type" );
00118 histos1D_[ "ptMean" ]->SetYTitle( "mean p_{T} (GeV)" );
00119
00120
00121 for( unsigned id = minID_; id <= maxID_; ++id ) {
00122 sumN_ [ id ] = 0;
00123 sumPt_[ id ] = 0.;
00124 }
00125 }
00126
00127 void PatTriggerAnalyzer::analyze( const edm::Event & iEvent, const edm::EventSetup & iSetup )
00128 {
00129
00130 edm::Handle< TriggerEvent > triggerEvent;
00131 iEvent.getByLabel( triggerEvent_, triggerEvent );
00132
00133
00134 edm::Handle< MuonCollection > muons;
00135 iEvent.getByLabel( muons_, muons );
00136
00137
00138 const helper::TriggerMatchHelper matchHelper;
00139
00140
00141
00142
00143
00144
00145 for( size_t iMuon = 0; iMuon < muons->size(); ++iMuon ) {
00146
00147 const TriggerObjectRef trigRef( matchHelper.triggerMatchObject( muons, iMuon, muonMatch_, iEvent, *triggerEvent ) );
00148
00149 if ( trigRef.isAvailable() && trigRef.isNonnull() ) {
00150 histos2D_[ "ptTrigCand" ]->Fill( muons->at( iMuon ).pt(), trigRef->pt() );
00151 histos2D_[ "etaTrigCand" ]->Fill( muons->at( iMuon ).eta(), trigRef->eta() );
00152 histos2D_[ "phiTrigCand" ]->Fill( muons->at( iMuon ).phi(), trigRef->phi() );
00153 }
00154 }
00155
00156
00157
00158
00159
00160
00161 for( size_t iMuon = 0; iMuon < muons->size(); ++iMuon ) {
00162
00163 histos1D_[ "countCand" ]->Fill( muons->at( iMuon ).pt() );
00164 }
00165
00166
00167 const TriggerObjectRefVector trigRefs( triggerEvent->objects( trigger::TriggerMuon ) );
00168
00169 for ( TriggerObjectRefVector::const_iterator iTrig = trigRefs.begin(); iTrig != trigRefs.end(); ++iTrig ) {
00170
00171 const reco::CandidateBaseRefVector candRefs( matchHelper.triggerMatchCandidates( ( *iTrig ), muonMatch_, iEvent, *triggerEvent ) );
00172 if ( candRefs.empty() ) continue;
00173
00174
00175
00176 reco::CandidateBaseRef muonRef( candRefs.at( 0 ) );
00177 if ( muonRef.isAvailable() && muonRef.isNonnull() ) {
00178 histos1D_[ "turnOn" ]->Fill( muonRef->pt() );
00179 }
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189 for ( unsigned id = minID_; id <= maxID_; ++id ) {
00190
00191 const TriggerObjectRefVector objRefs( triggerEvent->objects( id ) );
00192
00193 sumN_[ id ] += objRefs.size();
00194
00195 for ( TriggerObjectRefVector::const_iterator iRef = objRefs.begin(); iRef != objRefs.end(); ++iRef ) {
00196 sumPt_[ id ] += ( *iRef )->pt();
00197 }
00198 }
00199 }
00200
00201 void PatTriggerAnalyzer::endJob()
00202 {
00203
00204
00205
00206
00207
00208 histos1D_[ "turnOn" ]->Divide( histos1D_[ "countCand" ] );
00209
00210
00211
00212
00213
00214
00215 for(unsigned id=minID_; id<=maxID_; ++id){
00216 if( sumN_[ id ] != 0 ) histos1D_[ "ptMean" ]->Fill( id, sumPt_[ id ] / sumN_[ id ] );
00217 }
00218 }
00219
00220
00221 #include "FWCore/Framework/interface/MakerMacros.h"
00222 DEFINE_FWK_MODULE( PatTriggerAnalyzer );