16Int_t mt_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 auto &histo = histograms.at(workerID);
51 for (
auto index :
ROOT::TSeqL(ntuple->GetEntriesFast())) {
52 ntuple->GetEntry(index);
53 histo.
Fill(ntuple->GetArgs()[0]);
57 TH1F sumHistogram(
"SumHisto",
"Random Numbers", 128, -4, 4);
60 std::vector<std::thread> workers;
64 for (
auto workerID : workerIDs) {
65 workers.emplace_back(workItem, workerID);
69 for (
auto &&worker : workers)
73 std::for_each(std::begin(histograms), std::end(histograms),
74 [&sumHistogram](
const TH1F &
h) { sumHistogram.Add(&
h); });
76 sumHistogram.Fit(
"gaus", 0);
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
A chain is a collection of files containing TTree objects.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
1-D histogram with a float per channel (see TH1 documentation)
A simple TTree restricted to a list of float variables only.
Int_t Fill() override
Fill a Ntuple with current values in fArgs.
void EnableThreadSafety()
Enable support for multi-threading within the ROOT code in particular, enables the global mutex to ma...