CMS 3D CMS Logo

PATTauDiscriminationAgainstElectronMVA6.cc
Go to the documentation of this file.
1 /* class PATTauDiscriminationAgainstElectronMVA6
2  * created : Apr 14 2016,
3  * revised : ,
4  * Authorss : Anne-Catherine Le Bihan (IPHC)
5  */
6 
9 
12 
15 
20 
21 #include <iostream>
22 #include <sstream>
23 #include <fstream>
24 
25 using namespace pat;
26 
28 public:
31  mva_ = std::make_unique<AntiElectronIDMVA6>(cfg);
32 
33  srcElectrons = cfg.getParameter<edm::InputTag>("srcElectrons");
34  electronToken = consumes<pat::ElectronCollection>(srcElectrons);
35  vetoEcalCracks_ = cfg.getParameter<bool>("vetoEcalCracks");
36  verbosity_ = cfg.getParameter<int>("verbosity");
37  }
38 
39  void beginEvent(const edm::Event&, const edm::EventSetup&) override;
40 
41  reco::SingleTauDiscriminatorContainer discriminate(const TauRef&) const override;
42 
44 
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
46 
47 private:
48  bool isInEcalCrack(double) const;
49 
51  std::unique_ptr<AntiElectronIDMVA6> mva_;
52 
57 
59 
61 };
62 
64  mva_->beginEvent(evt, es);
65 
66  evt.getByToken(Tau_token, taus_);
67 
68  evt.getByToken(electronToken, Electrons);
69 }
70 
72  const TauRef& theTauRef) const {
74  result.rawValues = {1., -1.};
75  double category = -1.;
76  bool isGsfElectronMatched = false;
77  float deltaRDummy = 9.9;
78  const float ECALBarrelEndcapEtaBorder = 1.479;
79  float tauEtaAtEcalEntrance = theTauRef->etaAtEcalEntrance();
80  float leadChargedPFCandEtaAtEcalEntrance = theTauRef->etaAtEcalEntranceLeadChargedCand();
81 
82  if ((*theTauRef).leadChargedHadrCand().isNonnull()) {
83  int numSignalPFGammaCandsInSigCone = 0;
84  const reco::CandidatePtrVector signalGammaCands = theTauRef->signalGammaCands();
85  for (const auto& gamma : signalGammaCands) {
86  double dR = deltaR(gamma->p4(), theTauRef->leadChargedHadrCand()->p4());
87  double signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTauRef->pt())));
88  // gammas inside the tau signal cone
89  if (dR < signalrad) {
90  numSignalPFGammaCandsInSigCone += 1;
91  }
92  }
93  // loop over the electrons
94  for (const auto& theElectron : *Electrons) {
95  if (theElectron.pt() > 10.) { // CV: only take electrons above some minimal energy/Pt into account...
96  double deltaREleTau = deltaR(theElectron.p4(), theTauRef->p4());
97  deltaRDummy = deltaREleTau;
98  if (deltaREleTau < 0.3) {
99  double mva_match = mva_->MVAValue(*theTauRef, theElectron);
100  bool hasGsfTrack = false;
101  pat::PackedCandidate const* packedLeadTauCand =
102  dynamic_cast<pat::PackedCandidate const*>(theTauRef->leadChargedHadrCand().get());
103  if (abs(packedLeadTauCand->pdgId()) == 11)
104  hasGsfTrack = true;
105  if (!hasGsfTrack)
106  hasGsfTrack = theElectron.gsfTrack().isNonnull();
107 
108  // veto taus that go to Ecal crack
109  if (vetoEcalCracks_ &&
110  (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance))) {
111  // return MVA output value
112  result.rawValues.at(0) = -99;
113  return result;
114  }
115  // Veto taus that go to Ecal crack
116  if (std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { // Barrel
117  if (numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack) {
118  category = 5.;
119  } else if (numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack) {
120  category = 7.;
121  }
122  } else { // Endcap
123  if (numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack) {
124  category = 13.;
125  } else if (numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack) {
126  category = 15.;
127  }
128  }
129  result.rawValues.at(0) = std::min(result.rawValues.at(0), float(mva_match));
130  isGsfElectronMatched = true;
131  } // deltaR < 0.3
132  } // electron pt > 10
133  } // end of loop over electrons
134 
135  if (!isGsfElectronMatched) {
136  result.rawValues.at(0) = mva_->MVAValue(*theTauRef);
137  bool hasGsfTrack = false;
138  pat::PackedCandidate const* packedLeadTauCand =
139  dynamic_cast<pat::PackedCandidate const*>(theTauRef->leadChargedHadrCand().get());
140  if (abs(packedLeadTauCand->pdgId()) == 11)
141  hasGsfTrack = true;
142 
143  // veto taus that go to Ecal crack
144  if (vetoEcalCracks_ &&
145  (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance))) {
146  // add category index
147  result.rawValues.at(1) = category;
148  // return MVA output value
149  result.rawValues.at(0) = -99;
150  return result;
151  }
152  // veto taus that go to Ecal crack
153  if (std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { // Barrel
154  if (numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack) {
155  category = 0.;
156  } else if (numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack) {
157  category = 2.;
158  }
159  } else { // Endcap
160  if (numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack) {
161  category = 8.;
162  } else if (numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack) {
163  category = 10.;
164  }
165  }
166  }
167  }
168  if (verbosity_) {
169  edm::LogPrint("PATTauAgainstEleMVA6") << "<PATTauDiscriminationAgainstElectronMVA6::discriminate>:";
170  edm::LogPrint("PATTauAgainstEleMVA6")
171  << " tau: Pt = " << theTauRef->pt() << ", eta = " << theTauRef->eta() << ", phi = " << theTauRef->phi();
172  edm::LogPrint("PATTauAgainstEleMVA6")
173  << " deltaREleTau = " << deltaRDummy << ", isGsfElectronMatched = " << isGsfElectronMatched;
174  edm::LogPrint("PATTauAgainstEleMVA6") << " #Prongs = " << theTauRef->signalChargedHadrCands().size();
175  edm::LogPrint("PATTauAgainstEleMVA6") << " MVA = " << result.rawValues.at(0) << ", category = " << category;
176  }
177  // add category index
178  result.rawValues.at(1) = category;
179  // return MVA output value
180  return result;
181 }
182 
184  double absEta = fabs(eta);
185  return (absEta > 1.460 && absEta < 1.558);
186 }
187 
189  // patTauDiscriminationAgainstElectronMVA6
191  desc.add<double>("minMVANoEleMatchWOgWOgsfBL", 0.0);
192  desc.add<double>("minMVANoEleMatchWgWOgsfBL", 0.0);
193  desc.add<bool>("vetoEcalCracks", true);
194  desc.add<bool>("usePhiAtEcalEntranceExtrapolation", false);
195  desc.add<std::string>("mvaName_wGwGSF_EC", "gbr_wGwGSF_EC");
196  desc.add<double>("minMVAWgWgsfBL", 0.0);
197  desc.add<std::string>("mvaName_woGwGSF_EC", "gbr_woGwGSF_EC");
198  desc.add<double>("minMVAWOgWgsfEC", 0.0);
199  desc.add<std::string>("mvaName_wGwGSF_BL", "gbr_wGwGSF_BL");
200  desc.add<std::string>("mvaName_woGwGSF_BL", "gbr_woGwGSF_BL");
201  desc.add<bool>("returnMVA", true);
202  desc.add<bool>("loadMVAfromDB", true);
203  {
205  psd0.add<std::string>("BooleanOperator", "and");
206  {
208  psd1.add<double>("cut");
209  psd1.add<edm::InputTag>("Producer");
210  psd0.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
211  }
212  desc.add<edm::ParameterSetDescription>("Prediscriminants", psd0);
213  }
214  desc.add<std::string>("mvaName_NoEleMatch_woGwoGSF_BL", "gbr_NoEleMatch_woGwoGSF_BL");
215  desc.add<edm::InputTag>("srcElectrons", edm::InputTag("slimmedElectrons"));
216  desc.add<double>("minMVANoEleMatchWOgWOgsfEC", 0.0);
217  desc.add<std::string>("mvaName_NoEleMatch_wGwoGSF_BL", "gbr_NoEleMatch_wGwoGSF_BL");
218  desc.add<edm::InputTag>("PATTauProducer", edm::InputTag("slimmedTaus"));
219  desc.add<double>("minMVAWOgWgsfBL", 0.0);
220  desc.add<double>("minMVAWgWgsfEC", 0.0);
221  desc.add<int>("verbosity", 0);
222  desc.add<std::string>("mvaName_NoEleMatch_wGwoGSF_EC", "gbr_NoEleMatch_wGwoGSF_EC");
223  desc.add<std::string>("method", "BDTG");
224  desc.add<std::string>("mvaName_NoEleMatch_woGwoGSF_EC", "gbr_NoEleMatch_woGwoGSF_EC");
225  desc.add<double>("minMVANoEleMatchWgWOgsfEC", 0.0);
226  descriptions.add("patTauDiscriminationAgainstElectronMVA6", desc);
227 }
228 
ConfigurationDescriptions.h
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:30
AntiElectronIDMVA6.h
PATTauDiscriminationAgainstElectronMVA6::discriminate
reco::SingleTauDiscriminatorContainer discriminate(const TauRef &) const override
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:71
PATTauDiscriminator.h
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
TauDiscriminationProducerBase.h
PATTauDiscriminationAgainstElectronMVA6::electronToken
edm::EDGetTokenT< pat::ElectronCollection > electronToken
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:54
PATTauDiscriminationAgainstElectronMVA6::beginEvent
void beginEvent(const edm::Event &, const edm::EventSetup &) override
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:63
PATTauDiscriminationAgainstElectronMVA6::moduleLabel_
std::string moduleLabel_
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:50
pat::PackedCandidate::pdgId
int pdgId() const override
PDG identifier.
Definition: PackedCandidate.h:832
min
T min(T a, T b)
Definition: MathUtil.h:58
edm::EDGetTokenT< pat::ElectronCollection >
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
CustomPhysics_cfi.gamma
gamma
Definition: CustomPhysics_cfi.py:17
edm::Handle< pat::ElectronCollection >
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:105
Tau.h
edm::Ref
Definition: AssociativeIterator.h:58
FileInPath.h
PATTauDiscriminationAgainstElectronMVA6::PATTauDiscriminationAgainstElectronMVA6
PATTauDiscriminationAgainstElectronMVA6(const edm::ParameterSet &cfg)
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:29
deltaR.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
edm::PtrVector< Candidate >
PVValHelper::eta
Definition: PVValidationHelpers.h:69
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
PATTauDiscriminationAgainstElectronMVA6::taus_
edm::Handle< TauCollection > taus_
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:56
PATTauDiscriminationAgainstElectronMVA6::srcElectrons
edm::InputTag srcElectrons
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:53
PATTauDiscriminationAgainstElectronMVA6_cfi.srcElectrons
srcElectrons
Definition: PATTauDiscriminationAgainstElectronMVA6_cfi.py:36
TauDiscriminationProducerBase
Definition: TauDiscriminationProducerBase.h:55
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
ParameterSetDescription.h
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PATTauDiscriminationAgainstElectronMVA6::~PATTauDiscriminationAgainstElectronMVA6
~PATTauDiscriminationAgainstElectronMVA6() override
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:43
PATTauDiscriminationAgainstElectronMVA6::verbosity_
int verbosity_
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:60
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
PATTauDiscriminationAgainstElectronMVA6::Electrons
edm::Handle< pat::ElectronCollection > Electrons
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:55
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
pat::PackedCandidate
Definition: PackedCandidate.h:22
edm::LogPrint
Definition: MessageLogger.h:342
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
looper.cfg
cfg
Definition: looper.py:297
PATTauDiscriminationAgainstElectronMVA6::isInEcalCrack
bool isInEcalCrack(double) const
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:183
Exception.h
PATTauDiscriminationAgainstElectronMVA6::mva_
std::unique_ptr< AntiElectronIDMVA6 > mva_
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:51
mps_fire.result
result
Definition: mps_fire.py:303
Candidate.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
PATTauDiscriminationAgainstElectronMVA6::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:188
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
edm::Event
Definition: Event.h:73
PATTauDiscriminationAgainstElectronMVA6
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:27
edm::InputTag
Definition: InputTag.h:15
PATTauDiscriminationAgainstElectronMVA6::vetoEcalCracks_
bool vetoEcalCracks_
Definition: PATTauDiscriminationAgainstElectronMVA6.cc:58
HLTTauDQMOffline_cfi.Electrons
Electrons
Definition: HLTTauDQMOffline_cfi.py:31
reco::SingleTauDiscriminatorContainer
Definition: TauDiscriminatorContainer.h:9