CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static 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 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< 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 39 of file PATTauDiscriminantCutMultiplexer.cc.

Member Typedef Documentation

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

Definition at line 65 of file PATTauDiscriminantCutMultiplexer.cc.

Constructor & Destructor Documentation

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

Definition at line 135 of file PATTauDiscriminantCutMultiplexer.cc.

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

137  moduleLabel_(cfg.getParameter<std::string>("@module_label")),
139  isInitialized_(false) {
140  toMultiplex_ = cfg.getParameter<edm::InputTag>("toMultiplex");
141  toMultiplex_token = consumes<pat::PATTauDiscriminator>(toMultiplex_);
142  key_ = cfg.getParameter<edm::InputTag>("key");
143  key_token = consumes<pat::PATTauDiscriminator>(key_);
144 
145  verbosity_ = cfg.getParameter<int>("verbosity");
146  loadMVAfromDB_ = cfg.getParameter<bool>("loadMVAfromDB");
147  if (!loadMVAfromDB_) {
148  inputFileName_ = cfg.getParameter<edm::FileInPath>("inputFileName");
149  }
150  if (verbosity_)
151  std::cout << moduleLabel_ << " loadMVA = " << loadMVAfromDB_ << std::endl;
153  "mvaOutput_normalization"); // default value is "" which should just overwrite existing value with same empty string
154 
155  // Setup our cut map
156  typedef std::vector<edm::ParameterSet> VPSet;
157  VPSet mapping = cfg.getParameter<VPSet>("mapping");
158  for (VPSet::const_iterator mappingEntry = mapping.begin(); mappingEntry != mapping.end(); ++mappingEntry) {
159  unsigned category = mappingEntry->getParameter<uint32_t>("category");
160  std::unique_ptr<DiscriminantCutEntry> cut{new DiscriminantCutEntry()};
161  if (mappingEntry->existsAs<double>("cut")) {
162  cut->cutValue_ = mappingEntry->getParameter<double>("cut");
164  } else if (mappingEntry->existsAs<std::string>("cut")) {
165  cut->cutName_ = mappingEntry->getParameter<std::string>("cut");
166  std::string cutVariable_string = mappingEntry->getParameter<std::string>("variable");
167  cut->cutVariable_.reset(new StringObjectFunction<pat::Tau>(cutVariable_string));
169  } else {
170  throw cms::Exception("PATTauDiscriminantCutMultiplexer") << " Undefined Configuration Parameter 'cut' !!\n";
171  }
173  }
174  verbosity_ = cfg.getParameter<int>("verbosity");
175  if (verbosity_)
176  std::cout << "constructed " << moduleLabel_ << std::endl;
177 }
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:511
PATTauDiscriminantCutMultiplexer::~PATTauDiscriminantCutMultiplexer ( )
override

Definition at line 179 of file PATTauDiscriminantCutMultiplexer.cc.

179 {}

Member Function Documentation

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

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 181 of file PATTauDiscriminantCutMultiplexer.cc.

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

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

Implements TauDiscriminationProducerBase< TauType, TauDiscriminator >.

Definition at line 221 of file PATTauDiscriminantCutMultiplexer.cc.

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

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

Definition at line 276 of file PATTauDiscriminantCutMultiplexer.cc.

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

276  {
277  // patTauDiscriminantCutMultiplexer
279  desc.add<edm::InputTag>("toMultiplex", edm::InputTag("fixme"));
280  desc.add<int>("verbosity", 0);
281  {
282  edm::ParameterSetDescription desc_mapping;
283  desc_mapping.add<unsigned int>("category");
284  desc_mapping.setAllowAnything(); //option cut can be double or (string plus additional option variable)
285 
286  std::vector<edm::ParameterSet> vpsd_mapping;
287  edm::ParameterSet psd1;
288  psd1.addParameter<unsigned int>("category", 0);
289  psd1.addParameter<double>("cut", 0.5);
290  vpsd_mapping.push_back(psd1);
291  edm::ParameterSet psd2;
292  psd2.addParameter<unsigned int>("category", 1);
293  psd2.addParameter<double>("cut", 0.2);
294  vpsd_mapping.push_back(psd2);
295  desc.addVPSet("mapping", desc_mapping, vpsd_mapping);
296  }
297  desc.add<edm::FileInPath>("inputFileName", edm::FileInPath("RecoTauTag/RecoTau/data/emptyMVAinputFile"));
298  desc.add<bool>("loadMVAfromDB", true);
299  fillProducerDescriptions(desc); // inherited from the base
300  desc.add<std::string>("mvaOutput_normalization", "");
301  desc.add<edm::InputTag>("key", edm::InputTag("fixme"));
302  descriptions.add("patTauDiscriminantCutMultiplexer", desc);
303 }
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
void setAllowAnything()
allow any parameter label/value pairs
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 PATTauDiscriminantCutMultiplexer::cuts_
private
edm::FileInPath PATTauDiscriminantCutMultiplexer::inputFileName_
private
bool PATTauDiscriminantCutMultiplexer::isInitialized_
private

Definition at line 71 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 76 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 69 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 75 of file PATTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent().

int PATTauDiscriminantCutMultiplexer::verbosity_
private