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