#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TH2.h" #include "TH3.h" #include "TGaxis.h" #include "TRandom.h" #include "TLegend.h" #include "TPaveStats.h" #include "TGraph.h" #include "TSystem.h" #include "TTree.h" #include "TTreePlayer.h" #include "TF1.h" #include "TCut.h" #include "TPaletteAxis.h" void graphb() { float p101; float p102; float p201; float p202; int p1p201=2; int p1p202=1; char fobject[50]; sprintf(fobject, "lemma"); TFile *fin = TFile::Open("C:/si-calo-sep18/si-500596-trasl.root"); fin->ls(); //TGaxis::SetMaxDigits(5); if (fin == 0) { printf("Error: cannot open the file!\n"); } else { TTree *fChain=0; fin->GetObject(fobject,fChain); TCut cut912 = TString::Format("TMath::Abs(Calo_Time[9] - Calo_Time[12] - (3.32785)) < (3)*(1.47188) ").Data(); TCut cut913 = TString::Format("TMath::Abs(Calo_Time[9] - Calo_Time[13] - (4.43584)) < (3)*(0.685633) ").Data(); TCut cut914 = TString::Format("TMath::Abs(Calo_Time[9] - Calo_Time[14] - (3.42323)) < (3)*(0.646554) ").Data(); TCut cut915 = TString::Format("TMath::Abs(Calo_Time[9] - Calo_Time[15] - (1.71963)) < (3)*(1.78036) ").Data(); TCut cut90 = TString::Format("TMath::Abs(Calo_Time[9] - Calo_Time[0] - (-125.007)) < (3)*(2.67618) ").Data(); TCut cut91 = TString::Format("TMath::Abs(Calo_Time[9] - Calo_Time[1] - (-125.773)) < (3)*(3.01779) ").Data(); TCut cut92 = TString::Format("TMath::Abs(Calo_Time[9] - Calo_Time[2] - (-124.395)) < (3)*(2.83948) ").Data(); TCanvas *c0 = new TCanvas("c0","LG 0 !1 !2",1280,1024); gStyle->SetOptFit(); fChain->SetLineColor(kBlue); TString hxb0n12string = TString::Format("bpar[0] >> htemp(100, 0., 0.)"); fChain->Draw(hxb0n12string, cut912 && cut913 && cut914 && cut915 && cut90 && !cut91 && !cut92); fChain->GetHistogram()->SetTitle("LG0n12"); //t->SetScanField(0); TH1F *hxb0n12 = (TH1F*)gPad->GetPrimitive("htemp"); TF1 *g01 = new TF1 ("m01", "gaus", -0.07, -0.06); g01->SetLineColor(kYellow); TF1 *g02 = new TF1 ("m02", "gaus",-0.06, -0.05); g02->SetLineColor(kGreen); TF1 *f01 = new TF1("double_gaus8sub", "gaus(0) + gaus(3)", -0.07,-0.05); f01->SetParNames("Constant 1", "Mean 1", "Sigma 1","Constant 2", "Mean 2", "Sigma 2"); f01->SetLineColor(kRed); hxb0n12->Fit(g01, "R"); hxb0n12->Fit(g02, "R"); Double_t par01[6]; g01->GetParameters(&par01[0]); g02->GetParameters(&par01[3]); f01->SetParameters(par01); hxb0n12->Fit(f01, "R"); hxb0n12->Draw("e1"); g01->Draw("SAME"); g02->Draw("SAME"); f01->Draw("SAME"); if (p1p201==1) { p101=f01->GetParameter(1); p102=f01->GetParameter(2); } else if (p1p201==2) { p101=f01->GetParameter(4); p102=f01->GetParameter(5); } hxb0n12->GetXaxis()->SetTitle("Slope"); hxb0n12->GetYaxis()->SetTitle("#Counts"); hxb0n12->SetTitle("si-500596, #mu^{+}_{22 GeV}- Slope Parameter LG 0, !1, !2"); hxb0n12->SetFillColorAlpha(kBlue, 0.35); hxb0n12->Draw(); hxb0n12->SetName("Slope LG 0 !1 !2"); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn c0->Update(); TLegend* leg01 = new TLegend(0.15, 0.7, .25, .75); leg01->SetHeader("Legend"); leg01->SetNColumns(1); leg01->AddEntry(hxb0n12, "Data", "l"); leg01->AddEntry(f01, "Fit", "l"); leg01->Draw(); c0->Update(); gPad->Modified(); gPad->Update(); TPaveStats *stat01 = (TPaveStats*)hxb0n12->GetListOfFunctions()->FindObject("stats"); stat01->SetTextColor(kBlue); stat01->SetX1NDC(0.80); stat01->SetX2NDC(0.98); stat01->SetY1NDC(0.77); stat01->SetY2NDC(0.92); stat01->AddText(TString::Format("Mean = %g", p101)); stat01->AddText(TString::Format("Sigma = %g", p102)); stat01->DrawClone(); gPad->Update(); c0->Print("C:/si-calo-sep18/Slope_0_!1_!2.pdf"); delete c0; TCanvas *c1 = new TCanvas("c1","LG 0 !1 !2",1280,1024); gStyle->SetOptFit(); fChain->SetLineColor(kBlue); TString hxb2n1string = TString::Format("bpar[0] >> htemp(100, 0., 0.)"); fChain->Draw(hxb2n1string, cut912 && cut913 && cut914 && cut915 && !cut91 && cut92); fChain->GetHistogram()->SetTitle("LG2n1"); //t->SetScanField(0); TH1F *hxb2n1 = (TH1F*)gPad->GetPrimitive("htemp"); TF1 *g01b = new TF1 ("m02", "gaus", -0.07, -0.06); g02->SetLineColor(kYellow); TF1 *g02b = new TF1 ("m02", "gaus",-0.06, -0.05); g02->SetLineColor(kGreen); TF1 *f02 = new TF1("double_gaus8sub", "gaus(0) + gaus(3)", -0.07,-0.05); f02->SetParNames("Constant 1", "Mean 1", "Sigma 1","Constant 2", "Mean 2", "Sigma 2"); f02->SetLineColor(kRed); hxb2n1->Fit(g02, "R"); hxb2n1->Fit(g02, "R"); Double_t par02[6]; g02->GetParameters(&par02[0]); g02->GetParameters(&par02[3]); f02->SetParameters(par02); hxb2n1->Fit(f02, "R"); hxb2n1->Draw("e1"); g02->Draw("SAME"); g02->Draw("SAME"); f02->Draw("SAME"); if (p1p202==1) { p201=f02->GetParameter(1); p202=f02->GetParameter(2); } else if (p1p202==2) { p201=f02->GetParameter(4); p202=f02->GetParameter(5); } hxb2n1->GetXaxis()->SetTitle("Slope"); hxb2n1->GetYaxis()->SetTitle("#Counts"); hxb2n1->SetTitle("si-500596, #mu^{+}_{22 GeV}- Slope Parameter LG 2, !1"); hxb2n1->SetFillColorAlpha(kBlue, 0.35); hxb2n1->Draw(); hxb2n1->SetName("Slope LG 2 !1 "); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn c1->Update(); TLegend* leg02 = new TLegend(0.15, 0.7, .25, .75); leg02->SetHeader("Legend"); leg02->SetNColumns(1); leg02->AddEntry(hxb2n1, "Data", "l"); leg02->AddEntry(f02, "Fit", "l"); leg02->Draw(); c1->Update(); gPad->Modified(); gPad->Update(); TPaveStats *stat02 = (TPaveStats*)hxb2n1->GetListOfFunctions()->FindObject("stats"); stat02->SetTextColor(kBlue); stat02->SetX1NDC(0.80); stat02->SetX2NDC(0.98); stat02->SetY1NDC(0.77); stat02->SetY2NDC(0.92); stat02->AddText(TString::Format("Mean = %g", p201)); stat02->AddText(TString::Format("Sigma = %g", p202)); stat02->DrawClone(); gPad->Update(); c1->Print("C:/si-calo-sep18/Slope_2_!1.pdf"); delete c1; } }