Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef RECOEGAMMA_EGAMMAISOLATIONALGOS_ELETKISOLFROMCANDS_H
0002 #define RECOEGAMMA_EGAMMAISOLATIONALGOS_ELETKISOLFROMCANDS_H
0003 
0004 #include "CommonTools/Utils/interface/KinematicColumns.h"
0005 #include "DataFormats/TrackReco/interface/TrackBase.h"
0006 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0007 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0008 #include "FWCore/SOA/interface/Table.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0011 
0012 //author S. Harper (RAL)
0013 //this class does a simple calculation of the track isolation for a track with eta,
0014 //phi and z vtx (typically the GsfTrack of the electron). It uses
0015 //PFPackedCandidates as proxies for the tracks. It now has been upgraded to
0016 //take general tracks as input also
0017 //
0018 //Note: due to rounding and space saving issues, the isolation calculated on tracks and
0019 //PFPackedCandidates will differ slightly even if the same cuts are used. These differences
0020 //are thought to be inconsquencial but as such its important to remake the PFPackedCandidates
0021 //in RECO/AOD if you want to be consistant with miniAOD
0022 //
0023 //The track version is more for variables that are stored in the electron rather than
0024 //objects which are recomputed on the fly for AOD/miniAOD
0025 //
0026 //Note, the tracks in miniAOD have additional cuts on and are missing algo information so this
0027 //has to be taken into account when using them
0028 
0029 //new for 9X:
0030 //  1) its now possible to use generalTracks as input
0031 //  2) adapted to 9X PF packed candidate improvements
0032 //  2a) the PF packed candidates now store the pt of the track in addition to the pt of the
0033 //      candidate. This means there is no need to pass in the electron collection any more
0034 //      to try and undo the electron e/p combination when the candidate is an electron
0035 //  2b) we now not only store the GsfTrack of the electron but also the general track of the electron
0036 //      there are three input collections now:
0037 //         packedPFCandidates : all PF candidates (with the track for ele candidates being the gsftrack)
0038 //         lostTracks : all tracks which were not made into a PFCandidate but passed some preselection
0039 //         lostTracks::eleTracks : KF electron tracks
0040 //      as such to avoid double counting the GSF and KF versions of an electron track, we now need to
0041 //      specify if the electron PF candidates are to be rejected in the sum over that collection or not.
0042 //      Note in all this, I'm not concerned about the electron in questions track, that will be rejected,
0043 //      I'm concerned about near by fake electrons which have been recoed by PF
0044 //      This is handled by the PIDVeto, which obviously is only used/required when using PFCandidates
0045 
0046 class EleTkIsolFromCands {
0047 public:
0048   struct TrkCuts {
0049     float minPt;
0050     float minDR2;
0051     float maxDR2;
0052     float minDEta;
0053     float maxDZ;
0054     float minHits;
0055     float minPixelHits;
0056     float maxDPtPt;
0057     std::vector<reco::TrackBase::TrackQuality> allowedQualities;
0058     std::vector<reco::TrackBase::TrackAlgorithm> algosToReject;
0059     explicit TrkCuts(const edm::ParameterSet& para);
0060     static edm::ParameterSetDescription pSetDescript();
0061   };
0062 
0063   struct Configuration {
0064     explicit Configuration(const edm::ParameterSet& para)
0065         : barrelCuts(para.getParameter<edm::ParameterSet>("barrelCuts")),
0066           endcapCuts(para.getParameter<edm::ParameterSet>("endcapCuts")) {}
0067     const TrkCuts barrelCuts;
0068     const TrkCuts endcapCuts;
0069   };
0070 
0071   enum class PIDVeto {
0072     NONE = 0,
0073     ELES,
0074     NONELES,
0075   };
0076 
0077   explicit EleTkIsolFromCands(Configuration const& cfg, reco::TrackCollection const& tracks)
0078       : cfg_{cfg}, tracks_{&tracks} {}
0079   explicit EleTkIsolFromCands(Configuration const& cfg,
0080                               pat::PackedCandidateCollection const& cands,
0081                               PIDVeto pidVeto = PIDVeto::NONE)
0082       : cfg_{cfg}, cands_{&cands}, pidVeto_{pidVeto} {}
0083 
0084   static edm::ParameterSetDescription pSetDescript();
0085 
0086   static PIDVeto pidVetoFromStr(const std::string& vetoStr);
0087 
0088   struct Output {
0089     const int nTracks;
0090     const float ptSum;
0091   };
0092 
0093   Output operator()(const reco::TrackBase& electronTrack);
0094 
0095 private:
0096   // For each electron, we want to try out which tracks are in a cone around
0097   // it. However, this will get expensive if there are many electrons and
0098   // tracks (Phase II conditions). In particular, calling
0099   // reco::TrackBase::eta() many times is costy because eta is not precomputed.
0100   // To solve this, we first cache the tracks in a simpler data structure in
0101   // which eta is already computed (TrackTable). Furthermore, the tracks are
0102   // preselected by the cuts that can already be applied without considering
0103   // the electron. Note that this has to be done twice, because the required
0104   // preselection is different for barrel and endcap electrons.
0105 
0106   using TrackTable = edm::soa::Table<edm::soa::col::Pt, edm::soa::col::Eta, edm::soa::col::Phi, edm::soa::col::Vz>;
0107 
0108   static bool passPIDVeto(const int pdgId, const EleTkIsolFromCands::PIDVeto pidVeto);
0109 
0110   static TrackTable preselectTracks(reco::TrackCollection const& tracks, TrkCuts const& cuts);
0111   static TrackTable preselectTracksFromCands(pat::PackedCandidateCollection const& cands,
0112                                              TrkCuts const& cuts,
0113                                              PIDVeto = PIDVeto::NONE);
0114 
0115   static bool passTrackPreselection(const reco::TrackBase& trk, float trkPt, const TrkCuts& cuts);
0116 
0117   //no qualities specified, accept all, ORed
0118   static bool passQual(const reco::TrackBase& trk, const std::vector<reco::TrackBase::TrackQuality>& quals);
0119   static bool passAlgo(const reco::TrackBase& trk, const std::vector<reco::TrackBase::TrackAlgorithm>& algosToRej);
0120 
0121   TrackTable const& getPreselectedTracks(bool isBarrel);
0122 
0123   Configuration const& cfg_;
0124 
0125   // All of these member variables are related to the caching of preselected tracks
0126   reco::TrackCollection const* tracks_ = nullptr;
0127   pat::PackedCandidateCollection const* cands_ = nullptr;
0128   const PIDVeto pidVeto_ = PIDVeto::NONE;
0129   TrackTable preselectedTracksWithBarrelCuts_;
0130   TrackTable preselectedTracksWithEndcapCuts_;
0131   bool tracksCachedForBarrelCuts_ = false;
0132   bool tracksCachedForEndcapCuts_ = false;
0133 };
0134 
0135 #endif