CMS 3D CMS Logo

PatAnalyzerSkeleton.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/StarterKit/interface/PatAnalyzerSkeleton.h"
00002 
00003 //
00004 // constants, enums and typedefs
00005 //
00006 
00007 //
00008 // static data member definitions
00009 //
00010 
00011 //
00012 // constructors and destructor
00013 //
00014 PatAnalyzerSkeleton::PatAnalyzerSkeleton(const edm::ParameterSet& iConfig):
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 }
00027 
00028 
00029 PatAnalyzerSkeleton::~PatAnalyzerSkeleton()
00030 {
00031  
00032    // do anything here that needs to be done at desctruction time
00033    // (e.g. close files, deallocate resources etc.)
00034 
00035 }
00036 
00037 
00038 //
00039 // member functions
00040 //
00041 
00042 // ------------ method called to for each event  ------------
00043 void
00044 PatAnalyzerSkeleton::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
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 }
00106 // ------------ method called once each job just before starting event loop  ------------
00107 void 
00108 PatAnalyzerSkeleton::beginJob(const edm::EventSetup&)
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 }
00135 
00136 // ------------ method called once each job just after ending the event loop  ------------
00137 void 
00138 PatAnalyzerSkeleton::endJob() {
00139 }
00140 
00141 //define this as a plug-in
00142 DEFINE_FWK_MODULE(PatAnalyzerSkeleton);

Generated on Tue Jun 9 17:41:52 2009 for CMSSW by  doxygen 1.5.4