19 #include <boost/foreach.hpp> 90 <<
" Failed to find File = " << inputFileName <<
" !!\n";
92 return std::unique_ptr<TFile>{
new TFile(inputFileName.
fullPath().data()) };
98 const T*
object =
dynamic_cast<T*
>(inputFile.Get(objectName.data()));
100 throw cms::Exception(
"PATTauDiscriminantCutMultiplexer::loadObjectFromFile")
101 <<
" Failed to load Object = " << objectName.data() <<
" from file = " << inputFile.GetName() <<
" !!\n";
103 std::unique_ptr<const T>
copy{
static_cast<T*
>(
object->Clone()) };
111 std::cout <<
"<loadTGraphFromDB>:" << std::endl;
112 std::cout <<
" graphName = " << graphName << std::endl;
116 return std::unique_ptr<const TGraph>{
new TGraph(*graphPayload.
product()) };
122 std::cout <<
"<loadTFormulaFromDB>:" << std::endl;
123 std::cout <<
" formulaName = " << formulaName << std::endl;
128 if ( formulaPayload->
formulas().size() == 1 && formulaPayload->
limits().size() == 1 ) {
129 return std::unique_ptr<TFormula> {
new TFormula(newName, formulaPayload->
formulas().at(0).data()) };
131 throw cms::Exception(
"PATTauDiscriminantCutMultiplexer::loadTFormulaFromDB")
132 <<
"Failed to load TFormula = " << formulaName <<
" from Database !!\n";
134 return std::unique_ptr<TFormula>{};
151 if ( !loadMVAfromDB_ ) {
152 if(cfg.
exists(
"inputFileName")){
154 }
else throw cms::Exception(
"MVA input not defined") <<
"Requested to load tau MVA input from ROOT file but no file provided in cfg file";
157 if ( cfg.
exists(
"mvaOutput_normalization") ) {
162 typedef std::vector<edm::ParameterSet>
VPSet;
164 for ( VPSet::const_iterator mappingEntry = mapping.begin();
165 mappingEntry != mapping.end(); ++mappingEntry ) {
166 unsigned category = mappingEntry->getParameter<uint32_t>(
"category");
168 if ( mappingEntry->existsAs<
double>(
"cut") ) {
169 cut->cutValue_ = mappingEntry->getParameter<
double>(
"cut");
171 }
else if ( mappingEntry->existsAs<
std::string>(
"cut") ) {
178 <<
" 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 <<
"<PATTauDiscriminantCutMultiplexer::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;
T getParameter(std::string const &) const
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
#define DEFINE_FWK_MODULE(type)
PATTauDiscriminantCutMultiplexer(const edm::ParameterSet &pset)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::map< int, std::unique_ptr< DiscriminantCutEntry > > DiscriminantCutMap
std::unique_ptr< StringObjectFunction< pat::Tau > > cutVariable_
edm::EDGetTokenT< pat::PATTauDiscriminator > key_token
edm::FileInPath inputFileName_
edm::InputTag toMultiplex_
edm::EDGetTokenT< pat::PATTauDiscriminator > toMultiplex_token
std::unique_ptr< const TGraph > cutFunction_
std::string mvaOutputNormalizationName_
LocationCode location() const
Where was the file found?
edm::Handle< pat::PATTauDiscriminator > toMultiplexHandle_
edm::Handle< pat::PATTauDiscriminator > keyHandle_
double discriminate(const pat::TauRef &) const override
std::string fullPath() const
~PATTauDiscriminantCutMultiplexer() override
T const * product() const
double prediscriminantFailValue_