#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 "TFitResult.h" #include "TMath.h" void inoutpart() { float fillcolor=0.35; TH1::AddDirectory(false); gSystem->mkdir(TString::Format("simulazione" ), kTRUE); gStyle->SetOptFit(); gStyle->SetFitFormat("8.6g"); gStyle->SetOptStat(111110); TFile *fin = TFile::Open("Positroni_entering/Be_1.5mm/B1/B1-build/B1_in.root"); // fin->ls (); TFile *fin2 = TFile::Open("Positroni/Be_1.5mm/B1/B1-build/B1_out.root"); // fin2->ls (); TGaxis::SetMaxDigits(3); if (fin == nullptr || fin2 == nullptr) { printf("Error: cannot open the file!\n"); } else { TTree *te=0; TTree *ts=0; fin->GetObject("B1Enteringparticles",te); fin2->GetObject("B1Exitparticles",ts); if (te == nullptr || ts == nullptr) { printf("Error: cannot get the trees!\n"); return; } gStyle->SetOptFit(); gStyle->SetOptStat(111110); te->SetLineColor(kBlue); TH1::StatOverflows(true); //---------------------------------------------------------------------EVENTS -------------------------------------------------------------// TCanvas *c01 = new TCanvas("c01","c01",1280,1024); te->Draw(Form("EnteringDirection.x>> htemp(100, 0., 0.)")); te->GetHistogram()->SetTitle(""); te->SetScanField(0); TH1F *htempentering= (TH1F*)gPad->GetPrimitive("htemp"); ts->Draw(Form("ExitParticleKinEn >> htemp(100, 0., 0.)")); ts->SetScanField(0); TH1F *htempoutgoing= (TH1F*)gPad->GetPrimitive("htemp"); htempentering->GetXaxis()->SetTitle("x (mm)"); htempentering->GetYaxis()->SetTitle("Counts"); htempentering->GetYaxis()->SetTitleSize(40); htempentering->GetYaxis()->SetTitleFont(43); htempentering->GetYaxis()->SetTitleOffset(1.1); htempentering->GetYaxis()->SetLabelFont(43); htempentering->GetYaxis()->SetLabelSize(40); htempentering->GetXaxis()->SetTitleSize(40); htempentering->GetXaxis()->SetTitleFont(43); htempentering->GetXaxis()->SetTitleOffset(1.1); htempentering->GetXaxis()->SetLabelFont(43); htempentering->GetXaxis()->SetLabelSize(40); htempentering->SetFillStyle(1001); htempentering->SetFillColorAlpha(kBlue, fillcolor); htempentering->SetStats(0); htempentering->Draw(); htempentering->SetName(""); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn htempoutgoing->Draw("SAME"); c01->Update(); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn /*TLegend* legenter = new TLegend(0.25, 0.7, .35, .75); legenter->SetHeader("Legend"); legenter->SetNColumns(1); legenter->AddEntry(htempentering, "MC", "l"); legenter->Draw();*/ c01->Update(); gPad->Modified(); gPad->Update(); /*TPaveStats *statsenter = (TPaveStats*)htempentering->GetListOfFunctions()->FindObject("stats"); statsenter->SetTextColor(kBlue); statsenter->SetX1NDC(0.80); statsenter->SetX2NDC(0.98); statsenter->SetY1NDC(0.83); statsenter->SetY2NDC(0.98); //statsenter->AddText(TString::Format("Integral = %g", integral)); statsenter->DrawClone();*/ gPad->Update(); gPad->Update(); c01->Print("simulazione/inoutpart_xposition_circ_Be15.png"); delete c01; } }