![]() |
![]() |
#include <PhysicsTools/StarterKit/plugins/PatAnalyzerSkeleton.cc>
Public Member Functions | |
PatAnalyzerSkeleton (const edm::ParameterSet &) | |
~PatAnalyzerSkeleton () | |
Private Member Functions | |
virtual void | analyze (const edm::Event &, const edm::EventSetup &) |
virtual void | beginJob (const edm::EventSetup &) |
virtual void | endJob () |
Private Attributes | |
edm::InputTag | eleLabel_ |
std::map< std::string, TH1D * > | histocontainer_ |
edm::InputTag | jetLabel_ |
edm::InputTag | metLabel_ |
edm::InputTag | muoLabel_ |
edm::InputTag | phoLabel_ |
edm::InputTag | tauLabel_ |
Implementation:
this analyzer shows how to loop over PAT output.
Definition at line 57 of file PatAnalyzerSkeleton.h.
PatAnalyzerSkeleton::PatAnalyzerSkeleton | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
Definition at line 14 of file PatAnalyzerSkeleton.cc.
00014 : 00015 histocontainer_(), 00016 eleLabel_(iConfig.getUntrackedParameter<edm::InputTag>("electronTag")), 00017 muoLabel_(iConfig.getUntrackedParameter<edm::InputTag>("muonTag")), 00018 jetLabel_(iConfig.getUntrackedParameter<edm::InputTag>("jetTag")), 00019 tauLabel_(iConfig.getUntrackedParameter<edm::InputTag>("tauTag")), 00020 metLabel_(iConfig.getUntrackedParameter<edm::InputTag>("metTag")), 00021 phoLabel_(iConfig.getUntrackedParameter<edm::InputTag>("photonTag")) 00022 00023 { 00024 //now do what ever initialization is needed 00025 00026 }
PatAnalyzerSkeleton::~PatAnalyzerSkeleton | ( | ) |
Definition at line 29 of file PatAnalyzerSkeleton.cc.
00030 { 00031 00032 // do anything here that needs to be done at desctruction time 00033 // (e.g. close files, deallocate resources etc.) 00034 00035 }
void PatAnalyzerSkeleton::analyze | ( | const edm::Event & | iEvent, | |
const edm::EventSetup & | iSetup | |||
) | [private, virtual] |
Implements edm::EDAnalyzer.
Definition at line 44 of file PatAnalyzerSkeleton.cc.
References edm::View< T >::begin(), eleLabel_, edm::View< T >::end(), edm::Event::getByLabel(), histocontainer_, jetLabel_, pfTauBenchmarkGeneric_cfi::jets, metLabel_, muoLabel_, muons_cfi::muons, phoLabel_, photons_cfi::photons, edm::View< T >::size(), and tauLabel_.
00045 { 00046 using namespace edm; 00047 00048 00049 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00050 // first: get all objects from the event. 00051 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00052 00053 edm::Handle<edm::View<pat::Muon> > muonHandle; 00054 iEvent.getByLabel(muoLabel_,muonHandle); 00055 edm::View<pat::Muon> muons = *muonHandle; 00056 00057 edm::Handle<edm::View<pat::Jet> > jetHandle; 00058 iEvent.getByLabel(jetLabel_,jetHandle); 00059 edm::View<pat::Jet> jets = *jetHandle; 00060 00061 edm::Handle<edm::View<pat::Electron> > electronHandle; 00062 iEvent.getByLabel(eleLabel_,electronHandle); 00063 edm::View<pat::Electron> electrons = *electronHandle; 00064 00065 edm::Handle<edm::View<pat::MET> > metHandle; 00066 iEvent.getByLabel(metLabel_,metHandle); 00067 edm::View<pat::MET> mets = *metHandle; 00068 00069 edm::Handle<edm::View<pat::Photon> > phoHandle; 00070 iEvent.getByLabel(phoLabel_,phoHandle); 00071 edm::View<pat::Photon> photons = *phoHandle; 00072 00073 edm::Handle<edm::View<pat::Tau> > tauHandle; 00074 iEvent.getByLabel(tauLabel_,tauHandle); 00075 edm::View<pat::Tau> taus = *tauHandle; 00076 00077 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00078 // example of a loop over objects... this works identical for all vectors defined above 00079 // once you have a jet object you can use all methods defined in the header file 00080 // (DataFormats/PatCandidates/interface/Jet.h and equivalent for other objects) 00081 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00082 size_t njetscounter=0; 00083 for(edm::View<pat::Jet>::const_iterator jet_iter = jets.begin(); jet_iter!=jets.end(); ++jet_iter){ 00084 if(jet_iter->pt()>50) 00085 njetscounter++; 00086 00087 } 00088 00089 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00090 //histocontainer_ is of type std::map<edm::View, TH1D*>. This means you can use it with this syntax: 00091 // histocontainer_["histname"]->Fill(x); 00092 // histocontainer_["histname"]->Draw(); 00093 // etc, etc. Essentially you use the histname string to look up a pointer to a TH1D* 00094 // which you can do everything to you would normally do in ROOT. 00095 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00096 00097 histocontainer_["njets"]->Fill(njetscounter); 00098 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00099 // for the other objects just quickly book the multiplicity. Again, just use the same infrastructure as for jets if you want to loop over them. 00100 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00101 histocontainer_["nelectrons"]->Fill(electrons.size()); 00102 histocontainer_["nphotons"]->Fill(photons.size()); 00103 histocontainer_["nmuons"]->Fill(muons.size()); 00104 histocontainer_["ntaus"]->Fill(taus.size()); 00105 }
void PatAnalyzerSkeleton::beginJob | ( | const edm::EventSetup & | ) | [private, virtual] |
Reimplemented from edm::EDAnalyzer.
Definition at line 108 of file PatAnalyzerSkeleton.cc.
References histocontainer_.
00109 { 00110 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00111 // define some histograms using the framework tfileservice. Define the output file name in your .cfg. 00112 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00113 edm::Service<TFileService> fs; 00114 00115 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00116 //histocontainer_ is of type std::map<std::string, TH1D*>. This means you can use it with this syntax: 00117 // histocontainer_["histname"]->Fill(x); 00118 // histocontainer_["histname"]->Draw(); 00119 // etc, etc. Essentially you use the histname string to look up a pointer to a TH1D* 00120 // which you can do everything to you would normally do in ROOT. 00121 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00122 00123 00124 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00125 // here we book new histograms: 00126 //{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} 00127 00128 histocontainer_["njets"]=fs->make<TH1D>("njets","jet multiplicity for jets with p_{T} > 50 GeV/c",10,0,10); 00129 histocontainer_["nelectrons"]=fs->make<TH1D>("nelectrons","electron multiplicity",10,0,10); 00130 histocontainer_["ntaus"]=fs->make<TH1D>("ntaus","tau multiplicity",10,0,10); 00131 histocontainer_["nphotons"]=fs->make<TH1D>("nphotons","photon multiplicity",10,0,10); 00132 histocontainer_["nmuons"]=fs->make<TH1D>("nmuons","muon multiplicity",10,0,10); 00133 00134 }
edm::InputTag PatAnalyzerSkeleton::eleLabel_ [private] |
std::map<std::string,TH1D*> PatAnalyzerSkeleton::histocontainer_ [private] |
edm::InputTag PatAnalyzerSkeleton::jetLabel_ [private] |
edm::InputTag PatAnalyzerSkeleton::metLabel_ [private] |
edm::InputTag PatAnalyzerSkeleton::muoLabel_ [private] |
edm::InputTag PatAnalyzerSkeleton::phoLabel_ [private] |
edm::InputTag PatAnalyzerSkeleton::tauLabel_ [private] |