3 #include "G4GeometryManager.hh" 4 #include "G4LogicalVolumeStore.hh" 5 #include "G4LogicalVolume.hh" 6 #include "G4PhysicalVolumeStore.hh" 7 #include "G4ProductionCuts.hh" 8 #include "G4PVPlacement.hh" 9 #include "G4RunManager.hh" 10 #include "G4SolidStore.hh" 11 #include "G4VisAttributes.hh" 12 #include "G4SDManager.hh" 13 #include "G4OpBoundaryProcess.hh" 14 #include "G4RegionStore.hh" 37 string hd_msg = gemcOpt.optMap[
"LOG_MSG"].args +
" >> Construction:";
38 double VERB = gemcOpt.optMap[
"G4P_VERBOSITY"].arg ;
39 string catch_v = gemcOpt.optMap[
"CATCH"].args;
40 string hall_mat = gemcOpt.optMap[
"HALL_MATERIAL"].args;
41 string hall_field = gemcOpt.optMap[
"HALL_FIELD"].args;
44 G4GeometryManager::GetInstance()->OpenGeometry();
45 G4PhysicalVolumeStore::GetInstance()->Clean();
46 G4LogicalVolumeStore::GetInstance()->Clean();
47 G4SolidStore::GetInstance()->Clean();
51 (*hallMap)[
"root"].create_solid(gemcOpt, hallMap);
52 (*hallMap)[
"root"].create_logical_volume(mats, gemcOpt);
53 (*hallMap)[
"root"].create_physical_volumes(gemcOpt, NULL);
54 hasMagfield((*hallMap)[
"root"]);
56 if(VERB > 3 || catch_v ==
"root") cout << hd_msg <<
" " << (*hallMap)[
"root"] ;
59 cout << hd_msg <<
" Building Detector from Geometry STL Map..." << endl;
65 if(VERB > 2) cout << hd_msg <<
" Mapping Physical Detector..." << endl << endl;
67 for(map<string, detector>::iterator i = hallMap->begin(); i!=hallMap->end(); i++)
69 if(VERB > 3) cout << hd_msg <<
" Scanning Detector " << i->first <<
" - existance: " << i->second.exist << endl;
72 detector mother = findDetector(i->second.mother);
74 while(mother.
name !=
"akasha" && mother.
name !=
"notfound")
78 if(VERB > 2) cout << hd_msg <<
"\t" << i->second.mother <<
" is not activated. Its child " << i->second.name
79 <<
" will be disactivated as well." << endl;
82 mother = findDetector(mother.
mother);
84 if(i->first !=
"root") i->second.scanned = 0;
87 if(i->second.type.find(
"ReplicaOf:") != string::npos)
90 string operands(i->second.type, 10, i->second.type.size());
95 replicants.insert(original);
104 vector<string> relatives;
107 vector<string> regions;
109 for( map<string, detector>::iterator i = hallMap->begin(); i!=hallMap->end(); i++)
112 if(i->second.exist == 0)
continue;
116 if(i->first !=
"root") relatives.push_back(i->second.name);
118 while(relatives.size() > 0)
120 detector kid = findDetector(relatives.back());
126 regions.push_back(kid.
name);
130 if(mom.name !=
"akasha" && mom.name ==
"notfound")
132 cout << hd_msg <<
" Mom was not found for <" << relatives.back() <<
">. " 133 <<
" We have a No Child Left Behind policy. Exiting. " << endl << endl;
138 if(VERB > 3 || kid.
name.find(catch_v) != string::npos)
140 for(
unsigned int ir=0; ir<relatives.size()-1; ir++) cout <<
"\t";
141 cout << hd_msg <<
" Checking " << kid.
name <<
", child of " << mom.name
142 <<
", for a living ancestor. " 143 <<
" This Geneaology Depth is " << relatives.size() <<
"." << endl;
147 if(kid.
scanned == 0 && mom.scanned == 1)
149 if(VERB > 3 || kid.
name.find(catch_v) != string::npos)
151 for(
unsigned int ir=0; ir<relatives.size()-1; ir++) cout <<
"\t";
152 cout << hd_msg <<
" Found: " << kid.
name 153 <<
" is not built yet but its mommie " << mom.name <<
" is." 154 <<
" Building " << kid.
name <<
" of type: " << kid.
type <<
"..." << endl;
158 if(kid.
type.find(
"CopyOf") == 0)
162 string operands(kid.
type, 6, kid.
type.size());
167 detector dorig = findDetector(original);
172 relatives.push_back(original);
173 if(VERB > 3 || kid.
name.find(catch_v) != string::npos)
175 for(
unsigned int ir=0; ir<relatives.size()-1; ir++) cout <<
"\t";
176 cout << hd_msg << kid.
name <<
" is copied volume. " 177 <<
" Must build: " << original <<
" first " << endl;
189 if(kid.
type.find(
"ReplicaOf:") == 0)
193 string operands(kid.
type, 10, kid.
type.size());
198 detector dorig = findDetector(original);
205 if(VERB > 3 || kid.
name.find(catch_v) != string::npos)
207 for(
unsigned int ir=0; ir<relatives.size()-1; ir++) cout <<
"\t";
208 cout << hd_msg << kid.
name <<
" is a replica volume of " << original
209 <<
". Must build: " << original <<
" first " << endl;
223 else if(kid.
type.find(
"Operation:") == 0)
226 if(kid.
type.find(
"Operation:~") == 0 || kid.
type.find(
"Operation:@") == 0 ) sstart = 11;
228 string operation(kid.
type, sstart, kid.
type.size());
230 string firstop = operands[0];
231 string secondop = operands[1];
235 detector dsecondop = findDetector(secondop);
238 relatives.push_back(secondop);
239 if(VERB > 3 || kid.
name.find(catch_v) != string::npos)
241 for(
unsigned int ir=0; ir<relatives.size()-1; ir++) cout <<
"\t";
242 cout << hd_msg << kid.
name <<
" is the result of an operation. " 243 <<
" Must build: " << secondop <<
" first " << endl;
246 detector dfirstop = findDetector(firstop);
249 relatives.push_back(firstop);
250 if(VERB > 3 || kid.
name.find(catch_v) != string::npos)
252 for(
unsigned int ir=0; ir<relatives.size()-1; ir++) cout <<
"\t";
253 cout << hd_msg << kid.
name <<
" is the result of an operation. " 254 <<
" Must build: " << firstop <<
" first " << endl;
274 if(kid.
scanned == 0 && mom.scanned == 0)
276 relatives.push_back(kid.
mother);
280 if(kid.
scanned == 1 && relatives.size())
282 if(VERB > 3 || kid.
name.find(catch_v) != string::npos)
283 cout << hd_msg <<
" " << kid <<
" is built." << endl << endl;
285 relatives.pop_back();
296 regions.push_back(
"root");
297 assignRegions(regions);
300 return (*hallMap)[
"root"].GetPhysical();
303 #include "G4UserLimits.hh" 307 string hd_msg = gemcOpt.optMap[
"LOG_MSG"].args +
" Sensitivity: >> ";
308 double VERB = gemcOpt.optMap[
"HIT_VERBOSITY"].arg ;
309 string catch_v = gemcOpt.optMap[
"CATCH"].args;
313 if(sensi !=
"no" && sensi.find(
"mirror:") == string::npos)
315 G4SDManager* SDman = G4SDManager::GetSDMpointer();
316 if (!SDman)
throw "Can't get G4SDManager";
318 if(VERB > 5 || detect.
name.find(catch_v) != string::npos)
319 cout << hd_msg <<
" " << detect.
name <<
" has assigned sensitivity: " << sensi << endl;
322 map<string, sensitiveDetector*>::iterator itr = SeDe_Map.find(sensi);
324 if(itr == SeDe_Map.end())
326 if(VERB > 3 || detect.
name.find(catch_v) != string::npos)
327 cout << endl << hd_msg <<
" Sensitive detector <" << sensi
328 <<
"> doesn't exist yet. Adding <" << sensi <<
">. " << endl;
334 SeDe_Map[sensi]->hallMap = hallMap;
336 SDman->AddNewDetector( SeDe_Map[sensi]);
341 detect.
SetUserLimits(
new G4UserLimits(SeDe_Map[sensi]->SDID.maxStep, SeDe_Map[sensi]->SDID.maxStep));
348 string hd_msg = gemcOpt.optMap[
"LOG_MSG"].args +
" Magnetic Field: >> ";
349 double verbosity = gemcOpt.optMap[
"FIELD_VERBOSITY"].arg ;
350 string catch_v = gemcOpt.optMap[
"CATCH"].args;
351 string field = gemcOpt.optMap[
"NO_FIELD"].args;
353 if(field ==
"all" || detect.
name.find(field) != string::npos)
360 map<string, gfield>::iterator itr = fieldsMap->find(magf);
362 if(itr == fieldsMap->end())
364 cout << hd_msg <<
" Electro-Magnetic Field <" << magf
365 <<
"> is not defined. Exiting." << endl;
369 activeFields.insert(magf);
372 if(verbosity > 1 || detect.
name.find(catch_v) != string::npos)
373 cout << hd_msg <<
" Field <" << magf <<
"> is built and assigned to " << detect.
name <<
"." << endl;
380 cout <<
"Updating geometry... " << endl;
381 G4RunManager::GetRunManager()->GeometryHasBeenModified();
384 detector MDetectorConstruction::findDetector(
string name)
386 map<string, detector>::iterator it = hallMap->find(name);
387 if(it != hallMap->end())
391 notfound.
name =
"notfound";
396 void MDetectorConstruction::buildDetector(
string name)
401 if(kid.
name !=
"notfound" || mom.
name !=
"notfound")
405 if(kid.
type.find(
"ReplicaOf:") == 0)
409 string operands(kid.
type, 10, kid.
type.size());
414 detector rep = findDetector(repName);
416 if(rep.
name !=
"notfound" )
419 (*hallMap)[kid.
name].create_replicas(gemcOpt, mom.
GetLogical(), rep);
423 cout <<
" Attention: " << kid.
name <<
" not found. " << endl;
428 (*hallMap)[kid.
name].create_solid(gemcOpt, hallMap);
431 if((*hallMap)[kid.
name].create_logical_volume(mats, gemcOpt))
435 if(replicants.find(kid.
name) == replicants.end())
436 (*hallMap)[kid.
name].create_physical_volumes(gemcOpt, mom.
GetLogical());
439 isSensitive((*hallMap)[kid.
name]);
440 hasMagfield((*hallMap)[kid.
name]);
442 (*hallMap)[kid.
name].scanned = 1;
446 if(kid.
name ==
"notfound")
447 cout <<
" Attention: " << kid.
name <<
" not found. " << endl;
448 if(mom.
name ==
"notfound" )
449 cout <<
" Attention: " << mom.
name <<
" not found. " << endl;
455 string hd_msg = gemcOpt.optMap[
"LOG_MSG"].args +
" Mirrors: >> ";
456 double VERB = gemcOpt.optMap[
"MIRROR_VERBOSITY"].arg ;
457 string catch_v = gemcOpt.optMap[
"CATCH"].args;
459 vector<G4OpticalSurface*> mirrorSurfaces;
460 vector<G4MaterialPropertiesTable*> mirrorsMPT;
461 vector<G4LogicalBorderSurface*> mirrorLBorderSurf;
462 vector<G4LogicalSkinSurface*> mirrorLSkinSurf;
464 for( map<string, detector>::iterator it = hallMap->begin(); it != hallMap->end(); it++)
466 string name = it->first;
468 string mirrorString =
"no";
469 if(it->second.sensitivity.find(
"mirror:") != string::npos)
471 vector<string> mmirror =
get_strings(it->second.sensitivity);
472 if(mmirror.size() == 2)
473 mirrorString = mmirror[1];
476 if(mirrorString !=
"no")
478 if(VERB > 5 || name.find(catch_v) != string::npos)
479 cout << hd_msg <<
" " << name <<
" has assigned mirror: " << mirrorString << endl;
481 map<string, mirror*>::iterator itr = mirs->find(mirrorString);
484 if(itr != mirs->end())
486 if(VERB > 3 || name.find(catch_v) != string::npos)
487 cout << endl << hd_msg <<
" Mirror <" << mirrorString <<
"> found for " << name <<
"." << endl;
491 string borderv = itr->second->border;
492 string mirrorSurf =
"mirrorBorderSurface_for_" + name +
"_and_" + borderv;
494 if(!(*hallMap)[borderv].GetPhysical() && borderv !=
"SkinSurface")
496 cout << hd_msg <<
" !! Error: border volume " << borderv <<
" is not found for volume " << name <<
". Exiting." << endl;
500 else if(borderv ==
"SkinSurface")
502 mirrorSurf =
"mirrorSkinSurface_for_" + name;
505 mirrorSurfaces.push_back(
new G4OpticalSurface(mirrorSurf));
511 string maptOptProps = itr->second->maptOptProps;
512 if( maptOptProps !=
"notDefined" && ( (*mats)[maptOptProps] )->GetMaterialPropertiesTable() )
514 mirrorsMPT.push_back( ( (*mats)[maptOptProps] )->GetMaterialPropertiesTable() );
518 mirrorsMPT.push_back(
new G4MaterialPropertiesTable());
520 vector<double> photonEnergy = itr->second->photonEnergy;
521 if(photonEnergy.size())
523 vector<double> indexOfRefraction = itr->second->indexOfRefraction;
524 vector<double> reflectivity = itr->second->reflectivity;
525 vector<double> efficiency = itr->second->efficiency;
526 vector<double> specularlobe = itr->second->specularlobe;
527 vector<double> specularspike = itr->second->specularspike;
528 vector<double> backscatter = itr->second->backscatter;
532 unsigned peneSize = photonEnergy.size();
534 G4double pene[peneSize];
535 G4double var[peneSize];
537 for(
unsigned i=0; i<peneSize; i++)
538 pene[i] = photonEnergy[i];
540 if(indexOfRefraction.size())
542 for(
unsigned i=0; i<peneSize; i++) var[i] = indexOfRefraction[i];
543 mirrorsMPT.back()->AddProperty(
"RINDEX", pene, var, peneSize);
545 if(reflectivity.size())
547 for(
unsigned i=0; i<peneSize; i++) var[i] = reflectivity[i];
548 mirrorsMPT.back()->AddProperty(
"REFLECTIVITY", pene, var, peneSize);
550 if(efficiency.size())
552 for(
unsigned i=0; i<peneSize; i++) var[i] = efficiency[i];
553 mirrorsMPT.back()->AddProperty(
"EFFICIENCY", pene, var, peneSize);
555 if(specularlobe.size())
557 for(
unsigned i=0; i<peneSize; i++)var[i] = specularlobe[i];
558 mirrorsMPT.back()->AddProperty(
"SPECULARLOBECONSTANT", pene, var, peneSize);
560 if(specularspike.size())
562 for(
unsigned i=0; i<peneSize; i++)var[i] = specularspike[i];
563 mirrorsMPT.back()->AddProperty(
"SPECULARSPIKECONSTANT", pene, var, peneSize);
565 if(backscatter.size())
567 for(
unsigned i=0; i<peneSize; i++)var[i] = backscatter[i];
568 mirrorsMPT.back()->AddProperty(
"BACKSCATTERCONSTANT", pene, var, peneSize);
573 cout <<
" !! Fatal error: no optical property material, and no optical properties for mirror " 574 << itr->second->name << endl;
578 mirrorSurfaces.back()->SetMaterialPropertiesTable(mirrorsMPT.back());
581 string surfaceType = itr->second->type;
582 if(surfaceType ==
"dielectric_metal") mirrorSurfaces.back()->SetType(dielectric_metal);
583 if(surfaceType ==
"dielectric_dielectric") mirrorSurfaces.back()->SetType(dielectric_dielectric);
584 if(surfaceType ==
"dielectric_LUT") mirrorSurfaces.back()->SetType(dielectric_LUT);
587 string surfaceFinish = itr->second->finish;
588 if(surfaceFinish ==
"polished") mirrorSurfaces.back()->SetFinish(polished);
589 if(surfaceFinish ==
"polishedfrontpainted") mirrorSurfaces.back()->SetFinish(polishedfrontpainted);
590 if(surfaceFinish ==
"polishedbackpainted") mirrorSurfaces.back()->SetFinish(polishedbackpainted);
592 if(surfaceFinish ==
"ground") mirrorSurfaces.back()->SetFinish(ground);
593 if(surfaceFinish ==
"groundfrontpainted") mirrorSurfaces.back()->SetFinish(groundfrontpainted);
594 if(surfaceFinish ==
"groundbackpainted") mirrorSurfaces.back()->SetFinish(groundbackpainted);
597 if(surfaceFinish ==
"polishedlumirrorair") mirrorSurfaces.back()->SetFinish(polishedlumirrorair);
598 if(surfaceFinish ==
"polishedlumirrorglue") mirrorSurfaces.back()->SetFinish(polishedlumirrorglue);
602 string surfaceModel = itr->second->model;
603 if(surfaceModel ==
"glisur") mirrorSurfaces.back()->SetModel(glisur);
604 if(surfaceModel ==
"unified") mirrorSurfaces.back()->SetModel(unified);
605 if(surfaceModel ==
"LUT") mirrorSurfaces.back()->SetModel(LUT);
608 if(borderv==
"SkinSurface")
610 mirrorLSkinSurf.push_back(
new G4LogicalSkinSurface(name,
611 (*hallMap)[name].GetLogical(), mirrorSurfaces.back()));
616 mirrorLBorderSurf.push_back(
new G4LogicalBorderSurface(name,
617 (*hallMap)[borderv].GetPhysical(),
618 (*hallMap)[name].GetPhysical(), mirrorSurfaces.back()));
622 if(VERB > 3 || name.find(catch_v) != string::npos)
624 cout << hd_msg <<
" " << name <<
" is a mirror:" << endl;
625 cout <<
" > Border Volume: " << borderv << endl;
626 cout <<
" > Surface Type: " << surfaceType << endl;
627 cout <<
" > Finish: " << surfaceFinish << endl;
628 cout <<
" > Model: " << surfaceModel << endl;
631 mirrorsMPT.back()->DumpTable();
636 cout <<
" !! Fatal error: mirror <" << mirrorString <<
"> not found for " << it->second.name <<
"." << endl;
646 double VERB = gemcOpt.optMap[
"HIT_VERBOSITY"].arg ;
648 for(
unsigned int i=0; i<volumes.size(); i++)
651 for(map<string, sensitiveDetector*>::iterator itr = SeDe_Map.begin(); itr != SeDe_Map.end(); itr++)
653 detector regionDet = findDetector(volumes[i]);
655 if(regionDet.
system == itr->second->SDID.system)
659 string regionName = volumes[i] +
"_" +
get_info(regionDet.
system,
"/").back();
662 map<string, G4Region*>::iterator itrr = SeRe_Map.find(regionName);
665 if(itrr == SeRe_Map.end())
669 SeRe_Map[regionName] =
new G4Region(regionName);
670 SeRe_Map[regionName]->AddRootLogicalVolume(regionDet.
GetLogical());
672 SePC_Map[regionName] =
new G4ProductionCuts;
673 SePC_Map[regionName] ->SetProductionCut(itr->second->SDID.prodThreshold);
676 cout <<
" Region " << regionName <<
" activated for volume " << regionDet.
name <<
" with range: " << itr->second->SDID.prodThreshold << endl;
678 SeRe_Map[regionName]->SetProductionCuts(SePC_Map[regionName]);
map< string, detector > buildDetector(map< string, detectorFactoryInMap > detectorFactoryMap, goptions go, runConditions rc)
G4VPhysicalVolume * Construct()
vector< string > get_strings(string input)
returns a vector of strings from a stringstream, space is delimiter
G4LogicalVolume * GetLogical()
Returns Logical Volume pointer.
string sensitivity
Defines the Sensitive Detector. possible choices: "no" "hits collection name".
string mother
Mother Volume name.
void AssignMFM(G4FieldManager *MFM)
Assigns Magnetic Field Manager to LogicV.
int run
run number that generated the detector
vector< string > get_info(string input, string chars)
get information from strings such as "5*GeV, 2*deg, 10*deg", parses out strings in second argument ...
void hasMagfield(detector)
map< string, mirror * > buildMirrors(map< string, mirrorFactory > mirrorFactoryMap, goptions go, runConditions rc)
string system
detector system
string replaceCharWithChars(string input, string x, string y)
string factory
factory that generated the detector
string name
Name of the volume. Since this is the key of the STL map, it has to be unique.
string material
Volume Material name.
void SetUserLimits(G4UserLimits *L)
void isSensitive(detector)
string magfield
Magnetic Field. The string "no" means that the field is inherited from the mother volume...
int exist
detector ON/OFF switch
string type
solid type. This follows the GEANT4 definitions
string TrimSpaces(string in)
Removes leading and trailing spaces.
int scanned
for use during construction
string variation
variation that generated the detector
MDetectorConstruction(goptions Opts)
void setSensitivity(G4VSensitiveDetector *SD)
Assign the sensitive detector to the Logical Volume.