Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:09

0001 // -*- C++ -*-
0002 //
0003 // Package:    EgammaHLTProducers
0004 // Class:      EgammaHLTRecoEcalCandidateProducers
0005 //
0006 /**\class EgammaHLTRecoEcalCandidateProducers.h EgammaHLTRecoEcalCandidateProducers.cc  RecoEgamma/EgammaHLTProducers/interface/EgammaHLTRecoEcalCandidateProducers.h.h
0007 */
0008 //
0009 // Original Author:  Monica Vazquez Acosta (CERN)
0010 //         Created:  Tue Jun 13 14:48:33 CEST 2006
0011 // $Id:
0012 //
0013 //
0014 
0015 #include "FWCore/Framework/interface/global/EDProducer.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/ESHandle.h"
0020 
0021 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0022 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0023 
0024 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
0025 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateFwd.h"
0026 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0028 
0029 #include <iostream>
0030 #include <vector>
0031 #include <memory>
0032 
0033 class EgammaHLTRecoEcalCandidateProducers : public edm::global::EDProducer<> {
0034 public:
0035   EgammaHLTRecoEcalCandidateProducers(const edm::ParameterSet& ps);
0036   ~EgammaHLTRecoEcalCandidateProducers() override;
0037 
0038   void produce(edm::StreamID sid, edm::Event& evt, const edm::EventSetup& es) const override;
0039   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0040 
0041 private:
0042   const edm::EDGetTokenT<reco::SuperClusterCollection> scHybridBarrelProducer_;
0043   const edm::EDGetTokenT<reco::SuperClusterCollection> scIslandEndcapProducer_;
0044   const std::string recoEcalCandidateCollection_;
0045 };
0046 
0047 EgammaHLTRecoEcalCandidateProducers::EgammaHLTRecoEcalCandidateProducers(const edm::ParameterSet& config)
0048     : scHybridBarrelProducer_(
0049           consumes<reco::SuperClusterCollection>(config.getParameter<edm::InputTag>("scHybridBarrelProducer"))),
0050       scIslandEndcapProducer_(
0051           consumes<reco::SuperClusterCollection>(config.getParameter<edm::InputTag>("scIslandEndcapProducer"))),
0052       recoEcalCandidateCollection_(config.getParameter<std::string>("recoEcalCandidateCollection")) {
0053   // Register the product
0054   produces<reco::RecoEcalCandidateCollection>(recoEcalCandidateCollection_);
0055 }
0056 
0057 EgammaHLTRecoEcalCandidateProducers::~EgammaHLTRecoEcalCandidateProducers() {}
0058 
0059 void EgammaHLTRecoEcalCandidateProducers::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0060   edm::ParameterSetDescription desc;
0061   desc.add<edm::InputTag>(("scHybridBarrelProducer"), edm::InputTag("correctedHybridSuperClusters"));
0062   desc.add<edm::InputTag>(("scIslandEndcapProducer"), edm::InputTag("correctedEndcapSuperClustersWithPreshower"));
0063   desc.add<std::string>(("recoEcalCandidateCollection"), "");
0064   descriptions.add(("hltEgammaHLTRecoEcalCandidateProducers"), desc);
0065 }
0066 
0067 void EgammaHLTRecoEcalCandidateProducers::produce(edm::StreamID sid,
0068                                                   edm::Event& theEvent,
0069                                                   const edm::EventSetup&) const {
0070   using namespace edm;
0071 
0072   //
0073   // create empty output collections
0074   //
0075 
0076   reco::RecoEcalCandidateCollection outputRecoEcalCandidateCollection;
0077   auto outputRecoEcalCandidateCollection_p = std::make_unique<reco::RecoEcalCandidateCollection>();
0078 
0079   // Get the  Barrel Super Cluster collection
0080   Handle<reco::SuperClusterCollection> scBarrelHandle;
0081   theEvent.getByToken(scHybridBarrelProducer_, scBarrelHandle);
0082   // Get the  Endcap Super Cluster collection
0083   Handle<reco::SuperClusterCollection> scEndcapHandle;
0084   theEvent.getByToken(scIslandEndcapProducer_, scEndcapHandle);
0085 
0086   //  Loop over barrel SC and fill the  recoecal collection
0087   int iSC = 0;  // index in recoecal collection
0088   int lSC = 0;  // local index on barrel
0089 
0090   for (reco::SuperClusterCollection::const_iterator aClus = scBarrelHandle->begin(); aClus != scBarrelHandle->end();
0091        aClus++) {
0092     const reco::Particle::Point vtx(0, 0, 0);
0093 
0094     // compute correctly the momentum vector of the recoecal from primary vertex and cluster position
0095     math::XYZVector direction = aClus->position() - vtx;
0096     math::XYZVector momentum = direction.unit() * aClus->energy();
0097     const reco::Particle::LorentzVector p4(momentum.x(), momentum.y(), momentum.z(), aClus->energy());
0098 
0099     reco::RecoEcalCandidate newCandidate(0, p4, vtx);
0100 
0101     outputRecoEcalCandidateCollection.push_back(newCandidate);
0102     reco::SuperClusterRef scRef(reco::SuperClusterRef(scBarrelHandle, lSC));
0103     outputRecoEcalCandidateCollection[iSC].setSuperCluster(scRef);
0104 
0105     lSC++;
0106     iSC++;
0107   }
0108 
0109   //  Loop over Endcap SC and fill the  recoecal collection
0110   lSC = 0;  // reset local index for endcap
0111 
0112   for (reco::SuperClusterCollection::const_iterator aClus = scEndcapHandle->begin(); aClus != scEndcapHandle->end();
0113        aClus++) {
0114     const reco::Particle::Point vtx(0, 0, 0);
0115 
0116     math::XYZVector direction = aClus->position() - vtx;
0117     math::XYZVector momentum = direction.unit() * aClus->energy();
0118     const reco::Particle::LorentzVector p4(momentum.x(), momentum.y(), momentum.z(), aClus->energy());
0119 
0120     reco::RecoEcalCandidate newCandidate(0, p4, vtx);
0121 
0122     outputRecoEcalCandidateCollection.push_back(newCandidate);
0123     reco::SuperClusterRef scRef(reco::SuperClusterRef(scEndcapHandle, lSC));
0124     outputRecoEcalCandidateCollection[iSC].setSuperCluster(scRef);
0125 
0126     iSC++;
0127     lSC++;
0128   }
0129 
0130   // put the product in the event
0131   outputRecoEcalCandidateCollection_p->assign(outputRecoEcalCandidateCollection.begin(),
0132                                               outputRecoEcalCandidateCollection.end());
0133   theEvent.put(std::move(outputRecoEcalCandidateCollection_p), recoEcalCandidateCollection_);
0134 }
0135 
0136 #include "FWCore/Framework/interface/MakerMacros.h"
0137 DEFINE_FWK_MODULE(EgammaHLTRecoEcalCandidateProducers);