Passing histograms between functions

Dear rooters,
I guess my question is not connected to ROOT or to histograms specifically, but…
I am trying to generate a few histograms, then loop over my events, fill the histograms in, then, outside the loop, save them in a file. This works fine, but now, I want to place my histogram initialisation in a function in another file, the filling of the histograms in a second, and the saving in a third, so my main macro looks like this:

#include "InitHistos.h"
#include "FillHistos.h"
#include "SaveHistos.h"
void func(){

   for(int i{0};i<ev_number;++i){

I am not sure how to make fillHistos “see” the histograms that I have without initialising them as global variables.
Thank you,

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


the way to percolate the information through the functions is to pass it as parameter. In your case this could be a reference to the collection of your histograms, e.g.:

void DoSomethingWithHistos(std::forward_list<std::unique_ptr<TH1F>> &histos);


Thank you for your answer,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.