00001 // $Id: Example_read_hist_file_list_draw_ps.C,v 1.6 2006/08/15 21:42:57 jeromel Exp $ 00002 // $Log: Example_read_hist_file_list_draw_ps.C,v $ 00003 // Revision 1.6 2006/08/15 21:42:57 jeromel 00004 // Fix rhic -> rhic.bnl.gov 00005 // 00006 // Revision 1.5 2000/01/19 15:46:05 kathy 00007 // change default input files to point to ones in /afs/rhic.bnl.gov/star/data/samples 00008 // 00009 // Revision 1.4 1999/11/30 20:04:17 kathy 00010 // 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 00011 // 00012 // Revision 1.3 1999/11/03 19:03:05 kathy 00013 // changes to default input files and output file names - needed by perl script for testing 00014 // 00015 // Revision 1.2 1999/11/02 22:54:36 kathy 00016 // fixing documentation in macro 00017 // 00018 // Revision 1.1 1999/10/11 17:17:58 kathy 00019 // 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 00020 // 00021 //======================================================================= 00022 // owner: Kathy Turner, 24 June 99 00023 // what it does: reads a flat root histogram file (not star specific) and 00024 // list all histograms - one can easily add functionality to draw or 00025 // send to postscript file from here 00026 // 00027 // This macro assumes you don't know what's in the file a priori. 00028 // 00029 // You can first run Example_read_dst_makehist.C to create 00030 // an output *hist.root file (flat file). 00031 // This macro then reads in the histogram file and draws 00032 // histogram h1. 00033 // 00034 // This will not work for *.hist.root files produced from bfc.C since 00035 // they have a tree directory structure. 00036 // 00037 // - adapted from macro taken from roottalk digest 00038 // http://root.cern.ch/root/roottalk/roottalk99/1228.html 00039 //========================================================================= 00040 // in TPostScript set 00041 // *-* 111 ps Portrait 00042 // *-* 112 ps Landscape 00043 // *-* 113 eps 00044 // *-* 00045 // 00046 00047 void Example_read_hist_file_list_draw_ps( 00048 const char* filein="Example_read_dst_makehist.root") 00049 { 00050 00051 // open file 00052 TFile fin(filein); 00053 00054 if (!fin->IsOpen()) { 00055 printf("<E> Cannot open input file %s\n",filein) ; 00056 exit(1) ; 00057 } 00058 00059 // list contents 00060 fin.ls(); 00061 00062 // create canvas 00063 TCanvas MyCanvas("CanvasName","Canvas Title",800,600); 00064 00065 // set statistics on 00066 gStyle->SetOptStat(111111); 00067 00068 // set paper size 00069 Int_t width = 21; 00070 Int_t height = 27; 00071 gStyle->SetPaperSize(width, height); 00072 00073 // define output ps file 00074 TPostScript ps("Example_read_hist_file_list_draw_ps.ps",111); 00075 00076 //range of figures on ps page 00077 ps.Range(20,26); 00078 00079 //.................................................................. 00080 // The following code (in ...) is all because you don't know the names 00081 // of the histograms in the file ahead of time 00082 00083 TList* list = fin->GetListOfKeys() ; 00084 if (!list) { printf("<E> No keys found in file\n") ; exit(1) ; } 00085 TIter next(list) ; 00086 TKey* key ; 00087 TObject* obj ; 00088 00089 while ( key = (TKey*)next() ) { 00090 obj = key->ReadObj() ; 00091 if ( (strcmp(obj->IsA()->GetName(),"TProfile")!=0) 00092 && (!obj->InheritsFrom("TH2")) 00093 && (!obj->InheritsFrom("TH1")) ) 00094 { 00095 printf("<W> Object %s is not 1D or 2D histogram : " 00096 "will not be converted\n",obj->GetName()) ; 00097 } 00098 00099 printf("Histo name:%s title:%s\n",obj->GetName(),obj->GetTitle()); 00100 00101 //............................................................... 00102 00103 // Now do the following commands for each histogram 00104 obj->Draw(); 00105 // do after each histogram (don't have to if at command line) 00106 gPad->Update(); 00107 } 00108 00109 // close output file 00110 ps.Close(); 00111 cout << " finished macro " << endl; 00112 } 00113
1.5.9