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

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 () override
 
- Public Member Functions inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
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< 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
 
- 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 taus_updatedMVAIds_cff::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_, taus_updatedMVAIds_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  verbosity_ = ( cfg.exists("verbosity") ) ?
151  cfg.getParameter<int>("verbosity") : 0;
152 
153  loadMVAfromDB_ = cfg.exists("loadMVAfromDB") ? cfg.getParameter<bool>("loadMVAfromDB") : false;
154  if ( !loadMVAfromDB_ ) {
155  if(cfg.exists("inputFileName")){
156  inputFileName_ = cfg.getParameter<edm::FileInPath>("inputFileName");
157  }else throw cms::Exception("MVA input not defined") << "Requested to load tau MVA input from ROOT file but no file provided in cfg file";
158  }
159  if(verbosity_) std::cout << moduleLabel_ << " loadMVA = " << loadMVAfromDB_ << std::endl;
160  if ( cfg.exists("mvaOutput_normalization") ) {
161  mvaOutputNormalizationName_ = cfg.getParameter<std::string>("mvaOutput_normalization");
162  }
163 
164  // Setup our cut map
165  typedef std::vector<edm::ParameterSet> VPSet;
166  VPSet mapping = cfg.getParameter<VPSet>("mapping");
167  for ( VPSet::const_iterator mappingEntry = mapping.begin();
168  mappingEntry != mapping.end(); ++mappingEntry ) {
169  unsigned category = mappingEntry->getParameter<uint32_t>("category");
170  std::unique_ptr<DiscriminantCutEntry> cut{new DiscriminantCutEntry()};
171  if ( mappingEntry->existsAs<double>("cut") ) {
172  cut->cutValue_ = mappingEntry->getParameter<double>("cut");
174  } else if ( mappingEntry->existsAs<std::string>("cut") ) {
175  cut->cutName_ = mappingEntry->getParameter<std::string>("cut");
176  std::string cutVariable_string = mappingEntry->getParameter<std::string>("variable");
177  cut->cutVariable_.reset( new StringObjectFunction<pat::Tau>(cutVariable_string) );
179  } else {
180  throw cms::Exception("PATTauDiscriminantCutMultiplexer")
181  << " Undefined Configuration Parameter 'cut' !!\n";
182  }
184  }
185 
186  if(verbosity_) std::cout << "constructed " << moduleLabel_ << std::endl;
187 }
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 ( )
override

Definition at line 189 of file PATTauDiscriminantCutMultiplexer.cc.

190 {
191 }

Member Function Documentation

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

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 193 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_, eostools::move(), mvaOutput_normalization_, mvaOutputNormalizationName_, groupFilesInBlocks::temp, toMultiplex_token, toMultiplexHandle_, and verbosity_.

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

Implements TauDiscriminationProducerBase< TauType, TauDiscriminator >.

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

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