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