18 mySettings = settings;
19 G4cout <<
"detector constructor" << G4endl;
28 con = mysql_init(
NULL);
32 G4cout <<
"begin Construct routine..." << endl;
74 G4String name, symbol;
76 mysql_query(con,
"SELECT eID, eName, symbol, z, n FROM Elements");
77 if (mysql_errno(con) != 0)
78 cout << mysql_error(con) << endl;
79 res = mysql_store_result(con);
80 int nElement = mysql_num_rows(res);
83 while ((row = mysql_fetch_row(res)))
93 elementVec[id] =
new G4Element(name, symbol, z, a);
96 mysql_free_result(res);
100 vector<double> perAbundance;
101 perAbundance.resize(11);
102 vector<G4String> eleName;
112 mysql_query(con,
"SELECT mID, mName, density, numElements, eID1, eID2, eID3, eID4, eID5, "
113 "eID6, eID7, eID8, eID9, eID10, elementPercent1, elementPercent2, "
114 "elementPercent3, elementPercent4, elementPercent5, elementPercent6, "
115 "elementPercent7, elementPercent8, elementPercent9, elementPercent10 FROM Materials");
116 if (mysql_errno(con) != 0)
117 cout << mysql_error(con) << endl;
118 res = mysql_store_result(con);
119 int nMaterial = mysql_num_rows(res);
122 while ((row = mysql_fetch_row(res)))
128 density = atof(row[2])*g/(cm*cm*cm);
129 numEle = atoi(row[3]);
130 for (
int i = 1; i <= numEle; i++)
132 eID[i] = atoi(row[3+i]);
133 perAbundance[i] = atof(row[13+i]);
136 materialVec[id] =
new G4Material(name, density, numEle);
138 for (
int j = 1; j <= numEle; j++)
142 mysql_free_result(res);
144 double xLength, yLength, zLength, radiusMin, radiusMax;
155 mysql_query(con,
"SELECT sID, sName, xLength, yLength, zLength FROM SolidBoxes");
156 if (mysql_errno(con) != 0)
157 cout << mysql_error(con) << endl;
158 res = mysql_store_result(con);
160 while ((row = mysql_fetch_row(res)))
167 xLength = atof(row[2])*cm;
168 yLength = atof(row[3])*cm;
169 zLength = atof(row[4])*cm;
171 solidVec[id] =
new G4Box(name, xLength/2.0, yLength/2.0, zLength/2.0);
173 mysql_free_result(res);
175 mysql_query(con,
"SELECT sID, sName, length, radiusMin, radiusMax FROM SolidTubes");
176 if (mysql_errno(con) != 0)
177 cout << mysql_error(con) << endl;
178 res = mysql_store_result(con);
180 while ((row = mysql_fetch_row(res)))
187 zLength = atof(row[2])*cm;
188 radiusMin = atof(row[3])*cm;
189 radiusMax = atof(row[4])*cm;
191 solidVec[id] =
new G4Tubs(name, radiusMin, radiusMax, zLength/2.0, 0, 360*deg);
193 mysql_free_result(res);
195 mysql_query(con,
"SELECT sID, sName, shellID, holeID, rotX, rotY, rotZ, posX, posY, posZ FROM SubtractionSolids");
196 if (mysql_errno(con) != 0)
197 cout << mysql_error(con) << endl;
198 res = mysql_store_result(con);
200 while ((row = mysql_fetch_row(res)))
207 shellID = atoi(row[2]);
208 holeID = atoi(row[3]);
211 ra.rotateX(atof(row[4]));
212 ra.rotateY(atof(row[5]));
213 ra.rotateZ(atof(row[6]));
215 ta.setX(atof(row[7]));
216 ta.setY(atof(row[8]));
217 ta.setZ(atof(row[9]));
219 rata = G4Transform3D(ra,ta);
223 mysql_free_result(res);
227 mysql_query(con,
"SELECT lvID, lvName, sID, mID FROM LogicalVolumes");
228 if (mysql_errno(con) != 0)
229 cout << mysql_error(con) << endl;
230 res = mysql_store_result(con);
231 int nLogicalVolume = mysql_num_rows(res);
234 while ((row = mysql_fetch_row(res)))
244 mysql_free_result(res);
246 int logicalID, motherID;
252 for (
int i = 0; i<(int)copy.size(); i++)
255 mysql_query(con,
"SELECT MAX(depth) FROM PhysicalVolumes");
256 if (mysql_errno(con) != 0)
257 cout << mysql_error(con) << endl;
258 res = mysql_store_result(con);
259 row = mysql_fetch_row(res);
260 int depth = atoi(row[0]);
264 mysql_query(con,
"SELECT lvID FROM PhysicalVolumes WHERE depth = 0");
265 if (mysql_errno(con) != 0)
266 cout << mysql_error(con) << endl;
267 res = mysql_store_result(con);
269 if ((row = mysql_fetch_row(res)))
271 logicalID = atoi(row[0]);
272 physiWorld =
new G4PVPlacement(0, G4ThreeVector(),
"World",
logicalVolumeVec[logicalID], 0,
false, 0);
275 mysql_free_result(res);
279 for (
int i = 1; i <= depth; i++)
281 sprintf(qry,
"SELECT pvID, pvName, lvID, motherID, xRel, yRel, zRel, rotX, rotY, rotZ "
282 "FROM PhysicalVolumes WHERE depth = %i", i);
283 mysql_query(con, qry);
284 if (mysql_errno(con) != 0)
285 cout << mysql_error(con) << endl;
286 res = mysql_store_result(con);
288 while ((row = mysql_fetch_row(res)))
292 logicalID = atoi(row[2]);
293 motherID = atoi(row[3]);
294 pos(0) = atof(row[4])*cm;
295 pos(1) = atof(row[5])*cm;
296 pos(2) = atof(row[6])*cm;
308 mysql_free_result(res);
311 mysql_query(con,
"SELECT * FROM ConstantsDerived");
312 if (mysql_errno(con) != 0)
313 cout << mysql_error(con) << endl;
314 res = mysql_store_result(con);
317 while ((row = mysql_fetch_row(res)))
319 sprintf(constant, row[0]);
320 if (!strcmp(constant,
"targetLength"))
322 else if (!strcmp(constant,
"targetCenter"))
324 else if (!strcmp(constant,
"targetRadius"))
326 else if (!strcmp(constant,
"fmagLength"))
328 else if (!strcmp(constant,
"fmagCenter"))
330 else if (!strcmp(constant,
"targetMaterialID"))
332 else if (!strcmp(constant,
"targetVolumeID"))
334 else if (!strcmp(constant,
"fmagMaterialID"))
336 else if (!strcmp(constant,
"fmagVolumeID"))
339 mysql_free_result(res);
345 G4cout <<
"Initializing sensitive detector manager...\n";
346 G4SDManager* SDman = G4SDManager::GetSDMpointer();
347 G4String sta_SDname =
"E906/StationSD";
349 SDman->AddNewDetector(
staSD);
350 G4cout <<
"Finished initializing sensitive detector manager!\n";
353 G4cout <<
"Setting attributes...\n";
354 AssignAttributes(physiWorld);
355 G4cout <<
"Finished setting attributes!\n";
360 G4cout <<
"Setting up physical magnetic field..." << G4endl;
363 G4FieldManager* fieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
364 fieldMgr->SetDetectorField(myField);
366 G4Mag_UsualEqRhs* fEquation =
new G4Mag_UsualEqRhs(myField);
367 G4MagIntegratorStepper* pStepper =
new G4ClassicalRK4(fEquation);
368 G4ChordFinder* pChordFinder =
new G4ChordFinder(myField,0.01*mm, pStepper);
369 fieldMgr->SetChordFinder(pChordFinder);
371 G4cout <<
"******************" << fieldMgr->DoesFieldExist() <<
"*******************" << G4endl;
375 G4cout <<
"here comes the material tables" << endl;
376 G4cout << *(G4Element::GetElementTable()) << endl;
377 G4cout << *(G4Material::GetMaterialTable()) << endl;
378 G4cout <<
"Geometry complete!!!" << G4endl;
383 int DetectorConstruction::AssignAttributes(G4VPhysicalVolume* mother_phy)
386 G4VisAttributes* targetVisAtt =
new G4VisAttributes(G4Colour(0.8,0.8,0.8));
387 targetVisAtt->SetForceSolid(
true);
388 G4VisAttributes* polyVisAtt =
new G4VisAttributes(G4Colour(0.7,0.0,0.3,0.3));
389 G4VisAttributes* magVisAtt =
new G4VisAttributes(G4Colour(0.0,0.6,0.0,0.2));
390 G4VisAttributes* coilVisAtt =
new G4VisAttributes(G4Colour(0.65,0.83,0.95,0.60));
391 G4VisAttributes* concreteVisAtt =
new G4VisAttributes(G4Colour(0.45,0.44,0.35,0.8));
392 G4VisAttributes* detVisAtt =
new G4VisAttributes(G4Colour(0.3,0.5,1.0));
393 G4VisAttributes* absWallVisAtt =
new G4VisAttributes(G4Colour(0.9,0.88,0.7));
394 absWallVisAtt->SetForceSolid(
true);
398 G4LogicalVolume *mother_vol = mother_phy->GetLogicalVolume();
399 G4String pName = mother_phy->GetName();
400 G4String lName = mother_vol->GetName();
401 G4int nDaughters = mother_vol->GetNoDaughters();
402 G4Material* mat = mother_vol->GetMaterial();
403 G4String matName = mat->GetName();
406 bool overDet = lName.contains(
"osta");
407 bool det = ( pName.contains(
"H1") || pName.contains(
"H2") || pName.contains(
"H3") || pName.contains(
"H4")
408 || pName.contains(
"C1") || pName.contains(
"C2") || pName.contains(
"C3")
409 || pName.contains(
"P1") || pName.contains(
"P2"));
412 mother_vol->SetSensitiveDetector(
staSD);
414 mother_vol->SetSensitiveDetector(
staSD);
421 mother_vol->SetVisAttributes(G4VisAttributes::Invisible);
423 mother_vol->SetVisAttributes(detVisAtt);
424 else if (matName ==
"Air" )
425 mother_vol->SetVisAttributes(G4VisAttributes::Invisible);
426 else if (lName.contains(
"absorber"))
427 mother_vol->SetVisAttributes( absWallVisAtt);
428 else if (lName.contains(
"targ"))
429 mother_vol->SetVisAttributes(targetVisAtt);
430 else if (lName.contains(
"poly"))
431 mother_vol->SetVisAttributes( polyVisAtt);
432 else if (lName.contains(
"block"))
433 mother_vol->SetVisAttributes(concreteVisAtt);
434 else if (lName.contains(
"coil"))
435 mother_vol->SetVisAttributes(coilVisAtt);
436 else if (lName.contains(
"concrete"))
437 mother_vol->SetVisAttributes(concreteVisAtt);
438 else if (lName.contains(
"body"))
439 mother_vol->SetVisAttributes(magVisAtt);
441 mother_vol->SetVisAttributes(G4VisAttributes::Invisible);
445 mother_vol->SetVisAttributes(G4VisAttributes::Invisible);
446 for(
int i=0; i < nDaughters; i++)
447 exit += AssignAttributes( mother_vol->GetDaughter(i));
459 G4NistManager* man = G4NistManager::Instance();
460 G4Material* targMat = man->FindOrBuildMaterial(material);
465 cout << material <<
" not found in material database." << endl;
467 G4RunManager::GetRunManager()->GeometryHasBeenModified();
474 G4NistManager* man = G4NistManager::Instance();
475 G4Material* air = man->FindOrBuildMaterial(
"Air");
482 G4RunManager::GetRunManager()->GeometryHasBeenModified();
490 G4cout <<
"Setting up physical magnetic field..." << G4endl;
492 G4FieldManager* fieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
493 fieldMgr->SetDetectorField(myField);
495 G4Mag_UsualEqRhs* fEquation =
new G4Mag_UsualEqRhs(myField);
496 G4MagIntegratorStepper* pStepper =
new G4ClassicalRK4(fEquation);
497 G4ChordFinder* pChordFinder =
new G4ChordFinder(myField,1.e-1*mm, pStepper);
499 fieldMgr->SetChordFinder(pChordFinder);
500 G4cout <<
"******************" << fieldMgr->DoesFieldExist() <<
"*******************" << G4endl;
502 G4RunManager::GetRunManager()->GeometryHasBeenModified();
vector< G4RotationMatrix * > rotationMatrixVec
G4LogicalVolume * magnetVolume
G4LogicalVolume * targetVolume
G4VPhysicalVolume * Construct()
vector< G4LogicalVolume * > logicalVolumeVec
vector< G4Material * > materialVec
vector< G4Element * > elementVec
DetectorConstruction(Settings *)
vector< G4VSolid * > solidVec
G4Material * defaultMagnetMat
void SetTargetMaterial(G4String)