#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" #include "TCutG.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(); TCut cutx37 = TString::Format("TMath::Abs(x37[0] - (-20.7411)) < (3)*(1.16973) ").Data(); TCut xh99 = TString::Format("xh > -99 ").Data(); TCut cutbpar = TString::Format("bpar[0] > -0.0.06 ").Data(); TCanvas *c0 = new TCanvas("c0","Slope",1280,1024); gStyle->SetOptFit(); TH1F *hxb01 = (TH1F *)fin->Get("hb333537"); if (hxb01 == 0) { printf("Error getting an histogram from the file!\n"); return; } TString hxb01string = TString::Format("hxb01 >> htemp(100, 0., 0.)"); fChain->Draw(hxb01string.Data(),cutbpar); 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); hxb01->Fit(g01, "R"); hxb01->Fit(g02, "R"); Double_t par01[6]; g01->GetParameters(&par01[0]); g02->GetParameters(&par01[3]); f01->SetParameters(par01); hxb01->Fit(f01, "R"); hxb01->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); } hxb01->GetXaxis()->SetTitle("Slope"); hxb01->GetYaxis()->SetTitle("#Counts"); hxb01->SetTitle("si-500596, #mu^{+}_{22 GeV}- Slope Parameter subdet33-35-37, xh>-99"); hxb01->SetFillColorAlpha(kBlue, 0.35); hxb01->Draw(); hxb01->SetName("Slope"); 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(hxb01, "Data", "l"); leg01->AddEntry(f01, "Fit", "l"); leg01->Draw(); c0->Update(); gPad->Modified(); gPad->Update(); TPaveStats *stat01 = (TPaveStats*)hxb01->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_33-35-37.pdf"); delete c0; } }