RunAction::RunAction() { // add new units for dose // const G4double milligray = 1.e-3gray; const G4double microgray = 1.e-6gray; const G4double nanogray = 1.e-9gray; const G4double picogray = 1.e-12gray; new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray); new G4UnitDefinition("microgray", "microGy" , "Dose", microgray); new G4UnitDefinition("nanogray" , "nanoGy" , "Dose", nanogray); new G4UnitDefinition("picogray" , "picoGy" , "Dose", picogray); // Register accumulable to the accumulable manager G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); accumulableManager->RegisterAccumulable(fEdep); accumulableManager->RegisterAccumulable(fEdep2); }
时间: 2023-07-21 22:02:02 浏览: 60
这段代码是一个构造函数的实现,它用于向代码中添加新的剂量单位。在这里,定义了四个新的剂量单位:milligray、microgray、nanogray和picogray,并将它们注册到G4UnitDefinition中。接下来,代码将fEdep和fEdep2这两个变量注册到G4AccumulableManager中,以便将它们添加到累加器管理器中进行累积。
相关问题
G4int nofEvents = run->GetNumberOfEvent(); if (nofEvents == 0) return; // Merge accumulables G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); accumulableManager->Merge(); // Compute dose = total energy deposit in a run and its variance // G4double edep = fEdep.GetValue(); G4double edep2 = fEdep2.GetValue(); G4double rms = edep2 - edep*edep/nofEvents; if (rms > 0.) rms = std::sqrt(rms); else rms = 0.; const auto detConstruction = static_cast<const DetectorConstruction*>( G4RunManager::GetRunManager()->GetUserDetectorConstruction()); G4double mass = detConstruction->GetScoringVolume()->GetMass(); G4double dose = edep/mass; G4double rmsDose = rms/mass;
这段代码是RunAction类中的一部分,用于计算模拟运行期间的剂量。
首先,代码通过调用run->GetNumberOfEvent()获取当前运行(run)中的事件数,并将其赋值给nofEvents变量。如果事件数为0,则直接返回。
接下来,代码调用G4AccumulableManager::Instance()获取累加器管理器的实例,并调用Merge()方法将累加器的值进行合并。
然后,代码分别从fEdep和fEdep2累加器中获取能量沉积的累积值和平方和的累积值,并分别赋值给edep和edep2变量。
接下来,代码计算能量沉积的均方根(RMS),通过使用公式rms = edep2 - edep*edep/nofEvents。如果rms大于0,则使用std::sqrt(rms)计算平方根,否则将rms设置为0。
接下来,代码获取用户构建的探测器构造对象(detConstruction)以及其得分体积的质量,并将其赋值给mass变量。
最后,代码计算剂量(dose)和剂量的均方根(rmsDose),分别通过将edep和rms除以mass得到。
这段代码的目的是计算模拟运行期间的能量沉积和剂量,以便后续分析和结果解释。
void RunAction::AddEdep(G4double edep) { fEdep += edep; fEdep2 += edep*edep; }
这段代码是RunAction类中的AddEdep方法的实现。该方法接受一个G4double类型的参数edep,表示能量沉积值。
在方法内部,代码将edep的值加到fEdep变量上,用于累积总的能量沉积值。然后,代码计算edep的平方并将其加到fEdep2变量上,用于计算能量沉积的平方和。这样可以在模拟运行过程中不断更新能量沉积的累积值和平方和,以便后续的分析和处理。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)