17 #include <boost/foreach.hpp> 93 <<
" Failed to find File = " << inputFileName <<
" !!\n";
95 return std::unique_ptr<TFile>{
new TFile(inputFileName.
fullPath().data()) };
101 const T*
object =
dynamic_cast<T*
>(inputFile.Get(objectName.data()));
103 throw cms::Exception(
"RecoTauDiscriminantCutMultiplexer::loadObjectFromFile")
104 <<
" Failed to load Object = " << objectName.data() <<
" from file = " << inputFile.GetName() <<
" !!\n";
106 return std::unique_ptr<const T>{
static_cast<T*
>(
object->Clone()) };
112 std::cout <<
"<loadTGraphFromDB>:" << std::endl;
113 std::cout <<
" graphName = " << graphName << std::endl;
117 return std::unique_ptr<const TGraph>{
new TGraph(*graphPayload.
product()) };
123 std::cout <<
"<loadTFormulaFromDB>:" << std::endl;
124 std::cout <<
" formulaName = " << formulaName << std::endl;
129 if ( formulaPayload->
formulas().size() == 1 && formulaPayload->
limits().size() == 1 ) {
130 return std::unique_ptr<TFormula> {
new TFormula(newName, formulaPayload->
formulas().at(0).data()) };
132 throw cms::Exception(
"RecoTauDiscriminantCutMultiplexer::loadTFormulaFromDB")
133 <<
"Failed to load TFormula = " << formulaName <<
" from Database !!\n";
135 return std::unique_ptr<TFormula>{};
154 if ( !loadMVAfromDB_ ) {
161 typedef std::vector<edm::ParameterSet>
VPSet;
163 for ( VPSet::const_iterator mappingEntry = mapping.begin();
164 mappingEntry != mapping.end(); ++mappingEntry ) {
165 unsigned category = mappingEntry->getParameter<uint32_t>(
"category");
167 if ( mappingEntry->existsAs<
double>(
"cut") ) {
168 cut->cutValue_ = mappingEntry->getParameter<
double>(
"cut");
170 }
else if ( mappingEntry->existsAs<
std::string>(
"cut") ) {
177 <<
" Undefined Configuration Parameter 'cut' !!\n";
206 for ( DiscriminantCutMap::iterator
cut =
cuts_.begin();
214 cut->second->cutFunction_ = loadObjectFromFile<TGraph>(*
inputFile,
cut->second->cutName_);
217 cut->second->cutFunction_ = loadTGraphFromDB(es,
cut->second->cutName_,
verbosity_);
232 std::cout <<
"<RecoTauDiscriminantCutMultiplexer::discriminate>:" << std::endl;
236 double disc_result = (*toMultiplexHandle_)[
tau];
238 std::cout <<
"disc_result = " << disc_result << std::endl;
245 std::cout <<
"disc_result (normalized) = " << disc_result << std::endl;
248 double key_result = (*keyHandle_)[
tau];
249 DiscriminantCutMap::const_iterator cutIter =
cuts_.find(TMath::Nint(key_result));
253 if ( cutIter ==
cuts_.end() ) {
257 bool passesCuts =
false;
259 passesCuts = (disc_result > cutIter->second->cutValue_);
261 std::cout <<
"cutValue (fixed) = " << cutIter->second->cutValue_ <<
" --> passesCuts = " << passesCuts << std::endl;
264 double cutVariable = (*cutIter->second->cutVariable_)(*tau);
266 cutIter->second->cutFunction_->GetPoint(0, xMin, dummy);
267 cutIter->second->cutFunction_->GetPoint(cutIter->second->cutFunction_->GetN() - 1,
xMax, dummy);
269 if ( cutVariable < (xMin + epsilon) ) cutVariable = xMin + epsilon;
270 else if ( cutVariable > (xMax - epsilon) ) cutVariable = xMax - epsilon;
271 double cutValue = cutIter->second->cutFunction_->Eval(cutVariable);
272 passesCuts = (disc_result > cutValue);
274 std::cout <<
"cutValue (@" << cutVariable <<
") = " << cutValue <<
" --> passesCuts = " << passesCuts << std::endl;
286 desc.
add<
int>(
"verbosity", 0);
293 desc_mapping.
add<
unsigned int>(
"category",0);
298 desc_mapping.
addOptional<
std::string>(
"variable")->setComment(
"the parameter is required when \"cut\" is string");
300 std::vector<edm::ParameterSet> vpsd_mapping;
301 vpsd_mapping.push_back(pset_mapping);
302 desc.
addVPSet(
"mapping",desc_mapping,vpsd_mapping);
306 desc.
add<
bool>(
"loadMVAfromDB",
true);
310 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_