Hello, I’m trying to add a magnetic field to the simulation following the example B5
- In the detectorconstruction
a. inB1DetectorConstruction::B1DetectorConstruction()
I added fMagneticLogical(nullptr)
b. in G4VPhysicalVolume* B1DetectorConstruction::Construct()
I built the volume
//magnet
G4LogicalVolume* MagnetlogicEnv;
G4Box* MagnetEnv;
MagnetEnv = new G4Box("MagnetEnv", 1.0*m, 1.0*m, 1.0*m);
MagnetlogicEnv= new G4LogicalVolume(MagnetEnv, vacuum, "Magnet");
new G4PVPlacement(0, //rotation
G4ThreeVector(0,0,5*cm), //at (0,0,fzFirDummyPos)
MagnetlogicEnv, //its logical volume
"Magnet", //its name
logicWorld, //its mother volume
false, //no boolean operation
0, //copy number
checkOverlaps); //overlaps checking
c. I added
void B1DetectorConstruction::ConstructSDandField()
{
// magnetic field ----------------------------------------------------------
fMagneticField = new B5MagneticField();
fFieldMgr = new G4FieldManager();
fFieldMgr->SetDetectorField(fMagneticField);
fFieldMgr->CreateChordFinder(fMagneticField);
G4bool forceToAllDaughters = true;
fMagneticLogical->SetFieldManager(fFieldMgr, forceToAllDaughters);
}
- In DetectorConstruction.hh
a. In class
B1DetectorConstruction : public G4VUserDetectorConstruction
{
private
I added
static G4ThreadLocal B5MagneticField* fMagneticField;
static G4ThreadLocal G4FieldManager* fFieldMgr;
G4LogicalVolume* fMagneticLogical;
Moreover, I copied in the src directory the B5MagneticField.cc
and in the include directory B5MagneticField.hh
but when I compile I get errors
C:\B1\include\B1DetectorConstruction.hh(95,40): error C2143: errore di sintassi: ';' mancante prima di '*' (compilazion
e del file di origine C:\B1\src\B1SteppingAction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,40): error C2143: errore di sintassi: ';' mancante prima di '*' (compilazion
e del file di origine C:\B1\exampleB1.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,40): error C4430: identificatore di tipo mancante, verrà utilizzato int. Not
a: default-int non è più supportato in C++ (compilazione del file di origine C:\B1\src\B1SteppingAction.cc) [C:\B1\B1-b
uild\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,40): error C4430: identificatore di tipo mancante, verrà utilizzato int. Not
a: default-int non è più supportato in C++ (compilazione del file di origine C:\B1\exampleB1.cc) [C:\B1\B1-build\exampl
eB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,56): error C2238: token imprevisti prima di ';' (compilazione del file di or
igine C:\B1\src\B1SteppingAction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,56): error C2238: token imprevisti prima di ';' (compilazione del file di or
igine C:\B1\exampleB1.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,41): error C2143: errore di sintassi: ';' mancante prima di '*' (compilazion
e del file di origine C:\B1\src\B1SteppingAction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,41): error C2143: errore di sintassi: ';' mancante prima di '*' (compilazion
e del file di origine C:\B1\exampleB1.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,41): error C4430: identificatore di tipo mancante, verrà utilizzato int. Not
a: default-int non è più supportato in C++ (compilazione del file di origine C:\B1\src\B1SteppingAction.cc) [C:\B1\B1-b
uild\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,41): error C4430: identificatore di tipo mancante, verrà utilizzato int. Not
a: default-int non è più supportato in C++ (compilazione del file di origine C:\B1\exampleB1.cc) [C:\B1\B1-build\exampl
eB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,52): error C2238: token imprevisti prima di ';' (compilazione del file di or
igine C:\B1\src\B1SteppingAction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,52): error C2238: token imprevisti prima di ';' (compilazione del file di or
igine C:\B1\exampleB1.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,40): error C2143: errore di sintassi: ';' mancante prima di '*' (compilazion
e del file di origine C:\B1\src\B1DetectorConstruction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,40): error C4430: identificatore di tipo mancante, verrà utilizzato int. Not
a: default-int non è più supportato in C++ (compilazione del file di origine C:\B1\src\B1DetectorConstruction.cc) [C:\B
1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,56): error C2238: token imprevisti prima di ';' (compilazione del file di or
igine C:\B1\src\B1DetectorConstruction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,41): error C2143: errore di sintassi: ';' mancante prima di '*' (compilazion
e del file di origine C:\B1\src\B1DetectorConstruction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,41): error C4430: identificatore di tipo mancante, verrà utilizzato int. Not
a: default-int non è più supportato in C++ (compilazione del file di origine C:\B1\src\B1DetectorConstruction.cc) [C:\B
1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,52): error C2238: token imprevisti prima di ';' (compilazione del file di or
igine C:\B1\src\B1DetectorConstruction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,40): error C2143: errore di sintassi: ';' mancante prima di '*' (compilazion
e del file di origine C:\B1\src\B1RunAction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,40): error C4430: identificatore di tipo mancante, verrà utilizzato int. Not
a: default-int non è più supportato in C++ (compilazione del file di origine C:\B1\src\B1RunAction.cc) [C:\B1\B1-build\
exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(95,56): error C2238: token imprevisti prima di ';' (compilazione del file di or
igine C:\B1\src\B1RunAction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,41): error C2143: errore di sintassi: ';' mancante prima di '*' (compilazion
e del file di origine C:\B1\src\B1RunAction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,41): error C4430: identificatore di tipo mancante, verrà utilizzato int. Not
a: default-int non è più supportato in C++ (compilazione del file di origine C:\B1\src\B1RunAction.cc) [C:\B1\B1-build\
exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(96,52): error C2238: token imprevisti prima di ';' (compilazione del file di or
igine C:\B1\src\B1RunAction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\src\B1DetectorConstruction.cc(57,56): error C2039: 'fMagneticField': non è un membro di 'B1DetectorConstruction'
[C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(41): message : vedere la dichiarazione di 'B1DetectorConstruction' [C:\B1\B1-bu
ild\exampleB1.vcxproj]
C:\B1\src\B1DetectorConstruction.cc(58,55): error C2039: 'fFieldMgr': non è un membro di 'B1DetectorConstruction' [C:\B
1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(41): message : vedere la dichiarazione di 'B1DetectorConstruction' [C:\B1\B1-bu
ild\exampleB1.vcxproj]
C:\B1\src\B1DetectorConstruction.cc(363,1): error C2509: 'ConstructSDandField': funzione membro non dichiarata in 'B1De
tectorConstruction' [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1DetectorConstruction.hh(41): message : vedere la dichiarazione di 'B1DetectorConstruction' [C:\B1\B1-bu
ild\exampleB1.vcxproj]
the line B1DetectorConstruction.hh(95,40): is
static G4ThreadLocal B5MagneticField* fMagneticField;
then I don’t understand what is the problem
B1DetectorConstruction.hh (4.3 KB)
B1DetectorConstruction.cc (15.1 KB)