蒙特卡洛模擬GEANT4例子exampleB4a源碼解讀

上傳人:ail****e4 文檔編號(hào):60872281 上傳時(shí)間:2022-03-09 格式:DOC 頁(yè)數(shù):31 大?。?16KB
收藏 版權(quán)申訴 舉報(bào) 下載
蒙特卡洛模擬GEANT4例子exampleB4a源碼解讀_第1頁(yè)
第1頁(yè) / 共31頁(yè)
蒙特卡洛模擬GEANT4例子exampleB4a源碼解讀_第2頁(yè)
第2頁(yè) / 共31頁(yè)
蒙特卡洛模擬GEANT4例子exampleB4a源碼解讀_第3頁(yè)
第3頁(yè) / 共31頁(yè)

下載文檔到電腦,查找使用更方便

0 積分

下載資源

還剩頁(yè)未讀,繼續(xù)閱讀

資源描述:

《蒙特卡洛模擬GEANT4例子exampleB4a源碼解讀》由會(huì)員分享,可在線(xiàn)閱讀,更多相關(guān)《蒙特卡洛模擬GEANT4例子exampleB4a源碼解讀(31頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。

1、Geant4 ExampleB4a 源碼解讀 今天繼續(xù)簡(jiǎn)單講一下 exampleB4中的幾個(gè)子例子,先是 exampleB4a,仍然是采用 Steppi ngAction —步一步抽取事件,這種方法的好處是能夠很詳細(xì)的考慮、輸出每一步的信 息,但有時(shí)候我們只希望對(duì)感興趣部分(位置)進(jìn)行事件抽取,則用 SD和Hit要明顯方便 一些,例如在exampleB4c中用到的就是 SD和Hit進(jìn)行數(shù)據(jù)抽取。exampleB4a和exampleB4c 描述的是同一個(gè)幾何、物理過(guò)程,只是數(shù)據(jù)抽取的方式不同,因此將這兩個(gè)例子放在一起具 有比較意義。本次先對(duì) exampleB4a進(jìn)行講解。exampleB4

2、a計(jì)算了入射粒子(默認(rèn)電子,能 量50 MeV,軸向方向)在多層鉛-液氬材料中(由10個(gè)吸收體和間隙復(fù)制組成)的能量沉 積及帶電粒子(包括次級(jí)粒子)徑跡長(zhǎng)度。 圖1.幾何可視化及粒子輸運(yùn)可視化 exampleB4a.cc #in clude "B4DetectorCo nstructio n.hh" #in clude "B4aActio nlni tializatio n.hh" #ifdef G4MULTITHREADED #in clude "G4MTRu nMan ager.hh" #else #in clude "G4Ru nMan ager.hh" #en

3、 dif #in clude "G4UIma nager.hh" #in clude "G4UIcomma nd.hh" #include "FTFP_BERT.hh" #include "Randomize.hh" #include "G4VisExecutive.hh" #include "G4UIExecutive.hh" // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo namespace { void PrintUsage() { G4cerr << " Usage: " << G4endl; G4cerr <<

4、" exampleB4a [-m macro ] [-u UIsession] [-t nThreads]" << G4endl; G4cerr << " note: -t option is available only for multi-threaded mode." << G4endl; } } // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo int main(int argc,char** argv) { // Evaluate arguments // if ( argc > 7 ) { PrintUsage();

5、 return 1; } G4String macro; G4String session; #ifdef G4MULTITHREADED G4int nThreads = 0; #endif for ( G4int i=1; i

6、[i]) == "-t" ) { nThreads = G4UIcommand::ConvertToInt(argv[i+1]); } #endif else { PrintUsage(); return 1; } } // Detect interactive mode (if no macro provided) and define UI session // G4UIExecutive* ui = nullptr; if ( ! macro.size() ) { ui = new G4UIExecutive(argc, argv, session); } /

7、/ Optionally: choose a different Random engine... // // G4Random::setTheEngine(new CLHEP::MTwistEngine); // Construct the default run manager // #ifdef G4MULTITHREADED auto runManager = new G4MTRunManager; if ( nThreads > 0 ) { runManager->SetNumberOfThreads(nThreads); } #else auto runMana

8、ger = new G4RunManager; #endif // Set mandatory initialization classes // auto detConstruction = new B4DetectorConstruction(); runManager->SetUserInitialization(detConstruction); auto physicsList = new FTFP_BERT; runManager->SetUserInitialization(physicsList); auto actionInitialization = new B

9、4aActionInitialization(detConstruction); runManager->SetUserInitialization(actionInitialization); // Initialize visualization // auto visManager = new G4VisExecutive; // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. // G4VisManager* visManager = new G4VisExecutive("Q

10、uiet"); visManager->Initialize(); // Get the pointer to the User Interface manager auto UImanager = G4UImanager::GetUIpointer(); // Process macro or start UI session // if ( macro.size() ) { // batch mode G4String command = "/control/execute "; UImanager->ApplyCommand(command+macro); } els

11、e { // interactive mode : define UI session UImanager->ApplyCommand("/control/execute init_vis.mac"); if (ui->IsGUI()) { UImanager->ApplyCommand("/control/execute gui.mac"); } ui->SessionStart(); delete ui; } // Job termination // Free the store: user actions, physics_list and detector_des

12、cription are // owned and deleted by the run manager, so they should not be deleted // in the main() program ! delete visManager; delete runManager; 用戶(hù)在終端輸入字符串個(gè)數(shù)大于 7 則調(diào)用 PrintUsage 提示出錯(cuò),并返回 1,跳出 main() 函數(shù)。通過(guò)for循環(huán)對(duì)輸入字符串掃描識(shí)別,若程序名后字符串為" -m”給macro賦值該字 符串后一個(gè)字符串;若程序名后字符串為 “ -u”給session賦值該字符串后一個(gè)字符串,

13、 否則 調(diào)用PrintUsage提示出錯(cuò),并返回 1跳出main()函數(shù)。定義一個(gè) UI操作類(lèi)對(duì)象,ui指針 初始化空指針,若用戶(hù)沒(méi)有調(diào)用 macro 控制文件,則 new 一個(gè) ui 指針,分內(nèi)存空間辟。初 始化探測(cè)器、物理過(guò)程以及用戶(hù)行為,其中,用戶(hù)行為與探測(cè)器構(gòu)造有關(guān)。 new 一個(gè)可視化 管理器并對(duì)其初始化。定義一個(gè) UI 管理類(lèi),通過(guò)判斷條件 macro 是否為空,來(lái)決定執(zhí)行交 互式界面模式還是批處理模式。最后 delete所有管理類(lèi),釋放內(nèi)存。 B4DetectorConstruction.hh #ifndef B4DetectorConstruction_h #defin

14、e B4DetectorConstruction_h 1 #include "G4VUserDetectorConstruction.hh" #include "globals.hh" class G4VPhysicalVolume; class G4GlobalMagFieldMessenger; class B4DetectorConstruction : public G4VUserDetectorConstruction { public: B4DetectorConstruction(); virtual ~B4DetectorConstruction(); pu

15、blic: virtual G4VPhysicalV olume* Construct(); virtual void ConstructSDandField(); // get methods // const G4VPhysicalVolume* GetAbsorberPV() const; //const 修飾指針, 指針的內(nèi)存空間 數(shù)據(jù)不能改變;函數(shù)重載 const G4VPhysicalV olume* GetGapPV() const; private: // methods // void DefineMaterials(); G4VPhysicalV ol

16、ume* DefineV olumes(); // data members // static G4ThreadLocal G4GlobalMagFieldMessenger* fMagFieldMessenger; // magnetic field messenger G4VPhysicalV olume* fAbsorberPV; // the absorber physical volume G4VPhysicalV olume* fGapPV; // the gap physical volume G4bool fCheckOverlaps; // option to

17、 activate checking of volumes overlaps }; // inline functions inline const G4VPhysicalV olume* B4DetectorConstruction::GetAbsorberPV() const { return fAbsorberPV; } inline const G4VPhysicalV olume* B4DetectorConstruction::GetGapPV() const { return fGapPV; } B4DetectorConstruction 繼承于 G4VUse

18、rDetectorConstruction 基類(lèi), 聲明構(gòu)造函數(shù)、 析構(gòu) 函數(shù),Con struct。返回物理體。虛方法Con structSDa ndField()用于定義SD探測(cè)器以及空間內(nèi) 的電磁場(chǎng)。 GetAbsorberPV() 和 GetGapPV() 為自定義的內(nèi)聯(lián)函數(shù)在類(lèi)體外進(jìn)行定義,分別返 回物理體 fAbsorberPV 和 fGapPV (私有數(shù)據(jù)成員) 。 G4GlobalMagFieldMessenger 類(lèi)用于描 述電磁場(chǎng)的大小、方向等信息。 B4DetectorConstruction.cc B4DetectorConstruction::B4Detector

19、Construction() : G4VUserDetectorConstruction(), fAbsorberPV(nullptr), fGapPV(nullptr), fCheckOverlaps(true) // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo B4DetectorConstruction::~B4DetectorConstruction() { } // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo G4VPhysicalVolume* B4Det

20、ectorConstruction::Construct() { // Define materials DefineMaterials(); // Define volumes return DefineVolumes(); } // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo void B4DetectorConstruction::DefineMaterials() { // Lead material defined using NIST Manager auto nistManager = G4NistMana

21、ger::Instance(); nistManager->FindOrBuildMaterial("G4_Pb"); // Liquid argon material G4double a; // mass of a mole; G4double z; // z=mean number of protons; G4double density; new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3); // The argon by NIST Manager is a gas with

22、 a different density // Vacuum new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density, kStateGas, 2.73*kelvin, 3.e-18*pascal); // Print materials G4cout << *(G4Material::GetMaterialTable()) << G4endl; } // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo G4VPhysicalVolu

23、me* B4DetectorConstruction::DefineV olumes() { // Geometry parameters G4int nofLayers = 10; // 定義有多少層 copynumber G4double absoThickness = 10.*mm; G4double gapThickness = 5.*mm; G4double calorSizeXY = 10.*cm; //整體厚度 auto layerThickness = absoThickness + gapThickness; //一層厚度 auto calorThickne

24、ss = nofLayers * layerThickness; auto worldSizeXY = 1.2 * calorSizeXY; auto worldSizeZ = 1.2 * calorThickness; // Get materials auto defaultMaterial = G4Material::GetMaterial("Galactic"); auto absorberMaterial = G4Material::GetMaterial("G4_Pb"); auto gapMaterial = G4Material::GetMaterial("liqu

25、idArgon"); if ( ! defaultMaterial || ! absorberMaterial || ! gapMaterial ) { G4ExceptionDescription msg; msg << "Cannot retrieve materials already defined."; G4Exception("B4DetectorConstruction::DefineV olumes()", "MyCode0001", FatalException, msg); } // // World // auto worldS = new G4Box

26、("World", // its name worldSizeXY/2, worldSizeXY/2, worldSizeZ/2); // its size auto worldLV = new G4LogicalV olume( worldS, defaultMaterial, "World"); auto worldPV = new G4PVPlacement( 0, G4ThreeVector(), worldLV , "World", 0, false, 0, fCheckOverlaps); // // Calorimeter // auto calorime

27、terS // its solid // its material // its name // no rotation // at (0,0,0) // its logical volume // its name // its mother volume // no boolean operation // copy number // checking overlaps // its name = new G4Box("Calorimeter", calorSizeXY/2, calorSizeXY/2, calorThickness/2); // its si

28、ze auto calorLV = new G4LogicalV olume( calorimeterS, defaultMaterial, "Calorimeter"); new G4PVPlacement( 0, G4ThreeVector(), calorLV, "Calorimeter", worldLV , false, 0, fCheckOverlaps); // its solid // its material // its name // no rotation // at (0,0,0) // its logical volume // its n

29、ame // its mother volume // no boolean operation // copy number // checking overlaps // // Layer // auto layerS = new G4Box("Layer", // its name calorSizeXY/2, calorSize

30、XY/2, layerThickness/2); // its size auto layerLV = new G4LogicalV olume( layerS, // its solid defaultMaterial, // its material "Layer"); // its name new G4PVReplica( "Layer", // its name layerLV, // its logical volume calorLV, // its mother kZAxis, // axis of replication nofLayers, // num

31、ber of replica layerThickness); // witdth of replica // // Absorber // auto absorberS = new G4Box("Abso", // its name calorSizeXY/2, calorSizeXY/2, absoThickness/2); // its size auto absorberLV = new G4LogicalV olume( absorberS, // its solid absorberMaterial, // its material "Abso"); // it

32、s name fAbsorberPV = new G4PVPlacement( 0, // no rotation G4ThreeVector(0., 0., -gapThickness/2), // its position absorberLV, // its logical volume "Abso", layerLV, false, 0, fCheckOverlaps); // its name // its mother volume // no boolean operation // copy number // checking overlaps //

33、 // Gap // auto gapS = new G4Box("Gap", // its name calorSizeXY/2, calorSizeXY/2, gapThickness/2); // its size auto gapLV // its solid // its material // its name = new G4LogicalV olume( gapS, gapMaterial, "Gap"); fGapPV = new G4PVPlacement( 0, // no rotation G4ThreeVector(0., 0., absoT

34、hickness/2), // its position gapLV, // its logical volume "Gap", // its name layerLV, // its mother volume false, // no boolean operation 0, // copy number fCheckOverlaps); // checking overlaps // // print parameters // G4cout << G4endl << " " << G4endl << "---> The calorimeter is " << n

35、ofLayers << " layers of: [ " << absoThickness/mm << "mm of " << absorberMaterial->GetName() << " + " << gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] " << G4endl << " " << G4endl; // // Visualization attributes // worldLV->SetVisAttributes (G4VisAttributes::GetInvisible()); aut

36、o simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0)); simpleBoxVisAtt->SetVisibility(true); calorLV->SetVisAttributes(simpleBoxVisAtt); // // Always return the physical World // return worldPV; } // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo void B4DetectorConstruction::Constr

37、uctSDandField() { // Create global magnetic field messenger. // Uniform magnetic field is then created automatically if // the field value is not zero. G4ThreeVector fieldV alue; fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue); fMagFieldMessenger->SetVerboseLevel(1); // Registe

38、r the field messenger for deleting G4AutoDelete::Register(fMagFieldMessenger); } 在 con struct。函數(shù)中,定義了" Calorimeter ”、"Layer ”、“ Abso ” 以及"Gap ”四個(gè)邏輯 體,它們之間的關(guān)系是:構(gòu)建一個(gè)大長(zhǎng)方體" Calorimeter ”,往里面復(fù)制并放置 10個(gè)規(guī)格相 同的長(zhǎng)方體稱(chēng)之為層" Layer ”,再往"Layer ”中分別放置" Abso ”以及"Gap ”。在 ConstructSDandField() 函數(shù)體里,我們可以定義 SD 探測(cè)器以及空間

39、電磁場(chǎng), 在本例 exampleB4a中我們只是定義了電磁場(chǎng),可以通過(guò) run 1.mac中命令行控制磁場(chǎng)屬性: /globalField/setValue 0.2 0 0 tesla //設(shè)置均勻磁場(chǎng),強(qiáng)度 0.2特斯拉,方向沿 x軸 exampleB4c 中,我們?cè)?ConstructSDandField() 函數(shù)體里還定義了兩個(gè) SD 探測(cè)器,這樣 做簡(jiǎn)化了后續(xù)數(shù)據(jù)抽取工作中對(duì)每一個(gè) step 的位置判斷,具體怎么操作到 B4c 例中再說(shuō)。 B4aActionInitialization.hh #ifndef B4aActionInitialization_h #define

40、B4aActionInitialization_h 1 #include "G4VUserActionInitialization.hh" class B4DetectorConstruction; /// Action initialization class. /// class B4aActionInitialization : public G4VUserActionInitialization { public: B4aActionInitialization(B4DetectorConstruction*); virtual ~B4aActionInitializ

41、ation(); virtual void BuildForMaster() const; virtual void Build() const; private: B4DetectorConstruction* fDetConstruction; }; #endif 在構(gòu)造函數(shù)中,用到了 B4DetectorConstruction 類(lèi)的對(duì)象做形參,這是因?yàn)樵诤罄m(xù)判斷 粒子當(dāng)前位置過(guò)程中用到了探測(cè)器幾何, 用于獲取幾何的物理體, 后面會(huì)說(shuō), 這里只需要知 道用戶(hù)初始化過(guò)程用到了 B4DetectorConstruction 類(lèi)。 B4aActionInitialization

42、.cc B4aActionInitialization::B4aActionInitialization (B4DetectorConstruction* detConstruction) : G4VUserActionInitialization(), fDetConstruction(detConstruction) {} // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo B4aActionInitialization::~B4aActionInitialization() {} // oooOO0OOooo oooOO0

43、OOooo oooOO0OOooo oooOO0OOooo void B4aActionInitialization::BuildForMaster() const { SetUserAction(new B4RunAction); } // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo void B4aActionInitialization::Build() const { SetUserAction(new B4PrimaryGeneratorAction); SetUserAction(new B4RunAction

44、); auto eventAction = new B4aEventAction; SetUserAction(eventAction); SetUserAction(new B4aSteppingAction(fDetConstruction,eventAction)); //在 step 里面用 到了 fDetConstruction 變量 } 將 detConstruction 賦值給 fDetConstruction ,另外,對(duì)粒子發(fā)射器、 RunAction 、EventAction 進(jìn)行用戶(hù)行為設(shè)置,其中, B4aSteppingAction 用到了探測(cè)器幾何信息,一般

45、是用于位置判 斷。 SetUserAction(new B4aSteppingAction(fDetConstruction,eventAction)); B4PrimaryGeneratorAction.hh class G4ParticleGun; class G4Event; /// The primary generator action class with particle gum. /// /// It defines a single particle which hits the calorimeter /// perpendicular to the inp

46、ut face. The type of the particle /// can be changed via the G4 build-in commands of G4ParticleGun class /// (see the macros provided with this example). class B4PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction { public: B4PrimaryGeneratorAction(); virtual ~B4PrimaryGeneratorAction

47、(); virtual void GeneratePrimaries(G4Event* event); // set methods void SetRandomFlag(G4bool value); private: G4ParticleGun* fParticleGun; // G4 particle gun }; 粒子發(fā)射器用的是 G4ParticleGun 類(lèi)。 B4PrimaryGeneratorAction.cc #include "B4PrimaryGeneratorAction.hh" #include "G4RunManager.hh" #include

48、 "G4LogicalV olumeStore.hh" #include "G4LogicalV olume.hh" #include "G4Box.hh" #include "G4Event.hh" #include "G4ParticleGun.hh" #include "G4ParticleTable.hh" #include "G4ParticleDefinition.hh" #include "G4SystemOfUnits.hh" #include "Randomize.hh" // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooO

49、O0OOooo B4PrimaryGeneratorAction::B4PrimaryGeneratorAction() : G4VUserPrimaryGeneratorAction(), fParticleGun(nullptr) { G4int nofParticles = 1; fParticleGun = new G4ParticleGun(nofParticles); // default particle kinematic // auto particleDefinition = G4ParticleTable::GetParticleTable()->F

50、indParticle("e-"); fParticleGun->SetParticleDefinition(particleDefinition); fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.)); fParticleGun->SetParticleEnergy(50.*MeV); } // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo B4PrimaryGeneratorAction::~B4PrimaryGeneratorAction() {

51、 delete fParticleGun; } // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo void B4PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) { // This function is called at the begining of event // In order to avoid dependence of PrimaryGeneratorAction // on DetectorConstruction class we g

52、et world volume // from G4LogicalVolumeStore // G4double worldZHalfLength = 0.; // 將 auto worldLV = G4LogicalV olumeStore::GetInstance()->GetV olume("World"); G4LogicalVolumeStore 實(shí)例化,把存儲(chǔ)在 constructd 的邏輯體找出來(lái) // Check that the world volume has box shape G4Box* worldBox = nullptr; if ( worldLV

53、 ) { worldBox = dynamic_cast(worldLV->GetSolid()); 型 強(qiáng)制轉(zhuǎn)化成 box 型 } //把 world solid 類(lèi) if ( worldBox ) { worldZHalfLength = worldBox->GetZHalfLength(); // 抽取 word 的 Z 軸 半長(zhǎng) } else { G4ExceptionDescription msg; msg << "World volume of box shape not found." << G4endl; msg << "Perhaps y

54、ou have changed geometry." << G4endl; msg << "The gun will be place in the center."; G4Exception("B4PrimaryGeneratorAction::GeneratePrimaries()", "MyCode0002", JustWarning, msg); } // Set gun position fParticleGun ->SetParticlePosition(G4ThreeVector(0., 0., -worldZHalfLength)); //將源的位置定 義在 wor

55、d 體上的 x-y 面 fParticleGun->GeneratePrimaryVertex(anEvent); //調(diào)用,開(kāi)始 } 粒子槍的設(shè)置應(yīng)該一樣,設(shè)置一個(gè)默認(rèn)初始值(可以在 macro 中更改),默認(rèn)是電子發(fā) 射,電子能量 50 MeV ,方向沿 z 軸。在對(duì)源位置定義時(shí), 從 world 邏輯體中把實(shí)體 get 出來(lái) 后賦值給 worldBox 指針, 此時(shí) worldBox 指針的地址就是在幾何體中構(gòu)建的 world 實(shí)體, 通 過(guò) worldZHalfLength = worldBox->GetZHalfLength() ;就是將 world 實(shí)體指向的內(nèi)存空間的值

56、拿出來(lái)賦給 worldZHalfLength ,于是源的位置就出來(lái)了,是一個(gè)貼著 world 的 x-y 面的源。 然后每一個(gè) event 到來(lái)時(shí)調(diào)用 fParticleGun->GeneratePrimaryVertex(anEvent) ;發(fā)射粒子。 B4RunAction.hh class B4RunAction : public G4UserRunActi

57、on { public: B4RunAction(); virtual ~B4RunAction(); virtual void BeginOfRunAction(const G4Run*); virtual void EndOfRunAction(const G4Run*); }; B4RunAction 繼承于 G4UserRunAction 基類(lèi),構(gòu)造函數(shù)、 析構(gòu)函數(shù)以及每次 run 的 begin 和 end 虛方法。 B4RunAction.cc (Begin) B4RunAction::B4RunAction() : G4UserRunAction() {

58、// set printing event number per each event G4RunManager::GetRunManager()->SetPrintProgress(1); //通過(guò) RunManager 管理器 獲取進(jìn)程,并打印 // Create analysis manager // The choice of analysis technology is done via selectin of a namespace // in B4Analysis.hh auto analysisManager = G4AnalysisManager::Instanc

59、e(); // G4AnalysisManager 實(shí)例化對(duì) 象 analysisManager G4cout << "Using " << analysisManager->GetType() << G4endl; // Create directories //analysisManager->SetHistoDirectoryName("histograms"); //analysisManager->SetNtupleDirectoryName("ntuple"); // analysisManager->SetVerboseLevel(1); analysisManager-

60、>SetNtupleMerging(true); // Note: merging ntuples is available only with Root output // Book histograms, ntuple // // Creating histograms analysisManager->CreateH1("Eabs","Edep in absorber", 100, 0., 800*MeV); // 創(chuàng) 建 histogram analysisManager->CreateH1("Egap","Edep in gap", 100, 0., 100*MeV);

61、 analysisManager->CreateH1("Labs","trackL in absorber", 100, 0., 1*m); analysisManager->CreateH1("Lgap","trackL in gap", 100, 0., 50*cm); // Creating ntuple // 創(chuàng)建 ntuple/ 分支 // analysisManager->CreateNtuple("B4", "Edep and TrackL"); //ntuple 名稱(chēng): B4 analysisManager->CreateNtupleDColumn("Eabs"); a

62、nalysisManager->CreateNtupleDColumn("Egap"); analysisManager->CreateNtupleDColumn("Labs"); analysisManager->CreateNtupleDColumn("Lgap"); analysisManager->FinishNtuple(); } // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo B4RunAction::~B4RunAction() { delete G4AnalysisManager::Instance(); }

63、 // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo void B4RunAction::BeginOfRunAction(const G4Run* /*run*/) { //inform the runManager to save random number seed //G4RunManager::GetRunManager()->SetRandomNumberStore(true); // Get analysis manager auto analysisManager = G4AnalysisManager::Inst

64、ance(); // Open an output file // //打開(kāi) B4 文件 G4String fileName = "B4"; analysisManager->OpenFile(fileName); } 在 B4RunAction 的構(gòu)造函數(shù)中, 通過(guò) runmanager 獲取進(jìn)程, 設(shè)置每隔多少 event 打印出 event數(shù)。analysisManager指針開(kāi)始創(chuàng)建 histogram和ntuple用于數(shù)據(jù)存放, 相當(dāng)于在root中 新建一個(gè)TH1F和tree。析構(gòu)函數(shù)中,最后將刪除 analysisManager,釋放內(nèi)存空間。通過(guò) analysisM

65、anager打開(kāi)"B4”文件,用于在 EventAction中存儲(chǔ)信息。 B4aEventAction.hh class B4aEventAction : public G4UserEventAction { public: B4aEventAction(); virtual ~B4aEventAction(); virtual void BeginOfEventAction(const G4Event* event); virtual void EndOfEventAction(const G4Event* event); void AddAbs(G4double de,

66、G4double dl); //函數(shù),吸收體屬性 void AddGap(G4double de, G4double dl); //函數(shù),間隙屬性 private: G4double fEnergyAbs; G4double fEnergyGap; G4double fTrackLAbs; G4double fTrackLGap; }; // inline functions inline void B4aEventAction::AddAbs(G4double de, G4double dl) { fEnergyAbs += de; fTrackLAbs += dl; } inline void B4aEventAction::AddGap(G4double de, G4double dl) { fEnergyGap += de; fTrackLGap += dl; } // oooOO0OOooo oooOO0OOooo oooOO0OOooo oooOO0OOooo #endif 在 B4aEventAction 類(lèi)中自定義了兩個(gè)內(nèi)聯(lián)系函數(shù), A

展開(kāi)閱讀全文
溫馨提示:
1: 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

相關(guān)資源

更多
正為您匹配相似的精品文檔
關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話(huà):18123376007

備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


本站為文檔C2C交易模式,即用戶(hù)上傳的文檔直接被用戶(hù)下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng),我們立即給予刪除!