CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TauJetCorrector.cc
Go to the documentation of this file.
2 
9 
10 #include <vector>
11 #include <fstream>
12 #include <sstream>
13 using namespace std;
14 
15 double TauJetCorrector::ParametrizationTauJet::value(double et, double eta)const{
16 
17  double x=et;
18  double etnew(et);
19  double etabound = (*theEtabound.find(type)).second;
20  std::vector<double> taus = (*theParam.find(type)).second;
21 
22  if ( fabs(eta) > etabound) {
23  //cout << " ===> ETA outside of range - CORRECTION NOT DONE ***" << endl;
24  //cout << " eta = " << eta <<" pt = " << et << " etabound "<<etabound<<endl;
25  return et;
26  }
27  //cout << "correction parameters: " << taus[0] << " " << taus[1] << " " << taus[2] << endl;
28  switch(type){
29  case 1:
30  {
31  etnew = 2*(x-taus[0])/(taus[1]+sqrt(taus[1]*taus[1]-4*taus[0]*taus[2]+4*x*taus[2]));
32  break;
33  }
34  case 2:
35  {
36  etnew = 2*(x-taus[0])/(taus[1]+sqrt(taus[1]*taus[1]-4*taus[0]*taus[2]+4*x*taus[2]));
37  break;
38  }
39  case 3:
40  {
41  etnew = 2*(x-taus[0])/(taus[1]+sqrt(taus[1]*taus[1]-4*taus[0]*taus[2]+4*x*taus[2]));
42  break;
43  }
44 
45  default:
46  edm::LogError("TauJetCorrector: Error: unknown parametrization type ") << type << " in TauJetCorrector. No correction applied" << endl;
47  //cerr<<"TauJetCorrector: Error: unknown parametrization type '"<<type<<"' in TauJetCorrector. No correction applied"<<endl;
48  break;
49  }
50  return etnew;
51 }
52 
54 public:
56  int neta(){return etavector.size();}
57  double eta(int ieta){return etavector[ieta];}
58  int type(int ieta){return typevector[ieta];}
59  const vector<double>& parameters(int ieta){return pars[ieta];}
60  bool valid(){return etavector.size();}
61 
62 private:
63 
64  vector<double> etavector;
65  vector<int> typevector;
66  vector< vector<double> > pars;
67 };
69 
70  std::string file="JetMETCorrections/TauJet/data/"+tag+".txt";
71 
72  edm::FileInPath f1(file);
73 
74  std::ifstream in( (f1.fullPath()).c_str() );
75 
76  // if ( f1.isLocal() ){
77  //cout << " Start to read file "<<file<<endl;
78  string line;
79  while( std::getline( in, line)){
80  if(!line.size() || line[0]=='#') continue;
81  istringstream linestream(line);
82  double par;
83  int type;
84  linestream>>par>>type;
85 
86  //cout<<" Parameter eta = "<<par<<" Type= "<<type<<endl;
87 
88  etavector.push_back(par);
89  typevector.push_back(type);
90  pars.push_back(vector<double>());
91  while(linestream>>par)pars.back().push_back(par);
92  }
93  // }
94  // else
95  // cout<<"The file \""<<file<<"\" was not found in path \""<<f1.fullPath()<<"\"."<<endl;
96 }
97 
98 
100 {
101  type = fConfig.getParameter<int>("TauTriggerType");
102  setParameters (fConfig.getParameter <std::string> ("tagName"),type);
103 }
104 
105 
107 {
108  for(ParametersMap::iterator ip=parametrization.begin();ip!=parametrization.end();ip++) delete ip->second;
109 }
110 
111 void TauJetCorrector::setParameters(std::string aCalibrationType, int itype)
112 {
113  //cout<< " Start to set parameters "<<endl;
114  type = itype;
115  JetCalibrationParameterSetTauJet pset(aCalibrationType);
116 
117  if((!pset.valid()) && (aCalibrationType!="no"))
118  {
119  edm::LogError( "TauJetCorrector:Jet Corrections not found ")<<aCalibrationType<<
120  " not found! Cannot apply any correction ... For JetPlusTrack calibration only radii 0.5 and 0.7 are included for JetParton" << endl;
121  return;
122  }
123  if (aCalibrationType=="no") return;
124 
125  map<int,vector<double> > pq;
126  map<int,vector<double> > pg;
127  map<int,vector<double> > pqcd;
128  map<int,double > etaboundx;
129  int iq = 0;
130  int ig = 0;
131  int iqcd = 0;
132  int mtype = 0;
133  for(int ieta=0; ieta<pset.neta();ieta++)
134  {
135  if( pset.type(ieta) == 1 ) {pq[iq] = pset.parameters(ieta); iq++; mtype=(int)(pset.type(ieta));}
136  if( pset.type(ieta) == 2 ) {pg[ig] = pset.parameters(ieta); ig++; mtype=(int)(pset.type(ieta));}
137  if( pset.type(ieta) == 3 ) {pqcd[iqcd] = pset.parameters(ieta);iqcd++;mtype=(int)(pset.type(ieta));}
138  if( pset.type(ieta) == -1 ) {etaboundx[mtype-1] = pset.eta(ieta);}
139  }
140 
141  //cout<<" Number of parameters "<<iq<<" "<<ig<<" "<<iqcd<<endl;
142  int mynum = 0;
143  for(int ieta=0; ieta<pset.neta();ieta++)
144  {
145  //cout<<" New parmetrization "<<ieta<<" "<<pset.type(ieta)<<endl;
146 
147  if ( pset.type(ieta) == -1 ) continue;
148  if( ieta < iq+1)
149  {
150  parametrization[pset.eta(ieta)]=new ParametrizationTauJet(pset.type(ieta),(*pq.find(ieta)).second,
151  (*etaboundx.find(0)).second);
152  //cout<<" ALL "<<ieta<<" "<<((*pq.find(ieta)).second)[0]<<" "<<((*pq.find(ieta)).second)[1]<<" "<<
153  //((*pq.find(ieta)).second)[2]<<endl;
154 
155  }
156  if( ieta > iq && ieta < iq + ig + 2 )
157  {
158  mynum = ieta - iq - 1;
159  parametrization[pset.eta(ieta)]=new ParametrizationTauJet(pset.type(ieta),(*pg.find(mynum)).second,
160  (*etaboundx.find(1)).second);
161  //cout<<" One prong "<<((*pg.find(mynum)).second)[0]<<" "<<((*pg.find(mynum)).second)[1]<<" "<<
162  //((*pg.find(mynum)).second)[2]<<endl;
163 
164  }
165  if( ieta > iq + ig + 1)
166  {
167  mynum = ieta - iq - ig - 2;
168  //cout<<" Mynum "<<mynum<<" "<<ieta<<" "<<pset.type(ieta)<<endl;
169  parametrization[pset.eta(ieta)]=new ParametrizationTauJet(pset.type(ieta),(*pqcd.find(mynum)).second,
170  (*etaboundx.find(2)).second);
171  //cout<<" Two prongs "<<((*pqcd.find(mynum)).second)[0]<<" "<<((*pqcd.find(mynum)).second)[1]<<" "<<
172  //((*pqcd.find(mynum)).second)[2]<<endl;
173  }
174  }
175  //cout<<" Parameters inserted into mAlgorithm "<<endl;
176 }
177 
178 double TauJetCorrector::correction( const LorentzVector& fJet) const
179 {
180  //cout<<" Start Apply Corrections "<<endl;
181  if(parametrization.empty()) { return 1.; }
182 
183  double et=fJet.Et();
184  double eta=fabs(fJet.Eta());
185 
186  //cout<<" Et and eta of jet "<<et<<" "<<eta<<endl;
187 
188  double etnew;
189  std::map<double,ParametrizationTauJet*>::const_iterator ip=parametrization.upper_bound(eta);
190  etnew=(--ip)->second->value(et,eta);
191 
192  //cout<<" The new energy found "<<etnew<<" "<<et<<endl;
193 
194  float mScale = etnew/et;
195 
196  return mScale;
197 }
198 
199 double TauJetCorrector::correction(const reco::Jet& fJet) const {
200  return correction(fJet.p4());
201 }
type
Definition: HCALResponse.h:22
T getParameter(std::string const &) const
TauJetCorrector(const edm::ParameterSet &fParameters)
vector< vector< double > > pars
Base class for all types of Jets.
Definition: Jet.h:21
virtual double correction(const LorentzVector &fJet) const
get correction using Jet information only
void setParameters(std::string, int)
const vector< double > & parameters(int ieta)
T eta() const
U second(std::pair< T, U > const &p)
T sqrt(T t)
Definition: SSEVec.h:46
double value(double, double) const
virtual ~TauJetCorrector()
std::string fullPath() const
Definition: FileInPath.cc:171
x
Definition: VDTMath.h:216
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
reco::Particle::LorentzVector LorentzVector
Definition: JetCorrector.h:24