|
65 | 65 | // |
66 | 66 | // For plotting correction factors |
67 | 67 | // PlotHistCorrFactor(infile, text, prefixF, scale, nmin, isRealData, |
68 | | -// drawStatBox, iformat, save); |
| 68 | +// drawStatBox, iformat, save); |
| 69 | +// Defaults: isRealData=true, drwaStatBox=false, nmin=100, iformat=0, |
| 70 | +// save=0 |
| 71 | +// |
| 72 | +// For plotting correction factors for a sigle depth |
| 73 | +// PlotHistCorrFactor(infile, text, depth, prefixF, scale, nmin, isRealData, |
| 74 | +// drawStatBox, iformat, save); |
69 | 75 | // Defaults: isRealData=true, drwaStatBox=false, nmin=100, iformat=0, |
70 | 76 | // save=0 |
71 | 77 | // |
|
83 | 89 | // Defaults: ratio=false, drawStatBox=true, nmin=100, isRealData=false, |
84 | 90 | // year=2018, iformat=0, save=0 |
85 | 91 | // |
| 92 | +// PlotHistCorr2Factors(infile1, text1, infile2, text2, depth, prefixF, ratio, |
| 93 | +// drawStatBox, nmin, isRealData, year, iformat, save) |
| 94 | +// Defaults: ratio=true, drawStatBox=false, nmin=100, isRealData=true, |
| 95 | +// year=2023, iformat=0, save=0 |
| 96 | +// |
86 | 97 | // For plotting correction factors including systematics |
87 | 98 | // PlotHistCorrSys(infilec, conds, text, save) |
88 | 99 | // Defaults: save=0 |
@@ -2163,11 +2174,11 @@ void PlotHistCorrResults(std::string infile, std::string text, std::string prefi |
2163 | 2174 |
|
2164 | 2175 | void PlotHistCorrFactor(char* infile, |
2165 | 2176 | std::string text, |
2166 | | - std::string prefixF = "", |
| 2177 | + std::string prefixF, |
2167 | 2178 | double scale = 1.0, |
2168 | 2179 | int nmin = 100, |
2169 | | - bool isRealData = false, |
2170 | | - bool drawStatBox = true, |
| 2180 | + bool isRealData = true, |
| 2181 | + bool drawStatBox = false, |
2171 | 2182 | int iformat = 0, |
2172 | 2183 | int save = 0) { |
2173 | 2184 | std::map<int, cfactors> cfacs; |
@@ -2292,6 +2303,139 @@ void PlotHistCorrFactor(char* infile, |
2292 | 2303 | } |
2293 | 2304 | } |
2294 | 2305 |
|
| 2306 | +void PlotHistCorrFactor(char* infile, |
| 2307 | + std::string text, |
| 2308 | + int depth, |
| 2309 | + std::string prefixF, |
| 2310 | + double scale = 1.0, |
| 2311 | + int nmin = 100, |
| 2312 | + bool isRealData = true, |
| 2313 | + bool drawStatBox = false, |
| 2314 | + int iformat = 0, |
| 2315 | + int save = 0) { |
| 2316 | + std::map<int, cfactors> cfacs; |
| 2317 | + int etamin(100), etamax(-100), maxdepth(0); |
| 2318 | + readCorrFactors(infile, scale, cfacs, etamin, etamax, maxdepth, iformat); |
| 2319 | + |
| 2320 | + gStyle->SetCanvasBorderMode(0); |
| 2321 | + gStyle->SetCanvasColor(kWhite); |
| 2322 | + gStyle->SetPadColor(kWhite); |
| 2323 | + gStyle->SetFillColor(kWhite); |
| 2324 | + gStyle->SetOptTitle(0); |
| 2325 | + if (drawStatBox) { |
| 2326 | + gStyle->SetOptStat(10); |
| 2327 | + gStyle->SetOptFit(10); |
| 2328 | + } else { |
| 2329 | + gStyle->SetOptStat(0); |
| 2330 | + gStyle->SetOptFit(0); |
| 2331 | + } |
| 2332 | + int colors[7] = {1, 6, 4, 7, 2, 9, 3}; |
| 2333 | + int mtype[7] = {20, 21, 22, 23, 24, 33, 25}; |
| 2334 | + int nbin = etamax - etamin + 1; |
| 2335 | + std::vector<TH1D*> hists; |
| 2336 | + std::vector<int> entries; |
| 2337 | + char name[100]; |
| 2338 | + double dy(0); |
| 2339 | + int fits(0); |
| 2340 | + sprintf(name, "hd%d", depth); |
| 2341 | + TH1D* h = new TH1D(name, name, nbin, etamin, etamax); |
| 2342 | + int nent(0); |
| 2343 | + for (std::map<int, cfactors>::const_iterator itr = cfacs.begin(); itr != cfacs.end(); ++itr) { |
| 2344 | + if ((itr->second).depth == depth) { |
| 2345 | + int ieta = (itr->second).ieta; |
| 2346 | + int bin = ieta - etamin + 1; |
| 2347 | + float val = (itr->second).corrf; |
| 2348 | + float dvl = (itr->second).dcorr; |
| 2349 | + h->SetBinContent(bin, val); |
| 2350 | + h->SetBinError(bin, dvl); |
| 2351 | + nent++; |
| 2352 | + } |
| 2353 | + } |
| 2354 | + if (nent > nmin) { |
| 2355 | + fits++; |
| 2356 | + dy += 0.025; |
| 2357 | + sprintf(name, "hdf%d", depth); |
| 2358 | + TF1* func = new TF1(name, "pol0", etamin, etamax); |
| 2359 | + h->Fit(func, "+QWLR", ""); |
| 2360 | + } |
| 2361 | + h->SetLineColor(colors[depth - 1]); |
| 2362 | + h->SetMarkerColor(colors[depth - 1]); |
| 2363 | + h->SetMarkerStyle(mtype[depth - 1]); |
| 2364 | + h->GetXaxis()->SetTitle("i#eta"); |
| 2365 | + h->GetYaxis()->SetTitle("Correction Factor"); |
| 2366 | + h->GetYaxis()->SetLabelOffset(0.005); |
| 2367 | + h->GetYaxis()->SetTitleOffset(1.20); |
| 2368 | + h->GetYaxis()->SetRangeUser(0.0, 2.0); |
| 2369 | + hists.push_back(h); |
| 2370 | + entries.push_back(nent); |
| 2371 | + dy += 0.025; |
| 2372 | + |
| 2373 | + sprintf(name, "c_%sD%dCorrFactor", prefixF.c_str(), depth); |
| 2374 | + TCanvas* pad = new TCanvas(name, name, 700, 500); |
| 2375 | + pad->SetRightMargin(0.10); |
| 2376 | + pad->SetTopMargin(0.10); |
| 2377 | + double yh = 0.90; |
| 2378 | + // double yl = yh - 0.025 * hists.size() - dy - 0.01; |
| 2379 | + double yl = 0.15; |
| 2380 | + TLegend* legend = new TLegend(0.35, yl, 0.85, yl + 0.04 * hists.size()); |
| 2381 | + legend->SetFillColor(kWhite); |
| 2382 | + for (unsigned int k = 0; k < hists.size(); ++k) { |
| 2383 | + if (k == 0) |
| 2384 | + hists[k]->Draw(""); |
| 2385 | + else |
| 2386 | + hists[k]->Draw("sames"); |
| 2387 | + pad->Update(); |
| 2388 | + if (drawStatBox) { |
| 2389 | + TPaveStats* st1 = (TPaveStats*)hists[k]->GetListOfFunctions()->FindObject("stats"); |
| 2390 | + if (st1 != nullptr) { |
| 2391 | + dy = (entries[k] > nmin) ? 0.05 : 0.025; |
| 2392 | + st1->SetLineColor(colors[k]); |
| 2393 | + st1->SetTextColor(colors[k]); |
| 2394 | + st1->SetY1NDC(yh - dy); |
| 2395 | + st1->SetY2NDC(yh); |
| 2396 | + st1->SetX1NDC(0.70); |
| 2397 | + st1->SetX2NDC(0.90); |
| 2398 | + yh -= dy; |
| 2399 | + } |
| 2400 | + } |
| 2401 | + sprintf(name, "Depth %d (%s)", depth, text.c_str()); |
| 2402 | + legend->AddEntry(hists[k], name, "lp"); |
| 2403 | + } |
| 2404 | + legend->Draw("same"); |
| 2405 | + pad->Update(); |
| 2406 | + if (fits < 1) { |
| 2407 | + double xmin = hists[0]->GetBinLowEdge(1); |
| 2408 | + int nbin = hists[0]->GetNbinsX(); |
| 2409 | + double xmax = hists[0]->GetBinLowEdge(nbin) + hists[0]->GetBinWidth(nbin); |
| 2410 | + TLine* line = new TLine(xmin, 1.0, xmax, 1.0); |
| 2411 | + line->SetLineColor(9); |
| 2412 | + line->SetLineWidth(2); |
| 2413 | + line->SetLineStyle(2); |
| 2414 | + line->Draw("same"); |
| 2415 | + pad->Modified(); |
| 2416 | + pad->Update(); |
| 2417 | + } |
| 2418 | + char txt1[30]; |
| 2419 | + double xmax = (isRealData) ? 0.33 : 0.44; |
| 2420 | + TPaveText* txt2 = new TPaveText(0.11, 0.85, xmax, 0.89, "blNDC"); |
| 2421 | + txt2->SetFillColor(0); |
| 2422 | + if (isRealData) |
| 2423 | + sprintf(txt1, "CMS Preliminary"); |
| 2424 | + else |
| 2425 | + sprintf(txt1, "CMS Simulation Preliminary"); |
| 2426 | + txt2->AddText(txt1); |
| 2427 | + txt2->Draw("same"); |
| 2428 | + pad->Modified(); |
| 2429 | + pad->Update(); |
| 2430 | + if (save > 0) { |
| 2431 | + sprintf(name, "%s.pdf", pad->GetName()); |
| 2432 | + pad->Print(name); |
| 2433 | + } else if (save < 0) { |
| 2434 | + sprintf(name, "%s.C", pad->GetName()); |
| 2435 | + pad->Print(name); |
| 2436 | + } |
| 2437 | +} |
| 2438 | + |
2295 | 2439 | void PlotHistCorrAsymmetry(char* infile, std::string text, std::string prefixF = "", int iformat = 0, int save = 0) { |
2296 | 2440 | std::map<int, cfactors> cfacs; |
2297 | 2441 | int etamin(100), etamax(-100), maxdepth(0); |
@@ -2628,6 +2772,207 @@ void PlotHistCorrFactors(char* infile1, |
2628 | 2772 | } |
2629 | 2773 | } |
2630 | 2774 | } |
| 2775 | +void PlotHistCorr2Factors(char* infile1, |
| 2776 | + std::string text1, |
| 2777 | + char* infile2, |
| 2778 | + std::string text2, |
| 2779 | + int depth, |
| 2780 | + std::string prefixF, |
| 2781 | + bool ratio = true, |
| 2782 | + bool drawStatBox = false, |
| 2783 | + int nmin = 100, |
| 2784 | + bool isRealData = true, |
| 2785 | + int year = 2023, |
| 2786 | + int iformat = 0, |
| 2787 | + int save = 0) { |
| 2788 | + std::map<int, cfactors> cfacs[5]; |
| 2789 | + std::vector<std::string> texts; |
| 2790 | + int nfile(0), etamin(100), etamax(-100), maxdepth(0); |
| 2791 | + const char* blank(""); |
| 2792 | + if (infile1 != blank) { |
| 2793 | + readCorrFactors(infile1, 1.0, cfacs[nfile], etamin, etamax, maxdepth, iformat); |
| 2794 | + if (cfacs[nfile].size() > 0) { |
| 2795 | + texts.push_back(text1); |
| 2796 | + ++nfile; |
| 2797 | + } |
| 2798 | + } |
| 2799 | + if (infile2 != blank) { |
| 2800 | + readCorrFactors(infile2, 1.0, cfacs[nfile], etamin, etamax, maxdepth, iformat); |
| 2801 | + if (cfacs[nfile].size() > 0) { |
| 2802 | + texts.push_back(text2); |
| 2803 | + ++nfile; |
| 2804 | + } |
| 2805 | + } |
| 2806 | + |
| 2807 | + if (nfile > 0) { |
| 2808 | + gStyle->SetCanvasBorderMode(0); |
| 2809 | + gStyle->SetCanvasColor(kWhite); |
| 2810 | + gStyle->SetPadColor(kWhite); |
| 2811 | + gStyle->SetFillColor(kWhite); |
| 2812 | + gStyle->SetOptTitle(0); |
| 2813 | + if ((!ratio) && drawStatBox) { |
| 2814 | + gStyle->SetOptStat(10); |
| 2815 | + gStyle->SetOptFit(10); |
| 2816 | + } else { |
| 2817 | + gStyle->SetOptStat(0); |
| 2818 | + gStyle->SetOptFit(0); |
| 2819 | + } |
| 2820 | + int colors[7] = {1, 6, 4, 2, 7, 9, 46}; |
| 2821 | + int mtype[7] = {20, 24, 22, 23, 21, 25, 33}; |
| 2822 | + int nbin = etamax - etamin + 1; |
| 2823 | + std::vector<TH1D*> hists; |
| 2824 | + std::vector<int> entries, htype, depths; |
| 2825 | + std::vector<double> fitr; |
| 2826 | + char name[100]; |
| 2827 | + double dy(0); |
| 2828 | + int fits(0); |
| 2829 | + int nline(0); |
| 2830 | + if (ratio) { |
| 2831 | + for (int ih = 1; ih < nfile; ++ih) { |
| 2832 | + sprintf(name, "h%dd%d", ih, depth); |
| 2833 | + TH1D* h = new TH1D(name, name, nbin, etamin, etamax); |
| 2834 | + double sumNum(0), sumDen(0); |
| 2835 | + std::map<int, cfactors>::const_iterator ktr = cfacs[ih].begin(); |
| 2836 | + for (std::map<int, cfactors>::const_iterator itr = cfacs[0].begin(); itr != cfacs[0].end(); ++itr, ++ktr) { |
| 2837 | + int dep = (itr->second).depth; |
| 2838 | + if (dep == depth) { |
| 2839 | + int ieta = (itr->second).ieta; |
| 2840 | + int bin = ieta - etamin + 1; |
| 2841 | + float val = (itr->second).corrf / (ktr->second).corrf; |
| 2842 | + float dvl = val * sqrt((((itr->second).dcorr * (itr->second).dcorr) / ((itr->second).corrf * (itr->second).corrf)) + (((ktr->second).dcorr * (ktr->second).dcorr) / ((ktr->second).corrf * (ktr->second).corrf))); |
| 2843 | + h->SetBinContent(bin, val); |
| 2844 | + h->SetBinError(bin, dvl); |
| 2845 | + sumNum += (val / (dvl * dvl)); |
| 2846 | + sumDen += (1.0 / (dvl * dvl)); |
| 2847 | + } |
| 2848 | + } |
| 2849 | + double fit = (sumDen > 0) ? (sumNum / sumDen) : 1.0; |
| 2850 | + std::cout << "Fit to Pol0: " << fit << std::endl; |
| 2851 | + h->SetLineColor(colors[ih]); |
| 2852 | + h->SetMarkerColor(colors[ih]); |
| 2853 | + h->SetMarkerStyle(mtype[depth - 1]); |
| 2854 | + h->SetMarkerSize(0.9); |
| 2855 | + h->GetXaxis()->SetTitle("i#eta"); |
| 2856 | + sprintf(name, "CF_{%s}/CF_{%s}", texts[0].c_str(), texts[1].c_str()); |
| 2857 | + h->GetYaxis()->SetTitle(name); |
| 2858 | + h->GetYaxis()->SetLabelOffset(0.005); |
| 2859 | + h->GetYaxis()->SetTitleSize(0.036); |
| 2860 | + h->GetYaxis()->SetTitleOffset(1.20); |
| 2861 | + h->GetYaxis()->SetRangeUser(0.50, 1.50); |
| 2862 | + hists.push_back(h); |
| 2863 | + fitr.push_back(fit); |
| 2864 | + htype.push_back(ih); |
| 2865 | + ++nline; |
| 2866 | + } |
| 2867 | + } else { |
| 2868 | + for (int k1 = 0; k1 < nfile; ++k1) { |
| 2869 | + sprintf(name, "h%dd%d", k1, depth); |
| 2870 | + TH1D* h = new TH1D(name, name, nbin, etamin, etamax); |
| 2871 | + int nent(0); |
| 2872 | + for (std::map<int, cfactors>::const_iterator itr = cfacs[k1].begin(); itr != cfacs[k1].end(); ++itr) { |
| 2873 | + int dep = (itr->second).depth; |
| 2874 | + if (dep == depth) { |
| 2875 | + int ieta = (itr->second).ieta; |
| 2876 | + int bin = ieta - etamin + 1; |
| 2877 | + float val = (itr->second).corrf; |
| 2878 | + float dvl = (itr->second).dcorr; |
| 2879 | + h->SetBinContent(bin, val); |
| 2880 | + h->SetBinError(bin, dvl); |
| 2881 | + nent++; |
| 2882 | + } |
| 2883 | + } |
| 2884 | + if (nent > nmin) { |
| 2885 | + fits++; |
| 2886 | + if (drawStatBox) |
| 2887 | + dy += 0.025; |
| 2888 | + sprintf(name, "h%ddf%d", k1, depth); |
| 2889 | + TF1* func = new TF1(name, "pol0", etamin, etamax); |
| 2890 | + h->Fit(func, "+QWLR", ""); |
| 2891 | + } |
| 2892 | + h->SetLineColor(colors[k1]); |
| 2893 | + h->SetMarkerColor(colors[k1]); |
| 2894 | + h->SetMarkerStyle(mtype[depth - 1]); |
| 2895 | + h->SetMarkerSize(0.9); |
| 2896 | + h->GetXaxis()->SetTitle("i#eta"); |
| 2897 | + h->GetYaxis()->SetTitle("Correction Factor"); |
| 2898 | + h->GetYaxis()->SetLabelOffset(0.005); |
| 2899 | + h->GetYaxis()->SetTitleOffset(1.20); |
| 2900 | + h->GetYaxis()->SetRangeUser(0.5, 1.5); |
| 2901 | + hists.push_back(h); |
| 2902 | + entries.push_back(nent); |
| 2903 | + if (drawStatBox) |
| 2904 | + dy += 0.025; |
| 2905 | + htype.push_back(k1); |
| 2906 | + } |
| 2907 | + ++nline; |
| 2908 | + } |
| 2909 | + if (ratio) |
| 2910 | + sprintf(name, "c_Corr%sD%dRatio", prefixF.c_str(), depth); |
| 2911 | + else |
| 2912 | + sprintf(name, "c_Corr%sD%d", prefixF.c_str(), depth); |
| 2913 | + TCanvas* pad = new TCanvas(name, name, 700, 500); |
| 2914 | + pad->SetRightMargin(0.10); |
| 2915 | + pad->SetTopMargin(0.10); |
| 2916 | + double yh = 0.90; |
| 2917 | + double yl = yh - 0.035 * hists.size() - dy - 0.01; |
| 2918 | + TLegend* legend = new TLegend(0.45, yl, 0.90, yl + 0.035 * nline); |
| 2919 | + legend->SetFillColor(kWhite); |
| 2920 | + for (unsigned int k = 0; k < hists.size(); ++k) { |
| 2921 | + if (k == 0) |
| 2922 | + hists[k]->Draw(""); |
| 2923 | + else |
| 2924 | + hists[k]->Draw("sames"); |
| 2925 | + pad->Update(); |
| 2926 | + int k1 = htype[k]; |
| 2927 | + if (!ratio) { |
| 2928 | + TPaveStats* st1 = (TPaveStats*)hists[k]->GetListOfFunctions()->FindObject("stats"); |
| 2929 | + if (st1 != nullptr) { |
| 2930 | + dy = (entries[k] > nmin) ? 0.05 : 0.025; |
| 2931 | + st1->SetLineColor(colors[k1]); |
| 2932 | + st1->SetTextColor(colors[k1]); |
| 2933 | + st1->SetY1NDC(yh - dy); |
| 2934 | + st1->SetY2NDC(yh); |
| 2935 | + st1->SetX1NDC(0.70); |
| 2936 | + st1->SetX2NDC(0.90); |
| 2937 | + yh -= dy; |
| 2938 | + } |
| 2939 | + sprintf(name, "Depth %d (%s)", depth, texts[k1].c_str()); |
| 2940 | + } else { |
| 2941 | + sprintf(name, "Depth %d (Mean[CF_{%s}/CF_{%s}] = %5.3f)", depth, text1.c_str(), texts[k1].c_str(), fitr[k]); |
| 2942 | + } |
| 2943 | + legend->AddEntry(hists[k], name, "lp"); |
| 2944 | + } |
| 2945 | + legend->Draw("same"); |
| 2946 | + TPaveText* txt0 = new TPaveText(0.11, 0.84, 0.45, 0.89, "blNDC"); |
| 2947 | + txt0->SetFillColor(0); |
| 2948 | + char txt[40]; |
| 2949 | + if (isRealData) |
| 2950 | + sprintf(txt, "CMS Preliminary (%d)", year); |
| 2951 | + else |
| 2952 | + sprintf(txt, "CMS Simulation Preliminary (%d)", year); |
| 2953 | + txt0->AddText(txt); |
| 2954 | + txt0->Draw("same"); |
| 2955 | + pad->Update(); |
| 2956 | + if (fits < 1) { |
| 2957 | + double xmin = hists[0]->GetBinLowEdge(1); |
| 2958 | + int nbin = hists[0]->GetNbinsX(); |
| 2959 | + double xmax = hists[0]->GetBinLowEdge(nbin) + hists[0]->GetBinWidth(nbin); |
| 2960 | + TLine* line = new TLine(xmin, 1.0, xmax, 1.0); |
| 2961 | + line->SetLineColor(9); |
| 2962 | + line->SetLineWidth(2); |
| 2963 | + line->SetLineStyle(2); |
| 2964 | + line->Draw("same"); |
| 2965 | + pad->Update(); |
| 2966 | + } |
| 2967 | + if (save > 0) { |
| 2968 | + sprintf(name, "%s.pdf", pad->GetName()); |
| 2969 | + pad->Print(name); |
| 2970 | + } else if (save < 0) { |
| 2971 | + sprintf(name, "%s.C", pad->GetName()); |
| 2972 | + pad->Print(name); |
| 2973 | + } |
| 2974 | + } |
| 2975 | +} |
2631 | 2976 |
|
2632 | 2977 | void PlotHistCorrSys(std::string infilec, int conds, std::string text, int save = 0) { |
2633 | 2978 | char fname[100]; |
|
0 commit comments