CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static 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
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator >
static void fillProducerDescriptions (edm::ParameterSetDescription &desc)
 
static std::string getTauTypeString ()
 helper method to retrieve tau type name, e.g. to build correct cfi getter More...
 

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
 
- 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 37 of file RecoTauDiscriminantCutMultiplexer.cc.

Member Typedef Documentation

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

Definition at line 71 of file RecoTauDiscriminantCutMultiplexer.cc.

Constructor & Destructor Documentation

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

Definition at line 139 of file RecoTauDiscriminantCutMultiplexer.cc.

References taus_updatedMVAIds_cff::category, gather_cfg::cout, TkAlMuonSelectors_cfi::cut, cuts_, Exception, 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().

141  moduleLabel_(cfg.getParameter<std::string>("@module_label")),
143  isInitialized_(false)
144 {
145 
146  toMultiplex_ = cfg.getParameter<edm::InputTag>("toMultiplex");
147  toMultiplex_token = consumes<reco::PFTauDiscriminator>(toMultiplex_);
148  key_ = cfg.getParameter<edm::InputTag>("key");
149  key_token = consumes<reco::PFTauDiscriminator>(key_);
150 
151  verbosity_ = cfg.getParameter<int>("verbosity");
152 
153  loadMVAfromDB_ = cfg.getParameter<bool>("loadMVAfromDB");
154  if ( !loadMVAfromDB_ ) {
155  inputFileName_ = cfg.getParameter<edm::FileInPath>("inputFileName");
156  }
157  if(verbosity_) std::cout << moduleLabel_ << " loadMVA = " << loadMVAfromDB_ << std::endl;
158  mvaOutputNormalizationName_ = cfg.getParameter<std::string>("mvaOutput_normalization");
159 
160  // Setup our cut map
161  typedef std::vector<edm::ParameterSet> VPSet;
162  VPSet mapping = cfg.getParameter<VPSet>("mapping");
163  for ( VPSet::const_iterator mappingEntry = mapping.begin();
164  mappingEntry != mapping.end(); ++mappingEntry ) {
165  unsigned category = mappingEntry->getParameter<uint32_t>("category");
166  std::unique_ptr<DiscriminantCutEntry> cut{new DiscriminantCutEntry()};
167  if ( mappingEntry->existsAs<double>("cut") ) {
168  cut->cutValue_ = mappingEntry->getParameter<double>("cut");
170  } else if ( mappingEntry->existsAs<std::string>("cut") ) {
171  cut->cutName_ = mappingEntry->getParameter<std::string>("cut");
172  std::string cutVariable_string = mappingEntry->getParameter<std::string>("variable");
173  cut->cutVariable_.reset( new StringObjectFunction<reco::PFTau>(cutVariable_string) );
175  } else {
176  throw cms::Exception("RecoTauDiscriminantCutMultiplexer")
177  << " Undefined Configuration Parameter 'cut' !!\n";
178  }
180  }
181 
182  verbosity_ = cfg.getParameter<int>("verbosity");
183  if(verbosity_) std::cout << "constructed " << moduleLabel_ << std::endl;
184 }
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:511
RecoTauDiscriminantCutMultiplexer::~RecoTauDiscriminantCutMultiplexer ( )
override

Definition at line 186 of file RecoTauDiscriminantCutMultiplexer.cc.

187 {
188 }

Member Function Documentation

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

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

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

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_.empty() ) {
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_);
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::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:511
double RecoTauDiscriminantCutMultiplexer::discriminate ( const reco::PFTauRef tau) const
override

Definition at line 229 of file RecoTauDiscriminantCutMultiplexer.cc.

References gather_cfg::cout, cuts_, 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.

230 {
231  if ( verbosity_ ) {
232  std::cout << "<RecoTauDiscriminantCutMultiplexer::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_
void RecoTauDiscriminantCutMultiplexer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 282 of file RecoTauDiscriminantCutMultiplexer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addNode(), edm::ParameterSetDescription::addOptional(), edm::ParameterSet::addParameter(), edm::ParameterSetDescription::addVPSet(), DEFINE_FWK_MODULE, TauDiscriminationProducerBase< TauType, TauDiscriminator >::fillProducerDescriptions(), and AlCaHLTBitMon_QueryRunRegistry::string.

282  {
283  // recoTauDiscriminantCutMultiplexer
285  desc.add<edm::InputTag>("toMultiplex", edm::InputTag("fixme"));
286  desc.add<int>("verbosity", 0);
287 
288  {
289  edm::ParameterSet pset_mapping;
290  pset_mapping.addParameter<unsigned int>("category",0);
291  pset_mapping.addParameter<double>("cut",0.);
292  edm::ParameterSetDescription desc_mapping;
293  desc_mapping.add<unsigned int>("category",0);
294  desc_mapping.addNode(edm::ParameterDescription<std::string>("cut", true) xor
295  edm::ParameterDescription<double>("cut", true));
296  // it seems the parameter string "variable" exists only when "cut" is string
297  // see hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBdR03oldDMwLT in RecoTauTag/Configuration/python/HPSPFTaus_cff.py
298  desc_mapping.addOptional<std::string>("variable")->setComment("the parameter is required when \"cut\" is string");
299  // desc_mapping.add<double>("cut",0.);
300  std::vector<edm::ParameterSet> vpsd_mapping;
301  vpsd_mapping.push_back(pset_mapping);
302  desc.addVPSet("mapping",desc_mapping,vpsd_mapping);
303  }
304 
305  desc.add<edm::FileInPath>("inputFileName", edm::FileInPath("RecoTauTag/RecoTau/data/emptyMVAinputFile"));
306  desc.add<bool>("loadMVAfromDB", true);
307  fillProducerDescriptions(desc); // inherited from the base
308  desc.add<std::string>("mvaOutput_normalization", "");
309  desc.add<edm::InputTag>("key", edm::InputTag("fixme"));
310  descriptions.add("recoTauDiscriminantCutMultiplexerDefault", desc);
311 }
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
static void fillProducerDescriptions(edm::ParameterSetDescription &desc)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:125
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)

Member Data Documentation

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

Definition at line 77 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 82 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 75 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 81 of file RecoTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent().

int RecoTauDiscriminantCutMultiplexer::verbosity_
private