Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:29:49

0001 
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "SimG4Core/MagneticField/interface/LocalFieldManager.h"
0004 
0005 #include "G4ChordFinder.hh"
0006 #include "G4Track.hh"
0007 
0008 #include "CLHEP/Units/SystemOfUnits.h"
0009 
0010 #include <iostream>
0011 
0012 using namespace sim;
0013 
0014 LocalFieldManager::LocalFieldManager(G4Field *commonField, G4FieldManager *priFM, G4FieldManager *altFM)
0015     : G4FieldManager(commonField, nullptr, false),
0016       fPrimaryFM(priFM),
0017       fAlternativeFM(altFM),
0018       fCurrentFM(nullptr),
0019       fVerbosity(false) {
0020   this->CopyValuesAndChordFinder(priFM);
0021   fCurrentFM = priFM;
0022 }
0023 
0024 void LocalFieldManager::ConfigureForTrack(const G4Track *trk) {
0025   int PID = trk->GetDynamicParticle()->GetDefinition()->GetPDGEncoding();
0026 
0027   if (std::abs(PID) != 13)  // maybe also high energy pions ?... what else ?
0028   {
0029     if (fCurrentFM != fAlternativeFM) {
0030       this->CopyValuesAndChordFinder(fAlternativeFM);
0031       fCurrentFM = fAlternativeFM;
0032       if (fVerbosity)
0033         print(trk);
0034     }
0035   } else {
0036     if (fCurrentFM != fPrimaryFM) {
0037       this->CopyValuesAndChordFinder(fPrimaryFM);
0038       fCurrentFM = fPrimaryFM;
0039       if (fVerbosity)
0040         print(trk);
0041     }
0042   }
0043 }
0044 
0045 const G4FieldManager *LocalFieldManager::CopyValuesAndChordFinder(G4FieldManager *fm) {
0046   SetDeltaIntersection(fm->GetDeltaIntersection());
0047   SetDeltaOneStep(fm->GetDeltaOneStep());
0048   G4ChordFinder *cf = fm->GetChordFinder();
0049   cf->SetDeltaChord(cf->GetDeltaChord());
0050   SetChordFinder(cf);
0051 
0052   return fm;
0053 }
0054 
0055 void LocalFieldManager::print(const G4Track *trk) {
0056   std::string ss = (fCurrentFM == fAlternativeFM) ? "Alternative field manager with" : "Global field manager with";
0057 
0058   edm::LogVerbatim("SimG4CoreMagneticField")
0059       << ss << " DeltaIntersection= " << G4FieldManager::GetDeltaIntersection()
0060       << ", DeltaOneStep= " << G4FieldManager::GetDeltaOneStep()
0061       << ", DeltaChord= " << G4FieldManager::GetChordFinder()->GetDeltaChord() << " for "
0062       << trk->GetDynamicParticle()->GetDefinition()->GetPDGEncoding() << " with "
0063       << trk->GetKineticEnergy() / CLHEP::GeV << " GeV in " << trk->GetVolume()->GetName();
0064 }