File indexing completed on 2024-04-06 12:23:58
0001 #include <map>
0002 #include <Math/Functions.h>
0003
0004 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0005 #include "PhysicsTools/PatAlgos/interface/StringResolutionProvider.h"
0006 #include "DataFormats/PatCandidates/interface/ParametrizationHelper.h"
0007
0008 StringResolutionProvider::StringResolutionProvider(const edm::ParameterSet& cfg) : constraints_() {
0009 typedef pat::CandKinResolution::Parametrization Parametrization;
0010
0011
0012 std::vector<double> constr = cfg.getParameter<std::vector<double> >("constraints");
0013 constraints_.insert(constraints_.end(), constr.begin(), constr.end());
0014
0015 std::string parametrization(cfg.getParameter<std::string>("parametrization"));
0016 parametrization_ = pat::helper::ParametrizationHelper::fromString(parametrization);
0017
0018 std::vector<edm::ParameterSet> functionSets_ = cfg.getParameter<std::vector<edm::ParameterSet> >("functions");
0019 for (std::vector<edm::ParameterSet>::const_iterator iSet = functionSets_.begin(); iSet != functionSets_.end();
0020 ++iSet) {
0021 if (iSet->exists("bin"))
0022 bins_.push_back(iSet->getParameter<std::string>("bin"));
0023 else if (functionSets_.size() == 1)
0024 bins_.push_back("");
0025 else
0026 throw cms::Exception("WrongConfig") << "Parameter 'bin' is needed if more than one PSet is specified\n";
0027
0028 funcEt_.push_back(iSet->getParameter<std::string>("et"));
0029 funcEta_.push_back(iSet->getParameter<std::string>("eta"));
0030 funcPhi_.push_back(iSet->getParameter<std::string>("phi"));
0031 }
0032 }
0033
0034 StringResolutionProvider::~StringResolutionProvider() {}
0035
0036 pat::CandKinResolution StringResolutionProvider::getResolution(const reco::Candidate& cand) const {
0037 int selectedBin = -1;
0038 for (unsigned int i = 0; i < bins_.size(); ++i) {
0039 StringCutObjectSelector<reco::Candidate> select_(bins_[i]);
0040 if (select_(cand)) {
0041 selectedBin = i;
0042 break;
0043 }
0044 }
0045 std::vector<pat::CandKinResolution::Scalar> covariances(3);
0046 if (selectedBin >= 0) {
0047 covariances[0] = ROOT::Math::Square(Function(funcEt_[selectedBin]).operator()(cand));
0048 covariances[1] = ROOT::Math::Square(Function(funcEta_[selectedBin]).operator()(cand));
0049 covariances[2] = ROOT::Math::Square(Function(funcPhi_[selectedBin]).operator()(cand));
0050 }
0051
0052 else
0053 for (int i = 0; i < 3; ++i) {
0054 covariances[i] = 0.;
0055 }
0056
0057 return pat::CandKinResolution(parametrization_, covariances, constraints_);
0058 }