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()) };
109 std::cout <<
"<loadTGraphFromDB>:" << std::endl;
110 std::cout <<
" graphName = " << graphName << std::endl;
114 return std::unique_ptr<const TGraph>{
new TGraph(*graphPayload.
product()) };
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(newName, 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>{};
153 if(cfg.
exists(
"inputFileName")){
155 }
else throw cms::Exception(
"MVA input not defined") <<
"Requested to load tau MVA input from ROOT file but no file provided in cfg file";
158 if ( cfg.
exists(
"mvaOutput_normalization") ) {
163 typedef std::vector<edm::ParameterSet>
VPSet;
165 for ( VPSet::const_iterator mappingEntry = mapping.begin();
166 mappingEntry != mapping.end(); ++mappingEntry ) {
167 unsigned category = mappingEntry->getParameter<uint32_t>(
"category");
169 if ( mappingEntry->existsAs<
double>(
"cut") ) {
170 cut->cutValue_ = mappingEntry->getParameter<
double>(
"cut");
172 }
else if ( mappingEntry->existsAs<
std::string>(
"cut") ) {
179 <<
" Undefined Configuration Parameter 'cut' !!\n";
207 for ( DiscriminantCutMap::iterator
cut =
cuts_.begin();
215 cut->second->cutFunction_ = loadObjectFromFile<TGraph>(*
inputFile,
cut->second->cutName_);
218 cut->second->cutFunction_ = loadTGraphFromDB(es,
cut->second->cutName_,
verbosity_);
233 std::cout <<
"<RecoTauDiscriminantCutMultiplexer::discriminate>:" << std::endl;
237 double disc_result = (*toMultiplexHandle_)[
tau];
239 std::cout <<
"disc_result = " << disc_result << std::endl;
246 std::cout <<
"disc_result (normalized) = " << disc_result << std::endl;
249 double key_result = (*keyHandle_)[
tau];
250 DiscriminantCutMap::const_iterator cutIter =
cuts_.find(TMath::Nint(key_result));
254 if ( cutIter ==
cuts_.end() ) {
258 bool passesCuts =
false;
260 passesCuts = (disc_result > cutIter->second->cutValue_);
262 std::cout <<
"cutValue (fixed) = " << cutIter->second->cutValue_ <<
" --> passesCuts = " << passesCuts << std::endl;
265 double cutVariable = (*cutIter->second->cutVariable_)(*tau);
267 cutIter->second->cutFunction_->GetPoint(0, xMin, dummy);
268 cutIter->second->cutFunction_->GetPoint(cutIter->second->cutFunction_->GetN() - 1,
xMax, dummy);
270 if ( cutVariable < (xMin + epsilon) ) cutVariable = xMin + epsilon;
271 else if ( cutVariable > (xMax - epsilon) ) cutVariable = xMax - epsilon;
272 double cutValue = cutIter->second->cutFunction_->Eval(cutVariable);
273 passesCuts = (disc_result > cutValue);
275 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() override
edm::EDGetTokenT< reco::PFTauDiscriminator > toMultiplex_token
double discriminate(const reco::PFTauRef &) const override
edm::FileInPath inputFileName_
edm::EDGetTokenT< reco::PFTauDiscriminator > key_token
LocationCode location() const
Where was the file found?
std::unique_ptr< const TGraph > cutFunction_
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_