Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4VBiasingOperator << 27 // ------------------------------------------- << 28 << 29 #include "G4VBiasingOperator.hh" 26 #include "G4VBiasingOperator.hh" 30 #include "G4VBiasingOperation.hh" 27 #include "G4VBiasingOperation.hh" 31 #include "G4VParticleChange.hh" 28 #include "G4VParticleChange.hh" >> 29 #include "G4BiasingTrackData.hh" >> 30 #include "G4BiasingTrackDataStore.hh" >> 31 32 32 33 G4MapCache< const G4LogicalVolume*, G4VBiasing 33 G4MapCache< const G4LogicalVolume*, G4VBiasingOperator* > G4VBiasingOperator::fLogicalToSetupMap; 34 G4VectorCache< G4VBiasingOperator* > G4VBiasin << 34 G4VectorCache< G4VBiasingOperator* > G4VBiasingOperator::fOperators; 35 G4Cache< G4BiasingOperatorStateNotifier* > G4V << 35 G4Cache< G4BiasingOperatorStateNotifier* > G4VBiasingOperator::fStateNotifier(0); >> 36 36 37 37 G4VBiasingOperator::G4VBiasingOperator(const G << 38 G4VBiasingOperator::G4VBiasingOperator(G4String name) 38 : fName( name ) << 39 : fName(name) 39 { 40 { 40 fOperators.Push_back(this); 41 fOperators.Push_back(this); 41 42 42 if ( fStateNotifier.Get() == nullptr ) << 43 if ( fStateNotifier.Get() == 0 ) fStateNotifier.Put( new G4BiasingOperatorStateNotifier() ); 43 fStateNotifier.Put( new G4BiasingOperatorS << 44 44 } 45 } 45 46 46 void G4VBiasingOperator::AttachTo(const G4Logi << 47 G4VBiasingOperator::~G4VBiasingOperator() 47 { 48 { 48 auto it = fLogicalToSetupMap.Find(logical); << 49 if ( it == fLogicalToSetupMap.End() ) << 50 { << 51 fLogicalToSetupMap[logical] = this; << 52 } << 53 else if ( (*it).second != this ) << 54 { << 55 G4ExceptionDescription ed; << 56 ed << "Biasing operator `" << GetName() << 57 << "' can not be attached to Logical vo << 58 << logical->GetName() << "' which is al << 59 << G4endl; << 60 G4Exception("G4VBiasingOperator::AttachTo( << 61 "BIAS.MNG.01", JustWarning, ed << 62 } << 63 } 49 } 64 50 65 const std::vector < G4VBiasingOperator* >& << 51 void G4VBiasingOperator::AttachTo(const G4LogicalVolume* logical) 66 G4VBiasingOperator::GetBiasingOperators() << 67 { 52 { 68 return fOperators.Get(); << 53 G4MapCache< const G4LogicalVolume*, G4VBiasingOperator* >::iterator it; >> 54 it = fLogicalToSetupMap.Find(logical); >> 55 if ( it == fLogicalToSetupMap.End() ) fLogicalToSetupMap[logical] = this; >> 56 else if ( (*it).second != this ) >> 57 { >> 58 G4ExceptionDescription ed; >> 59 ed << "Biasing operator `" << GetName() >> 60 << "' can not be attached to Logical volume `" >> 61 << logical->GetName() << "' which is already used by an other operator !" << G4endl; >> 62 G4Exception("G4VBiasingOperator::AttachTo(...)", >> 63 "BIAS.MNG.01", >> 64 JustWarning, >> 65 ed); >> 66 } 69 } 67 } 70 68 >> 69 71 G4VBiasingOperator* G4VBiasingOperator::GetBia 70 G4VBiasingOperator* G4VBiasingOperator::GetBiasingOperator(const G4LogicalVolume* logical) 72 { 71 { 73 auto it = fLogicalToSetupMap.Find(logical); << 72 G4MapCache< const G4LogicalVolume*, G4VBiasingOperator* >::iterator it; 74 if ( it == fLogicalToSetupMap.End() ) { retu << 73 it = fLogicalToSetupMap.Find(logical); 75 else { return (*it).second; } << 74 if ( it == fLogicalToSetupMap.End() ) return 0; >> 75 else return (*it).second; 76 } 76 } 77 77 78 G4VBiasingOperation* G4VBiasingOperator::GetPr 78 G4VBiasingOperation* G4VBiasingOperator::GetProposedOccurenceBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess) 79 { 79 { 80 fOccurenceBiasingOperation = ProposeOccurenc 80 fOccurenceBiasingOperation = ProposeOccurenceBiasingOperation(track, callingProcess); 81 return fOccurenceBiasingOperation; 81 return fOccurenceBiasingOperation; 82 } 82 } 83 83 84 G4VBiasingOperation* G4VBiasingOperator::GetPr 84 G4VBiasingOperation* G4VBiasingOperator::GetProposedFinalStateBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess) 85 { 85 { 86 fFinalStateBiasingOperation = ProposeFinalSt 86 fFinalStateBiasingOperation = ProposeFinalStateBiasingOperation(track, callingProcess); 87 return fFinalStateBiasingOperation; 87 return fFinalStateBiasingOperation; 88 } 88 } 89 89 90 G4VBiasingOperation* G4VBiasingOperator::GetPr 90 G4VBiasingOperation* G4VBiasingOperator::GetProposedNonPhysicsBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess) 91 { 91 { 92 fNonPhysicsBiasingOperation = ProposeNonPhys 92 fNonPhysicsBiasingOperation = ProposeNonPhysicsBiasingOperation(track, callingProcess); 93 return fNonPhysicsBiasingOperation; 93 return fNonPhysicsBiasingOperation; 94 } 94 } 95 95 96 void G4VBiasingOperator:: << 96 const G4VBiasingOperation* G4VBiasingOperator::GetBirthOperation( const G4Track* track ) 97 ReportOperationApplied( const G4BiasingProcess << 97 { 98 G4BiasingApplied << 98 const G4BiasingTrackData* biasingData = G4BiasingTrackDataStore::GetInstance()->GetBiasingTrackData(track); 99 G4VBiasingOperat << 99 if ( biasingData != 0 ) return biasingData->GetBirthOperation(); 100 const G4VParticleChang << 100 else return 0; >> 101 } >> 102 >> 103 >> 104 void G4VBiasingOperator::ReportOperationApplied( const G4BiasingProcessInterface* callingProcess, >> 105 G4BiasingAppliedCase biasingCase, >> 106 G4VBiasingOperation* operationApplied, >> 107 const G4VParticleChange* particleChangeProduced ) 101 { 108 { 102 fPreviousBiasingAppliedCase = biasingCase; 109 fPreviousBiasingAppliedCase = biasingCase; 103 fPreviousAppliedOccurenceBiasingOperation = << 110 fPreviousAppliedOccurenceBiasingOperation = 0; 104 fPreviousAppliedFinalStateBiasingOperation = << 111 fPreviousAppliedFinalStateBiasingOperation = 0; 105 fPreviousAppliedNonPhysicsBiasingOperation = << 112 fPreviousAppliedNonPhysicsBiasingOperation = 0; 106 switch ( biasingCase ) 113 switch ( biasingCase ) 107 { << 114 { 108 case BAC_None: 115 case BAC_None: 109 break; 116 break; 110 case BAC_NonPhysics: 117 case BAC_NonPhysics: 111 fPreviousAppliedNonPhysicsBiasingOperati 118 fPreviousAppliedNonPhysicsBiasingOperation = operationApplied ; 112 break; 119 break; >> 120 case BAC_DenyInteraction: >> 121 fPreviousAppliedOccurenceBiasingOperation = operationApplied; >> 122 break; 113 case BAC_FinalState: 123 case BAC_FinalState: 114 fPreviousAppliedFinalStateBiasingOperati 124 fPreviousAppliedFinalStateBiasingOperation = operationApplied; 115 break; 125 break; 116 case BAC_Occurence: 126 case BAC_Occurence: 117 G4Exception("G4VBiasingOperator::ReportO 127 G4Exception("G4VBiasingOperator::ReportOperationApplied(...)", 118 "BIAS.MNG.02", JustWarning, << 128 "BIAS.MNG.02", 119 "Internal logic error, pleas << 129 JustWarning, >> 130 "Internal logic error, please report !"); 120 break; 131 break; 121 default: 132 default: 122 G4Exception("G4VBiasingOperator::ReportO 133 G4Exception("G4VBiasingOperator::ReportOperationApplied(...)", 123 "BIAS.MNG.03", JustWarning, << 134 "BIAS.MNG.03", 124 "Internal logic error, pleas << 135 JustWarning, 125 } << 136 "Internal logic error, please report !"); >> 137 } 126 OperationApplied( callingProcess, biasingCas 138 OperationApplied( callingProcess, biasingCase, operationApplied, particleChangeProduced ); 127 } 139 } 128 140 129 void G4VBiasingOperator:: << 141 void G4VBiasingOperator::ReportOperationApplied( const G4BiasingProcessInterface* callingProcess, 130 ReportOperationApplied( const G4BiasingProcess << 142 G4BiasingAppliedCase biasingCase, 131 G4BiasingApplied << 143 G4VBiasingOperation* occurenceOperationApplied, 132 G4VBiasingOperat << 144 G4double weightForOccurenceInteraction, 133 G4double weightF << 145 G4VBiasingOperation* finalStateOperationApplied, 134 G4VBiasingOperat << 146 const G4VParticleChange* particleChangeProduced ) 135 const G4VParticleChang << 136 { 147 { 137 fPreviousBiasingAppliedCase = biasingCase; 148 fPreviousBiasingAppliedCase = biasingCase; 138 fPreviousAppliedOccurenceBiasingOperation = << 149 fPreviousAppliedOccurenceBiasingOperation = occurenceOperationApplied; 139 fPreviousAppliedFinalStateBiasingOperation = 150 fPreviousAppliedFinalStateBiasingOperation = finalStateOperationApplied; 140 OperationApplied( callingProcess, biasingCas 151 OperationApplied( callingProcess, biasingCase, occurenceOperationApplied, weightForOccurenceInteraction, finalStateOperationApplied, particleChangeProduced ); 141 } 152 } 142 153 143 void G4VBiasingOperator:: << 154 144 ExitingBiasing( const G4Track* track, const G4 << 155 void G4VBiasingOperator::ExitingBiasing( const G4Track* track, const G4BiasingProcessInterface* callingProcess ) 145 { 156 { 146 ExitBiasing( track, callingProcess ); 157 ExitBiasing( track, callingProcess ); 147 158 148 // -- reset all data members: 159 // -- reset all data members: 149 fOccurenceBiasingOperation << 160 fOccurenceBiasingOperation = 0 ; 150 fFinalStateBiasingOperation << 161 fFinalStateBiasingOperation = 0 ; 151 fNonPhysicsBiasingOperation << 162 fNonPhysicsBiasingOperation = 0 ; 152 fPreviousProposedOccurenceBiasingOperation << 163 fPreviousProposedOccurenceBiasingOperation = 0 ; 153 fPreviousProposedFinalStateBiasingOperation << 164 fPreviousProposedFinalStateBiasingOperation = 0 ; 154 fPreviousProposedNonPhysicsBiasingOperation << 165 fPreviousProposedNonPhysicsBiasingOperation = 0 ; 155 fPreviousAppliedOccurenceBiasingOperation << 166 fPreviousAppliedOccurenceBiasingOperation = 0 ; 156 fPreviousAppliedFinalStateBiasingOperation << 167 fPreviousAppliedFinalStateBiasingOperation = 0 ; 157 fPreviousAppliedNonPhysicsBiasingOperation << 168 fPreviousAppliedNonPhysicsBiasingOperation = 0 ; 158 fPreviousBiasingAppliedCase 169 fPreviousBiasingAppliedCase = BAC_None ; 159 } 170 } 160 171 161 // -- dummy empty implementations to allow let << 172 162 // -- but avoiding annoying warning messages a << 173 void G4VBiasingOperator::RememberSecondaries( const G4BiasingProcessInterface* callingProcess, 163 // -- methods to inform operator that its bias << 174 const G4VBiasingOperation* operationApplied, 164 void G4VBiasingOperator:: << 175 const G4VParticleChange* particleChangeProduced) 165 ExitBiasing( const G4Track*, const G4BiasingPr << 166 {} << 167 void G4VBiasingOperator:: << 168 OperationApplied( const G4BiasingProcessInterf << 169 G4VBiasingOperation*, const << 170 { 176 { >> 177 for (G4int i2nd = 0; i2nd < particleChangeProduced->GetNumberOfSecondaries (); i2nd++) >> 178 new G4BiasingTrackData( particleChangeProduced->GetSecondary (i2nd), >> 179 operationApplied, >> 180 this, >> 181 callingProcess); 171 } 182 } 172 void G4VBiasingOperator:: << 183 173 OperationApplied( const G4BiasingProcessInterf << 184 void G4VBiasingOperator::ForgetTrack( const G4Track* track ) 174 G4VBiasingOperation*, G4doub << 175 G4VBiasingOperation*, const << 176 { 185 { >> 186 G4BiasingTrackData* biasingData = G4BiasingTrackDataStore::GetInstance()->GetBiasingTrackData(track); >> 187 if ( biasingData != 0 ) delete biasingData; 177 } 188 } 178 189 >> 190 >> 191 // -- dummy empty implementations to allow letting arguments visible in the .hh >> 192 // -- but avoiding annoying warning messages about unused variables >> 193 // -- methods to inform operator that its biasing control is over: >> 194 void G4VBiasingOperator::ExitBiasing( const G4Track*, const G4BiasingProcessInterface*) >> 195 {} >> 196 void G4VBiasingOperator::OperationApplied( const G4BiasingProcessInterface*, G4BiasingAppliedCase, >> 197 G4VBiasingOperation*, const G4VParticleChange* ) >> 198 {} >> 199 void G4VBiasingOperator::OperationApplied( const G4BiasingProcessInterface*, G4BiasingAppliedCase, >> 200 G4VBiasingOperation*, G4double, >> 201 G4VBiasingOperation*, const G4VParticleChange* ) >> 202 {} >> 203 >> 204 179 // ------------------------------------------- 205 // ---------------------------------------------------------------------------- 180 // -- state machine to get biasing operators m 206 // -- state machine to get biasing operators messaged at the beginning of runs: 181 // ------------------------------------------- 207 // ---------------------------------------------------------------------------- 182 208 183 G4BiasingOperatorStateNotifier::G4BiasingOpera 209 G4BiasingOperatorStateNotifier::G4BiasingOperatorStateNotifier() 184 : G4VStateDependent() 210 : G4VStateDependent() 185 { 211 { 186 fPreviousState = G4State_PreInit; 212 fPreviousState = G4State_PreInit; 187 } 213 } 188 214 189 G4bool G4BiasingOperatorStateNotifier:: << 215 G4BiasingOperatorStateNotifier::~G4BiasingOperatorStateNotifier() 190 Notify( G4ApplicationState requestedState ) << 216 {} >> 217 >> 218 G4bool G4BiasingOperatorStateNotifier::Notify( G4ApplicationState requestedState ) 191 { 219 { 192 if ( ( fPreviousState == G4State_Idle ) << 220 if ( ( fPreviousState == G4State_Idle ) && ( requestedState == G4State_GeomClosed ) ) 193 && ( requestedState == G4State_GeomClosed << 194 { << 195 for ( auto i = 0; i < (G4int)G4VBiasingOpe << 196 { 221 { 197 G4VBiasingOperator::fOperators[i]->Start << 222 for ( size_t i = 0 ; i < G4VBiasingOperator::fOperators.Size() ; i++ ) G4VBiasingOperator::fOperators[i]->StartRun(); 198 } 223 } 199 } << 224 200 fPreviousState = requestedState; 225 fPreviousState = requestedState; 201 226 202 return true; 227 return true; 203 } 228 } 204 229