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 << 36 35 37 G4VBiasingOperator::G4VBiasingOperator(const G << 36 38 : fName( name ) << 37 G4VBiasingOperator::G4VBiasingOperator(G4String name) >> 38 : fName(name) 39 { 39 { 40 fOperators.Push_back(this); 40 fOperators.Push_back(this); >> 41 } 41 42 42 if ( fStateNotifier.Get() == nullptr ) << 43 G4VBiasingOperator::~G4VBiasingOperator() 43 fStateNotifier.Put( new G4BiasingOperatorS << 44 { 44 } 45 } 45 46 46 void G4VBiasingOperator::AttachTo(const G4Logi 47 void G4VBiasingOperator::AttachTo(const G4LogicalVolume* logical) 47 { 48 { 48 auto it = fLogicalToSetupMap.Find(logical); << 49 G4MapCache< const G4LogicalVolume*, G4VBiasingOperator* >::iterator it; 49 if ( it == fLogicalToSetupMap.End() ) << 50 it = fLogicalToSetupMap.Find(logical); 50 { << 51 if ( it == fLogicalToSetupMap.End() ) fLogicalToSetupMap[logical] = this; 51 fLogicalToSetupMap[logical] = this; << 52 } << 53 else if ( (*it).second != this ) 52 else if ( (*it).second != this ) 54 { << 53 { 55 G4ExceptionDescription ed; << 54 G4ExceptionDescription ed; 56 ed << "Biasing operator `" << GetName() << 55 ed << "Biasing operator `" << GetName() 57 << "' can not be attached to Logical vo << 56 << "' can not be attached to Logical volume `" 58 << logical->GetName() << "' which is al << 57 << logical->GetName() << "' which is already used by an other operator !" << G4endl; 59 << G4endl; << 58 G4Exception("G4VBiasingOperator::AttachTo(...)", 60 G4Exception("G4VBiasingOperator::AttachTo( << 59 "BIAS.MNG.01", 61 "BIAS.MNG.01", JustWarning, ed << 60 JustWarning, 62 } << 61 ed); >> 62 } 63 } 63 } 64 64 65 const std::vector < G4VBiasingOperator* >& << 66 G4VBiasingOperator::GetBiasingOperators() << 67 { << 68 return fOperators.Get(); << 69 } << 70 65 71 G4VBiasingOperator* G4VBiasingOperator::GetBia 66 G4VBiasingOperator* G4VBiasingOperator::GetBiasingOperator(const G4LogicalVolume* logical) 72 { 67 { 73 auto it = fLogicalToSetupMap.Find(logical); << 68 G4MapCache< const G4LogicalVolume*, G4VBiasingOperator* >::iterator it; 74 if ( it == fLogicalToSetupMap.End() ) { retu << 69 it = fLogicalToSetupMap.Find(logical); 75 else { return (*it).second; } << 70 if ( it == fLogicalToSetupMap.End() ) return 0; >> 71 else return (*it).second; 76 } 72 } 77 73 78 G4VBiasingOperation* G4VBiasingOperator::GetPr 74 G4VBiasingOperation* G4VBiasingOperator::GetProposedOccurenceBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess) 79 { 75 { 80 fOccurenceBiasingOperation = ProposeOccurenc 76 fOccurenceBiasingOperation = ProposeOccurenceBiasingOperation(track, callingProcess); >> 77 // G4cout << GetName() << " Occurence : "; >> 78 // if ( fOccurenceBiasingOperation ) G4cout << fOccurenceBiasingOperation->GetName() << G4endl; >> 79 // else G4cout << " (none) " << G4endl; 81 return fOccurenceBiasingOperation; 80 return fOccurenceBiasingOperation; 82 } 81 } 83 82 84 G4VBiasingOperation* G4VBiasingOperator::GetPr 83 G4VBiasingOperation* G4VBiasingOperator::GetProposedFinalStateBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess) 85 { 84 { 86 fFinalStateBiasingOperation = ProposeFinalSt 85 fFinalStateBiasingOperation = ProposeFinalStateBiasingOperation(track, callingProcess); >> 86 // G4cout << GetName() << " Final State : "; >> 87 // if ( fFinalStateBiasingOperation ) G4cout << fFinalStateBiasingOperation->GetName() << G4endl; >> 88 // else G4cout << " (none) " << G4endl; 87 return fFinalStateBiasingOperation; 89 return fFinalStateBiasingOperation; 88 } 90 } 89 91 90 G4VBiasingOperation* G4VBiasingOperator::GetPr 92 G4VBiasingOperation* G4VBiasingOperator::GetProposedNonPhysicsBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess) 91 { 93 { 92 fNonPhysicsBiasingOperation = ProposeNonPhys 94 fNonPhysicsBiasingOperation = ProposeNonPhysicsBiasingOperation(track, callingProcess); >> 95 // G4cout << GetName() << " Non Physics : "; >> 96 // if ( fNonPhysicsBiasingOperation ) G4cout << fNonPhysicsBiasingOperation->GetName() << G4endl; >> 97 // else G4cout << " (none) " << G4endl; 93 return fNonPhysicsBiasingOperation; 98 return fNonPhysicsBiasingOperation; 94 } 99 } 95 100 96 void G4VBiasingOperator:: << 101 // void G4VBiasingOperator::RegisterSecondariesBirth( G4VBiasingOperation* operation, const G4VParticleChange* pChange ) 97 ReportOperationApplied( const G4BiasingProcess << 102 // { 98 G4BiasingApplied << 103 // for (G4int i2nd = 0; i2nd < pChange->GetNumberOfSecondaries (); i2nd++) 99 G4VBiasingOperat << 104 // RegisterSecondaryBirth( operation, pChange->GetSecondary (i2nd) ); 100 const G4VParticleChang << 105 // } >> 106 >> 107 // void G4VBiasingOperator::RegisterSecondaryBirth( G4VBiasingOperation* operation, const G4Track* track ) >> 108 // { >> 109 // // G4cout << " --> Registering operation, track = " << operation->GetName() << " " << track << G4endl; >> 110 // fSecondaryBirthOperation[track] = operation; >> 111 // } >> 112 >> 113 const G4VBiasingOperation* G4VBiasingOperator::GetBirthOperation( const G4Track* track ) >> 114 { >> 115 const G4BiasingTrackData* biasingData = G4BiasingTrackDataStore::GetInstance()->GetBiasingTrackData(track); >> 116 if ( biasingData != 0 ) return biasingData->GetBirthOperation(); >> 117 else return 0; >> 118 } >> 119 >> 120 >> 121 void G4VBiasingOperator::ReportOperationApplied( const G4BiasingProcessInterface* callingProcess, >> 122 G4BiasingAppliedCase biasingCase, >> 123 G4VBiasingOperation* operationApplied, >> 124 const G4VParticleChange* particleChangeProduced ) 101 { 125 { 102 fPreviousBiasingAppliedCase = biasingCase; 126 fPreviousBiasingAppliedCase = biasingCase; 103 fPreviousAppliedOccurenceBiasingOperation = << 127 // if ( operationApplied != 0 ) 104 fPreviousAppliedFinalStateBiasingOperation = << 128 // { 105 fPreviousAppliedNonPhysicsBiasingOperation = << 129 // if ( operationApplied->GetRememberSecondaries() ) >> 130 // { >> 131 // for (G4int i2nd = 0; i2nd < particleChangeProduced->GetNumberOfSecondaries (); i2nd++) >> 132 // new G4BiasingTrackData( particleChangeProduced->GetSecondary (i2nd), >> 133 // operationApplied, >> 134 // this, >> 135 // callingProcess); >> 136 // } >> 137 // } >> 138 fPreviousAppliedOccurenceBiasingOperation = 0; >> 139 fPreviousAppliedFinalStateBiasingOperation = 0; >> 140 fPreviousAppliedNonPhysicsBiasingOperation = 0; 106 switch ( biasingCase ) 141 switch ( biasingCase ) 107 { << 142 { 108 case BAC_None: 143 case BAC_None: 109 break; 144 break; 110 case BAC_NonPhysics: 145 case BAC_NonPhysics: 111 fPreviousAppliedNonPhysicsBiasingOperati 146 fPreviousAppliedNonPhysicsBiasingOperation = operationApplied ; 112 break; 147 break; >> 148 case BAC_DenyInteraction: >> 149 fPreviousAppliedOccurenceBiasingOperation = operationApplied; >> 150 break; 113 case BAC_FinalState: 151 case BAC_FinalState: 114 fPreviousAppliedFinalStateBiasingOperati 152 fPreviousAppliedFinalStateBiasingOperation = operationApplied; 115 break; 153 break; 116 case BAC_Occurence: 154 case BAC_Occurence: 117 G4Exception("G4VBiasingOperator::ReportO 155 G4Exception("G4VBiasingOperator::ReportOperationApplied(...)", 118 "BIAS.MNG.02", JustWarning, << 156 "BIAS.MNG.02", 119 "Internal logic error, pleas << 157 JustWarning, >> 158 "Internal logic error, please report !"); 120 break; 159 break; 121 default: 160 default: 122 G4Exception("G4VBiasingOperator::ReportO 161 G4Exception("G4VBiasingOperator::ReportOperationApplied(...)", 123 "BIAS.MNG.03", JustWarning, << 162 "BIAS.MNG.03", 124 "Internal logic error, pleas << 163 JustWarning, 125 } << 164 "Internal logic error, please report !"); >> 165 } 126 OperationApplied( callingProcess, biasingCas 166 OperationApplied( callingProcess, biasingCase, operationApplied, particleChangeProduced ); 127 } 167 } 128 168 129 void G4VBiasingOperator:: << 169 void G4VBiasingOperator::ReportOperationApplied( const G4BiasingProcessInterface* callingProcess, 130 ReportOperationApplied( const G4BiasingProcess << 170 G4BiasingAppliedCase biasingCase, 131 G4BiasingApplied << 171 G4VBiasingOperation* occurenceOperationApplied, 132 G4VBiasingOperat << 172 G4double weightForOccurenceInteraction, 133 G4double weightF << 173 G4VBiasingOperation* finalStateOperationApplied, 134 G4VBiasingOperat << 174 const G4VParticleChange* particleChangeProduced ) 135 const G4VParticleChang << 136 { 175 { 137 fPreviousBiasingAppliedCase = biasingCase; 176 fPreviousBiasingAppliedCase = biasingCase; 138 fPreviousAppliedOccurenceBiasingOperation = << 177 // G4VBiasingOperation* operation(finalStateOperationApplied != 0 ? finalStateOperationApplied : occurenceOperationApplied); >> 178 // G4bool remember = occurenceOperationApplied->GetRememberSecondaries(); >> 179 // if ( finalStateOperationApplied != 0 ) remember = remember || finalStateOperationApplied->GetRememberSecondaries(); >> 180 // if ( remember ) >> 181 // { >> 182 // for (G4int i2nd = 0; i2nd < particleChangeProduced->GetNumberOfSecondaries (); i2nd++) >> 183 // new G4BiasingTrackData( particleChangeProduced->GetSecondary (i2nd), >> 184 // operation, >> 185 // this, >> 186 // callingProcess); >> 187 // } >> 188 fPreviousAppliedOccurenceBiasingOperation = occurenceOperationApplied; 139 fPreviousAppliedFinalStateBiasingOperation = 189 fPreviousAppliedFinalStateBiasingOperation = finalStateOperationApplied; 140 OperationApplied( callingProcess, biasingCas 190 OperationApplied( callingProcess, biasingCase, occurenceOperationApplied, weightForOccurenceInteraction, finalStateOperationApplied, particleChangeProduced ); 141 } 191 } 142 192 143 void G4VBiasingOperator:: << 193 144 ExitingBiasing( const G4Track* track, const G4 << 194 void G4VBiasingOperator::ExitingBiasing( const G4Track* track, const G4BiasingProcessInterface* callingProcess ) 145 { 195 { 146 ExitBiasing( track, callingProcess ); 196 ExitBiasing( track, callingProcess ); 147 197 148 // -- reset all data members: 198 // -- reset all data members: 149 fOccurenceBiasingOperation << 199 fOccurenceBiasingOperation = 0 ; 150 fFinalStateBiasingOperation << 200 fFinalStateBiasingOperation = 0 ; 151 fNonPhysicsBiasingOperation << 201 fNonPhysicsBiasingOperation = 0 ; 152 fPreviousProposedOccurenceBiasingOperation << 202 fPreviousProposedOccurenceBiasingOperation = 0 ; 153 fPreviousProposedFinalStateBiasingOperation << 203 fPreviousProposedFinalStateBiasingOperation = 0 ; 154 fPreviousProposedNonPhysicsBiasingOperation << 204 fPreviousProposedNonPhysicsBiasingOperation = 0 ; 155 fPreviousAppliedOccurenceBiasingOperation << 205 fPreviousAppliedOccurenceBiasingOperation = 0 ; 156 fPreviousAppliedFinalStateBiasingOperation << 206 fPreviousAppliedFinalStateBiasingOperation = 0 ; 157 fPreviousAppliedNonPhysicsBiasingOperation << 207 fPreviousAppliedNonPhysicsBiasingOperation = 0 ; 158 fPreviousBiasingAppliedCase 208 fPreviousBiasingAppliedCase = BAC_None ; 159 } 209 } 160 210 161 // -- dummy empty implementations to allow let << 162 // -- but avoiding annoying warning messages a << 163 // -- methods to inform operator that its bias << 164 void G4VBiasingOperator:: << 165 ExitBiasing( const G4Track*, const G4BiasingPr << 166 {} << 167 void G4VBiasingOperator:: << 168 OperationApplied( const G4BiasingProcessInterf << 169 G4VBiasingOperation*, const << 170 { << 171 } << 172 void G4VBiasingOperator:: << 173 OperationApplied( const G4BiasingProcessInterf << 174 G4VBiasingOperation*, G4doub << 175 G4VBiasingOperation*, const << 176 { << 177 } << 178 << 179 // ------------------------------------------- << 180 // -- state machine to get biasing operators m << 181 // ------------------------------------------- << 182 211 183 G4BiasingOperatorStateNotifier::G4BiasingOpera << 212 void G4VBiasingOperator::RememberSecondaries( const G4BiasingProcessInterface* callingProcess, 184 : G4VStateDependent() << 213 const G4VBiasingOperation* operationApplied, >> 214 const G4VParticleChange* particleChangeProduced) 185 { 215 { 186 fPreviousState = G4State_PreInit; << 216 for (G4int i2nd = 0; i2nd < particleChangeProduced->GetNumberOfSecondaries (); i2nd++) >> 217 new G4BiasingTrackData( particleChangeProduced->GetSecondary (i2nd), >> 218 operationApplied, >> 219 this, >> 220 callingProcess); 187 } 221 } 188 222 189 G4bool G4BiasingOperatorStateNotifier:: << 223 void G4VBiasingOperator::ForgetTrack( const G4Track* track ) 190 Notify( G4ApplicationState requestedState ) << 191 { 224 { 192 if ( ( fPreviousState == G4State_Idle ) << 225 G4BiasingTrackData* biasingData = G4BiasingTrackDataStore::GetInstance()->GetBiasingTrackData(track); 193 && ( requestedState == G4State_GeomClosed << 226 if ( biasingData != 0 ) delete biasingData; 194 { << 195 for ( auto i = 0; i < (G4int)G4VBiasingOpe << 196 { << 197 G4VBiasingOperator::fOperators[i]->Start << 198 } << 199 } << 200 fPreviousState = requestedState; << 201 << 202 return true; << 203 } 227 } >> 228 >> 229 >> 230 // -- dummy empty implementations to allow letting arguments visible in the .hh >> 231 // -- but avoiding annoying warning messages about unused variables >> 232 // -- methods to inform operator that its biasing control is over: >> 233 void G4VBiasingOperator::ExitBiasing( const G4Track*, const G4BiasingProcessInterface*) >> 234 {} >> 235 void G4VBiasingOperator::OperationApplied( const G4BiasingProcessInterface*, G4BiasingAppliedCase, >> 236 G4VBiasingOperation*, const G4VParticleChange* ) >> 237 {} >> 238 void G4VBiasingOperator::OperationApplied( const G4BiasingProcessInterface*, G4BiasingAppliedCase, >> 239 G4VBiasingOperation*, G4double, >> 240 G4VBiasingOperation*, const G4VParticleChange* ) >> 241 {} 204 242