1 /* *************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.8 2000/07/12 08:56:32 fca
19 Coding convention correction and warning removal
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 ?)
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
30 Revision 1.5 2000/03/20 15:11:03 fca
31 Mods to make the code compile on HP
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
37 Revision 1.3 1999/11/14 14:31:14 fca
38 Correct small error and remove compilation warnings on HP
40 Revision 1.2 1999/11/10 16:53:35 fca
41 The new geometry viewer from A.Morsch
47 * Written by Andreas Morsch
51 * For questions critics and suggestions to this part of the code
52 * contact andreas.morsch@cern.ch
54 **************************************************************************/
57 #include "AliGeant3GeometryGUI.h"
58 #include "AliDrawVolume.h"
59 #include "AliGUIMaterial.h"
60 #include "AliGUIMedium.h"
61 #include "AliGuiGeomMain.h"
63 AliDrawVolume *gCurrentVolume = new AliDrawVolume("NULL");
64 AliGUIMaterial *gCurrentMaterial = new AliGUIMaterial();
65 AliGUIMedium *gCurrentMedium = new AliGUIMedium();
67 ClassImp(AliGeant3GeometryGUI)
69 AliGeant3GeometryGUI::AliGeant3GeometryGUI()
72 fPanel = new AliGuiGeomMain(gClient->GetRoot(), 500, 500);
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;
83 fGclink=geant3->Gclink();
84 fGcnum=geant3->Gcnum();
90 void AliGeant3GeometryGUI::Streamer(TBuffer &)
97 void AliGeant3GeometryGUI::ReadGeometryTree()
100 // Copy zebra volume tree into ROOT LisTree
103 char /* *namec, */ *tmp;
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");
111 const TGPicture* kDocument = gClient->GetPicture("doc_t.xpm");
113 AliDrawVolume *volume;
117 Int_t newlevel=nlevel;
119 volume = new AliDrawVolume("ALIC");
120 volume->SetIdVolume(((TGeant3*)gMC)->VolId("ALIC"));
121 volume->SetIdCopy(0);
122 volume->SetItem(NULL);
123 (*fVolumes)[0]=volume;
125 // Loop over volumes for which information has been collected
127 for (Int_t i=nst; i<nlevel; i++)
129 TGListTreeItem *itemi, *item2;
130 // GEANT3 volume number
131 Int_t ivol=TMath::Abs(Volume(i)->GetIdVolume());
133 // icopy=1 normal positioning
134 // icopy>1 positioning with parposp
136 Int_t icopy = Volume(i)->GetIdCopy();
137 // Medium and material number, handle special case of divisions
142 imat=Material(-ivol);
148 // Number of children
149 Int_t nch = NChildren(ivol);
150 strcpy(namec,((TGeant3*)gMC)->VolName(ivol));
152 printf("\n %s has %d children \n ", namec, nch);
154 printf("\n %s has divisions \n ", namec);
157 // Name to be used in ListTree
159 strncpy(vname,namec, 4);
163 sprintf(namec,"%s*%3dPos",namec,icopy);
164 } else if (icopy <0) {
165 sprintf(namec,"%s*%3dDiv",namec,-icopy);
168 itemi=Volume(i)->GetItem();
174 // Add volume to list tree
177 item2 = fPanel->AddItem(new AliDrawVolume(vname),
178 itemi, namec, kOpenFolder, kFolder);
180 item2 = fPanel->AddItem(new AliDrawVolume(vname),
181 itemi, namec, kDocument, kDocument);
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);
189 // Set current volume to first list tree entry
190 if (!i) gCurrentVolume= ((AliDrawVolume *) item2->GetUserData());
193 // Collect children information
195 // nch < 0: Children by division
198 // Geant volume number
199 Int_t icvol=Child(ivol,1);
201 strcpy(namec,((TGeant3*)gMC)->VolName(-icvol));
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);
212 volume->SetItem(item2);
213 (*fVolumes)[newlevel]=volume;
214 printf("\n volume %s %d %d %d", namec, icvol, nch, ndiv);
217 // Children by positioning
220 // Loop over children
221 for (Int_t j=0; j<nch; j++)
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++) {
230 Volume(newlevel-k-1)->GetIdVolume())
232 Volume(newlevel-k-1)->AddCopy();
241 strcpy(namec,((TGeant3*)gMC)->VolName(icvol));
243 strncpy(tmp,(char *) &namec, 4);
244 volume = new AliDrawVolume(namec);
245 volume->SetIdVolume(icvol);
246 volume->SetIdCopy(1);
248 volume->SetItem(item2);
249 (*fVolumes)[newlevel]=volume;
250 printf("\n volume %s %d %d", namec, icvol, nch);
257 // Move one level deaper
263 void AliGeant3GeometryGUI::ReadMaterials()
266 // Puts media and material names into ComboBox and
267 // collects material information
269 Float_t a, z, dens, radl, absl;
270 a=z=dens=radl=absl=-1;
272 Int_t imat, isvol, ifield;
273 Float_t fieldm, tmaxfd, stemax, deemax, epsil, stmin;
278 char natmed[21], namate[21];
283 for(Int_t itm=1;itm<=fGcnum->ntmed;itm++) {
284 Int_t jtm = fZlq[fGclink->jtmed-itm];
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);
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));
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));
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));
313 } //End local scope for j
316 fPanel->AddMedium(medium, nEntries);
318 // Associated material
319 imat = Int_t (fZq[jtm+6]);
320 Int_t jma = Int_t (fZlq[fGclink->jmate-imat]);
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);
327 // Create new material object
328 AliGUIMaterial * material =
329 new AliGUIMaterial(imat,namate,a,z,dens,radl,absl);
330 (*fMaterials)[nEntries-1]=material;
334 fPanel->AddMaterial(material, nEntries);
335 gCurrentMaterial=material;
338 fPanel->SetComboEntries(fMaterials);
339 fPanel->SetMediaComboEntries(fMedia);
343 Int_t AliGeant3GeometryGUI::NChildren(Int_t idvol)
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]);
352 Int_t AliGeant3GeometryGUI::Child(Int_t idvol, Int_t idc)
355 // Return GEANT id of child number idc of volume idvol
356 Int_t jvo = fZlq[fGclink->jvolum-idvol];
358 Int_t jin = fZlq[jvo-nin];
359 Int_t numb = Int_t (fZq[jin +3]);
361 return -Int_t(fZq[jin+2]);
363 return Int_t(fZq[jin+2]);
367 Int_t AliGeant3GeometryGUI::Medium(Int_t idvol)
370 // Return medium number for volume idvol.
371 // If idvol is negative the volume results from a division.
374 Int_t jvo = fZlq[fGclink->jvolum-idvol];
375 imed = Int_t(fZq[jvo+4]);
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]);
386 Int_t AliGeant3GeometryGUI::Material(Int_t idvol)
388 // Return material number for volume idvol.
389 // If idvol is negative the volume results from a division.
391 Int_t imed=Medium(idvol);
392 Int_t jtm = fZlq[fGclink->jtmed-imed];
393 return Int_t (fZq[jtm+6]);
397 Float_t AliGeant3GeometryGUI::Cut(Int_t imed, Int_t icut)
399 // Return cuts icut for medium idmed
401 Int_t jtm = fZlq[fGclink->jtmed-imed];
403 // Have the defaults been modified ??
404 Int_t jtmn = fZlq[jtm];
412 return Float_t (fZq[jtm+icut]);