CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PFRecoTauDiscriminationAgainstElectronMVA5 Class Reference
Inheritance diagram for PFRecoTauDiscriminationAgainstElectronMVA5:
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
 
 PFRecoTauDiscriminationAgainstElectronMVA5 (const edm::ParameterSet &cfg)
 
 ~PFRecoTauDiscriminationAgainstElectronMVA5 () 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_
 
AntiElectronIDMVA5mva_
 
float * mvaInput_
 
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
 
- Static Public Member Functions inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
static std::string getTauTypeString ()
 helper method to retrieve tau type name, e.g. to build correct cfi getter More...
 
- 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 29 of file PFRecoTauDiscriminationAgainstElectronMVA5.cc.

Constructor & Destructor Documentation

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

Definition at line 32 of file PFRecoTauDiscriminationAgainstElectronMVA5.cc.

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

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

Member Function Documentation

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

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 78 of file PFRecoTauDiscriminationAgainstElectronMVA5.cc.

References edm::Event::getByToken().

79 {
80  mva_->beginEvent(evt, es);
81 
84 
86 }
edm::RefProd< TauCollection > TauRefProd
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
void beginEvent(const edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< TauCollection > Tau_token
edm::EDGetTokenT< reco::GsfElectronCollection > GsfElectrons_token
double PFRecoTauDiscriminationAgainstElectronMVA5::discriminate ( const PFTauRef thePFTauRef) const
override

Definition at line 88 of file PFRecoTauDiscriminationAgainstElectronMVA5.cc.

References Abs(), taus_updatedMVAIds_cff::category, reco::deltaR(), reco::TrackBase::eta(), edm::Ref< C, T, F >::isNonnull(), Min(), reco::TrackBase::pt(), and HiIsolationCommonParameters_cff::track.

89 {
90  double mvaValue = 1.;
91  double category = -1.;
92  bool isGsfElectronMatched = false;
93 
94  float deltaRDummy = 9.9;
95 
96  float tauEtaAtEcalEntrance = -99.;
97  float sumEtaTimesEnergy = 0.;
98  float sumEnergy = 0.;
99  const std::vector<reco::PFCandidatePtr>& signalPFCands = thePFTauRef->signalPFCands();
100  for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
101  pfCandidate != signalPFCands.end(); ++pfCandidate ) {
102  sumEtaTimesEnergy += ((*pfCandidate)->positionAtECALEntrance().eta()*(*pfCandidate)->energy());
103  sumEnergy += (*pfCandidate)->energy();
104  }
105  if ( sumEnergy > 0. ) {
106  tauEtaAtEcalEntrance = sumEtaTimesEnergy/sumEnergy;
107  }
108 
109  float leadChargedPFCandEtaAtEcalEntrance = -99.;
110  float leadChargedPFCandPt = -99.;
111  for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
112  pfCandidate != signalPFCands.end(); ++pfCandidate ) {
113  const reco::Track* track = nullptr;
114  if ( (*pfCandidate)->trackRef().isNonnull() ) track = (*pfCandidate)->trackRef().get();
115  else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->innerTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->innerTrack().get();
116  else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->globalTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->globalTrack().get();
117  else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->outerTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->outerTrack().get();
118  else if ( (*pfCandidate)->gsfTrackRef().isNonnull() ) track = (*pfCandidate)->gsfTrackRef().get();
119  if ( track ) {
120  if ( track->pt() > leadChargedPFCandPt ) {
121  leadChargedPFCandEtaAtEcalEntrance = (*pfCandidate)->positionAtECALEntrance().eta();
122  leadChargedPFCandPt = track->pt();
123  }
124  }
125  }
126 
127  if( (*thePFTauRef).leadPFChargedHadrCand().isNonnull()) {
128  for ( reco::GsfElectronCollection::const_iterator theGsfElectron = gsfElectrons_->begin();
129  theGsfElectron != gsfElectrons_->end(); ++theGsfElectron ) {
130  if ( theGsfElectron->pt() > 10. ) { // CV: only take electrons above some minimal energy/Pt into account...
131  double deltaREleTau = deltaR(theGsfElectron->p4(), thePFTauRef->p4());
132  deltaRDummy = deltaREleTau;
133  if ( deltaREleTau < 0.3 ) {
134  double mva_match = mva_->MVAValue(*thePFTauRef, *theGsfElectron);
135  size_t numSignalPFGammaCands = thePFTauRef->signalPFGammaCands().size();
136  bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().isNonnull();
137 
139  if ( isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance) ) {
140  // add category index
141  category_output_->setValue(tauIndex_, category);
142  // return MVA output value
143  return -99;
144  }
146 
147  if ( TMath::Abs(tauEtaAtEcalEntrance) < 1.479 ) { // Barrel
148  if ( numSignalPFGammaCands == 0 && !hasGsfTrack ) {
149  category = 4.;
150  } else if ( numSignalPFGammaCands == 0 && hasGsfTrack ) {
151  category = 5.;
152  } else if ( numSignalPFGammaCands >= 1 && !hasGsfTrack ) {
153  category = 6.;
154  } else if ( numSignalPFGammaCands >= 1 && hasGsfTrack ) {
155  category = 7.;
156  }
157  } else { // Endcap
158  if ( numSignalPFGammaCands == 0 && !hasGsfTrack ) {
159  category = 12.;
160  } else if ( numSignalPFGammaCands == 0 && hasGsfTrack ) {
161  category = 13.;
162  } else if ( numSignalPFGammaCands >= 1 && !hasGsfTrack ) {
163  category = 14.;
164  } else if ( numSignalPFGammaCands >= 1 && hasGsfTrack ) {
165  category = 15.;
166  }
167  }
168 
169  mvaValue = TMath::Min(mvaValue, mva_match);
170  isGsfElectronMatched = true;
171  } // deltaR < 0.3
172  } // electron pt > 10
173  } // end of loop over electrons
174 
175  if ( !isGsfElectronMatched ) {
176  mvaValue = mva_->MVAValue(*thePFTauRef);
177  size_t numSignalPFGammaCands = thePFTauRef->signalPFGammaCands().size();
178  bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().isNonnull();
179 
181  if ( isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance) ) {
182  // add category index
183  category_output_->setValue(tauIndex_, category);
184  // return MVA output value
185  return -99;
186  }
188 
189  if ( TMath::Abs(tauEtaAtEcalEntrance) < 1.479 ) { // Barrel
190  if ( numSignalPFGammaCands == 0 && !hasGsfTrack ) {
191  category = 0.;
192  } else if ( numSignalPFGammaCands == 0 && hasGsfTrack ) {
193  category = 1.;
194  } else if ( numSignalPFGammaCands >= 1 && !hasGsfTrack ) {
195  category = 2.;
196  } else if ( numSignalPFGammaCands >= 1 && hasGsfTrack ) {
197  category = 3.;
198  }
199  } else { // Endcap
200  if ( numSignalPFGammaCands == 0 && !hasGsfTrack ) {
201  category = 8.;
202  } else if ( numSignalPFGammaCands == 0 && hasGsfTrack ) {
203  category = 9.;
204  } else if ( numSignalPFGammaCands >= 1 && !hasGsfTrack ) {
205  category = 10.;
206  } else if ( numSignalPFGammaCands >= 1 && hasGsfTrack ) {
207  category = 11.;
208  }
209  }
210  }
211  }
212 
213  if ( verbosity_ ) {
214  edm::LogPrint("PFTauAgainstEleMVA5") << "<PFRecoTauDiscriminationAgainstElectronMVA5::discriminate>:" ;
215  edm::LogPrint("PFTauAgainstEleMVA5") << " tau: Pt = " << thePFTauRef->pt() << ", eta = " << thePFTauRef->eta() << ", phi = " << thePFTauRef->phi();
216  edm::LogPrint("PFTauAgainstEleMVA5") << " deltaREleTau = " << deltaRDummy << ", isGsfElectronMatched = " << isGsfElectronMatched;
217  edm::LogPrint("PFTauAgainstEleMVA5") << " #Prongs = " << thePFTauRef->signalPFChargedHadrCands().size();
218  edm::LogPrint("PFTauAgainstEleMVA5") << " MVA = " << mvaValue << ", category = " << category;
219  }
220 
221  // add category index
222  category_output_->setValue(tauIndex_, category);
223  // return MVA output value
224  return mvaValue;
225 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
T Min(T a, T b)
Definition: MathUtil.h:39
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
double pt() const
track transverse momentum
Definition: TrackBase.h:621
T Abs(T a)
Definition: MathUtil.h:49
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
double MVAValue(Float_t TauEtaAtEcalEntrance, Float_t TauPt, Float_t TauLeadChargedPFCandEtaAtEcalEntrance, Float_t TauLeadChargedPFCandPt, Float_t TaudCrackEta, Float_t TaudCrackPhi, Float_t TauEmFraction, Float_t TauSignalPFGammaCands, Float_t TauLeadPFChargedHadrHoP, Float_t TauLeadPFChargedHadrEoP, Float_t TauVisMass, Float_t TauHadrMva, const std::vector< Float_t > &GammasdEta, const std::vector< Float_t > &GammasdPhi, const std::vector< Float_t > &GammasPt, Float_t TauKFNumHits, Float_t TauGSFNumHits, Float_t TauGSFChi2, Float_t TauGSFTrackResol, Float_t TauGSFTracklnPt, Float_t TauGSFTrackEta, Float_t TauPhi, Float_t TauSignalPFChargedCands, Float_t TauHasGsf, Float_t ElecEta, Float_t ElecPhi, Float_t ElecPt, Float_t ElecEe, Float_t ElecEgamma, Float_t ElecPin, Float_t ElecPout, Float_t ElecFbrem, Float_t ElecChi2GSF, Float_t ElecGSFNumHits, Float_t ElecGSFTrackResol, Float_t ElecGSFTracklnPt, Float_t ElecGSFTrackEta)
void PFRecoTauDiscriminationAgainstElectronMVA5::endEvent ( edm::Event evt)
overridevirtual

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 227 of file PFRecoTauDiscriminationAgainstElectronMVA5.cc.

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

228 {
229  // add all category indices to event
230  evt.put(std::move(category_output_), "category");
231 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
def move(src, dest)
Definition: eostools.py:510
bool PFRecoTauDiscriminationAgainstElectronMVA5::isInEcalCrack ( double  eta) const
private

Definition at line 234 of file PFRecoTauDiscriminationAgainstElectronMVA5.cc.

References DEFINE_FWK_MODULE.

235 {
236  double absEta = fabs(eta);
237  return (absEta > 1.460 && absEta < 1.558);
238 }

Member Data Documentation

std::unique_ptr<PFTauDiscriminator> PFRecoTauDiscriminationAgainstElectronMVA5::category_output_
private
edm::Handle<reco::GsfElectronCollection> PFRecoTauDiscriminationAgainstElectronMVA5::gsfElectrons_
private
edm::EDGetTokenT<reco::GsfElectronCollection> PFRecoTauDiscriminationAgainstElectronMVA5::GsfElectrons_token
private
std::string PFRecoTauDiscriminationAgainstElectronMVA5::moduleLabel_
private
AntiElectronIDMVA5* PFRecoTauDiscriminationAgainstElectronMVA5::mva_
private
float* PFRecoTauDiscriminationAgainstElectronMVA5::mvaInput_
private
edm::InputTag PFRecoTauDiscriminationAgainstElectronMVA5::srcGsfElectrons_
private
edm::Handle<TauCollection> PFRecoTauDiscriminationAgainstElectronMVA5::taus_
private
int PFRecoTauDiscriminationAgainstElectronMVA5::verbosity_
private