Geant4  10.02.p01
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 // $Id: G4gsposp.cc 67982 2013-03-13 10:36:03Z gcosmo $
28 //
29 // by I.Hrivnacova, 13.10.99
30 
31 #include "G3G4Interface.hh"
32 #include "G3toG4.hh"
33 #include "G3VolTable.hh"
34 #include "G3toG4MakeSolid.hh"
35 #include "G3Division.hh"
36 #include "G4SystemOfUnits.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 
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 = "G3NegVolPars still returns negative parameters!";
95  G4Exception("G4ProcessDaughters()", "G3toG40019",
96  FatalException, text);
97  return;
98  }
99 
100  // create solid
101  G4bool hasNegPars;
102  G4bool deferred;
103  G4bool okAxis[3];
104  G4VSolid* solid
105  = G3toG4MakeSolid(dvte->GetName(), dvte->GetShape(), pars, npar,
106  hasNegPars, deferred, okAxis);
107  if (hasNegPars) {
108  G4String text = "G3toG4MakeSolid still returns negative parameters!";
109  G4Exception("G4ProcessDaughters()", "G3toG40020",
110  FatalException, text);
111  return;
112  }
113 
114  // update dvte
115  dvte->SetNRpar(npar, pars);
116  dvte->SetSolid(solid);
117  dvte->SetHasNegPars(hasNegPars);
118  }
119 
120  // process daughters
121  G4ProcessDaughters(dvte);
122  }
123  }
124  }
125 }
126 
128 // copy vte daughters to vteClone
129 // (in case of daughters with negative parameters
130 // or with divisions new clone copies have to be created)
131 {
132  G4int nofDaughters = vte->GetNoDaughters();
133  if (nofDaughters>0)
134  for (G4int id=0; id<nofDaughters; id++) {
135  G3VolTableEntry* dvte = vte->GetDaughter(id);
136 
137  if (dvte->HasNegPars() || dvte->GetDivision()){
138  // create new dvteClone with Position/Division
139  // and set it to vteClone
140 
141  // get master of dvte
142  G3VolTableEntry* dvteMaster = dvte->GetMasterClone();
143 
144  // generate vteClone name
145  G4int cloneNo = dvteMaster->GetNoClones();
146  char index[5]; sprintf(index,"%d",cloneNo);
147  G4String newName = dvteMaster->GetName();
148  newName.append(gSeparator); 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.append(gSeparator); newName = newName + index;
273 
274  // update vteClone
275  vteClone->SetName(newName);
276  vteClone->SetSolid(solid);
277  vteClone->SetHasNegPars(negpars);
278 
279  // let vte and vol table know about it
280  G3Vol.PutVTE(vteClone);
281  vte->AddClone(vteClone);
282 
283  // add aG3Pos to the vteClone
284  vteClone->AddG3Pos(aG3Pos);
285  mvteClone->AddDaughter(vteClone);
286  vteClone->AddMother(mvteClone);
287 
288  // copy all daughters
289  G4CloneDaughters(vte, vteClone);
290 
291  // retrieve daughters parameters
292  if (!negpars) G4ProcessDaughters(vteClone);
293  }
294  }
295 }
296 
297 void G4gsposp(G4String vname, G4int num, G4String vmoth, G4double x,
298  G4double y, G4double z, G4int irot, G4String vonly,
299  G4double pars[], G4int npar)
300 {
301  // find VTEs
302  G3VolTableEntry* vte = G3Vol.GetVTE(vname);
303  G3VolTableEntry* mvte = G3Vol.GetVTE(vmoth);
304 
305  if (vte == 0) {
306  G4String err_message1 = "G4gsposp: '" + vname + "' has no VolTableEntry";
307  G4Exception("G4psposp()", "G3toG40021", FatalException, err_message1);
308  return;
309  }
310  if (mvte == 0) {
311  G4String err_message2 = "G4gsposp: '" + vmoth + "' has no VolTableEntry";
312  G4Exception("G4psposp()", "G3toG40022", FatalException, err_message2);
313  return;
314  }
315  else {
316  // a new vte clone copy is created for each mother (clone copy)
317  // and its parameters are derived from it if possible
318 
319  G4CreateCloneVTE(vte, mvte, pars, npar, num, x, y, z, irot, vonly);
320  }
321 }
static const double cm
Definition: G4SIunits.hh:118
G3G4DLL_API G4double Rpar[1000]
Definition: clparse.cc:67
G3Pos * GetG3PosCopy(G4int copy=0)
void UpdateVTE()
Definition: G3Division.cc:97
G3Division * GetDivision()
CLHEP::Hep3Vector G4ThreeVector
G3VolTableEntry * GetMasterClone()
G4double z
Definition: TRTMaterials.hh:39
Definition: G3Pos.hh:43
void G4CloneDaughters(G3VolTableEntry *vte, G3VolTableEntry *vteClone)
Definition: G4gsposp.cc:127
G4String name
Definition: TRTMaterials.hh:40
void G4ProcessDaughters(G3VolTableEntry *vte)
Definition: G4gsposp.cc:66
void SetDivision(G3Division *division)
G4String GetShape()
G4double * GetRpar()
G4int NPCopies()
void G3fillParams(G4String *tokens, const char *ptypes)
Definition: clparse.cc:219
G3VolTableEntry * GetClone(G4int i)
int G4int
Definition: G4Types.hh:78
G3VolTableEntry * GetVTE(const G4String &Vname)
Definition: G3VolTable.cc:54
G4int GetNoClones()
void SetName(G4String name)
G3VolTableEntry * GetDaughter(G4int i)
G4int GetNoDaughters()
G4int GetNpar()
void PG4gsposp(G4String *tokens)
Definition: G4gsposp.cc:42
bool G4bool
Definition: G4Types.hh:79
G3G4DLL_API G4String Spar[1000]
Definition: clparse.cc:68
void SetNRpar(G4int npar, G4double *Rpar)
void SetHasNegPars(G4bool hasNegPars)
void SetSolid(G4VSolid *solid)
G4int GetNmed()
G4VSolid * G3toG4MakeSolid(const G4String &vname, const G4String &shape, const G4double *Rpar, const G4int npar, G4bool &NegVolPars, G4bool &Deferred, G4bool *OKAxis)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G3G4DLL_API G4int Ipar[1000]
Definition: clparse.cc:66
void AddG3Pos(G3Pos *aG3Pos)
G4bool G3NegVolPars(G4double pars[], G4int *nparpt, G3VolTableEntry *vte, G3VolTableEntry *mvte, const char routine[])
void AddMother(G3VolTableEntry *aDaughter)
G4String & append(const G4String &)
G4String GetName()
const G4double x[NPOINTSGL]
G4bool HasNegPars()
void AddClone(G3VolTableEntry *aDaughter)
G3G4DLL_API char gSeparator
#define G4endl
Definition: G4ios.hh:61
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
#define PTgsposp
Definition: G3toG4.hh:54
G3VolTableEntry * PutVTE(G3VolTableEntry *aVTE)
Definition: G3VolTable.cc:76
double G4double
Definition: G4Types.hh:76
G3G4DLL_API G3VolTable G3Vol
Definition: clparse.cc:54
void AddDaughter(G3VolTableEntry *aDaughter)
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:297
G4GLOB_DLL std::ostream G4cerr