Go to the documentation of this file.00001 #include "RecoMuon/MuonIsolation/interface/IsolatorByNominalEfficiency.h"
00002 #include "RecoMuon/MuonIsolation/src/NominalEfficiencyThresholds.h"
00003 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00004 #include "FWCore/ParameterSet/interface/FileInPath.h"
00005
00006 using namespace muonisolation;
00007 using namespace std;
00008
00009 double IsolatorByNominalEfficiency::ConeSizes::size(int i) const
00010 { if (i >= 0 && i< DIM) return cone_dr[i]; else return 0.; }
00011
00012 int IsolatorByNominalEfficiency::ConeSizes::index(float dr) const
00013 {
00014 for(int i=DIM; i>=1; i--) if (cone_dr[i-1] < dr) return i;
00015 return 0;
00016 }
00017
00018 float IsolatorByNominalEfficiency::ConeSizes::cone_dr[]=
00019 { 0.001, 0.02, 0.045, 0.09, 0.13, 0.17, 0.20, 0.24, 0.28, 0.32, 0.38, 0.45, 0.5, 0.6, 0.7};
00020
00021 IsolatorByNominalEfficiency::IsolatorByNominalEfficiency(const string & thrFile,
00022 const vector<string> & ceff, const vector<double>& weights) : theWeights(weights){
00023 thresholds = new NominalEfficiencyThresholds(findPath(thrFile));
00024 coneForEfficiency = cones(ceff);
00025 theDepThresholds = std::vector<double>(weights.size(), -1e12);
00026 }
00027
00028 IsolatorByNominalEfficiency::
00029 IsolatorByNominalEfficiency(const string & thrFile, const vector<string> & ceff,
00030 const vector<double>& weights, const vector<double>& thresh
00031 ) : theWeights(weights), theDepThresholds(thresh){
00032 thresholds = new NominalEfficiencyThresholds(findPath(thrFile));
00033 coneForEfficiency = cones(ceff);
00034 }
00035
00036 IsolatorByNominalEfficiency::~IsolatorByNominalEfficiency()
00037 {
00038 delete thresholds;
00039 }
00040
00041 IsolatorByNominalEfficiency::mapNomEff_Cone
00042 IsolatorByNominalEfficiency::cones(const vector<string>& usrVec) {
00043 mapNomEff_Cone result;
00044 for (vector<string>::const_iterator is = usrVec.begin();
00045 is != usrVec.end(); is++) {
00046 char * evp = 0;
00047 int cone = strtol( (*is).c_str(), &evp, 10);
00048 float effic = strtod(evp+1, &evp);
00049 result.insert(make_pair(effic,cone));
00050 }
00051 return result;
00052 }
00053
00054 string IsolatorByNominalEfficiency::findPath(const string& fileName)
00055 {
00056
00057 edm::FileInPath f(fileName);
00058 return f.fullPath();
00059 }
00060
00061 MuIsoBaseIsolator::Result
00062 IsolatorByNominalEfficiency::result(const DepositContainer& deposits, const edm::Event*) const{
00063
00064 if (deposits.size()==0) {
00065 cout << "IsolatorByNominalEfficiency: no deposit" << endl;
00066 return Result(resultType());
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 float theEta = deposits.back().dep->eta();
00076
00077
00078
00079
00080 float nominalEfficiency = 1.;
00081 const float deltaeff=0.005;
00082 const float mineff=deltaeff;
00083 for (float eff=.995; eff>mineff; eff-=deltaeff) {
00084 int cone = bestConeForEfficiencyIndex(eff);
00085 float coneSize = theConesInfo.size(cone);
00086 NominalEfficiencyThresholds::ThresholdLocation location = {theEta,cone};
00087 float thres = thresholds->thresholdValueForEfficiency(location, eff);
00088 float sumDep = weightedSum(deposits,coneSize);
00089
00090
00091
00092
00093
00094
00095
00096
00097 if (sumDep > thres) break;
00098 nominalEfficiency = eff;
00099 }
00100 Result res(resultType());
00101 res.valFloat = nominalEfficiency;
00102 return res;
00103 }
00104
00105 int IsolatorByNominalEfficiency::bestConeForEfficiencyIndex(float eff_thr) const
00106 {
00107
00108
00109 int best_cone;
00110 if (coneForEfficiency.size() != 0) {
00111 best_cone = (--(coneForEfficiency.end()))->second;
00112 } else return 0;
00113
00114 mapNomEff_Cone::const_reverse_iterator it;
00115 for (it = coneForEfficiency.rbegin();
00116 it != coneForEfficiency.rend(); it++) {
00117 if (eff_thr <= (*it).first) best_cone = (*it).second;
00118 }
00119 return best_cone;
00120 }
00121
00122
00123 double IsolatorByNominalEfficiency::weightedSum(const DepositContainer& deposits,
00124 float dRcone) const {
00125 double sumDep=0;
00126
00127 assert(deposits.size()==theWeights.size());
00128
00129 vector<double>::const_iterator w = theWeights.begin();
00130 vector<double>::const_iterator dThresh = theDepThresholds.begin();
00131 for (DepositContainer::const_iterator dep = deposits.begin();
00132 dep != deposits.end(); dep++) {
00133 if (dep->vetos != 0){
00134 sumDep += dep->dep->depositAndCountWithin(dRcone, *dep->vetos, *dThresh).first * (*w);
00135 } else {
00136 sumDep += dep->dep->depositAndCountWithin(dRcone, Vetos(), *dThresh).first * (*w);
00137 }
00138 if (sumDep <0.) sumDep = 0.;
00139 w++;
00140 dThresh++;
00141 }
00142 return sumDep;
00143 }
00144
00145 Cuts IsolatorByNominalEfficiency::cuts(float nominalEfficiency) const
00146 {
00147 vector<double> etaBounds = thresholds->bins();
00148 vector<double> coneSizes;
00149 vector<double> cutvalues;
00150 for (vector<double>::const_iterator it=etaBounds.begin(),itEnd=etaBounds.end();it < itEnd;++it){
00151 float eta = (*it);
00152 int icone = bestConeForEfficiencyIndex(nominalEfficiency);
00153 coneSizes.push_back( theConesInfo.size(icone));
00154 NominalEfficiencyThresholds::ThresholdLocation location = {eta-1.e-3f, icone};
00155 cutvalues.push_back( thresholds->thresholdValueForEfficiency(location, nominalEfficiency));
00156 }
00157 return Cuts(etaBounds,coneSizes,cutvalues);
00158 }