ATLAS Offline Software
Loading...
Searching...
No Matches
DerivedG4SensitiveDetectorTestSetting.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "G4HCofThisEvent.hh"
6#include "G4Step.hh"
7#include "G4TouchableHistory.hh"
8
9#include "G4Track.hh"
10#include "G4StepPoint.hh"
11#include "G4DynamicParticle.hh"
12#include "G4ThreeVector.hh"
13#include "G4Box.hh"
14#include "G4NistManager.hh"
15#include "G4Material.hh"
16#include "G4VPhysicalVolume.hh"
17#include "G4SystemOfUnits.hh"
18
19#include "DerivedG4Process.h"
20
21//In this function, the reasons why I use 'new' to define objects instead of using smart pointers are as follows:
22// 1. this function aims to set environment for test code, which means the objects that were defined in the function should exist throughout the whole code running. Therefore, defining the objects with 'new' can meet the requirement. If I define them with smart pointer, they will be destruct once they are out of scope.
23// 2. this function will only be used in the unit test code for testing the sensitive detector classes based on G4VSensitiveDetector. So it will never be responsible for memory leaks in production jobs.
24void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalEnergyDeposit, std::vector<G4String>& physicalNames, G4String& logicalName1, std::vector<G4int>& copyNos, G4ThreeVector& preStepPos, G4ThreeVector& postStepPos, G4double& globalTime0/*for preSP*/, G4double& kineticEnergy0/*for preSP*/, G4double& velocity0/*for preSP*/, G4double& globalTime/*for track*/, G4double& kineticEnergy/*for track*/, G4double& globalTime1/*for postSP*/, G4double& kineticEnergy1/*for postSP*/, G4double& velocity1/*for postSP*/, G4double& steplength, G4double& charge, G4int& encoding, G4int& antiencoding, G4String& astring, G4ProcessType& atype, G4String& nop1, G4String& nop2, G4String& nop3)
25{
26
27 if (copyNos.size()!=physicalNames.size()) { throw std::runtime_error("ERROR: physicalNames and copyNos must have the same length."); }
28//decorate sp with the variable called TotalEnergyDeposit
29 G4double TotalEnergyDeposit = totalEnergyDeposit;//para(i.e. there is a parameter in this line)
30 sp.SetTotalEnergyDeposit( TotalEnergyDeposit );
31//end
32
33//decorate sp with a G4StepPoint object
34 G4StepPoint* stepPoint = new G4StepPoint();
35 stepPoint->SetPosition(preStepPos);//para
36 G4NavigationHistory* navigationHistory = new G4NavigationHistory();
37 G4String boxName = "name";
38 G4Box* box = new G4Box(boxName, 1.0, 1.0, 1.0);
39 G4NistManager* man = G4NistManager::Instance();
40 G4Material* material = man->FindOrBuildMaterial("G4_AIR");
41 G4String name = "logicalName";
42 G4LogicalVolume* fLogical = new G4LogicalVolume(box, material, name);
43 G4String PhysicalName = physicalNames[0];//para
44 G4VPhysicalVolume* pPhysical = nullptr;
45 G4MyPhysicalVolume* physicalVolume = new G4MyPhysicalVolume(0, G4ThreeVector(0,0,0), PhysicalName, fLogical, pPhysical);
46 G4int CopyNo = copyNos[0];
47 physicalVolume->SetCopyNo(CopyNo);//para
48 G4int nReplica = 2;
49 navigationHistory->SetFirstEntry(physicalVolume);
50 if (physicalNames.size()==1) {
51 // temporary workaround
52 navigationHistory->NewLevel(physicalVolume, kNormal, nReplica);
53 navigationHistory->NewLevel(physicalVolume, kNormal, nReplica);
54 navigationHistory->NewLevel(physicalVolume, kNormal, nReplica);
55 navigationHistory->NewLevel(physicalVolume, kNormal, nReplica);
56 navigationHistory->NewLevel(physicalVolume, kNormal, nReplica);
57 }
58 else {
59 bool skip(true);
60 size_t idx(0);
61 for( const auto& name : physicalNames) {
62 if (skip) { skip=false; ++idx; continue; }//skip first entry
63 G4MyPhysicalVolume* parentPhysVol = new G4MyPhysicalVolume(0, G4ThreeVector(0,0,0), name, fLogical, pPhysical);
64 parentPhysVol->SetCopyNo(copyNos[idx]);
65 ++idx;
66 navigationHistory->NewLevel(parentPhysVol, kNormal, nReplica);
67 }
68 }
69 G4TouchableHistory* touchableHistory = new G4TouchableHistory(*navigationHistory);
70 G4TouchableHandle touchableHandle(touchableHistory);
71 stepPoint->SetTouchableHandle(touchableHandle);
72 G4double GlobalTime0 = globalTime0;
73 G4double KineticEnergy0 = kineticEnergy0;
74 G4double Velocity0 = velocity0;
75 stepPoint->SetGlobalTime(GlobalTime0);//para
76 stepPoint->SetKineticEnergy(KineticEnergy0);//para
77 stepPoint->SetVelocity(Velocity0);//para
78
79 sp.SetPreStepPoint(stepPoint);
80//end
81
82//decorate sp with another G4StepPoint object
83 G4StepPoint* stepPoint1 = new G4StepPoint();
84 stepPoint1->SetPosition(postStepPos);//para
85 G4double GlobalTime1 = globalTime1;
86 G4double KineticEnergy1 = kineticEnergy1;
87 G4double Velocity1 = velocity1;
88 stepPoint1->SetGlobalTime(GlobalTime1);//para
89 stepPoint1->SetKineticEnergy(KineticEnergy1);//para
90 stepPoint1->SetVelocity(Velocity1);//para
91
92 sp.SetPostStepPoint(stepPoint1);
93//end
94
95//set step length for the step
96 G4double StepLength = steplength;
97 sp.SetStepLength(StepLength);//para
98//end
99
100//decorate sp with a G4Track object
101 G4double Charge = charge;
102 G4int Encoding = encoding;
103 G4int Antiencoding = antiencoding;
104 G4String NOP1 = nop1;
105 G4String NOP2 = nop2;
106 G4String NOP3 = nop3;
107 G4ParticleDefinition* particle = new G4ParticleDefinition(NOP1, 0.0*MeV, 0.0*MeV, Charge,//para
108 2, -1, -1,
109 0, 0, 0,
110 NOP2, 0, 0, Encoding,//para
111 true, -1.0, nullptr,
112 false, NOP3, Antiencoding//para
113 );
114 G4ThreeVector aMomentumDirection(0,0,0);
115 G4double aKineticEnergy = kineticEnergy;//para
116 G4DynamicParticle* dynamicPar = new G4DynamicParticle(particle, aMomentumDirection, aKineticEnergy);
117 G4double aValueTime = 1;
118 G4ThreeVector ValuePosition(1.0, 1.0, 1.0);
119 G4Track* track = new G4Track(dynamicPar, aValueTime, ValuePosition);
120 //G4double globalTime = globalTime;
121 track->SetGlobalTime(globalTime);//para
122 int trackID = 3;
123 track->SetTrackID(trackID);
124 G4String boxName1 = "name";
125 G4Box* box1 = new G4Box(boxName1, 1.0, 1.0, 1.0);
126 G4NistManager* man1 = G4NistManager::Instance();
127 G4Material* material1 = man1->FindOrBuildMaterial("G4_AIR");
128 G4String name2 = logicalName1;//para
129 G4LogicalVolume* fLogical1 = new G4LogicalVolume(box1, material1, name2);
130 track->SetLogicalVolumeAtVertex(fLogical1);
131 G4Step* stepForTrack = new G4Step();
132 G4StepPoint* stepPoint2 = new G4StepPoint();
133 G4Material* mat1 = man1->FindOrBuildMaterial("G4_AIR");
134 G4MaterialPropertiesTable* propertiesTable = new G4MaterialPropertiesTable();
135 G4double Energies[5] = {1,2,3,4,5};
136 G4double Values[5] = {1,2,3,4,5};
137 size_t VectorLength = 5;
138 G4MaterialPropertyVector* mpv = new G4MaterialPropertyVector(Energies, Values, VectorLength);
139 G4MaterialPropertyVector* mpv1 = new G4MaterialPropertyVector(Energies, Values, VectorLength);
140 propertiesTable->AddProperty("RINDEX", mpv);
141 propertiesTable->AddProperty("ABSLENGTH", mpv1);
142 mat1->SetMaterialPropertiesTable(propertiesTable);
143 stepPoint2->SetMaterial(mat1);
144 stepForTrack->SetPreStepPoint(stepPoint2);
145 track->SetStep(stepForTrack);
146
147 G4ProcessType aType = atype;
148 G4String aString = astring;
149 G4MyProcess* process = new G4MyProcess( aString, aType );//para para
150 track->SetCreatorProcess( process );
151
152 track->SetTouchableHandle(touchableHandle);
153
154 sp.SetTrack(track);
155//end
156
157 return;
158}
double charge(const T &p)
Definition AtlasPID.h:997
void DerivedG4SensitiveDetectorTestSetting(G4Step &sp, G4double &totalEnergyDeposit, std::vector< G4String > &physicalNames, G4String &logicalName1, std::vector< G4int > &copyNos, G4ThreeVector &preStepPos, G4ThreeVector &postStepPos, G4double &globalTime0, G4double &kineticEnergy0, G4double &velocity0, G4double &globalTime, G4double &kineticEnergy, G4double &globalTime1, G4double &kineticEnergy1, G4double &velocity1, G4double &steplength, G4double &charge, G4int &encoding, G4int &antiencoding, G4String &astring, G4ProcessType &atype, G4String &nop1, G4String &nop2, G4String &nop3)
static Double_t sp
void SetCopyNo(G4int CopyNo) final
const std::string process