Histogram writing to files (0.9/13)

From: Chris Green (Christopher.Green@cern.ch)
Date: Wed Mar 12 1997 - 13:00:25 MET


I'm trying to write to a .root file by calling the same routine several
tims. I wish to write histograms to the same file with different names to
avoid overwriting. Can you tell me what's wrong with this? 

char stanb[12] = " (all tanb)";
char ht1[30] = "minevt_tot";
char ht2[30] = "minevt_rr";
char ht3[30]= "lim_tot";
char ht4[30] = "lim_rr";
char ht5[30]= "lim_tot172"; 
char ht6[30]= "lim_rr172"; 

if (tbval) sprintf(stanb," (tanb = %f)",tbval);
strcat(stanb,ht1);
strcat(stanb,ht2);
strcat(stanb,ht3);
strcat(stanb,ht4);
strcat(stanb,ht5);
strcat(stanb,ht6);

TH2F *minevt_tot = new TH2F(ht1,"Minimum expected events (left+right)",
                         71,19.5,90.5,71,19.5,90.5);
TH2F *minevt_rr = new TH2F(ht2,"Minimum expected events (right only)",
                         71,19.5,90.5,71,19.5,90.5);
TH2F *lim_tot = new TH2F(ht3,"Excluded region(left+right)",
                         71,19.5,90.5,71,19.5,90.5);
TH2F *lim_rr = new TH2F(ht4,"Excluded region (right only)",
                         71,19.5,90.5,71,19.5,90.5);
TH2F *lim_tot172 = new TH2F(ht5,"Excluded region(left+right) at 172 GeV",
                         71,19.5,90.5,71,19.5,90.5);
TH2F *lim_rr172 = new TH2F(ht6,"Excluded region (right only) at 172 GeV",
                         71,19.5,90.5,71,19.5,90.5);

(filling blurb) ..

TFile *combout = new TFile("combout.root","UPDATE");

if ( ! combout->IsOpen() ) {
  printf("File does not appear to exist. Trying to create ...\n");
  TFile *combout = new TFile("combout.root","NEW");
  if ( ! combout->IsOpen() ) {
    printf("Still unable to open output file. Exiting with problems.\n");
    exit(127);
      } else { printf("File opened successfully.\n"); }
}
minevt_tot->Write(ht1);
minevt_rr->Write(ht2);
lim_tot->Write(ht3);
lim_rr->Write(ht4);
lim_tot172->Write(ht5);
lim_rr172->Write(ht6);

combout->Close();

When I open the file in ROOT, however, all I get is updated cycles of the
same histogram (haven't had chance to try the same thing with 1.0beta
yet). Help?

Thanks,
Chris.



--- 
Chris Green. HEP, University of Liverpool 
MAIL Chris.Green@cern.ch, WWW http://hep.ph.liv.ac.uk/~chris/
+41 22 767 8075. On LTA at CERN.
---
"Woof. In tones of low menace." -- Gaspode the wonder dog (Terry Pratchett, Moving Pictures)



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:18 MET