CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetPartonCorrector.cc
Go to the documentation of this file.
8 #include <vector>
9 #include <fstream>
10 #include <sstream>
11 using namespace std;
12 
13 namespace JetPartonNamespace{
15  public:
17  virtual ~UserPartonMixture(){}
18  virtual double mixt (double et,double eta)
19  {
20  // The mixture of quark and gluons corresponds to QCD jets.
21  double f = 0.2+et/1000.*(1.+.13*exp(eta));
22  return f;
23  }
24 };
25 
27 
28  public:
29 
30  ParametrizationJetParton(int thePartonMixture,vector<double> x, vector<double> y, vector<double> z)
31  {
32  type = thePartonMixture;
33  pq = x;
34  pg = y;
35  pqcd = z;
36  }
37 
38  double value(double arg1, double arg2) const;
39 
40  private:
41 
42  int type;
43  std::vector<double> pq;
44  std::vector<double> pg;
45  std::vector<double> pqcd;
46 
47 };
48 
49 double ParametrizationJetParton::value(double e, double eta)const{
50  double enew(e);
51  double x = e;
52  double y = eta;
53 
54  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] )
55  {
56  return enew;
57  }
58 
59  double kjetq = pq[0]-pq[1]/(x-pq[2]);
60  double kjetg = pg[0]-pg[1]/(x-pg[2]);
61  double kjetqcd = pqcd[0]-pqcd[1]/(x-pqcd[2]);
62 
63  switch(type){
64  case 1:
65  {
66  if( abs(kjetq) > 0.0001 ) enew=e/kjetq;
67  break;
68  }
69  case 2:
70  {
71  if( abs(kjetg) > 0.0001 ) enew=e/kjetg;
72  break;
73  }
74  case 3:
75  {
76  if( abs(kjetqcd) > 0.0001 ) enew=e/kjetqcd;
77  break;
78  }
79  case 4:
80  {
81  cout<<"[Jets] JetPartonCorrector: Warning! Calibration to b-quark - does not implemented yet. Light quark calibration is used instead "<<endl;
82  if( abs(kjetq) > 0.0001 ) enew=e/kjetq;
83  break;
84  }
85  case 100:
86  {
88  double f = upm.mixt(x,y);
89  double kjet=(f*kjetq+kjetg)/(f+1);
90  if( abs(kjet) > 0.0001 ) enew=e/kjet;
91  break;
92  }
93 
94  default:
95  cerr<<"[Jets] JetPartonCorrector: Error! unknown parametrization type = "<<type<<" No correction applied ..."<<endl;
96  break;
97  }
98  return enew;
99 }
100 
102  public:
104  int neta(){return etavector.size();}
105  double eta(int ieta){return etavector[ieta];}
106  int type(int ieta){return typevector[ieta];}
107  const vector<double>& parameters(int ieta){return pars[ieta];}
108  bool valid(){return etavector.size();}
109 
110  private:
111 
112  vector<double> etavector;
113  vector<int> typevector;
114  vector< vector<double> > pars;
115 };
116 
117 JetPartonCalibrationParameterSet::JetPartonCalibrationParameterSet(string tag){
118 
119  std::string file="JetMETCorrections/JetParton/data/"+tag+".txt";
120 
121  edm::FileInPath f1(file);
122 
123  std::ifstream in( (f1.fullPath()).c_str() );
124 
125 
126 
127  // if ( f1.isLocal() ){
128  string line;
129  while( std::getline( in, line) ){
130  if(!line.size() || line[0]=='#') continue;
131  istringstream linestream(line);
132  double par;
133  int type;
134  linestream>>par>>type;
135  etavector.push_back(par);
136  typevector.push_back(type);
137  pars.push_back(vector<double>());
138  while(linestream>>par)pars.back().push_back(par);
139  }
140  // }
141  // else
142  // if (tag!="no") { cout<<"The file \""<<file<<"\" was not found in path \""<<f1.fullPath()<<"\"."<<endl; }
143 }
144 } // namespace
145 
147 {
148  thePartonMixture = fConfig.getParameter<int>("MixtureType");
149  theJetFinderRadius = fConfig.getParameter<double>("Radius");
150  setParameters (fConfig.getParameter <std::string> ("tagName"),theJetFinderRadius,thePartonMixture );
151 }
152 
154 {
155  for(ParametersMap::iterator ip=parametrization.begin();ip!=parametrization.end();ip++) delete ip->second;
156 }
157 
158 void JetPartonCorrector::setParameters(std::string aCalibrationType, double aJetFinderRadius, int aPartonMixture )
159 {
160 
161  theJetFinderRadius = aJetFinderRadius;
162  thePartonMixture = aPartonMixture;
163 
165 
166  if((!pset.valid()) && (aCalibrationType != "no"))
167  {
168  edm::LogError ("JetPartonCorrector: Jet Corrections not found ") << aCalibrationType <<
169  " not found! Cannot apply any correction ... For JetPlusTrack calibration only radii 0.5 and 0.7 are included for JetParton" << endl;
170  return;
171  }
172  if (aCalibrationType=="no") return;
173 
174 
175  map<int,vector<double> > pq;
176  map<int,vector<double> > pg;
177  map<int,vector<double> > pqcd;
178  int iq = 0;
179  int ig = 0;
180  int iqcd = 0;
181  for(int ieta=0; ieta<pset.neta();ieta++)
182  {
183  if( pset.type(ieta) == 1 ) {pq[iq] = pset.parameters(ieta); iq++;};
184  if( pset.type(ieta) == 2 ) {pg[ig] = pset.parameters(ieta);ig++;};
185  if( pset.type(ieta) == 3 ) {pqcd[iqcd] = pset.parameters(ieta);iqcd++;};
186  }
187 
188  for(int ieta=0; ieta<iq;ieta++){
189  parametrization[pset.eta(ieta)]=new JetPartonNamespace::ParametrizationJetParton(thePartonMixture,(*pq.find(ieta)).second,(*pg.find(ieta)).second,(*pqcd.find(ieta)).second);
190  }
191 }
193 {
194  if(parametrization.empty()) { return 1.; }
195 
196  double et=fJet.Et();
197  double eta=fabs(fJet.Eta());
198 
199  //if(eta<10) { eta=abs(fJet.getY()); }
200 
201  double etnew;
202  std::map<double,JetPartonNamespace::ParametrizationJetParton*>::const_iterator ip=parametrization.upper_bound(eta);
203  if(ip==parametrization.begin())
204  {
205  etnew=ip->second->value(et,eta);
206  }
207  else if(ip==parametrization.end())
208  {
209  etnew=(--ip)->second->value(et,eta);
210  }
211  else
212  {
213  double eta2=ip->first;
214  double et2=ip->second->value(et,eta);
215  ip--;
216  double eta1=ip->first;
217  double et1=ip->second->value(et,eta);
218 
219  etnew=(eta2*et1 - eta1*et2 + eta*et2 - eta*et1)/(eta2-eta1);
220  }
221  cout<<" JetParton::The new energy found "<<etnew<<" "<<et<<endl;
222  float mScale = 1000.;
223 
224  if( et > 0.001) mScale = etnew/et;
225 
226  return mScale;
227 
228 
229 }
type
Definition: HCALResponse.h:22
T getParameter(std::string const &) const
JetPartonCorrector(const edm::ParameterSet &fConfig)
virtual double mixt(double et, double eta)
#define abs(x)
Definition: mlp_lapack.h:159
T eta() const
double double double z
U second(std::pair< T, U > const &p)
virtual double correction(const LorentzVector &fJet) const
get correction using Jet information only
void setParameters(std::string aCalibrationType, double aJetFinderRadius, int aPartonMixture)
double f[11][100]
ParametrizationJetParton(int thePartonMixture, vector< double > x, vector< double > y, vector< double > z)
tuple cout
Definition: gather_cfg.py:121
std::string fullPath() const
Definition: FileInPath.cc:171
x
Definition: VDTMath.h:216
reco::Particle::LorentzVector LorentzVector
Definition: JetCorrector.h:24