File indexing completed on 2025-01-30 09:17:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include <DDG4/Geant4Config.h>
0029 #include <DDG4/Geant4TestActions.h>
0030 #include <CLHEP/Units/SystemOfUnits.h>
0031 #include <TSystem.h>
0032 #include <iostream>
0033 #include <ctime>
0034
0035 using namespace std;
0036 using namespace dd4hep;
0037 using namespace dd4hep::sim;
0038 using namespace dd4hep::sim::Test;
0039 using namespace dd4hep::sim::Setup;
0040
0041 Geant4SensDetActionSequence* setupDetector(Geant4Kernel& kernel, const std::string& name) {
0042 SensitiveSeq sd = SensitiveSeq(kernel,"Geant4SensDetActionSequence/"+name);
0043 Sensitive sens = Sensitive(kernel,"Geant4TestSensitive/"+name+"Handler",name);
0044 sens["OutputLevel"] = 2;
0045 sd->adopt(sens);
0046 sens = Sensitive(kernel,"Geant4TestSensitive/"+name+"Monitor",name);
0047 sd->adopt(sens);
0048 return sd;
0049 }
0050
0051 int setupG4_CINT(bool interactive) {
0052 Geant4Kernel& kernel = Geant4Kernel::instance(Detector::getInstance());
0053 string det_dir = getenv("DD4hepINSTALL");
0054 string install_dir = getenv("DD4hepExamplesINSTALL");
0055 Phase p;
0056
0057 kernel.loadGeometry(("file:"+det_dir+"/DDDetectors/compact/SiD.xml").c_str());
0058 kernel.loadXML(("file:"+install_dir+"/examples/CLICSiD/sim/field.xml").c_str());
0059
0060 if ( interactive ) {
0061 kernel.property("UI") = "UI";
0062 setPrintLevel(DEBUG);
0063
0064 Action ui(kernel,"Geant4UIManager/UI");
0065 ui["HaveVIS"] = true;
0066 ui["HaveUI"] = true;
0067 ui["SessionType"] = "csh";
0068 kernel.registerGlobalAction(ui);
0069 }
0070 else {
0071 kernel.property("NumEvents") = 4;
0072 }
0073
0074 Action rndm(kernel, "Geant4Random/Random");
0075 rndm["Seed"] = ::time(0);
0076 kernel.registerGlobalAction(rndm);
0077
0078 GenAction gun(kernel,"Geant4ParticleGun/Gun");
0079 gun["energy"] = 10*CLHEP::GeV;
0080 gun["particle"] = "e-";
0081 gun["multiplicity"] = 1;
0082 gun["OutputLevel"] = 3;
0083 kernel.generatorAction().adopt(gun);
0084
0085 RunAction run_init(kernel,"Geant4TestRunAction/RunInit");
0086 run_init["Property_int"] = 12345;
0087 kernel.runAction().adopt(run_init);
0088 kernel.eventAction().callAtBegin(run_init.get(),&Geant4TestRunAction::beginEvent);
0089 kernel.eventAction().callAtEnd (run_init.get(),&Geant4TestRunAction::endEvent);
0090
0091 EventAction evt_1(kernel,"Geant4TestEventAction/UserEvent_1");
0092 evt_1["Property_int"] = 12345;
0093 evt_1["Property_string"] = "Events";
0094 evt_1["OutputLevel"] = 3;
0095 kernel.eventAction().adopt(evt_1);
0096
0097 p = kernel.addPhase<const G4Run*>("BeginRun");
0098 p->add(evt_1.get(),&Geant4TestEventAction::beginRun);
0099 kernel.runAction().callAtBegin(p.get(),&Geant4ActionPhase::call<const G4Run*>);
0100
0101 p = kernel.addPhase<const G4Run*>("EndRun");
0102 p->add(evt_1.get(),&Geant4TestEventAction::endRun);
0103 kernel.runAction().callAtEnd(p.get(),&Geant4ActionPhase::call<const G4Run*>);
0104 p = nullptr;
0105
0106 EventAction evt_2(kernel,"Geant4TestEventAction/UserEvent_2");
0107 kernel.eventAction().adopt(evt_2);
0108
0109 EventAction out(kernel,"Geant4Output2ROOT/RootOutput");
0110 out["Output"] = is_aclick() ? "CLICSiD.aclick.root" : "CLICSiD.exe.root";
0111 kernel.eventAction().adopt(out);
0112
0113 setupDetector(kernel,"SiVertexBarrel");
0114 setupDetector(kernel,"SiVertexEndcap");
0115 setupDetector(kernel,"SiTrackerBarrel");
0116 setupDetector(kernel,"SiTrackerEndcap");
0117 setupDetector(kernel,"SiTrackerForward");
0118 setupDetector(kernel,"EcalBarrel");
0119 setupDetector(kernel,"EcalEndcap");
0120 setupDetector(kernel,"HcalBarrel");
0121 setupDetector(kernel,"HcalEndcap");
0122 setupDetector(kernel,"HcalPlug");
0123 setupDetector(kernel,"MuonBarrel");
0124 setupDetector(kernel,"MuonEndcap");
0125 setupDetector(kernel,"LumiCal");
0126 setupDetector(kernel,"BeamCal");
0127
0128 kernel.configure();
0129 kernel.initialize();
0130 kernel.run();
0131 std::cout << "Successfully executed application .... " << std::endl;
0132 kernel.terminate();
0133 std::cout << "TEST_PASSED" << std::endl;
0134 return 0;
0135 }
0136
0137 int CLICSiDAClick() {
0138 return setupG4_CINT(false);
0139 }
0140
0141 #if not(defined(G__DICTIONARY) || defined(__CLING__) || defined(__CINT__) || defined(__MAKECINT__))
0142 int main(int, char**) {
0143 std::cout << "Running CLICSiDAClick as standalone executable...." << std::endl;
0144 return CLICSiDAClick();
0145 }
0146 #endif