CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SignAlgoResolutions.cc
Go to the documentation of this file.
2 // -*- C++ -*-
3 //
4 // Package: METAlgorithms
5 // Class: SignAlgoResolutions
6 //
14 //
15 // Original Author: Kyle Story, Freya Blekman (Cornell University)
16 // Created: Fri Apr 18 11:58:33 CEST 2008
17 // $Id: SignAlgoResolutions.cc,v 1.11 2013/05/06 17:56:45 sakuma Exp $
18 //
19 //
25 
26 
27 #include <math.h>
28 
29 #include <cstdlib>
30 #include <iostream>
31 #include <sstream>
32 #include <string>
33 #include <sys/stat.h>
34 
36  functionmap_(),
37  ptResol_(0),
38  phiResol_(0)
39 {
40  addResolutions(iConfig);
41 }
42 
43 
44 
45 double metsig::SignAlgoResolutions::eval(const resolutionType & type, const resolutionFunc & func, const double & et, const double & phi, const double & eta) const {
46  // derive p from et and eta;
47  double theta = 2*atan(exp(-eta));
48  double p = et / sin(theta); // rough assumption: take e and p equivalent...
49  return eval(type,func,et,phi,eta,p);
50 
51 }
52 
53 double metsig::SignAlgoResolutions::eval(const resolutionType & type, const resolutionFunc & func, const double & et, const double & phi, const double & eta, const double &p) const {
54 
55  functionPars x(4);
56  x[0]=et;
57  x[1]=phi;
58  x[2]=eta;
59  x[3]=p;
60  // std::cout << "getting function of type " << type << " " << func << " " << x[0] << " " << x[1] << " " << x[2] << " " << x[3] << std::endl;
61  return getfunc(type,func,x);
62 
63 }
64 
66  double eta = candidate->eta();
67  double phi = candidate->phi();
68  double et = candidate->energy()*sin(candidate->theta());
69  resolutionType thetype;
71  int type = candidate->particleId();
72  switch (type)
73  {
74  case 1:
75  thetype=PFtype1;name="PFChargedHadron"; break;
76  case 2:
77  thetype=PFtype2;name="PFChargedEM"; break;
78  case 3:
79  thetype=PFtype3;name="PFMuon"; break;
80  case 4:
81  thetype=PFtype4;name="PFNeutralEM"; break;
82  case 5:
83  thetype=PFtype5;name="PFNeutralHadron"; break;
84  case 6:
85  thetype=PFtype6;name="PFtype6"; break;
86  case 7:
87  thetype=PFtype7;name="PFtype7"; break;
88  default:
89  thetype=PFtype7;name="PFunknown"; break;
90  }
91 
92  double d_et=0, d_phi=0; //d_phi here is the error on phi component of the et
93  reco::TrackRef trackRef = candidate->trackRef();
94  if(!trackRef.isNull()){
95  d_phi = et*trackRef->phiError();
96  d_et = (type==2) ? ElectronPtResolution(candidate) : trackRef->ptError();
97  //if(type==2) std::cout << eval(thetype,ET,et,phi,eta) << " " << trackRef->ptError() << " "<< ElectronPtResolution(candidate) << std::endl;
98  }
99  else{
100  d_et = eval(thetype,ET,et,phi,eta);
101  d_phi = eval(thetype,PHI,et,phi,eta);
102  }
103 
104  metsig::SigInputObj resultingobj(name,et,phi,d_et,d_phi);
105  return resultingobj;
106 }
107 
108 
111 
112  double jpt = jet->pt();
113  double jphi = jet->phi();
114  double jeta = jet->eta();
115  double jdeltapt = 999.;
116  double jdeltapphi = 999.;
117 
118  if(jpt<ptResolThreshold_ && jpt<20.){ //use temporary fix for low pT jets
119  double feta = TMath::Abs(jeta);
120  int ieta = feta<5.? int(feta/0.5) : 9; //bin size = 0.5
121  int ipt = jpt>3. ? int(jpt-3./2) : 0; //bin size =2, starting from ptmin=3GeV
122  jdeltapt = jdpt[ieta][ipt];
123  jdeltapphi = jpt*jdphi[ieta][ipt];
124  }
125  else{
126  //use the resolution functions at |eta|=5 to avoid crash for jets with large eta.
127  if(jeta>5) jeta=5;
128  if(jeta<-5) jeta=-5;
129  double jptForEval = jpt>ptResolThreshold_ ? jpt : ptResolThreshold_;
130  jdeltapt = jpt*ptResol_->parameterEtaEval("sigma",jeta,jptForEval);
131  jdeltapphi = jpt*phiResol_->parameterEtaEval("sigma",jeta,jptForEval);
132  }
133 
134  std::string inputtype = "jet";
135  metsig::SigInputObj obj_jet(inputtype,jpt,jphi,jdeltapt,jdeltapphi);
136  //std::cout << "RESOLUTIONS JET: " << jpt << " " << jphi<< " " <<jdeltapt << " " << jdeltapphi << std::endl;
137  return obj_jet;
138 }
139 
140 
142  using namespace std;
143 
144  // Jet Resolutions - for now load from the files. Migrate to EventSetup asap.
146 
147  ptResolThreshold_ = iConfig.getParameter<double>("ptresolthreshold");
148 
149 
150  //get temporary low pT pfjet resolutions
151  for (int ieta=0; ieta<10; ieta++){
152  jdpt[ieta] = iConfig.getParameter<std::vector<double> >(Form("jdpt%d", ieta));
153  jdphi[ieta] = iConfig.getParameter<std::vector<double> >(Form("jdphi%d", ieta));
154  }
155 
156 
157  // for now: do this by hand - this can obviously also be done via ESSource etc.
158  functionPars etparameters(3,0);
159  functionPars phiparameters(1,0);
160  // set the parameters per function:
161  // ECAL, BARREL:
162  std::vector<double> ebet = iConfig.getParameter<std::vector<double> >("EB_EtResPar");
163  std::vector<double> ebphi = iConfig.getParameter<std::vector<double> >("EB_PhiResPar");
164 
165  etparameters[0]=ebet[0];
166  etparameters[1]=ebet[1];
167  etparameters[2]=ebet[2];
168  phiparameters[0]=ebphi[0];
169  addfunction(caloEB,ET,etparameters);
170  addfunction(caloEB,PHI,phiparameters);
171  // ECAL, ENDCAP:
172  std::vector<double> eeet = iConfig.getParameter<std::vector<double> >("EE_EtResPar");
173  std::vector<double> eephi = iConfig.getParameter<std::vector<double> >("EE_PhiResPar");
174 
175  etparameters[0]=eeet[0];
176  etparameters[1]=eeet[1];
177  etparameters[2]=eeet[2];
178  phiparameters[0]=eephi[0];
179  addfunction(caloEE,ET,etparameters);
180  addfunction(caloEE,PHI,phiparameters);
181  // HCAL, BARREL:
182  std::vector<double> hbet = iConfig.getParameter<std::vector<double> >("HB_EtResPar");
183  std::vector<double> hbphi = iConfig.getParameter<std::vector<double> >("HB_PhiResPar");
184 
185  etparameters[0]=hbet[0];
186  etparameters[1]=hbet[1];
187  etparameters[2]=hbet[2];
188  phiparameters[0]=hbphi[0];
189  addfunction(caloHB,ET,etparameters);
190  addfunction(caloHB,PHI,phiparameters);
191  // HCAL, ENDCAP:
192  std::vector<double> heet = iConfig.getParameter<std::vector<double> >("HE_EtResPar");
193  std::vector<double> hephi = iConfig.getParameter<std::vector<double> >("HE_PhiResPar");
194 
195  etparameters[0]=heet[0];
196  etparameters[1]=heet[1];
197  etparameters[2]=heet[2];
198  phiparameters[0]=hephi[0];
199  addfunction(caloHE,ET,etparameters);
200  addfunction(caloHE,PHI,phiparameters);
201  // HCAL, Outer
202  std::vector<double> hoet = iConfig.getParameter<std::vector<double> >("HO_EtResPar");
203  std::vector<double> hophi = iConfig.getParameter<std::vector<double> >("HO_PhiResPar");
204 
205 
206  etparameters[0]=hoet[0];
207  etparameters[1]=hoet[1];
208  etparameters[2]=hoet[2];
209  phiparameters[0]=hophi[0];
210  addfunction(caloHO,ET,etparameters);
211  addfunction(caloHO,PHI,phiparameters);
212  // HCAL, Forward
213  std::vector<double> hfet = iConfig.getParameter<std::vector<double> >("HF_EtResPar");
214  std::vector<double> hfphi = iConfig.getParameter<std::vector<double> >("HF_PhiResPar");
215 
216  etparameters[0]=hfet[0];
217  etparameters[1]=hfet[1];
218  etparameters[2]=hfet[2];
219  phiparameters[0]=hfphi[0];
220  addfunction(caloHF,ET,etparameters);
221  addfunction(caloHF,PHI,phiparameters);
222 
223 
224  // PF objects:
225  // type 1:
226  std::vector<double> pf1et = iConfig.getParameter<std::vector<double> >("PF_EtResType1");
227  std::vector<double> pf1phi = iConfig.getParameter<std::vector<double> >("PF_PhiResType1");
228  etparameters[0]=pf1et[0];
229  etparameters[1]=pf1et[1];
230  etparameters[2]=pf1et[2];
231  phiparameters[0]=pf1phi[0];
232  addfunction(PFtype1,ET,etparameters);
233  addfunction(PFtype1,PHI,phiparameters);
234 
235  // PF objects:
236  // type 2:
237  std::vector<double> pf2et = iConfig.getParameter<std::vector<double> >("PF_EtResType2");
238  std::vector<double> pf2phi = iConfig.getParameter<std::vector<double> >("PF_PhiResType2");
239  etparameters[0]=pf2et[0];
240  etparameters[1]=pf2et[1];
241  etparameters[2]=pf2et[2];
242  phiparameters[0]=pf2phi[0];
243  addfunction(PFtype2,ET,etparameters);
244  addfunction(PFtype2,PHI,phiparameters);
245 
246  // PF objects:
247  // type 3:
248  std::vector<double> pf3et = iConfig.getParameter<std::vector<double> >("PF_EtResType3");
249  std::vector<double> pf3phi = iConfig.getParameter<std::vector<double> >("PF_PhiResType3");
250  etparameters[0]=pf3et[0];
251  etparameters[1]=pf3et[1];
252  etparameters[2]=pf3et[2];
253  phiparameters[0]=pf3phi[0];
254  addfunction(PFtype3,ET,etparameters);
255  addfunction(PFtype3,PHI,phiparameters);
256 
257  // PF objects:
258  // type 4:
259  std::vector<double> pf4et = iConfig.getParameter<std::vector<double> >("PF_EtResType4");
260  std::vector<double> pf4phi = iConfig.getParameter<std::vector<double> >("PF_PhiResType4");
261  etparameters[0]=pf4et[0];
262  etparameters[1]=pf4et[1];
263  etparameters[2]=pf4et[2];
264  //phiparameters[0]=pf4phi[0];
265  addfunction(PFtype4,ET,etparameters);
266  addfunction(PFtype4,PHI,pf4phi); //use the same functional form for photon phi error as for pT, pass whole vector
267 
268  // PF objects:
269  // type 5:
270  std::vector<double> pf5et = iConfig.getParameter<std::vector<double> >("PF_EtResType5");
271  std::vector<double> pf5phi = iConfig.getParameter<std::vector<double> >("PF_PhiResType5");
272  etparameters[0]=pf5et[0];
273  etparameters[1]=pf5et[1];
274  etparameters[2]=pf5et[2];
275  phiparameters[0]=pf5phi[0];
276  addfunction(PFtype5,ET,etparameters);
277  addfunction(PFtype5,PHI,pf5phi);
278 
279  // PF objects:
280  // type 6:
281  std::vector<double> pf6et = iConfig.getParameter<std::vector<double> >("PF_EtResType6");
282  std::vector<double> pf6phi = iConfig.getParameter<std::vector<double> >("PF_PhiResType6");
283  etparameters[0]=pf6et[0];
284  etparameters[1]=pf6et[1];
285  etparameters[2]=pf6et[2];
286  phiparameters[0]=pf6phi[0];
287  addfunction(PFtype6,ET,etparameters);
288  addfunction(PFtype6,PHI,phiparameters);
289 
290 
291  // PF objects:
292  // type 7:
293  std::vector<double> pf7et = iConfig.getParameter<std::vector<double> >("PF_EtResType7");
294  std::vector<double> pf7phi = iConfig.getParameter<std::vector<double> >("PF_PhiResType7");
295  etparameters[0]=pf7et[0];
296  etparameters[1]=pf7et[1];
297  etparameters[2]=pf7et[2];
298  phiparameters[0]=pf7phi[0];
299  addfunction(PFtype7,ET,etparameters);
300  addfunction(PFtype7,PHI,phiparameters);
301 
302  return;
303 }
304 
306 
307  functionCombo mypair(type,func);
308  functionmap_[mypair]=parameters;
309 
310 }
311 
313 
314  double result=0;
315  functionCombo mypair(type,func);
316 
317  if(functionmap_.count(mypair)==0){
318  return result;
319  }
320 
321  functionPars values = (functionmap_.find(mypair))->second;
322  switch ( func ){
323  case metsig::ET :
324  return EtFunction(x,values);
325  case metsig::PHI :
326  return PhiFunction(x,values);
327  case metsig::TRACKP :
328  return PFunction(x,values);
329  case metsig::CONSTPHI :
330  return PhiConstFunction(x,values);
331  }
332 
333  // std::cout << "returning function " << type << " " << func << " " << result << " " << x[0] << std::endl;
334 
335  return result;
336 }
337 
339 {
340  if(par.size()<3)
341  return 0.;
342  if(x.size()<1)
343  return 0.;
344  double et=x[0];
345  if(et<=0.)
346  return 0.;
347  double result = et*sqrt((par[2]*par[2])+(par[1]*par[1]/et)+(par[0]*par[0]/(et*et)));
348  return result;
349 }
350 
351 
353 {
354  double et=x[0];
355  if(et<=0.){
356  return 0.;
357  }
358 
359  //if 1 parameter is C provided, returns C*pT, if three parameters N, S, C are provided, it returns the usual resolution value, as for sigmaPt
360  if(par.size()!=1 && par.size()!=3){//only 1 or 3 parameters supported for phi function
361  return 0.;
362  }
363  else if(par.size()==1){
364  return par[0]*et;
365  }
366  else{
367  return et*sqrt((par[2]*par[2])+(par[1]*par[1]/et)+(par[0]*par[0]/(et*et)));
368  }
369 
370 }
372 {
373  // not currently implemented
374  return 0;
375 }
376 
378 {
379  return par[0];
380 }
381 
382 void
384 
385  using namespace std;
386 
387  // only reinitialize the resolutsion if the pointers are zero
388  if ( ptResol_ == 0 ) {
389  string resolutionsAlgo = iConfig.getParameter<std::string>("resolutionsAlgo");
390  string resolutionsEra = iConfig.getParameter<std::string>("resolutionsEra");
391 
392  string cmssw_base(getenv("CMSSW_BASE"));
393  string cmssw_release_base(getenv("CMSSW_RELEASE_BASE"));
394  string path = cmssw_base + "/src/CondFormats/JetMETObjects/data";
395  struct stat st;
396  if (stat(path.c_str(),&st)!=0) {
397  path = cmssw_release_base + "/src/CondFormats/JetMETObjects/data";
398  }
399  if (stat(path.c_str(),&st)!=0) {
400  cerr<<"ERROR: tried to set path but failed, abort."<<endl;
401  }
402  string era(resolutionsEra);
403  string alg(resolutionsAlgo);
404  string ptFileName = path + "/" + era + "_PtResolution_" +alg+".txt";
405  string phiFileName = path + "/" + era + "_PhiResolution_"+alg+".txt";
406 
407  ptResol_ = new JetResolution(ptFileName,false);
408  phiResol_ = new JetResolution(phiFileName,false);
409  }
410 }
411 
412 double
414 
415  double eta = c->eta();
416  double energy = c->energy();
417  double dEnergy = pfresol_->getEnergyResolutionEm(energy, eta);
418 
419  return dEnergy/cosh(eta);
420 }
421 
type
Definition: HCALResponse.h:21
virtual double energy() const GCC11_FINAL
energy
T getParameter(std::string const &) const
dictionary parameters
Definition: Parameters.py:2
double PhiFunction(const functionPars &x, const functionPars &par) const
double getfunc(const resolutionType &type, const resolutionFunc &func, std::vector< double > &x) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
metsig::SigInputObj evalPF(const reco::PFCandidate *candidate) const
Geom::Theta< T > theta() const
virtual double theta() const GCC11_FINAL
momentum polar angle
T eta() const
double eval(const resolutionType &type, const resolutionFunc &func, const double &et, const double &phi, const double &eta, const double &p) const
Jets made from PFObjects.
Definition: PFJet.h:22
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:349
U second(std::pair< T, U > const &p)
double ElectronPtResolution(const reco::PFCandidate *c) const
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
bool isNull() const
Checks for null.
Definition: Ref.h:247
T sqrt(T t)
Definition: SSEVec.h:48
tuple result
Definition: query.py:137
double EtFunction(const functionPars &x, const functionPars &par) const
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
std::vector< double > functionPars
metsig::SigInputObj evalPFJet(const reco::PFJet *jet) const
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:35
list cmssw_release_base
Definition: cmsBenchmark.py:61
void initializeJetResolutions(const edm::ParameterSet &iConfig)
double PhiConstFunction(const functionPars &x, const functionPars &par) const
Definition: DDAxes.h:10
virtual ParticleType particleId() const
Definition: PFCandidate.h:347
virtual float pt() const GCC11_FINAL
transverse momentum
void addfunction(const resolutionType type, const resolutionFunc func, std::vector< double > parameters)
std::pair< metsig::resolutionType, metsig::resolutionFunc > functionCombo
double PFunction(const functionPars &x, const functionPars &par) const
void addResolutions(const edm::ParameterSet &iConfig)
Definition: DDAxes.h:10