CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
PATObjectCrossLinker Class Reference

#include <PhysicsTools/PATObjectCrossLinker/plugins/PATObjectCrossLinker.cc>

Inheritance diagram for PATObjectCrossLinker:
edm::stream::EDProducer<>

Public Member Functions

 PATObjectCrossLinker (const edm::ParameterSet &)
 
 ~PATObjectCrossLinker () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void beginStream (edm::StreamID) override
 
void endStream () override
 
template<class C1 , class C2 , class C3 , class C4 >
void matchElectronToPhoton (const C1 &refProdOne, C2 &itemsOne, const std::string &nameOne, const C3 &refProdMany, C4 &itemsMany, const std::string &nameMany)
 
template<class C1 , class C2 , class C3 , class C4 >
void matchLowPtToElectron (const C1 &refProdOne, C2 &itemsOne, const std::string &nameOne, const C3 &refProdMany, C4 &itemsMany, const std::string &nameMany)
 
template<class C1 , class C2 , class C3 , class C4 >
void matchOneToMany (const C1 &refProdOne, C2 &itemsOne, const std::string &nameOne, const C3 &refProdMany, C4 &itemsMany, const std::string &nameMany)
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

const edm::EDGetTokenT< edm::View< pat::Electron > > electrons_
 
const edm::EDGetTokenT< edm::View< pat::Jet > > jets_
 
edm::EDGetTokenT< edm::View< pat::Electron > > lowPtElectrons_
 
edm::InputTag lowPtElectronsTag_
 
const edm::EDGetTokenT< edm::View< pat::Muon > > muons_
 
const edm::EDGetTokenT< edm::View< pat::Photon > > photons_
 
const edm::EDGetTokenT< edm::View< pat::Tau > > taus_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 45 of file PATObjectCrossLinker.cc.

Constructor & Destructor Documentation

◆ PATObjectCrossLinker()

PATObjectCrossLinker::PATObjectCrossLinker ( const edm::ParameterSet params)
explicit

Definition at line 99 of file PATObjectCrossLinker.cc.

References edm::InputTag::label(), and lowPtElectronsTag_.

100  : jets_(consumes<edm::View<pat::Jet>>(params.getParameter<edm::InputTag>("jets"))),
101  muons_(consumes<edm::View<pat::Muon>>(params.getParameter<edm::InputTag>("muons"))),
102  electrons_(consumes<edm::View<pat::Electron>>(params.getParameter<edm::InputTag>("electrons"))),
103  lowPtElectronsTag_(params.getParameter<edm::InputTag>("lowPtElectrons")),
105  taus_(consumes<edm::View<pat::Tau>>(params.getParameter<edm::InputTag>("taus"))),
106  photons_(consumes<edm::View<pat::Photon>>(params.getParameter<edm::InputTag>("photons")))
107 
108 {
109  produces<std::vector<pat::Jet>>("jets");
110  produces<std::vector<pat::Muon>>("muons");
111  produces<std::vector<pat::Electron>>("electrons");
112  if (!lowPtElectronsTag_.label().empty())
113  produces<std::vector<pat::Electron>>("lowPtElectrons");
114  produces<std::vector<pat::Tau>>("taus");
115  produces<std::vector<pat::Photon>>("photons");
116 }
const edm::EDGetTokenT< edm::View< pat::Muon > > muons_
std::string const & label() const
Definition: InputTag.h:36
edm::EDGetTokenT< edm::View< pat::Electron > > lowPtElectrons_
const edm::EDGetTokenT< edm::View< pat::Jet > > jets_
const edm::EDGetTokenT< edm::View< pat::Electron > > electrons_
edm::InputTag lowPtElectronsTag_
const edm::EDGetTokenT< edm::View< pat::Tau > > taus_
const edm::EDGetTokenT< edm::View< pat::Photon > > photons_

◆ ~PATObjectCrossLinker()

PATObjectCrossLinker::~PATObjectCrossLinker ( )
override

Definition at line 118 of file PATObjectCrossLinker.cc.

118  {
119  // do anything here that needs to be done at destruction time
120  // (e.g. close files, deallocate resources etc.)
121 }

Member Function Documentation

◆ beginStream()

void PATObjectCrossLinker::beginStream ( edm::StreamID  )
overrideprivate

Definition at line 273 of file PATObjectCrossLinker.cc.

273 {}

◆ endStream()

void PATObjectCrossLinker::endStream ( )
overrideprivate

Definition at line 276 of file PATObjectCrossLinker.cc.

276 {}

◆ fillDescriptions()

void PATObjectCrossLinker::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 279 of file PATObjectCrossLinker.cc.

References edm::ConfigurationDescriptions::addDefault(), and submitPVResolutionJobs::desc.

279  {
280  //The following says we do not know what parameters are allowed so do no validation
281  // Please change this to state exactly what you do use, even if it is no parameters
283  desc.setUnknown();
284  descriptions.addDefault(desc);
285 }
void addDefault(ParameterSetDescription const &psetDescription)

◆ matchElectronToPhoton()

template<class C1 , class C2 , class C3 , class C4 >
void PATObjectCrossLinker::matchElectronToPhoton ( const C1 &  refProdOne,
C2 &  itemsOne,
const std::string &  nameOne,
const C3 &  refProdMany,
C4 &  itemsMany,
const std::string &  nameMany 
)
private

Definition at line 154 of file PATObjectCrossLinker.cc.

References dqmiolumiharvest::j, visualization-live-secondInstance_cfg::m, matchByCommonParentSuperClusterRef(), analyzePatCleaning_cfg::overlaps, and edm::PtrVectorBase::productGetter().

Referenced by produce().

159  {
160  size_t ji = 0;
161  for (auto& j : itemsOne) {
162  edm::PtrVector<reco::Candidate> overlaps(refProdMany.id());
163  size_t mi = 0;
164  for (auto& m : itemsMany) {
165  if (matchByCommonParentSuperClusterRef(j, m) && (!m.hasUserCand(nameOne))) {
166  m.addUserCand(nameOne, reco::CandidatePtr(refProdOne.id(), ji, refProdOne.productGetter()));
167  overlaps.push_back(reco::CandidatePtr(refProdMany.id(), mi, refProdMany.productGetter()));
168  }
169  mi++;
170  }
171  j.setOverlaps(nameMany, overlaps);
172  ji++;
173  }
174 }
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:63
bool matchByCommonParentSuperClusterRef(const C1 &c1, const C2 &c2)
Definition: MatchingUtils.h:21

◆ matchLowPtToElectron()

template<class C1 , class C2 , class C3 , class C4 >
void PATObjectCrossLinker::matchLowPtToElectron ( const C1 &  refProdOne,
C2 &  itemsOne,
const std::string &  nameOne,
const C3 &  refProdMany,
C4 &  itemsMany,
const std::string &  nameMany 
)
private

Definition at line 177 of file PATObjectCrossLinker.cc.

References HLTMuonOfflineAnalyzer_cfi::deltaR2, MillePedeFileConverter_cfg::e, heavyIonCSV_trainingSettings::idx, dqmiolumiharvest::j, visualization-live-secondInstance_cfg::m, analyzePatCleaning_cfg::overlaps, and jetUpdater_cfi::sort.

Referenced by produce().

182  {
183  size_t ji = 0;
184  for (auto& j : itemsOne) {
185  std::vector<std::pair<size_t, float>> idxs;
186  size_t mi = 0;
187  for (auto& m : itemsMany) {
188  float dr2 = deltaR2(m, j);
189  if (dr2 < 1.e-6) { // deltaR < 1.e-3
190  m.addUserCand(nameOne, reco::CandidatePtr(refProdOne.id(), ji, refProdOne.productGetter()));
191  idxs.push_back(std::make_pair(mi, dr2));
192  }
193  mi++;
194  }
195  std::sort(idxs.begin(), idxs.end(), [](auto& left, auto& right) { return left.second < right.second; });
196 
197  edm::PtrVector<reco::Candidate> overlaps(refProdMany.id());
198  for (auto idx : idxs) {
199  overlaps.push_back(reco::CandidatePtr(refProdMany.id(), idx.first, refProdMany.productGetter()));
200  }
201  j.setOverlaps(nameMany, overlaps);
202  ji++;
203  }
204 }

◆ matchOneToMany()

template<class C1 , class C2 , class C3 , class C4 >
void PATObjectCrossLinker::matchOneToMany ( const C1 &  refProdOne,
C2 &  itemsOne,
const std::string &  nameOne,
const C3 &  refProdMany,
C4 &  itemsMany,
const std::string &  nameMany 
)
private

Definition at line 131 of file PATObjectCrossLinker.cc.

References dqmiolumiharvest::j, visualization-live-secondInstance_cfg::m, matchByCommonSourceCandidatePtr(), analyzePatCleaning_cfg::overlaps, and edm::PtrVectorBase::productGetter().

Referenced by produce().

136  {
137  size_t ji = 0;
138  for (auto& j : itemsOne) {
139  edm::PtrVector<reco::Candidate> overlaps(refProdMany.id());
140  size_t mi = 0;
141  for (auto& m : itemsMany) {
142  if (matchByCommonSourceCandidatePtr(j, m) && (!m.hasUserCand(nameOne))) {
143  m.addUserCand(nameOne, reco::CandidatePtr(refProdOne.id(), ji, refProdOne.productGetter()));
144  overlaps.push_back(reco::CandidatePtr(refProdMany.id(), mi, refProdMany.productGetter()));
145  }
146  mi++;
147  }
148  j.setOverlaps(nameMany, overlaps);
149  ji++;
150  }
151 }
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:63
bool matchByCommonSourceCandidatePtr(const C1 &c1, const C2 &c2)
Definition: MatchingUtils.h:9

◆ produce()

void PATObjectCrossLinker::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 206 of file PATObjectCrossLinker.cc.

References MillePedeFileConverter_cfg::e, pwdgSkimBPark_cfi::electrons, electrons_, iEvent, dqmiolumiharvest::j, PDWG_EXODelayedJetMET_cff::jets, jets_, edm::InputTag::label(), nano_cff::lowPtElectrons, lowPtElectrons_, lowPtElectronsTag_, visualization-live-secondInstance_cfg::m, matchElectronToPhoton(), matchLowPtToElectron(), matchOneToMany(), eostools::move(), PDWG_BPHSkim_cff::muons, muons_, AlCaHLTBitMon_ParallelJobs::p, BPHMonitor_cfi::photons, photons_, submitPVValidationJobs::t, Tau3MuMonitor_cff::taus, and taus_.

206  {
207  using namespace edm;
209  iEvent.getByToken(jets_, jetsIn);
210  auto jets = std::make_unique<std::vector<pat::Jet>>();
211  for (const auto& j : *jetsIn)
212  jets->push_back(j);
213  auto jetRefProd = iEvent.getRefBeforePut<std::vector<pat::Jet>>("jets");
214 
216  iEvent.getByToken(muons_, muonsIn);
217  auto muons = std::make_unique<std::vector<pat::Muon>>();
218  for (const auto& m : *muonsIn)
219  muons->push_back(m);
220  auto muRefProd = iEvent.getRefBeforePut<std::vector<pat::Muon>>("muons");
221 
223  iEvent.getByToken(electrons_, electronsIn);
224  auto electrons = std::make_unique<std::vector<pat::Electron>>();
225  for (const auto& e : *electronsIn)
226  electrons->push_back(e);
227  auto eleRefProd = iEvent.getRefBeforePut<std::vector<pat::Electron>>("electrons");
228 
229  edm::Handle<edm::View<pat::Electron>> lowPtElectronsIn;
230  auto lowPtElectrons = std::make_unique<std::vector<pat::Electron>>();
231  if (!lowPtElectronsTag_.label().empty()) {
232  iEvent.getByToken(lowPtElectrons_, lowPtElectronsIn);
233  for (const auto& e : *lowPtElectronsIn) {
234  lowPtElectrons->push_back(e);
235  }
236  }
237 
239  iEvent.getByToken(taus_, tausIn);
240  auto taus = std::make_unique<std::vector<pat::Tau>>();
241  for (const auto& t : *tausIn)
242  taus->push_back(t);
243  auto tauRefProd = iEvent.getRefBeforePut<std::vector<pat::Tau>>("taus");
244 
246  iEvent.getByToken(photons_, photonsIn);
247  auto photons = std::make_unique<std::vector<pat::Photon>>();
248  for (const auto& p : *photonsIn)
249  photons->push_back(p);
250  auto phRefProd = iEvent.getRefBeforePut<std::vector<pat::Photon>>("photons");
251 
252  matchOneToMany(jetRefProd, *jets, "jet", muRefProd, *muons, "muons");
253  matchOneToMany(jetRefProd, *jets, "jet", eleRefProd, *electrons, "electrons");
254  matchOneToMany(jetRefProd, *jets, "jet", tauRefProd, *taus, "taus");
255  matchOneToMany(jetRefProd, *jets, "jet", phRefProd, *photons, "photons");
256 
257  matchElectronToPhoton(eleRefProd, *electrons, "electron", phRefProd, *photons, "photons");
258  if (!lowPtElectronsTag_.label().empty()) {
259  auto lowPtEleRefProd = iEvent.getRefBeforePut<std::vector<pat::Electron>>("lowPtElectrons");
260  matchLowPtToElectron(lowPtEleRefProd, *lowPtElectrons, "lowPtElectron", eleRefProd, *electrons, "electrons");
261  }
262 
263  iEvent.put(std::move(jets), "jets");
264  iEvent.put(std::move(muons), "muons");
265  iEvent.put(std::move(electrons), "electrons");
266  if (!lowPtElectronsTag_.label().empty())
267  iEvent.put(std::move(lowPtElectrons), "lowPtElectrons");
268  iEvent.put(std::move(taus), "taus");
269  iEvent.put(std::move(photons), "photons");
270 }
void matchOneToMany(const C1 &refProdOne, C2 &itemsOne, const std::string &nameOne, const C3 &refProdMany, C4 &itemsMany, const std::string &nameMany)
const edm::EDGetTokenT< edm::View< pat::Muon > > muons_
std::string const & label() const
Definition: InputTag.h:36
edm::EDGetTokenT< edm::View< pat::Electron > > lowPtElectrons_
lowPtElectrons
Definition: nano_cff.py:42
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< edm::View< pat::Jet > > jets_
const edm::EDGetTokenT< edm::View< pat::Electron > > electrons_
void matchElectronToPhoton(const C1 &refProdOne, C2 &itemsOne, const std::string &nameOne, const C3 &refProdMany, C4 &itemsMany, const std::string &nameMany)
void matchLowPtToElectron(const C1 &refProdOne, C2 &itemsOne, const std::string &nameOne, const C3 &refProdMany, C4 &itemsMany, const std::string &nameMany)
edm::InputTag lowPtElectronsTag_
const edm::EDGetTokenT< edm::View< pat::Tau > > taus_
HLT enums.
const edm::EDGetTokenT< edm::View< pat::Photon > > photons_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ electrons_

const edm::EDGetTokenT<edm::View<pat::Electron> > PATObjectCrossLinker::electrons_
private

Definition at line 89 of file PATObjectCrossLinker.cc.

Referenced by produce().

◆ jets_

const edm::EDGetTokenT<edm::View<pat::Jet> > PATObjectCrossLinker::jets_
private

Definition at line 87 of file PATObjectCrossLinker.cc.

Referenced by produce().

◆ lowPtElectrons_

edm::EDGetTokenT<edm::View<pat::Electron> > PATObjectCrossLinker::lowPtElectrons_
private

Definition at line 91 of file PATObjectCrossLinker.cc.

Referenced by produce().

◆ lowPtElectronsTag_

edm::InputTag PATObjectCrossLinker::lowPtElectronsTag_
private

Definition at line 90 of file PATObjectCrossLinker.cc.

Referenced by PATObjectCrossLinker(), and produce().

◆ muons_

const edm::EDGetTokenT<edm::View<pat::Muon> > PATObjectCrossLinker::muons_
private

Definition at line 88 of file PATObjectCrossLinker.cc.

Referenced by produce().

◆ photons_

const edm::EDGetTokenT<edm::View<pat::Photon> > PATObjectCrossLinker::photons_
private

Definition at line 93 of file PATObjectCrossLinker.cc.

Referenced by produce().

◆ taus_

const edm::EDGetTokenT<edm::View<pat::Tau> > PATObjectCrossLinker::taus_
private

Definition at line 92 of file PATObjectCrossLinker.cc.

Referenced by produce().