CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoEgamma/PhotonIdentification/plugins/PhotonIDProducer.cc

Go to the documentation of this file.
00001 #include "RecoEgamma/PhotonIdentification/plugins/PhotonIDProducer.h"
00002 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00003 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
00004 #include "DataFormats/Common/interface/ValueMap.h"
00005 
00006 
00007 
00008 PhotonIDProducer::PhotonIDProducer(const edm::ParameterSet& conf) : conf_(conf) {
00009 
00010   photonProducer_ = conf_.getParameter<std::string>("photonProducer");
00011   photonLabel_ = conf_.getParameter<std::string>("photonLabel");
00012  
00013   photonCutBasedIDLooseLabel_ = conf.getParameter<std::string>("photonCutBasedIDLooseLabel");
00014   photonCutBasedIDTightLabel_ = conf.getParameter<std::string>("photonCutBasedIDTightLabel");
00015   photonCutBasedIDLooseEMLabel_ = conf.getParameter<std::string>("photonCutBasedIDLooseEMLabel");
00016 
00017   doCutBased_ = conf_.getParameter<bool>("doCutBased");
00018   cutBasedAlgo_ = new CutBasedPhotonIDAlgo();
00019   cutBasedAlgo_->setup(conf);
00020   produces<edm::ValueMap<Bool_t> > (photonCutBasedIDLooseLabel_);
00021   produces<edm::ValueMap<Bool_t> > (photonCutBasedIDTightLabel_);
00022   produces<edm::ValueMap<Bool_t> > (photonCutBasedIDLooseEMLabel_);
00023 
00024 }
00025 
00026 PhotonIDProducer::~PhotonIDProducer() {
00027 
00028   //if (doCutBased_)
00029   delete cutBasedAlgo_;
00030 
00031 }
00032 
00033 void PhotonIDProducer::produce(edm::Event& e, const edm::EventSetup& c) {
00034 
00035    // Read in photons
00036   edm::Handle<reco::PhotonCollection> photons;
00037   e.getByLabel(photonProducer_,photonLabel_,photons);
00038 
00039 
00040   // Loop over photons and calculate photon ID using specified technique(s)
00041   reco::PhotonCollection::const_iterator photon;
00042   std::vector <Bool_t> Loose;
00043   std::vector <Bool_t> Tight;
00044   std::vector <Bool_t> LooseEM;
00045   for (photon = (*photons).begin();
00046        photon != (*photons).end(); ++photon) {
00047     bool LooseQual;
00048     bool TightQual;
00049     bool LooseEMQual;
00050     if (photon->isEB())
00051       cutBasedAlgo_->decideEB(&(*photon),LooseEMQual,LooseQual, TightQual);
00052     else
00053       cutBasedAlgo_->decideEE(&(*photon),LooseEMQual,LooseQual, TightQual);
00054     LooseEM.push_back(LooseEMQual);
00055     Loose.push_back(LooseQual);
00056     Tight.push_back(TightQual);
00057     
00058   }
00059   
00060 
00061   std::auto_ptr<edm::ValueMap<Bool_t> > outlooseEM(new edm::ValueMap<Bool_t>());
00062   edm::ValueMap<Bool_t>::Filler fillerlooseEM(*outlooseEM);
00063   fillerlooseEM.insert(photons, LooseEM.begin(), LooseEM.end());
00064   fillerlooseEM.fill();
00065   // and put it into the event
00066   e.put(outlooseEM, photonCutBasedIDLooseEMLabel_);
00067 
00068   std::auto_ptr<edm::ValueMap<Bool_t> > outloose(new edm::ValueMap<Bool_t>());
00069   edm::ValueMap<Bool_t>::Filler fillerloose(*outloose);
00070   fillerloose.insert(photons, Loose.begin(), Loose.end());
00071   fillerloose.fill();
00072   // and put it into the event
00073   e.put(outloose, photonCutBasedIDLooseLabel_);
00074   
00075   std::auto_ptr<edm::ValueMap<Bool_t> > outtight(new edm::ValueMap<Bool_t>());
00076   edm::ValueMap<Bool_t>::Filler fillertight(*outtight);
00077   fillertight.insert(photons, Tight.begin(), Tight.end());
00078   fillertight.fill();
00079   // and put it into the event
00080   e.put(outtight, photonCutBasedIDTightLabel_);
00081   
00082   
00083 }