//--------------------------------------------------------------------------- // // This root macro file is used for readinf ntuple file named output.root. // // Mar 2024 //--------------------------------------------------------------------------- void ntupleReader(){ // input file and its tree TFile *input = new TFile("output.root","read"); TTree *tree = (TTree*) input->Get("Values"); // my local variables int evt, pdgid; double px,py,pz,pmag; // sent branch adr. tree->SetBranchAddress("Event", &evt); tree->SetBranchAddress("PDGcode", &pdgid); tree->SetBranchAddress("pmag", &pmag); tree->SetBranchAddress("px", &px); tree->SetBranchAddress("py", &py); tree->SetBranchAddress("pz", &pz); // total number of entreis int entries = tree->GetEntries(); cout << "Total # of entries = " << entries << endl; cout << "I will print first 10 of the data\n"; for(int i=0; i<10; i++){ tree->GetEntry(i); cout << evt << " " << pdgid << " " << pmag << endl; } // --- analysis starts from here --- TCanvas *c1 = new TCanvas(); TH1F *h1 = new TH1F("hMomentum",";momentum (MeV);Entries",100,900,1000); TH2F *h2 = new TH2F("hpxpy",";px (MeV);py (MeV)",100,-150,150, 100,-150,150); cout << "I will analyse all data\n"; for(int i=0; iGetEntry(i); h1->Fill(pmag); h2->Fill(px, py); } c1->Divide(2,1); c1->cd(1); h1->Draw(); c1->cd(2); h2->Draw(); }