File indexing completed on 2023-03-17 11:26:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031
0032 #include "DataFormats/Candidate/interface/CompositeCandidate.h"
0033 #include "DataFormats/PatCandidates/interface/Muon.h"
0034
0035
0036
0037
0038
0039 class MuMuForEmbeddingSelector : public edm::stream::EDProducer<> {
0040 public:
0041 explicit MuMuForEmbeddingSelector(const edm::ParameterSet&);
0042 ~MuMuForEmbeddingSelector() override;
0043
0044 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045
0046 private:
0047 void beginStream(edm::StreamID) override;
0048 void produce(edm::Event&, const edm::EventSetup&) override;
0049 void endStream() override;
0050
0051
0052
0053
0054
0055
0056
0057 edm::EDGetTokenT<edm::View<reco::CompositeCandidate>> ZmumuCandidates_;
0058 double ZMass = 91.0;
0059 };
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 MuMuForEmbeddingSelector::MuMuForEmbeddingSelector(const edm::ParameterSet& iConfig)
0073 : ZmumuCandidates_(consumes<edm::View<reco::CompositeCandidate>>(
0074 iConfig.getParameter<edm::InputTag>("ZmumuCandidatesCollection"))) {
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 produces<edm::RefVector<pat::MuonCollection>>();
0086
0087
0088 }
0089
0090 MuMuForEmbeddingSelector::~MuMuForEmbeddingSelector() {
0091
0092
0093 }
0094
0095
0096
0097
0098
0099
0100 void MuMuForEmbeddingSelector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0101 using namespace edm;
0102 edm::Handle<edm::View<reco::CompositeCandidate>> ZmumuCandidatesHandle;
0103 iEvent.getByToken(ZmumuCandidates_, ZmumuCandidatesHandle);
0104 edm::View<reco::CompositeCandidate> ZmumuCandidates = *ZmumuCandidatesHandle;
0105
0106 const reco::CompositeCandidate* chosenZCand = nullptr;
0107 double massDifference = -1.0;
0108 for (edm::View<reco::CompositeCandidate>::const_iterator iZCand = ZmumuCandidates.begin();
0109 iZCand != ZmumuCandidates.end();
0110 ++iZCand) {
0111 if (std::abs(ZMass - iZCand->mass()) < massDifference || massDifference < 0) {
0112 massDifference = std::abs(ZMass - iZCand->mass());
0113 chosenZCand = &(*iZCand);
0114 }
0115 }
0116 std::unique_ptr<edm::RefVector<pat::MuonCollection>> prod(new edm::RefVector<pat::MuonCollection>());
0117 prod->reserve(2);
0118 prod->push_back(chosenZCand->daughter(0)->masterClone().castTo<pat::MuonRef>());
0119 prod->push_back(chosenZCand->daughter(1)->masterClone().castTo<pat::MuonRef>());
0120 iEvent.put(std::move(prod));
0121 }
0122
0123
0124 void MuMuForEmbeddingSelector::beginStream(edm::StreamID) {}
0125
0126
0127 void MuMuForEmbeddingSelector::endStream() {}
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162 void MuMuForEmbeddingSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0163
0164
0165 edm::ParameterSetDescription desc;
0166 desc.setUnknown();
0167 descriptions.addDefault(desc);
0168 }
0169
0170
0171 DEFINE_FWK_MODULE(MuMuForEmbeddingSelector);