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