BOSS 7.0.1
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#include "GaudiKernel/ISvcLocator.h"
22#include "GaudiKernel/Bootstrap.h"
23#include "GaudiKernel/MsgStream.h"
24#include "G4LossTableManager.hh"
25#include "G4ElectronIonPair.hh"
26
27//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
28
29BesTofSD::BesTofSD( G4String name ) : BesSensitiveDetector(name), m_besTofList(0) {
30 collectionName.insert("BesTofHitsCollection");
31 collectionName.insert("BesTofHitsList");
32 elIonPair = new G4ElectronIonPair();
33}
34
35//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36
38}
39
40//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41
42void BesTofSD::Initialize( G4HCofThisEvent* ) {
43 m_besTofCollection = new BesTofHitsCollection( SensitiveDetectorName, collectionName[0] );
44 //elIonPair = G4LossTableManager::Instance()->ElectronIonPair();
45}
46
47//for MC Truth
48void BesTofSD::BeginOfTruthEvent( const G4Event* ) {
49 m_besTofList = new BesTofHitsCollection( SensitiveDetectorName, collectionName[1] );
50 m_trackIndexes.clear();
51 m_trackIndex = -99;
52}
53
54void BesTofSD::EndOfTruthEvent( const G4Event* evt ) {
55 static G4int HLID=-1;
56 if( HLID<0 ) {
57 HLID = G4SDManager::GetSDMpointer()->GetCollectionID( collectionName[1] );
58 }
59 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
60 HCE->AddHitsCollection( HLID, m_besTofList );
61}
62
63//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64
65G4bool BesTofSD::ProcessHits( G4Step* aStep, G4TouchableHistory* ) {
66
67 G4double chg=aStep->GetTrack()->GetDefinition()->GetPDGCharge();
68 G4double edep = aStep->GetTotalEnergyDeposit();
69 G4double stepL=aStep->GetStepLength();
70 G4double deltaT=aStep->GetDeltaTime();
71 G4StepPoint* preStep = aStep->GetPreStepPoint();
72 G4ThreeVector pDirection=preStep->GetMomentumDirection();
73 G4String particleName = aStep->GetTrack()->GetDefinition()->GetParticleName();
74 G4Material* scinMaterial = aStep->GetTrack()->GetMaterial();
75 G4double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
76 G4int pdgcode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
77
78 if( chg==0 && edep==0 && stepL==0 ) { return false; }
79
80 BesTofHit *newHit = new BesTofHit();
81 G4int trackId = aStep->GetTrack()->GetTrackID();
82
83 newHit->SetTrackIndex(-99);
84 newHit->SetG4Index(aStep->GetTrack()->GetTrackID());
85 newHit->SetEdep(edep);
86 newHit->SetStepL(stepL);
87 //newHit->SetPName(particleName);
88 newHit->SetTrackL(aStep->GetTrack()->GetTrackLength());
89 G4ThreeVector pos=preStep->GetPosition();
90 newHit->SetPos(pos);
91 G4double globalTime=preStep->GetGlobalTime();
92 newHit->SetTime(globalTime);
93 newHit->SetDeltaT(deltaT);
94 newHit->SetPDirection(pDirection);
95 newHit->SetMomentum(preStep->GetMomentum());
96 //newHit->SetMaterial(scinMaterial);
97 newHit->SetCharge(charge);
98 newHit->SetPDGcode(pdgcode);
99
100 //Get local position in sensitive detector, add by anff
101 G4ThreeVector locPos(0,0,0);
102 G4TouchableHistory* theTouchable = (G4TouchableHistory*)( preStep->GetTouchable() );
103 //partId: barrel(1), east endcap(0), west endcap(2);
104 //scinNb: barrel(0-175),east endcap(0-47), west endcap(0-47)
105 //partId: mrpc: east(3), west(4),
106
107 G4String name;
108 //for(G4int i=0; i<theTouchable->GetHistoryDepth(); i++)
109 //{
110 // name = theTouchable->GetVolume(i)->GetName();
111 // G4cout<<"********* name of the "<<i<<" volume: "<<name<<" ***************"<<G4endl;
112 //}
113 name = theTouchable->GetVolume(0)->GetName();
114
115 G4int partId=-1, scinNb=-1, gapNb=-1, number=-1;
116 G4int strip = -1;
117 gapNb = theTouchable->GetReplicaNumber(0);
118 number = theTouchable->GetReplicaNumber(2); //This is valid only for scintillator
119
120 //MRPC ENDCAPS construct by geant4 code
121 if(name.contains("physical_gasLayer"))
122 {
123 locPos = theTouchable->GetHistory()->GetTopTransform().TransformPoint(pos);
124 number = theTouchable->GetReplicaNumber(3);
125 scinNb = number;
126
127 G4String name1 = theTouchable->GetVolume(4)->GetName();
128 if(name1 == "physicalEcTofEast") partId=3;
129 else if(name1 == "physicalEcTofWest") partId=4;
130 //G4cout<<"scinNb= "<<scinNb<<" gapNb= "<<gapNb<<" partId="<<partId<<G4endl;
131 }
132 //MRPC ENDCAPS construct by GDML
133 else if(name=="logical_gasLayer")
134 {
135 locPos = theTouchable->GetHistory()->GetTopTransform().TransformPoint(pos);
136 number = theTouchable->GetReplicaNumber(3);
137 scinNb = 35-number;
138
139 G4String name1 = theTouchable->GetVolume(4)->GetName();
140 if(name1 == "logicalEcTofEast") partId=3;
141 else if(name1 == "logicalEcTofWest") partId=4;
142 //G4cout<<"scinNb= "<<scinNb<<" gapNb= "<<gapNb<<" partId="<<partId<<G4endl;
143 }
144
145
146 // Scintillator
147 else if( name=="physicalScinBr1" ) {
148 partId = 1;
149 scinNb = number;
150 //G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
151 }
152 else if( name=="physicalScinBr2" ) {
153 partId = 1;
154 scinNb = number+88;
155 //G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
156 }
157 else if( name=="physicalScinEcWest" ) {
158 partId = 2;
159 scinNb = number;
160 //G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
161 }
162 else if( name=="physicalScinEcEast" ) {
163 partId = 0;
164 scinNb = number;
165 //G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
166 }
167
168
169 //if construct by gdml files
170 else if( name=="logicalScinBr1" || name=="logicalScinBr2" ) {
171 partId = 1;
172 scinNb = (527-number)/3;
173 }
174 //copy number: east:1-95(scinNb:47-0), west:1-95(scinNb:47-0)
175 else if( name=="logicalScinEcEast" ) {
176 partId = 0;
177 scinNb = (95-number)/2;
178 }
179 else if( name=="logicalScinEcWest" ) {
180 partId = 2;
181 scinNb = (95-number)/2;
182 }
183 else { return false; }
184
185
186 if(name.contains("physical_gasLayer") || name.contains("logical_gasLayer"))
187 {
188 G4double zz = locPos.z()-0.5*mm+(24+3)*mm*6; //0.5mm is the offset between strip and gasLayer
189 if(zz<=0)
190 {
191 strip=0;
192 }
193 else if(zz>0 && zz<12*27*mm)
194 {
195 for(G4int i=0; i<12; i++)
196 {
197 if(zz>i*27*mm && zz<=(i+1)*27*mm)
198 {
199 strip = i;
200 //G4cout<<"Local z is "<<locPos.z()<<" strip number is: "<<strip<<" !!!"<<G4endl;
201 break;
202 }
203 }
204 }
205 else
206 {
207 strip=11;
208 }
209 if(strip<0) strip=0;
210 if(strip>11) strip=11;
211 }
212
213
214 newHit->SetPartId(partId);
215 newHit->SetScinNb(scinNb);
216 newHit->SetGapNb(gapNb);
217 newHit->SetLocPos(locPos);
218 newHit->SetModule(scinNb);
219 newHit->SetStrip(strip);
220 //newHit->SetIons(elIonPair->SampleNumberOfIonsAlongStep(aStep));
221 newHit->SetIons(SampleNumberOfIonsAlongStep(aStep,elIonPair));
222 //newHit->Draw();
223
224 G4int trackIndex, g4TrackId;
225 GetCurrentTrackIndex( trackIndex, g4TrackId );
226 newHit->SetTrackIndex( trackIndex );
227 //newHit->Print();
228 if( edep>0 ) {
229 m_besTofCollection->insert( newHit );
230 }
231
232 //for mc truth
233 if( m_besTofList ) {
234 G4int trackIndex, g4TrackId;
235 GetCurrentTrackIndex(trackIndex, g4TrackId);
236 newHit->SetTrackIndex(trackIndex);
237 if( m_trackIndex != trackIndex ) {
238 m_trackIndex = trackIndex;
239 //G4int size = m_trackIndexes.size();
240 //G4int flag=1;
241 //if(size>0)
242 //{
243 // for(G4int i=0;i<size;i++)
244 // if(m_trackIndexes[i] == trackIndex )
245 // {flag =0; break;}
246 //}
247 //if(flag && aStep->GetTrack()->GetTrackID()==g4TrackId )
248 G4int flag = 1;
249 G4int pdg = abs(aStep->GetTrack()->GetDefinition()->GetPDGEncoding());
250 if( pdg==12 || pdg==14 || pdg==16 ) { flag=0; }
251 if( flag && aStep->GetTrack()->GetTrackID()==g4TrackId ) {
252 m_trackIndexes.push_back(trackIndex);
253 BesTofHit* truHit = new BesTofHit();
254 *truHit = *newHit;
255 m_besTofList->insert(truHit);
256 }
257 }
258 }
259 if( edep<=0 ) { delete newHit; }
260
261 return true;
262
263}//Close Process Hits
264
265//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
266
267void BesTofSD::EndOfEvent( G4HCofThisEvent* HCE ) {
268 static G4int HCID=-1;
269 if( HCID<0 ) {
270 HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
271 }
272 HCE->AddHitsCollection(HCID,m_besTofCollection);
273}
274
275//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
276
277G4int BesTofSD::SampleNumberOfIonsAlongStep( const G4Step* step, G4ElectronIonPair* eipair ) {
278 G4double FanoFactor = 0.2; //Is this value appropiate?
279 G4double meanion = eipair->MeanNumberOfIonsAlongStep(step);
280 G4double sig = std::sqrt(FanoFactor*meanion); //Be carefull : In originally Geant4 code this calculatin is wrong!
281 G4int nion = G4int(G4RandGauss::shoot(meanion,sig) + 0.5);
282 return nion;
283}
284
285
G4THitsCollection< BesTofHit > BesTofHitsCollection
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const
void SetPDirection(G4ThreeVector pDirection)
void SetLocPos(G4ThreeVector locPos)
void SetMomentum(G4ThreeVector momentum)
void BeginOfTruthEvent(const G4Event *)
Definition: BesTofSD.cc:48
virtual void Initialize(G4HCofThisEvent *HCE)
Definition: BesTofSD.cc:42
virtual void EndOfEvent(G4HCofThisEvent *HCE)
Definition: BesTofSD.cc:267
BesTofSD(G4String name)
Definition: BesTofSD.cc:29
virtual ~BesTofSD()
Definition: BesTofSD.cc:37
void EndOfTruthEvent(const G4Event *)
Definition: BesTofSD.cc:54
G4int SampleNumberOfIonsAlongStep(const G4Step *, G4ElectronIonPair *)
Definition: BesTofSD.cc:277
virtual G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *)
Definition: BesTofSD.cc:65