CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoHI/HiEgammaAlgos/plugins/HiEgammaIsolationProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    PatAlgos
00004 // Class:      HiEgammaIsolationProducer
00005 // 
00013 //
00014 // Original Author:  Yen-Jie Lee
00015 //
00016 //
00017 
00018 
00019 // system include files
00020 #include <memory>
00021 
00022 // user include files
00023 #include "FWCore/Framework/interface/Frameworkfwd.h"
00024 #include "FWCore/Framework/interface/EDProducer.h"
00025 
00026 #include "FWCore/Framework/interface/Event.h"
00027 #include "FWCore/Framework/interface/MakerMacros.h"
00028 
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 #include "FWCore/Utilities/interface/InputTag.h"
00031 
00032 
00033 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00034 
00035 #include "DataFormats/Common/interface/View.h"
00036 #include "DataFormats/Common/interface/ValueMap.h"
00037 #include "DataFormats/Common/interface/OwnVector.h"
00038 
00039 #include "RecoHI/HiEgammaAlgos/interface/CxCalculator.h"
00040 #include "RecoHI/HiEgammaAlgos/interface/RxCalculator.h"
00041 #include "RecoHI/HiEgammaAlgos/interface/TxyCalculator.h"
00042 #include "RecoHI/HiEgammaAlgos/interface/dRxyCalculator.h"
00043 
00044 #include <string>
00045 
00046 namespace edm { using ::std::advance; }
00047 
00048 //
00049 // class decleration
00050 //
00051 
00052 class HiEgammaIsolationProducer : public edm::EDProducer {
00053    public:
00054       explicit HiEgammaIsolationProducer(const edm::ParameterSet&);
00055       ~HiEgammaIsolationProducer();
00056 
00057 
00058    private:
00059       virtual void produce(edm::Event&, const edm::EventSetup&);
00060 
00061       // ----------member data ---------------------------
00062       edm::InputTag photons_;
00063       edm::InputTag barrelBCLabel_;
00064       edm::InputTag endcapBCLabel_;
00065       edm::InputTag hfLabel_;
00066       edm::InputTag hoLabel_;
00067       edm::InputTag hbheLabel_;
00068       edm::InputTag trackLabel_;
00069       
00070       std::string   label_;
00071       enum IsoMode { calcCx, calcRx, calcTxy, calcDRxy, calcErr };
00072       double x_;
00073       double y_;
00074       IsoMode var_;
00075       int mode_;
00076 };
00077 
00078 //
00079 // constructors and destructor
00080 //
00081 HiEgammaIsolationProducer::HiEgammaIsolationProducer(const edm::ParameterSet& iConfig):
00082   photons_(iConfig.getParameter<edm::InputTag>("photons")),
00083   barrelBCLabel_(iConfig.getParameter<edm::InputTag>("barrelBasicCluster")),
00084   endcapBCLabel_(iConfig.getParameter<edm::InputTag>("endcapBasicCluster")),
00085   hfLabel_(iConfig.getParameter<edm::InputTag>("hfreco")),
00086   hoLabel_(iConfig.getParameter<edm::InputTag>("horeco")),
00087   hbheLabel_(iConfig.getParameter<edm::InputTag>("hbhereco")),
00088   trackLabel_(iConfig.getParameter<edm::InputTag>("track")),
00089   label_(iConfig.existsAs<std::string>("label") ? iConfig.getParameter<std::string>("label") : ""),
00090   x_(iConfig.getParameter<double>("x")),
00091   y_(iConfig.getParameter<double>("y")),
00092   var_(iConfig.getParameter<std::string>("iso") == "Cx" ? calcCx :
00093        iConfig.getParameter<std::string>("iso") == "Rx" ? calcRx :
00094        iConfig.getParameter<std::string>("iso") == "Txy" ? calcTxy :
00095        iConfig.getParameter<std::string>("iso") == "dRxy" ? calcDRxy : calcErr ),
00096   mode_( iConfig.getParameter<std::string>("mode") == "BackgroundSubtracted" ? 1 : 0)
00097 {
00098       produces<edm::ValueMap<float> >();
00099 }
00100 
00101 
00102 HiEgammaIsolationProducer::~HiEgammaIsolationProducer()
00103 {
00104 }
00105 
00106 // ------------ method called to for each event  ------------
00107 void
00108 HiEgammaIsolationProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00109 {
00110    using namespace edm;
00111    using namespace std;
00112 
00113    Handle<View<reco::Photon> > recoPhotons;
00114    iEvent.getByLabel(photons_, recoPhotons);
00115    //std::cout << "Got " << recoPhotons->size() << " photons" << std::endl;
00116    //std::cout << "mode "<<mode_<<std::endl;
00117    vector<float> floats(recoPhotons->size(), -100);
00118    
00119    CxCalculator   CxC(iEvent,iSetup,barrelBCLabel_,endcapBCLabel_);
00120    RxCalculator   RxC(iEvent,iSetup,hbheLabel_,hfLabel_,hoLabel_);
00121    TxyCalculator  TxyC(iEvent,iSetup,trackLabel_);
00122    dRxyCalculator dRxyC(iEvent,iSetup,trackLabel_);
00123 
00124    for (size_t i = 0; i < recoPhotons->size(); ++i) {
00125       if (var_ == calcRx) {
00126          if (mode_ == 1) {
00127             floats[i] = RxC.getCRx((*recoPhotons)[i].superCluster(),x_,0);
00128          } else {
00129             floats[i] = RxC.getRx((*recoPhotons)[i].superCluster(),x_,0);
00130          }
00131       } else if (var_ == calcCx) {
00132          if (mode_ == 1) {
00133             floats[i] = CxC.getCCx((*recoPhotons)[i].superCluster(),x_,0);
00134          } else {
00135             floats[i] = CxC.getCx((*recoPhotons)[i].superCluster(),x_,0);
00136          }
00137       } else if (var_ == calcTxy) {
00138          if (mode_ == 1) {
00139             // No background subtraction for the moment...
00140             floats[i] = TxyC.getTxy((*recoPhotons)[i],x_,y_);
00141          } else {
00142             floats[i] = TxyC.getTxy((*recoPhotons)[i],x_,y_);
00143          }
00144       } else if (var_ == calcDRxy) {
00145          if (mode_ == 1) {
00146             // No background subtraction for the moment...
00147             floats[i] = dRxyC.getDRxy((*recoPhotons)[i],x_,y_);
00148          } else {
00149             floats[i] = dRxyC.getDRxy((*recoPhotons)[i],x_,y_);
00150          }
00151       }
00152    }
00153 
00154    auto_ptr<ValueMap<float> > pis(new ValueMap<float>());
00155    ValueMap<float>::Filler floatfiller(*pis);
00156    floatfiller.insert(recoPhotons, floats.begin(), floats.end());
00157    floatfiller.fill();
00158    iEvent.put(pis);
00159    
00160 
00161 }
00162 
00163 //define this as a plug-in
00164 DEFINE_FWK_MODULE(HiEgammaIsolationProducer);