#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 #include #include float fillcolor=0.35; void scintillator() { gStyle->SetOptStat(111110); TFile *fin = TFile::Open("B1/B1-build/B1.root"); fin->ls (); if (fin == 0) { printf("Error: cannot open the file!\n"); } else { TTree *t=0; fin->GetObject("B1Scintparticles",t); t->SetScanField(0); TCanvas *c01 = new TCanvas("c01","",1280,1024); // c01->SetLogx(); c01->SetLogy(); auto h1 = new TH1D("h1","h1",100., 0., 2.); auto h2 = new TH1D("h2","h2",100., 0., 2.); auto h3 = new TH1D("h3","h3",100., 0., 2.); // h1->SetFillColor(kBlue); h2->SetFillColor(kGreen); h3->SetFillColor(kYellow); h1->SetLineColor(kBlue); h2->SetLineColor(kGreen); h3->SetLineColor(kYellow); h1->SetFillColorAlpha(kBlue, fillcolor); // h2->SetFillColorAlpha(kGreen, fillcolor); // h3->SetFillColorAlpha(kYellow, fillcolor); TString helestring = TString::Format("ScintParticleKinEn >> h1"); TString hposstring = TString::Format("ScintParticleKinEn >> h2"); TString hgamstring = TString::Format("ScintParticleKinEn >> h3"); TCut Idpele = TString::Format("ScintParticleID==11").Data(); TCut Idppos = TString::Format("ScintParticleID==-11").Data(); TCut Idpgam = TString::Format("ScintParticleID==22").Data(); h1->SetFillStyle(1001); h2->SetFillStyle(3004); h3->SetFillStyle(3005); t->Draw(helestring,Idpele,"goff"); t->Draw(hposstring,Idppos,"goff"); t->Draw(hgamstring,Idpgam,"goff"); THStack *hs = new THStack(); /* h1->GetXaxis()->SetTitle("Energy (GeV)"); h1->GetYaxis()->SetTitle("Counts"); h1->GetXaxis()->SetLabelFont(43); h1->GetXaxis()->SetLabelSize(30); h1->GetYaxis()->SetLabelFont(43); h1->GetYaxis()->SetLabelSize(30); h1->GetXaxis()->SetTitleFont(43); h1->GetXaxis()->SetTitleSize(30); h1->GetYaxis()->SetTitleFont(43); h1->GetYaxis()->SetTitleSize(30);*/ gPad->Update(); hs->Add(h2); hs->Add(h3); hs->Add(h1); hs->Draw(); TLegend* leg = new TLegend(0.65, 0.7, .75, .75); leg->SetHeader("Legend"); leg->SetNColumns(1); leg->AddEntry(h1, "electrons", "l"); leg->AddEntry(h2, "positrons", "l"); leg->AddEntry(h3, "photons", "l"); leg->Draw(); gPad->Update(); TPaveStats *stats = (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats"); TPaveStats *stats2 = (TPaveStats*)h2->GetListOfFunctions()->FindObject("stats"); TPaveStats *stats3 = (TPaveStats*)h3->GetListOfFunctions()->FindObject("stats"); stats->SetTextColor(kBlue); stats->SetX1NDC(0.80); stats->SetX2NDC(0.98); stats->SetY1NDC(0.77); stats->SetY2NDC(0.92); stats2->SetTextColor(kGreen); stats2->SetX1NDC(0.80); stats->SetX2NDC(0.98); stats2->SetY1NDC(0.60); stats->SetY2NDC(0.75); stats3->SetTextColor(kYellow); stats3->SetX1NDC(0.80); stats->SetX2NDC(0.98); stats3->SetY1NDC(0.43); stats->SetY2NDC(0.58); gPad->Update(); c01->Print("simulazione/spectrum.png"); delete c01; } }