]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4MaterialsFrames.cxx
cuts on Q out, side, long added
[u/mrichter/AliRoot.git] / TGeant4 / TG4MaterialsFrames.cxx
1 // $Id$
2 // Category: interfaces
3 //
4 // Author: D. Adamova
5 //
6 //========================================================
7 //
8 //------------TG4MaterialsFrames.cxx--------------------------------//
9 //--------- Frames for the the display of materials properties---//
10 //
11 //========================================================= 
12  
13 #include "TG4MaterialsFrames.h" 
14 #include "TG4Globals.h"
15
16 #include <TGTextBuffer.h>
17 #include <TGTextEntry.h>
18 #include <TGComboBox.h>
19 #include <TGLabel.h>
20 #include <TGTab.h>
21  
22 #include <G4Material.hh>
23 #include <G4Element.hh>
24
25
26
27  ClassImp(TG4MaterialsFrames)
28
29 TG4MaterialsFrames::TG4MaterialsFrames( TGTab* Tab, TGMainFrame* ActionFrame )
30
31 //---> creates the materials properties display frame
32 //---> and plunges it into the main frame
33    TGCompositeFrame* parent = Tab->AddTab("Materials Properties");
34    fCapFrame = new TGCompositeFrame(parent, 60, 20, kHorizontalFrame);
35    ULong_t back= TGFrame::GetBlackPixel(); 
36    fCapFrame->ChangeBackground(back);   
37    fMatSubframe1 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
38    fMatFrameLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
39
40    // ComboBox for materials
41    fMaterialsCombo = new TGComboBox(fMatSubframe1, 200);
42    TGLayoutHints* lLayoutHints3 = 
43              new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
44                            2, 2, 2, 2);   
45    Text_t* lComboLabelText = " Pick up a material here ";
46    fComboLabel = new TGLabel( fMatSubframe1, lComboLabelText);
47    fMatSubframe1->AddFrame(fComboLabel, lLayoutHints3);
48    fMatSubframe1->AddFrame(fMaterialsCombo, fMatFrameLayout);
49
50
51    fMaterialsCombo->Resize(200, 30);
52    fMaterialsCombo->Associate(ActionFrame); 
53
54
55    
56 // text labels with material properties 
57    Text_t* labelText[8]  = 
58    {"Index             ", 
59     "Number of elements",
60     "Elements list     ",
61     "Atomic mass       ",
62     "Density           ", 
63     "State             ", 
64     "Radiation Length  ",
65     "Abs. Length       " }; 
66
67 // Entries for material properties
68    TGLayoutHints* lLayoutHints4   = 
69        new TGLayoutHints(kLHintsTop | kLHintsExpandY, 5, 5, 5, 5);
70    TGLayoutHints* lLayoutHints5 = 
71        new TGLayoutHints(kLHintsLeft | kLHintsExpandX );
72    fMatSubframe2 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
73                 
74    { // local scope for i
75      for (Int_t i=0; i<8; i++) {
76        Int_t idT=i+1;   
77        fHframe[i] = new TGHorizontalFrame(fMatSubframe2, 500, 100, kFixedWidth);
78        fMatTextBuff[i] = new TGTextBuffer(200);
79        fMatTextEntry[i] = new TGTextEntry(fHframe[i], fMatTextBuff[i], 300);
80        fLabel[i] = new TGLabel(fHframe[i], labelText[i]);
81        fHframe[i]->AddFrame(fLabel[i], lLayoutHints5);
82        fHframe[i]->AddFrame(fMatTextEntry[i], lLayoutHints5);
83        fMatSubframe2->AddFrame(fHframe[i], lLayoutHints4);
84        fMatTextEntry[i]->Associate(ActionFrame);
85      }
86    } 
87
88 // making up Materials frame   
89      fCapFrame->AddFrame(fMatSubframe1,fMatFrameLayout);  
90      fCapFrame->AddFrame(fMatSubframe2,fMatFrameLayout);
91
92 // going to the main frame     
93      parent->AddFrame(fCapFrame, fMatFrameLayout);   
94    
95 }
96
97 TG4MaterialsFrames::TG4MaterialsFrames(const TG4MaterialsFrames& mf) 
98 {
99 // Dummy copy constructor 
100   TG4Globals::Exception(
101     "Attempt to use TG4MaterialsFrames copy constructor.");
102 }
103
104 TG4MaterialsFrames& TG4MaterialsFrames::operator=(const TG4MaterialsFrames& mf)
105 {
106   // check assignement to self
107   if (this == &mf) return *this;
108
109   TG4Globals::Exception(
110     "Attempt to assign TG4MaterialsFrames singleton.");
111     
112   return *this;  
113 }    
114
115 TG4MaterialsFrames::~TG4MaterialsFrames()
116 {
117   //---> liquidator
118   
119    G4cout << "\n Now in  TG4MaterialsFrames destructor \n"<< G4endl;
120    delete fMatSubframe1;
121    delete fMatFrameLayout;
122    delete fMaterialsCombo;
123    delete fComboLabel;
124    delete fMatSubframe2;
125    delete fCapFrame;
126
127    Int_t i;
128    for (i=0; i<8; i++) {
129      delete fHframe[i];
130      delete fMatTextBuff[i];
131      delete fMatTextEntry[i];
132      delete fLabel[i];
133    }
134
135 }
136
137 void TG4MaterialsFrames::SetMaterialsComboEntries()
138 {
139 //---> puts names of materials into the combo box entries
140
141    const G4MaterialTable* lComboEntries = G4Material::GetMaterialTable();
142
143     G4int ig = lComboEntries->size();
144     G4String name;
145     
146     for (int ii=0; ii < ig; ii++)
147         { name = ((*lComboEntries )[ii])->GetName() ;
148           AddMaterialName( name, ii+1);
149         };
150
151     name = "  " ;
152     AddMaterialName( name, ig+1);
153                    
154 }
155
156 void TG4MaterialsFrames::AddMaterialName( const char* name, Int_t index) const
157 {
158   
159 //-----> adds a material name to the combo box  
160
161    fMaterialsCombo->AddEntry( name, index);
162    fMaterialsCombo->Select(index);
163    fMaterialsCombo->Resize(200, 20);
164 }
165
166 void TG4MaterialsFrames::DisplayMaterialCharacteristics( int qmat)
167 {
168   
169 //---> shows informations about materials listed in G4MaterialTable
170 //---> qmat eq 0 means clicking in the MaterialsFrames ComboBox
171 //---> qmat gt 0 means clicking in the VolumesFrames ComboBox
172
173    const G4MaterialTable* lComboEntries = G4Material::GetMaterialTable();
174    G4int ientr = lComboEntries->size();
175    G4int index = qmat ;
176    
177    if ( !(qmat < 1) )
178         fMaterialsCombo->Select( index );
179    
180    if ( qmat < 1 )
181         index = fMaterialsCombo->GetSelected();
182    
183    G4cout << "\nThe clicked-on material has the index:  " << index << G4endl;
184    
185    if( index < ientr+1 ) {
186    
187      G4int ii = index-1;
188      G4Material* lvMaterial = (*lComboEntries )[ii];
189      const G4ElementVector* allElements = lvMaterial->GetElementVector();
190
191      G4cout << lvMaterial->GetName() << "  "
192             << lvMaterial->GetNumberOfElements() << "  "
193             << (*allElements )[0]->GetName() << "...  "
194             << lvMaterial->GetDensity()/(g/cm3) << "(g/cm3)  "
195             << lvMaterial->GetState() << "  "
196             << lvMaterial->GetRadlen()/(cm) << "(cm)  "
197             << G4endl;
198           
199    char buff[200];
200    G4String line = " ";
201    
202     sprintf(buff, "%12i",index );
203     fMatTextBuff[0]->Clear();
204     fMatTextBuff[0]->AddText(0, buff);
205     gClient->NeedRedraw(fMatTextEntry[0]);
206     
207     G4int noe = lvMaterial->GetNumberOfElements();
208     sprintf(buff, "%12i", noe);
209     fMatTextBuff[1]->Clear();
210     fMatTextBuff[1]->AddText(0, buff);
211     gClient->NeedRedraw(fMatTextEntry[1]);
212
213     G4String stringOfElements = "  ";
214     for (G4int ie=0; ie < noe; ie++) {
215     stringOfElements += (*allElements )[ie]->GetName();
216     stringOfElements += "  ";
217     };
218     sprintf(buff, stringOfElements);
219     fMatTextBuff[2]->Clear();
220     fMatTextBuff[2]->AddText(0, buff);
221     gClient->NeedRedraw(fMatTextEntry[2]);
222
223     sprintf(buff, "   Multi element material" );
224     if( noe < 2 )
225         sprintf(buff, "%12.5e", lvMaterial->GetA()/(g) );
226     line += buff;
227     if( noe < 2 )
228          line += "   (g)";
229     fMatTextBuff[3]->Clear();
230     fMatTextBuff[3]->AddText(0, line);
231     gClient->NeedRedraw(fMatTextEntry[3]);
232     line = " ";
233     
234     sprintf(buff, "%12.5e", lvMaterial->GetDensity()/(g/cm3) );
235     line += buff;
236     line += "   (g/cm3)";
237     fMatTextBuff[4]->Clear();
238     fMatTextBuff[4]->AddText(0, line);
239     gClient->NeedRedraw(fMatTextEntry[4]);
240     line = " ";
241     
242     sprintf(buff,"%12i", lvMaterial->GetState());
243     fMatTextBuff[5]->Clear();
244     fMatTextBuff[5]->AddText(0, buff);
245     gClient->NeedRedraw(fMatTextEntry[5]);
246     
247     sprintf(buff,"%12.5e", lvMaterial->GetRadlen()/(cm));
248     line += buff;
249     line += "  (cm)";    
250     fMatTextBuff[6]->Clear();
251     fMatTextBuff[6]->AddText(0, line);
252     gClient->NeedRedraw(fMatTextEntry[6]);
253     line = " ";
254     
255     sprintf(buff, "           " );
256     fMatTextBuff[7]->Clear();
257     fMatTextBuff[7]->AddText(0, buff);
258     gClient->NeedRedraw(fMatTextEntry[7]);
259     
260    };
261    
262    if( index == ientr+1 ) {
263    
264       for ( G4int ii=0; ii<8; ii++) {
265         fMatTextBuff[ii]->Clear();          
266         gClient->NeedRedraw(fMatTextEntry[ii]);
267         };
268      };      
269    
270 }
271