CMS 3D CMS Logo

Tau.cc

Go to the documentation of this file.
00001 //
00002 // $Id: Tau.cc,v 1.11.2.2 2009/04/09 12:33:43 veelken Exp $
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<TauType>(),
00015     embeddedIsolationTracks_(false),
00016     embeddedLeadTrack_(false),
00017     embeddedSignalTracks_(false)
00018 {
00019 }
00020 
00021 
00023 Tau::Tau(const TauType & aTau) :
00024     Lepton<TauType>(aTau),
00025     embeddedIsolationTracks_(false),
00026     embeddedLeadTrack_(false),
00027     embeddedSignalTracks_(false)
00028 {
00029     const reco::PFTau * pfTau = dynamic_cast<const reco::PFTau *>(&aTau);
00030     if (pfTau != 0) pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau));
00031     const reco::CaloTau * caloTau = dynamic_cast<const reco::CaloTau *>(&aTau);
00032     if (caloTau != 0) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau));
00033 }
00034 
00035 
00037 Tau::Tau(const edm::RefToBase<TauType> & aTauRef) :
00038     Lepton<TauType>(aTauRef),
00039     embeddedIsolationTracks_(false),
00040     embeddedLeadTrack_(false),
00041     embeddedSignalTracks_(false)
00042 {
00043     const reco::PFTau * pfTau = dynamic_cast<const reco::PFTau *>(aTauRef.get());
00044     if (pfTau != 0) pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau));
00045     const reco::CaloTau * caloTau = dynamic_cast<const reco::CaloTau *>(aTauRef.get());
00046     if (caloTau != 0) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau));
00047 }
00048 
00050 Tau::Tau(const edm::Ptr<TauType> & aTauRef) :
00051     Lepton<TauType>(aTauRef),
00052     embeddedIsolationTracks_(false),
00053     embeddedLeadTrack_(false),
00054     embeddedSignalTracks_(false)
00055 {
00056     const reco::PFTau * pfTau = dynamic_cast<const reco::PFTau *>(aTauRef.get());
00057     if (pfTau != 0) pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau));
00058     const reco::CaloTau * caloTau = dynamic_cast<const reco::CaloTau *>(aTauRef.get());
00059     if (caloTau != 0) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau));
00060 }
00061 
00062 
00063 
00065 Tau::~Tau() {
00066 }
00067 
00068 
00070 const reco::TrackRefVector & Tau::isolationTracks() const {
00071   if (embeddedIsolationTracks_) {
00072     if (!isolationTracksTransientRefVectorFixed_) {
00073         reco::TrackRefVector trackRefVec;
00074         for (unsigned int i = 0; i < isolationTracks_.size(); i++) {
00075           trackRefVec.push_back(reco::TrackRef(&isolationTracks_, i));
00076         }
00077         isolationTracksTransientRefVector_.swap(trackRefVec);
00078         isolationTracksTransientRefVectorFixed_ = true;
00079     }
00080     return isolationTracksTransientRefVector_;
00081   } else {
00082     return TauType::isolationTracks();
00083   }
00084 }
00085 
00086 
00088 reco::TrackRef Tau::leadTrack() const {
00089   if (embeddedLeadTrack_) {
00090     return reco::TrackRef(&leadTrack_, 0);
00091   } else {
00092     return TauType::leadTrack();
00093   }
00094 }
00095 
00096 
00098 const reco::TrackRefVector & Tau::signalTracks() const {
00099   if (embeddedSignalTracks_) {
00100     reco::TrackRefVector trackRefVec;
00101     if (!signalTracksTransientRefVectorFixed_) {
00102         for (unsigned int i = 0; i < signalTracks_.size(); i++) {
00103           trackRefVec.push_back(reco::TrackRef(&signalTracks_, i));
00104         }
00105         signalTracksTransientRefVector_.swap(trackRefVec);
00106         signalTracksTransientRefVectorFixed_ = true;
00107     }
00108     return signalTracksTransientRefVector_;
00109   } else {
00110     return TauType::signalTracks();
00111   }
00112 }
00113 
00114 
00116 void Tau::embedIsolationTracks() {
00117   isolationTracks_.clear();
00118   reco::TrackRefVector trackRefVec = TauType::isolationTracks();
00119   for (unsigned int i = 0; i < trackRefVec.size(); i++) {
00120     isolationTracks_.push_back(*trackRefVec.at(i));
00121   }
00122   embeddedIsolationTracks_ = true;
00123 }
00124 
00125 
00127 void Tau::embedLeadTrack() {
00128   leadTrack_.clear();
00129   if (TauType::leadTrack().isNonnull()) {
00130       leadTrack_.push_back(*TauType::leadTrack());
00131       embeddedLeadTrack_ = true;
00132   }
00133 }
00134 
00135 
00137 void Tau::embedSignalTracks(){
00138   signalTracks_.clear();
00139   reco::TrackRefVector trackRefVec = TauType::signalTracks();
00140   for (unsigned int i = 0; i < trackRefVec.size(); i++) {
00141     signalTracks_.push_back(*trackRefVec.at(i));
00142   }
00143   embeddedSignalTracks_ = true;
00144 }
00145 
00146 
00148 void Tau::setGenJet(const reco::GenJetRef& gj) {
00149   genJet_.clear();
00150   genJet_.push_back(*gj);
00151 }
00152 
00154 const reco::GenJet * Tau::genJet() const {
00155   return (genJet_.size() > 0 ? &genJet_.front() : 0);
00156 }
00157 
00158 
00159 // method to retrieve a tau ID (or throw)
00160 float Tau::tauID(const std::string & name) const {
00161   for (std::vector<IdPair>::const_iterator it = tauIDs_.begin(), ed = tauIDs_.end(); it != ed; ++it) {
00162     if (it->first == name) return it->second;
00163   }
00164   cms::Exception ex("Key not found");
00165   ex << "pat::Tau: the ID " << name << " can't be found in this pat::Tau.\n";
00166   ex << "The available IDs are: ";
00167   for (std::vector<IdPair>::const_iterator it = tauIDs_.begin(), ed = tauIDs_.end(); it != ed; ++it) {
00168     ex << "'" << it->first << "' ";
00169   }
00170   ex << ".\n";
00171   throw ex;
00172 }
00173 // check if an ID is there
00174 bool Tau::isTauIDAvailable(const std::string & name) const {
00175   for (std::vector<IdPair>::const_iterator it = tauIDs_.begin(), ed = tauIDs_.end(); it != ed; ++it) {
00176     if (it->first == name) return true;
00177   }
00178   return false;
00179 }
00180 
00181 
00182 const pat::tau::TauPFSpecific & Tau::pfSpecific() const {
00183   if (!isPFTau()) throw cms::Exception("Type Error") << "Requesting a PFTau-specific information from a pat::Tau which wasn't made from a PFTau.\n";
00184   return pfSpecific_[0]; 
00185 }
00186 
00187 const pat::tau::TauCaloSpecific & Tau::caloSpecific() const {
00188   if (!isCaloTau()) throw cms::Exception("Type Error") << "Requesting a CaloTau-specific information from a pat::Tau which wasn't made from a CaloTau.\n";
00189   return caloSpecific_[0]; 
00190 }
00191 
00192 
00193 void Tau::setDecayMode(int decayMode)
00194 {
00195   if (!isPFTau()) throw cms::Exception("Type Error") << "Requesting a PFTau-specific information from a pat::Tau which wasn't made from a PFTau.\n";
00196   pfSpecific_[0].decayMode_ = decayMode;
00197 }

Generated on Tue Jun 9 17:31:28 2009 for CMSSW by  doxygen 1.5.4