CMS 3D CMS Logo

PATObjectCrossLinker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: PATObjectCrossLinker
5 //
13 //
14 // Original Author: Andrea Rizzi
15 // Created: Mon, 28 Aug 2017 09:26:39 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
37 
39 
41 //
42 // class declaration
43 //
44 
46 public:
47  explicit PATObjectCrossLinker(const edm::ParameterSet&);
48  ~PATObjectCrossLinker() override;
49 
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52 private:
53  void beginStream(edm::StreamID) override;
54  void produce(edm::Event&, const edm::EventSetup&) override;
55  void endStream() override;
56 
57  template <class C1, class C2, class C3, class C4>
58  void matchOneToMany(const C1& refProdOne,
59  C2& itemsOne,
60  const std::string& nameOne,
61  const C3& refProdMany,
62  C4& itemsMany,
63  const std::string& nameMany);
64 
65  template <class C1, class C2, class C3, class C4>
66  void matchElectronToPhoton(const C1& refProdOne,
67  C2& itemsOne,
68  const std::string& nameOne,
69  const C3& refProdMany,
70  C4& itemsMany,
71  const std::string& nameMany);
72 
73  //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
74  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
75  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
76  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
77 
78  // ----------member data ---------------------------
84 };
85 
86 //
87 // constructors and destructor
88 //
90  : jets_(consumes<edm::View<pat::Jet>>(params.getParameter<edm::InputTag>("jets"))),
91  muons_(consumes<edm::View<pat::Muon>>(params.getParameter<edm::InputTag>("muons"))),
92  electrons_(consumes<edm::View<pat::Electron>>(params.getParameter<edm::InputTag>("electrons"))),
93  taus_(consumes<edm::View<pat::Tau>>(params.getParameter<edm::InputTag>("taus"))),
94  photons_(consumes<edm::View<pat::Photon>>(params.getParameter<edm::InputTag>("photons")))
95 
96 {
97  produces<std::vector<pat::Jet>>("jets");
98  produces<std::vector<pat::Muon>>("muons");
99  produces<std::vector<pat::Electron>>("electrons");
100  produces<std::vector<pat::Tau>>("taus");
101  produces<std::vector<pat::Photon>>("photons");
102 }
103 
105  // do anything here that needs to be done at destruction time
106  // (e.g. close files, deallocate resources etc.)
107 }
108 
109 //
110 // member functions
111 //
112 
113 // ------------ method called to produce the data ------------
114 
116 template <class C1, class C2, class C3, class C4>
117 void PATObjectCrossLinker::matchOneToMany(const C1& refProdOne,
118  C2& itemsOne,
119  const std::string& nameOne,
120  const C3& refProdMany,
121  C4& itemsMany,
122  const std::string& nameMany) {
123  size_t ji = 0;
124  for (auto& j : itemsOne) {
125  edm::PtrVector<reco::Candidate> overlaps(refProdMany.id());
126  size_t mi = 0;
127  for (auto& m : itemsMany) {
128  if (matchByCommonSourceCandidatePtr(j, m) && (!m.hasUserCand(nameOne))) {
129  m.addUserCand(nameOne, reco::CandidatePtr(refProdOne.id(), ji, refProdOne.productGetter()));
130  overlaps.push_back(reco::CandidatePtr(refProdMany.id(), mi, refProdMany.productGetter()));
131  }
132  mi++;
133  }
134  j.setOverlaps(nameMany, overlaps);
135  ji++;
136  }
137 }
138 
139 template <class C1, class C2, class C3, class C4>
141  C2& itemsOne,
142  const std::string& nameOne,
143  const C3& refProdMany,
144  C4& itemsMany,
145  const std::string& nameMany) {
146  size_t ji = 0;
147  for (auto& j : itemsOne) {
148  edm::PtrVector<reco::Candidate> overlaps(refProdMany.id());
149  size_t mi = 0;
150  for (auto& m : itemsMany) {
151  if (matchByCommonParentSuperClusterRef(j, m) && (!m.hasUserCand(nameOne))) {
152  m.addUserCand(nameOne, reco::CandidatePtr(refProdOne.id(), ji, refProdOne.productGetter()));
153  overlaps.push_back(reco::CandidatePtr(refProdMany.id(), mi, refProdMany.productGetter()));
154  }
155  mi++;
156  }
157  j.setOverlaps(nameMany, overlaps);
158  ji++;
159  }
160 }
161 
163  using namespace edm;
165  iEvent.getByToken(jets_, jetsIn);
166  auto jets = std::make_unique<std::vector<pat::Jet>>();
167  for (const auto& j : *jetsIn)
168  jets->push_back(j);
169  auto jetRefProd = iEvent.getRefBeforePut<std::vector<pat::Jet>>("jets");
170 
172  iEvent.getByToken(muons_, muonsIn);
173  auto muons = std::make_unique<std::vector<pat::Muon>>();
174  for (const auto& m : *muonsIn)
175  muons->push_back(m);
176  auto muRefProd = iEvent.getRefBeforePut<std::vector<pat::Muon>>("muons");
177 
179  iEvent.getByToken(electrons_, electronsIn);
180  auto electrons = std::make_unique<std::vector<pat::Electron>>();
181  for (const auto& e : *electronsIn)
182  electrons->push_back(e);
183  auto eleRefProd = iEvent.getRefBeforePut<std::vector<pat::Electron>>("electrons");
184 
186  iEvent.getByToken(taus_, tausIn);
187  auto taus = std::make_unique<std::vector<pat::Tau>>();
188  for (const auto& t : *tausIn)
189  taus->push_back(t);
190  auto tauRefProd = iEvent.getRefBeforePut<std::vector<pat::Tau>>("taus");
191 
193  iEvent.getByToken(photons_, photonsIn);
194  auto photons = std::make_unique<std::vector<pat::Photon>>();
195  for (const auto& p : *photonsIn)
196  photons->push_back(p);
197  auto phRefProd = iEvent.getRefBeforePut<std::vector<pat::Photon>>("photons");
198 
199  matchOneToMany(jetRefProd, *jets, "jet", muRefProd, *muons, "muons");
200  matchOneToMany(jetRefProd, *jets, "jet", eleRefProd, *electrons, "electrons");
201  matchOneToMany(jetRefProd, *jets, "jet", tauRefProd, *taus, "taus");
202  matchOneToMany(jetRefProd, *jets, "jet", phRefProd, *photons, "photons");
203 
204  matchElectronToPhoton(eleRefProd, *electrons, "electron", phRefProd, *photons, "photons");
205 
206  iEvent.put(std::move(jets), "jets");
207  iEvent.put(std::move(muons), "muons");
208  iEvent.put(std::move(electrons), "electrons");
209  iEvent.put(std::move(taus), "taus");
210  iEvent.put(std::move(photons), "photons");
211 }
212 
213 // ------------ method called once each stream before processing any runs, lumis or events ------------
215 
216 // ------------ method called once each stream after processing all runs, lumis and events ------------
218 
219 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
221  //The following says we do not know what parameters are allowed so do no validation
222  // Please change this to state exactly what you do use, even if it is no parameters
224  desc.setUnknown();
225  descriptions.addDefault(desc);
226 }
227 
228 //define this as a plug-in
edm::StreamID
Definition: StreamID.h:30
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
matchByCommonParentSuperClusterRef
bool matchByCommonParentSuperClusterRef(const C1 &c1, const C2 &c2)
Definition: MatchingUtils.h:21
PATObjectCrossLinker::muons_
const edm::EDGetTokenT< edm::View< pat::Muon > > muons_
Definition: PATObjectCrossLinker.cc:80
sistrip::View
View
Definition: ConstantsForView.h:26
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::EDGetTokenT
Definition: EDGetToken.h:33
Tau3MuMonitor_cff.taus
taus
Definition: Tau3MuMonitor_cff.py:7
Electron
Definition: Electron.py:1
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
PATObjectCrossLinker
Definition: PATObjectCrossLinker.cc:45
Photon.h
matchByCommonSourceCandidatePtr
bool matchByCommonSourceCandidatePtr(const C1 &c1, const C2 &c2)
Definition: MatchingUtils.h:9
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
PATObjectCrossLinker::~PATObjectCrossLinker
~PATObjectCrossLinker() override
Definition: PATObjectCrossLinker.cc:104
EDProducer.h
edm::PtrVectorBase::productGetter
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:61
PATObjectCrossLinker::endStream
void endStream() override
Definition: PATObjectCrossLinker.cc:217
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
Tau
Definition: Tau.py:1
edm::Handle
Definition: AssociativeIterator.h:50
Tau.h
Muon
Definition: Muon.py:1
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Jet
Definition: Jet.py:1
edm::PtrVector
Definition: PtrVector.h:36
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
PATObjectCrossLinker::photons_
const edm::EDGetTokenT< edm::View< pat::Photon > > photons_
Definition: PATObjectCrossLinker.cc:83
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PATObjectCrossLinker::beginStream
void beginStream(edm::StreamID) override
Definition: PATObjectCrossLinker.cc:214
analyzePatCleaning_cfg.overlaps
overlaps
Definition: analyzePatCleaning_cfg.py:9
PATObjectCrossLinker::matchElectronToPhoton
void matchElectronToPhoton(const C1 &refProdOne, C2 &itemsOne, const std::string &nameOne, const C3 &refProdMany, C4 &itemsMany, const std::string &nameMany)
Definition: PATObjectCrossLinker.cc:140
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
Photon
Definition: Photon.py:1
iEvent
int iEvent
Definition: GenABIO.cc:224
MatchingUtils.h
edm::stream::EDProducer
Definition: EDProducer.h:38
BPHMonitor_cfi.photons
photons
Definition: BPHMonitor_cfi.py:91
PATObjectCrossLinker::taus_
const edm::EDGetTokenT< edm::View< pat::Tau > > taus_
Definition: PATObjectCrossLinker.cc:82
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
Jet.h
edm::Ptr< Candidate >
PATObjectCrossLinker::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PATObjectCrossLinker.cc:220
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
pwdgSkimBPark_cfi.electrons
electrons
Definition: pwdgSkimBPark_cfi.py:6
Frameworkfwd.h
PATObjectCrossLinker::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PATObjectCrossLinker.cc:162
Electron.h
PATObjectCrossLinker::jets_
const edm::EDGetTokenT< edm::View< pat::Jet > > jets_
Definition: PATObjectCrossLinker.cc:79
PATObjectCrossLinker::PATObjectCrossLinker
PATObjectCrossLinker(const edm::ParameterSet &)
Definition: PATObjectCrossLinker.cc:89
PATObjectCrossLinker::matchOneToMany
void matchOneToMany(const C1 &refProdOne, C2 &itemsOne, const std::string &nameOne, const C3 &refProdMany, C4 &itemsMany, const std::string &nameMany)
Definition: PATObjectCrossLinker.cc:117
View.h
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
PATObjectCrossLinker::electrons_
const edm::EDGetTokenT< edm::View< pat::Electron > > electrons_
Definition: PATObjectCrossLinker.cc:81
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
StreamID.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37