CMS 3D CMS Logo

ZToMuMuIsolationSelector.cc
Go to the documentation of this file.
1 /* \class ZToMuMuIsolationSelector
2  *
3  * \author Luca Lista, INFN
4  *
5  */
6 
7 struct IsolatedSelector {
8  IsolatedSelector(double cut) : cut_(cut) { }
9  bool operator()(double i1, double i2) const {
10  return i1 < cut_ && i2 < cut_;
11  }
12  double cut() const { return cut_; }
13 private:
14  double cut_;
15 };
16 
17 struct NonIsolatedSelector {
18  NonIsolatedSelector(double cut) : isolated_(cut) { }
19  bool operator()(double i1, double i2) const {
20  return !isolated_(i1, i2);
21  }
22  double cut() const { return isolated_.cut(); }
23 private:
24  IsolatedSelector isolated_;
25 };
26 
28  OneNonIsolatedSelector(double cut) : cut_(cut) { }
29  bool operator()(double i1, double i2) const {
30  return (i1 < cut_ && i2 >= cut_) || (i1 >= cut_ && i2 < cut_);
31  }
32  double cut() const { return cut_; }
33 private:
34  double cut_;
35 };
36 
38  TwoNonIsolatedSelector(double cut) : cut_(cut) { }
39  bool operator()(double i1, double i2) const {
40  return i1 >= cut_ && i2 >= cut_;
41  }
42  double cut() const { return cut_; }
43 private:
44  double cut_;
45 };
46 
52 
53 template<typename Isolator>
55 public:
57  isolator_(cfg.template getParameter<double>("isoCut")) {
58  std::string iso = cfg.template getParameter<std::string>("isolationType");
59  if(iso == "track") {
60  leptonIsolation_ = & pat::Lepton<reco::Muon>::trackIso;
61  trackIsolation_ = & pat::GenericParticle::trackIso;
62  }
63  else if(iso == "ecal") {
64  leptonIsolation_ = & pat::Lepton<reco::Muon>::ecalIso;
65  trackIsolation_ = & pat::GenericParticle::ecalIso;
66  }
67  else if(iso == "hcal") {
68  leptonIsolation_ = & pat::Lepton<reco::Muon>::hcalIso;
69  trackIsolation_ = & pat::GenericParticle::hcalIso;
70  }
71  else if(iso == "calo") {
72  leptonIsolation_ = & pat::Lepton<reco::Muon>::caloIso;
73  trackIsolation_ = & pat::GenericParticle::caloIso;
74  }
76  << "Invalid isolation type: " << iso << ". Valid types are:"
77  << "'track', 'ecal', 'hcal', 'calo'\n";
78  }
79  bool operator()(const reco::Candidate & z) const {
80  if(z.numberOfDaughters()!=2)
82  << "Candidate has " << z.numberOfDaughters() << " daughters, 2 expected\n";
83  const reco::Candidate * dau0 = z.daughter(0);
84  const reco::Candidate * dau1 = z.daughter(1);
85  if(!(dau0->hasMasterClone()&&dau1->hasMasterClone()))
87  << "Candidate daughters have no master clone\n";
88  const reco::Candidate * m0 = &*dau0->masterClone(), * m1 = &*dau1->masterClone();
89  double iso0 = -1, iso1 = -1;
90  const pat::Muon * mu0 = dynamic_cast<const pat::Muon *>(m0);
91  if(mu0 != nullptr) {
92  iso0 = ((*mu0).*(leptonIsolation_))();
93  } else {
94  const pat::GenericParticle * trk0 = dynamic_cast<const pat::GenericParticle*>(m0);
95  if(trk0 != nullptr) {
96  iso0 = ((*trk0).*(trackIsolation_))();
97  } else {
99  << "Candidate daughter #0 is neither pat::Muons nor pat::GenericParticle\n";
100  }
101  }
102  const pat::Muon * mu1 = dynamic_cast<const pat::Muon *>(m1);
103  if(mu1 != nullptr) {
104  iso1 = ((*mu1).*(leptonIsolation_))();
105  } else {
106  const pat::GenericParticle * trk1 = dynamic_cast<const pat::GenericParticle*>(m1);
107  if(trk1 != nullptr) {
108  iso1 = ((*trk1).*(trackIsolation_))();
109  } else {
111  << "Candidate daughter #1 is neither pat::Muons nor pat::GenericParticle\n";
112  }
113  }
114  bool pass = isolator_(iso0, iso1);
115  return pass;
116  }
117  private:
118  typedef float (pat::Lepton<reco::Muon>::*LeptonIsolationType)() const;
119  typedef float (pat::GenericParticle::*TrackIsolationType)() const;
120  LeptonIsolationType leptonIsolation_;
121  TrackIsolationType trackIsolation_;
122  Isolator isolator_;
123 };
124 
125 namespace dummy {
126  void Isolationdummy() {
128  //ignore return values
129  pat.trackIso(); pat.ecalIso(); pat.hcalIso(); pat.caloIso();
130  }
131 }
132 
136 
140  >
142 
146  >
148 
149 
153  >
155 
159  >
161 
162 
164 
float ecalIso() const
Definition: Lepton.h:127
SingleObjectSelector< reco::CandidateView, AndSelector< ZToMuMuIsolationSelector< OneNonIsolatedSelector >, StringCutObjectSelector< reco::Candidate > > > ZToMuMuOneNonIsolatedSelector
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
bool operator()(double i1, double i2) const
float trackIso() const
Definition: HeavyIon.h:7
float hcalIso() const
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Analysis-level lepton class.
Definition: Lepton.h:31
bool operator()(double i1, double i2) const
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
float trackIso() const
Definition: Lepton.h:117
float caloIso() const
bool operator()(double i1, double i2) const
virtual const CandidateBaseRef & masterClone() const =0
SingleObjectSelector< reco::CandidateView, AndSelector< ZToMuMuIsolationSelector< IsolatedSelector >, StringCutObjectSelector< reco::Candidate > > > ZToMuMuIsolatedSelector
SingleObjectSelector< reco::CandidateView, AndSelector< ZToMuMuIsolationSelector< NonIsolatedSelector >, StringCutObjectSelector< reco::Candidate > > > ZToMuMuNonIsolatedSelector
float caloIso() const
Definition: Lepton.h:122
float hcalIso() const
Definition: Lepton.h:132
float ecalIso() const
virtual size_type numberOfDaughters() const =0
number of daughters
Analysis-level muon class.
Definition: Muon.h:50
SingleObjectSelector< reco::CandidateView, AndSelector< ZToMuMuIsolationSelector< TwoNonIsolatedSelector >, StringCutObjectSelector< reco::Candidate > > > ZToMuMuTwoNonIsolatedSelector
edm::View< Candidate > CandidateView
view of a collection containing candidates
Definition: CandidateFwd.h:23
bool operator()(double i1, double i2) const
virtual bool hasMasterClone() const =0
bool operator()(const reco::Candidate &z) const
ZToMuMuIsolationSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)