0%

geant detector construction

  1. 几何旋转符合左手法则及RotationMatrix的使用
    经过验证geant4中的rotate符合左手法则
1
2
3
4
G4RotationMatrix *rot=new G4RotationMatrix;
rot->rotateX(90*degree);
rot->rotateY(90*degree);
rot->rotateZ(90*degree);

注意,再次对rot重复赋值无效,如对上述代码再作如下操作rot->rotateX(180*degree),该操作将无效,不会改变之前的rot;
那么,要对rot再次赋值该怎么办呢?如下:只需在再次赋值前加rot =new G4RotationMatrix即可;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  G4RotationMatrix* rotationMatrix_X = new G4RotationMatrix;

for(G4int x_col_num = 0; x_col_num <=NBD_colNb; x_col_num++){
if(x_col_num==0){ // the center colume
NBDx = NBDx0;
for(G4int y_row_num = 0; y_row_num <=NBD_rowNb; y_row_num++ ){
index// NBDx = NBDx0;
indexNBDy = NBDy0+R*sin(y_row_num*theta);
indexNBDz = NBDz0+R*(1-cos(y_row_num*theta));

indexif(y_row_num==0){
index // center position
index rotationMatrix_X = new G4RotationMatrix;
index rotationMatrix_X->rotateX(y_row_num*theta);

index new G4PVPlacement(rotationMatrix_X, //no rotation
indexindexindex G4ThreeVector(NBDx,NBDy,NBDz), //at (0,0,0)
indexindexindex logicAssembleNBD, //its logical volume
indexindexindex "AssembleNBD", //its name
indexindexindex expHall_logV, //its mother volume
indexindexindex false, //no boolean operation
indexindexindex 0, //copy number
indexindexindex true); //overlaps checking
index}
indexelse{
index //+y++
index rotationMatrix_X = new G4RotationMatrix;
index rotationMatrix_X->rotateX(-y_row_num*theta);

index new G4PVPlacement(rotationMatrix_X, //no rotation
indexindexindex G4ThreeVector(NBDx,NBDy,NBDz), //at (0,0,0)
indexindexindex logicAssembleNBD, //its logical volume
indexindexindex "AssembleNBD", //its name
indexindexindex expHall_logV, //its mother volume
indexindexindex false, //no boolean operation
indexindexindex 0, //copy number
indexindexindex true); // overlaps checking
index //-y++
index rotationMatrix_X = new G4RotationMatrix;
index rotationMatrix_X->rotateX(y_row_num*theta);
index new G4PVPlacement(rotationMatrix_X, //no rotation
indexindexindex G4ThreeVector(NBDx,-NBDy,NBDz), //at (0,0,0)
indexindexindex logicAssembleNBD, //its logical volume
indexindexindex "AssembleNBD", //its name
indexindexindex expHall_logV, //its mother volume
indexindexindex false, //no boolean operation
indexindexindex 0, //copy number
indexindexindex true); // overlaps checking
index}
}
...

  1. G4VParameterisation()的使用
  • ComputeTransformation defines where one of the copies is placed
  • ComputeDimensions defines the size of one copy, and a constructor that initializes any member variables that are required.

G4VParameterisation的具体应用可参看Basics/B2/B2b

颜色的配置

Geant4中的颜色配置由红、绿、蓝、是否透明四个构成;red、green、blue、alpha(opacity/opaque)

1
2
3
4
5
6
G4Colour::G4Colour ( G4double  r = 1.0,
indexindex G4double g = 1.0,
indexindex G4double b = 1.0,
G4double a = 1.0);
//0<=red, green, blue <= 1.0

颜色的实例化应用

1.颜色配置实例化

1
2
3
4
5
6
7
8
9
10
G4Colour  white  ();  //white
G4Colour white (1.0,1.0,1.0); //white
G4Colour gray (0.5,0.5,0.5); //gray
G4Colour black (0.0,0.0,0.0); //black
G4Colour red (1.0,0.0,0.0); //red
G4Colour green (0.0,1.0,0.0); //green
G4Colour blue (0.0,0.0,1.0); //blue
G4Colour cyan (0.0,1.0,1.0); //cyan
G4Colour magenta(1.0,0.0,1.0); //magenta
G4Colour yellow (1.0,1.0,0.0); //yellow

example

1
G4VisAttributes* Assemble_VisAtt= new G4VisAttributes(G4Colour(0.0,0.0,1.0));//blue

2.静态公用数据函数实例化

1
2
3
4
5
6
7
8
9
10
static const G4Colour& White   ();
static const G4Colour& Gray ();
static const G4Colour& Grey ();
static const G4Colour& Black ();
static const G4Colour& Red ();
static const G4Colour& Green ();
static const G4Colour& Blue ();
static const G4Colour& Cyan ();
static const G4Colour& Magenta ();
static const G4Colour& Yellow ();

example

1
G4Colour myRed(G4Colour::Red());

实例化Colour对象后,可以采用如下方式获得函数

1
2
3
G4double G4Colour::GetRed   () const;
G4double G4Colour::GetGreen () const;
G4double G4Colour::GetBlue () const;

Colour Map的应用

1
2
3
4
5
6
7
8
9
10
11
12
G4String		G4Colour
---------------------------------------
white G4Colour::White ()
gray G4Colour::Gray ()
grey G4Colour::Grey ()
black G4Colour::Black ()
red G4Colour::Red ()
green G4Colour::Green ()
blue G4Colour::Blue ()
cyan G4Colour::Cyan ()
magenta G4Colour::Magenta ()
yellow G4Colour::Yellow ()

Colours的检索可以采用如下方式

1
bool G4Colour::GetColour(const G4String& key, G4Colour& result)

example

1
2
3
4
5
6
7
G4Colour myColour(G4Colour::Black());
if (G4Colour::GetColour("red", myColour)) {
// Successfully retrieved colour "red". myColour is now red
}
else {
// Colour did not exist in map. myColour is still black
}