#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH2.h" #include "TGaxis.h" #include "TSystem.h" #include "TTree.h" #include "TLegend.h" #include "TPaveStats.h" #include "TMath.h" #include #include #include #include "TRandom.h" void emiter(Int_t seed=0){ TRandom *r=new TRandom(); r->SetSeed(seed); ofstream results; ofstream resultsthf; results.open("emittanceerxxp.txt", ios::app); resultsthf.open("emittanceerxxp_2.txt", ios::app); char Secondary[50]; sprintf(Secondary, "B1Secondaryparticles"); TFile *fin = TFile::Open("B1.root"); fin->ls (); TGaxis::SetMaxDigits(3); TTree *ts=0; fin->GetObject(Secondary,ts); gStyle->SetOptFit(); gStyle->SetOptStat(111110); ts->SetLineColor(kBlue); TCanvas *c37 = new TCanvas("c37","Plot",1280,1024); TH2F *htempdirxsp = new TH2F("htempdirxsp", "", 500, 0., 0.,500, 0.,0.); TString varhemitxxpsp = TString::Format("SecondaryParticleAng.x : (PositionDirection.x-SecondaryParticleVert.x) >> htempdirxsp"); TH2::StatOverflows(true); ts->Draw(varhemitxxpsp); ts->GetHistogram()->SetTitle("Primary e^{+} emittance"); ts->SetScanField(0); htempdirxsp->GetXaxis()->SetTitle("x (mm)"); htempdirxsp->GetYaxis()->SetTitle("x' (rad)"); htempdirxsp->SetFillStyle(1001); htempdirxsp->SetFillColorAlpha(kBlue, 0.35); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legdirxsp = new TLegend(0.15, 0.6, .25, .65); legdirxsp->SetHeader("Legend"); legdirxsp->SetNColumns(1); legdirxsp->AddEntry(htempdirxsp, "MC", "l"); legdirxsp->Draw(); c37->Update(); gPad->Modified(); gPad->Update(); TCanvas *c0 = new TCanvas("c0","c0",1280,1024); TH1F *hscoring = new TH1F("hscoring","Released energy",100,0.,0.); //----------------EMITTANCE CALCULATION-----------------// int i; int Nextraction=1000; //int nentries = ts->GetEntries(); int nentries = 1000; // for(i=0; iSetBranchAddress("SecondaryParticleVert.x", &xVv[0]); ts->SetBranchAddress("PositionDirection.x", &xv[0]); ts->SetBranchAddress("SecondaryParticleAng.x", &xpv[0]); for(int jentry=0; jentryGetXaxis()->SetTitle("Emittance (nm*rad)"); hscoring->GetYaxis()->SetTitle("Counts"); hscoring->Draw(); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TPaveStats *statshscoring = (TPaveStats*)hscoring->GetListOfFunctions()->FindObject("stats"); statshscoring->SetTextColor(kBlue); statshscoring->SetX1NDC(0.80); statshscoring->SetX2NDC(0.98); statshscoring->SetY1NDC(0.77); statshscoring->SetY2NDC(0.92); c0->Update(); gPad->Modified(); gPad->Update(); c0->Print("emittanceer_xxp.pdf"); delete c0; delete c37; }