CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/ElectroWeakAnalysis/Skimming/plugins/ZMuMuOneTrackUserData.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDProducer.h"
00002 #include "FWCore/Utilities/interface/InputTag.h"
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "FWCore/Framework/interface/Event.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "DataFormats/PatCandidates/interface/Muon.h"
00007 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
00008 #include "FWCore/Utilities/interface/EDMException.h"
00009 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00010 
00011 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00012 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00013 #include "DataFormats/PatCandidates/interface/Isolation.h"
00014 #include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
00015 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
00016 
00017 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00018 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00019 #include "DataFormats/VertexReco/interface/Vertex.h"
00020 
00021 #include <vector>
00022 
00023 using namespace edm;
00024 using namespace std;
00025 using namespace reco;
00026 using namespace isodeposit;
00027 //using namespace pat;
00028 
00029 class ZMuMuUserDataOneTrack : public edm::EDProducer {
00030 public:
00031   ZMuMuUserDataOneTrack( const edm::ParameterSet & );   
00032   typedef math::XYZVector Vector;
00033 private:
00034   void produce( edm::Event &, const edm::EventSetup & );
00035   
00036   InputTag src_,beamSpot_, primaryVertices_, zGenParticlesMatch_;
00037   double alpha_, beta_; 
00038   string hltPath_; 
00039   int counter;
00040   
00041 
00042 };
00043 
00044 
00045 
00046 ZMuMuUserDataOneTrack::ZMuMuUserDataOneTrack( const ParameterSet & cfg ):
00047   src_( cfg.getParameter<InputTag>( "src" ) ),
00048   beamSpot_(cfg.getParameter<InputTag>( "beamSpot" ) ),
00049   primaryVertices_(cfg.getParameter<InputTag>( "primaryVertices" ) ),
00050   zGenParticlesMatch_(cfg.getParameter<InputTag>( "zGenParticlesMatch" ) ),
00051   alpha_(cfg.getParameter<double>("alpha") ),
00052   beta_(cfg.getParameter<double>("beta") ), 
00053   hltPath_(cfg.getParameter<std::string >("hltPath") ){
00054   produces<vector<pat::CompositeCandidate> >();
00055 }
00056 
00057 void ZMuMuUserDataOneTrack::produce( Event & evt, const EventSetup & ) {
00058   Handle<std::vector<reco::CompositeCandidate> > dimuons;
00059   evt.getByLabel(src_,dimuons);
00060 
00061   Handle<BeamSpot> beamSpotHandle;
00062   if (!evt.getByLabel(beamSpot_, beamSpotHandle)) {
00063     std::cout << ">>> No beam spot found !!!"<<std::endl;
00064   }
00065   
00066   Handle<VertexCollection> primaryVertices;  // Collection of primary Vertices
00067   if (!evt.getByLabel(primaryVertices_, primaryVertices)){
00068     std::cout << ">>> No primary vertices  found !!!"<<std::endl;
00069   }
00070   
00071   bool isMCMatchTrue=false;
00072   
00073   Handle<GenParticleMatch> zGenParticlesMatch;
00074   if(evt.getByLabel( zGenParticlesMatch_, zGenParticlesMatch )){
00075     isMCMatchTrue=true;
00076   }
00077   
00078   //cout<<"isMCMatchTrue"<<isMCMatchTrue <<endl;
00079   auto_ptr<vector<pat::CompositeCandidate> > dimuonColl( new vector<pat::CompositeCandidate> () );
00080 
00081 
00082   for (unsigned int i = 0; i< dimuons->size();++i){
00083     const CompositeCandidate & z = (*dimuons)[i];
00084     //CandidateBaseRef zRef = dimuons ->refAt(i);
00085     edm::Ref<std::vector<reco::CompositeCandidate> > zRef(dimuons, i);
00086     pat::CompositeCandidate dimuon(z);
00087     
00088     float trueMass,truePt,trueEta,truePhi,trueY;
00089     if (isMCMatchTrue){
00090       GenParticleRef trueZRef  = (*zGenParticlesMatch)[zRef];
00091       //CandidateRef trueZRef = trueZIter->val;
00092       if( trueZRef.isNonnull() ) {
00093         const Candidate & z = * trueZRef;
00094         trueMass = z.mass();
00095         truePt   = z.pt();
00096         trueEta  = z.eta();
00097         truePhi  = z.phi();
00098         trueY    = z.rapidity();
00099       } else {
00100         trueMass = -100; 
00101         truePt   = -100;
00102         trueEta  = -100;
00103         truePhi  = -100;
00104         trueY    = -100;  
00105       }
00106       
00107       dimuon.addUserFloat("TrueMass",trueMass);
00108       dimuon.addUserFloat("TruePt",truePt);
00109       dimuon.addUserFloat("TrueEta",trueEta);
00110       dimuon.addUserFloat("TruePhi",truePhi);
00111       dimuon.addUserFloat("TrueY",trueY);
00112       
00113     }
00114 
00115     dimuonColl->push_back(dimuon);
00116   
00117   }
00118   
00119   evt.put( dimuonColl);
00120 }
00121 
00122 #include "FWCore/Framework/interface/MakerMacros.h"
00123 
00124 DEFINE_FWK_MODULE( ZMuMuUserDataOneTrack );
00125