Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:42

0001 // -*- C++ -*-
0002 //
0003 // Package:    PatAlgos
0004 // Class:      PATHIPhotonTestModule
0005 //
0006 /**\class PATHIPhotonTestModule PATHIPhotonTestModule.cc PhysicsTools/PatAlgos/test/PATHIPhotonTestModule.cc
0007 
0008  Description: Test Photon isolation variables in PAT
0009 
0010  Implementation:
0011  
0012  this analyzer shows how to loop over PAT output. 
0013 */
0014 //
0015 // Original Author:  Yen-Jie Lee
0016 //         Created:  Mon July 1 11:53:50 EST 2009
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/EDAnalyzer.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/Utilities/interface/InputTag.h"
0032 
0033 #include "FWCore/ServiceRegistry/interface/Service.h"
0034 
0035 #include "DataFormats/PatCandidates/interface/Photon.h"
0036 
0037 #include "DataFormats/Common/interface/View.h"
0038 #include "DataFormats/Common/interface/ValueMap.h"
0039 #include "DataFormats/Common/interface/OwnVector.h"
0040 
0041 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0042 
0043 #include <string>
0044 #include "TNtuple.h"
0045 
0046 namespace edm {
0047   using ::std::advance;
0048 }
0049 
0050 //
0051 // class decleration
0052 //
0053 
0054 class PATHIPhotonTestModule : public edm::EDAnalyzer {
0055 public:
0056   explicit PATHIPhotonTestModule(const edm::ParameterSet&);
0057   ~PATHIPhotonTestModule();
0058 
0059 private:
0060   virtual void beginJob();
0061   virtual void analyze(const edm::Event&, const edm::EventSetup&);
0062   virtual void endJob();
0063 
0064   // ----------member data ---------------------------
0065   edm::InputTag photons_;
0066   std::string label_;
0067   enum TestMode { TestRead, TestWrite, TestExternal };
0068   TestMode mode_;
0069   TNtuple* datatemp;
0070   edm::Service<TFileService> fs;
0071 };
0072 
0073 //
0074 // constructors and destructor
0075 //
0076 PATHIPhotonTestModule::PATHIPhotonTestModule(const edm::ParameterSet& iConfig)
0077     : photons_(iConfig.getParameter<edm::InputTag>("photons")) {}
0078 
0079 PATHIPhotonTestModule::~PATHIPhotonTestModule() {}
0080 
0081 // ------------ method called to for each event  ------------
0082 void PATHIPhotonTestModule::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0083   using namespace edm;
0084 
0085   edm::Handle<edm::View<pat::Photon>> photons;
0086   iEvent.getByLabel(photons_, photons);
0087 
0088   auto output = std::make_unique<std::vector<pat::Photon>>();
0089 
0090   for (edm::View<pat::Photon>::const_iterator photon = photons->begin(), end = photons->end(); photon != end;
0091        ++photon) {
0092     Float_t var[100];
0093 
0094     int idx = 0;
0095     var[idx] = photon->et();
0096     idx++;
0097 
0098     for (int i = 1; i < 6; i++) {
0099       var[idx] = photon->userFloat(Form("isoCC%d", i));
0100       idx++;
0101     }
0102 
0103     for (int i = 1; i < 6; i++) {
0104       var[idx] = photon->userFloat(Form("isoCR%d", i));
0105       idx++;
0106     }
0107 
0108     for (int i = 1; i < 5; i++) {
0109       for (int j = 1; j < 5; j++) {
0110         var[idx] = photon->userFloat(Form("isoT%d%d", i, j));
0111         idx++;
0112       }
0113     }
0114 
0115     for (int i = 1; i < 5; i++) {
0116       for (int j = 1; j < 5; j++) {
0117         var[idx] = photon->userFloat(Form("isoDR%d%d", i, j));
0118         idx++;
0119       }
0120     }
0121 
0122     var[idx] = photon->e3x3();
0123     idx++;
0124     var[idx] = photon->e5x5();
0125     idx++;
0126 
0127     datatemp->Fill(var);
0128   }
0129 }
0130 
0131 // ------------ method called once each job just before starting event loop  ------------
0132 void PATHIPhotonTestModule::beginJob() {
0133   datatemp = fs->make<TNtuple>("gammas",
0134                                "photon candidate info",
0135                                "et:"
0136                                "cC1:cC2:cC3:cC4:cC5:cR1:cR2:cR3:cR4:cR5:"
0137                                "T11:T12:T13:T14:"
0138                                "T21:T22:T23:T24:"
0139                                "T31:T32:T33:T34:"
0140                                "T41:T42:T43:T44:"
0141                                "dR11:dR12:dR13:dR14:"
0142                                "dR21:dR22:dR23:dR24:"
0143                                "dR31:dR32:dR33:dR34:"
0144                                "dR41:dR42:dR43:dR44");
0145 }
0146 
0147 // ------------ method called once each job just after ending the event loop  ------------
0148 void PATHIPhotonTestModule::endJob() {}
0149 
0150 //define this as a plug-in
0151 DEFINE_FWK_MODULE(PATHIPhotonTestModule);