From 76009cf39eef8eb3aacba4b0a045784885518cd8 Mon Sep 17 00:00:00 2001 From: lihan <hanliangliang_1_2@163.com> Date: Sun, 9 Jun 2019 05:50:11 +0200 Subject: [PATCH 1/9] finish test of SctSensorSD just using gtest --- .../InDetG4/SCT_G4_SD/CMakeLists.txt | 29 +++ .../InDetG4/SCT_G4_SD/share/optionForTest.txt | 7 + .../SCT_G4_SD/src/G4MyPhysicalVolume.h | 52 ++++ .../InDetG4/SCT_G4_SD/src/SctSensorSD.h | 9 +- .../SCT_G4_SD/test/SctSensorSD_gtest.cxx | 245 ++++++++++++++++++ 5 files changed, 341 insertions(+), 1 deletion(-) create mode 100644 InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt create mode 100644 InnerDetector/InDetG4/SCT_G4_SD/src/G4MyPhysicalVolume.h create mode 100644 InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx diff --git a/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt b/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt index 76cb06964681..664d7cc48704 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt +++ b/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt @@ -13,12 +13,30 @@ atlas_depends_on_subdirs( PRIVATE InnerDetector/InDetSimEvent Simulation/G4Atlas/G4AtlasTools Simulation/G4Sim/MCTruth + AtlasTest/TestTools + Control/AthenaBaseComps + DetectorDescription/AtlasDetDescr + Generators/GeneratorObjects + Simulation/Interfaces/HepMC_Interfaces + Simulation/ISF/ISF_Core/ISF_Event + Simulation/ISF/ISF_Core/ISF_Interfaces + Tools/PmbCxxUtils + Simulation/ISF/ISF_Core/ISF_Algorithms + LArCalorimeter/LArSimEvent + TileCalorimeter/TileSimEvent + MuonSpectrometer/MuonSimEvent ) # External dependencies: find_package( CLHEP ) find_package( Geant4 ) find_package( XercesC ) +find_package( GTest ) + +find_package( Eigen ) +find_package( Boost COMPONENTS filesystem thread system ) +find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread ) + # Component(s) in the package: atlas_add_component( SCT_G4_SD @@ -27,10 +45,21 @@ atlas_add_component( SCT_G4_SD INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} LINK_LIBRARIES ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} CxxUtils StoreGateLib SGtests GaudiKernel InDetSimEvent G4AtlasToolsLib MCTruth ) +atlas_add_library( SCT_G4_SDLib + src/*.cxx + PUBLIC_HEADERS SCT_G4_SD + INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS} + LINK_LIBRARIES ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} ${GMOCK_LIBRARIES} CxxUtils StoreGateLib SGtests GaudiKernel InDetSimEvent G4AtlasToolsLib MCTruth ) + atlas_add_test( SCT_G4_SDToolConfig_test SCRIPT test/SCT_G4_SDToolConfig_test.py PROPERTIES TIMEOUT 300 ) +atlas_add_test( SctSensorSD_gtest + SOURCES test/SctSensorSD_gtest.cxx + INCLUDE_DIRS ${GTEST_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS} + LINK_LIBRARIES TestTools ${GTEST_LIBRARIES} ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} SCT_G4_SDLib CxxUtils StoreGateLib SGtests GaudiKernel InDetSimEvent G4AtlasToolsLib MCTruth pthread ENVIRONMENT "JOBOPTSEARCHPATH=${CMAKE_CURRENT_SOURCE_DIR}/share" AtlasDetDescr GeneratorObjects ISF_Event ISF_Interfaces PmbCxxUtils InDetSimEvent LArSimEvent TileSimEvent MuonSimEvent AthenaBaseComps +) # Install files from the package: atlas_install_python_modules( python/*.py ) diff --git a/InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt b/InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt new file mode 100644 index 000000000000..a93c03599d88 --- /dev/null +++ b/InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt @@ -0,0 +1,7 @@ +ApplicationMgr.ExtSvc += { "StoreGateSvc/DetectorStore", "StoreGateSvc/HistoryStore" }; + +//FIXME uncomment to verify that your CLIDs are good! + +//ClassIDSvc.CLIDDBFiles += { "clid.db" }; +AuditorSvc.Auditors += { "AlgContextAuditor"}; + diff --git a/InnerDetector/InDetG4/SCT_G4_SD/src/G4MyPhysicalVolume.h b/InnerDetector/InDetG4/SCT_G4_SD/src/G4MyPhysicalVolume.h new file mode 100644 index 000000000000..a5e80e92ea73 --- /dev/null +++ b/InnerDetector/InDetG4/SCT_G4_SD/src/G4MyPhysicalVolume.h @@ -0,0 +1,52 @@ +#ifndef G4MyPhysicalVolume_h +#define G4MyPhysicalVolume_h + +#include "G4VPhysicalVolume.hh" +#include "G4RotationMatrix.hh" +#include "G4ThreeVector.hh" +#include "G4LogicalVolume.hh" +#include "G4String.hh" +#include "G4VPVParameterisation.hh" + +class G4MyPhysicalVolume : public G4VPhysicalVolume { + +public: + + G4MyPhysicalVolume( G4RotationMatrix *pRot, const G4ThreeVector &tlate, const G4String& pName, G4LogicalVolume* pLogical, G4VPhysicalVolume* pPhysical ) : G4VPhysicalVolume(pRot, tlate, pName, pLogical, pPhysical) + { + + } + + ~G4MyPhysicalVolume() {} + + G4int GetCopyNo() const + { + return copyNo; + } + + void SetCopyNo(G4int CopyNo) + { + copyNo = CopyNo; + } + + G4bool IsMany() const {return true;} + G4bool IsReplicated() const {return true;} + G4bool IsParameterised() const {return true;} + G4VPVParameterisation* GetParameterisation() const {return NULL;} + void GetReplicationData(EAxis& axis, G4int& nReplicas, G4double& width, G4double& offset, G4bool& consuming) const +{ + axis = (EAxis)1; + nReplicas = 0; + width = 0.0; + offset = 0.0; + consuming = true; +} + G4bool IsRegularStructure() const {return true;} + G4int GetRegularStructureId() const {return 0;} + + G4int copyNo; + +}; +#endif + + diff --git a/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensorSD.h b/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensorSD.h index 417901b891f4..2cb71c77e78a 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensorSD.h +++ b/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensorSD.h @@ -39,10 +39,17 @@ public: could get rather tricky, but the idea is to allow fast simulations to use the very same SD classes as the standard simulation. */ template <class... Args> void AddHit(Args&&... args){ m_HitColl->Emplace( args... ); } - +#ifdef TESTSctSensorSD +public: +#else private: +#endif void indexMethod(const G4TouchableHistory *myTouch, double coord1z, int &brlEcap, int &layerDisk, int &etaMod, int &phiMod, int &side); +#ifdef TESTSctSensorSD +public: +#else protected: +#endif // The hits collection SG::WriteHandle<SiHitCollection> m_HitColl; }; diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx new file mode 100644 index 000000000000..780138bf53ae --- /dev/null +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx @@ -0,0 +1,245 @@ +#define TESTSctSensorSD + +#include "src/SctSensorSD.h" + +#include "gtest/gtest.h" + +#include "TestTools/initGaudi.h" +#include "src/CollectionMerger.h" +#include "src/CollectionMerger.cxx" + +#include "G4HCofThisEvent.hh" +#include "G4Step.hh" +#include "G4TouchableHistory.hh" + +#include "G4Track.hh" +#include "G4StepPoint.hh" +#include "G4DynamicParticle.hh" +#include "G4ThreeVector.hh" +#include "G4Box.hh" +#include "G4NistManager.hh" +#include "G4Material.hh" +#include "G4VPhysicalVolume.hh" + +#include "src/G4MyPhysicalVolume.h" +#include "MCTruth/TrackHelper.h" + +//set environment +ISvcLocator* g_svcLoc = nullptr; +class GaudiEnvironment : public ::testing::Environment { + protected: + virtual void SetUp() override { + Athena_test::initGaudi("/afs/cern.ch/user/l/lihan/private/repo/athena/InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt", g_svcLoc); + } +}; +class SctSensorSDtest : public ::testing::Test { + protected: + virtual void SetUp() override { + m_alg = new ISF::CollectionMerger{"CollectionMerger", g_svcLoc}; + ASSERT_TRUE( m_alg->setProperties().isSuccess() ); + } + + virtual void TearDown() override { + ASSERT_TRUE( m_alg->finalize().isSuccess() ); + delete m_alg; + } + ISF::CollectionMerger* m_alg; +}; +//end of environment setting + +TEST_F( SctSensorSDtest, Initialize ) { + G4HCofThisEvent hce; + SctSensorSD sd1("name1", "name1" ); + sd1.Initialize( &hce ); + ASSERT_TRUE(sd1.m_HitColl.isValid()); //check if initialization of m_HitColl is successful +} + +TEST_F( SctSensorSDtest, ProcessHits ) +{ + G4Step sp; + G4TouchableHistory th; + G4HCofThisEvent hce; + +//setting to make aStep->GetTotalEnergyDeposit() in class to be tested work + G4double TotalEnergyDeposit = 3.0; + sp.SetTotalEnergyDeposit( TotalEnergyDeposit ); +//end + +//setting for using aStep->GetPreStepPoint() + G4StepPoint* stepPoint = new G4StepPoint(); + G4ThreeVector preStepPos(0, 0, 1); + stepPoint->SetPosition(preStepPos); + G4NavigationHistory* navigationHistory = new G4NavigationHistory(); + G4String boxName = "name"; + G4Box* box = new G4Box(boxName, 1.0, 1.0, 1.0); + G4NistManager* man = G4NistManager::Instance(); + G4Material* material = man->FindOrBuildMaterial("G4_AIR"); + G4String name = "logicalName"; + G4LogicalVolume fLogical(box, material, name); + G4String name1 = "physicalName"; + G4VPhysicalVolume* pPhysical = NULL; + G4MyPhysicalVolume physicalVolume(0, G4ThreeVector(0,0,0), name1, &fLogical, pPhysical); + physicalVolume.SetCopyNo(1000); + G4int nReplica = 2; + navigationHistory->SetFirstEntry(&physicalVolume); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + G4TouchableHistory* touchableHistory = new G4TouchableHistory(*navigationHistory); +// G4TouchableHistory touchableHistory(*navigationHistory); + G4TouchableHandle touchableHandle(touchableHistory); + stepPoint->SetTouchableHandle(touchableHandle); + stepPoint->SetGlobalTime(0.5); + + sp.SetPreStepPoint(stepPoint); +//end + +//decorate aStep with another G4StepPoint object + G4StepPoint* stepPoint1 = new G4StepPoint(); + G4ThreeVector postStepPos(0, 0, 2); + stepPoint1->SetPosition(postStepPos); + + sp.SetPostStepPoint(stepPoint1); +//end + +//decorate aStep with G4Track + G4DynamicParticle* dynamicPar = new G4DynamicParticle(); + G4double aValueTime = 1; + G4ThreeVector ValuePosition(1.0, 1.0, 1.0); + G4Track track(dynamicPar, aValueTime, ValuePosition); + G4double globalTime = 5.0; + track.SetGlobalTime(globalTime); + + sp.SetTrack(&track); +//end + + SctSensorSD sd2("name2", "name2"); + sd2.Initialize( &hce ); + sd2.ProcessHits(&sp, &th ); + + HepGeom::Point3D<double> P1,P2; + P1[SiHit::xEta] = 1; + P1[SiHit::xPhi] = 0; + P1[SiHit::xDep] = 0; + P2[SiHit::xEta] = 2; + P2[SiHit::xPhi] = 0; + P2[SiHit::xDep] = 0; + + int barcode = 0; + HepMcParticleLink plink(barcode); + + SiHitCollection* a = sd2.m_HitColl.ptr(); + ASSERT_EQ(a->begin()->localStartPosition(), P1); + ASSERT_EQ(a->begin()->localEndPosition(), P2); + ASSERT_EQ(a->begin()->energyLoss(), 3.0); + ASSERT_EQ(a->begin()->meanTime(), 0.5); + ASSERT_EQ(a->begin()->particleLink(), plink); + ASSERT_EQ(a->begin()->identify(),4101273733); + + ASSERT_EQ(a->size(), 1); +} + +TEST_F( SctSensorSDtest, indexMethod ) +{ +// decorate G4TouchableHistory object that will be used as the actual para of indexMethod + G4NavigationHistory* navigationHistory = new G4NavigationHistory(); + G4String boxName = "name"; + G4Box* box = new G4Box(boxName, 1.0, 1.0, 1.0); + G4NistManager* man = G4NistManager::Instance(); + G4Material* material = man->FindOrBuildMaterial("G4_AIR"); + G4String name = "logicalName"; + G4LogicalVolume fLogical(box, material, name); + G4String name1 = "physicalName"; + G4VPhysicalVolume* pPhysical = NULL; + G4MyPhysicalVolume physicalVolume(0, G4ThreeVector(0,0,0), name1, &fLogical, pPhysical); + physicalVolume.SetCopyNo(1000); + G4int nReplica = 2; + navigationHistory->SetFirstEntry(&physicalVolume); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + G4TouchableHistory th(*navigationHistory); +// end + + G4HCofThisEvent hce; + + double coord1z = 1; + int brlEcap = 0; + int layerDisk = 0; + int etaMod = 0; + int phiMod = 0; + int side = 0; + + SctSensorSD sd3("name3", "name3"); + sd3.Initialize( &hce ); + sd3.indexMethod(&th, coord1z, brlEcap, layerDisk, etaMod, phiMod, side ); + + ASSERT_EQ(brlEcap, 0); + ASSERT_EQ(layerDisk, 1000); + ASSERT_EQ(etaMod, 1000); + ASSERT_EQ(phiMod, 1000); + ASSERT_EQ(side, 1000); + +} + +TEST_F( SctSensorSDtest, AddHit ) +{ + HepGeom::Point3D<double> lP1,lP2; + lP1[SiHit::xEta] = 1; + lP1[SiHit::xPhi] = 0; + lP1[SiHit::xDep] = 0; + lP2[SiHit::xEta] = 2; + lP2[SiHit::xPhi] = 0; + lP2[SiHit::xDep] = 0; + + G4DynamicParticle* dynamicPar = new G4DynamicParticle(); + G4double aValueTime = 1; + G4ThreeVector ValuePosition(1.0, 1.0, 1.0); + G4Track track(dynamicPar, aValueTime, ValuePosition); + TrackHelper trHelp(&track); + + int brlEcap = 0; + int layerDisk = 0; + int etaMod = 0; + int phiMod = 0; + int side = 0; + SctSensorSD sd4("name4", "name4"); + G4HCofThisEvent hce; + sd4.Initialize( &hce ); + sd4.AddHit(lP1, lP2, 2.0, 1.0, trHelp.GetParticleLink(), 1, brlEcap, layerDisk, etaMod, phiMod, side); + + HepGeom::Point3D<double> P1,P2; + P1[SiHit::xEta] = 1; + P1[SiHit::xPhi] = 0; + P1[SiHit::xDep] = 0; + P2[SiHit::xEta] = 2; + P2[SiHit::xPhi] = 0; + P2[SiHit::xDep] = 0; + + int barcode = 0; + HepMcParticleLink plink(barcode); + + SiHitCollection* a = sd4.m_HitColl.ptr(); + ASSERT_EQ(a->begin()->localStartPosition(), P1); + ASSERT_EQ(a->begin()->localEndPosition(), P2); + ASSERT_EQ(a->begin()->energyLoss(), 2.0); + ASSERT_EQ(a->begin()->meanTime(), 1.0); + ASSERT_EQ(a->begin()->particleLink(), plink); + ASSERT_EQ(a->begin()->identify(), 10245); + ASSERT_EQ(a->size(), 1); + +} + +int main( int argc, char** argv ) { + + auto g=new GaudiEnvironment; + ::testing::AddGlobalTestEnvironment(g); + ::testing::InitGoogleTest( &argc, argv ); + return RUN_ALL_TESTS(); + +} + -- GitLab From 6fc5702ce645b70ce79fd64666618df05b7e44b5 Mon Sep 17 00:00:00 2001 From: lihan <hanliangliang_1_2@163.com> Date: Mon, 9 Sep 2019 10:24:16 +0200 Subject: [PATCH 2/9] quench already-merged changes --- Calorimeter/CaloG4Sim/CMakeLists.txt | 8 +-- .../derivedVEscapedEnergyProcessing.h | 52 ------------------- .../test/EscapedEnergyRegistry_gtest.cxx | 20 ------- .../src/G4FieldManagerToolBase.cxx | 25 +-------- 4 files changed, 2 insertions(+), 103 deletions(-) delete mode 100644 Calorimeter/CaloG4Sim/CaloG4Sim/derivedVEscapedEnergyProcessing.h delete mode 100644 Calorimeter/CaloG4Sim/test/EscapedEnergyRegistry_gtest.cxx diff --git a/Calorimeter/CaloG4Sim/CMakeLists.txt b/Calorimeter/CaloG4Sim/CMakeLists.txt index e54a2b73d03f..1d6c8725c1e9 100644 --- a/Calorimeter/CaloG4Sim/CMakeLists.txt +++ b/Calorimeter/CaloG4Sim/CMakeLists.txt @@ -20,7 +20,7 @@ find_package( CLHEP ) find_package( Geant4 ) find_package( TBB ) find_package( XercesC ) -find_package( GTest REQUIRED ) + # Component(s) in the package: atlas_add_library( CaloG4SimLib src/*.cc @@ -39,9 +39,3 @@ atlas_add_component( CaloG4Sim # Install files from the package: atlas_install_python_modules( python/*.py ) -atlas_add_test( EscapedEnergyRegistry_gtest - SOURCES - test/EscapedEnergyRegistry_gtest.cxx - INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${TBB_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS} - LINK_LIBRARIES ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} ${TBB_LIBRARIES} ${GTEST_LIBRARIES} AthenaBaseComps GaudiKernel G4AtlasInterfaces G4AtlasToolsLib - CxxUtils MCTruth CaloG4SimLib pthread ) diff --git a/Calorimeter/CaloG4Sim/CaloG4Sim/derivedVEscapedEnergyProcessing.h b/Calorimeter/CaloG4Sim/CaloG4Sim/derivedVEscapedEnergyProcessing.h deleted file mode 100644 index 5ffd4a941a16..000000000000 --- a/Calorimeter/CaloG4Sim/CaloG4Sim/derivedVEscapedEnergyProcessing.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -// VEscapedEnergyProcessing -// 13-Jul-2004 William Seligman - -#ifndef CaloG4_derivedVEscapedEnergyProcessing_H -#define CaloG4_derivedVEscapedEnergyProcessing_H - -#include "G4Step.hh" -#include "globals.hh" -#include "CaloG4Sim/VEscapedEnergyProcessing.h" - -namespace CaloG4 -{ - - /// @class VEscapedEnergyProcessing - /// @brief Virtual interface for escaped energy processor classes. - /// - /// The SimulationEnergies class provides a common procedure for - /// categorizing the energy deposited in a given G4Step. However, - /// different detectors have different scheme for handling one of the - /// categories: escaped energy. - /// - /// The issue is that, if a particle's energy is lost by escaping the - /// simulation, you don't want to record that energy in the volume it - /// escapes; you want to record that energy in the volume in which the - /// particle was created. Neutrinos are a good example of this. - /// - /// In effect, the SimulationEnergies class has to issue an "interrupt" - /// to some other volume than the current G4Step, telling that other - /// volume to accumulate the energy of the escaped particle. The Tile - /// Simulation and the LAr simulation handle this interrupt - /// differently, since they organize sensitive detectors in a different - /// way. - /// - /// This interface "hides" the different escaped-energy processing - /// required by the different detectors in the simulation. - /// - class derivedVEscapedEnergyProcessing : public VEscapedEnergyProcessing - { - - public: - - virtual G4bool Process( G4Step* ) { return true; } - - }; - -} // namespace CaloG4 - -#endif // CaloG4_derivedVEscapedEnergyProcessing_H diff --git a/Calorimeter/CaloG4Sim/test/EscapedEnergyRegistry_gtest.cxx b/Calorimeter/CaloG4Sim/test/EscapedEnergyRegistry_gtest.cxx deleted file mode 100644 index 370f719e1f19..000000000000 --- a/Calorimeter/CaloG4Sim/test/EscapedEnergyRegistry_gtest.cxx +++ /dev/null @@ -1,20 +0,0 @@ -#include "CaloG4Sim/EscapedEnergyRegistry.h" -#include "CaloG4Sim/derivedVEscapedEnergyProcessing.h" -#include "gtest/gtest.h" - -TEST( testcase, test1 ) { - -const G4String name = "processing"; -CaloG4::EscapedEnergyRegistry* classToTest = CaloG4::EscapedEnergyRegistry::GetInstance(); -CaloG4::derivedVEscapedEnergyProcessing* classToOperate = new CaloG4::derivedVEscapedEnergyProcessing(); -classToTest->AddAndAdoptProcessing( name, classToOperate ); -ASSERT_EQ( classToOperate, classToTest->GetProcessing( name ) ); - -} -//add something -int main(int argc, char **argv) { - - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); - -} diff --git a/Simulation/G4Atlas/G4AtlasTools/src/G4FieldManagerToolBase.cxx b/Simulation/G4Atlas/G4AtlasTools/src/G4FieldManagerToolBase.cxx index ae3efd9378b3..9b82794ab97f 100644 --- a/Simulation/G4Atlas/G4AtlasTools/src/G4FieldManagerToolBase.cxx +++ b/Simulation/G4Atlas/G4AtlasTools/src/G4FieldManagerToolBase.cxx @@ -16,18 +16,7 @@ #include "G4NystromRK4.hh" #include "G4ClassicalRK4.hh" #include "G4AtlasRK4.hh" -#include "G4BogackiShampine23.hh" -#include "G4BogackiShampine45.hh" -#include "G4CashKarpRKF45.hh" -#include "G4DoLoMcPriRK34.hh" -#include "G4DormandPrince745.hh" -#include "G4DormandPrinceRK56.hh" -#include "G4DormandPrinceRK78.hh" -#include "G4RK547FEq1.hh" -#include "G4RK547FEq2.hh" -#include "G4RK547FEq3.hh" -#include "G4RKG3_Stepper.hh" -#include "G4TsitourasRK45.hh" + // CLHEP includes #include "CLHEP/Units/SystemOfUnits.h" @@ -120,18 +109,6 @@ G4FieldManagerToolBase::getStepper(std::string name, G4MagneticField* field) con else if (name=="NystromRK4") return new G4NystromRK4(eqRhs); else if (name=="ClassicalRK4") return new G4ClassicalRK4(eqRhs); else if (name=="AtlasRK4") return new G4AtlasRK4(eqRhs); - else if (name=="BogackiShampine23") return new G4BogackiShampine23(eqRhs); - else if (name=="BogackiShampine45") return new G4BogackiShampine45(eqRhs); - else if (name=="CashKarpRKF45") return new G4CashKarpRKF45(eqRhs); - else if (name=="DoLoMcPriRK34") return new G4DoLoMcPriRK34(eqRhs); - else if (name=="DormandPrince745") return new G4DormandPrince745(eqRhs); - else if (name=="DormandPrinceRK56") return new G4DormandPrinceRK56(eqRhs); - else if (name=="DormandPrinceRK78") return new G4DormandPrinceRK78(eqRhs); - else if (name=="RK547FEq1") return new G4RK547FEq1(eqRhs); - else if (name=="RK547FEq2") return new G4RK547FEq2(eqRhs); - else if (name=="RK547FEq3") return new G4RK547FEq3(eqRhs); - else if (name=="RKG3_Stepper") return new G4RKG3_Stepper(eqRhs); - else if (name=="TsitourasRK45") return new G4TsitourasRK45(eqRhs); else { ATH_MSG_ERROR("Stepper " << name << " not available! returning NystromRK4!"); return new G4NystromRK4(eqRhs); -- GitLab From a68db415940204a82e5c500ab158500ad709eb1a Mon Sep 17 00:00:00 2001 From: lihan <hanliangliang_1_2@163.com> Date: Sun, 15 Sep 2019 17:29:45 +0200 Subject: [PATCH 3/9] the test of SctSensor_CTB was included in this branch --- .../InDetG4/SCT_G4_SD/CMakeLists.txt | 29 +-- .../InDetG4/SCT_G4_SD/src/SctSensorSD.h | 14 +- .../InDetG4/SCT_G4_SD/src/SctSensor_CTB.h | 5 + .../SCT_G4_SD/test/SctSensorSD_gtest.cxx | 38 ++- .../SCT_G4_SD/test/SctSensor_CTB_gtest.cxx | 216 ++++++++++++++++++ .../DerivedG4SensitiveDetectorTestSetting.h | 127 ++++++++++ .../G4AtlasTools}/G4MyPhysicalVolume.h | 2 - .../G4AtlasTools/G4AtlasTools/G4MyProcess.h | 89 ++++++++ 8 files changed, 480 insertions(+), 40 deletions(-) create mode 100644 InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx create mode 100644 Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h rename {InnerDetector/InDetG4/SCT_G4_SD/src => Simulation/G4Atlas/G4AtlasTools/G4AtlasTools}/G4MyPhysicalVolume.h (99%) create mode 100644 Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyProcess.h diff --git a/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt b/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt index 664d7cc48704..18346cd064af 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt +++ b/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt @@ -14,17 +14,6 @@ atlas_depends_on_subdirs( PRIVATE Simulation/G4Atlas/G4AtlasTools Simulation/G4Sim/MCTruth AtlasTest/TestTools - Control/AthenaBaseComps - DetectorDescription/AtlasDetDescr - Generators/GeneratorObjects - Simulation/Interfaces/HepMC_Interfaces - Simulation/ISF/ISF_Core/ISF_Event - Simulation/ISF/ISF_Core/ISF_Interfaces - Tools/PmbCxxUtils - Simulation/ISF/ISF_Core/ISF_Algorithms - LArCalorimeter/LArSimEvent - TileCalorimeter/TileSimEvent - MuonSpectrometer/MuonSimEvent ) # External dependencies: @@ -33,11 +22,6 @@ find_package( Geant4 ) find_package( XercesC ) find_package( GTest ) -find_package( Eigen ) -find_package( Boost COMPONENTS filesystem thread system ) -find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread ) - - # Component(s) in the package: atlas_add_component( SCT_G4_SD src/*.cxx @@ -57,9 +41,16 @@ atlas_add_test( SCT_G4_SDToolConfig_test atlas_add_test( SctSensorSD_gtest SOURCES test/SctSensorSD_gtest.cxx - INCLUDE_DIRS ${GTEST_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS} - LINK_LIBRARIES TestTools ${GTEST_LIBRARIES} ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} SCT_G4_SDLib CxxUtils StoreGateLib SGtests GaudiKernel InDetSimEvent G4AtlasToolsLib MCTruth pthread ENVIRONMENT "JOBOPTSEARCHPATH=${CMAKE_CURRENT_SOURCE_DIR}/share" AtlasDetDescr GeneratorObjects ISF_Event ISF_Interfaces PmbCxxUtils InDetSimEvent LArSimEvent TileSimEvent MuonSimEvent AthenaBaseComps + INCLUDE_DIRS ${GTEST_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} + LINK_LIBRARIES TestTools ${GTEST_LIBRARIES} ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} SCT_G4_SDLib CxxUtils StoreGateLib SGtests GaudiKernel InDetSimEvent G4AtlasToolsLib MCTruth +) + +atlas_add_test( SctSensor_CTB_gtest + SOURCES test/SctSensor_CTB_gtest.cxx + INCLUDE_DIRS ${GTEST_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} + LINK_LIBRARIES TestTools ${GTEST_LIBRARIES} ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} SCT_G4_SDLib CxxUtils StoreGateLib SGtests GaudiKernel InDetSimEvent G4AtlasToolsLib MCTruth ) + # Install files from the package: atlas_install_python_modules( python/*.py ) - +atlas_install_joboptions( share/optionForTest.txt ) diff --git a/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensorSD.h b/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensorSD.h index 2cb71c77e78a..2695af0528bf 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensorSD.h +++ b/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensorSD.h @@ -15,6 +15,7 @@ // For the hits #include "InDetSimEvent/SiHitCollection.h" #include "StoreGate/WriteHandle.h" +#include <gtest/gtest_prod.h> // G4 needed classes class G4Step; @@ -22,6 +23,11 @@ class G4TouchableHistory; class SctSensorSD : public G4VSensitiveDetector { + + FRIEND_TEST( SctSensorSDtest, Initialize ); + FRIEND_TEST( SctSensorSDtest, ProcessHits ); + FRIEND_TEST( SctSensorSDtest, indexMethod ); + FRIEND_TEST( SctSensorSDtest, AddHit ); public: // Constructor SctSensorSD(const std::string& name, const std::string& hitCollectionName); @@ -39,17 +45,9 @@ public: could get rather tricky, but the idea is to allow fast simulations to use the very same SD classes as the standard simulation. */ template <class... Args> void AddHit(Args&&... args){ m_HitColl->Emplace( args... ); } -#ifdef TESTSctSensorSD -public: -#else private: -#endif void indexMethod(const G4TouchableHistory *myTouch, double coord1z, int &brlEcap, int &layerDisk, int &etaMod, int &phiMod, int &side); -#ifdef TESTSctSensorSD -public: -#else protected: -#endif // The hits collection SG::WriteHandle<SiHitCollection> m_HitColl; }; diff --git a/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensor_CTB.h b/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensor_CTB.h index f50fccae5386..28d1a14e919c 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensor_CTB.h +++ b/InnerDetector/InDetG4/SCT_G4_SD/src/SctSensor_CTB.h @@ -16,6 +16,7 @@ // For the hits #include "StoreGate/WriteHandle.h" #include "InDetSimEvent/SiHitCollection.h" +#include <gtest/gtest_prod.h> // G4 needed classes class G4Step; @@ -25,6 +26,10 @@ class G4TouchableHistory; class SctSensor_CTB : public G4VSensitiveDetector { + + FRIEND_TEST( SctSensor_CTBtest, Initialize ); + FRIEND_TEST( SctSensor_CTBtest, ProcessHits ); + FRIEND_TEST( SctSensor_CTBtest, AddHit ); public: // Constructor SctSensor_CTB( const std::string& name, const std::string& hitCollectionName ); diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx index 780138bf53ae..9a121a7f8b6e 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx @@ -1,12 +1,8 @@ -#define TESTSctSensorSD - #include "src/SctSensorSD.h" #include "gtest/gtest.h" #include "TestTools/initGaudi.h" -#include "src/CollectionMerger.h" -#include "src/CollectionMerger.cxx" #include "G4HCofThisEvent.hh" #include "G4Step.hh" @@ -21,7 +17,8 @@ #include "G4Material.hh" #include "G4VPhysicalVolume.hh" -#include "src/G4MyPhysicalVolume.h" +#include "G4AtlasTools/G4MyPhysicalVolume.h" +#include "G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h" #include "MCTruth/TrackHelper.h" //set environment @@ -29,21 +26,19 @@ ISvcLocator* g_svcLoc = nullptr; class GaudiEnvironment : public ::testing::Environment { protected: virtual void SetUp() override { - Athena_test::initGaudi("/afs/cern.ch/user/l/lihan/private/repo/athena/InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt", g_svcLoc); + Athena_test::initGaudi("SCT_G4_SD/optionForTest.txt", g_svcLoc); } }; class SctSensorSDtest : public ::testing::Test { protected: virtual void SetUp() override { - m_alg = new ISF::CollectionMerger{"CollectionMerger", g_svcLoc}; - ASSERT_TRUE( m_alg->setProperties().isSuccess() ); +//... } virtual void TearDown() override { - ASSERT_TRUE( m_alg->finalize().isSuccess() ); - delete m_alg; +//... } - ISF::CollectionMerger* m_alg; +//... }; //end of environment setting @@ -60,6 +55,26 @@ TEST_F( SctSensorSDtest, ProcessHits ) G4TouchableHistory th; G4HCofThisEvent hce; + G4double totalenergydeposit = 3.0; + G4String physicalname = "physicalName"; + G4int copyno = 1000; + G4ThreeVector preStepPos = G4ThreeVector(0,0,1); + G4ThreeVector postStepPos = G4ThreeVector(0,0,2); + G4double globaltime0 = 0.5; + G4double kineticenergy0 = 1.5; + G4double velocity0 = 99.93100; + G4double globaltime1 = 5; + G4double kineticenergy1 = 0.5; + G4double velocity1 = 99.93100; + G4double steplength = 1.0; + G4double charge = 1.0; + G4int encoding = 22; + G4int antiencoding = 22; + G4String astring = "Cerenkov"; + G4ProcessType atype = (G4ProcessType)0; + DerivedG4SensitiveDetectorTestSetting(sp, totalenergydeposit, physicalname, copyno, preStepPos, postStepPos, globaltime0, kineticenergy0, velocity0, globaltime1, kineticenergy1, velocity1, steplength, charge, encoding, antiencoding, astring, atype); + +/* //setting to make aStep->GetTotalEnergyDeposit() in class to be tested work G4double TotalEnergyDeposit = 3.0; sp.SetTotalEnergyDeposit( TotalEnergyDeposit ); @@ -114,6 +129,7 @@ TEST_F( SctSensorSDtest, ProcessHits ) sp.SetTrack(&track); //end +*/ SctSensorSD sd2("name2", "name2"); sd2.Initialize( &hce ); diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx new file mode 100644 index 000000000000..0907500e42e0 --- /dev/null +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx @@ -0,0 +1,216 @@ +#include "src/SctSensor_CTB.h" + +#include "gtest/gtest.h" + +#include "TestTools/initGaudi.h" + +#include "G4HCofThisEvent.hh" +#include "G4Step.hh" +#include "G4TouchableHistory.hh" + +#include "G4Track.hh" +#include "G4StepPoint.hh" +#include "G4DynamicParticle.hh" +#include "G4ThreeVector.hh" +#include "G4Box.hh" +#include "G4NistManager.hh" +#include "G4Material.hh" +#include "G4VPhysicalVolume.hh" + +#include "G4AtlasTools/G4MyPhysicalVolume.h" +#include "G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h" +#include "MCTruth/TrackHelper.h" + +//set environment +ISvcLocator* g_svcLoc = nullptr; +class GaudiEnvironment : public ::testing::Environment { + protected: + virtual void SetUp() override { + Athena_test::initGaudi("SCT_G4_SD/optionForTest.txt", g_svcLoc); + } +}; +class SctSensor_CTBtest : public ::testing::Test { + protected: + virtual void SetUp() override { +//... + } + + virtual void TearDown() override { +//... + } +//... +}; +//end of environment setting + +TEST_F( SctSensor_CTBtest, Initialize ) +{ + G4HCofThisEvent hce; + SctSensor_CTB sd1("name1", "name1" ); + sd1.Initialize( &hce ); + ASSERT_TRUE(sd1.m_HitColl.isValid());//check if initialization of m_HitColl is successful +} + +TEST_F( SctSensor_CTBtest, ProcessHits ) +{ + G4Step sp; + G4TouchableHistory th; + G4HCofThisEvent hce; + + G4double totalenergydeposit = 3.0; + G4String physicalname = "physicalName"; + G4int copyno = 1000; + G4ThreeVector preStepPos = G4ThreeVector(0,0,1); + G4ThreeVector postStepPos = G4ThreeVector(0,0,2); + G4double globaltime0 = 0.5; + G4double kineticenergy0 = 1.5; + G4double velocity0 = 99.93100; + G4double globaltime1 = 5; + G4double kineticenergy1 = 0.5; + G4double velocity1 = 99.93100; + G4double steplength = 1.0; + G4double charge = 1.0; + G4int encoding = 22; + G4int antiencoding = 22; + G4String astring = "Cerenkov"; + G4ProcessType atype = (G4ProcessType)0; + DerivedG4SensitiveDetectorTestSetting(sp, totalenergydeposit, physicalname, copyno, preStepPos, postStepPos, globaltime0, kineticenergy0, velocity0, globaltime1, kineticenergy1, velocity1, steplength, charge, encoding, antiencoding, astring, atype); + +/* +// decorate G4Step object with TotalEnergyDeposit + G4double TotalEnergyDeposit = 3.0; + sp.SetTotalEnergyDeposit( TotalEnergyDeposit ); +//end + +// decorate G4Stetp object with a G4StepPoint object + G4StepPoint* stepPoint = new G4StepPoint(); + G4ThreeVector preStepPos(0, 0, 1); + stepPoint->SetPosition(preStepPos); + G4NavigationHistory* navigationHistory = new G4NavigationHistory(); + G4String boxName = "name"; + G4Box* box = new G4Box(boxName, 1.0, 1.0, 1.0); + G4NistManager* man = G4NistManager::Instance(); + G4Material* material = man->FindOrBuildMaterial("G4_AIR"); + G4String name = "logicalName"; + G4LogicalVolume fLogical(box, material, name); + G4String name1 = "physicalName"; + G4VPhysicalVolume* pPhysical = NULL; + G4MyPhysicalVolume physicalVolume(0, G4ThreeVector(0,0,0), name1, &fLogical, pPhysical); + physicalVolume.SetCopyNo(1000); + G4int nReplica = 2; + navigationHistory->SetFirstEntry(&physicalVolume); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); + G4TouchableHistory* touchableHistory = new G4TouchableHistory(*navigationHistory); + G4TouchableHandle touchableHandle(touchableHistory); + stepPoint->SetTouchableHandle(touchableHandle); + stepPoint->SetGlobalTime(0.5); + + sp.SetPreStepPoint(stepPoint); +// end + +//decorate G4Step object with another G4StepPoint object + G4StepPoint* stepPoint1 = new G4StepPoint(); + G4ThreeVector postStepPos(0, 0, 2); + stepPoint1->SetPosition(postStepPos); + + sp.SetPostStepPoint(stepPoint1); +//end + +//decorate G4Step object with a G4Track object + G4DynamicParticle* dynamicPar = new G4DynamicParticle(); + G4double aValueTime = 1; + G4ThreeVector ValuePosition(1.0, 1.0, 1.0); + G4Track track(dynamicPar, aValueTime, ValuePosition); + G4double globalTime = 5.0; + track.SetGlobalTime(globalTime); + + sp.SetTrack(&track); +//end +*/ + + SctSensor_CTB sd2("name2", "name2"); + sd2.Initialize( &hce ); + sd2.ProcessHits(&sp, &th ); + + HepGeom::Point3D<double> P1,P2; + P1[SiHit::xEta] = 1; + P1[SiHit::xPhi] = 0; + P1[SiHit::xDep] = 0; + P2[SiHit::xEta] = 2; + P2[SiHit::xPhi] = 0; + P2[SiHit::xDep] = 0; + + int barcode = 0; + HepMcParticleLink plink(barcode); + + SiHitCollection* a = sd2.m_HitColl.ptr(); + ASSERT_EQ(a->begin()->localStartPosition(), P1); + ASSERT_EQ(a->begin()->localEndPosition(), P2); + ASSERT_EQ(a->begin()->energyLoss(), 3.0); + ASSERT_EQ(a->begin()->meanTime(), 0.5); + ASSERT_EQ(a->begin()->particleLink(), plink); + ASSERT_EQ(a->begin()->identify(),4093651781); + + ASSERT_EQ(a->size(), 1); +} + +TEST_F( SctSensor_CTBtest, AddHit ) +{ + HepGeom::Point3D<double> lP1,lP2; + lP1[SiHit::xEta] = 1; + lP1[SiHit::xPhi] = 0; + lP1[SiHit::xDep] = 0; + lP2[SiHit::xEta] = 2; + lP2[SiHit::xPhi] = 0; + lP2[SiHit::xDep] = 0; + + G4DynamicParticle* dynamicPar = new G4DynamicParticle(); + G4double aValueTime = 1; + G4ThreeVector ValuePosition(1.0, 1.0, 1.0); + G4Track track(dynamicPar, aValueTime, ValuePosition); + TrackHelper trHelp(&track); + + int brlEcap = 0; + int layerDisk = 0; + int etaMod = 0; + int phiMod = 0; + int side = 0; + SctSensor_CTB sd4("name4", "name4"); + G4HCofThisEvent hce; + sd4.Initialize( &hce ); + sd4.AddHit(lP1, lP2, 2.0, 1.0, trHelp.GetParticleLink(), 1, brlEcap, layerDisk, etaMod, phiMod, side); + + HepGeom::Point3D<double> P1,P2; + P1[SiHit::xEta] = 1; + P1[SiHit::xPhi] = 0; + P1[SiHit::xDep] = 0; + P2[SiHit::xEta] = 2; + P2[SiHit::xPhi] = 0; + P2[SiHit::xDep] = 0; + + int barcode = 0; + HepMcParticleLink plink(barcode); + + SiHitCollection* a = sd4.m_HitColl.ptr(); + ASSERT_EQ(a->begin()->localStartPosition(), P1); + ASSERT_EQ(a->begin()->localEndPosition(), P2); + ASSERT_EQ(a->begin()->energyLoss(), 2.0); + ASSERT_EQ(a->begin()->meanTime(), 1.0); + ASSERT_EQ(a->begin()->particleLink(), plink); + ASSERT_EQ(a->begin()->identify(), 10245); + ASSERT_EQ(a->size(), 1); + +} + +int main( int argc, char** argv ) { + + auto g=new GaudiEnvironment; + ::testing::AddGlobalTestEnvironment(g); + ::testing::InitGoogleTest( &argc, argv ); + return RUN_ALL_TESTS(); + +} + diff --git a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h new file mode 100644 index 000000000000..26606040950b --- /dev/null +++ b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h @@ -0,0 +1,127 @@ +#include "G4HCofThisEvent.hh" +#include "G4Step.hh" +#include "G4TouchableHistory.hh" + +#include "G4Track.hh" +#include "G4StepPoint.hh" +#include "G4DynamicParticle.hh" +#include "G4ThreeVector.hh" +#include "G4Box.hh" +#include "G4NistManager.hh" +#include "G4Material.hh" +#include "G4VPhysicalVolume.hh" +#include "G4SystemOfUnits.hh" + +#include "G4MyProcess.h" + +void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydeposit, G4String& physicalname, G4int& copyno, G4ThreeVector& preStepPos, G4ThreeVector& postStepPos, G4double& globaltime0, G4double& kineticenergy0, G4double& velocity0, G4double& globaltime1, G4double& kineticenergy1, G4double& velocity1, G4double& steplength, G4double& charge, G4int& encoding, G4int& antiencoding, G4String& astring, G4ProcessType& atype) +{ +//decorate sp with the variable called TotalEnergyDeposit + G4double TotalEnergyDeposit = totalenergydeposit;//para + sp.SetTotalEnergyDeposit( TotalEnergyDeposit ); +//end + +//decorate sp with a G4StepPoint object + G4StepPoint* stepPoint = new G4StepPoint(); + stepPoint->SetPosition(preStepPos);//para + G4NavigationHistory* navigationHistory = new G4NavigationHistory(); + G4String boxName = "name"; + G4Box* box = new G4Box(boxName, 1.0, 1.0, 1.0); + G4NistManager* man = G4NistManager::Instance(); + G4Material* material = man->FindOrBuildMaterial("G4_AIR"); + G4String name = "logicalName"; + G4LogicalVolume* fLogical = new G4LogicalVolume(box, material, name); + G4String PhysicalName = physicalname;//para + G4VPhysicalVolume* pPhysical = NULL; + G4MyPhysicalVolume* physicalVolume = new G4MyPhysicalVolume(0, G4ThreeVector(0,0,0), PhysicalName, fLogical, pPhysical); + G4int CopyNo = copyno; + physicalVolume->SetCopyNo(copyno);//para + G4int nReplica = 2; + navigationHistory->SetFirstEntry(physicalVolume); + navigationHistory->NewLevel(physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(physicalVolume, kNormal, nReplica); + navigationHistory->NewLevel(physicalVolume, kNormal, nReplica); + G4TouchableHistory* touchableHistory = new G4TouchableHistory(*navigationHistory); + G4TouchableHandle touchableHandle(touchableHistory); + stepPoint->SetTouchableHandle(touchableHandle); + G4double GlobalTime0 = globaltime0; + G4double KineticEnergy0 = kineticenergy0; + G4double Velocity0 = velocity0; + stepPoint->SetGlobalTime(GlobalTime0);//para + stepPoint->SetKineticEnergy(KineticEnergy0);//para + stepPoint->SetVelocity(Velocity0);//para + + sp.SetPreStepPoint(stepPoint); +//end + +//decorate sp with another G4StepPoint object + G4StepPoint* stepPoint1 = new G4StepPoint(); +// G4ThreeVector postStepPos(0, 0, 2); + stepPoint1->SetPosition(postStepPos);//para + G4double Velocity1 = velocity1; + stepPoint1->SetVelocity(Velocity1);//para + + sp.SetPostStepPoint(stepPoint1); +//end + +//set step length for the step + G4double StepLength = steplength; + sp.SetStepLength(StepLength);//para +//end + +//decorate sp with a G4Track object +G4double Charge = charge; +G4int Encoding = encoding; +G4int Antiencoding = antiencoding; +G4ParticleDefinition* particle = new G4ParticleDefinition("anyon", 0.0*MeV, 0.0*MeV, Charge,//para + 2, -1, -1, + 0, 0, 0, + "anyon", 0, 0, Encoding,//para + true, -1.0, NULL, + false, "anyon", Antiencoding//para + ); + G4ThreeVector aMomentumDirection(0,0,0); + G4double aKineticEnergy = kineticenergy1;//para + G4DynamicParticle* dynamicPar = new G4DynamicParticle(particle, aMomentumDirection, aKineticEnergy); + G4double aValueTime = 1; + G4ThreeVector ValuePosition(1.0, 1.0, 1.0); + G4Track* track = new G4Track(dynamicPar, aValueTime, ValuePosition); + G4double globalTime = globaltime1; + track->SetGlobalTime(globalTime);//para + int trackID = 3; + track->SetTrackID(trackID); + G4String boxName1 = "name"; + G4Box* box1 = new G4Box(boxName1, 1.0, 1.0, 1.0); + G4NistManager* man1 = G4NistManager::Instance(); + G4Material* material1 = man1->FindOrBuildMaterial("G4_AIR"); + G4String name2 = "name2"; + G4LogicalVolume* fLogical1 = new G4LogicalVolume(box1, material1, name2); + track->SetLogicalVolumeAtVertex(fLogical1); + G4Step* stepForTrack = new G4Step(); + G4StepPoint* stepPoint2 = new G4StepPoint(); + G4Material* mat1 = man1->FindOrBuildMaterial("G4_AIR"); + G4MaterialPropertiesTable* propertiesTable = new G4MaterialPropertiesTable(); + G4double Energies[5] = {1,2,3,4,5}; + G4double Values[5] = {1,2,3,4,5}; + size_t VectorLength = 5; + G4MaterialPropertyVector* mpv = new G4MaterialPropertyVector(Energies, Values, VectorLength); + G4MaterialPropertyVector* mpv1 = new G4MaterialPropertyVector(Energies, Values, VectorLength); + propertiesTable->AddProperty("RINDEX", mpv); + propertiesTable->AddProperty("ABSLENGTH", mpv1); + mat1->SetMaterialPropertiesTable(propertiesTable); + stepPoint2->SetMaterial(mat1); + stepForTrack->SetPreStepPoint(stepPoint2); + track->SetStep(stepForTrack); + + G4ProcessType aType = atype; + G4String aString = astring; + G4MyProcess* process = new G4MyProcess( aString, aType );//para para + track->SetCreatorProcess( process ); + + sp.SetTrack(track); +//end + + return; +} diff --git a/InnerDetector/InDetG4/SCT_G4_SD/src/G4MyPhysicalVolume.h b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyPhysicalVolume.h similarity index 99% rename from InnerDetector/InDetG4/SCT_G4_SD/src/G4MyPhysicalVolume.h rename to Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyPhysicalVolume.h index a5e80e92ea73..37adc096b1c3 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/src/G4MyPhysicalVolume.h +++ b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyPhysicalVolume.h @@ -48,5 +48,3 @@ public: }; #endif - - diff --git a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyProcess.h b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyProcess.h new file mode 100644 index 000000000000..3e74ce58ca26 --- /dev/null +++ b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyProcess.h @@ -0,0 +1,89 @@ +#ifndef G4MyProcess_h +#define G4MyProcess_h + +#include "G4VProcess.hh" + +class G4MyProcess : public G4VProcess { + + public: + + G4MyProcess( G4String& aName, G4ProcessType aType ) : G4VProcess( aName, aType ) + { + + } + + ~G4MyProcess() {} + + G4VParticleChange* PostStepDoIt( + const G4Track& track, + const G4Step& stepData + ) + { +// G4Track a = track; +// G4Step b = stepData; + + return nullptr; + } + + G4VParticleChange* AlongStepDoIt( + const G4Track& track, + const G4Step& stepData + ) + { +// G4Track a = track; +// G4Step b = stepData; + + return nullptr; + } + + G4VParticleChange* AtRestDoIt( + const G4Track& track, + const G4Step& stepData + ) + { +// G4Track a = track; +// G4Step b = stepData; + + return nullptr; + } + + G4double AlongStepGetPhysicalInteractionLength( + const G4Track& track, + G4double previousStepSize, + G4double currentMinimumStep, + G4double& proposedSafety, + G4GPILSelection* selection) + { +// G4Track a = track; +// G4double c = previousStepSize; +// G4double d = currentMinimumStep; +// G4double e = proposedSafety; +// G4GPILSelection* f = selection; + return 0.0; + } + + G4double AtRestGetPhysicalInteractionLength( + const G4Track& track, + G4ForceCondition* condition + ) + { +// G4Track a = track; +// G4ForceCondition* b = condition; + return 0.0; + } + + G4double PostStepGetPhysicalInteractionLength( + const G4Track& track, + G4double previousStepSize, + G4ForceCondition* condition + ) + { +// G4Track a = track; +// G4double b = previousStepSize; +// G4ForceCondition* c = condition; + return 0.0; + } +}; + +#endif + -- GitLab From eea14241e194565b408664c8af9566378005cc95 Mon Sep 17 00:00:00 2001 From: lihan <hanliangliang_1_2@163.com> Date: Mon, 16 Sep 2019 16:18:10 +0200 Subject: [PATCH 4/9] update DerivedG4SensitiveDetectorTestSetting.h --- .../SCT_G4_SD/test/SctSensorSD_gtest.cxx | 10 ++++++-- .../SCT_G4_SD/test/SctSensor_CTB_gtest.cxx | 12 ++++++--- .../DerivedG4SensitiveDetectorTestSetting.h | 25 +++++++++++++------ 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx index 9a121a7f8b6e..d4f08f983c2e 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx @@ -57,13 +57,16 @@ TEST_F( SctSensorSDtest, ProcessHits ) G4double totalenergydeposit = 3.0; G4String physicalname = "physicalName"; + G4String logicalname = "BBBBBBBBBTubeGas"; G4int copyno = 1000; G4ThreeVector preStepPos = G4ThreeVector(0,0,1); G4ThreeVector postStepPos = G4ThreeVector(0,0,2); G4double globaltime0 = 0.5; G4double kineticenergy0 = 1.5; G4double velocity0 = 99.93100; - G4double globaltime1 = 5; + G4double globaltime = 5.0; + G4double kineticenergy = 0.5; + G4double globaltime1 = 0.5; G4double kineticenergy1 = 0.5; G4double velocity1 = 99.93100; G4double steplength = 1.0; @@ -72,7 +75,10 @@ TEST_F( SctSensorSDtest, ProcessHits ) G4int antiencoding = 22; G4String astring = "Cerenkov"; G4ProcessType atype = (G4ProcessType)0; - DerivedG4SensitiveDetectorTestSetting(sp, totalenergydeposit, physicalname, copyno, preStepPos, postStepPos, globaltime0, kineticenergy0, velocity0, globaltime1, kineticenergy1, velocity1, steplength, charge, encoding, antiencoding, astring, atype); + G4String nop1 = "opticalphoton"; + G4String nop2 = "opticalphoton"; + G4String nop3 = "photon"; + DerivedG4SensitiveDetectorTestSetting(sp, totalenergydeposit, physicalname, logicalname, copyno, preStepPos, postStepPos, globaltime0, kineticenergy0, velocity0, globaltime, kineticenergy, globaltime1, kineticenergy1, velocity1, steplength, charge, encoding, antiencoding, astring, atype, nop1, nop2, nop3); /* //setting to make aStep->GetTotalEnergyDeposit() in class to be tested work diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx index 0907500e42e0..5bd16a1da2f1 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx @@ -58,22 +58,28 @@ TEST_F( SctSensor_CTBtest, ProcessHits ) G4double totalenergydeposit = 3.0; G4String physicalname = "physicalName"; + G4String logicalname = "BBBBBBBBBTubeGas"; G4int copyno = 1000; G4ThreeVector preStepPos = G4ThreeVector(0,0,1); G4ThreeVector postStepPos = G4ThreeVector(0,0,2); G4double globaltime0 = 0.5; G4double kineticenergy0 = 1.5; G4double velocity0 = 99.93100; - G4double globaltime1 = 5; + G4double globaltime = 5.0; + G4double kineticenergy = 0.5; + G4double globaltime1 = 0.5; G4double kineticenergy1 = 0.5; G4double velocity1 = 99.93100; G4double steplength = 1.0; G4double charge = 1.0; - G4int encoding = 22; + G4int encoding =22; G4int antiencoding = 22; G4String astring = "Cerenkov"; G4ProcessType atype = (G4ProcessType)0; - DerivedG4SensitiveDetectorTestSetting(sp, totalenergydeposit, physicalname, copyno, preStepPos, postStepPos, globaltime0, kineticenergy0, velocity0, globaltime1, kineticenergy1, velocity1, steplength, charge, encoding, antiencoding, astring, atype); + G4String nop1 = "opticalphoton"; + G4String nop2 = "opticalphoton"; + G4String nop3 = "photon"; + DerivedG4SensitiveDetectorTestSetting(sp, totalenergydeposit, physicalname, logicalname, copyno, preStepPos, postStepPos, globaltime0, kineticenergy0, velocity0, globaltime, kineticenergy, globaltime1, kineticenergy1, velocity1, steplength, charge, encoding, antiencoding, astring, atype, nop1, nop2, nop3); /* // decorate G4Step object with TotalEnergyDeposit diff --git a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h index 26606040950b..f2d4e8c45a72 100644 --- a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h +++ b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h @@ -14,7 +14,7 @@ #include "G4MyProcess.h" -void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydeposit, G4String& physicalname, G4int& copyno, G4ThreeVector& preStepPos, G4ThreeVector& postStepPos, G4double& globaltime0, G4double& kineticenergy0, G4double& velocity0, G4double& globaltime1, G4double& kineticenergy1, G4double& velocity1, G4double& steplength, G4double& charge, G4int& encoding, G4int& antiencoding, G4String& astring, G4ProcessType& atype) +void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydeposit, G4String& physicalname, G4String& logicalname1, G4int& copyno, G4ThreeVector& preStepPos, G4ThreeVector& postStepPos, G4double& globaltime0/*for preSP*/, G4double& kineticenergy0/*for preSP*/, G4double& velocity0/*for preSP*/, G4double& globaltime/*for track*/, G4double& kineticenergy/*for track*/, G4double& globaltime1/*for postSP*/, G4double& kineticenergy1/*for postSP*/, G4double& velocity1/*for postSP*/, G4double& steplength, G4double& charge, G4int& encoding, G4int& antiencoding, G4String& astring, G4ProcessType& atype, G4String& nop1, G4String& nop2, G4String& nop3) { //decorate sp with the variable called TotalEnergyDeposit G4double TotalEnergyDeposit = totalenergydeposit;//para @@ -35,7 +35,7 @@ void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydepo G4VPhysicalVolume* pPhysical = NULL; G4MyPhysicalVolume* physicalVolume = new G4MyPhysicalVolume(0, G4ThreeVector(0,0,0), PhysicalName, fLogical, pPhysical); G4int CopyNo = copyno; - physicalVolume->SetCopyNo(copyno);//para + physicalVolume->SetCopyNo(CopyNo);//para G4int nReplica = 2; navigationHistory->SetFirstEntry(physicalVolume); navigationHistory->NewLevel(physicalVolume, kNormal, nReplica); @@ -60,7 +60,11 @@ void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydepo G4StepPoint* stepPoint1 = new G4StepPoint(); // G4ThreeVector postStepPos(0, 0, 2); stepPoint1->SetPosition(postStepPos);//para + G4double GlobalTime1 = globaltime1; + G4double KineticEnergy1 = kineticenergy1; G4double Velocity1 = velocity1; + stepPoint1->SetGlobalTime(GlobalTime1);//para + stepPoint1->SetKineticEnergy(KineticEnergy1);//para stepPoint1->SetVelocity(Velocity1);//para sp.SetPostStepPoint(stepPoint1); @@ -75,20 +79,23 @@ void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydepo G4double Charge = charge; G4int Encoding = encoding; G4int Antiencoding = antiencoding; -G4ParticleDefinition* particle = new G4ParticleDefinition("anyon", 0.0*MeV, 0.0*MeV, Charge,//para +G4String NOP1 = nop1; +G4String NOP2 = nop2; +G4String NOP3 = nop3; +G4ParticleDefinition* particle = new G4ParticleDefinition(NOP1, 0.0*MeV, 0.0*MeV, Charge,//para 2, -1, -1, 0, 0, 0, - "anyon", 0, 0, Encoding,//para + NOP2, 0, 0, Encoding,//para true, -1.0, NULL, - false, "anyon", Antiencoding//para + false, NOP3, Antiencoding//para ); G4ThreeVector aMomentumDirection(0,0,0); - G4double aKineticEnergy = kineticenergy1;//para + G4double aKineticEnergy = kineticenergy;//para G4DynamicParticle* dynamicPar = new G4DynamicParticle(particle, aMomentumDirection, aKineticEnergy); G4double aValueTime = 1; G4ThreeVector ValuePosition(1.0, 1.0, 1.0); G4Track* track = new G4Track(dynamicPar, aValueTime, ValuePosition); - G4double globalTime = globaltime1; + G4double globalTime = globaltime; track->SetGlobalTime(globalTime);//para int trackID = 3; track->SetTrackID(trackID); @@ -96,7 +103,7 @@ G4ParticleDefinition* particle = new G4ParticleDefinition("anyon", 0.0*M G4Box* box1 = new G4Box(boxName1, 1.0, 1.0, 1.0); G4NistManager* man1 = G4NistManager::Instance(); G4Material* material1 = man1->FindOrBuildMaterial("G4_AIR"); - G4String name2 = "name2"; + G4String name2 = logicalname1;//para G4LogicalVolume* fLogical1 = new G4LogicalVolume(box1, material1, name2); track->SetLogicalVolumeAtVertex(fLogical1); G4Step* stepForTrack = new G4Step(); @@ -120,6 +127,8 @@ G4ParticleDefinition* particle = new G4ParticleDefinition("anyon", 0.0*M G4MyProcess* process = new G4MyProcess( aString, aType );//para para track->SetCreatorProcess( process ); + track->SetTouchableHandle(touchableHandle); + sp.SetTrack(track); //end -- GitLab From c965037eea3d46ee47d3cabeb2d9f7fcf1f159f8 Mon Sep 17 00:00:00 2001 From: lihan <hanliangliang_1_2@163.com> Date: Tue, 8 Oct 2019 10:06:59 +0200 Subject: [PATCH 5/9] modify the common files --- .../SCT_G4_SD/test/SctSensorSD_gtest.cxx | 2 +- .../SCT_G4_SD/test/SctSensor_CTB_gtest.cxx | 2 +- ...icalVolume.h => DerivedG4PhysicalVolume.h} | 22 +++++++----- .../{G4MyProcess.h => DerivedG4Process.h} | 35 ++++++------------- .../DerivedG4SensitiveDetectorTestSetting.h | 13 ++++--- 5 files changed, 33 insertions(+), 41 deletions(-) rename Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/{G4MyPhysicalVolume.h => DerivedG4PhysicalVolume.h} (59%) rename Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/{G4MyProcess.h => DerivedG4Process.h} (66%) diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx index d4f08f983c2e..4f9b5ad99006 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx @@ -17,7 +17,7 @@ #include "G4Material.hh" #include "G4VPhysicalVolume.hh" -#include "G4AtlasTools/G4MyPhysicalVolume.h" +#include "G4AtlasTools/DerivedG4PhysicalVolume.h" #include "G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h" #include "MCTruth/TrackHelper.h" diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx index 5bd16a1da2f1..3a86293bb757 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx @@ -17,7 +17,7 @@ #include "G4Material.hh" #include "G4VPhysicalVolume.hh" -#include "G4AtlasTools/G4MyPhysicalVolume.h" +#include "G4AtlasTools/DerivedG4PhysicalVolume.h" #include "G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h" #include "MCTruth/TrackHelper.h" diff --git a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyPhysicalVolume.h b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4PhysicalVolume.h similarity index 59% rename from Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyPhysicalVolume.h rename to Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4PhysicalVolume.h index 37adc096b1c3..01f90ffa311e 100644 --- a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyPhysicalVolume.h +++ b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4PhysicalVolume.h @@ -1,3 +1,7 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + #ifndef G4MyPhysicalVolume_h #define G4MyPhysicalVolume_h @@ -19,21 +23,21 @@ public: ~G4MyPhysicalVolume() {} - G4int GetCopyNo() const + G4int GetCopyNo() const final { return copyNo; } - void SetCopyNo(G4int CopyNo) + void SetCopyNo(G4int CopyNo) final { copyNo = CopyNo; } - G4bool IsMany() const {return true;} - G4bool IsReplicated() const {return true;} - G4bool IsParameterised() const {return true;} - G4VPVParameterisation* GetParameterisation() const {return NULL;} - void GetReplicationData(EAxis& axis, G4int& nReplicas, G4double& width, G4double& offset, G4bool& consuming) const + G4bool IsMany() const final {return true;} + G4bool IsReplicated() const final {return true;} + G4bool IsParameterised() const final {return true;} + G4VPVParameterisation* GetParameterisation() const final {return nullptr;} + void GetReplicationData(EAxis& axis, G4int& nReplicas, G4double& width, G4double& offset, G4bool& consuming) const final { axis = (EAxis)1; nReplicas = 0; @@ -41,8 +45,8 @@ public: offset = 0.0; consuming = true; } - G4bool IsRegularStructure() const {return true;} - G4int GetRegularStructureId() const {return 0;} + G4bool IsRegularStructure() const final {return true;} + G4int GetRegularStructureId() const final {return 0;} G4int copyNo; diff --git a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyProcess.h b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4Process.h similarity index 66% rename from Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyProcess.h rename to Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4Process.h index 3e74ce58ca26..32a8947fdb47 100644 --- a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/G4MyProcess.h +++ b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4Process.h @@ -1,3 +1,7 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + #ifndef G4MyProcess_h #define G4MyProcess_h @@ -17,33 +21,24 @@ class G4MyProcess : public G4VProcess { G4VParticleChange* PostStepDoIt( const G4Track& track, const G4Step& stepData - ) + ) final { -// G4Track a = track; -// G4Step b = stepData; - return nullptr; } G4VParticleChange* AlongStepDoIt( const G4Track& track, const G4Step& stepData - ) + ) final { -// G4Track a = track; -// G4Step b = stepData; - return nullptr; } G4VParticleChange* AtRestDoIt( const G4Track& track, const G4Step& stepData - ) + ) final { -// G4Track a = track; -// G4Step b = stepData; - return nullptr; } @@ -52,23 +47,16 @@ class G4MyProcess : public G4VProcess { G4double previousStepSize, G4double currentMinimumStep, G4double& proposedSafety, - G4GPILSelection* selection) + G4GPILSelection* selection) final { -// G4Track a = track; -// G4double c = previousStepSize; -// G4double d = currentMinimumStep; -// G4double e = proposedSafety; -// G4GPILSelection* f = selection; return 0.0; } G4double AtRestGetPhysicalInteractionLength( const G4Track& track, G4ForceCondition* condition - ) + ) final { -// G4Track a = track; -// G4ForceCondition* b = condition; return 0.0; } @@ -76,11 +64,8 @@ class G4MyProcess : public G4VProcess { const G4Track& track, G4double previousStepSize, G4ForceCondition* condition - ) + ) final { -// G4Track a = track; -// G4double b = previousStepSize; -// G4ForceCondition* c = condition; return 0.0; } }; diff --git a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h index f2d4e8c45a72..5607cb1d0841 100644 --- a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h +++ b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h @@ -1,3 +1,7 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + #include "G4HCofThisEvent.hh" #include "G4Step.hh" #include "G4TouchableHistory.hh" @@ -12,12 +16,12 @@ #include "G4VPhysicalVolume.hh" #include "G4SystemOfUnits.hh" -#include "G4MyProcess.h" +#include "DerivedG4Process.h" void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydeposit, G4String& physicalname, G4String& logicalname1, G4int& copyno, G4ThreeVector& preStepPos, G4ThreeVector& postStepPos, G4double& globaltime0/*for preSP*/, G4double& kineticenergy0/*for preSP*/, G4double& velocity0/*for preSP*/, G4double& globaltime/*for track*/, G4double& kineticenergy/*for track*/, G4double& globaltime1/*for postSP*/, G4double& kineticenergy1/*for postSP*/, G4double& velocity1/*for postSP*/, G4double& steplength, G4double& charge, G4int& encoding, G4int& antiencoding, G4String& astring, G4ProcessType& atype, G4String& nop1, G4String& nop2, G4String& nop3) { //decorate sp with the variable called TotalEnergyDeposit - G4double TotalEnergyDeposit = totalenergydeposit;//para + G4double TotalEnergyDeposit = totalenergydeposit;//para(i.e. there is a parameter in this line) sp.SetTotalEnergyDeposit( TotalEnergyDeposit ); //end @@ -32,7 +36,7 @@ void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydepo G4String name = "logicalName"; G4LogicalVolume* fLogical = new G4LogicalVolume(box, material, name); G4String PhysicalName = physicalname;//para - G4VPhysicalVolume* pPhysical = NULL; + G4VPhysicalVolume* pPhysical = nullptr; G4MyPhysicalVolume* physicalVolume = new G4MyPhysicalVolume(0, G4ThreeVector(0,0,0), PhysicalName, fLogical, pPhysical); G4int CopyNo = copyno; physicalVolume->SetCopyNo(CopyNo);//para @@ -58,7 +62,6 @@ void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydepo //decorate sp with another G4StepPoint object G4StepPoint* stepPoint1 = new G4StepPoint(); -// G4ThreeVector postStepPos(0, 0, 2); stepPoint1->SetPosition(postStepPos);//para G4double GlobalTime1 = globaltime1; G4double KineticEnergy1 = kineticenergy1; @@ -86,7 +89,7 @@ G4ParticleDefinition* particle = new G4ParticleDefinition(NOP1, 0.0*MeV, 2, -1, -1, 0, 0, 0, NOP2, 0, 0, Encoding,//para - true, -1.0, NULL, + true, -1.0, nullptr, false, NOP3, Antiencoding//para ); G4ThreeVector aMomentumDirection(0,0,0); -- GitLab From 15329a8cc242f8bb58fea3b563e11760a9f49f76 Mon Sep 17 00:00:00 2001 From: lihan <hanliangliang_1_2@163.com> Date: Wed, 9 Oct 2019 02:58:56 +0200 Subject: [PATCH 6/9] add copyright and remove commented-out lines in jobOptions file --- InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt | 4 ---- InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx | 4 ++++ InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt b/InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt index a93c03599d88..9d326fe9edfd 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt +++ b/InnerDetector/InDetG4/SCT_G4_SD/share/optionForTest.txt @@ -1,7 +1,3 @@ ApplicationMgr.ExtSvc += { "StoreGateSvc/DetectorStore", "StoreGateSvc/HistoryStore" }; - -//FIXME uncomment to verify that your CLIDs are good! - -//ClassIDSvc.CLIDDBFiles += { "clid.db" }; AuditorSvc.Auditors += { "AlgContextAuditor"}; diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx index 4f9b5ad99006..236f07daff9d 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx @@ -1,3 +1,7 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + #include "src/SctSensorSD.h" #include "gtest/gtest.h" diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx index 3a86293bb757..25b93c76b91f 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx @@ -1,3 +1,7 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + #include "src/SctSensor_CTB.h" #include "gtest/gtest.h" -- GitLab From d68da8fa6b60ab03788268d97280cd3035bd2cc5 Mon Sep 17 00:00:00 2001 From: lihan <hanliangliang_1_2@163.com> Date: Wed, 9 Oct 2019 05:07:30 +0200 Subject: [PATCH 7/9] cleaning test code --- .../SCT_G4_SD/test/SctSensorSD_gtest.cxx | 64 +------------------ .../SCT_G4_SD/test/SctSensor_CTB_gtest.cxx | 63 +----------------- 2 files changed, 4 insertions(+), 123 deletions(-) diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx index 236f07daff9d..9169339918d1 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx @@ -26,23 +26,20 @@ #include "MCTruth/TrackHelper.h" //set environment -ISvcLocator* g_svcLoc = nullptr; class GaudiEnvironment : public ::testing::Environment { protected: virtual void SetUp() override { - Athena_test::initGaudi("SCT_G4_SD/optionForTest.txt", g_svcLoc); + Athena_test::initGaudi("SCT_G4_SD/optionForTest.txt", m_svcLoc); } + ISvcLocator* m_svcLoc = nullptr; }; class SctSensorSDtest : public ::testing::Test { protected: virtual void SetUp() override { -//... } virtual void TearDown() override { -//... } -//... }; //end of environment setting @@ -84,63 +81,6 @@ TEST_F( SctSensorSDtest, ProcessHits ) G4String nop3 = "photon"; DerivedG4SensitiveDetectorTestSetting(sp, totalenergydeposit, physicalname, logicalname, copyno, preStepPos, postStepPos, globaltime0, kineticenergy0, velocity0, globaltime, kineticenergy, globaltime1, kineticenergy1, velocity1, steplength, charge, encoding, antiencoding, astring, atype, nop1, nop2, nop3); -/* -//setting to make aStep->GetTotalEnergyDeposit() in class to be tested work - G4double TotalEnergyDeposit = 3.0; - sp.SetTotalEnergyDeposit( TotalEnergyDeposit ); -//end - -//setting for using aStep->GetPreStepPoint() - G4StepPoint* stepPoint = new G4StepPoint(); - G4ThreeVector preStepPos(0, 0, 1); - stepPoint->SetPosition(preStepPos); - G4NavigationHistory* navigationHistory = new G4NavigationHistory(); - G4String boxName = "name"; - G4Box* box = new G4Box(boxName, 1.0, 1.0, 1.0); - G4NistManager* man = G4NistManager::Instance(); - G4Material* material = man->FindOrBuildMaterial("G4_AIR"); - G4String name = "logicalName"; - G4LogicalVolume fLogical(box, material, name); - G4String name1 = "physicalName"; - G4VPhysicalVolume* pPhysical = NULL; - G4MyPhysicalVolume physicalVolume(0, G4ThreeVector(0,0,0), name1, &fLogical, pPhysical); - physicalVolume.SetCopyNo(1000); - G4int nReplica = 2; - navigationHistory->SetFirstEntry(&physicalVolume); - navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); - navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); - navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); - navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); - navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); - G4TouchableHistory* touchableHistory = new G4TouchableHistory(*navigationHistory); -// G4TouchableHistory touchableHistory(*navigationHistory); - G4TouchableHandle touchableHandle(touchableHistory); - stepPoint->SetTouchableHandle(touchableHandle); - stepPoint->SetGlobalTime(0.5); - - sp.SetPreStepPoint(stepPoint); -//end - -//decorate aStep with another G4StepPoint object - G4StepPoint* stepPoint1 = new G4StepPoint(); - G4ThreeVector postStepPos(0, 0, 2); - stepPoint1->SetPosition(postStepPos); - - sp.SetPostStepPoint(stepPoint1); -//end - -//decorate aStep with G4Track - G4DynamicParticle* dynamicPar = new G4DynamicParticle(); - G4double aValueTime = 1; - G4ThreeVector ValuePosition(1.0, 1.0, 1.0); - G4Track track(dynamicPar, aValueTime, ValuePosition); - G4double globalTime = 5.0; - track.SetGlobalTime(globalTime); - - sp.SetTrack(&track); -//end -*/ - SctSensorSD sd2("name2", "name2"); sd2.Initialize( &hce ); sd2.ProcessHits(&sp, &th ); diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx index 25b93c76b91f..7f8576a0cc75 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx @@ -26,23 +26,20 @@ #include "MCTruth/TrackHelper.h" //set environment -ISvcLocator* g_svcLoc = nullptr; class GaudiEnvironment : public ::testing::Environment { protected: virtual void SetUp() override { - Athena_test::initGaudi("SCT_G4_SD/optionForTest.txt", g_svcLoc); + Athena_test::initGaudi("SCT_G4_SD/optionForTest.txt", m_svcLoc); } + ISvcLocator* m_svcLoc = nullptr; }; class SctSensor_CTBtest : public ::testing::Test { protected: virtual void SetUp() override { -//... } virtual void TearDown() override { -//... } -//... }; //end of environment setting @@ -85,62 +82,6 @@ TEST_F( SctSensor_CTBtest, ProcessHits ) G4String nop3 = "photon"; DerivedG4SensitiveDetectorTestSetting(sp, totalenergydeposit, physicalname, logicalname, copyno, preStepPos, postStepPos, globaltime0, kineticenergy0, velocity0, globaltime, kineticenergy, globaltime1, kineticenergy1, velocity1, steplength, charge, encoding, antiencoding, astring, atype, nop1, nop2, nop3); -/* -// decorate G4Step object with TotalEnergyDeposit - G4double TotalEnergyDeposit = 3.0; - sp.SetTotalEnergyDeposit( TotalEnergyDeposit ); -//end - -// decorate G4Stetp object with a G4StepPoint object - G4StepPoint* stepPoint = new G4StepPoint(); - G4ThreeVector preStepPos(0, 0, 1); - stepPoint->SetPosition(preStepPos); - G4NavigationHistory* navigationHistory = new G4NavigationHistory(); - G4String boxName = "name"; - G4Box* box = new G4Box(boxName, 1.0, 1.0, 1.0); - G4NistManager* man = G4NistManager::Instance(); - G4Material* material = man->FindOrBuildMaterial("G4_AIR"); - G4String name = "logicalName"; - G4LogicalVolume fLogical(box, material, name); - G4String name1 = "physicalName"; - G4VPhysicalVolume* pPhysical = NULL; - G4MyPhysicalVolume physicalVolume(0, G4ThreeVector(0,0,0), name1, &fLogical, pPhysical); - physicalVolume.SetCopyNo(1000); - G4int nReplica = 2; - navigationHistory->SetFirstEntry(&physicalVolume); - navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); - navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); - navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); - navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); - navigationHistory->NewLevel(&physicalVolume, kNormal, nReplica); - G4TouchableHistory* touchableHistory = new G4TouchableHistory(*navigationHistory); - G4TouchableHandle touchableHandle(touchableHistory); - stepPoint->SetTouchableHandle(touchableHandle); - stepPoint->SetGlobalTime(0.5); - - sp.SetPreStepPoint(stepPoint); -// end - -//decorate G4Step object with another G4StepPoint object - G4StepPoint* stepPoint1 = new G4StepPoint(); - G4ThreeVector postStepPos(0, 0, 2); - stepPoint1->SetPosition(postStepPos); - - sp.SetPostStepPoint(stepPoint1); -//end - -//decorate G4Step object with a G4Track object - G4DynamicParticle* dynamicPar = new G4DynamicParticle(); - G4double aValueTime = 1; - G4ThreeVector ValuePosition(1.0, 1.0, 1.0); - G4Track track(dynamicPar, aValueTime, ValuePosition); - G4double globalTime = 5.0; - track.SetGlobalTime(globalTime); - - sp.SetTrack(&track); -//end -*/ - SctSensor_CTB sd2("name2", "name2"); sd2.Initialize( &hce ); sd2.ProcessHits(&sp, &th ); -- GitLab From 275bdf68fb9c425ede8a4ec3862042f718f80dce Mon Sep 17 00:00:00 2001 From: lihan <hanliangliang_1_2@163.com> Date: Wed, 9 Oct 2019 13:46:02 +0200 Subject: [PATCH 8/9] comment ASSERT statements --- .../InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx | 10 +++++----- .../InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx index 9169339918d1..41fe752ec2ae 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensorSD_gtest.cxx @@ -97,14 +97,14 @@ TEST_F( SctSensorSDtest, ProcessHits ) HepMcParticleLink plink(barcode); SiHitCollection* a = sd2.m_HitColl.ptr(); - ASSERT_EQ(a->begin()->localStartPosition(), P1); + ASSERT_EQ(a->begin()->localStartPosition(), P1); //test if the localStartPosition value of the Hit generated by this member function is right, the same below ASSERT_EQ(a->begin()->localEndPosition(), P2); ASSERT_EQ(a->begin()->energyLoss(), 3.0); ASSERT_EQ(a->begin()->meanTime(), 0.5); ASSERT_EQ(a->begin()->particleLink(), plink); ASSERT_EQ(a->begin()->identify(),4101273733); - ASSERT_EQ(a->size(), 1); + ASSERT_EQ(a->size(), 1); //test the current size of the Hit container } TEST_F( SctSensorSDtest, indexMethod ) @@ -144,7 +144,7 @@ TEST_F( SctSensorSDtest, indexMethod ) sd3.Initialize( &hce ); sd3.indexMethod(&th, coord1z, brlEcap, layerDisk, etaMod, phiMod, side ); - ASSERT_EQ(brlEcap, 0); + ASSERT_EQ(brlEcap, 0); //test the value of brlEcap changed by the member function indexMethod, it should be 0 in this case. The same below ASSERT_EQ(layerDisk, 1000); ASSERT_EQ(etaMod, 1000); ASSERT_EQ(phiMod, 1000); @@ -190,13 +190,13 @@ TEST_F( SctSensorSDtest, AddHit ) HepMcParticleLink plink(barcode); SiHitCollection* a = sd4.m_HitColl.ptr(); - ASSERT_EQ(a->begin()->localStartPosition(), P1); + ASSERT_EQ(a->begin()->localStartPosition(), P1); //test the localStartPosition value of the Hit generated by the member function AddHit, the same below ASSERT_EQ(a->begin()->localEndPosition(), P2); ASSERT_EQ(a->begin()->energyLoss(), 2.0); ASSERT_EQ(a->begin()->meanTime(), 1.0); ASSERT_EQ(a->begin()->particleLink(), plink); ASSERT_EQ(a->begin()->identify(), 10245); - ASSERT_EQ(a->size(), 1); + ASSERT_EQ(a->size(), 1); //test the current size of the Hit container } diff --git a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx index 7f8576a0cc75..c025887a6793 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx +++ b/InnerDetector/InDetG4/SCT_G4_SD/test/SctSensor_CTB_gtest.cxx @@ -98,19 +98,19 @@ TEST_F( SctSensor_CTBtest, ProcessHits ) HepMcParticleLink plink(barcode); SiHitCollection* a = sd2.m_HitColl.ptr(); - ASSERT_EQ(a->begin()->localStartPosition(), P1); + ASSERT_EQ(a->begin()->localStartPosition(), P1); //test the localStartPosition value of the Hit generated by the member function ProcessHits, and it should be P1 according to my setting, the same below ASSERT_EQ(a->begin()->localEndPosition(), P2); ASSERT_EQ(a->begin()->energyLoss(), 3.0); ASSERT_EQ(a->begin()->meanTime(), 0.5); ASSERT_EQ(a->begin()->particleLink(), plink); ASSERT_EQ(a->begin()->identify(),4093651781); - ASSERT_EQ(a->size(), 1); + ASSERT_EQ(a->size(), 1); //test the size of the Hit container, it should be 1 since just 1 Hit was stored in it } TEST_F( SctSensor_CTBtest, AddHit ) { - HepGeom::Point3D<double> lP1,lP2; + HepGeom::Point3D<double> lP1,lP2; lP1[SiHit::xEta] = 1; lP1[SiHit::xPhi] = 0; lP1[SiHit::xDep] = 0; @@ -146,13 +146,13 @@ TEST_F( SctSensor_CTBtest, AddHit ) HepMcParticleLink plink(barcode); SiHitCollection* a = sd4.m_HitColl.ptr(); - ASSERT_EQ(a->begin()->localStartPosition(), P1); + ASSERT_EQ(a->begin()->localStartPosition(), P1); //test the localStartPosition value of the Hit added by the member function AddHit, and it should be P1 based on the setting, the same below ASSERT_EQ(a->begin()->localEndPosition(), P2); ASSERT_EQ(a->begin()->energyLoss(), 2.0); ASSERT_EQ(a->begin()->meanTime(), 1.0); ASSERT_EQ(a->begin()->particleLink(), plink); ASSERT_EQ(a->begin()->identify(), 10245); - ASSERT_EQ(a->size(), 1); + ASSERT_EQ(a->size(), 1); //test the current size of the Hit container } -- GitLab From 706d73fb84f81ace0d5ad9fc4643704ee5ef1a2a Mon Sep 17 00:00:00 2001 From: lihan <hanliangliang_1_2@163.com> Date: Sat, 9 Nov 2019 05:52:54 +0100 Subject: [PATCH 9/9] change PUBLIC_HEADERS to NO_PUBLIC_Pand ready to merge --- .../InDetG4/SCT_G4_SD/CMakeLists.txt | 2 +- .../G4AtlasTools/DerivedG4PhysicalVolume.h | 32 +++++++++++-------- .../DerivedG4SensitiveDetectorTestSetting.h | 17 ++++++---- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt b/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt index 18346cd064af..14e37b3e37f4 100644 --- a/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt +++ b/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt @@ -31,7 +31,7 @@ atlas_add_component( SCT_G4_SD atlas_add_library( SCT_G4_SDLib src/*.cxx - PUBLIC_HEADERS SCT_G4_SD + NO_PUBLIC_HEADERS SCT_G4_SD INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS} LINK_LIBRARIES ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} ${GMOCK_LIBRARIES} CxxUtils StoreGateLib SGtests GaudiKernel InDetSimEvent G4AtlasToolsLib MCTruth ) diff --git a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4PhysicalVolume.h b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4PhysicalVolume.h index 01f90ffa311e..5d39ffb33374 100644 --- a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4PhysicalVolume.h +++ b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4PhysicalVolume.h @@ -33,20 +33,26 @@ public: copyNo = CopyNo; } - G4bool IsMany() const final {return true;} - G4bool IsReplicated() const final {return true;} - G4bool IsParameterised() const final {return true;} - G4VPVParameterisation* GetParameterisation() const final {return nullptr;} + G4bool IsMany() const final { return true; } + + G4bool IsReplicated() const final { return true; } + + G4bool IsParameterised() const final { return true; } + + G4VPVParameterisation* GetParameterisation() const final { return nullptr; } + void GetReplicationData(EAxis& axis, G4int& nReplicas, G4double& width, G4double& offset, G4bool& consuming) const final -{ - axis = (EAxis)1; - nReplicas = 0; - width = 0.0; - offset = 0.0; - consuming = true; -} - G4bool IsRegularStructure() const final {return true;} - G4int GetRegularStructureId() const final {return 0;} + { + axis = (EAxis)1; + nReplicas = 0; + width = 0.0; + offset = 0.0; + consuming = true; + } + + G4bool IsRegularStructure() const final { return true; } + + G4int GetRegularStructureId() const final { return 0; } G4int copyNo; diff --git a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h index 5607cb1d0841..af3dbc39dca8 100644 --- a/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h +++ b/Simulation/G4Atlas/G4AtlasTools/G4AtlasTools/DerivedG4SensitiveDetectorTestSetting.h @@ -18,6 +18,9 @@ #include "DerivedG4Process.h" +//In this function, the reasons why I use 'new' to define objects instead of using smart pointers are as follows: +// 1. this function aims to set environment for test code, which means the objects that were defined in the function should exist throughout the whole code running. Therefore, defining the objects with 'new' can meet the requirement. If I define them with smart pointer, they will be destruct once they are out of scope. +// 2. this function will only be used in the unit test code for testing the sensitive detector classes based on G4VSensitiveDetector. So it will never be responsible for memory leaks in production jobs. void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydeposit, G4String& physicalname, G4String& logicalname1, G4int& copyno, G4ThreeVector& preStepPos, G4ThreeVector& postStepPos, G4double& globaltime0/*for preSP*/, G4double& kineticenergy0/*for preSP*/, G4double& velocity0/*for preSP*/, G4double& globaltime/*for track*/, G4double& kineticenergy/*for track*/, G4double& globaltime1/*for postSP*/, G4double& kineticenergy1/*for postSP*/, G4double& velocity1/*for postSP*/, G4double& steplength, G4double& charge, G4int& encoding, G4int& antiencoding, G4String& astring, G4ProcessType& atype, G4String& nop1, G4String& nop2, G4String& nop3) { //decorate sp with the variable called TotalEnergyDeposit @@ -79,13 +82,13 @@ void DerivedG4SensitiveDetectorTestSetting(G4Step& sp, G4double& totalenergydepo //end //decorate sp with a G4Track object -G4double Charge = charge; -G4int Encoding = encoding; -G4int Antiencoding = antiencoding; -G4String NOP1 = nop1; -G4String NOP2 = nop2; -G4String NOP3 = nop3; -G4ParticleDefinition* particle = new G4ParticleDefinition(NOP1, 0.0*MeV, 0.0*MeV, Charge,//para + G4double Charge = charge; + G4int Encoding = encoding; + G4int Antiencoding = antiencoding; + G4String NOP1 = nop1; + G4String NOP2 = nop2; + G4String NOP3 = nop3; + G4ParticleDefinition* particle = new G4ParticleDefinition(NOP1, 0.0*MeV, 0.0*MeV, Charge,//para 2, -1, -1, 0, 0, 0, NOP2, 0, 0, Encoding,//para -- GitLab