CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PatTriggerTagAndProbe.cc
Go to the documentation of this file.
1 #include <map>
2 #include <string>
3 
4 #include "TH1D.h"
5 #include "TH2D.h"
6 
14 
15 
17 
18  public:
20  explicit PatTriggerTagAndProbe( const edm::ParameterSet & iConfig );
23 
24  private:
26  virtual void beginJob() ;
28  virtual void analyze( const edm::Event & iEvent, const edm::EventSetup & iSetup );
30  virtual void endJob();
31 
33  void setErrors(TH1D& h, const TH1D& ref);
34 
42  std::map< std::string, TH1D* > histos1D_;
43 };
44 
45 
46 #include "TMath.h"
47 
51 
52 
54  // pat::TriggerEvent
55  triggerEventToken_( consumes< pat::TriggerEvent >( iConfig.getParameter< edm::InputTag >( "triggerEvent" ) ) ),
56  // muon input collection
57  muonsToken_( consumes< pat::MuonCollection >( iConfig.getParameter< edm::InputTag >( "muons" ) ) ),
58  // muon match objects
59  muonMatch_( iConfig.getParameter< std::string >( "muonMatch" ) ),
60  // histogram management
61  histos1D_()
62 {
63 }
64 
66 {
67 }
68 
70 {
72 
73  // mass plot around Z peak
74  histos1D_[ "mass" ] = fileService->make< TH1D >( "mass" , "Mass_{Z} (GeV)", 90, 30., 120.);
75  // pt for test candidate
76  histos1D_[ "testPt" ] = fileService->make< TH1D >( "testPt" , "p_{T} (GeV)" , 100, 0., 100.);
77  // pt for probe candidate
78  histos1D_[ "probePt" ] = fileService->make< TH1D >( "probePt" , "p_{T} (GeV)" , 100, 0., 100.);
79  // eta for test candidate
80  histos1D_[ "testEta" ] = fileService->make< TH1D >( "testEta" , "#eta" , 48, -2.4, 2.4);
81  // eta for probe candidate
82  histos1D_[ "probeEta"] = fileService->make< TH1D >( "probeEta", "#eta" , 48, -2.4, 2.4);
83 }
84 
86 {
87  // trigger event
89  iEvent.getByToken( triggerEventToken_, triggerEvent );
90  // pat candidate collection
92  iEvent.getByToken( muonsToken_, muons );
93 
94  // pat trigger helper to recieve for trigger
95  // matching information
96  const pat::helper::TriggerMatchHelper matchHelper;
97 
98  // ask for trigger accept of HLT_Mu9; otherwise we don't even start
99  if(!(triggerEvent->path("HLT_IsoMu17_v5")->wasRun() && triggerEvent->path("HLT_IsoMu17_v5")->wasAccept())){
100  return;
101  }
102 
103  // loop over muon references for the tag muon
104  for( size_t idxTag=0; idxTag<muons->size(); ++idxTag){
105  const pat::TriggerObjectRef trigRefTag( matchHelper.triggerMatchObject( muons, idxTag, muonMatch_, iEvent, *triggerEvent ) );
106  if( trigRefTag.isAvailable() ){
107  // loop over muon references for the probe/test muon
108  for( size_t idxProbe=0; idxProbe<muons->size() && idxProbe!=idxTag; ++idxProbe){
109  histos1D_[ "mass" ]->Fill( (muons->at(idxTag).p4()+muons->at(idxProbe).p4()).mass() );
110  if(fabs((muons->at(idxTag).p4()+muons->at(idxProbe).p4()).mass()-90)<5){
111  const pat::TriggerObjectRef trigRefProbe( matchHelper.triggerMatchObject( muons, idxProbe, muonMatch_, iEvent, *triggerEvent ) );
112  histos1D_[ "probePt" ]->Fill( muons->at(idxProbe).pt () );
113  histos1D_[ "probeEta" ]->Fill( muons->at(idxProbe).eta() );
114  if( trigRefProbe.isAvailable() ){
115  histos1D_[ "testPt" ]->Fill( muons->at(idxProbe).pt () );
116  histos1D_[ "testEta"]->Fill( muons->at(idxProbe).eta() );
117  }
118  }
119  }
120  }
121  }
122 }
123 
125 {
126  // normalize the entries of the histograms
127  histos1D_[ "testPt" ]->Divide(histos1D_ [ "probePt" ]);
128  setErrors(*histos1D_["testPt" ],*histos1D_[ "probePt" ]);
129  histos1D_[ "testEta" ]->Divide(histos1D_ [ "probeEta" ]);
130  setErrors(*histos1D_["testEta"],*histos1D_[ "probeEta" ]);
131 }
132 
133 void PatTriggerTagAndProbe::setErrors(TH1D& h, const TH1D& ref)
134 {
135  for(int bin=0; bin<h.GetNbinsX(); ++bin){
136  if(ref.GetBinContent(bin+1)>0){
137  h.SetBinError(bin+1, sqrt((h.GetBinContent(bin+1)*(1.-h.GetBinContent(bin+1)))/ref.GetBinContent(bin+1)));
138  } else{ h.SetBinError(bin+1, 0.); }
139  }
140 }
141 
142 
PatTriggerTagAndProbe(const edm::ParameterSet &iConfig)
default constructor
TriggerObjectRef triggerMatchObject(const reco::CandidateBaseRef &candRef, const TriggerObjectMatch *matchResult, const edm::Event &event, const TriggerEvent &triggerEvent) const
Methods.
~PatTriggerTagAndProbe()
default destructor
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::EDGetTokenT< pat::MuonCollection > muonsToken_
input for muons
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
everythin that needs to be done during the event loop
edm::EDGetTokenT< pat::TriggerEvent > triggerEventToken_
input for patTriggerEvent
void setErrors(TH1D &h, const TH1D &ref)
helper function to set proper bin errors
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
int iEvent
Definition: GenABIO.cc:230
T sqrt(T t)
Definition: SSEVec.h:48
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
virtual void beginJob()
everythin that needs to be done before the event loop
std::map< std::string, TH1D * > histos1D_
management of 1d histograms
edm::Service< TFileService > fileService
std::string muonMatch_
input for trigger match objects
tuple muons
Definition: patZpeak.py:38
virtual void endJob()
everythin that needs to be done after the event loop