Go to the documentation of this file.00001 #include "Riostream.h"
00002
00005
00006
00007
00009
00011
00012
00013
00014
00016 Bool_t projectionY(const char* name1, const char* polyname, Int_t firstxbin, Int_t lastxbin, 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 TH2* his1(0);
00025 if(ob1 && ob1->InheritsFrom("TH2")) his1 = (TH2*) ob1;
00026 if(his1==0) {
00027 std::cout <<"projectionY could not get 2d histogram "<<fullname1 << std::endl;
00028 return kFALSE;
00029 }
00030 TGo4PolyCond* poly(0);
00031 TCutG *cut(0);
00032 if(strlen(polyname)>0){
00033 TString fullname2 = go4->FindItem(polyname);
00034 TObject* ob2=go4->GetObject(fullname2,1000);
00035 if(ob2 && ob2->InheritsFrom("TGo4Condition")) poly = (TGo4PolyCond*) ob2;
00036 if(poly==0) {
00037 std::cout <<"projectionX could not get polygon condition "<<polyname << std::endl;
00038 return kFALSE;
00039 }
00040 }
00041 TString n1 = his1->GetName();
00042 TString t1 = his1->GetTitle();
00043 TString oper;
00044 oper.Form("(xlo=%d, xup=%d)",firstxbin,lastxbin);
00045 TString finalname = TString("Y-Projection of ")+n1;
00046 TString finaltitle = TString("Y-Proj.")+oper+" of "+t1;
00047 TString options("");
00048 if(poly){
00049 cut = (TCutG*) poly->GetCut(kFALSE)->Clone("tempcut");
00050 options.Form("[%s]",cut->GetName());
00051 }
00052 TH1* result = his1->ProjectionY(finalname.Data(),firstxbin,lastxbin);
00053 if(poly) delete cut;
00054 result->SetTitle(finaltitle);
00055 result->SetDirectory(0);
00056 TString rname = go4->SaveToMemory("Projections", result, kTRUE);
00057 std::cout<< "Saved result histogram to " << rname.Data() <<std::endl;
00058 if(draw) {
00059 ViewPanelHandle panel1 = go4->StartViewPanel();
00060 go4->DivideViewPanel(panel1, 2, 1);
00061 go4->SelectPad(panel1, 2);
00062 go4->DrawItem(fullname1, panel1,"COLZ");
00063 go4->SelectPad(panel1, 1);
00064 go4->DrawItem(rname, panel1);
00065 }
00066 return kTRUE;
00067 }