/* * GraphAnalyzer.cpp * * Created on: Apr 22, 2015 * Author: Hovanes Egiyan */ #include "GraphAnalyzer.hh" using namespace std; GraphAnalyzer::GraphAnalyzer( TGraph2DErrors* graph, string sName, string label ) : TGraph2DErrors( *(dynamic_cast(graph->Clone( (string(graph->GetName()) + ":" + label ).c_str() )) ) ) , gaScanName(sName), gaLabel(label) { cout << "In GraphAnalyzer::GraphAnalyzer() with name " << GetName() << endl; cout << "Setting titles to : " << graph->GetXaxis()->GetTitle() << " and " << graph->GetYaxis()->GetTitle() << endl; this->GetXaxis()->SetTitle(graph->GetXaxis()->GetTitle()); this->GetYaxis()->SetTitle(graph->GetYaxis()->GetTitle()); return; } GraphAnalyzer::GraphAnalyzer( const GraphAnalyzer& analyzer ) : TGraph2DErrors( analyzer ) { gaScanName = analyzer.gaScanName; gaLabel = analyzer.gaLabel; this->GetXaxis()->SetTitle(analyzer.GetXaxis()->GetTitle()); this->GetYaxis()->SetTitle(analyzer.GetYaxis()->GetTitle()); return; } GraphAnalyzer::~GraphAnalyzer() { return; } TObject* GraphAnalyzer::Clone( const char* newname ) const { GraphAnalyzer* newObject = new GraphAnalyzer( *this ); newObject->SetName( newname ); const_cast(this)->SetName( this->GetName() ); return newObject; } //TH2D* GraphAnalyzer::GetHistogram( Option_t* option ) { // TH2D* tmpHist0 = TGraph2D::GetHistogram( option ); // tmpHist0->SetXTitle( GetXaxis()->GetTitle() ); // tmpHist0->SetYTitle( GetYaxis()->GetTitle() ); // return tmpHist0; //} void GraphAnalyzer::Paint(Option_t *option) { // Paints this 2D graph with its current attributes if (fNpoints <= 0) { Error("Paint", "Empty TGraph2D"); return; } string xTitle = GetXaxis()->GetTitle(); string yTitle = GetYaxis()->GetTitle(); TString opt = option; opt.ToLower(); if (opt.Contains("p") && !opt.Contains("tri")) { if (!opt.Contains("pol") && !opt.Contains("sph") && !opt.Contains("psr")) opt.Append("tri0"); } if (opt.Contains("line") && !opt.Contains("tri")) opt.Append("tri0"); if (opt.Contains("err") && !opt.Contains("tri")) opt.Append("tri0"); if (opt.Contains("tri0")) { GetHistogram("empty"); } else { GetHistogram(); } fHistogram->SetLineColor(GetLineColor()); fHistogram->SetLineStyle(GetLineStyle()); fHistogram->SetLineWidth(GetLineWidth()); fHistogram->SetFillColor(GetFillColor()); fHistogram->SetFillStyle(GetFillStyle()); fHistogram->SetMarkerColor(GetMarkerColor()); fHistogram->SetMarkerStyle(GetMarkerStyle()); fHistogram->SetMarkerSize(GetMarkerSize()); fHistogram->SetXTitle(xTitle.c_str()); fHistogram->SetYTitle(yTitle.c_str()); fHistogram->Paint(opt.Data()); } char* GraphAnalyzer::GetObjectInfo( Int_t px, Int_t py ) const { if ( !gPad ) return (char*) ""; // static char info[64]; // Float_t x = gPad->AbsPixeltoX( px ); // Float_t y = gPad->AbsPixeltoY( py ); TH2D* histPtr = const_cast(this)->GetHistogram(); char* info = histPtr->GetObjectInfo( px, py ); // int xBin = histPtr->GetXaxis()->FindBin( gPad->PadtoX( x ) ); // int yBin = histPtr->GetYaxis()->FindBin( gPad->PadtoY( y ) ); // double value = histPtr->GetBinContent( xBin, yBin ); // snprintf( info, 64, "x=%g, y=%g, z=%g", gPad->PadtoX( x ), gPad->PadtoY( y ), value ); return info; }