CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
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
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
const edm::EDGetTokenT< edm::View< reco::Muon > > muons_
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
const edm::EDGetTokenT< pat::GenericParticleCollection > photons_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
tuple muons
Definition: patZpeak.py:41
MuonFSRAssociator(const edm::ParameterSet &iConfig)
~MuonFSRAssociator() override