2 #include <boost/foreach.hpp>
31 qualityCutsPSet_(pset.getParameter<edm::
ParameterSet>(
"qualityCuts"))
34 "ApplyDiscriminationByTrackerIsolation");
36 "ApplyDiscriminationByECALIsolation");
38 applyOccupancyCut_ = pset.
getParameter<
bool>(
"applyOccupancyCut");
39 maximumOccupancy_ = pset.
getParameter<uint32_t>(
"maximumOccupancy");
41 applySumPtCut_ = pset.
getParameter<
bool>(
"applySumPtCut");
42 maximumSumPt_ = pset.
getParameter<
double>(
"maximumSumPtCut");
45 "applyRelativeSumPtCut");
48 offsetRelativeSumPt_ = pset.
exists(
"relativeSumPtOffset") ?
51 storeRawOccupancy_ = pset.
exists(
"storeRawOccupancy") ?
53 storeRawSumPt_ = pset.
exists(
"storeRawSumPt") ?
55 storeRawPUsumPt_ = pset.
exists(
"storeRawPUsumPt") ?
60 if ( applySumPtCut_ || applyOccupancyCut_ || applyRelativeSumPtCut_ ) {
61 if ( storeRawSumPt_ || storeRawOccupancy_ || storeRawPUsumPt_ ) {
63 <<
"A 'store raw' and a 'apply cut' option have been set to true "
64 <<
"simultaneously. These options are mutually exclusive.";
69 int numStoreOptions = 0;
70 if ( storeRawSumPt_ ) ++numStoreOptions;
71 if ( storeRawOccupancy_ ) ++numStoreOptions;
72 if ( storeRawPUsumPt_ ) ++numStoreOptions;
73 if ( numStoreOptions > 1 ) {
75 <<
"Both 'store sum pt' and 'store occupancy' options are set."
76 <<
" These options are mutually exclusive.";
79 if ( pset.
exists(
"customOuterCone") ) {
80 customIsoCone_ = pset.
getParameter<
double>(
"customOuterCone");
87 "isolationQualityCuts");
91 vertexAssociator_.reset(
94 applyDeltaBeta_ = pset.
exists(
"applyDeltaBetaCorrection") ?
95 pset.
getParameter<
bool>(
"applyDeltaBetaCorrection") :
false;
97 if ( applyDeltaBeta_ ) {
100 std::pair<edm::ParameterSet, edm::ParameterSet> puFactorizedIsoQCuts =
105 if ( pset.
exists(
"deltaBetaPUTrackPtCutOverride") ) {
106 puFactorizedIsoQCuts.second.addParameter<
double>(
108 pset.
getParameter<
double>(
"deltaBetaPUTrackPtCutOverride"));
111 puFactorizedIsoQCuts.second.addParameter<
double>(
117 puFactorizedIsoQCuts.first));
120 puFactorizedIsoQCuts.second));
123 pfCand_token=consumes<reco::PFCandidateCollection>(pfCandSrc_);
125 vertex_token=consumes<reco::VertexCollection>(vertexSrc_);
127 "isoConeSizeForDeltaBeta");
130 deltaBetaFormula_.reset(
131 new TFormula(
"DB_corr", deltaBetaFactorFormula.c_str()));
134 applyRhoCorrection_ = pset.
exists(
"applyRhoCorrection") ?
136 if ( applyRhoCorrection_ ) {
138 rho_token=consumes<double>(rhoProducer_);
139 rhoConeSize_ = pset.
getParameter<
double>(
"rhoConeSize");
140 rhoUEOffsetCorrection_ =
144 verbosity_ = ( pset.
exists(
"verbosity") ) ?
151 double discriminate(
const PFTauRef& pfTau)
override;
157 std::auto_ptr<tau::RecoTauQualityCuts>
qcuts_;
220 vertexAssociator_->setEvent(event);
224 if ( applyDeltaBeta_ ) {
227 event.getByToken(pfCand_token, pfCandidates);
228 chargedPFCandidatesInEvent_.clear();
229 chargedPFCandidatesInEvent_.reserve(pfCandidates->size());
230 size_t numPFCandidates = pfCandidates->size();
231 for (
size_t i = 0;
i < numPFCandidates; ++
i ) {
233 if ( pfCandidate->charge() != 0 ) {
234 chargedPFCandidatesInEvent_.push_back(pfCandidate);
240 event.getByToken(vertex_token, vertices);
241 size_t nVtxThisEvent = vertices->size();
242 deltaBetaFactorThisEvent_ = deltaBetaFormula_->Eval(nVtxThisEvent);
245 if ( applyRhoCorrection_ ) {
247 event.getByToken(rho_token, rhoHandle_);
248 rhoThisEvent_ = (*rhoHandle_ - rhoUEOffsetCorrection_)*
249 (3.14159)*rhoConeSize_*rhoConeSize_;
257 std::cout <<
"<PFRecoTauDiscriminationByIsolation::discriminate (moduleLabel = " <<
moduleLabel_ <<
")>:" << std::endl;
258 std::cout <<
" tau: Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta() <<
", phi = " << pfTau->phi() << std::endl;
263 isoCharged_.reserve(pfTau->isolationPFChargedHadrCands().size());
265 isoNeutral_.reserve(pfTau->isolationPFGammaCands().size());
267 isoPU_.reserve(chargedPFCandidatesInEvent_.size());
275 std::cout <<
"pv: x = " << pv->position().x() <<
", y = " << pv->position().y() <<
", z = " << pv->position().z() << std::endl;
279 if ( pfTau->leadPFChargedHadrCand().
isNonnull() ) {
281 <<
" Pt = " << pfTau->leadPFChargedHadrCand()->pt() <<
","
282 <<
" eta = " << pfTau->leadPFChargedHadrCand()->eta() <<
","
283 <<
" phi = " << pfTau->leadPFChargedHadrCand()->phi() << std::endl;
285 std::cout <<
"leadPFChargedHadron: N/A" << std::endl;
293 qcuts_->setLeadTrack(pfTau->leadPFChargedHadrCand());
295 if ( applyDeltaBeta_ ) {
296 pileupQcutsGeneralQCuts_->setPV(pv);
297 pileupQcutsGeneralQCuts_->setLeadTrack(pfTau->leadPFChargedHadrCand());
298 pileupQcutsPUTrackSelection_->setPV(pv);
299 pileupQcutsPUTrackSelection_->setLeadTrack(pfTau->leadPFChargedHadrCand());
303 if ( includeTracks_ ) {
305 if ( qcuts_->filterCandRef(cand) ) {
306 isoCharged_.push_back(cand);
310 if ( includeGammas_ ) {
312 if ( qcuts_->filterCandRef(cand) ) {
313 isoNeutral_.push_back(cand);
321 if ( applyDeltaBeta_ ) {
327 std::vector<PFCandidatePtr> allPU =
328 pileupQcutsPUTrackSelection_->filterCandRefs(
329 chargedPFCandidatesInEvent_,
true);
335 std::vector<PFCandidatePtr> cleanPU =
336 pileupQcutsGeneralQCuts_->filterCandRefs(allPU);
342 DRFilter deltaBetaFilter(pfTau->p4(), 0, deltaBetaCollectionCone_);
344 if ( deltaBetaFilter(cand) ) {
345 isoPU_.push_back(cand);
354 if ( customIsoCone_ >= 0. ) {
357 DRFilter
filter(pfTau->p4(), 0, customIsoCone_);
358 std::vector<PFCandidatePtr> isoCharged_filter;
359 std::vector<PFCandidatePtr> isoNeutral_filter;
362 if (
filter(isoObject) ) isoCharged_filter.push_back(isoObject);
365 if (
filter(isoObject) ) isoNeutral_filter.push_back(isoObject);
367 isoCharged_ = isoCharged_filter;
368 isoNeutral_ = isoNeutral_filter;
371 bool failsOccupancyCut =
false;
372 bool failsSumPtCut =
false;
373 bool failsRelativeSumPtCut =
false;
376 int neutrals = isoNeutral_.size();
378 if ( applyDeltaBeta_ ) {
379 neutrals -= TMath::Nint(deltaBetaFactorThisEvent_*isoPU_.size());
381 if ( neutrals < 0 ) {
385 size_t nOccupants = isoCharged_.size() + neutrals;
387 failsOccupancyCut = ( nOccupants > maximumOccupancy_ );
389 double totalPt = 0.0;
392 if ( applySumPtCut_ || applyRelativeSumPtCut_ || storeRawSumPt_ || storeRawPUsumPt_ ) {
393 double chargedPt = 0.0;
394 double neutralPt = 0.0;
396 chargedPt += isoObject->pt();
399 neutralPt += isoObject->pt();
402 puPt += isoObject->pt();
405 std::cout <<
"chargedPt = " << chargedPt << std::endl;
406 std::cout <<
"neutralPt = " << neutralPt << std::endl;
407 std::cout <<
"puPt = " << puPt <<
" (delta-beta corr. = " << (deltaBetaFactorThisEvent_*puPt) <<
")" << std::endl;
410 if ( applyDeltaBeta_ ) {
411 neutralPt -= deltaBetaFactorThisEvent_*puPt;
414 if ( applyRhoCorrection_ ) {
415 neutralPt -= rhoThisEvent_;
418 if ( neutralPt < 0.0 ) {
422 totalPt = chargedPt + neutralPt;
424 std::cout <<
"totalPt = " << totalPt <<
" (cut = " << maximumSumPt_ <<
")" << std::endl;
427 failsSumPtCut = (totalPt > maximumSumPt_);
430 failsRelativeSumPtCut = (totalPt > ((pfTau->pt() - offsetRelativeSumPt_)*maximumRelativeSumPt_));
433 bool fails = (applyOccupancyCut_ && failsOccupancyCut) ||
434 (applySumPtCut_ && failsSumPtCut) ||
435 (applyRelativeSumPtCut_ && failsRelativeSumPtCut);
438 if ( storeRawSumPt_ ) {
440 }
else if ( storeRawPUsumPt_ ) {
441 if ( applyDeltaBeta_ )
return puPt;
442 else if ( applyRhoCorrection_ )
return rhoThisEvent_;
444 }
else if ( storeRawOccupancy_ ) {
447 return (fails ? 0. : 1.);
PFRecoTauDiscriminationByIsolation(const edm::ParameterSet &pset)
T getParameter(std::string const &) const
edm::EDGetTokenT< double > rho_token
std::auto_ptr< tau::RecoTauQualityCuts > pileupQcutsGeneralQCuts_
std::vector< PFCandidatePtr > isoCharged_
~PFRecoTauDiscriminationByIsolation()
void beginEvent(const edm::Event &evt, const edm::EventSetup &evtSetup) override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::vector< PFCandidatePtr > isoNeutral_
double rhoUEOffsetCorrection_
double maximumRelativeSumPt_
bool applyRelativeSumPtCut_
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
double rhoCorrectionThisEvent_
double deltaBetaFactorThisEvent_
double offsetRelativeSumPt_
bool isNonnull() const
Checks for non-null.
edm::EDGetTokenT< reco::PFCandidateCollection > pfCand_token
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
std::vector< PFCandidatePtr > isoPU_
double discriminate(const PFTauRef &pfTau) override
std::auto_ptr< tau::RecoTauQualityCuts > qcuts_
std::auto_ptr< tau::RecoTauQualityCuts > pileupQcutsPUTrackSelection_
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
double deltaBetaCollectionCone_
ParameterSet const & getParameterSet(std::string const &) const
uint32_t maximumOccupancy_
std::auto_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
edm::InputTag rhoProducer_
std::auto_ptr< TFormula > deltaBetaFormula_
edm::ParameterSet qualityCutsPSet_
edm::EDGetTokenT< reco::VertexCollection > vertex_token