00001 #include <map> 00002 #include <Math/Functions.h> 00003 00004 #include "CommonTools/Utils/interface/StringCutObjectSelector.h" 00005 #include "PhysicsTools/PatAlgos/interface/StringResolutionProvider.h" 00006 #include "DataFormats/PatCandidates/interface/ParametrizationHelper.h" 00007 00008 StringResolutionProvider::StringResolutionProvider(const edm::ParameterSet& cfg): constraints_() 00009 { 00010 typedef pat::CandKinResolution::Parametrization Parametrization; 00011 00012 // 00013 std::vector<double> constr = cfg.getParameter<std::vector<double> > ("constraints"); 00014 constraints_.insert(constraints_.end(), constr.begin(), constr.end()); 00015 00016 std::string parametrization(cfg.getParameter<std::string> ("parametrization") ); 00017 parametrization_ = pat::helper::ParametrizationHelper::fromString(parametrization); 00018 00019 std::vector<edm::ParameterSet> functionSets_ = cfg.getParameter <std::vector<edm::ParameterSet> >("functions"); 00020 for(std::vector<edm::ParameterSet>::const_iterator iSet = functionSets_.begin(); iSet != functionSets_.end(); ++iSet){ 00021 if(iSet->exists("bin"))bins_.push_back(iSet->getParameter<std::string>("bin")); 00022 else if(functionSets_.size()==1)bins_.push_back(""); 00023 else throw cms::Exception("WrongConfig") << "Parameter 'bin' is needed if more than one PSet is specified\n"; 00024 00025 funcEt_.push_back(iSet->getParameter<std::string>("et")); 00026 funcEta_.push_back(iSet->getParameter<std::string>("eta")); 00027 funcPhi_.push_back(iSet->getParameter<std::string>("phi")); 00028 } 00029 } 00030 00031 StringResolutionProvider::~StringResolutionProvider() 00032 { 00033 } 00034 00035 pat::CandKinResolution 00036 StringResolutionProvider::getResolution(const reco::Candidate& cand) const 00037 { 00038 int selectedBin=-1; 00039 for(unsigned int i=0; i<bins_.size(); ++i){ 00040 StringCutObjectSelector<reco::Candidate> select_(bins_[i]); 00041 if(select_(cand)){ 00042 selectedBin = i; 00043 break; 00044 } 00045 } 00046 std::vector<pat::CandKinResolution::Scalar> covariances(3); 00047 if(selectedBin>=0){ 00048 covariances[0] = ROOT::Math::Square(Function(funcEt_ [selectedBin]).operator()(cand)); 00049 covariances[1] = ROOT::Math::Square(Function(funcEta_[selectedBin]).operator()(cand)); 00050 covariances[2] = ROOT::Math::Square(Function(funcPhi_[selectedBin]).operator()(cand)); 00051 } 00052 // fill 0. for not selected candidates 00053 else for(int i=0; i<3; ++i){covariances[i] = 0.;} 00054 00055 return pat::CandKinResolution(parametrization_, covariances, constraints_); 00056 }