30 qualityCutsPSet_(pset.getParameter<edm::
ParameterSet>(
"qualityCuts"))
33 "ApplyDiscriminationByTrackerIsolation");
35 "ApplyDiscriminationByECALIsolation");
37 calculateWeights_ = pset.
exists(
"ApplyDiscriminationByWeightedECALIsolation") ?
38 pset.
getParameter<
bool>(
"ApplyDiscriminationByWeightedECALIsolation") :
false;
40 applyOccupancyCut_ = pset.
getParameter<
bool>(
"applyOccupancyCut");
41 maximumOccupancy_ = pset.
getParameter<uint32_t>(
"maximumOccupancy");
43 applySumPtCut_ = pset.
getParameter<
bool>(
"applySumPtCut");
44 maximumSumPt_ = pset.
getParameter<
double>(
"maximumSumPtCut");
47 "applyRelativeSumPtCut");
50 offsetRelativeSumPt_ = pset.
exists(
"relativeSumPtOffset") ?
53 storeRawOccupancy_ = pset.
exists(
"storeRawOccupancy") ?
55 storeRawSumPt_ = pset.
exists(
"storeRawSumPt") ?
57 storeRawPUsumPt_ = pset.
exists(
"storeRawPUsumPt") ?
62 if ( applySumPtCut_ || applyOccupancyCut_ || applyRelativeSumPtCut_ ) {
63 if ( storeRawSumPt_ || storeRawOccupancy_ || storeRawPUsumPt_ ) {
65 <<
"A 'store raw' and a 'apply cut' option have been set to true "
66 <<
"simultaneously. These options are mutually exclusive.";
71 if(includeGammas_ && calculateWeights_)
74 <<
"Both 'ApplyDiscriminationByECALIsolation' and 'ApplyDiscriminationByWeightedECALIsolation' "
75 <<
"have been set to true. These options are mutually exclusive.";
79 int numStoreOptions = 0;
80 if ( storeRawSumPt_ ) ++numStoreOptions;
81 if ( storeRawOccupancy_ ) ++numStoreOptions;
82 if ( storeRawPUsumPt_ ) ++numStoreOptions;
83 if ( numStoreOptions > 1 ) {
85 <<
"Both 'store sum pt' and 'store occupancy' options are set."
86 <<
" These options are mutually exclusive.";
89 if ( pset.
exists(
"customOuterCone") ) {
90 customIsoCone_ = pset.
getParameter<
double>(
"customOuterCone");
97 "isolationQualityCuts");
101 vertexAssociator_.reset(
104 applyDeltaBeta_ = pset.
exists(
"applyDeltaBetaCorrection") ?
105 pset.
getParameter<
bool>(
"applyDeltaBetaCorrection") :
false;
107 if ( applyDeltaBeta_ || calculateWeights_ ) {
110 std::pair<edm::ParameterSet, edm::ParameterSet> puFactorizedIsoQCuts =
115 if ( pset.
exists(
"deltaBetaPUTrackPtCutOverride") ) {
116 puFactorizedIsoQCuts.second.addParameter<
double>(
118 pset.
getParameter<
double>(
"deltaBetaPUTrackPtCutOverride"));
121 puFactorizedIsoQCuts.second.addParameter<
double>(
127 puFactorizedIsoQCuts.first));
130 puFactorizedIsoQCuts.second));
133 pfCand_token=consumes<reco::PFCandidateCollection>(pfCandSrc_);
135 vertex_token=consumes<reco::VertexCollection>(vertexSrc_);
137 "isoConeSizeForDeltaBeta");
140 deltaBetaFormula_.reset(
141 new TFormula(
"DB_corr", deltaBetaFactorFormula.c_str()));
144 applyRhoCorrection_ = pset.
exists(
"applyRhoCorrection") ?
146 if ( applyRhoCorrection_ ) {
148 rho_token=consumes<double>(rhoProducer_);
149 rhoConeSize_ = pset.
getParameter<
double>(
"rhoConeSize");
150 rhoUEOffsetCorrection_ =
153 useAllPFCands_ = pset.
exists(
"UseAllPFCandsForWeights") ?
154 pset.
getParameter<
bool>(
"UseAllPFCandsForWeights") :
false;
156 verbosity_ = ( pset.
exists(
"verbosity") ) ?
163 double discriminate(
const PFTauRef& pfTau)
const override;
167 for (
auto const & inObj_ : inColl_){
168 double sum = (inObj_->pt()*inObj_->pt())/(
deltaR2(eta,phi,inObj_->eta(),inObj_->phi()));
169 if(sum > 1.0) out *= sum;
178 std::auto_ptr<tau::RecoTauQualityCuts>
qcuts_;
240 vertexAssociator_->setEvent(event);
244 if ( applyDeltaBeta_ || calculateWeights_ ) {
247 event.getByToken(pfCand_token, pfCandidates);
248 chargedPFCandidatesInEvent_.clear();
249 chargedPFCandidatesInEvent_.reserve(pfCandidates->size());
250 size_t numPFCandidates = pfCandidates->size();
251 for (
size_t i = 0;
i < numPFCandidates; ++
i ) {
253 if ( pfCandidate->charge() != 0 ) {
254 chargedPFCandidatesInEvent_.push_back(pfCandidate);
260 event.getByToken(vertex_token, vertices);
261 size_t nVtxThisEvent = vertices->size();
262 deltaBetaFactorThisEvent_ = deltaBetaFormula_->Eval(nVtxThisEvent);
265 if ( applyRhoCorrection_ ) {
267 event.getByToken(rho_token, rhoHandle_);
268 rhoThisEvent_ = (*rhoHandle_ - rhoUEOffsetCorrection_)*
269 (3.14159)*rhoConeSize_*rhoConeSize_;
276 LogDebug(
"discriminate") <<
" tau: Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta() <<
", phi = " << pfTau->phi();
277 LogDebug(
"discriminate") << *pfTau ;
280 std::vector<PFCandidatePtr> isoCharged_;
281 std::vector<PFCandidatePtr> isoNeutral_;
282 std::vector<PFCandidatePtr> isoPU_;
284 std::vector<PFCandidatePtr> chPV_;
285 isoCharged_.reserve(pfTau->isolationPFChargedHadrCands().size());
286 isoNeutral_.reserve(pfTau->isolationPFGammaCands().size());
287 isoPU_.reserve(chargedPFCandidatesInEvent_.size());
288 isoNeutralWeight_.reserve(pfTau->isolationPFGammaCands().size());
290 chPV_.reserve(chargedPFCandidatesInEvent_.size());
298 LogTrace(
"discriminate") <<
"pv: x = " << pv->position().x() <<
", y = " << pv->position().y() <<
", z = " << pv->position().z() ;
300 LogTrace(
"discriminate") <<
"pv: N/A" ;
302 if ( pfTau->leadPFChargedHadrCand().
isNonnull() ) {
303 LogTrace(
"discriminate") <<
"leadPFChargedHadron:"
304 <<
" Pt = " << pfTau->leadPFChargedHadrCand()->pt() <<
","
305 <<
" eta = " << pfTau->leadPFChargedHadrCand()->eta() <<
","
306 <<
" phi = " << pfTau->leadPFChargedHadrCand()->phi() ;
308 LogTrace(
"discriminate") <<
"leadPFChargedHadron: N/A" ;
316 qcuts_->setLeadTrack(pfTau->leadPFChargedHadrCand());
318 if ( applyDeltaBeta_ || calculateWeights_) {
319 pileupQcutsGeneralQCuts_->setPV(pv);
320 pileupQcutsGeneralQCuts_->setLeadTrack(pfTau->leadPFChargedHadrCand());
321 pileupQcutsPUTrackSelection_->setPV(pv);
322 pileupQcutsPUTrackSelection_->setLeadTrack(pfTau->leadPFChargedHadrCand());
326 if ( includeTracks_ ) {
327 for(
auto const & cand : pfTau->isolationPFChargedHadrCands() ) {
328 if ( qcuts_->filterCandRef(cand) ) {
329 LogTrace(
"discriminate") <<
"adding charged iso cand with pt " << cand->pt() ;
330 isoCharged_.push_back(cand);
334 if ( includeGammas_ || calculateWeights_ ) {
335 for(
auto const & cand : pfTau->isolationPFGammaCands() ) {
336 if ( qcuts_->filterCandRef(cand) ) {
337 LogTrace(
"discriminate") <<
"adding neutral iso cand with pt " << cand->pt() ;
338 isoNeutral_.push_back(cand);
347 if ( applyDeltaBeta_ || calculateWeights_) {
350 std::cout <<
"Initial PFCands: " << chargedPFCandidatesInEvent_.size() << std::endl;
353 std::vector<PFCandidatePtr> allPU =
354 pileupQcutsPUTrackSelection_->filterCandRefs(
355 chargedPFCandidatesInEvent_,
true);
357 std::vector<PFCandidatePtr> allNPU =
358 pileupQcutsPUTrackSelection_->filterCandRefs(
359 chargedPFCandidatesInEvent_);
360 LogTrace(
"discriminate") <<
"After track cuts: " << allPU.size() ;
364 std::vector<PFCandidatePtr> cleanPU =
365 pileupQcutsGeneralQCuts_->filterCandRefs(allPU);
367 std::vector<PFCandidatePtr> cleanNPU =
368 pileupQcutsGeneralQCuts_->filterCandRefs(allNPU);
371 LogTrace(
"discriminate") <<
"After cleaning cuts: " << cleanPU.size() ;
375 DRFilter deltaBetaFilter(pfTau->p4(), 0, deltaBetaCollectionCone_);
376 for(
auto const & cand : cleanPU) {
377 if ( deltaBetaFilter(cand) ) isoPU_.push_back(cand);
380 for(
auto const & cand : cleanNPU) {
381 if ( deltaBetaFilter(cand) ) chPV_.push_back(cand);
383 LogTrace(
"discriminate") <<
"After cone cuts: " << isoPU_.size() <<
" " << chPV_.size() ;
390 if (calculateWeights_)
392 for(
auto const & isoObject : isoNeutral_ ) {
393 if(isoObject->charge() !=0){
395 isoNeutralWeight_.push_back(*isoObject);
399 double eta=isoObject->eta();
400 double phi=isoObject->phi();
401 double sumNPU = 0.5*
log(weightedSum(chPV_,eta,phi));
403 double sumPU = 0.5*
log(weightedSum(isoPU_,eta,phi));
405 if (sumNPU+sumPU>0) neutral.
setP4(((sumNPU)/(sumNPU+sumPU))*neutral.
p4());
407 isoNeutralWeight_.push_back(neutral);
412 if ( customIsoCone_ >= 0. ) {
413 DRFilter
filter(pfTau->p4(), 0, customIsoCone_);
414 DRFilter2 filter2(pfTau->p4(), 0, customIsoCone_);
415 std::vector<PFCandidatePtr> isoCharged_filter;
416 std::vector<PFCandidatePtr> isoNeutral_filter;
419 for(
auto const & isoObject : isoCharged_ ) {
420 if (
filter(isoObject) ) isoCharged_filter.push_back(isoObject);
422 if(!calculateWeights_){
423 for(
auto const & isoObject : isoNeutral_ ) {
424 if (
filter(isoObject) ) isoNeutral_filter.push_back(isoObject);
426 isoNeutral_ = isoNeutral_filter;
428 for(
auto const & isoObject : isoNeutralWeight_){
429 if ( filter2(isoObject) ) isoNeutralWeight_filter.push_back(isoObject);
431 isoNeutralWeight_ = isoNeutralWeight_filter;
433 isoCharged_ = isoCharged_filter;
436 bool failsOccupancyCut =
false;
437 bool failsSumPtCut =
false;
438 bool failsRelativeSumPtCut =
false;
441 int neutrals = isoNeutral_.size();
443 if ( applyDeltaBeta_ ) {
444 neutrals -= TMath::Nint(deltaBetaFactorThisEvent_*isoPU_.size());
446 if ( neutrals < 0 ) {
450 size_t nOccupants = isoCharged_.size() + neutrals;
452 failsOccupancyCut = ( nOccupants > maximumOccupancy_ );
454 double totalPt = 0.0;
457 if ( applySumPtCut_ || applyRelativeSumPtCut_ || storeRawSumPt_ || storeRawPUsumPt_ ) {
458 double chargedPt = 0.0;
459 double neutralPt = 0.0;
460 double weightedNeutralPt = 0.0;
461 for(
auto const & isoObject : isoCharged_ ) {
462 chargedPt += isoObject->pt();
464 if(!calculateWeights_){
465 for(
auto const & isoObject : isoNeutral_ ) {
466 neutralPt += isoObject->pt();
469 for(
auto const & isoObject : isoNeutralWeight_){
470 weightedNeutralPt+=isoObject.pt();
473 for(
auto const & isoObject : isoPU_ ) {
474 puPt += isoObject->pt();
476 LogTrace(
"discriminate") <<
"chargedPt = " << chargedPt ;
477 LogTrace(
"discriminate") <<
"neutralPt = " << neutralPt ;
478 LogTrace(
"discriminate") <<
"weighted neutral Pt = " << weightedNeutralPt ;
479 LogTrace(
"discriminate") <<
"puPt = " << puPt <<
" (delta-beta corr. = " << (deltaBetaFactorThisEvent_*puPt) <<
")" ;
480 if( calculateWeights_) {
481 neutralPt = weightedNeutralPt;
484 if ( applyDeltaBeta_ ) {
485 neutralPt -= deltaBetaFactorThisEvent_*puPt;
488 if ( applyRhoCorrection_ ) {
489 neutralPt -= rhoThisEvent_;
492 if ( neutralPt < 0.0 ) {
496 totalPt = chargedPt + neutralPt;
497 LogTrace(
"discriminate") <<
"totalPt = " << totalPt <<
" (cut = " << maximumSumPt_ <<
")" ;
499 failsSumPtCut = (totalPt > maximumSumPt_);
502 failsRelativeSumPtCut = (totalPt > ((pfTau->pt() - offsetRelativeSumPt_)*maximumRelativeSumPt_));
505 bool fails = (applyOccupancyCut_ && failsOccupancyCut) ||
506 (applySumPtCut_ && failsSumPtCut) ||
507 (applyRelativeSumPtCut_ && failsRelativeSumPtCut);
510 if ( storeRawSumPt_ ) {
512 }
else if ( storeRawPUsumPt_ ) {
513 if ( applyDeltaBeta_ )
return puPt;
514 else if ( applyRhoCorrection_ )
return rhoThisEvent_;
516 }
else if ( storeRawOccupancy_ ) {
519 return (fails ? 0. : 1.);
PFRecoTauDiscriminationByIsolation(const edm::ParameterSet &pset)
T getParameter(std::string const &) const
double weightedSum(std::vector< PFCandidatePtr > inColl_, double eta, double phi) const
edm::EDGetTokenT< double > rho_token
bool isNonnull() const
Checks for non-null.
std::auto_ptr< tau::RecoTauQualityCuts > pileupQcutsGeneralQCuts_
#define DEFINE_FWK_MODULE(type)
~PFRecoTauDiscriminationByIsolation()
void beginEvent(const edm::Event &evt, const edm::EventSetup &evtSetup) override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual void setP4(const LorentzVector &p4)
set 4-momentum
double rhoUEOffsetCorrection_
double maximumRelativeSumPt_
bool applyRelativeSumPtCut_
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
double rhoCorrectionThisEvent_
double deltaBetaFactorThisEvent_
double offsetRelativeSumPt_
edm::EDGetTokenT< reco::PFCandidateCollection > pfCand_token
double deltaR2(const T1 &t1, const T2 &t2)
std::vector< reco::PFCandidatePtr > chargedPFCandidatesInEvent_
std::pair< edm::ParameterSet, edm::ParameterSet > factorizePUQCuts(const edm::ParameterSet &inputSet)
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 discriminate(const PFTauRef &pfTau) const override
std::auto_ptr< tau::RecoTauQualityCuts > qcuts_
std::auto_ptr< tau::RecoTauQualityCuts > pileupQcutsPUTrackSelection_
double deltaBetaCollectionCone_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
ParameterSet const & getParameterSet(std::string const &) const
uint32_t maximumOccupancy_
Particle reconstructed by the particle flow algorithm.
std::auto_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
edm::InputTag rhoProducer_
std::auto_ptr< TFormula > deltaBetaFormula_
edm::ParameterSet qualityCutsPSet_
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
edm::EDGetTokenT< reco::VertexCollection > vertex_token