├── LICENSE ├── README.rst ├── nipXray ├── Makefile ├── include │ ├── NXChamberParameterisation.hh │ ├── NXEventAction.hh │ ├── NXHit.hh │ ├── NXMagneticField.hh │ ├── NXPhysicsList.hh │ ├── NXPrimaryGeneratorAction.hh │ ├── NXRunAction.hh │ ├── NXSensitiveDetector.hh │ ├── NXSteppingAction.hh │ ├── NXSteppingVerbose.hh │ ├── NXUIMessenger.hh │ └── NXUserDetectorConstruction.hh ├── nipXray.cc └── src │ ├── NXChamberParameterisation.cc │ ├── NXEventAction.cc │ ├── NXHit.cc │ ├── NXMagneticField.cc │ ├── NXPhysicsList.cc │ ├── NXPrimaryGeneratorAction.cc │ ├── NXRunAction.cc │ ├── NXSensitiveDetector.cc │ ├── NXSteppingAction.cc │ ├── NXSteppingVerbose.cc │ ├── NXUIMessenger.cc │ └── NXUserDetectorConstruction.cc ├── obscurer ├── Makefile ├── cmds.geant4 ├── include │ ├── NXPhysicsList.hh │ ├── NXPrimaryGeneratorAction.hh │ ├── NXRunAction.hh │ ├── NXSensitiveDetector.hh │ └── NXUserDetectorConstruction.hh ├── main.cc └── src │ ├── NXPhysicsList.cc │ ├── NXPrimaryGeneratorAction.cc │ ├── NXRunAction.cc │ ├── NXSensitiveDetector.cc │ └── NXUserDetectorConstruction.cc └── simplest ├── Makefile ├── include ├── NXPhysicsList.hh ├── NXPrimaryGeneratorAction.hh ├── NXRunAction.hh ├── NXSensitiveDetector.hh └── NXUserDetectorConstruction.hh ├── main.cc └── src ├── NXPhysicsList.cc ├── NXPrimaryGeneratorAction.cc ├── NXRunAction.cc ├── NXSensitiveDetector.cc └── NXUserDetectorConstruction.cc /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, xrfind 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | GEANT4 Simple example 2 | --------------------------------------------------- 3 | 4 | Demo to show the simplest possible Geant4 example. 5 | 6 | Based on code from https://github.com/xrfind/old-geant4-program 7 | 8 | simplest: 9 | It sends a 2 keV photon from (0,0,0) to a detector plate at (0,0,1m). 10 | 11 | obscurer: 12 | A photo-electric absorber plate is placed between emitting source and detector 13 | 14 | -------------------------------------------------------------------------------- /nipXray/Makefile: -------------------------------------------------------------------------------- 1 | 2 | INC += -I /usr/include/geant4 -I include/ 3 | LIBS += -l CLHEP 4 | LIBS += -l G4global -l G4tracking -l G4run -l G4materials -l G4geometry -l G4particles -l G4processes -l G4event -l G4RayTracer -l G4digits_hits 5 | LIBS += -l G4interfaces -l G4intercoms -l G4graphics_reps -l G4vis_management -l G4OpenGL 6 | #LIBS += $(shell geant4-config --libs-without-gui) 7 | #LIBS += -lG4interfaces -lG4persistency -lG4error_propagation -lG4readout -lG4physicslists -lG4run -lG4event -lG4tracking -lG4parmodels -lG4processes -lG4digits_hits -lG4track -lG4particles -lG4geometry -lG4materials -lG4graphics_reps -lG4intercoms -lG4global 8 | #LIBS += -lG4digits_hits -lG4error_propagation -lG4event -lG4FR -lG4geometry -lG4gl2ps -lG4global -lG4GMocren -lG4graphics_reps -lG4intercoms -lG4interfaces -lG4materials -lG4modeling -lG4OpenGL -lG4parmodels -lG4particles -lG4persistency -lG4physicslists -lG4processes -lG4RayTracer -lG4readout -lG4run -lG4tracking -lG4track -lG4Tree -lG4visHepRep -lG4vis_management -lG4visXXX -lG4VRML 9 | 10 | src := src/NXChamberParameterisation.cc src/NXEventAction.cc src/NXHit.cc src/NXMagneticField.cc src/NXPhysicsList.cc src/NXPrimaryGeneratorAction.cc src/NXRunAction.cc src/NXSensitiveDetector.cc src/NXSteppingAction.cc src/NXSteppingVerbose.cc src/NXUIMessenger.cc src/NXUserDetectorConstruction.cc 11 | inc := include/NXChamberParameterisation.hh include/NXEventAction.hh include/NXHit.hh include/NXMagneticField.hh include/NXPhysicsList.hh include/NXPrimaryGeneratorAction.hh include/NXRunAction.hh include/NXSensitiveDetector.hh include/NXSteppingAction.hh include/NXSteppingVerbose.hh include/NXUIMessenger.hh include/NXUserDetectorConstruction.hh 12 | 13 | interim := $(subst .cc,.o,${src}) 14 | #CPPFLAGS += -Wall -Wextra -pedantic 15 | 16 | all: nipXray 17 | 18 | src/%.o: src/%.cc include/%.hh 19 | g++ ${CPPFLAGS} ${INC} $< -c -o $@ 20 | 21 | nipXray: nipXray.cc ${interim} 22 | g++ ${CPPFLAGS} ${INC} ${LIBS} $^ -o $@ 23 | 24 | clean: 25 | rm nipXray src/*.o 26 | 27 | #nipXray: nipXray.cc ${src} ${inc} 28 | # g++ ${libs} -I /usr/include/geant4 -I include/ nipXray.cc ${src} 29 | 30 | .PHONY: all clean -------------------------------------------------------------------------------- /nipXray/include/NXChamberParameterisation.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXChamberParameterisation_H 5 | #define NXChamberParameterisation_H 1 6 | 7 | #include "globals.hh" 8 | #include "G4VPVParameterisation.hh" 9 | #include "G4NistManager.hh" 10 | 11 | class G4VPhysicalVolume; 12 | class G4Box; 13 | 14 | // Dummy declarations to get rid of warnings ... 15 | class G4Trd; 16 | class G4Trap; 17 | class G4Cons; 18 | class G4Orb; 19 | class G4Sphere; 20 | class G4Torus; 21 | class G4Para; 22 | class G4Hype; 23 | class G4Tubs; 24 | class G4Polycone; 25 | class G4Polyhedra; 26 | 27 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 28 | 29 | class NXChamberParameterisation : public G4VPVParameterisation 30 | { 31 | public: 32 | 33 | NXChamberParameterisation( G4double startZ ); 34 | 35 | virtual 36 | ~NXChamberParameterisation(); 37 | 38 | void ComputeTransformation (const G4int copyNo, 39 | G4VPhysicalVolume* physVol) const; 40 | 41 | void ComputeDimensions (G4Box & trackerLayer, const G4int copyNo, 42 | const G4VPhysicalVolume* physVol) const; 43 | 44 | G4Material* ComputeMaterial(const G4int repNo,G4VPhysicalVolume *currentVol, 45 | const G4VTouchable *parentTouch=0); 46 | 47 | private: // Dummy declarations to get rid of warnings ... 48 | 49 | void ComputeDimensions (G4Trd&,const G4int,const G4VPhysicalVolume*) const {} 50 | void ComputeDimensions (G4Trap&,const G4int,const G4VPhysicalVolume*) const {} 51 | void ComputeDimensions (G4Cons&,const G4int,const G4VPhysicalVolume*) const {} 52 | void ComputeDimensions (G4Sphere&,const G4int,const G4VPhysicalVolume*) const {} 53 | void ComputeDimensions (G4Orb&,const G4int,const G4VPhysicalVolume*) const {} 54 | void ComputeDimensions (G4Torus&,const G4int,const G4VPhysicalVolume*) const {} 55 | void ComputeDimensions (G4Para&,const G4int,const G4VPhysicalVolume*) const {} 56 | void ComputeDimensions (G4Hype&,const G4int,const G4VPhysicalVolume*) const {} 57 | void ComputeDimensions (G4Tubs&,const G4int,const G4VPhysicalVolume*) const {} 58 | void ComputeDimensions (G4Polycone&,const G4int,const G4VPhysicalVolume*) const {} 59 | void ComputeDimensions (G4Polyhedra&,const G4int,const G4VPhysicalVolume*) const {} 60 | private: 61 | 62 | G4double fStartZ; 63 | G4Material* Fe; 64 | G4Material* Vacuum; 65 | }; 66 | 67 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 68 | 69 | #endif 70 | 71 | 72 | -------------------------------------------------------------------------------- /nipXray/include/NXEventAction.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXEventAction_h 5 | #define NXEventAction_h 1 6 | 7 | #include "G4UserEventAction.hh" 8 | 9 | class G4Event; 10 | 11 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 12 | 13 | class NXEventAction : public G4UserEventAction 14 | { 15 | public: 16 | NXEventAction(); 17 | ~NXEventAction(); 18 | 19 | public: 20 | void BeginOfEventAction(const G4Event*); 21 | void EndOfEventAction(const G4Event*); 22 | }; 23 | 24 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 25 | 26 | #endif 27 | 28 | 29 | -------------------------------------------------------------------------------- /nipXray/include/NXHit.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXHit_h 5 | #define NXHit_h 1 6 | 7 | #include "G4VHit.hh" 8 | #include "G4THitsCollection.hh" 9 | #include "G4Allocator.hh" 10 | #include "G4ThreeVector.hh" 11 | 12 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 13 | 14 | class NXHit : public G4VHit 15 | { 16 | public: 17 | 18 | NXHit(); 19 | ~NXHit(); 20 | NXHit(const NXHit&); 21 | const NXHit& operator=(const NXHit&); 22 | G4int operator==(const NXHit&) const; 23 | 24 | inline void* operator new(size_t); 25 | inline void operator delete(void*); 26 | 27 | void Draw(); 28 | void Print(); 29 | 30 | public: 31 | 32 | void SetTrackID (G4int track) { trackID = track; }; 33 | void SetChamberNb(G4int chamb) { chamberNb = chamb; }; 34 | void SetEdep (G4double de) { edep = de; }; 35 | void SetPos (G4ThreeVector xyz){ pos = xyz; }; 36 | 37 | G4int GetTrackID() { return trackID; }; 38 | G4int GetChamberNb() { return chamberNb; }; 39 | G4double GetEdep() { return edep; }; 40 | G4ThreeVector GetPos(){ return pos; }; 41 | 42 | private: 43 | 44 | G4int trackID; 45 | G4int chamberNb; 46 | G4double edep; 47 | G4ThreeVector pos; 48 | }; 49 | 50 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 | 52 | typedef G4THitsCollection NXHitsCollection; 53 | 54 | extern G4Allocator NXHitAllocator; 55 | 56 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 | 58 | inline void* NXHit::operator new(size_t) 59 | { 60 | void *aHit; 61 | aHit = (void *) NXHitAllocator.MallocSingle(); 62 | return aHit; 63 | } 64 | 65 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 66 | 67 | inline void NXHit::operator delete(void *aHit) 68 | { 69 | NXHitAllocator.FreeSingle((NXHit*) aHit); 70 | } 71 | 72 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /nipXray/include/NXMagneticField.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXMagneticField_H 5 | #define NXMagneticField_H 6 | 7 | #include "G4UniformMagField.hh" 8 | 9 | class G4FieldManager; 10 | 11 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 12 | 13 | 14 | class NXMagneticField: public G4UniformMagField 15 | { 16 | public: 17 | 18 | NXMagneticField(G4ThreeVector); // The value of the field 19 | NXMagneticField(); // A zero field 20 | ~NXMagneticField(); 21 | 22 | //Set the field (fieldValue,0,0) 23 | void SetMagFieldValue(G4double fieldValue); 24 | void SetMagFieldValue(G4ThreeVector fieldVector); 25 | 26 | G4ThreeVector GetConstantFieldValue(); 27 | 28 | protected: 29 | 30 | // Find the global Field Manager 31 | G4FieldManager* GetGlobalFieldManager(); // static 32 | }; 33 | 34 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /nipXray/include/NXPhysicsList.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXPhysicsList_h 5 | #define NXPhysicsList_h 1 6 | 7 | #include "G4VUserPhysicsList.hh" 8 | #include "globals.hh" 9 | 10 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 11 | 12 | class NXPhysicsList: public G4VUserPhysicsList 13 | { 14 | public: 15 | NXPhysicsList(); 16 | ~NXPhysicsList(); 17 | 18 | protected: 19 | // Construct particle and physics 20 | void ConstructParticle(); 21 | void ConstructProcess(); 22 | 23 | void SetCuts(); 24 | 25 | 26 | protected: 27 | // these methods Construct particles 28 | void ConstructBosons(); 29 | void ConstructLeptons(); 30 | void ConstructMesons(); 31 | void ConstructBaryons(); 32 | void ConstructIons(); 33 | 34 | protected: 35 | // these methods Construct physics processes and register them 36 | void ConstructGeneral(); 37 | void ConstructEM(); 38 | void AddStepMax(); 39 | }; 40 | 41 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 42 | 43 | #endif 44 | 45 | 46 | -------------------------------------------------------------------------------- /nipXray/include/NXPrimaryGeneratorAction.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXPrimaryGeneratorAction_h 5 | #define NXPrimaryGeneratorAction_h 1 6 | 7 | #include "G4VUserPrimaryGeneratorAction.hh" 8 | 9 | class NXUserDetectorConstruction; 10 | class G4ParticleGun; 11 | class G4Event; 12 | 13 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 14 | 15 | class NXPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction 16 | { 17 | public: 18 | NXPrimaryGeneratorAction(NXUserDetectorConstruction*); 19 | ~NXPrimaryGeneratorAction(); 20 | 21 | public: 22 | void GeneratePrimaries(G4Event*); 23 | 24 | private: 25 | G4ParticleGun* particleGun; 26 | NXUserDetectorConstruction* myDetector; 27 | }; 28 | 29 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 30 | 31 | #endif 32 | 33 | 34 | -------------------------------------------------------------------------------- /nipXray/include/NXRunAction.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXRunAction_h 5 | #define NXRunAction_h 1 6 | 7 | #include "G4UserRunAction.hh" 8 | #include "globals.hh" 9 | 10 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 11 | 12 | class G4Run; 13 | 14 | class NXRunAction : public G4UserRunAction 15 | { 16 | public: 17 | NXRunAction(); 18 | ~NXRunAction(); 19 | 20 | public: 21 | void BeginOfRunAction(const G4Run*); 22 | void EndOfRunAction(const G4Run*); 23 | 24 | G4int CenterESofGamma[2000]; 25 | G4int CenterESofPositron[2000]; 26 | G4int CenterESofNegatron[2000]; 27 | G4int NumofPrePointNotBoundary; 28 | G4int NumofPrePointIsBoundary; 29 | G4int OtherParticle; 30 | G4double EnergyofGammaContrb; 31 | G4double EnergyofNegatronContrb; 32 | G4double EnergyofPositronContrb; 33 | G4double EnergyofOtherParticleContrb; 34 | 35 | }; 36 | 37 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 38 | 39 | #endif 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /nipXray/include/NXSensitiveDetector.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXSensitiveDetector_h 5 | #define NXSensitiveDetector_h 1 6 | 7 | #include "G4VSensitiveDetector.hh" 8 | #include "NXHit.hh" 9 | 10 | class G4Step; 11 | class G4HCofThisEvent; 12 | 13 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 14 | 15 | class NXSensitiveDetector : public G4VSensitiveDetector 16 | { 17 | public: 18 | NXSensitiveDetector(G4String); 19 | ~NXSensitiveDetector(); 20 | 21 | void Initialize(G4HCofThisEvent*); 22 | G4bool ProcessHits(G4Step*, G4TouchableHistory*); 23 | void EndOfEvent(G4HCofThisEvent*); 24 | 25 | private: 26 | NXHitsCollection* trackerCollection; 27 | 28 | }; 29 | 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /nipXray/include/NXSteppingAction.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXSteppingAction_h 5 | #define NXSteppingAction_h 1 6 | 7 | #include "G4UserSteppingAction.hh" 8 | 9 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 10 | 11 | class NXSteppingAction : public G4UserSteppingAction 12 | { 13 | public: 14 | NXSteppingAction(); 15 | ~NXSteppingAction(){}; 16 | 17 | void UserSteppingAction(const G4Step*); 18 | }; 19 | 20 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /nipXray/include/NXSteppingVerbose.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | class NXSteppingVerbose; 5 | 6 | #ifndef NXSteppingVerbose_h 7 | #define NXSteppingVerbose_h 1 8 | 9 | #include "G4SteppingVerbose.hh" 10 | 11 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 12 | 13 | class NXSteppingVerbose : public G4SteppingVerbose 14 | { 15 | public: 16 | 17 | NXSteppingVerbose(); 18 | ~NXSteppingVerbose(); 19 | 20 | void StepInfo(); 21 | void TrackingStarted(); 22 | 23 | }; 24 | 25 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /nipXray/include/NXUIMessenger.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXUIMessenger_h 5 | #define NXUIMessenger_h 1 6 | 7 | #include "globals.hh" 8 | #include "G4UImessenger.hh" 9 | 10 | class NXUserDetectorConstruction; 11 | class G4UIdirectory; 12 | class G4UIcmdWithAString; 13 | class G4UIcmdWithADoubleAndUnit; 14 | 15 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 16 | 17 | class NXUIMessenger: public G4UImessenger 18 | { 19 | public: 20 | NXUIMessenger(NXUserDetectorConstruction*); 21 | ~NXUIMessenger(); 22 | 23 | void SetNewValue(G4UIcommand*, G4String); 24 | 25 | private: 26 | NXUserDetectorConstruction* myDetector; 27 | 28 | G4UIdirectory* N02Dir; 29 | G4UIdirectory* detDir; 30 | G4UIcmdWithAString* TargMatCmd; 31 | G4UIcmdWithAString* ChamMatCmd; 32 | G4UIcmdWithADoubleAndUnit* FieldCmd; 33 | G4UIcmdWithADoubleAndUnit* StepMaxCmd; 34 | G4UIcmdWithADoubleAndUnit* TargetLengthZCmd; 35 | G4UIcmdWithADoubleAndUnit* OneFeLengthZCmd; 36 | G4UIcmdWithADoubleAndUnit* GapinTargetCmd; 37 | }; 38 | 39 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /nipXray/include/NXUserDetectorConstruction.hh: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #ifndef NXUserDetectorConstruction_h 5 | #define NXUserDetectorConstruction_h 1 6 | 7 | #include "globals.hh" 8 | #include "G4VUserDetectorConstruction.hh" 9 | #include "NXMagneticField.hh" 10 | 11 | class G4Box; 12 | class G4LogicalVolume; 13 | class G4VPhysicalVolume; 14 | class G4Material; 15 | class G4VPVParameterisation; 16 | class G4UserLimits; 17 | class NXUIMessenger; 18 | 19 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 20 | 21 | class NXUserDetectorConstruction : public G4VUserDetectorConstruction 22 | { 23 | public: 24 | 25 | NXUserDetectorConstruction(); 26 | ~NXUserDetectorConstruction(); 27 | 28 | public: 29 | 30 | G4VPhysicalVolume* Construct(); 31 | 32 | const 33 | G4VPhysicalVolume* GetTracker() {return physiTracker;}; 34 | //G4double GetTrackerFullLength() {return fTrackerLength;}; 35 | //G4double GetTargetFullLength() {return fTargetLength;}; 36 | G4double GetWorldFullLength() {return fWorldLength;}; 37 | 38 | void setTargetMaterial (G4String); 39 | void setOneFeLengthZ( G4double); 40 | void setTargetLengthZ (G4double); 41 | void setGapinTarget(G4double); 42 | void setChamberMaterial(G4String); 43 | void SetMagField(G4double); 44 | void SetMaxStep (G4double); 45 | 46 | private: 47 | 48 | G4Box* solidWorld; // pointer to the solid envelope 49 | G4LogicalVolume* logicWorld; // pointer to the logical envelope 50 | G4VPhysicalVolume* physiWorld; // pointer to the physical envelope 51 | 52 | G4Box* solidTarget; // pointer to the solid Target 53 | G4LogicalVolume* logicTarget; // pointer to the logical Target 54 | G4VPhysicalVolume* physiTarget; // pointer to the physical Target 55 | G4VPhysicalVolume* physiTargetArray[10]; // pointer to the physical Target 56 | 57 | G4Box *solidoneFe; 58 | G4LogicalVolume* logiconeFe; 59 | G4VPhysicalVolume* physioneFe; 60 | 61 | G4Box* solidTracker; // pointer to the solid Tracker 62 | G4LogicalVolume* logicTracker; // pointer to the logical Tracker 63 | G4VPhysicalVolume* physiTracker; // pointer to the physical Tracker 64 | 65 | G4Box* solidChamber; // pointer to the solid Chamber 66 | G4LogicalVolume* logicChamber; // pointer to the logical Chamber 67 | G4VPhysicalVolume* physiChamber; // pointer to the physical Chamber 68 | 69 | G4Material* TargetMater; // pointer to the target material 70 | G4Material* ChamberMater; // pointer to the chamber material 71 | 72 | G4VPVParameterisation* chamberParam; // pointer to chamber parameterisation 73 | G4UserLimits* stepLimit; // pointer to user step limits 74 | 75 | NXMagneticField* fpMagField; // pointer to the magnetic field 76 | 77 | NXUIMessenger* detectorMessenger; // pointer to the Messenger 78 | 79 | G4double fWorldLength; // Full length of the world volume 80 | G4double fTargetLength; 81 | G4int NbOfChambers; // Nb of chambers in the tracker region 82 | G4double GapinTarget; 83 | }; 84 | 85 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /nipXray/nipXray.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXUserDetectorConstruction.hh" 5 | #include "NXPhysicsList.hh" 6 | #include "NXPrimaryGeneratorAction.hh" 7 | #include "NXRunAction.hh" 8 | #include "NXEventAction.hh" 9 | #include "NXSteppingAction.hh" 10 | #include "NXSteppingVerbose.hh" 11 | 12 | #include "G4RunManager.hh" 13 | #include "G4UImanager.hh" 14 | #include "G4UIterminal.hh" 15 | #include "G4UItcsh.hh" 16 | 17 | #include "G4Timer.hh" 18 | #include "ctime" 19 | #include "cstdio" 20 | 21 | #ifdef G4VIS_USE 22 | #include "G4VisExecutive.hh" 23 | #endif 24 | 25 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 26 | 27 | int main(int argc,char** argv) 28 | { 29 | G4Timer myTimer; 30 | myTimer.Start(); 31 | time_t lt = time(NULL); 32 | printf("the beginning time is %s", ctime(<)); 33 | 34 | // User Verbose output class 35 | // 36 | G4VSteppingVerbose* verbosity = new NXSteppingVerbose; 37 | G4VSteppingVerbose::SetInstance(verbosity); 38 | 39 | // Run manager 40 | // 41 | G4RunManager * runManager = new G4RunManager; 42 | 43 | // User Initialization classes (mandatory) 44 | // 45 | NXUserDetectorConstruction* detector = new NXUserDetectorConstruction; 46 | runManager->SetUserInitialization(detector); 47 | // 48 | G4VUserPhysicsList* physics = new NXPhysicsList; 49 | runManager->SetUserInitialization(physics); 50 | 51 | // User Action classes 52 | // 53 | G4VUserPrimaryGeneratorAction* gen_action = new NXPrimaryGeneratorAction(detector); 54 | runManager->SetUserAction(gen_action); 55 | // 56 | G4UserRunAction* run_action = new NXRunAction; 57 | runManager->SetUserAction(run_action); 58 | // 59 | G4UserEventAction* event_action = new NXEventAction; 60 | runManager->SetUserAction(event_action); 61 | // 62 | G4UserSteppingAction* stepping_action = new NXSteppingAction; 63 | runManager->SetUserAction(stepping_action); 64 | 65 | // Initialize G4 kernel 66 | // 67 | runManager->Initialize(); 68 | 69 | // Get the pointer to the User Interface manager 70 | // 71 | G4UImanager * UI = G4UImanager::GetUIpointer(); 72 | 73 | #ifdef G4VIS_USE 74 | G4VisManager* visManager = new G4VisExecutive; 75 | visManager->Initialize(); 76 | #endif 77 | 78 | if (argc!=1) // batch mode 79 | { 80 | G4String command = "/control/execute "; 81 | G4String fileName = argv[1]; 82 | UI->ApplyCommand(command+fileName); 83 | } 84 | else // interactive mode : define visualization and UI terminal 85 | { 86 | G4UIsession * session = 0; 87 | #ifdef G4UI_USE_TCSH 88 | session = new G4UIterminal(new G4UItcsh); 89 | #else 90 | session = new G4UIterminal(); 91 | #endif 92 | #ifdef G4VIS_USE 93 | UI->ApplyCommand("/control/execute macs/vis.mac"); 94 | #endif 95 | session->SessionStart(); 96 | delete session; 97 | } 98 | 99 | // Free the store: user actions, physics_list and detector_description are 100 | // owned and deleted by the run manager, so they should not 101 | // be deleted in the main() program ! 102 | 103 | #ifdef G4VIS_USE 104 | delete visManager; 105 | #endif 106 | 107 | delete runManager; 108 | delete verbosity; 109 | 110 | lt = time(NULL); 111 | printf( "the end time is %s", ctime(<)); 112 | myTimer.Stop(); 113 | G4cout<<"Spend time:"<FindOrBuildMaterial("G4_Fe"); //26 18 | Vacuum=new G4Material("Vacuum",1.0,1.01*g/mole,1.0E-25*g/cm3,kStateGas,2.73*kelvin, 3.0E-18*pascal); 19 | } 20 | 21 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 22 | 23 | NXChamberParameterisation::~NXChamberParameterisation() 24 | { 25 | delete Fe; 26 | delete Vacuum; 27 | } 28 | 29 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 30 | 31 | void NXChamberParameterisation::ComputeTransformation 32 | (const G4int copyNo, G4VPhysicalVolume* physVol) const 33 | { 34 | G4double Zposition= fStartZ+copyNo*2*cm; 35 | physVol->SetTranslation(G4ThreeVector(0,0,Zposition)); 36 | physVol->SetRotation(0); 37 | } 38 | 39 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 40 | 41 | void NXChamberParameterisation::ComputeDimensions 42 | (G4Box& trackerChamber, const G4int copyNo, const G4VPhysicalVolume*) const 43 | { 44 | trackerChamber.SetXHalfLength(2*cm); 45 | trackerChamber.SetYHalfLength(2*cm); 46 | trackerChamber.SetZHalfLength(0.5*cm); 47 | } 48 | 49 | G4Material* NXChamberParameterisation::ComputeMaterial (const G4int copyNo,G4VPhysicalVolume * physVol,const G4VTouchable*) 50 | { 51 | //if(copyNo == 0) { 52 | // physVol->GetLogicalVolume()->SetMaterial(Fe); 53 | // return Fe; 54 | //} 55 | physVol->GetLogicalVolume()->SetMaterial(Vacuum); 56 | return Vacuum; 57 | } 58 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 | -------------------------------------------------------------------------------- /nipXray/src/NXEventAction.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXEventAction.hh" 5 | 6 | #include "G4Event.hh" 7 | #include "G4EventManager.hh" 8 | #include "G4TrajectoryContainer.hh" 9 | #include "G4Trajectory.hh" 10 | #include "G4ios.hh" 11 | 12 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 13 | 14 | NXEventAction::NXEventAction() 15 | {} 16 | 17 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 18 | 19 | NXEventAction::~NXEventAction() 20 | {} 21 | 22 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 23 | 24 | void NXEventAction::BeginOfEventAction(const G4Event*) 25 | {} 26 | 27 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 28 | 29 | void NXEventAction::EndOfEventAction(const G4Event* evt) 30 | { 31 | G4int event_id = evt->GetEventID(); 32 | 33 | /* 34 | // get number of stored trajectories 35 | // 36 | G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer(); 37 | G4int n_trajectories = 0; 38 | if (trajectoryContainer) n_trajectories = trajectoryContainer->entries(); 39 | 40 | // periodic printing 41 | // 42 | if (event_id < 100 || event_id%100 == 0) { 43 | G4cout << ">>> Event " << evt->GetEventID() << G4endl; 44 | G4cout << " " << n_trajectories 45 | << " trajectories stored in this event." << G4endl; 46 | } 47 | */ 48 | } 49 | 50 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 | -------------------------------------------------------------------------------- /nipXray/src/NXHit.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXHit.hh" 5 | #include "G4UnitsTable.hh" 6 | #include "G4VVisManager.hh" 7 | #include "G4Circle.hh" 8 | #include "G4Colour.hh" 9 | #include "G4VisAttributes.hh" 10 | 11 | G4Allocator NXHitAllocator; 12 | 13 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 14 | 15 | NXHit::NXHit() {} 16 | 17 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 18 | 19 | NXHit::~NXHit() {} 20 | 21 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 22 | 23 | NXHit::NXHit(const NXHit& right) : 24 | G4VHit() 25 | { 26 | trackID = right.trackID; 27 | chamberNb = right.chamberNb; 28 | edep = right.edep; 29 | pos = right.pos; 30 | } 31 | 32 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 | 34 | const NXHit& NXHit::operator=(const NXHit& right) 35 | { 36 | trackID = right.trackID; 37 | chamberNb = right.chamberNb; 38 | edep = right.edep; 39 | pos = right.pos; 40 | return *this; 41 | } 42 | 43 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 44 | 45 | G4int NXHit::operator==(const NXHit& right) const 46 | { 47 | return (this==&right) ? 1 : 0; 48 | } 49 | 50 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 | 52 | void NXHit::Draw() 53 | { 54 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 55 | if(pVVisManager) 56 | { 57 | G4Circle circle(pos); 58 | circle.SetScreenSize(2.); 59 | circle.SetFillStyle(G4Circle::filled); 60 | G4Colour colour(1.,0.,0.); 61 | G4VisAttributes attribs(colour); 62 | circle.SetVisAttributes(attribs); 63 | pVVisManager->Draw(circle); 64 | } 65 | } 66 | 67 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 68 | 69 | void NXHit::Print() 70 | { 71 | G4cout << " trackID: " << trackID << " chamberNb: " << chamberNb 72 | << " energy deposit: " << G4BestUnit(edep,"Energy") 73 | << " position: " << G4BestUnit(pos,"Length") << G4endl; 74 | } 75 | 76 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 77 | 78 | -------------------------------------------------------------------------------- /nipXray/src/NXMagneticField.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXMagneticField.hh" 5 | #include "G4FieldManager.hh" 6 | #include "G4TransportationManager.hh" 7 | 8 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 9 | 10 | NXMagneticField::NXMagneticField() : 11 | G4UniformMagField(G4ThreeVector()) 12 | { 13 | GetGlobalFieldManager()->SetDetectorField(this); 14 | GetGlobalFieldManager()->CreateChordFinder(this); 15 | } 16 | 17 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 18 | 19 | NXMagneticField::NXMagneticField(G4ThreeVector fieldVector) : 20 | G4UniformMagField(fieldVector) 21 | { 22 | GetGlobalFieldManager()->SetDetectorField(this); 23 | GetGlobalFieldManager()->CreateChordFinder(this); 24 | } 25 | 26 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 27 | 28 | NXMagneticField::~NXMagneticField() 29 | { 30 | } 31 | 32 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 | 34 | // Set the value of the Global Field to fieldValue along X 35 | // 36 | void NXMagneticField::SetMagFieldValue(G4double fieldValue) 37 | { 38 | SetMagFieldValue(G4ThreeVector(fieldValue,0,0)); 39 | } 40 | 41 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 42 | 43 | // Set the value of the Global Field 44 | // 45 | void NXMagneticField::SetMagFieldValue(G4ThreeVector fieldVector) 46 | { 47 | // Find the Field Manager for the global field 48 | G4FieldManager* fieldMgr= GetGlobalFieldManager(); 49 | 50 | if(fieldVector!=G4ThreeVector(0.,0.,0.)) 51 | { 52 | SetFieldValue(fieldVector); 53 | fieldMgr->SetDetectorField(this); 54 | } else { 55 | // If the new field's value is Zero, then it is best to 56 | // insure that it is not used for propagation. 57 | G4MagneticField* magField = 0; 58 | fieldMgr->SetDetectorField(magField); 59 | } 60 | } 61 | 62 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 | 64 | G4FieldManager* NXMagneticField::GetGlobalFieldManager() 65 | { 66 | return G4TransportationManager::GetTransportationManager()->GetFieldManager(); 67 | } 68 | 69 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 | -------------------------------------------------------------------------------- /nipXray/src/NXPhysicsList.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "globals.hh" 5 | #include "NXPhysicsList.hh" 6 | 7 | #include "G4ProcessManager.hh" 8 | #include "G4ParticleTypes.hh" 9 | 10 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 11 | 12 | NXPhysicsList::NXPhysicsList(): G4VUserPhysicsList() 13 | { 14 | defaultCutValue = 1.0*cm; 15 | SetVerboseLevel(1); 16 | } 17 | 18 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 19 | 20 | NXPhysicsList::~NXPhysicsList() 21 | {} 22 | 23 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 24 | 25 | void NXPhysicsList::ConstructParticle() 26 | { 27 | // In this method, static member functions should be called 28 | // for all particles which you want to use. 29 | // This ensures that objects of these particle types will be 30 | // created in the program. 31 | 32 | // there are six major categories: lepton, meson, baryon, boson, shortlived and ion. but here is four. I think they are enougy. (Rui) 33 | ConstructBosons(); 34 | ConstructLeptons(); 35 | ConstructMesons(); 36 | ConstructBaryons(); 37 | 38 | // I add another particle category. 39 | ConstructIons(); 40 | 41 | } 42 | 43 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 44 | 45 | void NXPhysicsList::ConstructBosons() 46 | { 47 | // pseudo-particles 48 | G4Geantino::GeantinoDefinition(); 49 | G4ChargedGeantino::ChargedGeantinoDefinition(); 50 | 51 | // gamma 52 | G4Gamma::GammaDefinition(); 53 | 54 | // optical photon 55 | G4OpticalPhoton::OpticalPhotonDefinition(); 56 | } 57 | 58 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 | 60 | #include "G4LeptonConstructor.hh" 61 | void NXPhysicsList::ConstructLeptons() 62 | { 63 | // Construct all leptons 64 | G4LeptonConstructor pConstructor; 65 | pConstructor.ConstructParticle(); 66 | } 67 | 68 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 69 | 70 | #include "G4MesonConstructor.hh" 71 | void NXPhysicsList::ConstructMesons() 72 | { 73 | // Construct all mesons 74 | G4MesonConstructor pConstructor; 75 | pConstructor.ConstructParticle(); 76 | } 77 | 78 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 | 80 | #include "G4BaryonConstructor.hh" 81 | void NXPhysicsList::ConstructBaryons() 82 | { 83 | // Construct all barions 84 | G4BaryonConstructor pConstructor; 85 | pConstructor.ConstructParticle(); 86 | } 87 | 88 | #include "G4IonConstructor.hh" 89 | void NXPhysicsList::ConstructIons() 90 | { 91 | // Construct light ions 92 | G4IonConstructor pConstructor; 93 | pConstructor.ConstructParticle(); 94 | } 95 | 96 | 97 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 98 | 99 | void NXPhysicsList::ConstructProcess() 100 | { 101 | AddTransportation(); 102 | ConstructEM(); 103 | ConstructGeneral(); 104 | AddStepMax(); 105 | } 106 | 107 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 108 | 109 | #include "G4ComptonScattering.hh" 110 | #include "G4GammaConversion.hh" 111 | #include "G4PhotoElectricEffect.hh" 112 | 113 | #include "G4eMultipleScattering.hh" 114 | #include "G4hMultipleScattering.hh" 115 | 116 | #include "G4eIonisation.hh" 117 | #include "G4eBremsstrahlung.hh" 118 | #include "G4eplusAnnihilation.hh" 119 | 120 | #include "G4MuIonisation.hh" 121 | #include "G4MuBremsstrahlung.hh" 122 | #include "G4MuPairProduction.hh" 123 | 124 | #include "G4hIonisation.hh" 125 | #include "G4hBremsstrahlung.hh" 126 | #include "G4hPairProduction.hh" 127 | 128 | #include "G4ionIonisation.hh" 129 | 130 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 131 | 132 | void NXPhysicsList::ConstructEM() 133 | { 134 | theParticleIterator->reset(); 135 | while( (*theParticleIterator)() ){ 136 | G4ParticleDefinition* particle = theParticleIterator->value(); 137 | G4ProcessManager* pmanager = particle->GetProcessManager(); 138 | G4String particleName = particle->GetParticleName(); 139 | 140 | if (particleName == "gamma") { 141 | // gamma 142 | pmanager->AddDiscreteProcess(new G4PhotoElectricEffect); 143 | pmanager->AddDiscreteProcess(new G4ComptonScattering); 144 | pmanager->AddDiscreteProcess(new G4GammaConversion); 145 | 146 | } else if (particleName == "e-") { 147 | //electron 148 | pmanager->AddProcess(new G4eMultipleScattering, -1, 1, 1); 149 | pmanager->AddProcess(new G4eIonisation, -1, 2, 2); 150 | pmanager->AddProcess(new G4eBremsstrahlung, -1, 3, 3); 151 | 152 | } else if (particleName == "e+") { 153 | //positron 154 | pmanager->AddProcess(new G4eMultipleScattering, -1, 1, 1); 155 | pmanager->AddProcess(new G4eIonisation, -1, 2, 2); 156 | pmanager->AddProcess(new G4eBremsstrahlung, -1, 3, 3); 157 | pmanager->AddProcess(new G4eplusAnnihilation, 0,-1, 4); 158 | 159 | } else if( particleName == "mu+" || 160 | particleName == "mu-" ) { 161 | //muon 162 | pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); 163 | pmanager->AddProcess(new G4MuIonisation, -1, 2, 2); 164 | pmanager->AddProcess(new G4MuBremsstrahlung, -1, 3, 3); 165 | pmanager->AddProcess(new G4MuPairProduction, -1, 4, 4); 166 | 167 | } else if( particleName == "proton" || 168 | particleName == "pi-" || 169 | particleName == "pi+" ) { 170 | //proton 171 | pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); 172 | pmanager->AddProcess(new G4hIonisation, -1, 2, 2); 173 | pmanager->AddProcess(new G4hBremsstrahlung, -1, 3, 3); 174 | pmanager->AddProcess(new G4hPairProduction, -1, 4, 4); 175 | 176 | } else if( particleName == "alpha" || 177 | particleName == "He3" || 178 | particleName == "GenericIon" ) { 179 | //Ions 180 | pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); 181 | pmanager->AddProcess(new G4ionIonisation, -1, 2, 2); 182 | 183 | } else if ((!particle->IsShortLived()) && 184 | (particle->GetPDGCharge() != 0.0) && 185 | (particle->GetParticleName() != "chargedgeantino")) { 186 | //all others charged particles except geantino 187 | pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); 188 | pmanager->AddProcess(new G4hIonisation, -1, 2, 2); 189 | } 190 | } 191 | } 192 | 193 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 194 | 195 | #include "G4Decay.hh" 196 | 197 | void NXPhysicsList::ConstructGeneral() 198 | { 199 | // Add Decay Process 200 | G4Decay* theDecayProcess = new G4Decay(); 201 | theParticleIterator->reset(); 202 | while( (*theParticleIterator)() ){ 203 | G4ParticleDefinition* particle = theParticleIterator->value(); 204 | G4ProcessManager* pmanager = particle->GetProcessManager(); 205 | if (theDecayProcess->IsApplicable(*particle)) { 206 | pmanager ->AddProcess(theDecayProcess); 207 | // set ordering for PostStepDoIt and AtRestDoIt 208 | pmanager ->SetProcessOrdering(theDecayProcess, idxPostStep); 209 | pmanager ->SetProcessOrdering(theDecayProcess, idxAtRest); 210 | } 211 | } 212 | } 213 | 214 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 215 | 216 | #include "G4StepLimiter.hh" 217 | #include "G4UserSpecialCuts.hh" 218 | 219 | void NXPhysicsList::AddStepMax() 220 | { 221 | // Step limitation seen as a process 222 | G4StepLimiter* stepLimiter = new G4StepLimiter(); 223 | ////G4UserSpecialCuts* userCuts = new G4UserSpecialCuts(); 224 | 225 | theParticleIterator->reset(); 226 | while ((*theParticleIterator)()){ 227 | G4ParticleDefinition* particle = theParticleIterator->value(); 228 | G4ProcessManager* pmanager = particle->GetProcessManager(); 229 | 230 | if (particle->GetPDGCharge() != 0.0) 231 | { 232 | pmanager ->AddDiscreteProcess(stepLimiter); 233 | ////pmanager ->AddDiscreteProcess(userCuts); 234 | } 235 | } 236 | } 237 | 238 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 239 | 240 | void NXPhysicsList::SetCuts() 241 | { 242 | //G4VUserPhysicsList::SetCutsWithDefault method sets 243 | //the default cut value for all particle types 244 | // 245 | SetCutsWithDefault(); 246 | 247 | if (verboseLevel>0) DumpCutValuesTable(); 248 | } 249 | 250 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 251 | 252 | -------------------------------------------------------------------------------- /nipXray/src/NXPrimaryGeneratorAction.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXPrimaryGeneratorAction.hh" 5 | #include "NXUserDetectorConstruction.hh" 6 | 7 | #include "G4Event.hh" 8 | #include "G4ParticleGun.hh" 9 | #include "G4ParticleTable.hh" 10 | #include "G4ParticleDefinition.hh" 11 | #include "globals.hh" 12 | 13 | #include "Randomize.hh" 14 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 15 | 16 | NXPrimaryGeneratorAction::NXPrimaryGeneratorAction( NXUserDetectorConstruction* myDC) : 17 | myDetector(myDC) 18 | { 19 | G4int n_particle = 1; 20 | particleGun = new G4ParticleGun(n_particle); 21 | 22 | // default particle 23 | 24 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); 25 | G4ParticleDefinition* particle = particleTable->FindParticle("e-"); 26 | //G4ParticleDefinition* particle = particleTable->FindParticle("gamma"); 27 | //G4ParticleDefinition* particle = particleTable->FindParticle("neutron"); 28 | //G4ParticleDefinition* particle = particleTable->FindParticle("alpha"); 29 | //G4ParticleDefinition* particle = particleTable->FindParticle("proton"); 30 | 31 | particleGun->SetParticleDefinition(particle); 32 | 33 | G4double position = -799.5*mm; 34 | particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position)); 35 | } 36 | 37 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 38 | 39 | NXPrimaryGeneratorAction::~NXPrimaryGeneratorAction() 40 | { 41 | delete particleGun; 42 | } 43 | 44 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 | 46 | void NXPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 47 | { 48 | /* 49 | // For Focus 50 | G4double x2y2_2 = 10*G4UniformRand(); 51 | G4double phi=twopi*G4UniformRand(); 52 | G4double x=x2y2_2*std::sin(phi); 53 | G4double y=x2y2_2*std::cos(phi); 54 | G4double z=232; 55 | particleGun->SetParticleMomentumDirection(G4ThreeVector(x,y,z)); 56 | */ 57 | 58 | /* 59 | // For discrete Energy Spectrum 60 | particleGun->SetParticleMomentumDirection(G4ThreeVector(0,0,1)); 61 | G4double energyPara; 62 | G4double rand=G4UniformRand(); 63 | if(rand<0.006662231) energyPara=0.2*MeV; 64 | else if(rand<0.019986694) energyPara=0.4*MeV; 65 | else if(rand<0.039973387) energyPara=0.6*MeV; 66 | else if(rand<0.066622312) energyPara=0.8*MeV; 67 | else if(rand<0.099933468) energyPara=1*MeV; 68 | else if(rand<0.139906855) energyPara=1.2*MeV; 69 | else if(rand<0.186542474) energyPara=1.4*MeV; 70 | else if(rand<0.239840323) energyPara=1.6*MeV; 71 | else if(rand<0.299800404) energyPara=1.8*MeV; 72 | else if(rand<0.366422716) energyPara=2*MeV; 73 | else if(rand<0.429713913) energyPara=2.2*MeV; 74 | else if(rand<0.489673993) energyPara=2.4*MeV; 75 | else if(rand<0.546302959) energyPara=2.6*MeV; 76 | else if(rand<0.599600808) energyPara=2.8*MeV; 77 | else if(rand<0.649567542) energyPara=3*MeV; 78 | else if(rand<0.696203161) energyPara=3.2*MeV; 79 | else if(rand<0.739507663) energyPara=3.4*MeV; 80 | else if(rand<0.779481051) energyPara=3.6*MeV; 81 | else if(rand<0.816123322) energyPara=3.8*MeV; 82 | else if(rand<0.849434478) energyPara=4*MeV; 83 | else if(rand<0.879414339) energyPara=4.2*MeV; 84 | else if(rand<0.906063104) energyPara=4.4*MeV; 85 | else if(rand<0.929380773) energyPara=4.6*MeV; 86 | else if(rand<0.949367347) energyPara=4.8*MeV; 87 | else if(rand<0.966022825) energyPara=5*MeV; 88 | else if(rand<0.979347207) energyPara=6*MeV; 89 | else if(rand<0.989340494) energyPara=8*MeV; 90 | else if(rand<0.996002685) energyPara=10*MeV; 91 | else if(rand<0.999333781) energyPara=15*MeV; 92 | else if(rand<1) energyPara=20*MeV; 93 | particleGun->SetParticleEnergy(energyPara); 94 | */ 95 | 96 | /* 97 | G4double mean; 98 | G4double stddev; 99 | mean = 0; 100 | stddev = 0.3*mm/2.35482; 101 | G4double x2plusy2_2; 102 | x2plusy2_2 = G4RandGauss::shoot(mean,stddev); 103 | G4double phi=twopi*G4UniformRand(); 104 | phi=3.1415926*G4UniformRand(); 105 | G4double x=x2plusy2_2*std::sin(phi); 106 | G4double y=x2plusy2_2*std::cos(phi); 107 | G4double z = -799.5*mm; 108 | particleGun->SetParticlePosition(G4ThreeVector(x,y,z)); 109 | */ 110 | 111 | particleGun->SetParticleMomentumDirection(G4ThreeVector(0,0,1)); 112 | particleGun->SetParticleEnergy(20*MeV); 113 | particleGun->GeneratePrimaryVertex(anEvent); 114 | } 115 | 116 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 117 | 118 | -------------------------------------------------------------------------------- /nipXray/src/NXRunAction.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXRunAction.hh" 5 | 6 | #include "G4Run.hh" 7 | 8 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 9 | 10 | NXRunAction::NXRunAction() 11 | {} 12 | 13 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 14 | 15 | NXRunAction::~NXRunAction() 16 | {} 17 | 18 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 19 | 20 | void NXRunAction::BeginOfRunAction(const G4Run* aRun) 21 | { 22 | G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; 23 | for(G4int i=0;i<2000;i++) { 24 | CenterESofGamma[i]=0; 25 | CenterESofPositron[i]=0; 26 | CenterESofNegatron[i]=0; 27 | } 28 | NumofPrePointNotBoundary=0; 29 | NumofPrePointIsBoundary=0; 30 | OtherParticle=0; 31 | EnergyofGammaContrb=0; 32 | EnergyofNegatronContrb=0; 33 | EnergyofPositronContrb=0; 34 | } 35 | 36 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 37 | 38 | void NXRunAction::EndOfRunAction(const G4Run*) 39 | { 40 | G4int AllNumofGamma=0; 41 | G4int AllNumofPositron=0; 42 | G4int AllNumofNegatron=0; 43 | for(G4int i=0;i<2000;i++) { 44 | AllNumofGamma+=CenterESofGamma[i]; 45 | AllNumofPositron+=CenterESofPositron[i]; 46 | AllNumofNegatron+=CenterESofNegatron[i]; 47 | } 48 | 49 | G4double CenterESofGammaPerC[2000]; 50 | G4double CenterESofPositronPerC[2000]; 51 | G4double CenterESofNegatronPerC[2000]; 52 | for (G4int i=0;i<2000;i++) { 53 | CenterESofGammaPerC[i]=1.0*CenterESofGamma[i]/AllNumofGamma; 54 | CenterESofPositronPerC[i]=1.0*CenterESofPositron[i]/AllNumofPositron; 55 | CenterESofNegatronPerC[i]=1.0*CenterESofNegatron[i]/AllNumofNegatron; 56 | } 57 | 58 | G4cout<GetCollectionID(collectionName[0]); } 35 | HCE->AddHitsCollection( HCID, trackerCollection ); 36 | } 37 | 38 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 39 | 40 | G4bool NXSensitiveDetector::ProcessHits(G4Step* aStep,G4TouchableHistory*) 41 | { 42 | G4StepPoint* pointPre=aStep->GetPreStepPoint(); 43 | G4StepPoint* pointPost=aStep->GetPostStepPoint(); 44 | 45 | G4TouchableHandle touchCur=pointPre->GetTouchableHandle(); 46 | 47 | G4VPhysicalVolume* volumeCur=touchCur->GetVolume(); 48 | 49 | G4String volumeCurName=volumeCur->GetName(); 50 | 51 | G4int copyNumofChamber=touchCur->GetCopyNumber(); 52 | 53 | G4Track* trackCur=aStep->GetTrack(); 54 | 55 | G4ParticleDefinition* particleCur = trackCur->GetDefinition(); 56 | G4String particleCurName = particleCur->GetParticleName(); 57 | 58 | G4double kineticEnergyCur = trackCur->GetKineticEnergy(); 59 | 60 | G4RunManager* runManager= G4RunManager::GetRunManager(); 61 | NXRunAction* runActionCur=(NXRunAction *)runManager->GetUserRunAction(); 62 | 63 | if(volumeCurName == "Chamber") { 64 | if(copyNumofChamber == 0) { 65 | if (pointPre->GetStepStatus() != fGeomBoundary) { 66 | runActionCur->NumofPrePointNotBoundary++; 67 | } else { 68 | runActionCur->NumofPrePointIsBoundary++; 69 | } 70 | 71 | if(particleCurName == "gamma") { 72 | runActionCur->EnergyofGammaContrb+=kineticEnergyCur; 73 | for(G4int i=0;i<2000;i++) { 74 | if(kineticEnergyCur<=((i+1)*0.01*MeV) && kineticEnergyCur>(i*0.01*MeV)) { 75 | runActionCur->CenterESofGamma[i]++; 76 | break; 77 | } 78 | } 79 | } else if(particleCurName == "e+") { 80 | runActionCur->EnergyofPositronContrb+=kineticEnergyCur; 81 | for(G4int i=0;i<2000;i++) { 82 | if(kineticEnergyCur<=((i+1)*0.01*MeV) && kineticEnergyCur>(i*0.01*MeV)) { 83 | runActionCur->CenterESofPositron[i]++; 84 | break; 85 | } 86 | } 87 | } else if(particleCurName == "e-") { 88 | runActionCur->EnergyofNegatronContrb+=kineticEnergyCur; 89 | for(G4int i=0;i<2000;i++) { 90 | if(kineticEnergyCur<=(0.01*(i+1.0)*MeV) && kineticEnergyCur>(i*0.01*MeV)) { 91 | runActionCur->CenterESofNegatron[i]++; 92 | break; 93 | } 94 | } 95 | } else { 96 | runActionCur->EnergyofOtherParticleContrb+=kineticEnergyCur; 97 | runActionCur->OtherParticle++; 98 | G4double edep = aStep->GetTotalEnergyDeposit(); 99 | 100 | if(edep==0.) return false; 101 | 102 | NXHit* newHit = new NXHit(); 103 | newHit->SetTrackID (aStep->GetTrack()->GetTrackID()); 104 | newHit->SetChamberNb(aStep->GetPreStepPoint()->GetTouchableHandle() 105 | ->GetCopyNumber()); 106 | newHit->SetEdep (edep); 107 | newHit->SetPos (aStep->GetPostStepPoint()->GetPosition()); 108 | trackerCollection->insert( newHit ); 109 | } 110 | } 111 | } 112 | 113 | //newHit->Print(); 114 | //newHit->Draw(); 115 | 116 | return true; 117 | } 118 | 119 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 120 | 121 | void NXSensitiveDetector::EndOfEvent(G4HCofThisEvent*) 122 | { 123 | if (verboseLevel>0) { 124 | G4int NbHits = trackerCollection->entries(); 125 | G4cout << "\n-------->Hits Collection: in this event they are " << NbHits 126 | << " hits in the tracker chambers: " << G4endl; 127 | for (G4int i=0;iPrint(); 128 | } 129 | } 130 | 131 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 132 | 133 | -------------------------------------------------------------------------------- /nipXray/src/NXSteppingAction.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXSteppingAction.hh" 5 | #include "G4SteppingManager.hh" 6 | 7 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 8 | 9 | NXSteppingAction::NXSteppingAction() 10 | { } 11 | 12 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 13 | 14 | void NXSteppingAction::UserSteppingAction(const G4Step*) 15 | { 16 | } 17 | 18 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 19 | 20 | -------------------------------------------------------------------------------- /nipXray/src/NXSteppingVerbose.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXSteppingVerbose.hh" 5 | 6 | #include "G4SteppingManager.hh" 7 | #include "G4UnitsTable.hh" 8 | 9 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 10 | 11 | NXSteppingVerbose::NXSteppingVerbose() 12 | {} 13 | 14 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 15 | 16 | NXSteppingVerbose::~NXSteppingVerbose() 17 | {} 18 | 19 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 20 | 21 | void NXSteppingVerbose::StepInfo() 22 | { 23 | CopyState(); 24 | 25 | G4int prec = G4cout.precision(3); 26 | 27 | if( verboseLevel >= 1 ){ 28 | if( verboseLevel >= 4 ) VerboseTrack(); 29 | if( verboseLevel >= 3 ){ 30 | G4cout << G4endl; 31 | G4cout << std::setw( 5) << "#Step#" << " " 32 | << std::setw( 6) << "X" << " " 33 | << std::setw( 6) << "Y" << " " 34 | << std::setw( 6) << "Z" << " " 35 | << std::setw( 9) << "KineE" << " " 36 | << std::setw( 9) << "dEStep" << " " 37 | << std::setw(10) << "StepLeng" 38 | << std::setw(10) << "TrakLeng" 39 | << std::setw(10) << "Volume" << " " 40 | << std::setw(10) << "Process" << G4endl; 41 | } 42 | 43 | G4cout << std::setw(5) << fTrack->GetCurrentStepNumber() << " " 44 | << std::setw(6) << G4BestUnit(fTrack->GetPosition().x(),"Length") 45 | << std::setw(6) << G4BestUnit(fTrack->GetPosition().y(),"Length") 46 | << std::setw(6) << G4BestUnit(fTrack->GetPosition().z(),"Length") 47 | << std::setw(6) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy") 48 | << std::setw(6) << G4BestUnit(fStep->GetTotalEnergyDeposit(),"Energy") 49 | << std::setw(6) << G4BestUnit(fStep->GetStepLength(),"Length") 50 | << std::setw(6) << G4BestUnit(fTrack->GetTrackLength(),"Length") 51 | << " "; 52 | 53 | if( fTrack->GetNextVolume() != 0 ) { 54 | G4cout << std::setw(10) << fTrack->GetVolume()->GetName(); 55 | } else { 56 | G4cout << std::setw(10) << "OutOfWorld"; 57 | } 58 | 59 | if(fStep->GetPostStepPoint()->GetProcessDefinedStep() != NULL){ 60 | G4cout << " " 61 | << std::setw(10) << fStep->GetPostStepPoint()->GetProcessDefinedStep() 62 | ->GetProcessName(); 63 | } else { 64 | G4cout << " UserLimit"; 65 | } 66 | 67 | G4cout << G4endl; 68 | 69 | if( verboseLevel == 2 ){ 70 | G4int tN2ndariesTot = fN2ndariesAtRestDoIt + 71 | fN2ndariesAlongStepDoIt + 72 | fN2ndariesPostStepDoIt; 73 | if(tN2ndariesTot>0){ 74 | G4cout << " :----- List of 2ndaries - " 75 | << "#SpawnInStep=" << std::setw(3) << tN2ndariesTot 76 | << "(Rest=" << std::setw(2) << fN2ndariesAtRestDoIt 77 | << ",Along=" << std::setw(2) << fN2ndariesAlongStepDoIt 78 | << ",Post=" << std::setw(2) << fN2ndariesPostStepDoIt 79 | << "), " 80 | << "#SpawnTotal=" << std::setw(3) << (*fSecondary).size() 81 | << " ---------------" 82 | << G4endl; 83 | 84 | for(size_t lp1=(*fSecondary).size()-tN2ndariesTot; 85 | lp1<(*fSecondary).size(); lp1++){ 86 | G4cout << " : " 87 | << std::setw(6) 88 | << G4BestUnit((*fSecondary)[lp1]->GetPosition().x(),"Length") 89 | << std::setw(6) 90 | << G4BestUnit((*fSecondary)[lp1]->GetPosition().y(),"Length") 91 | << std::setw(6) 92 | << G4BestUnit((*fSecondary)[lp1]->GetPosition().z(),"Length") 93 | << std::setw(6) 94 | << G4BestUnit((*fSecondary)[lp1]->GetKineticEnergy(),"Energy") 95 | << std::setw(10) 96 | << (*fSecondary)[lp1]->GetDefinition()->GetParticleName(); 97 | G4cout << G4endl; 98 | } 99 | 100 | G4cout << " :-----------------------------" 101 | << "----------------------------------" 102 | << "-- EndOf2ndaries Info ---------------" 103 | << G4endl; 104 | } 105 | } 106 | 107 | } 108 | G4cout.precision(prec); 109 | } 110 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 111 | 112 | void NXSteppingVerbose::TrackingStarted() 113 | { 114 | 115 | CopyState(); 116 | G4int prec = G4cout.precision(3); 117 | if( verboseLevel > 0 ){ 118 | 119 | G4cout << std::setw( 5) << "Step#" << " " 120 | << std::setw( 6) << "X" << " " 121 | << std::setw( 6) << "Y" << " " 122 | << std::setw( 6) << "Z" << " " 123 | << std::setw( 9) << "KineE" << " " 124 | << std::setw( 9) << "dEStep" << " " 125 | << std::setw(10) << "StepLeng" 126 | << std::setw(10) << "TrakLeng" 127 | << std::setw(10) << "Volume" << " " 128 | << std::setw(10) << "Process" << G4endl; 129 | 130 | G4cout << std::setw(5) << fTrack->GetCurrentStepNumber() << " " 131 | << std::setw(6) << G4BestUnit(fTrack->GetPosition().x(),"Length") 132 | << std::setw(6) << G4BestUnit(fTrack->GetPosition().y(),"Length") 133 | << std::setw(6) << G4BestUnit(fTrack->GetPosition().z(),"Length") 134 | << std::setw(6) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy") 135 | << std::setw(6) << G4BestUnit(fStep->GetTotalEnergyDeposit(),"Energy") 136 | << std::setw(6) << G4BestUnit(fStep->GetStepLength(),"Length") 137 | << std::setw(6) << G4BestUnit(fTrack->GetTrackLength(),"Length") 138 | << " "; 139 | 140 | if(fTrack->GetNextVolume()){ 141 | G4cout << std::setw(10) << fTrack->GetVolume()->GetName(); 142 | } else { 143 | G4cout << std::setw(10) << "OutOfWorld"; 144 | } 145 | G4cout << " initStep" << G4endl; 146 | } 147 | G4cout.precision(prec); 148 | } 149 | 150 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 151 | -------------------------------------------------------------------------------- /nipXray/src/NXUIMessenger.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXUIMessenger.hh" 5 | 6 | #include "NXUserDetectorConstruction.hh" 7 | #include "G4UIdirectory.hh" 8 | #include "G4UIcmdWithAString.hh" 9 | #include "G4UIcmdWithADoubleAndUnit.hh" 10 | #include "globals.hh" 11 | 12 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 13 | 14 | NXUIMessenger::NXUIMessenger(NXUserDetectorConstruction* myDet) : 15 | myDetector(myDet) 16 | { 17 | N02Dir = new G4UIdirectory("/N02/"); 18 | N02Dir->SetGuidance("UI commands specific to this example."); 19 | 20 | detDir = new G4UIdirectory("/N02/det/"); 21 | detDir->SetGuidance("detector control."); 22 | 23 | TargMatCmd = new G4UIcmdWithAString("/NX/TargetMaterial",this); 24 | TargMatCmd->SetGuidance("Select Material of the Target."); 25 | TargMatCmd->SetParameterName("choice",false); 26 | TargMatCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 27 | 28 | ChamMatCmd = new G4UIcmdWithAString("/N02/det/setChamberMate",this); 29 | ChamMatCmd->SetGuidance("Select Material of the Target."); 30 | ChamMatCmd->SetParameterName("choice",false); 31 | ChamMatCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 32 | 33 | FieldCmd = new G4UIcmdWithADoubleAndUnit("/N02/det/setField",this); 34 | FieldCmd->SetGuidance("Define magnetic field."); 35 | FieldCmd->SetGuidance("Magnetic field will be in X direction."); 36 | FieldCmd->SetParameterName("Bx",false); 37 | FieldCmd->SetUnitCategory("Magnetic flux density"); 38 | FieldCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 39 | 40 | StepMaxCmd = new G4UIcmdWithADoubleAndUnit("/N02/det/stepMax",this); 41 | StepMaxCmd->SetGuidance("Define a step max"); 42 | StepMaxCmd->SetParameterName("stepMax",false); 43 | StepMaxCmd->SetUnitCategory("Length"); 44 | StepMaxCmd->AvailableForStates(G4State_Idle); 45 | 46 | TargetLengthZCmd = new G4UIcmdWithADoubleAndUnit("/NX/TargetLengthZ",this); 47 | TargetLengthZCmd->SetGuidance("redefine the length of target."); 48 | TargetLengthZCmd->SetParameterName("TargetLengthZ",false); 49 | TargetLengthZCmd->SetUnitCategory("Length"); 50 | TargetLengthZCmd->AvailableForStates(G4State_Idle); 51 | 52 | OneFeLengthZCmd = new G4UIcmdWithADoubleAndUnit("/NX/OneFeLengthZ",this); 53 | OneFeLengthZCmd->SetGuidance("redefine the length of oneFe."); 54 | OneFeLengthZCmd->SetParameterName("OneFeLengthZ",false); 55 | OneFeLengthZCmd->SetUnitCategory("Length"); 56 | OneFeLengthZCmd->AvailableForStates(G4State_Idle); 57 | 58 | GapinTargetCmd = new G4UIcmdWithADoubleAndUnit("/NX/GapinTarget",this); 59 | GapinTargetCmd->SetGuidance("define the gap between target."); 60 | GapinTargetCmd->SetParameterName("GapinTarget",false); 61 | GapinTargetCmd->SetUnitCategory("Length"); 62 | GapinTargetCmd->AvailableForStates(G4State_Idle); 63 | } 64 | 65 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 66 | 67 | NXUIMessenger::~NXUIMessenger() 68 | { 69 | delete TargMatCmd; 70 | delete ChamMatCmd; 71 | delete FieldCmd; 72 | delete StepMaxCmd; 73 | delete TargetLengthZCmd; 74 | delete detDir; 75 | delete N02Dir; 76 | } 77 | 78 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 | 80 | void NXUIMessenger::SetNewValue(G4UIcommand* command,G4String newValue) 81 | { 82 | if( command == TargMatCmd ) 83 | { myDetector->setTargetMaterial(newValue);} 84 | 85 | if( command == ChamMatCmd ) 86 | { myDetector->setChamberMaterial(newValue);} 87 | 88 | if( command == FieldCmd ) 89 | { myDetector->SetMagField(FieldCmd->GetNewDoubleValue(newValue));} 90 | 91 | if( command == StepMaxCmd ) 92 | { myDetector->SetMaxStep(StepMaxCmd->GetNewDoubleValue(newValue));} 93 | 94 | if( command == TargetLengthZCmd) 95 | { myDetector->setTargetLengthZ(TargetLengthZCmd->GetNewDoubleValue(newValue));} 96 | 97 | if( command == OneFeLengthZCmd) 98 | { myDetector->setOneFeLengthZ(OneFeLengthZCmd->GetNewDoubleValue(newValue));} 99 | 100 | if( command == GapinTargetCmd) 101 | { myDetector->setGapinTarget(GapinTargetCmd->GetNewDoubleValue(newValue));} 102 | } 103 | 104 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 105 | -------------------------------------------------------------------------------- /nipXray/src/NXUserDetectorConstruction.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXUserDetectorConstruction.hh" 5 | #include "NXUIMessenger.hh" 6 | #include "NXChamberParameterisation.hh" 7 | #include "NXMagneticField.hh" 8 | #include "NXSensitiveDetector.hh" 9 | 10 | #include "G4Material.hh" 11 | #include "G4Box.hh" 12 | #include "G4LogicalVolume.hh" 13 | #include "G4PVPlacement.hh" 14 | #include "G4PVParameterised.hh" 15 | #include "G4SDManager.hh" 16 | #include "G4GeometryTolerance.hh" 17 | #include "G4GeometryManager.hh" 18 | 19 | #include "G4UserLimits.hh" 20 | 21 | #include "G4VisAttributes.hh" 22 | #include "G4Colour.hh" 23 | 24 | #include "G4ios.hh" 25 | 26 | #include "G4NistManager.hh" 27 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 28 | 29 | NXUserDetectorConstruction::NXUserDetectorConstruction() : 30 | solidWorld(0), logicWorld(0), physiWorld(0), 31 | solidTarget(0), logicTarget(0), physiTarget(0), 32 | solidTracker(0),logicTracker(0),physiTracker(0), 33 | solidoneFe(0),logiconeFe(0),physioneFe(0), 34 | solidChamber(0),logicChamber(0),physiChamber(0), 35 | TargetMater(0), ChamberMater(0),chamberParam(0), 36 | stepLimit(0), fpMagField(0), 37 | fWorldLength(0.), GapinTarget(0), fTargetLength(0), 38 | NbOfChambers(0) 39 | { 40 | //In NXMagneticField, the constructor does everything. now there is no MagneticField, because there is no G4threevector variable in () and it mean the MagneticField is zero. 41 | fpMagField = new NXMagneticField(); 42 | detectorMessenger = new NXUIMessenger(this); 43 | for(G4int i=0;i<10;i++) { 44 | physiTargetArray[i]=0; 45 | } 46 | } 47 | 48 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 | 50 | NXUserDetectorConstruction::~NXUserDetectorConstruction() 51 | { 52 | delete fpMagField; 53 | delete stepLimit; 54 | delete chamberParam; 55 | delete detectorMessenger; 56 | } 57 | 58 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 | 60 | G4VPhysicalVolume* NXUserDetectorConstruction::Construct() 61 | { 62 | //--------- Material definition --------- 63 | 64 | G4double a, z; 65 | G4double density, temperature, pressure; 66 | G4int nel; 67 | 68 | //Air 69 | G4Element* N = new G4Element("Nitrogen", "N", z=7., a= 14.01*g/mole); 70 | G4Element* O = new G4Element("Oxygen" , "O", z=8., a= 16.00*g/mole); 71 | 72 | G4Material* Air = new G4Material("Air", density= 1.29*mg/cm3, nel=2); 73 | Air->AddElement(N, 70*perCent); 74 | Air->AddElement(O, 30*perCent); 75 | 76 | //Lead 77 | G4Material* Pb = new G4Material("Lead", z=82., a= 207.19*g/mole, density= 11.35*g/cm3); 78 | 79 | //Xenon gas 80 | G4Material* Xenon = new G4Material("XenonGas", z=54., a=131.29*g/mole, density= 5.458*mg/cm3, kStateGas, temperature= 293.15*kelvin, pressure= 1*atmosphere); 81 | 82 | //Use Nist material Database instead of build material by myself. 83 | G4NistManager* man=G4NistManager::Instance(); 84 | G4Material* PMMANist=man->FindOrBuildMaterial("G4_PLEXIGLASS"); 85 | G4Material* Al=man->FindOrBuildMaterial("G4_Al"); //13 86 | 87 | //G4Material* Ti=man->FindOrBuildMaterial("G4_Ti"); //22 88 | G4Material* V=man->FindOrBuildMaterial("G4_V"); //23 89 | //G4Material* Cr=man->FindOrBuildMaterial("G4_Cr"); //24 90 | //G4Material* Mn=man->FindOrBuildMaterial("G4_Mn"); //25 91 | G4Material* Fe=man->FindOrBuildMaterial("G4_Fe"); //26 92 | //G4Material* Co=man->FindOrBuildMaterial("G4_Co"); //27 93 | //G4Material* Ni=man->FindOrBuildMaterial("G4_Ni"); //28 94 | G4Material* Cu=man->FindOrBuildMaterial("G4_Cu"); //29 95 | 96 | G4Material* Mo=man->FindOrBuildMaterial("G4_Mo"); //42 97 | G4Material* Ag=man->FindOrBuildMaterial("G4_Ag"); //47 98 | 99 | G4Material* Ta=man->FindOrBuildMaterial("G4_Ta");//73 100 | G4Material* W=man->FindOrBuildMaterial("G4_W");//74 101 | G4Material* Au=man->FindOrBuildMaterial("G4_Au");//79 102 | 103 | // build material by myself. 104 | //vacuum 105 | G4Material* Vacuum=new G4Material("Vacuum",1.0,1.01*g/mole,1.0E-25*g/cm3,kStateGas,2.73*kelvin,3.0E-18*pascal); 106 | //Ta 107 | G4Material* Ta_byme = new G4Material( "Ta", 73., 180.95*g/mole, 16.65* g/cm3 ); 108 | 109 | // Print all the materials defined. 110 | // 111 | G4cout << G4endl << "The materials defined are : " << G4endl << G4endl; 112 | G4cout << *(G4Material::GetMaterialTable()) << G4endl; 113 | 114 | 115 | //--------- Definitions of Solids, Logical Volumes, Physical Volumes --------- 116 | 117 | //------------------------------ 118 | // World 119 | //------------------------------ 120 | 121 | fWorldLength= 2*m; 122 | G4double HalfWorldLength = 0.5*fWorldLength; 123 | 124 | G4GeometryManager::GetInstance()->SetWorldMaximumExtent(fWorldLength); 125 | G4cout << "Computed tolerance = " 126 | << G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()/mm 127 | << " mm" << G4endl; 128 | 129 | solidWorld= new G4Box("world",HalfWorldLength,HalfWorldLength,HalfWorldLength); 130 | logicWorld= new G4LogicalVolume( solidWorld, Vacuum, "World", 0, 0, 0); 131 | 132 | // Must place the World Physical volume unrotated at (0,0,0). 133 | // 134 | physiWorld = new G4PVPlacement(0, // no rotation 135 | G4ThreeVector(), // at (0,0,0) 136 | logicWorld, // its logical volume 137 | "World", // its name 138 | 0, // its mother volume 139 | false, // no boolean operations 140 | 0); // copy number 141 | 142 | //------------------------------ 143 | // Target 144 | //------------------------------ 145 | 146 | TargetMater = Ta; 147 | G4ThreeVector positionTarget = G4ThreeVector(0,0,-70*cm); 148 | fTargetLength=1*mm; 149 | G4double fHalfTargetLength=0.5*fTargetLength; 150 | 151 | solidTarget = new G4Box("target", 2*cm, 2*cm, fHalfTargetLength); 152 | logicTarget = new G4LogicalVolume(solidTarget,TargetMater,"Target",0,0,0); 153 | for(G4int i=0;i<24;i++) { 154 | G4double z=-70*cm+i*(GapinTarget+2*(solidTarget->GetZHalfLength())); 155 | positionTarget=G4ThreeVector(0,0,z); 156 | physiTargetArray[i] = new G4PVPlacement(0, // no rotation 157 | positionTarget, // at (x,y,z) 158 | logicTarget, // its logical volume 159 | "Target", // its name 160 | logicWorld, // its mother volume 161 | false, // no boolean operations 162 | 0); // copy number 163 | } 164 | 165 | //------------------------------ 166 | // OneFe 167 | //------------------------------ 168 | G4ThreeVector positiononeFe= G4ThreeVector(0,0,0); 169 | 170 | solidoneFe= new G4Box("oneFe", 5*cm, 5*cm, 5*mm); 171 | logiconeFe= new G4LogicalVolume(solidoneFe, Fe, "OneFe",0,0,0); 172 | physioneFe= new G4PVPlacement(0, // no rotation 173 | positiononeFe, // at (x,y,z) 174 | logiconeFe, // its logical volume 175 | "Tracker", // its name 176 | logicWorld, // its mother volume 177 | false, // no boolean operations 178 | 0); // copy number 179 | 180 | 181 | //------------------------------ 182 | // Tracker 183 | //------------------------------ 184 | 185 | G4ThreeVector positionTracker = G4ThreeVector(0,0,20*cm); 186 | 187 | solidTracker = new G4Box("tracker", 5*cm, 5*cm, 5*cm); 188 | logicTracker = new G4LogicalVolume(solidTracker , Vacuum, "Tracker",0,0,0); 189 | physiTracker = new G4PVPlacement(0, // no rotation 190 | positionTracker, // at (x,y,z) 191 | logicTracker, // its logical volume 192 | "Tracker", // its name 193 | logicWorld, // its mother volume 194 | false, // no boolean operations 195 | 0); // copy number 196 | 197 | //------------------------------ 198 | // Tracker segments 199 | //------------------------------ 200 | // 201 | // An example of Parameterised volumes 202 | // dummy values for G4Box -- modified by parameterised volume 203 | 204 | NbOfChambers = 1; 205 | ChamberMater = Vacuum; 206 | 207 | solidChamber = new G4Box("chamber", 1*cm, 1*cm, 0.5*cm); 208 | logicChamber = new G4LogicalVolume(solidChamber,ChamberMater,"Chamber",0,0,0); 209 | 210 | G4double firstPosition = 0; 211 | 212 | chamberParam = new NXChamberParameterisation( firstPosition); 213 | 214 | // dummy value : kZAxis -- modified by parameterised volume 215 | // 216 | physiChamber = new G4PVParameterised( 217 | "Chamber", // their name 218 | logicChamber, // their logical volume 219 | logicTracker, // Mother logical volume 220 | kZAxis, // Are placed along this axis 221 | NbOfChambers, // Number of chambers 222 | chamberParam); // The parametrisation 223 | 224 | G4cout << "There are " << NbOfChambers << " chambers in the tracker region. " 225 | << ChamberMater->GetName() << "\n The distance between chamber is " 226 | << " cm" << G4endl; 227 | 228 | G4cout<<"The world is G4Box, fWorldLength is "<AddNewDetector( aTrackerSD ); 240 | logicChamber->SetSensitiveDetector( aTrackerSD ); 241 | 242 | //--------- Visualization attributes ------------------------------- 243 | //G4Colour white () // white 244 | //G4Colour white (1.0, 1.0, 1.0) // white 245 | //G4Colour gray (0.5, 0.5, 0.5) // gray 246 | //G4Colour black (0.0, 0.0, 0.0) // black 247 | //G4Colour red (1.0, 0.0, 0.0) // red 248 | //G4Colour green (0.0, 1.0, 0.0) // green 249 | //G4Colour blue (0.0, 0.0, 1.0) // blue 250 | //G4Colour cyan (0.0, 1.0, 1.0) // cyan 251 | //G4Colour magenta (1.0, 0.0, 1.0) // magenta 252 | //G4Colour yellow (1.0, 1.0, 0.0) // yellow 253 | 254 | G4VisAttributes* BoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0)); 255 | logicWorld ->SetVisAttributes(BoxVisAtt); //white 256 | 257 | G4VisAttributes* TargetVisAtt= new G4VisAttributes(G4Colour(0,0,1.0)); 258 | logicTarget ->SetVisAttributes(TargetVisAtt); //blue 259 | 260 | G4VisAttributes* TrackerVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0)); 261 | logicTracker->SetVisAttributes(TrackerVisAtt); //yellow 262 | 263 | G4VisAttributes* ChamberVisAtt = new G4VisAttributes(G4Colour(0,1.0,0.0)); 264 | logicChamber->SetVisAttributes(ChamberVisAtt); //green 265 | 266 | //--------- example of User Limits ------------------------------- 267 | 268 | // below is an example of how to set tracking constraints in a given 269 | // logical volume(see also in NXPhysicsList how to setup the processes 270 | // G4StepLimiter or G4UserSpecialCuts). 271 | 272 | // Sets a max Step length in the tracker region, with G4StepLimiter 273 | // 274 | G4double maxStep = 0.5*cm; 275 | stepLimit = new G4UserLimits(maxStep); 276 | logicTracker->SetUserLimits(stepLimit); 277 | 278 | return physiWorld; 279 | } 280 | 281 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 282 | 283 | void NXUserDetectorConstruction::setTargetMaterial(G4String materialName) 284 | { 285 | // search the material by its name 286 | G4Material* pttoMaterial = G4Material::GetMaterial(materialName); 287 | if (pttoMaterial) 288 | {TargetMater = pttoMaterial; 289 | logicTarget->SetMaterial(pttoMaterial); 290 | G4cout << "\n----> The target is " << materialName << G4endl; 291 | } 292 | } 293 | 294 | void NXUserDetectorConstruction::setTargetLengthZ(G4double z) 295 | { 296 | solidTarget->SetZHalfLength(z/2); 297 | } 298 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 299 | 300 | void NXUserDetectorConstruction::setGapinTarget(G4double gap) 301 | { 302 | GapinTarget=gap; 303 | G4ThreeVector positionTarget = G4ThreeVector(0,0,-70*cm); 304 | for(G4int i=0;i<10;i++) { 305 | G4double z=-70*cm+i*(GapinTarget+2*(solidTarget->GetZHalfLength())); 306 | positionTarget=G4ThreeVector(0,0,z); 307 | delete physiTargetArray[i]; 308 | physiTargetArray[i]= new G4PVPlacement(0, // no rotation 309 | positionTarget, // at (x,y,z) 310 | logicTarget, // its logical volume 311 | "Target", // its name 312 | logicWorld, // its mother volume 313 | false, // no boolean operations 314 | 0); // copy number 315 | } 316 | } 317 | 318 | void NXUserDetectorConstruction::setChamberMaterial(G4String materialName) 319 | { 320 | // search the material by its name 321 | G4Material* pttoMaterial = G4Material::GetMaterial(materialName); 322 | if (pttoMaterial) 323 | {ChamberMater = pttoMaterial; 324 | logicChamber->SetMaterial(pttoMaterial); 325 | G4cout << "\n----> The chambers are " << materialName << G4endl; 326 | } 327 | } 328 | 329 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 330 | 331 | void NXUserDetectorConstruction::SetMagField(G4double fieldValue) 332 | { 333 | fpMagField->SetFieldValue(G4ThreeVector(fieldValue,0,0)); 334 | } 335 | 336 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 337 | 338 | void NXUserDetectorConstruction::SetMaxStep(G4double maxStep) 339 | { 340 | if ((stepLimit)&&(maxStep>0.)) stepLimit->SetMaxAllowedStep(maxStep); 341 | } 342 | 343 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 344 | void NXUserDetectorConstruction::setOneFeLengthZ(G4double z) 345 | { 346 | // search the material by its name 347 | solidoneFe->SetZHalfLength(z/2); 348 | } 349 | 350 | 351 | -------------------------------------------------------------------------------- /obscurer/Makefile: -------------------------------------------------------------------------------- 1 | 2 | INC += -I /usr/include/Geant4 -I include/ 3 | LIBS += -l CLHEP 4 | LIBS += -l G4global -l G4tracking -l G4run -l G4materials -l G4geometry -l G4particles -l G4processes -l G4event -l G4RayTracer -l G4digits_hits 5 | LIBS += -l G4interfaces -l G4intercoms -l G4graphics_reps -l G4vis_management 6 | LIBS += -l G4OpenGL -l G4modeling -l G4Tree -l G4FR -l G4VRML -l G4visHepRep -l G4GMocren 7 | 8 | src := $(wildcard src/*.cc) 9 | 10 | interim := $(subst .cc,.o,${src}) 11 | CPPFLAGS += -O3 -Wall -Wextra -Wno-long-long -pedantic -ggdb -DG4VIS_USE_OPENGLQT -DG4VIS_USE 12 | 13 | all: prog 14 | 15 | src/%.o: src/%.cc include/%.hh 16 | g++ ${CPPFLAGS} ${INC} $< -c -o $@ 17 | 18 | prog: main.cc ${interim} 19 | g++ ${CPPFLAGS} ${INC} ${LIBS} $^ -o $@ 20 | 21 | clean: 22 | rm -f prog src/*.o 23 | 24 | 25 | .PHONY: all clean 26 | -------------------------------------------------------------------------------- /obscurer/cmds.geant4: -------------------------------------------------------------------------------- 1 | /process/em/fluo true 2 | /process/em/auger true 3 | /process/em/pixe true 4 | /gps/verbose 0 5 | /gps/particle gamma 6 | /gps/number 100000 7 | /gps/ang/type focused 8 | /gps/direction 1 0 0 m 9 | /gps/ang/focuspoint 1 0 0 m 10 | /gps/ene/type Pow 11 | /gps/ene/min 0.1 keV 12 | /gps/ene/max 10 keV 13 | /gps/ene/alpha 0 14 | /run/beamOn 100 15 | -------------------------------------------------------------------------------- /obscurer/include/NXPhysicsList.hh: -------------------------------------------------------------------------------- 1 | #ifndef NXPhysicsList_h 2 | #define NXPhysicsList_h 1 3 | 4 | #include "G4VUserPhysicsList.hh" 5 | #include "G4VPhysicsConstructor.hh" 6 | #include "globals.hh" 7 | 8 | class NXPhysicsList: public G4VUserPhysicsList 9 | { 10 | public: 11 | NXPhysicsList(); 12 | ~NXPhysicsList(); 13 | 14 | protected: 15 | // Construct particle and physics 16 | void ConstructParticle(); 17 | void ConstructProcess(); 18 | void SetCuts(); 19 | 20 | 21 | protected: 22 | // these methods Construct particles 23 | void ConstructBosons(); 24 | void ConstructLeptons(); 25 | void ConstructBaryons(); 26 | 27 | protected: 28 | // these methods Construct physics processes and register them 29 | void ConstructEM(); 30 | }; 31 | 32 | #endif 33 | 34 | 35 | -------------------------------------------------------------------------------- /obscurer/include/NXPrimaryGeneratorAction.hh: -------------------------------------------------------------------------------- 1 | #ifndef NXPrimaryGeneratorAction_h 2 | #define NXPrimaryGeneratorAction_h 1 3 | 4 | #include "G4VUserPrimaryGeneratorAction.hh" 5 | 6 | class NXUserDetectorConstruction; 7 | class G4GeneralParticleSource; 8 | class G4Event; 9 | 10 | class NXPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction 11 | { 12 | public: 13 | NXPrimaryGeneratorAction(NXUserDetectorConstruction*); 14 | ~NXPrimaryGeneratorAction(); 15 | 16 | public: 17 | void GeneratePrimaries(G4Event*); 18 | 19 | private: 20 | G4GeneralParticleSource* particleSource; 21 | NXUserDetectorConstruction* myDetector; 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /obscurer/include/NXRunAction.hh: -------------------------------------------------------------------------------- 1 | #ifndef NXRunAction_h 2 | #define NXRunAction_h 1 3 | 4 | #include "G4UserRunAction.hh" 5 | #include "globals.hh" 6 | 7 | class G4Run; 8 | 9 | class NXRunAction : public G4UserRunAction 10 | { 11 | public: 12 | NXRunAction(); 13 | ~NXRunAction(); 14 | 15 | public: 16 | void BeginOfRunAction(const G4Run*); 17 | void EndOfRunAction(const G4Run*); 18 | }; 19 | 20 | #endif 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /obscurer/include/NXSensitiveDetector.hh: -------------------------------------------------------------------------------- 1 | #ifndef NXSensitiveDetector_h 2 | #define NXSensitiveDetector_h 1 3 | 4 | #include "G4VSensitiveDetector.hh" 5 | 6 | class G4Step; 7 | class G4HCofThisEvent; 8 | 9 | #define NENERGY 400 10 | #define NTHETA 5 11 | 12 | class NXSensitiveDetector : public G4VSensitiveDetector 13 | { 14 | public: 15 | NXSensitiveDetector(G4String); 16 | ~NXSensitiveDetector(); 17 | 18 | void Initialize(G4HCofThisEvent*); 19 | G4bool ProcessHits(G4Step*, G4TouchableHistory*); 20 | void EndOfEvent(G4HCofThisEvent*); 21 | void writeCounters(); 22 | private: 23 | long int counters[NTHETA][NENERGY]; 24 | 25 | }; 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /obscurer/include/NXUserDetectorConstruction.hh: -------------------------------------------------------------------------------- 1 | #ifndef NXUserDetectorConstruction_h 2 | #define NXUserDetectorConstruction_h 1 3 | 4 | #include "globals.hh" 5 | #include "G4VUserDetectorConstruction.hh" 6 | 7 | class G4Box; 8 | class G4Sphere; 9 | class G4LogicalVolume; 10 | class G4VPhysicalVolume; 11 | class G4Material; 12 | class G4VPVParameterisation; 13 | class G4UserLimits; 14 | 15 | class NXUserDetectorConstruction : public G4VUserDetectorConstruction 16 | { 17 | public: 18 | 19 | NXUserDetectorConstruction(); 20 | ~NXUserDetectorConstruction(); 21 | 22 | public: 23 | 24 | G4VPhysicalVolume* Construct(); 25 | G4double GetWorldFullLength() {return worldLength;}; 26 | 27 | private: 28 | 29 | G4Box* solidWorld; // pointer to the solid envelope 30 | G4LogicalVolume* logicWorld; // pointer to the logical envelope 31 | G4VPhysicalVolume* physiWorld; // pointer to the physical envelope 32 | 33 | G4Sphere* solidTarget; // pointer to the solid Target 34 | G4LogicalVolume* logicTarget; // pointer to the logical Target 35 | G4VPhysicalVolume* physiTarget; // pointer to the physical Target 36 | 37 | G4Box* solidAbsorber; // pointer to the solid envelope 38 | G4LogicalVolume* logicAbsorber; // pointer to the logical envelope 39 | G4VPhysicalVolume* physiAbsorber; // pointer to the physical envelope 40 | 41 | G4UserLimits* stepLimit; // pointer to user step limits 42 | 43 | G4double worldLength; // Full length of the world volume 44 | G4double fTargetLength; 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /obscurer/main.cc: -------------------------------------------------------------------------------- 1 | #include "NXUserDetectorConstruction.hh" 2 | #include "NXPhysicsList.hh" 3 | #include "NXPrimaryGeneratorAction.hh" 4 | #include "NXRunAction.hh" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #ifdef G4VIS_USE 12 | #include 13 | #endif 14 | #include 15 | 16 | int main(int argc,char** argv) 17 | { 18 | G4Timer myTimer; 19 | myTimer.Start(); 20 | // User Verbose output class 21 | // 22 | //G4VSteppingVerbose* verbosity = new NXSteppingVerbose; 23 | //G4VSteppingVerbose::SetInstance(verbosity); 24 | 25 | // Run manager 26 | // 27 | G4cout<<"main: init G4RunManager"<SetUserInitialization(detector); 36 | // 37 | G4cout<<"main: physics loading"<SetUserInitialization(physics); 41 | 42 | // User Action classes 43 | // 44 | G4cout<<"main: generator init "<SetUserAction(gen_action); 48 | // 49 | // G4cout<<"main: run action init"<SetUserAction(run_action); 53 | // 54 | //G4UserEventAction* event_action = new NXEventAction; 55 | //runManager->SetUserAction(event_action); 56 | // 57 | //G4UserSteppingAction* stepping_action = new NXSteppingAction; 58 | //runManager->SetUserAction(stepping_action); 59 | 60 | // Initialize G4 kernel 61 | // 62 | G4cout<Initialize(); 65 | 66 | // Instantiation and initialization of the Visualization Manager 67 | #ifdef G4VIS_USE 68 | G4VisManager* visManager = new G4VisExecutive; 69 | visManager->Initialize(); 70 | #endif 71 | 72 | // Get the pointer to the User Interface manager 73 | // 74 | G4UImanager * UI = G4UImanager::GetUIpointer(); 75 | if (argc!=1) { 76 | G4String command = "/control/execute "; 77 | G4String fileName = argv[1]; 78 | G4cout<ApplyCommand(command+fileName); 81 | G4cout<<"main: executing done"<SessionStart(); 86 | delete session; 87 | } 88 | 89 | delete runManager; 90 | #ifdef G4VIS_USE 91 | delete visManager; 92 | #endif 93 | //delete verbosity; 94 | 95 | myTimer.Stop(); 96 | G4cout<<"Spend time:"<reset(); 113 | while( (*theParticleIterator)() ){ 114 | G4ParticleDefinition* particle = theParticleIterator->value(); 115 | G4String particleName = particle->GetParticleName(); 116 | 117 | if (particleName == "gamma") { 118 | 119 | ////ph->RegisterProcess(new G4RayleighScattering, particle); 120 | ph->RegisterProcess(new G4PhotoElectricEffect, particle); 121 | G4ComptonScattering* cs = new G4ComptonScattering; 122 | cs->SetEmModel(new G4KleinNishinaModel()); 123 | ph->RegisterProcess(cs, particle); 124 | ph->RegisterProcess(new G4GammaConversion, particle); 125 | 126 | } else if (particleName == "e-") { 127 | 128 | G4eIonisation* eIoni = new G4eIonisation(); 129 | eIoni->SetStepFunction(0.1, 100*um); 130 | ph->RegisterProcess(eIoni, particle); 131 | ph->RegisterProcess(new G4eBremsstrahlung(), particle); 132 | 133 | } 134 | } 135 | 136 | // Deexcitation 137 | // 138 | G4VAtomDeexcitation* de = new G4UAtomicDeexcitation(); 139 | de->SetFluo(true); 140 | de->SetAuger(true); 141 | de->SetPIXE(true); 142 | G4LossTableManager::Instance()->SetAtomDeexcitation(de); 143 | } 144 | 145 | 146 | void NXPhysicsList::SetCuts() 147 | { 148 | G4cout<<"setting default cuts "<SetNumberOfParticles(n_particle); 19 | 20 | // default particle 21 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); 22 | G4ParticleDefinition* particle = particleTable->FindParticle("gamma"); 23 | particleSource->SetParticleDefinition(particle); 24 | 25 | G4cout<<"NXPrimaryGeneratorAction: setting position "<SetParticlePosition(G4ThreeVector(0,0,0)); 27 | } 28 | 29 | NXPrimaryGeneratorAction::~NXPrimaryGeneratorAction() 30 | { 31 | delete particleSource; 32 | } 33 | 34 | void NXPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 35 | { 36 | //particleSource->SetParticleMomentumDirection(G4ThreeVector(0,0,1*m)); 37 | /*G4cout<<"NXPrimaryGeneratorAction: shooting " 38 | " from "<< particleSource->GetParticlePosition() << 39 | " to "<< particleSource->GetParticleMomentumDirection() << 40 | " with Energy "<< particleSource->GetParticleEnergy() / keV << 41 | " keV" <SetParticleMomentumDirection(G4ThreeVector(0,0,1)); 44 | // random energies 45 | //G4double energy = (10*G4UniformRand() + 0.1) * keV; 46 | //particleSource->SetParticleEnergy(energy); 47 | particleSource->GeneratePrimaryVertex(anEvent); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /obscurer/src/NXRunAction.cc: -------------------------------------------------------------------------------- 1 | #include "NXRunAction.hh" 2 | #include "G4Run.hh" 3 | 4 | NXRunAction::NXRunAction() 5 | {} 6 | 7 | NXRunAction::~NXRunAction() 8 | {} 9 | 10 | void NXRunAction::BeginOfRunAction(const G4Run* aRun) 11 | { 12 | G4cout << "NXRunAction::BeginOfRunAction: Run #" << aRun->GetRunID() << " start." << G4endl; 13 | } 14 | 15 | void NXRunAction::EndOfRunAction(const G4Run*) 16 | { 17 | G4cout<<"NXRunAction::EndOfRunAction: end of run"<GetPreStepPoint(); 42 | G4StepPoint* pointPost=aStep->GetPostStepPoint(); 43 | G4TouchableHandle touchCur=pointPre->GetTouchableHandle(); 44 | G4Track* trackCur=aStep->GetTrack(); 45 | G4VPhysicalVolume* volumeCur=touchCur->GetVolume(); 46 | G4String volumeCurName=volumeCur->GetName(); 47 | G4int copyNumofChamber=touchCur->GetCopyNumber(); 48 | G4ParticleDefinition* particleCur = trackCur->GetDefinition(); 49 | G4String particleCurName = particleCur->GetParticleName(); 50 | G4double kineticEnergyCur = trackCur->GetKineticEnergy(); 51 | //G4RunManager* runManager= G4RunManager::GetRunManager(); 52 | //NXRunAction* runActionCur=(NXRunAction *)runManager->GetUserRunAction();*/ 53 | 54 | /* 55 | G4cerr << "Detector hit! " << pointPre->GetPosition() << " --> " << pointPost->GetPosition() << 56 | " at theta angle " << pointPre->GetPosition().theta() * 180 / pi << "deg" << 57 | " at phi angle " << pointPre->GetPosition().phi() * 180 / pi << "deg" << 58 | " by " << particleCurName << 59 | " with E=" << (kineticEnergyCur / keV) << "keV inside " << volumeCurName << G4endl; 60 | */ 61 | 62 | if (kineticEnergyCur / keV < ELOW) { 63 | return true; 64 | } 65 | double e = (kineticEnergyCur / keV - ELOW) / (EHIGH - ELOW) * NENERGY; 66 | int ebin = (int) e; 67 | double theta = pointPre->GetPosition().theta() - pi / 2; 68 | if (theta > pi / 2) 69 | theta -= pi / 2; 70 | if (theta < 0) 71 | theta += pi / 2; 72 | 73 | int thetabin = (int)(theta / (pi / 2) * NTHETA); 74 | //G4cout << " storing in " << ebin << " | " << 75 | // pointPre->GetPosition().theta() << " -> " << thetabin << 76 | // G4endl; 77 | if (thetabin < NTHETA && thetabin >= 0 && ebin < NENERGY && ebin >= 0) { 78 | counters[thetabin][ebin] += 1; 79 | } else { 80 | G4cout << " WARNING: stored at strange index " << kineticEnergyCur / keV << "keV | theta=" << thetabin << G4endl; 81 | } 82 | 83 | return true; 84 | } 85 | 86 | void NXSensitiveDetector::EndOfEvent(G4HCofThisEvent*) 87 | { 88 | writeCounters(); 89 | G4cout << "Event end!" << G4endl; 90 | } 91 | -------------------------------------------------------------------------------- /obscurer/src/NXUserDetectorConstruction.cc: -------------------------------------------------------------------------------- 1 | #include "NXUserDetectorConstruction.hh" 2 | #include "NXSensitiveDetector.hh" 3 | 4 | #include "G4Material.hh" 5 | #include "G4Box.hh" 6 | #include "G4Sphere.hh" 7 | #include "G4LogicalVolume.hh" 8 | #include "G4PVPlacement.hh" 9 | #include "G4PVParameterised.hh" 10 | #include "G4SDManager.hh" 11 | #include "G4GeometryTolerance.hh" 12 | #include "G4GeometryManager.hh" 13 | 14 | #include "G4UserLimits.hh" 15 | 16 | #include "G4VisAttributes.hh" 17 | #include "G4Colour.hh" 18 | #include "G4ios.hh" 19 | #include "G4NistManager.hh" 20 | #include "G4SystemOfUnits.hh" 21 | #include "G4PhysicalConstants.hh" 22 | #include "G4Isotope.hh" 23 | #include "G4Element.hh" 24 | #include "G4Material.hh" 25 | #include "G4UnitsTable.hh" 26 | 27 | //#define scale (3.08e13*km / 1000000) 28 | #define scale (m) 29 | #define densityscalefactor (scale*scale*scale/(parsec*1.*parsec*parsec)) 30 | 31 | NXUserDetectorConstruction::NXUserDetectorConstruction() : 32 | solidWorld(0), logicWorld(0), physiWorld(0), 33 | solidTarget(0), logicTarget(0), physiTarget(0), 34 | stepLimit(0), 35 | worldLength(5.*scale), fTargetLength(0) 36 | { 37 | } 38 | 39 | NXUserDetectorConstruction::~NXUserDetectorConstruction() 40 | { 41 | delete stepLimit; 42 | } 43 | 44 | G4VPhysicalVolume* NXUserDetectorConstruction::Construct() 45 | { 46 | G4cout<<"NXUserDetectorConstruction::Construct: "<FindOrBuildMaterial("G4_Galactic"); 50 | 51 | 52 | //--------- Definitions of Solids, Logical Volumes, Physical Volumes --------- 53 | // World 54 | 55 | G4double worldboxside = worldLength / 2; 56 | 57 | G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength); 58 | G4cout<<"construct: world solid"<FindOrBuildMaterial("G4_Fe");; 79 | G4Element* elFe = new G4Element("Iron" ,"Fe", 26., 55.85*g/mole); 80 | G4Element* elH = new G4Element("Hydrogen","H" , 1., 1.01*g/mole); 81 | G4double density = 1.0e38*g/(densityscalefactor*parsec*parsec*parsec); 82 | density = 1e-5*g/m3 * (densityscalefactor*parsec*parsec*parsec); 83 | G4double pressure = 1.e-19*pascal; 84 | G4double temperature = 10*kelvin; 85 | G4Material* GalGas = new G4Material("GalacticGas", density, 2, kStateGas, temperature, pressure); 86 | GalGas->AddElement(elH, 99.9*perCent); 87 | GalGas->AddElement(elFe, 0.1*perCent); 88 | G4double absThickness=1*scale; 89 | G4Material* absMaterial = GalGas; 90 | 91 | G4cout<<"construct: target solid"<AddNewDetector( aTrackerSD ); 132 | logicTarget->SetSensitiveDetector( aTrackerSD ); 133 | 134 | G4cout<<"construct: setting user steps"<SetUserLimits(stepLimit); 138 | 139 | 140 | G4cout<<"construct: returning constructed world"<SetUserInitialization(detector); 41 | // 42 | G4cout<<"main: physics loading"<SetUserInitialization(physics); 46 | 47 | // User Action classes 48 | // 49 | G4cout<<"main: generator init "<SetUserAction(gen_action); 53 | // 54 | G4cout<<"main: run action init"<SetUserAction(run_action); 58 | // 59 | //G4UserEventAction* event_action = new NXEventAction; 60 | //runManager->SetUserAction(event_action); 61 | // 62 | //G4UserSteppingAction* stepping_action = new NXSteppingAction; 63 | //runManager->SetUserAction(stepping_action); 64 | 65 | // Initialize G4 kernel 66 | // 67 | G4cout<Initialize(); 70 | 71 | // Get the pointer to the User Interface manager 72 | // 73 | G4UImanager * UI = G4UImanager::GetUIpointer(); 74 | UI->ApplyCommand("/run/beamOn"); 75 | 76 | /*if (argc!=1) { 77 | G4String command = "/control/execute "; 78 | G4String fileName = argv[1]; 79 | G4cout<ApplyCommand(command+fileName); 82 | G4cout<<"main: executing done"<SessionStart(); 87 | delete session; 88 | }*/ 89 | 90 | delete runManager; 91 | //delete verbosity; 92 | 93 | lt = time(NULL); 94 | printf( "the end time is %s", ctime(<)); 95 | myTimer.Stop(); 96 | G4cout<<"Spend time:"<reset(); 93 | while( (*theParticleIterator)() ){ 94 | G4ParticleDefinition* particle = theParticleIterator->value(); 95 | G4ProcessManager* pmanager = particle->GetProcessManager(); 96 | G4String particleName = particle->GetParticleName(); 97 | 98 | //G4cout<<"for "<AddDiscreteProcess(new G4PhotoElectricEffect); 103 | //pmanager->AddDiscreteProcess(new G4ComptonScattering); 104 | //pmanager->AddDiscreteProcess(new G4GammaConversion); 105 | 106 | } else if (particleName == "e-") { 107 | //electron 108 | G4cout<<"adding electron processes "<AddProcess(new G4eMultipleScattering, -1, 1, 1); 110 | //pmanager->AddProcess(new G4eIonisation, -1, 2, 2); 111 | //pmanager->AddProcess(new G4eBremsstrahlung, -1, 3, 3); 112 | } 113 | } 114 | } 115 | 116 | void NXPhysicsList::SetCuts() 117 | { 118 | G4cout<<"setting default cuts "<FindParticle("e-"); 22 | G4ParticleDefinition* particle = particleTable->FindParticle("gamma"); 23 | //G4ParticleDefinition* particle = particleTable->FindParticle("neutron"); 24 | //G4ParticleDefinition* particle = particleTable->FindParticle("alpha"); 25 | //G4ParticleDefinition* particle = particleTable->FindParticle("proton"); 26 | 27 | particleGun->SetParticleDefinition(particle); 28 | 29 | G4cout<<"NXPrimaryGeneratorAction: setting position "<SetParticlePosition(G4ThreeVector(0,0,0)); 31 | } 32 | 33 | NXPrimaryGeneratorAction::~NXPrimaryGeneratorAction() 34 | { 35 | delete particleGun; 36 | } 37 | 38 | void NXPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 39 | { 40 | G4cout<<"NXPrimaryGeneratorAction: shooting "<SetParticleMomentumDirection(G4ThreeVector(0,0,1)); 42 | particleGun->SetParticleEnergy(2*keV); 43 | particleGun->GeneratePrimaryVertex(anEvent); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /simplest/src/NXRunAction.cc: -------------------------------------------------------------------------------- 1 | #include "NXRunAction.hh" 2 | #include "G4Run.hh" 3 | 4 | NXRunAction::NXRunAction() 5 | {} 6 | 7 | NXRunAction::~NXRunAction() 8 | {} 9 | 10 | void NXRunAction::BeginOfRunAction(const G4Run* aRun) 11 | { 12 | G4cout << "NXRunAction::BeginOfRunAction: Run #" << aRun->GetRunID() << " start." << G4endl; 13 | } 14 | 15 | void NXRunAction::EndOfRunAction(const G4Run*) 16 | { 17 | G4cout<<"NXRunAction::EndOfRunAction: end of run"<GetPreStepPoint(); 25 | G4StepPoint* pointPost=aStep->GetPostStepPoint(); 26 | G4TouchableHandle touchCur=pointPre->GetTouchableHandle(); 27 | G4VPhysicalVolume* volumeCur=touchCur->GetVolume(); 28 | G4String volumeCurName=volumeCur->GetName(); 29 | G4int copyNumofChamber=touchCur->GetCopyNumber(); 30 | G4Track* trackCur=aStep->GetTrack(); 31 | G4ParticleDefinition* particleCur = trackCur->GetDefinition(); 32 | G4String particleCurName = particleCur->GetParticleName(); 33 | G4double kineticEnergyCur = trackCur->GetKineticEnergy(); 34 | G4RunManager* runManager= G4RunManager::GetRunManager(); 35 | //NXRunAction* runActionCur=(NXRunAction *)runManager->GetUserRunAction(); 36 | 37 | G4cout << "Detector hit! " << pointPre->GetPosition() << " --> " << pointPost->GetPosition() << 38 | " by " << particleCurName << 39 | " with E=" << kineticEnergyCur / keV << "keV inside " << volumeCurName << G4endl; 40 | 41 | 42 | return true; 43 | } 44 | 45 | void NXSensitiveDetector::EndOfEvent(G4HCofThisEvent*) 46 | { 47 | G4cout << "Event end!" << G4endl; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /simplest/src/NXUserDetectorConstruction.cc: -------------------------------------------------------------------------------- 1 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 2 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 3 | 4 | #include "NXUserDetectorConstruction.hh" 5 | #include "NXSensitiveDetector.hh" 6 | 7 | #include "G4Material.hh" 8 | #include "G4Box.hh" 9 | #include "G4LogicalVolume.hh" 10 | #include "G4PVPlacement.hh" 11 | #include "G4PVParameterised.hh" 12 | #include "G4SDManager.hh" 13 | #include "G4GeometryTolerance.hh" 14 | #include "G4GeometryManager.hh" 15 | 16 | #include "G4UserLimits.hh" 17 | 18 | #include "G4VisAttributes.hh" 19 | #include "G4Colour.hh" 20 | 21 | #include "G4ios.hh" 22 | 23 | #include "G4NistManager.hh" 24 | 25 | NXUserDetectorConstruction::NXUserDetectorConstruction() : 26 | solidWorld(0), logicWorld(0), physiWorld(0), 27 | solidTarget(0), logicTarget(0), physiTarget(0), 28 | stepLimit(0), 29 | worldLength(100*m), fTargetLength(0) 30 | { 31 | } 32 | 33 | NXUserDetectorConstruction::~NXUserDetectorConstruction() 34 | { 35 | delete stepLimit; 36 | } 37 | 38 | G4VPhysicalVolume* NXUserDetectorConstruction::Construct() 39 | { 40 | G4cout<<"NXUserDetectorConstruction::Construct: "<FindOrBuildMaterial("G4_Galactic"); 44 | 45 | 46 | //--------- Definitions of Solids, Logical Volumes, Physical Volumes --------- 47 | // World 48 | 49 | G4double worldboxside = worldLength / 2; 50 | 51 | G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength); 52 | G4cout<<"construct: world solid"<FindOrBuildMaterial("G4_Fe");; 75 | fTargetLength=1*mm; 76 | G4double fHalfTargetLength=0.5*fTargetLength; 77 | 78 | G4cout<<"construct: target solid"<AddNewDetector( aTrackerSD ); 102 | logicTarget->SetSensitiveDetector( aTrackerSD ); 103 | 104 | G4cout<<"construct: setting user steps"<SetUserLimits(stepLimit); 108 | 109 | 110 | G4cout<<"construct: returning constructed world"<