ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/SchieferD/jetcalib/jetcorr.cpp
Revision: 1.5
Committed: Fri Nov 23 13:34:44 2007 UTC (17 years, 5 months ago) by schiefer
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // jetcorr
4 // -------
5 //
6 // 07/05/2007 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
7 ////////////////////////////////////////////////////////////////////////////////
8
9
10 #include "jetcorr.h"
11
12 #include <TF1.h>
13
14 #include <iostream>
15 #include <fstream>
16 #include <sstream>
17 #include <algorithm>
18 #include <cmath>
19
20
21 using namespace std;
22
23
24 double fnc_official(double*x,double*p);
25
26
27 ////////////////////////////////////////////////////////////////////////////////
28 // construction/destruction
29 ////////////////////////////////////////////////////////////////////////////////
30
31 //______________________________________________________________________________
32 jetcorr::jetcorr()
33 {
34
35 }
36
37 //______________________________________________________________________________
38 jetcorr::~jetcorr()
39 {
40 clear();
41 }
42
43
44 ////////////////////////////////////////////////////////////////////////////////
45 // implementation of member functions
46 ////////////////////////////////////////////////////////////////////////////////
47
48 //______________________________________________________________________________
49 float jetcorr::eval(float pt,float eta)
50 {
51 MapCIter_t it = fitfncs_.lower_bound(eta);
52 assert(it!=fitfncs_.end());
53 double rsp = it->second->Eval(pt);
54 double jes = (rsp>0.0) ? 1./rsp : 1.0;
55 return jes;
56 }
57
58
59
60 //______________________________________________________________________________
61 bool jetcorr::initialize(const string& filename)
62 {
63 clear();
64
65 ifstream fin(filename.c_str());
66
67 if (!fin.is_open()) {
68 cout<<"can't open "<<filename<<endl;
69 return false;
70 }
71
72 stringstream ss;
73 bool filter(false);
74 while (!fin.eof()) {
75 char next;
76 fin.get(next);
77 if (!filter&&next=='#') filter=true;
78 if(!filter) ss<<next;
79 if (filter&&next=='\n') filter=false;
80 }
81 fin.close();
82
83 int netabins;
84 string fitfncAsString;
85 int fitfncNbParams;
86 float eta,par;
87
88 ss>>netabins>>fitfncAsString>>fitfncNbParams;
89
90 for (int ieta=0;ieta<netabins;ieta++) {
91 ss>>eta;
92 stringstream fname; fname<<"fitfnc_eta"<<eta;
93 TF1* fitfnc = (fitfncAsString=="official") ?
94 new TF1(fname.str().c_str(),fnc_official,1,1e4,9) :
95 new TF1(fname.str().c_str(),fitfncAsString.c_str());
96 fitfncs_[eta] = fitfnc;
97 for (int ipar=0;ipar<fitfncNbParams;ipar++) {
98 ss>>par;
99 fitfnc->SetParameter(ipar,par);
100 }
101 }
102
103 return true;
104 }
105
106
107 //______________________________________________________________________________
108 void jetcorr::clear()
109 {
110 for (MapIter_t it=fitfncs_.begin();it!=fitfncs_.end();++it) delete it->second;
111 fitfncs_.clear();
112 }
113
114
115 //______________________________________________________________________________
116 double fnc_official(double*xx,double*p)
117 {
118 double a2 = p[5]/(std::sqrt(std::abs(p[6]*p[1] + p[7]))) + p[8];
119 double a1 = p[2]*std::sqrt(p[0] +p[3]) + p[4];
120 double w1 = (a1*p[1] - a2*p[0])/(p[1]-p[0]);
121 double w2 = (a2-a1)/(p[1]-p[0]);
122 double koef = 1.;
123 double e = xx[0];
124 double JetCalibrEt = e;
125 double x =e;
126 double etConstantResponse=5.;
127
128 if ( e<etConstantResponse ) JetCalibrEt=etConstantResponse;
129
130 for (int ie=0; ie<10; ie++) { //10 iterations garantees convergence
131
132 if ( JetCalibrEt<etConstantResponse ) JetCalibrEt=etConstantResponse;
133
134 if (JetCalibrEt < p[0]) {
135 koef = p[2]*std::sqrt(std::abs(JetCalibrEt +p[3])) + p[4];
136 }
137
138 else if (JetCalibrEt < p[1]) {
139 koef = w1 + JetCalibrEt*w2;
140 }
141
142 else if (JetCalibrEt > p[1]) {
143 koef = p[5]/(std::sqrt(std::abs(p[6]*JetCalibrEt + p[7]))) + p[8];
144 }
145
146 if(koef<0.1) koef=0.1;
147 JetCalibrEt = x / koef;
148 }
149
150 return koef;
151 }