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 "PamVMCDigMgr.h" |
12 |
#include "PamVMCGeoIDMgr.h" |
13 |
#include "PamRootManager.h" |
14 |
#include "PamVMCStack.h" |
15 |
#include <TParticle.h> |
16 |
|
17 |
|
18 |
enum fin{INSIDE,ENTERING,EXITING}; |
19 |
|
20 |
class PamVMCDetectorSD : public TObject { |
21 |
|
22 |
|
23 |
|
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 |
PamVMCDigitizer * fdig; |
36 |
|
37 |
public: |
38 |
|
39 |
|
40 |
PamVMCDetectorSD( |
41 |
const char *cname="PamVMCDetectorHit", |
42 |
const char *dname="", |
43 |
Int_t is=0): |
44 |
fcname(cname), fdname(dname), fnohit(0), fdetID(0) |
45 |
{ |
46 |
if(is) { |
47 |
fHitColl=new TClonesArray(fcname.Data(),is); |
48 |
} else { |
49 |
fHitColl=new TClonesArray(fcname.Data()); |
50 |
} |
51 |
fhit = new PamVMCDetectorHit(); |
52 |
|
53 |
fdig = (PamVMCDigitizer*)PamVMCDigMgr::Instance()->GetDIG(dname); |
54 |
|
55 |
AddGeoID(dname); |
56 |
} |
57 |
|
58 |
|
59 |
virtual ~PamVMCDetectorSD() { delete fhit; delete fHitColl; delete fdetID;} |
60 |
|
61 |
virtual void Register(){ |
62 |
|
63 |
PamRootManager::Instance()-> |
64 |
Register(fdname.Data(),"TClonesArray", &fHitColl); |
65 |
|
66 |
if (fdig) fdig->RegisterCollections(fdname.Data(),fHitColl); |
67 |
|
68 |
TString a=fHitColl?"exist":"not exist"; |
69 |
} |
70 |
|
71 |
void AddGeoID(const char * dname){ |
72 |
TString temp=dname; |
73 |
fdetID=new PamVMCGeoID(dname); |
74 |
fdmap.Add(new TObjString(temp), fdetID); |
75 |
cout <<" Inside AddGeoID "<<fdname.Data() << endl; |
76 |
fdmap.Print(); |
77 |
} |
78 |
|
79 |
|
80 |
virtual void CleanHit(){ fhit->CleanHit();} |
81 |
|
82 |
virtual void InitHit() { |
83 |
if(fdetID) { |
84 |
fhit->SetPOS( fdetID->GetID( )) ; |
85 |
} else { fhit->SetPOS(-1); } |
86 |
} |
87 |
|
88 |
virtual void UpdateHit(TVirtualMC *g, Bool_t is_prim ){ fhit->FillHit(g, is_prim); } |
89 |
|
90 |
virtual void SaveHit(){ |
91 |
PamVMCDetectorHit * k=CreateHit(); |
92 |
k=fhit; |
93 |
} |
94 |
|
95 |
virtual void SaveHit(Int_t f){ |
96 |
PamVMCDetectorHit * k=CreateHit(f); |
97 |
*k+=*fhit; |
98 |
} |
99 |
|
100 |
virtual void SaveHit(const char * dname){ |
101 |
PamVMCDetectorHit * k=CreateHit(dname); |
102 |
*k=*fhit; |
103 |
} |
104 |
|
105 |
virtual PamVMCDetectorHit * CreateHit() |
106 |
{ |
107 |
PamVMCDetectorHit *hit= (PamVMCDetectorHit *) fHitColl->New(fnohit++); |
108 |
InitHit(); |
109 |
//cout<<"New hit in"<<fdname<<" nhit="<<fnohit<<endl; |
110 |
return hit; |
111 |
} |
112 |
|
113 |
virtual void FillVolID(){ |
114 |
fdetID->FillVolID(); |
115 |
fhit->SetPOS( fdetID->GetID( )) ; |
116 |
} |
117 |
|
118 |
virtual PamVMCDetectorHit * CreateHit(const char * dname) |
119 |
{ |
120 |
fdetID=(PamVMCGeoID*)fdmap(dname); |
121 |
return CreateHit(); |
122 |
} |
123 |
|
124 |
virtual PamVMCDetectorHit * CreateHit(Int_t flag) { |
125 |
if(!fHitColl->At(flag)) { |
126 |
PamVMCDetectorHit *hit= (PamVMCDetectorHit *) fHitColl->New(flag); |
127 |
InitHit(); |
128 |
return hit; |
129 |
} |
130 |
return (PamVMCDetectorHit*)fHitColl->At(flag); |
131 |
} |
132 |
|
133 |
virtual void PreEvent(){/* this method was created |
134 |
for zeroing digits in common area. |
135 |
calls from application before each event*/}; |
136 |
|
137 |
virtual void Compress(){ (*fHitColl).Compress(); }; |
138 |
|
139 |
virtual void Digitize(){/*this method do pre-digitize action, |
140 |
ex. calculate strips energy release |
141 |
(create something to be digitized (if any). |
142 |
calls from application*/ } |
143 |
|
144 |
|
145 |
virtual void ClearHitColl(){ |
146 |
fnohit=0; |
147 |
(*fHitColl).Clear("C"); |
148 |
} |
149 |
|
150 |
virtual void FillHit(fin f,TVirtualMC *g, Bool_t is_prim){ |
151 |
ffi=f; |
152 |
switch(f) { |
153 |
case ENTERING: |
154 |
CleanHit(); |
155 |
FillVolID(); |
156 |
InitHit(); |
157 |
default: |
158 |
UpdateHit(g, is_prim); |
159 |
break; |
160 |
} |
161 |
|
162 |
switch(f){ |
163 |
case EXITING: |
164 |
// Save hit if energy release is greater than zero |
165 |
if(fhit->GetEREL()){ |
166 |
SaveHit(fdname.Data()); |
167 |
} |
168 |
break; |
169 |
default: |
170 |
break; |
171 |
} |
172 |
} |
173 |
|
174 |
Int_t GetNhits() const { return fnohit; } |
175 |
|
176 |
|
177 |
virtual void Print(const Option_t* ="") const { |
178 |
|
179 |
// Print more information like the name |
180 |
std::cout<<"DETECTOR "<<fdname<<" NHITS:"<<fnohit<<" HIT COLLECTION"<<std::endl; |
181 |
fHitColl->Print(); |
182 |
} |
183 |
|
184 |
ClassDef(PamVMCDetectorSD,1) |
185 |
}; |
186 |
|
187 |
|
188 |
#endif //PAMVMC_DETECTOR_SD_H |