16Int_t mt102_readNtuplesFillHistosAndFit()
23 TChain inputChain(
"multiCore");
24 inputChain.Add(
"mt101_multiCore_*.root");
25 TH1F outHisto(
"outHisto",
"Random Numbers", 128, -4, 4);
26 inputChain.Draw(
"r >> outHisto");
36 const auto nFiles = inputChain.GetListOfFiles()->GetEntries();
39 std::vector<TH1F> histograms;
41 histograms.reserve(nFiles);
42 for (
auto workerID : workerIDs) {
43 histograms.emplace_back(
TH1F(
Form(
"outHisto_%u", workerID),
"Random Numbers", 128, -4, 4));
47 auto workItem = [&histograms](
UInt_t workerID) {
48 TFile f(
Form(
"mt101_multiCore_%u.root", workerID));
50 f.GetObject(
"multiCore", ntuple);
51 auto &histo = histograms.at(workerID);
54 histo.Fill(ntuple->
GetArgs()[0]);
58 TH1F sumHistogram(
"SumHisto",
"Random Numbers", 128, -4, 4);
61 std::vector<std::thread> workers;
65 for (
auto workerID : workerIDs) {
66 workers.emplace_back(workItem, workerID);
70 for (
auto &&worker : workers)
74 std::for_each(std::begin(histograms), std::end(histograms),
75 [&sumHistogram](
const TH1F &
h) { sumHistogram.Add(&
h); });
77 sumHistogram.Fit(
"gaus", 0);
char * Form(const char *fmt,...)
A pseudo container class which is a generator of indices.
A chain is a collection of files containing TTree objects.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
1-D histogram with a float per channel (see TH1 documentation)}
A simple TTree restricted to a list of float variables only.
Float_t * GetArgs() const
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
virtual Long64_t GetEntriesFast() const
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.