/* * AnalysisFrame.cpp * * Created on: Apr 22, 2015 * Author: Hovanes Egiyan */ #include "AnalysisFrame.hh" using namespace std; AnalysisFrame::AnalysisFrame( const ScanPlot* plot, string label, const TGWindow* pWindow, UInt_t width, UInt_t height ) : TGVerticalFrame( pWindow, width, height ), afEmbeddedCanvas( 0 ), afStatusBar(0), afPlot( plot ), afGraphAnalyzer( 0 ), afLabel( label ), afStyle( 0 ) { cout << "In AnalysisFrame::AnalysisFrame()" << endl; afStyle = new TStyle( *gStyle ); SetStyle(); afGraphAnalyzer = new CollimatorGraphAnalyzer( afPlot->getGraph(), afPlot->getScanName(), afLabel ); cout << "GraphAnalyzer has been built for " << afPlot->getGraph()->GetName() << " as " << afLabel << endl; string canvasName; if ( afPlot != 0 ) canvasName = afPlot->getName(); afEmbeddedCanvas = new TRootEmbeddedCanvas( canvasName.c_str(), this, width, height ); Int_t widID = afEmbeddedCanvas->GetCanvasWindowId(); TCanvas *myc = new TCanvas( (canvasName + "::C").c_str(), 0, 0, widID ); afEmbeddedCanvas->AdoptCanvas( myc ); // Link the event info myc->Connect( "ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "AnalysisFrame", this, "EventInfo(Int_t,Int_t,Int_t,TObject*)" ); // Add embedded canvas this->AddFrame( afEmbeddedCanvas, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 1 ) ); Int_t parts[] = {45, 10, 45}; // Create the status bar afStatusBar = new TGStatusBar(this, 50, 10, kVerticalFrame); afStatusBar->SetParts(parts, 4); afStatusBar->Draw3DCorner(kFALSE); this->AddFrame(afStatusBar, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0)); string newName = string( afPlot->getGraph()->GetName() ) + string( ":1" ); afEmbeddedCanvas->GetCanvas()->cd(); SetStyle(); // afStyle->SetOptDate(1); cout << "plot object is at " << hex << showbase << afPlot << dec << endl; cout << "Class name of plot object is " << afPlot->ClassName() << endl; cout << "Detector pointer is " << hex << showbase << afPlot->getDetector() << endl; cout << "Class of Detector pointer is " << afPlot->getDetector()->ClassName() << endl; // cout << "Recovered scanstream pointer is " << hex << showbase // << afPlot->getDetector()->getScanStream() << dec << endl; // if ( afPlot != 0 && afPlot->getDetector() != 0 // && afPlot->getDetector()->getScanStream() != 0 ) { if( afPlot != 0 ) { afDateText = new TText( afStyle->GetDateX(), afStyle->GetDateY(), afPlot->getDate().c_str() ); afDateText->SetX( afStyle->GetDateX() ); afDateText->SetY( afStyle->GetDateY() ); afDateText->SetTextSize( 0.025 ); afDateText->SetNDC( true ); DrawFrame(); } return; } AnalysisFrame::~AnalysisFrame() { if ( afGraphAnalyzer != 0 ) delete afGraphAnalyzer; if( afEmbeddedCanvas != 0 ) delete afEmbeddedCanvas; if( afStatusBar != 0 ) delete afStatusBar; this->Cleanup(); if( afDateText!= 0 ) delete afDateText; if( afStyle != 0 ) delete afStyle; return; } void AnalysisFrame::SetStyle() { // afStyle->SetOptFit( 111 ); // afStyle->SetOptStat( 1101 ); afStyle->SetOptTitle( 1 ); afStyle->SetTitleH( 0.08 ); afStyle->SetTitleW( 0.9 ); afStyle->SetTitleX( 0.5 ); afStyle->SetTitleY( 0.99 ); afStyle->SetMarkerStyle(20); afStyle->SetTitleOffset( 1.7, "X" ); afStyle->SetTitleOffset( 1.7, "Y" ); afStyle->cd(); return; } void AnalysisFrame::DrawFrame() { // afGraphAnalyzer->Draw( "W" ); SetStyle(); afStyle->cd(); // afGraphAnalyzer->Draw( "AWP" ); // afGraphAnalyzer->Draw( "W" ); // afGraphAnalyzer->FitGraph(); gPad->SetFrameFillColor( 0 ); gPad->SetGrid( 1, 1 ); // if ( afGraphAnalyzer->GetMinimum() > 0 ) gPad->SetLogy( 1 ); afGraphAnalyzer->SetMarkerStyle(20); // Draw the graph afGraphAnalyzer->Draw( "TRI1 P0"); // Draw the date afDateText->Draw(); gPad->Update(); gPad->Modified(); return; } void AnalysisFrame::SetStatusText( const char *txt, Int_t pi ) { // Set text in status bar. afStatusBar->SetText( txt, pi ); } void AnalysisFrame::EventInfo( Int_t event, Int_t px, Int_t py, TObject *selected ) { // Writes the event status in the status bar parts const char *text0, *text2; char text1[50]; text0 = selected->GetTitle(); SetStatusText( text0, 0 ); // text1 = selected->GetName(); // SetStatusText( text1, 1 ); if ( event == kKeyPress ) sprintf( text1, "%c", (char) px ); else sprintf( text1, "%d,%d", px, py ); SetStatusText( text1, 1 ); text2 = selected->GetObjectInfo( px, py ); SetStatusText( text2, 2 ); }