void macro() { TFile *f = new TFile("pythia8NCDIS_5x100_minQ2\=1000_beamEffects_xAngle\=-0.025_hiDiv_1.0029.root "); TTree *tree= (TTree*)f->Get("events"); Float_t ReconstructedParticles.p.x, ReconstructedParticles.p.z,ReconstructedParticles.p.z,ReconstructedParticles.energy; tree->SetBranchAddress("ReconstructedParticles.p.x",&ReconstructedParticles.p.x); tree->SetBranchAddress("ReconstructedParticles.p.y",&ReconstructedParticles.p.y); tree->SetBranchAddress("ReconstructedParticles.p.z",&ReconstructedParticles.p.z); tree->SetBranchAddress("ReconstructedParticles.energy",&ReconstructedParticles.energy); //create histograms TH1F *h1 = new TH1F("px","",100, -20, 20); TH1F *h2 = new TH1F("py","",100, -20,20); TH1F *h3 = new TH1F("pz","",100, -20,20); TH1F *h4 = new TH1F("energy","",100, 0, 200); //read all entries and fill the histograms Int_t nentries = (Int_t)tree->GetEntries(); for (Int_t i=0; iGetEntry(i); h1->Fill(ReconstructedParticles.p.x); h1->GetXaxis()->SetTitle("px"); h1->GetXaxis()->SetTitleSize(0.05); h1->GetXaxis()->CenterTitle(); h1->SetLineWidth(2); h2->Fill(ReconstructedParticles.p.y); h2->GetXaxis()->SetTitle("py"); h2->GetXaxis()->SetTitleSize(0.05); h2->GetXaxis()->CenterTitle(); h2->SetLineWidth(2); h3->Fill(ReconstructedParticles.p.z); h3->GetXaxis()->SetTitle("pz"); h3->GetXaxis()->SetTitleSize(0.05); h3->GetXaxis()->CenterTitle(); h3->SetLineWidth(2); h4->Fill(ReconstructedParticles.energy); h4->GetXaxis()->SetTitle("energy"); h4->GetXaxis()->SetTitleSize(0.05); h4->GetXaxis()->CenterTitle(); h4->SetLineWidth(2); } TFile * f1 = new TFile("output.root","RECREATE"); h1->Write(); h2->Write(); h3->Write(); h4->Write(); f1->Close(); }