#include "omp.h" #include "TROOT.h" #include "TFile.h" #include "TDirectory.h" #include "TH2S.h" #include "TCanvas.h" #include "TKey.h" #include "TRandom.h" int main(int argc, char** argv) { // Set to batch mode, to avoid the GUI to pop up gROOT->SetBatch(1); // Enable thread safety ROOT::EnableThreadSafety(); // Number of histograms int num_hists = 10; // Retrieve all histograms in the ROOT file std::vector vec(num_hists); for(int i = 0; i < num_hists; i++) { std::string name = "h" + std::to_string(i); TH2S *h = new TH2S(name.c_str(),"",40,-4,4,40,-20,20); Float_t px, py; for (Int_t i = 0; i < 2500000; i++) { gRandom->Rannor(px,py); h->Fill(px,5*py); } vec[i] = h; } #pragma omp parallel for for (size_t i = 0; i < vec.size(); i++) { TH2S* h = vec[i]; TCanvas *c = new TCanvas(std::to_string(i).c_str()); h->Draw("colz"); std::string name = std::string(h->GetName()); c->Print((name + ".png").c_str()); delete c; } return 0; }