Geant4-11
G4gsposp.cc
Go to the documentation of this file.
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//
28// by I.Hrivnacova, 13.10.99
29
30#include "G3G4Interface.hh"
31#include "G3toG4.hh"
32#include "G3VolTable.hh"
33#include "G3toG4MakeSolid.hh"
34#include "G3Division.hh"
35#include "G4SystemOfUnits.hh"
36#include "G4VSolid.hh"
37
38G4bool G3NegVolPars(G4double pars[], G4int *nparpt,
39 G3VolTableEntry* vte, G3VolTableEntry* mvte, const char routine[]);
40
41void PG4gsposp(G4String *tokens){
42 // fill the parameter containers
43 G3fillParams(tokens,PTgsposp);
44
45 // interpret the parameters
46 G4String name = Spar[0];
47 G4String moth = Spar[1];
48 G4String only = Spar[2];
49 G4int num = Ipar[0];
50 G4int irot = Ipar[1];
51 G4int npar = Ipar[2];
52 // all parameters are passed to G4gsxxx methods
53 // in G3 default units
54 //G4double x = Rpar[0]*cm;
55 //G4double y = Rpar[1]*cm;
56 //G4double z = Rpar[2]*cm;
57 G4double x = Rpar[0];
58 G4double y = Rpar[1];
59 G4double z = Rpar[2];
60 G4double *pars = &Rpar[3];
61
62 G4gsposp(name, num, moth, x, y, z, irot, only, pars, npar);
63}
64
66// restore negative volume parameters and create solid for all
67// vte daughters
68{
69 if (vte->HasNegPars()) {
70 G4cerr << " Warning:" << G4endl;
71 G4cerr << " G4ProcessDaughters: Ignored (vte has negative parameters)."
72 << G4endl;
73 }
74 else {
75 for (G4int i=0; i<vte->GetNoDaughters(); i++) {
76
77 G3VolTableEntry* dvte = vte->GetDaughter(i);
78
79 if (dvte->HasNegPars()) {
80 if (dvte->GetDivision()) {
81 // call division method for creating solid and updating
82 // dvte parameters
83 dvte->GetDivision()->UpdateVTE();
84 }
85 else {
86 // update negative parameters
87 G4double* pars = dvte->GetRpar();
88 G4int npar = dvte->GetNpar();
89 G4bool negpars
90 = G3NegVolPars(pars,&npar, dvte, vte, "GSPOS");
91
92 if (negpars) {
93 G4String text = "G3NegVolPars still returns negative parameters!";
94 G4Exception("G4ProcessDaughters()", "G3toG40019",
95 FatalException, text);
96 return;
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 = "G3toG4MakeSolid still returns negative parameters!";
108 G4Exception("G4ProcessDaughters()", "G3toG40020",
109 FatalException, text);
110 return;
111 }
112
113 // update dvte
114 dvte->SetNRpar(npar, pars);
115 dvte->SetSolid(solid);
116 dvte->SetHasNegPars(hasNegPars);
117 }
118
119 // process daughters
120 G4ProcessDaughters(dvte);
121 }
122 }
123 }
124}
125
127// copy vte daughters to vteClone
128// (in case of daughters with negative parameters
129// or with divisions new clone copies have to be created)
130{
131 G4int nofDaughters = vte->GetNoDaughters();
132 if (nofDaughters>0)
133 for (G4int id=0; id<nofDaughters; id++) {
134 G3VolTableEntry* dvte = vte->GetDaughter(id);
135
136 if (dvte->HasNegPars() || dvte->GetDivision()){
137 // create new dvteClone with Position/Division
138 // and set it to vteClone
139
140 // get master of dvte
141 G3VolTableEntry* dvteMaster = dvte->GetMasterClone();
142
143 // generate vteClone name
144 G4int cloneNo = dvteMaster->GetNoClones();
145 char index[5]; sprintf(index,"%d",cloneNo);
146 G4String newName = dvteMaster->GetName();
147 newName += gSeparator;
148 newName = newName + index;
149
150 // create dvteClone
151 G4String dvteShape = dvte->GetShape();
152 G4double* dvteRpar = dvte->GetRpar();
153 G4int dvteNpar = dvte->GetNpar();
154 G4int dvteNmed = dvte->GetNmed();
155 G4bool hasNegPars = dvte->HasNegPars();
156 G3VolTableEntry* dvteClone
157 = new G3VolTableEntry(newName, dvteShape, dvteRpar, dvteNpar,
158 dvteNmed, 0, hasNegPars);
159
160 // let dvte master and vol table know about it
161 G3Vol.PutVTE(dvteClone);
162 dvteMaster->AddClone(dvteClone);
163
164 // set mother daughter
165 vteClone->AddDaughter(dvteClone);
166 dvteClone->AddMother(vteClone);
167
168 // copy positions
169 G4int nofPositions = dvte->NPCopies();
170 for (G4int ip=0; ip<nofPositions; ip++)
171 dvteClone->AddG3Pos(dvte->GetG3PosCopy(ip));
172
173 // copy division
174 G3Division* dvteDivision = dvte->GetDivision();
175 if (dvteDivision) {
176 G3Division* dvteCloneDivision
177 = new G3Division(dvteClone, vteClone, *dvteDivision);
178 dvteClone->SetDivision(dvteCloneDivision);
179 dvteCloneDivision->UpdateVTE();
180 }
181
182 // clone daughters recursively
183 G4CloneDaughters(dvte, dvteClone);
184 }
185 else {
186 // set dvte to vteClone
187 vteClone->AddDaughter(dvte);
188 dvte->AddMother(vteClone);
189 }
190 }
191}
192
194 G4double pars[], G4int npar, G4int num,
195 G4double x, G4double y, G4double z, G4int irot, G4String vonly)
196//
197// create a new vte clone copy for each mother
198// and derive its parameters from the mother if possible
199{
200 // create a G3Pos
201 G4ThreeVector* offset = new G4ThreeVector(x*cm, y*cm, z*cm);
202 G3Pos* aG3Pos = new G3Pos(mvte->GetName(), num, offset, irot, vonly);
203
204 // loop over all mothers
205 for (G4int i=0; i<mvte->GetNoClones(); i++) {
206 // mvte was retrieved from its "master" name
207 // -> there is no need to call GetMasterClone()
208 G3VolTableEntry* mvteClone = mvte->GetClone(i);
209
210 G4String tmpName = "TRY";
211 G4String vteShape = vte->GetShape();
212 G3VolTableEntry* vteClone
213 = new G3VolTableEntry(tmpName, vteShape, pars, npar, vte->GetNmed(),
214 0, true);
215
216 // negative parameters will be updated only
217 // for vteClone, pars are unchanged
218 G4double* clonePars = vteClone->GetRpar();
219 G4int cloneNpar = vteClone->GetNpar();
220 G4bool negpars
221 = G3NegVolPars(clonePars, &cloneNpar, vteClone, mvteClone, "GSPOS");
222 vteClone->SetHasNegPars(negpars);
223
224 G3VolTableEntry* vteSameClone = 0;
225 G4VSolid* solid = 0;
226 if (!negpars) {
227 // check if vteClone with the same parameters exist
228 for (G4int ic=0; ic<vte->GetNoClones(); ic++) {
229 G3VolTableEntry* checkClone = vte->GetClone(ic);
230 G4int checkNpar = checkClone->GetNpar();
231 G4double* checkPars = checkClone->GetRpar();
232
233 G4bool isSame;
234 if (checkNpar != cloneNpar)
235 isSame = false;
236 else {
237 isSame = true;
238 for (G4int ip=0; ip<cloneNpar; ip++)
239 if (checkPars[ip] != clonePars[ip]) {
240 isSame = false;
241 break;
242 }
243 }
244 if (isSame) { vteSameClone = checkClone; break; }
245 }
246
247 if (vteSameClone) {
248 delete vteClone;
249
250 // add aG3Pos to the vteClone
251 vteSameClone->AddG3Pos(aG3Pos);
252 mvteClone->AddDaughter(vteSameClone);
253 vteSameClone->AddMother(mvteClone);
254 }
255 else {
256 // create the solid
257 G4bool hasNegPars;
258 G4bool deferred;
259 G4bool okAxis[3];
260 G4String vteName = vte->GetName();
261 G4String cloneShape = vteClone->GetShape();
262 solid = G3toG4MakeSolid(vteName, cloneShape, clonePars, cloneNpar,
263 hasNegPars, deferred, okAxis);
264 }
265 }
266
267 if ( negpars || !(vteSameClone)) {
268 // generate vteClone name
269 G4int cloneNo = vte->GetNoClones();
270 char index[5]; sprintf(index,"%d",cloneNo);
271 G4String newName = vte->GetName();
272 newName += gSeparator;
273 newName = newName + index;
274
275 // update vteClone
276 vteClone->SetName(newName);
277 vteClone->SetSolid(solid);
278 vteClone->SetHasNegPars(negpars);
279
280 // let vte and vol table know about it
281 G3Vol.PutVTE(vteClone);
282 vte->AddClone(vteClone);
283
284 // add aG3Pos to the vteClone
285 vteClone->AddG3Pos(aG3Pos);
286 mvteClone->AddDaughter(vteClone);
287 vteClone->AddMother(mvteClone);
288
289 // copy all daughters
290 G4CloneDaughters(vte, vteClone);
291
292 // retrieve daughters parameters
293 if (!negpars) G4ProcessDaughters(vteClone);
294 }
295 }
296}
297
298void G4gsposp(G4String vname, G4int num, G4String vmoth, G4double x,
299 G4double y, G4double z, G4int irot, G4String vonly,
300 G4double pars[], G4int npar)
301{
302 // find VTEs
303 G3VolTableEntry* vte = G3Vol.GetVTE(vname);
304 G3VolTableEntry* mvte = G3Vol.GetVTE(vmoth);
305
306 if (vte == 0) {
307 G4String err_message1 = "G4gsposp: '" + vname + "' has no VolTableEntry";
308 G4Exception("G4psposp()", "G3toG40021", FatalException, err_message1);
309 return;
310 }
311 if (mvte == 0) {
312 G4String err_message2 = "G4gsposp: '" + vmoth + "' has no VolTableEntry";
313 G4Exception("G4psposp()", "G3toG40022", FatalException, err_message2);
314 return;
315 }
316 else {
317 // a new vte clone copy is created for each mother (clone copy)
318 // and its parameters are derived from it if possible
319
320 G4CreateCloneVTE(vte, mvte, pars, npar, num, x, y, z, irot, vonly);
321 }
322}
G3G4DLL_API G3VolTable G3Vol
Definition: clparse.cc:53
G4VSolid * G3toG4MakeSolid(const G4String &vname, const G4String &shape, const G4double *Rpar, const G4int npar, G4bool &NegVolPars, G4bool &Deferred, G4bool *OKAxis)
#define PTgsposp
Definition: G3toG4.hh:53
G3G4DLL_API G4int Ipar[1000]
Definition: clparse.cc:65
void G3fillParams(G4String *tokens, const char *ptypes)
Definition: clparse.cc:218
G3G4DLL_API G4double Rpar[1000]
Definition: clparse.cc:66
G3G4DLL_API G4String Spar[1000]
Definition: clparse.cc:67
G3G4DLL_API char gSeparator
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
static constexpr double cm
Definition: G4SIunits.hh:99
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void G4CreateCloneVTE(G3VolTableEntry *vte, G3VolTableEntry *mvte, G4double pars[], G4int npar, G4int num, G4double x, G4double y, G4double z, G4int irot, G4String vonly)
Definition: G4gsposp.cc:193
void PG4gsposp(G4String *tokens)
Definition: G4gsposp.cc:41
void G4CloneDaughters(G3VolTableEntry *vte, G3VolTableEntry *vteClone)
Definition: G4gsposp.cc:126
G4bool G3NegVolPars(G4double pars[], G4int *nparpt, G3VolTableEntry *vte, G3VolTableEntry *mvte, const char routine[])
void G4gsposp(G4String vname, G4int num, G4String vmoth, G4double x, G4double y, G4double z, G4int irot, G4String vonly, G4double pars[], G4int npar)
Definition: G4gsposp.cc:298
void G4ProcessDaughters(G3VolTableEntry *vte)
Definition: G4gsposp.cc:65
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
void UpdateVTE()
Definition: G3Division.cc:96
Definition: G3Pos.hh:43
void AddClone(G3VolTableEntry *aDaughter)
void AddMother(G3VolTableEntry *aDaughter)
void SetDivision(G3Division *division)
void SetName(G4String name)
G3VolTableEntry * GetMasterClone()
G3Division * GetDivision()
G3VolTableEntry * GetClone(G4int i)
void AddG3Pos(G3Pos *aG3Pos)
void SetHasNegPars(G4bool hasNegPars)
G4double * GetRpar()
void SetNRpar(G4int npar, G4double *Rpar)
void AddDaughter(G3VolTableEntry *aDaughter)
void SetSolid(G4VSolid *solid)
G3Pos * GetG3PosCopy(G4int copy=0)
G3VolTableEntry * GetDaughter(G4int i)
G3VolTableEntry * PutVTE(G3VolTableEntry *aVTE)
Definition: G3VolTable.cc:75
G3VolTableEntry * GetVTE(const G4String &Vname)
Definition: G3VolTable.cc:53
const char * name(G4int ptype)