]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4VolumesFrames.cxx
Add Boost() method to boost all particles to LHC lab frame. Needed for asymmetric...
[u/mrichter/AliRoot.git] / TGeant4 / TG4VolumesFrames.cxx
1 // $Id$
2 // Category: interfaces
3 //
4 // Author: D. Adamova
5 //
6 //========================================================
7 //
8 //------------TG4VolumesFrames.cxx--------------------------------//
9 //--------- Frames for the the display of volumes properties---//
10 //
11 //========================================================= 
12  
13 #include "TG4VolumesFrames.h"
14 #include "TG4MaterialsFrames.h"
15 #include "TG4Editor.h"
16 #include "TG4Globals.h" 
17 #include "TG4Limits.h"
18 #include "TG4G3CutVector.h"
19 #include "TG4G3Cut.h"
20
21 #include <TGTextBuffer.h>
22 #include <TGTextEntry.h>
23 #include <TGComboBox.h>
24 #include <TGLabel.h>
25 #include <TGTab.h>
26 //#include <TGFrame.h>
27 //#include <TGButton.h>
28
29 #include <G4LogicalVolumeStore.hh>
30 #include <G4LogicalVolume.hh>
31 #include <G4Material.hh>
32 #include <G4VSolid.hh>
33 #include <G4UserLimits.hh>
34 #include <G4Track.hh>
35  
36  
37  ClassImp(TG4VolumesFrames)
38
39 TG4VolumesFrames::TG4VolumesFrames( TGTab* Tab, TGMainFrame* ActionFrame)
40
41 //---> creates the volumes properties display frame
42 //---> and plunges it into the main frame
43    TGCompositeFrame* parent = Tab->AddTab("Volumes Properties");
44    fCapFrame = new TGCompositeFrame(parent, 60, 20, kHorizontalFrame);
45    ULong_t back= TGFrame::GetBlackPixel(); 
46    fCapFrame->ChangeBackground(back);
47    fVolSubframe1 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
48    fVolFrameLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
49
50 // ComboBox for lvolumes
51    fVolumesCombo = new TGComboBox(fVolSubframe1, 100);
52    TGLayoutHints* lLayoutHints3 = 
53              new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
54                            2, 2, 2, 2);   
55    Text_t* lComboLabelText = " Pick up a volume here ";
56    fComboLabel = new TGLabel( fVolSubframe1, lComboLabelText);
57    fVolSubframe1->AddFrame(fComboLabel, lLayoutHints3);
58    fVolSubframe1->AddFrame(fVolumesCombo, fVolFrameLayout);
59
60    fVolumesCombo->Resize(200, 30);
61    fVolumesCombo->Associate(ActionFrame); 
62
63    
64 // text labels with lvolumes properties 
65
66    Text_t* labelText[3]  = 
67    {"Shape's Name", 
68     "Material    ",
69     "User Limits " }; 
70
71 // Entries for lvolumes properties
72    TGLayoutHints* lLayoutHints4   = 
73        new TGLayoutHints(kLHintsTop | kLHintsExpandY, 5, 5, 5, 5);
74    TGLayoutHints* lLayoutHints5 = 
75        new TGLayoutHints(kLHintsLeft | kLHintsExpandX );
76    fVolSubframe2 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
77
78    { // local scope for i
79      for (Int_t i=0; i<2; i++) {
80        Int_t idT=i+1;   
81        fHframe[i] = new TGHorizontalFrame(fVolSubframe2, 500, 100, kFixedWidth);
82        fVolSubframe2->AddFrame(fHframe[i], lLayoutHints4);
83        fVolTextBuff[i] = new TGTextBuffer(200);
84        fVolTextEntry[i] = new TGTextEntry(fHframe[i], fVolTextBuff[i], 300);
85        fLabel[i] = new TGLabel(fHframe[i], labelText[i]);
86        fHframe[i]->AddFrame(fLabel[i], lLayoutHints5);
87        fHframe[i]->AddFrame(fVolTextEntry[i], lLayoutHints5);
88        fVolTextEntry[i]->Associate(ActionFrame); 
89      }
90    }
91      
92 // --->a group frame for displaying user's limits with a text entry added
93
94   fGrFrame =
95   new TGGroupFrame(fVolSubframe2, "----- User Limits Showcase -----", kVerticalFrame);
96   fHframe[2] = new TGHorizontalFrame( fGrFrame, 410, 100, kFixedWidth);
97   TGLayoutHints* lLayoutHints6 = new TGLayoutHints(kLHintsTop | kLHintsLeft ,
98                            4, 0, 20, 2);
99   fLabel[2] = new TGLabel(fHframe[2], labelText[2]);
100   fHframe[2]->AddFrame(fLabel[2],lLayoutHints6);
101   fVolTextBuff[2] = new TGTextBuffer(200);
102   fVolTextEntry[2] = new TGTextEntry(fHframe[2], fVolTextBuff[2], 300);
103   fVolTextEntry[2]->Resize(1000, fVolTextEntry[2]->GetDefaultHeight());
104   fHframe[2]->AddFrame(fVolTextEntry[2], lLayoutHints6); 
105   fVolTextEntry[2]->Associate(ActionFrame);
106
107   fGrFrame->AddFrame(fHframe[2], lLayoutHints4);
108
109 // ---> adding to the group frame another frame with text buttons 
110 // for calling up a full display of user's limits properties
111
112   fGrHFrame= new TGHorizontalFrame( fGrFrame, 500, 100);
113   fbtsumm = new TGTextButton(fGrHFrame, "&User Limits", 301);
114   fbtcuts = new TGTextButton(fGrHFrame, "&Show Cuts", 302);
115   fbtcontrols = new TGTextButton(fGrHFrame, "&Show Controls", 303);
116   TGLayoutHints* lLayoutHints7   = 
117        new TGLayoutHints(kLHintsTop | kLHintsLeft, 50, 0, 5, 5);
118   fGrHFrame->SetLayoutManager(new TGMatrixLayout(fGrHFrame, 0, 3, 15));
119   fGrHFrame->AddFrame( fbtsumm );
120   fbtsumm->Resize(90, fbtsumm->GetDefaultHeight());
121   fGrHFrame->AddFrame( fbtcuts );
122   fbtcuts->Resize(90, fbtcuts->GetDefaultHeight());
123   fGrHFrame->AddFrame( fbtcontrols );
124   fbtcontrols->Resize(90, fbtcontrols->GetDefaultHeight());
125
126   fbtsumm->Associate(ActionFrame);
127   fbtcuts->Associate(ActionFrame);
128   fbtcontrols->Associate(ActionFrame);
129   
130   fGrFrame->AddFrame(fGrHFrame, lLayoutHints4);
131
132 //---> adding the group frame to the subrame 2
133   fVolSubframe2->AddFrame( fGrFrame, lLayoutHints7);
134   fGrFrame->Resize(fGrFrame->GetDefaultSize());
135
136 // ---> text for the user's limits display window when no volume specified yet 
137   fDisplBuff = new TGTextBuffer(1000);
138   fDisplBuff->Clear(); 
139   fDisplBuff->AddText(0, "\n\n***  No volume specified, "
140   "no limits displayed *** ");
141   
142
143 // ---> making up the Volumes frame   
144      fCapFrame->AddFrame(fVolSubframe1,fVolFrameLayout);  
145      fCapFrame->AddFrame(fVolSubframe2,fVolFrameLayout);
146
147 // --->  going to the main frame     
148      parent->AddFrame(fCapFrame, fVolFrameLayout);
149      
150      SetPanel(ActionFrame);     
151      
152 }
153
154 TG4VolumesFrames::TG4VolumesFrames(const TG4VolumesFrames& vf) 
155 {
156 // Dummy copy constructor 
157   TG4Globals::Exception(
158     "Attempt to use TG4VolumesFrames copy constructor.");
159 }
160
161 TG4VolumesFrames& TG4VolumesFrames::operator=(const TG4VolumesFrames& vf)
162 {
163   // check assignement to self
164   if (this == &vf) return *this;
165
166   TG4Globals::Exception(
167     "Attempt to assign  singleton.");
168     
169   return *this;  
170 }    
171
172 TG4VolumesFrames::~TG4VolumesFrames()
173 {
174 //---> liquidator 
175
176    G4cout << "\n Now in  TG4VolumesFrames destructor \n" << G4endl;
177    delete fVolSubframe1;
178    delete fVolFrameLayout;
179    delete fVolumesCombo;
180    delete fComboLabel;
181    delete fVolSubframe2;
182    delete fCapFrame;
183    delete fGrFrame;
184    delete fGrHFrame;
185    delete fbtsumm;
186    delete fbtcuts;
187    delete fbtcontrols;
188   
189    Int_t i;
190    for (i=0; i<3; i++) {
191      delete fHframe[i];
192      delete fVolTextBuff[i];
193      delete fVolTextEntry[i];
194      delete fLabel[i];
195    }
196      delete fDisplBuff;
197 }
198
199 void TG4VolumesFrames::SetPanel(TGMainFrame* ActionFrame)
200 {
201 //---> produces the pointer to the main frame
202
203     fPanel = (TG4MainFrame*) ActionFrame;
204 }
205
206 void TG4VolumesFrames::SetVolumesComboEntries() 
207 {
208 //--->//---> puts names of lvolumes into the combo box entries
209
210     G4LogicalVolumeStore* lComboEntries = G4LogicalVolumeStore::GetInstance();
211
212     G4int ig = lComboEntries->size();
213     G4String name;
214     
215     for (int ii=0; ii < ig; ii++)
216         { name = ((*lComboEntries )[ii])->GetName() ;
217           AddLogicalVolumeName( name, ii+1);
218         };
219         
220     name = "  " ;
221     AddLogicalVolumeName( name, ig+1);
222         
223     
224 }
225
226 void TG4VolumesFrames::AddLogicalVolumeName( const char* name, Int_t index) const
227 {
228 //-----> adds an lvolume name to the combo box  
229
230    fVolumesCombo->AddEntry( name, index);
231    fVolumesCombo->Select(index);
232    fVolumesCombo->Resize(200, 20);
233 }
234
235 void TG4VolumesFrames::DisplayVolumeCharacteristics()
236 {
237 //-----> shows informations about a logical volume 
238
239    G4LogicalVolumeStore* lComboEntries = G4LogicalVolumeStore::GetInstance();
240    G4int ientr = lComboEntries->size();
241    G4int index = fVolumesCombo->GetSelected();
242    G4int imat = 0;
243    
244    G4cout << "\nThe clicked-on volumes entry has the index:  " << index << G4endl;
245   
246    TG4Limits* lLimits;
247    
248    if( index < ientr+1 ) {
249    
250      G4int ii = index-1;
251      G4LogicalVolume* lVolume = (*lComboEntries )[ii];
252      G4Material* lvMaterial = ((*lComboEntries )[ii])->GetMaterial();
253      lLimits = (TG4Limits*)lVolume->GetUserLimits(); 
254      TString lDisplayLimits = GetDisplay(lLimits); 
255
256 //---> fills up the buffer for popup frame display
257      fDisplBuff->Clear(); 
258      fDisplBuff->AddText(0,lDisplayLimits);
259
260      G4cout << lVolume->GetName() << "  " 
261             << lVolume->GetSolid()->GetEntityType() << "  "
262             << lvMaterial->GetName() << "  "
263             << lVolume->GetUserLimits()->GetType() <<  G4endl;
264
265 //---> putting text in the text entries      
266     char buff[100];
267
268     sprintf(buff, lVolume->GetSolid()->GetEntityType());
269     fVolTextBuff[0]->Clear();
270     fVolTextBuff[0]->AddText(0, buff);
271     gClient->NeedRedraw(fVolTextEntry[0]);
272     
273     sprintf(buff, lvMaterial->GetName());
274     fVolTextBuff[1]->Clear();
275     fVolTextBuff[1]->AddText(0, buff);
276     gClient->NeedRedraw(fVolTextEntry[1]);
277
278     
279     sprintf(buff, "User limits undefined" );
280     if (lVolume->GetUserLimits())
281        sprintf(buff, lLimits->GetName()); 
282     fVolTextBuff[2]->Clear();
283     fVolTextBuff[2]->AddText(0, buff);
284     gClient->NeedRedraw(fVolTextEntry[2]);
285     
286     imat = lvMaterial->GetIndex();    
287     
288    };
289    
290    if( index == ientr+1 ) {
291    
292       for ( G4int ii=0; ii<3; ii++) {
293         fVolTextBuff[ii]->Clear();          
294         gClient->NeedRedraw(fVolTextEntry[ii]);
295         };
296      fDisplBuff->Clear(); 
297      fDisplBuff->AddText(0, "\n\n***  No volume specified, "
298      "no limits displayed *** ");
299       
300      };
301
302 //---> setting appropriate  display in the MaterialsFrames    
303    TG4MaterialsFrames* mFrames = fPanel->GetMaterialsFrames();
304    mFrames->DisplayMaterialCharacteristics( imat + 1 );
305
306 }
307
308 void TG4VolumesFrames::DisplayUserLimits()
309 {
310 //-----> displays User Limits associated with the logical volume 
311
312   const char* cdisplay = fDisplBuff->GetString();
313   TG4Editor* ed = new TG4Editor( fCapFrame, 450, 300);
314                       ed->LoadBuffer(cdisplay);
315                       ed->Popup();      
316
317 }
318
319 TString TG4VolumesFrames::GetDisplay(G4UserLimits* limits) const
320 {
321 // Returns text for the user limits display in a separate frame
322 // ---
323   G4String display;
324   G4Track dummy;
325   char buff[200];
326
327   display = "\n\n**************************************";
328   display += "\n**************************************\n\n";
329   display += "\" ";
330   display += ((TG4Limits*)limits)->GetName();
331   display += "\"  limits:";
332   display += "\n\n  Max step length (mm): ";
333   TG4Globals::AppendNumberToString( display, limits->GetMaxAllowedStep(dummy)/mm);
334 //  sprintf(buff, "%12.5e", fMaxStep/mm );
335 //  display += buff;
336   display += "\n\n  Max track length (mm): ";
337   sprintf(buff, "%12.5e", limits->GetUserMaxTrackLength(dummy)/mm );
338   display += buff;
339   display += "\n\n  Max time (s)         : ";
340   sprintf(buff, "%12.5e", limits->GetUserMaxTime(dummy)/s );
341   display += buff;
342   display += "\n\n  Min kin. energy (MeV): ";
343   TG4Globals::AppendNumberToString( display, limits->GetUserMinEkine(dummy)/MeV);
344 //  sprintf(buff, "%12.5e", fMinEkine/MeV );
345 //  display += buff;
346   display += "\n\n  Min range (mm):        " ;
347   TG4Globals::AppendNumberToString( display, limits->GetUserMinRange(dummy)/mm);
348 //  sprintf(buff, "%12.5e", fMinRange/mm);
349 //  display += buff;
350   display += "\n\n**************************************";
351   display += "\n**************************************\n\n";
352   
353   const char* tmp = display;
354   
355   return TString(tmp);
356
357 }
358