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 hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () 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)
 

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

Constructor & Destructor Documentation

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

Definition at line 133 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().

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

178 {}

Member Function Documentation

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

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 180 of file RecoTauDiscriminantCutMultiplexer.cc.

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

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

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

Definition at line 275 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(), HLT_2018_cff::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

275  {
276  // recoTauDiscriminantCutMultiplexer
278  desc.add<edm::InputTag>("toMultiplex", edm::InputTag("fixme"));
279  desc.add<int>("verbosity", 0);
280 
281  {
282  edm::ParameterSet pset_mapping;
283  pset_mapping.addParameter<unsigned int>("category", 0);
284  pset_mapping.addParameter<double>("cut", 0.);
285  edm::ParameterSetDescription desc_mapping;
286  desc_mapping.add<unsigned int>("category", 0);
287  desc_mapping.addNode(edm::ParameterDescription<std::string>("cut", true) xor
288  edm::ParameterDescription<double>("cut", true));
289  // it seems the parameter string "variable" exists only when "cut" is string
290  // see hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBdR03oldDMwLT in RecoTauTag/Configuration/python/HPSPFTaus_cff.py
291  desc_mapping.addOptional<std::string>("variable")->setComment("the parameter is required when \"cut\" is string");
292  // desc_mapping.add<double>("cut",0.);
293  std::vector<edm::ParameterSet> vpsd_mapping;
294  vpsd_mapping.push_back(pset_mapping);
295  desc.addVPSet("mapping", desc_mapping, vpsd_mapping);
296  }
297 
298  desc.add<edm::FileInPath>("inputFileName", edm::FileInPath("RecoTauTag/RecoTau/data/emptyMVAinputFile"));
299  desc.add<bool>("loadMVAfromDB", true);
300  fillProducerDescriptions(desc); // inherited from the base
301  desc.add<std::string>("mvaOutput_normalization", "");
302  desc.add<edm::InputTag>("key", edm::InputTag("fixme"));
303  descriptions.add("recoTauDiscriminantCutMultiplexerDefault", desc);
304 }
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:124
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 69 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 74 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 67 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 73 of file RecoTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent().

int RecoTauDiscriminantCutMultiplexer::verbosity_
private