CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/TopQuarkAnalysis/Examples/plugins/TopMuonAnalyzer.cc

Go to the documentation of this file.
00001 #include "DataFormats/PatCandidates/interface/Muon.h"
00002 #include "TopQuarkAnalysis/Examples/plugins/TopMuonAnalyzer.h"
00003 
00004 
00005 TopMuonAnalyzer::TopMuonAnalyzer(const edm::ParameterSet& cfg):
00006   input_  (cfg.getParameter<edm::InputTag>("input"  )),
00007   verbose_(cfg.getParameter<bool>         ("verbose"))
00008 {
00009   edm::Service<TFileService> fs;
00010   
00011   mult_ = fs->make<TH1F>("mult", "multiplicity (muons)", 10,  0 ,   10);
00012   en_   = fs->make<TH1F>("en"  , "energy (muons)",       60,  0., 300.);
00013   pt_   = fs->make<TH1F>("pt"  , "pt (muons)",           60,  0., 300.);
00014   eta_  = fs->make<TH1F>("eta" , "eta (muons)",          30, -3.,   3.);
00015   phi_  = fs->make<TH1F>("phi" , "phi (muons)",          40, -4.,   4.);
00016   
00017 }
00018 
00019 TopMuonAnalyzer::~TopMuonAnalyzer()
00020 {
00021 }
00022 
00023 void
00024 TopMuonAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& setup)
00025 {
00026   edm::Handle<std::vector<pat::Muon> > muons;
00027   evt.getByLabel(input_, muons); 
00028 
00029   // fill histograms
00030 
00031   mult_->Fill( muons->size() ); 
00032   for(std::vector<pat::Muon>::const_iterator muon=muons->begin(); muon!=muons->end(); ++muon){
00033     pt_ ->Fill( muon->pt()     );
00034     en_ ->Fill( muon->energy() );
00035     eta_->Fill( muon->eta()    );
00036     phi_->Fill( muon->phi()    );
00037   }
00038 
00039   // produce printout if desired
00040 
00041   if( muons->size()<1 || !verbose_ )
00042     return;
00043 
00044   unsigned i=0;
00045 
00046   std::cout << "==================================================================="
00047             << std::endl;
00048   std::cout << std::setw(5 ) << "mu  :"
00049             << std::setw(13) << "pt :"
00050             << std::setw(13) << "eta :"
00051             << std::setw(13) << "phi :"
00052             << std::setw(13) << "relIso :"
00053             << std::setw(6 ) << "GLB :"
00054             << std::setw(4 ) << "TRK" << std::endl;
00055   std::cout << "-------------------------------------------------------------------"
00056             << std::endl;
00057   for(std::vector<pat::Muon>::const_iterator muon=muons->begin(); muon!=muons->end(); ++muon){
00058     std::cout << std::setw(3 ) << i << " : "
00059               << std::setw(10) << muon->pt() << " : "
00060               << std::setw(10) << muon->eta() << " : "
00061               << std::setw(10) << muon->phi() << " : "
00062               << std::setw(10) << (muon->trackIso()+muon->caloIso())/muon->pt() << " : "
00063               << std::setw( 3) << muon->isGlobalMuon() << " : "
00064               << std::setw( 3) << muon->isTrackerMuon() << std::endl;
00065     i++;
00066   }
00067   std::cout << "==================================================================="
00068             << std::endl;
00069 }
00070 
00071 void TopMuonAnalyzer::beginJob()
00072 {
00073 }
00074 
00075 void TopMuonAnalyzer::endJob()
00076 {
00077 }