#include <RecoTauTag/TauTagTools/src/TauMVATrainer.cc>
Public Types | |
typedef vector < tauMatchingInfoHolder > | tauMatchingInfos |
typedef vector< pair< TTree *, const PFTauDecayModeMatchMap * > > | treeToMatchTuple |
Public Member Functions | |
virtual void | analyze (const edm::Event &, const edm::EventSetup &) |
virtual void | beginJob (const edm::EventSetup &) |
virtual void | endJob () |
TauMVATrainer (const edm::ParameterSet &) | |
~TauMVATrainer () | |
Private Attributes | |
PFTauDiscriminantManager | discriminantManager_ |
bool | iAmSignal_ |
vector< tauMatchingInfoHolder > | matchingInfo_ |
vector< ParameterSet > | matchingSources_ |
uint32_t | maxPiZeroes_ |
uint32_t | maxTracks_ |
InputTag | mcTruthSource_ |
DiscriminantList | myDiscriminants_ |
map< string, TTree * > | myTrainerTrees_ |
TFile * | outputFile_ |
std::string | outputRootFileName_ |
TTree * | theTruthTree_ |
Classes | |
struct | tauMatchingInfoHolder |
Implementation: <Notes on="" implementation>="">
Definition at line 46 of file TauMVATrainer.cc.
typedef vector<tauMatchingInfoHolder> TauMVATrainer::tauMatchingInfos |
Definition at line 57 of file TauMVATrainer.cc.
typedef vector<pair<TTree*, const PFTauDecayModeMatchMap*> > TauMVATrainer::treeToMatchTuple |
Definition at line 58 of file TauMVATrainer.cc.
TauMVATrainer::TauMVATrainer | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
Definition at line 89 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.
00089 : 00090 mcTruthSource_(iConfig.getParameter<InputTag>("mcTruthSource")), 00091 matchingSources_(iConfig.getParameter<vector<ParameterSet> >("matchingSources")), 00092 iAmSignal_(iConfig.getParameter<bool>("iAmSignal")), 00093 maxTracks_(iConfig.getParameter<uint32_t>("maxTracks")), 00094 maxPiZeroes_(iConfig.getParameter<uint32_t>("maxPiZeroes")), 00095 outputRootFileName_(iConfig.getParameter<string>("outputRootFileName")) 00096 00097 { 00098 outputFile_ = new TFile(outputRootFileName_.c_str(), "RECREATE"); 00099 edm::LogInfo("TauMVATrainer") << "Initializing TauMVATrainer ctor..."; 00100 // set as signal or background 00101 discriminantManager_.setSignalFlag(iAmSignal_); 00102 00103 edm::LogInfo("TauMVATrainer") << "Adding discriminants to TauDiscriminantManager..."; 00104 // add the discriminants to the discriminant manager 00105 for(DiscriminantList::const_iterator aDiscriminant = myDiscriminants_.begin(); 00106 aDiscriminant != myDiscriminants_.end(); 00107 ++aDiscriminant) 00108 { 00109 discriminantManager_.addDiscriminant(*aDiscriminant); 00110 } 00111 00112 //create tree to hold truth variables 00113 edm::LogInfo("TauMVATrainer") << "Building truth tree..."; 00114 TTree* truthTree = new TTree("truth", "truth"); 00115 // truthTree->SetDebug(); 00116 myTrainerTrees_.insert(make_pair("truth", truthTree)); 00117 theTruthTree_ = truthTree; 00118 // branch this trees according to the holder variables in the discrimimnant manager 00119 discriminantManager_.branchTree(truthTree); 00120 00121 for(vector<ParameterSet>::const_iterator iSrc = matchingSources_.begin(); 00122 iSrc != matchingSources_.end(); 00123 ++iSrc) 00124 { 00125 //create new matching info record 00126 tauMatchingInfoHolder aMatcher; 00127 //create a new tree for each input source 00128 aMatcher.truthToRecoTauMatchingTag = iSrc->getParameter<InputTag>("truthMatchSource"); 00129 aMatcher.decayModeToRecoTauAssociationTag = iSrc->getParameter<InputTag>("decayModeAssociationSource"); 00130 string label = aMatcher.decayModeToRecoTauAssociationTag.label(); 00131 edm::LogInfo("TauMVATrainer") << "Building reco tree w/ label: " << label << "..."; 00132 TTree* newTree = new TTree(label.c_str(),label.c_str()); 00133 discriminantManager_.branchTree(newTree); 00134 aMatcher.associatedTTree = newTree; 00135 matchingInfo_.push_back(aMatcher); 00136 myTrainerTrees_.insert(make_pair(label, newTree)); 00137 } 00138 00139 }
TauMVATrainer::~TauMVATrainer | ( | ) |
void TauMVATrainer::analyze | ( | const edm::Event & | iEvent, | |
const edm::EventSetup & | iSetup | |||
) | [virtual] |
Implements edm::EDAnalyzer.
Definition at line 149 of file TauMVATrainer.cc.
References funct::abs(), reco::Particle::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(), HcalSimpleRecAlgoImpl::reco(), PFTauDiscriminants::PFTauDiscriminantManager::setEventData(), PFTauDiscriminants::PFTauDiscriminantManager::setNullResult(), and theTruthTree_.
00150 { 00151 using namespace edm; 00152 using namespace reco; 00153 00154 00155 // get list of MC Truth objects 00156 Handle<PFTauDecayModeCollection> truthObjects; 00157 iEvent.getByLabel(mcTruthSource_, truthObjects); 00158 00159 size_t numberOfTruthObjects = truthObjects->size(); 00160 // loop over true MCTaus and find matched reco objects for each producer 00161 for(size_t iTrueTau = 0; iTrueTau < numberOfTruthObjects; ++iTrueTau) 00162 { 00163 PFTauDecayModeRef theTrueTau = PFTauDecayModeRef(truthObjects, iTrueTau); 00164 00165 // compute quantities for the truth object and fill associated tree 00166 discriminantManager_.setEventData(*theTrueTau, iEvent); 00167 theTruthTree_->Fill(); 00168 00169 // loop over the reco object collections 00170 for(tauMatchingInfos::iterator iMatchingInfo = matchingInfo_.begin(); 00171 iMatchingInfo != matchingInfo_.end(); 00172 ++iMatchingInfo) 00173 { 00174 //get matching info from event 00175 Handle<PFTauDecayModeMatchMap>& theMatching = iMatchingInfo->truthToRecoTauMatchingHandle; 00176 iEvent.getByLabel(iMatchingInfo->truthToRecoTauMatchingTag, theMatching); 00177 00178 //get PFTau->PFTauDecayMode association from event 00179 Handle<PFTauDecayModeAssociation>& theDMAssoc = iMatchingInfo->decayModeToRecoTauAssociationHandle; 00180 iEvent.getByLabel(iMatchingInfo->decayModeToRecoTauAssociationTag, theDMAssoc); 00181 00182 //get associated ttree 00183 TTree* treeToFill = iMatchingInfo->associatedTTree; 00184 00185 // Retrieves associated PFTau 00186 PFTauRef theAssociatedRecoTau = (*theMatching)[theTrueTau]; 00187 00188 //determine if there is a RECO match and make sure it has at least one charged signal occupant 00189 bool isNonNull = (theAssociatedRecoTau.isNonnull() && theAssociatedRecoTau->signalPFChargedHadrCands().size()); 00190 00191 // apply discriminants if there is an associated reconstructed object with at least one track 00192 if(isNonNull) 00193 { 00194 // From associated PFTau get the DecayMode reconstruction 00195 const PFTauDecayMode& theAssociatedDecayMode = (*theDMAssoc)[theAssociatedRecoTau]; 00196 //determine if tau needs a PRE-pass/fail cut 00197 bool prePass = false; 00198 bool preFail = false; 00199 unsigned int numberOfTracks = theAssociatedDecayMode.chargedPions().numberOfDaughters(); 00200 unsigned int charge = abs(theAssociatedDecayMode.charge()); 00201 unsigned int numberOfPiZeros = theAssociatedDecayMode.neutralPions().numberOfDaughters(); 00202 unsigned int numberOfOutliers = theAssociatedDecayMode.pfTauRef()->isolationPFCands().size(); 00203 //cut on high multiplicity 00204 if (numberOfTracks > maxTracks_ || numberOfPiZeros > maxPiZeroes_ || (charge != 1 && numberOfTracks == 3)) 00205 preFail = true; 00206 //cut on isolated single prong 00207 else if (numberOfTracks == 1 && numberOfPiZeros == 0 && numberOfOutliers == 0) 00208 { 00209 prePass = true; 00210 } 00211 00212 discriminantManager_.setEventData(theAssociatedDecayMode, iEvent, 1.0, prePass, preFail); 00213 } 00214 else 00215 // if not, set the null flag 00216 discriminantManager_.setNullResult(iEvent); 00217 treeToFill->Fill(); 00218 } 00219 } 00220 }
void TauMVATrainer::beginJob | ( | const edm::EventSetup & | ) | [virtual] |
Reimplemented from edm::EDAnalyzer.
Definition at line 230 of file TauMVATrainer.cc.
References myTrainerTrees_, and outputFile_.
00230 { 00231 for(map<string, TTree*>::iterator iTree = myTrainerTrees_.begin(); 00232 iTree != myTrainerTrees_.end(); 00233 ++iTree) 00234 { 00235 const TTree* myTree = iTree->second; 00236 edm::LogInfo("TauMVATrainer") << "Tree " << myTree->GetName() << " has " << myTree->GetEntries() << " entries."; 00237 } 00238 outputFile_->Write(); 00239 }
bool TauMVATrainer::iAmSignal_ [private] |
vector<tauMatchingInfoHolder> TauMVATrainer::matchingInfo_ [private] |
vector<ParameterSet> TauMVATrainer::matchingSources_ [private] |
uint32_t TauMVATrainer::maxPiZeroes_ [private] |
uint32_t TauMVATrainer::maxTracks_ [private] |
InputTag TauMVATrainer::mcTruthSource_ [private] |
map<string, TTree*> TauMVATrainer::myTrainerTrees_ [private] |
TFile* TauMVATrainer::outputFile_ [private] |
std::string TauMVATrainer::outputRootFileName_ [private] |
TTree* TauMVATrainer::theTruthTree_ [private] |