CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Attributes
TauMVATrainer Class Reference

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

Inheritance diagram for TauMVATrainer:
edm::EDAnalyzer edm::EDConsumerBase

Classes

struct  tauMatchingInfoHolder
 

Public Types

typedef std::vector
< tauMatchingInfoHolder
tauMatchingInfos
 
typedef std::vector< std::pair
< TTree *, const
PFTauDecayModeMatchMap * > > 
treeToMatchTuple
 
- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void endJob ()
 
 TauMVATrainer (const edm::ParameterSet &)
 
 ~TauMVATrainer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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_, diffTwoXMLs::label, edm::InputTag::label(), matchingInfo_, matchingSources_, myDiscriminants_, myTrainerTrees_, outputFile_, outputRootFileName_, PFTauDiscriminants::PFTauDiscriminantManager::setSignalFlag(), theTruthTree_, and TauMVATrainer::tauMatchingInfoHolder::truthToRecoTauMatchingTag.

90  :
91  mcTruthSource_(iConfig.getParameter<InputTag>("mcTruthSource")),
92  matchingSources_(iConfig.getParameter<vector<ParameterSet> >("matchingSources")),
93  iAmSignal_(iConfig.getParameter<bool>("iAmSignal")),
94  maxTracks_(iConfig.getParameter<uint32_t>("maxTracks")),
95  maxPiZeroes_(iConfig.getParameter<uint32_t>("maxPiZeroes")),
96  outputRootFileName_(iConfig.getParameter<string>("outputRootFileName"))
97 
98 {
99  outputFile_ = new TFile(outputRootFileName_.c_str(), "RECREATE");
100  edm::LogInfo("TauMVATrainer") << "Initializing TauMVATrainer ctor...";
101  // set as signal or background
103 
104  edm::LogInfo("TauMVATrainer") << "Adding discriminants to TauDiscriminantManager...";
105  // add the discriminants to the discriminant manager
107  aDiscriminant != myDiscriminants_.end();
108  ++aDiscriminant)
109  {
110  discriminantManager_.addDiscriminant(*aDiscriminant);
111  }
112 
113  //create tree to hold truth variables
114  edm::LogInfo("TauMVATrainer") << "Building truth tree...";
115  TTree* truthTree = new TTree("truth", "truth");
116 // truthTree->SetDebug();
117  myTrainerTrees_.insert(make_pair("truth", truthTree));
118  theTruthTree_ = truthTree;
119  // branch this trees according to the holder variables in the discrimimnant manager
120  discriminantManager_.branchTree(truthTree);
121 
122  for(std::vector<ParameterSet>::const_iterator iSrc = matchingSources_.begin();
123  iSrc != matchingSources_.end();
124  ++iSrc)
125  {
126  //create new matching info record
127  tauMatchingInfoHolder aMatcher;
128  //create a new tree for each input source
129  aMatcher.truthToRecoTauMatchingTag = iSrc->getParameter<InputTag>("truthMatchSource");
130  aMatcher.decayModeToRecoTauAssociationTag = iSrc->getParameter<InputTag>("decayModeAssociationSource");
131  string label = aMatcher.decayModeToRecoTauAssociationTag.label();
132  edm::LogInfo("TauMVATrainer") << "Building reco tree w/ label: " << label << "...";
133  TTree* newTree = new TTree(label.c_str(),label.c_str());
135  aMatcher.associatedTTree = newTree;
136  matchingInfo_.push_back(aMatcher);
137  myTrainerTrees_.insert(make_pair(label, newTree));
138  }
139 
140 }
T getParameter(std::string const &) const
InputTag mcTruthSource_
std::string outputRootFileName_
std::map< string, TTree * > myTrainerTrees_
void addDiscriminant(Discriminant *const aDiscriminant)
add a discriminant
uint32_t maxTracks_
std::vector< ParameterSet > matchingSources_
uint32_t maxPiZeroes_
std::vector< tauMatchingInfoHolder > matchingInfo_
bool branchTree(TTree *const treeToBranch, bool addTargetBranch=false, bool addWeightBranch=false)
add a set of branches ot the TTree
const_iterator begin()
iterators over the list
collection::const_iterator const_iterator
DiscriminantList myDiscriminants_
PFTauDiscriminantManager discriminantManager_
TTree * theTruthTree_
TFile * outputFile_
TauMVATrainer::~TauMVATrainer ( )

Definition at line 143 of file TauMVATrainer.cc.

144 {
145 }

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, DeDxDiscriminatorTools::charge(), reco::LeafCandidate::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(), L1Trigger_dataformats::reco, PFTauDiscriminants::PFTauDiscriminantManager::setEvent(), PFTauDiscriminants::PFTauDiscriminantManager::setNullResult(), PFTauDiscriminants::PFTauDiscriminantManager::setTau(), and theTruthTree_.

151 {
152  using namespace edm;
153  using namespace reco;
154 
155 
156  // get list of MC Truth objects
158  iEvent.getByLabel(mcTruthSource_, truthObjects);
159 
160  discriminantManager_.setEvent(iEvent, 1.0); // unit weight for now
161 
162  size_t numberOfTruthObjects = truthObjects->size();
163  // loop over true MCTaus and find matched reco objects for each producer
164  for(size_t iTrueTau = 0; iTrueTau < numberOfTruthObjects; ++iTrueTau)
165  {
166  PFTauDecayModeRef theTrueTau = PFTauDecayModeRef(truthObjects, iTrueTau);
167 
168  // compute quantities for the truth object and fill associated tree
169  discriminantManager_.setTau(*theTrueTau);
170  theTruthTree_->Fill();
171 
172  // loop over the reco object collections
173  for(tauMatchingInfos::iterator iMatchingInfo = matchingInfo_.begin();
174  iMatchingInfo != matchingInfo_.end();
175  ++iMatchingInfo)
176  {
177  //get matching info from event
178  edm::Handle<PFTauDecayModeMatchMap>& theMatching = iMatchingInfo->truthToRecoTauMatchingHandle;
179  iEvent.getByLabel(iMatchingInfo->truthToRecoTauMatchingTag, theMatching);
180 
181  //get PFTau->PFTauDecayMode association from event
182  edm::Handle<PFTauDecayModeAssociation>& theDMAssoc = iMatchingInfo->decayModeToRecoTauAssociationHandle;
183  iEvent.getByLabel(iMatchingInfo->decayModeToRecoTauAssociationTag, theDMAssoc);
184 
185  //get associated ttree
186  TTree* treeToFill = iMatchingInfo->associatedTTree;
187 
188  // Retrieves associated PFTau
189  PFTauRef theAssociatedRecoTau = (*theMatching)[theTrueTau];
190 
191  //determine if there is a RECO match and make sure it has at least one charged signal occupant
192  bool isNonNull = (theAssociatedRecoTau.isNonnull() && theAssociatedRecoTau->signalPFChargedHadrCands().size());
193 
194  // apply discriminants if there is an associated reconstructed object with at least one track
195  if(isNonNull)
196  {
197  // From associated PFTau get the DecayMode reconstruction
198  const PFTauDecayMode& theAssociatedDecayMode = (*theDMAssoc)[theAssociatedRecoTau];
199  //determine if tau needs a PRE-pass/fail cut
200  bool prePass = false;
201  bool preFail = false;
202  unsigned int numberOfTracks = theAssociatedDecayMode.chargedPions().numberOfDaughters();
203  unsigned int charge = std::abs(theAssociatedDecayMode.charge());
204  unsigned int numberOfPiZeros = theAssociatedDecayMode.neutralPions().numberOfDaughters();
205  unsigned int numberOfOutliers = theAssociatedDecayMode.pfTauRef()->isolationPFCands().size();
206  //cut on high multiplicity
207  if (numberOfTracks > maxTracks_ || numberOfPiZeros > maxPiZeroes_ || (charge != 1 && numberOfTracks == 3))
208  preFail = true;
209  //cut on isolated single prong
210  else if (numberOfTracks == 1 && numberOfPiZeros == 0 && numberOfOutliers == 0)
211  {
212  prePass = true;
213  }
214 
215  discriminantManager_.setTau(theAssociatedDecayMode, prePass, preFail);
216  }
217  else
218  // if not, set the null flag
220  treeToFill->Fill();
221  }
222  }
223 }
InputTag mcTruthSource_
bool setTau(const reco::PFTauDecayMode &theTau, bool prePass=false, bool preFail=false)
set objects for this discriminant
uint32_t maxTracks_
#define abs(x)
Definition: mlp_lapack.h:159
const VertexCompositeCandidate & chargedPions() const
returns collection of charged pions w/ vertex information (tracks are refit)
double charge(const std::vector< uint8_t > &Ampls)
virtual size_type numberOfDaughters() const
number of daughters
const PFTauRef & pfTauRef() const
return reference to associated PFTau object
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
const CompositeCandidate & neutralPions() const
returns a collection of merged Pi0s
void setEvent(const edm::Event &, double eventWeight)
set the current event. Must be called (once per event) before setTau or setNullResult ...
uint32_t maxPiZeroes_
std::vector< tauMatchingInfoHolder > matchingInfo_
edm::Ref< PFTauDecayModeCollection > PFTauDecayModeRef
presistent reference to a PFTauDecayMode
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual int charge() const GCC11_FINAL
electric charge
PFTauDiscriminantManager discriminantManager_
TTree * theTruthTree_
void TauMVATrainer::beginJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 227 of file TauMVATrainer.cc.

228 {
229 }
void TauMVATrainer::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 233 of file TauMVATrainer.cc.

References myTrainerTrees_, and outputFile_.

233  {
234  for(std::map<string, TTree*>::iterator iTree = myTrainerTrees_.begin();
235  iTree != myTrainerTrees_.end();
236  ++iTree)
237  {
238  const TTree* myTree = iTree->second;
239  edm::LogInfo("TauMVATrainer") << "Tree " << myTree->GetName() << " has " << myTree->GetEntries() << " entries.";
240  }
241  outputFile_->Write();
242 }
std::map< string, TTree * > myTrainerTrees_
TFile * outputFile_

Member Data Documentation

PFTauDiscriminantManager TauMVATrainer::discriminantManager_
private

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().

std::vector<tauMatchingInfoHolder> TauMVATrainer::matchingInfo_
private

Definition at line 72 of file TauMVATrainer.cc.

Referenced by analyze(), and TauMVATrainer().

std::vector<ParameterSet> TauMVATrainer::matchingSources_
private

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().

InputTag TauMVATrainer::mcTruthSource_
private

Definition at line 69 of file TauMVATrainer.cc.

Referenced by analyze().

DiscriminantList TauMVATrainer::myDiscriminants_
private

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().