CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/ElectroWeakAnalysis/ZMuMu/plugins/ZToMuMuIsolationSelector.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 
00052 template<typename Isolator>
00053 class ZToMuMuIsolationSelector {
00054 public:
00055   ZToMuMuIsolationSelector(const edm::ParameterSet & cfg) :
00056     isolator_(cfg.template getParameter<double>("isoCut")) {
00057     std::string iso = cfg.template getParameter<std::string>("isolationType");
00058     if(iso == "track")  { 
00059       leptonIsolation_ = & pat::Lepton<reco::Muon>::trackIso;
00060       trackIsolation_ = & pat::GenericParticle::trackIso;
00061     }
00062     else if(iso == "ecal") {
00063       leptonIsolation_ = & pat::Lepton<reco::Muon>::ecalIso;
00064       trackIsolation_ = & pat::GenericParticle::ecalIso;
00065     }
00066     else if(iso == "hcal") {
00067       leptonIsolation_ = & pat::Lepton<reco::Muon>::hcalIso;
00068       trackIsolation_ = & pat::GenericParticle::hcalIso;
00069     }
00070     else if(iso == "calo") {
00071       leptonIsolation_ = & pat::Lepton<reco::Muon>::caloIso;
00072       trackIsolation_ = & pat::GenericParticle::caloIso;
00073     }
00074     else   throw edm::Exception(edm::errors::Configuration) 
00075       << "Invalid isolation type: " << iso << ". Valid types are:"
00076       << "'track', 'ecal', 'hcal', 'calo'\n";
00077   }
00078   bool operator()(const reco::Candidate & z) const {
00079     if(z.numberOfDaughters()!=2) 
00080       throw edm::Exception(edm::errors::InvalidReference) 
00081         << "Candidate has " << z.numberOfDaughters() << " daughters, 2 expected\n";
00082     const reco::Candidate * dau0 = z.daughter(0);
00083     const reco::Candidate * dau1 = z.daughter(1);
00084     if(!(dau0->hasMasterClone()&&dau1->hasMasterClone()))
00085       throw edm::Exception(edm::errors::InvalidReference) 
00086         << "Candidate daughters have no master clone\n"; 
00087     const reco::Candidate * m0 = &*dau0->masterClone(), * m1 = &*dau1->masterClone();
00088     double iso0 = -1, iso1 = -1;
00089     const pat::Muon * mu0 = dynamic_cast<const pat::Muon *>(m0);
00090     if(mu0 != 0) {
00091       iso0 = ((*mu0).*(leptonIsolation_))(); 
00092     } else {
00093       const pat::GenericParticle * trk0 = dynamic_cast<const pat::GenericParticle*>(m0);
00094       if(trk0 != 0) {
00095         iso0 = ((*trk0).*(trackIsolation_))(); 
00096       } else {
00097         throw edm::Exception(edm::errors::InvalidReference) 
00098           << "Candidate daughter #0 is neither pat::Muons nor pat::GenericParticle\n";      
00099       }
00100     }
00101     const pat::Muon * mu1 = dynamic_cast<const pat::Muon *>(m1);
00102     if(mu1 != 0) {
00103       iso1 = ((*mu1).*(leptonIsolation_))(); 
00104     } else {
00105       const pat::GenericParticle * trk1 = dynamic_cast<const pat::GenericParticle*>(m1);
00106       if(trk1 != 0) {
00107         iso1 = ((*trk1).*(trackIsolation_))(); 
00108       } else {
00109         throw edm::Exception(edm::errors::InvalidReference) 
00110           << "Candidate daughter #1 is neither pat::Muons nor pat::GenericParticle\n";      
00111       }
00112     } 
00113     bool pass = isolator_(iso0, iso1);
00114     return pass;
00115   }
00116   private:
00117     typedef float (pat::Lepton<reco::Muon>::*LeptonIsolationType)() const;
00118     typedef float (pat::GenericParticle::*TrackIsolationType)() const;
00119     LeptonIsolationType leptonIsolation_;
00120     TrackIsolationType trackIsolation_;
00121     Isolator isolator_;
00122 };
00123 
00124 namespace dummy {
00125   void Isolationdummy() {
00126     pat::Lepton<reco::Muon> pat;
00127     //ignore return values
00128     pat.trackIso(); pat.ecalIso(); pat.hcalIso(); pat.caloIso();
00129   }
00130 }
00131 
00132 #include "CommonTools/UtilAlgos/interface/SingleObjectSelector.h"
00133 #include "CommonTools/UtilAlgos/interface/AndSelector.h"
00134 #include "CommonTools/UtilAlgos/interface/StringCutObjectSelector.h"
00135 
00136 typedef SingleObjectSelector<reco::CandidateView, 
00137     AndSelector<ZToMuMuIsolationSelector<IsolatedSelector>, 
00138                 StringCutObjectSelector<reco::Candidate> 
00139     > 
00140   > ZToMuMuIsolatedSelector;
00141 
00142 typedef SingleObjectSelector<reco::CandidateView, 
00143     AndSelector<ZToMuMuIsolationSelector<NonIsolatedSelector>, 
00144                 StringCutObjectSelector<reco::Candidate> 
00145     > 
00146   > ZToMuMuNonIsolatedSelector;
00147 
00148 
00149 typedef SingleObjectSelector<reco::CandidateView, 
00150     AndSelector<ZToMuMuIsolationSelector<OneNonIsolatedSelector>, 
00151                 StringCutObjectSelector<reco::Candidate> 
00152     > 
00153   > ZToMuMuOneNonIsolatedSelector;
00154 
00155 typedef SingleObjectSelector<reco::CandidateView, 
00156     AndSelector<ZToMuMuIsolationSelector<TwoNonIsolatedSelector>, 
00157                 StringCutObjectSelector<reco::Candidate> 
00158     > 
00159   > ZToMuMuTwoNonIsolatedSelector;
00160 
00161 
00162 #include "FWCore/Framework/interface/MakerMacros.h"
00163 
00164 DEFINE_FWK_MODULE(ZToMuMuIsolatedSelector);
00165 DEFINE_FWK_MODULE(ZToMuMuNonIsolatedSelector);
00166 DEFINE_FWK_MODULE(ZToMuMuOneNonIsolatedSelector);
00167 DEFINE_FWK_MODULE(ZToMuMuTwoNonIsolatedSelector);