00001 #include "RecoEgamma/PhotonIdentification/plugins/PhotonIDProducer.h"
00002 #include "DataFormats/EgammaCandidates/interface/PhotonID.h"
00003 #include "DataFormats/EgammaCandidates/interface/PhotonIDAssociation.h"
00004 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00005 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 PhotonIDProducer::PhotonIDProducer(const edm::ParameterSet& conf) : conf_(conf) {
00016
00017 photonProducer_ = conf_.getParameter<std::string>("photonProducer");
00018 photonLabel_ = conf_.getParameter<std::string>("photonLabel");
00019 photonIDLabel_ = conf_.getParameter<std::string>("photonIDLabel");
00020 photonIDAssociation_ = conf_.getParameter<std::string>("photonIDAssociationLabel");
00021
00022 doCutBased_ = conf_.getParameter<bool>("doCutBased");
00023 cutBasedAlgo_ = new CutBasedPhotonIDAlgo();
00024 cutBasedAlgo_->setup(conf);
00025 produces<reco::PhotonIDCollection>(photonIDLabel_);
00026 produces<reco::PhotonIDAssociationCollection>(photonIDAssociation_);
00027
00028 }
00029
00030 PhotonIDProducer::~PhotonIDProducer() {
00031
00032
00033 delete cutBasedAlgo_;
00034
00035 }
00036
00037 void PhotonIDProducer::produce(edm::Event& e, const edm::EventSetup& c) {
00038
00039
00040 edm::Handle<reco::PhotonCollection> photons;
00041 e.getByLabel(photonProducer_,photonLabel_,photons);
00042
00043
00044 reco::PhotonIDCollection photonIDCollection;
00045 std::auto_ptr<reco::PhotonIDCollection> photonIDCollection_p(new reco::PhotonIDCollection);
00046
00047
00048 reco::PhotonCollection::const_iterator photon;
00049 for (photon = (*photons).begin();
00050 photon != (*photons).end(); ++photon) {
00051 reco::PhotonID phoID = cutBasedAlgo_->calculate(&(*photon),e, c);
00052 photonIDCollection.push_back(phoID);
00053 }
00054
00055
00056 photonIDCollection_p->assign(photonIDCollection.begin(),
00057 photonIDCollection.end());
00058 edm::OrphanHandle<reco::PhotonIDCollection> PhotonIDHandle = e.put(photonIDCollection_p,photonIDLabel_);
00059
00060
00061 std::auto_ptr<reco::PhotonIDAssociationCollection> photonIDAssocs_p(new reco::PhotonIDAssociationCollection);
00062 for (unsigned int i = 0; i < photons->size(); i++){
00063 photonIDAssocs_p->insert(edm::Ref<reco::PhotonCollection>(photons,i),edm::Ref<reco::PhotonIDCollection>(PhotonIDHandle,i));
00064 }
00065 e.put(photonIDAssocs_p,photonIDAssociation_);
00066
00067 }