Hi there.
I have a root file that has two branches, ADC
and hit
, which has the type of std::vector<int>
and std::vector<bool>
respectively.
With the kind help, I was able to write a code to draw histograms of each element in ADC
.
Then I tried to do something like
TH1D histo[30];
for (int i=0;i<30;++i){
if (hit[i] == true){
h[i].Fill(ADC[i]);
}
}
And the actual code I wrote follows:
using ints = ROOT::RVec<int>;
using bools = ROOT::RVec<bool>;
std::vector<ROOT::RDF::RResultPtr<TH1D>> histos;
for (int i = 0; i < 30; ++i)
{
// Book the filling of the histogram of i-th element of branch `ADC'
// this is my code before modified
/*
auto ith = [i](const ints &v) { return v.at(i); };
ROOT::RDF::RResultPtr<TH1D> histo = df.Define("ADCi", ith, {"ADC"})
.Histo1D({Form("histo%d", i + 1), "title;ADC(ch);Counts/2ch", 2048, 0, 4096}, "ADCi");
*/
auto ith = [i](const ints &v, const bools &b)
{
if (b.at(i))
{
return v.at(i);
}
};
ROOT::RDF::RResultPtr<TH1D> histo = df.Define("ADCi", ith, {"ADC", "isHit"})
.Histo1D({Form("histo%d", i + 1), "title;ADC(ch);Counts/2ch", 2048, 0, 4096}, "ADCi");
histos.push_back(histo);
}
The problem of the modified code above is its speed. It took 23 minutes to run the program before modified, but after modified it takes 3 hours! Both are executed using ACLiC (adding +
after the filename).
Please help me speed up my program.
Cheers,
haltack.