]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant3/AliGuiGeomMain.cxx
Mostly minor style modifications to be ready for cloning with EMCAL
[u/mrichter/AliRoot.git] / AliGeant3 / AliGuiGeomMain.cxx
1 /* *************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictlSy for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.5  2002/03/19 09:36:17  morsch
19 Unnecessary includes removes, one included. (Jacek M. Holeczek)
20
21 Revision 1.4  2001/07/18 14:59:13  morsch
22 Unactive code in dialog removed (caused compiling problems with ROOT 3.01/06)
23
24 Revision 1.3  2001/07/17 09:50:21  morsch
25 Index on media and material arrays corrected
26
27 Revision 1.2  2001/07/09 11:46:08  morsch
28 Conversion code moved to AliG3toRoot
29
30 Revision 1.1  2000/07/13 16:19:10  fca
31 Mainly coding conventions + some small bug fixes
32
33 Revision 1.8  2000/07/12 08:56:32  fca
34 Coding convention correction and warning removal
35
36 Revision 1.7  2000/06/28 21:27:45  morsch
37 Most coding rule violations corrected.
38 Still to do: Split the file (on file per class) ? Avoid the global variables.
39 Copy constructors and assignment operators (dummy ?)
40
41 Revision 1.6  2000/04/14 11:07:46  morsch
42 Correct volume to medium assignment in case several media are asigned to the
43 same material.
44
45 Revision 1.5  2000/03/20 15:11:03  fca
46 Mods to make the code compile on HP
47
48 Revision 1.4  2000/01/18 16:12:08  morsch
49 Bug in calculation of number of volume divisions and number of positionings corrected
50 Browser for Material and Media properties added
51
52 Revision 1.3  1999/11/14 14:31:14  fca
53 Correct small error and remove compilation warnings on HP
54
55 Revision 1.2  1999/11/10 16:53:35  fca
56 The new geometry viewer from A.Morsch
57
58 */
59
60 /* 
61  *  Version: 0
62  *  Written by Andreas Morsch
63  *  
64  * 
65  *
66  * For questions critics and suggestions to this part of the code
67  * contact andreas.morsch@cern.ch
68  * 
69  **************************************************************************/
70
71 #include <stdlib.h>
72 #include <TArrayF.h>
73 #include <TGMsgBox.h>
74 #include <TGMenu.h>
75 #include <TGTab.h>
76 #include <TGFrame.h>
77 #include <TGTextBuffer.h>
78 #include <TGTextEntry.h>
79 #include <TGLabel.h>
80 #include <TGButton.h>
81 #include <TGraph.h>
82 #include <TCanvas.h>
83 #include <TH1.h>
84 #include <TApplication.h>
85 #include <TGFileDialog.h>
86 #include <TGListTree.h>
87 #include <TGeant3.h>
88 #include <TShape.h>
89 #include <TGeometry.h>
90 #include <TBRIK.h>
91 #include <TGeometry.h>
92 #include <TList.h>
93 #include <TFile.h>
94 #include <TFolder.h>
95
96 #include "AliGuiGeomMain.h"
97 #include "AliGuiGeomDialog.h"
98 #include "AliG3Volume.h"
99 #include "AliG3Medium.h"
100 #include "AliG3Material.h"
101 #include "AliNode.h"
102
103
104 ClassImp(AliGuiGeomMain)
105
106 static Int_t           gCurrentParticle = 1;
107 static Int_t           gCurrentProcess  = 1;
108
109  const Text_t* kLabelTextP[19]  = 
110 {"PAIR  ", "COMP  ", "PHOT  ", "PFIS  ", "DRAY  ", "ANNI  ", "BREM  ", 
111  "HADR  ", "MUNU  ", "DCAY  ", "LOSS  ", "MULS  ", "GHCOR1", "BIRK1 ", 
112  "BIRK2 ", "BIRK3 ", "LABS  ", "SYNC  ", "STRA  "};
113
114
115  const Text_t* kLabelTextC[10]  = 
116  {"CUTGAM", "CUTELE", "CUTNEU", "CUTHAD", "CUTMUO", "BCUTE", "BCUTM",
117   "DCUTE ", "DCUTM ", "PPCUTM"};
118
119 const Text_t* kLabelTextPart[24]  = 
120 {"Photon", "Positron", "Electron", "Neutrino", "Muon+", "Muon-", 
121  "Pi0", "Pi+", "Pi-", "Kaon_L", "Kaon+", "Kaon-", "Neutron", "Proton", 
122  "Anti Proton", "Kaon_S", "Eta", "Lambda", "Sigma+", "Sigma0", "Sigma-",
123  "Xi0", "Xi-", "Omega-"};
124
125 const Text_t* kLabelTextMechanism[24]  = 
126 {"HADF", "INEF", "ELAF", "FISF", "CAPF",
127  "HADG", "INEG", "ELAG", "FISG", "CAPG",
128  "LOSS", "PHOT", "ANNI", "COMP", "BREM",
129  "PAIR", "DRAY", "PFIS", "RAYL", "HADG",
130  "MUNU", "RANG", "STEP", "MUON"};
131
132
133
134
135 enum ETestCommandIdentifiers {
136    kFileOpen,
137    kFileSave,
138    kFileSaveAs,
139    kFileExit,
140
141    kTestDlg,
142
143    kHelpContents,
144    kHelpSearch,
145    kHelpAbout,
146
147
148    kVId1,
149    kHId1,
150    kVId2,
151    kHId2,
152
153    kVSId1,
154    kHSId1,
155    kVSId2,
156    kHSId2
157 };
158
159
160 Int_t mbButtonId[9] = { kMBYes, kMBNo, kMBOk, kMBApply,
161                           kMBRetry, kMBIgnore, kMBCancel,
162                           kMBClose, kMBDismiss };
163
164 EMsgBoxIcon mbIcon[4] = { kMBIconStop, kMBIconQuestion,
165                            kMBIconExclamation, kMBIconAsterisk };
166
167 const char *kFileTypes[] = { "All files",     "*",
168                             "ROOT files",    "*.root",
169                             "ROOT macros",   "*.C",
170                             0,               0 };
171
172
173
174
175 TGListTreeItem*  AliGuiGeomMain::
176 AddItem(TObject * obj, TGListTreeItem *parent, const char* name, const TGPicture *open, const TGPicture *closed)
177 {
178 // Add item to the list tree
179     return fLt->AddItem(parent, name, obj, open, closed);
180 }
181
182 AliGuiGeomMain::AliGuiGeomMain(const TGWindow *p, UInt_t w, UInt_t h)
183       : TGMainFrame(p, w, h)
184 {
185     // Create test main frame. A TGMainFrame is a top level window.
186     // Create menubar and popup menus. The hint objects are used to place
187     // and group the different menu widgets with respect to eachother.
188     
189     fDialog=0;
190     fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
191                                        0, 0, 1, 1);
192     fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
193     fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
194     
195     fMenuFile = new TGPopupMenu(gClient->GetRoot());
196     fMenuFile->AddEntry("&Open...", kFileOpen);
197     fMenuFile->AddEntry("&Save", kFileSave);
198     fMenuFile->AddEntry("S&ave as...", kFileSaveAs);
199     fMenuFile->AddEntry("&Close", -1);
200     fMenuFile->AddSeparator();
201     fMenuFile->AddEntry("E&xit", kFileExit);
202     
203     fMenuFile->DisableEntry(kFileSaveAs);
204     fMenuFile->DisableEntry(kFileOpen);
205     fMenuFile->DisableEntry(kFileSave);
206     
207
208
209    fMenuTest = new TGPopupMenu(this);
210    fMenuTest->AddLabel("Draw");
211    fMenuTest->AddSeparator();
212    fMenuTest->AddEntry("&Volume Draw Control", kTestDlg);
213    fMenuTest->AddSeparator();
214    fMenuTest->Associate(this);
215    
216    
217    fMenuHelp = new TGPopupMenu(gClient->GetRoot());
218    fMenuHelp->AddEntry("&Contents", kHelpContents);
219    fMenuHelp->AddEntry("&Search...", kHelpSearch);
220    fMenuHelp->AddSeparator();
221    fMenuHelp->AddEntry("&About", kHelpAbout);
222
223    fMenuFile->DisableEntry(kHelpContents);
224    fMenuFile->DisableEntry(kHelpSearch);
225    fMenuFile->DisableEntry(kHelpAbout);
226    // Menu button messages are handled by the main frame (i.e. "this")
227    // ProcessMessage() method.
228    fMenuFile->Associate(this);
229    fMenuTest->Associate(this);
230    fMenuHelp->Associate(this);
231
232    fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
233    fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
234    fMenuBar->AddPopup("&Draw Control", fMenuTest, fMenuBarItemLayout);
235    fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
236
237    AddFrame(fMenuBar, fMenuBarLayout);
238
239 // 
240 // Volumes
241 //
242    fTab = new TGTab(this, 400, 400);
243    TGCompositeFrame *tf = fTab->AddTab("Volumes");
244    TGLayoutHints *lTab = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
245                                           kLHintsExpandY, 2, 2, 5, 1);
246    AddFrame(fTab, lTab);
247
248 // Create TGCanvas and a canvas container which uses a tile layout manager
249    fCanvasWindow = new TGCanvas(tf, 400, 240);
250 // Create TreeList
251    fLt = new TGListTree(fCanvasWindow->GetViewPort(), 10, 10, kHorizontalFrame,
252                         fgWhitePixel);
253    fLt->Associate(this);
254    fCanvasWindow->SetContainer(fLt);
255
256     
257    TGLayoutHints *lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
258    tf->AddFrame(fCanvasWindow, lo);
259 //
260 // Materials
261 //
262    tf = fTab->AddTab("Materials");
263    fF2 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
264    fL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
265 // ComboBox for materials
266    fMaterialCombo = new TGComboBox(fF2, 1);
267    fF2->AddFrame(fMaterialCombo, fL2);
268 // 
269 // text labels with material properties 
270 //
271    Text_t* labelText[6]  = 
272    {"Material Number  ", 
273     "Atomic Weight    ",
274     "Atomic Number    ", 
275     "Density          ",
276     "Radiation Length ", 
277     "Absorption Length"};
278
279    TGLayoutHints* bly   = 
280        new TGLayoutHints(kLHintsTop | kLHintsExpandY, 5, 5, 5, 5);
281    TGLayoutHints* bFly1 = 
282        new TGLayoutHints(kLHintsLeft | kLHintsExpandX );
283    fF21 = new TGCompositeFrame(fF2, 60, 20, kVerticalFrame);
284    fF2->AddFrame(fF21,fL2);
285    { //Begin local scope for i
286      for (Int_t i=0; i<6; i++) {
287        Int_t idT=i+1;       
288        fHframe[i] = new TGHorizontalFrame(fF21, 400, 100, kFixedWidth);
289        fF21->AddFrame(fHframe[i], bly);
290        fTbh[i] = new TGTextBuffer(10);
291        fTeh[i] = new TGTextEntry(fHframe[i], fTbh[i],idT);
292        fTeh[i]->Associate(this);
293        fLabel[i] = new TGLabel(fHframe[i], labelText[i]);
294        fHframe[i]->AddFrame(fLabel[i], bFly1);
295        fHframe[i]->AddFrame(fTeh[i], bFly1);
296      }
297    } //End local scope for i
298    tf->AddFrame(fF2, fL2);
299    fMaterialCombo->Resize(200, 20);
300    fMaterialCombo->Associate(this);
301    
302
303 // Media Combo
304 //   
305    tf = fTab->AddTab("Media");
306    fF3 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
307 // ComboBox for tracking media
308    fMediaCombo = new TGComboBox(fF3, 2);
309    fF3->AddFrame(fMediaCombo, fL2);
310 // 
311 // text labels with material properties 
312 //
313    Text_t* labelTextM[8]  = 
314    {"Sensitivity Flag      ", 
315     "Magnetic Field Flag   ",
316     "Maximum Field         ", 
317     "Max. Ang. Deviation   ",
318     "Maximum Step          ", 
319     "Max. Frac. Energy Loss",
320     "Crossing Precission   ",
321     "Minimum Step Size     "};
322
323    fF31 = new TGCompositeFrame(fF3, 60, 20, kVerticalFrame);
324    fF3->AddFrame(fF31,fL2);
325    { //Begin local scope for i
326      for (Int_t i=0; i<8; i++) {
327        Int_t idT=i+1;       
328        fHframeM[i] = new TGHorizontalFrame(fF31, 400, 100, kFixedWidth);
329        fF31->AddFrame(fHframeM[i], bly);
330        fTbhM[i] = new TGTextBuffer(10);
331        fTehM[i] = new TGTextEntry(fHframeM[i], fTbhM[i],idT);
332        fTehM[i]->Associate(this);
333        fLabelM[i] = new TGLabel(fHframeM[i], labelTextM[i]);
334        fHframeM[i]->AddFrame(fLabelM[i], bFly1);
335        fHframeM[i]->AddFrame(fTehM[i], bFly1);
336      }
337    } //End local scope for i
338    tf->AddFrame(fF3, fL2);
339    fMediaCombo->Resize(200, 20);
340    fMediaCombo->Associate(this);
341 //
342 // Processes
343    tf = fTab->AddTab("Processes");
344    fF4 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
345    fProcessLB = new TGListBox(fF4, 1);
346    fF4->AddFrame(fProcessLB, fL2);
347    tf->AddFrame(fF4, fL2);
348    fProcessLB->Resize(150, 350);
349    fProcessLB->Associate(this);
350    
351 //
352 // Cuts
353    tf = fTab->AddTab("Cuts");
354    fF5 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
355    fCutsLB = new TGListBox(fF5, 1);
356    fF5->AddFrame(fCutsLB, fL2);
357    tf->AddFrame(fF5, fL2);
358    fCutsLB->Resize(150, 350);
359
360 //
361 // de/dx and cross-sections
362    tf = fTab->AddTab("DE/DX and X-Sections");
363    fF6 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
364
365 // ComboBox for particles
366    fF61 = new TGCompositeFrame(fF6, 60, 20, kVerticalFrame);
367    fF6->AddFrame(fF61, fL2);
368    fParticleCombo = new TGComboBox(fF61, 3);
369    fF61->AddFrame(fParticleCombo, fL2);
370    { //Begin local scope for i
371      for (Int_t i = 0; i < 24; i++) {
372        char tmp[20];
373        sprintf(tmp, "%s", kLabelTextPart[i]);
374        fParticleCombo->AddEntry(tmp, i+1);
375      }
376    } //End local scope for i
377    fParticleCombo->Select(1);
378    fParticleCombo->Resize(100, 20);
379    fParticleCombo->Associate(this);
380
381 // ComboBox for mechanisms
382    fF63 = new TGCompositeFrame(fF6, 60, 20, kVerticalFrame);
383    fF6->AddFrame(fF63, fL2);
384    fMechanismCombo = new TGComboBox(fF63, 4);
385    fF63->AddFrame(fMechanismCombo, fL2);
386    { //Begin local scope for i
387      for (Int_t i = 0; i < 24; i++) {
388        char tmp[20];
389        sprintf(tmp, "%s", kLabelTextMechanism[i]);
390        fMechanismCombo->AddEntry(tmp, i+1);
391      }
392    } //End local scope for i
393    fMechanismCombo->Select(1);
394    fMechanismCombo->Resize(100, 20);
395    fMechanismCombo->Associate(this);
396
397 //
398 // Energy Range
399 //
400    fTbh61 = new TGTextBuffer(10);
401    fTeh61 = new TGTextEntry(fF61, fTbh61,10);
402    fTbh61->AddText(0, "  100");
403    fTeh61->Associate(this);
404
405    fTbh62 = new TGTextBuffer(10);
406    fTeh62 = new TGTextEntry(fF61, fTbh62,11);
407    fTbh62->AddText(0, "0.001");
408    fTeh62->Associate(this);
409     
410    fTbh63 = new TGTextBuffer(10);
411    fTeh63 = new TGTextEntry(fF61, fTbh63,12);
412    fTbh63->AddText(0, "10.");
413    fTeh63->Associate(this);
414
415    fEmin=0.001;
416    fEmax=10.;
417    fNbins=100;
418    
419    fSLabel61 = new TGLabel(fF61, "Nbins-Emin-Emax");
420    bFly1 = new TGLayoutHints(kLHintsLeft | kLHintsExpandX );
421    fF61->AddFrame(fSLabel61, bFly1);
422    fF61->AddFrame(fTeh61, bFly1);
423    fF61->AddFrame(fTeh62, bFly1);
424    fF61->AddFrame(fTeh63, bFly1);
425 //
426 // Plot Button
427    fF62 = new TGCompositeFrame(fF6, 60, 20, kHorizontalFrame);
428    fF6->AddFrame(fF62, fL2);
429    fPlotButton = new TGTextButton(fF62, "Plot", 1);
430    fPlotButton -> Associate(this);
431    fF62->AddFrame(fPlotButton);
432
433    tf->AddFrame(fF6, fL2);
434 // Window name and final mapping
435 //
436    SetWindowName("AliRoot Geometry Browser");
437    MapSubwindows();
438    // We need to use GetDefault...() to initialize the layout algorithm...
439    Resize(GetDefaultSize());
440    MapWindow();
441 }
442
443 AliGuiGeomMain::~AliGuiGeomMain()
444 {
445    // Delete all created widgets.
446
447    delete fCanvasWindow;
448
449    delete fMenuBarLayout;
450    delete fMenuBarItemLayout;
451    delete fMenuBarHelpLayout;
452
453    delete fMenuFile;
454    delete fMenuTest;
455    delete fMenuHelp;
456 }
457
458 void AliGuiGeomMain::Streamer(TBuffer &)
459 {
460 // Dummy streamer
461 ;
462 }
463
464 void AliGuiGeomMain::Plot()
465 {
466 // plot de/dx or cross-sections
467     const Float_t kAvo=0.60221367;
468     Float_t *tkin  = new Float_t[fNbins];
469     Float_t *value = new Float_t[fNbins];
470     Float_t *pcut  = new Float_t[fNbins];
471     Int_t ixst;
472     Int_t imate = gCurrentMaterial->Id();
473     Float_t z = gCurrentMaterial->GetZ();
474     Float_t a = gCurrentMaterial->GetA();
475     Float_t density = gCurrentMaterial->GetDensity();
476     
477     Int_t ipart=gCurrentParticle;
478     const char *kChMeca= kLabelTextMechanism[gCurrentProcess-1];
479     char* tmp;
480     tmp = new char[5];
481     strncpy(tmp, kChMeca, 4);
482     tmp[4]='\0';
483     Int_t kdim=fNbins;
484     Float_t de=(fEmax-fEmin)/fNbins;
485     { //Begin local scope for i
486       for (Int_t i=0; i<kdim; i++) {
487         tkin[i]=fEmin+Float_t(i)*de;
488         value[i]=0.;
489       }
490     } //End local scope for i
491     if (kChMeca!="MUON") {
492         ((TGeant3*) gMC)->Gftmat(imate, ipart, tmp, kdim, tkin, value, pcut, ixst);
493     } else {
494         for (Int_t i=0; i<kdim; i++) {
495             Float_t ekin=tkin[i];
496             value[i]+=((TGeant3*) gMC)->Gbrelm(z,ekin,1.e10);
497             value[i]+=((TGeant3*) gMC)->Gprelm(z,ekin,1.e10);
498             value[i]*=1000.*kAvo*density/a;
499         }
500     }
501
502     if (ixst) {
503         TGraph *graph = new TGraph(kdim,tkin,value);
504         TCanvas *c1 = new TCanvas("c1"," ",400,10,600,700);
505         c1->Divide(1,1);
506         c1->cd(1);
507         
508         graph->SetFillColor(42);
509         graph->SetMarkerColor(4);
510         graph->SetMarkerStyle(21);
511         graph->Draw("AC");
512         graph->GetHistogram()->SetXTitle("Energy (GeV)");
513         if (kChMeca == "RANG" || kChMeca == "STEP") {
514             graph->GetHistogram()->SetYTitle
515                 ("Distance (cm)");   
516         } else if (kChMeca == "LOSS" || kChMeca == "MUON") {
517             graph->GetHistogram()->SetYTitle("dE/dx (MeV/cm)");   
518         } else {
519             graph->GetHistogram()->SetYTitle
520                 ("Macroscopic X-Section (1/cm)"); 
521         }
522     }
523     
524     delete tkin;
525     delete value;
526     delete pcut;
527     
528     
529 }
530
531 void AliGuiGeomMain::Update()
532 {
533 // Update widgets
534     if (fDialog) {
535         fDialog->Update();
536     }
537
538     Int_t imat=gCurrentVolume->Material();
539     Int_t nmat=fComboMaterialEntries->GetEntriesFast();
540     Int_t i=0;
541     for (i=0; i<nmat; i++) {
542         gCurrentMaterial = (AliG3Material*) 
543             (fComboMaterialEntries->UncheckedAt(i));
544         if ((gCurrentMaterial->Id())==imat) break;
545     }
546     Int_t imed = gCurrentVolume->Medium();
547     Int_t nmed=fComboMediaEntries->GetEntriesFast();
548     for (i=0; i<nmed; i++) {
549         gCurrentMedium = (AliG3Medium*) 
550             (fComboMediaEntries->UncheckedAt(i));
551         if (gCurrentMedium->Id()==imed) break;
552     }
553
554     UpdateCombo();
555     UpdateListBox();
556     
557 }
558
559 void AliGuiGeomMain::UpdateCombo()
560 {
561 // Update combos
562
563     Int_t   imat = gCurrentMaterial->Id();
564     Float_t    a = gCurrentMaterial->GetA();
565     Float_t    z = gCurrentMaterial->GetZ();    
566     Float_t dens = gCurrentMaterial->GetDensity();
567     Float_t radl = gCurrentMaterial->GetRadLength();
568     Float_t absl = gCurrentMaterial->GetInterLength();
569     Int_t entry  = gCurrentMaterial->GetNumber();
570 //    
571 //
572     fMaterialCombo->Select(entry);
573     fMediaCombo->Select(entry);    
574     char buf[10];
575      
576     sprintf(buf, "%10i", imat);
577     fTbh[0]->Clear();
578     fTbh[0]->AddText(0, buf);
579     gClient->NeedRedraw(fTeh[0]);
580     sprintf(buf, "%10.2e", a);
581     fTbh[1]->Clear();
582     fTbh[1]->AddText(0, buf);
583     gClient->NeedRedraw(fTeh[1]);
584
585     sprintf(buf, "%10.2e", z);
586     fTbh[2]->Clear();
587     fTbh[2]->AddText(0, buf);
588     gClient->NeedRedraw(fTeh[2]);
589
590     sprintf(buf, "%10.2e", dens);
591     fTbh[3]->Clear();
592     fTbh[3]->AddText(0, buf);
593     gClient->NeedRedraw(fTeh[3]);
594
595     sprintf(buf, "%10.2e", radl);
596     fTbh[4]->Clear();
597     fTbh[4]->AddText(0, buf);
598     gClient->NeedRedraw(fTeh[4]);
599
600     sprintf(buf, "%10.2e", absl);
601     fTbh[5]->Clear();
602     fTbh[5]->AddText(0, buf);
603     gClient->NeedRedraw(fTeh[5]);
604
605 //  Media Combo
606     sprintf(buf, "%10i", gCurrentMedium->Isvol());
607     fTbhM[0]->Clear();
608     fTbhM[0]->AddText(0, buf);
609     gClient->NeedRedraw(fTehM[0]);
610
611
612     sprintf(buf, "%10i", gCurrentMedium->Ifield());
613     fTbhM[1]->Clear();
614     fTbhM[1]->AddText(0, buf);
615     gClient->NeedRedraw(fTehM[1]);
616
617     sprintf(buf, "%10.2e", gCurrentMedium->Fieldm());
618     fTbhM[2]->Clear();
619     fTbhM[2]->AddText(0, buf);
620     gClient->NeedRedraw(fTehM[2]);
621
622     sprintf(buf, "%10.2e", gCurrentMedium->Tmaxfd());
623     fTbhM[3]->Clear();
624     fTbhM[3]->AddText(0, buf);
625     gClient->NeedRedraw(fTehM[3]);
626
627     sprintf(buf, "%10.2e", gCurrentMedium->Stemax());
628     fTbhM[4]->Clear();
629     fTbhM[4]->AddText(0, buf);
630     gClient->NeedRedraw(fTehM[4]);
631
632     sprintf(buf, "%10.2e", gCurrentMedium->Deemax());
633     fTbhM[5]->Clear();
634     fTbhM[5]->AddText(0, buf);
635     gClient->NeedRedraw(fTehM[5]);
636
637     sprintf(buf, "%10.2e", gCurrentMedium->Epsil());
638     fTbhM[6]->Clear();
639     fTbhM[6]->AddText(0, buf);
640     gClient->NeedRedraw(fTehM[6]);
641
642     sprintf(buf, "%10.2e", gCurrentMedium->Stmin());
643     fTbhM[7]->Clear();
644     fTbhM[7]->AddText(0, buf);
645     gClient->NeedRedraw(fTehM[7]);
646 }
647
648 void AliGuiGeomMain::UpdateListBox()
649 {
650 // Update the list box
651     Int_t i;
652     fProcessLB->RemoveEntries(1,19);
653     for (i=11; i < 30; i++) {
654         Float_t p=gCurrentMedium->GetPar(i);
655         char tmp[20];
656         sprintf(tmp, "%6s%5d", kLabelTextP[i-11], Int_t(p));
657         fProcessLB->AddEntry(tmp, i-10);
658     }
659     fProcessLB->MapSubwindows();
660     fProcessLB->Layout();
661
662     fCutsLB->RemoveEntries(1,10);
663     for (i=1; i < 11; i++) {
664         Float_t p=gCurrentMedium->GetPar(i);
665         char tmp[20];
666         sprintf(tmp, "%6s%10.3e", kLabelTextC[i-1], p);
667         fCutsLB->AddEntry(tmp,i);
668     }
669     fCutsLB->MapSubwindows();
670     fCutsLB->Layout();
671 }
672
673
674 void AliGuiGeomMain::CloseWindow()
675 {
676    // Got close message for this MainFrame. Calls parent CloseWindow()
677    // (which destroys the window) and terminate the application.
678    // The close message is generated by the window manager when its close
679    // window menu item is selected.
680
681    TGMainFrame::CloseWindow();
682    gApplication->Terminate(0);
683 }
684
685 Bool_t AliGuiGeomMain::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
686 {
687 // Process messages to widgets
688     switch (GET_MSG(msg)) {
689 //
690 //  Text entries for binning of cross-section plots
691     case kC_TEXTENTRY:
692         switch (GET_SUBMSG(msg)) {
693         case kTE_TEXTCHANGED:
694             switch (parm1) {
695             case 10:
696                 fNbins=(Int_t) atof(fTbh61->GetString());
697                 break;
698             case 11:
699                 fEmin= atof(fTbh62->GetString());
700                 break;
701             case 12:
702                 fEmax= atof(fTbh63->GetString());
703                 break;
704             }
705         }
706         break;
707 //
708 // ListTree for volumes
709     case kC_LISTTREE:
710         switch (GET_SUBMSG(msg)) {
711 //
712 // Handle mouse click 
713         case kCT_ITEMCLICK:
714 //
715 // Button 1: Select volume
716             if (parm1 == kButton1) {
717               TGListTreeItem *item;
718               if ((item = fLt->GetSelected())) 
719                 {
720                   gCurrentVolume=((AliG3Volume *) item->GetUserData());
721                   Update();
722                 }
723             }
724 //
725 // Button 2: Draw volume specifications
726
727             if (parm1 == kButton2) {
728                 TGListTreeItem *item;
729                 if ((item = fLt->GetSelected())) 
730                 {
731
732                     ((AliG3Volume *) item->GetUserData())->DrawSpec();
733
734                     gCurrentVolume=((AliG3Volume *) item->GetUserData());
735                     Update();
736                 }
737             }
738 //
739 // Button 3: Draw Volume
740             if (parm1 == kButton3) {
741                 TGListTreeItem *item;
742                 if ((item = fLt->GetSelected())) 
743                 {
744                     ((AliG3Volume *) item->GetUserData())->Draw();
745                     gCurrentVolume=((AliG3Volume *) item->GetUserData());
746                     Update();
747                 }
748             }
749             
750             
751             break;
752         case kCT_ITEMDBLCLICK:
753             if (parm1 == kButton1) {
754                 if (fLt->GetSelected() != 0) {
755                     gClient->NeedRedraw(fLt);
756                 }
757             }
758             break;
759         default:
760             break;
761         }
762         break;
763     case kC_COMMAND:
764         switch (GET_SUBMSG(msg)) {
765         case kCM_BUTTON:
766             switch(parm1) {
767             case 1:
768                 Plot();
769                 break;
770             }
771             break;
772         case kCM_COMBOBOX:
773 //
774 // Combo box bindings
775             switch(parm1) {
776 //
777 // Material Combo
778             case 1:
779                 gCurrentMaterial=(AliG3Material*) 
780                     (fComboMaterialEntries->UncheckedAt(Int_t(parm2-1)));
781                 gCurrentMedium=(AliG3Medium*) 
782                     (fComboMediaEntries->UncheckedAt(Int_t(parm2-1)));
783                 UpdateCombo();
784                 UpdateListBox();
785                 break;
786 //
787 // Media Combo
788             case 2:
789                 gCurrentMedium=(AliG3Medium*) 
790                     (fComboMediaEntries->UncheckedAt(Int_t(parm2-1)));
791                 gCurrentMaterial=(AliG3Material*) 
792                     (fComboMaterialEntries->UncheckedAt(Int_t(parm2-1)));
793                 UpdateCombo();
794                 UpdateListBox();
795                 break;
796 //
797 // Particle Combo
798             case 3:
799                 gCurrentParticle=Int_t(parm2);
800                 break;
801 //
802 // Mechanism Combo
803             case 4:
804                 gCurrentProcess=Int_t(parm2);
805                 break;
806             }
807             break;
808         case kCM_MENUSELECT:
809             break;
810             
811         case kCM_MENU:
812             switch (parm1) {
813             case kFileOpen:
814             {
815                 printf("kFileOpen not yet implemented \n");
816             }
817             break;
818             
819             case kTestDlg:
820                 fDialog = new AliGuiGeomDialog
821                     (gClient->GetRoot(), this, 400, 200);
822                 break;
823                 
824             case kFileSave:
825                 printf("kFileSave not yet implemented \n");
826                 break;
827                 
828             case kFileExit:
829 //              printf("kFileExit not yet implemented \n");
830                 CloseWindow();   // this also terminates theApp
831                 break;
832             default:
833                 break;
834             }
835         default:
836             break;
837         }
838     default:
839         break;
840     }
841     return kTRUE;
842 }
843
844 void AliGuiGeomMain::AddMaterial(AliG3Material *Material, Int_t i)
845 {
846 // Add material to material combo
847     const char* tmp;
848     tmp=Material->GetName();
849     char mName[21];
850     
851     strncpy(mName, tmp, 20);
852     mName[20]='\0';
853     
854 //    Material->SetItemId(i);
855     fMaterialCombo->AddEntry(mName, i);
856     fMaterialCombo->Select(i);
857     fMaterialCombo->Resize(200, 20);
858 }
859
860 void AliGuiGeomMain::AddMedium(AliG3Medium *Medium, Int_t i)
861 {
862 // Add medium to medium combo
863     const char* tmp;
864     tmp=Medium->GetName();
865     char mName[21];
866     strncpy(mName, tmp, 20);
867     mName[20]='\0';
868     Medium->SetItemId(i);
869     fMediaCombo->AddEntry(mName, i);
870     fMediaCombo->Select(i);
871     fMediaCombo->Resize(200, 20);
872 }
873
874 void AliGuiGeomMain::SetMaterialComboEntries(TClonesArray *entries)
875 {
876 // Set the material combo entries
877 //
878     fComboMaterialEntries = entries;
879     Int_t nent = fComboMaterialEntries->GetEntriesFast();
880     for (Int_t i=0; i < nent; i++)
881     {
882         AddMaterial((AliG3Material*)fComboMaterialEntries->At(i), i);
883         gCurrentMaterial = (AliG3Material*)fComboMaterialEntries->At(i);
884     }
885 }
886
887
888 void AliGuiGeomMain::SetMediaComboEntries(TClonesArray *entries)
889 {
890 // Set the media combo entries
891 //
892     fComboMediaEntries = entries;
893     Int_t nent = fComboMediaEntries->GetEntriesFast();
894     for (Int_t i=0; i < nent; i++)
895     {
896         AddMedium((AliG3Medium*)fComboMediaEntries->At(i), i);
897         gCurrentMedium = (AliG3Medium*)fComboMediaEntries->At(i);
898     }
899 }
900
901 void AliGuiGeomMain::AddFoldersRecursively(TFolder* folder, TGListTreeItem* parent)
902 {
903 // Display geometry represented by TFolders in List Tree
904 //
905     const TGPicture* kFolder     = gClient->GetPicture("folder_t.xpm");
906     const TGPicture* kOpenFolder = gClient->GetPicture("ofolder_t.xpm");
907     const TGPicture* kDocument   = gClient->GetPicture("doc_t.xpm");
908     
909     AliG3Volume* volume = ((AliG3Volume *) folder->FindObject(folder->GetName()));
910     volume->SetItem(folder);
911
912     TList* folders = (TList*) folder->GetListOfFolders();
913     TIter next(folders);
914     TObject* obj;
915     TGListTreeItem* nParent = 0;
916     if (folders->GetSize() > 1) {
917         nParent = fLt->AddItem(parent, folder->GetName(), volume, kOpenFolder, kFolder);
918     } else {
919         nParent = fLt->AddItem(parent, folder->GetName(), volume, kDocument, kDocument);
920     }
921     
922     while ((obj = next()))
923     {
924         if ((AliG3Volume*) obj == volume) continue;
925         TFolder* item = (TFolder*) obj;
926         AddFoldersRecursively(item, nParent);
927     }
928 }
929