00001 void plothistos(const char* file, Stat_t lo, Stat_t up, Bool_t ylog) 00002 { 00003 // parameters: 00004 // file= filename with histograms to display (without ".root") 00005 // lo: x axis lower limit (in axis units); -1 to show full range 00006 // up: x axis upper limit (in axis units) 00007 // ylog: 1 to display y in logscale, 0 for linear scale 00009 // examples of usage: 00010 // .L plothistos.C 00011 // plothistos("mar0492_ASF",500,1000,0); 00012 // plothistos("mar0492_ASF",-1,0,1); 00013 // 00015 // NOTE: for Go4 Version > 2.8 and ROOT >= 4.00/06, 00016 // Go4 uses the root library mapping, so it is not 00017 // necessary to use gSystem->Load of required libraries in any 00018 // macro. If you work with older versions of root, 00019 // please uncomment the following lines: 00020 //gSystem->Load("libThread.so"); 00021 //gSystem->Load("libMinuit.so"); 00022 //gSystem->Load("$GO4SYS/lib/libGo4Base.so"); 00023 //gSystem->Load("$GO4SYS/lib/libGo4Fit.so"); 00024 //gSystem->Load("$GO4SYS/lib/libGo4ThreadManager.so"); 00025 //gSystem->Load("$GO4SYS/lib/libGo4TaskHandler.so"); 00026 //gSystem->Load("$GO4SYS/lib/libGo4Version.so"); 00027 //gSystem->Load("$GO4SYS/lib/libGo4AnalBase.so"); 00028 //gSystem->Load("$GO4SYS/lib/libGo4Analysis.so"); 00029 //gSystem->Load("libGo4UserAnalysis.so"); 00030 00031 #include <fstream.h> 00032 #include <stdio.h> 00033 #include <stdarg.h> 00034 00035 // number of histograms/pad divisions 00036 #define NUMHIS 6 00037 00040 gStyle->SetTitleX(0.22); // top left corner (ratio of pad width 0...1) 00041 gStyle->SetTitleY(0.97); // top left corner (ratio of pad height 0...1) 00042 //gStyle->SetTitleW(0.1); // box width; if not specified, title box will match text 00043 //gStyle->SetTitleH(0.1); // box height; if not specified, title box will match text 00044 //gStyle->SetTitleFillColor(1); 00045 //gStyle->SetTitleTextColor(1); 00046 //gStyle->SetTitleStyle(1001); 00047 //gStyle->SetTitleFontSize(0); 00048 //gStyle->SetTitleBorderSize(2); 00049 00050 00051 // // settings for histogram statistics box 00052 // gStyle->SetStatBorderSize(2); 00053 // gStyle->SetStatFont(62); 00054 // gStyle->SetStatFontSize(0); 00055 // gStyle->SetStatFormat("6.4g"); // printf like format string 00056 gStyle->SetStatX(0.95); // top right corner (ratio of pad size 0...1) 00057 gStyle->SetStatY(0.95); // top right corner (ratio of pad size 0...1) 00058 //gStyle->SetStatW(0.19); // relative to pad size 00059 //gStyle->SetStatH(0.1); // relative to pad size 00060 gStyle->SetOptStat("neimr"); // what is in statistic box: 00061 // n : name of histogram is printed 00062 // e : number of entries printed 00063 // m : mean value printed 00064 // r : rms printed 00065 00066 // u : number of underflows printed 00067 // o : number of overflows printed 00068 // i : integral of bins printed 00069 00070 00071 // // x axis label 00072 // gStyle->SetLabelFont(62,"X"); 00073 // gStyle->SetLabelOffset(0.005,"X"); 00074 // gStyle->SetLabelSize(0.04,"X"); 00075 00076 // // y axis label 00077 // gStyle->SetLabelFont(62,"Y"); 00078 // gStyle->SetLabelOffset(0.005,"Y"); 00079 // gStyle->SetLabelSize(0.04,"Y") 00080 00081 //TString filename="test_ASF.root"; 00082 TCanvas* mycan=new TCanvas("printout","myhistograms",1); 00083 Int_t DivX,DivY; 00084 DivX=(int)sqrt(NUMHIS); 00085 DivY=DivX; 00086 if(DivX*DivY<NUMHIS){ 00087 do{ 00088 DivX=DivX+1; 00089 }while(DivX*DivY<NUMHIS); 00090 } 00091 mycan->Divide(DivX,DivY); 00092 TString filename=file; 00093 TString filenameroot = filename+".root"; 00094 TFile* myfile = TFile::Open(filenameroot.Data(),"READ"); 00095 TH1* his[NUMHIS]; 00096 TString hname[NUMHIS]; 00097 for(Int_t i=0; i<NUMHIS; ++i) 00098 { 00099 //hname[i]="Ge7_0"; 00100 hname[i]="Cr1Ch0"; // specify "name pattern" for histograms here 00101 hname[i]+=i+1; // Cr1Ch01 to Cr1Ch06 00102 his[i]= (TH1*) myfile->FindObjectAny(hname[i].Data()); 00103 if(his[i]) 00104 { 00105 std::cout <<"Loaded "<<hname[i].Data() << std::endl; 00106 mycan->cd(i+1); 00107 // here settings for adjust histogram view: 00109 //gPad->SetLogx(kTRUE); 00110 gPad->SetLogy(ylog); 00111 //gPad->SetGridx(kTRUE); // grid background for pad 00112 //gPad->SetGridy(kTRUE); 00113 TAxis* xax=his[i]->GetXaxis(); 00114 if(lo>=0) xax->SetRangeUser(lo,up); 00115 //xax->SetNdivisions(20,kTRUE); // specify axis divisions 00116 //xax->SetTicks("+-"); // ticks on which side of the axis 00117 //xax->SetTickLength(0.02); // ratio of pad width for tick length 00119 xax->SetTitle("Channels"); 00120 xax->CenterTitle(kTRUE); // default is right just 00121 //xax->SetTitleOffset(1); // 1 is default distance from axis 00122 //xax->SetTitleSize(0.05); // ratio of pad width 00123 //xax->SetTitleFont(62); 00125 //xax->SetLabelOffset(1); // 1 is default distance from axis 00126 //xax->SetLabelSize(0.05); // ratio of pad width 00127 //xax->SetLabelFont(62); 00128 TAxis* yax=his[i]->GetYaxis(); 00129 //yax->SetRangeUser(0,1000); 00130 //xax->SetNdivisions(10,kTRUE); // specify axis divisions 00131 //yax->SetTicks("+-");// ticks on which side of the axis 00132 //yax->SetTickLength(0.02); // ratio of pad width for tick length 00134 yax->SetTitle("N"); 00135 //yax->CenterTitle(kTRUE); // default is top just 00136 //yax->SetTitleOffset(1); 00137 //yax->SetTitleOffset(1); // 1 is default distance from axis 00138 //yax->SetTitleSize(0.05); // ratio of pad width 00139 //yax->SetTitleFont(62); 00141 //yax->SetLabelOffset(1); // 1 is default distance from axis 00142 //yax->SetLabelSize(0.05); // ratio of pad width 00143 //yax->SetLabelFont(62); 00147 00148 his[i]->Draw(); 00149 00150 } 00151 else 00152 { 00153 std::cout <<"Could not read histogram "<<hname[i].Data()<<" from file "<<filenameroot.Data() << std::endl; 00154 } 00155 } 00156 00157 }