Go to the documentation of this file.00001 #include "Riostream.h"
00002
00005
00006
00007
00009
00011
00012
00014 Bool_t rebin(const char* name1, Int_t ngroup1 = 2, Int_t ngroup2 = 0, Bool_t draw = kTRUE)
00015 {
00016 if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) {
00017 std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl;
00018 return kFALSE;
00019 }
00020 TString newname;
00021 if(ngroup1<1) ngroup1=1;
00022 if(ngroup2<1) ngroup2=1;
00023 TString fullname1 = go4->FindItem(name1);
00024 TObject* ob1 = go4->GetObject(fullname1,1000);
00025
00026 TH1* result(0);
00027 if(ob1 && ob1->InheritsFrom("TH2")){
00028 TH2* his1 = (TH2*)ob1;
00029 TString n1 = his1->GetName();
00030 TString t1 = his1->GetTitle();
00031 newname.Form("_rebinned_%d_%d",ngroup1,ngroup2);
00032 TString finalname=n1+newname;
00033 TString finaltitle=t1+newname;
00034 result = his1->Rebin2D(ngroup1,ngroup2,finalname);
00035 result->SetTitle(finaltitle);
00036 } else if(ob1 && ob1->InheritsFrom("TH1")){
00037 ngroup2=0;
00038 TH1* his1=(TH1*)ob1;
00039 TString n1=his1->GetName();
00040 TString t1=his1->GetTitle();
00041 newname.Form("_rebinned_%d",ngroup1);
00042 TString finalname = n1+newname;
00043 TString finaltitle = t1+newname;
00044 result = his1->Rebin(ngroup1,finalname);
00045 result->SetTitle(finaltitle);
00046 } else {
00047 std::cout <<"rebin could not get histogram "<<fullname1 << std::endl;
00048 return kFALSE;
00049 }
00050
00051 result->SetDirectory(0);
00052 TString rname = go4->SaveToMemory("Rebinned", result, kTRUE);
00053 std::cout<< "Saved result histogram to " << rname.Data() <<std::endl;
00054 if(draw){
00055 ViewPanelHandle vpanel = go4->StartViewPanel();
00056 if(ngroup2 == 0){
00057 go4->SetSuperimpose(vpanel,kTRUE);
00058 go4->DrawItem(fullname1, vpanel);
00059 }
00060 go4->DrawItem(rname, vpanel);
00061 }
00062 return kTRUE;
00063 }