Write all histograms

Bonjour,
my python script is doing the following :

  • booking histos
  • opening an “INFILE” Tfile containing a TTree
  • looping on TTree entries to fill histos
  • opening/creating an new “OUTFILE” TFile to store the histograms
  • writing the histograms

I write my histograms with “MYHISTO”.Write() and this works.
The question is : since I have a long list of histograms, is there a way to write them all (in a loop) which means somehow retrieving a pointer or a key to each histogram.
Apparently, I could do something like this : “OUTFILE”.Write() which would write all histos.
But when I do this, it does not write anything since it cannot find this histograms.
I understand that I’m a bit lost in directories, memories, disks etc … although I’ve been printing interactively all the “path” …

Thanks in advance for your help !
– filip

Modify your logic into:

  • opening/creating a new “OUTFILE” TFile to store the histograms
  • booking histos (they will automatically become “owned” by your “OUTFILE”)
  • opening an “INFILE” TFile containing a TTree
  • looping on TTree entries to fill histos
  • OUTFILE->Write(); // store all “owned” objects (i.e. histos)
  • delete OUTFILE; // note it will automatically delete all your histos, too

Wile,
that’s exactly what I wanted !
I modified my logic and it works !
Thanks !!!
– filip