Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
B2a::DetectorConstruction Class Reference
basic » B2 » B2a

Detector construction class to define materials, geometry and global uniform magnetic field. More...

#include <Doxymodules_basic.h>

Inheritance diagram for B2a::DetectorConstruction:
G4VUserDetectorConstruction

Public Member Functions

 DetectorConstruction ()
 
 ~DetectorConstruction () override
 
G4VPhysicalVolumeConstruct () override
 
void ConstructSDandField () override
 
void SetTargetMaterial (G4String)
 
void SetChamberMaterial (G4String)
 
void SetMaxStep (G4double)
 
void SetCheckOverlaps (G4bool)
 

Private Member Functions

void DefineMaterials ()
 
G4VPhysicalVolumeDefineVolumes ()
 

Private Attributes

G4int fNbOfChambers = 0
 
G4LogicalVolumefLogicTarget = nullptr
 
G4LogicalVolume ** fLogicChamber = nullptr
 
G4MaterialfTargetMaterial = nullptr
 
G4MaterialfChamberMaterial = nullptr
 
G4UserLimitsfStepLimit = nullptr
 
DetectorMessengerfMessenger = nullptr
 
G4bool fCheckOverlaps = true
 

Static Private Attributes

static G4ThreadLocal G4GlobalMagFieldMessengerfMagFieldMessenger = nullptr
 

Detailed Description

Detector construction class to define materials, geometry and global uniform magnetic field.

Definition at line 48 of file Doxymodules_basic.h.

Constructor & Destructor Documentation

◆ DetectorConstruction()

B2a::DetectorConstruction::DetectorConstruction ( )

Definition at line 65 of file DetectorConstruction.cc.

66{
67 fMessenger = new DetectorMessenger(this);
68
69 fNbOfChambers = 5;
71}

◆ ~DetectorConstruction()

B2a::DetectorConstruction::~DetectorConstruction ( )
override

Definition at line 75 of file DetectorConstruction.cc.

76{
77 delete [] fLogicChamber;
78 delete fStepLimit;
79 delete fMessenger;
80}

Member Function Documentation

◆ Construct()

G4VPhysicalVolume * B2a::DetectorConstruction::Construct ( )
override

Definition at line 84 of file DetectorConstruction.cc.

85{
86 // Define materials
88
89 // Define volumes
90 return DefineVolumes();
91}
G4VPhysicalVolume * DefineVolumes()

◆ ConstructSDandField()

void B2a::DetectorConstruction::ConstructSDandField ( )
override

Definition at line 278 of file DetectorConstruction.cc.

279{
280 // Sensitive detectors
281
282 G4String trackerChamberSDname = "/TrackerChamberSD";
283 auto aTrackerSD = new TrackerSD(trackerChamberSDname, "TrackerHitsCollection");
284 G4SDManager::GetSDMpointer()->AddNewDetector(aTrackerSD);
285 // Setting aTrackerSD to all logical volumes with the same name
286 // of "Chamber_LV".
287 SetSensitiveDetector("Chamber_LV", aTrackerSD, true);
288
289 // Create global magnetic field messenger.
290 // Uniform magnetic field is then created automatically if
291 // the field value is not zero.
292 G4ThreeVector fieldValue = G4ThreeVector();
294 fMagFieldMessenger->SetVerboseLevel(1);
295
296 // Register the field messenger for deleting
297 G4AutoDelete::Register(fMagFieldMessenger);
298}
Tracker sensitive detector class.
static G4ThreadLocal G4GlobalMagFieldMessenger * fMagFieldMessenger

◆ SetTargetMaterial()

void B2a::DetectorConstruction::SetTargetMaterial ( G4String  materialName)

Definition at line 302 of file DetectorConstruction.cc.

303{
304 G4NistManager* nistManager = G4NistManager::Instance();
305
306 G4Material* pttoMaterial =
307 nistManager->FindOrBuildMaterial(materialName);
308
309 if (fTargetMaterial != pttoMaterial) {
310 if ( pttoMaterial ) {
311 fTargetMaterial = pttoMaterial;
312 if (fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial);
313 G4cout
314 << G4endl
315 << "----> The target is made of " << materialName << G4endl;
316 } else {
317 G4cout
318 << G4endl
319 << "--> WARNING from SetTargetMaterial : "
320 << materialName << " not found" << G4endl;
321 }
322 }
323}

◆ SetChamberMaterial()

void B2a::DetectorConstruction::SetChamberMaterial ( G4String  materialName)

Definition at line 327 of file DetectorConstruction.cc.

328{
329 G4NistManager* nistManager = G4NistManager::Instance();
330
331 G4Material* pttoMaterial =
332 nistManager->FindOrBuildMaterial(materialName);
333
334 if (fChamberMaterial != pttoMaterial) {
335 if ( pttoMaterial ) {
336 fChamberMaterial = pttoMaterial;
337 for (G4int copyNo=0; copyNo<fNbOfChambers; copyNo++) {
338 if (fLogicChamber[copyNo]) fLogicChamber[copyNo]->
339 SetMaterial(fChamberMaterial);
340 }
341 G4cout
342 << G4endl
343 << "----> The chambers are made of " << materialName << G4endl;
344 } else {
345 G4cout
346 << G4endl
347 << "--> WARNING from SetChamberMaterial : "
348 << materialName << " not found" << G4endl;
349 }
350 }
351}

◆ SetMaxStep()

void B2a::DetectorConstruction::SetMaxStep ( G4double  maxStep)

Definition at line 355 of file DetectorConstruction.cc.

356{
357 if ((fStepLimit)&&(maxStep>0.)) fStepLimit->SetMaxAllowedStep(maxStep);
358}

◆ SetCheckOverlaps()

void B2a::DetectorConstruction::SetCheckOverlaps ( G4bool  checkOverlaps)

Definition at line 362 of file DetectorConstruction.cc.

363{
364 fCheckOverlaps = checkOverlaps;
365}

◆ DefineMaterials()

void B2a::DetectorConstruction::DefineMaterials ( )
private

Definition at line 95 of file DetectorConstruction.cc.

96{
97 // Material definition
98
99 G4NistManager* nistManager = G4NistManager::Instance();
100
101 // Air defined using NIST Manager
102 nistManager->FindOrBuildMaterial("G4_AIR");
103
104 // Lead defined using NIST Manager
105 fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Pb");
106
107 // Xenon gas defined using NIST Manager
108 fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe");
109
110 // Print materials
111 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
112}

◆ DefineVolumes()

G4VPhysicalVolume * B2a::DetectorConstruction::DefineVolumes ( )
private

Set additional contraints on the track, with G4UserSpecialCuts

G4double maxLength = 2*trackerLength, maxTime = 0.1*ns, minEkin = 10*MeV; trackerLV->SetUserLimits(new G4UserLimits(maxStep, maxLength, maxTime, minEkin));

Definition at line 116 of file DetectorConstruction.cc.

117{
118 G4Material* air = G4Material::GetMaterial("G4_AIR");
119
120 // Sizes of the principal geometrical components (solids)
121
122 G4double chamberSpacing = 80*cm; // from chamber center to center!
123
124 G4double chamberWidth = 20.0*cm; // width of the chambers
125 G4double targetLength = 5.0*cm; // full length of Target
126
127 G4double trackerLength = (fNbOfChambers+1)*chamberSpacing;
128
129 G4double worldLength = 1.2 * (2*targetLength + trackerLength);
130
131 G4double targetRadius = 0.5*targetLength; // Radius of Target
132 targetLength = 0.5*targetLength; // Half length of the Target
133 G4double trackerSize = 0.5*trackerLength; // Half length of the Tracker
134
135 // Definitions of Solids, Logical Volumes, Physical Volumes
136
137 // World
138
139 G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength);
140
141 G4cout << "Computed tolerance = "
142 << G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()/mm
143 << " mm" << G4endl;
144
145 auto worldS = new G4Box("world", // its name
146 worldLength / 2, worldLength / 2, worldLength / 2); // its size
147 auto worldLV = new G4LogicalVolume(worldS, // its solid
148 air, // its material
149 "World"); // its name
150
151 // Must place the World Physical volume unrotated at (0,0,0).
152 //
153 auto worldPV = new G4PVPlacement(nullptr, // no rotation
154 G4ThreeVector(), // at (0,0,0)
155 worldLV, // its logical volume
156 "World", // its name
157 nullptr, // its mother volume
158 false, // no boolean operations
159 0, // copy number
160 fCheckOverlaps); // checking overlaps
161
162 // Target
163
164 G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetLength+trackerSize));
165
166 auto targetS = new G4Tubs("target", 0., targetRadius, targetLength, 0. * deg, 360. * deg);
167 fLogicTarget = new G4LogicalVolume(targetS, fTargetMaterial, "Target", nullptr, nullptr, nullptr);
168 new G4PVPlacement(nullptr, // no rotation
169 positionTarget, // at (x,y,z)
170 fLogicTarget, // its logical volume
171 "Target", // its name
172 worldLV, // its mother volume
173 false, // no boolean operations
174 0, // copy number
175 fCheckOverlaps); // checking overlaps
176
177 G4cout << "Target is " << 2*targetLength/cm << " cm of "
178 << fTargetMaterial->GetName() << G4endl;
179
180 // Tracker
181
182 G4ThreeVector positionTracker = G4ThreeVector(0,0,0);
183
184 auto trackerS = new G4Tubs("tracker", 0, trackerSize, trackerSize, 0. * deg, 360. * deg);
185 auto trackerLV = new G4LogicalVolume(trackerS, air, "Tracker", nullptr, nullptr, nullptr);
186 new G4PVPlacement(nullptr, // no rotation
187 positionTracker, // at (x,y,z)
188 trackerLV, // its logical volume
189 "Tracker", // its name
190 worldLV, // its mother volume
191 false, // no boolean operations
192 0, // copy number
193 fCheckOverlaps); // checking overlaps
194
195 // Visualization attributes
196
197 G4VisAttributes boxVisAtt(G4Colour::White());
198 G4VisAttributes chamberVisAtt(G4Colour::Yellow());
199
200 worldLV ->SetVisAttributes(boxVisAtt);
201 fLogicTarget ->SetVisAttributes(boxVisAtt);
202 trackerLV ->SetVisAttributes(boxVisAtt);
203
204 // Tracker segments
205
206 G4cout << "There are " << fNbOfChambers << " chambers in the tracker region. "
207 << G4endl
208 << "The chambers are " << chamberWidth/cm << " cm of "
209 << fChamberMaterial->GetName() << G4endl
210 << "The distance between chamber is " << chamberSpacing/cm << " cm"
211 << G4endl;
212
213 G4double firstPosition = -trackerSize + chamberSpacing;
214 G4double firstLength = trackerLength/10;
215 G4double lastLength = trackerLength;
216
217 G4double halfWidth = 0.5*chamberWidth;
218 G4double rmaxFirst = 0.5 * firstLength;
219
220 G4double rmaxIncr = 0.0;
221 if( fNbOfChambers > 0 ){
222 rmaxIncr = 0.5 * (lastLength-firstLength)/(fNbOfChambers-1);
223 if (chamberSpacing < chamberWidth) {
224 G4Exception("DetectorConstruction::DefineVolumes()",
225 "InvalidSetup", FatalException,
226 "Width>Spacing");
227 }
228 }
229
230 for (G4int copyNo=0; copyNo<fNbOfChambers; copyNo++) {
231
232 G4double Zposition = firstPosition + copyNo * chamberSpacing;
233 G4double rmax = rmaxFirst + copyNo * rmaxIncr;
234
235 auto chamberS = new G4Tubs("Chamber_solid", 0, rmax, halfWidth, 0. * deg, 360. * deg);
236
237 fLogicChamber[copyNo] =
238 new G4LogicalVolume(chamberS, fChamberMaterial, "Chamber_LV", nullptr, nullptr, nullptr);
239
240 fLogicChamber[copyNo]->SetVisAttributes(chamberVisAtt);
241
242 new G4PVPlacement(nullptr, // no rotation
243 G4ThreeVector(0, 0, Zposition), // at (x,y,z)
244 fLogicChamber[copyNo], // its logical volume
245 "Chamber_PV", // its name
246 trackerLV, // its mother volume
247 false, // no boolean operations
248 copyNo, // copy number
249 fCheckOverlaps); // checking overlaps
250 }
251
252 // Example of User Limits
253 //
254 // Below is an example of how to set tracking constraints in a given
255 // logical volume
256 //
257 // Sets a max step length in the tracker region, with G4StepLimiter
258
259 G4double maxStep = 0.5*chamberWidth;
260 fStepLimit = new G4UserLimits(maxStep);
261 trackerLV->SetUserLimits(fStepLimit);
262
263 /// Set additional contraints on the track, with G4UserSpecialCuts
264 ///
265 /// G4double maxLength = 2*trackerLength, maxTime = 0.1*ns, minEkin = 10*MeV;
266 /// trackerLV->SetUserLimits(new G4UserLimits(maxStep,
267 /// maxLength,
268 /// maxTime,
269 /// minEkin));
270
271 // Always return the physical world
272
273 return worldPV;
274}

Member Data Documentation

◆ fMagFieldMessenger

G4ThreadLocal G4GlobalMagFieldMessenger * B2a::DetectorConstruction::fMagFieldMessenger = nullptr
staticprivate

Definition at line 73 of file DetectorConstruction.hh.

◆ fNbOfChambers

G4int B2a::DetectorConstruction::fNbOfChambers = 0
private

Definition at line 76 of file DetectorConstruction.hh.

◆ fLogicTarget

G4LogicalVolume* B2a::DetectorConstruction::fLogicTarget = nullptr
private

Definition at line 78 of file DetectorConstruction.hh.

◆ fLogicChamber

G4LogicalVolume** B2a::DetectorConstruction::fLogicChamber = nullptr
private

Definition at line 79 of file DetectorConstruction.hh.

◆ fTargetMaterial

G4Material* B2a::DetectorConstruction::fTargetMaterial = nullptr
private

Definition at line 81 of file DetectorConstruction.hh.

◆ fChamberMaterial

G4Material* B2a::DetectorConstruction::fChamberMaterial = nullptr
private

Definition at line 82 of file DetectorConstruction.hh.

◆ fStepLimit

G4UserLimits* B2a::DetectorConstruction::fStepLimit = nullptr
private

Definition at line 84 of file DetectorConstruction.hh.

◆ fMessenger

DetectorMessenger* B2a::DetectorConstruction::fMessenger = nullptr
private

Definition at line 86 of file DetectorConstruction.hh.

◆ fCheckOverlaps

G4bool B2a::DetectorConstruction::fCheckOverlaps = true
private

Definition at line 88 of file DetectorConstruction.hh.


The documentation for this class was generated from the following files:

Applications | User Support | Publications | Collaboration