CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Attributes

PFTauMVADiscriminator Class Reference

#include <RecoTauTag/RecoTau/plugins/PFTauMVADiscriminator.cc>

Inheritance diagram for PFTauMVADiscriminator:
TauDiscriminationProducerBase< TauType, TauDiscriminator > edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Classes

struct  MVAComputerFromDB

Public Types

typedef std::map< int,
MVAList::iterator > 
DecayModeToMVAMap
typedef std::vector
< MVAComputerFromDB
MVAList

Public Member Functions

void beginEvent (const edm::Event &, const edm::EventSetup &)
double discriminate (const PFTauRef &)
 PFTauMVADiscriminator (const edm::ParameterSet &)
 ~PFTauMVADiscriminator ()

Private Attributes

bool applyCut_
DecayModeToMVAMap computerMap_
MVAList computers_
std::string dbLabel_
PFTauDiscriminantManager discriminantManager_
std::vector
< PhysicsTools::Variable::Value
mvaComputerInput_
DiscriminantList myDiscriminants_
edm::Handle
< PFTauDecayModeAssociation
pfTauDecayModes
edm::InputTag pfTauDecayModeSrc_
bool remapOutput_

Detailed Description

Description: Produces a PFTauDiscriminator mapping MVA outputs to PFTau objects Requires an AssociationVector of PFTauDecayModes->PFTau objects See RecoTauTag/RecoTau/src/PFTauDecayModeDeterminator.cc

Definition at line 41 of file PFTauMVADiscriminator.cc.


Member Typedef Documentation

typedef std::map<int, MVAList::iterator> PFTauMVADiscriminator::DecayModeToMVAMap

Definition at line 53 of file PFTauMVADiscriminator.cc.

Definition at line 52 of file PFTauMVADiscriminator.cc.


Constructor & Destructor Documentation

PFTauMVADiscriminator::PFTauMVADiscriminator ( const edm::ParameterSet iConfig) [explicit]

Definition at line 74 of file PFTauMVADiscriminator.cc.

References PFTauDiscriminants::PFTauDiscriminantManager::addDiscriminant(), applyCut_, PFTauDiscriminants::DiscriminantList::begin(), PFTauMVADiscriminator::MVAComputerFromDB::computer, computerMap_, PFTauMVADiscriminator::MVAComputerFromDB::computerName, computers_, dbLabel_, discriminantManager_, PFTauDiscriminants::DiscriminantList::end(), Exception, edm::ParameterSet::getParameter(), myDiscriminants_, pfTauDecayModeSrc_, TauDiscriminationProducerBase< TauType, TauDiscriminator >::prediscriminantFailValue_, remapOutput_, AlCaHLTBitMon_QueryRunRegistry::string, and PFTauMVADiscriminator::MVAComputerFromDB::userCut.

                                                                          :PFTauDiscriminationProducerBase(iConfig)
{
   pfTauDecayModeSrc_        = iConfig.getParameter<edm::InputTag>("pfTauDecayModeSrc");
   remapOutput_              = iConfig.getParameter<bool>("RemapOutput");
   applyCut_                 = iConfig.getParameter<bool>("MakeBinaryDecision");
   prediscriminantFailValue_ = iConfig.getParameter<double>("prefailValue"); //defined in base class
   dbLabel_                  = iConfig.getParameter<std::string>("dbLabel");

   // build the decaymode->computer map
   std::vector<edm::ParameterSet> decayModeMap = iConfig.getParameter<std::vector<edm::ParameterSet> >("computers");
   computers_.reserve(decayModeMap.size());
   for(std::vector<edm::ParameterSet>::const_iterator iComputer  = decayModeMap.begin(); iComputer != decayModeMap.end(); ++iComputer)
   {
      MVAComputerFromDB toInsert;
      toInsert.computerName = iComputer->getParameter<std::string>("computerName");
      toInsert.userCut      = iComputer->getParameter<double>("cut");
      toInsert.computer     = new PhysicsTools::MVAComputerCache();
      MVAList::iterator computerJustAdded = computers_.insert(computers_.end(), toInsert); //add this computer to the end of the list

      //populate the map
      std::vector<int> associatedDecayModes = iComputer->getParameter<std::vector<int> >("decayModeIndices");
      for(std::vector<int>::const_iterator iDecayMode  = associatedDecayModes.begin();
                                      iDecayMode != associatedDecayModes.end();
                                    ++iDecayMode)
      {
         //map this integer specifying the decay mode to the MVA comptuer we just added to the list
         std::pair<DecayModeToMVAMap::iterator, bool> insertResult = computerMap_.insert(std::make_pair(*iDecayMode, computerJustAdded));

         //make sure we aren't double mapping a decay mode
         if(insertResult.second == false) { //indicates that the current key (decaymode) has already been entered!
            throw cms::Exception("PFTauMVADiscriminator::ctor") << "A tau decay mode: " << *iDecayMode << " has been mapped to two different MVA implementations, "
                                                              << insertResult.first->second->computerName << " and " << toInsert.computerName 
                                                              << ". Please check the appropriate cfi file." << std::endl;
         }
      }
   }

   for(DiscriminantList::const_iterator aDiscriminant  = myDiscriminants_.begin();
                                        aDiscriminant != myDiscriminants_.end();
                                      ++aDiscriminant)
   {
      //load the discriminants into the discriminant manager
      discriminantManager_.addDiscriminant(*aDiscriminant);
   }
   
}
PFTauMVADiscriminator::~PFTauMVADiscriminator ( )

Definition at line 121 of file PFTauMVADiscriminator.cc.

References computers_.

{
   for(MVAList::iterator iMVAComputer  = computers_.begin(); iMVAComputer != computers_.end(); ++iMVAComputer)
   {
      delete iMVAComputer->computer;
   }
}

Member Function Documentation

void PFTauMVADiscriminator::beginEvent ( const edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 130 of file PFTauMVADiscriminator.cc.

References computers_, dbLabel_, discriminantManager_, edm::Event::getByLabel(), pfTauDecayModes, pfTauDecayModeSrc_, PFTauDiscriminants::PFTauDiscriminantManager::setEvent(), and AlCaHLTBitMon_QueryRunRegistry::string.

{
   // load the PFTauDecayModes
   iEvent.getByLabel(pfTauDecayModeSrc_, pfTauDecayModes);

   // expose the event to the PFTau discriminant quantity computers
   discriminantManager_.setEvent(iEvent, 1.0); //event weight = 1 

   // Refresh MVAs
   //we do this on each event as the crossing an IOV boundary could change the appropriate record
   for(MVAList::iterator iMVAComputer  = computers_.begin();
                         iMVAComputer != computers_.end();
                       ++iMVAComputer)
   {
      std::string nameToGet = iMVAComputer->computerName;
      iMVAComputer->computer->update<TauMVAFrameworkDBRcd>(dbLabel_.c_str(), iSetup, nameToGet.c_str());
   } 
}
double PFTauMVADiscriminator::discriminate ( const PFTauRef pfTau)

Definition at line 149 of file PFTauMVADiscriminator.cc.

References applyCut_, PFTauDiscriminants::PFTauDiscriminantManager::buildMVAComputerLink(), PhysicsTools::MVAComputerCache::computer, computerMap_, discriminantManager_, reco::PFTauDecayMode::getDecayMode(), mvaComputerInput_, TauDiscriminationProducerBase< TauType, TauDiscriminator >::prediscriminantFailValue_, remapOutput_, query::result, and PFTauDiscriminants::PFTauDiscriminantManager::setTau().

{
   double result = prediscriminantFailValue_;

   mvaComputerInput_.clear();
   const PFTauDecayMode& theTauDecayMode = (*pfTauDecayModes)[pfTau]; // get PFTauDecayMode associated to this PFTau


   //get appropriate MVA computer
   int decayMode = theTauDecayMode.getDecayMode();
   DecayModeToMVAMap::iterator iterToComputer = computerMap_.find(decayMode);

   if(iterToComputer != computerMap_.end()) //if we don't have a MVA mapped to this decay mode, skip it.
   {
      const PhysicsTools::MVAComputerCache* mvaComputer = iterToComputer->second->computer;
      if ( (*mvaComputer) ) 
      {
         //sets the current tau decay mode as the active object
         discriminantManager_.setTau(theTauDecayMode);
         //applies associated discriminants (see ctor) and constructs the appropriate MVA framework input
         discriminantManager_.buildMVAComputerLink(mvaComputerInput_);
         result = (*mvaComputer)->eval(mvaComputerInput_);
      } 
      else 
      {
         edm::LogWarning("PFTauMVADiscriminator") << "Warning: got a null pointer to MVA computer in conditions database"
            << " for decay mode: " << decayMode << ", expected MVA computer name: " 
            << iterToComputer->second->computerName;
      }

      if (remapOutput_) // TMVA maps result to [-1, 1].  Remap, if desired, to [0, 1]
      {
         if      (result >  1) result = 1.;
         else if (result < -1) result = 0.;
         else { 
            result += 1.;
            result /= 2.;
         }
      }
      if (applyCut_)
      {
         //If the user desires a yes or no decision, 
         // use the supplied cut to make a decision
         if (result > iterToComputer->second->userCut) 
            result = 1.0;
         else 
            result = 0.0;
      }
   }

   return result;
}

Member Data Documentation

Definition at line 61 of file PFTauMVADiscriminator.cc.

Referenced by discriminate(), and PFTauMVADiscriminator().

Definition at line 63 of file PFTauMVADiscriminator.cc.

Referenced by discriminate(), and PFTauMVADiscriminator().

std::string PFTauMVADiscriminator::dbLabel_ [private]

Definition at line 65 of file PFTauMVADiscriminator.cc.

Referenced by beginEvent(), and PFTauMVADiscriminator().

Definition at line 67 of file PFTauMVADiscriminator.cc.

Referenced by beginEvent(), discriminate(), and PFTauMVADiscriminator().

Definition at line 71 of file PFTauMVADiscriminator.cc.

Referenced by discriminate().

Definition at line 66 of file PFTauMVADiscriminator.cc.

Referenced by PFTauMVADiscriminator().

Definition at line 69 of file PFTauMVADiscriminator.cc.

Referenced by beginEvent().

Definition at line 59 of file PFTauMVADiscriminator.cc.

Referenced by beginEvent(), and PFTauMVADiscriminator().

Definition at line 60 of file PFTauMVADiscriminator.cc.

Referenced by discriminate(), and PFTauMVADiscriminator().