ATLAS Offline Software
SwitchingFieldManager.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "G4ThreeVector.hh"
6 #include "G4Field.hh"
7 
9 #include "G4ChordFinder.hh"
10 
11 #include "G4Track.hh"
12 #include "G4MuonPlus.hh"
13 #include "G4MuonMinus.hh"
14 #include "G4ChargedGeantino.hh"
15 
16 
17 
19  : G4FieldManager( detectorField ),
20  m_savedField( detectorField )
21 {}
22 
24 {}
25 
26 // Inside Calo area switch off the B-field.
27 //
29 {
30  assert( GetDetectorField() == m_savedField
31  || GetDetectorField() == nullptr );
32  // Must ensure that SetDetectorField() has NOT been called to establish
33  // a different field by an inside entity
34  // ... it would invalidate our assumptions !
35 
36  const bool isMuonTrack = (track->GetDefinition()==G4MuonPlus::Definition() ||
37  track->GetDefinition()==G4MuonMinus::Definition() ||
38  track->GetDefinition()==G4ChargedGeantino::ChargedGeantinoDefinition());
39 
40  const G4ThreeVector position = track->GetPosition();
41  const G4double r2XY = position.x()*position.x() + position.y()*position.y();
42  const G4double Z = position.z();
43  const G4double r2Min = (m_radiusXYmin + m_offset)*(m_radiusXYmin + m_offset);
44  const G4double r2Max = (m_radiusXYmax - m_offset)*(m_radiusXYmax - m_offset);
45 
46  const bool inSide = (r2XY > r2Min) && (r2XY < r2Max) && (fabs(Z) < m_Zmax - m_offset);
47 
48  if ( inSide && DoesFieldExist() && !isMuonTrack )
49  ChangeDetectorField( nullptr );
50  else if ( !inSide && !DoesFieldExist() )
51  ChangeDetectorField( m_savedField );
52 }
53 
54 G4FieldManager* SwitchingFieldManager::Clone() const
55 {
56  G4Field* cloneField = m_savedField->Clone();
57  auto clone= new SwitchingFieldManager( cloneField );
58 
59  clone->SetMinimumEpsilonStep( this->GetMinimumEpsilonStep() );
60  clone->SetMaximumEpsilonStep( this->GetMaximumEpsilonStep() );
61  clone->SetDeltaOneStep( this->GetDeltaOneStep() );
62  clone->SetDeltaIntersection( this->GetDeltaIntersection() );
63 
64  clone->GetChordFinder()->SetDeltaChord( this->GetChordFinder()->GetDeltaChord() );
65  // This lives in our chord finder ...
66 
67  return clone;
68 }
SwitchingFieldManager::m_radiusXYmax
G4double m_radiusXYmax
Definition: SwitchingFieldManager.h:36
Monitored::Z
@ Z
Definition: HistogramFillerUtils.h:24
SwitchingFieldManager::Clone
G4FieldManager * Clone() const override
Definition: SwitchingFieldManager.cxx:54
SwitchingFieldManager::m_radiusXYmin
G4double m_radiusXYmin
Definition: SwitchingFieldManager.h:37
SwitchingFieldManager::m_Zmax
G4double m_Zmax
Definition: SwitchingFieldManager.h:38
python.Utilities.clone
clone
Definition: Utilities.py:134
SwitchingFieldManager::~SwitchingFieldManager
~SwitchingFieldManager()
Definition: SwitchingFieldManager.cxx:23
SwitchingFieldManager::m_savedField
G4Field * m_savedField
Definition: SwitchingFieldManager.h:34
SwitchingFieldManager::m_offset
G4double m_offset
Definition: SwitchingFieldManager.h:39
SwitchingFieldManager::ConfigureForTrack
void ConfigureForTrack(const G4Track *) override
Definition: SwitchingFieldManager.cxx:28
SwitchingFieldManager::SwitchingFieldManager
SwitchingFieldManager(G4Field *field)
Definition: SwitchingFieldManager.cxx:18
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
SwitchingFieldManager.h