CMS 3D CMS Logo

LeptonUpdater.cc
Go to the documentation of this file.
9 
14 
15 namespace pat {
16 
17 
18  template<typename T>
20 
21  public:
22 
23  explicit LeptonUpdater(const edm::ParameterSet & iConfig) :
24  src_(consumes<std::vector<T>>(iConfig.getParameter<edm::InputTag>("src"))),
25  vertices_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("vertices"))),
26  computeMiniIso_(iConfig.getParameter<bool>("computeMiniIso"))
27  {
28  //for mini-isolation calculation
29  if (computeMiniIso_) {
30  readMiniIsoParams(iConfig);
31  pcToken_ = consumes<pat::PackedCandidateCollection >(iConfig.getParameter<edm::InputTag>("pfCandsForMiniIso"));
32  }
34  if (typeid(T) == typeid(pat::Muon)) recomputeMuonBasicSelectors_ = iConfig.getParameter<bool>("recomputeMuonBasicSelectors");
35  produces<std::vector<T>>();
36  }
37 
38  ~LeptonUpdater() override {}
39 
40  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override ;
41 
42  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
44  desc.add<edm::InputTag>("src")->setComment("Lepton collection");
45  desc.add<edm::InputTag>("vertices")->setComment("Vertex collection");
46  desc.add<bool>("computeMiniIso", false)->setComment("Recompute miniIsolation");
47  desc.addOptional<edm::InputTag>("pfCandsForMiniIso", edm::InputTag("packedPFCandidates"))->setComment("PackedCandidate collection used for miniIso");
48  if (typeid(T) == typeid(pat::Muon)) {
49  desc.add<bool>("recomputeMuonBasicSelectors",false)->setComment("Recompute basic cut-based muon selector flags");
50  desc.addOptional<std::vector<double>>("miniIsoParams")->setComment("Parameters used for miniIso (as in PATMuonProducer)");
51  descriptions.add("muonsUpdated", desc);
52  } else if (typeid(T) == typeid(pat::Electron)) {
53  desc.addOptional<std::vector<double>>("miniIsoParamsB")->setComment("Parameters used for miniIso in the barrel (as in PATElectronProducer)");
54  desc.addOptional<std::vector<double>>("miniIsoParamsE")->setComment("Parameters used for miniIso in the endcap (as in PATElectronProducer)");
55  descriptions.add("electronsUpdated", desc);
56  }
57  }
58 
59  void setDZ(T & lep, const reco::Vertex & pv) const {}
60 
61  void readMiniIsoParams(const edm::ParameterSet & iConfig) {
62  miniIsoParams_[0] = iConfig.getParameter<std::vector<double> >("miniIsoParams");
63  if(miniIsoParams_[0].size() != 9) throw cms::Exception("ParameterError", "miniIsoParams must have exactly 9 elements.\n");
64  }
65  const std::vector<double> & miniIsoParams(const T &lep) const { return miniIsoParams_[0]; }
66 
67  void recomputeMuonBasicSelectors(T &, const reco::Vertex &, const bool) const;
68 
69  private:
70  // configurables
75  std::vector<double> miniIsoParams_[2];
77  };
78 
79  // must do the specialization within the namespace otherwise gcc complains
80  //
81  template<>
83  auto track = anElectron.gsfTrack();
84  anElectron.setDB( track->dz(pv.position()), std::hypot(track->dzError(), pv.zError()), pat::Electron::PVDZ );
85  }
86 
87  template<>
89  auto track = aMuon.muonBestTrack();
90  aMuon.setDB( track->dz(pv.position()), std::hypot(track->dzError(), pv.zError()), pat::Muon::PVDZ );
91  }
92 
93  template<>
95  miniIsoParams_[0] = iConfig.getParameter<std::vector<double> >("miniIsoParamsB");
96  miniIsoParams_[1] = iConfig.getParameter<std::vector<double> >("miniIsoParamsE");
97  if(miniIsoParams_[0].size() != 9) throw cms::Exception("ParameterError", "miniIsoParamsB must have exactly 9 elements.\n");
98  if(miniIsoParams_[1].size() != 9) throw cms::Exception("ParameterError", "miniIsoParamsE must have exactly 9 elements.\n");
99  }
100  template<>
101  const std::vector<double> & LeptonUpdater<pat::Electron>::miniIsoParams(const pat::Electron &lep) const {
102  return miniIsoParams_[lep.isEE()];
103  }
104 
105  template<typename T>
106  void LeptonUpdater<T>::recomputeMuonBasicSelectors(T & lep, const reco::Vertex & pv, const bool do_hip_mitigation_2016) const {}
107 
108  template<>
109  void LeptonUpdater<pat::Muon>::recomputeMuonBasicSelectors(pat::Muon & lep, const reco::Vertex & pv, const bool do_hip_mitigation_2016) const {
110  muon::setCutBasedSelectorFlags(lep, &pv, do_hip_mitigation_2016);
111  }
112 
113 } // namespace
114 
115 template<typename T>
118  iEvent.getByToken(src_, src);
119 
121  iEvent.getByToken(vertices_, vertices);
122  const reco::Vertex & pv = vertices->front();
123 
125  if(computeMiniIso_) iEvent.getByToken(pcToken_, pc);
126 
127  std::unique_ptr<std::vector<T>> out(new std::vector<T>(*src));
128 
129  const bool do_hip_mitigation_2016 = recomputeMuonBasicSelectors_ && (272728 <= iEvent.run() && iEvent.run() <= 278808);
130 
131  for (unsigned int i = 0, n = src->size(); i < n; ++i) {
132  T & lep = (*out)[i];
133  setDZ(lep, pv);
134  if (computeMiniIso_) {
135  const auto & params = miniIsoParams(lep);
136  pat::PFIsolation miniiso = pat::getMiniPFIsolation(pc.product(), lep.p4(),
137  params[0], params[1], params[2],
138  params[3], params[4], params[5],
139  params[6], params[7], params[8]);
140  lep.setMiniPFIsolation(miniiso);
141  }
142  if (recomputeMuonBasicSelectors_) recomputeMuonBasicSelectors(lep,pv,do_hip_mitigation_2016);
143  }
144 
145  iEvent.put(std::move(out));
146 }
147 
148 
149 
152 
size
Write out results.
T getParameter(std::string const &) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
double zError() const
error on z
Definition: Vertex.h:123
pat::LeptonUpdater< pat::Electron > PATElectronUpdater
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
LeptonUpdater(const edm::ParameterSet &iConfig)
void setCutBasedSelectorFlags(reco::Muon &muon, const reco::Vertex *vertex=0, bool run2016_hip_mitigation=false)
const Point & position() const
position
Definition: Vertex.h:109
edm::EDGetTokenT< std::vector< T > > src_
bool isEE() const
Definition: GsfElectron.h:353
pat::LeptonUpdater< pat::Muon > PATMuonUpdater
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
void setDB(double dB, double edB, IPTYPE type)
Set impact parameter of a certain type and its uncertainty.
int iEvent
Definition: GenABIO.cc:230
void setDB(double dB, double edB, IPTYPE type=PV2D)
Definition: Muon.h:244
bool recomputeMuonBasicSelectors_
~LeptonUpdater() override
RunNumber_t run() const
Definition: Event.h:109
def pv(vc)
Definition: MetAnalyzer.py:6
void setDZ(T &lep, const reco::Vertex &pv) const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void recomputeMuonBasicSelectors(T &, const reco::Vertex &, const bool) const
edm::EDGetTokenT< pat::PackedCandidateCollection > pcToken_
T const * product() const
Definition: Handle.h:81
Analysis-level electron class.
Definition: Electron.h:52
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const std::vector< double > & miniIsoParams(const T &lep) const
void readMiniIsoParams(const edm::ParameterSet &iConfig)
fixed size matrix
HLT enums.
PFIsolation getMiniPFIsolation(const pat::PackedCandidateCollection *pfcands, const math::XYZTLorentzVector &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)
reco::TrackRef muonBestTrack() const override
Track selected to be the best measurement of the muon parameters (including PFlow global information)...
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
std::vector< double > miniIsoParams_[2]
reco::GsfTrackRef gsfTrack() const override
override the reco::GsfElectron::gsfTrack method, to access the internal storage of the supercluster ...
long double T
Analysis-level muon class.
Definition: Muon.h:50
edm::EDGetTokenT< std::vector< reco::Vertex > > vertices_
def move(src, dest)
Definition: eostools.py:510