19 #include <boost/foreach.hpp> 86 throw cms::Exception(
"PATTauDiscriminantCutMultiplexer::loadObjectFromFile")
87 <<
" Failed to find File = " << inputFileName <<
" !!\n";
89 return std::unique_ptr<TFile>{
new TFile(inputFileName.
fullPath().data())};
94 const T*
object =
dynamic_cast<T*
>(inputFile.Get(objectName.data()));
96 throw cms::Exception(
"PATTauDiscriminantCutMultiplexer::loadObjectFromFile")
97 <<
" Failed to load Object = " << objectName.data() <<
" from file = " << inputFile.GetName() <<
" !!\n";
99 return std::unique_ptr<const T>{
static_cast<T*
>(
object->Clone())};
102 std::unique_ptr<const TGraph> loadTGraphFromDB(
const edm::EventSetup& es,
106 std::cout <<
"<loadTGraphFromDB>:" << std::endl;
107 std::cout <<
" graphName = " << graphName << std::endl;
111 return std::unique_ptr<const TGraph>{
new TGraph(*graphPayload.
product())};
114 std::unique_ptr<TFormula> loadTFormulaFromDB(
const edm::EventSetup& es,
119 std::cout <<
"<loadTFormulaFromDB>:" << std::endl;
120 std::cout <<
" formulaName = " << formulaName << std::endl;
125 if (formulaPayload->
formulas().size() == 1 && formulaPayload->
limits().size() == 1) {
126 return std::unique_ptr<TFormula>{
new TFormula(newName, formulaPayload->
formulas().at(0).data())};
128 throw cms::Exception(
"PATTauDiscriminantCutMultiplexer::loadTFormulaFromDB")
129 <<
"Failed to load TFormula = " << formulaName <<
" from Database !!\n";
131 return std::unique_ptr<TFormula>{};
147 if (!loadMVAfromDB_) {
153 "mvaOutput_normalization");
156 typedef std::vector<edm::ParameterSet>
VPSet;
158 for (VPSet::const_iterator mappingEntry = mapping.begin(); mappingEntry != mapping.end(); ++mappingEntry) {
159 unsigned category = mappingEntry->getParameter<uint32_t>(
"category");
161 if (mappingEntry->existsAs<
double>(
"cut")) {
162 cut->cutValue_ = mappingEntry->getParameter<
double>(
"cut");
164 }
else if (mappingEntry->existsAs<
std::string>(
"cut")) {
170 throw cms::Exception(
"PATTauDiscriminantCutMultiplexer") <<
" Undefined Configuration Parameter 'cut' !!\n";
193 auto temp = loadTFormulaFromDB(
206 cut->second->cutFunction_ = loadObjectFromFile<TGraph>(*
inputFile,
cut->second->cutName_);
209 std::cout <<
"Loading from DB" << std::endl;
210 cut->second->cutFunction_ = loadTGraphFromDB(es,
cut->second->cutName_,
verbosity_);
223 std::cout <<
"<PATTauDiscriminantCutMultiplexer::discriminate>:" << std::endl;
227 double disc_result = (*toMultiplexHandle_)[
tau];
229 std::cout <<
"disc_result = " << disc_result << std::endl;
236 std::cout <<
"disc_result (normalized) = " << disc_result << std::endl;
239 double key_result = (*keyHandle_)[
tau];
240 DiscriminantCutMap::const_iterator cutIter =
cuts_.find(TMath::Nint(key_result));
243 if (cutIter ==
cuts_.end()) {
247 bool passesCuts =
false;
249 passesCuts = (disc_result > cutIter->second->cutValue_);
251 std::cout <<
"cutValue (fixed) = " << cutIter->second->cutValue_ <<
" --> passesCuts = " << passesCuts
255 double cutVariable = (*cutIter->second->cutVariable_)(*tau);
257 cutIter->second->cutFunction_->GetPoint(0, xMin, dummy);
258 cutIter->second->cutFunction_->GetPoint(cutIter->second->cutFunction_->GetN() - 1,
xMax, dummy);
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);
267 std::cout <<
"cutValue (@" << cutVariable <<
") = " << cutValue <<
" --> passesCuts = " << passesCuts
280 desc.
add<
int>(
"verbosity", 0);
283 desc_mapping.
add<
unsigned int>(
"category");
286 std::vector<edm::ParameterSet> vpsd_mapping;
290 vpsd_mapping.push_back(psd1);
294 vpsd_mapping.push_back(psd2);
295 desc.
addVPSet(
"mapping", desc_mapping, vpsd_mapping);
298 desc.
add<
bool>(
"loadMVAfromDB",
true);
302 descriptions.
add(
"patTauDiscriminantCutMultiplexer", desc);
T getParameter(std::string const &) const
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
std::unique_ptr< const TFormula > mvaOutput_normalization_
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void setAllowAnything()
allow any parameter label/value pairs
PATTauDiscriminantCutMultiplexer(const edm::ParameterSet &pset)
std::map< int, std::unique_ptr< DiscriminantCutEntry > > DiscriminantCutMap
std::unique_ptr< StringObjectFunction< pat::Tau > > cutVariable_
edm::EDGetTokenT< pat::PATTauDiscriminator > key_token
edm::FileInPath inputFileName_
#define DEFINE_FWK_MODULE(type)
static void fillProducerDescriptions(edm::ParameterSetDescription &desc)
edm::InputTag toMultiplex_
edm::EDGetTokenT< pat::PATTauDiscriminator > toMultiplex_token
void addParameter(std::string const &name, T const &value)
std::unique_ptr< const TGraph > cutFunction_
std::string mvaOutputNormalizationName_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
LocationCode location() const
Where was the file found?
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::Handle< pat::PATTauDiscriminator > toMultiplexHandle_
edm::Handle< pat::PATTauDiscriminator > keyHandle_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double discriminate(const pat::TauRef &) const override
std::string fullPath() const
~PATTauDiscriminantCutMultiplexer() override
T const * product() const
double prediscriminantFailValue_