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>{};
154 if(cfg.
exists(
"inputFileName")){
156 }
else throw cms::Exception(
"MVA input not defined") <<
"Requested to load tau MVA input from ROOT file but no file provided in cfg file";
159 if ( cfg.
exists(
"mvaOutput_normalization") ) {
164 typedef std::vector<edm::ParameterSet>
VPSet;
166 for ( VPSet::const_iterator mappingEntry = mapping.begin();
167 mappingEntry != mapping.end(); ++mappingEntry ) {
168 unsigned category = mappingEntry->getParameter<uint32_t>(
"category");
170 if ( mappingEntry->existsAs<
double>(
"cut") ) {
171 cut->cutValue_ = mappingEntry->getParameter<
double>(
"cut");
173 }
else if ( mappingEntry->existsAs<
std::string>(
"cut") ) {
180 <<
" Undefined Configuration Parameter 'cut' !!\n";
185 verbosity_ = ( cfg.
exists(
"verbosity") ) ?
210 for ( DiscriminantCutMap::iterator
cut =
cuts_.begin();
218 cut->second->cutFunction_ = loadObjectFromFile<TGraph>(*
inputFile,
cut->second->cutName_);
221 cut->second->cutFunction_ = loadTGraphFromDB(es,
cut->second->cutName_,
verbosity_);
236 std::cout <<
"<RecoTauDiscriminantCutMultiplexer::discriminate>:" << std::endl;
240 double disc_result = (*toMultiplexHandle_)[
tau];
242 std::cout <<
"disc_result = " << disc_result << std::endl;
249 std::cout <<
"disc_result (normalized) = " << disc_result << std::endl;
252 double key_result = (*keyHandle_)[
tau];
253 DiscriminantCutMap::const_iterator cutIter =
cuts_.find(TMath::Nint(key_result));
257 if ( cutIter ==
cuts_.end() ) {
261 bool passesCuts =
false;
263 passesCuts = (disc_result > cutIter->second->cutValue_);
265 std::cout <<
"cutValue (fixed) = " << cutIter->second->cutValue_ <<
" --> passesCuts = " << passesCuts << std::endl;
268 double cutVariable = (*cutIter->second->cutVariable_)(*tau);
270 cutIter->second->cutFunction_->GetPoint(0, xMin, dummy);
271 cutIter->second->cutFunction_->GetPoint(cutIter->second->cutFunction_->GetN() - 1,
xMax, dummy);
273 if ( cutVariable < (xMin + epsilon) ) cutVariable = xMin + epsilon;
274 else if ( cutVariable > (xMax - epsilon) ) cutVariable = xMax - epsilon;
275 double cutValue = cutIter->second->cutFunction_->Eval(cutVariable);
276 passesCuts = (disc_result > cutValue);
278 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_