17 #include <boost/foreach.hpp> 84 throw cms::Exception(
"RecoTauDiscriminantCutMultiplexer::loadObjectFromFile")
85 <<
" Failed to find File = " << inputFileName <<
" !!\n";
87 return std::unique_ptr<TFile>{
new TFile(inputFileName.
fullPath().data())};
92 const T*
object =
dynamic_cast<T*
>(inputFile.Get(objectName.data()));
94 throw cms::Exception(
"RecoTauDiscriminantCutMultiplexer::loadObjectFromFile")
95 <<
" Failed to load Object = " << objectName.data() <<
" from file = " << inputFile.GetName() <<
" !!\n";
97 return std::unique_ptr<const T>{
static_cast<T*
>(
object->Clone())};
100 std::unique_ptr<const TGraph> loadTGraphFromDB(
const edm::EventSetup& es,
104 std::cout <<
"<loadTGraphFromDB>:" << std::endl;
105 std::cout <<
" graphName = " << graphName << std::endl;
109 return std::unique_ptr<const TGraph>{
new TGraph(*graphPayload.
product())};
112 std::unique_ptr<TFormula> loadTFormulaFromDB(
const edm::EventSetup& es,
117 std::cout <<
"<loadTFormulaFromDB>:" << std::endl;
118 std::cout <<
" formulaName = " << formulaName << std::endl;
123 if (formulaPayload->
formulas().size() == 1 && formulaPayload->
limits().size() == 1) {
124 return std::unique_ptr<TFormula>{
new TFormula(newName, formulaPayload->
formulas().at(0).data())};
126 throw cms::Exception(
"RecoTauDiscriminantCutMultiplexer::loadTFormulaFromDB")
127 <<
"Failed to load TFormula = " << formulaName <<
" from Database !!\n";
129 return std::unique_ptr<TFormula>{};
146 if (!loadMVAfromDB_) {
154 typedef std::vector<edm::ParameterSet>
VPSet;
156 for (VPSet::const_iterator mappingEntry = mapping.begin(); mappingEntry != mapping.end(); ++mappingEntry) {
157 unsigned category = mappingEntry->getParameter<uint32_t>(
"category");
159 if (mappingEntry->existsAs<
double>(
"cut")) {
160 cut->cutValue_ = mappingEntry->getParameter<
double>(
"cut");
162 }
else if (mappingEntry->existsAs<
std::string>(
"cut")) {
168 throw cms::Exception(
"RecoTauDiscriminantCutMultiplexer") <<
" Undefined Configuration Parameter 'cut' !!\n";
192 auto temp = loadTFormulaFromDB(
205 cut->second->cutFunction_ = loadObjectFromFile<TGraph>(*
inputFile,
cut->second->cutName_);
208 std::cout <<
"Loading from DB" << std::endl;
209 cut->second->cutFunction_ = loadTGraphFromDB(es,
cut->second->cutName_,
verbosity_);
222 std::cout <<
"<RecoTauDiscriminantCutMultiplexer::discriminate>:" << std::endl;
226 double disc_result = (*toMultiplexHandle_)[
tau];
228 std::cout <<
"disc_result = " << disc_result << std::endl;
235 std::cout <<
"disc_result (normalized) = " << disc_result << std::endl;
238 double key_result = (*keyHandle_)[
tau];
239 DiscriminantCutMap::const_iterator cutIter =
cuts_.find(TMath::Nint(key_result));
242 if (cutIter ==
cuts_.end()) {
246 bool passesCuts =
false;
248 passesCuts = (disc_result > cutIter->second->cutValue_);
250 std::cout <<
"cutValue (fixed) = " << cutIter->second->cutValue_ <<
" --> passesCuts = " << passesCuts
254 double cutVariable = (*cutIter->second->cutVariable_)(*tau);
256 cutIter->second->cutFunction_->GetPoint(0, xMin, dummy);
257 cutIter->second->cutFunction_->GetPoint(cutIter->second->cutFunction_->GetN() - 1,
xMax, dummy);
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);
266 std::cout <<
"cutValue (@" << cutVariable <<
") = " << cutValue <<
" --> passesCuts = " << passesCuts
279 desc.
add<
int>(
"verbosity", 0);
286 desc_mapping.
add<
unsigned int>(
"category", 0);
291 desc_mapping.
addOptional<
std::string>(
"variable")->setComment(
"the parameter is required when \"cut\" is string");
293 std::vector<edm::ParameterSet> vpsd_mapping;
294 vpsd_mapping.push_back(pset_mapping);
295 desc.
addVPSet(
"mapping", desc_mapping, vpsd_mapping);
299 desc.
add<
bool>(
"loadMVAfromDB",
true);
303 descriptions.
add(
"recoTauDiscriminantCutMultiplexerDefault", desc);
T getParameter(std::string const &) const
std::unique_ptr< const TFormula > mvaOutput_normalization_
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
std::string mvaOutputNormalizationName_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::Handle< reco::PFTauDiscriminator > keyHandle_
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) override
edm::Handle< reco::PFTauDiscriminator > toMultiplexHandle_
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
std::unique_ptr< StringObjectFunction< reco::PFTau > > cutVariable_
~RecoTauDiscriminantCutMultiplexer() override
#define DEFINE_FWK_MODULE(type)
static void fillProducerDescriptions(edm::ParameterSetDescription &desc)
edm::EDGetTokenT< reco::PFTauDiscriminator > toMultiplex_token
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double discriminate(const reco::PFTauRef &) const override
void addParameter(std::string const &name, T const &value)
edm::FileInPath inputFileName_
edm::EDGetTokenT< reco::PFTauDiscriminator > key_token
LocationCode location() const
Where was the file found?
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::unique_ptr< const TGraph > cutFunction_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::InputTag toMultiplex_
RecoTauDiscriminantCutMultiplexer(const edm::ParameterSet &pset)
std::string fullPath() const
std::map< int, std::unique_ptr< DiscriminantCutEntry > > DiscriminantCutMap
T const * product() const
double prediscriminantFailValue_