CMS 3D CMS Logo

Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

PFTauDiscriminants::PFTauDiscriminantManager Class Reference

#include <PFTauDiscriminantManager.h>

List of all members.

Public Types

typedef std::vector< const
reco::Candidate * > 
candPtrVector
typedef std::map< std::string,
Discriminant *const > 
discriminantHolder

Public Member Functions

void addDiscriminant (Discriminant *const aDiscriminant)
 add a discriminant
bool branchTree (TTree *const treeToBranch, bool addTargetBranch=false, bool addWeightBranch=false)
 add a set of branches ot the TTree
void buildMVAComputerLink (std::vector< PhysicsTools::Variable::Value > &)
 connect to an MVA computer
candPtrVector filterByCharge (const candPtrVector &input, bool isCharged) const
const reco::PFTauDecayModegetDecayMode () const
 returns associated PFTauDecayMode
const edm::EventgetEvent () const
 returns associated edm::Event
const reco::CandidatemainTrack ()
 get the 'main' track (track computed for relevancy to tau decay resonances) (ie pi- in pi+pi+pi-)
const std::vector< const
reco::Candidate * > & 
outlierObjectsSortedByDR ()
const std::vector< const
reco::Candidate * > & 
outlierObjectsSortedByPt ()
 PFTauDiscriminantManager ()
void setEvent (const edm::Event &, double eventWeight)
 set the current event. Must be called (once per event) before setTau or setNullResult
bool setNullResult ()
void setSignalFlag (bool isSignal)
bool setTau (const reco::PFTauDecayMode &theTau, bool prePass=false, bool preFail=false)
 set objects for this discriminant
const std::vector< const
reco::Candidate * > & 
signalObjectsSortedByDR ()
const std::vector< const
reco::Candidate * > & 
signalObjectsSortedByPt ()
 accessed by Discriminant classes (caches to prevent multiple sorts)
 ~PFTauDiscriminantManager ()

Static Public Member Functions

static std::vector< const
reco::Candidate * > 
getLeafDaughters (const reco::Candidate *input)
 return the lowest level constituent candidates of a composite candidate

Private Member Functions

void clearCache ()
void computeMainTrack ()
void fillOutlierObjects (candPtrVector &input)
void fillSignalObjects (candPtrVector &input)

Private Attributes

const reco::PFTauDecayModecurrentTauDecayMode_
const edm::EventeventData_
Double_t eventWeight_
Bool_t iAmNull_
Bool_t iAmSignal_
const reco::CandidatemainTrack_
discriminantHolder myDiscriminants_
candPtrVector outlierObjectsSortedByDR_
candPtrVector outlierObjectsSortedByPt_
Bool_t preFail_
Bool_t prePass_
candPtrVector signalObjectsSortedByDR_
candPtrVector signalObjectsSortedByPt_

Detailed Description

Definition at line 16 of file PFTauDiscriminantManager.h.


Member Typedef Documentation

Definition at line 21 of file PFTauDiscriminantManager.h.

Definition at line 23 of file PFTauDiscriminantManager.h.


Constructor & Destructor Documentation

PFTauDiscriminants::PFTauDiscriminantManager::PFTauDiscriminantManager ( )

Definition at line 10 of file PFTauDiscriminantManager.cc.

References NULL.

PFTauDiscriminants::PFTauDiscriminantManager::~PFTauDiscriminantManager ( )

Definition at line 367 of file PFTauDiscriminantManager.cc.

{
}

Member Function Documentation

void PFTauDiscriminants::PFTauDiscriminantManager::addDiscriminant ( Discriminant *const  aDiscriminant)

add a discriminant

Definition at line 21 of file PFTauDiscriminantManager.cc.

References PFTauDiscriminants::Discriminant::name().

Referenced by PFTauMVADiscriminator::PFTauMVADiscriminator(), and TauMVATrainer::TauMVATrainer().

{
   if (!discriminant)
   {
      edm::LogError("PFTauDiscriminantManager") << "Error adding a discriminant, null pointer!";
      return;
   }
   string            discriminantName = discriminant->name();
   myDiscriminants_.insert(make_pair(discriminantName, discriminant));
}
bool PFTauDiscriminants::PFTauDiscriminantManager::branchTree ( TTree *const  treeToBranch,
bool  addTargetBranch = false,
bool  addWeightBranch = false 
)

add a set of branches ot the TTree

Definition at line 301 of file PFTauDiscriminantManager.cc.

References PFTauDiscriminants::Discriminant::branchTree(), and PFTauDiscriminants::Discriminant::name().

Referenced by TauMVATrainer::TauMVATrainer().

{
   if(!treeToBranch)
   {
      edm::LogError("PFTauDiscriminantManager") << "Error: trying to branch ttree - TTree pointer is null!";
      return false;
   }

   //add magic variables _TARGET_ (for sig/bkg) and _WEIGHT_, and ISNULL for non-existence
   if (addTargetBranch)
      treeToBranch->Branch("__TARGET__", &iAmSignal_,  "__TARGET__/O");  //needs bugfix in MVA framework code..
   if (addWeightBranch)
      treeToBranch->Branch("__WEIGHT__", &eventWeight_,"__WEIGHT__/D");
   // note: Target and Weight are normally added after the fact, in the training code.

   treeToBranch->Branch("__ISNULL__",  &iAmNull_,"__ISNULL__/O");
   treeToBranch->Branch("__PREPASS__", &prePass_,"__PREPASS__/O");
   treeToBranch->Branch("__PREFAIL__", &preFail_,"__PREFAIL__/O");

   //loop over all the variables and make a branch for each one
   for(discriminantHolder::iterator iVariable  = myDiscriminants_.begin();
                                    iVariable != myDiscriminants_.end();
                                  ++iVariable)
   {
      Discriminant * theDiscriminant = iVariable->second;
      edm::LogInfo("PFTauDiscriminantManager") << "Branching for discriminant w/ name: " << theDiscriminant->name();
      theDiscriminant->branchTree(treeToBranch);
   }
   return true;
}
void PFTauDiscriminants::PFTauDiscriminantManager::buildMVAComputerLink ( std::vector< PhysicsTools::Variable::Value > &  toFill)

connect to an MVA computer

Definition at line 333 of file PFTauDiscriminantManager.cc.

References PFTauDiscriminants::Discriminant::fillMVA().

Referenced by PFTauMVADiscriminator::discriminate().

{
   for(discriminantHolder::iterator iVariable  = myDiscriminants_.begin();
                                    iVariable != myDiscriminants_.end();
                                  ++iVariable)
   {
      Discriminant * theDiscriminant = iVariable->second;
      theDiscriminant->fillMVA(toFill);
   }
}
void PFTauDiscriminants::PFTauDiscriminantManager::clearCache ( ) [private]
void PFTauDiscriminants::PFTauDiscriminantManager::computeMainTrack ( ) [private]
void PFTauDiscriminants::PFTauDiscriminantManager::fillOutlierObjects ( candPtrVector input) [private]

Definition at line 117 of file PFTauDiscriminantManager.cc.

References edm::RefVector< C, T, F >::begin(), edm::RefVector< C, T, F >::end(), reco::LeafCandidate::get(), reco::PFTau::isolationPFCands(), and NULL.

{
   toFill.clear();
   if (currentTauDecayMode_ == NULL)
   {
      edm::LogError("PFTauDiscriminantManager") << "Trying to get QCD objects from null PFTauDecayMode object!  Returning empty vector...";
      return;
   }

   // add in filtered objects (created in PFRecoTauDecayModeDeterminator) i.e filtered 2-prongs
   // note that this uses the underlying PFCandidates, to be consistent w/ the rest of the objects
   PFCandidateRefVector theFilteredObjects = currentTauDecayMode_->filteredPFCandidates();
   
   for(PFCandidateRefVector::const_iterator iFilteredCand  = theFilteredObjects.begin();
                                            iFilteredCand != theFilteredObjects.end();
                                          ++iFilteredCand)
   {
      const PFCandidate* pfCand = iFilteredCand->get();
      const Candidate* castedCand = static_cast<const Candidate*>(pfCand);
      if (castedCand)
         toFill.push_back(castedCand);
   }

   // get associated PFTau from PFTauDecayMode
   const PFTau* originalTau = currentTauDecayMode_->pfTauRef().get();
   if(originalTau) //this may be null by design if there is no associated PFTau (e.g. if DecayMode is constructed from MC truth)
   {
      const PFCandidateRefVector& theOutliers = originalTau->isolationPFCands();
      for(PFCandidateRefVector::const_iterator iIsoCand  = theOutliers.begin();
                                               iIsoCand != theOutliers.end();
                                             ++iIsoCand)
      {
         const PFCandidate* pfCand = iIsoCand->get();
         const Candidate* castedCand = static_cast<const Candidate*>(pfCand);
         if (castedCand)
            toFill.push_back(castedCand);
      }
   }
}
void PFTauDiscriminants::PFTauDiscriminantManager::fillSignalObjects ( candPtrVector input) [private]

Definition at line 103 of file PFTauDiscriminantManager.cc.

References NULL.

{
   toFill.clear();
   if (currentTauDecayMode_ == NULL)
   {
      edm::LogError("PFTauDiscriminantManager") << "Trying to get signal objects from null PFTauDecayMode object!  Returning empty vector...";
      return;
   }
   candPtrVector tempChargedVector = currentTauDecayMode_->chargedPionCandidates();
   candPtrVector tempNeutralVector = currentTauDecayMode_->neutralPionCandidates();
   toFill.insert(toFill.end(), tempChargedVector.begin(), tempChargedVector.end());
   toFill.insert(toFill.end(), tempNeutralVector.begin(), tempNeutralVector.end());
}
candPtrVector PFTauDiscriminants::PFTauDiscriminantManager::filterByCharge ( const candPtrVector input,
bool  isCharged 
) const

Definition at line 207 of file PFTauDiscriminantManager.cc.

References convertSQLitetoXML_cfg::output.

{
   candPtrVector output;
   for(candPtrVector::const_iterator iCandidate  = input.begin();
                                     iCandidate != input.end();
                                   ++iCandidate)
   {
      bool chargeType = (*iCandidate)->charge();
      if( chargeType == isCharged ) 
         output.push_back(*iCandidate);
   }
   return output;
}
const reco::PFTauDecayMode* PFTauDiscriminants::PFTauDiscriminantManager::getDecayMode ( ) const [inline]
const edm::Event* PFTauDiscriminants::PFTauDiscriminantManager::getEvent ( ) const [inline]

returns associated edm::Event

Definition at line 45 of file PFTauDiscriminantManager.h.

References eventData_.

{ return eventData_; };
vector< const reco::Candidate * > PFTauDiscriminants::PFTauDiscriminantManager::getLeafDaughters ( const reco::Candidate input) [static]

return the lowest level constituent candidates of a composite candidate

Definition at line 345 of file PFTauDiscriminantManager.cc.

References reco::Candidate::daughter(), reco::Candidate::numberOfDaughters(), and convertSQLitetoXML_cfg::output.

Referenced by PFTauDiscriminants::GammaPt::doComputation(), and PFTauDiscriminants::GammaOccupancy::doComputation().

{
   std::vector<const reco::Candidate*> output;

   //check for validity
   if(!input)   
      return output;

   size_t nDaughters = input->numberOfDaughters();
   if(!nDaughters)      //this is a leaf
      output.push_back(input);
   else                 //recurse down this objects daughters
   {
      for(size_t iDaughter = 0; iDaughter < nDaughters; ++iDaughter)
      {
         std::vector<const reco::Candidate*> leafsOnThisBranch = getLeafDaughters(input->daughter(iDaughter));
         output.insert(output.end(), leafsOnThisBranch.begin(), leafsOnThisBranch.end());
      }
   }
   return output;
}
const reco::Candidate * PFTauDiscriminants::PFTauDiscriminantManager::mainTrack ( )

get the 'main' track (track computed for relevancy to tau decay resonances) (ie pi- in pi+pi+pi-)

Definition at line 158 of file PFTauDiscriminantManager.cc.

References DeDxDiscriminatorTools::charge(), NULL, and python::multivaluedict::sort().

Referenced by PFTauDiscriminants::MainTrackAngle::doComputation(), PFTauDiscriminants::TrackAngle::doComputation(), PFTauDiscriminants::Dalitz::doComputation(), PFTauDiscriminants::MainTrackPt::doComputation(), PFTauDiscriminants::TrackPt::doComputation(), and PFTauDiscriminants::InvariantMass::doComputation().

{
   if (mainTrack_ == NULL) //otherwise already cached or d.n.e
   {
      if (!this->getDecayMode())
      {
         edm::LogError("PFTauDiscriminantManager") << "In ::mainTrack(), trying to access a null PFTauDecayMode - returning null pointer for main track";
         return NULL;
      }

      std::vector<const reco::Candidate*> myChargedCandidates = getDecayMode()->chargedPionCandidates();
      size_t nTracks = myChargedCandidates.size();
      if (!nTracks) 
      {
         // ...removing this warning for now, not sure what to do about this case (as it shoudl be permissible to pass a jet->pftau->pfTauDecayMode of all gammas??)
         //edm::LogError("PFTauDiscriminantManager") << "In ::mainTrack(), associated PFTauDecayMode has no associated tracks, returning null pointer.";
         return NULL;
      }

      //if there are more than three tracks, only take the top three, by Pt
      TauTagTools::sortByAscendingPt<reco::Candidate> ptSorter;
      sort(myChargedCandidates.begin(), myChargedCandidates.end(), ptSorter);
      size_t maxTracks = (nTracks > 3) ? 3 : nTracks;
      int    charge    = 0;

      if (maxTracks < 3) //two or one track, returning higher Pt track
         mainTrack_ = myChargedCandidates[0];
      else
      {
         for(size_t iTrack = 0; iTrack < maxTracks; ++iTrack)
            charge += myChargedCandidates[iTrack]->charge();

         for(size_t iTrack = 0; iTrack < maxTracks; ++iTrack)
         {
            int currentCharge = myChargedCandidates[iTrack]->charge();
            if (currentCharge != charge)
            {
               mainTrack_ = myChargedCandidates[iTrack];
               break;
            }
         }
      }
   }
   return mainTrack_;
}
const std::vector< const reco::Candidate * > & PFTauDiscriminants::PFTauDiscriminantManager::outlierObjectsSortedByDR ( )

Definition at line 278 of file PFTauDiscriminantManager.cc.

References TauTagTools::computeDeltaR(), NULL, and python::multivaluedict::sort().

{
   if(!outlierObjectsSortedByDR_.empty() || iAmNull_)
   {
      return outlierObjectsSortedByDR_;
   }
   else
   {
      if (currentTauDecayMode_ == NULL)
      {
         edm::LogError("PFTauDiscriminantManager") << "Trying to get outlier objects from null PFTauDecayMode object!  Returning empty vector...";
         return outlierObjectsSortedByDR_;
      }
      math::XYZVector signalAxisVector = currentTauDecayMode_->momentum();
      fillOutlierObjects(outlierObjectsSortedByDR_);
      TauTagTools::sortByOpeningAngleAscending<reco::Candidate> mySorter(signalAxisVector, TauTagTools::computeDeltaR);
      sort(outlierObjectsSortedByDR_.begin(), outlierObjectsSortedByDR_.end(), mySorter);
   }
   return outlierObjectsSortedByDR_;
}
const std::vector< const reco::Candidate * > & PFTauDiscriminants::PFTauDiscriminantManager::outlierObjectsSortedByPt ( )
void PFTauDiscriminants::PFTauDiscriminantManager::setEvent ( const edm::Event iEvent,
double  eventWeight 
)

set the current event. Must be called (once per event) before setTau or setNullResult

Definition at line 69 of file PFTauDiscriminantManager.cc.

References ExpressReco_HICollisions_FallBack::eventWeight, and iEvent.

Referenced by TauMVATrainer::analyze(), and PFTauMVADiscriminator::beginEvent().

bool PFTauDiscriminants::PFTauDiscriminantManager::setNullResult ( )

in case there is no tau but you wish to fill anyway (for example, to see situations where one cone algorithm fails to find a tau but another does not

Definition at line 76 of file PFTauDiscriminantManager.cc.

References NULL, and PFTauDiscriminants::Discriminant::setNullResult().

Referenced by TauMVATrainer::analyze().

{
   currentTauDecayMode_ = NULL;
   iAmNull_             = true;
   prePass_             = false;
   preFail_             = false;
   //reset cached collections
   clearCache();

   for(discriminantHolder::iterator aDiscriminant  = myDiscriminants_.begin();
                                    aDiscriminant != myDiscriminants_.end();
                                  ++aDiscriminant)
   {
      Discriminant* const theAlgo  = aDiscriminant->second;
      if (!theAlgo)
      {
         string theName  = aDiscriminant->first;
         edm::LogError("PFTauDiscriminantManager") << "Error filling discriminant " << theName <<", null pointer!";
         return false;
      }
      theAlgo->setNullResult(this);
   }
   return true;
}
void PFTauDiscriminants::PFTauDiscriminantManager::setSignalFlag ( bool  isSignal) [inline]

Definition at line 38 of file PFTauDiscriminantManager.h.

References iAmSignal_.

Referenced by TauMVATrainer::TauMVATrainer().

{ iAmSignal_ = isSignal; };
bool PFTauDiscriminants::PFTauDiscriminantManager::setTau ( const reco::PFTauDecayMode theTau,
bool  prePass = false,
bool  preFail = false 
)

set objects for this discriminant

Definition at line 43 of file PFTauDiscriminantManager.cc.

References PFTauDiscriminants::Discriminant::compute().

Referenced by TauMVATrainer::analyze(), and PFTauMVADiscriminator::discriminate().

{
   currentTauDecayMode_ = &theTau;
   iAmNull_             = false;
   prePass_             = prePass;
   preFail_             = preFail;
   //reset cached collections
   clearCache();
   
   for(discriminantHolder::iterator aDiscriminant  = myDiscriminants_.begin();
                                    aDiscriminant != myDiscriminants_.end();
                                  ++aDiscriminant)
   {
      Discriminant* const theAlgo  = aDiscriminant->second;
      if (!theAlgo)
      {
         string theName  = aDiscriminant->first;
         edm::LogError("PFTauDiscriminantManager") << "Error filling discriminant " << theName <<", null pointer!";
         return false;
      }
      theAlgo->compute(this);
   }
   return true;
}
const std::vector< const reco::Candidate * > & PFTauDiscriminants::PFTauDiscriminantManager::signalObjectsSortedByDR ( )

Definition at line 239 of file PFTauDiscriminantManager.cc.

References TauTagTools::computeDeltaR(), NULL, and python::multivaluedict::sort().

{
   // return already computed vector if has already been computed or is empty (due to null tau)
   if(!signalObjectsSortedByDR_.empty() || iAmNull_)  
   {
      return signalObjectsSortedByDR_;
   }
   else
   {  
      if (currentTauDecayMode_ == NULL)
      {
         edm::LogError("PFTauDiscriminantManager") << "Trying to get signal objects from null PFTauDecayMode object!  Returning empty vector...";
         return signalObjectsSortedByDR_;
      }
      math::XYZVector signalAxisVector = currentTauDecayMode_->momentum();
      TauTagTools::sortByOpeningAngleAscending<reco::Candidate> mySorter(signalAxisVector, TauTagTools::computeDeltaR);
      fillSignalObjects(signalObjectsSortedByDR_);
      sort(signalObjectsSortedByDR_.begin(), signalObjectsSortedByDR_.end(), mySorter);
   }
   return signalObjectsSortedByDR_;
}
const std::vector< const reco::Candidate * > & PFTauDiscriminants::PFTauDiscriminantManager::signalObjectsSortedByPt ( )

Member Data Documentation

Definition at line 72 of file PFTauDiscriminantManager.h.

Referenced by getDecayMode().

Definition at line 73 of file PFTauDiscriminantManager.h.

Referenced by getEvent().

Definition at line 70 of file PFTauDiscriminantManager.h.

Definition at line 66 of file PFTauDiscriminantManager.h.

Definition at line 65 of file PFTauDiscriminantManager.h.

Referenced by setSignalFlag().

Definition at line 77 of file PFTauDiscriminantManager.h.

Definition at line 71 of file PFTauDiscriminantManager.h.

Definition at line 81 of file PFTauDiscriminantManager.h.

Definition at line 80 of file PFTauDiscriminantManager.h.

Definition at line 68 of file PFTauDiscriminantManager.h.

Definition at line 67 of file PFTauDiscriminantManager.h.

Definition at line 79 of file PFTauDiscriminantManager.h.

Definition at line 78 of file PFTauDiscriminantManager.h.