CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_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.3 2012/11/29 09:54:35 kuessel 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   std::cout<<"valid?"<< h_muons.isValid()<<" size?"<<  h_muons->size();
00105   if ( h_muons.isValid() && h_muons->size() > 1 ) {
00106 
00107       for ( edm::View<pat::Muon>::const_iterator muonsBegin = h_muons->begin(),
00108                 muonsEnd = h_muons->end(), imuon = muonsBegin;
00109             imuon != muonsEnd - 1; ++imuon ) {
00110           
00111           for ( edm::View<pat::Muon>::const_iterator jmuon = imuon + 1;
00112                 jmuon != muonsEnd; ++jmuon ) {
00113               if ( imuon->charge() * jmuon->charge() < 0 ) {
00114                   
00115                   //A composite Candidate is very useful to build event hypothesis and cut on combined object information.
00116                   pat::CompositeCandidate jpsi;
00117                   jpsi.addDaughter( *imuon, "mu1");
00118                   jpsi.addDaughter( *jmuon, "mu2");
00119                   
00120                   AddFourMomenta addp4;
00121                   addp4.set( jpsi );
00122                   
00123                   double dR = reco::deltaR<pat::Muon,pat::Muon>( *imuon, *jmuon );
00124                   
00125                   // Analogue to any other PAT object we can add our own information into the object via addUserFloat/Int/Data()
00126                   jpsi.addUserFloat("dR", dR );
00127                   
00128                   jpsiCands->push_back( jpsi );
00129                   
00130               }
00131           }
00132       }
00133   }
00134   iEvent.put( jpsiCands );
00135  
00136 }
00137 
00138 // ------------ method called once each job just before starting event loop  ------------
00139 void 
00140 PatJPsiProducer::beginJob()
00141 {
00142 }
00143 
00144 // ------------ method called once each job just after ending the event loop  ------------
00145 void 
00146 PatJPsiProducer::endJob() {
00147 }
00148 
00149 //define this as a plug-in
00150 DEFINE_FWK_MODULE(PatJPsiProducer);