This commit is contained in:
liuyihui 2023-02-13 14:50:36 +08:00
commit 3239ffb8e2
30 changed files with 10575 additions and 0 deletions

208
.clang-format Normal file
View File

@ -0,0 +1,208 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^[<"].*\.h[>"]'
Priority: 0
SortPriority: 0
CaseSensitive: false
- Regex: '^[<"].*\.hh[>"]'
Priority: 1
SortPriority: 1
CaseSensitive: false
- Regex: '.*'
Priority: 2
SortPriority: 2
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PenaltyIndentedWhitespace: 0
PointerAlignment: Left
PPIndentWidth: -1
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
CanonicalDelimiter: pb
BasedOnStyle: google
ReferenceAlignment: Pointer
ReflowComments: true
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

12
.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
# Build Cache
.xmake/
build/
bin/
lib/
# Settings
.vscode/*.json
!.vscode/c_cpp_properties.json
# Data
*.root

24
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${default}",
"${workspaceFolder}/include",
"/home/fox/G4Kit/Geant4/include",
"/home/fox/G4Kit/ROOT/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.xmake-tools"
}
],
"version": 4
}

8468
MyData.data Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,60 @@
#ifndef GENEANALYSISMANAGER_HH
#define GENEANALYSISMANAGER_HH 1
#define ANALYSIS_USE
#include "globals.hh"
#ifdef ANALYSIS_USE
#include "TFile.h"
#include "TROOT.h"
#include "TTree.h"
#endif
struct detEvent {
G4double Thetacm;
G4double Thetalab;
G4int Ndets;
G4double detE[24];
G4int detId[24];
};
class GeneAnalysisManager {
/**
* Analysis manager is a singleton object (there is only one instance).
* The pointer to this object is available through the use of the method GetInstance();
*
* @see GetInstance
*/
public:
GeneAnalysisManager();
~GeneAnalysisManager();
static GeneAnalysisManager *GetInstance();
void SetAnalysisFileName(G4String);
void FillAng(G4double thetacm, G4double thetalab);
void FillDetData(G4int ndets, G4double *edet, G4int *ndet);
// void EventNo();
#ifdef ANALYSIS_USE
void book();
void FillTree();
void save();
#endif
private:
static GeneAnalysisManager *instance;
struct detEvent mydata;
// G4int evtNo;
G4String analysisFileName;
#ifdef ANALYSIS_USE
TFile *theTFile;
TTree *tr;
#endif
};
#endif

View File

@ -0,0 +1,34 @@
#ifndef GeneDetectorConstruction_H
#define GeneDetectorConstruction_H 1
class G4LogicalVolume;
class G4VPhysicalVolume;
class GeneDetectorConstructionMessenger;
#include "G4VUserDetectorConstruction.hh"
#include "globals.hh"
class GeneDetectorConstruction : public G4VUserDetectorConstruction {
public:
GeneDetectorConstruction();
~GeneDetectorConstruction();
public:
G4VPhysicalVolume* Construct();
inline void SetZoffset(G4double val) { Zoffset = val; };
inline void SetZactiveshift(G4double val) { Zactiveshift = val; };
inline void SetBfraction(G4double val) { PE_Bfraction = val; };
inline void SetDetReaction(G4String val) { SReaction = val; };
private:
G4LogicalVolume* logicalWorld;
G4VPhysicalVolume* physicalWorld;
G4double Zoffset;
G4double Zactiveshift;
G4double PE_Bfraction;
G4String SReaction;
GeneDetectorConstructionMessenger* pMessenger;
};
#endif

View File

@ -0,0 +1,30 @@
#ifndef GeneDetectorConstructionMessenger_h
#define GeneDetectorConstructionMessenger_h 1
#include "G4UImessenger.hh"
#include "globals.hh"
class GeneDetectorConstruction;
class G4UIdirectory;
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithADouble;
class G4UIcmdWithAString;
class GeneDetectorConstructionMessenger : public G4UImessenger {
public:
GeneDetectorConstructionMessenger(GeneDetectorConstruction*);
virtual ~GeneDetectorConstructionMessenger();
virtual void SetNewValue(G4UIcommand*, G4String);
private:
GeneDetectorConstruction* pDetectorConstruction;
G4UIdirectory* DetectorDir;
G4UIcmdWithADoubleAndUnit* ZoffsetCmd;
G4UIcmdWithADoubleAndUnit* ZactiveshiftCmd;
G4UIcmdWithADouble* PE_BfractionCmd;
G4UIcmdWithAString* DetReactionCmd;
};
#endif

View File

@ -0,0 +1,24 @@
#ifndef GeneEventAction_HH
#define GeneEventAction_HH 1
#include "G4UserEventAction.hh"
#include "globals.hh"
class GeneEventAction : public G4UserEventAction {
public:
GeneEventAction();
virtual ~GeneEventAction();
public:
virtual void BeginOfEventAction(const G4Event*);
virtual void EndOfEventAction(const G4Event*);
inline void SetDrawFlag(G4String val) { drawFlag = val; };
void drawtracks(const G4Event*);
private:
G4int GeneHe3detSDCollID;
G4String drawFlag;
};
#endif

67
include/GeneHe3detHit.hh Normal file
View File

@ -0,0 +1,67 @@
#ifndef GeneHe3detHit_h
#define GeneHe3detHit_h 1
#include "G4Allocator.hh"
#include "G4THitsCollection.hh"
#include "G4ThreeVector.hh"
#include "G4VHit.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
class GeneHe3detHit : public G4VHit {
public:
GeneHe3detHit();
~GeneHe3detHit();
GeneHe3detHit(const GeneHe3detHit&);
const GeneHe3detHit& operator=(const GeneHe3detHit&);
int operator==(const GeneHe3detHit&) const;
inline void* operator new(size_t);
inline void operator delete(void*);
void Draw();
void Print();
public:
void SetCpNo(G4int id) { cpNo = id; };
void SetEdep(G4double de) { edep = de; };
void SetPos(G4ThreeVector xyz) { pos = xyz; };
void SetParticle(G4String name) { particleName = name; };
void SetParticleEnergy(G4double e1) { particleEnergy = e1; };
void SetTime(G4double t2) { HitTime = t2; };
inline G4int GetCpNo() { return cpNo; };
inline G4double GetEdep() { return edep; };
inline G4ThreeVector GetPos() { return pos; };
inline G4String GetParticle() { return particleName; };
inline G4double GetParticleEnergy() { return particleEnergy; };
inline G4double GetTime() { return HitTime; };
private:
G4int cpNo;
G4double edep;
G4ThreeVector pos;
G4double HitTime;
G4String particleName;
G4double particleEnergy;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
typedef G4THitsCollection<GeneHe3detHit> GeneHe3detHitsCollection;
extern G4Allocator<GeneHe3detHit> GeneHe3detHitAllocator;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
inline void* GeneHe3detHit::operator new(size_t) {
void* aHit;
aHit = (void*)GeneHe3detHitAllocator.MallocSingle();
return aHit;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
inline void GeneHe3detHit::operator delete(void* aHit) { GeneHe3detHitAllocator.FreeSingle((GeneHe3detHit*)aHit); }
#endif

30
include/GeneHe3detSD.hh Normal file
View File

@ -0,0 +1,30 @@
#ifndef GeneHe3detSD_HH
#define GeneHe3detSD_HH 1
#include "G4VSensitiveDetector.hh"
#include "GeneHe3detHit.hh"
#include "globals.hh"
class G4Step;
class G4HCofThisEvent;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
class GeneHe3detSD : public G4VSensitiveDetector {
public:
GeneHe3detSD(G4String);
~GeneHe3detSD();
void Initialize(G4HCofThisEvent*);
G4bool ProcessHits(G4Step*, G4TouchableHistory*);
void EndOfEvent(G4HCofThisEvent*);
void clear();
void DrawAll();
void PrintAll();
private:
GeneHe3detHitsCollection* scintillatorCollection;
G4int HitID;
};
#endif

View File

@ -0,0 +1,38 @@
#ifndef GenePrimaryGeneratorAction_H
#define GenePrimaryGeneratorAction_H 1
#include "G4VUserPrimaryGeneratorAction.hh"
#include "globals.hh"
class G4ParticleGun;
class G4Event;
class TH1F;
class GenePrimaryGeneratorActionMessenger;
class GenePrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction {
public:
GenePrimaryGeneratorAction();
~GenePrimaryGeneratorAction();
void GeneratePrimaries(G4Event* anEvent);
void SetBeamEnergy(G4double);
void SetAngType(G4String&);
void SetReaction(G4String&);
private:
G4ParticleGun* particleGun;
G4double fBeamEnergy;
G4double mass[4];
G4double beta;
G4double gamma;
G4double t3_cm;
G4double t4_cm;
G4double p3_cm;
G4double p4_cm;
TH1F* hAng;
G4int iReaction;
GenePrimaryGeneratorActionMessenger* pMessenger;
};
#endif

View File

@ -0,0 +1,28 @@
#ifndef GenePrimaryGeneratorActionMessenger_h
#define GenePrimaryGeneratorActionMessenger_h 1
#include "G4UImessenger.hh"
#include "globals.hh"
class GenePrimaryGeneratorAction;
class G4UIdirectory;
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithAString;
class GenePrimaryGeneratorActionMessenger : public G4UImessenger {
public:
GenePrimaryGeneratorActionMessenger(GenePrimaryGeneratorAction*);
virtual ~GenePrimaryGeneratorActionMessenger();
virtual void SetNewValue(G4UIcommand*, G4String);
private:
GenePrimaryGeneratorAction* pPrimaryGeneratorAction;
G4UIdirectory* PrimaryDir;
G4UIcmdWithADoubleAndUnit* BeamEnergyCmd;
G4UIcmdWithAString* AngularCmd;
G4UIcmdWithAString* ReactionCmd;
};
#endif

23
include/GeneRunAction.hh Normal file
View File

@ -0,0 +1,23 @@
#ifndef GeneRunAction_HH
#define GeneRunAction_HH 1
#include "G4UserRunAction.hh"
#include "globals.hh"
class G4String;
class GeneRunActionMessenger;
class GeneRunAction : public G4UserRunAction {
public:
GeneRunAction();
~GeneRunAction();
public:
void BeginOfRunAction(const G4Run*);
void EndOfRunAction(const G4Run*);
inline void SetRunNo(G4String val) { RunNo = val; };
G4String RunNo;
GeneRunActionMessenger* pMessenger;
};
#endif

View File

@ -0,0 +1,25 @@
#ifndef GeneRunActionMessenger_h
#define GeneRunActionMessenger_h 1
#include "G4UImessenger.hh"
#include "globals.hh"
class GeneRunAction;
class G4UIdirectory;
class G4UIcmdWithAString;
class GeneRunActionMessenger : public G4UImessenger {
public:
GeneRunActionMessenger(GeneRunAction*);
virtual ~GeneRunActionMessenger();
virtual void SetNewValue(G4UIcommand*, G4String);
private:
GeneRunAction* pRunAction;
G4UIdirectory* RunDir;
G4UIcmdWithAString* RunNoCmd;
};
#endif

16
init_vis.mac Normal file
View File

@ -0,0 +1,16 @@
# Macro file for the initialization of example B1
# in interactive session
#
# Set some default verbose
/control/verbose 2
/control/saveHistory
/run/verbose 2
#
# Change the default number of threads (in multi-threaded mode)
#/run/numberOfThreads 4
#
# Initialize kernel
/run/initialize
#
# Visualization setting
/control/execute vis.mac

43
integral.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <TFile.h>
#include <TTree.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
double e[24];
int id[24], N[1];
int sum1, sum2;
if (argc != 2) {
printf("usage: ./xxx <input root file>\n");
return 0;
}
TFile f(argv[1]);
if (f.IsZombie()) {
printf("cannot open root file\n");
return 0;
}
TTree* t = (TTree*)f.Get("SimData1");
if (!t) {
printf("cannot find tree!\n");
return 0;
}
t->SetBranchAddress("detE", e);
t->SetBranchAddress("detId", id);
t->SetBranchAddress("Ndets", N);
int n = t->GetEntries();
// printf("n=%d\n", n);
int i, j;
sum1 = sum2 = 0;
for (i = 0; i < n; i++) {
t->GetEntry(i);
for (j = 0; j < N[0]; j++) {
if (e[j] > 0.18 && id[j] < 12) {
sum1++;
}
if (e[j] > 0.18 && id[j] > 11) {
sum2++;
}
}
}
printf(" %s,%d,%d,%d,%f\n", argv[1], sum1 + sum2, sum1, sum2, 1.0 * sum1 / sum2);
return 0;
}

58
main.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "TROOT.h"
#include "time.h"
#include "G4RunManager.hh"
#include "G4SystemOfUnits.hh"
#include "G4UIExecutive.hh"
#include "G4UImanager.hh"
#include "G4UItcsh.hh"
#include "G4UIterminal.hh"
#include "G4UnitsTable.hh"
#include "G4VisExecutive.hh"
#include "GeneDetectorConstruction.hh"
#include "GeneEventAction.hh"
#include "GenePrimaryGeneratorAction.hh"
#include "GeneRunAction.hh"
#include "QGSP_BERT_HP.hh"
#include "Randomize.hh"
int main(int argc, char **argv) {
G4UIExecutive* ui = nullptr;
if (argc == 1) ui = new G4UIExecutive(argc, argv);
gROOT->GetInterpreter();
CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
CLHEP::HepRandom::setTheSeed(time(NULL));
// run manager
G4RunManager *runManager = new G4RunManager;
runManager->SetUserInitialization(new GeneDetectorConstruction);
G4VModularPhysicsList *physicsList = new QGSP_BERT_HP;
physicsList->SetVerboseLevel(1);
runManager->SetUserInitialization(physicsList);
runManager->SetUserAction(new GenePrimaryGeneratorAction);
runManager->SetUserAction(new GeneRunAction);
runManager->SetUserAction(new GeneEventAction);
runManager->Initialize();
G4VisManager *visManager = new G4VisExecutive;
G4UImanager *UIManager = G4UImanager::GetUIpointer();
visManager->Initialize();
if (!ui) {
G4String command = "/control/execute ";
G4String fileName = argv[1];
UIManager->ApplyCommand(command + fileName);
} else {
UIManager->ApplyCommand("/control/execute vis.mac");
ui->SessionStart();
delete ui;
}
delete visManager;
delete runManager;
return 0;
}

39
run.mac Normal file
View File

@ -0,0 +1,39 @@
# Macro file for the initialization phase of "Neutron.cc"
# Sets some default verbose and initializes the graphic.
#
#
# Some Settings
/control/verbose 1
/run/verbose 0
/tracking/verbose 0
# user setting
# 1st reaction
# 2nd energy
# 3rd angular
# reaction setting
/Gene/PrimaryGA/SetReaction C13an # V51pn or C13an
/Gene/Detector/SetDetReaction C13an # V51pn or C13an, default: C13an
# energy setting
/Gene/PrimaryGA/SetBeamEnergy 1.0 MeV # alpha energy for 13C(a,n)16O reaction
# proton energy for 51V(p,n)51Cr reaction
# angular setting
/Gene/PrimaryGA/SetAngular ISO # ISO or ENDF
# detector offset setting
/Gene/Detector/SetZoffset 0.0 mm # default: 0 mm
/Gene/Detector/SetZactiveshift 0.0 mm # default: 0 mm
# Boron fraction in PE moderator
/Gene/Detector/SetBfraction 0.054 # perCent, default: 0.054%
# user setting for runNo of output file
/Gene/Run/RunNo 00_C13an_ISO_1000keV_zoffset0mm_zshift0mm_B054_100000evts_Coll60mm
/run/initialize
# gsp particle
/gun/particle neutron
/run/beamOn 1000

View File

@ -0,0 +1,82 @@
#include "GeneAnalysisManager.hh"
GeneAnalysisManager* GeneAnalysisManager::instance = 0;
GeneAnalysisManager::GeneAnalysisManager()
#ifdef ANALYSIS_USE
: analysisFileName("Simulation_C13an.root"),
theTFile(0),
tr(0)
#endif
{
// evtNo = 0;
memset(&mydata, 0x00, sizeof(mydata));
}
GeneAnalysisManager::~GeneAnalysisManager() {
#ifdef ANALYSIS_USE
delete theTFile;
theTFile = 0;
delete tr;
tr = 0;
#endif
}
GeneAnalysisManager* GeneAnalysisManager::GetInstance() {
if (instance == 0) instance = new GeneAnalysisManager;
return instance;
}
void GeneAnalysisManager::SetAnalysisFileName(G4String aFileName) { analysisFileName = aFileName; }
void GeneAnalysisManager::FillDetData(G4int ndets, G4double* edet, G4int* ndet) {
mydata.Ndets = ndets;
for (G4int i = 0; i < ndets; i++) {
mydata.detE[i] = edet[i];
mydata.detId[i] = ndet[i];
}
}
void GeneAnalysisManager::FillAng(G4double thetacm, G4double thetalab) {
mydata.Thetacm = thetacm;
mydata.Thetalab = thetalab;
}
/*
void GeneAnalysisManager::EventNo(){
evtNo++;
}
*/
#ifdef ANALYSIS_USE
void GeneAnalysisManager::book() {
// delete all associated variables created via new, moreover it delete itself.
if (theTFile != 0) delete theTFile;
theTFile = new TFile(analysisFileName, "RECREATE");
// create a tree
tr = new TTree("SimData1", "C13an simulation data");
tr->Branch("Thetacm", &mydata.Thetacm, "Thetacm/D");
tr->Branch("Thetalab", &mydata.Thetalab, "Thetalab/D");
tr->Branch("Ndets", &mydata.Ndets, "Ndets/I");
tr->Branch("detE", mydata.detE, "detE[Ndets]/D");
tr->Branch("detId", mydata.detId, "detId[Ndets]/I");
}
void GeneAnalysisManager::FillTree() {
tr->Fill();
memset(&mydata, 0x00, sizeof(mydata));
}
// save data & close the file
void GeneAnalysisManager::save() {
if (theTFile) {
theTFile->Write();
theTFile->Close();
}
// evtNo = 0;
// G4cout<<" --> reactNum: "<< reactNum <<G4endl;
}
#endif

View File

@ -0,0 +1,563 @@
#include "GeneDetectorConstruction.hh"
#include "G4Box.hh"
#include "G4Colour.hh"
#include "G4LogicalVolume.hh"
#include "G4Material.hh"
#include "G4NistManager.hh"
#include "G4PVPlacement.hh"
#include "G4PhysicalConstants.hh"
#include "G4RotationMatrix.hh"
#include "G4SDManager.hh"
#include "G4SubtractionSolid.hh"
#include "G4SystemOfUnits.hh"
#include "G4ThreeVector.hh"
#include "G4Tubs.hh"
#include "G4VisAttributes.hh"
#include "GeneDetectorConstructionMessenger.hh"
#include "GeneHe3detSD.hh"
#include "globals.hh"
GeneDetectorConstruction::GeneDetectorConstruction() {
Zoffset = 0;
Zactiveshift = 0;
PE_Bfraction = 0.054;
SReaction = "C13an";
pMessenger = new GeneDetectorConstructionMessenger(this);
}
GeneDetectorConstruction::~GeneDetectorConstruction() { delete pMessenger; }
G4VPhysicalVolume* GeneDetectorConstruction::Construct() {
G4NistManager* manager = G4NistManager::Instance();
G4double density, temperature, pressure, fractionmass;
G4String name, symbol;
G4double z, n, a;
G4int ncomponents;
// world
G4Material* Air = manager->FindOrBuildMaterial("G4_AIR");
G4double world_xyz = 2. * m;
G4Box* solidWorld = new G4Box("world_S", 0.5 * world_xyz, 0.5 * world_xyz, 0.5 * world_xyz);
logicalWorld = new G4LogicalVolume(solidWorld, Air, "world_L", 0, 0, 0);
physicalWorld = new G4PVPlacement(0, G4ThreeVector(), "world_P", logicalWorld,
NULL, // mother volume
false, // no boolean operation
0); // copy number
logicalWorld->SetVisAttributes(G4VisAttributes::GetInvisible);
// Polyethylene
G4Material* polyethylene_Nist = manager->FindOrBuildMaterial("G4_POLYETHYLENE");
G4Material* boron_Nist = manager->FindOrBuildMaterial("G4_B");
// shielding PE
density = 0.938 * g / cm3;
G4Material* shield_mat = new G4Material("PE_B", density, ncomponents = 2);
shield_mat->AddMaterial(polyethylene_Nist, fractionmass = 93 * perCent);
shield_mat->AddMaterial(boron_Nist, fractionmass = 7 * perCent);
// moderator PE
G4Material* moderator_mat = new G4Material("PE_B_impurity", density, ncomponents = 2);
moderator_mat->AddMaterial(polyethylene_Nist, fractionmass = (100.0 - PE_Bfraction) * perCent);
moderator_mat->AddMaterial(boron_Nist, fractionmass = PE_Bfraction * perCent);
// shielding PE
G4double BPE_xyz = 60.0 * cm;
G4Box* BPE_box = new G4Box("BPE_box", 0.5 * BPE_xyz, 0.5 * BPE_xyz, 0.5 * BPE_xyz);
// moderator PE
G4double PE_xyz = 50.0 * cm;
G4Box* PE_box = new G4Box("PE_box", 0.5 * PE_xyz, 0.5 * PE_xyz, 0.5 * PE_xyz);
// Beam hole
G4double rMin0 = 0.;
G4double rMax0 = 5.0 * cm;
G4Tubs* PE_hole = new G4Tubs("PE_hole", rMin0, rMax0, 0.5 * BPE_xyz, 0, 360. * deg);
// He3 Tube holes
G4double active_len = 30 * cm; // length
G4double dead_len = 2 * cm;
G4double tube_r = 2.54 / 2 * cm; // radius
G4double tube_t = 0.5 * mm; // thickness
G4double gas_region_len = active_len + 2.0 * dead_len; // 32cm
G4double gas_region_r = tube_r - tube_t; // active region radius and dead region radius is the same
G4double tube_len = gas_region_len + 2 * tube_t; // 32.1cm
G4double tube_hole_len = 0.5 * BPE_xyz + 0.5 * active_len + dead_len + 1 * cm; // 48cm
G4double tube_hole_r = 0.5 * 2.745 * cm;
G4double tube_hole_z = -0.5 * BPE_xyz + 0.5 * tube_hole_len;
G4Tubs* He3tube_Hole = new G4Tubs("He3tube_Hole", 0, tube_hole_r, 0.5 * tube_hole_len, 0, 360. * deg);
// He3 Tubs
G4Material* tube_mat = manager->FindOrBuildMaterial("G4_STAINLESS-STEEL");
G4Isotope* isoHe3 = new G4Isotope(name = "He3", z = 2.0, n = 3.0, a = 3.016 * g / mole);
G4Element* elHe3 = new G4Element(name = "Helium3", symbol = "He3", ncomponents = 1);
elHe3->AddIsotope(isoHe3, 100.0 * perCent);
G4Element* elAr = new G4Element(name = "Argon", symbol = "Ar", z = 18.0, a = 39.948 * g / mole);
density = 4.38564 * mg / cm3; // 0.49074(3He)+3.8949(Ar) Calculate by LISE++
G4Material* WorkGas = new G4Material("WorkGas", density, ncomponents = 2, kStateGas, temperature = 300.00 * kelvin,
pressure = 6.4 * atmosphere); // 4atm3He+2.4atmAr
WorkGas->AddElement(elHe3, 11.1897 * perCent);
WorkGas->AddElement(elAr, 88.8103 * perCent);
G4Tubs* He3tub = new G4Tubs("He3tub", 0, tube_r, 0.5 * tube_len, 0, 360. * deg);
G4Tubs* He3gas = new G4Tubs("He3gas", 0, gas_region_r, 0.5 * gas_region_len, 0, 360. * deg);
G4Tubs* He3active = new G4Tubs("He3active", 0, gas_region_r, 0.5 * active_len, 0, 360. * deg);
G4SubtractionSolid* He3tub_sub = new G4SubtractionSolid("He3tub_sub", He3tub, He3gas);
G4RotationMatrix rot0;
G4SubtractionSolid* He3gas_sub =
new G4SubtractionSolid("He3tub_sub", He3gas, He3active, G4Transform3D(rot0, G4ThreeVector(0, 0, Zactiveshift)));
G4LogicalVolume* He3tub_log = new G4LogicalVolume(He3tub_sub, tube_mat, "He3tub_log");
G4LogicalVolume* He3gas_log = new G4LogicalVolume(He3gas_sub, WorkGas, "He3gas_log");
G4LogicalVolume* He3active_log = new G4LogicalVolume(He3active, WorkGas, "He3active_log");
// G4VisAttributes* He3gas_vis= new G4VisAttributes(G4Colour(1.0,1.0,0.0,0.1));
// He3gas_vis->SetForceSolid(true);
// He3gas_vis->SetForceWireframe(true);
// He3gas_log->SetVisAttributes(He3gas_vis);
G4VisAttributes* He3active_vis = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0));
He3active_vis->SetForceSolid(true);
He3active_log->SetVisAttributes(He3active_vis);
// He3gas_log -> SetVisAttributes(G4VisAttributes::GetInvisible);
He3tub_log->SetVisAttributes(G4VisAttributes::GetInvisible);
// He3active_log -> SetVisAttributes(G4VisAttributes::GetInvisible);
G4SubtractionSolid* solid_PE = new G4SubtractionSolid("solid_PE", PE_box, PE_hole);
G4SubtractionSolid* sub_BPE = new G4SubtractionSolid("sub_BPE", BPE_box, PE_box);
G4SubtractionSolid* solid_BPE = new G4SubtractionSolid("solid_BPE", sub_BPE, PE_hole);
char tmp[50];
G4double posx, posy;
for (G4int i = 0; i < 12; i++) {
posx = 8.5 * cm * std::cos(i * 30.0 * deg);
posy = 8.5 * cm * std::sin(i * 30.0 * deg);
sprintf(tmp, "solid_PE%d", i);
solid_PE = new G4SubtractionSolid(tmp, solid_PE, He3tube_Hole,
G4Transform3D(rot0, G4ThreeVector(posx, posy, tube_hole_z)));
sprintf(tmp, "solid_BPE%d", i);
solid_BPE = new G4SubtractionSolid(tmp, solid_BPE, He3tube_Hole,
G4Transform3D(rot0, G4ThreeVector(posx, posy, tube_hole_z)));
posx = 13.0 * cm * std::cos(i * 30.0 * deg + 15.0 * deg);
posy = 13.0 * cm * std::sin(i * 30.0 * deg + 15.0 * deg);
sprintf(tmp, "solid_PE%d", i + 12);
solid_PE = new G4SubtractionSolid(tmp, solid_PE, He3tube_Hole,
G4Transform3D(rot0, G4ThreeVector(posx, posy, tube_hole_z)));
sprintf(tmp, "solid_BPE%d", i + 12);
solid_BPE = new G4SubtractionSolid(tmp, solid_BPE, He3tube_Hole,
G4Transform3D(rot0, G4ThreeVector(posx, posy, tube_hole_z)));
}
// z offset for position measurement
G4LogicalVolume* PE_log = new G4LogicalVolume(solid_PE, moderator_mat, "logic_PE");
new G4PVPlacement(0, G4ThreeVector(0, 0, Zoffset), "PE_phys", PE_log, physicalWorld, false, 1, true);
G4LogicalVolume* BPE_log = new G4LogicalVolume(solid_BPE, shield_mat, "logic_BPE");
new G4PVPlacement(0, G4ThreeVector(0, 0, Zoffset), "BPE_phys", BPE_log, physicalWorld, false, 2, true);
G4VisAttributes* PE_vis = new G4VisAttributes(G4Colour(0.0, 0.8, 0.8, 0.5));
PE_vis->SetForceSolid(true);
// PE_vis->SetForceWireframe(true);
PE_log->SetVisAttributes(PE_vis);
// G4VisAttributes* BPE_vis= new G4VisAttributes(G4Colour(1.0,1.0,1.0,0.1));
// BPE_vis->SetForceSolid(true);
// BPE_vis->SetForceWireframe(true);
// BPE_log->SetVisAttributes(BPE_vis);
// PE_log -> SetVisAttributes(G4VisAttributes::GetInvisible);
BPE_log->SetVisAttributes(G4VisAttributes::GetInvisible);
G4double posz = tube_hole_len - 0.5 * BPE_xyz - 0.5 * tube_len;
for (G4int i = 0; i < 12; i++) {
posx = 8.5 * cm * std::cos(i * 30.0 * deg);
posy = 8.5 * cm * std::sin(i * 30.0 * deg);
sprintf(tmp, "He3tub_phys%d", i);
new G4PVPlacement(0, G4ThreeVector(posx, posy, posz + Zoffset), tmp, He3tub_log, physicalWorld, false, 100 + i,
true);
sprintf(tmp, "He3gas_phys%d", i);
new G4PVPlacement(0, G4ThreeVector(posx, posy, posz + Zoffset), tmp, He3gas_log, physicalWorld, false, 200 + i,
true);
sprintf(tmp, "He3active_phys%d", i);
new G4PVPlacement(0, G4ThreeVector(posx, posy, posz + Zoffset + Zactiveshift), tmp, He3active_log,
physicalWorld, false, 300 + i, true);
posx = 13.0 * cm * std::cos(i * 30.0 * deg + 15.0 * deg);
posy = 13.0 * cm * std::sin(i * 30.0 * deg + 15.0 * deg);
sprintf(tmp, "He3tub_phys%d", i + 12);
new G4PVPlacement(0, G4ThreeVector(posx, posy, posz + Zoffset), tmp, He3tub_log, physicalWorld, false,
100 + i + 12, true);
sprintf(tmp, "He3gas_phys%d", i + 12);
new G4PVPlacement(0, G4ThreeVector(posx, posy, posz + Zoffset), tmp, He3gas_log, physicalWorld, false,
200 + i + 12, true);
sprintf(tmp, "He3active_phys%d", i + 12);
new G4PVPlacement(0, G4ThreeVector(posx, posy, posz + Zoffset + Zactiveshift), tmp, He3active_log,
physicalWorld, false, 300 + i + 12, true);
}
G4VisAttributes* C13_vis = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0, 1.0));
C13_vis->SetForceSolid(true);
G4VisAttributes* CuSub_vis = new G4VisAttributes(G4Colour(0.1, 0.5, 0.7, 1.0));
CuSub_vis->SetForceSolid(true);
G4VisAttributes* tube_vis = new G4VisAttributes(G4Colour(0.8, 0.8, 0.8, 1.0));
tube_vis->SetForceSolid(true);
G4VisAttributes* water_vis = new G4VisAttributes(G4Colour(0.0, 0.0, 0.1, 1.0));
water_vis->SetForceSolid(true);
if (SReaction == "C13an") {
// C13 target
G4Isotope* isoC12 = new G4Isotope(name = "C12", z = 6.0, n = 12.0, a = 12.0 * g / mole);
G4Isotope* isoC13 = new G4Isotope(name = "C13", z = 6.0, n = 13.0, a = 13.003 * g / mole);
G4Element* elC = new G4Element(name = "Carbon", symbol = "C13", ncomponents = 2);
elC->AddIsotope(isoC12, 1.0 * perCent);
elC->AddIsotope(isoC13, 99.0 * perCent);
G4Material* targetC = new G4Material("targetC", density = 2.3 * g / cm3, ncomponents = 1);
targetC->AddElement(elC, 100 * perCent);
G4double C13thickness = 2.0 * mm;
G4Tubs* C13tub = new G4Tubs("C13tub", 0, 20. * mm, 0.5 * C13thickness, 0, 360. * deg);
G4LogicalVolume* C13log = new G4LogicalVolume(C13tub, targetC, "C13log");
new G4PVPlacement(0, G4ThreeVector(), "C13phys", C13log, physicalWorld, false, 3, true);
C13log->SetVisAttributes(C13_vis);
// C13log -> SetVisAttributes(G4VisAttributes::GetInvisible);
// Cu_Substrate
G4Material* Cu = manager->FindOrBuildMaterial("G4_Cu");
G4double Cu0thickness = 1.5 * mm;
G4double Cu0z = 0.5 * (C13thickness + Cu0thickness);
G4Tubs* CuSubstrate_tub0 =
new G4Tubs("CuSubstrate_tub0", 18. * mm, 25. * mm, 0.5 * Cu0thickness, 0, 360. * deg);
G4LogicalVolume* CuSubstrate_log0 = new G4LogicalVolume(CuSubstrate_tub0, Cu, "CuSubstrate_log0");
new G4PVPlacement(0, G4ThreeVector(0, 0, Cu0z), "CuSubstrate_phys1", CuSubstrate_log0, physicalWorld, false, 4,
true);
G4double Cu1thickness = C13thickness;
G4double Cu1z = 0.0 * mm;
G4Tubs* CuSubstrate_tub1 =
new G4Tubs("CuSubstrate_tub1", 20. * mm, 24.25 * mm, 0.5 * Cu1thickness, 0, 360. * deg);
G4LogicalVolume* CuSubstrate_log1 = new G4LogicalVolume(CuSubstrate_tub1, Cu, "CuSubstrate_log1");
new G4PVPlacement(0, G4ThreeVector(0, 0, Cu1z), "CuSubstrate_phys1", CuSubstrate_log1, physicalWorld, false, 5,
true);
G4double Cu2thickness = 3.5 * mm;
G4double Cu2z = -0.5 * (C13thickness + Cu2thickness);
G4Tubs* CuSubstrate_tub2 = new G4Tubs("CuSubstrate_tub2", 0, 24.25 * mm, 0.5 * Cu2thickness, 0, 360. * deg);
G4LogicalVolume* CuSubstrate_log2 = new G4LogicalVolume(CuSubstrate_tub2, Cu, "CuSubstrate_log2");
new G4PVPlacement(0, G4ThreeVector(0, 0, Cu2z), "CuSubstrate_phys2", CuSubstrate_log2, physicalWorld, false, 6,
true);
G4double Cu3thickness = 2.0 * mm;
G4double Cu3z = Cu2z - 0.5 * Cu2thickness - 0.5 * Cu3thickness;
G4Tubs* CuSubstrate_tub3 = new G4Tubs("CuSubstrate_tub3", 0, 29. * mm, 0.5 * Cu3thickness, 0, 360. * deg);
G4LogicalVolume* CuSubstrate_log3 = new G4LogicalVolume(CuSubstrate_tub3, Cu, "CuSubstrate_log3");
new G4PVPlacement(0, G4ThreeVector(0, 0, Cu3z), "CuSubstrate_phys3", CuSubstrate_log3, physicalWorld, false, 7,
true);
CuSubstrate_log0->SetVisAttributes(CuSub_vis);
CuSubstrate_log1->SetVisAttributes(CuSub_vis);
CuSubstrate_log2->SetVisAttributes(CuSub_vis);
CuSubstrate_log3->SetVisAttributes(CuSub_vis);
// CuSubstrate_log0 -> SetVisAttributes(G4VisAttributes::GetInvisible);
// CuSubstrate_log1 -> SetVisAttributes(G4VisAttributes::GetInvisible);
// CuSubstrate_log2 -> SetVisAttributes(G4VisAttributes::GetInvisible);
// CuSubstrate_log3 -> SetVisAttributes(G4VisAttributes::GetInvisible);
// Target flange
G4double flange0_thickness = 9.0 * mm;
G4double flange0z = Cu2z - 0.5 * Cu2thickness + 0.5 * flange0_thickness;
G4Tubs* flange_tub0 = new G4Tubs("flange_tub0", 25. * mm, 42.33 * mm, 0.5 * flange0_thickness, 0, 360. * deg);
G4LogicalVolume* flange_log0 = new G4LogicalVolume(flange_tub0, tube_mat, "flange_log0");
new G4PVPlacement(0, G4ThreeVector(0, 0, flange0z), "flange_phys0", flange_log0, physicalWorld, false, 8, true);
G4double flange1_thickness = 7.0 * mm;
G4double flange1z = flange0z - 0.5 * (flange0_thickness + flange1_thickness);
G4Tubs* flange_tub1 = new G4Tubs("flange_tub1", 29. * mm, 44.45 * mm, 0.5 * flange1_thickness, 0, 360. * deg);
G4LogicalVolume* flange_log1 = new G4LogicalVolume(flange_tub1, tube_mat, "flange_log1");
new G4PVPlacement(0, G4ThreeVector(0, 0, flange1z), "flange_phys1", flange_log1, physicalWorld, false, 9, true);
// BeamLine_stainlesss
G4double BeampipeLength = 60.0 * cm;
G4double Beampipez = flange0z - 0.5 * flange0_thickness + 0.5 * BeampipeLength;
G4Tubs* Beampipe_tub =
new G4Tubs("Beampipe_tub", 42.33 * mm, 44.45 * mm, 0.5 * BeampipeLength, 0. * deg, 360. * deg);
G4LogicalVolume* Beampipe_log = new G4LogicalVolume(Beampipe_tub, tube_mat, "Beampipe_log");
new G4PVPlacement(0, G4ThreeVector(0, 0, Beampipez), "Beampipe_phys", Beampipe_log, physicalWorld, false, 10,
true);
flange_log0->SetVisAttributes(tube_vis);
flange_log1->SetVisAttributes(tube_vis);
Beampipe_log->SetVisAttributes(tube_vis);
// Cold trap
G4double CuTrapLength = 50.0 * cm;
G4double CuTrapz = 0.5 * CuTrapLength + 12.0 * mm + 60.0 * mm;
G4Tubs* CuTrap_tub = new G4Tubs("CuTrap_tub", 28.0 * mm, 30.0 * mm, 0.5 * CuTrapLength, 0, 360. * deg);
G4LogicalVolume* CuTrap_log = new G4LogicalVolume(CuTrap_tub, Cu, "CuTrap_log");
new G4PVPlacement(0, G4ThreeVector(0, 0, CuTrapz), "CuTrap_phys", CuTrap_log, physicalWorld, false, 11, true);
CuTrap_log->SetVisAttributes(CuSub_vis);
// Suppressor
G4double CuSupLength = 1.0 * mm;
G4double CuSupz = 0.5 * CuSupLength + 8.0 * mm + 60.0 * mm;
G4Tubs* CuSup_tub = new G4Tubs("CuSup_tub", 15.0 * mm, 30.0 * mm, 0.5 * CuSupLength, 0, 360. * deg);
G4LogicalVolume* CuSup_log = new G4LogicalVolume(CuSup_tub, Cu, "CuSup_log");
new G4PVPlacement(0, G4ThreeVector(0, 0, CuSupz), "CuSup_phys", CuSup_log, physicalWorld, false, 12, true);
// Collimator
G4Material* Au = manager->FindOrBuildMaterial("G4_Au");
G4double AuCollLength = 3.0 * um;
G4double AuCollz = -0.5 * AuCollLength + 12.0 * mm + 60.0 * mm;
G4Tubs* AuColl_tub = new G4Tubs("AuColl_tub", 5.0 * mm, 28.0 * mm, 0.5 * AuCollLength, 0, 360. * deg);
G4LogicalVolume* AuColl_log = new G4LogicalVolume(AuColl_tub, Au, "AuColl_log");
new G4PVPlacement(0, G4ThreeVector(0, 0, AuCollz), "AuColl_phys", AuColl_log, physicalWorld, false, 13, true);
G4double CuColl0Length = 2.0 * mm;
G4double CuColl0z = 0.5 * CuColl0Length + 12.0 * mm + 60.0 * mm;
G4Tubs* CuColl_tub0 = new G4Tubs("CuColl_tub0", 5.0 * mm, 28.0 * mm, 0.5 * CuColl0Length, 0, 360. * deg);
G4LogicalVolume* CuColl_log0 = new G4LogicalVolume(CuColl_tub0, Cu, "CuColl_log0");
new G4PVPlacement(0, G4ThreeVector(0, 0, CuColl0z), "CuColl_phys0", CuColl_log0, physicalWorld, false, 14,
true);
G4double CuColl1Length = 3.0 * mm;
G4double CuColl1z = CuColl0z + 0.5 * CuColl0Length + 0.5 * CuColl1Length;
G4Tubs* CuColl_tub1 = new G4Tubs("CuColl_tub1", 25.0 * mm, 28.0 * mm, 0.5 * CuColl1Length, 0, 360. * deg);
G4LogicalVolume* CuColl_log1 = new G4LogicalVolume(CuColl_tub1, Cu, "CuColl_log1");
new G4PVPlacement(0, G4ThreeVector(0, 0, CuColl1z), "CuColl_phys1", CuColl_log1, physicalWorld, false, 15,
true);
// Vacuum
pressure = 1.0e-5 * pascal;
density = 1.29 * kg / m3 * pressure / atmosphere;
temperature = 77 * kelvin;
G4Material* Vacuum = new G4Material("Vacuum", density, ncomponents = 1, kStateGas, temperature, pressure);
Vacuum->AddMaterial(Air, 100.0 * perCent);
G4double VacuumLength = 70.0 * cm;
G4double Vacuumz = 0.5 * VacuumLength + Cu2z - 0.5 * Cu2thickness;
G4Tubs* Vacuum_tub = new G4Tubs("Vacuum_tub", 0, 42.33 * mm, 0.5 * VacuumLength, 0, 360. * deg);
G4double VacuumTflangez = -0.5 * VacuumLength + 0.5 * flange0_thickness;
G4SubtractionSolid* Vacuum_sub =
new G4SubtractionSolid("VacuumTflange_sub", Vacuum_tub, flange_tub0,
G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumTflangez))); // Target flange0
G4double VacuumCu2z = -0.5 * VacuumLength + 0.5 * Cu2thickness;
Vacuum_sub = new G4SubtractionSolid("Vacuum_sub2", Vacuum_sub, CuSubstrate_tub2,
G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumCu2z))); // Cu2
G4double VacuumCu1z = VacuumCu2z + 0.5 * Cu2thickness + 0.5 * Cu1thickness;
Vacuum_sub = new G4SubtractionSolid("Vacuum_sub1", Vacuum_sub, CuSubstrate_tub1,
G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumCu1z))); // Cu1
G4double VacuumCu0z = VacuumCu1z + 0.5 * Cu1thickness + 0.5 * Cu0thickness;
Vacuum_sub = new G4SubtractionSolid("Vacuum_sub0", Vacuum_sub, CuSubstrate_tub0,
G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumCu0z))); // Cu0
G4double VacuumC13z = VacuumCu1z;
Vacuum_sub = new G4SubtractionSolid("VacuumC13_sub", Vacuum_sub, C13tub,
G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumC13z))); // C13 target
G4double VacuumCuTrapz = VacuumC13z + 12.0 * mm + 0.5 * CuTrapLength + 60.0 * mm;
Vacuum_sub = new G4SubtractionSolid("VacuumCuTrap_sub", Vacuum_sub, CuTrap_tub,
G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumCuTrapz))); // Cu Trap
G4double VacuumCuSupz = VacuumC13z + 8.0 * mm + 0.5 * CuSupLength + 60.0 * mm;
Vacuum_sub = new G4SubtractionSolid("VacuumCuSup_sub", Vacuum_sub, CuSup_tub,
G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumCuSupz))); // Cu Suppressor
G4double VacuumAuCollz = VacuumC13z + 12.0 * mm - 0.5 * AuCollLength + 60.0 * mm;
Vacuum_sub = new G4SubtractionSolid("VacuumAuColl_sub", Vacuum_sub, AuColl_tub,
G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumAuCollz))); // Au Collimator
G4double VacuumCuColl0z = VacuumC13z + 12.0 * mm + 0.5 * CuColl0Length + 60.0 * mm;
Vacuum_sub =
new G4SubtractionSolid("VacuumCuColl_sub0", Vacuum_sub, CuColl_tub0,
G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumCuColl0z))); // Cu Collimator0
G4double VacuumCuColl1z = VacuumCuColl0z + 0.5 * CuColl0Length + 0.5 * CuColl1Length;
Vacuum_sub =
new G4SubtractionSolid("VacuumCuColl_sub1", Vacuum_sub, CuColl_tub1,
G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumCuColl1z))); // Cu Collimator1
G4LogicalVolume* Vacuum_log = new G4LogicalVolume(Vacuum_sub, Vacuum, "Vacuum_log");
new G4PVPlacement(0, G4ThreeVector(0, 0, Vacuumz), "Vacuum_phys", Vacuum_log, physicalWorld, false, 16, true);
// Water_cold
G4Material* water = manager->FindOrBuildMaterial("G4_WATER");
G4double WaterBack_thickness = 1.0 * mm;
G4double WaterBackz = Cu3z - 0.5 * Cu3thickness - 0.5 * WaterBack_thickness;
G4Tubs* WaterBack_tub =
new G4Tubs("WaterBack_tub", 0, 29.0 * mm, 0.5 * WaterBack_thickness, 0. * deg, 360. * deg);
G4LogicalVolume* WaterBack_log = new G4LogicalVolume(WaterBack_tub, water, "WaterBack_log");
new G4PVPlacement(0, G4ThreeVector(0, 0, WaterBackz), "WaterBack_phys", WaterBack_log, physicalWorld, false, 17,
true);
WaterBack_log->SetVisAttributes(water_vis);
// Al Substrate
G4Material* Al = manager->FindOrBuildMaterial("G4_Al");
G4double Al0thickness = 4.0 * mm;
G4double Al0z = WaterBackz - 0.5 * WaterBack_thickness - 0.5 * Al0thickness;
G4Tubs* AlSubstrate_tub0 =
new G4Tubs("AlSubstrate_tub0", 0, 29.0 * mm, 0.5 * Al0thickness, 0. * deg, 360. * deg);
G4LogicalVolume* AlSubstrate_log0 = new G4LogicalVolume(AlSubstrate_tub0, Al, "AlSubstrate_log0");
G4PVPlacement* Al0phys = new G4PVPlacement(0, G4ThreeVector(0, 0, Al0z), "AlSubstrate_phys0", AlSubstrate_log0,
physicalWorld, false, 18, true);
AlSubstrate_log0->SetVisAttributes(tube_vis);
G4double Al1thickness = 4.0 * mm;
G4double Al1z = Al0z - 0.5 * Al0thickness - 0.5 * Al1thickness;
G4Tubs* AlSubstrate_tub1 =
new G4Tubs("AlSubstrate_tub1", 0, 44.45 * mm, 0.5 * Al1thickness, 0. * deg, 360. * deg);
G4LogicalVolume* AlSubstrate_log1 = new G4LogicalVolume(AlSubstrate_tub1, Al, "AlSubstrate_log1");
G4PVPlacement* Al1phys = new G4PVPlacement(0, G4ThreeVector(0, 0, Al1z), "AlSubstrate_phys1", AlSubstrate_log1,
physicalWorld, false, 19, true);
AlSubstrate_log1->SetVisAttributes(tube_vis);
// Waterpipe
G4double Waterpipe0_thickness = 4.0 * mm;
G4Tubs* Waterpipe_tub0 =
new G4Tubs("Waterpipe_tub0", 0, 2.5 * mm, 0.5 * Waterpipe0_thickness, 0. * deg, 360. * deg);
G4LogicalVolume* Waterpipe_log0 = new G4LogicalVolume(Waterpipe_tub0, water, "Waterpipe_log0");
new G4PVPlacement(0, G4ThreeVector(0, 21.5 * mm, 0), "Waterpipe_phys00", Waterpipe_log0, Al0phys, false, 20,
true);
new G4PVPlacement(0, G4ThreeVector(0, -21.5 * mm, 0), "Waterpipe_phys01", Waterpipe_log0, Al0phys, false, 21,
true);
new G4PVPlacement(0, G4ThreeVector(0, 21.5 * mm, 0), "Waterpipe_phys02", Waterpipe_log0, Al1phys, false, 22,
true);
new G4PVPlacement(0, G4ThreeVector(0, -21.5 * mm, 0), "Waterpipe_phys03", Waterpipe_log0, Al1phys, false, 23,
true);
G4double Waterpipe1_thickness = BPE_xyz / 2.0 + 10.0 * cm;
G4double Waterpipe1z = Al1z - 0.5 * Al1thickness - 0.5 * Waterpipe1_thickness;
G4Tubs* Waterpipe_tub1 =
new G4Tubs("Waterpipe_tub1", 0, 2.5 * mm, 0.5 * Waterpipe1_thickness, 0. * deg, 360. * deg);
G4LogicalVolume* Waterpipe_log1 = new G4LogicalVolume(Waterpipe_tub1, water, "Waterpipe_log1");
new G4PVPlacement(0, G4ThreeVector(0, 21.5 * mm, Waterpipe1z), "Waterpipe_phys1", Waterpipe_log1, physicalWorld,
false, 24, true);
new G4PVPlacement(0, G4ThreeVector(0, -21.5 * mm, Waterpipe1z), "Waterpipe_phys2", Waterpipe_log1,
physicalWorld, false, 25, true);
Waterpipe_log0->SetVisAttributes(water_vis);
Waterpipe_log1->SetVisAttributes(water_vis);
} else if (SReaction == "V51pn") {
// V51 on Ta target
G4Material* Ta = manager->FindOrBuildMaterial("G4_Ta");
G4double Tathickness = 1.0 * mm;
G4Tubs* Tatub = new G4Tubs("Tatub", 0, 15. * mm, 0.5 * Tathickness, 0, 360. * deg);
G4LogicalVolume* Talog = new G4LogicalVolume(Tatub, Ta, "Talog");
new G4PVPlacement(0, G4ThreeVector(), "Taphys", Talog, physicalWorld, false, 3, true);
Talog->SetVisAttributes(C13_vis);
// Cu_Substrate
G4Material* Cu = manager->FindOrBuildMaterial("G4_Cu");
G4double Cu0thickness = 8.0 * mm;
G4double Cu0z = 0.5 * (Tathickness + Cu0thickness);
G4Tubs* CuSubstrate_tub0 =
new G4Tubs("CuSubstrate_tub0", 11. * mm, 29. * mm, 0.5 * Cu0thickness, 0, 360. * deg);
G4LogicalVolume* CuSubstrate_log0 = new G4LogicalVolume(CuSubstrate_tub0, Cu, "CuSubstrate_log0");
new G4PVPlacement(0, G4ThreeVector(0, 0, Cu0z), "CuSubstrate_phys1", CuSubstrate_log0, physicalWorld, false, 4,
true);
CuSubstrate_log0->SetVisAttributes(CuSub_vis);
// Target flange
G4double flange0_thickness = 9.0 * mm;
G4double flange0z = Cu0z + 0.5 * Cu0thickness + 0.5 * flange0_thickness;
G4Tubs* flange_tub0 = new G4Tubs("flange_tub0", 25. * mm, 42.33 * mm, 0.5 * flange0_thickness, 0, 360. * deg);
G4LogicalVolume* flange_log0 = new G4LogicalVolume(flange_tub0, tube_mat, "flange_log0");
new G4PVPlacement(0, G4ThreeVector(0, 0, flange0z), "flange_phys0", flange_log0, physicalWorld, false, 8, true);
G4double flange1_thickness = 7.0 * mm;
G4double flange1z = flange0z - 0.5 * (flange0_thickness + flange1_thickness);
G4Tubs* flange_tub1 = new G4Tubs("flange_tub1", 29. * mm, 44.45 * mm, 0.5 * flange1_thickness, 0, 360. * deg);
G4LogicalVolume* flange_log1 = new G4LogicalVolume(flange_tub1, tube_mat, "flange_log1");
new G4PVPlacement(0, G4ThreeVector(0, 0, flange1z), "flange_phys1", flange_log1, physicalWorld, false, 9, true);
// BeamLine_stainlesss
G4double BeampipeLength = 60.0 * cm;
G4double Beampipez = flange0z - 0.5 * flange0_thickness + 0.5 * BeampipeLength;
G4Tubs* Beampipe_tub =
new G4Tubs("Beampipe_tub", 42.33 * mm, 44.45 * mm, 0.5 * BeampipeLength, 0. * deg, 360. * deg);
G4LogicalVolume* Beampipe_log = new G4LogicalVolume(Beampipe_tub, tube_mat, "Beampipe_log");
new G4PVPlacement(0, G4ThreeVector(0, 0, Beampipez), "Beampipe_phys", Beampipe_log, physicalWorld, false, 10,
true);
flange_log0->SetVisAttributes(tube_vis);
flange_log1->SetVisAttributes(tube_vis);
Beampipe_log->SetVisAttributes(tube_vis);
// Vacuum
pressure = 1.0e-5 * pascal;
density = 1.29 * kg / m3 * pressure / atmosphere;
temperature = 77 * kelvin;
G4Material* Vacuum = new G4Material("Vacuum", density, ncomponents = 1, kStateGas, temperature, pressure);
Vacuum->AddMaterial(Air, 100.0 * perCent);
G4double VacuumLength = 70.0 * cm;
G4double Vacuumz = 0.5 * VacuumLength + Cu0z - 0.5 * Cu0thickness;
G4Tubs* Vacuum_tub = new G4Tubs("Vacuum_tub", 0, 42.33 * mm, 0.5 * VacuumLength, 0, 360. * deg);
G4double VacuumCu0z = -0.5 * VacuumLength + 0.5 * Cu0thickness;
G4Tubs* CuSubstrate_tub1 = new G4Tubs("CuSubstrate_tub1", 11. * mm, 50 * mm, 0.5 * Cu0thickness, 0, 360. * deg);
G4SubtractionSolid* Vacuum_sub = new G4SubtractionSolid(
"Vacuum_sub0", Vacuum_tub, CuSubstrate_tub1, G4Transform3D(rot0, G4ThreeVector(0, 0, VacuumCu0z))); // Cu0
G4double Vacuumflange0z = VacuumCu0z + 0.5 * Cu0thickness + 0.5 * flange0_thickness;
Vacuum_sub =
new G4SubtractionSolid("Vacuumflange0_sub", Vacuum_sub, flange_tub0,
G4Transform3D(rot0, G4ThreeVector(0, 0, Vacuumflange0z))); // Target flange0
G4LogicalVolume* Vacuum_log = new G4LogicalVolume(Vacuum_sub, Vacuum, "Vacuum_log");
new G4PVPlacement(0, G4ThreeVector(0, 0, Vacuumz), "Vacuum_phys", Vacuum_log, physicalWorld, false, 11, true);
Vacuum_log->SetVisAttributes(G4VisAttributes::GetInvisible);
// Water_cold
G4Material* water = manager->FindOrBuildMaterial("G4_WATER");
G4double WaterBack_thickness = 1.3 * mm;
G4double WaterBackz = -0.5 * Tathickness - 0.5 * WaterBack_thickness;
G4Tubs* WaterBack_tub =
new G4Tubs("WaterBack_tub", 0, 12.0 * mm, 0.5 * WaterBack_thickness, 0. * deg, 360. * deg);
G4LogicalVolume* WaterBack_log = new G4LogicalVolume(WaterBack_tub, water, "WaterBack_log");
new G4PVPlacement(0, G4ThreeVector(0, 0, WaterBackz), "WaterBack_phys", WaterBack_log, physicalWorld, false, 12,
true);
WaterBack_log->SetVisAttributes(water_vis);
// Fe backflange
G4double Fe0thickness = 1.3 * mm;
G4double Fe0z = WaterBackz;
G4Tubs* FeBack_tub0 =
new G4Tubs("FeBack_tub0", 12.0 * mm, 44.45 * mm, 0.5 * Fe0thickness, 0. * deg, 360. * deg);
G4LogicalVolume* FeBack_log0 = new G4LogicalVolume(FeBack_tub0, tube_mat, "FeBack_log0");
new G4PVPlacement(0, G4ThreeVector(0, 0, Fe0z), "FeBack_phys0", FeBack_log0, physicalWorld, false, 13, true);
G4double Fe1thickness = 6.7 * mm;
G4double Fe1z = Fe0z - 0.5 * Fe0thickness - 0.5 * Fe1thickness;
G4Tubs* FeBack_tub1 = new G4Tubs("FeBack_tub1", 0, 44.45 * mm, 0.5 * Fe1thickness, 0. * deg, 360. * deg);
G4LogicalVolume* FeBack_log1 = new G4LogicalVolume(FeBack_tub1, tube_mat, "FeBack_log1");
G4PVPlacement* Fe1phys = new G4PVPlacement(0, G4ThreeVector(0, 0, Fe1z), "FeBack_phys1", FeBack_log1,
physicalWorld, false, 14, true);
FeBack_log0->SetVisAttributes(tube_vis);
FeBack_log1->SetVisAttributes(tube_vis);
// Waterpipe
G4double Waterpipe1_thickness = Fe1thickness;
G4Tubs* Waterpipe_tub1 =
new G4Tubs("Waterpipe_tub1", 0, 1.6 * mm, 0.5 * Waterpipe1_thickness, 0. * deg, 360. * deg);
G4LogicalVolume* Waterpipe_log1 = new G4LogicalVolume(Waterpipe_tub1, water, "Waterpipe_log1");
new G4PVPlacement(0, G4ThreeVector(0, 9.0 * mm, 0), "Waterpipe_phys01", Waterpipe_log1, Fe1phys, false, 17,
true);
new G4PVPlacement(0, G4ThreeVector(0, -9.0 * mm, 0), "Waterpipe_phys02", Waterpipe_log1, Fe1phys, false, 18,
true);
G4double Waterpipe2_thickness = BPE_xyz / 2.0 + 10.0 * cm;
G4double Waterpipe2z = Fe1z - 0.5 * Fe1thickness - 0.5 * Waterpipe2_thickness;
G4Tubs* Waterpipe_tub2 =
new G4Tubs("Waterpipe_tub2", 0, 2.0 * mm, 0.5 * Waterpipe2_thickness, 0. * deg, 360. * deg);
G4LogicalVolume* Waterpipe_log2 = new G4LogicalVolume(Waterpipe_tub2, water, "Waterpipe_log2");
new G4PVPlacement(0, G4ThreeVector(0, 9.0 * mm, Waterpipe2z), "Waterpipe_phys20", Waterpipe_log2, physicalWorld,
false, 19, true);
new G4PVPlacement(0, G4ThreeVector(0, -9.0 * mm, Waterpipe2z), "Waterpipe_phys21", Waterpipe_log2,
physicalWorld, false, 20, true);
Waterpipe_log1->SetVisAttributes(water_vis);
Waterpipe_log2->SetVisAttributes(water_vis);
}
G4SDManager* SDman = G4SDManager::GetSDMpointer();
GeneHe3detSD* detSD = new GeneHe3detSD("/GeneHe3det/");
SDman->AddNewDetector(detSD);
He3active_log->SetSensitiveDetector(detSD);
return physicalWorld;
}

View File

@ -0,0 +1,61 @@
#include "GeneDetectorConstructionMessenger.hh"
#include "G4UIcmdWithADouble.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIdirectory.hh"
#include "GeneDetectorConstruction.hh"
GeneDetectorConstructionMessenger::GeneDetectorConstructionMessenger(GeneDetectorConstruction* pDets)
: pDetectorConstruction(pDets) {
DetectorDir = new G4UIdirectory("/Gene/Detector/");
DetectorDir->SetGuidance("Command to set detector offset");
ZoffsetCmd = new G4UIcmdWithADoubleAndUnit("/Gene/Detector/SetZoffset", this);
ZoffsetCmd->SetGuidance("Set detector Z offset");
ZoffsetCmd->SetParameterName("Zoffset", false);
ZoffsetCmd->SetUnitCategory("Length");
// ZoffsetCmd->SetRange("Zoffset>0");
ZoffsetCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
ZactiveshiftCmd = new G4UIcmdWithADoubleAndUnit("/Gene/Detector/SetZactiveshift", this);
ZactiveshiftCmd->SetGuidance("Set He3 active region Z shift");
ZactiveshiftCmd->SetParameterName("Zactiveshift", false);
ZactiveshiftCmd->SetUnitCategory("Length");
ZactiveshiftCmd->SetRange("Zactiveshift>-20 && Zactiveshift<20");
ZactiveshiftCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
PE_BfractionCmd = new G4UIcmdWithADouble("/Gene/Detector/SetBfraction", this);
PE_BfractionCmd->SetGuidance("Set Boron fraction of PE moderator");
PE_BfractionCmd->SetParameterName("PE_Bfraction", false);
PE_BfractionCmd->SetRange("PE_Bfraction>=0");
PE_BfractionCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
DetReactionCmd = new G4UIcmdWithAString("/Gene/Detector/SetDetReaction", this);
DetReactionCmd->SetGuidance("Set type of reaction for detector setup.");
DetReactionCmd->SetParameterName("DetReaction", false);
DetReactionCmd->AvailableForStates(G4State_PreInit);
}
GeneDetectorConstructionMessenger::~GeneDetectorConstructionMessenger() {
delete ZoffsetCmd;
delete ZactiveshiftCmd;
delete PE_BfractionCmd;
delete DetReactionCmd;
delete DetectorDir;
}
void GeneDetectorConstructionMessenger::SetNewValue(G4UIcommand* command, G4String newValue) {
if (command == ZoffsetCmd) {
pDetectorConstruction->SetZoffset(ZoffsetCmd->GetNewDoubleValue(newValue));
}
if (command == ZactiveshiftCmd) {
pDetectorConstruction->SetZactiveshift(ZactiveshiftCmd->GetNewDoubleValue(newValue));
}
if (command == PE_BfractionCmd) {
pDetectorConstruction->SetBfraction(PE_BfractionCmd->GetNewDoubleValue(newValue));
}
if (command == DetReactionCmd) {
pDetectorConstruction->SetDetReaction(newValue);
}
}

100
src/GeneEventAction.cc Normal file
View File

@ -0,0 +1,100 @@
#include "GeneEventAction.hh"
#include "G4Event.hh"
#include "G4EventManager.hh"
#include "G4HCofThisEvent.hh"
#include "G4SDManager.hh"
#include "G4SystemOfUnits.hh"
#include "G4Trajectory.hh"
#include "G4TrajectoryContainer.hh"
#include "G4UImanager.hh"
#include "G4UnitsTable.hh"
#include "G4VHitsCollection.hh"
#include "G4VVisManager.hh"
#include "G4ios.hh"
#include "GeneAnalysisManager.hh"
#include "GeneHe3detHit.hh"
#include "Randomize.hh"
#define ANALYSIS_USE
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
GeneEventAction::GeneEventAction() : GeneHe3detSDCollID(-1), drawFlag("non") {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
GeneEventAction::~GeneEventAction() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeneEventAction::BeginOfEventAction(const G4Event* evt) {
G4int evtNb = evt->GetEventID();
if (evtNb % 1000 == 0) G4cout << "Event No." << evtNb << G4endl;
G4SDManager* SDman = G4SDManager::GetSDMpointer();
if (GeneHe3detSDCollID == -1) {
GeneHe3detSDCollID = SDman->GetCollectionID("GeneHe3detHitCollection");
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeneEventAction::EndOfEventAction(const G4Event* evt) {
// G4int event_id = evt->GetEventID();
G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
GeneHe3detHitsCollection* GeneHe3detHC = 0;
GeneAnalysisManager* analysisManager = GeneAnalysisManager::GetInstance();
if (HCE) {
GeneHe3detHC = (GeneHe3detHitsCollection*)(HCE->GetHC(GeneHe3detSDCollID));
G4double ede = 0.;
G4double Etot[24];
G4int Ndet[24];
G4int cpNo;
for (G4int i = 0; i < 24; i++) {
Etot[i] = 0.;
Ndet[i] = -1;
}
// GeneHe3det event
if (GeneHe3detHC) {
G4int n_hits = GeneHe3detHC->entries();
if (n_hits > 0) {
for (G4int i = 0; i < n_hits; i++) {
cpNo = (*GeneHe3detHC)[i]->GetCpNo();
ede = (*GeneHe3detHC)[i]->GetEdep();
Etot[cpNo - 300] += ede;
}
cpNo = 0;
for (G4int i = 0; i < 24; i++) {
if (Etot[i] > 0) {
Ndet[cpNo] = i;
Etot[cpNo] = Etot[i];
cpNo++;
}
}
analysisManager->FillDetData(cpNo, Etot, Ndet);
// analysisManager->EventNo(); // evtNo++ only for detected events
#ifdef ANALYSIS_USE
analysisManager->FillTree();
#endif
}
}
}
// G4cout<<"--> EndOfEventAction in EventAction"<<G4endl;
if (drawFlag == "all") drawtracks(evt);
}
void GeneEventAction::drawtracks(const G4Event* evt) {
if (G4VVisManager::GetConcreteInstance()) {
G4TrajectoryContainer* trajContainer = evt->GetTrajectoryContainer();
G4int n_trajectories = 0;
if (trajContainer) n_trajectories = trajContainer->entries();
for (G4int i = 0; i < n_trajectories; i++) {
G4Trajectory* trj = (G4Trajectory*)(*trajContainer)[i];
if (trj->GetParticleName() != "opticalphoton") trj->DrawTrajectory();
}
G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
}
}

65
src/GeneHe3detHit.cc Normal file
View File

@ -0,0 +1,65 @@
#include "GeneHe3detHit.hh"
#include "G4Circle.hh"
#include "G4Colour.hh"
#include "G4UnitsTable.hh"
#include "G4VVisManager.hh"
#include "G4VisAttributes.hh"
#include <iomanip>
G4Allocator<GeneHe3detHit> GeneHe3detHitAllocator;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
GeneHe3detHit::GeneHe3detHit() {
cpNo = -1;
edep = 0.;
pos = G4ThreeVector(0., 0., 0.);
HitTime = 0.;
particleName = "";
particleEnergy = 0.;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
GeneHe3detHit::~GeneHe3detHit() { ; }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
GeneHe3detHit::GeneHe3detHit(const GeneHe3detHit& right) : G4VHit(right) {
cpNo = right.cpNo;
edep = right.edep;
pos = right.pos;
HitTime = right.HitTime;
particleName = right.particleName;
particleEnergy = right.particleEnergy;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
const GeneHe3detHit& GeneHe3detHit::operator=(const GeneHe3detHit& right) {
cpNo = right.cpNo;
edep = right.edep;
pos = right.pos;
HitTime = right.HitTime;
particleName = right.particleName;
particleEnergy = right.particleEnergy;
return *this;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
int GeneHe3detHit::operator==(const GeneHe3detHit& right) const { return (this == &right) ? 1 : 0; }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeneHe3detHit::Draw() { ; }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeneHe3detHit::Print() {
G4cout << " He3 detector hitcollection: " << std::setw(5) << G4BestUnit(edep, "Energy") << ", at "
<< G4BestUnit(pos, "Length") << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

87
src/GeneHe3detSD.cc Normal file
View File

@ -0,0 +1,87 @@
#include "GeneHe3detSD.hh"
#include "G4HCofThisEvent.hh"
#include "G4Ions.hh"
#include "G4ParticleDefinition.hh"
#include "G4ParticleTypes.hh"
#include "G4SDManager.hh"
#include "G4Step.hh"
#include "G4VPhysicalVolume.hh"
#include "G4ios.hh"
#include "GeneHe3detHit.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
GeneHe3detSD::GeneHe3detSD(G4String name) : G4VSensitiveDetector(name) {
G4String HCname = "GeneHe3detHitCollection";
collectionName.insert(HCname);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
GeneHe3detSD::~GeneHe3detSD() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeneHe3detSD::Initialize(G4HCofThisEvent*) {
scintillatorCollection = new GeneHe3detHitsCollection(SensitiveDetectorName, collectionName[0]);
HitID = -1;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
G4bool GeneHe3detSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
G4double edep = aStep->GetTotalEnergyDeposit();
G4ParticleDefinition* particleType = aStep->GetTrack()->GetDefinition();
G4String particleName = particleType->GetParticleName();
// G4double stepl = 0.;
// if (particleType->GetPDGCharge() != 0.)
// stepl = aStep->GetStepLength();
if (particleName == "opticalphoton") return false;
if ((edep == 0.)) return false;
G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
G4TouchableHistory* theTouchable = (G4TouchableHistory*)(preStepPoint->GetTouchable());
G4int copyNo = theTouchable->GetVolume()->GetCopyNo();
// fill in hit
GeneHe3detHit* newHit = new GeneHe3detHit();
newHit->SetCpNo(copyNo);
newHit->SetEdep(edep);
newHit->SetPos(aStep->GetPostStepPoint()->GetPosition());
newHit->SetTime(aStep->GetPostStepPoint()->GetGlobalTime());
newHit->SetParticle(particleName);
newHit->SetParticleEnergy(aStep->GetPreStepPoint()->GetKineticEnergy());
HitID = scintillatorCollection->insert(newHit);
return true;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeneHe3detSD::EndOfEvent(G4HCofThisEvent* HCE) {
G4String HCname = collectionName[0];
static G4int HCID = -1;
if (HCID < 0) HCID = G4SDManager::GetSDMpointer()->GetCollectionID(HCname);
HCE->AddHitsCollection(HCID, scintillatorCollection);
G4int nHits = scintillatorCollection->entries();
if (verboseLevel >= 1) G4cout << " Si collection: " << nHits << " hits" << G4endl;
if (verboseLevel >= 2) scintillatorCollection->PrintAllHits();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeneHe3detSD::clear() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeneHe3detSD::DrawAll() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeneHe3detSD::PrintAll() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

View File

@ -0,0 +1,203 @@
#include "GenePrimaryGeneratorAction.hh"
#include "TGraph.h"
#include "TH1F.h"
#include "G4Event.hh"
#include "G4ParticleDefinition.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4PhysicalConstants.hh"
#include "G4SystemOfUnits.hh"
#include "GeneAnalysisManager.hh"
#include "GenePrimaryGeneratorActionMessenger.hh"
#include "Randomize.hh"
#include "globals.hh"
#include "fstream"
#define ANALYSIS_USE
GenePrimaryGeneratorAction::GenePrimaryGeneratorAction() {
G4int n_particle = 1;
particleGun = new G4ParticleGun(n_particle);
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4String particleName;
particleGun->SetParticleDefinition(particleTable->FindParticle(particleName = "neutron"));
particleGun->SetParticlePosition(G4ThreeVector());
hAng = new TH1F("hAng", "hAng;theta(deg);prob.", 180, 0, 180);
fBeamEnergy = 0;
pMessenger = new GenePrimaryGeneratorActionMessenger(this);
}
GenePrimaryGeneratorAction::~GenePrimaryGeneratorAction() {
delete particleGun;
delete hAng;
delete pMessenger;
}
void GenePrimaryGeneratorAction::SetReaction(G4String& name) {
if (name == "V51pn")
iReaction = 0;
else if (name == "C13an")
iReaction = 1;
else {
G4cout << "Unknown reaction type!!!!" << G4endl;
G4cout << "Unknown reaction type!!!!" << G4endl;
G4cout << "Unknown reaction type!!!!" << G4endl;
G4cout << "Unknown reaction type!!!!" << G4endl;
G4cout << "Unknown reaction type!!!!" << G4endl;
G4cin >> iReaction;
}
}
void GenePrimaryGeneratorAction::SetBeamEnergy(G4double val) {
fBeamEnergy = val / MeV;
G4double umass = 931.494;
G4double massHe4 = 4.00260325413 * umass;
G4double massC13 = 13.00335483521 * umass;
G4double massO16 = 15.9949146196 * umass;
G4double massn = 939.56563;
G4double massp = 938.78294;
G4double massV51 = 50.9439569 * umass;
G4double massCr51 = 50.9447647 * umass;
if (iReaction == 0) {
mass[0] = massp;
mass[1] = massV51;
mass[2] = massCr51;
mass[3] = massn;
} else if (iReaction == 1) {
mass[0] = massHe4;
mass[1] = massC13;
mass[2] = massO16;
mass[3] = massn;
} else {
G4cout << "Unknown reaction type!!!!" << G4endl;
G4cout << "Unknown reaction type!!!!" << G4endl;
G4cout << "Unknown reaction type!!!!" << G4endl;
G4cout << "Unknown reaction type!!!!" << G4endl;
G4cout << "Unknown reaction type!!!!" << G4endl;
G4cin >> iReaction;
}
G4double eb = fBeamEnergy + mass[0];
G4double pb2 = fBeamEnergy * fBeamEnergy + 2.0 * fBeamEnergy * mass[0];
G4double pb = std::sqrt(pb2);
G4double esum = eb + mass[1];
beta = pb / esum;
gamma = 1.0 / std::sqrt(1.0 - beta * beta);
G4double e_cm2 = esum * esum - pb2;
G4double e_cm = std::sqrt(e_cm2);
G4double t_cm = e_cm - mass[2] - mass[3];
if (t_cm < 0.0) {
G4cout << "No solution!" << G4endl;
G4cin >> iReaction;
return;
}
G4double t_cm2 = t_cm * t_cm;
t3_cm = (t_cm2 + 2.0 * mass[3] * t_cm) / e_cm / 2.0;
t4_cm = (t_cm2 + 2.0 * mass[2] * t_cm) / e_cm / 2.0;
G4double p3_cm2 = t3_cm * t3_cm + 2.0 * t3_cm * mass[2];
G4double p4_cm2 = t4_cm * t4_cm + 2.0 * t4_cm * mass[3];
p3_cm = std::sqrt(p3_cm2);
p4_cm = std::sqrt(p4_cm2);
}
void GenePrimaryGeneratorAction::SetAngType(G4String& name) {
if (name == "ENDF") {
std::ifstream infile("xt_nov21.a");
G4int iN = 0;
if (infile.fail()) {
G4cout << "ifstream: Failure to open input file!!!" << G4endl;
G4cout << "ifstream: Failure to open input file!!!" << G4endl;
G4cout << "ifstream: Failure to open input file!!!" << G4endl;
G4cout << "ifstream: Failure to open input file!!!" << G4endl;
G4cout << "ifstream: Failure to open input file!!!" << G4endl;
G4cin >> iN;
return;
}
G4double Elab[5000], A1[5000], A2[5000], A3[5000];
G4double felab, fecm, fa0, fa1, fa2, fa3;
while (infile >> felab >> fecm >> fa0 >> fa1 >> fa2 >> fa3) {
Elab[iN] = felab;
A1[iN] = fa1;
A2[iN] = fa2;
A3[iN] = fa3;
iN++;
}
infile.close();
TGraph gr1(iN, Elab, A1);
TGraph gr2(iN, Elab, A2);
TGraph gr3(iN, Elab, A3);
fa1 = gr1.Eval(fBeamEnergy, 0, "S");
fa2 = gr2.Eval(fBeamEnergy, 0, "S");
fa3 = gr3.Eval(fBeamEnergy, 0, "S");
G4double thcm, costh, pthcm;
for (G4int i = 0; i < 180; i++) {
thcm = pi * i / 180.0;
costh = std::cos(thcm);
pthcm = 1.0 + fa1 * costh + fa2 * 0.5 * (3.0 * costh * costh - 1.0) +
fa3 * 0.5 * (5.0 * std::pow(costh, 3.0) - 3.0 * costh);
pthcm = pthcm * 2.0 * pi * std::sin(thcm);
if (pthcm < 0.0) pthcm = 0.0;
hAng->SetBinContent(i + 1, pthcm);
}
} else if (name == "ISO") {
G4double thcm, pthcm;
for (G4int i = 0; i < 180; i++) {
thcm = pi * i / 180.0;
pthcm = 2.0 * pi * std::sin(thcm);
hAng->SetBinContent(i + 1, pthcm);
}
} else {
G4cout << "Wrong Angular type!!!!" << G4endl;
G4cout << "Wrong Angular type!!!!" << G4endl;
G4cout << "Wrong Angular type!!!!" << G4endl;
G4cout << "Wrong Angular type!!!!" << G4endl;
G4cout << "Wrong Angular type!!!!" << G4endl;
G4int iN;
G4cin >> iN;
return;
}
}
void GenePrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) {
G4double thetacmr, thetalabr;
thetacmr = hAng->GetRandom() / 180.0 * pi;
G4double tg_thetalabr =
p4_cm * std::sin(thetacmr) /
(gamma * (p4_cm * std::cos(thetacmr) + beta * std::sqrt(p4_cm * p4_cm + mass[3] * mass[3])));
if (tg_thetalabr >= 1.0e6)
thetalabr = pi / 2.0;
else
thetalabr = std::atan(tg_thetalabr);
if (thetalabr < 0.0) thetalabr = pi + thetalabr;
G4double p4_cmx = p4_cm * std::sin(thetacmr);
G4double p4_cmz = p4_cm * std::cos(thetacmr);
G4double p4_labx = p4_cmx;
G4double p4_labz = gamma * (p4_cmz + beta * (t4_cm + mass[3]));
G4double p4_lab = std::sqrt(p4_labx * p4_labx + p4_labz * p4_labz);
G4double e4_lab = sqrt(p4_lab * p4_lab + mass[3] * mass[3]) - mass[3];
G4double phi = (G4UniformRand() * 2 * pi) - pi;
G4double x0 = std::sin(thetalabr) * std::cos(phi);
G4double y0 = std::sin(thetalabr) * std::sin(phi);
G4double z0 = std::cos(thetalabr);
#ifdef ANALYSIS_USE
GeneAnalysisManager* analysisManager = GeneAnalysisManager::GetInstance();
analysisManager->FillAng(thetacmr, thetalabr);
#endif
particleGun->SetParticleMomentumDirection(G4ThreeVector(x0, y0, z0));
particleGun->SetParticleEnergy(e4_lab * MeV);
particleGun->GeneratePrimaryVertex(anEvent);
}

View File

@ -0,0 +1,51 @@
#include "GenePrimaryGeneratorActionMessenger.hh"
#include "G4SystemOfUnits.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIdirectory.hh"
#include "GenePrimaryGeneratorAction.hh"
GenePrimaryGeneratorActionMessenger::GenePrimaryGeneratorActionMessenger(GenePrimaryGeneratorAction* pPrimary)
: pPrimaryGeneratorAction(pPrimary) {
PrimaryDir = new G4UIdirectory("/Gene/PrimaryGA/");
PrimaryDir->SetGuidance("Commands to set alpha beam energy");
BeamEnergyCmd = new G4UIcmdWithADoubleAndUnit("/Gene/PrimaryGA/SetBeamEnergy", this);
BeamEnergyCmd->SetGuidance("Set alpha beam energy.");
BeamEnergyCmd->SetParameterName("BeamEnergy", false);
BeamEnergyCmd->SetUnitCategory("Energy");
BeamEnergyCmd->SetRange("BeamEnergy>0.0");
BeamEnergyCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
AngularCmd = new G4UIcmdWithAString("/Gene/PrimaryGA/SetAngular", this);
AngularCmd->SetGuidance("Set type of angular distribution.");
AngularCmd->SetParameterName("Angular", false);
AngularCmd->AvailableForStates(G4State_PreInit);
ReactionCmd = new G4UIcmdWithAString("/Gene/PrimaryGA/SetReaction", this);
ReactionCmd->SetGuidance("Set type of reaction.");
ReactionCmd->SetParameterName("Reaction", false);
ReactionCmd->AvailableForStates(G4State_PreInit);
}
GenePrimaryGeneratorActionMessenger::~GenePrimaryGeneratorActionMessenger() {
delete BeamEnergyCmd;
delete PrimaryDir;
delete AngularCmd;
delete ReactionCmd;
}
void GenePrimaryGeneratorActionMessenger::SetNewValue(G4UIcommand* command, G4String newValue) {
if (command == BeamEnergyCmd) {
pPrimaryGeneratorAction->SetBeamEnergy(BeamEnergyCmd->GetNewDoubleValue(newValue));
}
if (command == AngularCmd) {
pPrimaryGeneratorAction->SetAngType(newValue);
}
if (command == ReactionCmd) {
pPrimaryGeneratorAction->SetReaction(newValue);
}
}

46
src/GeneRunAction.cc Normal file
View File

@ -0,0 +1,46 @@
#include "GeneRunAction.hh"
#include "G4Run.hh"
#include "G4SystemOfUnits.hh"
#include "G4UImanager.hh"
#include "G4VVisManager.hh"
#include "G4ios.hh"
#include "GeneAnalysisManager.hh"
#include "GeneRunActionMessenger.hh"
#define ANALYSIS_USE
GeneRunAction::GeneRunAction() : G4UserRunAction() {
RunNo = "00";
pMessenger = new GeneRunActionMessenger(this);
}
GeneRunAction::~GeneRunAction() { delete pMessenger; }
void GeneRunAction::BeginOfRunAction(const G4Run*) {
// Prepare the visualization
if (G4VVisManager::GetConcreteInstance()) {
G4UImanager* UI = G4UImanager::GetUIpointer();
UI->ApplyCommand("/vis/scene/notifyHandlers");
}
#ifdef ANALYSIS_USE
GeneAnalysisManager* analysisManager = GeneAnalysisManager::GetInstance();
G4String sFileName = "Simulation_RunNo" + RunNo + ".root";
analysisManager->SetAnalysisFileName(sFileName);
// Open an output file
analysisManager->book();
#endif
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeneRunAction::EndOfRunAction(const G4Run*) {
// Run ended, update the visualization
if (G4VVisManager::GetConcreteInstance()) {
G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
}
#ifdef ANALYSIS_USE
GeneAnalysisManager* analysisManager = GeneAnalysisManager::GetInstance();
analysisManager->save();
#endif
}

View File

@ -0,0 +1,26 @@
#include "GeneRunActionMessenger.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIdirectory.hh"
#include "GeneRunAction.hh"
GeneRunActionMessenger::GeneRunActionMessenger(GeneRunAction* pRun) : pRunAction(pRun) {
RunDir = new G4UIdirectory("/Gene/Run/");
RunDir->SetGuidance("Commands to set RunNo");
RunNoCmd = new G4UIcmdWithAString("/Gene/Run/RunNo", this);
RunNoCmd->SetGuidance("Set RunNo of file");
RunNoCmd->SetParameterName("RunNo", false);
RunNoCmd->AvailableForStates(G4State_PreInit);
}
GeneRunActionMessenger::~GeneRunActionMessenger() {
delete RunNoCmd;
delete RunDir;
}
void GeneRunActionMessenger::SetNewValue(G4UIcommand* command, G4String newValue) {
if (command == RunNoCmd) {
pRunAction->SetRunNo(newValue);
}
}

32
vis.mac Normal file
View File

@ -0,0 +1,32 @@
# 设置视图使用OpenGL
/vis/open OGL 800x800-0+0
# 禁止自动刷新,消息静音(除错误外)
/vis/viewer/set/autoRefresh false
/vis/verbose errors
# 绘制几何体
/vis/drawVolume
# 绘制轨迹 类型为平滑
/vis/scene/add/trajectories smooth
# 根据粒子ID进行绘制
/vis/modeling/trajectories/create/drawByParticleID
# 以2px的宽度绘制节点
/vis/modeling/trajectories/drawByParticleID-0/default/setDrawStepPts true
/vis/modeling/trajectories/drawByParticleID-0/default/setStepPtsSize 2
# 保留、叠加所有事例
/vis/scene/endOfEventAction accumulate
# 设置颜色
/vis/viewer/set/style surface
# 坐标轴
/vis/scene/add/scale # Simple scale line
/vis/scene/add/axes # Simple axes: x=red, y=green, z=blue.
#
# To get nice view
#
# Re-establish auto refreshing and verbosity:
/vis/viewer/set/autoRefresh true
/vis/verbose warnings

32
xmake.lua Normal file
View File

@ -0,0 +1,32 @@
set_project("Neuron Detector")
set_languages("c++17")
add_requires("cmake::Geant4", {
alias = "Geant4",
system = true,
configs = {
components = {"ui_all", "vis_all"}
}
})
add_requires("cmake::ROOT", {
alias = "ROOT",
system = true,
configs = {
components = {
"dl", "Gui", "Core", "RIO", "Net", "Hist", "Gpad",
"Tree", "Physics", "MathCore", "Thread", "ASImage"
}
}
})
target("NDSim")
set_kind("binary")
add_files("main.cpp")
add_files("src/*.cc")
add_includedirs("include")
add_packages("Geant4", "ROOT")
set_installdir("$(projectdir)/")
after_install(function (target)
local installdir = target:installdir()
os.cp("$(projectdir)/*.mac", path.join(installdir, "bin"))
end)