19 #include <boost/foreach.hpp> 94 <<
" Failed to find File = " << inputFileName <<
" !!\n";
96 return std::unique_ptr<TFile>{
new TFile(inputFileName.
fullPath().data()) };
102 const T*
object =
dynamic_cast<T*
>(inputFile.Get(objectName.data()));
104 throw cms::Exception(
"PATTauDiscriminantCutMultiplexer::loadObjectFromFile")
105 <<
" Failed to load Object = " << objectName.data() <<
" from file = " << inputFile.GetName() <<
" !!\n";
107 return std::unique_ptr<const T>{
static_cast<T*
>(
object->Clone()) };
113 std::cout <<
"<loadTGraphFromDB>:" << std::endl;
114 std::cout <<
" graphName = " << graphName << std::endl;
118 return std::unique_ptr<const TGraph>{
new TGraph(*graphPayload.
product()) };
124 std::cout <<
"<loadTFormulaFromDB>:" << std::endl;
125 std::cout <<
" formulaName = " << formulaName << std::endl;
130 if ( formulaPayload->
formulas().size() == 1 && formulaPayload->
limits().size() == 1 ) {
131 return std::unique_ptr<TFormula> {
new TFormula(newName, formulaPayload->
formulas().at(0).data()) };
133 throw cms::Exception(
"PATTauDiscriminantCutMultiplexer::loadTFormulaFromDB")
134 <<
"Failed to load TFormula = " << formulaName <<
" from Database !!\n";
136 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";
205 for ( DiscriminantCutMap::iterator
cut =
cuts_.begin();
213 cut->second->cutFunction_ = loadObjectFromFile<TGraph>(*
inputFile,
cut->second->cutName_);
216 cut->second->cutFunction_ = loadTGraphFromDB(es,
cut->second->cutName_,
verbosity_);
231 std::cout <<
"<PATTauDiscriminantCutMultiplexer::discriminate>:" << std::endl;
235 double disc_result = (*toMultiplexHandle_)[
tau];
237 std::cout <<
"disc_result = " << disc_result << std::endl;
244 std::cout <<
"disc_result (normalized) = " << disc_result << std::endl;
247 double key_result = (*keyHandle_)[
tau];
248 DiscriminantCutMap::const_iterator cutIter =
cuts_.find(TMath::Nint(key_result));
252 if ( cutIter ==
cuts_.end() ) {
256 bool passesCuts =
false;
258 passesCuts = (disc_result > cutIter->second->cutValue_);
260 std::cout <<
"cutValue (fixed) = " << cutIter->second->cutValue_ <<
" --> passesCuts = " << passesCuts << std::endl;
263 double cutVariable = (*cutIter->second->cutVariable_)(*tau);
265 cutIter->second->cutFunction_->GetPoint(0, xMin, dummy);
266 cutIter->second->cutFunction_->GetPoint(cutIter->second->cutFunction_->GetN() - 1,
xMax, dummy);
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);
273 std::cout <<
"cutValue (@" << cutVariable <<
") = " << cutValue <<
" --> passesCuts = " << passesCuts << std::endl;
285 desc.
add<
int>(
"verbosity", 0);
288 desc_mapping.
add<
unsigned int>(
"category");
291 std::vector<edm::ParameterSet> vpsd_mapping;
295 vpsd_mapping.push_back(psd1);
299 vpsd_mapping.push_back(psd2);
300 desc.
addVPSet(
"mapping", desc_mapping, vpsd_mapping);
303 desc.
add<
bool>(
"loadMVAfromDB",
true);
307 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_