ScintillatorConstruction.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 #include <utl/ErrorLogger.h>
5 #include <utl/Reader.h>
6 #include <utl/MathConstants.h>
7 
8 //G4 Classes
9 #include <G4RunManager.hh>
10 #include <G4RegionStore.hh>
11 #include <G4Box.hh>
12 #include <G4Tubs.hh>
13 #include <G4LogicalVolume.hh>
14 #include <G4ThreeVector.hh>
15 #include <G4PVPlacement.hh>
16 #include <G4Transform3D.hh>
17 #include <G4RotationMatrix.hh>
18 #include <G4VisAttributes.hh>
19 #include <G4Colour.hh>
20 #include <G4Material.hh>
21 #include <G4Element.hh>
22 #include <G4MaterialPropertiesTable.hh>
23 
24 #include <utl/TabularStream.h>
25 #include <utl/ConfigUtils.h>
26 
27 
28 using namespace fwk;
29 using namespace utl;
30 using namespace EdepSimulatorAG;
31 
32 ScintillatorConstruction::ScintillatorConstruction ( )
33 {
34  fLogicalWorld = 0;
35  fPhysicalWorld = 0;
36  fLogicalScintillator = 0;
37  fPhysicalScintillator = 0;
38  L_LogScintillator = 0;
39  L_PhyScintillator = 0;
40  R_LogScintillator = 0;
41  R_PhyScintillator = 0;
42 
43  INFO("\n++++\nGetting parameters from XML file...");
44  Branch config(fwk::CentralConfig::GetInstance()->GetTopBranch("MdEdepSimulator"));
45 
46  fLog.Configure(config);
47  //Set energy units to MeV (otherwise default is eV)
48  fUnits.SetEnergyDefault( utl::MeV, "MeV");
49  fUnits.SetLengthDefault( utl::cm , "cm");
50  fUnits.Configure(config);
51 
52  LoadConfig( config.GetChild("scintillator"), "density", fScintillatorDensity, 1.06*utl::g/utl::cm3 );
53 
54  std::vector<G4double> vScintiSize, vScintiSizeDefault;
55 
56  vScintiSizeDefault.push_back( 4.01*utl::cm );
57  vScintiSizeDefault.push_back( 400.00*utl::cm );
58  vScintiSizeDefault.push_back( 1.00*utl::cm );
59 
60  LoadConfig( config.GetChild("scintillator"), "size", vScintiSize,vScintiSizeDefault );
61 
62  fScint_Side_X = vScintiSize.at(0)/2;
63  fScint_Side_Y = vScintiSize.at(1)/2;
64  fScint_Side_Z = vScintiSize.at(2)/2;
65 
66  fWorld_Side_X = 3*fScint_Side_X;//To host 3 strips (central + 2 neighbours)
67  fWorld_Side_Y = fScint_Side_Y;
68  fWorld_Side_Z = fScint_Side_Z;
69 
70  //Convert from AugerUnits to CLHEP units
71  fScintillatorDensity *= ((CLHEP::g/CLHEP::cm3)/(utl::g/utl::cm3));
72 
73  fWorld_Side_X *= (CLHEP::m / utl::m);
74  fWorld_Side_Y *= (CLHEP::m / utl::m);
75  fWorld_Side_Z *= (CLHEP::m / utl::m);
76 
77  fScint_Side_X *= (CLHEP::m / utl::m);
78  fScint_Side_Y *= (CLHEP::m / utl::m);
79  fScint_Side_Z *= (CLHEP::m / utl::m);
80 
81  G4cerr << "X World size " << 2*fWorld_Side_X/CLHEP::m << " (m)" << G4endl;
82  G4cerr << "Y World size " << 2*fWorld_Side_Y/CLHEP::m << " (m)" << G4endl;
83  G4cerr << "Z World size " << 2*fWorld_Side_Z/CLHEP::m << " (m)" << G4endl;
84 
85  G4cerr << "Scintillator Density " << fScintillatorDensity/(CLHEP::g/CLHEP::cm3) << " g/cm3"<< G4endl;
86 
87  G4cerr << "X Scinti size " << 2*fScint_Side_X/CLHEP::m << " (m)" << G4endl;
88  G4cerr << "Y Scinti size " << 2*fScint_Side_Y/CLHEP::m << " (m)" << G4endl;
89  G4cerr << "Z Scinti size " << 2*fScint_Side_Z/CLHEP::m << " (m)" << G4endl;
90 
91  //Creates materials after unit conversion
92  CreateMaterials();
93 }
94 
95 ScintillatorConstruction::~ScintillatorConstruction ( ){}
96 
97 G4VPhysicalVolume *
98 ScintillatorConstruction::Construct ( )
99 {
100  if(!fPhysicalWorld){
101  G4Colour red ( 1, 0, 0 );
102  G4Colour green ( 0, 1, 0 );
103  G4Colour blue ( 0, 0, 1 );
104 
105  G4ThreeVector placement;
106 
107  INFO("\n++++\nCreating World for scintillator simulation");
108  //World Box
109  G4Box *WorldBox = new G4Box("WorldBox", fWorld_Side_X, fWorld_Side_Y, fWorld_Side_Z);
110  fLogicalWorld = new G4LogicalVolume ( WorldBox, fWorldMaterial, "LogWorld", 0, 0, 0 );
111  fPhysicalWorld = new G4PVPlacement ( 0, G4ThreeVector ( ), fLogicalWorld, "WorldPhys", 0, false, 0 );
112  G4VisAttributes *fLogicalWorldVisAtt = new G4VisAttributes ( red );
113  fLogicalWorld->SetVisAttributes ( fLogicalWorldVisAtt );
114  //fLogicalWorld->SetVisAttributes ( G4VisAttributes::Invisible );
115 
116  INFO("\n++++\nCreating scintillator + first neighbours");
117  //Scintillator Box
118  G4Box *ScintillatorBox = new G4Box ( "ScintillatorBox", fScint_Side_X, fScint_Side_Y, fScint_Side_Z );
119  fLogicalScintillator = new G4LogicalVolume ( ScintillatorBox, fScintillatorMaterial, "ScintillatorLog" );
120 
121  G4double scintillator_pos_x;
122  G4double scintillator_pos_y;
123  G4double scintillator_pos_z;
124 
125  //Central scintillator (where particle is injected)
126  scintillator_pos_x = 0.0 * utl::m;
127  scintillator_pos_y = 0.0 * utl::m;
128  scintillator_pos_z = 0.0 * utl::m;//-fScint_Side_Z;
129  placement = G4ThreeVector ( scintillator_pos_x, scintillator_pos_y, scintillator_pos_z );
130  fPhysicalScintillator = new G4PVPlacement ( 0, placement, fLogicalScintillator, "CentralScint", fLogicalWorld, false, 0 );//CENTRAL
131  fLogicalScintillator->SetVisAttributes ( new G4VisAttributes ( green ) );
132 
133  //First neighbouring scintillators
134  L_LogScintillator = new G4LogicalVolume ( ScintillatorBox, fScintillatorMaterial, "L_ScintillatorLog" );//LEFT
135  placement = G4ThreeVector ( scintillator_pos_x - 2*fScint_Side_X, scintillator_pos_y, scintillator_pos_z );
136  L_PhyScintillator = new G4PVPlacement ( 0, placement, L_LogScintillator, "LeftScint", fLogicalWorld, false, 0 );
137  L_LogScintillator ->SetVisAttributes ( new G4VisAttributes ( blue ) );
138 
139  R_LogScintillator = new G4LogicalVolume ( ScintillatorBox, fScintillatorMaterial, "R_ScintillatorLog" );//RIGHT
140  placement = G4ThreeVector ( scintillator_pos_x + 2*fScint_Side_X, scintillator_pos_y, scintillator_pos_z );
141  R_PhyScintillator = new G4PVPlacement ( 0, placement, R_LogScintillator, "RightScint", fLogicalWorld, false, 0 );
142  R_LogScintillator ->SetVisAttributes ( new G4VisAttributes ( blue ) );
143  }
144  return fPhysicalWorld;
145 }
146 
147 void
148 ScintillatorConstruction::CreateMaterials ( )
149 {
150  INFO("\n++++\nCreating materials...");
151  G4double a(0), z(0);
152  G4int nel(0);
153 
154  H = new G4Element ( "Hydrogen" , "H", z = 1., a = 1.010 * CLHEP::g / CLHEP::mole );
155  C = new G4Element ( "Carbon" , "C", z = 6., a = 12.01 * CLHEP::g / CLHEP::mole );
156  N = new G4Element ( "Nitrogen" , "N", z = 7., a = 14.01 * CLHEP::g / CLHEP::mole );
157  O = new G4Element ( "Oxygen" , "O", z = 8., a = 15.99 * CLHEP::g / CLHEP::mole );
158 
159  G4Material *Polystyrene = new G4Material ( "Polystyrene", fScintillatorDensity, nel = 2 );
160  Polystyrene->AddElement ( C, 8 );
161  Polystyrene->AddElement ( H, 8 );
162 
163  //Malargue Scintillator
164  fScintillatorMaterial = new G4Material ( "Scintillator", fScintillatorDensity , nel = 1 );
165  fScintillatorMaterial->AddMaterial ( Polystyrene, 100.0 * CLHEP::perCent );
166 
167  //World material (Air)
168  fWorldMaterial = new G4Material ( "Air_MdEdep", 1.29 * CLHEP::mg / CLHEP::cm3, nel = 2 );
169  fWorldMaterial->AddElement ( N, 70. * CLHEP::perCent );
170  fWorldMaterial->AddElement ( O, 30. * CLHEP::perCent );
171 
172  return;
173 }
constexpr double perCent
Definition: AugerUnits.h:282
constexpr double cm3
Definition: AugerUnits.h:119
static const G4Colour green(0.0, 1.0, 0.0)
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
constexpr double MeV
Definition: AugerUnits.h:184
Class representing a document branch.
Definition: Branch.h:107
constexpr double mole
Definition: AugerUnits.h:262
constexpr double g
Definition: AugerUnits.h:200
static const G4Colour red(1.0, 0.0, 0.0)
constexpr double mg
Definition: AugerUnits.h:201
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
constexpr double cm
Definition: AugerUnits.h:117
void LoadConfig(const utl::Branch &b, const std::string &tag, T1 &var, const T2 &defaultValue)
Helper method to load a particular configuration parameter.
Definition: ConfigUtils.h:35
constexpr double m
Definition: AugerUnits.h:121
static const G4Colour blue(0.0, 0.0, 1.0)

, generated on Tue Sep 26 2023.