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

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 72 of file PATTauDiscriminantCutMultiplexer.cc.

Constructor & Destructor Documentation

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

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

142  moduleLabel_(cfg.getParameter<std::string>("@module_label")),
144  isInitialized_(false)
145 {
146 
147  toMultiplex_ = cfg.getParameter<edm::InputTag>("toMultiplex");
148  toMultiplex_token = consumes<pat::PATTauDiscriminator>(toMultiplex_);
149  key_ = cfg.getParameter<edm::InputTag>("key");
150  key_token = consumes<pat::PATTauDiscriminator>(key_);
151 
152  verbosity_ = cfg.getParameter<int>("verbosity");
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"); // default value is "" which should just overwrite existing value with same empty string
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<pat::Tau>(cutVariable_string) );
175  } else {
176  throw cms::Exception("PATTauDiscriminantCutMultiplexer")
177  << " Undefined Configuration Parameter 'cut' !!\n";
178  }
180  }
181  verbosity_ = cfg.getParameter<int>("verbosity");
182  if(verbosity_) std::cout << "constructed " << moduleLabel_ << std::endl;
183 }
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 185 of file PATTauDiscriminantCutMultiplexer.cc.

186 {
187 }

Member Function Documentation

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

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator >.

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

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

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

Definition at line 281 of file PATTauDiscriminantCutMultiplexer.cc.

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

281  {
282  // patTauDiscriminantCutMultiplexer
284  desc.add<edm::InputTag>("toMultiplex", edm::InputTag("fixme"));
285  desc.add<int>("verbosity", 0);
286  {
287  edm::ParameterSetDescription desc_mapping;
288  desc_mapping.add<unsigned int>("category");
289  desc_mapping.setAllowAnything(); //option cut can be double or (string plus additional option variable)
290 
291  std::vector<edm::ParameterSet> vpsd_mapping;
292  edm::ParameterSet psd1;
293  psd1.addParameter<unsigned int>("category", 0);
294  psd1.addParameter<double>("cut", 0.5);
295  vpsd_mapping.push_back(psd1);
296  edm::ParameterSet psd2;
297  psd2.addParameter<unsigned int>("category", 1);
298  psd2.addParameter<double>("cut", 0.2);
299  vpsd_mapping.push_back(psd2);
300  desc.addVPSet("mapping", desc_mapping, vpsd_mapping);
301  }
302  desc.add<edm::FileInPath>("inputFileName", edm::FileInPath("RecoTauTag/RecoTau/data/emptyMVAinputFile"));
303  desc.add<bool>("loadMVAfromDB", true);
304  fillProducerDescriptions(desc); // inherited from the base
305  desc.add<std::string>("mvaOutput_normalization", "");
306  desc.add<edm::InputTag>("key", edm::InputTag("fixme"));
307  descriptions.add("patTauDiscriminantCutMultiplexer", desc);
308 }
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:125
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 78 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 83 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 76 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 82 of file PATTauDiscriminantCutMultiplexer.cc.

Referenced by beginEvent().

int PATTauDiscriminantCutMultiplexer::verbosity_
private