Go to the documentation of this file.00001
00002
00003
00004
00005
00007
00009
00010
00012
00013
00014
00016 #include "Riostream.h"
00017
00018
00019 #ifdef __GO4MACRO__
00020
00021 Bool_t hishisto(const char* name1, Int_t bins, Bool_t draw)
00022 {
00023
00024 if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) {
00025 std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl;
00026 return kFALSE;
00027 }
00028 TString fullname1 = go4->FindItem(name1);
00029 TObject* ob1 = go4->GetObject(fullname1,1000);
00030 if((ob1==0) || !ob1->InheritsFrom("TH1")) {
00031 std::cout <<"corr could not get histogram "<< fullname1 << std::endl;
00032 return kFALSE;
00033 }
00034
00035 TH1* his1 = (TH1*)ob1;
00036
00037 #else
00038
00039 Bool_t hishisto(const char *file, const char* name1, Int_t bins, Bool_t draw)
00040 {
00041 TFile *f = TFile::Open(file,"r");
00042 if(f == 0) {
00043 std::cout <<"corrhistos could not open file " << file << std::endl;
00044 return kFALSE;
00045 }
00046 TH1* his1 = dynamic_cast<TH1*> (f->Get(name1));
00047 if(his1 == 0) {
00048 std::cout <<"corrhistos could not get histogram "<<name1 << " in file " << file << std::endl;
00049 return kFALSE;
00050 }
00051 #endif
00052 TString n1 = his1->GetName();
00053 TString t1 = his1->GetTitle();
00054 TString finalname = n1+"-stat";
00055 TString axistitle = n1+" content";
00056 TString finaltitle = t1+" statistics";
00057 Double_t max = his1->GetMaximum();
00058 Double_t min = his1->GetMinimum();
00059 std::cout << min << " " << max << std::endl;
00060 if(max > 0) max = 1.1*max;
00061 else max = 0.9*max;
00062 if(min > 0) min = 0.9*min;
00063 else min = 1.1*min;
00064 TH1I* stat = new TH1I(finalname,finaltitle,bins,min,max);
00065 stat->GetXaxis()->SetTitle(axistitle);
00066 stat->GetYaxis()->SetTitle("Counts");
00067 TGaxis::SetMaxDigits(2);
00068 stat->GetXaxis()->SetNoExponent(kTRUE);
00069
00070 Int_t nb1=his1->GetNbinsX();
00071 for(Int_t i=1;i<=nb1;i++)
00072 {
00073 stat->Fill(his1->GetBinContent(i));
00074 }
00075
00076 #ifdef __GO4MACRO__
00077
00078 TString graname = go4->SaveToMemory("Statistics",stat,kTRUE);
00079 std::cout << graname.Data() << std::endl;
00080 if(!draw) return kTRUE;
00081 ViewPanelHandle vpanel = go4->StartViewPanel();
00082 go4->DrawItem(graname, vpanel, "");
00083 #else
00084 TCanvas *canv = new TCanvas(file,finaltitle,1100,800);
00085 stat->Draw();
00086 canv->Update();
00087 #endif
00088 return kTRUE;
00089 }