CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/PhysicsTools/PatExamples/plugins/PatJPsiProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    PatJPsiProducer
00004 // Class:      PatJPsiProducer
00005 // 
00013 //
00014 // Original Author:  "Salvatore Rappoccio"
00015 //         Created:  Mon Sep 28 12:53:57 CDT 2009
00016 // $Id: PatJPsiProducer.cc,v 1.2 2009/10/20 12:24:28 hegner Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDProducer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 
00033 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
00034 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00035 #include "DataFormats/PatCandidates/interface/Muon.h"
00036 #include "DataFormats/TrackReco/interface/Track.h"
00037 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00038 #include "PhysicsTools/CandUtils/interface/AddFourMomenta.h"
00039 #include "DataFormats/Math/interface/deltaR.h"
00040 
00041 
00042 #include <TLorentzVector.h>
00043 
00044 
00045 #include <vector>
00046 
00047 //
00048 // class decleration
00049 //
00050 
00051 class PatJPsiProducer : public edm::EDProducer {
00052    public:
00053       explicit PatJPsiProducer(const edm::ParameterSet&);
00054       ~PatJPsiProducer();
00055 
00056    private:
00057       virtual void beginJob() ;
00058       virtual void produce(edm::Event&, const edm::EventSetup&);
00059       virtual void endJob() ;
00060       
00061       // ----------member data ---------------------------
00062 
00063   edm::InputTag    muonSrc_;
00064 };
00065 
00066 //
00067 // constants, enums and typedefs
00068 //
00069 
00070 
00071 //
00072 // static data member definitions
00073 //
00074 
00075 //
00076 // constructors and destructor
00077 //
00078 PatJPsiProducer::PatJPsiProducer(const edm::ParameterSet& iConfig) :
00079   muonSrc_ ( iConfig.getParameter<edm::InputTag>("muonSrc") )
00080 {
00081   produces<std::vector<pat::CompositeCandidate> > ();
00082   
00083 }
00084 
00085 
00086 PatJPsiProducer::~PatJPsiProducer()
00087 {
00088  
00089 }
00090 
00091 
00092 //
00093 // member functions
00094 //
00095 
00096 // ------------ method called to produce the data  ------------
00097 void
00098 PatJPsiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00099 {
00100 
00101   std::auto_ptr<std::vector<pat::CompositeCandidate> > jpsiCands( new std::vector<pat::CompositeCandidate> );
00102   edm::Handle<edm::View<pat::Muon> > h_muons;
00103   iEvent.getByLabel( muonSrc_, h_muons );
00104 
00105   // const double MUON_MASS = 0.106;
00106   const double JPSI_MASS = 3.097;
00107 
00108         
00109   if ( h_muons.isValid() && h_muons->size() > 1 ) {
00110     
00111     for ( edm::View<pat::Muon>::const_iterator muonsBegin = h_muons->begin(),
00112             muonsEnd = h_muons->end(), imuon = muonsBegin;
00113           imuon != muonsEnd - 1; ++imuon ) {
00114       if ( imuon->pt() > 1.0 ) {
00115 
00116 
00117         for ( edm::View<pat::Muon>::const_iterator jmuon = imuon + 1;
00118               jmuon != muonsEnd; ++jmuon ) {
00119           if ( imuon->charge() * jmuon->charge() < 0 ) {
00120 
00121             pat::CompositeCandidate jpsi;
00122             jpsi.addDaughter( *imuon, "mu1");
00123             jpsi.addDaughter( *jmuon, "mu2");
00124 
00125             AddFourMomenta addp4;
00126             addp4.set( jpsi );
00127 
00128             double dR = reco::deltaR<pat::Muon,pat::Muon>( *imuon, *jmuon );
00129 
00130             jpsi.addUserFloat("dR", dR );
00131 
00132             if ( fabs( jpsi.mass() - JPSI_MASS ) < 1.0 ) {
00133               jpsiCands->push_back( jpsi );
00134             }
00135           }
00136         }
00137       }
00138     }
00139   }
00140   
00141   iEvent.put( jpsiCands );
00142  
00143 }
00144 
00145 // ------------ method called once each job just before starting event loop  ------------
00146 void 
00147 PatJPsiProducer::beginJob()
00148 {
00149 }
00150 
00151 // ------------ method called once each job just after ending the event loop  ------------
00152 void 
00153 PatJPsiProducer::endJob() {
00154 }
00155 
00156 //define this as a plug-in
00157 DEFINE_FWK_MODULE(PatJPsiProducer);