CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Attributes
RecoTauDiscriminantCutMultiplexer Class Reference
Inheritance diagram for RecoTauDiscriminantCutMultiplexer:
TauDiscriminationProducerBase< TauType, TauDiscriminator > edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Classes

struct  DiscriminantCutEntry
 

Public Member Functions

void beginEvent (const edm::Event &event, const edm::EventSetup &eventSetup) override
 
double discriminate (const reco::PFTauRef &) const override
 
 RecoTauDiscriminantCutMultiplexer (const edm::ParameterSet &pset)
 
 ~RecoTauDiscriminantCutMultiplexer () override
 
- Public Member Functions inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
virtual double discriminate (const TauRef &tau) const =0
 
virtual void endEvent (edm::Event &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 TauDiscriminationProducerBase (const edm::ParameterSet &iConfig)
 
 TauDiscriminationProducerBase ()
 
 ~TauDiscriminationProducerBase () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Types

typedef std::map< int, std::unique_ptr< DiscriminantCutEntry > > DiscriminantCutMap
 

Private Attributes

DiscriminantCutMap cuts_
 
edm::FileInPath inputFileName_
 
bool isInitialized_
 
edm::InputTag key_
 
edm::EDGetTokenT< reco::PFTauDiscriminatorkey_token
 
edm::Handle< reco::PFTauDiscriminatorkeyHandle_
 
bool loadMVAfromDB_
 
std::string moduleLabel_
 
std::unique_ptr< const TFormula > mvaOutput_normalization_
 
std::string mvaOutputNormalizationName_
 
edm::InputTag toMultiplex_
 
edm::EDGetTokenT< reco::PFTauDiscriminatortoMultiplex_token
 
edm::Handle< reco::PFTauDiscriminatortoMultiplexHandle_
 
int verbosity_
 

Additional Inherited Members

- Public Types inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
typedef std::vector< TauType > TauCollection
 
typedef edm::Ref< TauCollectionTauRef
 
typedef edm::RefProd< TauCollectionTauRefProd
 
- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- 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)
 
- Protected Attributes inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
std::string moduleLabel_
 
double prediscriminantFailValue_
 
edm::EDGetTokenT< TauCollectionTau_token
 
size_t tauIndex_
 
edm::InputTag TauProducer_
 

Detailed Description

Definition at line 34 of file RecoTauDiscriminantCutMultiplexer.cc.

Member Typedef Documentation

typedef std::map<int, std::unique_ptr<DiscriminantCutEntry> > RecoTauDiscriminantCutMultiplexer::DiscriminantCutMap
private

Definition at line 66 of file RecoTauDiscriminantCutMultiplexer.cc.

Constructor & Destructor Documentation

RecoTauDiscriminantCutMultiplexer::RecoTauDiscriminantCutMultiplexer ( const edm::ParameterSet pset)
explicit

Definition at line 136 of file RecoTauDiscriminantCutMultiplexer.cc.

References python.rootplot.argparse::category, gather_cfg::cout, TkAlMuonSelectors_cfi::cut, cuts_, Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), inputFileName_, key_, key_token, RecoTauDiscriminantCutMultiplexer::DiscriminantCutEntry::kFixedCut, RecoTauDiscriminantCutMultiplexer::DiscriminantCutEntry::kVariableCut, loadMVAfromDB_, HPSPFTaus_cff::mapping, moduleLabel_, eostools::move(), mvaOutputNormalizationName_, AlCaHLTBitMon_QueryRunRegistry::string, toMultiplex_, toMultiplex_token, verbosity_, and HistogramManager_cfi::VPSet().

138  moduleLabel_(cfg.getParameter<std::string>("@module_label")),
140  isInitialized_(false)
141 {
142 
143  toMultiplex_ = cfg.getParameter<edm::InputTag>("toMultiplex");
144  toMultiplex_token = consumes<reco::PFTauDiscriminator>(toMultiplex_);
145  key_ = cfg.getParameter<edm::InputTag>("key");
146  key_token = consumes<reco::PFTauDiscriminator>(key_);
147 
148  verbosity_ = ( cfg.exists("verbosity") ) ?
149  cfg.getParameter<int>("verbosity") : 0;
150 
151 
152  loadMVAfromDB_ = cfg.exists("loadMVAfromDB") ? cfg.getParameter<bool>("loadMVAfromDB") : false;
153  if ( !loadMVAfromDB_ ) {
154  if(cfg.exists("inputFileName")){
155  inputFileName_ = cfg.getParameter<edm::FileInPath>("inputFileName");
156  }else throw cms::Exception("MVA input not defined") << "Requested to load tau MVA input from ROOT file but no file provided in cfg file";
157  }
158  if(verbosity_) std::cout << moduleLabel_ << " loadMVA = " << loadMVAfromDB_ << std::endl;
159  if ( cfg.exists("mvaOutput_normalization") ) {
160  mvaOutputNormalizationName_ = cfg.getParameter<std::string>("mvaOutput_normalization");
161  }
162 
163  // Setup our cut map
164  typedef std::vector<edm::ParameterSet> VPSet;
165  VPSet mapping = cfg.getParameter<VPSet>("mapping");
166  for ( VPSet::const_iterator mappingEntry = mapping.begin();
167  mappingEntry != mapping.end(); ++mappingEntry ) {
168  unsigned category = mappingEntry->getParameter<uint32_t>("category");
169  std::unique_ptr<DiscriminantCutEntry> cut{new DiscriminantCutEntry()};
170  if ( mappingEntry->existsAs<double>("cut") ) {
171  cut->cutValue_ = mappingEntry->getParameter<double>("cut");
173  } else if ( mappingEntry->existsAs<std::string>("cut") ) {
174  cut->cutName_ = mappingEntry->getParameter<std::string>("cut");
175  std::string cutVariable_string = mappingEntry->getParameter<std::string>("variable");
176  cut->cutVariable_.reset( new StringObjectFunction<reco::PFTau>(cutVariable_string) );
178  } else {
179  throw cms::Exception("RecoTauDiscriminantCutMultiplexer")
180  << " Undefined Configuration Parameter 'cut' !!\n";
181  }
183  }
184 
185  verbosity_ = ( cfg.exists("verbosity") ) ?
186  cfg.getParameter<int>("verbosity") : 0;
187  if(verbosity_) std::cout << "constructed " << moduleLabel_ << std::endl;
188 }
std::unique_ptr< const TFormula > mvaOutput_normalization_
edm::EDGetTokenT< reco::PFTauDiscriminator > toMultiplex_token
edm::EDGetTokenT< reco::PFTauDiscriminator > key_token
TauDiscriminationProducerBase< reco::PFTau, reco::PFTauDiscriminator > PFTauDiscriminationProducerBase
def move(src, dest)
Definition: eostools.py:510
RecoTauDiscriminantCutMultiplexer::~RecoTauDiscriminantCutMultiplexer ( )
override

Definition at line 190 of file RecoTauDiscriminantCutMultiplexer.cc.

191 {
192 }

Member Function Documentation

void RecoTauDiscriminantCutMultiplexer::beginEvent ( const edm::Event event,
const edm::EventSetup eventSetup 
)
overridevirtual

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 194 of file RecoTauDiscriminantCutMultiplexer.cc.

References gather_cfg::cout, TkAlMuonSelectors_cfi::cut, cuts_, edm::Event::getByToken(), analyzePatCleaning_cfg::inputFile, inputFileName_, isInitialized_, key_token, keyHandle_, RecoTauDiscriminantCutMultiplexer::DiscriminantCutEntry::kVariableCut, loadMVAfromDB_, moduleLabel_, eostools::move(), mvaOutput_normalization_, mvaOutputNormalizationName_, groupFilesInBlocks::temp, toMultiplex_token, toMultiplexHandle_, and verbosity_.

195 {
196  if(verbosity_) std::cout << " begin! " << moduleLabel_ << " " << isInitialized_ << std::endl;
197  if ( !isInitialized_ ) {
198  //Only open the file once and we can close it when this routine is done
199  // since all objects gotten from the file will have been copied
200  std::unique_ptr<TFile> inputFile;
201  if ( mvaOutputNormalizationName_ != "" ) {
202  if ( !loadMVAfromDB_ ) {
203  inputFile = openInputFile(inputFileName_);
204  mvaOutput_normalization_ = loadObjectFromFile<TFormula>(*inputFile, mvaOutputNormalizationName_);
205  } else {
206  auto temp = loadTFormulaFromDB(es, mvaOutputNormalizationName_, Form("%s_mvaOutput_normalization", moduleLabel_.data()), verbosity_);
208  }
209  }
210  for ( DiscriminantCutMap::iterator cut = cuts_.begin();
211  cut != cuts_.end(); ++cut ) {
212  if ( cut->second->mode_ == DiscriminantCutEntry::kVariableCut ) {
213  if ( !loadMVAfromDB_ ) {
214  if(not inputFile) {
215  inputFile = openInputFile(inputFileName_);
216  }
217  if(verbosity_) std::cout << "Loading from file" << inputFileName_ << std::endl;
218  cut->second->cutFunction_ = loadObjectFromFile<TGraph>(*inputFile, cut->second->cutName_);
219  } else {
220  if(verbosity_) std::cout << "Loading from DB" << std::endl;
221  cut->second->cutFunction_ = loadTGraphFromDB(es, cut->second->cutName_, verbosity_);
222  }
223  }
224  }
225  isInitialized_ = true;
226  }
227 
228  evt.getByToken(toMultiplex_token, toMultiplexHandle_);
229  evt.getByToken(key_token, keyHandle_);
230 }
std::unique_ptr< const TFormula > mvaOutput_normalization_
edm::Handle< reco::PFTauDiscriminator > keyHandle_
edm::Handle< reco::PFTauDiscriminator > toMultiplexHandle_
edm::EDGetTokenT< reco::PFTauDiscriminator > toMultiplex_token
edm::EDGetTokenT< reco::PFTauDiscriminator > key_token
def move(src, dest)
Definition: eostools.py:510
double RecoTauDiscriminantCutMultiplexer::discriminate ( const reco::PFTauRef tau) const
override

Definition at line 233 of file RecoTauDiscriminantCutMultiplexer.cc.

References gather_cfg::cout, cuts_, DEFINE_FWK_MODULE, geometryDiff::epsilon, RecoTauDiscriminantCutMultiplexer::DiscriminantCutEntry::kFixedCut, RecoTauDiscriminantCutMultiplexer::DiscriminantCutEntry::kVariableCut, moduleLabel_, mvaOutput_normalization_, TauDiscriminationProducerBase< TauType, TauDiscriminator >::prediscriminantFailValue_, metsig::tau, verbosity_, anotherprimaryvertexanalyzer_cfi::xMax, and anotherprimaryvertexanalyzer_cfi::xMin.

234 {
235  if ( verbosity_ ) {
236  std::cout << "<RecoTauDiscriminantCutMultiplexer::discriminate>:" << std::endl;
237  std::cout << " moduleLabel = " << moduleLabel_ << std::endl;
238  }
239 
240  double disc_result = (*toMultiplexHandle_)[tau];
241  if ( verbosity_ ) {
242  std::cout << "disc_result = " << disc_result << std::endl;
243  }
244  if ( mvaOutput_normalization_ ) {
245  disc_result = mvaOutput_normalization_->Eval(disc_result);
246  //if ( disc_result > 1. ) disc_result = 1.;
247  //if ( disc_result < 0. ) disc_result = 0.;
248  if ( verbosity_ ) {
249  std::cout << "disc_result (normalized) = " << disc_result << std::endl;
250  }
251  }
252  double key_result = (*keyHandle_)[tau];
253  DiscriminantCutMap::const_iterator cutIter = cuts_.find(TMath::Nint(key_result));
254 
255 
256  // Return null if it doesn't exist
257  if ( cutIter == cuts_.end() ) {
259  }
260  // See if the discriminator passes our cuts
261  bool passesCuts = false;
262  if ( cutIter->second->mode_ == DiscriminantCutEntry::kFixedCut ) {
263  passesCuts = (disc_result > cutIter->second->cutValue_);
264  if ( verbosity_ ) {
265  std::cout << "cutValue (fixed) = " << cutIter->second->cutValue_ << " --> passesCuts = " << passesCuts << std::endl;
266  }
267  } else if ( cutIter->second->mode_ == DiscriminantCutEntry::kVariableCut ) {
268  double cutVariable = (*cutIter->second->cutVariable_)(*tau);
269  double xMin, xMax, dummy;
270  cutIter->second->cutFunction_->GetPoint(0, xMin, dummy);
271  cutIter->second->cutFunction_->GetPoint(cutIter->second->cutFunction_->GetN() - 1, xMax, dummy);
272  const double epsilon = 1.e-3;
273  if ( cutVariable < (xMin + epsilon) ) cutVariable = xMin + epsilon;
274  else if ( cutVariable > (xMax - epsilon) ) cutVariable = xMax - epsilon;
275  double cutValue = cutIter->second->cutFunction_->Eval(cutVariable);
276  passesCuts = (disc_result > cutValue);
277  if ( verbosity_ ) {
278  std::cout << "cutValue (@" << cutVariable << ") = " << cutValue << " --> passesCuts = " << passesCuts << std::endl;
279  }
280  } else assert(0);
281 
282  return passesCuts;
283 }
std::unique_ptr< const TFormula > mvaOutput_normalization_

Member Data Documentation

DiscriminantCutMap RecoTauDiscriminantCutMultiplexer::cuts_
private
edm::FileInPath RecoTauDiscriminantCutMultiplexer::inputFileName_
private
bool RecoTauDiscriminantCutMultiplexer::isInitialized_
private

Definition at line 72 of file RecoTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent().

edm::InputTag RecoTauDiscriminantCutMultiplexer::key_
private
edm::EDGetTokenT<reco::PFTauDiscriminator> RecoTauDiscriminantCutMultiplexer::key_token
private
edm::Handle<reco::PFTauDiscriminator> RecoTauDiscriminantCutMultiplexer::keyHandle_
private

Definition at line 77 of file RecoTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent().

bool RecoTauDiscriminantCutMultiplexer::loadMVAfromDB_
private
std::string RecoTauDiscriminantCutMultiplexer::moduleLabel_
private
std::unique_ptr<const TFormula> RecoTauDiscriminantCutMultiplexer::mvaOutput_normalization_
private

Definition at line 70 of file RecoTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent(), and discriminate().

std::string RecoTauDiscriminantCutMultiplexer::mvaOutputNormalizationName_
private
edm::InputTag RecoTauDiscriminantCutMultiplexer::toMultiplex_
private
edm::EDGetTokenT<reco::PFTauDiscriminator> RecoTauDiscriminantCutMultiplexer::toMultiplex_token
private
edm::Handle<reco::PFTauDiscriminator> RecoTauDiscriminantCutMultiplexer::toMultiplexHandle_
private

Definition at line 76 of file RecoTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent().

int RecoTauDiscriminantCutMultiplexer::verbosity_
private