Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:00

0001 /** \class GEDPhotonCoreProducer
0002  **  
0003  **
0004  **  \author Nancy Marinelli, U. of Notre Dame, US
0005  **
0006  ***/
0007 
0008 #include "DataFormats/Common/interface/Handle.h"
0009 #include "DataFormats/Common/interface/ValidHandle.h"
0010 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0011 #include "DataFormats/EgammaCandidates/interface/PhotonCore.h"
0012 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
0013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0014 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateEGammaExtra.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/stream/EDProducer.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 
0019 class GEDPhotonCoreProducer : public edm::stream::EDProducer<> {
0020 public:
0021   GEDPhotonCoreProducer(const edm::ParameterSet& ps);
0022 
0023   void produce(edm::Event& evt, const edm::EventSetup& es) override;
0024 
0025 private:
0026   const edm::EDGetTokenT<reco::PFCandidateCollection> pfEgammaCandidates_;
0027   const edm::EDGetTokenT<reco::ElectronSeedCollection> pixelSeedProducer_;
0028   const edm::EDPutTokenT<reco::PhotonCoreCollection> putToken_;
0029 };
0030 
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 DEFINE_FWK_MODULE(GEDPhotonCoreProducer);
0033 
0034 GEDPhotonCoreProducer::GEDPhotonCoreProducer(const edm::ParameterSet& config)
0035     : pfEgammaCandidates_{consumes(config.getParameter<edm::InputTag>("pfEgammaCandidates"))},
0036       pixelSeedProducer_{consumes(config.getParameter<edm::InputTag>("pixelSeedProducer"))},
0037       putToken_{produces<reco::PhotonCoreCollection>(config.getParameter<std::string>("gedPhotonCoreCollection"))} {}
0038 
0039 void GEDPhotonCoreProducer::produce(edm::Event& event, const edm::EventSetup&) {
0040   reco::PhotonCoreCollection outputPhotonCoreCollection;
0041 
0042   // Get the  PF refined cluster  collection
0043   auto pfCandidateHandle = edm::makeValid(event.getHandle(pfEgammaCandidates_));
0044 
0045   // Get ElectronPixelSeeds
0046   bool validPixelSeeds = true;
0047   auto pixelSeedHandle = event.getHandle(pixelSeedProducer_);
0048   if (!pixelSeedHandle.isValid()) {
0049     validPixelSeeds = false;
0050   }
0051 
0052   // Loop over PF candidates and get only photons
0053   for (auto const& cand : *pfCandidateHandle) {
0054     // Retrieve stuff from the pfPhoton
0055     auto const& pfPho = *cand.egammaExtraRef();
0056     reco::SuperClusterRef refinedSC = pfPho.superClusterRef();
0057     reco::SuperClusterRef boxSC = pfPho.superClusterPFECALRef();
0058 
0059     // Construct new PhotonCore
0060     outputPhotonCoreCollection.emplace_back();
0061     auto& newCandidate = outputPhotonCoreCollection.back();
0062 
0063     newCandidate.setPFlowPhoton(true);
0064     newCandidate.setStandardPhoton(false);
0065     newCandidate.setSuperCluster(refinedSC);
0066     newCandidate.setParentSuperCluster(boxSC);
0067 
0068     // Fill conversion infos
0069     for (auto const& conv : pfPho.conversionRef()) {
0070       newCandidate.addConversion(conv);
0071     }
0072     for (auto const& conv : pfPho.singleLegConversionRef()) {
0073       newCandidate.addOneLegConversion(conv);
0074     }
0075 
0076     //    std::cout << "newCandidate pf refined SC energy="<< newCandidate.superCluster()->energy()<<std::endl;
0077     //std::cout << "newCandidate pf SC energy="<< newCandidate.parentSuperCluster()->energy()<<std::endl;
0078     //std::cout << "newCandidate  nconv2leg="<<newCandidate.conversions().size()<< std::endl;
0079 
0080     if (validPixelSeeds) {
0081       for (unsigned int icp = 0; icp < pixelSeedHandle->size(); icp++) {
0082         reco::ElectronSeedRef cpRef(pixelSeedHandle, icp);
0083         if (boxSC.isNonnull() && boxSC.id() == cpRef->caloCluster().id() && boxSC.key() == cpRef->caloCluster().key()) {
0084           newCandidate.addElectronPixelSeed(cpRef);
0085         }
0086       }
0087     }
0088   }
0089 
0090   // put the product in the event
0091   event.emplace(putToken_, std::move(outputPhotonCoreCollection));
0092 }