1 |
schiefer |
1.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 |
|
|
|
19 |
|
|
|
20 |
|
|
using namespace std;
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
24 |
|
|
// construction/destruction
|
25 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
26 |
|
|
|
27 |
|
|
//______________________________________________________________________________
|
28 |
|
|
jetcorr::jetcorr()
|
29 |
|
|
{
|
30 |
|
|
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
//______________________________________________________________________________
|
34 |
|
|
jetcorr::~jetcorr()
|
35 |
|
|
{
|
36 |
|
|
clear();
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
// implementation of member functions
|
42 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
|
|
//______________________________________________________________________________
|
45 |
|
|
float jetcorr::eval(float pt,float eta)
|
46 |
|
|
{
|
47 |
|
|
MapCIter_t it = fitfncs_.lower_bound(eta);
|
48 |
|
|
assert(it!=fitfncs_.end());
|
49 |
|
|
return 1.0/it->second->Eval(pt);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
//______________________________________________________________________________
|
55 |
|
|
bool jetcorr::initialize(const string& filename)
|
56 |
|
|
{
|
57 |
|
|
clear();
|
58 |
|
|
|
59 |
|
|
ifstream fin(filename.c_str());
|
60 |
|
|
|
61 |
|
|
if (!fin.is_open()) {
|
62 |
|
|
cout<<"can't open "<<filename<<endl;
|
63 |
|
|
return false;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
stringstream ss;
|
67 |
|
|
bool filter(false);
|
68 |
|
|
while (!fin.eof()) {
|
69 |
|
|
char next;
|
70 |
|
|
fin.get(next);
|
71 |
|
|
if (!filter&&next=='#') filter=true;
|
72 |
|
|
if(!filter) ss<<next;
|
73 |
|
|
if (filter&&next=='\n') filter=false;
|
74 |
|
|
}
|
75 |
|
|
fin.close();
|
76 |
|
|
|
77 |
|
|
int netabins;
|
78 |
|
|
string fitfncAsString;
|
79 |
|
|
int fitfncNbParams;
|
80 |
|
|
float eta,par,parerr;
|
81 |
|
|
|
82 |
|
|
ss>>netabins>>fitfncAsString>>fitfncNbParams;
|
83 |
|
|
|
84 |
|
|
for (int ieta=0;ieta<netabins;ieta++) {
|
85 |
|
|
ss>>eta;
|
86 |
|
|
stringstream fname; fname<<"fitfnc_eta"<<eta;
|
87 |
|
|
TF1* fitfnc = new TF1(fname.str().c_str(),fitfncAsString.c_str());
|
88 |
|
|
fitfncs_[eta] = fitfnc;
|
89 |
|
|
for (int ipar=0;ipar<fitfncNbParams;ipar++) {
|
90 |
|
|
ss>>par>>parerr;
|
91 |
|
|
fitfnc->SetParameter(ipar,par);
|
92 |
|
|
fitfnc->SetParError(ipar,parerr);
|
93 |
|
|
}
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
return true;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
//______________________________________________________________________________
|
101 |
|
|
void jetcorr::clear()
|
102 |
|
|
{
|
103 |
|
|
for (MapIter_t it=fitfncs_.begin();it!=fitfncs_.end();++it) delete it->second;
|
104 |
|
|
fitfncs_.clear();
|
105 |
|
|
}
|
106 |
|
|
|