17 #include <boost/foreach.hpp>
88 <<
" Failed to find File = " << inputFileName <<
" !!\n";
90 return std::unique_ptr<TFile>{
new TFile(inputFileName.
fullPath().data()) };
96 const T*
object =
dynamic_cast<T*
>(inputFile.Get(objectName.data()));
98 throw cms::Exception(
"RecoTauDiscriminantCutMultiplexer::loadObjectFromFile")
99 <<
" Failed to load Object = " << objectName.data() <<
" from file = " << inputFile.GetName() <<
" !!\n";
101 std::unique_ptr<const T>
copy{
static_cast<T*
>(
object->Clone()) };
103 return std::move(
copy);
106 std::unique_ptr<const TGraph> loadTGraphFromDB(
const edm::EventSetup& es,
const std::string& graphName,
const int& verbosity_ = 0)
109 std::cout <<
"<loadTGraphFromDB>:" << std::endl;
110 std::cout <<
" graphName = " << graphName << std::endl;
114 return std::unique_ptr<const TGraph>{
new TGraph(*graphPayload.
product()) };
117 std::unique_ptr<TFormula> loadTFormulaFromDB(
const edm::EventSetup& es,
const std::string& formulaName,
const int& verbosity_ = 0)
120 std::cout <<
"<loadTFormulaFromDB>:" << std::endl;
121 std::cout <<
" formulaName = " << formulaName << std::endl;
126 if ( formulaPayload->formulas().size() == 1 && formulaPayload->limits().size() == 1 ) {
127 return std::unique_ptr<TFormula> {
new TFormula(
"mvaNormalizationFormula", formulaPayload->formulas().at(0).data()) };
129 throw cms::Exception(
"RecoTauDiscriminantCutMultiplexer::loadTFormulaFromDB")
130 <<
"Failed to load TFormula = " << formulaName <<
" from Database !!\n";
132 return std::unique_ptr<TFormula>{};
139 mvaOutput_normalization_(),
140 isInitialized_(
false)
157 if ( cfg.
exists(
"mvaOutput_normalization") ) {
162 typedef std::vector<edm::ParameterSet> VPSet;
164 for ( VPSet::const_iterator mappingEntry = mapping.begin();
165 mappingEntry != mapping.end(); ++mappingEntry ) {
166 unsigned category = mappingEntry->getParameter<uint32_t>(
"category");
168 if ( mappingEntry->existsAs<
double>(
"cut") ) {
169 cut->cutValue_ = mappingEntry->getParameter<
double>(
"cut");
171 }
else if ( mappingEntry->existsAs<
std::string>(
"cut") ) {
178 <<
" Undefined Configuration Parameter 'cut' !!\n";
183 verbosity_ = ( cfg.
exists(
"verbosity") ) ?
209 for ( DiscriminantCutMap::iterator
cut =
cuts_.begin();
217 cut->second->cutFunction_ = loadObjectFromFile<TGraph>(*
inputFile,
cut->second->cutName_);
220 cut->second->cutFunction_ = loadTGraphFromDB(es,
cut->second->cutName_,
verbosity_);
235 std::cout <<
"<RecoTauDiscriminantCutMultiplexer::discriminate>:" << std::endl;
239 double disc_result = (*toMultiplexHandle_)[
tau];
241 std::cout <<
"disc_result = " << disc_result << std::endl;
248 std::cout <<
"disc_result (normalized) = " << disc_result << std::endl;
251 double key_result = (*keyHandle_)[
tau];
252 DiscriminantCutMap::const_iterator cutIter =
cuts_.find(TMath::Nint(key_result));
256 if ( cutIter ==
cuts_.end() ) {
260 bool passesCuts =
false;
262 passesCuts = (disc_result > cutIter->second->cutValue_);
264 std::cout <<
"cutValue (fixed) = " << cutIter->second->cutValue_ <<
" --> passesCuts = " << passesCuts << std::endl;
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);
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);
277 std::cout <<
"cutValue (@" << cutVariable <<
") = " << cutValue <<
" --> passesCuts = " << passesCuts << std::endl;
T getParameter(std::string const &) const
std::unique_ptr< const TFormula > mvaOutput_normalization_
std::string mvaOutputNormalizationName_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::Handle< reco::PFTauDiscriminator > keyHandle_
#define DEFINE_FWK_MODULE(type)
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
edm::Handle< reco::PFTauDiscriminator > toMultiplexHandle_
std::unique_ptr< StringObjectFunction< reco::PFTau > > cutVariable_
~RecoTauDiscriminantCutMultiplexer()
double discriminate(const reco::PFTauRef &) const override
edm::EDGetTokenT< reco::PFTauDiscriminator > toMultiplex_token
edm::FileInPath inputFileName_
edm::EDGetTokenT< reco::PFTauDiscriminator > key_token
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::unique_ptr< const TGraph > cutFunction_
LocationCode location() const
Where was the file found?
T const * product() const
edm::InputTag toMultiplex_
RecoTauDiscriminantCutMultiplexer(const edm::ParameterSet &pset)
volatile std::atomic< bool > shutdown_flag false
std::string fullPath() const
std::map< int, std::unique_ptr< DiscriminantCutEntry > > DiscriminantCutMap
double prediscriminantFailValue_