Go to the documentation of this file.00001 #include "Riostream.h"
00002
00005
00006
00007
00009
00011
00012
00013
00014
00015
00016
00017
00019 Bool_t scalex(const char* name1, Double_t a1 = 1, Double_t a0= 0, Bool_t draw = kTRUE)
00020 {
00021 if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) {
00022 std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl;
00023 return kFALSE;
00024 }
00025
00026 TString fullname1 = go4->FindItem(name1);
00027 TObject* ob1=go4->GetObject(fullname1,1000);
00028 TH1* his1(0);
00029 if(ob1 && ob1->InheritsFrom("TH1"))
00030 his1 = (TH1*)ob1;
00031 if(his1==0) {
00032 std::cout <<"rebin could not get histogram "<<fullname1 << std::endl;
00033 return kFALSE;
00034 }
00035 if(his1->InheritsFrom("TH2") || his1->InheritsFrom("TH3")) {
00036 std::cout <<"can not scale multi dim histogram "<<fullname1 << std::endl;
00037 return kFALSE;
00038 }
00039 TString n1 = his1->GetName();
00040 TString t1 = his1->GetTitle();
00041 TString soper;
00042 soper.Form("_scaled_a1:%f_a0:%f",a1,a0);
00043 TString finalname = n1+soper;
00044 TString finaltitle = t1+soper;
00045 Int_t nbins = his1->GetNbinsX();
00046 std::cout <<"rescaling histogram of " << nbins << " bins..." << std::endl;
00047
00048 Double_t* binarray = new Double_t[nbins+1];
00049 for(Int_t i=0; i<=nbins; ++i)
00050 binarray[i] = a1*(his1->GetXaxis()->GetBinUpEdge(i)) + a0;
00051
00052 TH1* result = new TH1I(finalname, finaltitle, nbins, binarray);
00053 for(Int_t i=0; i<nbins; ++i)
00054 result->SetBinContent(i,his1->GetBinContent(i));
00055 delete[] binarray;
00056
00057
00058 result->SetDirectory(0);
00059 TString rname = go4->SaveToMemory("Scaled", result, kTRUE);
00060 std::cout<< "Saved result histogram to " << rname.Data() <<std::endl;
00061 if(draw) {
00062 ViewPanelHandle vpanel = go4->StartViewPanel();
00063 go4->DrawItem(rname, vpanel);
00064 }
00065 return kTRUE;
00066 }