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 |
protected: |
22 |
|
23 |
TString fcname; |
24 |
TString fdname; |
25 |
Int_t fnohit; |
26 |
// PamVMCDetectorHit *fhit; |
27 |
TClonesArray *fHitColl; |
28 |
TMap fdmap; |
29 |
PamVMCGeoID *fdetID; |
30 |
PamVMCDetectorHit fhit; |
31 |
|
32 |
public: |
33 |
|
34 |
|
35 |
//PamVMCDetectorSD(){}; |
36 |
// fcname(""), fdname(""), fnohit(0), fdetID(0), fHitColl(0) { ;}; |
37 |
|
38 |
PamVMCDetectorSD( |
39 |
const char *cname="pHitData", |
40 |
char *dname="", |
41 |
Int_t is=0): |
42 |
fcname(cname), fdname(dname), fnohit(0), fdetID(0) |
43 |
{ |
44 |
if(is) { |
45 |
fHitColl=new TClonesArray(fcname.Data(),is); |
46 |
} else { |
47 |
fHitColl=new TClonesArray(fcname.Data()); |
48 |
} |
49 |
// fHitColl->Print(); |
50 |
/// cout<<"!!! Created array:" <<fdname.Data()<<" is="<<is<<endl; |
51 |
AddGeoID(dname); |
52 |
// fdetID=PamVMCGeoIDMgr::Instance()->GetGeoID(fdname.Data()); |
53 |
} |
54 |
|
55 |
|
56 |
virtual ~PamVMCDetectorSD() { delete fHitColl; delete fdetID;} |
57 |
|
58 |
void PamVMCDetectorSD::Register(){ |
59 |
|
60 |
PamRootManager::Instance()-> |
61 |
Register(fdname.Data(),"TClonesArray", &fHitColl); |
62 |
// fdname.Print(); |
63 |
|
64 |
TString a=fHitColl?"exist":"not exist"; |
65 |
cout<<"!!! Registered TREE:" <<fdname.Data()<< endl; |
66 |
cout << "HitColl=" <<a.Data() << endl; |
67 |
} |
68 |
|
69 |
void AddGeoID(const char * dname){ |
70 |
TString temp=dname; |
71 |
fdetID=new PamVMCGeoID(dname); |
72 |
fdmap.Add(new TObjString(temp), fdetID); |
73 |
cout <<" Inside AddGeoID "<<fdname.Data() << endl; |
74 |
fdmap.Print(); |
75 |
} |
76 |
|
77 |
virtual void CleanHit(){ fhit.CleanHit();} |
78 |
|
79 |
virtual void InitHit() { |
80 |
if(fdetID) { |
81 |
// fdetID->FillVolID(); |
82 |
// fdetID->Print(); |
83 |
fhit.SetPOS( fdetID->GetID( )) ; |
84 |
} else { fhit.SetPOS(-1); } |
85 |
} |
86 |
|
87 |
virtual void UpdateHit(TVirtualMC *g){ fhit.FillHit(g); } |
88 |
|
89 |
// virtual void AddGlobalTime(TVirtualMC *g){ |
90 |
// Double_t GlobTime=g->GetStack()->GetCurrentTrack()->T(); |
91 |
// fhit.SetTOF(fhit.GetTOF()+GlobTime/TG4G3Units::Time()); |
92 |
// } |
93 |
|
94 |
virtual void SaveHit(){ |
95 |
pHitData * t=CreateHit(); |
96 |
*t=*fhit.GetHit(); |
97 |
} |
98 |
|
99 |
virtual void SaveHit(Int_t f){ |
100 |
pHitData * t=CreateHit(f); |
101 |
*t+=*(fhit.GetHit()); |
102 |
} |
103 |
|
104 |
virtual void SaveHit(const char * dname){ |
105 |
pHitData * t=CreateHit(dname); |
106 |
*t=*fhit.GetHit(); |
107 |
} |
108 |
|
109 |
virtual pHitData * CreateHit() |
110 |
{ |
111 |
pHitData *hit= (pHitData *) fHitColl->New(fnohit++); |
112 |
// fdetID->FillVolID(); |
113 |
// hit->fPOS= fdetID->GetID( ) ; |
114 |
InitHit(); |
115 |
return hit; |
116 |
} |
117 |
virtual void FillVolID(){ |
118 |
fdetID->FillVolID(); |
119 |
fhit.SetPOS( fdetID->GetID( )) ; |
120 |
} |
121 |
virtual pHitData * CreateHit(const char * dname) |
122 |
{ |
123 |
fdetID=(PamVMCGeoID*)fdmap(dname); |
124 |
return CreateHit(); |
125 |
} |
126 |
|
127 |
virtual pHitData * CreateHit(Int_t flag) { |
128 |
if(!fHitColl->At(flag)) { return PamVMCDetectorSD::CreateHit(); } |
129 |
return (pHitData*)fHitColl->At(flag); |
130 |
} |
131 |
|
132 |
virtual void ClearHitColl(){ |
133 |
fnohit=0; |
134 |
(*fHitColl).Clear(); |
135 |
} |
136 |
|
137 |
virtual void FillHit(fin f,TVirtualMC *g){ |
138 |
switch(f) { |
139 |
case ENTERING: |
140 |
CleanHit(); |
141 |
FillVolID(); |
142 |
InitHit(); |
143 |
|
144 |
//UpdateHit(g); |
145 |
// break; |
146 |
default: |
147 |
UpdateHit(g); |
148 |
break; |
149 |
} |
150 |
|
151 |
switch(f){ |
152 |
case EXITING: |
153 |
// Save hit if energy release is greater than zero |
154 |
UpdateHit(g); |
155 |
|
156 |
if(fhit.GetEREL()){ |
157 |
// AddGlobalTime(g); |
158 |
SaveHit(fdname.Data()); |
159 |
} |
160 |
break; |
161 |
default: |
162 |
break; |
163 |
} |
164 |
} |
165 |
|
166 |
|
167 |
virtual void Print(const Option_t* ="") const { |
168 |
|
169 |
// Print more information like the name |
170 |
std::cout<<"DETECTOR "<<fdname<<" HIT COLLECTION"<<std::endl; |
171 |
fHitColl->Print(); |
172 |
} |
173 |
|
174 |
ClassDef(PamVMCDetectorSD,1) |
175 |
}; |
176 |
|
177 |
|
178 |
|
179 |
|
180 |
#endif //PAMVMC_DETECTOR_SD_H |