#include "TH1.h" #include #include #include #include "TH2.h" #include "TStyle.h" #include "TCanvas.h" #include "TFile.h" #include "TTree.h" #include "TROOT.h" #include #include void hits_function_thita() { // Open the root file TFile *file = TFile::Open("data22_13p6TeV_00436422_physics.root"); // If the file doesn't exist or couldn't be opened, exit the program if (!file || file->IsZombie()) { printf("Unable to open file.\n"); delete file; return; } // List the objects in the file file->ls(); TTree* tree; file->GetObject("BasicTesterTree", tree); if (!tree) { delete file; return; } // just a precaution //tree->Print(); tree->SetBranchStatus("*", 0); tree->SetBranchStatus("mmOnTrackNStrips", 1); std::vector* mmOnTrackNStrips = 0; // Set the addresses of the branches to the variables tree->SetBranchAddress("mmOnTrackNStrips",&mmOnTrackNStrips); gROOT->cd(); // newly created histograms should ge here TH1F *hist = new TH1F("hist","mmOnTrackNStrips",100,0,60); // Loop over the entries in the tree and print the values of std::cout << tree->GetEntries() <GetEntries(); i++) { tree->GetEntry(i); if (!mmOnTrackNStrips) continue; // just a precaution for (unsigned j = 0; j < mmOnTrackNStrips->size(); j++) hist->Fill(mmOnTrackNStrips->at(j)); } hist->Draw(); // tree->ResetBranchAddresses(); // disconnect from local variables delete file; // automatically deletes the tree, too }