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