Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4gsposp.cc File Reference
#include "G3G4Interface.hh"
#include "G3toG4.hh"
#include "G3VolTable.hh"
#include "G3toG4MakeSolid.hh"
#include "G3Division.hh"
#include "G4SystemOfUnits.hh"
#include "G4VSolid.hh"

Go to the source code of this file.

Functions

G4bool G3NegVolPars (G4double pars[], G4int *nparpt, G3VolTableEntry *vte, G3VolTableEntry *mvte, const char routine[])
 
void PG4gsposp (G4String *tokens)
 
void G4ProcessDaughters (G3VolTableEntry *vte)
 
void G4CloneDaughters (G3VolTableEntry *vte, G3VolTableEntry *vteClone)
 
void G4CreateCloneVTE (G3VolTableEntry *vte, G3VolTableEntry *mvte, G4double pars[], G4int npar, G4int num, G4double x, G4double y, G4double z, G4int irot, G4String vonly)
 
void G4gsposp (G4String vname, G4int num, G4String vmoth, G4double x, G4double y, G4double z, G4int irot, G4String vonly, G4double pars[], G4int npar)
 

Function Documentation

◆ G3NegVolPars()

G4bool G3NegVolPars ( G4double  pars[],
G4int nparpt,
G3VolTableEntry vte,
G3VolTableEntry mvte,
const char  routine[] 
)

Definition at line 180 of file G3NegVolPars.cc.

183{
184 G4bool NegPresent = FALSE;
185
186 // retrieve parameters
187
188 // the volume
189 G4String shape = vte->GetShape();
190 G4double* rpar = vte->GetRpar();
191 G4int npar = vte->GetNpar();
192 if (npar ==0) {
193 // no solid parameters are defined in vte
194 npar = *nparpt;
195 rpar = pars;
196 }
197 else {
198 // solid parameters are already defined in vte
199 // pars[], nparpt are ignored
200 // TO DO: check if g3 ignores them too or resets
201 // vte parameters according to this new ones !!
202 }
203
204 // mother
205 G4String shapem = mvte->GetShape();
206 G4double* rparm = mvte->GetRpar();
207
208 if (strcmp(routine,"GSPOS") == 0 || strcmp(routine,"GSVOLU") == 0) {
209 NegPresent = G3CalcParamsFn(rpar,npar,rparm,shape,shapem);
210 }
211 if (strcmp(routine,"GSDVN") == 0) {
212 // just set the flag. The parametrization function figures out
213 // what to do.
214 for (G4int i=0;i<npar;i++) {
215 if (rpar[i] < 0) {
216 NegPresent = TRUE;
217 }
218 }
219 }
220 return NegPresent;
221}
G4bool G3CalcParamsFn(G4double *rpar, G4int npar, G4double *rparm, G4String shape, G4String shapem)
Definition: G3NegVolPars.cc:36
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23
G4double * GetRpar()

Referenced by G4CreateCloneVTE(), and G4ProcessDaughters().

◆ G4CloneDaughters()

void G4CloneDaughters ( G3VolTableEntry vte,
G3VolTableEntry vteClone 
)

Definition at line 126 of file G4gsposp.cc.

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.append(gSeparator); newName = newName + index;
148
149 // create dvteClone
150 G4String dvteShape = dvte->GetShape();
151 G4double* dvteRpar = dvte->GetRpar();
152 G4int dvteNpar = dvte->GetNpar();
153 G4int dvteNmed = dvte->GetNmed();
154 G4bool hasNegPars = dvte->HasNegPars();
155 G3VolTableEntry* dvteClone
156 = new G3VolTableEntry(newName, dvteShape, dvteRpar, dvteNpar,
157 dvteNmed, 0, hasNegPars);
158
159 // let dvte master and vol table know about it
160 G3Vol.PutVTE(dvteClone);
161 dvteMaster->AddClone(dvteClone);
162
163 // set mother daughter
164 vteClone->AddDaughter(dvteClone);
165 dvteClone->AddMother(vteClone);
166
167 // copy positions
168 G4int nofPositions = dvte->NPCopies();
169 for (G4int ip=0; ip<nofPositions; ip++)
170 dvteClone->AddG3Pos(dvte->GetG3PosCopy(ip));
171
172 // copy division
173 G3Division* dvteDivision = dvte->GetDivision();
174 if (dvteDivision) {
175 G3Division* dvteCloneDivision
176 = new G3Division(dvteClone, vteClone, *dvteDivision);
177 dvteClone->SetDivision(dvteCloneDivision);
178 dvteCloneDivision->UpdateVTE();
179 }
180
181 // clone daughters recursively
182 G4CloneDaughters(dvte, dvteClone);
183 }
184 else {
185 // set dvte to vteClone
186 vteClone->AddDaughter(dvte);
187 dvte->AddMother(vteClone);
188 }
189 }
190}
G3G4DLL_API G3VolTable G3Vol
Definition: clparse.cc:53
G3G4DLL_API char gSeparator
void G4CloneDaughters(G3VolTableEntry *vte, G3VolTableEntry *vteClone)
Definition: G4gsposp.cc:126
void UpdateVTE()
Definition: G3Division.cc:96
void AddClone(G3VolTableEntry *aDaughter)
void AddMother(G3VolTableEntry *aDaughter)
void SetDivision(G3Division *division)
G3VolTableEntry * GetMasterClone()
G3Division * GetDivision()
void AddG3Pos(G3Pos *aG3Pos)
void AddDaughter(G3VolTableEntry *aDaughter)
G3Pos * GetG3PosCopy(G4int copy=0)
G3VolTableEntry * GetDaughter(G4int i)
G3VolTableEntry * PutVTE(G3VolTableEntry *aVTE)
Definition: G3VolTable.cc:75
G4String & append(const G4String &)

Referenced by G4CloneDaughters(), and G4CreateCloneVTE().

◆ G4CreateCloneVTE()

void G4CreateCloneVTE ( G3VolTableEntry vte,
G3VolTableEntry mvte,
G4double  pars[],
G4int  npar,
G4int  num,
G4double  x,
G4double  y,
G4double  z,
G4int  irot,
G4String  vonly 
)

Definition at line 192 of file G4gsposp.cc.

198{
199 // create a G3Pos
200 G4ThreeVector* offset = new G4ThreeVector(x*cm, y*cm, z*cm);
201 G3Pos* aG3Pos = new G3Pos(mvte->GetName(), num, offset, irot, vonly);
202
203 // loop over all mothers
204 for (G4int i=0; i<mvte->GetNoClones(); i++) {
205 // mvte was retrieved from its "master" name
206 // -> there is no need to call GetMasterClone()
207 G3VolTableEntry* mvteClone = mvte->GetClone(i);
208
209 G4String tmpName = "TRY";
210 G4String vteShape = vte->GetShape();
211 G3VolTableEntry* vteClone
212 = new G3VolTableEntry(tmpName, vteShape, pars, npar, vte->GetNmed(),
213 0, true);
214
215 // negative parameters will be updated only
216 // for vteClone, pars are unchanged
217 G4double* clonePars = vteClone->GetRpar();
218 G4int cloneNpar = vteClone->GetNpar();
219 G4bool negpars
220 = G3NegVolPars(clonePars, &cloneNpar, vteClone, mvteClone, "GSPOS");
221 vteClone->SetHasNegPars(negpars);
222
223 G3VolTableEntry* vteSameClone = 0;
224 G4VSolid* solid = 0;
225 if (!negpars) {
226 // check if vteClone with the same parameters exist
227 for (G4int ic=0; ic<vte->GetNoClones(); ic++) {
228 G3VolTableEntry* checkClone = vte->GetClone(ic);
229 G4int checkNpar = checkClone->GetNpar();
230 G4double* checkPars = checkClone->GetRpar();
231
232 G4bool isSame;
233 if (checkNpar != cloneNpar)
234 isSame = false;
235 else {
236 isSame = true;
237 for (G4int ip=0; ip<cloneNpar; ip++)
238 if (checkPars[ip] != clonePars[ip]) {
239 isSame = false;
240 break;
241 }
242 }
243 if (isSame) { vteSameClone = checkClone; 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}
G4VSolid * G3toG4MakeSolid(const G4String &vname, const G4String &shape, const G4double *Rpar, const G4int npar, G4bool &NegVolPars, G4bool &Deferred, G4bool *OKAxis)
CLHEP::Hep3Vector G4ThreeVector
G4bool G3NegVolPars(G4double pars[], G4int *nparpt, G3VolTableEntry *vte, G3VolTableEntry *mvte, const char routine[])
void G4ProcessDaughters(G3VolTableEntry *vte)
Definition: G4gsposp.cc:65
Definition: G3Pos.hh:43
void SetName(G4String name)
G3VolTableEntry * GetClone(G4int i)
void SetHasNegPars(G4bool hasNegPars)
void SetSolid(G4VSolid *solid)

Referenced by G4gspos(), and G4gsposp().

◆ G4gsposp()

void G4gsposp ( G4String  vname,
G4int  num,
G4String  vmoth,
G4double  x,
G4double  y,
G4double  z,
G4int  irot,
G4String  vonly,
G4double  pars[],
G4int  npar 
)

Definition at line 296 of file G4gsposp.cc.

299{
300 // find VTEs
301 G3VolTableEntry* vte = G3Vol.GetVTE(vname);
302 G3VolTableEntry* mvte = G3Vol.GetVTE(vmoth);
303
304 if (vte == 0) {
305 G4String err_message1 = "G4gsposp: '" + vname + "' has no VolTableEntry";
306 G4Exception("G4psposp()", "G3toG40021", FatalException, err_message1);
307 return;
308 }
309 if (mvte == 0) {
310 G4String err_message2 = "G4gsposp: '" + vmoth + "' has no VolTableEntry";
311 G4Exception("G4psposp()", "G3toG40022", FatalException, err_message2);
312 return;
313 }
314 else {
315 // a new vte clone copy is created for each mother (clone copy)
316 // and its parameters are derived from it if possible
317
318 G4CreateCloneVTE(vte, mvte, pars, npar, num, x, y, z, irot, vonly);
319 }
320}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
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:192
G3VolTableEntry * GetVTE(const G4String &Vname)
Definition: G3VolTable.cc:53

Referenced by PG4gsposp().

◆ G4ProcessDaughters()

void G4ProcessDaughters ( G3VolTableEntry vte)

Definition at line 65 of file G4gsposp.cc.

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}
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
void SetNRpar(G4int npar, G4double *Rpar)

Referenced by G4CreateCloneVTE(), and G4ProcessDaughters().

◆ PG4gsposp()

void PG4gsposp ( G4String tokens)

Definition at line 41 of file G4gsposp.cc.

41 {
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}
#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
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:296
const char * name(G4int ptype)

Referenced by G3CLEval().