Blank Histogram (SOLVED)

I have what I believe to be one of the simplest root code chunks ever… |-) (ov course besides the hello world examples…) Problem is that the output is just a grey rectangle. If I move the TCanvas and saveas stuff to just past the clone it prints that one ok, but then if I move it out back to the bottom I get just the grey and if I move it to just before the TFile close statement I get a segfualt. I just do not know what is wrong here. Can somebody pass me some pointers… Thanks.


#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <TH1F.h>
#include <TFile.h>
#include <TCanvas.h>

using namespace std;

int main(int argc, char *argv[]) {

  // Initialize things

  TH1F *histo = 0;
  string origident = argv[1];

  // Open the description file

  ifstream infile("Combine/desc");

  if(!infile) {
    cout << "Unable to open the file\n";

  string filename;

  while(infile >> filename) {

    TFile tmpfile(filename.c_str());
    TObject *tmphist = tmpfile.FindObjectAny(origident.c_str());

    if(tmphist != 0x0) {

      TH1F *thisto = (TH1F*) tmphist;

      if(histo == 0x0) {
        cout << "Initalizing from file " << filename << "\n";
        histo = (TH1F*) thisto->Clone("tmp");
      } else {
        cout << "Adding      from file " << filename << "\n";
        histo->Add(thisto, 1.0);



  // Output the histogram
  TCanvas *can = new TCanvas("mycanvas");


  stringstream tmpname;
  tmpname << origident << ".ps";




I do not see anything wrong but I could not run your macro because a file is missing. Can you send runable macro ?


 I did not set this up as a macro, but a standalone executable.  I have created a directory structure with the needed files and a simple script to build and run the code block.  Just untar and then go into the Combine directory.  From there just run "./make" (not make since not a real makefile).  From there you should be able to just move to the "SomethingWrong" directory and execute the "./run_comb" script.  The "files" file just has a list of root files that I want to combine.  Thanks for taking a look at this.  I have subsequently altered the code to work another way but this has added a restriction.

somethingwrong.tar.gz (54 KB)

I should state that I am not sure which version of root that was. It is the standard D0 root version which is and early version 4 I think. I wish I could tell you exactly.


Your example does not work for me:> ./run_comb
Unable to open the file

According to your program it seems the file Combine/desc is missing.

Ohh, shoot. I had mode some mods. Just move the “files” file into the Combine directory and rename it to “desc”. If it just the list of root files that it should combine. I do not have access to a terminal right now to see what version of root I am running.


hmmm … sounds strange because run_comb is:> cat run_comb
./Combine/comb ./files nj

so it seems the file “files” is needed … so if I move " files" as you suggest it will not work … Any way i just copied the file " files" into Combine/desc and I get:> run_comb
 *** Break *** segmentation violation
(no debugging symbols found)
Using host libthread_db library "/lib/tls/".
Attaching to program: /proc/19087/exe, process 19087
[Thread debugging using libthread_db enabled]
[New Thread -1218565600 (LWP 19087)]

I feel like such a . The execute line that I had given you was for the newer version. The first arg for the program needs to be the key name of the histo that you want to combine. So, an example would be “./Combine/comb nj”. The comb program needs to be executed from where the files were found. Thanks for looking at this and I am sorry for giving you the mis-information.


I get now:> ./Combine/comb nj
Initalizing from file ./cafe_20070525111232-5443228/info.root
Adding      from file ./cafe_20070525111232-5443229/info.root
 *** Break *** segmentation violation
(no debugging symbols found)
Using host libthread_db library "/lib/tls/".
Attaching to program: /proc/19224/exe, process 19224
[Thread debugging using libthread_db enabled]
[New Thread -1218569696 (LWP 19224)]

May be you should send me something working, a bit simpler, which reproduces the problem…


But we will have to wait. I am in Springfield, mo right now and not a good connection (timeouts during kerberos transactions). When I get to FNAL I will get a working copy of this. It is strange though cause that code block should not produce this seg fault. But I will hammer something together and post it. That will be on the 1st or 2nd of June.


That’s fine. I will get a email as soon as you’ll post something new.

Well, the issue seemes to be related to Object Ownership. So for some reason it was going out of scope. So I just added TH1::AddDirectory(kFALSE) and now all is working…

Ok fine. Thanks to have let me know.