Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:41

0001 // -*- C++ -*-
0002 //
0003 // Package:    SkimmingForB/LeptonSkimming
0004 // Class:      LeptonSkimming
0005 //
0006 /**\class LeptonSkimming LeptonSkimming.cc SkimmingForB/LeptonSkimming/plugins/LeptonSkimming.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Georgios Karathanasis georgios.karathanasis@cern.ch
0015 //         Created:  Thu, 29 Nov 2018 15:23:09 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDFilter.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "FWCore/Utilities/interface/StreamID.h"
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "DataFormats/Common/interface/Handle.h"
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0034 #include "DataFormats/PatCandidates/interface/Electron.h"
0035 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0036 #include "DataFormats/VertexReco/interface/Vertex.h"
0037 #include "DataFormats/EgammaCandidates/interface/ConversionFwd.h"
0038 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
0039 #include "CommonTools/Egamma/interface/ConversionTools.h"
0040 #include "DataFormats/Common/interface/TriggerResults.h"
0041 #include "FWCore/Common/interface/TriggerNames.h"
0042 #include "FWCore/ServiceRegistry/interface/Service.h"
0043 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0044 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0045 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0046 #include "FWCore/PluginManager/interface/ModuleDef.h"
0047 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0048 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0049 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
0050 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateIsolation.h"
0051 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0052 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateIsolation.h"
0053 #include "DataFormats/Common/interface/AssociationMap.h"
0054 #include "HLTrigger/HLTcore/interface/HLTFilter.h"
0055 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0056 #include "DataFormats/TrackReco/interface/Track.h"
0057 #include "DataFormats/MuonReco/interface/Muon.h"
0058 #include "FWCore/Common/interface/TriggerNames.h"
0059 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0060 #include "MagneticField/Engine/interface/MagneticField.h"
0061 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0062 #include "TrackingTools/IPTools/interface/IPTools.h"
0063 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexFitter.h"
0064 #include "L1Trigger/L1TNtuples/interface/MuonID.h"
0065 #include <vector>
0066 #include <string>
0067 #include <iostream>
0068 #include "DataFormats/Common/interface/Ref.h"
0069 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0070 #include "DataFormats/TrackReco/interface/Track.h"
0071 #include "CommonTools/Statistics/interface/ChiSquaredProbability.h"
0072 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
0073 #include "TLorentzVector.h"
0074 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
0075 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
0076 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0077 #include "DataFormats/Math/interface/deltaR.h"
0078 #include <cmath>
0079 
0080 //
0081 // class declaration
0082 //
0083 
0084 class LeptonSkimming : public edm::stream::EDFilter<> {
0085 public:
0086   explicit LeptonSkimming(const edm::ParameterSet&);
0087   ~LeptonSkimming() override;
0088 
0089   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0090 
0091 private:
0092   void beginStream(edm::StreamID) override;
0093   bool filter(edm::Event&, const edm::EventSetup&) override;
0094   void endStream() override;
0095 
0096   bool hltFired(const edm::Event& iEvent, const edm::EventSetup& iSetup, std::vector<string> HLTPath);
0097   std::array<float, 5> hltObject(const edm::Event& iEvent, const edm::EventSetup& iSetup, std::vector<string> Seed);
0098 
0099   edm::EDGetToken electronsToken_;
0100   edm::EDGetTokenT<edm::ValueMap<float>> eleBWPToken_;
0101   edm::EDGetTokenT<edm::ValueMap<float>> eleUnBWPToken_;
0102   edm::EDGetToken muonsToken_;
0103   edm::EDGetToken Tracks_;
0104   edm::EDGetTokenT<reco::VertexCollection> vtxToken_;
0105   edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
0106   edm::EDGetTokenT<reco::ConversionCollection> conversionsToken_;
0107   edm::EDGetTokenT<edm::TriggerResults> trgresultsToken_;
0108   edm::EDGetTokenT<trigger::TriggerEvent> trigobjectsToken_;
0109   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> bFieldToken_;
0110   std::vector<string> HLTFilter_, HLTPath_;
0111 
0112   bool Result = false;
0113   float beam_x, beam_y, beam_z;
0114 
0115   std::vector<float> track_vx, track_vy, track_vz;
0116   std::vector<float> muon_pt, muon_eta, muon_phi, el_pt, el_eta, el_phi, muon_soft, muon_medium, muon_tight;
0117   std::vector<unsigned int> Epair_ObjectIndex, Epair_TrkIndex, Epair_ObjectId;
0118 
0119   std::vector<float> SelectedTrgObj_PtEtaPhiCharge;
0120   int SelectedMu_index;
0121 
0122   float SelectedMu_DR = -1;
0123   float ZvertexTrg = -1 * std::numeric_limits<float>::max();
0124   unsigned int trk_index = 0;
0125   reco::TrackBase::Point vertex_point;
0126   std::vector<float> tempPtEtaPhiM, tempXYZ;
0127   std::vector<std::shared_ptr<reco::Track>> cleanedObjTracks;
0128   std::vector<std::shared_ptr<reco::Track>> cleanedPairTracks;
0129   std::vector<std::shared_ptr<reco::Track>> MuTracks;
0130   std::vector<std::shared_ptr<reco::Track>> ElTracks;
0131   std::vector<std::shared_ptr<reco::Track>> cleanedTracks;
0132   std::vector<unsigned int> trackObj_container, trackPair_container;
0133   std::vector<unsigned int> Trk_container, object_container, object_id;
0134 
0135   unsigned int nel = 0, nmuons = 0, ntracks = 0;
0136   //options
0137   double PtTrack_Cut = 0;
0138   double EtaTrack_Cut = 10;
0139   double MinChi2Track_Cut = -1000;
0140   double MaxChi2Track_Cut = 1000;
0141   double MuTrkMinDR_Cut = 0;
0142   double MaxMee_Cut = 1000;
0143   double PtKTrack_Cut = 0;
0144   double MaxMB_Cut = 1000;
0145   double MinMB_Cut = 0;
0146   bool SaveOnlyTracks = false;
0147   bool SaveOnlyEPairTracks = false;
0148   double TrackSdxy_Cut = 0;
0149   bool UseOnlyBKeeMCForTriplets = false;
0150   double MinMee_Cut = 0;
0151   double Probee_Cut = 0;
0152   double Cosee_Cut = -1;
0153   bool EarlyStop = false;
0154   double MuTrgMatchCone = 1000;
0155   bool SkipIfNoMuMatch = false;
0156   double EpairZvtx_Cut = 10000000;
0157   double Ksdxy_Cut = 1000;
0158   double ProbeeK_Cut = 0;
0159   double CoseeK_Cut = 0;
0160   double TrackMuDz_Cut = 100000000;
0161   double TrgExclusionCone = -1;
0162   double SLxy_Cut = 0;
0163   double PtB_Cut = 0;
0164   double PtMu_Cut = 0;
0165   double QualMu_Cut = 0;
0166   double PtEl_Cut = 0;
0167   double MuTrgExclusionCone = 0;
0168   double ElTrgExclusionCone = 0;
0169   double TrkObjExclusionCone = 0;
0170   double MuTrgMuDz_Cut = 1000;
0171   double ElTrgMuDz_Cut = 1000;
0172   bool SaveOutputRoot = true;
0173   bool ObjPtLargerThanTrack = false;
0174   double BiasedWP = -100;
0175   double UnbiasedWP = -100;
0176   bool SkimOnlyMuons = false;
0177   bool SkimOnlyElectrons = false;
0178   int test_ev = 0;
0179   // ----------member data ---------------------------
0180 };