From 8f1a1aaa102e70d5c101d76c2152b52c814e66e4 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Tue, 1 Oct 2019 19:39:30 -0500 Subject: [PATCH 1/4] Fix event generator to be in the target, not downstream Due to a sign error, the events were generated around +4587 mm instead of around -4587 mm. The call to GetFrameTranslation should have been a call to GetTranslation, or various equivalent sign changes. This was not a problem before since the target was centered at zero, and so -0 is the same... --- src/remollBeamTarget.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/remollBeamTarget.cc b/src/remollBeamTarget.cc index 82c1d9db6..607611afa 100644 --- a/src/remollBeamTarget.cc +++ b/src/remollBeamTarget.cc @@ -125,7 +125,7 @@ void remollBeamTarget::UpdateInfo() if (!fTargetMother) { return; } - fMotherTargetAbsolutePosition = fTargetMother->GetFrameTranslation().z(); + fMotherTargetAbsolutePosition = fTargetMother->GetTranslation().z(); for (std::vector::iterator it = fTargetVolumes.begin(); it != fTargetVolumes.end(); it++) { @@ -154,7 +154,7 @@ void remollBeamTarget::UpdateInfo() fActiveTargetEffectiveLength = tubs->GetZHalfLength()*2.0 * material->GetDensity(); - fActiveTargetRelativePosition = (*it)->GetFrameTranslation().z(); + fActiveTargetRelativePosition = (*it)->GetTranslation().z(); fTotalTargetEffectiveLength += tubs->GetZHalfLength()*2.0 * material->GetDensity(); @@ -245,7 +245,7 @@ remollVertex remollBeamTarget::SampleVertex(SampType_t samp) it = fTargetVolumes.begin(); it != fTargetVolumes.end() && !found_active_volume; it++ ){ // Relative position of this target volume in mother volume - //G4double relative_position = (*it)->GetFrameTranslation().z(); + G4double volume_relative_position = (*it)->GetTranslation().z(); // Try to cast the target volume into its tubs solid G4LogicalVolume* volume = (*it)->GetLogicalVolume(); @@ -304,9 +304,10 @@ remollVertex remollBeamTarget::SampleVertex(SampType_t samp) // For our own info fTravelledLength = actual_position_in_volume; fRadiationLength = cumulative_radiation_length; - fVer = G4ThreeVector( rasx, rasy, - actual_position_in_volume - (*it)->GetFrameTranslation().z() + fMotherTargetAbsolutePosition - - tubs->GetZHalfLength() ); + fVer = G4ThreeVector( rasx, rasy, + fMotherTargetAbsolutePosition + + volume_relative_position - tubs->GetZHalfLength() + + actual_position_in_volume ); G4double masssum = 0.0; const G4int *atomvec = material->GetAtomsVector(); From 59046cf838735f3aa2d3dc3ee3b76b3962c7b5e9 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Tue, 1 Oct 2019 20:17:20 -0500 Subject: [PATCH 2/4] /remoll/scalefield -> /remoll/field/scale et al /remoll/magcurrent -> /remoll/field/current Previous versions didn't work anymore since now Geant4 tokenizes arguments on spaces and only the first one (field name) was passed. Now passing also second one. No unit since only two arguments are supported by G4AnyMethod. --- include/remollGlobalField.hh | 5 +---- macros/runexample.mac | 4 ++-- src/remollGlobalField.cc | 36 ++++-------------------------------- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/include/remollGlobalField.hh b/include/remollGlobalField.hh index c20d0f9bf..2a4edf680 100644 --- a/include/remollGlobalField.hh +++ b/include/remollGlobalField.hh @@ -27,11 +27,8 @@ class remollGlobalField : public G4MagneticField { void AddNewField(G4String& name); - void SetFieldScaleByString(G4String& name_scale); void SetFieldScale(const G4String& name, G4double scale); - - void SetMagnetCurrentByString(G4String& name_scale); - void SetMagnetCurrent(const G4String& name, G4double scale); + void SetMagnetCurrent(const G4String& name, G4double current); void PrintFieldValue(const G4ThreeVector&); diff --git a/macros/runexample.mac b/macros/runexample.mac index bc02c77ec..2ef760633 100644 --- a/macros/runexample.mac +++ b/macros/runexample.mac @@ -21,8 +21,8 @@ /remoll/addfield map_directory/blockyHybrid_rm_3.0.txt /remoll/addfield map_directory/blockyUpstream_rm_1.1.txt -#/remoll/scalefield map_directory/blockyHybrid_rm_3.0.txt 1.0 -#/remoll/magcurrent map_directory/blockyHybrid_rm_3.0.txt 1000.0 A +#/remoll/field/scale map_directory/blockyHybrid_rm_3.0.txt 1.0 +#/remoll/field/current map_directory/blockyHybrid_rm_3.0.txt 1000.0 # Raster and initial angle stuff /remoll/oldras true diff --git a/src/remollGlobalField.cc b/src/remollGlobalField.cc index c1022b858..3966d334f 100644 --- a/src/remollGlobalField.cc +++ b/src/remollGlobalField.cc @@ -66,8 +66,6 @@ remollGlobalField::remollGlobalField() // Create generic messenger fMessenger = new G4GenericMessenger(this,"/remoll/","Remoll properties"); fMessenger->DeclareMethod("addfield",&remollGlobalField::AddNewField,"Add magnetic field"); - fMessenger->DeclareMethod("scalefield",&remollGlobalField::SetFieldScaleByString,"Scale magnetic field"); - fMessenger->DeclareMethod("magcurrent",&remollGlobalField::SetMagnetCurrentByString,"Scale magnetic field by current"); // Create global field messenger fGlobalFieldMessenger = new G4GenericMessenger(this,"/remoll/field/","Remoll global field properties"); @@ -80,6 +78,8 @@ remollGlobalField::remollGlobalField() fGlobalFieldMessenger->DeclareProperty("deltachord",fDeltaChord,"Set delta chord for the chord finder"); fGlobalFieldMessenger->DeclareProperty("deltaonestep",fDeltaOneStep,"Set delta one step for the field manager"); fGlobalFieldMessenger->DeclareProperty("deltaintersection",fMinStep,"Set delta intersection for the field manager"); + fGlobalFieldMessenger->DeclareMethod("scale",&remollGlobalField::SetFieldScale,"Scale magnetic field by factor"); + fGlobalFieldMessenger->DeclareMethod("current",&remollGlobalField::SetMagnetCurrent,"Scale magnetic field by current"); fGlobalFieldMessenger->DeclareMethod("value",&remollGlobalField::PrintFieldValue,"Print the field value at a given point (in m)"); } @@ -271,16 +271,7 @@ void remollGlobalField::GetFieldValue(const G4double p[], G4double *resB) const } } -void remollGlobalField::SetFieldScaleByString(G4String& name_scale) { - std::istringstream iss(name_scale); - - G4String name, scalestr; - iss >> name; - iss >> scalestr; - - G4double scaleval = atof(scalestr); - SetFieldScale(name, scaleval); } void remollGlobalField::SetFieldScale(const G4String& name, G4double scale) @@ -295,31 +286,12 @@ void remollGlobalField::SetFieldScale(const G4String& name, G4double scale) } } -void remollGlobalField::SetMagnetCurrentByString(G4String& name_scale) -{ - std::istringstream iss(name_scale); - - G4String name, scalestr, scaleunit; - iss >> name; - iss >> scalestr; - iss >> scaleunit; - - if (scaleunit != "A") { - // FIXME: less snark and more functionality? - G4cerr << __FILE__ << " line " << __LINE__ << ":\n\tGraaaah - just put the current for " << name << " in amps..." << G4endl; - exit(1); - } - - G4double scaleval = atof(scalestr); - SetMagnetCurrent(name, scaleval); -} - -void remollGlobalField::SetMagnetCurrent(const G4String& name, G4double scale) +void remollGlobalField::SetMagnetCurrent(const G4String& name, G4double current) { remollMagneticField *field = GetFieldByName(name); if (field) { G4AutoLock lock(&remollGlobalFieldMutex); - field->SetMagnetCurrent(scale); + field->SetMagnetCurrent(current); } else { G4cerr << "WARNING " << __FILE__ << " line " << __LINE__ << ": field " << name << " scaling failed" << G4endl; From 96fd953b6ec0230f6ff403b6765a582f9c08ccca Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Tue, 1 Oct 2019 20:18:10 -0500 Subject: [PATCH 3/4] macro field SetZOffset with /remoll/field/zoffset Value entered in meters since, again, no third token for units is allowed. --- include/remollGlobalField.hh | 1 + macros/runexample.mac | 3 +++ src/remollGlobalField.cc | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/include/remollGlobalField.hh b/include/remollGlobalField.hh index 2a4edf680..dea0100b6 100644 --- a/include/remollGlobalField.hh +++ b/include/remollGlobalField.hh @@ -27,6 +27,7 @@ class remollGlobalField : public G4MagneticField { void AddNewField(G4String& name); + void SetZOffset(const G4String& name, G4double offset); void SetFieldScale(const G4String& name, G4double scale); void SetMagnetCurrent(const G4String& name, G4double current); diff --git a/macros/runexample.mac b/macros/runexample.mac index 2ef760633..2c19ef7e7 100644 --- a/macros/runexample.mac +++ b/macros/runexample.mac @@ -21,6 +21,9 @@ /remoll/addfield map_directory/blockyHybrid_rm_3.0.txt /remoll/addfield map_directory/blockyUpstream_rm_1.1.txt +/remoll/field/zoffset map_directory/blockyHybrid_rm_3.0.txt -5087. +/remoll/field/zoffset map_directory/blockyUpstream_rm_1.1.txt -5087. + #/remoll/field/scale map_directory/blockyHybrid_rm_3.0.txt 1.0 #/remoll/field/current map_directory/blockyHybrid_rm_3.0.txt 1000.0 diff --git a/src/remollGlobalField.cc b/src/remollGlobalField.cc index 3966d334f..79ff876f0 100644 --- a/src/remollGlobalField.cc +++ b/src/remollGlobalField.cc @@ -78,6 +78,7 @@ remollGlobalField::remollGlobalField() fGlobalFieldMessenger->DeclareProperty("deltachord",fDeltaChord,"Set delta chord for the chord finder"); fGlobalFieldMessenger->DeclareProperty("deltaonestep",fDeltaOneStep,"Set delta one step for the field manager"); fGlobalFieldMessenger->DeclareProperty("deltaintersection",fMinStep,"Set delta intersection for the field manager"); + fGlobalFieldMessenger->DeclareMethod("zoffset",&remollGlobalField::SetZOffset,"Set magnetic field z offset"); fGlobalFieldMessenger->DeclareMethod("scale",&remollGlobalField::SetFieldScale,"Scale magnetic field by factor"); fGlobalFieldMessenger->DeclareMethod("current",&remollGlobalField::SetMagnetCurrent,"Scale magnetic field by current"); fGlobalFieldMessenger->DeclareMethod("value",&remollGlobalField::PrintFieldValue,"Print the field value at a given point (in m)"); @@ -271,7 +272,16 @@ void remollGlobalField::GetFieldValue(const G4double p[], G4double *resB) const } } +void remollGlobalField::SetZOffset(const G4String& name, G4double offset) { + remollMagneticField *field = GetFieldByName(name); + if (field) { + G4AutoLock lock(&remollGlobalFieldMutex); + field->SetZoffset(offset); + } else { + G4cerr << "WARNING " << __FILE__ << " line " << __LINE__ + << ": field " << name << " offset failed" << G4endl; + } } void remollGlobalField::SetFieldScale(const G4String& name, G4double scale) From 45d23f19389563addf7015bac90add90604c11dd Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Wed, 2 Oct 2019 14:13:16 -0500 Subject: [PATCH 4/4] Set the default z shift of the magnetic field to -5.087 m This will cause the old magnetic fields to be read in correctly, even if there is no /remoll/field/zoffset command --- macros/runexample.mac | 3 --- src/remollMagneticField.cc | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/macros/runexample.mac b/macros/runexample.mac index 2c19ef7e7..2ef760633 100644 --- a/macros/runexample.mac +++ b/macros/runexample.mac @@ -21,9 +21,6 @@ /remoll/addfield map_directory/blockyHybrid_rm_3.0.txt /remoll/addfield map_directory/blockyUpstream_rm_1.1.txt -/remoll/field/zoffset map_directory/blockyHybrid_rm_3.0.txt -5087. -/remoll/field/zoffset map_directory/blockyUpstream_rm_1.1.txt -5087. - #/remoll/field/scale map_directory/blockyHybrid_rm_3.0.txt 1.0 #/remoll/field/current map_directory/blockyHybrid_rm_3.0.txt 1000.0 diff --git a/src/remollMagneticField.cc b/src/remollMagneticField.cc index b0f35bc90..3ffebd179 100644 --- a/src/remollMagneticField.cc +++ b/src/remollMagneticField.cc @@ -38,7 +38,10 @@ remollMagneticField::remollMagneticField( G4String filename ){ fPhi0 = -1e9; - fZoffset = 0.0; + // Default offset for field maps in reference frame with + // the hall pivot at z = 0. + fZoffset = -5087.0; + fInit = false; fMagCurrent0 = -1e9;