/* * AnalysisMainFrame.cpp * * Created on: Apr 21, 2015 * Author: Hovanes Egiyan */ #include "AnalysisMainFrame.hh" #include #include ClassImp(AnalysisMainFrame) AnalysisMainFrame::AnalysisMainFrame(const TGWindow *pWindow, const char* name, UInt_t width, UInt_t height, const ScanPlot* plot ) : LogableMainFrame(pWindow,width,height), amfLeftFrame(0), amfMiddleFrame(0), amfRightFrame(0), amfPlotFrame(0), amfButtonFrame(0), amfPlot(plot) { this->MakeMenuBar(); cout << "Will set AnalysisMainFrame name to " << name << endl; // Sets window name and shows the main frame SetWindowName( name ); SetName(name); amfPlotFrame = new TGHorizontalFrame( this, 0.95*width, 0.9*height ); amfLeftFrame = new AnalysisFrame( amfPlot, "X", amfPlotFrame, width/3.0, 0.9*height ); amfPlotFrame->AddFrame( amfLeftFrame, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 1) ); amfMiddleFrame = new AnalysisFrame( amfPlot, "U", amfPlotFrame, width/3.0, 0.9*height ); amfPlotFrame->AddFrame( amfMiddleFrame, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 1) ); amfRightFrame = new AnalysisFrame( amfPlot, "Y", amfPlotFrame, width/3.0, 0.9*height ); amfPlotFrame->AddFrame( amfRightFrame, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 1) ); this->AddFrame( amfPlotFrame, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 1) ); amfButtonFrame = new TGHorizontalFrame( this, 0.95*width, 0.1*height); amfButtonFrame->SetBackgroundColor(0xAA7A52); amfLogButton = new TGTextButton(amfButtonFrame, "Make &Log Entry"); amfLogButton->Connect("Clicked()", "AnalysisMainFrame", this, "MakeLogEntry()"); // amfLogButton->SetWidth(900); // amfLogButton->SetMinWidth(800); // amfLogButton->SetHeight(500); amfButtonFrame->AddFrame( amfLogButton, new TGLayoutHints( kLHintsCenterX | kLHintsCenterY, 5, 5, 3, 4) ); amfCloseButton = new TGTextButton(amfButtonFrame, "&Close Window"); amfCloseButton->Connect("Clicked()", "AnalysisMainFrame", this, "CloseWindow()"); // amfCloseButton->SetWidth(900); // amfCloseButton->SetMinWidth(800); // amfCloseButton->SetHeight(500); amfButtonFrame->AddFrame( amfCloseButton, new TGLayoutHints( kLHintsCenterX | kLHintsCenterY, 5, 5, 3, 4) ); amfInfoFrame = new TGHorizontalFrame(amfButtonFrame, width/2, 0.1*height) ; amfButtonFrame->AddFrame( amfInfoFrame, new TGLayoutHints( kLHintsExpandY, 1, 1, 1, 1) ); amfEmbeddedCanvas = new TRootEmbeddedCanvas( "Info", amfInfoFrame, width/2, 0.05*height ); amfInfoFrame->AddFrame( amfEmbeddedCanvas, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 0.05, 0.05, 0.05, 0.05) ); this->AddFrame( amfButtonFrame, new TGLayoutHints( kLHintsExpandX | kLHintsBottom, 1, 1, 1, 1) ); MapSubwindows(); Resize(GetDefaultSize()); MapWindow(); double xWidth = amfLeftFrame->GetFitSigma(); double uWidth = amfMiddleFrame->GetFitSigma(); double yWidth = amfRightFrame->GetFitSigma(); this->UpdateInfo(xWidth,yWidth,uWidth); // Test values // this->UpdateInfo( 3.7749, 3.2787, 3.07715 ); return; } AnalysisMainFrame::~AnalysisMainFrame() { this->Cleanup(); return; } void AnalysisMainFrame::Fit() { cout << "Fitting plots " << amfPlot->getName() << endl; amfLeftFrame->Fit(); amfMiddleFrame->Fit(); // amfRightFrame->Fit(); double xWidth = amfLeftFrame->GetFitSigma(); double uWidth = amfMiddleFrame->GetFitSigma(); double yWidth = amfRightFrame->GetFitSigma(); this->UpdateInfo(xWidth,yWidth,uWidth); return; } void AnalysisMainFrame::UpdateInfo(double xWidth, double yWidth, double uWidth) { double phiAngleDeg = (90.0 / acos(0)) * AnalysisMainFrame::GetPhiAngle( xWidth, yWidth, uWidth ); double sigmaBig = AnalysisMainFrame::GetBigSigma( xWidth, yWidth, uWidth ); double sigmaSmall = AnalysisMainFrame::GetSmallSigma( xWidth, yWidth, uWidth ); cout << "Calculated Phi is " << phiAngleDeg << endl; std::ostringstream streamMessage; streamMessage << std::fixed << std::setprecision(2) << "Derived beam parameters : #phi_{long}^{GlueX} = " << phiAngleDeg << " degrees " << std::setprecision(3) << ", #sigma_{long} = " << sigmaBig << " mm " << ", #sigma_{short} = " << sigmaSmall << " mm " ; cout << streamMessage.str().c_str() << endl; amfEmbeddedCanvas->GetCanvas()->cd(); amfInfoText = new TLatex( 1, 1, streamMessage.str().c_str() ); amfInfoText->SetX( 0.05 ); amfInfoText->SetY( 0.35 ); amfInfoText->SetTextSize(0.5); amfInfoText->SetNDC( true ); amfEmbeddedCanvas->GetCanvas()->cd(); amfInfoText->Draw(); gPad->Update(); gPad->Modified(); } // Return the angle between the beam large axis and the x axis of the GlueX system using the // x, y, and u beam widths. double AnalysisMainFrame::GetPhiAngle( double x, double y, double u ) { double sigma2Diff = (x*x - y*y); double sigma2Sum = (x*x + y*y); if( abs(sigma2Diff) < 1.0e-15 ) { // If widths in x and y are the same then we either have a round beam or the phi angle is +-45 degrees. // Either Phi=-45 or +45 degrees is always correct answer in this case. double angleSign = 1; // If the 45-degree scan has smaller width than the other two scans then sign is negative if( u < x ) angleSign = -1; return ( angleSign * acos(0.0) / 2.0 ); } double tag2phi = ( 2.0 * u*u - sigma2Sum ) / sigma2Diff; double phi = 0.5 * atan( tag2phi ) ; // if y is greater than x then it means the beam rotated by more than 45 degrees (assuming the big axis was along x) // This resolves the ambiguity due to the range of phi from -45 to 45 . if( x < y ) { phi += acos( 0.0 ); } return( phi ); } double AnalysisMainFrame::GetBigSigma( double x, double y, double u ) { double sigma2Diff = (x*x - y*y); double sigma2Sum = (x*x + y*y); double phi = GetPhiAngle( x, y , u ); double bigSigma = 0; if( abs(cos(2*phi)) > 1.0e-15 ) { bigSigma = sqrt( 0.5 * ( sigma2Sum + ( 1./cos(2*phi) ) * sigma2Diff ) ) ; } else { if( phi > 0 ) { bigSigma = u ; } else { bigSigma = sqrt( sigma2Sum - u*u ); } } return bigSigma; } double AnalysisMainFrame::GetSmallSigma( double x, double y, double u ) { double sigma2Diff = (x*x - y*y); double sigma2Sum = (x*x + y*y); double phi = GetPhiAngle(x, y , u); double smallSigma = 0; if( abs(cos(2*phi)) > 1.0e-15 ) { if( ( sigma2Sum - (sigma2Diff)/cos(2*phi) ) < 0 ) { smallSigma = std::numeric_limits::quiet_NaN(); } else { smallSigma = sqrt( 0.5 * ( sigma2Sum - ( 1./cos(2*phi) ) * sigma2Diff ) ) ; } } else { if( phi < 0 ) { smallSigma = u ; } else { smallSigma = sqrt( sigma2Sum - u*u ); } } return smallSigma; }