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>{};
155 if(cfg.
exists(
"inputFileName")){
157 }
else throw cms::Exception(
"MVA input not defined") <<
"Requested to load tau MVA input from ROOT file but no file provided in cfg file";
160 if ( cfg.
exists(
"mvaOutput_normalization") ) {
165 typedef std::vector<edm::ParameterSet>
VPSet;
167 for ( VPSet::const_iterator mappingEntry = mapping.begin();
168 mappingEntry != mapping.end(); ++mappingEntry ) {
169 unsigned category = mappingEntry->getParameter<uint32_t>(
"category");
171 if ( mappingEntry->existsAs<
double>(
"cut") ) {
172 cut->cutValue_ = mappingEntry->getParameter<
double>(
"cut");
174 }
else if ( mappingEntry->existsAs<
std::string>(
"cut") ) {
181 <<
" Undefined Configuration Parameter 'cut' !!\n";
209 for ( DiscriminantCutMap::iterator
cut =
cuts_.begin();
217 cut->second->cutFunction_ = loadObjectFromFile<TGraph>(*
inputFile,
cut->second->cutName_);
220 cut->second->cutFunction_ = loadTGraphFromDB(es,
cut->second->cutName_,
verbosity_);
235 std::cout <<
"<PATTauDiscriminantCutMultiplexer::discriminate>:" << std::endl;
239 double disc_result = (*toMultiplexHandle_)[
tau];
241 std::cout <<
"disc_result = " << disc_result << std::endl;
248 std::cout <<
"disc_result (normalized) = " << disc_result << std::endl;
251 double key_result = (*keyHandle_)[
tau];
252 DiscriminantCutMap::const_iterator cutIter =
cuts_.find(TMath::Nint(key_result));
256 if ( cutIter ==
cuts_.end() ) {
260 bool passesCuts =
false;
262 passesCuts = (disc_result > cutIter->second->cutValue_);
264 std::cout <<
"cutValue (fixed) = " << cutIter->second->cutValue_ <<
" --> passesCuts = " << passesCuts << std::endl;
267 double cutVariable = (*cutIter->second->cutVariable_)(*tau);
269 cutIter->second->cutFunction_->GetPoint(0, xMin, dummy);
270 cutIter->second->cutFunction_->GetPoint(cutIter->second->cutFunction_->GetN() - 1,
xMax, dummy);
272 if ( cutVariable < (xMin + epsilon) ) cutVariable = xMin + epsilon;
273 else if ( cutVariable > (xMax - epsilon) ) cutVariable = xMax - epsilon;
274 double cutValue = cutIter->second->cutFunction_->Eval(cutVariable);
275 passesCuts = (disc_result > cutValue);
277 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_