CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/ElectroWeakAnalysis/Skimming/plugins/ZMuMuUserData.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 ZMuMuUserData : public edm::EDProducer {
00030 public:
00031   ZMuMuUserData( 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 ZMuMuUserData::ZMuMuUserData( 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 ZMuMuUserData::produce( Event & evt, const EventSetup & ) {
00058   Handle<std::vector<reco::CompositeCandidate> > dimuons;
00059   evt.getByLabel(src_,dimuons);
00060 
00061   Handle<BeamSpot> beamSpotHandle;
00062   evt.getByLabel(beamSpot_, beamSpotHandle);
00063   
00064   Handle<VertexCollection> primaryVertices;  // Collection of primary Vertices
00065   evt.getByLabel(primaryVertices_, primaryVertices);
00066 
00067   
00068   bool isMCMatchTrue=false;
00069    
00070   Handle<GenParticleMatch> zGenParticlesMatch;
00071   if(evt.getByLabel( zGenParticlesMatch_, zGenParticlesMatch )){
00072     isMCMatchTrue=true;
00073   }
00074   
00075   //cout<<"isMCMatchTrue"<<isMCMatchTrue <<endl;
00076   auto_ptr<vector<pat::CompositeCandidate> > dimuonColl( new vector<pat::CompositeCandidate> () );
00077 
00078 
00079   for (unsigned int i = 0; i< dimuons->size();++i){
00080     const CompositeCandidate & z = (*dimuons)[i];
00081     //CandidateBaseRef zRef = dimuons ->refAt(i);
00082     edm::Ref<std::vector<reco::CompositeCandidate> > zRef(dimuons, i);
00083     pat::CompositeCandidate dimuon(z);
00084     
00085     float trueMass,truePt,trueEta,truePhi,trueY;
00086     if (isMCMatchTrue){
00087     GenParticleRef trueZRef  = (*zGenParticlesMatch)[zRef];
00088     //CandidateRef trueZRef = trueZIter->val;
00089     if( trueZRef.isNonnull() ) {
00090       const Candidate & z = * trueZRef;
00091       trueMass = z.mass();
00092       truePt   = z.pt();
00093       trueEta  = z.eta();
00094       truePhi  = z.phi();
00095       trueY    = z.rapidity();
00096     } else {
00097       trueMass = -100; 
00098       truePt   = -100;
00099       trueEta  = -100;
00100       truePhi  = -100;
00101       trueY    = -100;  
00102     }
00103    
00104     dimuon.addUserFloat("TrueMass",trueMass);
00105     dimuon.addUserFloat("TruePt",truePt);
00106     dimuon.addUserFloat("TrueEta",trueEta);
00107     dimuon.addUserFloat("TruePhi",truePhi);
00108     dimuon.addUserFloat("TrueY",trueY);
00109 
00110     }
00111     const Candidate * dau1 = z.daughter(0); 
00112     const Candidate * dau2 = z.daughter(1); 
00113     const pat::Muon & mu1 = dynamic_cast<const pat::Muon&>(*dau1->masterClone());
00114     const pat::Muon & mu2 = dynamic_cast<const pat::Muon&>(*dau2->masterClone());
00115     
00116     /*cout<<"mu1 is null? "<<mu1.isMuon()<<endl;
00117     cout<<"mu2 is null? "<<mu2.isMuon()<<endl;
00118     cout<<"mu1 is global?"<<mu1.isGlobalMuon()<<endl;
00119     cout<<"mu2 is global?"<<mu2.isGlobalMuon()<<endl;
00120     */
00121 
00122     if(mu1.isGlobalMuon()==true && mu2.isGlobalMuon()==true){
00123       TrackRef stAloneTrack1;
00124       TrackRef stAloneTrack2;
00125       Vector momentum;
00126       Candidate::PolarLorentzVector p4_1;
00127       double mu_mass;
00128       stAloneTrack1 = dau1->get<TrackRef,reco::StandAloneMuonTag>();
00129       stAloneTrack2 = dau2->get<TrackRef,reco::StandAloneMuonTag>();
00130       float zDau1SaEta = stAloneTrack1->eta();
00131       float zDau2SaEta = stAloneTrack2->eta();
00132       float zDau1SaPhi = stAloneTrack1->phi();
00133       float zDau2SaPhi = stAloneTrack2->phi();
00134       float zDau1SaPt,zDau2SaPt;
00135       if(counter % 2 == 0) {
00136         momentum = stAloneTrack1->momentum();
00137         p4_1 = dau2->polarP4();
00138         mu_mass = dau1->mass();
00140         zDau1SaPt = stAloneTrack1->pt();
00141         zDau2SaPt = - stAloneTrack2->pt();
00142       }else{
00143         momentum = stAloneTrack2->momentum();
00144         p4_1= dau1->polarP4();
00145         mu_mass = dau2->mass();
00147         zDau1SaPt = - stAloneTrack1->pt();
00148         zDau2SaPt =  stAloneTrack2->pt();
00149       }
00150       
00151       Candidate::PolarLorentzVector p4_2(momentum.rho(), momentum.eta(),momentum.phi(), mu_mass);
00152       double mass = (p4_1+p4_2).mass();
00153       float zMassSa = mass;
00154       //cout<<"zMassSa "<<zMassSa;
00155       dimuon.addUserFloat("MassSa",zMassSa);    
00156       dimuon.addUserFloat("Dau1SaPt",zDau1SaPt);        
00157       dimuon.addUserFloat("Dau2SaPt",zDau2SaPt);        
00158       dimuon.addUserFloat("Dau1SaPhi",zDau1SaPhi);      
00159       dimuon.addUserFloat("Dau2SaPhi",zDau2SaPhi);      
00160       dimuon.addUserFloat("Dau1SaEta",zDau1SaEta);      
00161       dimuon.addUserFloat("Dau2SaEta",zDau2SaEta);      
00162       ++counter;
00163     }
00164     dimuonColl->push_back(dimuon);
00165     
00166   }
00167   
00168 
00169   evt.put( dimuonColl);
00170 }
00171 
00172 #include "FWCore/Framework/interface/MakerMacros.h"
00173 
00174 DEFINE_FWK_MODULE( ZMuMuUserData );
00175