#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("C:/root-6.24.00_build/macros/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->SetLogy(); t->SetLineColor(kBlue); TString helestring = TString::Format("ScintParticleKinEn >> htemp1(100., 0., 0.)"); //plot 0 E TString hposstring = TString::Format("ScintParticleKinEn >> htemp2(100., 0., 0.)"); //plot 0 E TString hgamstring = TString::Format("ScintParticleKinEn >> htemp3(100., 0., 0.)"); //plot 0 E TH1F *hpos = (TH1F*)gPad->GetPrimitive("htemp2"); TH1F *hgam = (TH1F*)gPad->GetPrimitive("htemp3"); TCut Idpele = TString::Format("ScintParticleID==11").Data(); TCut Idppos = TString::Format("ScintParticleID==-11").Data(); TCut Idpgam = TString::Format("ScintParticleID==22").Data(); t->Draw(helestring,Idpele); t->Draw(hposstring,Idppos); t->Draw(hgamstring,Idpgam); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(""); TH1F *hele = (TH1F*)gPad->GetPrimitive("htemp1"); hele->SetFillStyle(1001); hele->GetXaxis()->SetTitle("Energy (GeV)"); hele->GetYaxis()->SetTitle("Counts"); hele->GetXaxis()->SetLabelFont(43); hele->GetXaxis()->SetLabelSize(30); hele->GetYaxis()->SetLabelFont(43); hele->GetYaxis()->SetLabelSize(30); hele->GetXaxis()->SetTitleFont(43); hele->GetXaxis()->SetTitleSize(30); hele->GetYaxis()->SetTitleFont(43); hele->GetYaxis()->SetTitleSize(30); hele->SetFillColorAlpha(kBlue, fillcolor); hele->SetStats(0); hele->SetName(""); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn hpos->SetFillColorAlpha(kGreen, fillcolor); hpos->SetFillStyle(3004); hgam->SetFillColorAlpha(kRed, fillcolor); hgam->SetFillStyle(3005); THStack *hs = new THStack("hs", ""); hs->Add(hele); hs->Add(hpos); hs->Add(hgam); hele->Draw("sames"); hpos->Draw("sames"); hgam->Draw("sames"); /* TLegend* legenea = new TLegend(0.65, 0.7, .75, .75); legenea->SetHeader("Legend"); legenea->SetNColumns(1); legenea->AddEntry(hele, "Data", "l"); legenea->Draw();*/ gPad->Update(); /* TPaveStats *stats = (TPaveStats*)hele->GetListOfFunctions()->FindObject("stats"); stats->SetTextColor(kBlue); stats->SetX1NDC(0.80); stats->SetX2NDC(0.98); stats->SetY1NDC(0.77); stats->SetY2NDC(0.92);*/ gPad->Update(); c01->Print("C:/simulazione/spectrum.png"); delete c01; } }