00001
00002
00003
00004
00005 #include "DataFormats/PatCandidates/interface/Tau.h"
00006 #include "DataFormats/JetReco/interface/GenJet.h"
00007
00008
00009 using namespace pat;
00010
00011
00013 Tau::Tau() :
00014 Lepton<reco::BaseTau>(),
00015 embeddedIsolationTracks_(false),
00016 embeddedLeadTrack_(false),
00017 embeddedSignalTracks_(false)
00018 ,embeddedLeadPFCand_(false)
00019 ,embeddedLeadPFChargedHadrCand_(false)
00020 ,embeddedLeadPFNeutralCand_(false)
00021 ,embeddedSignalPFCands_(false)
00022 ,embeddedSignalPFChargedHadrCands_(false)
00023 ,embeddedSignalPFNeutralHadrCands_(false)
00024 ,embeddedSignalPFGammaCands_(false)
00025 ,embeddedIsolationPFCands_(false)
00026 ,embeddedIsolationPFChargedHadrCands_(false)
00027 ,embeddedIsolationPFNeutralHadrCands_(false)
00028 ,embeddedIsolationPFGammaCands_(false)
00029 {
00030 }
00031
00033 Tau::Tau(const reco::BaseTau & aTau) :
00034 Lepton<reco::BaseTau>(aTau),
00035 embeddedIsolationTracks_(false),
00036 embeddedLeadTrack_(false),
00037 embeddedSignalTracks_(false)
00038 ,embeddedLeadPFCand_(false)
00039 ,embeddedLeadPFChargedHadrCand_(false)
00040 ,embeddedLeadPFNeutralCand_(false)
00041 ,embeddedSignalPFCands_(false)
00042 ,embeddedSignalPFChargedHadrCands_(false)
00043 ,embeddedSignalPFNeutralHadrCands_(false)
00044 ,embeddedSignalPFGammaCands_(false)
00045 ,embeddedIsolationPFCands_(false)
00046 ,embeddedIsolationPFChargedHadrCands_(false)
00047 ,embeddedIsolationPFNeutralHadrCands_(false)
00048 ,embeddedIsolationPFGammaCands_(false)
00049 {
00050 const reco::PFTau * pfTau = dynamic_cast<const reco::PFTau *>(&aTau);
00051 if (pfTau != 0) pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau));
00052 const reco::CaloTau * caloTau = dynamic_cast<const reco::CaloTau *>(&aTau);
00053 if (caloTau != 0) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau));
00054 }
00055
00057 Tau::Tau(const edm::RefToBase<reco::BaseTau> & aTauRef) :
00058 Lepton<reco::BaseTau>(aTauRef),
00059 embeddedIsolationTracks_(false),
00060 embeddedLeadTrack_(false),
00061 embeddedSignalTracks_(false)
00062 ,embeddedLeadPFCand_(false)
00063 ,embeddedLeadPFChargedHadrCand_(false)
00064 ,embeddedLeadPFNeutralCand_(false)
00065 ,embeddedSignalPFCands_(false)
00066 ,embeddedSignalPFChargedHadrCands_(false)
00067 ,embeddedSignalPFNeutralHadrCands_(false)
00068 ,embeddedSignalPFGammaCands_(false)
00069 ,embeddedIsolationPFCands_(false)
00070 ,embeddedIsolationPFChargedHadrCands_(false)
00071 ,embeddedIsolationPFNeutralHadrCands_(false)
00072 ,embeddedIsolationPFGammaCands_(false)
00073 {
00074 const reco::PFTau * pfTau = dynamic_cast<const reco::PFTau *>(aTauRef.get());
00075 if (pfTau != 0) pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau));
00076 const reco::CaloTau * caloTau = dynamic_cast<const reco::CaloTau *>(aTauRef.get());
00077 if (caloTau != 0) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau));
00078 }
00079
00081 Tau::Tau(const edm::Ptr<reco::BaseTau> & aTauRef) :
00082 Lepton<reco::BaseTau>(aTauRef),
00083 embeddedIsolationTracks_(false),
00084 embeddedLeadTrack_(false),
00085 embeddedSignalTracks_(false)
00086 ,embeddedLeadPFCand_(false)
00087 ,embeddedLeadPFChargedHadrCand_(false)
00088 ,embeddedLeadPFNeutralCand_(false)
00089 ,embeddedSignalPFCands_(false)
00090 ,embeddedSignalPFChargedHadrCands_(false)
00091 ,embeddedSignalPFNeutralHadrCands_(false)
00092 ,embeddedSignalPFGammaCands_(false)
00093 ,embeddedIsolationPFCands_(false)
00094 ,embeddedIsolationPFChargedHadrCands_(false)
00095 ,embeddedIsolationPFNeutralHadrCands_(false)
00096 ,embeddedIsolationPFGammaCands_(false)
00097 {
00098 const reco::PFTau * pfTau = dynamic_cast<const reco::PFTau *>(aTauRef.get());
00099 if (pfTau != 0) pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau));
00100 const reco::CaloTau * caloTau = dynamic_cast<const reco::CaloTau *>(aTauRef.get());
00101 if (caloTau != 0) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau));
00102 }
00103
00105 Tau::~Tau() {
00106 }
00107
00108 std::ostream&
00109 reco::operator<<(std::ostream& out, const pat::Tau& obj)
00110 {
00111 if(!out) return out;
00112
00113 out << "\tpat::Tau: ";
00114 out << std::setiosflags(std::ios::right);
00115 out << std::setiosflags(std::ios::fixed);
00116 out << std::setprecision(3);
00117 out << " E/pT/eta/phi "
00118 << obj.energy()<<"/"
00119 << obj.pt()<<"/"
00120 << obj.eta()<<"/"
00121 << obj.phi();
00122 return out;
00123 }
00124
00126 const reco::TrackRefVector & Tau::isolationTracks() const {
00127 if (embeddedIsolationTracks_) {
00128 if (!isolationTracksTransientRefVectorFixed_) {
00129 reco::TrackRefVector trackRefVec;
00130 for (unsigned int i = 0; i < isolationTracks_.size(); i++) {
00131 trackRefVec.push_back(reco::TrackRef(&isolationTracks_, i));
00132 }
00133 isolationTracksTransientRefVector_.swap(trackRefVec);
00134 isolationTracksTransientRefVectorFixed_ = true;
00135 }
00136 return isolationTracksTransientRefVector_;
00137 } else {
00138 return reco::BaseTau::isolationTracks();
00139 }
00140 }
00141
00142
00144 reco::TrackRef Tau::leadTrack() const {
00145 if (embeddedLeadTrack_) {
00146 return reco::TrackRef(&leadTrack_, 0);
00147 } else {
00148 return reco::BaseTau::leadTrack();
00149 }
00150 }
00151
00152
00154 const reco::TrackRefVector & Tau::signalTracks() const {
00155 if (embeddedSignalTracks_) {
00156 reco::TrackRefVector trackRefVec;
00157 if (!signalTracksTransientRefVectorFixed_) {
00158 for (unsigned int i = 0; i < signalTracks_.size(); i++) {
00159 trackRefVec.push_back(reco::TrackRef(&signalTracks_, i));
00160 }
00161 signalTracksTransientRefVector_.swap(trackRefVec);
00162 signalTracksTransientRefVectorFixed_ = true;
00163 }
00164 return signalTracksTransientRefVector_;
00165 } else {
00166 return reco::BaseTau::signalTracks();
00167 }
00168 }
00169
00170
00172 void Tau::embedIsolationTracks() {
00173 isolationTracks_.clear();
00174 reco::TrackRefVector trackRefVec = reco::BaseTau::isolationTracks();
00175 for (unsigned int i = 0; i < trackRefVec.size(); i++) {
00176 isolationTracks_.push_back(*trackRefVec.at(i));
00177 }
00178 embeddedIsolationTracks_ = true;
00179 }
00180
00181
00183 void Tau::embedLeadTrack() {
00184 leadTrack_.clear();
00185 if (reco::BaseTau::leadTrack().isNonnull()) {
00186 leadTrack_.push_back(*reco::BaseTau::leadTrack());
00187 embeddedLeadTrack_ = true;
00188 }
00189 }
00190
00191
00193 void Tau::embedSignalTracks(){
00194 signalTracks_.clear();
00195 reco::TrackRefVector trackRefVec = reco::BaseTau::signalTracks();
00196 for (unsigned int i = 0; i < trackRefVec.size(); i++) {
00197 signalTracks_.push_back(*trackRefVec.at(i));
00198 }
00199 embeddedSignalTracks_ = true;
00200 }
00201
00202
00204 void Tau::setGenJet(const reco::GenJetRef& gj) {
00205 genJet_.clear();
00206 genJet_.push_back(*gj);
00207 }
00208
00210 const reco::GenJet * Tau::genJet() const {
00211 return (genJet_.size() > 0 ? &genJet_.front() : 0);
00212 }
00213
00214
00215
00216 float Tau::tauID(const std::string & name) const {
00217 for (std::vector<IdPair>::const_iterator it = tauIDs_.begin(), ed = tauIDs_.end(); it != ed; ++it) {
00218 if (it->first == name) return it->second;
00219 }
00220 cms::Exception ex("Key not found");
00221 ex << "pat::Tau: the ID " << name << " can't be found in this pat::Tau.\n";
00222 ex << "The available IDs are: ";
00223 for (std::vector<IdPair>::const_iterator it = tauIDs_.begin(), ed = tauIDs_.end(); it != ed; ++it) {
00224 ex << "'" << it->first << "' ";
00225 }
00226 ex << ".\n";
00227 throw ex;
00228 }
00229
00230 bool Tau::isTauIDAvailable(const std::string & name) const {
00231 for (std::vector<IdPair>::const_iterator it = tauIDs_.begin(), ed = tauIDs_.end(); it != ed; ++it) {
00232 if (it->first == name) return true;
00233 }
00234 return false;
00235 }
00236
00237
00238 const pat::tau::TauPFSpecific & Tau::pfSpecific() const {
00239 if (!isPFTau()) throw cms::Exception("Type Error") << "Requesting a PFTau-specific information from a pat::Tau which wasn't made from a PFTau.\n";
00240 return pfSpecific_[0];
00241 }
00242
00243 const pat::tau::TauCaloSpecific & Tau::caloSpecific() const {
00244 if (!isCaloTau()) throw cms::Exception("Type Error") << "Requesting a CaloTau-specific information from a pat::Tau which wasn't made from a CaloTau.\n";
00245 return caloSpecific_[0];
00246 }
00247
00248 float Tau::etaetaMoment() const
00249 {
00250 if ( isCaloTau() ) return caloSpecific().etaetaMoment_;
00251 if ( isPFTau() ) return pfSpecific().etaetaMoment_;
00252 throw cms::Exception("Type Error") << "Requesting a CaloTau/PFTau-specific information from a pat::Tau which wasn't made from either a CaloTau or a PFTau.\n";
00253 }
00254
00255 float Tau::phiphiMoment() const
00256 {
00257 if ( isCaloTau() ) return caloSpecific().phiphiMoment_;
00258 if ( isPFTau() ) return pfSpecific().phiphiMoment_;
00259 throw cms::Exception("Type Error") << "Requesting a CaloTau/PFTau-specific information from a pat::Tau which wasn't made from either a CaloTau or a PFTau.\n";
00260 }
00261
00262 float Tau::etaphiMoment() const
00263 {
00264 if ( isCaloTau() ) return caloSpecific().etaphiMoment_;
00265 if ( isPFTau() ) return pfSpecific().etaphiMoment_;
00266 throw cms::Exception("Type Error") << "Requesting a CaloTau/PFTau-specific information from a pat::Tau which wasn't made from either a CaloTau or a PFTau.\n";
00267 }
00268
00269 void Tau::setDecayMode(int decayMode)
00270 {
00271 if (!isPFTau()) throw cms::Exception("Type Error") << "Requesting a PFTau-specific information from a pat::Tau which wasn't made from a PFTau.\n";
00272 pfSpecific_[0].decayMode_ = decayMode;
00273 }
00274
00276 void Tau::embedLeadPFCand() {
00277 if (!isPFTau() ) {
00278 return;
00279 }
00280 leadPFCand_.clear();
00281 if (pfSpecific_[0].leadPFCand_.isNonnull() ) {
00282 leadPFCand_.push_back(*pfSpecific_[0].leadPFCand_);
00283 embeddedLeadPFCand_ = true;
00284 }
00285 }
00287 void Tau::embedLeadPFChargedHadrCand() {
00288 if (!isPFTau() ) {
00289 return;
00290 }
00291 leadPFChargedHadrCand_.clear();
00292 if (pfSpecific_[0].leadPFChargedHadrCand_.isNonnull() ) {
00293 leadPFChargedHadrCand_.push_back(*pfSpecific_[0].leadPFChargedHadrCand_);
00294 embeddedLeadPFChargedHadrCand_ = true;
00295 }
00296 }
00298 void Tau::embedLeadPFNeutralCand() {
00299 if (!isPFTau() ) {
00300 return;
00301 }
00302 leadPFNeutralCand_.clear();
00303 if (pfSpecific_[0].leadPFNeutralCand_.isNonnull() ) {
00304 leadPFNeutralCand_.push_back(*pfSpecific_[0].leadPFNeutralCand_);
00305 embeddedLeadPFNeutralCand_ = true;
00306 }
00307 }
00308
00309 void Tau::embedSignalPFCands() {
00310 if (!isPFTau() ) {
00311 return;
00312 }
00313 reco::PFCandidateRefVector candRefVec = pfSpecific_[0].selectedSignalPFCands_;
00314 for (unsigned int i = 0; i < candRefVec.size(); i++) {
00315 signalPFCands_.push_back(*candRefVec.at(i));
00316 }
00317 embeddedSignalPFCands_ = true;
00318 }
00319 void Tau::embedSignalPFChargedHadrCands() {
00320 if (!isPFTau() ) {
00321 return;
00322 }
00323 reco::PFCandidateRefVector candRefVec = pfSpecific_[0].selectedSignalPFChargedHadrCands_;
00324 for (unsigned int i = 0; i < candRefVec.size(); i++) {
00325 signalPFChargedHadrCands_.push_back(*candRefVec.at(i));
00326 }
00327 embeddedSignalPFChargedHadrCands_ = true;
00328 }
00329 void Tau::embedSignalPFNeutralHadrCands() {
00330 if (!isPFTau() ) {
00331 return;
00332 }
00333 reco::PFCandidateRefVector candRefVec = pfSpecific_[0].selectedSignalPFNeutrHadrCands_;
00334 for (unsigned int i = 0; i < candRefVec.size(); i++) {
00335 signalPFNeutralHadrCands_.push_back(*candRefVec.at(i));
00336 }
00337 embeddedSignalPFNeutralHadrCands_ = true;
00338 }
00339 void Tau::embedSignalPFGammaCands() {
00340 if (!isPFTau() ) {
00341 return;
00342 }
00343 reco::PFCandidateRefVector candRefVec = pfSpecific_[0].selectedSignalPFGammaCands_;
00344 for (unsigned int i = 0; i < candRefVec.size(); i++) {
00345 signalPFGammaCands_.push_back(*candRefVec.at(i));
00346 }
00347 embeddedSignalPFGammaCands_ = true;
00348 }
00349
00350 void Tau::embedIsolationPFCands() {
00351 if (!isPFTau() ) {
00352 return;
00353 }
00354 reco::PFCandidateRefVector candRefVec = pfSpecific_[0].selectedIsolationPFCands_;
00355 for (unsigned int i = 0; i < candRefVec.size(); i++) {
00356 isolationPFCands_.push_back(*candRefVec.at(i));
00357 }
00358 embeddedIsolationPFCands_ = true;
00359 }
00360
00361 void Tau::embedIsolationPFChargedHadrCands() {
00362 if (!isPFTau() ) {
00363 return;
00364 }
00365 reco::PFCandidateRefVector candRefVec = pfSpecific_[0].selectedIsolationPFChargedHadrCands_;
00366 for (unsigned int i = 0; i < candRefVec.size(); i++) {
00367 isolationPFChargedHadrCands_.push_back(*candRefVec.at(i));
00368 }
00369 embeddedIsolationPFChargedHadrCands_ = true;
00370 }
00371 void Tau::embedIsolationPFNeutralHadrCands() {
00372 if (!isPFTau() ) {
00373 return;
00374 }
00375 reco::PFCandidateRefVector candRefVec = pfSpecific_[0].selectedIsolationPFNeutrHadrCands_;
00376 for (unsigned int i = 0; i < candRefVec.size(); i++) {
00377 isolationPFNeutralHadrCands_.push_back(*candRefVec.at(i));
00378 }
00379 embeddedIsolationPFNeutralHadrCands_ = true;
00380 }
00381 void Tau::embedIsolationPFGammaCands() {
00382 if (!isPFTau() ) {
00383 return;
00384 }
00385 reco::PFCandidateRefVector candRefVec = pfSpecific_[0].selectedIsolationPFGammaCands_;
00386 for (unsigned int i = 0; i < candRefVec.size(); i++) {
00387 isolationPFGammaCands_.push_back(*candRefVec.at(i));
00388 }
00389 embeddedIsolationPFGammaCands_ = true;
00390 }
00391
00392 const reco::PFCandidateRef Tau::leadPFChargedHadrCand() const {
00393 if(!embeddedLeadPFChargedHadrCand_)
00394 return pfSpecific().leadPFChargedHadrCand_;
00395 else
00396 return reco::PFCandidateRef(&leadPFChargedHadrCand_,0);
00397 }
00398
00399 const reco::PFCandidateRef Tau::leadPFNeutralCand() const {
00400 if(!embeddedLeadPFNeutralCand_)
00401 return pfSpecific().leadPFNeutralCand_;
00402 else
00403 return reco::PFCandidateRef(&leadPFNeutralCand_,0);
00404 }
00405
00406 const reco::PFCandidateRef Tau::leadPFCand() const {
00407 if(!embeddedLeadPFCand_)
00408 return pfSpecific().leadPFCand_;
00409 else
00410 return reco::PFCandidateRef(&leadPFCand_,0);
00411 }
00412
00413 const reco::PFCandidateRefVector & Tau::signalPFCands() const {
00414 if (embeddedSignalPFCands_) {
00415 if (!signalPFCandsRefVectorFixed_) {
00416 reco::PFCandidateRefVector aRefVec;
00417 for (unsigned int i = 0; i < signalPFCands_.size(); i++) {
00418 aRefVec.push_back(reco::PFCandidateRef(&signalPFCands_, i) );
00419 }
00420 signalPFCandsTransientRefVector_.swap(aRefVec);
00421 signalPFCandsRefVectorFixed_ = true;
00422 }
00423 return signalPFCandsTransientRefVector_;
00424 } else
00425 return pfSpecific().selectedSignalPFCands_;
00426 }
00427
00428 const reco::PFCandidateRefVector & Tau::signalPFChargedHadrCands() const {
00429 if (embeddedSignalPFChargedHadrCands_) {
00430 if (!signalPFChargedHadrCandsRefVectorFixed_) {
00431 reco::PFCandidateRefVector aRefVec;
00432 for (unsigned int i = 0; i < signalPFChargedHadrCands_.size(); i++) {
00433 aRefVec.push_back(reco::PFCandidateRef(&signalPFChargedHadrCands_, i) );
00434 }
00435 signalPFChargedHadrCandsTransientRefVector_.swap(aRefVec);
00436 signalPFChargedHadrCandsRefVectorFixed_ = true;
00437 }
00438 return signalPFChargedHadrCandsTransientRefVector_;
00439 } else
00440 return pfSpecific().selectedSignalPFChargedHadrCands_;
00441 }
00442
00443 const reco::PFCandidateRefVector & Tau::signalPFNeutrHadrCands() const {
00444 if (embeddedSignalPFNeutralHadrCands_) {
00445 if (!signalPFNeutralHadrCandsRefVectorFixed_) {
00446 reco::PFCandidateRefVector aRefVec;
00447 for (unsigned int i = 0; i < signalPFNeutralHadrCands_.size(); i++) {
00448 aRefVec.push_back(reco::PFCandidateRef(&signalPFNeutralHadrCands_, i) );
00449 }
00450 signalPFNeutralHadrCandsTransientRefVector_.swap(aRefVec);
00451 signalPFNeutralHadrCandsRefVectorFixed_ = true;
00452 }
00453 return signalPFNeutralHadrCandsTransientRefVector_;
00454 } else
00455 return pfSpecific().selectedSignalPFNeutrHadrCands_;
00456 }
00457
00458 const reco::PFCandidateRefVector & Tau::signalPFGammaCands() const {
00459 if (embeddedSignalPFGammaCands_) {
00460 if (!signalPFGammaCandsRefVectorFixed_) {
00461 reco::PFCandidateRefVector aRefVec;
00462 for (unsigned int i = 0; i < signalPFGammaCands_.size(); i++) {
00463 aRefVec.push_back(reco::PFCandidateRef(&signalPFGammaCands_, i) );
00464 }
00465 signalPFGammaCandsTransientRefVector_.swap(aRefVec);
00466 signalPFGammaCandsRefVectorFixed_ = true;
00467 }
00468 return signalPFGammaCandsTransientRefVector_;
00469 } else
00470 return pfSpecific().selectedSignalPFGammaCands_;
00471 }
00472
00473 const reco::PFCandidateRefVector & Tau::isolationPFCands() const {
00474 if (embeddedIsolationPFCands_) {
00475 if (!isolationPFCandsRefVectorFixed_) {
00476 reco::PFCandidateRefVector aRefVec;
00477 for (unsigned int i = 0; i < isolationPFCands_.size(); i++) {
00478 aRefVec.push_back(reco::PFCandidateRef(&isolationPFCands_, i) );
00479 }
00480 isolationPFCandsTransientRefVector_.swap(aRefVec);
00481 isolationPFCandsRefVectorFixed_ = true;
00482 }
00483 return isolationPFCandsTransientRefVector_;
00484 } else
00485 return pfSpecific().selectedIsolationPFCands_;
00486 }
00487
00488 const reco::PFCandidateRefVector & Tau::isolationPFChargedHadrCands() const {
00489 if (embeddedIsolationPFChargedHadrCands_) {
00490 if (!isolationPFChargedHadrCandsRefVectorFixed_) {
00491 reco::PFCandidateRefVector aRefVec;
00492 for (unsigned int i = 0; i < isolationPFChargedHadrCands_.size(); i++) {
00493 aRefVec.push_back(reco::PFCandidateRef(&isolationPFChargedHadrCands_, i) );
00494 }
00495 isolationPFChargedHadrCandsTransientRefVector_.swap(aRefVec);
00496 isolationPFChargedHadrCandsRefVectorFixed_ = true;
00497 }
00498 return isolationPFChargedHadrCandsTransientRefVector_;
00499 } else
00500 return pfSpecific().selectedIsolationPFChargedHadrCands_;
00501 }
00502
00503 const reco::PFCandidateRefVector & Tau::isolationPFNeutrHadrCands() const {
00504 if (embeddedIsolationPFNeutralHadrCands_) {
00505 if (!isolationPFNeutralHadrCandsRefVectorFixed_) {
00506 reco::PFCandidateRefVector aRefVec;
00507 for (unsigned int i = 0; i < isolationPFNeutralHadrCands_.size(); i++) {
00508 aRefVec.push_back(reco::PFCandidateRef(&isolationPFNeutralHadrCands_, i) );
00509 }
00510 isolationPFNeutralHadrCandsTransientRefVector_.swap(aRefVec);
00511 isolationPFNeutralHadrCandsRefVectorFixed_ = true;
00512 }
00513 return isolationPFNeutralHadrCandsTransientRefVector_;
00514 } else
00515 return pfSpecific().selectedIsolationPFNeutrHadrCands_;
00516 }
00517
00518 const reco::PFCandidateRefVector & Tau::isolationPFGammaCands() const {
00519 if (embeddedIsolationPFGammaCands_) {
00520 if (!isolationPFGammaCandsRefVectorFixed_) {
00521 reco::PFCandidateRefVector aRefVec;
00522 for (unsigned int i = 0; i < isolationPFGammaCands_.size(); i++) {
00523 aRefVec.push_back(reco::PFCandidateRef(&isolationPFGammaCands_, i) );
00524 }
00525 isolationPFGammaCandsTransientRefVector_.swap(aRefVec);
00526 isolationPFGammaCandsRefVectorFixed_ = true;
00527 }
00528 return isolationPFGammaCandsTransientRefVector_;
00529 } else
00530 return pfSpecific().selectedIsolationPFGammaCands_;
00531 }