CMS 3D CMS Logo

PFRecoTauDiscriminationAgainstElectronMVA6.cc
Go to the documentation of this file.
1 /* class PFRecoTauDiscriminationAgainstElectronMVA6
2  * created : Nov 2 2015,
3  * revised : ,
4  * Authorss : Fabio Colombo (KIT)
5  */
6 
9 
12 
15 
22 
23 #include <iostream>
24 #include <sstream>
25 #include <fstream>
26 
27 using namespace reco;
28 
30 public:
33  mva_ = std::make_unique<AntiElectronIDMVA6>(cfg);
34 
35  srcGsfElectrons_ = cfg.getParameter<edm::InputTag>("srcGsfElectrons");
36  GsfElectrons_token = consumes<reco::GsfElectronCollection>(srcGsfElectrons_);
37  vetoEcalCracks_ = cfg.getParameter<bool>("vetoEcalCracks");
38 
39  verbosity_ = cfg.getParameter<int>("verbosity");
40  }
41 
42  void beginEvent(const edm::Event&, const edm::EventSetup&) override;
43 
44  reco::SingleTauDiscriminatorContainer discriminate(const PFTauRef&) const override;
45 
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50 private:
51  bool isInEcalCrack(double) const;
52 
54  std::unique_ptr<AntiElectronIDMVA6> mva_;
55 
60 
62 
64 };
65 
67  mva_->beginEvent(evt, es);
68 
69  evt.getByToken(Tau_token, taus_);
70 
71  evt.getByToken(GsfElectrons_token, gsfElectrons_);
72 }
73 
75  const PFTauRef& thePFTauRef) const {
77  result.rawValues = {1., -1.};
78  double category = -1.;
79  bool isGsfElectronMatched = false;
80 
81  float deltaRDummy = 9.9;
82 
83  const float ECALBarrelEndcapEtaBorder = 1.479;
84  float tauEtaAtEcalEntrance = -99.;
85  float sumEtaTimesEnergy = 0.;
86  float sumEnergy = 0.;
87  for (const auto& pfCandidate : thePFTauRef->signalPFCands()) {
88  sumEtaTimesEnergy += (pfCandidate->positionAtECALEntrance().eta() * pfCandidate->energy());
89  sumEnergy += pfCandidate->energy();
90  }
91  if (sumEnergy > 0.) {
92  tauEtaAtEcalEntrance = sumEtaTimesEnergy / sumEnergy;
93  }
94 
95  float leadChargedPFCandEtaAtEcalEntrance = -99.;
96  float leadChargedPFCandPt = -99.;
97  for (const auto& pfCandidate : thePFTauRef->signalPFCands()) {
98  const reco::Track* track = nullptr;
99  if (pfCandidate->trackRef().isNonnull())
100  track = pfCandidate->trackRef().get();
101  else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->innerTrack().isNonnull())
102  track = pfCandidate->muonRef()->innerTrack().get();
103  else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->globalTrack().isNonnull())
104  track = pfCandidate->muonRef()->globalTrack().get();
105  else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->outerTrack().isNonnull())
106  track = pfCandidate->muonRef()->outerTrack().get();
107  else if (pfCandidate->gsfTrackRef().isNonnull())
108  track = pfCandidate->gsfTrackRef().get();
109  if (track) {
110  if (track->pt() > leadChargedPFCandPt) {
111  leadChargedPFCandEtaAtEcalEntrance = pfCandidate->positionAtECALEntrance().eta();
112  leadChargedPFCandPt = track->pt();
113  }
114  }
115  }
116 
117  if ((*thePFTauRef).leadChargedHadrCand().isNonnull()) {
118  int numSignalGammaCandsInSigCone = 0;
119  const std::vector<reco::CandidatePtr>& signalGammaCands = thePFTauRef->signalGammaCands();
120 
121  for (const auto& pfGamma : signalGammaCands) {
122  double dR = deltaR(pfGamma->p4(), thePFTauRef->leadChargedHadrCand()->p4());
123  double signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, thePFTauRef->pt())));
124 
125  // pfGammas inside the tau signal cone
126  if (dR < signalrad) {
127  numSignalGammaCandsInSigCone += 1;
128  }
129  }
130 
131  // loop over the electrons
132  for (const auto& theGsfElectron : *gsfElectrons_) {
133  if (theGsfElectron.pt() > 10.) { // CV: only take electrons above some minimal energy/Pt into account...
134  double deltaREleTau = deltaR(theGsfElectron.p4(), thePFTauRef->p4());
135  deltaRDummy = deltaREleTau;
136  if (deltaREleTau < 0.3) {
137  double mva_match = mva_->MVAValue(*thePFTauRef, theGsfElectron);
138  const reco::PFCandidatePtr& lpfch = thePFTauRef->leadPFChargedHadrCand();
139  bool hasGsfTrack = false;
140  if (lpfch.isNonnull()) {
141  hasGsfTrack = lpfch->gsfTrackRef().isNonnull();
142  }
143  if (!hasGsfTrack)
144  hasGsfTrack = theGsfElectron.gsfTrack().isNonnull();
145 
147  if (vetoEcalCracks_ &&
148  (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance))) {
149  // return MVA output value
150  result.rawValues.at(0) = -99.;
151  return result;
152  }
154 
155  if (std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { // Barrel
156  if (numSignalGammaCandsInSigCone == 0 && hasGsfTrack) {
157  category = 5.;
158  } else if (numSignalGammaCandsInSigCone >= 1 && hasGsfTrack) {
159  category = 7.;
160  }
161  } else { // Endcap
162  if (numSignalGammaCandsInSigCone == 0 && hasGsfTrack) {
163  category = 13.;
164  } else if (numSignalGammaCandsInSigCone >= 1 && hasGsfTrack) {
165  category = 15.;
166  }
167  }
168 
169  result.rawValues.at(0) = std::min(result.rawValues.at(0), float(mva_match));
170  isGsfElectronMatched = true;
171  } // deltaR < 0.3
172  } // electron pt > 10
173  } // end of loop over electrons
174 
175  if (!isGsfElectronMatched) {
176  result.rawValues.at(0) = mva_->MVAValue(*thePFTauRef);
177  const reco::PFCandidatePtr& lpfch = thePFTauRef->leadPFChargedHadrCand();
178  bool hasGsfTrack = false;
179  if (lpfch.isNonnull()) {
180  hasGsfTrack = lpfch->gsfTrackRef().isNonnull();
181  }
182 
184  if (vetoEcalCracks_ &&
185  (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance))) {
186  // add category index
187  result.rawValues.at(1) = category;
188  // return MVA output value
189  result.rawValues.at(0) = -99.;
190  return result;
191  }
193 
194  if (std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { // Barrel
195  if (numSignalGammaCandsInSigCone == 0 && !hasGsfTrack) {
196  category = 0.;
197  } else if (numSignalGammaCandsInSigCone >= 1 && !hasGsfTrack) {
198  category = 2.;
199  }
200  } else { // Endcap
201  if (numSignalGammaCandsInSigCone == 0 && !hasGsfTrack) {
202  category = 8.;
203  } else if (numSignalGammaCandsInSigCone >= 1 && !hasGsfTrack) {
204  category = 10.;
205  }
206  }
207  }
208  }
209 
210  if (verbosity_) {
211  edm::LogPrint("PFTauAgainstEleMVA6") << "<PFRecoTauDiscriminationAgainstElectronMVA6::discriminate>:";
212  edm::LogPrint("PFTauAgainstEleMVA6") << " tau: Pt = " << thePFTauRef->pt() << ", eta = " << thePFTauRef->eta()
213  << ", phi = " << thePFTauRef->phi();
214  edm::LogPrint("PFTauAgainstEleMVA6") << " deltaREleTau = " << deltaRDummy
215  << ", isGsfElectronMatched = " << isGsfElectronMatched;
216  edm::LogPrint("PFTauAgainstEleMVA6") << " #Prongs = " << thePFTauRef->signalChargedHadrCands().size();
217  edm::LogPrint("PFTauAgainstEleMVA6") << " MVA = " << result.rawValues.at(0) << ", category = " << category;
218  }
219 
220  // add category index
221  result.rawValues.at(1) = category;
222  // return MVA output value
223  return result;
224 }
225 
227  double absEta = fabs(eta);
228  return (absEta > 1.460 && absEta < 1.558);
229 }
230 
232  // pfRecoTauDiscriminationAgainstElectronMVA6
234  desc.add<double>("minMVANoEleMatchWOgWOgsfBL", 0.0);
235  desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfTauProducer"));
236  desc.add<double>("minMVANoEleMatchWgWOgsfBL", 0.0);
237  desc.add<std::string>("mvaName_wGwGSF_EC", "gbr_wGwGSF_EC");
238  desc.add<double>("minMVAWgWgsfBL", 0.0);
239  desc.add<std::string>("mvaName_woGwGSF_EC", "gbr_woGwGSF_EC");
240  desc.add<double>("minMVAWOgWgsfEC", 0.0);
241  desc.add<std::string>("mvaName_wGwGSF_BL", "gbr_wGwGSF_BL");
242  desc.add<std::string>("mvaName_woGwGSF_BL", "gbr_woGwGSF_BL");
243  desc.add<bool>("returnMVA", true);
244  desc.add<bool>("loadMVAfromDB", true);
245  {
246  edm::ParameterSetDescription pset_Prediscriminants;
247  pset_Prediscriminants.add<std::string>("BooleanOperator", "and");
248  {
250  psd1.add<double>("cut");
251  psd1.add<edm::InputTag>("Producer");
252  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
253  }
254  {
255  // encountered this at
256  // RecoTauTag/Configuration/python/HPSPFTaus_cff.py
258  psd1.add<double>("cut");
259  psd1.add<edm::InputTag>("Producer");
260  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("decayMode", psd1);
261  }
262  desc.add<edm::ParameterSetDescription>("Prediscriminants", pset_Prediscriminants);
263  }
264  desc.add<std::string>("mvaName_NoEleMatch_woGwoGSF_BL", "gbr_NoEleMatch_woGwoGSF_BL");
265  desc.add<bool>("vetoEcalCracks", true);
266  desc.add<bool>("usePhiAtEcalEntranceExtrapolation", false);
267  desc.add<std::string>("mvaName_NoEleMatch_wGwoGSF_BL", "gbr_NoEleMatch_wGwoGSF_BL");
268  desc.add<double>("minMVANoEleMatchWOgWOgsfEC", 0.0);
269  desc.add<double>("minMVAWOgWgsfBL", 0.0);
270  desc.add<double>("minMVAWgWgsfEC", 0.0);
271  desc.add<int>("verbosity", 0);
272  desc.add<std::string>("mvaName_NoEleMatch_wGwoGSF_EC", "gbr_NoEleMatch_wGwoGSF_EC");
273  desc.add<std::string>("method", "BDTG");
274  desc.add<edm::InputTag>("srcGsfElectrons", edm::InputTag("gedGsfElectrons"));
275  desc.add<std::string>("mvaName_NoEleMatch_woGwoGSF_EC", "gbr_NoEleMatch_woGwoGSF_EC");
276  desc.add<double>("minMVANoEleMatchWgWOgsfEC", 0.0);
277  descriptions.add("pfRecoTauDiscriminationAgainstElectronMVA6", desc);
278 }
279 
PFRecoTauDiscriminationAgainstElectronMVA6::vetoEcalCracks_
bool vetoEcalCracks_
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:61
ConfigurationDescriptions.h
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:30
AntiElectronIDMVA6.h
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
Muon.h
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
PFRecoTauDiscriminationAgainstElectronMVA6::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:231
TauDiscriminationProducerBase.h
PFCandidate.h
PFRecoTauDiscriminationAgainstElectronMVA6::isInEcalCrack
bool isInEcalCrack(double) const
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:226
min
T min(T a, T b)
Definition: MathUtil.h:58
edm::EDGetTokenT< reco::GsfElectronCollection >
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
PFRecoTauDiscriminationAgainstElectronMVA6::discriminate
reco::SingleTauDiscriminatorContainer discriminate(const PFTauRef &) const override
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:74
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle< reco::GsfElectronCollection >
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:105
PFRecoTauDiscriminationAgainstElectronMVA6::PFRecoTauDiscriminationAgainstElectronMVA6
PFRecoTauDiscriminationAgainstElectronMVA6(const edm::ParameterSet &cfg)
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:31
PFRecoTauDiscriminationAgainstElectronMVA6::beginEvent
void beginEvent(const edm::Event &, const edm::EventSetup &) override
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:66
edm::Ref< PFTauCollection >
FileInPath.h
deltaR.h
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
PVValHelper::eta
Definition: PVValidationHelpers.h:69
PFRecoTauDiscriminationAgainstElectronMVA6::GsfElectrons_token
edm::EDGetTokenT< reco::GsfElectronCollection > GsfElectrons_token
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:57
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
reco::Track
Definition: Track.h:27
PFRecoTauDiscriminationAgainstElectronMVA6::srcGsfElectrons_
edm::InputTag srcGsfElectrons_
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:56
TauDiscriminationProducerBase
Definition: TauDiscriminationProducerBase.h:55
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PFRecoTauDiscriminationAgainstElectronMVA6::~PFRecoTauDiscriminationAgainstElectronMVA6
~PFRecoTauDiscriminationAgainstElectronMVA6() override
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:46
PFRecoTauDiscriminationAgainstElectronMVA6::gsfElectrons_
edm::Handle< reco::GsfElectronCollection > gsfElectrons_
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:58
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
reco::PFCandidate::gsfTrackRef
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:440
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
GsfTrack.h
edm::LogPrint
Definition: MessageLogger.h:342
edm::EventSetup
Definition: EventSetup.h:57
edm::Ptr< PFCandidate >
looper.cfg
cfg
Definition: looper.py:297
PFRecoTauDiscriminationAgainstElectronMVA6::mva_
std::unique_ptr< AntiElectronIDMVA6 > mva_
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:54
boostedElectronIsolation_cff.pfGamma
pfGamma
Definition: boostedElectronIsolation_cff.py:91
PFRecoTauDiscriminationAgainstElectronMVA6
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:29
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
edm::Ptr::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
Exception.h
PFRecoTauDiscriminationAgainstElectronMVA6::moduleLabel_
std::string moduleLabel_
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:53
PFRecoTauDiscriminationAgainstElectronMVA6::verbosity_
int verbosity_
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:63
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
mps_fire.result
result
Definition: mps_fire.py:303
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
PFRecoTauDiscriminationAgainstElectronMVA6::taus_
edm::Handle< TauCollection > taus_
Definition: PFRecoTauDiscriminationAgainstElectronMVA6.cc:59
PFCandidateFwd.h
reco::SingleTauDiscriminatorContainer
Definition: TauDiscriminatorContainer.h:9