Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //******************************************************************************
0002 //
0003 // Part of the refactorisation of of the E/gamma pixel matching for 2017 pixels
0004 // This refactorisation converts the monolithic  approach to a series of
0005 // independent producer modules, with each modules performing  a specific
0006 // job as recommended by the 2017 tracker framework
0007 //
0008 //
0009 // The module produces the ElectronSeeds, similarly to ElectronSeedProducer
0010 // although with a varible number of required hits
0011 //
0012 //
0013 // Author : Sam Harper (RAL), 2017
0014 //
0015 //*******************************************************************************
0016 
0017 #include "FWCore/Framework/interface/global/EDProducer.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/EventSetup.h"
0020 #include "FWCore/Framework/interface/ConsumesCollector.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/Utilities/interface/EDGetToken.h"
0025 
0026 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0027 #include "DataFormats/VertexReco/interface/Vertex.h"
0028 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0029 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0030 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
0031 #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
0032 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0033 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0034 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0035 
0036 #include "RecoEgamma/EgammaElectronAlgos/interface/TrajSeedMatcher.h"
0037 
0038 class ElectronNHitSeedProducer : public edm::global::EDProducer<> {
0039 public:
0040   explicit ElectronNHitSeedProducer(const edm::ParameterSet&);
0041 
0042   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const final;
0043 
0044   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046 private:
0047   const TrajSeedMatcher::Configuration matcherConfiguration_;
0048 
0049   std::vector<edm::EDGetTokenT<std::vector<reco::SuperClusterRef>>> superClustersTokens_;
0050   const edm::EDGetTokenT<TrajectorySeedCollection> initialSeedsToken_;
0051   const edm::EDGetTokenT<std::vector<reco::Vertex>> verticesToken_;
0052   const edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
0053   const edm::EDGetTokenT<MeasurementTrackerEvent> measTkEvtToken_;
0054   const edm::EDPutTokenT<reco::ElectronSeedCollection> putToken_;
0055   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> trackerTopologyToken_;
0056 };
0057 
0058 namespace {
0059   int getLayerOrDiskNr(DetId detId, const TrackerTopology& trackerTopo) {
0060     if (detId.subdetId() == PixelSubdetector::PixelBarrel) {
0061       return trackerTopo.pxbLayer(detId);
0062     } else if (detId.subdetId() == PixelSubdetector::PixelEndcap) {
0063       return trackerTopo.pxfDisk(detId);
0064     } else
0065       return -1;
0066   }
0067 
0068   reco::ElectronSeed::PMVars makeSeedPixelVar(const TrajSeedMatcher::MatchInfo& matchInfo,
0069                                               const TrackerTopology& trackerTopo) {
0070     int layerOrDisk = getLayerOrDiskNr(matchInfo.detId, trackerTopo);
0071     reco::ElectronSeed::PMVars pmVars;
0072     pmVars.setDet(matchInfo.detId, layerOrDisk);
0073     pmVars.setDPhi(matchInfo.dPhiPos, matchInfo.dPhiNeg);
0074     pmVars.setDRZ(matchInfo.dRZPos, matchInfo.dRZNeg);
0075 
0076     return pmVars;
0077   }
0078 
0079 }  // namespace
0080 
0081 ElectronNHitSeedProducer::ElectronNHitSeedProducer(const edm::ParameterSet& pset)
0082     : matcherConfiguration_(pset.getParameter<edm::ParameterSet>("matcherConfig"), consumesCollector()),
0083       initialSeedsToken_(consumes(pset.getParameter<edm::InputTag>("initialSeeds"))),
0084       verticesToken_(consumes(pset.getParameter<edm::InputTag>("vertices"))),
0085       beamSpotToken_(consumes(pset.getParameter<edm::InputTag>("beamSpot"))),
0086       measTkEvtToken_(consumes(pset.getParameter<edm::InputTag>("measTkEvt"))),
0087       putToken_{produces<reco::ElectronSeedCollection>()},
0088       trackerTopologyToken_{esConsumes()} {
0089   for (const auto& scTag : pset.getParameter<std::vector<edm::InputTag>>("superClusters")) {
0090     superClustersTokens_.emplace_back(consumes(scTag));
0091   }
0092 }
0093 
0094 void ElectronNHitSeedProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0095   edm::ParameterSetDescription desc;
0096   desc.add<edm::InputTag>("initialSeeds", {"hltElePixelSeedsCombined"});
0097   desc.add<edm::InputTag>("vertices", {});
0098   desc.add<edm::InputTag>("beamSpot", {"hltOnlineBeamSpot"});
0099   desc.add<edm::InputTag>("measTkEvt", {"hltSiStripClusters"});
0100   desc.add<std::vector<edm::InputTag>>("superClusters", {{"hltEgammaSuperClustersToPixelMatch"}});
0101   desc.add<edm::ParameterSetDescription>("matcherConfig", TrajSeedMatcher::makePSetDescription());
0102 
0103   descriptions.add("electronNHitSeedProducer", desc);
0104 }
0105 
0106 void ElectronNHitSeedProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0107   auto const& trackerTopology = iSetup.getData(trackerTopologyToken_);
0108 
0109   reco::ElectronSeedCollection eleSeeds{};
0110 
0111   TrajSeedMatcher matcher{iEvent.get(initialSeedsToken_),
0112                           iEvent.get(beamSpotToken_).position(),
0113                           matcherConfiguration_,
0114                           iSetup,
0115                           iEvent.get(measTkEvtToken_)};
0116 
0117   // Loop over all super-cluster collections (typically barrel and forward are supplied separately)
0118   for (const auto& superClustersToken : superClustersTokens_) {
0119     for (auto& superClusRef : iEvent.get(superClustersToken)) {
0120       //the eta of the supercluster when mustache clustered is slightly biased due to bending in magnetic field
0121       //the eta of its seed cluster is a better estimate of the orginal position
0122       GlobalPoint caloPosition(GlobalPoint::Polar(superClusRef->seed()->position().theta(),  //seed theta
0123                                                   superClusRef->position().phi(),            //supercluster phi
0124                                                   superClusRef->position().r()));            //supercluster r
0125 
0126       for (auto const& matchedSeed : matcher(caloPosition, superClusRef->energy())) {
0127         reco::ElectronSeed eleSeed(matchedSeed.seed);
0128         reco::ElectronSeed::CaloClusterRef caloClusRef(superClusRef);
0129         eleSeed.setCaloCluster(caloClusRef);
0130         eleSeed.setNrLayersAlongTraj(matchedSeed.nrValidLayers);
0131         for (auto const& matchInfo : matchedSeed.matchInfos) {
0132           eleSeed.addHitInfo(makeSeedPixelVar(matchInfo, trackerTopology));
0133         }
0134         eleSeeds.emplace_back(eleSeed);
0135       }
0136     }
0137   }
0138   iEvent.emplace(putToken_, std::move(eleSeeds));
0139 }
0140 
0141 #include "FWCore/Framework/interface/MakerMacros.h"
0142 DEFINE_FWK_MODULE(ElectronNHitSeedProducer);