100 {
101 G4Track* gTrack = aStep->GetTrack();
102
103 G4double globalT =
104 gTrack->GetGlobalTime();
105 if ( std::isnan( globalT ) )
106 {
107 G4cout << "MdcSD:error, globalT is nan " << G4endl;
108 return false;
109 }
110 if ( globalT > 2000 ) return false;
111
112
113 G4int charge = gTrack->GetDefinition()->GetPDGCharge();
114 if ( charge == 0 ) return false;
115
116
117 G4double stepLength = aStep->GetStepLength();
118 if ( stepLength == 0 )
119 {
120
121 return false;
122 }
123
124 G4double edep = aStep->GetTotalEnergyDeposit() / stepLength;
125 if ( edep == 0. ) return false;
126
127
128 G4StepPoint* prePoint = aStep->GetPreStepPoint();
129 G4StepPoint* postPoint = aStep->GetPostStepPoint();
130
131
132 G4ThreeVector pointIn = prePoint->GetPosition();
133 G4ThreeVector pointOut = postPoint->GetPosition();
134
135
136 const G4VTouchable* touchable = prePoint->GetTouchable();
137 G4VPhysicalVolume* volume = touchable->GetVolume( 0 );
138
139 G4double driftD = 0;
140 G4double driftT = 0;
141 G4double edepTemp = 0;
142 G4double lengthTemp = 0;
143 G4int cellId = 0;
144 G4int layerId = touchable->GetVolume( 1 )->GetCopyNo();
145 if ( volume->IsReplicated() ) { cellId = touchable->GetReplicaNumber(); }
146 else { cellId = touchable->GetVolume( 0 )->GetCopyNo(); }
147 if ( layerId == 18 && ( cellId == 27 || cellId == 42 ) ) return false;
148
150 {
151
152
153 if ( layerId >= 36 ) layerId = 36 + ( layerId - 36 ) / 2;
154 }
155
156 G4double halfLayerLength = mdcGeomSvc->Layer( layerId )->Length() / 2.;
157 if ( ( ( fabs( pointIn.z() ) - halfLayerLength ) > -7. ) &&
158 ( ( fabs( pointOut.z() ) - halfLayerLength ) > -7. ) )
159 return false;
160
161 G4int trackID = gTrack->GetTrackID();
162 G4int truthID, g4TrackID;
164
165 G4double theta = gTrack->GetMomentumDirection().theta();
166
167 G4ThreeVector hitPosition( 0, 0, 0 );
168 G4double transferT = 0;
169 driftD =
Distance( layerId, cellId, pointIn, pointOut, hitPosition, transferT );
170
171 G4double posPhi, wirePhi;
172 posPhi = hitPosition.phi();
173 if ( posPhi < 0 ) posPhi += 2 *
pi;
174 wirePhi =
175 mdcGeoPointer->SignalWire( layerId, cellId ).Phi( hitPosition.z() );
176
177 G4int posFlag;
178 if ( posPhi <= wirePhi ) { posFlag = 0; }
179 else { posFlag = 1; }
180
181 if ( posPhi < 1. && wirePhi > 5. ) posFlag = 1;
182 if ( posPhi > 5. && wirePhi < 1. ) posFlag = 0;
183
184 G4ThreeVector hitLine = pointOut - pointIn;
185 G4double enterAngle = hitLine.phi() - wirePhi;
186 while ( enterAngle < -
pi / 2. ) enterAngle +=
pi;
187 while ( enterAngle >
pi / 2. ) enterAngle -=
pi;
188
189 if ( m_G4Svc->GetMdcDedxFlag() == 1 )
190 {
191 G4double betaGamma =
192 aStep->GetPreStepPoint()->GetBeta() * aStep->GetPreStepPoint()->GetGamma();
193 if ( betaGamma < 0.01 ) return false;
194
195
196 G4double eCount = dedxSample( betaGamma, charge, theta );
197 edep = eCount;
198 }
199
200 BesMdcHit* newHit = new BesMdcHit();
202
206 newHit->
SetPos( hitPosition );
211
212
213 mdcCalPointer->SetHitPointer( newHit );
214
215 driftT = mdcCalPointer->D2T( driftD );
216 globalT += transferT;
217 driftT += globalT;
218
221
222 if ( hitPointer[layerId][cellId] == -1 )
223 {
224 hitsCollection->insert( newHit );
225 G4int NbHits = hitsCollection->entries();
226 hitPointer[layerId][cellId] = NbHits - 1;
227 }
228 else
229 {
230 G4int pointer = hitPointer[layerId][cellId];
231 if ( g4TrackID == trackID )
232 { G4double preDriftT = ( *hitsCollection )[pointer]->GetDriftT(); }
233
234 G4double preDriftT = ( *hitsCollection )[pointer]->GetDriftT();
235 if ( driftT < preDriftT )
236 {
237 ( *hitsCollection )[pointer]->SetTrackID( truthID );
238
239 ( *hitsCollection )[pointer]->SetDriftD( driftD );
240 ( *hitsCollection )[pointer]->SetDriftT( driftT );
241 ( *hitsCollection )[pointer]->SetPos( hitPosition );
242 ( *hitsCollection )[pointer]->SetGlobalT( globalT );
243 ( *hitsCollection )[pointer]->SetTheta( theta );
244 ( *hitsCollection )[pointer]->SetPosFlag( posFlag );
245 ( *hitsCollection )[pointer]->SetEnterAngle( enterAngle );
246 }
247
248 delete newHit;
249 }
250
251
252 if ( truthCollection )
253 {
254 if ( g4TrackID == trackID )
255 {
256 G4int pointer = truthPointer[layerId][cellId];
257 if ( pointer == -1 )
258 {
259 BesMdcHit* truthHit = new BesMdcHit();
264 truthHit->
SetPos( hitPosition );
271
272 truthCollection->insert( truthHit );
273 G4int NbHits = truthCollection->entries();
274 truthPointer[layerId][cellId] = NbHits - 1;
275 }
276 else
277 {
278 if ( truthID == ( *truthCollection )[pointer]->GetTrackID() )
279 {
280 G4double preDriftT = ( *truthCollection )[pointer]->GetDriftT();
281 if ( driftT < preDriftT )
282 {
283 ( *truthCollection )[pointer]->SetDriftD( driftD );
284 ( *truthCollection )[pointer]->SetDriftT( driftT );
285 ( *truthCollection )[pointer]->SetPos( hitPosition );
286 ( *truthCollection )[pointer]->SetGlobalT( globalT );
287 ( *truthCollection )[pointer]->SetTheta( theta );
288 ( *truthCollection )[pointer]->SetPosFlag( posFlag );
289 ( *truthCollection )[pointer]->SetEnterAngle( enterAngle );
290 }
291 edepTemp = ( *truthCollection )[pointer]->GetEdep();
292 ( *truthCollection )[pointer]->SetEdep( edepTemp + edep );
293 }
294 else
295 {
296 BesMdcHit* truthHit = new BesMdcHit();
301 truthHit->
SetPos( hitPosition );
308
309 truthCollection->insert( truthHit );
310 G4int NbHits = truthCollection->entries();
311 truthPointer[layerId][cellId] = NbHits - 1;
312 }
313 }
314 }
315 }
316
317
318
319
320 return true;
321}
void SetEdep(G4double de)
void SetDriftT(G4double time)
void SetEnterAngle(G4double angle)
void SetCellNo(G4int cell)
void SetPos(G4ThreeVector xyz)
void SetTrackID(G4int track)
void SetLayerNo(G4int layer)
void SetTheta(G4double angle)
void SetDriftD(G4double distance)
void SetGlobalT(G4double time)
void SetPosFlag(G4int flag)
G4double Distance(G4int, G4int, G4ThreeVector, G4ThreeVector, G4ThreeVector &, G4double &)
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const