Difference: Geant4Tutorial (1 vs. 6)

Revision 62015-07-09 - JohnIdarraga

Line: 1 to 1
 
META TOPICPARENT name="JohnIdarraga"
Line: 29 to 29
 
target_link_libraries(exampleXX ${Geant4_LIBRARIES} ${ROOT_LIBRARIES})
Added:
>
>
If you are using a library needing C++0x (like ROOT6) you need to add this

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
 

Cmake line

Revision 52014-11-06 - JohnIdarraga

Line: 1 to 1
 
META TOPICPARENT name="JohnIdarraga"
Line: 222 to 222
 
META FILEATTACHMENT attachment="FindROOT.cmake" attr="" comment="" date="1385677271" name="FindROOT.cmake" path="FindROOT.cmake" size="9602" user="idarraga" version="1"
META FILEATTACHMENT attachment="CMakeLists.txt" attr="" comment="" date="1385677271" name="CMakeLists.txt" path="CMakeLists.txt" size="2661" user="idarraga" version="1"
Added:
>
>
META FILEATTACHMENT attachment="vis_gps.mac" attr="" comment="OpenInventor visualization" date="1415267696" name="vis_gps.mac" path="vis_gps.mac" size="1690" user="idarraga" version="1"
META FILEATTACHMENT attachment="vis_pgun.mac" attr="" comment="" date="1415271222" name="vis_pgun.mac" path="vis_pgun.mac" size="1317" user="idarraga" version="1"

Revision 42014-11-05 - JohnIdarraga

Line: 1 to 1
 
META TOPICPARENT name="JohnIdarraga"
Line: 6 to 6
  http://physics.nist.gov/PhysRefData/Star/Text/PSTAR.html
Added:
>
>

ROOT integration using cmake

Download the file FindROOT.cmake file available at the bottom of this page (wget it for instance). In the CMakeLists.txt! file related to a particular project include these lines right after the project name

include(FindROOT.cmake)

set(INCLUDE_DIRECTORIES
   ${ROOT_INCLUDE_DIR} 
)
include_directories( ${INCLUDE_DIRECTORIES})

set(LINK_DIRECTORIES
   ${ROOT_LIBRARY_DIR}
)
link_directories( ${LINK_DIRECTORIES} )

Then change the following line (a few lines down). Include the ${ROOT_LIBRARIES} part

target_link_libraries(exampleXX ${Geant4_LIBRARIES} ${ROOT_LIBRARIES})
 

Cmake line

Changed:
<
<
$ cmake -DGeant4_DIR=/media/simulation/geant4.9.6-install/lib/Geant4-9.6.2/ -DCMAKE_BUILD_TYPE=Debug ../N0X
>
>
$cmake -G"Eclipse CDT4 - Unix Makefiles" -DGeant4_DIR=/media/geant4/sw/geant4.10.00.p02-install/lib/Geant4-10.0.2/ ../B2
 

Save Hits data

Revision 22013-11-28 - JohnIdarraga

Line: 1 to 1
 
META TOPICPARENT name="JohnIdarraga"
Line: 189 to 189
 

-- JohnIdarraga - 28 Nov 2013

Added:
>
>

META FILEATTACHMENT attachment="FindROOT.cmake" attr="" comment="" date="1385677271" name="FindROOT.cmake" path="FindROOT.cmake" size="9602" user="idarraga" version="1"
META FILEATTACHMENT attachment="CMakeLists.txt" attr="" comment="" date="1385677271" name="CMakeLists.txt" path="CMakeLists.txt" size="2661" user="idarraga" version="1"

Revision 12013-11-28 - JohnIdarraga

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="JohnIdarraga"

Cmake line

$ cmake -DGeant4_DIR=/media/simulation/geant4.9.6-install/lib/Geant4-9.6.2/ -DCMAKE_BUILD_TYPE=Debug ../N0X

Save Hits data

We will do it by creating a ROOT file. In the ROOT file we will store a n-tuple using a TTree object. A suitable place is the ExN02TrackerSD.

ExN02TrackerSD.hh

<!-- SyntaxHighlightingPlugin -->
    1class ExN02TrackerSD : public G4VSensitiveDetector {
    2
    3  public:
    4      ExN02TrackerSD(G4String);
    5     ~ExN02TrackerSD();
    6
    7      void Initialize(G4HCofThisEvent*);
    8      G4bool ProcessHits(G4Step*, G4TouchableHistory*);
    9      void EndOfEvent(G4HCofThisEvent*);
   10
   11  private:
   12      ExN02TrackerHitsCollection* trackerCollection;
   13
   14      // ROOT
   15      TFile * m_HitsFile;
   16      TTree * m_HitsTree;
   17
   18      G4double m_edep;
   19      vector<G4int> m_trackId;
   20
   21};
<!-- end SyntaxHighlightingPlugin -->

ExN02TrackerSD.cc

<!-- SyntaxHighlightingPlugin -->
    1ExN02TrackerSD::ExN02TrackerSD(G4String name)
    2:G4VSensitiveDetector(name)
    3{
    4
    5  G4String HCname = "hitsCollection";
    6  collectionName.insert(HCname);
    7
    8  // ROOT
    9  m_HitsFile = new TFile("hitsOutput.root", "RECREATE");
   10  m_HitsTree = new TTree("T","Hits Tree");
   11
   12  m_HitsTree->Branch("edep", &m_edep, "edep/D");
   13  m_HitsTree->Branch("trackId", &m_trackId);
   14
   15  m_edep = 0.;
   16  m_trackId.clear();
   17
   18}
<!-- end SyntaxHighlightingPlugin -->

<!-- SyntaxHighlightingPlugin -->
    1ExN02TrackerSD::~ExN02TrackerSD(){
    2
    3	m_HitsFile->cd();
    4	m_HitsTree->Write();
    5	m_HitsFile->Close();
    6
    7}
<!-- end SyntaxHighlightingPlugin -->

<!-- SyntaxHighlightingPlugin -->
    1G4bool ExN02TrackerSD::ProcessHits(G4Step* aStep,G4TouchableHistory*)
    2{
    3  G4double edep = aStep->GetTotalEnergyDeposit();
    4
    5  if(edep==0.) return false;
    6
    7  ExN02TrackerHit* newHit = new ExN02TrackerHit();
    8  newHit->SetTrackID  (aStep->GetTrack()->GetTrackID());
    9  newHit->SetChamberNb(aStep->GetPreStepPoint()->GetTouchableHandle()
   10                                               ->GetCopyNumber());
   11  newHit->SetEdep     (edep);
   12  newHit->SetPos      (aStep->GetPostStepPoint()->GetPosition());
   13  trackerCollection->insert( newHit );
   14  
   15  newHit->Print();
   16  //newHit->Draw();
   17
   18  // Send to ntuple
   19  m_edep += edep/keV;
   20  m_trackId.push_back( aStep->GetTrack()->GetTrackID() );
   21
   22  return true;
   23}
<!-- end SyntaxHighlightingPlugin -->

<!-- SyntaxHighlightingPlugin -->
    1void ExN02TrackerSD::EndOfEvent(G4HCofThisEvent*)
    2{
    3  if (verboseLevel>0) {
    4     G4int NbHits = trackerCollection->entries();
    5     G4cout << "\n-------->Hits Collection: in this event they are " << NbHits 
    6            << " hits in the tracker chambers: " << G4endl;
    7     for (G4int i=0;i<NbHits;i++) (*trackerCollection)[i]->Print();
    8  }
    9
   10  // Fill the Tree
   11  m_HitsFile->cd();
   12  m_HitsTree->Fill();
   13  // Clean up
   14  m_edep = 0.;
   15  m_trackId.clear();
   16
   17}
<!-- end SyntaxHighlightingPlugin -->

New materials. G4NistManager and G4Material.

<!-- SyntaxHighlightingPlugin -->
    1// NIST
    2	G4NistManager * nistman = G4NistManager::Instance();
    3	// Si
    4	G4Material * Silicon = nistman->FindOrBuildMaterial("G4_Si");
    5
    6	// Vacuum
    7	G4double atomicNumber = 1.;
    8	G4double massOfMole = 1.008*g/mole;
    9	G4double density_v = 1.e-25*g/cm3;
   10	G4double temperature_v = 2.73*kelvin;
   11	G4double pressure_v = 3.e-18*pascal;
   12	G4Material * vacuum = new G4Material("interGalactic", atomicNumber,
   13			massOfMole, density_v, kStateGas,
   14			temperature_v, pressure_v);
<!-- end SyntaxHighlightingPlugin -->

Digitization

Digitizer.h

<!-- SyntaxHighlightingPlugin -->
    1
<!-- end SyntaxHighlightingPlugin -->

Digitizer.cc

<!-- SyntaxHighlightingPlugin -->
    1
<!-- end SyntaxHighlightingPlugin -->

Digit.h

<!-- SyntaxHighlightingPlugin -->
    1
<!-- end SyntaxHighlightingPlugin -->

Digit.cc

<!-- SyntaxHighlightingPlugin -->
    1
<!-- end SyntaxHighlightingPlugin -->

-- JohnIdarraga - 28 Nov 2013

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback