CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Attributes
PATTauDiscriminantCutMultiplexer Class Reference
Inheritance diagram for PATTauDiscriminantCutMultiplexer:
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 pat::TauRef &) const override
 
 PATTauDiscriminantCutMultiplexer (const edm::ParameterSet &pset)
 
 ~PATTauDiscriminantCutMultiplexer ()
 
- Public Member Functions inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
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::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- 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 ()
 
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, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 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
 
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< pat::PATTauDiscriminatorkey_token
 
edm::Handle< pat::PATTauDiscriminatorkeyHandle_
 
bool loadMVAfromDB_
 
std::string moduleLabel_
 
std::unique_ptr< const TFormula > mvaOutput_normalization_
 
std::string mvaOutputNormalizationName_
 
edm::InputTag toMultiplex_
 
edm::EDGetTokenT< pat::PATTauDiscriminatortoMultiplex_token
 
edm::Handle< pat::PATTauDiscriminatortoMultiplexHandle_
 
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
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 36 of file PATTauDiscriminantCutMultiplexer.cc.

Member Typedef Documentation

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

Definition at line 68 of file PATTauDiscriminantCutMultiplexer.cc.

Constructor & Destructor Documentation

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

Definition at line 138 of file PATTauDiscriminantCutMultiplexer.cc.

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

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

Definition at line 186 of file PATTauDiscriminantCutMultiplexer.cc.

187 {
188 }

Member Function Documentation

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

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 190 of file PATTauDiscriminantCutMultiplexer.cc.

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

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

Implements TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 229 of file PATTauDiscriminantCutMultiplexer.cc.

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

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

Member Data Documentation

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

Definition at line 74 of file PATTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent().

edm::InputTag PATTauDiscriminantCutMultiplexer::key_
private
edm::EDGetTokenT<pat::PATTauDiscriminator> PATTauDiscriminantCutMultiplexer::key_token
private
edm::Handle<pat::PATTauDiscriminator> PATTauDiscriminantCutMultiplexer::keyHandle_
private

Definition at line 79 of file PATTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent().

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

Definition at line 72 of file PATTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent(), and discriminate().

std::string PATTauDiscriminantCutMultiplexer::mvaOutputNormalizationName_
private
edm::InputTag PATTauDiscriminantCutMultiplexer::toMultiplex_
private
edm::EDGetTokenT<pat::PATTauDiscriminator> PATTauDiscriminantCutMultiplexer::toMultiplex_token
private
edm::Handle<pat::PATTauDiscriminator> PATTauDiscriminantCutMultiplexer::toMultiplexHandle_
private

Definition at line 78 of file PATTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent().

int PATTauDiscriminantCutMultiplexer::verbosity_
private