CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PFRecoTauDiscriminationAgainstElectronMVA6 Class Reference
Inheritance diagram for PFRecoTauDiscriminationAgainstElectronMVA6:
TauDiscriminationProducerBase< TauType, TauDiscriminator > edm::stream::EDProducer<>

Public Member Functions

void beginEvent (const edm::Event &, const edm::EventSetup &) override
 
double discriminate (const PFTauRef &) const override
 
void endEvent (edm::Event &) override
 
 PFRecoTauDiscriminationAgainstElectronMVA6 (const edm::ParameterSet &cfg)
 
 ~PFRecoTauDiscriminationAgainstElectronMVA6 () override
 
- Public Member Functions inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
virtual double discriminate (const TauRef &tau) const =0
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 TauDiscriminationProducerBase (const edm::ParameterSet &iConfig)
 
 TauDiscriminationProducerBase ()
 
 ~TauDiscriminationProducerBase () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Member Functions

bool isInEcalCrack (double) const
 

Private Attributes

std::unique_ptr< PFTauDiscriminatorcategory_output_
 
edm::Handle< reco::GsfElectronCollectiongsfElectrons_
 
edm::EDGetTokenT< reco::GsfElectronCollectionGsfElectrons_token
 
std::string moduleLabel_
 
std::unique_ptr< AntiElectronIDMVA6mva_
 
edm::InputTag srcGsfElectrons_
 
edm::Handle< TauCollectiontaus_
 
int verbosity_
 

Additional Inherited Members

- Public Types inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
typedef std::vector< TauType > TauCollection
 
typedef edm::Ref< TauCollectionTauRef
 
typedef edm::RefProd< TauCollectionTauRefProd
 
- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Protected Attributes inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
std::string moduleLabel_
 
double prediscriminantFailValue_
 
edm::EDGetTokenT< TauCollectionTau_token
 
size_t tauIndex_
 
edm::InputTag TauProducer_
 

Detailed Description

Definition at line 27 of file PFRecoTauDiscriminationAgainstElectronMVA6.cc.

Constructor & Destructor Documentation

PFRecoTauDiscriminationAgainstElectronMVA6::PFRecoTauDiscriminationAgainstElectronMVA6 ( const edm::ParameterSet cfg)
inlineexplicit

Definition at line 30 of file PFRecoTauDiscriminationAgainstElectronMVA6.cc.

References looper::cfg, edm::ParameterSet::exists(), and edm::ParameterSet::getParameter().

32  mva_(),
34  {
35  mva_ = std::make_unique<AntiElectronIDMVA6>(cfg);
36 
37  srcGsfElectrons_ = cfg.getParameter<edm::InputTag>("srcGsfElectrons");
38  GsfElectrons_token = consumes<reco::GsfElectronCollection>(srcGsfElectrons_);
39 
40  verbosity_ = ( cfg.exists("verbosity") ) ?
41  cfg.getParameter<int>("verbosity") : 0;
42 
43  // add category index
44  produces<PFTauDiscriminator>("category");
45  }
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< reco::GsfElectronCollection > GsfElectrons_token
TauDiscriminationProducerBase< reco::PFTau, reco::PFTauDiscriminator > PFTauDiscriminationProducerBase
PFRecoTauDiscriminationAgainstElectronMVA6::~PFRecoTauDiscriminationAgainstElectronMVA6 ( )
inlineoverride

Definition at line 53 of file PFRecoTauDiscriminationAgainstElectronMVA6.cc.

53 {}

Member Function Documentation

void PFRecoTauDiscriminationAgainstElectronMVA6::beginEvent ( const edm::Event evt,
const edm::EventSetup es 
)
overridevirtual

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 71 of file PFRecoTauDiscriminationAgainstElectronMVA6.cc.

References edm::Event::getByToken().

72 {
73  mva_->beginEvent(evt, es);
74 
77 
79 }
edm::RefProd< TauCollection > TauRefProd
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
edm::EDGetTokenT< reco::GsfElectronCollection > GsfElectrons_token
edm::EDGetTokenT< TauCollection > Tau_token
double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate ( const PFTauRef thePFTauRef) const
override

Definition at line 81 of file PFRecoTauDiscriminationAgainstElectronMVA6.cc.

References funct::abs(), taus_updatedMVAIds_cff::category, reco::deltaR(), PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi::dR, reco::TrackBase::eta(), edm::Ref< C, T, F >::isNonnull(), SiStripPI::max, min(), boostedElectronIsolation_cff::pfGamma, reco::TrackBase::pt(), and HiIsolationCommonParameters_cff::track.

82 {
83  double mvaValue = 1.;
84  double category = -1.;
85  bool isGsfElectronMatched = false;
86 
87  float deltaRDummy = 9.9;
88 
89  const float ECALBarrelEndcapEtaBorder = 1.479;
90  float tauEtaAtEcalEntrance = -99.;
91  float sumEtaTimesEnergy = 0.;
92  float sumEnergy = 0.;
93  const std::vector<reco::PFCandidatePtr>& signalPFCands = thePFTauRef->signalPFCands();
94  for ( const auto & pfCandidate : signalPFCands ) {
95  sumEtaTimesEnergy += (pfCandidate->positionAtECALEntrance().eta()*pfCandidate->energy());
96  sumEnergy += pfCandidate->energy();
97  }
98  if ( sumEnergy > 0. ) {
99  tauEtaAtEcalEntrance = sumEtaTimesEnergy/sumEnergy;
100  }
101 
102  float leadChargedPFCandEtaAtEcalEntrance = -99.;
103  float leadChargedPFCandPt = -99.;
104  for ( const auto & pfCandidate : signalPFCands ) {
105  const reco::Track* track = nullptr;
106  if ( pfCandidate->trackRef().isNonnull() ) track = pfCandidate->trackRef().get();
107  else if ( pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->innerTrack().isNonnull() ) track = pfCandidate->muonRef()->innerTrack().get();
108  else if ( pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->globalTrack().isNonnull() ) track = pfCandidate->muonRef()->globalTrack().get();
109  else if ( pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->outerTrack().isNonnull() ) track = pfCandidate->muonRef()->outerTrack().get();
110  else if ( pfCandidate->gsfTrackRef().isNonnull() ) track = pfCandidate->gsfTrackRef().get();
111  if ( track ) {
112  if ( track->pt() > leadChargedPFCandPt ) {
113  leadChargedPFCandEtaAtEcalEntrance = pfCandidate->positionAtECALEntrance().eta();
114  leadChargedPFCandPt = track->pt();
115  }
116  }
117  }
118 
119  if( (*thePFTauRef).leadPFChargedHadrCand().isNonnull()) {
120 
121  int numSignalPFGammaCandsInSigCone = 0;
122  const std::vector<reco::PFCandidatePtr>& signalPFGammaCands = thePFTauRef->signalPFGammaCands();
123 
124  for ( const auto & pfGamma : signalPFGammaCands ) {
125 
126  double dR = deltaR(pfGamma->p4(), thePFTauRef->leadPFChargedHadrCand()->p4());
127  double signalrad = std::max(0.05, std::min(0.10, 3.0/std::max(1.0, thePFTauRef->pt())));
128 
129  // pfGammas inside the tau signal cone
130  if (dR < signalrad) {
131  numSignalPFGammaCandsInSigCone += 1;
132  }
133  }
134 
135  // loop over the electrons
136  for ( const auto & theGsfElectron : *gsfElectrons_ ) {
137  if ( theGsfElectron.pt() > 10. ) { // CV: only take electrons above some minimal energy/Pt into account...
138  double deltaREleTau = deltaR(theGsfElectron.p4(), thePFTauRef->p4());
139  deltaRDummy = deltaREleTau;
140  if ( deltaREleTau < 0.3 ) {
141  double mva_match = mva_->MVAValue(*thePFTauRef, theGsfElectron);
142  bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().isNonnull();
143  if ( !hasGsfTrack )
144  hasGsfTrack = theGsfElectron.gsfTrack().isNonnull();
145 
147  if ( isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance) ) {
148  // add category index
149  category_output_->setValue(tauIndex_, category);
150  // return MVA output value
151  return -99;
152  }
154 
155  if ( std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder ) { // Barrel
156  if ( numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack ) {
157  category = 5.;
158  }
159  else if ( numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack ) {
160  category = 7.;
161  }
162  } else { // Endcap
163  if ( numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack ) {
164  category = 13.;
165  }
166  else if ( numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack ) {
167  category = 15.;
168  }
169  }
170 
171  mvaValue = std::min(mvaValue, mva_match);
172  isGsfElectronMatched = true;
173  } // deltaR < 0.3
174  } // electron pt > 10
175  } // end of loop over electrons
176 
177  if ( !isGsfElectronMatched ) {
178  mvaValue = mva_->MVAValue(*thePFTauRef);
179  bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().isNonnull();
180 
182  if ( isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance) ) {
183  // add category index
184  category_output_->setValue(tauIndex_, category);
185  // return MVA output value
186  return -99;
187  }
189 
190  if ( std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder ) { // Barrel
191  if ( numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack ) {
192  category = 0.;
193  }
194  else if ( numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack ) {
195  category = 2.;
196  }
197  } else { // Endcap
198  if ( numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack ) {
199  category = 8.;
200  }
201  else if ( numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack ) {
202  category = 10.;
203  }
204  }
205  }
206  }
207 
208  if ( verbosity_ ) {
209  edm::LogPrint("PFTauAgainstEleMVA6") << "<PFRecoTauDiscriminationAgainstElectronMVA6::discriminate>:" ;
210  edm::LogPrint("PFTauAgainstEleMVA6") << " tau: Pt = " << thePFTauRef->pt() << ", eta = " << thePFTauRef->eta() << ", phi = " << thePFTauRef->phi();
211  edm::LogPrint("PFTauAgainstEleMVA6") << " deltaREleTau = " << deltaRDummy << ", isGsfElectronMatched = " << isGsfElectronMatched;
212  edm::LogPrint("PFTauAgainstEleMVA6") << " #Prongs = " << thePFTauRef->signalPFChargedHadrCands().size();
213  edm::LogPrint("PFTauAgainstEleMVA6") << " MVA = " << mvaValue << ", category = " << category;
214  }
215 
216  // add category index
217  category_output_->setValue(tauIndex_, category);
218  // return MVA output value
219  return mvaValue;
220 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:684
double pt() const
track transverse momentum
Definition: TrackBase.h:654
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
void PFRecoTauDiscriminationAgainstElectronMVA6::endEvent ( edm::Event evt)
overridevirtual

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 222 of file PFRecoTauDiscriminationAgainstElectronMVA6.cc.

References eostools::move(), and edm::Event::put().

223 {
224  // add all category indices to event
225  evt.put(std::move(category_output_), "category");
226 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
def move(src, dest)
Definition: eostools.py:511
bool PFRecoTauDiscriminationAgainstElectronMVA6::isInEcalCrack ( double  eta) const
private

Definition at line 229 of file PFRecoTauDiscriminationAgainstElectronMVA6.cc.

References DEFINE_FWK_MODULE.

230 {
231  double absEta = fabs(eta);
232  return (absEta > 1.460 && absEta < 1.558);
233 }

Member Data Documentation

std::unique_ptr<PFTauDiscriminator> PFRecoTauDiscriminationAgainstElectronMVA6::category_output_
private
edm::Handle<reco::GsfElectronCollection> PFRecoTauDiscriminationAgainstElectronMVA6::gsfElectrons_
private
edm::EDGetTokenT<reco::GsfElectronCollection> PFRecoTauDiscriminationAgainstElectronMVA6::GsfElectrons_token
private
std::string PFRecoTauDiscriminationAgainstElectronMVA6::moduleLabel_
private
std::unique_ptr<AntiElectronIDMVA6> PFRecoTauDiscriminationAgainstElectronMVA6::mva_
private
edm::InputTag PFRecoTauDiscriminationAgainstElectronMVA6::srcGsfElectrons_
private
edm::Handle<TauCollection> PFRecoTauDiscriminationAgainstElectronMVA6::taus_
private
int PFRecoTauDiscriminationAgainstElectronMVA6::verbosity_
private