Go to the documentation of this file.00001 #include "JetMETCorrections/JetParton/interface/JetPartonCorrector.h"
00002 #include "FWCore/ParameterSet/interface/FileInPath.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "DataFormats/Common/interface/Handle.h"
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include <vector>
00009 #include <fstream>
00010 #include <sstream>
00011 using namespace std;
00012
00013 namespace JetPartonNamespace{
00014 class UserPartonMixture{
00015 public:
00016 UserPartonMixture(){}
00017 virtual ~UserPartonMixture(){}
00018 virtual double mixt (double et,double eta)
00019 {
00020
00021 double f = 0.2+et/1000.*(1.+.13*exp(eta));
00022 return f;
00023 }
00024 };
00025
00026 class ParametrizationJetParton{
00027
00028 public:
00029
00030 ParametrizationJetParton(int thePartonMixture,vector<double> x, vector<double> y, vector<double> z)
00031 {
00032 type = thePartonMixture;
00033 pq = x;
00034 pg = y;
00035 pqcd = z;
00036 }
00037
00038 double value(double arg1, double arg2) const;
00039
00040 private:
00041
00042 int type;
00043 std::vector<double> pq;
00044 std::vector<double> pg;
00045 std::vector<double> pqcd;
00046
00047 };
00048
00049 double ParametrizationJetParton::value(double e, double eta)const{
00050 double enew(e);
00051 double x = e;
00052 double y = eta;
00053
00054 if( abs(x-pq[2]) < pq[1]/pq[0] || abs(x-pg[2]) < pg[1]/pg[0] || abs(x-pqcd[2]) < pqcd[1]/pqcd[0] )
00055 {
00056 return enew;
00057 }
00058
00059 double kjetq = pq[0]-pq[1]/(x-pq[2]);
00060 double kjetg = pg[0]-pg[1]/(x-pg[2]);
00061 double kjetqcd = pqcd[0]-pqcd[1]/(x-pqcd[2]);
00062
00063 switch(type){
00064 case 1:
00065 {
00066 if( abs(kjetq) > 0.0001 ) enew=e/kjetq;
00067 break;
00068 }
00069 case 2:
00070 {
00071 if( abs(kjetg) > 0.0001 ) enew=e/kjetg;
00072 break;
00073 }
00074 case 3:
00075 {
00076 if( abs(kjetqcd) > 0.0001 ) enew=e/kjetqcd;
00077 break;
00078 }
00079 case 4:
00080 {
00081 cout<<"[Jets] JetPartonCorrector: Warning! Calibration to b-quark - does not implemented yet. Light quark calibration is used instead "<<endl;
00082 if( abs(kjetq) > 0.0001 ) enew=e/kjetq;
00083 break;
00084 }
00085 case 100:
00086 {
00087 UserPartonMixture upm;
00088 double f = upm.mixt(x,y);
00089 double kjet=(f*kjetq+kjetg)/(f+1);
00090 if( abs(kjet) > 0.0001 ) enew=e/kjet;
00091 break;
00092 }
00093
00094 default:
00095 cerr<<"[Jets] JetPartonCorrector: Error! unknown parametrization type = "<<type<<" No correction applied ..."<<endl;
00096 break;
00097 }
00098 return enew;
00099 }
00100
00101 class JetPartonCalibrationParameterSet{
00102 public:
00103 JetPartonCalibrationParameterSet(string tag);
00104 int neta(){return etavector.size();}
00105 double eta(int ieta){return etavector[ieta];}
00106 int type(int ieta){return typevector[ieta];}
00107 const vector<double>& parameters(int ieta){return pars[ieta];}
00108 bool valid(){return etavector.size();}
00109
00110 private:
00111
00112 vector<double> etavector;
00113 vector<int> typevector;
00114 vector< vector<double> > pars;
00115 };
00116
00117 JetPartonCalibrationParameterSet::JetPartonCalibrationParameterSet(string tag){
00118
00119 std::string file="JetMETCorrections/JetParton/data/"+tag+".txt";
00120
00121 edm::FileInPath f1(file);
00122
00123 std::ifstream in( (f1.fullPath()).c_str() );
00124
00125
00126
00127
00128 string line;
00129 while( std::getline( in, line) ){
00130 if(!line.size() || line[0]=='#') continue;
00131 istringstream linestream(line);
00132 double par;
00133 int type;
00134 linestream>>par>>type;
00135 etavector.push_back(par);
00136 typevector.push_back(type);
00137 pars.push_back(vector<double>());
00138 while(linestream>>par)pars.back().push_back(par);
00139 }
00140
00141
00142
00143 }
00144 }
00145
00146 JetPartonCorrector::JetPartonCorrector(const edm::ParameterSet& fConfig)
00147 {
00148 thePartonMixture = fConfig.getParameter<int>("MixtureType");
00149 theJetFinderRadius = fConfig.getParameter<double>("Radius");
00150 setParameters (fConfig.getParameter <std::string> ("tagName"),theJetFinderRadius,thePartonMixture );
00151 }
00152
00153 JetPartonCorrector::~JetPartonCorrector()
00154 {
00155 for(ParametersMap::iterator ip=parametrization.begin();ip!=parametrization.end();ip++) delete ip->second;
00156 }
00157
00158 void JetPartonCorrector::setParameters(std::string aCalibrationType, double aJetFinderRadius, int aPartonMixture )
00159 {
00160
00161 theJetFinderRadius = aJetFinderRadius;
00162 thePartonMixture = aPartonMixture;
00163
00164 JetPartonNamespace::JetPartonCalibrationParameterSet pset(aCalibrationType);
00165
00166 if((!pset.valid()) && (aCalibrationType != "no"))
00167 {
00168 edm::LogError ("JetPartonCorrector: Jet Corrections not found ") << aCalibrationType <<
00169 " not found! Cannot apply any correction ... For JetPlusTrack calibration only radii 0.5 and 0.7 are included for JetParton" << endl;
00170 return;
00171 }
00172 if (aCalibrationType=="no") return;
00173
00174
00175 map<int,vector<double> > pq;
00176 map<int,vector<double> > pg;
00177 map<int,vector<double> > pqcd;
00178 int iq = 0;
00179 int ig = 0;
00180 int iqcd = 0;
00181 for(int ieta=0; ieta<pset.neta();ieta++)
00182 {
00183 if( pset.type(ieta) == 1 ) {pq[iq] = pset.parameters(ieta); iq++;};
00184 if( pset.type(ieta) == 2 ) {pg[ig] = pset.parameters(ieta);ig++;};
00185 if( pset.type(ieta) == 3 ) {pqcd[iqcd] = pset.parameters(ieta);iqcd++;};
00186 }
00187
00188 for(int ieta=0; ieta<iq;ieta++){
00189 parametrization[pset.eta(ieta)]=new JetPartonNamespace::ParametrizationJetParton(thePartonMixture,(*pq.find(ieta)).second,(*pg.find(ieta)).second,(*pqcd.find(ieta)).second);
00190 }
00191 }
00192 double JetPartonCorrector::correction( const LorentzVector& fJet) const
00193 {
00194 if(parametrization.empty()) { return 1.; }
00195
00196 double et=fJet.Et();
00197 double eta=fabs(fJet.Eta());
00198
00199
00200
00201 double etnew;
00202 std::map<double,JetPartonNamespace::ParametrizationJetParton*>::const_iterator ip=parametrization.upper_bound(eta);
00203 if(ip==parametrization.begin())
00204 {
00205 etnew=ip->second->value(et,eta);
00206 }
00207 else if(ip==parametrization.end())
00208 {
00209 etnew=(--ip)->second->value(et,eta);
00210 }
00211 else
00212 {
00213 double eta2=ip->first;
00214 double et2=ip->second->value(et,eta);
00215 ip--;
00216 double eta1=ip->first;
00217 double et1=ip->second->value(et,eta);
00218
00219 etnew=(eta2*et1 - eta1*et2 + eta*et2 - eta*et1)/(eta2-eta1);
00220 }
00221 cout<<" JetParton::The new energy found "<<etnew<<" "<<et<<endl;
00222 float mScale = 1000.;
00223
00224 if( et > 0.001) mScale = etnew/et;
00225
00226 return mScale;
00227
00228
00229 }