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