Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:26:00

0001 // -*- C++ -*-
0002 //
0003 // Package:    TauAnalysis/EmbeddingProducer
0004 // Class:      MuMuForEmbeddingSelector
0005 //
0006 /**\class MuMuForEmbeddingSelector MuMuForEmbeddingSelector.cc TauAnalysis/EmbeddingProducer/plugins/MuMuForEmbeddingSelector.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Artur Akhmetshin
0015 //         Created:  Mon, 13 Jun 2016 11:05:32 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
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 // class declaration
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   //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
0052   //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
0053   //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0054   //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0055 
0056   // ----------member data ---------------------------
0057   edm::EDGetTokenT<edm::View<reco::CompositeCandidate>> ZmumuCandidates_;
0058   double ZMass = 91.0;
0059 };
0060 
0061 //
0062 // constants, enums and typedefs
0063 //
0064 
0065 //
0066 // static data member definitions
0067 //
0068 
0069 //
0070 // constructors and destructor
0071 //
0072 MuMuForEmbeddingSelector::MuMuForEmbeddingSelector(const edm::ParameterSet& iConfig)
0073     : ZmumuCandidates_(consumes<edm::View<reco::CompositeCandidate>>(
0074           iConfig.getParameter<edm::InputTag>("ZmumuCandidatesCollection"))) {
0075   //register your products
0076   /* Examples
0077    produces<ExampleData2>();
0078 
0079    //if do put with a label
0080    produces<ExampleData2>("label");
0081  
0082    //if you want to put into the Run
0083    produces<ExampleData2,InRun>();
0084 */
0085   produces<edm::RefVector<pat::MuonCollection>>();
0086 
0087   //now do what ever other initialization is needed
0088 }
0089 
0090 MuMuForEmbeddingSelector::~MuMuForEmbeddingSelector() {
0091   // do anything here that needs to be done at destruction time
0092   // (e.g. close files, deallocate resources etc.)
0093 }
0094 
0095 //
0096 // member functions
0097 //
0098 
0099 // ------------ method called to produce the data  ------------
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 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0124 void MuMuForEmbeddingSelector::beginStream(edm::StreamID) {}
0125 
0126 // ------------ method called once each stream after processing all runs, lumis and events  ------------
0127 void MuMuForEmbeddingSelector::endStream() {}
0128 
0129 // ------------ method called when starting to processes a run  ------------
0130 /*
0131 void
0132 MuMuForEmbeddingSelector::beginRun(edm::Run const&, edm::EventSetup const&)
0133 {
0134 }
0135 */
0136 
0137 // ------------ method called when ending the processing of a run  ------------
0138 /*
0139 void
0140 MuMuForEmbeddingSelector::endRun(edm::Run const&, edm::EventSetup const&)
0141 {
0142 }
0143 */
0144 
0145 // ------------ method called when starting to processes a luminosity block  ------------
0146 /*
0147 void
0148 MuMuForEmbeddingSelector::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0149 {
0150 }
0151 */
0152 
0153 // ------------ method called when ending the processing of a luminosity block  ------------
0154 /*
0155 void
0156 MuMuForEmbeddingSelector::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0157 {
0158 }
0159 */
0160 
0161 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0162 void MuMuForEmbeddingSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0163   //The following says we do not know what parameters are allowed so do no validation
0164   // Please change this to state exactly what you do use, even if it is no parameters
0165   edm::ParameterSetDescription desc;
0166   desc.setUnknown();
0167   descriptions.addDefault(desc);
0168 }
0169 
0170 //define this as a plug-in
0171 DEFINE_FWK_MODULE(MuMuForEmbeddingSelector);