Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-06 09:40:14

0001 #include "CommonTools/Egamma/interface/ConversionTools.h"
0002 #include "CommonTools/Utils/interface/PtComparator.h"
0003 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0004 #include "DataFormats/Candidate/interface/CandAssociation.h"
0005 #include "DataFormats/Common/interface/Association.h"
0006 #include "DataFormats/Common/interface/ValueMap.h"
0007 #include "DataFormats/Common/interface/View.h"
0008 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0009 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
0010 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0011 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
0012 #include "DataFormats/Math/interface/LorentzVector.h"
0013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0014 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0015 #include "DataFormats/PatCandidates/interface/Conversion.h"
0016 #include "DataFormats/PatCandidates/interface/Electron.h"
0017 #include "DataFormats/PatCandidates/interface/UserData.h"
0018 #include "DataFormats/VertexReco/interface/Vertex.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/global/EDProducer.h"
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0023 #include "FWCore/ParameterSet/interface/FileInPath.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0026 #include "FWCore/Utilities/interface/InputTag.h"
0027 #include "PhysicsTools/PatAlgos/interface/EfficiencyLoader.h"
0028 #include "PhysicsTools/PatAlgos/interface/KinResolutionsLoader.h"
0029 #include "PhysicsTools/PatAlgos/interface/MultiIsolator.h"
0030 #include "PhysicsTools/PatAlgos/interface/PATUserDataHelper.h"
0031 #include "PhysicsTools/PatUtils/interface/CaloIsolationEnergy.h"
0032 #include "PhysicsTools/PatUtils/interface/TrackerIsolationPt.h"
0033 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
0034 #include "TrackingTools/IPTools/interface/IPTools.h"
0035 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
0036 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0037 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
0038 
0039 #include <memory>
0040 #include <string>
0041 #include <vector>
0042 
0043 namespace pat {
0044 
0045   class PATConversionProducer : public edm::global::EDProducer<> {
0046   public:
0047     explicit PATConversionProducer(const edm::ParameterSet &iConfig);
0048     ~PATConversionProducer() override;
0049 
0050     void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override;
0051 
0052   private:
0053     // configurables
0054     const edm::EDGetTokenT<edm::View<reco::GsfElectron> > electronToken_;
0055     const edm::EDGetTokenT<reco::BeamSpot> bsToken_;
0056     const edm::EDGetTokenT<reco::ConversionCollection> conversionsToken_;
0057   };
0058 
0059 }  // namespace pat
0060 
0061 using namespace pat;
0062 using namespace std;
0063 
0064 PATConversionProducer::PATConversionProducer(const edm::ParameterSet &iConfig)
0065     : electronToken_(consumes<edm::View<reco::GsfElectron> >(iConfig.getParameter<edm::InputTag>("electronSource"))),
0066       bsToken_(consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot"))),
0067       conversionsToken_(consumes<reco::ConversionCollection>(edm::InputTag("allConversions"))) {
0068   // produces vector of muons
0069   produces<std::vector<Conversion> >();
0070 }
0071 
0072 PATConversionProducer::~PATConversionProducer() {}
0073 
0074 void PATConversionProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0075   // Get the collection of electrons from the event
0076   edm::Handle<edm::View<reco::GsfElectron> > electrons;
0077   iEvent.getByToken(electronToken_, electrons);
0078 
0079   edm::Handle<reco::BeamSpot> bsHandle;
0080   iEvent.getByToken(bsToken_, bsHandle);
0081   const reco::BeamSpot &beamspot = *bsHandle.product();
0082 
0083   // for conversion veto selection
0084   edm::Handle<reco::ConversionCollection> hConversions;
0085   iEvent.getByToken(conversionsToken_, hConversions);
0086 
0087   std::vector<Conversion> *patConversions = new std::vector<Conversion>();
0088 
0089   for (reco::ConversionCollection::const_iterator conv = hConversions->begin(); conv != hConversions->end(); ++conv) {
0090     reco::Vertex vtx = conv->conversionVertex();
0091 
0092     int index = 0;
0093     for (edm::View<reco::GsfElectron>::const_iterator itElectron = electrons->begin(); itElectron != electrons->end();
0094          ++itElectron) {
0095       //find matched conversions with electron and save those conversions with matched electron index
0096       if (ConversionTools::matchesConversion(*itElectron, *conv)) {
0097         double vtxProb = TMath::Prob(vtx.chi2(), vtx.ndof());
0098         math::XYZVector mom(conv->refittedPairMomentum());
0099         double dbsx = vtx.x() - beamspot.position().x();
0100         double dbsy = vtx.y() - beamspot.position().y();
0101         double lxy = (mom.x() * dbsx + mom.y() * dbsy) / mom.rho();
0102         int nHitsMax = 0;
0103 
0104         for (std::vector<uint8_t>::const_iterator it = conv->nHitsBeforeVtx().begin();
0105              it != conv->nHitsBeforeVtx().end();
0106              ++it) {
0107           if ((*it) > nHitsMax)
0108             nHitsMax = (*it);
0109         }
0110 
0111         pat::Conversion anConversion(index);
0112         anConversion.setVtxProb(vtxProb);
0113         anConversion.setLxy(lxy);
0114         anConversion.setNHitsMax(nHitsMax);
0115 
0116         patConversions->push_back(anConversion);
0117         break;
0118       }
0119       index++;
0120     }
0121   }
0122 
0123   // add the electrons to the event output
0124   std::unique_ptr<std::vector<Conversion> > ptr(patConversions);
0125   iEvent.put(std::move(ptr));
0126 }
0127 
0128 #include "FWCore/Framework/interface/MakerMacros.h"
0129 DEFINE_FWK_MODULE(PATConversionProducer);