8 #include <boost/foreach.hpp>
9 #include <boost/bind.hpp>
11 namespace reco {
namespace tau {
22 &
tau_->selectedSignalPFChargedHadrCands_;
24 &
tau_->selectedSignalPFGammaCands_;
26 &
tau_->selectedSignalPFNeutrHadrCands_;
28 &
tau_->selectedSignalPFCands_;
31 &
tau_->selectedIsolationPFChargedHadrCands_;
33 &
tau_->selectedIsolationPFGammaCands_;
35 &
tau_->selectedIsolationPFNeutrHadrCands_;
37 &
tau_->selectedIsolationPFCands_;
44 new SortedListPtr::element_type);
51 LogDebug(
"TauConstructorAddPFCand") <<
" region = " << region <<
", type = " << type <<
": Pt = " << ref->pt() <<
", eta = " << ref->eta() <<
", phi = " << ref->phi();
56 LogDebug(
"TauConstructorAddPFCand") <<
"--> adding PFCand to tauP4." ;
66 LogDebug(
"TauConstructorAddPFCand") <<
" region = " << region <<
", type = " << type <<
": Pt = " << ptr->pt() <<
", eta = " << ptr->eta() <<
", phi = " << ptr->phi();
71 LogDebug(
"TauConstructorAddPFCand") <<
"--> adding PFCand to tauP4." ;
93 tau_->signalTauChargedHadronCandidates_.reserve(size);
94 tau_->selectedSignalPFChargedHadrCands_.reserve(size);
96 tau_->isolationTauChargedHadronCandidates_.reserve(size);
97 tau_->selectedIsolationPFChargedHadrCands_.reserve(size);
103 void checkOverlap(
const PFCandidatePtr& neutral,
const std::vector<PFCandidatePtr>&
pfGammas,
bool& isUnique)
105 LogDebug(
"TauConstructorCheckOverlap") <<
" pfGammas: #entries = " << pfGammas.size();
106 for ( std::vector<PFCandidatePtr>::const_iterator
pfGamma = pfGammas.begin();
109 if ( (*
pfGamma) == neutral ) isUnique =
false;
113 void checkOverlap(
const PFCandidatePtr& neutral,
const std::vector<reco::RecoTauPiZero>& piZeros,
bool& isUnique)
115 LogDebug(
"TauConstructorCheckOverlap") <<
" piZeros: #entries = " << piZeros.size();
116 for ( std::vector<reco::RecoTauPiZero>::const_iterator piZero = piZeros.begin();
117 piZero != piZeros.end(); ++piZero ) {
118 size_t numPFGammas = piZero->numberOfDaughters();
119 for (
size_t iPFGamma = 0; iPFGamma < numPFGammas; ++iPFGamma ) {
121 LogDebug(
"TauConstructorCheckOverlap") <<
"pfGamma = " << pfGamma.
id() <<
":" << pfGamma.
key();
122 if ( pfGamma.
id() == neutral.
id() && pfGamma.
key() == neutral.key() ) isUnique =
false;
130 LogDebug(
"TauConstructorAddChH") <<
" region = " << region <<
": Pt = " << chargedHadron.
pt() <<
", eta = " << chargedHadron.
eta() <<
", phi = " << chargedHadron.
phi();
133 std::vector<PFCandidatePtr> neutrals_cleaned;
134 for ( std::vector<PFCandidatePtr>::const_iterator neutral = neutrals.begin();
135 neutral != neutrals.end(); ++neutral ) {
136 LogDebug(
"TauConstructorAddChH") <<
"neutral = " << neutral->id() <<
":" << neutral->key();
137 bool isUnique =
true;
139 else checkOverlap(*neutral,
tau_->signalPiZeroCandidates_, isUnique);
142 else checkOverlap(*neutral,
tau_->isolationPiZeroCandidates_, isUnique);
144 LogDebug(
"TauConstructorAddChH") <<
"--> isUnique = " << isUnique;
145 if ( isUnique ) neutrals_cleaned.push_back(*neutral);
148 if ( neutrals_cleaned.size() != neutrals.size() ) {
153 tau_->signalTauChargedHadronCandidates_.push_back(chargedHadron_cleaned);
154 p4_ += chargedHadron_cleaned.
p4();
159 for ( std::vector<PFCandidatePtr>::const_iterator neutral = neutrals.begin();
160 neutral != neutrals.end(); ++neutral ) {
165 tau_->isolationTauChargedHadronCandidates_.push_back(chargedHadron_cleaned);
171 for ( std::vector<PFCandidatePtr>::const_iterator neutral = neutrals.begin();
172 neutral != neutrals.end(); ++neutral ) {
182 tau_->signalPiZeroCandidates_.reserve(size);
187 tau_->isolationPiZeroCandidates_.reserve(size);
194 LogDebug(
"TauConstructorAddPi0") <<
" region = " << region <<
": Pt = " << piZero.
pt() <<
", eta = " << piZero.
eta() <<
", phi = " << piZero.
phi();
196 tau_->signalPiZeroCandidates_.push_back(piZero);
206 tau_->isolationPiZeroCandidates_.push_back(piZero);
214 std::vector<PFCandidatePtr>*
232 template<
typename T1,
typename T2>
233 void checkMatchedProductIds(
const T1& t1,
const T2& t2) {
234 if (t1.id() != t2.id()) {
235 throw cms::Exception(
"MismatchedPFCandSrc") <<
"Error: the input tag"
236 <<
" for the PF candidate collection provided to the RecoTauBuilder "
237 <<
" does not match the one that was used to build the source jets."
238 <<
" Please update the pfCandSrc paramters for the PFTau builders.";
246 checkMatchedProductIds(pfRef,
pfCands_);
255 checkMatchedProductIds(candPtr,
pfCands_);
261 template<
typename T>
bool ptDescending(
const T&
a,
const T&
b) {
262 return a.pt() > b.pt();
264 template<
typename T>
bool ptDescendingPtr(
const T& a,
const T& b) {
265 return a->pt() > b->pt();
272 tau_->signalTauChargedHadronCandidates_.end(),
273 ptDescending<PFRecoTauChargedHadron>);
274 std::sort(
tau_->isolationTauChargedHadronCandidates_.begin(),
275 tau_->isolationTauChargedHadronCandidates_.end(),
276 ptDescending<PFRecoTauChargedHadron>);
278 tau_->signalPiZeroCandidates_.end(),
279 ptDescending<RecoTauPiZero>);
281 tau_->isolationPiZeroCandidates_.end(),
282 ptDescending<RecoTauPiZero>);
289 sortedCollection->end(),
290 ptDescendingPtr<PFCandidatePtr>);
292 for ( std::vector<PFCandidatePtr>::const_iterator particle = sortedCollection->begin();
293 particle != sortedCollection->end(); ++particle ) {
294 colkey.second->push_back(*particle);
301 LogDebug(
"TauConstructorGet") <<
"Start getting" ;
316 double leadChargedHadronPt = 0.;
317 int leadChargedHadronCharge = 0;
318 for ( std::vector<PFRecoTauChargedHadron>::const_iterator chargedHadron =
tau_->signalTauChargedHadronCandidates_.begin();
319 chargedHadron !=
tau_->signalTauChargedHadronCandidates_.end(); ++chargedHadron ) {
322 charge += chargedHadron->charge();
323 if ( chargedHadron->pt() > leadChargedHadronPt ) {
324 leadChargedHadronPt = chargedHadron->pt();
325 leadChargedHadronCharge = chargedHadron->charge();
329 if ( nCharged == 3 )
tau_->setCharge(charge);
330 else tau_->setCharge(leadChargedHadronCharge);
333 tau_->setPdgId(
tau_->charge() < 0 ? 15 : -15);
345 tau_->setDecayMode(dm);
347 LogDebug(
"TauConstructorGet") <<
"Pt = " <<
tau_->pt() <<
", eta = " <<
tau_->eta() <<
", phi = " <<
tau_->phi() <<
", mass = " <<
tau_->mass() <<
", dm = " <<
tau_->decayMode() ;
350 tau_->setisolationPFChargedHadrCandsPtSum(
356 tau_->setisolationPFGammaCandsEtSum(
366 if ( setupLeadingObjects ) {
367 typedef std::vector<PFCandidatePtr>::const_iterator Iter;
374 tau_->setleadPFCand(*leadingCand);
382 tau_->setleadPFChargedHadrCand(*leadingChargedCand);
390 tau_->setleadPFNeutralCand(*leadingGammaCand);
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.
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.
virtual float pt() const
transverse momentum
double sumPFCandPt(InputIterator begin, InputIterator end)
Sum the pT of a collection of PFCandidates.
boost::shared_ptr< std::vector< PFCandidatePtr > > SortedListPtr
std::vector< PFCandidatePtr > * getCollection(Region region, ParticleType type)
std::vector< PFCandidatePtr > pfGammas(const PFJet &jet, bool sort=true)
Extract all pfGammas from a PFJet.
virtual float phi() const
momentum azimuthal angle
key_type key() const
Accessor for product key.
SortedCollectionMap sortedCollections_
const edm::Handle< PFCandidateCollection > & pfCands_
SortedListPtr getSortedCollection(Region region, ParticleType type)
virtual float eta() const
momentum pseudorapidity
Container::value_type value_type
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.
PFCandidatePtr convertToPtr(const PFCandidatePtr &pfPtr) const
unsigned int nCharged(const GenJet &jet)
std::auto_ptr< reco::PFTau > tau_
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.
RecoTauConstructor(const PFJetRef &jetRef, const edm::Handle< PFCandidateCollection > &pfCands, bool copyGammasFromPiZeros=false)
Constructor with PFCandidate Handle.
const daughters & daughterPtrVector() const
references to daughtes
void sortAndCopyIntoTau()
void addPiZero(Region region, const RecoTauPiZero &piZero)
Add a PiZero to the given collection.
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
tuple size
Write out results.
const PFCandidatePtr & getChargedPFCandidate() const
reference to "charged" PFCandidate (either charged PFCandidate or PFNeutralHadron) ...