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