// Glauber States - CERN ROOT implemantation of Glauber Applet // // Java Applet and description: // http://web.ift.uib.no/AMOS/MOV/HO/ // http://www-troja.fjfi.cvut.cz/~ladi/HO/ // // CERN ROOT http://root.cern.ch/ // // // Developed in 2002 by L. Kocbach (ladi@ift.uib.no) // in collaboration with a student project: // Fadia Jaber contributed to the basic math part // Suhail Lubbad contributed to the basic math part // // point root console to a directory containing this file // at the command line ( root [0] ) // root [0] .x Glauber.C // // // http://www.slac.stanford.edu/grp/eg/minos/ROOT_CVS/root/ // // AnimSliders.C: test program for ROOT sliders // .x AnimSliders.C // Based on Bsliders.C which was based on // guitest.C from tutorials // // Constructed by L. Kocbach, ladi@ift.uib.no // // Fadia Jaber contributed to the basic math part // Suhail Lubbad contributed to the basic math part // ( suhail.lubbad@gmail.com ) // // // Note: as stand-alone it might crash on exit // Stable in Root // // This runs an animation which you can stop and start // // // This user interface example is developed for use of // // ROOT system // for educational demonstration programs // including animations etc // // // What happens on .x AnimSliders.C // By dragging the sliders, you change the function // WHICH IS ANIMATED in the // standard root canvas with a graph // // See the comments in BergenMainFrame::BergenMainFrame() // reprinted below here: // // fVframe1 fVframe2 fVframe3 are three frames // where we put the 4 sliders (2 in each) and the exit button into fVframe3 // // The four text fields are fTeh1 fTeh2 fTev1 fTev2 (belong to the sliders) // The sliders: fHslider1 fHslider2 fVslider1 fVslider2 // The sliders and text fields are bound together ONLY in the callback // functions // All response to sliders is in DoSlider() // All response to text is in DoText() // The exit button fExitButton has response DoExit(); // The variables to be used are defined and used in the last section // =========================== // Program itself // =========================== // The variables (5 of them) are WhichButton ... 4 and BergenUserVar // WhichButton ... 4 are used in the functions // BergenMainFrame::DoText() and BergenMainFrame::DoSlider() // // // Hints for use // // You will wish perhaps to use only the type of slider used for fVslider2 // which has a most flexible range // Hint: if you need 5 of such sliders, make 5 frames as fVframe1 // put each of the sliders in one such frame // remove the other definitions // change the DoSlider and DoText // If you decide to remove text fields, you must remove ref. to them // // Generally, no need to change the canvas and the BergenMainFrame // All changes for your application should take place in // DoText, DoSlider, and in the last section "Program itself" // // // Watch also the identifier collection EBergenCommandIdentifiers // Your new names MUST be added there // They are used as object identifiers // // // Hint: The last part could also be made into an object // // Hint: So could a frame with n sliders // and a frame with n buttons // when you are building several applications // of the same type // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // =================================================== enum EBergenCommandIdentifiers { VId1, HId1, VId2, HId2, VSId1, HSId1, VSId2, HSId2 }; class BergenMainFrame { private: TGMainFrame *fMain; TGCompositeFrame *fStatusFrame; TGVerticalFrame *fVframe1, *fVframe2, *fVframe3, *fVframe4; TGLayoutHints *fBly, *fBfly1; TGHSlider *fHslider0, *fHslider1, *fHslider2, *fHslider3, *fHslider4, *fHslider5, *fHslider6, *fHslider7, *fHslider8, *fHslider9; TGVSlider *fVslider0; TGButton *fButton0, *fButton1, *fButton2, *fButton3, *fButton4, *fButton5, *fButton6, *fButton7, *fButton8, *fButton9; TGButton *fExitButton, *fGoButton *fStopButton; public: BergenMainFrame(const TGWindow *p, UInt_t w, UInt_t h); virtual ~BergenMainFrame(); void CloseWindow(); void DoButtons(const char *text); void DoSlider(Int_t pos = 0); void AdjustSliders(); void DoExit(); void DoStartAnim(); // for animation buttons void DoStopAnim(); void Welcome() { printf("BergenMainFrame has been created. Welcome!\n"); } }; BergenMainFrame::BergenMainFrame(const TGWindow *p, UInt_t w, UInt_t h) { // Create test main frame. A TGMainFrame is a top level window. fMain = new TGMainFrame(p, w, h); fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame); // // fVframe1 fVframe2 fVframe3 are three frames // where we put the 4 sliders (2 in each) and the exit button into fVframe3 // // The four text fields are fTeh1 fTeh2 fTev1 fTev2 (belong to the sliders) // The sliders: fHslider1 fHslider2 fVslider1 fVslider2 // The sliders and text fields are bound together ONLY in the callback // functions // All response to sliders is in DoSlider() // All response to text is in DoText() // The exit button fExitButton has response DoExit(); //--- layout for buttons: top align, equally expand horizontally fBly = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 3, 0); //--- layout for the frame: place at bottom, right aligned fBfly1 = new TGLayoutHints(kLHintsTop | kLHintsRight, 20, 10, 15, 0); // fVframe1 Exit Button Frame fVframe1 = new TGVerticalFrame(fMain, 0, 0, 0); fHslider9 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, 209); fHslider9->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fHslider9->SetRange(0,100); fVframe1->AddFrame(fHslider9, fBly); fHslider8 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, 208); fHslider8->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fHslider8->SetRange(0,100); fVframe1->AddFrame(fHslider8, fBly); fHslider7 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, 207); fHslider7->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fHslider7->SetRange(0,100); fVframe1->AddFrame(fHslider7, fBly); fHslider6 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, 206); fHslider6->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fHslider6->SetRange(0,100); fVframe1->AddFrame(fHslider6, fBly); fHslider5 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, 205); fHslider5->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fHslider5->SetRange(0,100); fVframe1->AddFrame(fHslider5, fBly); fHslider4 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, 204); fHslider4->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fHslider4->SetRange(0,100); fVframe1->AddFrame(fHslider4, fBly); fHslider3 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, 203); fHslider3->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fHslider3->SetRange(0,100); fVframe1->AddFrame(fHslider3, fBly); fHslider2 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, 202); fHslider2->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fHslider2->SetRange(0,100); fVframe1->AddFrame(fHslider2, fBly); fHslider1 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, 201); fHslider1->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fHslider1->SetRange(0,100); fVframe1->AddFrame(fHslider1, fBly); fHslider0 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, 200); fHslider0->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fHslider0->SetRange(0,100); fVframe1->AddFrame(fHslider0, fBly); // fVframe2 Vertical Slider Frame fVframe2 = new TGVerticalFrame(fMain, 0, 0, 0); fVslider0 = new TGVSlider(fVframe2, 300, kSlider1 | kScaleBoth, 301); fVslider0->Connect("PositionChanged(Int_t)", "BergenMainFrame", this, "DoSlider(Int_t)"); fVslider0->SetRange(0,300); fVframe2->AddFrame(fVslider0, fBly); // fVframe3 Exit Button Frame fVframe3 = new TGVerticalFrame(fMain, 0, 0, 0); // EXIT BUTTON fExitButton = new TGTextButton( fVframe3, " Close ", 1); fExitButton->Connect("Clicked()", "BergenMainFrame",this, "DoExit()"); fVframe3->AddFrame(fExitButton, fBly ); fGoButton = new TGTextButton( fVframe3, " Start Anim ", 1); fGoButton->Connect("Clicked()", "BergenMainFrame",this, "DoStartAnim()"); fVframe3->AddFrame(fGoButton, fBly ); fStopButton = new TGTextButton( fVframe3, " Stop Anim ", 1); fStopButton->Connect("Clicked()", "BergenMainFrame",this, "DoStopAnim()"); fVframe3->AddFrame(fStopButton, fBly ); // fVframe4 Button Frame fVframe4 = new TGVerticalFrame(fMain, 0, 0, 0); // MANY BUTTONS fButton9 = new TGTextButton( fVframe4, " 9 ", 109); fButton9->Connect("Clicked()", "BergenMainFrame",this, "DoButtons()"); fVframe4->AddFrame(fButton9, fBly ); fButton8 = new TGTextButton( fVframe4, " 8 ", 108); fButton8->Connect("Clicked()", "BergenMainFrame",this, "DoButtons()"); fVframe4->AddFrame(fButton8, fBly ); fButton7 = new TGTextButton( fVframe4, " 7 ", 107); fButton7->Connect("Clicked()", "BergenMainFrame",this, "DoButtons()"); fVframe4->AddFrame(fButton7, fBly ); fButton6 = new TGTextButton( fVframe4, " 6 ", 106); fButton6->Connect("Clicked()", "BergenMainFrame",this, "DoButtons()"); fVframe4->AddFrame(fButton6, fBly ); fButton5 = new TGTextButton( fVframe4, " 5 ", 105); fButton5->Connect("Clicked()", "BergenMainFrame",this, "DoButtons()"); fVframe4->AddFrame(fButton5, fBly ); fButton4 = new TGTextButton( fVframe4, " 4 ", 104); fButton4->Connect("Clicked()", "BergenMainFrame",this, "DoButtons()"); fVframe4->AddFrame(fButton4, fBly ); fButton3 = new TGTextButton( fVframe4, " 3 ", 103); fButton3->Connect("Clicked()", "BergenMainFrame",this, "DoButtons()"); fVframe4->AddFrame(fButton3, fBly ); fButton2 = new TGTextButton( fVframe4, " 2 ", 102); fButton2->Connect("Clicked()", "BergenMainFrame",this, "DoButtons()"); fVframe4->AddFrame(fButton2, fBly ); fButton1 = new TGTextButton( fVframe4, " 1 ", 101); fButton1->Connect("Clicked()", "BergenMainFrame",this, "DoButtons()"); fVframe4->AddFrame(fButton1, fBly ); fButton0 = new TGTextButton( fVframe4, " 0 ", 100); fButton0->Connect("Clicked()", "BergenMainFrame",this, "DoButtons()"); fVframe4->AddFrame(fButton0, fBly ); fVframe1->Resize(100, 400); fVframe2->Resize(100, 400); fVframe3->Resize(150, 100); fVframe4->Resize(50, 100); // fVframe4 Button Frame // fVframe3 Exit Button Frame // fVframe1 Many Sliders Frame // fVframe2 Vertical Slider Frame fMain->AddFrame(fVframe2, fBfly1); // fVframe2 Vertical Slider Frame fMain->AddFrame(fVframe1, fBfly1); // fVframe1 Many Sliders Frame fMain->AddFrame(fVframe4, fBfly1); // fVframe4 Button Frame fMain->AddFrame(fVframe3, fBfly1); // fVframe3 Exit Button Frame fVframe3->Resize(150, 100); fMain->SetWindowName("BergenSlider Window"); TGDimension size = fMain->GetDefaultSize(); fMain->Resize(size); fMain->SetWMSize(size.fWidth, size.fHeight); fMain->SetWMSizeHints(size.fWidth, size.fHeight, size.fWidth, size.fHeight, 24, 24); fMain->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize | kMWMDecorMinimize | kMWMDecorMenu, kMWMFuncAll | kMWMFuncResize | kMWMFuncMaximize | kMWMFuncMinimize , kMWMInputFullApplicationModal); // kMWMInputFullApplicationModal BergenMainFrame::AdjustSliders(); fMain->MapSubwindows(); fMain->MapWindow(); gClient->WaitFor(fMain); } BergenMainFrame::~BergenMainFrame() { // Delete all created widgets. delete fStatusFrame; delete fVframe1; delete fVframe2; delete fBfly1; delete fBly; delete fHslider1; delete fHslider2; delete fVslider1; delete fVslider2; delete fTeh1; delete fTeh2; delete fTev1; delete fTev2; delete fMain; } void BergenMainFrame::CloseWindow() { gApplication->Terminate(0); } void BergenMainFrame::DoButtons() { // Handle different buttons. Int_t id; TGButton *btn = (TGButton *) gTQSender; id = btn->WidgetId(); printf("DoButton: id = %d\n", id); Glauber=0; // If any of state button pressed, // The wavefunction is not Glauber type WhichButton=( (int) id ) - 100; WhichSlider=-300; // i.e. not a slider event Restart(); } void BergenMainFrame::DoSlider(Int_t pos) { // Handle slider widgets. Int_t id; int locVar; TGFrame *frm = (TGFrame *) gTQSender; if (frm->IsA()->InheritsFrom(TGSlider::Class())) { TGSlider *sl = (TGSlider*) frm; id = sl->WidgetId(); } else { TGDoubleSlider *sd = (TGDoubleSlider *) frm; id = sd->WidgetId(); } WhichButton=-100; // i.e. not a button event locVar=pos; SliderReading=((double)locVar)/100.0; // double WhichSlider=-200+(int)id; Glauber=0; // If any of state button pressed, // The wavefunction is not Glauber type if (WhichSlider > 50) { WhichSlider=100; Glauber=1; // If the energy slider is moved, Energy evaluated // The wavefunction will be of Glauber type SliderReading=((double)locVar)/300.0; // double } Restart(); } void BergenMainFrame::DoExit() { printf("\nTerminating exit pressed\n"); BergenMainFrame::CloseWindow(); } void BergenMainFrame::AdjustSliders() { BergenMainFrame::fHslider0->SetPosition((int)(CoeffsArr[ 0 ]*100)); BergenMainFrame::fHslider1->SetPosition((int)(CoeffsArr[ 1 ]*100)); BergenMainFrame::fHslider2->SetPosition((int)(CoeffsArr[ 2 ]*100)); BergenMainFrame::fHslider3->SetPosition((int)(CoeffsArr[ 3 ]*100)); BergenMainFrame::fHslider4->SetPosition((int)(CoeffsArr[ 4 ]*100)); BergenMainFrame::fHslider5->SetPosition((int)(CoeffsArr[ 5 ]*100)); BergenMainFrame::fHslider6->SetPosition((int)(CoeffsArr[ 6 ]*100)); BergenMainFrame::fHslider7->SetPosition((int)(CoeffsArr[ 7 ]*100)); BergenMainFrame::fHslider8->SetPosition((int)(CoeffsArr[ 8 ]*100)); BergenMainFrame::fHslider9->SetPosition((int)(CoeffsArr[ 9 ]*100)); BergenMainFrame::fVslider0->SetPosition((int)((MaxEnergy-(Energy-0.5))/MaxEnergy*300)); } void BergenMainFrame::DoStartAnim() { printf("\n Animation running \n"); BU_Go(); } void BergenMainFrame::DoStopAnim() { printf("\n Animation stopped \n"); BU_Wait(); } // /////////////////////////////////////////////////////////////////////// //macro illustrating how to animate a picture using a Timer // // =================================================== // // Program itself // // =================================================== // #include "TMath.h" #include gROOT->Reset(); TControlBar *bar = new TControlBar("vertical", "Animations"); gROOT->SaveContext(); TGraph *GR; TCanvas *C1 ; TGraph *hpx; TTimer *timer = new TTimer(20); // Variables from oscillator int const Nq=25; int const Nx=120; int const Nlev=10; TGraph *levgr[Nlev]; Double_t xx[2], yy[2]; Double_t Btime; Double_t pi; Double_t alfa, Energy, MaxEnergy; Double_t Btime; int animating, Glauber; Double_t Tnum , deltasum2; double PSIarr[Nq][Nx]; Double_t Dens_t[Nx]; Double_t CoeffsArr[Nq]; Double_t Varr[Nx],xarr[Nlev][2],yarr[Nlev][2]; double x[Nx]; double xmin, dx, sum , PSItRe, PSItIm , phase , PsiL; double LconRe[Nq], LconIm[Nq]; // ///////////////////////////////////////////////////////////////////// double fan(int i) { double d=1; double const pi=TMath::Pi(); for(int n=1; n<=i; n++) { d=d*n; } return(1/(sqrt(d*sqrt(pi)*pow((double)2.0,i)))); } //this calculate the coefficient double Coeffs(int i,double alfa) { double d=1; double f; for(int n=1; n<=i; n++) { d=d*n; } // f=(exp(-alfa*alfa/2)*pow((double)alfa,n))/sqrt(d); return((exp(-alfa*alfa/2.0)*pow((double)alfa,i))/sqrt(d)); } double H(int n, double x) { double h1,h2, hn; h2= 1.0; h1= 2.0*x; hn= 1.0; if(n==0) return ((double) h2); if(n==1) return((double) h1); for(int i=2; i<=n;i++) { hn=2*x*h1 - 2*(i-1)*h2; h2=h1; h1=hn; } return (hn); } double Psi_n_form(int n, double x) { double PSI=fan(n)*H(n,x)*exp(-x*x/2.0); return(PSI); } // global variables to change // This must be modified by the User Double_t SliderReading, BergenUserVar; Int_t WhichButton, BergenUserVar2, WhichSlider; const Int_t n = 20; Double_t x[n], y[n]; Double_t xx[2], yy[2]; Double_t Btime; Double_t pi; void HarmOscDefs() { for(int i=0;iClear(""); grV = new TGraph(Nx,x,Varr); GRL = new TGraph(Nx,x, Dens_t); hpxL =new TGraph(2,xx,yy); hpxL->SetMarkerColor(19); hpxL->SetMarkerStyle(6); hpxL->SetMarkerSize(0); hpxL->Draw("AP"); grV->Draw("CP"); GRL->Draw("CP"); for (int k=0; kDraw("CP"); } C1->Modified(); C1->Update(); delete GRL; delete hpxL; delete grV; for (int k=0; kTurnOn(); animating=1; } void BU_Wait() { timer->TurnOff(); animating=0; BUStatic(); } void BUStatic() { timer->TurnOff(); GRL = new TGraph(Nx,x,Dens_t); hpxL =new TGraph(2,xx,yy); C1->Clear(""); hpxL->SetMarkerColor(19); hpxL->SetMarkerStyle(6); hpxL->SetMarkerSize(0); hpxL->Draw("AP"); for (int k=0; kDraw("CP"); grV = new TGraph(Nx,x,Varr); grV->Draw("CP"); for (int k=0; kDraw("CP"); } C1->Modified(); C1->Update(); } void GetEnergy() { Energy=0.5+MaxEnergy*(1.0-SliderReading); if (Energy < 0.500001 ) { Energy=0.500001;} } void SetValues( ) { Btime=0.0; MaxEnergy= 9.5; Energy= 4.5; xmin=-7.0; dx=2.0*abs(xmin)/(double) (Nx-1); pi = TMath::Pi(); xx[0]=-7; yy[0]=0; xx[1]= 7; yy[1]=9.50; // GRAPH =================== C1 = new TCanvas("c1"); // GRAPH =================== for (int k=0; k -1) // Single state Button { for(int iq=0;iq -1) // State Slider Action { for(int iq=10;iq 1.0 ) timer->TurnOff(); BUReplot(); } void Glauber() { SetValues( ); // Window sizes, graphs etc HarmOscDefs(); // Evaluate static H.O. states -> Arrays BUCoherent(); // Coherent coefficients for a given alfa Glauber=1; timer->SetCommand("Animate()"); animating=1; BU_Go(); // does timer->TurnOn(); // bar->AddButton("start", "timer->TurnOn();", "Start animation"); // bar->AddButton("stop", "BUWait();", "Stop animation"); new BergenMainFrame(gClient->GetRoot(), 400, 220); BergenMainFrame::AdjustSliders(); }