File indexing completed on 2025-08-05 08:12:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include <TCanvas.h>
0024 #include <TFile.h>
0025 #include <TF1.h>
0026 #include <TGraph.h>
0027 #include <TGraphErrors.h>
0028 #include <TH1.h>
0029 #include <TH2.h>
0030 #include <TLatex.h>
0031 #include <TLegend.h>
0032 #include <TNtuple.h>
0033 #include <TString.h>
0034 #include <TStyle.h>
0035 #include <iostream>
0036 using namespace std;
0037
0038 std::vector<int> searchLeadingJets(TNtuple *T, float cutPT, const char *targetV = "gpt");
0039
0040
0041 void fjetResol(
0042 const char* path = "/gpfs/mnt/gpfs04/sphenix/user/ckim/fjets/Ana/results_1121",
0043 const char* var = "e",
0044 const char* suffix = "",
0045 bool print = true
0046 )
0047 {
0048
0049
0050 const int setPy[] = {8};
0051 const int setBeamE[] = {200};
0052 const int setR[] = {4, 6};
0053 const int setMinPT[] = { 5, 10, 15};
0054 const float setEta[] = {1.2, 1.6, 2.0, 2.4, 2.8, 3.2, 3.6};
0055 const float setE[] = {20,25,30,35,40,45,50, 60,70,80,90,100,110,120,130,140,150,160, 180,200};
0056
0057 const int nsetPy = sizeof(setPy) /sizeof(setPy[0]);
0058 const int nsetBeamE = sizeof(setBeamE)/sizeof(setBeamE[0]);
0059 const int nsetR = sizeof(setR) /sizeof(setR[0]);
0060 const int nsetMinPT = sizeof(setMinPT)/sizeof(setMinPT[0]);
0061 const int nsetEta = sizeof(setEta) /sizeof(setEta[0]) - 1;
0062 const int nsetE = sizeof(setE) /sizeof(setE[0]) - 1;
0063
0064
0065
0066
0067 TH2F *h2[nsetPy][nsetBeamE][nsetR][nsetEta];
0068 TH1F *h1[nsetPy][nsetBeamE][nsetR][nsetEta][nsetE];
0069 for (int a=0; a<nsetPy; a++)
0070 for (int b=0; b<nsetBeamE; b++)
0071 for (int c=0; c<nsetR; c++)
0072 for (int x=0; x<nsetEta; x++)
0073 {
0074 const char* h2Name = Form("sanity_py%i_%i_r0%i_eta%i", setPy[a],setBeamE[b],setR[c],x);
0075 h2[a][b][c][x] = new TH2F(h2Name, "", 100,0,b==0?100:200, 60,0,2);
0076 for (int y=0; y<nsetE; y++)
0077 {
0078 const char* h1Name = Form("h1_%s_py%i_%i_r0%i_eta%i_e%i", var,setPy[a],setBeamE[b],setR[c],x,y);
0079 h1[a][b][c][x][y] = new TH1F(h1Name, "", 150,-1.5,1.5);
0080 }
0081 }
0082
0083
0084
0085
0086 for (int a=0; a<nsetPy; a++)
0087 for (int b=0; b<nsetBeamE; b++)
0088 for (int c=0; c<nsetR; c++)
0089 for (int d=0; d<nsetMinPT; d++)
0090 {
0091
0092 const char *finName = Form("%s/pythia%i_%i_r0%i_pT%i.root", path,setPy[a],setBeamE[b],setR[c],setMinPT[d]);
0093 TFile *F = TFile::Open(finName);
0094 TNtuple *T = (TNtuple*)F->Get("ntp_truthjet");
0095 cout <<Form("Open %s from %s...", T->GetName(), F->GetName()) <<endl;
0096
0097
0098 std::vector<int> jetList = searchLeadingJets(T, (float)setMinPT[d]);
0099
0100
0101
0102 float event, geta, gphi, ge, eta, phi, e;
0103 T->SetBranchAddress("event", &event);
0104 T->SetBranchAddress("geta", &geta);
0105 T->SetBranchAddress("gphi", &gphi);
0106 T->SetBranchAddress("ge", &ge);
0107 T->SetBranchAddress("eta", &eta);
0108 T->SetBranchAddress("phi", &phi);
0109 T->SetBranchAddress("e", &e);
0110
0111
0112 for (unsigned int i=0; i<jetList.size(); i++)
0113 {
0114 T->GetEntry(jetList[i]);
0115
0116 int id_eta = -1;
0117 for (int x=0; x<nsetEta; x++) { if (geta > setEta[x] && geta < setEta[x+1]) id_eta = x; }
0118 if (id_eta == -1) continue;
0119
0120 h2[a][b][c][id_eta]->Fill(ge, e/ge);
0121
0122 int id_e = -1;
0123 for (int y=0; y<nsetE; y++) { if (ge > setE[y] && ge < setE[y+1]) id_e = y; }
0124 if (id_e == -1) continue;
0125
0126 if (!strcmp(var, "e")) h1[a][b][c][id_eta][id_e]->Fill(e/ge);
0127 }
0128
0129
0130 T->ResetBranchAddresses();
0131 T->Delete();
0132 F->Delete();
0133 }
0134
0135
0136
0137 gStyle->SetOptStat("e");
0138
0139
0140 TCanvas *c1[nsetPy][nsetBeamE][nsetR];
0141 for (int a=0; a<nsetPy; a++)
0142 for (int b=0; b<nsetBeamE; b++)
0143 for (int c=0; c<nsetR; c++)
0144 {
0145 const char* c1Name = Form("sanity_py%i_%i_r0%i", setPy[a],setBeamE[b],setR[c]);
0146 c1[a][b][c] = new TCanvas(c1Name, c1Name, 1280, 800);
0147 c1[a][b][c]->Divide(nsetEta/2, 2, 0.015, 0.015, 10);
0148 for (int x=0; x<nsetEta; x++)
0149 {
0150 c1[a][b][c]->cd(x+1)->SetGrid();
0151 h2[a][b][c][x]->SetTitle(Form("%2.1f < #eta < %2.1f;True e;Reco e/True e", setEta[x], setEta[x+1]));
0152 h2[a][b][c][x]->GetYaxis()->SetTitleOffset(1.45);
0153 h2[a][b][c][x]->Draw("colz");
0154 }
0155 if (print) c1[a][b][c]->Print(Form("%s%s.png", c1[a][b][c]->GetName(),suffix));
0156 }
0157
0158
0159 TCanvas *c2 = new TCanvas(Form("resol_%s", var), var, 1280, 800);
0160 c2->Divide(nsetEta/2, 2, 0.015, 0.015, 10);
0161 TF1 *f1Gaus = new TF1("f1Gaus", "[0]*TMath::Gaus(x, [1], [2])", -0.2, 0.2);
0162 TLegend *leg1 = new TLegend(0.4, 0.6, 0.9, 0.9);
0163 for (int a=0; a<nsetPy; a++)
0164 for (int b=0; b<nsetBeamE; b++)
0165 for (int c=0; c<nsetR; c++)
0166 for (int x=0; x<nsetEta; x++)
0167 {
0168 TGraphErrors *g1 = new TGraphErrors();
0169 g1->SetName(Form("g1_%s_py%i_%i_r0%i_eta%i_e%i", var,setPy[a],setBeamE[b],setR[c],x));
0170 g1->SetLineColor(2 * (b+1));
0171 g1->SetMarkerColor(2 * (b+1));
0172 g1->SetMarkerSize(1.);
0173 g1->SetMarkerStyle(20 + 4*c);
0174
0175 for (int y=0; y<nsetE; y++)
0176 {
0177 if (h1[a][b][c][x][y]->GetEntries() < 50)
0178 {
0179 h1[a][b][c][x][y]->Delete();
0180 continue;
0181 }
0182 f1Gaus->SetParameters(
0183 h1[a][b][c][x][y]->GetMaximum(),
0184 h1[a][b][c][x][y]->GetMean(),
0185 h1[a][b][c][x][y]->GetRMS()
0186 );
0187 h1[a][b][c][x][y]->Fit(
0188 f1Gaus->GetName(), "QR0", "",
0189 h1[a][b][c][x][y]->GetMean() - h1[a][b][c][x][y]->GetRMS() * 3,
0190 h1[a][b][c][x][y]->GetMean() + h1[a][b][c][x][y]->GetRMS() * 3
0191 );
0192 g1->SetPoint(g1->GetN(), (setE[y]+setE[y+1])/2, f1Gaus->GetParameter(2));
0193 g1->SetPointError(g1->GetN()-1, 0, f1Gaus->GetParError(2));
0194 }
0195
0196 c2->cd(x+1)->SetGrid();
0197 if (a==0 && b==0 && c==0)
0198 {
0199 const char *yTitle = "#sigma (Reco e / True e)";
0200 const char *gTitle = Form("%2.1f < #eta < %2.1f;True e;%s", setEta[x],setEta[x+1], yTitle);
0201 gPad->DrawFrame(20-5, 0.05, 200+5, 0.3, gTitle);
0202 gPad->Modified();
0203 }
0204 if (a==0 && x==0)
0205 {
0206 leg1->AddEntry(g1, Form("PYTHIA%i, #sqrt{s} = %i, R = 0.%i", setPy[a], setBeamE[b], setR[c]), "p");
0207 }
0208 g1->Draw("pe same");
0209 if (a==(nsetPy-1) && b==(nsetBeamE-1) && c==(nsetR-1) && x==0) leg1->Draw("same");
0210 }
0211 if (print) c2->Print(Form("%s%s.png", c2->GetName(),suffix));
0212
0213 return;
0214 }
0215
0216
0217 std::vector<int> searchLeadingJets(TNtuple *T, float cutPT, const char *targetV)
0218 {
0219 std::vector<int> jetList;
0220
0221 float event, gpt, var;
0222 T->SetBranchAddress("event", &event);
0223 if (strcmp("gpt", targetV))
0224 {
0225 T->SetBranchAddress("gpt", &gpt);
0226 cout <<"Search leading jets by using " <<targetV <<endl;
0227 }
0228 T->SetBranchAddress(targetV, &var);
0229
0230
0231 int evtCheck = -1;
0232 int high1_n = -1;
0233 int high2_n = -1;
0234 float high1_v = -1;
0235 float high2_v = -2;
0236
0237 const int allEntries = T->GetEntries();
0238 for (int a=0; a<allEntries; a++)
0239 {
0240
0241
0242
0243
0244
0245
0246 T->GetEntry(a);
0247
0248
0249 float tempPT = (strcmp("gpt", targetV))?gpt:var;
0250 if (tempPT < cutPT) continue;
0251
0252 if (evtCheck != event || a == allEntries)
0253 {
0254 if (high1_n != -1 && high2_n != -1)
0255 {
0256 if (high1_n < high2_n)
0257 {
0258 jetList.push_back(high1_n);
0259 jetList.push_back(high2_n);
0260 }
0261 else
0262 {
0263 jetList.push_back(high2_n);
0264 jetList.push_back(high1_n);
0265 }
0266 }
0267
0268
0269 evtCheck = event;
0270 high1_n = a;
0271 high2_n = -1;
0272 high1_v = var;
0273 high2_v = -1;
0274 }
0275 else
0276 {
0277 if (var > high1_v)
0278 {
0279 high2_n = high1_n;
0280 high2_v = high1_v;
0281 high1_n = a;
0282 high1_v = var;
0283 }
0284 else if (var > high2_v)
0285 {
0286 high2_n = a;
0287 high2_v = var;
0288 }
0289 }
0290 }
0291
0292 T->ResetBranchAddresses();
0293 return jetList;
0294 }