]>
Commit | Line | Data |
---|---|---|
ef42d733 | 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 strictly 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.8 2000/07/12 08:56:32 fca | |
19 | Coding convention correction and warning removal | |
20 | ||
21 | Revision 1.7 2000/06/28 21:27:45 morsch | |
22 | Most coding rule violations corrected. | |
23 | Still to do: Split the file (on file per class) ? Avoid the global variables. | |
24 | Copy constructors and assignment operators (dummy ?) | |
25 | ||
26 | Revision 1.6 2000/04/14 11:07:46 morsch | |
27 | Correct volume to medium assignment in case several media are asigned to the | |
28 | same material. | |
29 | ||
30 | Revision 1.5 2000/03/20 15:11:03 fca | |
31 | Mods to make the code compile on HP | |
32 | ||
33 | Revision 1.4 2000/01/18 16:12:08 morsch | |
34 | Bug in calculation of number of volume divisions and number of positionings corrected | |
35 | Browser for Material and Media properties added | |
36 | ||
37 | Revision 1.3 1999/11/14 14:31:14 fca | |
38 | Correct small error and remove compilation warnings on HP | |
39 | ||
40 | Revision 1.2 1999/11/10 16:53:35 fca | |
41 | The new geometry viewer from A.Morsch | |
42 | ||
43 | */ | |
44 | ||
45 | /* | |
46 | * Version: 0 | |
47 | * Written by Andreas Morsch | |
48 | * | |
49 | * | |
50 | * | |
51 | * For questions critics and suggestions to this part of the code | |
52 | * contact andreas.morsch@cern.ch | |
53 | * | |
54 | **************************************************************************/ | |
55 | ||
56 | ||
57 | #include "AliGeant3GeometryGUI.h" | |
58 | #include "AliDrawVolume.h" | |
59 | #include "AliGUIMaterial.h" | |
60 | #include "AliGUIMedium.h" | |
61 | #include "AliGuiGeomMain.h" | |
62 | ||
63 | AliDrawVolume *gCurrentVolume = new AliDrawVolume("NULL"); | |
64 | AliGUIMaterial *gCurrentMaterial = new AliGUIMaterial(); | |
65 | AliGUIMedium *gCurrentMedium = new AliGUIMedium(); | |
66 | ||
67 | ClassImp(AliGeant3GeometryGUI) | |
68 | ||
69 | AliGeant3GeometryGUI::AliGeant3GeometryGUI() | |
70 | { | |
71 | // Constructor | |
72 | fPanel = new AliGuiGeomMain(gClient->GetRoot(), 500, 500); | |
73 | fNstack = 0; | |
74 | fVolumes = new TClonesArray("AliDrawVolume",1000); | |
75 | fMaterials = new TClonesArray("AliGUIMaterial",1000); | |
76 | fMedia = new TClonesArray("AliGUIMedium",1000); | |
77 | // Store local copy of zebra bank entries | |
78 | TGeant3 *geant3 = (TGeant3*) gMC; | |
79 | if (geant3) { | |
80 | fZlq=geant3->Lq(); | |
81 | fZq=geant3->Q(); | |
82 | fZiq=geant3->Iq(); | |
83 | fGclink=geant3->Gclink(); | |
84 | fGcnum=geant3->Gcnum(); | |
85 | // | |
86 | ReadGeometryTree(); | |
87 | ReadMaterials(); | |
88 | } | |
89 | } | |
90 | void AliGeant3GeometryGUI::Streamer(TBuffer &) | |
91 | { | |
92 | // Dummy Streamer | |
93 | ; | |
94 | } | |
95 | ||
96 | ||
97 | void AliGeant3GeometryGUI::ReadGeometryTree() | |
98 | { | |
99 | // | |
100 | // Copy zebra volume tree into ROOT LisTree | |
101 | // | |
102 | char *vname; | |
103 | char /* *namec, */ *tmp; | |
104 | char namec[30]; | |
105 | // Icons for | |
106 | // Closed folder (=volume containing children) | |
107 | const TGPicture* kFolder = gClient->GetPicture("folder_t.xpm"); | |
108 | // Open folder (=volume containing children) | |
109 | const TGPicture* kOpenFolder = gClient->GetPicture("ofolder_t.xpm"); | |
110 | // Empty object | |
111 | const TGPicture* kDocument = gClient->GetPicture("doc_t.xpm"); | |
112 | ||
113 | AliDrawVolume *volume; | |
114 | ||
115 | Int_t nst=0; | |
116 | Int_t nlevel=1; | |
117 | Int_t newlevel=nlevel; | |
118 | ||
119 | volume = new AliDrawVolume("ALIC"); | |
120 | volume->SetIdVolume(((TGeant3*)gMC)->VolId("ALIC")); | |
121 | volume->SetIdCopy(0); | |
122 | volume->SetItem(NULL); | |
123 | (*fVolumes)[0]=volume; | |
124 | // | |
125 | // Loop over volumes for which information has been collected | |
126 | while(nlevel>nst) { | |
127 | for (Int_t i=nst; i<nlevel; i++) | |
128 | { | |
129 | TGListTreeItem *itemi, *item2; | |
130 | // GEANT3 volume number | |
131 | Int_t ivol=TMath::Abs(Volume(i)->GetIdVolume()); | |
132 | // Copy number | |
133 | // icopy=1 normal positioning | |
134 | // icopy>1 positioning with parposp | |
135 | // icopy<0 division | |
136 | Int_t icopy = Volume(i)->GetIdCopy(); | |
137 | // Medium and material number, handle special case of divisions | |
138 | Int_t imat, imed; | |
139 | ||
140 | if (icopy <0) { | |
141 | imed=Medium(-ivol); | |
142 | imat=Material(-ivol); | |
143 | } else { | |
144 | imed=Medium(ivol); | |
145 | imat=Material(ivol); | |
146 | } | |
147 | // | |
148 | // Number of children | |
149 | Int_t nch = NChildren(ivol); | |
150 | strcpy(namec,((TGeant3*)gMC)->VolName(ivol)); | |
151 | if (nch >= 0) { | |
152 | printf("\n %s has %d children \n ", namec, nch); | |
153 | } else { | |
154 | printf("\n %s has divisions \n ", namec); | |
155 | } | |
156 | // | |
157 | // Name to be used in ListTree | |
158 | vname = new char[5]; | |
159 | strncpy(vname,namec, 4); | |
160 | vname[4]='\0'; | |
161 | ||
162 | if (icopy >1) { | |
163 | sprintf(namec,"%s*%3dPos",namec,icopy); | |
164 | } else if (icopy <0) { | |
165 | sprintf(namec,"%s*%3dDiv",namec,-icopy); | |
166 | } | |
167 | if (i>0) { | |
168 | itemi=Volume(i)->GetItem(); | |
169 | } else { | |
170 | itemi=NULL; | |
171 | } | |
172 | ||
173 | // | |
174 | // Add volume to list tree | |
175 | ||
176 | if (nch!=0) { | |
177 | item2 = fPanel->AddItem(new AliDrawVolume(vname), | |
178 | itemi, namec, kOpenFolder, kFolder); | |
179 | } else { | |
180 | item2 = fPanel->AddItem(new AliDrawVolume(vname), | |
181 | itemi, namec, kDocument, kDocument); | |
182 | } | |
183 | // | |
184 | // Add medium information to list tree item | |
185 | ((AliDrawVolume *) item2->GetUserData())->SetIdVolume(ivol); | |
186 | ((AliDrawVolume *) item2->GetUserData())->SetIdMaterial(imat); | |
187 | ((AliDrawVolume *) item2->GetUserData())->SetIdMedium(imed); | |
188 | // | |
189 | // Set current volume to first list tree entry | |
190 | if (!i) gCurrentVolume= ((AliDrawVolume *) item2->GetUserData()); | |
191 | ||
192 | // | |
193 | // Collect children information | |
194 | // | |
195 | // nch < 0: Children by division | |
196 | if (nch < 0) { | |
197 | // | |
198 | // Geant volume number | |
199 | Int_t icvol=Child(ivol,1); | |
200 | // Name | |
201 | strcpy(namec,((TGeant3*)gMC)->VolName(-icvol)); | |
202 | tmp = new char[4]; | |
203 | strncpy(tmp,(char *) &namec, 4); | |
204 | volume = new AliDrawVolume(namec); | |
205 | volume->SetIdVolume(-icvol); | |
206 | // Number of divisions | |
207 | Int_t jvo = fZlq[fGclink->jvolum-ivol]; | |
208 | Int_t jdiv = fZlq[jvo-1]; | |
209 | Int_t ndiv = Int_t (fZq[jdiv+3]); | |
210 | volume->SetIdCopy(-ndiv); | |
211 | // Link to mother | |
212 | volume->SetItem(item2); | |
213 | (*fVolumes)[newlevel]=volume; | |
214 | printf("\n volume %s %d %d %d", namec, icvol, nch, ndiv); | |
215 | newlevel++; | |
216 | // | |
217 | // Children by positioning | |
218 | } else { | |
219 | Int_t nnew=0; | |
220 | // Loop over children | |
221 | for (Int_t j=0; j<nch; j++) | |
222 | { | |
223 | // | |
224 | // Find out if this volume was already positioned and count copies | |
225 | Int_t icvol=Child(ivol,j+1); | |
226 | icvol = TMath::Abs(icvol); | |
227 | Bool_t inList=kFALSE; | |
228 | for (Int_t k=0; k<nnew; k++) { | |
229 | if (icvol== | |
230 | Volume(newlevel-k-1)->GetIdVolume()) | |
231 | { | |
232 | Volume(newlevel-k-1)->AddCopy(); | |
233 | inList=kTRUE; | |
234 | } | |
235 | } | |
236 | // | |
237 | // New child | |
238 | if (!inList) { | |
239 | // | |
240 | // Name | |
241 | strcpy(namec,((TGeant3*)gMC)->VolName(icvol)); | |
242 | tmp = new char[4]; | |
243 | strncpy(tmp,(char *) &namec, 4); | |
244 | volume = new AliDrawVolume(namec); | |
245 | volume->SetIdVolume(icvol); | |
246 | volume->SetIdCopy(1); | |
247 | // Link to mother | |
248 | volume->SetItem(item2); | |
249 | (*fVolumes)[newlevel]=volume; | |
250 | printf("\n volume %s %d %d", namec, icvol, nch); | |
251 | newlevel++; | |
252 | nnew++; | |
253 | } | |
254 | } | |
255 | } | |
256 | } | |
257 | // Move one level deaper | |
258 | nst=nlevel; | |
259 | nlevel=newlevel; | |
260 | } | |
261 | } | |
262 | ||
263 | void AliGeant3GeometryGUI::ReadMaterials() | |
264 | { | |
265 | // | |
266 | // Puts media and material names into ComboBox and | |
267 | // collects material information | |
268 | // | |
269 | Float_t a, z, dens, radl, absl; | |
270 | a=z=dens=radl=absl=-1; | |
271 | Int_t npar=0; | |
272 | Int_t imat, isvol, ifield; | |
273 | Float_t fieldm, tmaxfd, stemax, deemax, epsil, stmin; | |
274 | Float_t par[50]; | |
275 | Float_t ubuf[50]; | |
276 | Int_t nwbuf; | |
277 | ||
278 | char natmed[21], namate[21]; | |
279 | // | |
280 | // Loop over media | |
281 | Int_t nEntries=0; | |
282 | ||
283 | for(Int_t itm=1;itm<=fGcnum->ntmed;itm++) { | |
284 | Int_t jtm = fZlq[fGclink->jtmed-itm]; | |
285 | if (jtm > 0) { | |
286 | nEntries++; | |
287 | // | |
288 | // Get medium parameters | |
289 | ((TGeant3*)(gMC))->Gftmed(itm, natmed, imat, isvol, ifield, fieldm, | |
290 | tmaxfd, stemax, deemax, epsil, stmin, ubuf, &nwbuf); | |
291 | strncpy(natmed,(char*)&fZiq[jtm+1],20); | |
292 | natmed[20]='\0'; | |
293 | // | |
294 | // Create new medium object | |
295 | AliGUIMedium * medium = | |
296 | new AliGUIMedium(itm, imat, natmed, isvol, ifield, fieldm, | |
297 | tmaxfd, stemax, deemax, epsil, stmin); | |
298 | (*fMedia)[nEntries-1]=medium; | |
299 | { //Begin local scope for j | |
300 | for (Int_t j=1; j<=22; j++) { | |
301 | medium->SetPar(j,Cut(itm,j)); | |
302 | } | |
303 | } //End local scope for j | |
304 | { //Begin local scope for j | |
305 | for (Int_t j=23; j<=26; j++) { | |
306 | medium->SetPar(j,Cut(itm,j+3)); | |
307 | } | |
308 | } //End local scope for j | |
309 | { //Begin local scope for j | |
310 | for (Int_t j=27; j<=29; j++) { | |
311 | medium->SetPar(j,Cut(itm,j+4)); | |
312 | } | |
313 | } //End local scope for j | |
314 | // | |
315 | // Add to ComboBox | |
316 | fPanel->AddMedium(medium, nEntries); | |
317 | // | |
318 | // Associated material | |
319 | imat = Int_t (fZq[jtm+6]); | |
320 | Int_t jma = Int_t (fZlq[fGclink->jmate-imat]); | |
321 | // | |
322 | // Get material parameters | |
323 | ((TGeant3*)(gMC))->Gfmate (imat,namate,a,z,dens,radl,absl,par,npar); | |
324 | strncpy(namate,(char *)&fZiq[jma+1],20); | |
325 | namate[20]='\0'; | |
326 | // | |
327 | // Create new material object | |
328 | AliGUIMaterial * material = | |
329 | new AliGUIMaterial(imat,namate,a,z,dens,radl,absl); | |
330 | (*fMaterials)[nEntries-1]=material; | |
331 | material->Dump(); | |
332 | // | |
333 | // Add to combo box | |
334 | fPanel->AddMaterial(material, nEntries); | |
335 | gCurrentMaterial=material; | |
336 | } | |
337 | } | |
338 | fPanel->SetComboEntries(fMaterials); | |
339 | fPanel->SetMediaComboEntries(fMedia); | |
340 | fPanel->Update(); | |
341 | } | |
342 | ||
343 | Int_t AliGeant3GeometryGUI::NChildren(Int_t idvol) | |
344 | { | |
345 | // | |
346 | // Return number of children for volume idvol | |
347 | Int_t jvo = fZlq[fGclink->jvolum-idvol]; | |
348 | Int_t nin = Int_t(fZq[jvo+3]); | |
349 | return nin; | |
350 | } | |
351 | ||
352 | Int_t AliGeant3GeometryGUI::Child(Int_t idvol, Int_t idc) | |
353 | { | |
354 | // | |
355 | // Return GEANT id of child number idc of volume idvol | |
356 | Int_t jvo = fZlq[fGclink->jvolum-idvol]; | |
357 | Int_t nin=idc; | |
358 | Int_t jin = fZlq[jvo-nin]; | |
359 | Int_t numb = Int_t (fZq[jin +3]); | |
360 | if (numb > 1) { | |
361 | return -Int_t(fZq[jin+2]); | |
362 | } else { | |
363 | return Int_t(fZq[jin+2]); | |
364 | } | |
365 | } | |
366 | ||
367 | Int_t AliGeant3GeometryGUI::Medium(Int_t idvol) | |
368 | { | |
369 | // | |
370 | // Return medium number for volume idvol. | |
371 | // If idvol is negative the volume results from a division. | |
372 | Int_t imed; | |
373 | if (idvol > 0) { | |
374 | Int_t jvo = fZlq[fGclink->jvolum-idvol]; | |
375 | imed = Int_t(fZq[jvo+4]); | |
376 | } else { | |
377 | idvol=-idvol; | |
378 | Int_t jdiv = fZlq[fGclink->jvolum-idvol]; | |
379 | Int_t ivin = Int_t ( fZq[jdiv+2]); | |
380 | Int_t jvin = fZlq[fGclink->jvolum-ivin]; | |
381 | imed = Int_t (fZq[jvin+4]); | |
382 | } | |
383 | return imed; | |
384 | } | |
385 | ||
386 | Int_t AliGeant3GeometryGUI::Material(Int_t idvol) | |
387 | { | |
388 | // Return material number for volume idvol. | |
389 | // If idvol is negative the volume results from a division. | |
390 | ||
391 | Int_t imed=Medium(idvol); | |
392 | Int_t jtm = fZlq[fGclink->jtmed-imed]; | |
393 | return Int_t (fZq[jtm+6]); | |
394 | } | |
395 | ||
396 | ||
397 | Float_t AliGeant3GeometryGUI::Cut(Int_t imed, Int_t icut) | |
398 | { | |
399 | // Return cuts icut for medium idmed | |
400 | // | |
401 | Int_t jtm = fZlq[fGclink->jtmed-imed]; | |
402 | // | |
403 | // Have the defaults been modified ?? | |
404 | Int_t jtmn = fZlq[jtm]; | |
405 | if (jtmn >0) { | |
406 | jtm=jtmn; | |
407 | ||
408 | } else { | |
409 | jtm=fGclink->jtmed; | |
410 | } | |
411 | ||
412 | return Float_t (fZq[jtm+icut]); | |
413 | } | |
414 | ||
415 |