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 corrhistos(const char* name1, const char* name2, Bool_t draw)
00022 {
00023 if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) {
00024 std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl;
00025 return kFALSE;
00026 }
00027 TString fullname1 = go4->FindItem(name1);
00028 TObject* ob1=go4->GetObject(fullname1,1000);
00029 if((ob1==0) || !ob1->InheritsFrom("TH1")) {
00030 std::cout <<"corr could not get histogram "<<fullname1 << std::endl;
00031 return kFALSE;
00032 }
00033 TH1* his1 = (TH1*)ob1;
00034 TString fullname2 = go4->FindItem(name2);
00035 TObject* ob2=go4->GetObject(fullname2,1000);
00036 if((ob2==0) || !ob2->InheritsFrom("TH1")) {
00037 std::cout <<"corr could not get histogram "<<fullname2 << std::endl;
00038 return kFALSE;
00039 }
00040 TH1* his2 = (TH1*) ob2;
00041 #else
00042
00043 Bool_t corrhistos(const char *file, const char* name1, const char* name2, Bool_t draw)
00044 {
00045 TFile *f=TFile::Open(file,"r");
00046 if(f == 0) {
00047 std::cout <<"corrhistos could not open file " << file << std::endl;
00048 return kFALSE;
00049 }
00050 TH1* his1=f->Get(name1);
00051 if(his1 == 0) {
00052 std::cout <<"corrhistos could not get histogram "<< name1 << " in file " << file << std::endl;
00053 return kFALSE;
00054 }
00055 TH1* his2=f->Get(name2);
00056 if(his2 == 0) {
00057 std::cout <<"corrhistos could not get histogram "<< name2 << " in file " << file << std::endl;
00058 return kFALSE;
00059 }
00060 #endif
00061 TString n1 = his1->GetName();
00062 TString n2 = his2->GetName();
00063 TString t1 = his1->GetName();
00064 TString t2 = his2->GetName();
00065 TString finalname=n1+"-"+n2;
00066 TString finaltitle=t1+" x "+t2;
00067 Int_t nb1=his1->GetNbinsX();
00068 Int_t nb2=his2->GetNbinsX();
00069 Int_t n = nb1;
00070 if(nb1 > nb2) n = nb2;
00071 TArrayD *x = new TArrayD(n);
00072 TArrayD *y = new TArrayD(n);
00073 for(Int_t i=0;i<n;i++)
00074 {
00075 x->AddAt(his1->GetBinContent(i+1),i);
00076 y->AddAt(his2->GetBinContent(i+1),i);
00077 }
00078 TGraph* result = new TGraph(n,x->GetArray(),y->GetArray());
00079 result->SetNameTitle(finalname,finaltitle);
00080 result->SetMarkerColor(4);
00081 result->SetMarkerSize(0.3);
00082 result->SetMarkerStyle(20);
00083 result->SetLineColor(1);
00084
00085 #ifdef __GO4MACRO__
00086
00087 TString graname = go4->SaveToMemory("Correlations",result,kTRUE);
00088
00089 std::cout << graname.Data() << std::endl;
00090 if(!draw) return kTRUE;
00091 ViewPanelHandle vpanel = go4->StartViewPanel();
00092 go4->DrawItem(graname, vpanel, "AP");
00093 #else
00094 TCanvas *canv=new TCanvas(file,finaltitle,1100,800);
00095 result->Draw("AP");
00096 result->GetXaxis()->SetTitle("xxx");
00097 result->GetYaxis()->SetTitle("yyy");
00098 result->GetXaxis()->CenterTitle();
00099 result->GetYaxis()->CenterTitle();
00100 result->Draw("AP");
00101 canv->Update();
00102 #endif
00103 return kTRUE;
00104 }