10 #include <boost/foreach.hpp> 11 #include <boost/bind.hpp> 13 namespace reco {
namespace tau {
16 bool copyGammasFromPiZeros,
20 : signalConeSize_(signalConeSize),
21 minAbsPhotonSumPt_insideSignalCone_(minAbsPhotonSumPt_insideSignalCone),
22 minRelPhotonSumPt_insideSignalCone_(minRelPhotonSumPt_insideSignalCone),
23 minAbsPhotonSumPt_outsideSignalCone_(minAbsPhotonSumPt_outsideSignalCone),
24 minRelPhotonSumPt_outsideSignalCone_(minRelPhotonSumPt_outsideSignalCone),
33 &
tau_->selectedSignalPFChargedHadrCands_;
35 &
tau_->selectedSignalPFGammaCands_;
37 &
tau_->selectedSignalPFNeutrHadrCands_;
39 &
tau_->selectedSignalPFCands_;
42 &
tau_->selectedIsolationPFChargedHadrCands_;
44 &
tau_->selectedIsolationPFGammaCands_;
46 &
tau_->selectedIsolationPFNeutrHadrCands_;
48 &
tau_->selectedIsolationPFCands_;
55 new SortedListPtr::element_type);
62 LogDebug(
"TauConstructorAddPFCand") <<
" region = " << region <<
", type = " << type <<
": Pt = " << ref->pt() <<
", eta = " << ref->eta() <<
", phi = " << ref->phi();
67 LogDebug(
"TauConstructorAddPFCand") <<
"--> adding PFCand to tauP4." ;
77 LogDebug(
"TauConstructorAddPFCand") <<
" region = " << region <<
", type = " << type <<
": Pt = " << ptr->pt() <<
", eta = " << ptr->eta() <<
", phi = " << ptr->phi();
82 LogDebug(
"TauConstructorAddPFCand") <<
"--> adding PFCand to tauP4." ;
104 tau_->signalTauChargedHadronCandidatesRestricted().reserve(size);
105 tau_->selectedSignalPFChargedHadrCands_.reserve(size);
107 tau_->isolationTauChargedHadronCandidatesRestricted().reserve(size);
108 tau_->selectedIsolationPFChargedHadrCands_.reserve(size);
116 LogDebug(
"TauConstructorCheckOverlap") <<
" pfGammas: #entries = " << pfGammas.size();
117 for ( std::vector<PFCandidatePtr>::const_iterator
pfGamma = pfGammas.begin();
120 if ( (*
pfGamma) == neutral ) isUnique =
false;
126 LogDebug(
"TauConstructorCheckOverlap") <<
" piZeros: #entries = " << piZeros.size();
127 for ( std::vector<reco::RecoTauPiZero>::const_iterator piZero = piZeros.begin();
128 piZero != piZeros.end(); ++piZero ) {
129 size_t numPFGammas = piZero->numberOfDaughters();
130 for (
size_t iPFGamma = 0; iPFGamma < numPFGammas; ++iPFGamma ) {
132 LogDebug(
"TauConstructorCheckOverlap") <<
"pfGamma = " << pfGamma.
id() <<
":" << pfGamma.
key();
133 if ( pfGamma.
id() == neutral.
id() && pfGamma.
key() == neutral.
key() ) isUnique =
false;
141 LogDebug(
"TauConstructorAddChH") <<
" region = " << region <<
": Pt = " << chargedHadron.
pt() <<
", eta = " << chargedHadron.
eta() <<
", phi = " << chargedHadron.
phi();
144 std::vector<PFCandidatePtr> neutrals_cleaned;
145 for ( std::vector<PFCandidatePtr>::const_iterator neutral = neutrals.begin();
146 neutral != neutrals.end(); ++neutral ) {
147 LogDebug(
"TauConstructorAddChH") <<
"neutral = " << neutral->id() <<
":" << neutral->key();
148 bool isUnique =
true;
150 else checkOverlap(*neutral,
tau_->signalPiZeroCandidatesRestricted(), isUnique);
153 else checkOverlap(*neutral,
tau_->isolationPiZeroCandidatesRestricted(), isUnique);
155 LogDebug(
"TauConstructorAddChH") <<
"--> isUnique = " << isUnique;
156 if ( isUnique ) neutrals_cleaned.push_back(*neutral);
159 if ( neutrals_cleaned.size() != neutrals.size() ) {
164 tau_->signalTauChargedHadronCandidatesRestricted().push_back(chargedHadron_cleaned);
165 p4_ += chargedHadron_cleaned.
p4();
170 for ( std::vector<PFCandidatePtr>::const_iterator neutral = neutrals.begin();
171 neutral != neutrals.end(); ++neutral ) {
176 tau_->isolationTauChargedHadronCandidatesRestricted().push_back(chargedHadron_cleaned);
182 for ( std::vector<PFCandidatePtr>::const_iterator neutral = neutrals.begin();
183 neutral != neutrals.end(); ++neutral ) {
193 tau_->signalPiZeroCandidatesRestricted().reserve(size);
198 tau_->isolationPiZeroCandidatesRestricted().reserve(size);
205 LogDebug(
"TauConstructorAddPi0") <<
" region = " << region <<
": Pt = " << piZero.
pt() <<
", eta = " << piZero.
eta() <<
", phi = " << piZero.
phi();
207 tau_->signalPiZeroCandidatesRestricted().push_back(piZero);
217 tau_->isolationPiZeroCandidatesRestricted().push_back(piZero);
225 std::vector<PFCandidatePtr>*
243 template<
typename T1,
typename T2>
244 void checkMatchedProductIds(
const T1& t1,
const T2&
t2) {
245 if (t1.id() != t2.id()) {
246 throw cms::Exception(
"MismatchedPFCandSrc") <<
"Error: the input tag" 247 <<
" for the PF candidate collection provided to the RecoTauBuilder " 248 <<
" does not match the one that was used to build the source jets." 249 <<
" Please update the pfCandSrc paramters for the PFTau builders.";
257 checkMatchedProductIds(pfRef,
pfCands_);
266 checkMatchedProductIds(candPtr,
pfCands_);
272 template<
typename T>
bool ptDescending(
const T&
a,
const T&
b) {
273 return a.pt() > b.pt();
275 template<
typename T>
bool ptDescendingPtr(
const T& a,
const T& b) {
276 return a->pt() > b->pt();
282 std::sort(
tau_->signalTauChargedHadronCandidatesRestricted().begin(),
283 tau_->signalTauChargedHadronCandidatesRestricted().end(),
284 ptDescending<PFRecoTauChargedHadron>);
285 std::sort(
tau_->isolationTauChargedHadronCandidatesRestricted().begin(),
286 tau_->isolationTauChargedHadronCandidatesRestricted().end(),
287 ptDescending<PFRecoTauChargedHadron>);
288 std::sort(
tau_->signalPiZeroCandidatesRestricted().begin(),
289 tau_->signalPiZeroCandidatesRestricted().end(),
290 ptDescending<RecoTauPiZero>);
291 std::sort(
tau_->isolationPiZeroCandidatesRestricted().begin(),
292 tau_->isolationPiZeroCandidatesRestricted().end(),
293 ptDescending<RecoTauPiZero>);
299 std::sort(sortedCollection->begin(),
300 sortedCollection->end(),
301 ptDescendingPtr<PFCandidatePtr>);
303 for ( std::vector<PFCandidatePtr>::const_iterator particle = sortedCollection->begin();
304 particle != sortedCollection->end(); ++particle ) {
305 colkey.second->push_back(*particle);
322 for ( std::vector<RecoTauPiZero>::const_iterator piZero = piZeros.begin();
323 piZero != piZeros.end(); ++piZero ) {
324 double photonSumPt_insideSignalCone = 0.;
325 double photonSumPt_outsideSignalCone = 0.;
326 int numPhotons = piZero->numberOfDaughters();
327 for (
int idxPhoton = 0; idxPhoton < numPhotons; ++idxPhoton ) {
330 if ( dR < dRsignalCone ) {
331 photonSumPt_insideSignalCone += photon->
pt();
333 photonSumPt_outsideSignalCone += photon->
pt();
336 if ( photonSumPt_insideSignalCone > minAbsPhotonSumPt_insideSignalCone || photonSumPt_insideSignalCone > (minRelPhotonSumPt_insideSignalCone*tau.
pt()) ||
337 photonSumPt_outsideSignalCone > minAbsPhotonSumPt_outsideSignalCone || photonSumPt_outsideSignalCone > (minRelPhotonSumPt_outsideSignalCone*tau.
pt()) ) ++
nPiZeros;
344 unsigned int trackIndex = (nCharged - 1)*(maxPiZeros + 1);
349 if ( nPiZeros > maxPiZeros ) nPiZeros =
maxPiZeros;
356 LogDebug(
"TauConstructorGet") <<
"Start getting" ;
371 double leadChargedHadronPt = 0.;
372 int leadChargedHadronCharge = 0;
373 for ( std::vector<PFRecoTauChargedHadron>::const_iterator
chargedHadron =
tau_->signalTauChargedHadronCandidatesRestricted().begin();
384 if ( nCharged == 3 )
tau_->setCharge(charge);
385 else tau_->setCharge(leadChargedHadronCharge);
388 tau_->setPdgId(
tau_->charge() < 0 ? 15 : -15);
395 tau_->setSignalConeSize(dRsignalCone);
400 tau_->setDecayMode(dm);
402 LogDebug(
"TauConstructorGet") <<
"Pt = " <<
tau_->pt() <<
", eta = " <<
tau_->eta() <<
", phi = " <<
tau_->phi() <<
", mass = " <<
tau_->mass() <<
", dm = " <<
tau_->decayMode() ;
405 tau_->setisolationPFChargedHadrCandsPtSum(
411 tau_->setisolationPFGammaCandsEtSum(
421 if ( setupLeadingObjects ) {
422 typedef std::vector<PFCandidatePtr>::const_iterator Iter;
429 tau_->setleadPFCand(*leadingCand);
437 tau_->setleadPFChargedHadrCand(*leadingChargedCand);
445 tau_->setleadPFNeutralCand(*leadingGammaCand);
virtual double pt() const final
transverse momentum
void addPFCand(Region region, ParticleType type, const PFCandidateRef &ref, bool skipAddToP4=false)
Append a PFCandidateRef/Ptr to a given collection.
void addTauChargedHadron(Region region, const PFRecoTauChargedHadron &chargedHadron)
Add a ChargedHadron to the given collection.
double minRelPhotonSumPt_outsideSignalCone_
reco::Candidate::LorentzVector p4_
std::auto_ptr< reco::PFTau > get(bool setupLeadingCandidates=true)
CollectionMap collections_
bool isNonnull() const
Checks for non-null.
void reserve(Region region, ParticleType type, size_t size)
Reserve a set amount of space for a given RefVector.
double sumPFCandPt(InputIterator begin, InputIterator end)
Sum the pT of a collection of PFCandidates.
boost::shared_ptr< std::vector< PFCandidatePtr > > SortedListPtr
virtual double eta() const final
momentum pseudorapidity
std::vector< PFCandidatePtr > * getCollection(Region region, ParticleType type)
std::vector< PFCandidatePtr > pfGammas(const PFJet &jet, bool sort=true)
Extract all pfGammas from a PFJet.
key_type key() const
Accessor for product key.
minRelPhotonSumPt_outsideSignalCone
virtual double phi() const final
momentum azimuthal angle
SortedCollectionMap sortedCollections_
RecoTauConstructor(const PFJetRef &jetRef, const edm::Handle< PFCandidateCollection > &pfCands, bool copyGammasFromPiZeros=false, const StringObjectFunction< reco::PFTau > *signalConeSize=0, double minAbsPhotonSumPt_insideSignalCone=2.5, double minRelPhotonSumPt_insideSignalCone=0., double minAbsPhotonSumPt_outsideSignalCone=1.e+9, double minRelPhotonSumPt_outsideSignalCone=1.e+9)
Constructor with PFCandidate Handle.
const edm::Handle< PFCandidateCollection > & pfCands_
Container::value_type value_type
auto const T2 &decltype(t1.eta()) t2
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
const std::vector< RecoTauPiZero > & signalPiZeroCandidates() const
Retrieve the association of signal region gamma candidates into candidate PiZeros.
SortedListPtr getSortedCollection(Region region, ParticleType type)
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
void addPFCands(Region region, ParticleType type, const InputIterator &begin, const InputIterator &end)
InputIterator leadPFCand(InputIterator begin, InputIterator end)
bool isNonnull() const
Checks for non-null.
double minAbsPhotonSumPt_outsideSignalCone_
PFCandidatePtr convertToPtr(const PFCandidatePtr &pfPtr) const
virtual double pt() const =0
transverse momentum
std::auto_ptr< reco::PFTau > tau_
minAbsPhotonSumPt_insideSignalCone
void reserveTauChargedHadron(Region region, size_t size)
Reserve a set amount of space for the ChargedHadrons.
const std::vector< PFCandidatePtr > & getNeutralPFCandidates() const
references to additional neutral PFCandidates
void reservePiZero(Region region, size_t size)
Reserve a set amount of space for the PiZeros.
std::vector< PFCandidatePtr > neutralPFCandidates_
ProductID id() const
Accessor for product ID.
double minRelPhotonSumPt_insideSignalCone_
def checkOverlap(process)
minAbsPhotonSumPt_outsideSignalCone
const daughters & daughterPtrVector() const
references to daughtes
void sortAndCopyIntoTau()
const std::vector< PFRecoTauChargedHadron > & signalTauChargedHadronCandidates() const
Retrieve the association of signal region PF candidates into candidate PFRecoTauChargedHadrons.
minRelPhotonSumPt_insideSignalCone
void addPiZero(Region region, const RecoTauPiZero &piZero)
Add a PiZero to the given collection.
const StringObjectFunction< reco::PFTau > * signalConeSize_
virtual const LorentzVector & p4() const final
four-momentum Lorentz vector
double minAbsPhotonSumPt_insideSignalCone_
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
const PFCandidatePtr & getChargedPFCandidate() const
reference to "charged" PFCandidate (either charged PFCandidate or PFNeutralHadron) ...