12.07.2015 Views

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Detector Definition and ResponseExample 4.14. An example of a concrete hit class.#ifndef ExN04TrackerHit_h#define ExN04TrackerHit_h 1#include "G4VHit.hh"#include "G4THitsCollection.hh"#include "G4Allocator.hh"#include "G4ThreeVector.hh"class ExN04TrackerHit : public G4VHit{public:};ExN04TrackerHit();~ExN04TrackerHit();ExN04TrackerHit(const ExN04TrackerHit &right);const ExN04TrackerHit& operator=(const ExN04TrackerHit &right);int operator==(const ExN04TrackerHit &right) const;inline void * operator new(size_t);inline void operator delete(void *aHit);void Draw() const;void Print() const;private:G4double edep;G4ThreeVector pos;public:inline void SetEdep(G4double de){ edep = de; }inline G4double GetEdep() const{ return edep; }inline void SetPos(G4ThreeVector xyz){ pos = xyz; }inline G4ThreeVector GetPos() const{ return pos; }typedef G4THitsCollection ExN04TrackerHitsCollection;extern G4Allocator ExN04TrackerHitAllocator;inline void* ExN04TrackerHit::operator new(size_t){void *aHit;aHit = (void *) ExN04TrackerHitAllocator.MallocSingle();return aHit;}inline void ExN04TrackerHit::operator delete(void *aHit){ExN04TrackerHitAllocator.FreeSingle((ExN04TrackerHit*) aHit);}#endifG4Allocator is a class <strong>for</strong> fast allocation of objects to the heap through the paging mechanism. For details ofG4Allocator, refer to Section 3.2.4. Use of G4Allocator is not mandatory, but it is recommended, especially <strong>for</strong>users who are not familiar with the C++ memory allocation mechanism or alternative tools of memory allocation.On the other hand, note that G4Allocator is to be used only <strong>for</strong> the concrete class that is not used as a base classof any other classes. For example, do not use the G4Trajectory class as a base class <strong>for</strong> a customized trajectoryclass, since G4Trajectory uses G4Allocator.G4THitsMapG4THitsMap is an alternative to G4THitsCollection. G4THitsMap does not demand G4VHit, but instead anyvariable which can be mapped with an integer key. Typically the key is a copy number of the volume, and themapped value could <strong>for</strong> example be a double, such as the energy deposition in a volume. G4THitsMap is conve-126

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!