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 // G4VDecayChannel << 27 // 26 // 28 // Class description: << 27 // $Id: G4VDecayChannel.hh 93024 2015-09-30 15:59:32Z gcosmo $ 29 // 28 // 30 // Abstract class to describe decay kinematics << 29 // >> 30 // ------------------------------------------------------------ >> 31 // GEANT 4 class header file >> 32 // >> 33 // History: first implementation, based on object model of >> 34 // 27 July 1996 H.Kurashige >> 35 // 30 May 1997 H.Kurashige >> 36 // 23 Mar. 2000 H.Weber : add GetAngularMomentum() >> 37 // ------------------------------------------------------------ >> 38 #ifndef G4VDecayChannel_h >> 39 #define G4VDecayChannel_h 1 31 40 32 // Author: H.Kurashige, 27 July 1996 << 41 #include <cmath> 33 // ------------------------------------------- << 34 #ifndef G4VDecayChannel_hh << 35 #define G4VDecayChannel_hh 1 << 36 42 37 #include "G4AutoLock.hh" << 38 #include "G4Threading.hh" << 39 #include "G4ThreeVector.hh" << 40 #include "G4ios.hh" 43 #include "G4ios.hh" 41 #include "globals.hh" 44 #include "globals.hh" >> 45 #include "G4ThreeVector.hh" >> 46 /////@@#include "G4PDefSplitter.hh" 42 47 43 #include <cmath> << 48 class G4ParticleDefinition; 44 << 49 class G4DecayProducts; 45 class G4ParticleDefinition; << 50 class G4ParticleTable; 46 class G4DecayProducts; << 51 47 class G4ParticleTable; << 52 /////@@class G4DecayChannelData 48 << 53 /////@@{ >> 54 /////@@ // Encapsulates the fields associated to the class G4VDecayChannel that >> 55 /////@@ // may not be read-only. >> 56 /////@@ >> 57 /////@@ public: >> 58 /////@@ >> 59 /////@@ void initialize() >> 60 /////@@ { >> 61 /////@@ parent = 0; >> 62 /////@@ daughters = 0; >> 63 /////@@ parent_mass = 0.0; >> 64 /////@@ daughters_mass = 0; >> 65 /////@@ daughters_width = 0; >> 66 /////@@ } >> 67 /////@@ >> 68 /////@@ G4ParticleDefinition* parent; >> 69 /////@@ G4ParticleDefinition** daughters; >> 70 /////@@ G4double parent_mass; >> 71 /////@@ G4double* daughters_mass; >> 72 /////@@ G4double* daughters_width; >> 73 /////@@}; >> 74 /////@@ >> 75 /////@@// The type G4DecayChannelManager is introduced to encapsulate the methods used >> 76 /////@@// by both the master thread and worker threads to allocate memory space for >> 77 /////@@// the fields encapsulated by the class G4DecayChannelData. When each thread >> 78 /////@@// initializes the value for these fields, it refers to them using a macro >> 79 /////@@// definition defined below. For every G4DecayChannel instance, there is >> 80 /////@@// a corresponding G4DecayChannelData instance. All G4DecayChannelData >> 81 /////@@// instances are organized by the class G4DecayChannelManager as an array. >> 82 /////@@// The field "int instanceID" is added to the class G4DecayChannel. >> 83 /////@@// The value of this field in each G4DecayChannel instance is the subscript >> 84 /////@@// of the corresponding G4DecayChannelData instance. >> 85 /////@@// In order to use the class G4DecayChannelManager, we add a static member in >> 86 /////@@// G4DecayChannel as follows: "static G4DecayChannelManager subInstanceManager". >> 87 /////@@// For the master thread, the array for G4DecayChannelData instances grows >> 88 /////@@// dynamically along with G4DecayChannel instances are created. >> 89 /////@@// For each worker thread, it copies the array of G4DecayChannelData instances >> 90 /////@@// from the master thread. >> 91 /////@@// In addition, it invokes a method similiar to the constructor explicitly >> 92 /////@@// to achieve the partial effect for each instance in the array. >> 93 /////@@// >> 94 /////@@typedef G4PDefSplitter<G4DecayChannelData> G4DecayChannelManager; >> 95 /////@@ >> 96 /////@@// These macros change the references to fields that are now encapsulated >> 97 /////@@// in the class G4DecayChannelData. >> 98 /////@@// >> 99 /////@@#define G4MT_parent ((G4VDecayChannel::subInstanceManager.offset[instanceID]).parent) >> 100 /////@@#define G4MT_daughters ((G4VDecayChannel::subInstanceManager.offset[instanceID]).daughters) >> 101 /////@@#define G4MT_parent_mass ((G4VDecayChannel::subInstanceManager.offset[instanceID]).parent_mass) >> 102 /////@@#define G4MT_daughters_mass ((G4VDecayChannel::subInstanceManager.offset[instanceID]).daughters_mass) >> 103 /////@@#define G4MT_daughters_width ((G4VDecayChannel::subInstanceManager.offset[instanceID]).daughters_width) >> 104 /////@@ 49 class G4VDecayChannel 105 class G4VDecayChannel 50 { 106 { 51 public: << 107 // Class Description: 52 // Constructors << 108 // 53 G4VDecayChannel(const G4String& aName, G4i << 109 // Abstract class to describe decay kinematics 54 G4VDecayChannel(const G4String& aName, con << 110 55 G4int theNumberOfDaughters << 111 public: // with description 56 const G4String& theDaughte << 112 57 const G4String& theDaughte << 113 // Constructors >> 114 G4VDecayChannel(const G4String &aName, G4int Verbose = 1); >> 115 G4VDecayChannel(const G4String &aName, >> 116 const G4String& theParentName, >> 117 G4double theBR, >> 118 G4int theNumberOfDaughters, >> 119 const G4String& theDaughterName1, >> 120 const G4String& theDaughterName2 = "", >> 121 const G4String& theDaughterName3 = "", >> 122 const G4String& theDaughterName4 = "" ); 58 123 59 // Destructor 124 // Destructor 60 virtual ~G4VDecayChannel(); 125 virtual ~G4VDecayChannel(); 61 126 62 // Equality operators << 127 // equality operators 63 G4bool operator==(const G4VDecayChannel& r << 128 G4int operator==(const G4VDecayChannel &right) const {return (this == &right);} 64 G4bool operator!=(const G4VDecayChannel& r << 129 G4int operator!=(const G4VDecayChannel &right) const {return (this != &right);} 65 130 66 // Less-than operator is defined for G4Dec << 131 // less-than operator is defined for G4DecayTable 67 inline G4bool operator<(const G4VDecayChan << 132 G4int operator<(const G4VDecayChannel &right) const; 68 133 69 virtual G4DecayProducts* DecayIt(G4double 134 virtual G4DecayProducts* DecayIt(G4double parentMass = -1.0) = 0; 70 135 71 // Get kinematics name << 136 // get kinematics name 72 inline const G4String& GetKinematicsName() << 137 const G4String& GetKinematicsName() const; 73 << 138 // get branching ratio 74 // Get branching ratio << 139 G4double GetBR() const; 75 inline G4double GetBR() const; << 140 // get number of daughter particles 76 << 141 G4int GetNumberOfDaughters() const; 77 // Get number of daughter particles << 142 78 inline G4int GetNumberOfDaughters() const; << 143 // get the pointer to the parent particle 79 << 144 G4ParticleDefinition * GetParent(); 80 // Get the pointer to the parent particle << 145 // get the pointer to a daughter particle 81 inline G4ParticleDefinition* GetParent(); << 146 G4ParticleDefinition * GetDaughter(G4int anIndex); 82 147 83 // Get the pointer to a daughter particle << 148 // get the angular momentum of the decay 84 inline G4ParticleDefinition* GetDaughter(G << 85 << 86 // Get the angular momentum of the decay << 87 G4int GetAngularMomentum(); 149 G4int GetAngularMomentum(); >> 150 // get the name of the parent particle >> 151 const G4String& GetParentName() const; >> 152 //get the name of a daughter particle >> 153 const G4String& GetDaughterName(G4int anIndex) const; >> 154 >> 155 // get mass of parent >> 156 G4double GetParentMass() const; >> 157 G4double GetDaughterMass(G4int anIndex) const; >> 158 >> 159 // set the parent particle (by name or by pointer) >> 160 void SetParent(const G4ParticleDefinition * particle_type); >> 161 void SetParent(const G4String &particle_name); >> 162 // set branching ratio >> 163 void SetBR(G4double value); >> 164 // set number of daughter particles >> 165 void SetNumberOfDaughters(G4int value); >> 166 // set a daughter particle (by name or by pointer) >> 167 void SetDaughter(G4int anIndex, >> 168 const G4ParticleDefinition * particle_type); >> 169 void SetDaughter(G4int anIndex, >> 170 const G4String &particle_name); >> 171 >> 172 void SetVerboseLevel(G4int value); >> 173 G4int GetVerboseLevel() const; >> 174 void DumpInfo(); >> 175 >> 176 G4double GetRangeMass() const; >> 177 void SetRangeMass(G4double val); >> 178 virtual G4bool IsOKWithParentMass(G4double parentMass); >> 179 >> 180 void SetPolarization(const G4ThreeVector&); >> 181 const G4ThreeVector& GetPolarization() const; >> 182 >> 183 /////@@ >> 184 /////@@ // returns the instance ID. >> 185 /////@@ inline G4int GetInstanceID() const; >> 186 /////@@ // returns the private data instance manager. >> 187 /////@@ static const G4DecayChannelManager& GetSubInstanceManager(); 88 188 89 // Get the name of the parent particle << 189 protected: // with description 90 inline const G4String& GetParentName() con << 91 << 92 // Get the name of a daughter particle << 93 inline const G4String& GetDaughterName(G4i << 94 << 95 // Get mass of parent << 96 inline G4double GetParentMass() const; << 97 << 98 // Get mass of daughter << 99 inline G4double GetDaughterMass(G4int anIn << 100 190 101 // Set the parent particle (by name or by << 191 // clear daughters array 102 void SetParent(const G4ParticleDefinition* << 192 void ClearDaughtersName(); 103 inline void SetParent(const G4String& part << 104 << 105 // Set branching ratio << 106 void SetBR(G4double value); << 107 << 108 // Set number of daughter particles << 109 void SetNumberOfDaughters(G4int value); << 110 << 111 // Set a daughter particle (by name or by << 112 void SetDaughter(G4int anIndex, const G4Pa << 113 void SetDaughter(G4int anIndex, const G4St << 114 << 115 inline void SetVerboseLevel(G4int value); << 116 inline G4int GetVerboseLevel() const; << 117 void DumpInfo(); << 118 193 119 inline G4double GetRangeMass() const; << 194 // fill daughters array 120 inline void SetRangeMass(G4double val); << 195 void FillDaughters(); 121 virtual G4bool IsOKWithParentMass(G4double << 196 // fill parent >> 197 void FillParent(); 122 198 123 void SetPolarization(const G4ThreeVector&) << 199 protected: // without description 124 inline const G4ThreeVector& GetPolarizatio << 125 200 126 protected: << 201 // default constructor 127 // Default constructor << 128 G4VDecayChannel(); 202 G4VDecayChannel(); 129 203 130 // Copy constructor and assignment operato << 204 // copy constructor and assignment operator 131 G4VDecayChannel(const G4VDecayChannel&); << 205 G4VDecayChannel(const G4VDecayChannel &); 132 G4VDecayChannel& operator=(const G4VDecayC << 206 G4VDecayChannel & operator=(const G4VDecayChannel &); 133 207 134 // Clear daughters array << 208 private: 135 void ClearDaughtersName(); << 136 209 137 inline void CheckAndFillDaughters(); << 210 const G4String& GetNoName() const; 138 inline void CheckAndFillParent(); << 139 211 140 G4double DynamicalMass(G4double massPDG, G << 212 protected: >> 213 G4double DynamicalMass(G4double massPDG, G4double width, G4double maxDev = +1.) const; 141 214 142 protected: 215 protected: 143 // Kinematics name << 144 G4String kinematics_name = ""; << 145 // Branching ratio [0.0 - 1.0] << 146 G4double rbranch = 0.0; << 147 // Parent particle << 148 G4String* parent_name = nullptr; << 149 // Daughter particles << 150 G4String** daughters_name = nullptr; << 151 216 152 // Range of mass allowed in decay << 217 // kinematics name 153 G4double rangeMass = 2.5; << 218 G4String kinematics_name; >> 219 // branching ratio [0.0 - 1.0] >> 220 G4double rbranch; >> 221 // number of daughters >> 222 G4int numberOfDaughters; >> 223 // parent particle >> 224 G4String* parent_name; >> 225 // daughter particles >> 226 G4String** daughters_name; >> 227 >> 228 // range of mass allowed in decay >> 229 G4double rangeMass; 154 230 155 // Polarization of the parent particle << 231 // polarization of the parent particle 156 G4ThreeVector parent_polarization; 232 G4ThreeVector parent_polarization; >> 233 >> 234 // pointer to particle table >> 235 G4ParticleTable* particletable; 157 236 158 // Pointer to particle table << 237 // control flag for output message 159 G4ParticleTable* particletable = nullptr; << 238 G4int verboseLevel; 160 << 161 static const G4String noName; << 162 << 163 G4ParticleDefinition* G4MT_parent = nullpt << 164 G4ParticleDefinition** G4MT_daughters = nu << 165 G4double G4MT_parent_mass = 0.0; << 166 G4double* G4MT_daughters_mass = nullptr; << 167 G4double* G4MT_daughters_width = nullptr; << 168 G4Mutex daughtersMutex; << 169 G4Mutex parentMutex; << 170 << 171 // Number of daughters << 172 G4int numberOfDaughters = 0; << 173 << 174 // Control flag for output message << 175 // 0: Silent 239 // 0: Silent 176 // 1: Warning message 240 // 1: Warning message 177 // 2: More 241 // 2: More 178 G4int verboseLevel = 1; << 179 242 180 private: << 243 static const G4String noName; 181 // Fill daughters array << 182 void FillDaughters(); << 183 << 184 // Fill parent << 185 void FillParent(); << 186 244 187 const G4String& GetNoName() const; << 245 /////@@ // This field is used as instance ID. >> 246 /////@@ G4int instanceID; >> 247 /////@@ // This field helps to use the class G4DecayChannelManager introduced above. >> 248 /////@@ G4PART_DLL static G4DecayChannelManager subInstanceManager; >> 249 G4ParticleDefinition* G4MT_parent; >> 250 G4ParticleDefinition** G4MT_daughters; >> 251 G4double G4MT_parent_mass; >> 252 G4double* G4MT_daughters_mass; >> 253 G4double* G4MT_daughters_width; 188 }; 254 }; 189 255 190 // ------------------------------------------- 256 // ------------------------------------------------------------ 191 // Inline methods 257 // Inline methods 192 // ------------------------------------------- 258 // ------------------------------------------------------------ 193 259 194 inline G4bool G4VDecayChannel::operator<(const << 260 inline >> 261 G4int G4VDecayChannel::operator<(const G4VDecayChannel &right) const 195 { 262 { 196 return (this->rbranch < right.rbranch); 263 return (this->rbranch < right.rbranch); 197 } 264 } 198 265 199 inline G4ParticleDefinition* G4VDecayChannel:: << 266 inline 200 { << 267 G4ParticleDefinition* G4VDecayChannel::GetDaughter(G4int anIndex) 201 // pointers to daughter particles are filled << 268 { 202 CheckAndFillDaughters(); << 269 // pointers to daughter particles are filled, if they are not set yet >> 270 if (G4MT_daughters == 0) FillDaughters(); 203 271 204 // get the pointer to a daughter particle 272 // get the pointer to a daughter particle 205 if ((anIndex >= 0) && (anIndex < numberOfDau << 273 if ( (anIndex>=0) && (anIndex<numberOfDaughters) ) { 206 return G4MT_daughters[anIndex]; 274 return G4MT_daughters[anIndex]; >> 275 } else { >> 276 if (verboseLevel>0) >> 277 G4cout << "G4VDecayChannel::GetDaughter index out of range "<<anIndex<<G4endl; >> 278 return 0; 207 } 279 } 208 << 209 if (verboseLevel > 0) << 210 G4cout << "G4VDecayChannel::GetDaughter i << 211 return nullptr; << 212 } 280 } 213 281 214 inline const G4String& G4VDecayChannel::GetDau << 282 inline >> 283 const G4String& G4VDecayChannel::GetDaughterName(G4int anIndex) const 215 { 284 { 216 if ((anIndex >= 0) && (anIndex < numberOfDau << 285 if ( (anIndex>=0) && (anIndex<numberOfDaughters) ) { 217 return *daughters_name[anIndex]; 286 return *daughters_name[anIndex]; >> 287 } else { >> 288 if (verboseLevel>0){ >> 289 G4cout << "G4VDecayChannel::GetDaughterName "; >> 290 G4cout << "index out of range " << anIndex << G4endl; >> 291 } >> 292 return GetNoName(); 218 } 293 } 219 << 220 if (verboseLevel > 0) { << 221 G4cout << "G4VDecayChannel::GetDaughterNam << 222 G4cout << "index out of range " << anIndex << 223 } << 224 return GetNoName(); << 225 } 294 } 226 295 227 inline G4double G4VDecayChannel::GetDaughterMa << 296 inline >> 297 G4double G4VDecayChannel::GetDaughterMass(G4int anIndex) const 228 { 298 { 229 if ((anIndex >= 0) && (anIndex < numberOfDau << 299 if ( (anIndex>=0) && (anIndex<numberOfDaughters) ) { 230 return G4MT_daughters_mass[anIndex]; 300 return G4MT_daughters_mass[anIndex]; >> 301 } else { >> 302 if (verboseLevel>0){ >> 303 G4cout << "G4VDecayChannel::GetDaughterMass "; >> 304 G4cout << "index out of range " << anIndex << G4endl; >> 305 } >> 306 return 0.0; 231 } 307 } 232 << 233 if (verboseLevel > 0) { << 234 G4cout << "G4VDecayChannel::GetDaughterMas << 235 G4cout << "index out of range " << anIndex << 236 } << 237 return 0.0; << 238 } 308 } 239 309 240 inline G4ParticleDefinition* G4VDecayChannel:: << 310 inline 241 { << 311 G4ParticleDefinition* G4VDecayChannel::GetParent() 242 // the pointer to the parent particle is fil << 312 { 243 CheckAndFillParent(); << 313 // the pointer to the parent particle is filled, if it is not set yet >> 314 if (G4MT_parent == 0) FillParent(); 244 // get the pointer to the parent particle 315 // get the pointer to the parent particle 245 return G4MT_parent; 316 return G4MT_parent; 246 } 317 } 247 318 248 inline const G4String& G4VDecayChannel::GetPar << 319 inline >> 320 const G4String& G4VDecayChannel::GetParentName() const 249 { 321 { 250 return *parent_name; 322 return *parent_name; 251 } 323 } 252 324 253 inline G4double G4VDecayChannel::GetParentMass << 325 inline >> 326 G4double G4VDecayChannel::GetParentMass() const 254 { 327 { 255 return G4MT_parent_mass; 328 return G4MT_parent_mass; 256 } 329 } 257 330 258 inline void G4VDecayChannel::SetParent(const G << 331 inline >> 332 void G4VDecayChannel::SetParent(const G4String &particle_name) 259 { 333 { 260 delete parent_name; << 334 if (parent_name != 0) delete parent_name; 261 parent_name = new G4String(particle_name); 335 parent_name = new G4String(particle_name); 262 G4MT_parent = nullptr; << 336 G4MT_parent = 0; 263 } 337 } 264 338 265 inline G4int G4VDecayChannel::GetNumberOfDaugh << 339 inline 266 { << 340 G4int G4VDecayChannel::GetNumberOfDaughters() const 267 return numberOfDaughters; << 341 { >> 342 return numberOfDaughters; 268 } 343 } 269 344 270 inline const G4String& G4VDecayChannel::GetKin << 345 inline 271 { << 346 const G4String& G4VDecayChannel::GetKinematicsName() const { return kinematics_name; } 272 return kinematics_name; << 273 } << 274 347 275 inline G4double G4VDecayChannel::GetBR() const << 348 inline 276 { << 349 void G4VDecayChannel::SetBR(G4double value){ rbranch = value; } 277 return rbranch; << 278 } << 279 350 280 inline void G4VDecayChannel::SetVerboseLevel(G << 351 inline 281 { << 352 G4double G4VDecayChannel::GetBR() const { return rbranch; } 282 verboseLevel = value; << 283 } << 284 353 285 inline G4int G4VDecayChannel::GetVerboseLevel( << 354 inline 286 { << 355 void G4VDecayChannel::SetVerboseLevel(G4int value){ verboseLevel = value; } 287 return verboseLevel; << 288 } << 289 356 290 inline G4double G4VDecayChannel::GetRangeMass( << 357 inline 291 { << 358 G4int G4VDecayChannel::GetVerboseLevel() const { return verboseLevel; } 292 return rangeMass; << 293 } << 294 359 295 inline void G4VDecayChannel::SetRangeMass(G4do << 360 inline 296 { << 361 G4double G4VDecayChannel::GetRangeMass() const { return rangeMass; } 297 if (val >= 0.) rangeMass = val; << 298 } << 299 362 300 inline void G4VDecayChannel::SetPolarization(c << 363 inline >> 364 void G4VDecayChannel::SetRangeMass(G4double val){ if(val>=0.) rangeMass=val; } >> 365 >> 366 inline >> 367 void G4VDecayChannel::SetPolarization(const G4ThreeVector& polar) 301 { 368 { 302 parent_polarization = polar; 369 parent_polarization = polar; 303 } 370 } 304 371 305 inline const G4ThreeVector& G4VDecayChannel::G << 372 inline >> 373 const G4ThreeVector& G4VDecayChannel::GetPolarization() const 306 { 374 { 307 return parent_polarization; 375 return parent_polarization; 308 } 376 } 309 377 310 inline void G4VDecayChannel::CheckAndFillDaugh << 378 311 { << 379 /////@@inline 312 G4AutoLock l(&daughtersMutex); << 380 /////@@ G4int G4VDecayChannel::GetInstanceID() const { return instanceID; } 313 if (G4MT_daughters == nullptr) { << 314 l.unlock(); << 315 FillDaughters(); << 316 } << 317 } << 318 << 319 inline void G4VDecayChannel::CheckAndFillParen << 320 { << 321 G4AutoLock l(&parentMutex); << 322 if (G4MT_parent == nullptr) { << 323 l.unlock(); << 324 FillParent(); << 325 } << 326 } << 327 381 328 #endif 382 #endif 329 383