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
PFTauMVADiscriminator Class Reference

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

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

Classes

struct  MVAComputerFromDB
 

Public Types

typedef std::map< int,
MVAList::iterator > 
DecayModeToMVAMap
 
typedef std::vector
< MVAComputerFromDB
MVAList
 
- Public Types inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
typedef std::vector< TauType > TauCollection
 
typedef edm::Ref< TauCollectionTauRef
 
typedef edm::RefProd
< TauCollection
TauRefProd
 
- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 

Public Member Functions

void beginEvent (const edm::Event &, const edm::EventSetup &)
 
double discriminate (const PFTauRef &)
 
 PFTauMVADiscriminator (const edm::ParameterSet &)
 
 ~PFTauMVADiscriminator ()
 
- Public Member Functions inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
virtual double discriminate (const TauRef &tau)=0
 
virtual void endEvent (edm::Event &evt)
 
void produce (edm::Event &, const edm::EventSetup &)
 
 TauDiscriminationProducerBase (const edm::ParameterSet &iConfig)
 
 TauDiscriminationProducerBase ()
 
virtual ~TauDiscriminationProducerBase ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

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_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 
- Protected Attributes inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
double prediscriminantFailValue_
 
edm::InputTag TauProducer_
 

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(), edm::hlt::Exception, edm::ParameterSet::getParameter(), myDiscriminants_, pfTauDecayModeSrc_, TauDiscriminationProducerBase< TauType, TauDiscriminator >::prediscriminantFailValue_, remapOutput_, and PFTauMVADiscriminator::MVAComputerFromDB::userCut.

75 {
76  pfTauDecayModeSrc_ = iConfig.getParameter<edm::InputTag>("pfTauDecayModeSrc");
77  remapOutput_ = iConfig.getParameter<bool>("RemapOutput");
78  applyCut_ = iConfig.getParameter<bool>("MakeBinaryDecision");
79  prediscriminantFailValue_ = iConfig.getParameter<double>("prefailValue"); //defined in base class
80  dbLabel_ = iConfig.getParameter<std::string>("dbLabel");
81 
82  // build the decaymode->computer map
83  std::vector<edm::ParameterSet> decayModeMap = iConfig.getParameter<std::vector<edm::ParameterSet> >("computers");
84  computers_.reserve(decayModeMap.size());
85  for(std::vector<edm::ParameterSet>::const_iterator iComputer = decayModeMap.begin(); iComputer != decayModeMap.end(); ++iComputer)
86  {
87  MVAComputerFromDB toInsert;
88  toInsert.computerName = iComputer->getParameter<std::string>("computerName");
89  toInsert.userCut = iComputer->getParameter<double>("cut");
90  toInsert.computer = new PhysicsTools::MVAComputerCache();
91  MVAList::iterator computerJustAdded = computers_.insert(computers_.end(), toInsert); //add this computer to the end of the list
92 
93  //populate the map
94  std::vector<int> associatedDecayModes = iComputer->getParameter<std::vector<int> >("decayModeIndices");
95  for(std::vector<int>::const_iterator iDecayMode = associatedDecayModes.begin();
96  iDecayMode != associatedDecayModes.end();
97  ++iDecayMode)
98  {
99  //map this integer specifying the decay mode to the MVA comptuer we just added to the list
100  std::pair<DecayModeToMVAMap::iterator, bool> insertResult = computerMap_.insert(std::make_pair(*iDecayMode, computerJustAdded));
101 
102  //make sure we aren't double mapping a decay mode
103  if(insertResult.second == false) { //indicates that the current key (decaymode) has already been entered!
104  throw cms::Exception("PFTauMVADiscriminator::ctor") << "A tau decay mode: " << *iDecayMode << " has been mapped to two different MVA implementations, "
105  << insertResult.first->second->computerName << " and " << toInsert.computerName
106  << ". Please check the appropriate cfi file." << std::endl;
107  }
108  }
109  }
110 
112  aDiscriminant != myDiscriminants_.end();
113  ++aDiscriminant)
114  {
115  //load the discriminants into the discriminant manager
116  discriminantManager_.addDiscriminant(*aDiscriminant);
117  }
118 
119 }
T getParameter(std::string const &) const
DiscriminantList myDiscriminants_
void addDiscriminant(Discriminant *const aDiscriminant)
add a discriminant
const_iterator begin()
iterators over the list
DecayModeToMVAMap computerMap_
TauDiscriminationProducerBase< reco::PFTau, reco::PFTauDiscriminator > PFTauDiscriminationProducerBase
collection::const_iterator const_iterator
PFTauDiscriminantManager discriminantManager_
Creates and and MVAComputer from calibrations via EventSetup.
PFTauMVADiscriminator::~PFTauMVADiscriminator ( )

Definition at line 121 of file PFTauMVADiscriminator.cc.

References computers_.

122 {
123  for(MVAList::iterator iMVAComputer = computers_.begin(); iMVAComputer != computers_.end(); ++iMVAComputer)
124  {
125  delete iMVAComputer->computer;
126  }
127 }

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_, and PFTauDiscriminants::PFTauDiscriminantManager::setEvent().

131 {
132  // load the PFTauDecayModes
134 
135  // expose the event to the PFTau discriminant quantity computers
136  discriminantManager_.setEvent(iEvent, 1.0); //event weight = 1
137 
138  // Refresh MVAs
139  //we do this on each event as the crossing an IOV boundary could change the appropriate record
140  for(MVAList::iterator iMVAComputer = computers_.begin();
141  iMVAComputer != computers_.end();
142  ++iMVAComputer)
143  {
144  std::string nameToGet = iMVAComputer->computerName;
145  iMVAComputer->computer->update<TauMVAFrameworkDBRcd>(dbLabel_.c_str(), iSetup, nameToGet.c_str());
146  }
147 }
void setEvent(const edm::Event &, double eventWeight)
set the current event. Must be called (once per event) before setTau or setNullResult ...
edm::Handle< PFTauDecayModeAssociation > pfTauDecayModes
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
PFTauDiscriminantManager discriminantManager_
double PFTauMVADiscriminator::discriminate ( const PFTauRef pfTau)

Definition at line 149 of file PFTauMVADiscriminator.cc.

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

150 {
152 
153  mvaComputerInput_.clear();
154  const PFTauDecayMode& theTauDecayMode = (*pfTauDecayModes)[pfTau]; // get PFTauDecayMode associated to this PFTau
155 
156 
157  //get appropriate MVA computer
158  int decayMode = theTauDecayMode.getDecayMode();
159  DecayModeToMVAMap::iterator iterToComputer = computerMap_.find(decayMode);
160 
161  if(iterToComputer != computerMap_.end()) //if we don't have a MVA mapped to this decay mode, skip it.
162  {
163  const PhysicsTools::MVAComputerCache* mvaComputer = iterToComputer->second->computer;
164  if ( (*mvaComputer) )
165  {
166  //sets the current tau decay mode as the active object
167  discriminantManager_.setTau(theTauDecayMode);
168  //applies associated discriminants (see ctor) and constructs the appropriate MVA framework input
170  result = (*mvaComputer)->eval(mvaComputerInput_);
171  }
172  else
173  {
174  edm::LogWarning("PFTauMVADiscriminator") << "Warning: got a null pointer to MVA computer in conditions database"
175  << " for decay mode: " << decayMode << ", expected MVA computer name: "
176  << iterToComputer->second->computerName;
177  }
178 
179  if (remapOutput_) // TMVA maps result to [-1, 1]. Remap, if desired, to [0, 1]
180  {
181  if (result > 1) result = 1.;
182  else if (result < -1) result = 0.;
183  else {
184  result += 1.;
185  result /= 2.;
186  }
187  }
188  if (applyCut_)
189  {
190  //If the user desires a yes or no decision,
191  // use the supplied cut to make a decision
192  if (result > iterToComputer->second->userCut)
193  result = 1.0;
194  else
195  result = 0.0;
196  }
197  }
198 
199  return result;
200 }
bool setTau(const reco::PFTauDecayMode &theTau, bool prePass=false, bool preFail=false)
set objects for this discriminant
hadronicTauDecayModes getDecayMode() const
std::vector< PhysicsTools::Variable::Value > mvaComputerInput_
tuple result
Definition: query.py:137
DecayModeToMVAMap computerMap_
PFTauDiscriminantManager discriminantManager_
Creates and and MVAComputer from calibrations via EventSetup.
void buildMVAComputerLink(std::vector< PhysicsTools::Variable::Value > &)
connect to an MVA computer

Member Data Documentation

bool PFTauMVADiscriminator::applyCut_
private

Definition at line 61 of file PFTauMVADiscriminator.cc.

Referenced by discriminate(), and PFTauMVADiscriminator().

DecayModeToMVAMap PFTauMVADiscriminator::computerMap_
private

Definition at line 63 of file PFTauMVADiscriminator.cc.

Referenced by discriminate(), and PFTauMVADiscriminator().

MVAList PFTauMVADiscriminator::computers_
private
std::string PFTauMVADiscriminator::dbLabel_
private

Definition at line 65 of file PFTauMVADiscriminator.cc.

Referenced by beginEvent(), and PFTauMVADiscriminator().

PFTauDiscriminantManager PFTauMVADiscriminator::discriminantManager_
private

Definition at line 67 of file PFTauMVADiscriminator.cc.

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

std::vector<PhysicsTools::Variable::Value> PFTauMVADiscriminator::mvaComputerInput_
private

Definition at line 71 of file PFTauMVADiscriminator.cc.

Referenced by discriminate().

DiscriminantList PFTauMVADiscriminator::myDiscriminants_
private

Definition at line 66 of file PFTauMVADiscriminator.cc.

Referenced by PFTauMVADiscriminator().

edm::Handle<PFTauDecayModeAssociation> PFTauMVADiscriminator::pfTauDecayModes
private

Definition at line 69 of file PFTauMVADiscriminator.cc.

Referenced by beginEvent().

edm::InputTag PFTauMVADiscriminator::pfTauDecayModeSrc_
private

Definition at line 59 of file PFTauMVADiscriminator.cc.

Referenced by beginEvent(), and PFTauMVADiscriminator().

bool PFTauMVADiscriminator::remapOutput_
private

Definition at line 60 of file PFTauMVADiscriminator.cc.

Referenced by discriminate(), and PFTauMVADiscriminator().