1 |
pamelats |
1.1 |
#ifndef PAMVMC_DETECTOR_SD_H |
2 |
|
|
#define PAMVMC_DETECTOR_SD_H |
3 |
|
|
#include <iostream> |
4 |
|
|
#include <TClonesArray.h> |
5 |
|
|
#include <TObject.h> |
6 |
|
|
#include <TString.h> |
7 |
|
|
#include <TObjString.h> |
8 |
|
|
#include <TMap.h> |
9 |
|
|
#include <TROOT.h> |
10 |
|
|
#include "PamVMCDetectorHit.h" |
11 |
|
|
#include "PamVMCGeoIDMgr.h" |
12 |
|
|
#include "PamRootManager.h" |
13 |
|
|
#include "PamVMCStack.h" |
14 |
|
|
#include <TParticle.h> |
15 |
|
|
//#include <TG4G3Units.h> |
16 |
|
|
|
17 |
|
|
enum fin{INSIDE,ENTERING,EXITING}; |
18 |
|
|
|
19 |
|
|
class PamVMCDetectorSD : public TObject { |
20 |
|
|
|
21 |
|
|
//private: |
22 |
|
|
|
23 |
|
|
//PamVMCDetectorHit fhit; |
24 |
|
|
|
25 |
|
|
protected: |
26 |
|
|
|
27 |
|
|
TString fcname; |
28 |
|
|
TString fdname; |
29 |
|
|
Int_t fnohit; |
30 |
|
|
fin ffi; |
31 |
|
|
TClonesArray *fHitColl; |
32 |
|
|
TMap fdmap; |
33 |
|
|
PamVMCGeoID *fdetID; |
34 |
|
|
PamVMCDetectorHit fhit; |
35 |
|
|
|
36 |
|
|
public: |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
PamVMCDetectorSD( |
40 |
|
|
const char *cname="pHitData", |
41 |
|
|
char *dname="", |
42 |
|
|
Int_t is=0): |
43 |
|
|
fcname(cname), fdname(dname), fnohit(0), fdetID(0) |
44 |
|
|
{ |
45 |
|
|
if(is) { |
46 |
|
|
fHitColl=new TClonesArray(fcname.Data(),is); |
47 |
|
|
} else { |
48 |
|
|
fHitColl=new TClonesArray(fcname.Data()); |
49 |
|
|
} |
50 |
|
|
AddGeoID(dname); |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
virtual ~PamVMCDetectorSD() { delete fHitColl; delete fdetID;} |
55 |
|
|
|
56 |
|
|
virtual void PamVMCDetectorSD::Register(){ |
57 |
|
|
|
58 |
|
|
PamRootManager::Instance()-> |
59 |
|
|
Register(fdname.Data(),"TClonesArray", &fHitColl); |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
TString a=fHitColl?"exist":"not exist"; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
void AddGeoID(const char * dname){ |
66 |
|
|
TString temp=dname; |
67 |
|
|
fdetID=new PamVMCGeoID(dname); |
68 |
|
|
fdmap.Add(new TObjString(temp), fdetID); |
69 |
|
|
cout <<" Inside AddGeoID "<<fdname.Data() << endl; |
70 |
|
|
fdmap.Print(); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
virtual void CleanHit(){ fhit.CleanHit();} |
74 |
|
|
|
75 |
|
|
virtual void InitHit() { |
76 |
|
|
if(fdetID) { |
77 |
|
|
fhit.SetPOS( fdetID->GetID( )) ; |
78 |
|
|
} else { fhit.SetPOS(-1); } |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
virtual void UpdateHit(TVirtualMC *g){ fhit.FillHit(g); } |
82 |
|
|
|
83 |
|
|
virtual void SaveHit(){ |
84 |
|
|
pHitData * t=CreateHit(); |
85 |
|
|
*t=*fhit.GetHit(); |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
virtual void SaveHit(Int_t f){ |
89 |
|
|
pHitData * t=CreateHit(f); |
90 |
|
|
*t+=*(fhit.GetHit()); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
virtual void SaveHit(const char * dname){ |
94 |
|
|
pHitData * t=CreateHit(dname); |
95 |
|
|
*t=*fhit.GetHit(); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
virtual pHitData * CreateHit() |
99 |
|
|
{ |
100 |
|
|
pHitData *hit= (pHitData *) fHitColl->New(fnohit++); |
101 |
|
|
InitHit(); |
102 |
|
|
return hit; |
103 |
|
|
} |
104 |
|
|
virtual void FillVolID(){ |
105 |
|
|
fdetID->FillVolID(); |
106 |
|
|
fhit.SetPOS( fdetID->GetID( )) ; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
virtual pHitData * CreateHit(const char * dname) |
110 |
|
|
{ |
111 |
|
|
fdetID=(PamVMCGeoID*)fdmap(dname); |
112 |
|
|
return CreateHit(); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
virtual pHitData * CreateHit(Int_t flag) { |
116 |
|
|
if(!fHitColl->At(flag)) { |
117 |
|
|
pHitData *hit= (pHitData *) fHitColl->New(flag); |
118 |
|
|
InitHit(); |
119 |
|
|
return hit; |
120 |
|
|
} |
121 |
|
|
return (pHitData*)fHitColl->At(flag); |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
virtual void PreEvent(){/* this method was created for zeroing digits in common area */}; |
125 |
|
|
|
126 |
|
|
virtual void Compress(){ (*fHitColl).Compress(); }; |
127 |
|
|
|
128 |
|
|
virtual void Digitize(){/* later will be = 0 */}; |
129 |
|
|
|
130 |
|
|
virtual void ClearHitColl(){ |
131 |
|
|
fnohit=0; |
132 |
|
|
(*fHitColl).Clear("C"); |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
virtual void FillHit(fin f,TVirtualMC *g){ |
136 |
|
|
ffi=f; |
137 |
|
|
switch(f) { |
138 |
|
|
case ENTERING: |
139 |
|
|
CleanHit(); |
140 |
|
|
FillVolID(); |
141 |
|
|
InitHit(); |
142 |
|
|
default: |
143 |
|
|
UpdateHit(g); |
144 |
|
|
break; |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
switch(f){ |
148 |
|
|
case EXITING: |
149 |
|
|
// Save hit if energy release is greater than zero |
150 |
|
|
|
151 |
|
|
if(fhit.GetEREL()){ |
152 |
|
|
SaveHit(fdname.Data()); |
153 |
|
|
} |
154 |
|
|
break; |
155 |
|
|
default: |
156 |
|
|
break; |
157 |
|
|
} |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
|
161 |
|
|
virtual void Print(const Option_t* ="") const { |
162 |
|
|
|
163 |
|
|
// Print more information like the name |
164 |
|
|
std::cout<<"DETECTOR "<<fdname<<" HIT COLLECTION"<<std::endl; |
165 |
|
|
fHitColl->Print(); |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
ClassDef(PamVMCDetectorSD,1) |
169 |
|
|
}; |
170 |
|
|
|
171 |
|
|
|
172 |
|
|
#endif //PAMVMC_DETECTOR_SD_H |