Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /geant4/examples/extended/field/field01/src/F01RunAction.cc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 #include "F01RunAction.hh"
0027 
0028 #include "G4CoupledTransportation.hh"
0029 #include "G4Electron.hh"
0030 #include "G4ParticleDefinition.hh"
0031 #include "G4ProcessManager.hh"
0032 #include "G4Run.hh"
0033 #include "G4SystemOfUnits.hh"
0034 #include "G4Transportation.hh"
0035 #include "globals.hh"
0036 
0037 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0038 
0039 void F01RunAction::BeginOfRunAction(const G4Run* aRun)
0040 {
0041   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
0042 
0043   G4cout << " Calling F01RunAction::ChangeLooperParameters() " << G4endl;
0044   ChangeLooperParameters(G4Electron::Definition());
0045 }
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 void F01RunAction::ChangeLooperParameters(const G4ParticleDefinition* particleDef)
0050 {
0051   if (particleDef == nullptr) particleDef = G4Electron::Definition();
0052   auto transport = FindTransportation(particleDef);
0053 
0054   // Note that all particles that share the same Transportation
0055   //  (or Coupled Transportation) process (with this particle)
0056   //  will be affected by this change
0057   //   -- to change these parameters by particle type, the values
0058   //      must instead be changed/reset in a (Start) Tracking Action.
0059 
0060   G4cout << " ChangeLooperParameters called with particle type " << particleDef->GetParticleName()
0061          << " transport process: ";
0062   if (transport != nullptr) {
0063     G4cout << transport->GetProcessName();
0064   }
0065   else {
0066     G4cout << " UNKNOWN -- it is neither G4Transportation nor G4CoupledTransportation";
0067   }
0068   G4cout << G4endl;
0069 
0070   if (transport != nullptr) {
0071     if (fWarningEnergy >= 0.0) {
0072       transport->SetThresholdWarningEnergy(fWarningEnergy);
0073       G4cout << "-- Changed Threshold Warning Energy (for loopers) = "
0074              << fWarningEnergy / CLHEP::MeV << " MeV " << G4endl;
0075     }
0076     if (fImportantEnergy >= 0.0) {
0077       transport->SetThresholdImportantEnergy(fImportantEnergy);
0078 
0079       G4cout << "-- Changed Threshold Important Energy (for loopers) = "
0080              << fImportantEnergy / CLHEP::MeV << " MeV " << G4endl;
0081     }
0082 
0083     if (fNumberOfTrials > 0) {
0084       transport->SetThresholdTrials(fNumberOfTrials);
0085 
0086       G4cout << "-- Changed number of Trials (for loopers) = " << fNumberOfTrials << G4endl;
0087     }
0088   }
0089 
0090   if (transport == nullptr) {
0091     if (fWarningEnergy >= 0.0)
0092       G4cerr << " Unknown transport process> Cannot change Warning Energy. " << G4endl;
0093     if (fImportantEnergy >= 0.0)
0094       G4cerr << " Unknown transport process> Cannot change 'Important' Energy. " << G4endl;
0095     if (fNumberOfTrials > 0)
0096       G4cerr << " Unknown transport process> Cannot change number of trials. " << G4endl;
0097   }
0098 }
0099 
0100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0101 
0102 void F01RunAction::EndOfRunAction(const G4Run*)
0103 {
0104   if (fVerboseLevel > 1)
0105     G4cout << G4endl << G4endl << " ###########  Track Statistics for Transportation process(es) "
0106            << " ########### " << G4endl << " ############################################## "
0107            << " ####################### " << G4endl << G4endl;
0108 
0109   auto transport = FindTransportation(G4Electron::Definition());
0110   if (transport) {
0111     transport->PrintStatistics(G4cout);
0112   }
0113 }
0114 
0115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0116 
0117 G4Transportation* F01RunAction::FindTransportation(const G4ParticleDefinition* particleDef,
0118                                                    bool reportError)
0119 {
0120   const auto* partPM = particleDef->GetProcessManager();
0121 
0122   G4VProcess* partTransport = partPM->GetProcess("Transportation");
0123   auto transport = dynamic_cast<G4Transportation*>(partTransport);
0124 
0125   if (!transport) {
0126     partTransport = partPM->GetProcess("CoupledTransportation");
0127     auto coupledTransport = dynamic_cast<G4CoupledTransportation*>(partTransport);
0128     if (coupledTransport) {
0129       transport = coupledTransport;
0130     }
0131     else {
0132       partTransport = partPM->GetProcess("TransportationWithMsc");
0133       auto transportWithMsc = dynamic_cast<G4CoupledTransportation*>(partTransport);
0134       if (transportWithMsc) {
0135         transport = transportWithMsc;
0136       }
0137     }
0138   }
0139 
0140   if (reportError && !transport) {
0141     G4cerr << "Unable to find Transportation process for particle type "
0142            << particleDef->GetParticleName() << "  ( PDG code = " << particleDef->GetPDGEncoding()
0143            << " ) " << G4endl;
0144   }
0145 
0146   return transport;
0147 }