class TSpyCanvas : public TCanvas { RQ_OBJECT("TSpyCanvas") private: vector fColorList; int fLastColor; TList *fCutList; bool fIsIntegralEnabled; TLegend *fLegend; TCutG *fCut; int npoint; public: TSpyCanvas(const char *name, Int_t ww, Int_t wh, Int_t winid); ~TSpyCanvas(); void RemoveIntegrals(); void DefineCountArea(Int_t event,Int_t px,Int_t py,TObject* obj); // *SLOT* void DoIntegral(); //*MENU* ClassDef(TSpyCanvas, 0); }; TSpyCanvas(const char *name, Int_t ww, Int_t wh, Int_t winid) : TCanvas(name,ww,wh,winid) { fLastColor=0; fColorList.push_back(kRed); fColorList.push_back(kGreen); fColorList.push_back(kBlue); fColorList.push_back(kBlack); fColorList.push_back(kBlack); fColorList.push_back(kMagenta); fColorList.push_back(kOrange); fColorList.push_back(kCyan); fLegend = new TLegend(0.12,0.73,0.55,0.88); fLegend->SetBorderSize(0); fIsIntegralEnabled = false; fCutList = new TList(); fCutList->SetOwner(true); } void RemoveIntegrals() { fCutList->Delete(); this->Modified(); this->Update(); fLegend->GetListOfPrimitives()->Delete(); } ~TSpyCanvas() { delete fCutList; } void DoIntegral() { cout << "do integral" << endl; this->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","TSpyCanvas",this, "DefineCountArea(Int_t,Int_t,Int_t,TObject*)"); } void DefineCountArea(Int_t event,Int_t px,Int_t py,TObject* obj) { if(!obj->InheritsFrom(TH2::Class())) { cout << "is not th2" << endl; //this->SetEditable(kTRUE); return; } this->SetEditable(kFALSE); cout << event << endl; if(event == 1) { fCut = new TCutG(); fCut->SetLineColor(fColorList[fLastColor]); if(++fLastColor >= fColorList.size()) fLastColor=0; fCut->SetLineWidth(2); fCutList->Add(fCut); npoint =0; } if(event == 21 || event == 1) { cout << "ev 21 | 1" << endl; // Float_t upx = this->AbsPixeltoX(px); Float_t x = this->PadtoX(this->AbsPixeltoX(px)); // Float_t upy = gPad->AbsPixeltoY(py); Float_t y = this->PadtoY(this->AbsPixeltoY(py)); fCut->AddPoint(x,y); this->SetEditable(kTRUE); fCut->Paint(); this->SetEditable(kFALSE); } if(event == 11) { if(fCut) { fCut->AddPoint(fCut->GetPointX(0),fCut->GetPointY(0)); this->SetEditable(kTRUE); fCut->Paint(); this->SetEditable(kFALSE); TList* primitives = this->GetListOfPrimitives(); TIter next(primitives); while(TObject *obj = next()) { if(obj->InheritsFrom(TH2::Class())) { fCut->IntegralHist((TH2*)obj); fLegend->AddEntry(fCut,Form("%i cts"),"l"); break; } } fCut = nullptr; this->Disconnect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", (void*)this, "DefineIntArea(Int_t,Int_t,Int_t,TObject*)"); } } this->Modified(); this->Update(); }