diff --git a/CMakeLists.txt b/CMakeLists.txt index 52ab283b565c94129d3e2192dad3693a5818be04..695851896ca29dcb69e08441eb985396cd919165 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ add_subdirectory(DDExamples/ILDExReco) add_subdirectory(DDExamples/ILDExTest) if(DD4HEP_WITH_GEANT4) add_subdirectory(DDExamples/CLICSiDSimu) -# add_subdirectory(DDExamples/ILDExSimu) + add_subdirectory(DDExamples/ILDExSimu) endif() #---Configuration------------------------------------------------------------------- diff --git a/DDExamples/ILDExDet/compact/ILDEx.xml b/DDExamples/ILDExDet/compact/ILDEx.xml index 796ceb519e21728375987364551a21ea44c57111..0a8de4a2928cd35ae51cbef84e209794240f1fd3 100644 --- a/DDExamples/ILDExDet/compact/ILDEx.xml +++ b/DDExamples/ILDExDet/compact/ILDEx.xml @@ -2,13 +2,13 @@ xmlns:xs="http://www.w3.org/2001/XMLSchema" xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd"> - <info name="clic_sid_cdr" - title="CLIC Silicon Detector CDR" - author="Christian Grefe" - url="https://twiki.cern.ch/twiki/bin/view/CLIC/ClicSidCdr" + <info name="ild_toy" + title="ILD Detector Toy model" + author="F. Gaede" + url="http://ilcsoft.desy.de" status="development" version="$Id: compact.xml,v 1.3 2010/12/02 16:34:00 grefe Exp $"> - <comment>The compact format for the CLIC Silicon Detector used for the conceptual design report</comment> + <comment>The compact format for the ILD Detector - toy model </comment> </info> <includes> @@ -22,7 +22,7 @@ <constant name="world_x" value="world_side/2"/> <constant name="world_y" value="world_side/2"/> <constant name="world_z" value="world_side/2"/> - <constant name="CrossingAngle" value="0.020"/> + <constant name="CrossingAngle" value="0.014"/> <constant name="TPC_zhalf" value="2500*mm"/> <constant name="TPC_outer_radius" value="1800*mm"/> @@ -156,8 +156,8 @@ </readout> </readouts> <fields> - <field type="SolenoidMagnet" name="GlobalSolenoid" inner_field="5.0*tesla" + <field type="SolenoidMagnet" name="GlobalSolenoid" inner_field="3.5*tesla" outer_field="-1.5*tesla" zmax="SolenoidCoilOuterZ" outer_radius="SolenoidalFieldRadius" /> - </fields> + </fields> </lccdd> diff --git a/DDExamples/ILDExDet/src/compact/ILDExVXD_geo.cpp b/DDExamples/ILDExDet/src/compact/ILDExVXD_geo.cpp index d5d9fd8338d362581f7307abf89ac07b48f36519..3c7e4a2a6ac7ae1e4d6b29f1620867e37f504e94 100644 --- a/DDExamples/ILDExDet/src/compact/ILDExVXD_geo.cpp +++ b/DDExamples/ILDExDet/src/compact/ILDExVXD_geo.cpp @@ -58,10 +58,10 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens) { Box suppbox (supp_thick/2.,width/2.,zhalf); Volume suppvol (layername+"_supp",suppbox,suppmat); - Position senspos (0,0,0); - Position supppos (0,0,0); - // Position senspos (-(sens_thick+supp_thick)/2.+sens_thick/2.,0,0); - // Position supppos (-(sens_thick+supp_thick)/2.+sens_thick+supp_thick/2.,0,0); + //Position senspos (0,0,0); + //Position supppos (0,0,0); + Position senspos (-(sens_thick+supp_thick)/2.+sens_thick/2.,0,0); + Position supppos (-(sens_thick+supp_thick)/2.+sens_thick+supp_thick/2.,0,0); sensvol.setVisAttributes(lcdd.visAttributes(x_layer.visStr())); sensvol.setSensitiveDetector(sens); diff --git a/DDExamples/ILDExSimu/CMakeLists.txt b/DDExamples/ILDExSimu/CMakeLists.txt index 8c8e5659cad29108aca114d8c9710bce38e33f8f..4b89b65e893c176cd909f95fa23cbd8d31811acc 100644 --- a/DDExamples/ILDExSimu/CMakeLists.txt +++ b/DDExamples/ILDExSimu/CMakeLists.txt @@ -8,15 +8,19 @@ if(NOT Geant4_clhep_FOUND) set(Geant4_LIBRARIES ${Geant4_LIBRARIES} ${CLHEP_LIBRARIES}) endif() +find_package(LCIO REQUIRED) + + include_directories( ${CMAKE_SOURCE_DIR}/DDCore/include ${CMAKE_SOURCE_DIR}/DDG4/include ${CMAKE_CURRENT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIR} ${Geant4_INCLUDE_DIRS} - ${VGM_INCLUDE_DIR}) + ${VGM_INCLUDE_DIR} + ${LCIO_INCLUDE_DIRS}) file(GLOB sources src/*.cpp) add_executable(ILDExSimu ILDExSimu.cpp ${sources}) -target_link_libraries(ILDExSimu DD4hepCore DD4hepG4 ILDEx ${Geant4_LIBRARIES}) +target_link_libraries(ILDExSimu DD4hepCore DD4hepG4 ILDEx ${Geant4_LIBRARIES} ${LCIO_LIBRARIES}) diff --git a/DDExamples/ILDExSimu/ILDExSimu.cpp b/DDExamples/ILDExSimu/ILDExSimu.cpp index 0fbb335fe13d1c6526465adb57f19ab52757c82b..657b3984e0a43b5717c62eb62eafc52ec1c829ab 100644 --- a/DDExamples/ILDExSimu/ILDExSimu.cpp +++ b/DDExamples/ILDExSimu/ILDExSimu.cpp @@ -21,6 +21,11 @@ #include "DDG4/Geant4DetectorConstruction.h" #include "DD4hep/LCDD.h" +// -- lcio -- +#include "lcio.h" +#include "IO/LCWriter.h" + + using namespace DD4hep::Geometry; using namespace DD4hep::Simulation; @@ -29,6 +34,13 @@ using namespace DD4hep::Simulation; int main(int argc,char** argv) { + std::string lcioOutFile("ILDExSimu.slcio") ; + + // -- open LCIO file ---- + lcio::LCWriter* lcWrt = lcio::LCFactory::getInstance()->createLCWriter() ; + lcWrt->open( lcioOutFile , lcio::LCIO::WRITE_NEW ) ; + + // Choose the Random engine // CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); @@ -61,8 +73,10 @@ int main(int argc,char** argv) G4VUserPrimaryGeneratorAction* gen_action = new ILDExPrimaryGeneratorAction(lcdd); runManager->SetUserAction(gen_action); - // + + //--- ILDExRunAction* run_action = new ILDExRunAction; + run_action->lcioWriter = lcWrt ; runManager->SetUserAction(run_action); // ILDExEventAction* event_action = new ILDExEventAction(run_action); @@ -108,7 +122,10 @@ int main(int argc,char** argv) delete runManager; - + + lcWrt->close() ; + delete lcWrt ; + return 0; } diff --git a/DDExamples/ILDExSimu/include/ILDExEventAction.h b/DDExamples/ILDExSimu/include/ILDExEventAction.h index 3a4cd7eea0acf1047d6661c3acaad711fe8bdffb..212ef1c2b59bccd0a21e462a045e0013937a1512 100644 --- a/DDExamples/ILDExSimu/include/ILDExEventAction.h +++ b/DDExamples/ILDExSimu/include/ILDExEventAction.h @@ -11,6 +11,7 @@ class ILDExRunAction; class ILDExEventActionMessenger; + //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... class ILDExEventAction : public G4UserEventAction @@ -35,7 +36,7 @@ private: G4double AngleSupport, AngleSensitive; G4int printModulo; - + ILDExEventActionMessenger* eventMessenger; }; diff --git a/DDExamples/ILDExSimu/include/ILDExRunAction.h b/DDExamples/ILDExSimu/include/ILDExRunAction.h index 850f930829afdb0f784d36f92e5ea2b79529d188..64cce4ee57d193896594fb839190588845904a0c 100644 --- a/DDExamples/ILDExSimu/include/ILDExRunAction.h +++ b/DDExamples/ILDExSimu/include/ILDExRunAction.h @@ -8,6 +8,8 @@ #include "G4UserRunAction.hh" #include "globals.hh" +#include "IO/LCWriter.h" + //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... class G4Run; @@ -25,6 +27,9 @@ public: G4double LSupport, G4double LSensitive, G4double AngleSupport, G4double AngleSensitive); + const G4Run* g4run ; + IO::LCWriter* lcioWriter ; + private: G4double sumESupport, sum2ESupport; @@ -36,6 +41,7 @@ private: G4double sumAngleSupport, sum2AngleSupport; G4double sumAngleSensitive, sum2AngleSensitive; + }; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/DDExamples/ILDExSimu/run1.mac b/DDExamples/ILDExSimu/run1.mac index ce78258d7839ac619eb7ba3d36616f85e8964f9e..1e97733fdd329cd4a988804982e8789a2f1a4998 100644 --- a/DDExamples/ILDExSimu/run1.mac +++ b/DDExamples/ILDExSimu/run1.mac @@ -15,6 +15,7 @@ # muon 300 MeV to the direction (1.,0.,0.) # 3 events # +/gun/direction 1. 1. 1. /gun/particle mu+ -/gun/energy 300 MeV +/gun/energy 1000 MeV /run/beamOn 3 diff --git a/DDExamples/ILDExSimu/src/ILDExEventAction.cpp b/DDExamples/ILDExSimu/src/ILDExEventAction.cpp index b64a686bffd9163f0a732cdf2353c2222cd9f2be..80722b16b881ff720408306c309ccaee0c0a9206 100644 --- a/DDExamples/ILDExSimu/src/ILDExEventAction.cpp +++ b/DDExamples/ILDExSimu/src/ILDExEventAction.cpp @@ -6,6 +6,7 @@ #include "ILDExRunAction.h" #include "ILDExEventActionMessenger.h" +#include "G4Run.hh" #include "G4Event.hh" #include "G4TrajectoryContainer.hh" #include "G4VTrajectory.hh" @@ -15,6 +16,63 @@ #include "Randomize.hh" #include <iomanip> +#include "DDG4/Geant4Hits.h" + +//--- lcio +#include "lcio.h" +#include "IMPL/LCEventImpl.h" +#include "IMPL/LCCollectionVec.h" +#include "IMPL/SimTrackerHitImpl.h" +#include "IMPL/SimCalorimeterHitImpl.h" +#include "UTIL/Operators.h" + + +#define DEBUG 1 + + +//------ helper functions ------------------ + +lcio::SimTrackerHitImpl* createSimTrackerHit( DD4hep::Simulation::Geant4TrackerHit* gh ){ + + lcio::SimTrackerHitImpl* lh = new lcio::SimTrackerHitImpl ; + + lh->setCellID0( ( gh->cellID >> 0 ) & 0xFFFFFFFF ) ; + lh->setCellID1( ( gh->cellID >> sizeof( int ) ) & 0xFFFFFFFF ) ; + + const double pos[3] = { gh->position.x() , gh->position.y() , gh->position.z() } ; + lh->setPosition( pos ) ; + + lh->setEDep( gh->energyDeposit ) ; + + lh->setTime( gh->truth.time ) ; + + lh->setMomentum( gh->momentum.x(), gh->momentum.y() , gh->momentum.z() ) ; + + lh->setPathLength( gh->length ) ; + + return lh ; +} + +//-------------- +lcio::SimCalorimeterHitImpl* createSimCalorimeterHit( DD4hep::Simulation::Geant4CalorimeterHit* gh ){ + + lcio::SimCalorimeterHitImpl* lh = new lcio::SimCalorimeterHitImpl ; + + lh->setCellID0( ( gh->cellID >> 0 ) & 0xFFFFFFFF ) ; + lh->setCellID1( ( gh->cellID >> sizeof( int ) ) & 0xFFFFFFFF ) ; + + const float pos[3] = { gh->position.x() , gh->position.y() , gh->position.z() } ; + lh->setPosition( pos ) ; + + lh->setEnergy( gh->energyDeposit ) ; + + return lh ; +} + + +//------------------------------------------ + + //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ILDExEventAction::ILDExEventAction(ILDExRunAction* run) @@ -52,6 +110,8 @@ void ILDExEventAction::BeginOfEventAction(const G4Event* evt) void ILDExEventAction::EndOfEventAction(const G4Event* evt) { + + //accumulates statistic // runAct->fillPerEvent(EnergySupport, EnergySensitive, TrackLSupport, TrackLSensitive, AngleSupport, AngleSensitive); @@ -59,7 +119,12 @@ void ILDExEventAction::EndOfEventAction(const G4Event* evt) //print per event (modulo n) // G4int evtNb = evt->GetEventID(); + + if (evtNb%printModulo == 0) { + +#if DEBUG + G4cout << "---> End of event: " << evtNb << G4endl; G4cout @@ -74,8 +139,92 @@ void ILDExEventAction::EndOfEventAction(const G4Event* evt) << G4BestUnit(TrackLSensitive,"Length") << G4endl; +#endif } - + + G4HCofThisEvent* hce = evt->GetHCofThisEvent() ; + + int nCol = hce->GetNumberOfCollections() ; + + lcio::LCEventImpl* lcEvt = new lcio::LCEventImpl ; + + lcEvt->setEventNumber( evt->GetEventID() ) ; + // lcEvt->setRunNumber( evt->GetRunID() ) ; + +#if DEBUG + G4cout << " ILDExEventAction::EndOfEventAction: HCE has " << nCol << " collections : " << G4endl ; +#endif + + for(int i=0 ; i<nCol ; ++i ){ + + G4VHitsCollection* hCol = hce->GetHC( i) ; + +#if DEBUG + G4cout << " --- " << i << ": " << hCol->GetName() << " from SD: " << hCol->GetSDname() << " size: " << hCol->GetSize() ; +#endif + + + bool isTracker = ( hCol->GetSize() ? dynamic_cast<DD4hep::Simulation::Geant4TrackerHit* >( hCol->GetHit(0) ) : 0 ) ; + bool isCalorimeter = ( hCol->GetSize() ? dynamic_cast<DD4hep::Simulation::Geant4CalorimeterHit*>( hCol->GetHit(0) ) : 0 ) ; + + if( hCol->GetSize() > 0 ){ + +#if DEBUG + if ( isTracker ) G4cout << " - type Geant4TrackerHit " << G4endl; + else if( isCalorimeter ) G4cout << " - type Geant4CalorimeterHit " << G4endl ; + else G4cout << " - type UNKNOWN " << G4endl; +#endif + + + + if( isTracker ) { //----------------------------------------------------------------- + + lcio::LCCollectionVec* col = new lcio::LCCollectionVec( lcio::LCIO::SIMTRACKERHIT ) ; + + for(int j=0,N= hCol->GetSize() ; j<N ; ++j) { + + lcio::SimTrackerHit* h = createSimTrackerHit( dynamic_cast<DD4hep::Simulation::Geant4TrackerHit*>( hCol->GetHit(0) ) ) ; + + col->addElement( h ) ; + +#if DEBUG + using namespace UTIL ; + std::cout << *h << G4endl ; +#endif + } + + lcEvt->addCollection( col , hCol->GetName() ) ; + } //----------------------------------------------------------------- + + if( isCalorimeter ) { + + lcio::LCCollectionVec* col = new lcio::LCCollectionVec( lcio::LCIO::SIMCALORIMETERHIT ) ; + + for(int j=0,N= hCol->GetSize() ; j<N ; ++j) { + + lcio::SimCalorimeterHit* h = createSimCalorimeterHit( dynamic_cast<DD4hep::Simulation::Geant4CalorimeterHit*>( hCol->GetHit(0) ) ) ; + + col->addElement( h ) ; + +#if DEBUG + using namespace UTIL ; + std::cout << *h << G4endl ; +#endif + } + + lcEvt->addCollection( col , hCol->GetName() ) ; + } //----------------------------------------------------------------- + + } + } + + // --- write the event + lcEvt->setRunNumber( runAct->g4run->GetRunID() ) ; + + runAct->lcioWriter->writeEvent( lcEvt ) ; + + } + //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/DDExamples/ILDExSimu/src/ILDExRunAction.cpp b/DDExamples/ILDExSimu/src/ILDExRunAction.cpp index 24feeb76411d4a4e119407c68c6ebd6e3b5918d6..6a1474f2d180643b804ea46979472e15c45809e1 100644 --- a/DDExamples/ILDExSimu/src/ILDExRunAction.cpp +++ b/DDExamples/ILDExSimu/src/ILDExRunAction.cpp @@ -8,6 +8,10 @@ #include "G4RunManager.hh" #include "G4UnitsTable.hh" +#include "lcio.h" +#include "IMPL/LCRunHeaderImpl.h" + + //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ILDExRunAction::ILDExRunAction() @@ -24,6 +28,9 @@ void ILDExRunAction::BeginOfRunAction(const G4Run* aRun) { G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; + // keep the run around: + g4run = aRun ; + //inform the runManager to save random number seed G4RunManager::GetRunManager()->SetRandomNumberStore(true); @@ -35,6 +42,12 @@ void ILDExRunAction::BeginOfRunAction(const G4Run* aRun) sumLSupport = sum2LSupport = sumLSensitive = sum2LSensitive = 0.; sumAngleSupport = sum2AngleSupport = sumAngleSensitive = sum2AngleSensitive = 0.; + + // --- write an lcio::RunHeader --------- + lcio::LCRunHeaderImpl* rh = new lcio::LCRunHeaderImpl ; + rh->setRunNumber( aRun->GetRunID() ) ; + lcioWriter->writeRunHeader( rh ) ; + } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......