1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // FredHit.hh |
---|
28 | // |
---|
29 | // Definition of FredHit: intersection of a track with a test volume |
---|
30 | // |
---|
31 | |
---|
32 | #ifndef FredHit_HH |
---|
33 | #define FredHit_HH |
---|
34 | |
---|
35 | // |
---|
36 | // Geez... this stuff would be very hard without examples... |
---|
37 | // |
---|
38 | #include "G4VHit.hh" |
---|
39 | #include "G4THitsCollection.hh" |
---|
40 | #include "G4Allocator.hh" |
---|
41 | #include "G4ThreeVector.hh" |
---|
42 | #include "G4Color.hh" |
---|
43 | #include "G4VisAttributes.hh" |
---|
44 | |
---|
45 | class G4Track; |
---|
46 | |
---|
47 | class FredHit : public G4VHit |
---|
48 | { |
---|
49 | public: |
---|
50 | FredHit() {;} |
---|
51 | ~FredHit() {;} |
---|
52 | FredHit( const G4ThreeVector pos, G4bool enters, const G4Track *track ); |
---|
53 | |
---|
54 | // |
---|
55 | // Tsk Tsk. c++ is such hell. |
---|
56 | // Define copy and comparison. Note that hits are never equal. |
---|
57 | FredHit( const FredHit &right ); |
---|
58 | const FredHit& operator=( const FredHit &right ); |
---|
59 | int operator==(const FredHit &) const { return 0; } |
---|
60 | |
---|
61 | // |
---|
62 | // See below. We use G4's special paging allocator |
---|
63 | inline void * operator new(size_t); |
---|
64 | inline void operator delete( void *hit ); |
---|
65 | |
---|
66 | // |
---|
67 | // These G4VHit virtual functions must be overridden, otherwise |
---|
68 | // c++ gets upset. We wouldn't want that. |
---|
69 | void Draw(); |
---|
70 | void Print(); |
---|
71 | |
---|
72 | // |
---|
73 | // Special draw modes |
---|
74 | void DrawShadowHit(); |
---|
75 | void DrawErrorHit(); |
---|
76 | void DrawMaskHit(); |
---|
77 | |
---|
78 | // |
---|
79 | // As tempting as it is, we should keep data structures private, |
---|
80 | // and write public routines to access them. Otherwise, |
---|
81 | // flexibility suffers. |
---|
82 | private: |
---|
83 | G4ThreeVector pos; |
---|
84 | G4bool enters; |
---|
85 | const G4Track *track; |
---|
86 | |
---|
87 | // Draw primitive |
---|
88 | void DrawPrim(G4int imode); |
---|
89 | |
---|
90 | public: |
---|
91 | void SetPos( const G4ThreeVector newPos ) { pos = newPos; } |
---|
92 | void SetEnters( G4bool newEnters ) { enters = newEnters; } |
---|
93 | void SetTrack( const G4Track *newTrack ) { track = newTrack; } |
---|
94 | |
---|
95 | G4ThreeVector GetPos() const { return pos; } |
---|
96 | G4bool GetEnters() const { return enters; } |
---|
97 | const G4Track *GetTrack() const { return track; } |
---|
98 | }; |
---|
99 | |
---|
100 | // |
---|
101 | // G4 likes to play with "collections" of hits, in a standard manner. |
---|
102 | // The supplied template class allows us to build this standard collection. |
---|
103 | // Not that I would *dare* challenge G4's designers, but couldn't they |
---|
104 | // have defined a hit collection as a collection of the G4VHit base |
---|
105 | // class?? |
---|
106 | typedef G4THitsCollection<FredHit> FredHitCollection; |
---|
107 | |
---|
108 | // |
---|
109 | // G4 has it's own paging allocator. Good idea for a program of this |
---|
110 | // complexity. It also allows all FredHit instances to be erased with |
---|
111 | // one line of code. Kinda dangerous. |
---|
112 | // |
---|
113 | // Normally you'd put these inline codes inside the class declaration, |
---|
114 | // but we can hardly do that, since we need to specify the allocator |
---|
115 | // template. But, was "inline" really necessary? |
---|
116 | extern G4Allocator<FredHit> FredHitAllocator; |
---|
117 | |
---|
118 | inline void *FredHit::operator new(size_t) |
---|
119 | { |
---|
120 | void *hit = (void *)FredHitAllocator.MallocSingle(); |
---|
121 | return hit; |
---|
122 | } |
---|
123 | |
---|
124 | inline void FredHit::operator delete( void *hit ) |
---|
125 | { |
---|
126 | FredHitAllocator.FreeSingle( (FredHit *)hit ); |
---|
127 | } |
---|
128 | |
---|
129 | #endif |
---|