Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-10 02:51:18

0001 // -*- C++ -*-
0002 //
0003 // Package:    PatJPsiProducer
0004 // Class:      PatJPsiProducer
0005 //
0006 /**\class PatJPsiProducer PatJPsiProducer.cc Analysis/PatJPsiProducer/src/PatJPsiProducer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  "Salvatore Rappoccio"
0015 //         Created:  Mon Sep 28 12:53:57 CDT 2009
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/global/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 
0031 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
0032 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0033 #include "DataFormats/PatCandidates/interface/Muon.h"
0034 #include "DataFormats/TrackReco/interface/Track.h"
0035 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0036 #include "CommonTools/CandUtils/interface/AddFourMomenta.h"
0037 #include "DataFormats/Math/interface/deltaR.h"
0038 
0039 #include <TLorentzVector.h>
0040 
0041 #include <vector>
0042 
0043 //
0044 // class decleration
0045 //
0046 
0047 class PatJPsiProducer : public edm::global::EDProducer<> {
0048 public:
0049   explicit PatJPsiProducer(const edm::ParameterSet&);
0050 
0051 private:
0052   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0053 
0054   // ----------member data ---------------------------
0055 
0056   edm::EDGetTokenT<edm::View<pat::Muon>> muonSrcToken_;
0057 };
0058 
0059 //
0060 // constants, enums and typedefs
0061 //
0062 
0063 //
0064 // static data member definitions
0065 //
0066 
0067 //
0068 // constructors and destructor
0069 //
0070 PatJPsiProducer::PatJPsiProducer(const edm::ParameterSet& iConfig)
0071     : muonSrcToken_(consumes<edm::View<pat::Muon>>(iConfig.getParameter<edm::InputTag>("muonSrc"))) {
0072   produces<std::vector<pat::CompositeCandidate>>();
0073 }
0074 
0075 //
0076 // member functions
0077 //
0078 
0079 // ------------ method called to produce the data  ------------
0080 void PatJPsiProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0081   auto jpsiCands = std::make_unique<std::vector<pat::CompositeCandidate>>();
0082   edm::Handle<edm::View<pat::Muon>> h_muons;
0083   iEvent.getByToken(muonSrcToken_, h_muons);
0084 
0085   // const double MUON_MASS = 0.106;
0086   const double JPSI_MASS = 3.097;
0087 
0088   if (h_muons.isValid() && h_muons->size() > 1) {
0089     for (edm::View<pat::Muon>::const_iterator muonsBegin = h_muons->begin(),
0090                                               muonsEnd = h_muons->end(),
0091                                               imuon = muonsBegin;
0092          imuon != muonsEnd - 1;
0093          ++imuon) {
0094       if (imuon->pt() > 1.0) {
0095         for (edm::View<pat::Muon>::const_iterator jmuon = imuon + 1; jmuon != muonsEnd; ++jmuon) {
0096           if (imuon->charge() * jmuon->charge() < 0) {
0097             pat::CompositeCandidate jpsi;
0098             jpsi.addDaughter(*imuon, "mu1");
0099             jpsi.addDaughter(*jmuon, "mu2");
0100 
0101             AddFourMomenta addp4;
0102             addp4.set(jpsi);
0103 
0104             double dR = reco::deltaR<pat::Muon, pat::Muon>(*imuon, *jmuon);
0105 
0106             jpsi.addUserFloat("dR", dR);
0107 
0108             if (fabs(jpsi.mass() - JPSI_MASS) < 1.0) {
0109               jpsiCands->push_back(jpsi);
0110             }
0111           }
0112         }
0113       }
0114     }
0115   }
0116 
0117   iEvent.put(std::move(jpsiCands));
0118 }
0119 
0120 //define this as a plug-in
0121 DEFINE_FWK_MODULE(PatJPsiProducer);