00001
00002
00003
00004
00005
00006
00007 #include "FWCore/Framework/interface/EDAnalyzer.h"
00008 #include "FWCore/Utilities/interface/InputTag.h"
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "DataFormats/Common/interface/Handle.h"
00011 #include "DataFormats/Candidate/interface/Particle.h"
00012 #include "DataFormats/Candidate/interface/Candidate.h"
00013 #include "DataFormats/Candidate/interface/CandMatchMap.h"
00014 #include "DataFormats/PatCandidates/interface/Muon.h"
00015 #include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "DataFormats/Common/interface/AssociationVector.h"
00020 #include "DataFormats/PatCandidates/interface/PATObject.h"
00021 #include "TH1.h"
00022 #include <vector>
00023 #include <string>
00024 #include <iostream>
00025 #include <iterator>
00026 using namespace edm;
00027 using namespace std;
00028 using namespace reco;
00029 using namespace pat;
00030
00031 class testAnalyzer : public edm::EDAnalyzer {
00032 public:
00033 testAnalyzer(const edm::ParameterSet& pset);
00034 private:
00035 virtual void analyze(const edm::Event& event, const edm::EventSetup& setup);
00036 virtual void endJob();
00037 int SingleTrigger_ ,DoubleTrigger_ , NoTrigger_ , zmumuIncrement_ ;
00038 InputTag selectMuon_, zMuMu_ ;
00039 string pathName_;
00040 int nbinsEta_;
00041 double minEta_ , maxEta_;
00042 int nbinsPt_;
00043 double minPt_ , maxPt_;
00044 int nbinsEtaPt_;
00045 TH1D *h_pt_distribution_;
00046 TH1D *h_numberTrigMuon_, *h_numberMuon_ ;
00047 TH1D *h_numberTrigMuon_ptStudy_, *h_numberMuon_ptStudy_ ;
00048 TH1D *h_EtaDist_Pt80_;
00049 vector<double> vectorPt , vectorEta ;
00050 };
00051
00052 testAnalyzer::testAnalyzer(const edm::ParameterSet& pset) :
00053 selectMuon_( pset.getParameter<InputTag>( "selectMuon" ) ),
00054 zMuMu_( pset.getParameter<InputTag>( "ZMuMu" ) ),
00055 pathName_( pset.getParameter<string>( "pathName" ) ),
00056 nbinsEta_( pset.getParameter<int>( "EtaBins" ) ),
00057 minEta_( pset.getParameter<double>( "minEta" ) ),
00058 maxEta_( pset.getParameter<double>( "maxEta" ) ),
00059 nbinsPt_( pset.getParameter<int>( "PtBins" ) ),
00060 minPt_( pset.getParameter<double>( "minPt" ) ),
00061 maxPt_( pset.getParameter<double>( "maxPt" ) ),
00062 nbinsEtaPt_( pset.getParameter<int>( "EtaPt80Bins" ) ){
00063 SingleTrigger_= 0;
00064 DoubleTrigger_= 0;
00065 NoTrigger_= 0;
00066 zmumuIncrement_=0;
00067 Service<TFileService> fs;
00068 h_pt_distribution_ = fs->make<TH1D>("PtResolution ","Pt Resolution",200,-4.,4.);
00069 h_numberMuon_ = fs->make<TH1D>("Denominatore","Number of Muons vs Eta",nbinsEta_,minEta_,maxEta_);
00070 h_numberTrigMuon_ = fs->make<TH1D>("NumeratoreTrigMuon","Number of Triggered Muons vs Eta",nbinsEta_ ,minEta_,maxEta_);
00071 h_numberMuon_ptStudy_ = fs->make<TH1D>("DenominatorePtStudy","Number of Muons vs Pt",nbinsPt_,minPt_,maxPt_);
00072 h_numberTrigMuon_ptStudy_ = fs->make<TH1D>("NumeratoreTrigMuonPtStudy","Number of Triggered Muons vs Pt",nbinsPt_,minPt_,maxPt_);
00073 h_EtaDist_Pt80_ = fs->make<TH1D>("EtaDistr","Eta distribution (Pt>80)",nbinsEtaPt_,minEta_,maxEta_);
00074 }
00075
00076 void testAnalyzer::analyze(const edm::Event& event, const edm::EventSetup& setup) {
00077 Handle<vector<pat::Muon> > selectMuon;
00078 event.getByLabel(selectMuon_, selectMuon);
00079 Handle<CandidateView> zMuMu;
00080 event.getByLabel(zMuMu_, zMuMu);
00081 int zmumuSize = zMuMu->size();
00082 if(zmumuSize > 0){
00083 for( int i = 0; i < zmumuSize ; ++i){
00084 bool singleTrigFlag0 = false;
00085 bool singleTrigFlag1 = false;
00086 zmumuIncrement_++;
00087 const Candidate & zMuMuCand = (*zMuMu)[i];
00088 CandidateBaseRef dau0 = zMuMuCand.daughter(0)->masterClone();
00089 CandidateBaseRef dau1 = zMuMuCand.daughter(1)->masterClone();
00090 const pat::Muon& mu0 = dynamic_cast<const pat::Muon&>(*dau0);
00091 const pat::Muon& mu1 = dynamic_cast<const pat::Muon&>(*dau1);
00092 const pat::TriggerObjectStandAloneCollection mu0HLTMatches =
00093 mu0.triggerObjectMatchesByPath( pathName_ );
00094 const pat::TriggerObjectStandAloneCollection mu1HLTMatches =
00095 mu1.triggerObjectMatchesByPath( pathName_ );
00096 double EtaPatMu0 = mu0.eta();
00097 double EtaPatMu1 = mu1.eta();
00098 double PtPatMu0 = mu0.pt();
00099 double PtPatMu1 = mu1.pt();
00100 h_numberMuon_->Fill(EtaPatMu0);
00101 h_numberMuon_->Fill(EtaPatMu1);
00102 h_numberMuon_ptStudy_->Fill(PtPatMu0);
00103 h_numberMuon_ptStudy_->Fill(PtPatMu1);
00104 int dimTrig0 = mu0HLTMatches.size();
00105 int dimTrig1 = mu1HLTMatches.size();
00106 if(dimTrig0 !=0){
00107 for(int j = 0; j < dimTrig0 ; ++j){
00108 singleTrigFlag0 = true;
00109 h_numberTrigMuon_->Fill(EtaPatMu0);
00110 h_numberTrigMuon_ptStudy_->Fill(PtPatMu0);
00111 double PtTrig = mu0HLTMatches[j].pt();
00112 double PtDif = PtTrig-PtPatMu0;
00113 h_pt_distribution_->Fill(PtDif);
00114 }
00115 }
00116 else{
00117 if(PtPatMu0>80) {
00118 h_EtaDist_Pt80_->Fill(EtaPatMu0);
00119 vectorPt.push_back(PtPatMu0);
00120 vectorEta.push_back(EtaPatMu0);
00121 }
00122 }
00123 if(dimTrig1 !=0){
00124 for(int j = 0; j < dimTrig1 ; ++j){
00125 singleTrigFlag1 = true;
00126 h_numberTrigMuon_->Fill(EtaPatMu1);
00127 h_numberTrigMuon_ptStudy_->Fill(PtPatMu1);
00128 double PtTrig = mu0HLTMatches[j].pt();
00129 double PtDif = PtTrig-PtPatMu1;
00130 h_pt_distribution_->Fill(PtDif);
00131 }
00132 }
00133 else{
00134 if(PtPatMu0>80) {
00135 h_EtaDist_Pt80_->Fill(EtaPatMu1);
00136 vectorPt.push_back(PtPatMu0);
00137 vectorEta.push_back(EtaPatMu0);
00138 }
00139 }
00140
00141 if(singleTrigFlag0 && singleTrigFlag1)DoubleTrigger_++;
00142 if(singleTrigFlag0 && !singleTrigFlag1)SingleTrigger_++;
00143 if(!singleTrigFlag0 && singleTrigFlag1)SingleTrigger_++;
00144 if(!singleTrigFlag0 && !singleTrigFlag1)NoTrigger_++;
00145
00146 }
00147 }
00148
00149 }
00150
00151 void testAnalyzer::endJob() {
00152 cout<< "DoubleTrigger = " << DoubleTrigger_ << " , SingleTrigger = " << SingleTrigger_ << " , NoTrigger = "<< NoTrigger_ <<" ,zmumuIncrement = "<< zmumuIncrement_ << endl;
00153 double OneTrig = (double)SingleTrigger_/(double)zmumuIncrement_;
00154 double DoubleTrig = (double)DoubleTrigger_/(double)zmumuIncrement_;
00155 cout<< "eps^2 = " << DoubleTrig << endl;
00156 cout<< "2eps(1 - eps) = " << OneTrig << endl;
00157 int dimVec =vectorPt.size();
00158 for(int i = 0; i<dimVec; ++i) cout << "Pt = " << vectorPt[i] << " ==> Eta = " << vectorEta[i] << endl;
00159 }
00160
00161 #include "FWCore/Framework/interface/MakerMacros.h"
00162
00163 DEFINE_FWK_MODULE(testAnalyzer);
00164