BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTofSD.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2// BOOST --- BESIII Object_Oriented Simulation Tool //
3//---------------------------------------------------------------------------//
4//Description:
5//Author: Dengzy
6//Created: Mar, 2004
7//Modified:
8//Comment:
9//---------------------------------------------------------------------------//
10//$Id: BesTofSD.cc
11
12#include "BesTofSD.hh"
13#include "ReadBoostRoot.hh"
14#include "G4HCofThisEvent.hh"
15#include "G4Step.hh"
16#include "G4ThreeVector.hh"
17#include "G4SDManager.hh"
18#include "G4ios.hh"
19#include "G4UnitsTable.hh"
20#include "G4Event.hh"
21
22
23
24#include "GaudiKernel/ISvcLocator.h"
25#include "GaudiKernel/Bootstrap.h"
26#include "GaudiKernel/MsgStream.h"
27
28
29#include "G4LossTableManager.hh"
30#include "G4ElectronIonPair.hh"
31
32
33
34//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
35
36
37
38BesTofSD::BesTofSD(G4String name)
39 :BesSensitiveDetector(name),m_besTofList(0)
40{
41 collectionName.insert("BesTofHitsCollection");
42 collectionName.insert("BesTofHitsList");
43 elIonPair = new G4ElectronIonPair();
44
45}
46
47//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48
50{ }
51
52//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53
54void BesTofSD::Initialize(G4HCofThisEvent* )
55{
56 m_besTofCollection = new BesTofHitsCollection
57 (SensitiveDetectorName,collectionName[0]);
58
59 //elIonPair = G4LossTableManager::Instance()->ElectronIonPair();
60}
61
62//for MC Truth
63void BesTofSD::BeginOfTruthEvent(const G4Event* )
64{
65 m_besTofList = new BesTofHitsCollection(SensitiveDetectorName, collectionName[1]);
66 m_trackIndexes.clear();
67 m_trackIndex = -99;
68}
69
70void BesTofSD::EndOfTruthEvent(const G4Event* evt)
71{
72 static G4int HLID=-1;
73 if (HLID<0)
74 {
75 HLID = G4SDManager::GetSDMpointer()->
76 GetCollectionID(collectionName[1]);
77 }
78
79 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
80 HCE->AddHitsCollection(HLID,m_besTofList);
81
82}
83//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84
85G4bool BesTofSD::ProcessHits(G4Step* aStep,G4TouchableHistory*)
86{
87
88 G4double chg=aStep->GetTrack()->GetDefinition()->GetPDGCharge();
89 G4double edep = aStep->GetTotalEnergyDeposit();
90 G4double stepL=aStep->GetStepLength();
91 G4double deltaT=aStep->GetDeltaTime();
92 G4StepPoint* preStep = aStep->GetPreStepPoint();
93 G4ThreeVector pDirection=preStep->GetMomentumDirection();
94 G4String particleName = aStep->GetTrack()->GetDefinition()->GetParticleName();
95 G4Material* scinMaterial = aStep->GetTrack()->GetMaterial();
96 G4double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
97 G4int pdgcode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
98
99 if (chg==0&&edep==0&&stepL==0)
100 return false;
101 BesTofHit *newHit = new BesTofHit();
102
103
104 G4int trackId = aStep->GetTrack()->GetTrackID();
105
106 newHit->SetTrackIndex(-99);
107 newHit->SetG4Index(aStep->GetTrack()->GetTrackID());
108 newHit->SetEdep(edep);
109 newHit->SetStepL(stepL);
110 //newHit->SetPName(particleName);
111 newHit->SetTrackL(aStep->GetTrack()->GetTrackLength());
112 G4ThreeVector pos=preStep->GetPosition();
113 newHit->SetPos(pos);
114 G4double globalTime=preStep->GetGlobalTime();
115 newHit->SetTime(globalTime);
116 newHit->SetDeltaT(deltaT);
117 newHit->SetPDirection(pDirection);
118 newHit->SetMomentum(preStep->GetMomentum());
119 //newHit->SetMaterial(scinMaterial);
120 newHit->SetCharge(charge);
121 newHit->SetPDGcode(pdgcode);
122 //barrel segment number: 0-175
123 //endcap west: 0-47 z<0
124 //endcap east: 0-47 z>0
125
126 G4TouchableHistory* theTouchable
127 = (G4TouchableHistory*)(preStep->GetTouchable());
128
129 //partId: barrel(1), east endcap(0), west endcap(2);
130 //partId:mrpc: east_layer_2 (3), east_layer_1 (4), west_layer_1 (5), west_layer_2 (6),
131 //scinNb: barrel(0-175),east endcap(0-47), west endcap(0-47)
132 G4String name = theTouchable->GetVolume(0)->GetName();
133
134 G4int partId, scinNb, number,help_mrpc,module_mrpc ;
135
136 number = theTouchable->GetReplicaNumber(2);
137 help_mrpc = theTouchable->GetReplicaNumber(3);
138
139
140 //MRPC ENDCAPS construct by geant4 code
141 if(name=="physical_sensitive_detector_west_1")
142 {
143 partId =5;
144 scinNb = help_mrpc;
145 }
146 else if(name=="physical_sensitive_detector_west_2")
147 {
148 partId =6;
149 scinNb = help_mrpc;
150 }
151 else if(name=="physical_sensitive_detector_east_1")
152 {
153 partId =4;
154 scinNb = help_mrpc;
155 }
156 else if(name=="physical_sensitive_detector_east_2")
157 {
158 partId =3;
159 scinNb = help_mrpc;
160 }
161 //MRPC ENDCAPS construct by GDML
162 else if(name=="logical_sensitive_detector_west_1")
163 {
164 partId =5;
165 scinNb = (help_mrpc)*(-0.5)+18.5;
166 }
167 else if(name=="logical_sensitive_detector_west_2")
168 {
169 partId =6;
170 scinNb = (help_mrpc)*(-0.5)+18;
171 }
172 else if(name=="logical_sensitive_detector_east_1")
173 {
174 partId =4;
175 scinNb = (help_mrpc)*(0.5)+0.5;
176 }
177
178 else if(name=="logical_sensitive_detector_east_2")
179 {
180 partId =3;
181 scinNb =( help_mrpc)*(0.5)+1;
182 }
183 //old TOF
184 else if (name=="physicalScinBr1")
185 {
186 partId = 1;
187 scinNb = number;
188 }
189 else if (name=="physicalScinBr2")
190 {
191 partId = 1;
192 scinNb = number+88;
193 }
194 else if (name=="physicalScinEcWest")
195 {
196 partId = 2;
197 scinNb = number;
198 }
199 else if (name=="physicalScinEcEast")
200 {
201 partId = 0;
202 scinNb = number;
203 }
204
205 //if construct by gdml files
206 else if (name=="logicalScinBr1" ||name=="logicalScinBr2")
207 {
208 partId = 1;
209 scinNb = (527-number)/3;
210 }
211 else if (name=="logicalScinEcEast")
212 { //copy number: east:1-95(scinNb:47-0), west:1-95(scinNb:47-0)
213 //east: partId=0 west: partId=2
214 partId = 0;
215 scinNb = (95-number)/2;
216 }
217 else if (name=="logicalScinEcWest")
218 {
219 partId = 2;
220 scinNb = (95-number)/2;
221 }
222 else
223 return false;
224
225
226
227
228
229
230
231
232 newHit->SetPartId(partId);
233 newHit->SetScinNb(scinNb);
234 newHit->SetModule_mrpc(scinNb);
235 //newHit->SetIons(elIonPair->SampleNumberOfIonsAlongStep(aStep));
236 newHit->SetIons(SampleNumberOfIonsAlongStep(aStep,elIonPair));
237
238
239
240
241 //newHit->Draw();
242 G4int trackIndex, g4TrackId;
243 GetCurrentTrackIndex(trackIndex, g4TrackId);
244 newHit->SetTrackIndex(trackIndex);
245 //newHit->Print();
246 if (edep>0)
247 {
248 m_besTofCollection->insert(newHit);
249
250 }
251
252 //for mc truth
253 if (m_besTofList)
254 {
255 G4int trackIndex, g4TrackId;
256 GetCurrentTrackIndex(trackIndex, g4TrackId);
257 newHit->SetTrackIndex(trackIndex);
258 if (m_trackIndex != trackIndex)
259 {
260 m_trackIndex = trackIndex;
261 //G4int size = m_trackIndexes.size();
262 //G4int flag=1;
263 //if(size>0)
264 //{
265 // for(G4int i=0;i<size;i++)
266 // if(m_trackIndexes[i] == trackIndex )
267 // {flag =0; break;}
268 //}
269 //if(flag && aStep->GetTrack()->GetTrackID()==g4TrackId )
270 G4int flag=1;
271 G4int pdg = abs(aStep->GetTrack()->GetDefinition()->GetPDGEncoding());
272 if (pdg==12 || pdg==14 || pdg==16)
273 flag=0;
274 if (flag && aStep->GetTrack()->GetTrackID()==g4TrackId)
275 {
276 m_trackIndexes.push_back(trackIndex);
277 BesTofHit* truHit = new BesTofHit();
278 *truHit = *newHit;
279 m_besTofList->insert(truHit);
280 }
281 }
282 }
283 if (edep<=0) delete newHit;
284
285
286
287return true;
288
289}//Close Process Hits
290
291//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
292
293void BesTofSD::EndOfEvent(G4HCofThisEvent* HCE)
294{
295 static G4int HCID=-1;
296 if (HCID<0)
297 {
298 HCID = G4SDManager::GetSDMpointer()->
299 GetCollectionID(collectionName[0]);
300 }
301 HCE->AddHitsCollection(HCID,m_besTofCollection);
302
303}
304
305
306//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
307
308
309
310G4int BesTofSD::SampleNumberOfIonsAlongStep(const G4Step* step, G4ElectronIonPair* eipair)
311{
312
313 G4double FanoFactor = 0.2; //Is this value appropiate?
314 G4double meanion = eipair->MeanNumberOfIonsAlongStep(step);
315 G4double sig = std::sqrt(FanoFactor*meanion); //Be carefull : In originally Geant4 code this calculatin is wrong!
316 G4int nion = G4int(G4RandGauss::shoot(meanion,sig) + 0.5);
317 return nion;
318
319}
320
321
G4THitsCollection< BesTofHit > BesTofHitsCollection
Definition: BesTofHit.hh:108
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const
void SetPos(G4ThreeVector pos)
Definition: BesTofHit.hh:48
void SetDeltaT(G4double deltaT)
Definition: BesTofHit.hh:50
void SetCharge(G4double charge)
Definition: BesTofHit.hh:55
void SetPDGcode(G4int pdgcode)
Definition: BesTofHit.hh:56
void SetTrackIndex(G4int trackIndex)
Definition: BesTofHit.hh:41
void SetPDirection(G4ThreeVector pDirection)
Definition: BesTofHit.hh:51
void SetIons(G4int ions)
Definition: BesTofHit.hh:79
void SetPartId(G4int partId)
Definition: BesTofHit.hh:43
void SetModule_mrpc(G4int module_mrpc)
Definition: BesTofHit.hh:84
void SetScinNb(G4int scinNb)
Definition: BesTofHit.hh:44
void SetStepL(G4double stepL)
Definition: BesTofHit.hh:46
void SetTrackL(G4double length)
Definition: BesTofHit.hh:47
void SetTime(G4double time)
Definition: BesTofHit.hh:49
void SetEdep(G4double edep)
Definition: BesTofHit.hh:45
void SetMomentum(G4ThreeVector momentum)
Definition: BesTofHit.hh:52
void SetG4Index(G4int index)
Definition: BesTofHit.hh:42
void BeginOfTruthEvent(const G4Event *)
Definition: BesTofSD.cc:63
virtual void Initialize(G4HCofThisEvent *HCE)
Definition: BesTofSD.cc:54
virtual void EndOfEvent(G4HCofThisEvent *HCE)
Definition: BesTofSD.cc:293
BesTofSD(G4String name)
Definition: BesTofSD.cc:38
virtual ~BesTofSD()
Definition: BesTofSD.cc:49
void EndOfTruthEvent(const G4Event *)
Definition: BesTofSD.cc:70
G4int SampleNumberOfIonsAlongStep(const G4Step *, G4ElectronIonPair *)
Definition: BesTofSD.cc:310
virtual G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *)
Definition: BesTofSD.cc:85