CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/PhysicsTools/UtilAlgos/src/BasicMuonAnalyzer.cc

Go to the documentation of this file.
00001 #include "DataFormats/Common/interface/Handle.h"
00002 #include "DataFormats/MuonReco/interface/Muon.h"
00003 #include "DataFormats/PatCandidates/interface/Muon.h"
00004 #include "PhysicsTools/UtilAlgos/interface/BasicMuonAnalyzer.h"
00005 
00006 
00008 BasicMuonAnalyzer::BasicMuonAnalyzer(const edm::ParameterSet& cfg, TFileDirectory& fs): 
00009   edm::BasicAnalyzer::BasicAnalyzer(cfg, fs),
00010   muons_(cfg.getParameter<edm::InputTag>("muons"))
00011 {
00012   hists_["muonPt"  ] = fs.make<TH1F>("muonPt"  , "pt"  ,  100,  0., 300.);
00013   hists_["muonEta" ] = fs.make<TH1F>("muonEta" , "eta" ,  100, -3.,   3.);
00014   hists_["muonPhi" ] = fs.make<TH1F>("muonPhi" , "phi" ,  100, -5.,   5.); 
00015   hists_["mumuMass"] = fs.make<TH1F>("mumuMass", "mass",   90, 30., 120.);
00016 }
00017 
00019 void 
00020 BasicMuonAnalyzer::analyze(const edm::EventBase& event)
00021 {
00022   // define what muon you are using; this is necessary as FWLite is not 
00023   // capable of reading edm::Views
00024   using reco::Muon;
00025 
00026   // Handle to the muon collection
00027   edm::Handle<std::vector<Muon> > muons;
00028   event.getByLabel(muons_, muons);
00029 
00030   // loop muon collection and fill histograms
00031   for(std::vector<Muon>::const_iterator mu1=muons->begin(); mu1!=muons->end(); ++mu1){
00032     hists_["muonPt" ]->Fill( mu1->pt () );
00033     hists_["muonEta"]->Fill( mu1->eta() );
00034     hists_["muonPhi"]->Fill( mu1->phi() );
00035     if( mu1->pt()>20 && fabs(mu1->eta())<2.1 ){
00036       for(std::vector<Muon>::const_iterator mu2=muons->begin(); mu2!=muons->end(); ++mu2){
00037         if(mu2>mu1){ // prevent double conting
00038           if( mu1->charge()*mu2->charge()<0 ){ // check only muon pairs of unequal charge 
00039             if( mu2->pt()>20 && fabs(mu2->eta())<2.1 ){
00040               hists_["mumuMass"]->Fill( (mu1->p4()+mu2->p4()).mass() );
00041             }
00042           }
00043         }
00044       }
00045     }
00046   }
00047 }