StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Example_read_hist_file_list_draw_ps.C
1 // $Id: Example_read_hist_file_list_draw_ps.C,v 1.6 2006/08/15 21:42:57 jeromel Exp $
2 // $Log: Example_read_hist_file_list_draw_ps.C,v $
3 // Revision 1.6 2006/08/15 21:42:57 jeromel
4 // Fix rhic -> rhic.bnl.gov
5 //
6 // Revision 1.5 2000/01/19 15:46:05 kathy
7 // change default input files to point to ones in /afs/rhic.bnl.gov/star/data/samples
8 //
9 // Revision 1.4 1999/11/30 20:04:17 kathy
10 // fix Example macros so that they work from .dst.root files or .dst.xdf files & update documentation; also had to change which values printed in *read_dst_print_tables* macro since the names have changed in dst tables
11 //
12 // Revision 1.3 1999/11/03 19:03:05 kathy
13 // changes to default input files and output file names - needed by perl script for testing
14 //
15 // Revision 1.2 1999/11/02 22:54:36 kathy
16 // fixing documentation in macro
17 //
18 // Revision 1.1 1999/10/11 17:17:58 kathy
19 // changed names of some macros to make them more standard; changed default input file to MakeHists since previous no longer existed; combined some macros so that the one example will show all functionality
20 //
21 //=======================================================================
22 // owner: Kathy Turner, 24 June 99
23 // what it does: reads a flat root histogram file (not star specific) and
24 // list all histograms - one can easily add functionality to draw or
25 // send to postscript file from here
26 //
27 // This macro assumes you don't know what's in the file a priori.
28 //
29 // You can first run Example_read_dst_makehist.C to create
30 // an output *hist.root file (flat file).
31 // This macro then reads in the histogram file and draws
32 // histogram h1.
33 //
34 // This will not work for *.hist.root files produced from bfc.C since
35 // they have a tree directory structure.
36 //
37 // - adapted from macro taken from roottalk digest
38 // http://root.cern.ch/root/roottalk/roottalk99/1228.html
39 //=========================================================================
40 // in TPostScript set
41 // *-* 111 ps Portrait
42 // *-* 112 ps Landscape
43 // *-* 113 eps
44 // *-*
45 //
46 
47 void Example_read_hist_file_list_draw_ps(
48  const char* filein="Example_read_dst_makehist.root")
49 {
50 
51 // open file
52 TFile fin(filein);
53 
54 if (!fin->IsOpen()) {
55 printf("<E> Cannot open input file %s\n",filein) ;
56 exit(1) ;
57 }
58 
59 // list contents
60 fin.ls();
61 
62 // create canvas
63 TCanvas MyCanvas("CanvasName","Canvas Title",800,600);
64 
65 // set statistics on
66 gStyle->SetOptStat(111111);
67 
68 // set paper size
69 Int_t width = 21;
70 Int_t height = 27;
71 gStyle->SetPaperSize(width, height);
72 
73 // define output ps file
74 TPostScript ps("Example_read_hist_file_list_draw_ps.ps",111);
75 
76 //range of figures on ps page
77 ps.Range(20,26);
78 
79 //..................................................................
80 // The following code (in ...) is all because you don't know the names
81 // of the histograms in the file ahead of time
82 
83 TList* list = fin->GetListOfKeys() ;
84 if (!list) { printf("<E> No keys found in file\n") ; exit(1) ; }
85 TIter next(list) ;
86 TKey* key ;
87 TObject* obj ;
88 
89 while ( key = (TKey*)next() ) {
90 obj = key->ReadObj() ;
91 if ( (strcmp(obj->IsA()->GetName(),"TProfile")!=0)
92  && (!obj->InheritsFrom("TH2"))
93  && (!obj->InheritsFrom("TH1")) )
94  {
95  printf("<W> Object %s is not 1D or 2D histogram : "
96  "will not be converted\n",obj->GetName()) ;
97  }
98 
99  printf("Histo name:%s title:%s\n",obj->GetName(),obj->GetTitle());
100 
101 //...............................................................
102 
103 // Now do the following commands for each histogram
104  obj->Draw();
105 // do after each histogram (don't have to if at command line)
106  gPad->Update();
107  }
108 
109 // close output file
110  ps.Close();
111  cout << " finished macro " << endl;
112 }
113