150{
151 G4Track* gTrack = aStep->GetTrack() ;
152
153 G4double globalT=gTrack->GetGlobalTime();
154 if(isnan(globalT)){
155 G4cout<<"MdcSD:error, globalT is nan "<<G4endl;
156 return false;
157 }
158 if(globalT > 2000)return false;
159
160
161 G4int
charge = gTrack->GetDefinition()->GetPDGCharge();
162 if (
charge == 0)
return false;
163
164
165 G4double stepLength=aStep->GetStepLength();
166 if(stepLength==0){
167
168 return false;
169 }
170
171 G4double edep = aStep->GetTotalEnergyDeposit() / stepLength;
172 if(edep==0.) return false;
173
174
175 G4StepPoint* prePoint = aStep->GetPreStepPoint() ;
176 G4StepPoint* postPoint = aStep->GetPostStepPoint() ;
177
178
179 G4ThreeVector pointIn = prePoint->GetPosition();
180 G4ThreeVector pointOut = postPoint->GetPosition();
181
182
183 const G4VTouchable *touchable = prePoint->GetTouchable();
184 G4VPhysicalVolume *volume = touchable->GetVolume(0);
185
186 G4double driftD = 0;
187 G4double driftT = 0;
188 G4double edepTemp = 0;
189 G4double lengthTemp = 0;
190 G4int cellId=0;
191 G4int layerId = touchable->GetVolume(1)->GetCopyNo();
192 if(volume->IsReplicated()){
193 cellId = touchable->GetReplicaNumber();
194 }else{
195 cellId=touchable->GetVolume(0)->GetCopyNo();
196 }
197 if(layerId==18&&(cellId==27||cellId==42))return false;
198
200
201
202 if(layerId >= 36) layerId = 36 + (layerId-36)/2;
203 }
204
205 G4double halfLayerLength=mdcGeomSvc->
Layer(layerId)->
Length()/2.;
206 if(((fabs(pointIn.z())-halfLayerLength)>-7.)
207 &&((fabs(pointOut.z())-halfLayerLength)>-7.))return false;
208
209 G4int trackID= gTrack->GetTrackID();
210 G4int truthID, g4TrackID;
212
213 G4double theta=gTrack->GetMomentumDirection().theta();
214
215 G4ThreeVector hitPosition=0;
216 G4double transferT=0;
217 driftD =
Distance(layerId,cellId,pointIn,pointOut,hitPosition,transferT);
218
219 G4double posPhi, wirePhi;
220 posPhi=hitPosition.phi();
221 if(posPhi<0)posPhi += 2*
pi;
222 wirePhi=mdcGeoPointer->
SignalWire(layerId,cellId).
Phi(hitPosition.z());
223
224 G4int posFlag;
225 if(posPhi<=wirePhi){
226 posFlag = 0;
227 }else{
228 posFlag = 1;
229 }
230
231 if(posPhi < 1. && wirePhi > 5.)posFlag = 1;
232 if(posPhi > 5. && wirePhi < 1.)posFlag = 0;
233
234 G4ThreeVector hitLine=pointOut-pointIn;
235 G4double enterAngle=hitLine.phi()-wirePhi;
236 while(enterAngle<-
pi/2.)enterAngle+=
pi;
237 while(enterAngle>
pi/2.)enterAngle-=
pi;
238
240 G4double betaGamma=aStep->GetPreStepPoint()->GetBeta() * aStep->GetPreStepPoint()->GetGamma();
241 if(betaGamma<0.01)return false;
242
243
244 G4double eCount=dedxSample(betaGamma,
charge, theta);
245 edep=eCount;
246 }
247
250
254 newHit->
SetPos(hitPosition);
259
260
262
263 driftT=mdcCalPointer->
D2T(driftD);
264 globalT+=transferT;
265 driftT+=globalT;
266
269
270 if (hitPointer[layerId][cellId] == -1) {
271 hitsCollection->insert(newHit);
272 G4int NbHits = hitsCollection->entries();
273 hitPointer[layerId][cellId]=NbHits-1;
274 }
275 else
276 {
277 G4int pointer=hitPointer[layerId][cellId];
278 if (g4TrackID == trackID) {
279 G4double preDriftT=(*hitsCollection)[pointer]->GetDriftT();
280 }
281
282 G4double preDriftT = (*hitsCollection)[pointer]->GetDriftT();
283 if (driftT < preDriftT) {
284 (*hitsCollection)[pointer]->SetTrackID(truthID);
285
286 (*hitsCollection)[pointer]->SetDriftD(driftD);
287 (*hitsCollection)[pointer]->SetDriftT(driftT);
288 (*hitsCollection)[pointer]->SetPos(hitPosition);
289 (*hitsCollection)[pointer]->SetGlobalT(globalT);
290 (*hitsCollection)[pointer]->SetTheta(theta);
291 (*hitsCollection)[pointer]->SetPosFlag(posFlag);
292 (*hitsCollection)[pointer]->SetEnterAngle(enterAngle);
293 }
294
295 delete newHit;
296 }
297
298
299 if(truthCollection){
300 if(g4TrackID==trackID){
301 G4int pointer=truthPointer[layerId][cellId];
302 if(pointer==-1){
308 truthHit->
SetPos (hitPosition);
315
316 truthCollection->insert(truthHit);
317 G4int NbHits = truthCollection->entries();
318 truthPointer[layerId][cellId]=NbHits-1;
319 }
320 else {
321 if(truthID == (*truthCollection)[pointer]->GetTrackID()){
322 G4double preDriftT=(*truthCollection)[pointer]->GetDriftT();
323 if(driftT<preDriftT){
324 (*truthCollection)[pointer]->SetDriftD(driftD);
325 (*truthCollection)[pointer]->SetDriftT(driftT);
326 (*truthCollection)[pointer]->SetPos(hitPosition);
327 (*truthCollection)[pointer]->SetGlobalT(globalT);
328 (*truthCollection)[pointer]->SetTheta(theta);
329 (*truthCollection)[pointer]->SetPosFlag(posFlag);
330 (*truthCollection)[pointer]->SetEnterAngle(enterAngle);
331 }
332 edepTemp=(*truthCollection)[pointer]->GetEdep();
333 (*truthCollection)[pointer]->SetEdep(edepTemp+edep);
334 } else {
340 truthHit->
SetPos(hitPosition);
347
348 truthCollection->insert(truthHit);
349 G4int NbHits = truthCollection->entries();
350 truthPointer[layerId][cellId]=NbHits-1;
351 }
352 }
353 }
354 }
355
356
357
358
359 return true;
360}
double D2T(double driftDNew)
void SetHitPointer(BesMdcHit *hit)
BesMdcWire SignalWire(int, int)
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