#include #include #include #include "TROOT.h" void exec3_mod() { // Temporary work around the lack of automatic refresh of the list // when a script is reloaded. gROOT->GetListOfGlobalFunctions()->Delete(); TH1F *h1 = new TH1F("h1","h1",100,-3,3); TH1F *h2 = new TH1F("h2","h2",100,-5,5); h1->FillRandom("gaus",1000); h2->FillRandom("gaus",1000); TCanvas *c1=new TCanvas("c1"); c1->Divide(1,2); c1->cd(1); h1->Draw(); c1->cd(2); h2->Draw(); c1->Update(); c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0, "exec3event(Int_t,Int_t,Int_t,TObject*)"); } void exec3event(Int_t event, Int_t x, Int_t y, TObject *selected) { if (event != 11) return; TCanvas *c = (TCanvas *) gTQSender; // printf("Canvas %s: event=%d, x=%d, y=%d, selected=%s, selected name=%s\n", c->GetName(), // event, x, y, selected->IsA()->GetName(), selected->GetName()); if (!selected->InheritsFrom(TPad::Class())) return; TPad *pad = (TPad*)selected; std::string pname = pad->GetName(); TH1D* htmp = new TH1D; TObject *obj; TIter next(pad->GetListOfPrimitives()); while ((obj = next())) { if (obj->InheritsFrom(TH1::Class())) { TH1* h = (TH1*)obj; htmp = (TH1D*)h->Clone(); } } TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2"); if(c2) delete c2->GetPrimitive(""); else c2 = new TCanvas("c2","",700,500); c2->cd(); htmp->Draw(); c2->Update(); }