Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:18

0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "DataFormats/PatCandidates/interface/Muon.h"
0003 #include "PhysicsTools/UtilAlgos/interface/BasicMuonAnalyzer.h"
0004 
0005 /// default constructor
0006 BasicMuonAnalyzer::BasicMuonAnalyzer(const edm::ParameterSet& cfg, TFileDirectory& fs)
0007     : edm::BasicAnalyzer::BasicAnalyzer(cfg, fs), muons_(cfg.getParameter<edm::InputTag>("muons")) {
0008   hists_["muonPt"] = fs.make<TH1F>("muonPt", "pt", 100, 0., 300.);
0009   hists_["muonEta"] = fs.make<TH1F>("muonEta", "eta", 100, -3., 3.);
0010   hists_["muonPhi"] = fs.make<TH1F>("muonPhi", "phi", 100, -5., 5.);
0011   hists_["mumuMass"] = fs.make<TH1F>("mumuMass", "mass", 90, 30., 120.);
0012 }
0013 BasicMuonAnalyzer::BasicMuonAnalyzer(const edm::ParameterSet& cfg, TFileDirectory& fs, edm::ConsumesCollector&& iC)
0014     : edm::BasicAnalyzer::BasicAnalyzer(cfg, fs),
0015       muons_(cfg.getParameter<edm::InputTag>("muons")),
0016       muonsToken_(iC.consumes<std::vector<reco::Muon> >(muons_)) {
0017   hists_["muonPt"] = fs.make<TH1F>("muonPt", "pt", 100, 0., 300.);
0018   hists_["muonEta"] = fs.make<TH1F>("muonEta", "eta", 100, -3., 3.);
0019   hists_["muonPhi"] = fs.make<TH1F>("muonPhi", "phi", 100, -5., 5.);
0020   hists_["mumuMass"] = fs.make<TH1F>("mumuMass", "mass", 90, 30., 120.);
0021 }
0022 
0023 /// everything that needs to be done during the event loop
0024 void BasicMuonAnalyzer::analyze(const edm::EventBase& event) {
0025   // define what muon you are using; this is necessary as FWLite is not
0026   // capable of reading edm::Views
0027   using reco::Muon;
0028 
0029   // Handle to the muon collection
0030   edm::Handle<std::vector<Muon> > muons;
0031   event.getByLabel(muons_, muons);
0032 
0033   // loop muon collection and fill histograms
0034   for (std::vector<Muon>::const_iterator mu1 = muons->begin(); mu1 != muons->end(); ++mu1) {
0035     hists_["muonPt"]->Fill(mu1->pt());
0036     hists_["muonEta"]->Fill(mu1->eta());
0037     hists_["muonPhi"]->Fill(mu1->phi());
0038     if (mu1->pt() > 20 && fabs(mu1->eta()) < 2.1) {
0039       for (std::vector<Muon>::const_iterator mu2 = muons->begin(); mu2 != muons->end(); ++mu2) {
0040         if (mu2 > mu1) {                            // prevent double conting
0041           if (mu1->charge() * mu2->charge() < 0) {  // check only muon pairs of unequal charge
0042             if (mu2->pt() > 20 && fabs(mu2->eta()) < 2.1) {
0043               hists_["mumuMass"]->Fill((mu1->p4() + mu2->p4()).mass());
0044             }
0045           }
0046         }
0047       }
0048     }
0049   }
0050 }