CMS 3D CMS Logo

LeptonUpdater.cc
Go to the documentation of this file.
9 
14 
15 namespace pat {
16 
17  template <typename T>
19  public:
20  explicit LeptonUpdater(const edm::ParameterSet &iConfig)
21  : src_(consumes<std::vector<T>>(iConfig.getParameter<edm::InputTag>("src"))),
22  vertices_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("vertices"))),
23  beamLineToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamspot"))),
24  computeMiniIso_(iConfig.getParameter<bool>("computeMiniIso")),
25  fixDxySign_(iConfig.getParameter<bool>("fixDxySign")) {
26  //for mini-isolation calculation
27  if (computeMiniIso_) {
28  readMiniIsoParams(iConfig);
29  pcToken_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandsForMiniIso"));
30  }
32  if (typeid(T) == typeid(pat::Muon))
33  recomputeMuonBasicSelectors_ = iConfig.getParameter<bool>("recomputeMuonBasicSelectors");
34  produces<std::vector<T>>();
35  }
36 
37  ~LeptonUpdater() override {}
38 
39  void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override;
40 
41  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
43  desc.add<edm::InputTag>("src")->setComment("Lepton collection");
44  desc.add<edm::InputTag>("vertices")->setComment("Vertex collection");
45  desc.add<edm::InputTag>("beamspot", edm::InputTag("offlineBeamSpot"))->setComment("Beam spot");
46  desc.add<bool>("computeMiniIso", false)->setComment("Recompute miniIsolation");
47  desc.add<bool>("fixDxySign", false)->setComment("Fix the IP sign");
48  desc.addOptional<edm::InputTag>("pfCandsForMiniIso", edm::InputTag("packedPFCandidates"))
49  ->setComment("PackedCandidate collection used for miniIso");
50  if (typeid(T) == typeid(pat::Muon)) {
51  desc.add<bool>("recomputeMuonBasicSelectors", false)
52  ->setComment("Recompute basic cut-based muon selector flags");
53  desc.addOptional<std::vector<double>>("miniIsoParams")
54  ->setComment("Parameters used for miniIso (as in PATMuonProducer)");
55  descriptions.add("muonsUpdated", desc);
56  } else if (typeid(T) == typeid(pat::Electron)) {
57  desc.addOptional<std::vector<double>>("miniIsoParamsB")
58  ->setComment("Parameters used for miniIso in the barrel (as in PATElectronProducer)");
59  desc.addOptional<std::vector<double>>("miniIsoParamsE")
60  ->setComment("Parameters used for miniIso in the endcap (as in PATElectronProducer)");
61  descriptions.add("electronsUpdated", desc);
62  }
63  }
64 
65  void setDZ(T &lep, const reco::Vertex &pv) const {}
66 
67  void readMiniIsoParams(const edm::ParameterSet &iConfig) {
68  miniIsoParams_[0] = iConfig.getParameter<std::vector<double>>("miniIsoParams");
69  if (miniIsoParams_[0].size() != 9)
70  throw cms::Exception("ParameterError", "miniIsoParams must have exactly 9 elements.\n");
71  }
72  const std::vector<double> &miniIsoParams(const T &lep) const { return miniIsoParams_[0]; }
73 
74  void recomputeMuonBasicSelectors(T &, const reco::Vertex &, const bool) const;
75 
76  private:
77  // configurables
84  std::vector<double> miniIsoParams_[2];
86  };
87 
88  // must do the specialization within the namespace otherwise gcc complains
89  //
90  template <>
92  auto track = anElectron.gsfTrack();
93  anElectron.setDB(track->dz(pv.position()), std::hypot(track->dzError(), pv.zError()), pat::Electron::PVDZ);
94  }
95 
96  template <>
98  auto track = aMuon.muonBestTrack();
99  aMuon.setDB(track->dz(pv.position()), std::hypot(track->dzError(), pv.zError()), pat::Muon::PVDZ);
100  }
101 
102  template <>
104  miniIsoParams_[0] = iConfig.getParameter<std::vector<double>>("miniIsoParamsB");
105  miniIsoParams_[1] = iConfig.getParameter<std::vector<double>>("miniIsoParamsE");
106  if (miniIsoParams_[0].size() != 9)
107  throw cms::Exception("ParameterError", "miniIsoParamsB must have exactly 9 elements.\n");
108  if (miniIsoParams_[1].size() != 9)
109  throw cms::Exception("ParameterError", "miniIsoParamsE must have exactly 9 elements.\n");
110  }
111  template <>
112  const std::vector<double> &LeptonUpdater<pat::Electron>::miniIsoParams(const pat::Electron &lep) const {
113  return miniIsoParams_[lep.isEE()];
114  }
115 
116  template <typename T>
118  const reco::Vertex &pv,
119  const bool do_hip_mitigation_2016) const {}
120 
121  template <>
123  const reco::Vertex &pv,
124  const bool do_hip_mitigation_2016) const {
125  lep.setSelectors(muon::makeSelectorBitset(lep, &pv, do_hip_mitigation_2016));
126  }
127 
128 } // namespace pat
129 
130 template <typename T>
133  iEvent.getByToken(src_, src);
134 
136  iEvent.getByToken(vertices_, vertices);
137  const reco::Vertex &pv = vertices->front();
138 
140  if (computeMiniIso_)
141  iEvent.getByToken(pcToken_, pc);
142 
143  edm::Handle<reco::BeamSpot> beamSpotHandle;
144  iEvent.getByToken(beamLineToken_, beamSpotHandle);
146  bool beamSpotIsValid = false;
147  if (beamSpotHandle.isValid()) {
148  beamSpot = *beamSpotHandle;
149  beamSpotIsValid = true;
150  } else {
151  edm::LogError("DataNotAvailable") << "No beam spot available \n";
152  }
153 
154  std::unique_ptr<std::vector<T>> out(new std::vector<T>(*src));
155 
156  const bool do_hip_mitigation_2016 =
157  recomputeMuonBasicSelectors_ && (272728 <= iEvent.run() && iEvent.run() <= 278808);
158 
159  for (unsigned int i = 0, n = src->size(); i < n; ++i) {
160  T &lep = (*out)[i];
161  setDZ(lep, pv);
162  if (computeMiniIso_) {
163  const auto &params = miniIsoParams(lep);
165  lep.polarP4(),
166  params[0],
167  params[1],
168  params[2],
169  params[3],
170  params[4],
171  params[5],
172  params[6],
173  params[7],
174  params[8]);
175  lep.setMiniPFIsolation(miniiso);
176  }
177  if (recomputeMuonBasicSelectors_)
178  recomputeMuonBasicSelectors(lep, pv, do_hip_mitigation_2016);
179  //Fixing the sign of impact parameters
180  if (fixDxySign_) {
181  float signPV = 1.;
182  float signBS = 1.;
183  if (beamSpotIsValid) {
184  if constexpr (std::is_same_v<T, pat::Electron>)
185  signBS = copysign(1., lep.gsfTrack()->dxy(beamSpot));
186  else
187  signBS = copysign(1., lep.bestTrack()->dxy(beamSpot));
188  }
189  if constexpr (std::is_same_v<T, pat::Electron>)
190  signPV = copysign(1., lep.gsfTrack()->dxy(pv.position()));
191  else
192  signPV = copysign(1., lep.bestTrack()->dxy(pv.position()));
193  lep.setDB(abs(lep.dB(T::PV2D)) * signPV, lep.edB(T::PV2D), T::PV2D);
194  lep.setDB(abs(lep.dB(T::BS2D)) * signBS, lep.edB(T::BS2D), T::BS2D);
195  }
196  }
197 
198  iEvent.put(std::move(out));
199 }
200 
203 
pat::LeptonUpdater::src_
edm::EDGetTokenT< std::vector< T > > src_
Definition: LeptonUpdater.cc:78
ConfigurationDescriptions.h
pat::LeptonUpdater::vertices_
edm::EDGetTokenT< std::vector< reco::Vertex > > vertices_
Definition: LeptonUpdater.cc:79
edm::StreamID
Definition: StreamID.h:30
reco::GsfElectron::isEE
bool isEE() const
Definition: GsfElectron.h:337
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
pat::Muon::muonBestTrack
reco::TrackRef muonBestTrack() const override
Track selected to be the best measurement of the muon parameters (including PFlow global information)
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11779
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
pat::LeptonUpdater::miniIsoParams
const std::vector< double > & miniIsoParams(const T &lep) const
Definition: LeptonUpdater.cc:72
edm::Handle::product
T const * product() const
Definition: Handle.h:70
pat::Muon::PVDZ
Definition: Muon.h:237
align::BeamSpot
Definition: StructureType.h:89
pat::LeptonUpdater
Definition: LeptonUpdater.cc:18
pat::LeptonUpdater::~LeptonUpdater
~LeptonUpdater() override
Definition: LeptonUpdater.cc:37
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::EDGetTokenT
Definition: EDGetToken.h:33
pat::LeptonUpdater::computeMiniIso_
bool computeMiniIso_
Definition: LeptonUpdater.cc:81
edm
HLT enums.
Definition: AlignableModifier.h:19
muons_cff.recomputeMuonBasicSelectors
recomputeMuonBasicSelectors
Definition: muons_cff.py:15
pat::LeptonUpdater::miniIsoParams_
std::vector< double > miniIsoParams_[2]
Definition: LeptonUpdater.cc:84
Muon.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
pat::Electron::gsfTrack
reco::GsfTrackRef gsfTrack() const override
override the reco::GsfElectron::gsfTrack method, to access the internal storage of the supercluster
muons_cff.miniIsoParams
miniIsoParams
Definition: muons_cff.py:14
pat::LeptonUpdater::produce
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Definition: LeptonUpdater.cc:131
pat::LeptonUpdater::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LeptonUpdater.cc:41
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
edm::Handle
Definition: AssociativeIterator.h:50
pat::Electron::setDB
void setDB(double dB, double edB, IPTYPE type)
Set impact parameter of a certain type and its uncertainty.
MakerMacros.h
pat::LeptonUpdater::fixDxySign_
bool fixDxySign_
Definition: LeptonUpdater.cc:82
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
pat::getMiniPFIsolation
PFIsolation getMiniPFIsolation(const pat::PackedCandidateCollection *pfcands, const reco::Candidate::PolarLorentzVector &p4, float mindr=0.05, float maxdr=0.2, float kt_scale=10.0, float ptthresh=0.5, float deadcone_ch=0.0001, float deadcone_pu=0.01, float deadcone_ph=0.01, float deadcone_nh=0.01, float dZ_cut=0.0)
Definition: MiniIsolation.cc:19
MuonSelectors.h
reco::BeamSpot
Definition: BeamSpot.h:21
PATMuonUpdater
pat::LeptonUpdater< pat::Muon > PATMuonUpdater
Definition: LeptonUpdater.cc:202
MiniIsolation.h
ParameterSetDescription.h
pat::Muon::setDB
void setDB(double dB, double edB, IPTYPE type=PV2D)
Definition: Muon.h:247
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
pat::LeptonUpdater::LeptonUpdater
LeptonUpdater(const edm::ParameterSet &iConfig)
Definition: LeptonUpdater.cc:20
Event.h
PackedCandidate.h
pat::LeptonUpdater::recomputeMuonBasicSelectors
void recomputeMuonBasicSelectors(T &, const reco::Vertex &, const bool) const
Definition: LeptonUpdater.cc:117
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
pat::LeptonUpdater::beamLineToken_
edm::EDGetTokenT< reco::BeamSpot > beamLineToken_
Definition: LeptonUpdater.cc:80
pat::LeptonUpdater::recomputeMuonBasicSelectors_
bool recomputeMuonBasicSelectors_
Definition: LeptonUpdater.cc:83
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
pat::LeptonUpdater::pcToken_
edm::EDGetTokenT< pat::PackedCandidateCollection > pcToken_
Definition: LeptonUpdater.cc:85
InputTag.h
muon::makeSelectorBitset
reco::Muon::Selector makeSelectorBitset(reco::Muon const &muon, reco::Vertex const *vertex=nullptr, bool run2016_hip_mitigation=false)
Definition: MuonSelectors.cc:1033
pat::PFIsolation
Definition: PFIsolation.h:12
pat::LeptonUpdater::setDZ
void setDZ(T &lep, const reco::Vertex &pv) const
Definition: LeptonUpdater.cc:65
pat::LeptonUpdater::readMiniIsoParams
void readMiniIsoParams(const edm::ParameterSet &iConfig)
Definition: LeptonUpdater.cc:67
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HltBtagValidation_cff.Vertex
Vertex
Definition: HltBtagValidation_cff.py:32
T
long double T
Definition: Basic3DVectorLD.h:48
pat::Electron::PVDZ
Definition: Electron.h:190
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Electron.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
cms::Exception
Definition: Exception.h:70
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
View.h
PATElectronUpdater
pat::LeptonUpdater< pat::Electron > PATElectronUpdater
Definition: LeptonUpdater.cc:201
ParameterSet.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:153
EDProducer.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
reco::Muon::setSelectors
void setSelectors(uint64_t selectors)
Definition: Muon.h:241
reco::Vertex
Definition: Vertex.h:35
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7