CMS 3D CMS Logo

MuonFSRAssociator.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
13 
17 
20 
22 
23 //
24 // class declaration
25 //
26 
28 public:
29  explicit MuonFSRAssociator(const edm::ParameterSet& iConfig)
30  :
31 
32  photons_{consumes<pat::GenericParticleCollection>(iConfig.getParameter<edm::InputTag>("photons"))},
33  muons_{consumes<edm::View<reco::Muon>>(iConfig.getParameter<edm::InputTag>("muons"))}
34 
35  {
36  produces<edm::Association<std::vector<pat::GenericParticle>>>();
37  produces<edm::ValueMap<int>>("fsrIndex");
38  }
39 
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
42  desc.add<edm::InputTag>("photons")->setComment("FSR photon collection to associate with muons");
43  desc.add<edm::InputTag>("muons")->setComment("collection of muons to associate with FSR photons");
44 
45  descriptions.addWithDefaultLabel(desc);
46  }
47  ~MuonFSRAssociator() override {}
48 
49 private:
50  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
51 
52  // ----------member data ---------------------------
55 };
56 
58  using namespace std;
59 
61  iEvent.getByToken(photons_, photons);
63  iEvent.getByToken(muons_, muons);
64 
65  std::vector<int> muonMapping(muons->size(), -1);
66  // loop over all muons
67  for (auto muon = muons->begin(); muon != muons->end(); ++muon) {
68  for (auto iter_pho = photons->begin(); iter_pho != photons->end(); iter_pho++) {
69  if (iter_pho->hasUserCand("associatedMuon") and
70  iter_pho->userCand("associatedMuon") == reco::CandidatePtr(muons, muon - muons->begin()))
71  muonMapping[muon - muons->begin()] = (iter_pho - photons->begin());
72  }
73  }
74 
75  auto muon2photon = std::make_unique<edm::Association<std::vector<pat::GenericParticle>>>(photons);
76  edm::Association<std::vector<pat::GenericParticle>>::Filler muon2photonFiller(*muon2photon);
77  muon2photonFiller.insert(muons, muonMapping.begin(), muonMapping.end());
78  muon2photonFiller.fill();
79  iEvent.put(std::move(muon2photon));
80 
81  std::unique_ptr<edm::ValueMap<int>> bareIdx(new edm::ValueMap<int>());
82  edm::ValueMap<int>::Filler fillerBareIdx(*bareIdx);
83  fillerBareIdx.insert(muons, muonMapping.begin(), muonMapping.end());
84  fillerBareIdx.fill();
85  iEvent.put(std::move(bareIdx), "fsrIndex");
86 }
87 
88 //define this as a plug-in
edm::StreamID
Definition: StreamID.h:30
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
muon
Definition: MuonCocktails.h:17
MuonFSRAssociator::MuonFSRAssociator
MuonFSRAssociator(const edm::ParameterSet &iConfig)
Definition: MuonFSRAssociator.cc:29
edm::EDGetTokenT< pat::GenericParticleCollection >
Muon.h
GenericParticle.h
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
Association.h
HLT_2018_cff.muon
muon
Definition: HLT_2018_cff.py:10349
edm::Handle
Definition: AssociativeIterator.h:50
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
MuonFSRAssociator::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: MuonFSRAssociator.cc:40
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
LorentzVector.h
iEvent
int iEvent
Definition: GenABIO.cc:224
BPHMonitor_cfi.photons
photons
Definition: BPHMonitor_cfi.py:91
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:57
ValueMap.h
MuonFSRAssociator::~MuonFSRAssociator
~MuonFSRAssociator() override
Definition: MuonFSRAssociator.cc:47
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
edm::ValueMap< int >
MuonFSRAssociator::photons_
const edm::EDGetTokenT< pat::GenericParticleCollection > photons_
Definition: MuonFSRAssociator.cc:53
MuonFSRAssociator
Definition: MuonFSRAssociator.cc:27
MuonFSRAssociator::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: MuonFSRAssociator.cc:57
Candidate.h
reco::CandidatePtr
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
StreamID.h
edm::InputTag
Definition: InputTag.h:15
MuonFSRAssociator::muons_
const edm::EDGetTokenT< edm::View< reco::Muon > > muons_
Definition: MuonFSRAssociator.cc:54
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87