Skip to content

Commit f7c70c5

Browse files
authored
Merge pull request #45418 from bsunanda/Run3-alca247E
Run3-alca247E Modify the macro for getting IsoTrack Calibration for HCAL
2 parents 43d4c02 + 01c1cef commit f7c70c5

File tree

1 file changed

+251
-1
lines changed

1 file changed

+251
-1
lines changed

Calibration/HcalCalibAlgos/macros/CalibFitPlots.C

Lines changed: 251 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@
9494
// Defaults: ratio=true, drawStatBox=false, nmin=100, isRealData=true,
9595
// year=2023, iformat=0, save=0
9696
//
97+
// PlotHistCorrDFactors(infile1, text1, infile2, text2, infile3, text3,
98+
// infile4, text4, infile5, text5, depth, prefixF, ratio,
99+
// drawStatBox, nmin, isRealData, year, iformat, save)
100+
// Defaults: ratio=true, drawStatBox=false, nmin=100, isRealData=true,
101+
// year=2024, iformat=0, save=0
102+
//
97103
// For plotting correction factors including systematics
98104
// PlotHistCorrSys(infilec, conds, text, save)
99105
// Defaults: save=0
@@ -2811,6 +2817,7 @@ void PlotHistCorrFactors(char* infile1,
28112817
}
28122818
}
28132819
}
2820+
28142821
void PlotHistCorr2Factors(char* infile1,
28152822
std::string text1,
28162823
char* infile2,
@@ -2860,7 +2867,7 @@ void PlotHistCorr2Factors(char* infile1,
28602867
int mtype[7] = {20, 24, 22, 23, 21, 25, 33};
28612868
int nbin = etamax - etamin + 1;
28622869
std::vector<TH1D*> hists;
2863-
std::vector<int> entries, htype, depths;
2870+
std::vector<int> entries, htype;
28642871
std::vector<double> fitr;
28652872
char name[100];
28662873
double dy(0);
@@ -3024,6 +3031,249 @@ void PlotHistCorr2Factors(char* infile1,
30243031
}
30253032
}
30263033

3034+
void PlotHistCorrDFactors(char* infile1,
3035+
std::string text1,
3036+
char* infile2,
3037+
std::string text2,
3038+
char* infile3,
3039+
std::string text3,
3040+
char* infile4,
3041+
std::string text4,
3042+
char* infile5,
3043+
std::string text5,
3044+
int depth,
3045+
std::string prefixF,
3046+
bool ratio = true,
3047+
bool drawStatBox = false,
3048+
int nmin = 100,
3049+
bool isRealData = true,
3050+
int year = 2024,
3051+
int iformat = 0,
3052+
int save = 0) {
3053+
std::map<int, cfactors> cfacs[5];
3054+
std::vector<std::string> texts;
3055+
int nfile(0), etamin(100), etamax(-100), maxdepth(0);
3056+
const char* blank("");
3057+
if (infile1 != blank) {
3058+
readCorrFactors(infile1, 1.0, cfacs[nfile], etamin, etamax, maxdepth, iformat);
3059+
if (cfacs[nfile].size() > 0) {
3060+
texts.push_back(text1);
3061+
++nfile;
3062+
}
3063+
}
3064+
if (infile2 != blank) {
3065+
readCorrFactors(infile2, 1.0, cfacs[nfile], etamin, etamax, maxdepth, iformat);
3066+
if (cfacs[nfile].size() > 0) {
3067+
texts.push_back(text2);
3068+
++nfile;
3069+
}
3070+
}
3071+
if (infile3 != blank) {
3072+
readCorrFactors(infile3, 1.0, cfacs[nfile], etamin, etamax, maxdepth, iformat);
3073+
if (cfacs[nfile].size() > 0) {
3074+
texts.push_back(text3);
3075+
++nfile;
3076+
}
3077+
}
3078+
if (infile4 != blank) {
3079+
readCorrFactors(infile4, 1.0, cfacs[nfile], etamin, etamax, maxdepth, iformat);
3080+
if (cfacs[nfile].size() > 0) {
3081+
texts.push_back(text4);
3082+
++nfile;
3083+
}
3084+
}
3085+
if (infile5 != blank) {
3086+
readCorrFactors(infile5, 1.0, cfacs[nfile], etamin, etamax, maxdepth, iformat);
3087+
if (cfacs[nfile].size() > 0) {
3088+
texts.push_back(text5);
3089+
++nfile;
3090+
}
3091+
}
3092+
3093+
if (nfile > 0) {
3094+
gStyle->SetCanvasBorderMode(0);
3095+
gStyle->SetCanvasColor(kWhite);
3096+
gStyle->SetPadColor(kWhite);
3097+
gStyle->SetFillColor(kWhite);
3098+
gStyle->SetOptTitle(0);
3099+
if ((!ratio) && drawStatBox) {
3100+
gStyle->SetOptStat(10);
3101+
gStyle->SetOptFit(10);
3102+
} else {
3103+
gStyle->SetOptStat(0);
3104+
gStyle->SetOptFit(0);
3105+
}
3106+
int colors[7] = {1, 6, 4, 2, 7, 9, 46};
3107+
int mtype[7] = {20, 24, 22, 23, 21, 25, 33};
3108+
int nbin = etamax - etamin + 1;
3109+
std::vector<TH1D*> hists;
3110+
std::vector<int> entries, htype;
3111+
std::vector<double> fitr;
3112+
char name[100];
3113+
double dy(0);
3114+
int fits(0);
3115+
int nline(0);
3116+
if (ratio) {
3117+
for (int ih = 1; ih < nfile; ++ih) {
3118+
sprintf(name, "h%dd%d", ih, depth);
3119+
TObject* ob = gROOT->FindObject(name);
3120+
if (ob)
3121+
ob->Delete();
3122+
TH1D* h = new TH1D(name, name, nbin, etamin, etamax);
3123+
double sumNum(0), sumDen(0);
3124+
std::map<int, cfactors>::const_iterator ktr = cfacs[ih].begin();
3125+
for (std::map<int, cfactors>::const_iterator itr = cfacs[0].begin(); itr != cfacs[0].end(); ++itr, ++ktr) {
3126+
int dep = (itr->second).depth;
3127+
if (dep == depth) {
3128+
int ieta = (itr->second).ieta;
3129+
int bin = ieta - etamin + 1;
3130+
float val = (itr->second).corrf / (ktr->second).corrf;
3131+
float dvl =
3132+
val * sqrt((((itr->second).dcorr * (itr->second).dcorr) / ((itr->second).corrf * (itr->second).corrf)) +
3133+
(((ktr->second).dcorr * (ktr->second).dcorr) / ((ktr->second).corrf * (ktr->second).corrf)));
3134+
h->SetBinContent(bin, val);
3135+
h->SetBinError(bin, dvl);
3136+
sumNum += (val / (dvl * dvl));
3137+
sumDen += (1.0 / (dvl * dvl));
3138+
}
3139+
}
3140+
double fit = (sumDen > 0) ? (sumNum / sumDen) : 1.0;
3141+
std::cout << "Fit to Pol0: " << fit << std::endl;
3142+
h->SetLineColor(colors[ih]);
3143+
h->SetMarkerColor(colors[ih]);
3144+
h->SetMarkerStyle(mtype[depth - 1]);
3145+
h->SetMarkerSize(0.9);
3146+
h->GetXaxis()->SetTitle("i#eta");
3147+
if (nfile > 2)
3148+
sprintf(name, "CF_{%s}/CF_{Set}", texts[0].c_str());
3149+
else
3150+
sprintf(name, "CF_{%s}/CF_{%s}", texts[0].c_str(), texts[ih].c_str());
3151+
h->GetYaxis()->SetTitle(name);
3152+
h->GetYaxis()->SetLabelOffset(0.005);
3153+
h->GetYaxis()->SetTitleSize(0.036);
3154+
h->GetYaxis()->SetTitleOffset(1.20);
3155+
h->GetYaxis()->SetRangeUser(0.50, 1.50);
3156+
hists.push_back(h);
3157+
fitr.push_back(fit);
3158+
htype.push_back(ih);
3159+
++nline;
3160+
}
3161+
} else {
3162+
for (int k1 = 0; k1 < nfile; ++k1) {
3163+
sprintf(name, "h%dd%d", k1, depth);
3164+
TObject* ob = gROOT->FindObject(name);
3165+
if (ob)
3166+
ob->Delete();
3167+
TH1D* h = new TH1D(name, name, nbin, etamin, etamax);
3168+
int nent(0);
3169+
for (std::map<int, cfactors>::const_iterator itr = cfacs[k1].begin(); itr != cfacs[k1].end(); ++itr) {
3170+
int dep = (itr->second).depth;
3171+
if (dep == depth) {
3172+
int ieta = (itr->second).ieta;
3173+
int bin = ieta - etamin + 1;
3174+
float val = (itr->second).corrf;
3175+
float dvl = (itr->second).dcorr;
3176+
h->SetBinContent(bin, val);
3177+
h->SetBinError(bin, dvl);
3178+
nent++;
3179+
}
3180+
}
3181+
if (nent > nmin) {
3182+
fits++;
3183+
if (drawStatBox)
3184+
dy += 0.025;
3185+
sprintf(name, "h%ddf%d", k1, depth);
3186+
TObject* ob = gROOT->FindObject(name);
3187+
if (ob)
3188+
ob->Delete();
3189+
TF1* func = new TF1(name, "pol0", etamin, etamax);
3190+
h->Fit(func, "+QWLR", "");
3191+
}
3192+
h->SetLineColor(colors[k1]);
3193+
h->SetMarkerColor(colors[k1]);
3194+
h->SetMarkerStyle(mtype[depth - 1]);
3195+
h->SetMarkerSize(0.9);
3196+
h->GetXaxis()->SetTitle("i#eta");
3197+
h->GetYaxis()->SetTitle("Correction Factor");
3198+
h->GetYaxis()->SetLabelOffset(0.005);
3199+
h->GetYaxis()->SetTitleOffset(1.20);
3200+
h->GetYaxis()->SetRangeUser(0.5, 1.5);
3201+
hists.push_back(h);
3202+
entries.push_back(nent);
3203+
if (drawStatBox)
3204+
dy += 0.025;
3205+
htype.push_back(k1);
3206+
++nline;
3207+
}
3208+
}
3209+
if (ratio)
3210+
sprintf(name, "c_Corr%sRatioD%d", prefixF.c_str(), depth);
3211+
else
3212+
sprintf(name, "c_Corr%sD%d", prefixF.c_str(), depth);
3213+
TCanvas* pad = new TCanvas(name, name, 700, 500);
3214+
pad->SetRightMargin(0.10);
3215+
pad->SetTopMargin(0.10);
3216+
double yh = 0.90;
3217+
double yl = yh - 0.035 * hists.size() - dy - 0.01;
3218+
TLegend* legend = new TLegend(0.45, yl, 0.90, yl + 0.035 * nline);
3219+
legend->SetFillColor(kWhite);
3220+
for (unsigned int k = 0; k < hists.size(); ++k) {
3221+
if (k == 0)
3222+
hists[k]->Draw("");
3223+
else
3224+
hists[k]->Draw("sames");
3225+
pad->Update();
3226+
int k1 = htype[k];
3227+
if (!ratio) {
3228+
TPaveStats* st1 = (TPaveStats*)hists[k]->GetListOfFunctions()->FindObject("stats");
3229+
if (st1 != nullptr) {
3230+
dy = (entries[k] > nmin) ? 0.05 : 0.025;
3231+
st1->SetLineColor(colors[k1]);
3232+
st1->SetTextColor(colors[k1]);
3233+
st1->SetY1NDC(yh - dy);
3234+
st1->SetY2NDC(yh);
3235+
st1->SetX1NDC(0.70);
3236+
st1->SetX2NDC(0.90);
3237+
yh -= dy;
3238+
}
3239+
sprintf(name, "Depth %d (%s)", depth, texts[k1].c_str());
3240+
} else {
3241+
sprintf(name, "Depth %d (Mean[CF_{%s}/CF_{%s}] = %5.3f)", depth, text1.c_str(), texts[k1].c_str(), fitr[k]);
3242+
}
3243+
legend->AddEntry(hists[k], name, "lp");
3244+
}
3245+
legend->Draw("same");
3246+
TPaveText* txt0 = new TPaveText(0.11, 0.84, 0.45, 0.89, "blNDC");
3247+
txt0->SetFillColor(0);
3248+
char txt[40];
3249+
if (isRealData)
3250+
sprintf(txt, "CMS Preliminary (%d)", year);
3251+
else
3252+
sprintf(txt, "CMS Simulation Preliminary (%d)", year);
3253+
txt0->AddText(txt);
3254+
txt0->Draw("same");
3255+
pad->Update();
3256+
if (fits < 1) {
3257+
double xmin = hists[0]->GetBinLowEdge(1);
3258+
int nbin = hists[0]->GetNbinsX();
3259+
double xmax = hists[0]->GetBinLowEdge(nbin) + hists[0]->GetBinWidth(nbin);
3260+
TLine* line = new TLine(xmin, 1.0, xmax, 1.0);
3261+
line->SetLineColor(9);
3262+
line->SetLineWidth(2);
3263+
line->SetLineStyle(2);
3264+
line->Draw("same");
3265+
pad->Update();
3266+
}
3267+
if (save > 0) {
3268+
sprintf(name, "%s.pdf", pad->GetName());
3269+
pad->Print(name);
3270+
} else if (save < 0) {
3271+
sprintf(name, "%s.C", pad->GetName());
3272+
pad->Print(name);
3273+
}
3274+
}
3275+
}
3276+
30273277
void PlotHistCorrSys(std::string infilec, int conds, std::string text, int save = 0) {
30283278
char fname[100];
30293279
int iformat(0);

0 commit comments

Comments
 (0)