Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:33:55

0001 #include "RecoEgamma/PhotonIdentification/plugins/PhotonIDProducer.h"
0002 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0003 #include "DataFormats/Common/interface/ValueMap.h"
0004 
0005 PhotonIDProducer::PhotonIDProducer(const edm::ParameterSet& conf) : conf_(conf) {
0006   photonToken_ = consumes<reco::PhotonCollection>(
0007       edm::InputTag(conf_.getParameter<std::string>("photonProducer"), conf_.getParameter<std::string>("photonLabel")));
0008 
0009   photonCutBasedIDLooseLabel_ = conf.getParameter<std::string>("photonCutBasedIDLooseLabel");
0010   photonCutBasedIDTightLabel_ = conf.getParameter<std::string>("photonCutBasedIDTightLabel");
0011   photonCutBasedIDLooseEMLabel_ = conf.getParameter<std::string>("photonCutBasedIDLooseEMLabel");
0012 
0013   doCutBased_ = conf_.getParameter<bool>("doCutBased");
0014   cutBasedAlgo_ = new CutBasedPhotonIDAlgo();
0015   cutBasedAlgo_->setup(conf);
0016   produces<edm::ValueMap<bool>>(photonCutBasedIDLooseLabel_);
0017   produces<edm::ValueMap<bool>>(photonCutBasedIDTightLabel_);
0018   produces<edm::ValueMap<bool>>(photonCutBasedIDLooseEMLabel_);
0019 }
0020 
0021 PhotonIDProducer::~PhotonIDProducer() {
0022   //if (doCutBased_)
0023   delete cutBasedAlgo_;
0024 }
0025 
0026 void PhotonIDProducer::produce(edm::Event& e, const edm::EventSetup& c) {
0027   // Read in photons
0028   edm::Handle<reco::PhotonCollection> photons;
0029   e.getByToken(photonToken_, photons);
0030 
0031   // Loop over photons and calculate photon ID using specified technique(s)
0032   reco::PhotonCollection::const_iterator photon;
0033   std::vector<bool> Loose;
0034   std::vector<bool> Tight;
0035   std::vector<bool> LooseEM;
0036   for (photon = (*photons).begin(); photon != (*photons).end(); ++photon) {
0037     bool LooseQual;
0038     bool TightQual;
0039     bool LooseEMQual;
0040     if (photon->isEB())
0041       cutBasedAlgo_->decideEB(&(*photon), LooseEMQual, LooseQual, TightQual);
0042     else
0043       cutBasedAlgo_->decideEE(&(*photon), LooseEMQual, LooseQual, TightQual);
0044     LooseEM.push_back(LooseEMQual);
0045     Loose.push_back(LooseQual);
0046     Tight.push_back(TightQual);
0047   }
0048 
0049   auto outlooseEM = std::make_unique<edm::ValueMap<bool>>();
0050   edm::ValueMap<bool>::Filler fillerlooseEM(*outlooseEM);
0051   fillerlooseEM.insert(photons, LooseEM.begin(), LooseEM.end());
0052   fillerlooseEM.fill();
0053   // and put it into the event
0054   e.put(std::move(outlooseEM), photonCutBasedIDLooseEMLabel_);
0055 
0056   auto outloose = std::make_unique<edm::ValueMap<bool>>();
0057   edm::ValueMap<bool>::Filler fillerloose(*outloose);
0058   fillerloose.insert(photons, Loose.begin(), Loose.end());
0059   fillerloose.fill();
0060   // and put it into the event
0061   e.put(std::move(outloose), photonCutBasedIDLooseLabel_);
0062 
0063   auto outtight = std::make_unique<edm::ValueMap<bool>>();
0064   edm::ValueMap<bool>::Filler fillertight(*outtight);
0065   fillertight.insert(photons, Tight.begin(), Tight.end());
0066   fillertight.fill();
0067   // and put it into the event
0068   e.put(std::move(outtight), photonCutBasedIDTightLabel_);
0069 }