// Geant4 simulation for MuSR // AUTHOR: Toni SHIROKA, Paul Scherrer Institut, PSI // DATE : 2008-05 // // // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // #include "G4GeometryManager.hh" #include "F04ElementField.hh" #include "F04GlobalField.hh" #include "lem4Parameters.hh" #include "lem4ErrorMessage.hh" G4Navigator* F04ElementField::aNavigator; F04ElementField::F04ElementField(G4ThreeVector c, G4LogicalVolume* lv) { elementFieldName="NAME_NOT_DEFINED"; center = c; minX = minY = minZ = -DBL_MAX; maxX = maxY = maxZ = DBL_MAX; ///G4cout<<"Kamil: F04GlobalField: addElementField() will be called: "<addElementField(this); color = "1,1,1"; userLimits = new G4UserLimits(); lvolume = lv; lvolume->SetVisAttributes(getVisAttribute(color)); maxStep = 1*mm; userLimits->SetMaxAllowedStep(maxStep); userLimits->SetUserMaxTrackLength(500.*m); userLimits->SetUserMaxTime(10*ms); // userLimits->SetUserMinEkine(0.1*MeV); // userLimits->SetUserMinRange(1*mm); lvolume->SetUserLimits(userLimits); } void F04ElementField::construct() { G4Navigator* theNavigator = G4TransportationManager::GetTransportationManager()-> GetNavigatorForTracking(); if (!aNavigator) { aNavigator = new G4Navigator(); if ( theNavigator->GetWorldVolume() ) aNavigator->SetWorldVolume(theNavigator->GetWorldVolume()); } G4GeometryManager* geomManager = G4GeometryManager::GetInstance(); if (!geomManager->IsGeometryClosed()) { geomManager->OpenGeometry(); geomManager->CloseGeometry(true); } ///G4cout<<"F04ElementField: center="<LocateGlobalPointAndSetup(center,0,false); G4TouchableHistoryHandle fTouchable = aNavigator->CreateTouchableHistoryHandle(); G4int depth = fTouchable->GetHistoryDepth(); for (G4int i = 0; iGetVolume()->GetLogicalVolume() == lvolume)break; fTouchable->MoveUpHistory(); } // Check that the point of origin of the field matches that of the logical volume, to which it is assigned: G4String volumeName=lvolume->GetName(); if (fTouchable->GetVolume()->GetLogicalVolume() != lvolume) { char eMessage[200]; sprintf(eMessage,"F04ElementField.cc::construct(): Origin of the field outside the respective logical volume!! \"%s\".", volumeName.c_str()); /// NOTE: Cannot apply fields to non simply connected bodies, as e.g. rings, tori, etc. ! lem4ErrorMessage::GetInstance()->lem4Error(FATAL,eMessage,false); } // G4cout<<"+!+!+! global2local VOLUME NAME: "<GetVolume()->GetName()<GetHistory()->GetTopTransform(); G4ThreeVector local_center = global2local.TransformPoint(center); G4cout<<"F04ElementField: " << elementFieldName << " in \""< "< "< 0 && (isdigit(color.c_str()[0]) || color.c_str()[0] == '.')) { G4double red=0.0, green=0.0, blue=0.0; if (sscanf(color.c_str(),"%lf,%lf,%lf",&red,&green,&blue) == 3) { p = new G4VisAttributes(true,G4Color(red,green,blue)); } else { G4cout << " Invalid color " << color << G4endl; } } if (!p) p = new G4VisAttributes(G4VisAttributes::Invisible); p->SetDaughtersInvisible(false); return p; } void F04ElementField::SetEventNrDependentField(G4double initialField, G4double finalField, G4int nrOfSteps) { G4double eventNrStep = float(lem4Parameters::nrOfEventsToBeGenerated)/(nrOfSteps); G4double fieldStep = (finalField-initialField)/(nrOfSteps-1); // G4cout<<"lem4Parameters::nrOfEventsToBeGenerated="<::iterator it; for ( it=changeFieldInStepsMap.begin() ; it != changeFieldInStepsMap.end(); it++ ) { G4cout << "Field will be changed at event "<< (*it).first << " to the value of " << (*it).second/tesla<<" T" << G4endl; // G4double nominalFieldValue=it->second; // it->SetNominalFieldValue(nominalFieldValue); } } void F04ElementField::SetElementFieldValueIfNeeded(G4int eventNr) { std::map::iterator itr; itr = changeFieldInStepsMap.find(eventNr); if (itr==F04ElementField::changeFieldInStepsMap.end()) { // eventNr was not found in the map ==> field is not going to change at this eventNr } else { G4double newFieldValue = itr->second; SetNominalFieldValue(newFieldValue); // G4cout<<"Nominal Field changed for "<