3 // modified 17/06/02: by I. Gonzalez. STL migration
7 #include "FGeometryInit.hh"
8 #include "FluggNavigator.hh"
9 #include "WrapUtils.hh"
10 #include "FlukaMaterial.hh"
11 #include "FlukaCompound.hh"
13 FGeometryInit * FGeometryInit::flagInstance=0;
15 FGeometryInit* FGeometryInit::GetInstance() {
16 #ifdef G4GEOMETRY_DEBUG
17 G4cout << "==> Flugg::FGeometryInit::GetInstance(), instance="
18 << flagInstance << G4endl;
21 flagInstance = new FGeometryInit();
23 #ifdef G4GEOMETRY_DEBUG
24 G4cout << "<== Flugg::FGeometryInit::GetInstance(), instance="
25 << flagInstance << G4endl;
31 FGeometryInit::FGeometryInit():
34 fTransportationManager(G4TransportationManager::GetTransportationManager()),
44 #ifdef G4GEOMETRY_DEBUG
45 G4cout << "==> Flugg FGeometryInit::FGeometryInit()" << G4endl;
46 G4cout << "\t+ Changing the G4Navigator for FluggNavigator..." << G4endl;
48 G4Navigator* actualnav = fTransportationManager->GetNavigatorForTracking();
50 FluggNavigator* newnav = new FluggNavigator();
51 fTransportationManager->SetNavigatorForTracking(newnav);
54 G4cerr << "ERROR: Could not find the actual G4Navigator" << G4endl;
59 #ifdef G4GEOMETRY_DEBUG
60 G4cout << "<== Flugg FGeometryInit::FGeometryInit()" << G4endl;
66 FGeometryInit::~FGeometryInit() {
67 G4cout << "==> Flugg FGeometryInit::~FGeometryInit()" << G4endl;
69 ptrGeoMan->OpenGeometry();
70 if (fTransportationManager)
71 delete fTransportationManager;
73 delete[] ptrJrLtGeant;
76 //keep ATTENTION: never delete a pointer twice!
77 G4cout << "<== Flugg FGeometryInit::FGeometryInit()" << G4endl;
81 void FGeometryInit::closeGeometry() {
82 #ifdef G4GEOMETRY_DEBUG
83 G4cout << "==> Flugg FGeometryInit::closeGeometry()" << G4endl;
86 ptrGeoMan = G4GeometryManager::GetInstance();
88 ptrGeoMan->OpenGeometry();
90 //true argoment allows voxel construction; if false voxels are built
91 //only for replicated volumes
92 ptrGeoMan->CloseGeometry(true);
95 G4cerr << "ERROR in FLUGG: Could not get G4GeometryManager instance"
97 G4cerr << " in FGeometryInit::closeGeometry. Exiting!!!"
101 #ifdef G4GEOMETRY_DEBUG
102 G4cout << "<== Flugg FGeometryInit::closeGeometry()" << G4endl;
106 //*************************************************************************
108 void FGeometryInit::InitHistArray() {
109 #ifdef G4GEOMETRY_DEBUG
110 G4cout << "==> Flugg FGeometryInit::InitHistArray()" << G4endl;
112 ptrArray = new G4int[1000000];
113 for(G4int i=0;i<1000000;i++)
115 #ifdef G4GEOMETRY_DEBUG
116 G4cout << "<== Flugg FGeometryInit::InitHistArray()" << G4endl;
122 //*************************************************************************
123 //jrLtGeant stores all crossed lattice volume histories.
125 void FGeometryInit::InitJrLtGeantArray() {
126 #ifdef G4GEOMETRY_DEBUG
127 G4cout << "==> Flugg FGeometryInit::InitJrLtGeantArray()" << G4endl;
128 G4cout << "Initializing JrLtGeant array" << G4endl;
130 ptrJrLtGeant = new G4int[10000];
131 for(G4int x=0;x<10000;x++)
134 #ifdef G4GEOMETRY_DEBUG
135 G4cout << "<== Flugg FGeometryInit::InitJrLtGeantArray()" << G4endl;
140 void FGeometryInit::SetLttcFlagGeant(G4int newFlagLttc) {
141 #ifdef G4GEOMETRY_DEBUG
142 G4cout << "==> Flugg FGeometryInit::SetLttcFlagGeant()" << G4endl;
144 // Added by A.Solodkov
145 if (newFlagLttc >= 10000) {
146 G4cout << "Problems in FGeometryInit::SetLttcFlagGeant" << G4endl;
147 G4cout << "Index newFlagLttc=" << newFlagLttc << " is outside array bounds"
149 G4cout << "Better to stop immediately !" << G4endl;
152 flagLttcGeant = newFlagLttc;
153 #ifdef G4GEOMETRY_DEBUG
154 G4cout << "<== Flugg FGeometryInit::SetLttcFlagGeant()" << G4endl;
158 void FGeometryInit::PrintJrLtGeant() {
159 #ifdef G4GEOMETRY_DEBUG
160 //G4cout << "jrLtGeant:" << G4endl;
161 //for(G4int y=0;y<=flagLttcGeant;y++)
163 // G4cout << "jrLtGeant[" << y << "]=" << ptrJrLtGeant[y] << G4endl;
167 //**************************************************************************
169 void FGeometryInit::PrintHistories() {
171 #ifdef G4GEOMETRY_DEBUG
172 G4cout << "Touch hist:" << G4endl;
173 G4cout << *(ptrTouchHist->GetHistory()) << G4endl;
174 G4cout << "Tmp hist:" << G4endl;
175 G4cout << *(ptrTempNavHist->GetHistory()) << G4endl;
176 G4cout << "Old hist:" << G4endl;
177 G4cout << *(ptrOldNavHist->GetHistory()) << G4endl;
184 void FGeometryInit::InitHistories() {
185 #ifdef G4GEOMETRY_DEBUG
186 G4cout << "==> Flugg FGeometryInit::InitHistories()" << G4endl;
188 //init utility histories with navigator history
190 fTransportationManager->GetNavigatorForTracking()->CreateTouchableHistory();
192 fTransportationManager->GetNavigatorForTracking()->CreateTouchableHistory();
193 ptrOldNavHist = new G4TouchableHistory();
194 #ifdef G4GEOMETRY_DEBUG
195 G4cout << "<== Flugg FGeometryInit::InitHistories()" << G4endl;
199 void FGeometryInit::DeleteHistories() {
200 #ifdef G4GEOMETRY_DEBUG
201 G4cout << "==> Flugg FGeometryInit::DeleteHistories()" << G4endl;
205 delete ptrOldNavHist;
206 delete ptrTempNavHist;
208 #ifdef G4GEOMETRY_DEBUG
209 G4cout << "Deleting step-history objects at end of run!" << G4endl;
210 G4cout << "<== Flugg FGeometryInit::DeleteHistories()" << G4endl;
215 void FGeometryInit::UpdateHistories(const G4NavigationHistory * history,
217 #ifdef G4GEOMETRY_DEBUG
218 G4cout << "==> Flugg FGeometryInit::UpdateHistories()" << G4endl;
222 #ifdef G4GEOMETRY_DEBUG
223 G4cout << "...updating histories!" << G4endl;
226 G4VPhysicalVolume * pPhysVol = history->GetTopVolume();
230 //this is the case when a new history is given to the
231 //navigator and old history has to be resetted
232 //touchable history has not been updated jet, so:
234 ptrTouchHist->UpdateYourself(pPhysVol,history);
235 ptrTempNavHist->UpdateYourself(pPhysVol,history);
236 G4NavigationHistory * ptrOldNavHistNotConst =
237 const_cast<G4NavigationHistory * >(ptrOldNavHist->GetHistory());
238 ptrOldNavHistNotConst->Reset();
239 ptrOldNavHistNotConst->Clear();
245 //this is the case when a new history is given to the
246 //navigator but old history has to be kept (e.g. LOOKZ
247 //is call during an event);
248 //touchable history has not been updated jet, so:
250 ptrTouchHist->UpdateYourself(pPhysVol,history);
251 ptrTempNavHist->UpdateYourself(pPhysVol,history);
257 //this is the case when the touchable history has been
258 //updated by a LocateGlobalPointAndUpdateTouchable call
260 G4VPhysicalVolume * pPhysVolTemp = ptrTempNavHist->GetVolume();
261 ptrOldNavHist->UpdateYourself(pPhysVolTemp,
262 ptrTempNavHist->GetHistory());
264 ptrTempNavHist->UpdateYourself(pPhysVol,history);
270 G4cout <<" ERROR in updating step-histories!" << G4endl;
275 #ifdef G4GEOMETRY_DEBUG
276 G4cout << "<== Flugg FGeometryInit::UpdateHistories()" << G4endl;
280 //*****************************************************************************
282 void FGeometryInit::createFlukaMatFile() {
283 // last modification Sara Vanini 1/III/99
284 // NAMES OF ELEMENTS AND COMPOUNDS: the names must be written in upper case,
285 // according to the fluka standard. In addition,. they must be equal to the
286 // names of the fluka materials - see fluka manual - in order that the
287 // program load the right cross sections, and equal to the names included in
288 // the .pemf. Otherwise the user must define the LOW-MAT CARDS, and make his
289 // own .pemf, in order to get the right cross sections loaded in memory.
291 #ifdef G4GEOMETRY_DEBUG
292 G4cout << "==> Flugg FGeometryInit::createFlukaMatFile()" << G4endl;
293 G4cout << "================== FILEWR =================" << G4endl;
299 G4std::ofstream vos("Volumes_index.inp");
300 PrintRegionsMap(vos);
303 //Materials and compounds
304 BuildMaterialTables();
305 G4std::ofstream fos("flukaMat.inp");
306 PrintMaterialTables(fos);
308 PrintMagneticField(fos);
311 #ifdef G4GEOMETRY_DEBUG
312 G4cout << "<== Flugg FGeometryInit::createFlukaMatFile()" << G4endl;
316 ////////////////////////////////////////////////////////////////////////
318 void FGeometryInit::BuildRegionsMap() {
319 #ifdef G4GEOMETRY_DEBUG
320 G4cout << "==> Flugg FGeometryInit::BuildRegionsMap()" << G4endl;
323 //Find number of Volumes in physical volume store
324 G4PhysicalVolumeStore * pVolStore = G4PhysicalVolumeStore::GetInstance();
325 unsigned int numVol = pVolStore->size();
327 G4cout << "\t* G4PhysicalVolumeStore (" << pVolStore
328 << ") has " << numVol << " volumes. Iterating..."
331 for(unsigned int l=0; l < numVol; l++) {
332 //Get each of the physical volumes
333 G4VPhysicalVolume * physicalvolume = (*pVolStore)[l];
334 G4int iFlukaRegion = l+1;
335 fRegionVolumeMap[physicalvolume] = iFlukaRegion;
340 #ifdef G4GEOMETRY_DEBUG
341 G4cout << "==> Flugg FGeometryInit::BuildRegionsMap()" << G4endl;
345 void FGeometryInit::PrintRegionsMap(G4std::ostream& os) {
346 #ifdef G4GEOMETRY_DEBUG
347 G4cout << "==> Flugg FGeometryInit::PrintRegionsMap()" << G4endl;
351 PrintHeader(os, "GEANT4 VOLUMES");
353 //Iterate over all volumes in the map
354 for (RegionIterator i = fRegionVolumeMap.begin();
355 i != fRegionVolumeMap.end();
358 //Get info in the map
359 G4VPhysicalVolume* ptrVol = (*i).first;
360 int index = (*i).second;
362 //Print index and region name in some fixed format
363 os.setf(G4std::ios::left, G4std::ios::adjustfield);
364 os << setw10 << index;
365 os << G4std::setw(20) << ptrVol->GetName() << G4std::setw(20) << "";
367 //If volume is a replica... print some more stuff
368 if(ptrVol->IsReplicated()) {
372 G4double offset = -1;
373 G4bool consum = false;
374 ptrVol->GetReplicationData(axis, nRep, width, offset, consum);
375 os.setf(G4std::ios::left, G4std::ios::adjustfield);
376 os << setw10 << "Repetion Nb: " << G4std::setw(3) << nRep;
382 #ifdef G4GEOMETRY_DEBUG
383 G4cout << "<== Flugg FGeometryInit::PrintRegionsMap()" << G4endl;
387 ////////////////////////////////////////////////////////////////////////
389 void FGeometryInit::BuildMediaMap()
391 fRegionMediumMap = new int[fNRegions+1];
392 for (RegionIterator i = fRegionVolumeMap.begin();
393 i != fRegionVolumeMap.end();
395 //Get info in the map
396 G4VPhysicalVolume* ptrVol = (*i).first;
397 int region = (*i).second;
398 G4int imed = fMediumVolumeMap[ptrVol];
399 fRegionMediumMap[region] = imed;
400 printf("BuildMediaMap %s %d %d\n",(ptrVol->GetName()).data(), region, imed);
405 G4int FGeometryInit::GetMedium(int region) const
407 return fRegionMediumMap[region];
411 void FGeometryInit::SetMediumFromName(const char* volName, int medium, int volid)
415 strncpy(tmp, volName, 4);
419 for (RegionIterator i = fRegionVolumeMap.begin();
420 i != fRegionVolumeMap.end();
423 //Get info in the map
424 G4VPhysicalVolume* ptrVol = (*i).first;
425 strncpy(name4, (ptrVol->GetName()).data(), 4);
427 for (int j = 0; j < 4; j++) {
428 if (name4[j] == '\0') {
429 for (int k = j; k < 4; k++) {
435 if (! strncmp(name4, tmp, 4)) {
436 fMediumVolumeMap[ptrVol] = medium;
437 fVolIdVolumeMap[ptrVol] = volid;
444 ////////////////////////////////////////////////////////////////////////
446 void FGeometryInit::BuildMaterialTables() {
447 #ifdef G4GEOMETRY_DEBUG
448 G4cout << "==> Flugg FGeometryInit::BuildMaterialTables()" << G4endl;
451 //some terminal printout also
452 G4cout << "\t* Storing information..." << G4endl;
454 //The logic is the folloing:
455 //Get the Material Table and:
456 // 1) For materials with density <= 1.00e-10*g/cm3 assign vacuum
457 // 2) For each single element material build a material equivalent
459 // 3.a) Build materials for each not already known element
460 // 3.b) Build the compound out of them
462 //Get the Material Table and iterate
463 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
464 for (MatTableIterator i = matTable->begin(); i != matTable->end(); i++) {
466 //Get some basic material information
467 G4Material* material = (*i);
468 G4String matName = material->GetName();
469 const G4double matDensity = material->GetDensity();
470 const G4int nMatElements = material->GetNumberOfElements();
472 G4cout << "\t\t+ " << matName
473 << ": dens. = " << matDensity/(g/cm3) << "g/cm3"
474 << ", nElem = " << nMatElements << G4endl;
476 // 1) For materials with density <= 1.00e-10*g/cm3 assign vacuum
477 // FlukaMaterial* is 0 in that case
478 if (matDensity <= 1.00e-10*g/cm3) {
479 G4FlukaMaterialMap[material] = 0;
480 G4cout << "\t\t Stored as vacuum" << G4endl;
482 // 2) For each single element material build a material equivalent
483 else if (nMatElements == 1) {
485 FlukaMaterial *flukamat =
486 BuildFlukaMaterialFromElement(material->GetElement(0),
489 G4FlukaMaterialMap[material] = flukamat;
490 G4cout << "\t\t Stored as " << flukamat->GetRealName() << G4endl;
492 } //else if (material->GetNumberOfElements() == 1)
495 // 3.a) Build materials for each not already known element
496 // 3.b) Build the compound out of them
498 FlukaCompound* flukacomp =
499 BuildFlukaCompoundFromMaterial(material);
500 G4FlukaCompoundMap[material] = flukacomp;
501 G4cout << "\t\t Stored as " << flukacomp->GetRealName() << G4endl;
505 #ifdef G4GEOMETRY_DEBUG
506 G4cout << "<== Flugg FGeometryInit::BuildMaterialTables()" << G4endl;
511 FGeometryInit::BuildFlukaMaterialFromElement(const G4Element* element,
512 G4double matDensity) {
513 #ifdef G4GEOMETRY_DEBUG
514 G4cout << "==> Flugg FGeometryInit::BuildFlukaMaterialFromElement()"
518 //Get element and its properties
519 G4String elemName(ToFlukaString(element->GetName()));
521 FlukaMaterial* flukamat = FlukaMaterial::GetFlukaMaterial(elemName);
522 if (matDensity != 0 || (matDensity == 0 && flukamat == 0)) {
524 G4int nIsotopes = element->GetNumberOfIsotopes();
525 if (nIsotopes == 0) {
526 G4double elemA = element->GetA()/g;
527 G4double elemZ = element->GetZ();
529 if (elemA != G4int(elemA) && elemZ != G4int(elemZ)) {
530 G4cout << "WARNING: Element \'" << elemName
531 << "\' has non integer Z (" << elemZ << ") or A ("
536 flukamat = new FlukaMaterial(elemName,
541 else if (nIsotopes == 1) {
542 const G4Isotope* isotope = element->GetIsotope(0);
543 flukamat = BuildFlukaMaterialFromIsotope(isotope, matDensity);
546 FlukaCompound *flucomp = BuildFlukaCompoundFromElement(element,
548 flukamat = flucomp->GetFlukaMaterial();
551 #ifdef G4GEOMETRY_DEBUG
553 G4cout << "INFO: Element \'" << elemName
554 << "\' already exists in the DB. It will not be recreated."
561 #ifdef G4GEOMETRY_DEBUG
562 G4cout << "<== Flugg FGeometryInit::BuildFlukaMaterialFromElement()"
568 FGeometryInit::BuildFlukaMaterialFromIsotope(const G4Isotope* isotope,
569 G4double matDensity) {
570 #ifdef G4GEOMETRY_DEBUG
571 G4cout << "==> Flugg FGeometryInit::BuildFlukaMaterialFromIsotope()"
574 G4String isoName(ToFlukaString(isotope->GetName()));
575 FlukaMaterial* flukamat = FlukaMaterial::GetFlukaMaterial(isoName);
576 if (matDensity != 0 || (matDensity == 0 && flukamat == 0)) {
577 G4int isoZ = isotope->GetZ();
578 G4double isoA = (isotope->GetA())/(g);
579 G4int isoN = isotope->GetN();
580 flukamat = new FlukaMaterial(isoName,
589 #ifdef G4GEOMETRY_DEBUG
590 G4cout << "==> Flugg FGeometryInit::BuildFlukaMaterialFromIsotope()"
596 FGeometryInit::BuildFlukaCompoundFromMaterial(const G4Material* material) {
597 #ifdef G4GEOMETRY_DEBUG
598 G4cout << "==> Flugg FGeometryInit::BuildFlukaCompoundFromMaterial()"
601 //Material properties
602 const G4double* elemFractions = material->GetFractionVector();
603 const G4int nMatElements = material->GetNumberOfElements();
604 const G4double matDensity = material->GetDensity();
605 G4String matName(ToFlukaString(material->GetName()));
606 FlukaCompound* flukacomp = new FlukaCompound(matName, matDensity/(g/cm3),
608 for (G4int i = 0; i < nMatElements; i++) {
609 FlukaMaterial *flukamat =
610 BuildFlukaMaterialFromElement(material->GetElement(i), 0.0);
612 flukacomp->AddElement(flukamat->GetIndex(), -elemFractions[i]);
618 #ifdef G4GEOMETRY_DEBUG
619 G4cout << "<== Flugg FGeometryInit::BuildFlukaCompoundFromMaterial()"
625 FGeometryInit::BuildFlukaCompoundFromElement(const G4Element* element,
626 G4double matDensity) {
627 #ifdef G4GEOMETRY_DEBUG
628 G4cout << "==> Flugg FGeometryInit::BuildFlukaCompoundFromElement()"
631 G4int nIsotopes = element->GetNumberOfIsotopes();
632 //fraction of nb of atomes per volume (= volume fraction?)
633 const G4double* isoAbundance = element->GetRelativeAbundanceVector();
634 G4String elemName(ToFlukaString(element->GetName()));
636 //Material properties
637 FlukaCompound* flukacomp = new FlukaCompound(elemName, matDensity/(g/cm3),
639 for (G4int i = 0; i < nIsotopes; i++) {
640 FlukaMaterial *flukamat =
641 BuildFlukaMaterialFromIsotope(element->GetIsotope(i), 0.0);
643 flukacomp->AddElement(flukamat->GetIndex(), isoAbundance[i]);
649 #ifdef G4GEOMETRY_DEBUG
650 G4cout << "<== Flugg FGeometryInit::BuildFlukaCompoundFromElement()"
655 void FGeometryInit::PrintMaterialTables(G4std::ostream& os) {
656 #ifdef G4GEOMETRY_DEBUG
657 G4cout << "==> Flugg FGeometryInit::PrintMaterialTables()" << G4endl;
660 PrintHeader(os, "GEANT4 MATERIALS AND COMPOUNDS");
662 //And some more stuff
663 size_t nIsotopes = G4Isotope::GetNumberOfIsotopes();
664 size_t nElements = G4Element::GetNumberOfElements();
665 size_t nMaterials = G4Material::GetNumberOfMaterials();
667 os << "* In Geant4 there are " << nMaterials << " materials" << G4endl;
668 os << "* In Geant4 there are " << nElements << " elements" << G4endl;
669 os << "* In Geant4 there are " << nIsotopes << " isotopes" << G4endl;
672 G4cout << "\t* Printing FLUKA materials..." << G4endl;
673 FlukaMaterial::PrintMaterialsByIndex(os);
674 //FlukaMaterial::PrintMaterialsByName(os);
677 G4cout << "\t* Printing FLUKA compounds..." << G4endl;
678 FlukaCompound::PrintCompounds(os);
680 #ifdef G4GEOMETRY_DEBUG
681 G4cout << "<== Flugg FGeometryInit::PrintMaterialTables()" << G4endl;
685 ////////////////////////////////////////////////////////////////////////
687 void FGeometryInit::PrintAssignmat(G4std::ostream& os) {
688 #ifdef G4GEOMETRY_DEBUG
689 G4cout << "==> Flugg FGeometryInit::PrintAssignmat()" << G4endl;
692 //Find number of Volumes in physical volume store
693 G4PhysicalVolumeStore * pVolStore = G4PhysicalVolumeStore::GetInstance();
694 unsigned int numVol = pVolStore->size();
696 G4cout << "\t* G4PhysicalVolumeStore (" << pVolStore
697 << ") has " << numVol << " volumes. " << G4endl;
699 G4cout << "\t* Printing ASSIGNMAT..." << G4endl;
702 PrintHeader(os,"GEANT4 MATERIAL ASSIGNMENTS");
703 for(unsigned int l=0; l < numVol; l++) {
705 //Get each of the physical volumes
706 G4VPhysicalVolume * physicalvol = (*pVolStore)[l];
708 //Get index for that volume
709 G4int iFlukaRegion = fRegionVolumeMap[physicalvol];
711 //Find G4 material and navigate to its fluka compound/material
712 G4LogicalVolume * logicalVol = physicalvol->GetLogicalVolume();
713 G4Material* material = logicalVol->GetMaterial();
715 if (G4FlukaCompoundMap[material])
716 matIndex = G4FlukaCompoundMap[material]->GetIndex();
717 if (G4FlukaMaterialMap[material])
718 matIndex = G4FlukaMaterialMap[material]->GetIndex();
720 //Find if there is a magnetic field in the region
721 //check if Magnetic Field is present in the region
722 G4double flagField = 0.0;
723 G4FieldManager * pMagFieldMan = logicalVol->GetFieldManager();
724 if(pMagFieldMan && pMagFieldMan->GetDetectorField())
728 os << setw10 << "ASSIGNMAT ";
729 os.setf(static_cast<G4std::ios::fmtflags>(0),G4std::ios::floatfield);
730 os << setw10 << setfixed << G4double(matIndex);
731 os << setw10 << setfixed << G4double(iFlukaRegion);
732 os << setw10 << "0.0";
733 os << setw10 << setfixed << flagField;
739 #ifdef G4GEOMETRY_DEBUG
740 G4cout << "==> Flugg FGeometryInit::PrintAssignmat()" << G4endl;
745 void FGeometryInit::PrintMagneticField(G4std::ostream& os) {
746 #ifdef G4GEOMETRY_DEBUG
747 G4cout << "==> Flugg FGeometryInit::PrintMagneticField()" << G4endl;
750 G4cout << "\t* Printing Magnetic Field..." << G4endl;
752 if(fTransportationManager->GetFieldManager()->DoesFieldExist()) {
754 //get magnetic field pointer
755 const G4Field * pMagField =
756 fTransportationManager->GetFieldManager()->GetDetectorField();
760 //Check if it can be made a uniform magnetic field
761 const G4UniformMagField *pUnifMagField =
762 dynamic_cast<const G4UniformMagField*>(pMagField);
765 G4double point[4]; //it is not really used
766 pUnifMagField->GetFieldValue(point,B);
768 //write MGNFIELD card
769 PrintHeader(os,"GEANT4 MAGNETIC FIELD");
770 os << setw10 << "MGNFIELD ";
774 os.setf(static_cast<G4std::ios::fmtflags>(0),G4std::ios::floatfield);
775 os << setw10 << setfixed
776 << G4std::setprecision(4) << B[0]
782 G4cout << "WARNING: No Uniform Magnetic Field found." << G4endl;
783 G4cout << " Manual intervention might be needed." << G4endl;
787 G4cout << "\t No detector field found... " << G4endl;
788 } // end if magnetic field
790 G4cout << "\t No field found... " << G4endl;
792 #ifdef G4GEOMETRY_DEBUG
793 G4cout << "<== Flugg FGeometryInit::PrintMagneticField()" << G4endl;
797 int FGeometryInit::CurrentVolID(int ir, int& copyNo)
799 G4PhysicalVolumeStore * pVolStore = G4PhysicalVolumeStore::GetInstance();
800 G4VPhysicalVolume * physicalvol = (*pVolStore)[ir- 1];
801 copyNo = physicalvol->GetCopyNo();
802 int id = fVolIdVolumeMap[physicalvol];
806 int FGeometryInit::CurrentVolOffID(int ir, int off, int& copyNo)
808 if (off == 0) return CurrentVolID(ir, copyNo);
810 G4PhysicalVolumeStore* pVolStore = G4PhysicalVolumeStore::GetInstance();
811 G4VPhysicalVolume* physicalvol = (*pVolStore)[ir- 1];
812 G4VPhysicalVolume* mother = physicalvol;
816 if (mother) mother = mother->GetMother();
823 G4cout << "Flugg FGeometryInit::CurrentVolOffID mother not found" << G4endl;
827 copyNo = mother ->GetCopyNo();
828 id = fVolIdVolumeMap[mother];
833 void FGeometryInit::Gmtod(double* xm, double* xd, int iflag)
835 // Transforms a position from the world reference frame
836 // to the current volume reference frame.
838 // Geant3 desription:
839 // ==================
840 // Computes coordinates XD (in DRS)
841 // from known coordinates XM in MRS
842 // The local reference system can be initialized by
843 // - the tracking routines and GMTOD used in GUSTEP
844 // - a call to GMEDIA(XM,NUMED)
845 // - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
846 // (inverse routine is GDTOM)
848 // If IFLAG=1 convert coordinates
849 // IFLAG=2 convert direction cosinus
852 FluggNavigator * ptrNavig = getNavigatorForTracking();
853 //setting variables (and dimension: Fluka uses cm.!)
854 G4ThreeVector pGlob(xm[0],xm[1],xm[2]);
858 pGlob *= 10.0; // in mm
860 ptrNavig->ComputeLocalPoint(pGlob);
861 pLoc /= 10.0; // in cm
862 } else if (iflag == 2) {
864 ptrNavig->ComputeLocalAxis(pGlob);
866 G4cout << "Flugg FGeometryInit::Gmtod called with undefined flag" << G4endl;
868 xd[0] = pLoc[0]; xd[1] = pLoc[1]; xd[2] = pLoc[2];
871 void FGeometryInit::Gdtom(double* xd, double* xm, int iflag)
873 // Transforms a position from the current volume reference frame
874 // to the world reference frame.
876 // Geant3 desription:
877 // ==================
878 // Computes coordinates XM (Master Reference System
879 // knowing the coordinates XD (Detector Ref System)
880 // The local reference system can be initialized by
881 // - the tracking routines and GDTOM used in GUSTEP
882 // - a call to GSCMED(NLEVEL,NAMES,NUMBER)
883 // (inverse routine is GMTOD)
885 // If IFLAG=1 convert coordinates
886 // IFLAG=2 convert direction cosinus
890 FluggNavigator * ptrNavig = getNavigatorForTracking();
891 G4ThreeVector pLoc(xd[0],xd[1],xd[2]);
895 pLoc *= 10.0; // in mm
896 pGlob = ptrNavig->GetLocalToGlobalTransform().
897 TransformPoint(pLoc);
898 pGlob /= 10.0; // in cm
899 } else if (iflag == 2) {
900 pGlob = ptrNavig->GetLocalToGlobalTransform().
903 G4cout << "Flugg FGeometryInit::Gdtom called with undefined flag" << G4endl;
906 xm[0] = pGlob[0]; xm[1] = pGlob[1]; xm[2] = pGlob[2];