CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Attributes

TauMVATrainer Class Reference

#include <RecoTauTag/TauTagTools/src/TauMVATrainer.cc>

Inheritance diagram for TauMVATrainer:
edm::EDAnalyzer

List of all members.

Classes

struct  tauMatchingInfoHolder

Public Types

typedef std::vector
< tauMatchingInfoHolder
tauMatchingInfos
typedef std::vector< std::pair
< TTree *, const
PFTauDecayModeMatchMap * > > 
treeToMatchTuple

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
virtual void beginJob ()
virtual void endJob ()
 TauMVATrainer (const edm::ParameterSet &)
 ~TauMVATrainer ()

Private Attributes

PFTauDiscriminantManager discriminantManager_
bool iAmSignal_
std::vector
< tauMatchingInfoHolder
matchingInfo_
std::vector< ParameterSetmatchingSources_
uint32_t maxPiZeroes_
uint32_t maxTracks_
InputTag mcTruthSource_
DiscriminantList myDiscriminants_
std::map< string, TTree * > myTrainerTrees_
TFile * outputFile_
std::string outputRootFileName_
TTree * theTruthTree_

Detailed Description

Description: Generates ROOT trees used to train PhysicsTools::MVAComputers

Implementation: <Notes on="" implementation>="">

Definition at line 47 of file TauMVATrainer.cc.


Member Typedef Documentation

Definition at line 58 of file TauMVATrainer.cc.

typedef std::vector<std::pair<TTree*, const PFTauDecayModeMatchMap*> > TauMVATrainer::treeToMatchTuple

Definition at line 59 of file TauMVATrainer.cc.


Constructor & Destructor Documentation

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

Definition at line 90 of file TauMVATrainer.cc.

References PFTauDiscriminants::PFTauDiscriminantManager::addDiscriminant(), TauMVATrainer::tauMatchingInfoHolder::associatedTTree, PFTauDiscriminants::DiscriminantList::begin(), PFTauDiscriminants::PFTauDiscriminantManager::branchTree(), TauMVATrainer::tauMatchingInfoHolder::decayModeToRecoTauAssociationTag, discriminantManager_, PFTauDiscriminants::DiscriminantList::end(), iAmSignal_, label, edm::InputTag::label(), matchingInfo_, matchingSources_, myDiscriminants_, myTrainerTrees_, outputFile_, outputRootFileName_, PFTauDiscriminants::PFTauDiscriminantManager::setSignalFlag(), theTruthTree_, and TauMVATrainer::tauMatchingInfoHolder::truthToRecoTauMatchingTag.

                                                          :
                   mcTruthSource_(iConfig.getParameter<InputTag>("mcTruthSource")),
                   matchingSources_(iConfig.getParameter<vector<ParameterSet> >("matchingSources")),
                   iAmSignal_(iConfig.getParameter<bool>("iAmSignal")),
                   maxTracks_(iConfig.getParameter<uint32_t>("maxTracks")),
                   maxPiZeroes_(iConfig.getParameter<uint32_t>("maxPiZeroes")),
                   outputRootFileName_(iConfig.getParameter<string>("outputRootFileName"))

{
   outputFile_ = new TFile(outputRootFileName_.c_str(), "RECREATE");
   edm::LogInfo("TauMVATrainer") << "Initializing TauMVATrainer ctor...";
   // set as signal or background
   discriminantManager_.setSignalFlag(iAmSignal_);

   edm::LogInfo("TauMVATrainer") << "Adding discriminants to TauDiscriminantManager...";
   // add the discriminants to the discriminant manager
   for(DiscriminantList::const_iterator aDiscriminant  = myDiscriminants_.begin();
                                        aDiscriminant != myDiscriminants_.end();
                                      ++aDiscriminant)
   {
      discriminantManager_.addDiscriminant(*aDiscriminant);
   }

   //create tree to hold truth variables
   edm::LogInfo("TauMVATrainer") << "Building truth tree...";
   TTree* truthTree = new TTree("truth", "truth");
//   truthTree->SetDebug();
   myTrainerTrees_.insert(make_pair("truth", truthTree));
   theTruthTree_ = truthTree;
   // branch this trees according to the holder variables in the discrimimnant manager
   discriminantManager_.branchTree(truthTree);

   for(std::vector<ParameterSet>::const_iterator iSrc  = matchingSources_.begin();
                                            iSrc != matchingSources_.end();
                                          ++iSrc)
   {
      //create new matching info record
      tauMatchingInfoHolder aMatcher;
      //create a new tree for each input source
      aMatcher.truthToRecoTauMatchingTag        = iSrc->getParameter<InputTag>("truthMatchSource");
      aMatcher.decayModeToRecoTauAssociationTag = iSrc->getParameter<InputTag>("decayModeAssociationSource"); 
      string label = aMatcher.decayModeToRecoTauAssociationTag.label();
      edm::LogInfo("TauMVATrainer") << "Building reco tree w/ label: " << label << "...";
      TTree* newTree = new TTree(label.c_str(),label.c_str());
      discriminantManager_.branchTree(newTree);
      aMatcher.associatedTTree = newTree;
      matchingInfo_.push_back(aMatcher);
      myTrainerTrees_.insert(make_pair(label, newTree));
   }

}
TauMVATrainer::~TauMVATrainer ( )

Definition at line 143 of file TauMVATrainer.cc.

{
}

Member Function Documentation

void TauMVATrainer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDAnalyzer.

Definition at line 150 of file TauMVATrainer.cc.

References abs, reco::LeafCandidate::charge(), DeDxDiscriminatorTools::charge(), reco::PFTauDecayMode::chargedPions(), discriminantManager_, edm::Event::getByLabel(), edm::Ref< C, T, F >::isNonnull(), matchingInfo_, maxPiZeroes_, maxTracks_, mcTruthSource_, reco::PFTauDecayMode::neutralPions(), reco::CompositeCandidate::numberOfDaughters(), reco::PFTauDecayMode::pfTauRef(), dt_dqm_sourceclient_common_cff::reco, PFTauDiscriminants::PFTauDiscriminantManager::setEvent(), PFTauDiscriminants::PFTauDiscriminantManager::setNullResult(), PFTauDiscriminants::PFTauDiscriminantManager::setTau(), and theTruthTree_.

{
   using namespace edm;
   using namespace reco;


   // get list of MC Truth objects
   edm::Handle<PFTauDecayModeCollection> truthObjects;
   iEvent.getByLabel(mcTruthSource_, truthObjects);

   discriminantManager_.setEvent(iEvent, 1.0); // unit weight for now

   size_t numberOfTruthObjects = truthObjects->size();
   // loop over true MCTaus and find matched reco objects for each producer
   for(size_t iTrueTau = 0; iTrueTau < numberOfTruthObjects; ++iTrueTau)
   {
      PFTauDecayModeRef theTrueTau = PFTauDecayModeRef(truthObjects, iTrueTau);

      // compute quantities for the truth object and fill associated tree
      discriminantManager_.setTau(*theTrueTau);
      theTruthTree_->Fill();

      // loop over the reco object collections
      for(tauMatchingInfos::iterator iMatchingInfo  = matchingInfo_.begin();
                                     iMatchingInfo != matchingInfo_.end();
                                   ++iMatchingInfo)
      {
         //get matching info from event
         edm::Handle<PFTauDecayModeMatchMap>& theMatching = iMatchingInfo->truthToRecoTauMatchingHandle;
         iEvent.getByLabel(iMatchingInfo->truthToRecoTauMatchingTag, theMatching);

         //get PFTau->PFTauDecayMode association from event
         edm::Handle<PFTauDecayModeAssociation>& theDMAssoc = iMatchingInfo->decayModeToRecoTauAssociationHandle;
         iEvent.getByLabel(iMatchingInfo->decayModeToRecoTauAssociationTag, theDMAssoc);

         //get associated ttree
         TTree* treeToFill           = iMatchingInfo->associatedTTree;

         // Retrieves associated PFTau
         PFTauRef          theAssociatedRecoTau   = (*theMatching)[theTrueTau];

         //determine if there is a RECO match and make sure it has at least one charged signal occupant
         bool isNonNull = (theAssociatedRecoTau.isNonnull() && theAssociatedRecoTau->signalPFChargedHadrCands().size());

         // apply discriminants if there is an associated reconstructed object with at least one track
         if(isNonNull)
         {
            // From associated PFTau get the DecayMode reconstruction
            const PFTauDecayMode& theAssociatedDecayMode = (*theDMAssoc)[theAssociatedRecoTau];
            //determine if tau needs a PRE-pass/fail cut
            bool prePass = false;
            bool preFail = false;
            unsigned int numberOfTracks   = theAssociatedDecayMode.chargedPions().numberOfDaughters();
            unsigned int charge           = std::abs(theAssociatedDecayMode.charge());
            unsigned int numberOfPiZeros  = theAssociatedDecayMode.neutralPions().numberOfDaughters();
            unsigned int numberOfOutliers = theAssociatedDecayMode.pfTauRef()->isolationPFCands().size();
            //cut on high multiplicity
            if (numberOfTracks > maxTracks_ || numberOfPiZeros > maxPiZeroes_  || (charge != 1 && numberOfTracks == 3))
               preFail = true;
            //cut on isolated single prong
            else if (numberOfTracks == 1 && numberOfPiZeros == 0 && numberOfOutliers == 0)
            {
               prePass = true;
            }

            discriminantManager_.setTau(theAssociatedDecayMode, prePass, preFail);
         }
         else 
            // if not, set the null flag
            discriminantManager_.setNullResult();
         treeToFill->Fill();
      }
   }
}
void TauMVATrainer::beginJob ( void  ) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 227 of file TauMVATrainer.cc.

{
}
void TauMVATrainer::endJob ( void  ) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 233 of file TauMVATrainer.cc.

References myTrainerTrees_, and outputFile_.

                      {
   for(std::map<string, TTree*>::iterator iTree  = myTrainerTrees_.begin();
                                     iTree != myTrainerTrees_.end();
                                   ++iTree)
   {
      const TTree* myTree = iTree->second;
      edm::LogInfo("TauMVATrainer") << "Tree " << myTree->GetName() << " has " << myTree->GetEntries() << " entries.";
   }
   outputFile_->Write();
}

Member Data Documentation

Definition at line 81 of file TauMVATrainer.cc.

Referenced by analyze(), and TauMVATrainer().

bool TauMVATrainer::iAmSignal_ [private]

Definition at line 73 of file TauMVATrainer.cc.

Referenced by TauMVATrainer().

Definition at line 72 of file TauMVATrainer.cc.

Referenced by analyze(), and TauMVATrainer().

Definition at line 71 of file TauMVATrainer.cc.

Referenced by TauMVATrainer().

uint32_t TauMVATrainer::maxPiZeroes_ [private]

Definition at line 76 of file TauMVATrainer.cc.

Referenced by analyze().

uint32_t TauMVATrainer::maxTracks_ [private]

Definition at line 75 of file TauMVATrainer.cc.

Referenced by analyze().

Definition at line 69 of file TauMVATrainer.cc.

Referenced by analyze().

Definition at line 83 of file TauMVATrainer.cc.

Referenced by TauMVATrainer().

std::map<string, TTree*> TauMVATrainer::myTrainerTrees_ [private]

Definition at line 79 of file TauMVATrainer.cc.

Referenced by endJob(), and TauMVATrainer().

TFile* TauMVATrainer::outputFile_ [private]

Definition at line 82 of file TauMVATrainer.cc.

Referenced by endJob(), and TauMVATrainer().

std::string TauMVATrainer::outputRootFileName_ [private]

Definition at line 78 of file TauMVATrainer.cc.

Referenced by TauMVATrainer().

TTree* TauMVATrainer::theTruthTree_ [private]

Definition at line 80 of file TauMVATrainer.cc.

Referenced by analyze(), and TauMVATrainer().