diff --git a/CMakeLists.txt b/CMakeLists.txt index 91fa4a91d3542d4be71a2b35440191f9163df2de..cc74e088527db68ce006fe3fd4884ea890756292 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,10 @@ add_subdirectory(DDExamples/CLICSiD) add_subdirectory(DDExamples/ILDExDisplay) add_subdirectory(DDExamples/ILDExReco) +add_subdirectory(VGM/packages) +add_subdirectory(DDExamples/ILDExSimu) + + #---Configuration------------------------------------------------------------------- configure_file(cmake/thisdd4hep.csh thisdd4hep.csh @ONLY) configure_file(cmake/thisdd4hep.sh thisdd4hep.sh @ONLY) diff --git a/DDCore/CMakeLists.txt b/DDCore/CMakeLists.txt index 52d2cb85d467b93cefd815f14bf617675ebfc2d7..a7aa22a8f62a40c5ca79f9c5910d5a349a43b9e6 100644 --- a/DDCore/CMakeLists.txt +++ b/DDCore/CMakeLists.txt @@ -10,7 +10,7 @@ file(GLOB sources src/*.cpp src/Evaluator/*.cpp) if(DD4HEP_USE_PYROOT) file(GLOB headers include/DD4hep/*.h) - list(REMOVE_ITEM headers ${CMAKE_CURRENT_SOURCE_DIR}/include/DetFactoryHelper.h) + list(REMOVE_ITEM headers ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/DetFactoryHelper.h) ROOT_GENERATE_DICTIONARY( G__DD4hep ${headers} LINKDEF include/ROOT/LinkDef.h) list(APPEND sources G__DD4hep.cxx) add_definitions(-DDD4HEP_USE_PYROOT) diff --git a/DDCore/python/lcdd.py b/DDCore/python/lcdd.py index c46f0323336c606b3f9076ea8a2ace6414c4d609..6ff8805a845e97de8e8c3570f2a8ffd6e025f5fa 100644 --- a/DDCore/python/lcdd.py +++ b/DDCore/python/lcdd.py @@ -49,6 +49,8 @@ xml._ElementInterface.getB = _getBool xml._ElementInterface.name = property(lambda self: self.get('name')) xml._ElementInterface.type = property(lambda self: self.get('type')) xml._ElementInterface.vis = property(lambda self: self.get('vis')) +xml._ElementInterface.ref = property(lambda self: self.get('ref')) +xml._ElementInterface.value = property(lambda self: self.getF('value')) xml._ElementInterface.material = property(lambda self: self.get('material')) xml._ElementInterface.module = property(lambda self: self.get('module')) xml._ElementInterface.id = property(lambda self: self.getI('id')) @@ -164,32 +166,52 @@ def process_materials(lcdd, elem): process_material(lcdd, m) #--------------------------------------------------------------------------------- +# <material formula="Ac" name="Actinium" state="solid" > +# <RL type="X0" unit="cm" value="0.601558" /> +# <NIL type="lambda" unit="cm" value="21.2048" /> +# <D type="density" unit="g/cm3" value="10.07" /> +# <composite n="1" ref="Ac" /> +#</material> +#<material name="G10"> +# <D type="density" value="1.7" unit="g/cm3"/> +# <fraction n="0.08" ref="Cl"/> +# <fraction n="0.773" ref="Quartz"/> +# <fraction n="0.147" ref="Epoxy"/> +#</material> + + def process_material(lcdd, m): - #print 'Adding material ...', m.get('name') - matname = m.get('name') + print 'Adding material ...', m.get('name') density = m.find('D') - composites = m.findall('fraction') + radlen = m.find('RL') + intlen = m.find('NIL') + composites = m.findall('fraction') or m.findall('composite') table = gGeoManager.GetElementTable() - mat = gGeoManager.GetMaterial(matname) + mat = gGeoManager.GetMaterial(m.name) if not mat: - mat = TGeoMixture(matname, len(composites), density.getF('value')) + mat = TGeoMixture(m.name, len(composites), eval(density.get('value')+'*'+density.get('unit')+'/(g/cm3)',constants)) SetOwnership( mat, False ) + rl = (radlen is not None) and eval(radlen.get('value')+'*'+radlen.get('unit'),constants) or 0.0 + il = (intlen is not None) and eval(intlen.get('value')+'*'+intlen.get('unit'),constants) or 0.0 + #mat.SetRadLen(-rl, -il) + mat.Print() elts = [mat.GetElement(i).GetName() for i in range(mat.GetNelements())] for c in composites: - nam = c.get('ref') + nam = c.ref if nam not in elts: - fraction = c.getF('n') + if c.tag == 'composite' : fraction = c.getI('n') + elif c.tag == 'fraction' : fraction = c.getF('n') if table.FindElement(nam): mat.AddElement(table.FindElement(nam), fraction) elif gGeoManager.GetMaterial(nam): mat.AddElement(gGeoManager.GetMaterial(nam), fraction) else: raise 'Something going very wrong. Undefined material:' + nam - medium = gGeoManager.GetMedium(matname) + medium = gGeoManager.GetMedium(m.name) if not medium: global unique_mat_id unique_mat_id = unique_mat_id - 1 - medium = TGeoMedium(matname, unique_mat_id, mat) + medium = TGeoMedium(m.name, unique_mat_id, mat) SetOwnership(medium, False) medium.SetTitle('material') medium.SetUniqueID(unique_mat_id) diff --git a/DDExamples/ILDExDet/compact/ILDEx.xml b/DDExamples/ILDExDet/compact/ILDEx.xml index 31b1b8d347b9f428bc91402a0d194f55ba3e6b62..5678f8e0488f90e97f56671bfe63e38f41396636 100644 --- a/DDExamples/ILDExDet/compact/ILDEx.xml +++ b/DDExamples/ILDExDet/compact/ILDEx.xml @@ -100,6 +100,10 @@ <detector name="TPC" type="ILDExTPC" vis="TPCVis" id="3"> <tubs rmin="TPC_inner_radius" rmax="TPC_outer_radius" zhalf="TPC_zhalf"/> + <!-- GEAR Data--> + <module number="36" driftlength="TPC_zhalf*0.9"/> + <!-- End of GEAR Data--> + <material name="Air"/> <detector name="TPC_InnerWall" type="TubeSegment" reflect="true" vis="TPCSupportVis" id="0"> diff --git a/DDExamples/ILDExDet/drivers/ILDExTPC.py b/DDExamples/ILDExDet/drivers/ILDExTPC.py index f0394ab9b57dfea86ed3fcd78127d0f9c128648e..af6ef9c151e59d84a903123b25ca7b4a1446e5bc 100644 --- a/DDExamples/ILDExDet/drivers/ILDExTPC.py +++ b/DDExamples/ILDExDet/drivers/ILDExTPC.py @@ -18,8 +18,7 @@ def detector_ILDExTPC(lcdd, det): part_vol = Volume(lcdd, px.name, part_tube, lcdd.material(px_mat.name)) print 'Vis for %s ' %det.name, px.vis part_vol.setVisAttributes(lcdd.visAttributes(px.vis)) - tpc_vol.placeVolume(part_vol, getPosition(px_pos), getRotation(px_rot)) - + part_det.addPlacement(tpc_vol.placeVolume(part_vol, getPosition(px_pos), getRotation(px_rot))) if px.id == 0 : tpc_de.setInnerWall(part_det) elif px.id == 1 : tpc_de.setOuterWall(part_det) elif px.id == 5 : tpc_de.setGasVolume(part_det) @@ -27,4 +26,9 @@ def detector_ILDExTPC(lcdd, det): print 'vis = ', det.vis tpc_vol.setVisAttributes(lcdd.visAttributes(det.vis)) lcdd.pickMotherVolume(tpc_de).placeVolume(tpc_vol) + #--additonal TPC data----------------------------- + mod = det.find('module') + tpc_de.setNModules(mod.getI('number')) + tpc_de.setDriftLength(mod.getF('driftlength')) + return tpc_de diff --git a/DDExamples/ILDExDet/include/ILDExTPC.h b/DDExamples/ILDExDet/include/ILDExTPC.h index 3e292a16492de4b7fd89754b14d59f08d1b02e2a..bfb79ca23ec21bd4e63d27ddc9bfd67ccdd5c763 100644 --- a/DDExamples/ILDExDet/include/ILDExTPC.h +++ b/DDExamples/ILDExDet/include/ILDExTPC.h @@ -18,6 +18,8 @@ namespace DD4hep { Ref_t innerWall; Ref_t gas; double pressure; + int nmodules; + double driftlength; }; struct ILDExTPC : public Geometry::DetElement { @@ -28,7 +30,11 @@ namespace DD4hep { void setInnerWall(Ref_t obj); void setOuterWall(Ref_t obj); void setGasVolume(Ref_t obj); + void setNModules(int); double getVolume() const; double getWeight() const; + int getNModules() const; + double getDriftLength() const; + void setDriftLength(double); }; } diff --git a/DDExamples/ILDExDet/src/ILDExTPC.cpp b/DDExamples/ILDExDet/src/ILDExTPC.cpp index 46909eb103e2e910a63ee37367073ca858558468..3cf506f3210a77e1087e2906a2de478b4884b012 100644 --- a/DDExamples/ILDExDet/src/ILDExTPC.cpp +++ b/DDExamples/ILDExDet/src/ILDExTPC.cpp @@ -33,5 +33,18 @@ namespace DD4hep { void ILDExTPC::setGasVolume(Ref_t obj) { data<Object>()->gas = obj; } + + void ILDExTPC::setNModules(int n) { + data<Object>()->nmodules = n; + } + int ILDExTPC::getNModules() const { + return data<Object>()->nmodules; + } + void ILDExTPC::setDriftLength(double d) { + data<Object>()->driftlength = d; + } + double ILDExTPC::getDriftLength() const { + return data<Object>()->driftlength; + } } diff --git a/DDExamples/ILDExReco/CMakeLists.txt b/DDExamples/ILDExReco/CMakeLists.txt index 39e403ab879fa43ddfe999bc5693774e3b9fc731..cf8f1b377f176bf7e0e924ce93f33ce0894c9c12 100644 --- a/DDExamples/ILDExReco/CMakeLists.txt +++ b/DDExamples/ILDExReco/CMakeLists.txt @@ -1,11 +1,10 @@ cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR) - include_directories( ${CMAKE_SOURCE_DIR}/DDCore/include ${CMAKE_SOURCE_DIR}/DDExamples/ILDExDet/include ${CMAKE_CURRENT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIR}) -add_executable(ILDExReco src/recons.cpp src/GearTPC.cpp) +add_executable(ILDExReco ILDExReco.cpp src/GearTPC.cpp) target_link_libraries(ILDExReco DD4hepCore ILDEx ${ROOT_LIBRARIES}) diff --git a/DDExamples/ILDExReco/src/recons.cpp b/DDExamples/ILDExReco/ILDExReco.cpp similarity index 81% rename from DDExamples/ILDExReco/src/recons.cpp rename to DDExamples/ILDExReco/ILDExReco.cpp index e3fcebfb073308e4296cd89e3d14ddb918cd0784..dd39604efafd3cc169d5cb8cb41929d2020b0b1f 100644 --- a/DDExamples/ILDExReco/src/recons.cpp +++ b/DDExamples/ILDExReco/ILDExReco.cpp @@ -26,6 +26,9 @@ int main(int argc,char** argv) { cout << "-----> Gear: Inner:" << tpc.innerRadius() << " Outer:" << tpc.outerRadius() << endl; cout << "-----> Gear: Press:" << tpc.pressure() << endl; + //cout << "-----> Gear: NModukes:" << tpc.getNModules() << endl; + //cout << "-----> Gear: DriftLength:" << tpc.getDriftLength() << endl; + return 0; } diff --git a/DDExamples/ILDExReco/include/GearTPC.h b/DDExamples/ILDExReco/include/GearTPC.h index 76e253bf8eef4091ad1e58985c5e57d82848fdb5..2b1d569b04c5f1ee2e1c616fa437c3869c05289d 100644 --- a/DDExamples/ILDExReco/include/GearTPC.h +++ b/DDExamples/ILDExReco/include/GearTPC.h @@ -12,12 +12,124 @@ namespace DD4hep { struct TPCData; + struct TPCModule {}; + struct GlobalPadIndex {}; + struct PadRowLayout2D {}; struct GearTPC : public Geometry::DetElement { typedef TPCData Object; GearTPC(const Geometry::Ref_t& e); + double innerRadius() const; double outerRadius() const; double pressure() const; + + const TPCModule & getModule(int ID) const; + + /** Returns number of modules in this TPC (endplate). + */ + int getNModules() const; + + /** Returns nearest module to given coordinates (2D). + * In case of a full TPC with two end caps the first matching module is returned, + * although a module from the other end plate might be closer in 3D. + * Use the 3D version of getNearestModule in this case + * to get the module from the correct half TPC. + */ + const TPCModule & getNearestModule(double c0, double c1) const; + + /** Returns nearest module to given coordinates (3D). + * The z coordinate is only used to determine whether the positive or negative + * half TPC is to be used. + */ + const TPCModule & getNearestModule(double c0, double c1, double z) const; + + /** The maximum drift length in the TPC in mm. + */ + double getMaxDriftLength() const; + + /** True if coordinate (c0,c1) is within any module. + * This may or may not be + * on a pad, since with resitive films being on the film is enough + * to generate signal on pads (see TPCModule::getBorderWidth() ). + * This is the 2D version. Use isInsideModule(double c0, double c1, double z) + * to limit to correct end plate in case there are two. + */ + bool isInsideModule(double c0, double c1) const; + + /** First determines the correct end plate from the z coordinate and then + * calls the same function as the 2D version on the modules from the correct + * end cap. + */ + bool isInsideModule(double c0, double c1, double z) const; + + /** True if coordinate (c0,c1) is within any pad, on any module. + * This is the 2D version. Use isInsideModule(double c0, double c1, double z) + * to limit to correct end plate in case there are two. + */ + bool isInsidePad(double c0, double c1) const; + + /** First determines the correct end plate from the z coordinate and then + * calls the same function as the 2D version on the modules from the correct + * end cap. + */ + bool isInsidePad(double c0, double c1, double z) const; + + /** Returns globalPadindex Object for nearest pad to given coordinates (2D). + * In case of a full TPC with two end caps the first matching module ID is returned, + * although a module from the other end plate might be closer in 3D. + * Use the 3D version of getNearestPad in this case + * to get the pad from a module from the correct half TPC. + */ + GlobalPadIndex getNearestPad(double c0, double c1) const; + + /** Returns globalPadindex Object for nearest pad to given coordinates (3D). + * The z coordinate is only used to determine whether the positive or negative + * half TPC is to be used. + */ + GlobalPadIndex getNearestPad(double c0, double c1, double z) const; + + /** Extent of the sensitive plane - [xmin,xmax,ymin,ymax] CARTESIAN or + * [rmin,rmax,phimin,phimax] POLAR. These are the outermost coordinates + * in the respective coordinate system. It does not mean that the complete + * plane is sensitive as there might be dead space between the modules. + */ + const std::vector<double> & getPlaneExtent() const; + + /** Returns coordinate type as an int (see PadRowLayout2D::CARTESIAN, + * PadRowLayout2D::POLAR) + */ + int getCoordinateType() const; + + /** Returns vector of all modules in this TPC (endplate). + */ + const std::vector<TPCModule *> & getModules() const; + + /** Kept for backward compatibility. + * In case there is only one module, which has no angle and no + * offset wrt. the gobal coordinate systen, it gives back the + * PadRowLayout2D of this module. + * Otherwise it throws a gear::Exception. + * + * \deprecated{Please use getModule(moduleID) instead. + * The TPCModule is an implementation of PadRowLayout2D} + */ + const PadRowLayout2D & getPadLayout() const; + + /** The electron drift velocity in the TPC in mm/s. + * Kept for backwards compatibility. + * + * \deprecated{This should come from conditions data.} + */ + double getDriftVelocity() const; + + /** Kept for backward compatibility. + * In case there is only one module it gives back the + * redaout frequency of this module. + * Otherwise it throws a gear::Exception. + * + * \deprecated{Use TPCModule::getReadoutFrequency() instead.} + */ + double getReadoutFrequency() const; }; } diff --git a/DDExamples/ILDExSimu/CMakeLists.txt b/DDExamples/ILDExSimu/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a0f2eab34b252e83ccee750e2f5080f25e8f31e5 --- /dev/null +++ b/DDExamples/ILDExSimu/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR) + +find_package(Geant4 REQUIRED) + +include_directories( ${CMAKE_SOURCE_DIR}/DDCore/include + ${CMAKE_SOURCE_DIR}/VGM/packages/RootGM/include + ${CMAKE_SOURCE_DIR}/VGM/packages/Geant4GM/include + ${CMAKE_SOURCE_DIR}/VGM/packages/BaseVGM/include + ${CMAKE_SOURCE_DIR}/VGM/packages/VGM/include + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${ROOT_INCLUDE_DIR} + ${Geant4_INCLUDE_DIR}) + +file(GLOB sources src/*.cpp) +add_executable(ILDExSimu ILDExSimu.cpp ${sources}) +target_link_libraries(ILDExSimu DD4hepCore ILDEx Geant4GM RootGM ${Geant4_LIBRARIES}) + diff --git a/DDExamples/ILDExSimu/ILDExSimu.cpp b/DDExamples/ILDExSimu/ILDExSimu.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1ddc9f8cd89477d9c7c41674fc14f0f106ed4912 --- /dev/null +++ b/DDExamples/ILDExSimu/ILDExSimu.cpp @@ -0,0 +1,107 @@ + +// This example is adapted from the Geant4 example N03 + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "G4RunManager.hh" +#include "G4UImanager.hh" +#include "G4UIsession.hh" +#include "Randomize.hh" + +//#include "ILDExDetectorConstruction.hh" +#include "ILDExPhysicsList.h" +#include "ILDExPrimaryGeneratorAction.h" +#include "ILDExRunAction.h" +#include "ILDExEventAction.h" +#include "ILDExSteppingAction.h" +#include "ILDExSteppingVerbose.h" +//#include "G4VisExecutive.h" +#include "G4DetectorConstruction.h" +#include "G4UIExecutive.hh" + + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +int main(int argc,char** argv) +{ + + // Choose the Random engine + // + CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); + + // User Verbose output class + // + G4VSteppingVerbose::SetInstance(new ILDExSteppingVerbose); + + // Construct the default run manager + // + G4RunManager * runManager = new G4RunManager; + + + // Get the detector constructed + // + DD4hep::G4DetectorConstruction* detector = new DD4hep::G4DetectorConstruction(argv[1]); + runManager->SetUserInitialization(detector); + + // + G4VUserPhysicsList* physics = new ILDExPhysicsList; + runManager->SetUserInitialization(physics); + + // Set user action classes + // + G4VUserPrimaryGeneratorAction* gen_action = + new ILDExPrimaryGeneratorAction(detector->GetLCDD()); + runManager->SetUserAction(gen_action); + // + ILDExRunAction* run_action = new ILDExRunAction; + runManager->SetUserAction(run_action); + // + ILDExEventAction* event_action = new ILDExEventAction(run_action); + runManager->SetUserAction(event_action); + // + G4UserSteppingAction* stepping_action = + new ILDExSteppingAction(event_action); + runManager->SetUserAction(stepping_action); + + // Initialize G4 kernel + // + runManager->Initialize(); + + // Initialize visualization + // + //G4VisManager* visManager = new G4VisExecutive; + //visManager->Initialize(); + + // Get the pointer to the User Interface manager + + G4UImanager* UImanager = G4UImanager::GetUIpointer(); + + if (argc!=1) { // batch mode + G4String command = "/control/execute "; + G4String fileName = argv[2]; + UImanager->ApplyCommand(command+fileName); + } + else { // interactive mode : define UI session + + //G4UIsession* ui = new G4UIQt(argc, argv); + + //ui->SessionStart(); + //delete ui; + + } + + // Job termination + // Free the store: user actions, physics_list and detector_description are + // owned and deleted by the run manager, so they should not + // be deleted in the main() program ! + + //delete visManager; + + + delete runManager; + + return 0; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/DDExamples/ILDExSimu/include/G4DetectorConstruction.h b/DDExamples/ILDExSimu/include/G4DetectorConstruction.h new file mode 100644 index 0000000000000000000000000000000000000000..4c61a99a51d67e715a3ca757a85ebdbc492f934a --- /dev/null +++ b/DDExamples/ILDExSimu/include/G4DetectorConstruction.h @@ -0,0 +1,27 @@ +#ifndef DD4hep_G4DetectorConstruction_h +#define DD4Hep_G4DetectorConstruction_h 1 + +#include "G4VUserDetectorConstruction.hh" + +class G4VPhysicalVolume; + +namespace DD4hep { + namespace Geometry { + class LCDD; + } + class G4DetectorConstruction : public G4VUserDetectorConstruction + { + public: + + G4DetectorConstruction(const std::string&); + ~G4DetectorConstruction(); + G4VPhysicalVolume* Construct(); + Geometry::LCDD& GetLCDD() { return m_lcdd;} + private: + Geometry::LCDD& m_lcdd; + std::string m_compactfile; + }; + +} +#endif + diff --git a/DDExamples/ILDExSimu/include/ILDExEventAction.h b/DDExamples/ILDExSimu/include/ILDExEventAction.h new file mode 100644 index 0000000000000000000000000000000000000000..3a4cd7eea0acf1047d6661c3acaad711fe8bdffb --- /dev/null +++ b/DDExamples/ILDExSimu/include/ILDExEventAction.h @@ -0,0 +1,46 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#ifndef ILDExEventAction_h +#define ILDExEventAction_h 1 + +#include "G4UserEventAction.hh" +#include "globals.hh" + +class ILDExRunAction; +class ILDExEventActionMessenger; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +class ILDExEventAction : public G4UserEventAction +{ +public: + ILDExEventAction(ILDExRunAction*); + virtual ~ILDExEventAction(); + + void BeginOfEventAction(const G4Event*); + void EndOfEventAction(const G4Event*); + + void SumSupport(G4double de, G4double dl, G4double da) {EnergySupport += de; TrackLSupport += dl; AngleSupport += da; }; + void SumSensitive(G4double de, G4double dl, G4double da) {EnergySensitive += de; TrackLSensitive += dl; AngleSensitive += da; }; + + void SetPrintModulo(G4int val) {printModulo = val;}; + +private: + ILDExRunAction* runAct; + + G4double EnergySupport, EnergySensitive; + G4double TrackLSupport, TrackLSensitive; + G4double AngleSupport, AngleSensitive; + + G4int printModulo; + + ILDExEventActionMessenger* eventMessenger; +}; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#endif + + diff --git a/DDExamples/ILDExSimu/include/ILDExEventActionMessenger.h b/DDExamples/ILDExSimu/include/ILDExEventActionMessenger.h new file mode 100644 index 0000000000000000000000000000000000000000..97191427ee980a2bb2f56599e053e277918e083a --- /dev/null +++ b/DDExamples/ILDExSimu/include/ILDExEventActionMessenger.h @@ -0,0 +1,33 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#ifndef ILDExEventActionMessenger_h +#define ILDExEventActionMessenger_h 1 + +#include "globals.hh" +#include "G4UImessenger.hh" + +class ILDExEventAction; +class G4UIdirectory; +class G4UIcmdWithAnInteger; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +class ILDExEventActionMessenger: public G4UImessenger +{ +public: + ILDExEventActionMessenger(ILDExEventAction*); + virtual ~ILDExEventActionMessenger(); + + void SetNewValue(G4UIcommand*, G4String); + +private: + ILDExEventAction* eventAction; + G4UIdirectory* eventDir; + G4UIcmdWithAnInteger* PrintCmd; +}; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#endif diff --git a/DDExamples/ILDExSimu/include/ILDExPhysicsList.h b/DDExamples/ILDExSimu/include/ILDExPhysicsList.h new file mode 100644 index 0000000000000000000000000000000000000000..0a658ba446d101a0ed28f53b62b37e2ac2bf2cd5 --- /dev/null +++ b/DDExamples/ILDExSimu/include/ILDExPhysicsList.h @@ -0,0 +1,37 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#ifndef ILDExPhysicsList_h +#define ILDExPhysicsList_h 1 + +#include "G4VUserPhysicsList.hh" +#include "globals.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +class ILDExPhysicsList: public G4VUserPhysicsList +{ +public: + ILDExPhysicsList(); + virtual ~ILDExPhysicsList(); + + // Construct particle and physics + void ConstructParticle(); + void ConstructProcess(); + + void SetCuts(); + +private: + + // these methods Construct physics processes and register them + void ConstructDecay(); + void ConstructEM(); +}; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#endif + + + diff --git a/DDExamples/ILDExSimu/include/ILDExPrimaryGeneratorAction.h b/DDExamples/ILDExSimu/include/ILDExPrimaryGeneratorAction.h new file mode 100644 index 0000000000000000000000000000000000000000..4d45243c659159485bfecc3564c61cbbcbf01b7f --- /dev/null +++ b/DDExamples/ILDExSimu/include/ILDExPrimaryGeneratorAction.h @@ -0,0 +1,39 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#ifndef ILDExPrimaryGeneratorAction_h +#define ILDExPrimaryGeneratorAction_h 1 + +#include "G4VUserPrimaryGeneratorAction.hh" +#include "DD4hep/LCDD.h" +#include "globals.hh" + +class G4ParticleGun; +class G4Event; +class ILDExDetectorConstruction; +class ILDExPrimaryGeneratorMessenger; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +class ILDExPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction +{ +public: + ILDExPrimaryGeneratorAction(const DD4hep::Geometry::LCDD&); + virtual ~ILDExPrimaryGeneratorAction(); + + void GeneratePrimaries(G4Event*); + void SetRndmFlag(G4String val) { rndmFlag = val;} + +private: + G4ParticleGun* particleGun; //pointer a to G4 class + const DD4hep::Geometry::LCDD& ILDExDetector; //pointer to the geometry + ILDExPrimaryGeneratorMessenger* gunMessenger; //messenger of this class + G4String rndmFlag; //flag for a rndm impact point +}; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#endif + + diff --git a/DDExamples/ILDExSimu/include/ILDExRunAction.h b/DDExamples/ILDExSimu/include/ILDExRunAction.h new file mode 100644 index 0000000000000000000000000000000000000000..850f930829afdb0f784d36f92e5ea2b79529d188 --- /dev/null +++ b/DDExamples/ILDExSimu/include/ILDExRunAction.h @@ -0,0 +1,44 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#ifndef ILDExRunAction_h +#define ILDExRunAction_h 1 + +#include "G4UserRunAction.hh" +#include "globals.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +class G4Run; + +class ILDExRunAction : public G4UserRunAction +{ +public: + ILDExRunAction(); + virtual ~ILDExRunAction(); + + void BeginOfRunAction(const G4Run*); + void EndOfRunAction(const G4Run*); + + void fillPerEvent(G4double ESupport, G4double ESensitive, + G4double LSupport, G4double LSensitive, + G4double AngleSupport, G4double AngleSensitive); + +private: + + G4double sumESupport, sum2ESupport; + G4double sumESensitive, sum2ESensitive; + + G4double sumLSupport, sum2LSupport; + G4double sumLSensitive, sum2LSensitive; + + G4double sumAngleSupport, sum2AngleSupport; + G4double sumAngleSensitive, sum2AngleSensitive; + +}; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#endif + diff --git a/DDExamples/ILDExSimu/include/ILDExSteppingAction.h b/DDExamples/ILDExSimu/include/ILDExSteppingAction.h new file mode 100644 index 0000000000000000000000000000000000000000..7a341e596cfd5bdcd4b5b22f6ff49d8b7c855d89 --- /dev/null +++ b/DDExamples/ILDExSimu/include/ILDExSteppingAction.h @@ -0,0 +1,30 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#ifndef ILDExSteppingAction_h +#define ILDExSteppingAction_h 1 + +#include "G4UserSteppingAction.hh" + +class ILDExDetectorConstruction; +class ILDExEventAction; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +class ILDExSteppingAction : public G4UserSteppingAction +{ +public: + ILDExSteppingAction(ILDExEventAction*); + virtual ~ILDExSteppingAction(); + + void UserSteppingAction(const G4Step*); + +private: + ILDExDetectorConstruction* detector; + ILDExEventAction* eventaction; +}; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#endif diff --git a/DDExamples/ILDExSimu/include/ILDExSteppingVerbose.h b/DDExamples/ILDExSimu/include/ILDExSteppingVerbose.h new file mode 100644 index 0000000000000000000000000000000000000000..cf7b1a4ee5602ac156c49a9b3fb260a53848fa67 --- /dev/null +++ b/DDExamples/ILDExSimu/include/ILDExSteppingVerbose.h @@ -0,0 +1,28 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +class ILDExSteppingVerbose; + +#ifndef ILDExSteppingVerbose_h +#define ILDExSteppingVerbose_h 1 + +#include "G4SteppingVerbose.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +class ILDExSteppingVerbose : public G4SteppingVerbose +{ + public: + + ILDExSteppingVerbose(); + ~ILDExSteppingVerbose(); + + void StepInfo(); + void TrackingStarted(); + +}; + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#endif diff --git a/DDExamples/ILDExSimu/run1.mac b/DDExamples/ILDExSimu/run1.mac new file mode 100644 index 0000000000000000000000000000000000000000..5d1ef3ec4b43a09ebb160dc5c795517a7440afb2 --- /dev/null +++ b/DDExamples/ILDExSimu/run1.mac @@ -0,0 +1,20 @@ +# $Id: run1.mac,v 1.2 2000-11-21 10:59:42 maire Exp $ +# +# Macro file for "exampleN03.cc" +# +# can be run in batch, without graphic +# or interactively: Idle> /control/execute run1.mac +# +/control/verbose 2 +/control/saveHistory +# +/run/verbose 2 +/event/verbose 0 +/tracking/verbose 1 +# +# muon 300 MeV to the direction (1.,0.,0.) +# 3 events +# +/gun/particle mu+ +/gun/energy 300 MeV +/run/beamOn 3 diff --git a/DDExamples/ILDExSimu/src/G4DetectorConstruction.cpp b/DDExamples/ILDExSimu/src/G4DetectorConstruction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b4095fd35f59c3f9074def8e40f4a44d3cf097c0 --- /dev/null +++ b/DDExamples/ILDExSimu/src/G4DetectorConstruction.cpp @@ -0,0 +1,34 @@ +#include "G4DetectorConstruction.h" +#include "DD4hep/LCDD.h" + +// VGM demo +#include "Geant4GM/volumes/Factory.h" +#include "RootGM/volumes/Factory.h" +#include "TGeoManager.h" + + +using namespace DD4hep; +using namespace DD4hep::Geometry; + +G4DetectorConstruction::G4DetectorConstruction(const std::string& xmlfile) : m_lcdd(LCDD::getInstance()), m_compactfile(xmlfile) { + // We need to construct the geometry at this level already + m_lcdd.fromCompact(m_compactfile); +} + +G4DetectorConstruction::~G4DetectorConstruction() {} + +G4VPhysicalVolume* G4DetectorConstruction::Construct() { + + // Import geometry from Root to VGM + RootGM::Factory rtFactory; + rtFactory.SetDebug(1); + rtFactory.Import(gGeoManager->GetTopNode()); + + // Export VGM geometry to Geant4 + // + Geant4GM::Factory g4Factory; + g4Factory.SetDebug(1); + rtFactory.Export(&g4Factory); + G4VPhysicalVolume* world = g4Factory.World(); + return world; +} diff --git a/DDExamples/ILDExSimu/src/ILDExEventAction.cpp b/DDExamples/ILDExSimu/src/ILDExEventAction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b64a686bffd9163f0a732cdf2353c2222cd9f2be --- /dev/null +++ b/DDExamples/ILDExSimu/src/ILDExEventAction.cpp @@ -0,0 +1,81 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "ILDExEventAction.h" +#include "ILDExRunAction.h" +#include "ILDExEventActionMessenger.h" + +#include "G4Event.hh" +#include "G4TrajectoryContainer.hh" +#include "G4VTrajectory.hh" +#include "G4VVisManager.hh" +#include "G4UnitsTable.hh" + +#include "Randomize.hh" +#include <iomanip> + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExEventAction::ILDExEventAction(ILDExRunAction* run) +:runAct(run),printModulo(1),eventMessenger(0) +{ + eventMessenger = new ILDExEventActionMessenger(this); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExEventAction::~ILDExEventAction() +{ + delete eventMessenger; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExEventAction::BeginOfEventAction(const G4Event* evt) +{ + G4int evtNb = evt->GetEventID(); + if (evtNb%printModulo == 0) { + G4cout << "\n---> Begin of event: " << evtNb << G4endl; + CLHEP::HepRandom::showEngineStatus(); +} + + // initialisation per event + EnergySupport = EnergySensitive = 0.; + TrackLSupport = TrackLSensitive = 0.; + AngleSupport = AngleSensitive = 0.; + + +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExEventAction::EndOfEventAction(const G4Event* evt) +{ + //accumulates statistic + // + runAct->fillPerEvent(EnergySupport, EnergySensitive, TrackLSupport, TrackLSensitive, AngleSupport, AngleSensitive); + + //print per event (modulo n) + // + G4int evtNb = evt->GetEventID(); + if (evtNb%printModulo == 0) { + G4cout << "---> End of event: " << evtNb << G4endl; + + G4cout + << " Support: total energy: " << std::setw(7) + << G4BestUnit(EnergySupport,"Energy") + << " total track length: " << std::setw(7) + << G4BestUnit(TrackLSupport,"Length") + << G4endl + << " Sensitive: total energy: " << std::setw(7) + << G4BestUnit(EnergySensitive,"Energy") + << " total track length: " << std::setw(7) + << G4BestUnit(TrackLSensitive,"Length") + << G4endl; + + } + +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/DDExamples/ILDExSimu/src/ILDExEventActionMessenger.cpp b/DDExamples/ILDExSimu/src/ILDExEventActionMessenger.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9089d329c10dbd7296fcd855629aa5a19c3f2280 --- /dev/null +++ b/DDExamples/ILDExSimu/src/ILDExEventActionMessenger.cpp @@ -0,0 +1,42 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "ILDExEventActionMessenger.h" +#include "ILDExEventAction.h" +#include "G4UIdirectory.hh" +#include "G4UIcmdWithAnInteger.hh" +#include "globals.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExEventActionMessenger::ILDExEventActionMessenger(ILDExEventAction* EvAct) +:eventAction(EvAct) +{ + eventDir = new G4UIdirectory("/ILDExDir/event/"); + eventDir->SetGuidance("event control"); + + PrintCmd = new G4UIcmdWithAnInteger("/ILDExDir/event/printModulo",this); + PrintCmd->SetGuidance("Print events modulo n"); + PrintCmd->SetParameterName("EventNb",false); + PrintCmd->SetRange("EventNb>0"); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExEventActionMessenger::~ILDExEventActionMessenger() +{ + delete PrintCmd; + delete eventDir; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExEventActionMessenger::SetNewValue( + G4UIcommand* command,G4String newValue) +{ + if(command == PrintCmd) + {eventAction->SetPrintModulo(PrintCmd->GetNewIntValue(newValue));} +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/DDExamples/ILDExSimu/src/ILDExPhysicsList.cpp b/DDExamples/ILDExSimu/src/ILDExPhysicsList.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ab829f406dd94fd39a4462cd0e1cc8d462fc55fe --- /dev/null +++ b/DDExamples/ILDExSimu/src/ILDExPhysicsList.cpp @@ -0,0 +1,194 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "ILDExPhysicsList.h" + +#include "G4ProcessManager.hh" +#include "G4BosonConstructor.hh" +#include "G4LeptonConstructor.hh" +#include "G4MesonConstructor.hh" +#include "G4BosonConstructor.hh" +#include "G4BaryonConstructor.hh" +#include "G4IonConstructor.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExPhysicsList::ILDExPhysicsList(): G4VUserPhysicsList() +{ + defaultCutValue = 1.0*mm; + SetVerboseLevel(1); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExPhysicsList::~ILDExPhysicsList() +{} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExPhysicsList::ConstructParticle() +{ + // In this method, static member functions should be called + // for all particles which you want to use. + // This ensures that objects of these particle types will be + // created in the program. + + G4BosonConstructor pBosonConstructor; + pBosonConstructor.ConstructParticle(); + + G4LeptonConstructor pLeptonConstructor; + pLeptonConstructor.ConstructParticle(); + +// G4MesonConstructor pMesonConstructor; +// pMesonConstructor.ConstructParticle(); +// +// G4BaryonConstructor pBaryonConstructor; +// pBaryonConstructor.ConstructParticle(); +// +// G4IonConstructor pIonConstructor; +// pIonConstructor.ConstructParticle(); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExPhysicsList::ConstructProcess() +{ + AddTransportation(); + ConstructEM(); + ConstructDecay(); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "G4ComptonScattering.hh" +#include "G4GammaConversion.hh" +#include "G4PhotoElectricEffect.hh" + +#include "G4eMultipleScattering.hh" +#include "G4eIonisation.hh" +#include "G4eBremsstrahlung.hh" +#include "G4eplusAnnihilation.hh" + +#include "G4MuMultipleScattering.hh" +#include "G4MuIonisation.hh" +#include "G4MuBremsstrahlung.hh" +#include "G4MuPairProduction.hh" + +#include "G4hMultipleScattering.hh" +#include "G4hIonisation.hh" +#include "G4hBremsstrahlung.hh" +#include "G4hPairProduction.hh" + +#include "G4ionIonisation.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExPhysicsList::ConstructEM() +{ + theParticleIterator->reset(); + while( (*theParticleIterator)() ){ + G4ParticleDefinition* particle = theParticleIterator->value(); + G4ProcessManager* pmanager = particle->GetProcessManager(); + G4String particleName = particle->GetParticleName(); + + if (particleName == "gamma") { + // gamma +// pmanager->AddDiscreteProcess(new G4PhotoElectricEffect); +// pmanager->AddDiscreteProcess(new G4ComptonScattering); +// pmanager->AddDiscreteProcess(new G4GammaConversion); + + } else if (particleName == "e-") { + //electron + pmanager->AddProcess(new G4eMultipleScattering,-1, 1, 1); +// pmanager->AddProcess(new G4eIonisation, -1, 2, 2); +// pmanager->AddProcess(new G4eBremsstrahlung, -1, 3, 3); + + } else if (particleName == "e+") { + //positron +// pmanager->AddProcess(new G4eMultipleScattering,-1, 1, 1) +// pmanager->AddProcess(new G4eIonisation, -1, 2, 2); +// pmanager->AddProcess(new G4eBremsstrahlung, -1, 3, 3); +// pmanager->AddProcess(new G4eplusAnnihilation, 0,-1, 4); + + } else if( particleName == "mu+" || + particleName == "mu-" ) { + //muon + pmanager->AddProcess(new G4MuMultipleScattering,-1, 1, 1); + //pmanager->AddProcess(new G4MuIonisation, -1, 2, 2); + // pmanager->AddProcess(new G4MuBremsstrahlung, -1, 3, 3); + // pmanager->AddProcess(new G4MuPairProduction, -1, 4, 4); + + } else if( particleName == "proton" || + particleName == "pi-" || + particleName == "pi+" ) { + //proton +// pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); +// pmanager->AddProcess(new G4hIonisation, -1, 2, 2); +// pmanager->AddProcess(new G4hBremsstrahlung, -1, 3, 3); +// pmanager->AddProcess(new G4hPairProduction, -1, 4, 4); + + } else if( particleName == "alpha" || + particleName == "He3" ) { + //alpha +// pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); +// pmanager->AddProcess(new G4ionIonisation, -1, 2, 2); + + } else if( particleName == "GenericIon" ) { + //Ions +// pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); +// pmanager->AddProcess(new G4ionIonisation, -1, 2, 2); + + } else if ((!particle->IsShortLived()) && + (particle->GetPDGCharge() != 0.0) && + (particle->GetParticleName() != "chargedgeantino")) { + //all others charged particles except geantino +// pmanager->AddProcess(new G4hMultipleScattering,-1, 1, 1); +// pmanager->AddProcess(new G4hIonisation, -1, 2, 2); + } + } +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "G4Decay.hh" + +void ILDExPhysicsList::ConstructDecay() +{ + // Add Decay Process + G4Decay* theDecayProcess = new G4Decay(); + theParticleIterator->reset(); + while( (*theParticleIterator)() ){ + G4ParticleDefinition* particle = theParticleIterator->value(); + G4ProcessManager* pmanager = particle->GetProcessManager(); + if (theDecayProcess->IsApplicable(*particle)) { + pmanager ->AddProcess(theDecayProcess); + // set ordering for PostStepDoIt and AtRestDoIt + pmanager ->SetProcessOrdering(theDecayProcess, idxPostStep); + pmanager ->SetProcessOrdering(theDecayProcess, idxAtRest); + } + } +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExPhysicsList::SetCuts() +{ + if (verboseLevel >0){ + G4cout << "ILDExPhysicsList::SetCuts:"; + G4cout << "CutLength : " << G4BestUnit(defaultCutValue,"Length") << G4endl; + } + + // set cut values for gamma at first and for e- second and next for e+, + // because some processes for e+/e- need cut values for gamma + // + SetCutValue(defaultCutValue, "gamma"); + SetCutValue(defaultCutValue, "e-"); + SetCutValue(defaultCutValue, "e+"); + // SetCutValue(defaultCutValue, "proton"); + + if (verboseLevel>0) DumpCutValuesTable(); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + diff --git a/DDExamples/ILDExSimu/src/ILDExPrimaryGeneratorAction.cpp b/DDExamples/ILDExSimu/src/ILDExPrimaryGeneratorAction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..890cbcd010f6890d66ed9dfa52e5860c7d34fb71 --- /dev/null +++ b/DDExamples/ILDExSimu/src/ILDExPrimaryGeneratorAction.cpp @@ -0,0 +1,62 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "ILDExPrimaryGeneratorAction.h" +#include "DD4hep/Volumes.h" +#include "TGeoBBox.h" +//#include "ILDExPrimaryGeneratorMessenger.h" + +#include "G4Event.hh" +#include "G4ParticleGun.hh" +#include "G4ParticleTable.hh" +#include "G4ParticleDefinition.hh" +#include "Randomize.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExPrimaryGeneratorAction::ILDExPrimaryGeneratorAction(const DD4hep::Geometry::LCDD& ILDExDC) +:ILDExDetector(ILDExDC),rndmFlag("off") +{ + G4int n_particle = 1; + particleGun = new G4ParticleGun(n_particle); + + // default particle kinematic + + G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); + G4String particleName; + G4ParticleDefinition* particle + = particleTable->FindParticle(particleName="e-"); + particleGun->SetParticleDefinition(particle); + particleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.)); + particleGun->SetParticleEnergy(50.*MeV); + DD4hep::Geometry::Box worldbox = ILDExDetector.worldVolume().solid(); + G4double position = -0.5*(worldbox->GetDX()); + particleGun->SetParticlePosition(G4ThreeVector(position,0.*cm,0.*cm)); + +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExPrimaryGeneratorAction::~ILDExPrimaryGeneratorAction() +{ + delete particleGun; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) +{ + //this function is called at the begining of event + // + G4double x0 = 0.*cm; + G4double y0 = 0.*cm; + G4double z0 = 0.*cm; + + particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)); + + particleGun->GeneratePrimaryVertex(anEvent); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + diff --git a/DDExamples/ILDExSimu/src/ILDExRunAction.cpp b/DDExamples/ILDExSimu/src/ILDExRunAction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..24feeb76411d4a4e119407c68c6ebd6e3b5918d6 --- /dev/null +++ b/DDExamples/ILDExSimu/src/ILDExRunAction.cpp @@ -0,0 +1,119 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "ILDExRunAction.h" + +#include "G4Run.hh" +#include "G4RunManager.hh" +#include "G4UnitsTable.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExRunAction::ILDExRunAction() +{} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExRunAction::~ILDExRunAction() +{} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExRunAction::BeginOfRunAction(const G4Run* aRun) +{ + G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; + + //inform the runManager to save random number seed + G4RunManager::GetRunManager()->SetRandomNumberStore(true); + + + //initialize cumulative quantities + // + + sumESupport = sum2ESupport = sumESensitive = sum2ESensitive = 0.; + sumLSupport = sum2LSupport = sumLSensitive = sum2LSensitive = 0.; + sumAngleSupport = sum2AngleSupport = sumAngleSensitive = sum2AngleSensitive = 0.; + +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExRunAction::fillPerEvent(G4double ESupport, G4double ESensitive, + G4double LSupport, G4double LSensitive, + G4double AngleSupport, G4double AngleSensitive) +{ + //accumulate statistic + // + sumESupport += ESupport; sum2ESupport += ESupport*ESupport; + sumESensitive += ESensitive; sum2ESensitive += ESensitive*ESensitive; + + sumLSupport += LSupport; sum2LSupport += LSupport*LSupport; + sumLSensitive += LSensitive; sum2LSensitive += LSensitive*LSensitive; + + sumAngleSupport += AngleSupport; sum2AngleSupport += AngleSupport*AngleSupport; + sumAngleSensitive += AngleSensitive; sum2AngleSensitive += AngleSensitive*AngleSensitive; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExRunAction::EndOfRunAction(const G4Run* aRun) +{ + G4int NbOfEvents = aRun->GetNumberOfEvent(); + if (NbOfEvents == 0) return; + + //compute statistics: mean and rms + // + sumESupport /= NbOfEvents; sum2ESupport /= NbOfEvents; + G4double rmsESupport = sum2ESupport - sumESupport*sumESupport; + if (rmsESupport >0.) rmsESupport = std::sqrt(rmsESupport); else rmsESupport = 0.; + + sumESensitive /= NbOfEvents; sum2ESensitive /= NbOfEvents; + G4double rmsESensitive = sum2ESensitive - sumESensitive*sumESensitive; + if (rmsESensitive >0.) rmsESensitive = std::sqrt(rmsESensitive); else rmsESensitive = 0.; + + sumLSupport /= NbOfEvents; sum2LSupport /= NbOfEvents; + G4double rmsLSupport = sum2LSupport - sumLSupport*sumLSupport; + if (rmsLSupport >0.) rmsLSupport = std::sqrt(rmsLSupport); else rmsLSupport = 0.; + + sumLSensitive /= NbOfEvents; sum2LSensitive /= NbOfEvents; + G4double rmsLSensitive = sum2LSensitive - sumLSensitive*sumLSensitive; + if (rmsLSensitive >0.) rmsLSensitive = std::sqrt(rmsLSensitive); else rmsLSensitive = 0.; + + sumAngleSupport /= NbOfEvents; sum2AngleSupport /= NbOfEvents; + G4double rmsAngleSupport = sum2AngleSupport - sumAngleSupport*sumAngleSupport; + if (rmsAngleSupport >0.) rmsAngleSupport = std::sqrt(rmsAngleSupport); else rmsAngleSupport = 0.; + + sumAngleSensitive /= NbOfEvents; sum2AngleSensitive /= NbOfEvents; + G4double rmsAngleSensitive = sum2AngleSensitive - sumAngleSensitive*sumAngleSensitive; + if (rmsAngleSensitive >0.) rmsAngleSensitive = std::sqrt(rmsAngleSensitive); else rmsAngleSensitive = 0.; + + + //print + // + G4cout + << "\n--------------------End of Run------------------------------\n" + << "\n mean Energy in Support : " << G4BestUnit(sumESupport,"Energy") + << " +- " << G4BestUnit(rmsESupport,"Energy") + << "\n mean Energy in Sensitive: " << G4BestUnit(sumESensitive,"Energy") + << " +- " << G4BestUnit(rmsESensitive,"Energy") + << G4endl; + + G4cout + << "\n mean trackLength in Support : " << G4BestUnit(sumLSupport,"Length") + << " +- " << G4BestUnit(rmsLSupport,"Length") + << "\n mean trackLength in Sensitive : " << G4BestUnit(sumLSensitive,"Length") + << " +- " << G4BestUnit(rmsLSensitive,"Length") + << G4endl; + + G4cout + << "\n mean Angle in Support : " << G4BestUnit(sumAngleSupport,"Angle") + << " +- " << G4BestUnit(rmsAngleSupport,"Angle") + << "\n mean Angle in Sensitive: " << G4BestUnit(sumAngleSensitive,"Angle") + << " +- " << G4BestUnit(rmsAngleSensitive,"Angle") + << "\n------------------------------------------------------------\n" + << G4endl; + +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/DDExamples/ILDExSimu/src/ILDExSteppingAction.cpp b/DDExamples/ILDExSimu/src/ILDExSteppingAction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b716e83538b2e1bd456cfd9e6636f39c7d26c1b6 --- /dev/null +++ b/DDExamples/ILDExSimu/src/ILDExSteppingAction.cpp @@ -0,0 +1,32 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "ILDExSteppingAction.h" +#include "ILDExEventAction.h" + +#include "G4Step.hh" + +////#include "G4RunManager.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExSteppingAction::ILDExSteppingAction(ILDExEventAction* evt) +:eventaction(evt) +{ } + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExSteppingAction::~ILDExSteppingAction() +{ } + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExSteppingAction::UserSteppingAction(const G4Step* aStep) +{ + + assert(aStep); + +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/DDExamples/ILDExSimu/src/ILDExSteppingVerbose.cpp b/DDExamples/ILDExSimu/src/ILDExSteppingVerbose.cpp new file mode 100644 index 0000000000000000000000000000000000000000..33fc810296d0636177d944fe6d4e4daf90000410 --- /dev/null +++ b/DDExamples/ILDExSimu/src/ILDExSteppingVerbose.cpp @@ -0,0 +1,154 @@ + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "ILDExSteppingVerbose.h" + +#include "G4SteppingManager.hh" +#include "G4UnitsTable.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExSteppingVerbose::ILDExSteppingVerbose() +{} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ILDExSteppingVerbose::~ILDExSteppingVerbose() +{} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExSteppingVerbose::StepInfo() +{ + CopyState(); + + G4int prec = G4cout.precision(3); + + if( verboseLevel >= 1 ){ + if( verboseLevel >= 4 ) VerboseTrack(); + if( verboseLevel >= 3 ){ + G4cout << G4endl; + G4cout << std::setw( 5) << "#Step#" << " " + << std::setw( 6) << "X" << " " + << std::setw( 6) << "Y" << " " + << std::setw( 6) << "Z" << " " + << std::setw( 9) << "KineE" << " " + << std::setw( 9) << "dEStep" << " " + << std::setw(10) << "StepLeng" + << std::setw(10) << "TrakLeng" + << std::setw(10) << "Volume" << " " + << std::setw(10) << "Process" << G4endl; + } + + G4cout << std::setw(5) << fTrack->GetCurrentStepNumber() << " " + << std::setw(6) << G4BestUnit(fTrack->GetPosition().x(),"Length") + << std::setw(6) << G4BestUnit(fTrack->GetPosition().y(),"Length") + << std::setw(6) << G4BestUnit(fTrack->GetPosition().z(),"Length") + << std::setw(6) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy") + << std::setw(6) << G4BestUnit(fStep->GetTotalEnergyDeposit(),"Energy") + << std::setw(6) << G4BestUnit(fStep->GetStepLength(),"Length") + << std::setw(6) << G4BestUnit(fTrack->GetTrackLength(),"Length") + << " "; + + // if( fStepStatus != fWorldBoundary){ + if( fTrack->GetNextVolume() != 0 ) { + G4cout << std::setw(10) << fTrack->GetVolume()->GetName(); + } else { + G4cout << std::setw(10) << "OutOfWorld"; + } + + if(fStep->GetPostStepPoint()->GetProcessDefinedStep() != 0){ + G4cout << " " + << std::setw(10) + << fStep->GetPostStepPoint()->GetProcessDefinedStep() + ->GetProcessName(); + } else { + G4cout << " UserLimit"; + } + + G4cout << G4endl; + + if( verboseLevel == 2 ){ + G4int tN2ndariesTot = fN2ndariesAtRestDoIt + + fN2ndariesAlongStepDoIt + + fN2ndariesPostStepDoIt; + if(tN2ndariesTot>0){ + G4cout << " :----- List of 2ndaries - " + << "#SpawnInStep=" << std::setw(3) << tN2ndariesTot + << "(Rest=" << std::setw(2) << fN2ndariesAtRestDoIt + << ",Along=" << std::setw(2) << fN2ndariesAlongStepDoIt + << ",Post=" << std::setw(2) << fN2ndariesPostStepDoIt + << "), " + << "#SpawnTotal=" << std::setw(3) << (*fSecondary).size() + << " ---------------" + << G4endl; + + for(size_t lp1=(*fSecondary).size()-tN2ndariesTot; + lp1<(*fSecondary).size(); lp1++){ + G4cout << " : " + << std::setw(6) + << G4BestUnit((*fSecondary)[lp1]->GetPosition().x(),"Length") + << std::setw(6) + << G4BestUnit((*fSecondary)[lp1]->GetPosition().y(),"Length") + << std::setw(6) + << G4BestUnit((*fSecondary)[lp1]->GetPosition().z(),"Length") + << std::setw(6) + << G4BestUnit((*fSecondary)[lp1]->GetKineticEnergy(),"Energy") + << std::setw(10) + << (*fSecondary)[lp1]->GetDefinition()->GetParticleName(); + G4cout << G4endl; + } + + G4cout << " :-----------------------------" + << "----------------------------------" + << "-- EndOf2ndaries Info ---------------" + << G4endl; + } + } + + } + G4cout.precision(prec); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ILDExSteppingVerbose::TrackingStarted() +{ + + CopyState(); +G4int prec = G4cout.precision(3); + if( verboseLevel > 0 ){ + + G4cout << std::setw( 5) << "Step#" << " " + << std::setw( 6) << "X" << " " + << std::setw( 6) << "Y" << " " + << std::setw( 6) << "Z" << " " + << std::setw( 9) << "KineE" << " " + << std::setw( 9) << "dEStep" << " " + << std::setw(10) << "StepLeng" + << std::setw(10) << "TrakLeng" + << std::setw(10) << "Volume" << " " + << std::setw(10) << "Process" << G4endl; + + G4cout << std::setw( 5) << fTrack->GetCurrentStepNumber() << " " + << std::setw( 6) << G4BestUnit(fTrack->GetPosition().x(),"Length") + << std::setw( 6) << G4BestUnit(fTrack->GetPosition().y(),"Length") + << std::setw( 6) << G4BestUnit(fTrack->GetPosition().z(),"Length") + << std::setw( 6) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy") + << std::setw( 6) << G4BestUnit(fStep->GetTotalEnergyDeposit(),"Energy") + << std::setw( 6) << G4BestUnit(fStep->GetStepLength(),"Length") + << std::setw( 6) << G4BestUnit(fTrack->GetTrackLength(),"Length") + << " "; + + if(fTrack->GetNextVolume()){ + G4cout << std::setw(10) << fTrack->GetVolume()->GetName(); + } else { + G4cout << "OutOfWorld"; + } + G4cout << " initStep" << G4endl; + } + G4cout.precision(prec); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/ILDEx/run1.mac b/ILDEx/run1.mac new file mode 100644 index 0000000000000000000000000000000000000000..5d1ef3ec4b43a09ebb160dc5c795517a7440afb2 --- /dev/null +++ b/ILDEx/run1.mac @@ -0,0 +1,20 @@ +# $Id: run1.mac,v 1.2 2000-11-21 10:59:42 maire Exp $ +# +# Macro file for "exampleN03.cc" +# +# can be run in batch, without graphic +# or interactively: Idle> /control/execute run1.mac +# +/control/verbose 2 +/control/saveHistory +# +/run/verbose 2 +/event/verbose 0 +/tracking/verbose 1 +# +# muon 300 MeV to the direction (1.,0.,0.) +# 3 events +# +/gun/particle mu+ +/gun/energy 300 MeV +/run/beamOn 3 diff --git a/ReadMe.txt b/ReadMe.txt index 1d22b3cd1c8755ab0e38630668f2ca348736636c..b9a30fbc90bf8f939182d83e6f354e88ee201c08 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -56,16 +56,21 @@ To build and run the simulation examples Geant4 will be required. svn co https://svnsrv.desy.de/basic/aidasoft/DD4hep/trunk DD4hep - Configure (for PyROOT) -mkdir build + +mkdir build; cd build cmake ../DD4hep +make -j4 - Configure (for XercesC) + cmake -DDD4HEP_USE_XERCESC=ON -DDD4HEP_USE_PYROOT=OFF -DXERCESC_ROOT_DIR=<xercesc> ../DD4hep - Run ILDEx display + DDExamples/ILDExDisplay/ILDExDisplay file:../DD4hep/DDExamples/ILDExDet/compact/ILDEx.xml - Run CLICSiD display + DDExamples/CLICSiD/CLICSiDtest file:../DD4hep/DDExamples/CLICSiD/compact/compact.xml