Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoMediumEditor.cxx
Go to the documentation of this file.
1 // @(#):$Id: c816a00a89512fcc6cd4a75fb1343c76ebaa3c24 $
2 // Author: M.Gheata
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TGeoMediumEditor
13 \ingroup Geometry_builder
14 
15 Editor class for TGeo tracking media.
16 
17 */
18 
19 #include "TGeoMediumEditor.h"
20 #include "TGeoTabManager.h"
21 #include "TGeoManager.h"
22 #include "TGeoMedium.h"
23 #include "TGeoMaterial.h"
24 #include "TPad.h"
25 #include "TGTab.h"
26 #include "TGComboBox.h"
27 #include "TGButton.h"
28 #include "TGTextEntry.h"
29 #include "TGNumberEntry.h"
30 #include "TGLabel.h"
31 #include "TG3DLine.h"
32 
33 ClassImp(TGeoMediumEditor);
34 
35 enum ETGeoMediumWid {
36  kMED_NAME, kMED_ID, kMED_MATSEL,
37  kMED_SENS, kMED_FLDOPT, kMED_EDIT_MAT,
38  kMED_FIELDM, kMED_TMAX, kMED_STEMAX,
39  kMED_DEEMAX, kMED_EPSIL, kMED_STMIN,
40  kMED_APPLY, kMED_CANCEL, kMED_UNDO
41 };
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// Constructor for medium editor
45 
46 TGeoMediumEditor::TGeoMediumEditor(const TGWindow *p, Int_t width,
47  Int_t height, UInt_t options, Pixel_t back)
48  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
49 {
50  fMedium = 0;
51  fIsEditable = kFALSE;
52  fIsModified = kFALSE;
53  Pixel_t color;
54  TGLabel *label;
55 
56  // TextEntry for medium name
57  MakeTitle("Name");
58  fMedName = new TGTextEntry(this, "", kMED_NAME);
59  fMedName->SetDefaultSize(135, fMedName->GetDefaultHeight());
60  fMedName->SetToolTipText("Enter the medium name");
61  fMedName->Associate(this);
62  AddFrame(fMedName, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 3, 1, 2, 2));
63 
64  TGTextEntry *nef;
65 
66 // Composite frame for medium ID and sensitivity
67  TGCompositeFrame *f1 = new TGCompositeFrame(this, 120, 30, kHorizontalFrame | kRaisedFrame);
68  f1->AddFrame(new TGLabel(f1, "ID"), new TGLayoutHints(kLHintsLeft, 4, 1, 6, 0));
69  fMedId = new TGNumberEntry(f1, 0., 1, kMED_ID);
70  nef = (TGTextEntry*)fMedId->GetNumberEntry();
71  nef->SetToolTipText("Enter the medium ID");
72  fMedId->Associate(this);
73  f1->AddFrame(fMedId, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
74  fMedSensitive = new TGCheckButton(f1, "&Sens", kMED_SENS);
75  fMedSensitive->Associate(this);
76  f1->AddFrame(fMedSensitive, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
77  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 3, 3, 2, 2));
78 
79  // Current material
80  f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame | kFixedWidth | kOwnBackground);
81  f1->AddFrame(label = new TGLabel(f1, "Current material"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
82  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
83  gClient->GetColorByName("#ff0000", color);
84  label->SetTextColor(color);
85  AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
86  f1 = new TGCompositeFrame(this, 155, 30, kHorizontalFrame);
87  fSelectedMaterial = 0;
88  fLSelMaterial = new TGLabel(f1, "Select material");
89  gClient->GetColorByName("#0000ff", color);
90  fLSelMaterial->SetTextColor(color);
91  fLSelMaterial->ChangeOptions(kChildFrame | kSunkenFrame | kDoubleBorder);
92  f1->AddFrame(fLSelMaterial, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
93  fBSelMaterial = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kMED_MATSEL);
94  fBSelMaterial->SetToolTipText("Replace with one of the existing materials");
95  fBSelMaterial->Associate(this);
96  f1->AddFrame(fBSelMaterial, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
97  fEditMaterial = new TGTextButton(f1, "Edit");
98  f1->AddFrame(fEditMaterial, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
99  fEditMaterial->SetToolTipText("Edit selected material");
100  fEditMaterial->Associate(this);
101  AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 0, 0));
102 
103 // Combo box for magnetic field option
104  f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame | kLHintsExpandX | kFixedWidth | kOwnBackground);
105  f1->AddFrame(label = new TGLabel(f1, "Mag. field option"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
106  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
107  gClient->GetColorByName("#ff0000", color);
108  label->SetTextColor(color);
109  AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
110  fMagfldOption = new TGComboBox(this, kMED_FLDOPT);
111  fMagfldOption->Resize(135, fMedName->GetDefaultHeight());
112  AddFrame(fMagfldOption, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 2));
113 
114 
115 // Number entries for other settings
116  f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame | kFixedWidth | kOwnBackground);
117  f1->AddFrame(label = new TGLabel(f1, "Medium cuts"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
118  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
119  gClient->GetColorByName("#ff0000", color);
120  label->SetTextColor(color);
121  AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
122  TGCompositeFrame *compxyz = new TGCompositeFrame(this, 130, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
123 
124  // Number entry for fieldm
125  f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
126  kLHintsExpandX | kFixedWidth | kOwnBackground);
127  f1->AddFrame(new TGLabel(f1, "FIELDM"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
128  fMedFieldm = new TGNumberEntry(f1, 0., 5, kMED_FIELDM);
129  nef = (TGTextEntry*)fMedFieldm->GetNumberEntry();
130  nef->SetToolTipText("Maximum magnetic field [kilogauss]");
131  fMedFieldm->Associate(this);
132  fMedFieldm->Resize(90, fMedFieldm->GetDefaultHeight());
133  f1->AddFrame(fMedFieldm, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
134  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
135 
136  // Number entry for tmaxfd
137  TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
138  kLHintsExpandX | kFixedWidth | kOwnBackground);
139  f2->AddFrame(new TGLabel(f2, "TMAXFD"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
140  fMedTmaxfd = new TGNumberEntry(f2, 0., 5, kMED_TMAX);
141  nef = (TGTextEntry*)fMedTmaxfd->GetNumberEntry();
142  nef->SetToolTipText("Maximum angle per step due to field [deg]");
143  fMedTmaxfd->Associate(this);
144  fMedTmaxfd->Resize(90, fMedTmaxfd->GetDefaultHeight());
145  f2->AddFrame(fMedTmaxfd, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
146  compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
147 
148  // Number entry for stemax
149  TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
150  kLHintsExpandX | kFixedWidth | kOwnBackground);
151  f3->AddFrame(new TGLabel(f3, "STEMAX"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
152  fMedStemax = new TGNumberEntry(f3, 0., 5, kMED_STEMAX);
153  nef = (TGTextEntry*)fMedStemax->GetNumberEntry();
154  nef->SetToolTipText("Maximum step allowed [cm]");
155  fMedStemax->Associate(this);
156  fMedStemax->Resize(90, fMedStemax->GetDefaultHeight());
157  f3->AddFrame(fMedStemax, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
158  compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
159 
160  // Number entry for deemax
161  TGCompositeFrame *f4 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
162  kLHintsExpandX | kFixedWidth | kOwnBackground);
163  f4->AddFrame(new TGLabel(f4, "DEEMAX"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
164  fMedDeemax = new TGNumberEntry(f4, 0., 5, kMED_DEEMAX);
165  nef = (TGTextEntry*)fMedDeemax->GetNumberEntry();
166  nef->SetToolTipText("Maximum fraction of energy lost in a step");
167  fMedDeemax->Associate(this);
168  fMedDeemax->Resize(90, fMedDeemax->GetDefaultHeight());
169  f4->AddFrame(fMedDeemax, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
170  compxyz->AddFrame(f4, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
171 
172  // Number entry for epsil
173  TGCompositeFrame *f5 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
174  kLHintsExpandX | kFixedWidth | kOwnBackground);
175  f5->AddFrame(new TGLabel(f5, "EPSIL"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
176  fMedEpsil = new TGNumberEntry(f5, 0., 5, kMED_EPSIL);
177  nef = (TGTextEntry*)fMedEpsil->GetNumberEntry();
178  nef->SetToolTipText("Tracking precision [cm]");
179  fMedEpsil->Associate(this);
180  fMedEpsil->Resize(90, fMedEpsil->GetDefaultHeight());
181  f5->AddFrame(fMedEpsil, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
182  compxyz->AddFrame(f5, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
183 
184  // Number entry for stmin
185  TGCompositeFrame *f6 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
186  kLHintsExpandX | kFixedWidth | kOwnBackground);
187  f6->AddFrame(new TGLabel(f6, "STMIN"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
188  fMedStmin = new TGNumberEntry(f6, 0., 5, kMED_STMIN);
189  nef = (TGTextEntry*)fMedStmin->GetNumberEntry();
190  nef->SetToolTipText("Minimum step due to continuous processes [cm]");
191  fMedStmin->Associate(this);
192  fMedStmin->Resize(90, fMedStmin->GetDefaultHeight());
193  f6->AddFrame(fMedStmin, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
194  compxyz->AddFrame(f6, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
195 
196  compxyz->Resize(160,50);
197  AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
198 
199  // Buttons
200  TGCompositeFrame *f23 = new TGCompositeFrame(this, 118, 20, kHorizontalFrame | kSunkenFrame | kDoubleBorder);
201  fApply = new TGTextButton(f23, "&Apply");
202  f23->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
203  fApply->Associate(this);
204  fUndo = new TGTextButton(f23, " &Undo ");
205  f23->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
206  fUndo->Associate(this);
207  AddFrame(f23, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
208 }
209 
210 ////////////////////////////////////////////////////////////////////////////////
211 /// Destructor
212 
213 TGeoMediumEditor::~TGeoMediumEditor()
214 {
215  TGFrameElement *el;
216  TIter next(GetList());
217  while ((el = (TGFrameElement *)next())) {
218  if (el->fFrame->IsA() == TGCompositeFrame::Class() ||
219  el->fFrame->IsA() == TGHorizontalFrame::Class() ||
220  el->fFrame->IsA() == TGVerticalFrame::Class())
221  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
222  }
223  Cleanup();
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Connect signals to slots.
228 
229 void TGeoMediumEditor::ConnectSignals2Slots()
230 {
231  fApply->Connect("Clicked()", "TGeoMediumEditor", this, "DoApply()");
232  fUndo->Connect("Clicked()", "TGeoMediumEditor", this, "DoUndo()");
233  fMedName->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoMedName()");
234  fBSelMaterial->Connect("Clicked()", "TGeoMediumEditor", this, "DoSelectMaterial()");
235  fEditMaterial->Connect("Clicked()", "TGeoMediumEditor", this, "DoEditMaterial()");
236  fMedId->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoMedId()");
237  fMedTmaxfd->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoTmaxfd()");
238  fMedStemax->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoStemax()");
239  fMedDeemax->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoDeemax()");
240  fMedEpsil->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoEpsil()");
241  fMedStmin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoStmin()");
242  fMedSensitive->Connect("Clicked()", "TGeoMediumEditor", this, "DoToggleSensitive()");
243  fMagfldOption->Connect("Selected(Int_t)", "TGeoMediumEditor", this, "DoMagfldSelect(Int_t)");
244  fInit = kFALSE;
245 }
246 
247 
248 ////////////////////////////////////////////////////////////////////////////////
249 /// Connect to the selected object.
250 
251 void TGeoMediumEditor::SetModel(TObject* obj)
252 {
253  if (obj == 0 || !(obj->IsA()==TGeoMedium::Class())) {
254  SetActive(kFALSE);
255  return;
256  }
257  fMedium = (TGeoMedium*)obj;
258  const char *sname = fMedium->GetName();
259  if (!strcmp(sname, fMedium->ClassName())) fMedName->SetText("");
260  else fMedName->SetText(sname);
261 
262  fMedId->SetNumber(fMedium->GetId());
263  Int_t isvol = (Int_t)fMedium->GetParam(0);
264  fMedSensitive->SetState((isvol==0)?kButtonUp:kButtonDown);
265 
266  fSelectedMaterial = fMedium->GetMaterial();
267  if (fSelectedMaterial) fLSelMaterial->SetText(fSelectedMaterial->GetName());
268 
269  if (!fMagfldOption->GetNumberOfEntries()) {
270  fMagfldOption->AddEntry("No field", 0);
271  fMagfldOption->AddEntry("User decision", 1);
272  fMagfldOption->AddEntry("Runge-Kutta", 2);
273  fMagfldOption->AddEntry("Helix", 3);
274  fMagfldOption->AddEntry("Helix3", 4);
275  fMagfldOption->AddEntry("Unknown option", 5);
276  }
277  Int_t ifld = (Int_t)fMedium->GetParam(1);
278  switch (ifld) {
279  case 0:
280  fMagfldOption->Select(0);
281  break;
282  case -1:
283  fMagfldOption->Select(1);
284  break;
285  case 1:
286  fMagfldOption->Select(2);
287  break;
288  case 2:
289  fMagfldOption->Select(3);
290  break;
291  case 3:
292  fMagfldOption->Select(4);
293  break;
294  default:
295  fMagfldOption->Select(5);
296  break;
297  }
298 
299  fMedFieldm->SetNumber(fMedium->GetParam(2));
300  fMedTmaxfd->SetNumber(fMedium->GetParam(3));
301  fMedStemax->SetNumber(fMedium->GetParam(4));
302  fMedDeemax->SetNumber(fMedium->GetParam(5));
303  fMedEpsil->SetNumber(fMedium->GetParam(6));
304  fMedStmin->SetNumber(fMedium->GetParam(7));
305 
306  fUndo->SetEnabled(kFALSE);
307  fIsModified = kFALSE;
308 
309 
310  if (fInit) ConnectSignals2Slots();
311  SetActive();
312 }
313 
314 ////////////////////////////////////////////////////////////////////////////////
315 /// Edit selected material.
316 
317 void TGeoMediumEditor::DoEditMaterial()
318 {
319  fTabMgr->GetMaterialEditor(fMedium->GetMaterial());
320 }
321 
322 ////////////////////////////////////////////////////////////////////////////////
323 /// Slot for medium name.
324 
325 void TGeoMediumEditor::DoMedName()
326 {
327  const char *name = fMedName->GetText();
328  if (!name[0] || !strcmp(name, fMedium->GetName())) return;
329  fMedium->SetName(name);
330 }
331 
332 ////////////////////////////////////////////////////////////////////////////////
333 /// Slot for medium id.
334 
335 void TGeoMediumEditor::DoMedId()
336 {
337 }
338 
339 ////////////////////////////////////////////////////////////////////////////////
340 /// Select the material component.
341 
342 void TGeoMediumEditor::DoSelectMaterial()
343 {
344  TGeoMaterial *material = fSelectedMaterial;
345  new TGeoMaterialDialog(fBSelMaterial, gClient->GetRoot(), 200,300);
346  fSelectedMaterial = (TGeoMaterial*)TGeoMaterialDialog::GetSelected();
347  if (fSelectedMaterial) fLSelMaterial->SetText(fSelectedMaterial->GetName());
348  else fSelectedMaterial = material;
349 }
350 
351 ////////////////////////////////////////////////////////////////////////////////
352 /// Slot for sensitivity.
353 
354 void TGeoMediumEditor::DoToggleSensitive()
355 {
356  fIsModified = kTRUE;
357 }
358 
359 ////////////////////////////////////////////////////////////////////////////////
360 /// Slot for mag. field.
361 
362 void TGeoMediumEditor::DoMagfldSelect(Int_t)
363 {
364  fIsModified = kTRUE;
365 }
366 
367 ////////////////////////////////////////////////////////////////////////////////
368 /// Slot for max field.
369 
370 void TGeoMediumEditor::DoFieldm()
371 {
372  fIsModified = kTRUE;
373 }
374 
375 ////////////////////////////////////////////////////////////////////////////////
376 /// Slot for tmaxfd.
377 
378 void TGeoMediumEditor::DoTmaxfd()
379 {
380  fIsModified = kTRUE;
381 }
382 
383 ////////////////////////////////////////////////////////////////////////////////
384 /// Slot for the max allowed step.
385 
386 void TGeoMediumEditor::DoStemax()
387 {
388  fIsModified = kTRUE;
389 }
390 
391 ////////////////////////////////////////////////////////////////////////////////
392 /// Slot for the maximum allowed dedx.
393 
394 void TGeoMediumEditor::DoDeemax()
395 {
396  fIsModified = kTRUE;
397 }
398 
399 ////////////////////////////////////////////////////////////////////////////////
400 /// Slot for tracking precision.
401 
402 void TGeoMediumEditor::DoEpsil()
403 {
404  fIsModified = kTRUE;
405 }
406 
407 ////////////////////////////////////////////////////////////////////////////////
408 /// Slot for min. step.
409 
410 void TGeoMediumEditor::DoStmin()
411 {
412  fIsModified = kTRUE;
413 }
414 
415 ////////////////////////////////////////////////////////////////////////////////
416 /// Slot for applying modifications.
417 
418 void TGeoMediumEditor::DoApply()
419 {
420  if (!fIsModified) return;
421  Double_t isvol = (fMedSensitive->IsOn())?1:0;
422  Double_t ifield = fMagfldOption->GetSelected();
423  if (ifield>0) {
424  ifield -= 1.;
425  if (ifield < 1.) ifield -= 1.;
426  }
427  Double_t fieldm = fMedFieldm->GetNumber();
428  Double_t tmaxfd = fMedTmaxfd->GetNumber();
429  Double_t stemax = fMedStemax->GetNumber();
430  Double_t deemax = fMedDeemax->GetNumber();
431  Double_t epsil = fMedEpsil->GetNumber();
432  Double_t stmin = fMedStmin->GetNumber();
433 
434  fMedium->SetParam(0,isvol);
435  fMedium->SetParam(1,ifield);
436  fMedium->SetParam(2,fieldm);
437  fMedium->SetParam(3,tmaxfd);
438  fMedium->SetParam(4,stemax);
439  fMedium->SetParam(5,deemax);
440  fMedium->SetParam(6,epsil);
441  fMedium->SetParam(7,stmin);
442  if (strcmp(fMedium->GetName(), fMedName->GetText())) fMedium->SetName(fMedName->GetText());
443  if (fMedium->GetId() != fMedId->GetIntNumber()) fMedium->SetId(fMedId->GetIntNumber());
444 }
445 
446 ////////////////////////////////////////////////////////////////////////////////
447 /// Slot for undoing last operation.
448 
449 void TGeoMediumEditor::DoUndo()
450 {
451 }
452