CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PatTriggerAnalyzer.cc
Go to the documentation of this file.
1 #include "TMath.h"
6 
7 
8 using namespace pat;
9 
10 
12  // pat::Trigger
13  trigger_( iConfig.getParameter< edm::InputTag >( "trigger" ) ),
14  // pat::TriggerEvent
15  triggerEvent_( iConfig.getParameter< edm::InputTag >( "triggerEvent" ) ),
16  // muon input collection
17  muons_( iConfig.getParameter< edm::InputTag >( "muons" ) ),
18  // muon match objects
19  muonMatch_( iConfig.getParameter< std::string >( "muonMatch" ) ),
20  // minimal id for of all trigger objects
21  minID_( iConfig.getParameter< unsigned >( "minID" ) ),
22  // maximal id for of all trigger objects
23  maxID_( iConfig.getParameter< unsigned >( "maxID" ) ),
24  histos1D_(), histos2D_()
25 {
26 }
27 
29 {
30 }
31 
33 {
35 
36  // pt correlation plot
37  histos2D_[ "ptTrigCand" ] = fileService->make< TH2D >( "ptTrigCand", "Object vs. candidate p_{T} (GeV)", 60, 0., 300., 60, 0., 300. );
38  histos2D_[ "ptTrigCand" ]->SetXTitle( "candidate p_{T} (GeV)" );
39  histos2D_[ "ptTrigCand" ]->SetYTitle( "object p_{T} (GeV)" );
40  // eta correlation plot
41  histos2D_[ "etaTrigCand" ] = fileService->make< TH2D >( "etaTrigCand", "Object vs. candidate #eta", 50, -2.5, 2.5, 50, -2.5, 2.5 );
42  histos2D_[ "etaTrigCand" ]->SetXTitle( "candidate #eta" );
43  histos2D_[ "etaTrigCand" ]->SetYTitle( "object #eta" );
44  // phi correlation plot
45  histos2D_[ "phiTrigCand" ] = fileService->make< TH2D >( "phiTrigCand", "Object vs. candidate #phi", 60, -TMath::Pi(), TMath::Pi(), 60, -TMath::Pi(), TMath::Pi() );
46  histos2D_[ "phiTrigCand" ]->SetXTitle( "candidate #phi" );
47  histos2D_[ "phiTrigCand" ]->SetYTitle( "object #phi" );
48  // turn-on curves
49  histos1D_[ "turnOn" ] = fileService->make< TH1D >( "turnOn", "p_{T} (GeV) of matched candidate", 10, 0., 50.);
50  histos1D_[ "turnOn" ]->SetXTitle( "candidate p_{T} (GeV)" );
51  histos1D_[ "turnOn" ]->SetYTitle( "# of objects" );
52  // mean pt for all trigger objects
53  histos1D_[ "ptMean" ] = fileService->make< TH1D >( "ptMean", "Mean p_{T} (GeV) per trigger object type", maxID_ - minID_ + 1, minID_ - 0.5, maxID_ + 0.5);
54  histos1D_[ "ptMean" ]->SetXTitle( "trigger object type" );
55  histos1D_[ "ptMean" ]->SetYTitle( "mean p_{T} (GeV)" );
56 
57  // initialize counters for mean pt calculation
58  for( unsigned id = minID_; id <= maxID_; ++id ){
59  sumN_ [ id ] = 0;
60  sumPt_[ id ] = 0.;
61  }
62 }
63 
65 {
66  // PAT trigger event
67  edm::Handle< TriggerEvent > triggerEvent;
68  iEvent.getByLabel( triggerEvent_, triggerEvent );
69 
70  // PAT object collection
72  iEvent.getByLabel( muons_, muons );
73 
74  // PAT trigger helper for trigger matching information
75  const helper::TriggerMatchHelper matchHelper;
76 
77  /*
78  kinematics comparison
79  */
80 
81  // loop over muon references (PAT muons have been used in the matcher in task 3)
82  for( size_t iMuon = 0; iMuon < muons->size(); ++iMuon ) {
83  // we need all these ingedients to recieve matched trigger objects from the matchHelper
84  const TriggerObjectRef trigRef( matchHelper.triggerMatchObject( muons, iMuon, muonMatch_, iEvent, *triggerEvent ) );
85  // finally we can fill the histograms
86  if ( trigRef.isAvailable() && trigRef.isNonnull() ) { // check references (necessary!)
87  histos2D_[ "ptTrigCand" ]->Fill( muons->at( iMuon ).pt(), trigRef->pt() );
88  histos2D_[ "etaTrigCand" ]->Fill( muons->at( iMuon ).eta(), trigRef->eta() );
89  histos2D_[ "phiTrigCand" ]->Fill( muons->at( iMuon ).phi(), trigRef->phi() );
90  }
91  }
92 
93  /*
94  turn-on curve
95  */
96 
97  // get the trigger objects corresponding to the used matching (HLT muons)
98  const TriggerObjectRefVector trigRefs( triggerEvent->objects( trigger::TriggerMuon ) );
99  // loop over selected trigger objects
100  for ( TriggerObjectRefVector::const_iterator iTrig = trigRefs.begin(); iTrig != trigRefs.end(); ++iTrig ) {
101  // get all matched candidates for the trigger object
102  const reco::CandidateBaseRefVector candRefs( matchHelper.triggerMatchCandidates( ( *iTrig ), muonMatch_, iEvent, *triggerEvent ) );
103  if ( candRefs.empty() ) continue;
104  // fill the histogram...
105  // (only for the first match, since we resolved ambiguities in the matching configuration,
106  // so that we have one at maximum per trigger object)
107  reco::CandidateBaseRef muonRef( candRefs.at( 0 ) );
108  if ( muonRef.isAvailable() && muonRef.isNonnull() ) {
109  histos1D_[ "turnOn" ]->Fill( muonRef->pt() );
110  }
111  }
112 
113  /*
114  mean pt
115  */
116 
117  // loop over all trigger match objects from minID to maxID; have
118  // a look to DataFormats/HLTReco/interface/TriggerTypeDefs.h to
119  // know more about the available trrigger object id's
120  for ( unsigned id=minID_; id<=maxID_; ++id ) {
121  // vector of all objects for a given object id
122  const TriggerObjectRefVector objRefs( triggerEvent->objects( id ) );
123  // buffer the number of objects
124  sumN_[ id ] += objRefs.size();
125  // iterate the objects and buffer the pt of the objects
126  for ( TriggerObjectRefVector::const_iterator iRef = objRefs.begin(); iRef != objRefs.end(); ++iRef ) {
127  sumPt_[ id ] += ( *iRef )->pt();
128  }
129  }
130 }
131 
133 {
134  // normalize the entries for the mean pt plot
135  for(unsigned id=minID_; id<=maxID_; ++id){
136  if( sumN_[ id ]!=0 ) histos1D_[ "ptMean" ]->Fill( id, sumPt_[ id ]/sumN_[ id ] );
137  }
138 }
139 
140 
const double Pi
virtual void beginJob()
everythin that needs to be done before the event loop
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
everythin that needs to be done during the event loop
~PatTriggerAnalyzer()
default destructor
virtual void endJob()
everythin that needs to be done after the event loop
int iEvent
Definition: GenABIO.cc:243
PatTriggerAnalyzer(const edm::ParameterSet &iConfig)
default constructor
std::map< std::string, TH1D * > histos1D_
histogram management
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
unsigned minID_
minimal id for meanPt plot
edm::Service< TFileService > fileService
edm::InputTag triggerEvent_
input for patTriggerEvent
std::map< unsigned, double > sumPt_
edm::InputTag muons_
input for muons
tuple muons
Definition: patZpeak.py:38
std::map< std::string, TH2D * > histos2D_
std::map< unsigned, unsigned > sumN_
internals for meanPt histogram calculation
T * make() const
make new ROOT object
unsigned maxID_
maximal id for meanPt plot
std::string muonMatch_
input for trigger match objects