CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/ElectroWeakAnalysis/ZMuMu/plugins/ZGlobalVsSAIsolationAnalyzer.cc

Go to the documentation of this file.
00001 #include "DataFormats/Common/interface/AssociationVector.h"
00002 #include "FWCore/Framework/interface/EDAnalyzer.h"
00003 #include "FWCore/Utilities/interface/EDMException.h"
00004 #include "DataFormats/Candidate/interface/Candidate.h"
00005 #include "DataFormats/Candidate/interface/Particle.h"
00006 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "FWCore/Utilities/interface/InputTag.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00013 #include "DataFormats/Math/interface/deltaR.h"
00014 #include "DataFormats/PatCandidates/interface/Muon.h"
00015 #include "DataFormats/TrackReco/interface/Track.h"
00016 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00017 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00018 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00019 #include "DataFormats/PatCandidates/interface/Isolation.h"
00020 #include "DataFormats/Common/interface/ValueMap.h"
00021 #include "DataFormats/PatCandidates/interface/GenericParticle.h"
00022 #include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
00023 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
00024 #include <vector>
00025 #include <string>
00026 #include <iostream>
00027 
00028 using namespace edm;
00029 using namespace std;
00030 using namespace reco;
00031 using namespace isodeposit;
00032 
00033 class ZGlobalVsSAIsolationAnalyzer : public edm::EDAnalyzer {
00034 public:
00035   typedef math::XYZVector Vector;
00036   ZGlobalVsSAIsolationAnalyzer(const edm::ParameterSet& cfg);
00037 private:
00038   virtual void analyze(const edm::Event& event, const edm::EventSetup& setup);
00039   virtual void endJob();
00040   InputTag src_;
00041   double dRVeto;
00042   double dRTrk, dREcal, dRHcal;
00043   double ptThreshold, etEcalThreshold, etHcalThreshold;
00044   double alpha, beta;
00045   double isoCut_;
00046   unsigned long selGlobal_, selSA_, totGlobal_, totSA_;
00047   bool isolated(const Direction & dir, const pat::IsoDeposit * trkIsoDep, 
00048                 const pat::IsoDeposit * ecalIsoDep, const pat::IsoDeposit * hcalIsoDep);
00049   void evaluate(const reco::Candidate* dau);
00050 };
00051 
00052 ZGlobalVsSAIsolationAnalyzer::ZGlobalVsSAIsolationAnalyzer(const ParameterSet& cfg):
00053   src_(cfg.getParameter<InputTag>("src")),
00054   dRVeto(cfg.getParameter<double>("veto")),
00055   dRTrk(cfg.getParameter<double>("deltaRTrk")),
00056   dREcal(cfg.getParameter<double>("deltaREcal")),
00057   dRHcal(cfg.getParameter<double>("deltaRHcal")),
00058   ptThreshold(cfg.getParameter<double>("ptThreshold")),
00059   etEcalThreshold(cfg.getParameter<double>("etEcalThreshold")),
00060   etHcalThreshold(cfg.getParameter<double>("etHcalThreshold")),
00061   alpha(cfg.getParameter<double>("alpha")),
00062   beta(cfg.getParameter<double>("beta")),
00063   isoCut_(cfg.getParameter<double>("isoCut")),
00064   selGlobal_(0), selSA_(0), totGlobal_(0), totSA_(0) {
00065 }
00066 
00067 bool ZGlobalVsSAIsolationAnalyzer::isolated(const Direction & dir, const pat::IsoDeposit * trkIsoDep, 
00068                                             const pat::IsoDeposit * ecalIsoDep, const pat::IsoDeposit * hcalIsoDep) {
00069   IsoDeposit::AbsVetos vetoTrk, vetoEcal, vetoHcal;
00070   vetoTrk.push_back(new ConeVeto(dir, dRVeto));
00071   vetoTrk.push_back(new ThresholdVeto(ptThreshold));
00072   vetoEcal.push_back(new ConeVeto(dir, 0.));
00073   vetoEcal.push_back(new ThresholdVeto(etEcalThreshold));
00074   vetoHcal.push_back(new ConeVeto(dir, 0.));
00075   vetoHcal.push_back(new ThresholdVeto(etHcalThreshold));
00076   
00077   double trkIso = trkIsoDep->sumWithin(dir, dRTrk, vetoTrk);
00078   double ecalIso = ecalIsoDep->sumWithin(dir, dREcal, vetoEcal);
00079   double hcalIso = hcalIsoDep->sumWithin(dir, dRHcal, vetoHcal);
00080   double iso = alpha*((0.5*(1+beta)*ecalIso) + (0.5*(1-beta)*hcalIso)) + (1-alpha)*trkIso;
00081   return iso < isoCut_;      
00082 }
00083 
00084 void ZGlobalVsSAIsolationAnalyzer::evaluate(const reco::Candidate* dau) {
00085   const pat::Muon * mu = dynamic_cast<const pat::Muon *>(&*dau->masterClone());
00086   if(mu == 0) throw Exception(errors::InvalidReference) << "Daughter is not a muon!\n";
00087   const pat::IsoDeposit * trkIsoDep = mu->isoDeposit(pat::TrackIso);
00088   const pat::IsoDeposit * ecalIsoDep = mu->isoDeposit(pat::EcalIso);
00089   const pat::IsoDeposit * hcalIsoDep = mu->isoDeposit(pat::HcalIso);
00090   // global muon
00091   {
00092     Direction dir = Direction(mu->eta(), mu->phi());
00093     if(isolated(dir, trkIsoDep, ecalIsoDep, hcalIsoDep)) selGlobal_++;
00094     totGlobal_++;
00095   }
00096   // stand-alone
00097   {
00098     TrackRef sa = dau->get<TrackRef,reco::StandAloneMuonTag>();
00099     Direction dir = Direction(sa->eta(), sa->phi());
00100     if(isolated(dir, trkIsoDep, ecalIsoDep, hcalIsoDep)) selSA_++;
00101     totSA_++;   
00102   }
00103 }
00104 
00105 void ZGlobalVsSAIsolationAnalyzer::analyze(const edm::Event& event, const edm::EventSetup& setup) {
00106   Handle<CandidateView> dimuons;
00107   event.getByLabel(src_, dimuons);
00108   for(unsigned int i=0; i< dimuons->size(); ++ i) {
00109     const Candidate & zmm = (* dimuons)[i];
00110     evaluate(zmm.daughter(0));
00111     evaluate(zmm.daughter(1));
00112   }    
00113 }
00114   
00115 void ZGlobalVsSAIsolationAnalyzer::endJob() {
00116   cout << "Isolation efficiency report:" << endl;
00117   double eff, err;
00118   eff =  double(selGlobal_)/double(totGlobal_);
00119   err = sqrt(eff*(1.-eff)/double(totGlobal_));
00120   cout <<"Global: " << selGlobal_ << "/" << totGlobal_ << " = " <<eff <<"+/-" << err<< endl;
00121   eff = double(selSA_)/double(totSA_);
00122   err = sqrt(eff*(1.-eff)/double(totSA_));  
00123   cout <<"St.Al.: " << selSA_ << "/" << totSA_ << " = " << eff <<"+/-" << err << endl;
00124 }
00125 
00126 #include "FWCore/Framework/interface/MakerMacros.h"
00127 
00128 DEFINE_FWK_MODULE(ZGlobalVsSAIsolationAnalyzer);