Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:01

0001 #include <map>
0002 #include <string>
0003 
0004 #include "TH1.h"
0005 
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/Utilities/interface/InputTag.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ServiceRegistry/interface/Service.h"
0011 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0012 
0013 #include "DataFormats/PatCandidates/interface/Jet.h"
0014 
0015 class PatZjetsJetAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0016 public:
0017   explicit PatZjetsJetAnalyzer(const edm::ParameterSet&);
0018   ~PatZjetsJetAnalyzer() override;
0019 
0020 private:
0021   void beginJob() override;
0022   void analyze(const edm::Event&, const edm::EventSetup&) override;
0023   void endJob() override;
0024 
0025   // simple map to contain all histograms;
0026   // histograms are booked in the beginJob()
0027   // method
0028   std::map<std::string, TH1F*> histContainer_;
0029 
0030   // input tags
0031   edm::EDGetTokenT<edm::View<pat::Jet> > srcToken_;
0032 };
0033 
0034 PatZjetsJetAnalyzer::PatZjetsJetAnalyzer(const edm::ParameterSet& iConfig)
0035     : histContainer_(), srcToken_(consumes<edm::View<pat::Jet> >(iConfig.getUntrackedParameter<edm::InputTag>("src"))) {
0036   usesResource(TFileService::kSharedResource);
0037 }
0038 
0039 PatZjetsJetAnalyzer::~PatZjetsJetAnalyzer() {}
0040 
0041 void PatZjetsJetAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0042   // get electron collection
0043   edm::Handle<edm::View<pat::Jet> > jets;
0044   iEvent.getByToken(srcToken_, jets);
0045 
0046   // loop jets
0047   for (edm::View<pat::Jet>::const_iterator ijet = jets->begin(); ijet != jets->end(); ++ijet) {
0048     // fill simple histograms
0049     pat::Jet jet = ijet->correctedJet("had", "uds");
0050     histContainer_["pt"]->Fill(jet.pt());
0051     histContainer_["eta"]->Fill(jet.eta());
0052     histContainer_["phi"]->Fill(jet.phi());
0053     histContainer_["emf"]->Fill(jet.emEnergyFraction());
0054     for (unsigned int i = 0; i < jet.getCaloConstituents().size(); ++i) {
0055       histContainer_["dEta"]->Fill(jet.getCaloConstituent(i)->eta() - jet.eta());
0056     }
0057   }
0058 }
0059 
0060 void PatZjetsJetAnalyzer::beginJob() {
0061   // register to the TFileService
0062   edm::Service<TFileService> fs;
0063 
0064   // book histograms:
0065   histContainer_["pt"] = fs->make<TH1F>("pt", "pt", 150, 0., 150.);
0066   histContainer_["eta"] = fs->make<TH1F>("eta", "eta", 50, 0., 5.);
0067   histContainer_["phi"] = fs->make<TH1F>("phi", "phi", 60, 3.14, 3.14);
0068   histContainer_["emf"] = fs->make<TH1F>("emf", "emf", 40, 0., 1.);
0069   histContainer_["dEta"] = fs->make<TH1F>("dEta", "dEta", 40, 0., 1.);
0070 }
0071 
0072 void PatZjetsJetAnalyzer::endJob() {}
0073 
0074 #include "FWCore/Framework/interface/MakerMacros.h"
0075 DEFINE_FWK_MODULE(PatZjetsJetAnalyzer);