CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFRecoTauDiscriminationByMVAIsolation.cc
Go to the documentation of this file.
1 #include <vector>
2 #include <TFile.h>
6 
7 /* class PFRecoTauDiscriminationByMVAIsolation
8  *
9  * Discriminates taus based on isolation deposit rings around tau
10  *
11  *
12  *
13  * Authors : Matthew Chan
14  */
15 
16 using namespace std;
17 using namespace reco;
18 
19 namespace reco {
20  namespace tau {
21  namespace cone {
22  struct IsoRings
23  {
24  vector<int> niso;
25  vector<vector<float> > rings;
26  vector<vector<float> > shapes;
27 
28  vector<float> getVector()
29  {
30  vector<float> all;
31  all.reserve(33);
32 
33  for(unsigned int i = 0; i < niso.size(); i++)
34  all.push_back(niso[i]);
35 
36  for(unsigned int i = 0; i < rings.size(); i++)
37  all.insert(all.end(), rings[i].begin(), rings[i].end());
38 
39  for(unsigned int i = 0; i < shapes.size(); i++)
40  all.insert(all.end(), shapes[i].begin(), shapes[i].end());
41 
42  return all;
43  }
44  };
45  }
46  }
47 }
48 
50 {
51 public:
54  rhoProducer_(iConfig.getParameter<edm::InputTag>("rhoProducer")),
55  gbrfFilePath_(iConfig.getParameter<edm::FileInPath>("gbrfFilePath")),
56  returnMVA_(iConfig.getParameter<bool>("returnMVA")),
57  mvaMin_(iConfig.getParameter<double>("mvaMin")),
58  rho_(0)
59  {
60  // Prediscriminant fail value
61  if(returnMVA_)
62  prediscriminantFailValue_ = -1;
63  else
64  prediscriminantFailValue_ = 0;
65 
66  // Read GBRForest
67  TFile *gbrfFile = new TFile(gbrfFilePath_.fullPath().data());
68  gbrfTauIso_ = (GBRForest *)(gbrfFile->Get("gbrfTauIso"));
69  }
70 
72 
73  void beginEvent(const edm::Event& evt, const edm::EventSetup& evtSetup);
74  double discriminate(const PFTauRef& pfTau);
75  reco::tau::cone::IsoRings computeIsoRings(const PFTauRef& pfTau);
76 
77 private:
81  bool returnMVA_;
82  double mvaMin_;
83  double rho_;
84 };
85 
87  const edm::EventSetup& eventSetup)
88 {
89  // Get rho of event
91  event.getByLabel(rhoProducer_, hRho);
92  rho_ = *hRho;
93 }
94 
96 {
97  reco::tau::cone::IsoRings isoRings = computeIsoRings(thePFTauRef);
98  vector<float> mvainput = isoRings.getVector();
99  mvainput.push_back(rho_);
100  double mvaValue = gbrfTauIso_->GetClassifier(&mvainput[0]);
101 
102  return returnMVA_ ? mvaValue : mvaValue > mvaMin_;
103 }
104 
106 {
107  vector<int> niso(3);
108  vector<vector<float> > rings(3, vector<float>(5));
109  vector<vector<float> > shapes(3, vector<float>(5));
110  vector<float> isoptsum(3);
111 
112  for(unsigned int i = 0; i < pfTau->isolationPFCands().size(); i++)
113  {
114  const PFCandidateRef pf = pfTau->isolationPFCands().at(i);
115 
116  // Angular distance between PF candidate and tau
117  float deta = pfTau->eta() - pf->eta();
118  float dphi = reco::deltaPhi(pfTau->phi(), pf->phi());
119  float dr = reco::deltaR(pfTau->eta(), pfTau->phi(), pf->eta(), pf->phi());
120  int pftype = 0;
121 
122  // Determine PF candidate type
123  if(pf->charge() != 0) pftype = 0;
124  else if(pf->particleId() == PFCandidate::gamma) pftype = 1;
125  else pftype = 2;
126 
127  // Number of isolation candidates by type
128  niso[pftype]++;
129 
130  // Isolation Rings
131  if(dr < 0.1) rings[pftype][0] += pf->pt();
132  else if(dr < 0.2) rings[pftype][1] += pf->pt();
133  else if(dr < 0.3) rings[pftype][2] += pf->pt();
134  else if(dr < 0.4) rings[pftype][3] += pf->pt();
135  else if(dr < 0.5) rings[pftype][4] += pf->pt();
136 
137  // Angle Shape Variables
138  shapes[pftype][0] += pf->pt() * deta;
139  shapes[pftype][1] += pf->pt() * dphi;
140  shapes[pftype][2] += pf->pt() * deta*deta;
141  shapes[pftype][3] += pf->pt() * dphi*dphi;
142  shapes[pftype][4] += pf->pt() * deta*dphi;
143  isoptsum[pftype] += pf->pt();
144  }
145 
146  // Mean and variance of angle variables are weighted by pT
147  for(unsigned int i = 0; i < shapes.size(); i++)
148  {
149  for(unsigned int j = 0; j < shapes[i].size(); j++)
150  {
151  shapes[i][j] = isoptsum[i] > 0 ? fabs(shapes[i][j]/isoptsum[i]) : 0;
152  }
153  }
154 
155  // Fill IsoRing object
156  reco::tau::cone::IsoRings isoRings;
157  isoRings.niso = niso;
158  isoRings.rings = rings;
159  isoRings.shapes = shapes;
160 
161  return isoRings;
162 }
int i
Definition: DBlmapReader.cc:9
PFRecoTauDiscriminationByMVAIsolation(const edm::ParameterSet &iConfig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
reco::tau::cone::IsoRings computeIsoRings(const PFTauRef &pfTau)
void beginEvent(const edm::Event &evt, const edm::EventSetup &evtSetup)
int j
Definition: DBlmapReader.cc:9
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:12