ATLAS Offline Software
LooperThresholdSet.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 "LooperThresholdSet.h"
6 #include <iostream>
7 
8 #include "G4Version.hh"
9 
10 #include "G4Electron.hh"
11 #include "G4ProcessManager.hh"
12 
13 #include "GaudiKernel/Bootstrap.h"
14 #include "GaudiKernel/ISvcLocator.h"
15 #include "GaudiKernel/IMessageSvc.h"
16 
17 namespace G4UA
18 {
19 
20 //---------------------------------------------------------------------------
22  AthMessaging(Gaudi::svcLocator()->service<IMessageSvc>("MessageSvc"), "LooperThresholdSet"),
23  m_config(config)
24 {
25 }
26 
27 //---------------------------------------------------------------------------
29 {
31 }
32 
33 void LooperThresholdSet::ChangeLooperParameters(const G4ParticleDefinition* particleDef)
34 {
35  if( particleDef == nullptr )
36  particleDef = G4Electron::Electron();
37  auto transportPair = findTransportation( particleDef );
38  auto transport = transportPair.first;
39  auto coupledTransport = transportPair.second;
40 
41  if( transport != nullptr )
42  {
43  // Change the values of the looping particle parameters of Transportation
44  ATH_MSG_INFO("Setting looper values of G4Transportation process...");
45  if( m_config.WarningEnergy >= 0.0 ) {
46  transport->SetThresholdWarningEnergy( m_config.WarningEnergy );
47  ATH_MSG_INFO("Set ThresholdWarningEnergy to " << m_config.WarningEnergy);
48  }
49  else
50  ATH_MSG_WARNING("Invalid ThresholdEnergy: " << m_config.WarningEnergy);
51  if( m_config.ImportantEnergy >= 0.0 ) {
52  transport->SetThresholdImportantEnergy( m_config.ImportantEnergy );
53  ATH_MSG_INFO("Set ImportantEnergy to " << m_config.ImportantEnergy);
54 
55  }
56  else
57  ATH_MSG_WARNING("Invalid ImportantEnergy: " << m_config.ImportantEnergy);
58  if( m_config.NumberOfTrials > 0 ) {
59  transport->SetThresholdTrials( m_config.NumberOfTrials );
60  ATH_MSG_INFO("Set NumberOfTrials to " << m_config.NumberOfTrials);
61 
62  }
63  else
64  ATH_MSG_WARNING("Invalid NumberOfTrials: " << m_config.NumberOfTrials);
65  // Geant4 printout
66 #if G4VERSION_NUMBER > 1049
67  transport->ReportLooperThresholds();
68 #endif
69  }
70  else if( coupledTransport != nullptr )
71  {
72  // Change the values for Coupled Transport
73  ATH_MSG_INFO("Setting looper values of G4CoupledTransportation process...");
74  if( m_config.WarningEnergy >= 0.0 ) {
75  coupledTransport->SetThresholdWarningEnergy( m_config.WarningEnergy );
76  ATH_MSG_INFO("Set ThresholdWarningEnergy to " << m_config.WarningEnergy);
77  }
78  else
79  ATH_MSG_WARNING("Invalid ThresholdEnergy: " << m_config.WarningEnergy);
80  if( m_config.ImportantEnergy >= 0.0 ) {
81  coupledTransport->SetThresholdImportantEnergy( m_config.ImportantEnergy );
82  ATH_MSG_INFO("Set ImportantEnergy to " << m_config.ImportantEnergy);
83 
84  }
85  else
86  ATH_MSG_WARNING("Invalid ImportantEnergy: " << m_config.ImportantEnergy);
87  if( m_config.NumberOfTrials > 0 ) {
88  coupledTransport->SetThresholdTrials( m_config.NumberOfTrials );
89  ATH_MSG_INFO("Set NumberOfTrials to " << m_config.NumberOfTrials);
90 
91  }
92  else
93  ATH_MSG_WARNING("Invalid NumberOfTrials: " << m_config.NumberOfTrials);
94  // Geant4 printout
95 #if G4VERSION_NUMBER > 1049
96  coupledTransport->ReportLooperThresholds();
97 #endif
98  }
99 }
100 
101 std::pair<G4Transportation*, G4CoupledTransportation*>
102 LooperThresholdSet::findTransportation( const G4ParticleDefinition* particleDef )
103 {
104  const auto *partPM = particleDef->GetProcessManager();
105 
106  G4VProcess* partTransport = partPM->GetProcess("Transportation");
107  auto transport = dynamic_cast<G4Transportation*>(partTransport);
108 
109  partTransport = partPM->GetProcess("CoupledTransportation");
110  auto coupledTransport=
111  dynamic_cast<G4CoupledTransportation*>(partTransport);
112 
113  return std::make_pair( transport, coupledTransport );
114 }
115 
116 } // namespace G4UA
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
G4UA::LooperThresholdSet::findTransportation
std::pair< G4Transportation *, G4CoupledTransportation * > findTransportation(const G4ParticleDefinition *particleDef, bool reportError)
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
G4UA::LooperThresholdSet::LooperThresholdSet
LooperThresholdSet()
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
G4UA::LooperThresholdSet::Config::ImportantEnergy
double ImportantEnergy
Definition: LooperThresholdSet.h:27
G4UA::LooperThresholdSet::Config::NumberOfTrials
int NumberOfTrials
Definition: LooperThresholdSet.h:28
G4UA::LooperThresholdSet::Config::WarningEnergy
double WarningEnergy
Definition: LooperThresholdSet.h:26
G4UA::LooperThresholdSet::BeginOfRunAction
virtual void BeginOfRunAction(const G4Run *aRun) override
Definition: LooperThresholdSet.cxx:28
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
LooperThresholdSet.h
G4UA::LooperThresholdSet::Config
Definition: LooperThresholdSet.h:25
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
G4UA::LooperThresholdSet::m_config
Config m_config
Definition: LooperThresholdSet.h:36
G4UA::LooperThresholdSet::ChangeLooperParameters
void ChangeLooperParameters(const G4ParticleDefinition *particleDef)
Definition: LooperThresholdSet.cxx:33