const int textFont = 22; // TNewRoman const bool divide = 0; // = 0 - each histo in separate file\screen. = 1 - all in one file\screen void makeUpHisto(TH1* histo, TString title) { if (histo){ TF1 *fit = new TF1("fit","gaus"); fit->SetLineColor(2); fit->SetLineWidth(3); histo->Fit("fit","","",histo->GetXaxis()->GetXmin(),histo->GetXaxis()->GetXmax()); histo->GetXaxis()->SetLabelFont(textFont); histo->GetXaxis()->SetTitleFont(textFont); histo->GetYaxis()->SetLabelFont(textFont); histo->GetYaxis()->SetTitleFont(textFont); histo->GetXaxis()->SetTitle(title); histo->GetXaxis()->SetTitleOffset(1); histo->GetYaxis()->SetTitle("Entries"); histo->GetYaxis()->SetTitleOffset(1.05); // good then entries per bit <= 9999 } else{ std::cout << " E: Read histos error! " << std::endl; } } void makeUpProfile(TProfile* prof, TString titleX, TString titleY) { if (prof){ prof->SetMarkerColor(kRed); prof->SetLineColor(kRed); prof->GetXaxis()->SetTitle(titleX); prof->GetXaxis()->SetTitleOffset(1); prof->GetYaxis()->SetTitle(titleY); prof->GetYaxis()->SetTitleOffset(0.85); prof->GetXaxis()->SetLabelFont(textFont); prof->GetXaxis()->SetTitleFont(textFont); prof->GetYaxis()->SetLabelFont(textFont); prof->GetYaxis()->SetTitleFont(textFont); } else{ std::cout << " E: Read profile error! " << std::endl; } } void Draw_L1_histo() { // ============================ Set Styles ============================ TStyle *histoStyle = new TStyle("histoStyle","Plain Style(no colors/fill areas)"); // TStyle *histoStyle = gStyle; histoStyle->SetTextFont(textFont); histoStyle->SetPadColor(0); histoStyle->SetCanvasColor(0); histoStyle->SetTitleColor(0); histoStyle->SetStatColor(0); histoStyle->SetOptTitle(0); // without main up title histoStyle->SetOptStat(1000000010); // The parameter mode can be = ksiourmen (default = 000001111) // k = 1; kurtosis printed // k = 2; kurtosis and kurtosis error printed // s = 1; skewness printed // s = 2; skewness and skewness error printed // i = 1; integral of bins printed // o = 1; number of overflows printed // u = 1; number of underflows printed // r = 1; rms printed // r = 2; rms and rms error printed // m = 1; mean value printed // m = 2; mean and mean error values printed // e = 1; number of entries printed // n = 1; name of histogram is printed histoStyle->SetOptFit(10001); // The parameter mode can be = pcev (default = 0111) // p = 1; print Probability // c = 1; print Chisquare/Number of degress of freedom // e = 1; print errors (if e=1, v must be 1) // v = 1; print name/values of parameters histoStyle->SetStatW(0.175); histoStyle->SetStatH(0.02); histoStyle->SetStatX(0.95); histoStyle->SetStatY(0.97); histoStyle->SetStatFontSize(0.05); histoStyle->SetStatFont(textFont); TStyle *profStyle = new TStyle("profStyle","Plain Style(no colors/fill areas)"); // TStyle *profStyle = gStyle; profStyle->SetTextFont(textFont); profStyle->SetPadColor(0); profStyle->SetCanvasColor(0); profStyle->SetTitleColor(0); profStyle->SetStatColor(0); profStyle->SetOptTitle(0); // without main up title profStyle->SetOptStat(0); profStyle->SetOptFit(0); // ============================ Open file ============================ const TString fileName = "L1_histo.root"; TFile *fileIn = new TFile(fileName.Data(),"read"); FILE *ress, *pulls; ress = fopen("resolution.txt","w"); pulls = fopen("pull.txt","w"); // ------------ make histos ----------- // ------------ tracks ----------- TString dirFitName = "/L1/Fit"; dirFitName = fileName + ":" + dirFitName; TDirectory *dirFit = fileIn->Get(dirFitName); const int nHisto = 10; struct THistoData { char *name; // one, which used in input file char *title; // for X-axis }; const THistoData histoData[nHisto] = { {"fst_pQP", "Pull q/p" } {"fst_ptx", "Pull t_{x}" } {"fst_pty", "Pull t_{y}" } {"fst_px", "Pull x" } {"fst_py", "Pull y" } {"fst_P", "Resolution (p^{reco}-p^{mc})/p^{mc}" } {"fst_tx", "Residual (t_{x}^{reco}-t_{x}^{mc}) [mrad]" } {"fst_ty", "Residual (t_{y}^{reco}-t_{y}^{mc}) [mrad]" } {"fst_x", "Residual (x^{reco}-x^{mc}) [#mum]" } {"fst_y", "Residual (y^{reco}-y^{mc}) [#mum]" } }; TH1F *histo[nHisto]; for (int i = 0; i < nHisto; i++){ histo[i] = (TH1F*) dirFit->Get(histoData[i].name); makeUpHisto(histo[i],histoData[i].title); } // ------------ hits, strips ----------- TString dirInputName = "/L1/Input"; dirInputName = fileName + ":" + dirInputName; TDirectory *dirInput = fileIn->Get(dirInputName); const int nHisto2 = 4; const THistoData histoData2[nHisto] = { {"Px", "Pull x" } {"Py", "Pull y" } {"x", "Residual (x^{hit}-x^{mc}) [#mum]" } {"y", "Residual (y^{hit}-y^{mc}) [#mum]" } }; TH1F *histo2[nHisto2]; for (int i = 0; i < nHisto2; i++){ histo2[i] = (TH1F*) dirInput->Get(histoData2[i].name); makeUpHisto(histo2[i],histoData2[i].title); } // ------------ make profiles ----------- TString dirName = "/L1"; dirName = fileName + ":" + dirName; TDirectory *dir = fileIn->Get(dirName); const int nProf = 1; struct TProfData { char *name; // one, which used in input file char *titleX; // for X-axis char *titleY; // for Y-axis }; const TProfData profData[nProf] = { {"p_eff_all_vs_mom", "Momentum [GeV/c]", "Efficiency [%]" } }; TProfile *profile[nProf]; for (int i = 0; i < nProf; i++){ profile[i] = (TProfile*) dir->Get(profData[i].name); makeUpProfile(profile[i], profData[i].titleX, profData[i].titleY); } // ============================ Draw ============================ // TCanvas *c1; // c1 = new TCanvas("c1","c1",0,0,1200,800); // c1 -> Divide(nHisto); // // c1->UseCurrentStyle(); // // for (int i = 0; i < nHisto; i++){ // c1->cd(i+1); // histo[i]->Draw(); // } // c1->SaveAs("histo.png"); const int nParts = 2; int iPart = 1; histoStyle->cd(); TCanvas *c2; if (!divide) c2 = new TCanvas("c2","c2",0,0,900,600); else c2 = new TCanvas("c2","c2",0,0,900*nParts,600*nParts); if (divide) c2->Divide(nParts, nParts); histoStyle->cd(); c2->cd(); for (int i = 0; i < nHisto; i++){ if (divide) c2->cd(iPart++); histo[i]->Draw(); TString name = TString(histoData[i].name)+".pdf"; if (!divide) c2->SaveAs(name); } for (int i = 0; i < nHisto2; i++){ if (divide) c2->cd(iPart++); histo2[i]->Draw(); TString name = TString(histoData2[i].name)+".pdf"; if (!divide) c2->SaveAs(name); } profStyle->cd(); for (int i = 0; i < nProf; i++){ if (divide) c2->cd(iPart++); profile[i]->Draw(); TString name = TString(profData[i].name)+".pdf"; if (!divide) c2->SaveAs(name); } if (divide) c2->SaveAs("L1_histo.pdf"); }