CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/ElectroWeakAnalysis/ZMuMu/plugins/ZToMuMuIsoDepositSelector.cc

Go to the documentation of this file.
00001 /* \class ZToMuMuIsolationSelector
00002  *
00003  * \author Luca Lista, INFN
00004  *
00005  */
00006 
00007 struct IsolatedSelector {
00008   IsolatedSelector(double cut) : cut_(cut) { }
00009   bool operator()(double i1, double i2) const {
00010     return i1 < cut_ && i2 < cut_;
00011   }
00012   double cut() const { return cut_; }
00013 private:
00014   double cut_;
00015 };
00016 
00017 struct NonIsolatedSelector {
00018   NonIsolatedSelector(double cut) : isolated_(cut) { }
00019   bool operator()(double i1, double i2) const {
00020     return !isolated_(i1, i2);
00021   }
00022   double cut() const { return isolated_.cut(); }
00023 private:
00024   IsolatedSelector isolated_;
00025 };
00026 
00027 struct OneNonIsolatedSelector {
00028   OneNonIsolatedSelector(double cut) : cut_(cut) { }
00029   bool operator()(double i1, double i2) const {
00030     return (i1 < cut_ && i2 >= cut_) || (i1 >= cut_ && i2 < cut_);
00031   }
00032   double cut() const { return cut_; }
00033 private:
00034   double cut_;
00035 };
00036 
00037 struct TwoNonIsolatedSelector {
00038   TwoNonIsolatedSelector(double cut) : cut_(cut) { }
00039   bool operator()(double i1, double i2) const {
00040     return i1 >= cut_ && i2 >= cut_;
00041   }
00042   double cut() const { return cut_; }
00043 private:
00044   double cut_;
00045 };
00046 
00047 #include "DataFormats/PatCandidates/interface/Muon.h"
00048 #include "DataFormats/PatCandidates/interface/GenericParticle.h"
00049 #include "FWCore/Utilities/interface/EDMException.h"
00050 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00051 #include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
00052 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
00053 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00054 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00055 #include "DataFormats/PatCandidates/interface/Isolation.h"
00056 
00057 using namespace reco;
00058 using namespace isodeposit;
00059 
00060 template<typename Isolator>
00061 class ZToMuMuIsoDepositSelector {
00062 public:
00063   ZToMuMuIsoDepositSelector(const edm::ParameterSet & cfg) :
00064     isolator_(cfg.template getParameter<double>("isoCut")),
00065     ptThreshold(cfg.getUntrackedParameter<double>("ptThreshold")),
00066     etEcalThreshold(cfg.getUntrackedParameter<double>("etEcalThreshold")),
00067     etHcalThreshold(cfg.getUntrackedParameter<double>("etHcalThreshold")),
00068     dRVetoTrk(cfg.getUntrackedParameter<double>("deltaRVetoTrk")),
00069     dRTrk(cfg.getUntrackedParameter<double>("deltaRTrk")),
00070     dREcal(cfg.getUntrackedParameter<double>("deltaREcal")),
00071     dRHcal(cfg.getUntrackedParameter<double>("deltaRHcal")),
00072     alpha(cfg.getUntrackedParameter<double>("alpha")),
00073     beta(cfg.getUntrackedParameter<double>("beta")),
00074     relativeIsolation(cfg.template getParameter<bool>("relativeIsolation")) {
00075   }
00076 
00077   template<typename T>
00078   double isolation(const T * t) const {
00079     const pat::IsoDeposit * trkIso = t->isoDeposit(pat::TrackIso);
00080     const pat::IsoDeposit * ecalIso = t->isoDeposit(pat::EcalIso);
00081     const pat::IsoDeposit * hcalIso = t->isoDeposit(pat::HcalIso);   
00082     
00083     Direction dir = Direction(t->eta(), t->phi());
00084     
00085     IsoDeposit::AbsVetos vetosTrk;
00086     vetosTrk.push_back(new ConeVeto( dir, dRVetoTrk ));
00087     vetosTrk.push_back(new ThresholdVeto( ptThreshold ));
00088     
00089     IsoDeposit::AbsVetos vetosEcal;
00090     vetosEcal.push_back(new ConeVeto( dir, 0.));
00091     vetosEcal.push_back(new ThresholdVeto( etEcalThreshold ));
00092     
00093     IsoDeposit::AbsVetos vetosHcal;
00094     vetosHcal.push_back(new ConeVeto( dir, 0. ));
00095     vetosHcal.push_back(new ThresholdVeto( etHcalThreshold ));
00096 
00097     double isovalueTrk = (trkIso->sumWithin(dRTrk,vetosTrk));
00098     double isovalueEcal = (ecalIso->sumWithin(dREcal,vetosEcal));
00099     double isovalueHcal = (hcalIso->sumWithin(dRHcal,vetosHcal));
00100     
00101 
00102     double iso = alpha*( ((1+beta)/2*isovalueEcal) + ((1-beta)/2*isovalueHcal) ) + ((1-alpha)*isovalueTrk) ;
00103     if(relativeIsolation) iso /= t->pt();
00104     return iso;
00105   }
00106 
00107   double candIsolation(const reco::Candidate* c) const {
00108     const pat::Muon * mu = dynamic_cast<const pat::Muon *>(c);
00109     if(mu != 0) return isolation(mu);
00110     const pat::GenericParticle * trk = dynamic_cast<const pat::GenericParticle*>(c);
00111     if(trk != 0) return isolation(trk);
00112     throw edm::Exception(edm::errors::InvalidReference) 
00113       << "Candidate daughter #0 is neither pat::Muons nor pat::GenericParticle\n";      
00114     return -1;
00115   }
00116   bool operator()(const reco::Candidate & z) const {
00117     if(z.numberOfDaughters()!=2) 
00118       throw edm::Exception(edm::errors::InvalidReference) 
00119         << "Candidate has " << z.numberOfDaughters() << " daughters, 2 expected\n";
00120     const reco::Candidate * dau0 = z.daughter(0);
00121     const reco::Candidate * dau1 = z.daughter(1);
00122     if(!(dau0->hasMasterClone()&&dau1->hasMasterClone()))
00123       throw edm::Exception(edm::errors::InvalidReference) 
00124         << "Candidate daughters have no master clone\n"; 
00125     const reco::Candidate * m0 = &*dau0->masterClone(), * m1 = &*dau1->masterClone();
00126     return isolator_(candIsolation(m0), candIsolation(m1));
00127   }
00128 private:
00129   Isolator isolator_;
00130   double ptThreshold,etEcalThreshold,etHcalThreshold, dRVetoTrk, dRTrk, dREcal, dRHcal, alpha, beta;  
00131   bool relativeIsolation;
00132   
00133 };
00134 
00135 #include "CommonTools/UtilAlgos/interface/SingleObjectSelector.h"
00136 #include "CommonTools/UtilAlgos/interface/AndSelector.h"
00137 #include "CommonTools/UtilAlgos/interface/StringCutObjectSelector.h"
00138 
00139 typedef SingleObjectSelector<reco::CandidateView, 
00140     AndSelector<ZToMuMuIsoDepositSelector<IsolatedSelector>, 
00141                 StringCutObjectSelector<reco::Candidate> 
00142     > 
00143   > ZToMuMuIsolatedIDSelector;
00144 
00145 typedef SingleObjectSelector<reco::CandidateView, 
00146     AndSelector<ZToMuMuIsoDepositSelector<NonIsolatedSelector>, 
00147                 StringCutObjectSelector<reco::Candidate> 
00148     > 
00149   > ZToMuMuNonIsolatedIDSelector;
00150 
00151 
00152 typedef SingleObjectSelector<reco::CandidateView, 
00153     AndSelector<ZToMuMuIsoDepositSelector<OneNonIsolatedSelector>, 
00154                 StringCutObjectSelector<reco::Candidate> 
00155     > 
00156   > ZToMuMuOneNonIsolatedIDSelector;
00157 
00158 typedef SingleObjectSelector<reco::CandidateView, 
00159     AndSelector<ZToMuMuIsoDepositSelector<TwoNonIsolatedSelector>, 
00160                 StringCutObjectSelector<reco::Candidate> 
00161     > 
00162   > ZToMuMuTwoNonIsolatedIDSelector;
00163 
00164 
00165 #include "FWCore/Framework/interface/MakerMacros.h"
00166 
00167 DEFINE_FWK_MODULE(ZToMuMuIsolatedIDSelector);
00168 DEFINE_FWK_MODULE(ZToMuMuNonIsolatedIDSelector);
00169 DEFINE_FWK_MODULE(ZToMuMuOneNonIsolatedIDSelector);
00170 DEFINE_FWK_MODULE(ZToMuMuTwoNonIsolatedIDSelector);