1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // $Id: G4gsposp.cc,v 1.16 2006/06/29 18:14:44 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // by I.Hrivnacova, 13.10.99 |
---|
31 | |
---|
32 | #include "G3G4Interface.hh" |
---|
33 | #include "G3toG4.hh" |
---|
34 | #include "G3VolTable.hh" |
---|
35 | #include "G3toG4MakeSolid.hh" |
---|
36 | #include "G3Division.hh" |
---|
37 | #include "G4VSolid.hh" |
---|
38 | |
---|
39 | G4bool G3NegVolPars(G4double pars[], G4int *nparpt, |
---|
40 | G3VolTableEntry* vte, G3VolTableEntry* mvte, const char routine[]); |
---|
41 | |
---|
42 | void PG4gsposp(G4String tokens[]){ |
---|
43 | // fill the parameter containers |
---|
44 | G3fillParams(tokens,PTgsposp); |
---|
45 | |
---|
46 | // interpret the parameters |
---|
47 | G4String name = Spar[0]; |
---|
48 | G4String moth = Spar[1]; |
---|
49 | G4String only = Spar[2]; |
---|
50 | G4int num = Ipar[0]; |
---|
51 | G4int irot = Ipar[1]; |
---|
52 | G4int npar = Ipar[2]; |
---|
53 | // all parameters are passed to G4gsxxx methods |
---|
54 | // in G3 default units |
---|
55 | //G4double x = Rpar[0]*cm; |
---|
56 | //G4double y = Rpar[1]*cm; |
---|
57 | //G4double z = Rpar[2]*cm; |
---|
58 | G4double x = Rpar[0]; |
---|
59 | G4double y = Rpar[1]; |
---|
60 | G4double z = Rpar[2]; |
---|
61 | G4double *pars = &Rpar[3]; |
---|
62 | |
---|
63 | G4gsposp(name, num, moth, x, y, z, irot, only, pars, npar); |
---|
64 | } |
---|
65 | |
---|
66 | void G4ProcessDaughters(G3VolTableEntry* vte) |
---|
67 | // restore negative volume parameters and create solid for all |
---|
68 | // vte daughters |
---|
69 | { |
---|
70 | if (vte->HasNegPars()) { |
---|
71 | G4cerr << " Warning:" << G4endl; |
---|
72 | G4cerr << " G4ProcessDaughters: Ignored (vte has negative parameters)." |
---|
73 | << G4endl; |
---|
74 | } |
---|
75 | else { |
---|
76 | for (G4int i=0; i<vte->GetNoDaughters(); i++) { |
---|
77 | |
---|
78 | G3VolTableEntry* dvte = vte->GetDaughter(i); |
---|
79 | |
---|
80 | if (dvte->HasNegPars()) { |
---|
81 | if (dvte->GetDivision()) { |
---|
82 | // call division method for creating solid and updating |
---|
83 | // dvte parameters |
---|
84 | dvte->GetDivision()->UpdateVTE(); |
---|
85 | } |
---|
86 | else { |
---|
87 | // update negative parameters |
---|
88 | G4double* pars = dvte->GetRpar(); |
---|
89 | G4int npar = dvte->GetNpar(); |
---|
90 | G4bool negpars |
---|
91 | = G3NegVolPars(pars,&npar, dvte, vte, "GSPOS"); |
---|
92 | |
---|
93 | if (negpars) { |
---|
94 | G4String text = " G4ProcessDaughter:\n"; |
---|
95 | text = text + " G3NegVolPars still returns negative parameters!"; |
---|
96 | G4Exception(text); |
---|
97 | } |
---|
98 | |
---|
99 | // create solid |
---|
100 | G4bool hasNegPars; |
---|
101 | G4bool deferred; |
---|
102 | G4bool okAxis[3]; |
---|
103 | G4VSolid* solid |
---|
104 | = G3toG4MakeSolid(dvte->GetName(), dvte->GetShape(), pars, npar, |
---|
105 | hasNegPars, deferred, okAxis); |
---|
106 | if (hasNegPars) { |
---|
107 | G4String text = " G4ProcessDaughter:\n"; |
---|
108 | text = text + " G3toG4MakeSolid still returns negative parameters!"; |
---|
109 | G4Exception(text); |
---|
110 | } |
---|
111 | |
---|
112 | // update dvte |
---|
113 | dvte->SetNRpar(npar, pars); |
---|
114 | dvte->SetSolid(solid); |
---|
115 | dvte->SetHasNegPars(hasNegPars); |
---|
116 | } |
---|
117 | |
---|
118 | // process daughters |
---|
119 | G4ProcessDaughters(dvte); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | void G4CloneDaughters(G3VolTableEntry* vte, G3VolTableEntry* vteClone) |
---|
126 | // copy vte daughters to vteClone |
---|
127 | // (in case of daughters with negative parameters |
---|
128 | // or with divisions new clone copies have to be created) |
---|
129 | { |
---|
130 | G4int nofDaughters = vte->GetNoDaughters(); |
---|
131 | if (nofDaughters>0) |
---|
132 | for (G4int id=0; id<nofDaughters; id++) { |
---|
133 | G3VolTableEntry* dvte = vte->GetDaughter(id); |
---|
134 | |
---|
135 | if (dvte->HasNegPars() || dvte->GetDivision()){ |
---|
136 | // create new dvteClone with Position/Division |
---|
137 | // and set it to vteClone |
---|
138 | |
---|
139 | // get master of dvte |
---|
140 | G3VolTableEntry* dvteMaster = dvte->GetMasterClone(); |
---|
141 | |
---|
142 | // generate vteClone name |
---|
143 | G4int cloneNo = dvteMaster->GetNoClones(); |
---|
144 | char index[5]; sprintf(index,"%d",cloneNo); |
---|
145 | G4String newName = dvteMaster->GetName(); |
---|
146 | newName.append(gSeparator); newName = newName + index; |
---|
147 | |
---|
148 | // create dvteClone |
---|
149 | G4String dvteShape = dvte->GetShape(); |
---|
150 | G4double* dvteRpar = dvte->GetRpar(); |
---|
151 | G4int dvteNpar = dvte->GetNpar(); |
---|
152 | G4int dvteNmed = dvte->GetNmed(); |
---|
153 | G4bool hasNegPars = dvte->HasNegPars(); |
---|
154 | G3VolTableEntry* dvteClone |
---|
155 | = new G3VolTableEntry(newName, dvteShape, dvteRpar, dvteNpar, |
---|
156 | dvteNmed, 0, hasNegPars); |
---|
157 | |
---|
158 | // let dvte master and vol table know about it |
---|
159 | G3Vol.PutVTE(dvteClone); |
---|
160 | dvteMaster->AddClone(dvteClone); |
---|
161 | |
---|
162 | // set mother daughter |
---|
163 | vteClone->AddDaughter(dvteClone); |
---|
164 | dvteClone->AddMother(vteClone); |
---|
165 | |
---|
166 | // copy positions |
---|
167 | G4int nofPositions = dvte->NPCopies(); |
---|
168 | for (G4int ip=0; ip<nofPositions; ip++) |
---|
169 | dvteClone->AddG3Pos(dvte->GetG3PosCopy(ip)); |
---|
170 | |
---|
171 | // copy division |
---|
172 | G3Division* dvteDivision = dvte->GetDivision(); |
---|
173 | if (dvteDivision) { |
---|
174 | G3Division* dvteCloneDivision |
---|
175 | = new G3Division(dvteClone, vteClone, *dvteDivision); |
---|
176 | dvteClone->SetDivision(dvteCloneDivision); |
---|
177 | dvteCloneDivision->UpdateVTE(); |
---|
178 | } |
---|
179 | |
---|
180 | // clone daughters recursively |
---|
181 | G4CloneDaughters(dvte, dvteClone); |
---|
182 | } |
---|
183 | else { |
---|
184 | // set dvte to vteClone |
---|
185 | vteClone->AddDaughter(dvte); |
---|
186 | dvte->AddMother(vteClone); |
---|
187 | } |
---|
188 | } |
---|
189 | } |
---|
190 | |
---|
191 | void G4CreateCloneVTE(G3VolTableEntry* vte, G3VolTableEntry* mvte, |
---|
192 | G4double pars[], G4int npar, G4int num, |
---|
193 | G4double x, G4double y, G4double z, G4int irot, G4String vonly) |
---|
194 | // |
---|
195 | // create a new vte clone copy for each mother |
---|
196 | // and derive its parameters from the mother if possible |
---|
197 | { |
---|
198 | // create a G3Pos |
---|
199 | G4ThreeVector* offset = new G4ThreeVector(x*cm, y*cm, z*cm); |
---|
200 | G3Pos* aG3Pos = new G3Pos(mvte->GetName(), num, offset, irot, vonly); |
---|
201 | |
---|
202 | // loop over all mothers |
---|
203 | for (G4int i=0; i<mvte->GetNoClones(); i++) { |
---|
204 | // mvte was retrieved from its "master" name |
---|
205 | // -> there is no need to call GetMasterClone() |
---|
206 | G3VolTableEntry* mvteClone = mvte->GetClone(i); |
---|
207 | |
---|
208 | G4String tmpName = "TRY"; |
---|
209 | G4String vteShape = vte->GetShape(); |
---|
210 | G3VolTableEntry* vteClone |
---|
211 | = new G3VolTableEntry(tmpName, vteShape, pars, npar, vte->GetNmed(), |
---|
212 | 0, true); |
---|
213 | |
---|
214 | // negative parameters will be updated only |
---|
215 | // for vteClone, pars are unchanged |
---|
216 | G4double* clonePars = vteClone->GetRpar(); |
---|
217 | G4int cloneNpar = vteClone->GetNpar(); |
---|
218 | G4bool negpars |
---|
219 | = G3NegVolPars(clonePars, &cloneNpar, vteClone, mvteClone, "GSPOS"); |
---|
220 | vteClone->SetHasNegPars(negpars); |
---|
221 | |
---|
222 | G3VolTableEntry* vteSameClone = 0; |
---|
223 | G4VSolid* solid = 0; |
---|
224 | if (!negpars) { |
---|
225 | // check if vteClone with the same parameters exist |
---|
226 | for (G4int ic=0; ic<vte->GetNoClones(); ic++) { |
---|
227 | G3VolTableEntry* checkClone = vte->GetClone(ic); |
---|
228 | G4int checkNpar = checkClone->GetNpar(); |
---|
229 | G4double* checkPars = checkClone->GetRpar(); |
---|
230 | |
---|
231 | G4bool isSame; |
---|
232 | if (checkNpar != cloneNpar) |
---|
233 | isSame = false; |
---|
234 | else { |
---|
235 | isSame = true; |
---|
236 | for (G4int ip=0; ip<cloneNpar; ip++) |
---|
237 | if (checkPars[ip] != clonePars[ip]) { |
---|
238 | isSame = false; |
---|
239 | break; |
---|
240 | } |
---|
241 | } |
---|
242 | if (isSame) vteSameClone = checkClone; |
---|
243 | break; |
---|
244 | } |
---|
245 | |
---|
246 | if (vteSameClone) { |
---|
247 | delete vteClone; |
---|
248 | |
---|
249 | // add aG3Pos to the vteClone |
---|
250 | vteSameClone->AddG3Pos(aG3Pos); |
---|
251 | mvteClone->AddDaughter(vteSameClone); |
---|
252 | vteSameClone->AddMother(mvteClone); |
---|
253 | } |
---|
254 | else { |
---|
255 | // create the solid |
---|
256 | G4bool hasNegPars; |
---|
257 | G4bool deferred; |
---|
258 | G4bool okAxis[3]; |
---|
259 | G4String vteName = vte->GetName(); |
---|
260 | G4String cloneShape = vteClone->GetShape(); |
---|
261 | solid = G3toG4MakeSolid(vteName, cloneShape, clonePars, cloneNpar, |
---|
262 | hasNegPars, deferred, okAxis); |
---|
263 | } |
---|
264 | } |
---|
265 | |
---|
266 | if ( negpars || !(vteSameClone)) { |
---|
267 | // generate vteClone name |
---|
268 | G4int cloneNo = vte->GetNoClones(); |
---|
269 | char index[5]; sprintf(index,"%d",cloneNo); |
---|
270 | G4String newName = vte->GetName(); |
---|
271 | newName.append(gSeparator); newName = newName + index; |
---|
272 | |
---|
273 | // update vteClone |
---|
274 | vteClone->SetName(newName); |
---|
275 | vteClone->SetSolid(solid); |
---|
276 | vteClone->SetHasNegPars(negpars); |
---|
277 | |
---|
278 | // let vte and vol table know about it |
---|
279 | G3Vol.PutVTE(vteClone); |
---|
280 | vte->AddClone(vteClone); |
---|
281 | |
---|
282 | // add aG3Pos to the vteClone |
---|
283 | vteClone->AddG3Pos(aG3Pos); |
---|
284 | mvteClone->AddDaughter(vteClone); |
---|
285 | vteClone->AddMother(mvteClone); |
---|
286 | |
---|
287 | // copy all daughters |
---|
288 | G4CloneDaughters(vte, vteClone); |
---|
289 | |
---|
290 | // retrieve daughters parameters |
---|
291 | if (!negpars) G4ProcessDaughters(vteClone); |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | |
---|
296 | void G4gsposp(G4String vname, G4int num, G4String vmoth, G4double x, |
---|
297 | G4double y, G4double z, G4int irot, G4String vonly, |
---|
298 | G4double pars[], G4int npar) |
---|
299 | { |
---|
300 | // find VTEs |
---|
301 | G3VolTableEntry* vte = G3Vol.GetVTE(vname); |
---|
302 | G3VolTableEntry* mvte = G3Vol.GetVTE(vmoth); |
---|
303 | |
---|
304 | if (vte == 0) { |
---|
305 | G4Exception("G4gsposp: '" + vname + "' has no VolTableEntry"); |
---|
306 | } |
---|
307 | if (mvte == 0) { |
---|
308 | G4Exception("G4gsposp: '" + vmoth + "' has no VolTableEntry"); |
---|
309 | } |
---|
310 | else { |
---|
311 | // a new vte clone copy is created for each mother (clone copy) |
---|
312 | // and its parameters are derived from it if possible |
---|
313 | |
---|
314 | G4CreateCloneVTE(vte, mvte, pars, npar, num, x, y, z, irot, vonly); |
---|
315 | } |
---|
316 | } |
---|