CMS 3D CMS Logo

LocalFieldManager.cc
Go to the documentation of this file.
1 
4 
5 #include "G4ChordFinder.hh"
6 #include "G4Track.hh"
7 
8 #include "CLHEP/Units/SystemOfUnits.h"
9 
10 #include <iostream>
11 
12 using namespace sim;
13 
14 LocalFieldManager::LocalFieldManager(G4Field *commonField, G4FieldManager *priFM, G4FieldManager *altFM)
15  : G4FieldManager(commonField, nullptr, false),
16  fPrimaryFM(priFM),
17  fAlternativeFM(altFM),
18  fCurrentFM(nullptr),
19  fVerbosity(false) {
20  this->CopyValuesAndChordFinder(priFM);
21  fCurrentFM = priFM;
22 }
23 
24 void LocalFieldManager::ConfigureForTrack(const G4Track *trk) {
25  int PID = trk->GetDynamicParticle()->GetDefinition()->GetPDGEncoding();
26 
27  if (std::abs(PID) != 13) // maybe also high energy pions ?... what else ?
28  {
29  if (fCurrentFM != fAlternativeFM) {
32  if (fVerbosity)
33  print(trk);
34  }
35  } else {
36  if (fCurrentFM != fPrimaryFM) {
39  if (fVerbosity)
40  print(trk);
41  }
42  }
43 }
44 
45 const G4FieldManager *LocalFieldManager::CopyValuesAndChordFinder(G4FieldManager *fm) {
46  SetDeltaIntersection(fm->GetDeltaIntersection());
47  SetDeltaOneStep(fm->GetDeltaOneStep());
48  G4ChordFinder *cf = fm->GetChordFinder();
49  cf->SetDeltaChord(cf->GetDeltaChord());
50  SetChordFinder(cf);
51 
52  return fm;
53 }
54 
55 void LocalFieldManager::print(const G4Track *trk) {
56  std::string ss = (fCurrentFM == fAlternativeFM) ? "Alternative field manager with" : "Global field manager with";
57 
58  edm::LogVerbatim("SimG4CoreMagneticField")
59  << ss << " DeltaIntersection= " << G4FieldManager::GetDeltaIntersection()
60  << ", DeltaOneStep= " << G4FieldManager::GetDeltaOneStep()
61  << ", DeltaChord= " << G4FieldManager::GetChordFinder()->GetDeltaChord() << " for "
62  << trk->GetDynamicParticle()->GetDefinition()->GetPDGEncoding() << " with "
63  << trk->GetKineticEnergy() / CLHEP::GeV << " GeV in " << trk->GetVolume()->GetName();
64 }
Log< level::Info, true > LogVerbatim
G4FieldManager * fCurrentFM
G4FieldManager * fAlternativeFM
const G4FieldManager * CopyValuesAndChordFinder(G4FieldManager *fm)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void print(const G4Track *trk)
G4FieldManager * fPrimaryFM
void ConfigureForTrack(const G4Track *trk) override
PID
Definition: data.h:16