00001 #include "TMath.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00004 #include "PhysicsTools/PatUtils/interface/TriggerHelper.h"
00005 #include "PhysicsTools/PatExamples/plugins/PatTriggerAnalyzer.h"
00006 #include <iostream>
00007
00008
00009 using namespace pat;
00010
00011
00012 PatTriggerAnalyzer::PatTriggerAnalyzer( const edm::ParameterSet & iConfig ) :
00013
00014 trigger_( iConfig.getParameter< edm::InputTag >( "trigger" ) ),
00015
00016 triggerEvent_( iConfig.getParameter< edm::InputTag >( "triggerEvent" ) ),
00017
00018 muons_( iConfig.getParameter< edm::InputTag >( "muons" ) ),
00019
00020 muonMatch_( iConfig.getParameter< std::string >( "muonMatch" ) ),
00021
00022 minID_( iConfig.getParameter< unsigned >( "minID" ) ),
00023
00024 maxID_( iConfig.getParameter< unsigned >( "maxID" ) ),
00025 histos1D_(), histos2D_()
00026 {
00027 }
00028
00029 PatTriggerAnalyzer::~PatTriggerAnalyzer()
00030 {
00031 }
00032
00033 void PatTriggerAnalyzer::beginJob()
00034 {
00035 edm::Service< TFileService > fileService;
00036
00037
00038 histos2D_[ "ptTrigCand" ] = fileService->make< TH2D >( "ptTrigCand", "Object vs. candidate p_{T} (GeV)", 60, 0., 300., 60, 0., 300. );
00039 histos2D_[ "ptTrigCand" ]->SetXTitle( "candidate p_{T} (GeV)" );
00040 histos2D_[ "ptTrigCand" ]->SetYTitle( "object p_{T} (GeV)" );
00041
00042 histos2D_[ "etaTrigCand" ] = fileService->make< TH2D >( "etaTrigCand", "Object vs. candidate #eta", 50, -2.5, 2.5, 50, -2.5, 2.5 );
00043 histos2D_[ "etaTrigCand" ]->SetXTitle( "candidate #eta" );
00044 histos2D_[ "etaTrigCand" ]->SetYTitle( "object #eta" );
00045
00046 histos2D_[ "phiTrigCand" ] = fileService->make< TH2D >( "phiTrigCand", "Object vs. candidate #phi", 60, -TMath::Pi(), TMath::Pi(), 60, -TMath::Pi(), TMath::Pi() );
00047 histos2D_[ "phiTrigCand" ]->SetXTitle( "candidate #phi" );
00048 histos2D_[ "phiTrigCand" ]->SetYTitle( "object #phi" );
00049
00050 histos1D_[ "turnOn" ] = fileService->make< TH1D >( "turnOn", "p_{T} (GeV) of matched candidate", 10, 0., 50.);
00051 histos1D_[ "turnOn" ]->SetXTitle( "candidate p_{T} (GeV)" );
00052 histos1D_[ "turnOn" ]->SetYTitle( "# of objects" );
00053
00054 histos1D_[ "ptMean" ] = fileService->make< TH1D >( "ptMean", "Mean p_{T} (GeV) per filter ID", maxID_ - minID_ + 1, minID_ - 0.5, maxID_ + 0.5);
00055 histos1D_[ "ptMean" ]->SetXTitle( "filter ID" );
00056 histos1D_[ "ptMean" ]->SetYTitle( "mean p_{T} (GeV)" );
00057
00058
00059 for( unsigned id = minID_; id <= maxID_; ++id ){
00060 sumN_ [ id ] = 0;
00061 sumPt_[ id ] = 0.;
00062 }
00063 }
00064
00065 void PatTriggerAnalyzer::analyze( const edm::Event & iEvent, const edm::EventSetup & iSetup )
00066 {
00067
00068 edm::Handle< TriggerEvent > triggerEvent;
00069 iEvent.getByLabel( triggerEvent_, triggerEvent );
00070
00071
00072 edm::Handle< MuonCollection > muons;
00073 iEvent.getByLabel( muons_, muons );
00074
00075
00076 const helper::TriggerMatchHelper matchHelper;
00077
00078
00079
00080
00081
00082
00083 for( size_t iMuon = 0; iMuon < muons->size(); ++iMuon ) {
00084
00085 const TriggerObjectRef trigRef( matchHelper.triggerMatchObject( muons, iMuon, muonMatch_, iEvent, *triggerEvent ) );
00086
00087 if ( trigRef.isAvailable() && trigRef.isNonnull() ) {
00088 histos2D_[ "ptTrigCand" ]->Fill( muons->at( iMuon ).pt(), trigRef->pt() );
00089 histos2D_[ "etaTrigCand" ]->Fill( muons->at( iMuon ).eta(), trigRef->eta() );
00090 histos2D_[ "phiTrigCand" ]->Fill( muons->at( iMuon ).phi(), trigRef->phi() );
00091 }
00092 }
00093
00094
00095
00096
00097
00098
00099 const TriggerObjectRefVector trigRefs( triggerEvent->objects( trigger::TriggerMuon ) );
00100
00101 for ( TriggerObjectRefVector::const_iterator iTrig = trigRefs.begin(); iTrig != trigRefs.end(); ++iTrig ) {
00102
00103 const reco::CandidateBaseRefVector candRefs( matchHelper.triggerMatchCandidates( ( *iTrig), muonMatch_, iEvent, *triggerEvent ) );
00104 if ( candRefs.empty() ) continue;
00105
00106
00107
00108 reco::CandidateBaseRef muonRef( candRefs.at( 0 ) );
00109 if ( muonRef.isAvailable() && muonRef.isNonnull() ) {
00110 histos1D_[ "turnOn" ]->Fill( muonRef->pt() );
00111 }
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121 for ( unsigned id=minID_; id<=maxID_; ++id ) {
00122
00123 const TriggerObjectRefVector objRefs( triggerEvent->objects( id ) );
00124
00125 sumN_[ id ] += objRefs.size();
00126
00127 for ( TriggerObjectRefVector::const_iterator iRef = objRefs.begin(); iRef != objRefs.end(); ++iRef ) {
00128 sumPt_[ id ] += ( *iRef )->pt();
00129 }
00130 }
00131 }
00132
00133 void PatTriggerAnalyzer::endJob()
00134 {
00135
00136 for(unsigned id=minID_; id<=maxID_; ++id){
00137 if( sumN_[ id ]!=0 ) histos1D_[ "ptMean" ]->Fill( id, sumPt_[ id ]/sumN_[ id ] );
00138 }
00139 }
00140
00141
00142 #include "FWCore/Framework/interface/MakerMacros.h"
00143 DEFINE_FWK_MODULE( PatTriggerAnalyzer );