Go to the documentation of this file.00001 #include "ForIA/AnalysisTools/JESUncertaintyProvider.hh"
00002
00003
00004 JESUncertaintyProvider::JESUncertaintyProvider(std::string CollectionName, std::string FileName):
00005 m_GeV(1000.0), m_collectionName(CollectionName), m_fileName(FileName), m_isInit(false)
00006 {
00007
00008 m_inputFile = 0;
00009 m_uncGraph.clear();
00010 m_pileupUncGraph.clear();
00011
00012 }
00013
00014
00015
00016 JESUncertaintyProvider::~JESUncertaintyProvider()
00017 {
00018
00019
00020 map<int, TH2D* >::iterator coll = m_uncGraph.begin();
00021 for(;coll!=m_uncGraph.end();coll++) {
00022 if(coll->first==6) continue;
00023 delete coll->second;
00024 }
00025 coll = m_pileupUncGraph.begin();
00026 for(;coll!=m_pileupUncGraph.end();coll++) {
00027 delete coll->second;
00028 }
00029
00030 }
00031
00032
00033 void JESUncertaintyProvider::init()
00034 {
00035
00036
00037 if (m_isInit == false) {
00038
00039 m_inputFile = openInputFile(m_fileName);
00040
00041 if(!m_inputFile)
00042 {
00043 Error( "JESUncertaintyProvider::init()", ("ERROR: Input File "+m_fileName+" could not be found").c_str());
00044 } else {
00045
00046 m_isInit = setInputCollection(m_collectionName);
00047
00048 m_inputFile->Close();
00049
00050
00051 }
00052
00053 }
00054
00055 }
00056
00057
00058 TFile* JESUncertaintyProvider::openInputFile(std::string FileName)
00059 {
00060
00061
00062 return new TFile(FileName.c_str());
00063 }
00064
00065
00066
00067 bool JESUncertaintyProvider::setInputCollection(std::string CollectionName)
00068 {
00069
00070 std::string suffixName;
00071
00072 if(CollectionName == "AntiKt6H1TopoJets" || CollectionName == "AntiKt6EMJESTopoJets" || CollectionName == "AntiKt6TopoJetsEM" )
00073 suffixName = "_AntiKt6Topo_EMJES";
00074 else if(CollectionName == "AntiKt4H1TopoJets" || CollectionName == "AntiKt4EMJESTopoJets" || CollectionName == "AntiKt4TopoJetsEM")
00075 suffixName = "_AntiKt4Topo_EMJES";
00076 else
00077 {
00078 Warning("JESUncertaintyProvider::setInputCollection()", "ERROR: Name not recognized, using default AntiKt6EMJESTopoJets");
00079 suffixName = "_AntiKt6Topo_EMJES";
00080 }
00081
00082
00083 std::string plotNames[m_nUncertainties] = {"Calorimeter","NoiseThresholds","Perugia2010", "AlpgenJimmy","EtaIntercalibration", "NonClosure", "Pileup"};
00084
00085 for(unsigned int i=0; i<m_nUncertainties; i++)
00086 {
00087
00088 std::string currentPlot = "";
00089
00090
00091 if (i!=6)
00092 {
00093
00094 currentPlot = plotNames[i]+suffixName;
00095 m_inputFile->GetObject(currentPlot.c_str(),m_uncGraph[i]);
00096 m_uncGraph[i]->SetName(TString("the").Append(currentPlot.c_str()));
00097 m_uncGraph[i]->SetDirectory(0);
00098 }
00099
00100 else
00101 {
00102
00103 currentPlot = "Pileup"+suffixName+"_NPV_1";
00104 m_inputFile->GetObject(currentPlot.c_str(),m_uncGraph[i]);
00105 m_uncGraph[i]->SetName(TString("the").Append(currentPlot.c_str()));
00106 m_uncGraph[i]->SetDirectory(0);
00107 }
00108
00109 if(!m_uncGraph[i])
00110 {
00111 Error("JESUncertaintyProvider::SetInputCollection()",("ERROR: Problem finding Required Input Graph: "+currentPlot).c_str());
00112 return false;
00113 }
00114
00115 }
00116
00117
00118 for (unsigned int i=0; i<m_nVertices; i++)
00119 {
00120
00121
00122 std::ostringstream osstream;
00123 osstream << i+1;
00124 std::string string_i = osstream.str();
00125
00126
00127 std::string currentPlot = "Pileup"+suffixName+"_NPV_"+string_i;
00128
00129 m_inputFile->GetObject(currentPlot.c_str(),m_pileupUncGraph[i]);
00130 m_pileupUncGraph[i]->SetName(TString("the").Append(currentPlot.c_str()));
00131 m_pileupUncGraph[i]->SetDirectory(0);
00132
00133 if(!m_pileupUncGraph[i])
00134 {
00135 Error("JESUncertaintyProvider::SetInputCollection()",("ERROR: Problem finding Required Input Graph: "+currentPlot).c_str());
00136 return false;
00137 }
00138
00139 }
00140
00141 return true;
00142
00143 }
00144
00145
00146 double JESUncertaintyProvider::getAbsUncert(double pT, double Eta, Components UncertComps, unsigned int nVtx)
00147 {
00148 return getRelUncert(pT, Eta, UncertComps, nVtx)*pT;
00149 }
00150
00151
00152 double JESUncertaintyProvider::getRelUncert(double pT, double Eta, Components UncertComps, unsigned int nVtx)
00153 {
00154
00155 pT /= m_GeV;
00156
00157
00158 if(pT <= 15 || pT >= 7000)
00159 {
00160 Warning("JESUncertaintyProvider::getRelUncert()", "pT outside of covered range (15-7000): Returning -1");
00161 return -1;
00162 }
00163
00164
00165 if(fabs(Eta) >= 4.5)
00166 {
00167 Warning("JESUncertaintyProvider::getRelUncert()", "Eta outside of covered range (0.0<|eta|<4.5): Returning -1");
00168 return -1;
00169 }
00170
00171
00172 if(pT > 2500)
00173 pT = 2400.;
00174
00175
00176
00177 int currentBin = m_uncGraph[0]->FindBin(pT, fabs(Eta));
00178
00179 return getComponents(currentBin, UncertComps, nVtx);
00180
00181 }
00182
00183
00184 TH2D* JESUncertaintyProvider::getUncGraphCopy(Components UncertComps, unsigned int nVtx)
00185 {
00186 TH2D* myPlot = (TH2D*)m_uncGraph[0]->Clone();
00187 myPlot->Reset("ICE");
00188 int nBinsX = myPlot->GetNbinsX();
00189 int nBinsY = myPlot->GetNbinsY();
00190
00191 for(int g=0; g<nBinsX; g++)
00192 {
00193 for(int h=0; h<nBinsY; h++)
00194 {
00195
00196 int currentBin = (g+1)+(nBinsX+2)*(h+1);
00197 myPlot->SetBinContent(currentBin, getComponents(currentBin, UncertComps, nVtx));
00198 }
00199 }
00200 return myPlot;
00201 }
00202
00203
00204 double JESUncertaintyProvider::getComponents(int currentBin, Components UncertComps, unsigned int nVtx)
00205 {
00206
00207 double quadrature(0);
00208
00209
00210
00211
00212 int bitmask = 1;
00213
00214
00215
00216
00217 if (nVtx > m_nVertices) nVtx=7;
00218
00219
00220 if (nVtx == 0) nVtx=1;
00221
00222
00223 m_uncGraph[6] = m_pileupUncGraph[nVtx-1];
00224
00225
00226 for(unsigned int i=0; i<m_nUncertainties; i++)
00227
00228 {
00229 double currentComponent = 0;
00230
00231
00232 if(int(UncertComps) & bitmask)
00233 currentComponent = m_uncGraph[i]->GetBinContent(currentBin);
00234
00235
00236 quadrature += currentComponent*currentComponent;
00237
00238
00239 bitmask *=2;
00240 }
00241
00242 return sqrt(quadrature);
00243
00244 }