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<>

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
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

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
 
- Static Public Member Functions inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
static std::string getTauTypeString ()
 helper method to retrieve tau type name, e.g. to build correct cfi getter More...
 
- 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 taus_updatedMVAIds_cff::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_, taus_updatedMVAIds_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  loadMVAfromDB_ = cfg.exists("loadMVAfromDB") ? cfg.getParameter<bool>("loadMVAfromDB") : false;
152  if ( !loadMVAfromDB_ ) {
153  if(cfg.exists("inputFileName")){
154  inputFileName_ = cfg.getParameter<edm::FileInPath>("inputFileName");
155  }else throw cms::Exception("MVA input not defined") << "Requested to load tau MVA input from ROOT file but no file provided in cfg file";
156  }
157  if(verbosity_) std::cout << moduleLabel_ << " loadMVA = " << loadMVAfromDB_ << std::endl;
158  if ( cfg.exists("mvaOutput_normalization") ) {
159  mvaOutputNormalizationName_ = cfg.getParameter<std::string>("mvaOutput_normalization");
160  }
161 
162  // Setup our cut map
163  typedef std::vector<edm::ParameterSet> VPSet;
164  VPSet mapping = cfg.getParameter<VPSet>("mapping");
165  for ( VPSet::const_iterator mappingEntry = mapping.begin();
166  mappingEntry != mapping.end(); ++mappingEntry ) {
167  unsigned category = mappingEntry->getParameter<uint32_t>("category");
168  std::unique_ptr<DiscriminantCutEntry> cut{new DiscriminantCutEntry()};
169  if ( mappingEntry->existsAs<double>("cut") ) {
170  cut->cutValue_ = mappingEntry->getParameter<double>("cut");
172  } else if ( mappingEntry->existsAs<std::string>("cut") ) {
173  cut->cutName_ = mappingEntry->getParameter<std::string>("cut");
174  std::string cutVariable_string = mappingEntry->getParameter<std::string>("variable");
175  cut->cutVariable_.reset( new StringObjectFunction<reco::PFTau>(cutVariable_string) );
177  } else {
178  throw cms::Exception("RecoTauDiscriminantCutMultiplexer")
179  << " Undefined Configuration Parameter 'cut' !!\n";
180  }
182  }
183 
184  if(verbosity_) std::cout << "constructed " << moduleLabel_ << std::endl;
185 }
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 187 of file RecoTauDiscriminantCutMultiplexer.cc.

188 {
189 }

Member Function Documentation

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

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 191 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_.

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

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