void tree_example2() { TH1F *hist1 = new TH1F("hist1", "hist1", 100, -200., 200.0); TH1F *hist2 = new TH1F("hist2", "hist2", 100, -200., 200.0); TH1F *hist3 = new TH1F("hist3", "hist3", 100, -200., 200.0); TH1F *hist4 = new TH1F("M_Z", "Masse of Z boson", 50, 0., 200.0); TH1F *hist5 = new TH1F("P_Z", "Momentum of Z boson", 100, -2000.0, 2000.0); // -------- //first method to read the root file //TFile *f = TFile::Open("ntuple_array.root"); // ... // -------- // ------- //second method to read the root file /*TFile *f; f = new TFile("ntuple_array.root"); f->ls(); TDirectoryFile *dir1 = (TDirectoryFile*)f->Get("ntupleProducer;1"); TTree *tree = (TTree*)dir1->FindObject("tree;1");*/ // ------- // ------- //third method to read the root file TFile *f = new TFile("ntuple_array.root"); TTree *tree = (TTree*)f->Get("ntupleProducer/tree;1"); // ------- TCanvas c; c.SaveAs("plots.pdf["); // opening pdf TCut cut1 = "genParticleCharge != 0"; Float_t genParticlePx, genParticlePy, genParticlePz, PZ, En, MZ, deltaMZ(10.); hist1->GetXaxis()->SetTitle("genParticlePx"); tree->Draw("genParticlePx>>hist1", cut1); hist1->Draw("colz"); c.SaveAs("plot.pdf"); c.Clear(); c.SaveAs("plots.pdf]"); f->Close(); /*tree->SetBranchAddress("genParticlePx",&genParticlePx); tree->SetBranchAddress("genParticlePy",&genParticlePy); tree->SetBranchAddress("genParticlePz",&genParticlePz); Int_t nentries = (Int_t)tree->GetEntries(); for (Int_t i = 0; iGetEntry(i); hist1->Fill(genParticlePx); hist1->Fill(genParticlePy); hist1->Fill(genParticlePz); En = sqrt(genParticlePx*genParticlePx+genParticlePy*genParticlePy+genParticlePz*genParticlePz); //PZ = (En+genParticlePx+genParticlePy+genParticlePz)*2; MZ = sqrt(En*En+genParticlePx*genParticlePx+genParticlePy*genParticlePy+genParticlePz*genParticlePz); hist5->Fill(PZ); //if (abs(MZ-91) <= 2*deltaMZ){ hist4->Fill(MZ); //} } TCanvas *c1 = new TCanvas(); hist4->GetXaxis()->SetTitle("Masse of Z boson"); hist4->Draw(); hist4->SetFillColor(kBlue-9); c1->SaveAs("masseZ.pdf");*/ /*TCanvas *c2 = new TCanvas(); hist5->GetXaxis()->SetTitle("Momentum of Z boson"); hist5->Draw(); hist5->SetFillColor(kBlue-9); c2->SaveAs("PZ.pdf");*/ }