Go to the documentation of this file.00001
00030
00031 #include "ForIA/AnalysisTools/JERProvider.hh"
00032
00033 JERProvider::JERProvider(std::string CollectionName, std::string MethodName, std::string FileName):
00034 m_collectionName(CollectionName), m_methodName(MethodName), m_fileName(FileName), m_isInit(false)
00035 {
00036
00037 }
00038
00039 void JERProvider::setFileName(std::string fileName)
00040 {
00041
00042 if(!m_isInit) m_fileName = fileName;
00043 else cout << "ERROR: Input file cannot be changed once JERProvider is initialized!" << endl;
00044 }
00045
00046 void JERProvider::init()
00047 {
00048
00049 if(!m_isInit) {
00050 m_inputFile = new TFile(m_fileName.c_str());
00051 if(!m_inputFile)
00052 {
00053 cout << "ERROR: Input File " << m_fileName << " could not be found." << endl;
00054 } else {
00055 setInputCollection(m_collectionName, m_methodName);
00056
00057
00058 m_isInit = true;
00059 }
00060
00061 m_inputFile->Close();
00062 delete m_inputFile;
00063 }
00064 else {
00065 cout << "JERProvider already initialized!" << endl;
00066 }
00067 }
00068
00069 JERProvider::~JERProvider()
00070 {
00071
00072 map<int, TF1* >::iterator func = m_jerFunc.begin();
00073 for(;func!=m_jerFunc.end();func++) {
00074 delete func->second;
00075 }
00076
00077 map<int, TGraphErrors* >::iterator off = m_jerOffset.begin();
00078 for(;off!=m_jerOffset.end();off++) {
00079 delete off->second;
00080 }
00081
00082 map<int, TGraphErrors* >::iterator syst = m_jerSyst.begin();
00083 for(;syst!=m_jerSyst.end();syst++) {
00084 delete syst->second;
00085 }
00086 }
00087
00088 void JERProvider::setInputCollection(std::string CollectionName, std::string MethodName)
00089 {
00090
00091 std::string suffixName;
00092
00093 if(CollectionName == "AntiKt6TopoJES")
00094 suffixName = "_AntiKt6TopoJES";
00095 else if(CollectionName == "AntiKt4TopoJES")
00096 suffixName = "_AntiKt4TopoJES";
00097 else if(CollectionName == "AntiKt6LCTopoJES")
00098 suffixName = "_AntiKt6LCTopoJES";
00099 else if(CollectionName == "AntiKt4LCTopoJES")
00100 suffixName = "_AntiKt4LCTopoJES";
00101 else
00102 {
00103 cout << "ERROR: " << CollectionName << " not implemented, using default AntiKt6TopoJES"
00104 << endl;
00105 suffixName = "_AntiKt6TopoJES";
00106 }
00107
00108
00109 if(MethodName == "Truth")
00110 suffixName = MethodName+suffixName;
00111
00112
00113
00114
00115 else {
00116 cout << "ERROR: " << MethodName << " not implemented, using default Truth"
00117 << endl;
00118 suffixName = "Truth_AntiKt6TopoJES";
00119 }
00120
00121 std::string regions[m_nY] = {"_0","_1","_2","_3","_4","_5"};
00122
00123
00124 for(int i=0; i < m_nY; i++)
00125 {
00126
00127 std::string currentPlot = suffixName+regions[i];
00128
00129 m_inputFile->GetObject(currentPlot.c_str(),m_jerFunc[i]);
00130 if(!m_jerFunc[i])
00131 cout << " ERROR: Problem finding Required Input Graph: " << currentPlot.c_str() << endl;
00132 else {
00133 m_jerFunc[i]->SetName(TString("the").Append(currentPlot.c_str()));
00134 }
00135 }
00136
00137
00138
00139 for(int i=0; i < m_nY - 2 ; i++)
00140 {
00141
00142 std::string currentPlot = "DataMCBisector_"+CollectionName+regions[i];
00143
00144 m_inputFile->GetObject(currentPlot.c_str(),m_jerOffset[i]);
00145 if(!m_jerOffset[i])
00146 cout << " ERROR: Problem finding Required Input Graph: " << currentPlot.c_str() << endl;
00147 else {
00148 m_jerOffset[i]->SetName(TString("the").Append(currentPlot.c_str()));
00149 }
00150 }
00151
00152
00153
00154 for(int i=0; i < m_nY - 2 ; i++)
00155 {
00156
00157 std::string currentPlot = "DataMCBisectorUNCERT_"+CollectionName+regions[i];
00158
00159 m_inputFile->GetObject(currentPlot.c_str(),m_jerSyst[i]);
00160 if(!m_jerSyst[i])
00161 cout << " ERROR: Problem finding Required Input Graph: " << currentPlot.c_str() << endl;
00162 else {
00163 m_jerSyst[i]->SetName(TString("the").Append(currentPlot.c_str()));
00164 }
00165 }
00166
00167
00168
00169 }
00170
00171 TF1* JERProvider::getParam(double y)
00172 {
00173
00174 if(!m_isInit) {
00175 cout << "JERProvider not initialized." << endl;
00176 return 0;
00177 }
00178
00179 y = fabs(y);
00180
00181
00182
00183 int index = -1;
00184 if (y <= 0.8) {
00185 index = 0;
00186 if (m_collectionName == "AntiKt6TopoJES" || m_collectionName == "AntiKt6LCTopoJES") m_syst = 0.08;
00187 if (m_collectionName == "AntiKt4TopoJES" || m_collectionName == "AntiKt4LCTopoJES") m_syst = 0.11;
00188 }
00189 else if (y >= 0.8 && y < 1.2) {
00190 index = 1;
00191 if (m_collectionName == "AntiKt6TopoJES" || m_collectionName == "AntiKt6LCTopoJES") m_syst = 0.10;
00192 if (m_collectionName == "AntiKt4TopoJES" || m_collectionName == "AntiKt4LCTopoJES") m_syst = 0.13;
00193 }
00194 else if (y >= 1.2 && y < 2.1) {
00195 index = 2;
00196 if (m_collectionName == "AntiKt6TopoJES" || m_collectionName == "AntiKt6LCTopoJES") m_syst = 0.09;
00197 if (m_collectionName == "AntiKt4TopoJES" || m_collectionName == "AntiKt4LCTopoJES") m_syst = 0.12;
00198 }
00199 else if (y >= 2.1 && y < 2.8) {
00200 index = 3;
00201 if (m_collectionName == "AntiKt6TopoJES" || m_collectionName == "AntiKt6LCTopoJES") m_syst = 0.10;
00202 if (m_collectionName == "AntiKt4TopoJES" || m_collectionName == "AntiKt4LCTopoJES") m_syst = 0.13;
00203 }
00204 else if (y >= 2.8 && y < 3.6) {
00205 index = 4;
00206 if (m_collectionName == "AntiKt6TopoJES" || m_collectionName == "AntiKt6LCTopoJES") { m_offset = 0.00; m_uncert = 0.20; m_syst = 0.11;}
00207 if (m_collectionName == "AntiKt4TopoJES" || m_collectionName == "AntiKt4LCTopoJES") { m_offset = 0.00; m_uncert = 0.20; m_syst = 0.14;}
00208 }
00209 else if (y >= 3.6 && y <= 4.5) {
00210 index = 5;
00211 if (m_collectionName == "AntiKt6TopoJES" || m_collectionName == "AntiKt6LCTopoJES") { m_offset = 0.00; m_uncert = 0.30; m_syst = 0.11;}
00212 if (m_collectionName == "AntiKt4TopoJES" || m_collectionName == "AntiKt4LCTopoJES") { m_offset = 0.00; m_uncert = 0.30; m_syst = 0.14;}
00213 }
00214 else {
00215
00216 cout << "WARNING: Y outside of covered range (0.0-4.5): Returning parametrization for 4.5" << endl;
00217 return m_jerFunc[5];
00218 }
00219
00220 return m_jerFunc[index];
00221
00222 }
00223
00224 TGraphErrors* JERProvider::getOffset(double y)
00225 {
00226
00227 if(!m_isInit) {
00228 cout << "JERProvider not initialized." << endl;
00229 return 0;
00230 }
00231
00232 y = fabs(y);
00233
00234
00235
00236 int index = -1;
00237 if (y <= 0.8) index = 0;
00238 else if (y >= 0.8 && y < 1.2) index = 1;
00239 else if (y >= 1.2 && y < 2.1) index = 2;
00240 else if (y >= 2.1 && y < 2.8) index = 3;
00241 else if (y >= 2.8 && y < 3.6) index = 3;
00242 else if (y >= 3.6 && y <= 4.5) index = 3;
00243 else {
00244
00245 cout << "WARNING: Y outside of covered range (0.0-4.5): Returning parametrization for 4.5" << endl;
00246 return m_jerOffset[3];
00247 }
00248
00249 return m_jerOffset[index];
00250
00251 }
00252
00253 TGraphErrors* JERProvider::getSyst(double y)
00254 {
00255
00256 if(!m_isInit) {
00257 cout << "JERProvider not initialized." << endl;
00258 return 0;
00259 }
00260
00261 y = fabs(y);
00262
00263
00264
00265 int index = -1;
00266 if (y <= 0.8) index = 0;
00267 else if (y >= 0.8 && y < 1.2) index = 1;
00268 else if (y >= 1.2 && y < 2.1) index = 2;
00269 else if (y >= 2.1 && y < 2.8) index = 3;
00270 else if (y >= 2.8 && y < 3.6) index = 3;
00271 else if (y >= 3.6 && y <= 4.5) index = 3;
00272 else {
00273
00274 cout << "WARNING: Y outside of covered range (0.0-4.5): Returning parametrization for 4.5" << endl;
00275 return m_jerSyst[3];
00276 }
00277
00278 return m_jerSyst[index];
00279
00280 }
00281
00282
00283 float JERProvider::getSigma(double pt, double y)
00284 {
00285
00286 if(!m_isInit) {
00287 cout << "JERProvider not initialized." << endl;
00288 return 0;
00289 }
00290
00291 y = fabs(y);
00292
00293
00294 if(fabs(y) > 4.5)
00295 {
00296
00297 y = 4.5;
00298 }
00299
00300
00301 if(pt < 10.)
00302 {
00303
00304 pt = 10.;
00305 }
00306
00307 if(pt > 2000.)
00308 {
00309
00310 pt = 2000.;
00311 }
00312
00313
00314
00315 TF1* jer = getParam(y);
00316 TGraphErrors* jer_offset = getOffset(y);
00317
00318 if ( fabs(y) < 2.8) m_offset = jer_offset->Eval(pt) / 100.;
00319 else m_offset = 0.0;
00320
00321
00322 m_param[0] = jer->GetParameter(0); m_param[3] = jer->GetParError(0);
00323 m_param[1] = jer->GetParameter(1); m_param[4] = jer->GetParError(1);
00324 m_param[2] = jer->GetParameter(2); m_param[5] = jer->GetParError(2);
00325
00326
00327
00328
00329 double sigma = sqrt(m_param[0]*m_param[0]/pt/pt + m_param[1]*m_param[1]/pt + m_param[2]*m_param[2]);
00330
00331 sigma = sigma + sigma*m_offset;
00332
00333 return sigma;
00334
00335 }
00336
00337
00338 float JERProvider::getUncert(double pt, double y)
00339 {
00340
00341 if(!m_isInit) {
00342 cout << "JERProvider not initialized." << endl;
00343 return 0;
00344 }
00345
00346 y = fabs(y);
00347
00348
00349 if(fabs(y) > 4.5)
00350 {
00351
00352 y = 4.5;
00353 }
00354
00355
00356 if(pt < 10.)
00357 {
00358
00359 pt = 10.;
00360 }
00361
00362 if(pt > 2000.)
00363 {
00364
00365 pt = 2000.;
00366 }
00367
00368
00369
00370 TF1* jer = getParam(y); jer->GetParameter(0);
00371
00372
00373 TGraphErrors* jer_syst = getSyst(y);
00374
00375
00376 float ptmin = 10; float ptmax = 1000; float ptpiv = 1000;
00377
00378 if ( y > 0.8 && y <= 1.2 ) { ptmin = 10; ptmax = 800; ptpiv = 800; }
00379 if ( y > 1.2 && y <= 2.1 ) { ptmin = 10; ptmax = 600; ptpiv = 600; }
00380 if ( y > 2.1 && y <= 2.8 ) { ptmin = 10; ptmax = 500; ptpiv = 500; }
00381 if ( y > 2.8 ) { ptmin = 10; ptmax = 500; ptpiv = 500; }
00382
00383
00384 float factor = 0;
00385
00386
00387
00388
00389
00390
00391
00392 if ( pt >= ptmin && pt <= ptmax) {
00393 if ( fabs(y) < 2.8 ) m_uncert = jer_syst->Eval(pt) / 100.;
00394 m_uncert = sqrt( m_uncert*m_uncert + m_syst*m_syst );
00395 m_uncert = m_uncert*getSigma(pt,y);
00396 }
00397 if ( pt > ptmax && pt <= 2*ptmax) {
00398 factor = (pt - ptmax)/ptpiv;
00399 if ( fabs(y) < 2.8 ) m_uncert = jer_syst->Eval(ptmax) / 100.;
00400 m_uncert = sqrt( m_uncert*m_uncert + m_syst*m_syst );
00401 m_uncert = (1+factor)*m_uncert*getSigma(pt,y);
00402 }
00403 if ( pt > 2*ptmax) {
00404 if ( fabs(y) < 2.8 ) m_uncert = jer_syst->Eval(ptmax) / 100.;
00405 m_uncert = sqrt( m_uncert*m_uncert + m_syst*m_syst );
00406 m_uncert = 2.0*m_uncert*getSigma(pt,y);
00407 }
00408
00409 return m_uncert;
00410
00411 }
00412
00413