126{
127 G4Track* gTrack = aStep->GetTrack() ;
128
129 G4double globalT=gTrack->GetGlobalTime();
130 if(std::isnan(globalT)){
131 G4cout<<"MdcSD:error, globalT is nan "<<G4endl;
132 return false;
133 }
134 if(globalT > 2000)return false;
135
136
137 G4int
charge = gTrack->GetDefinition()->GetPDGCharge();
138 if (
charge == 0)
return false;
139
140
141 G4double stepLength=aStep->GetStepLength();
142 if(stepLength==0){
143
144 return false;
145 }
146
147 G4double edep = aStep->GetTotalEnergyDeposit() / stepLength;
148 if(edep==0.) return false;
149
150
151 G4StepPoint* prePoint = aStep->GetPreStepPoint() ;
152 G4StepPoint* postPoint = aStep->GetPostStepPoint() ;
153
154
155 G4ThreeVector pointIn = prePoint->GetPosition();
156 G4ThreeVector pointOut = postPoint->GetPosition();
157
158
159 const G4VTouchable *touchable = prePoint->GetTouchable();
160 G4VPhysicalVolume *volume = touchable->GetVolume(0);
161
162 G4double driftD = 0;
163 G4double driftT = 0;
164 G4double edepTemp = 0;
165 G4double lengthTemp = 0;
166 G4int cellId=0;
167 G4int layerId = touchable->GetVolume(1)->GetCopyNo();
168 if(volume->IsReplicated()){
169 cellId = touchable->GetReplicaNumber();
170 }else{
171 cellId=touchable->GetVolume(0)->GetCopyNo();
172 }
173 if(layerId==18&&(cellId==27||cellId==42))return false;
174
176
177
178 if(layerId >= 36) layerId = 36 + (layerId-36)/2;
179 }
180
181 G4double halfLayerLength=mdcGeomSvc->
Layer(layerId)->
Length()/2.;
182 if(((fabs(pointIn.z())-halfLayerLength)>-7.)
183 &&((fabs(pointOut.z())-halfLayerLength)>-7.))return false;
184
185 G4int trackID= gTrack->GetTrackID();
186 G4int truthID, g4TrackID;
188
189 G4double theta=gTrack->GetMomentumDirection().theta();
190
191 G4ThreeVector hitPosition(0,0,0);
192 G4double transferT=0;
193 driftD =
Distance(layerId,cellId,pointIn,pointOut,hitPosition,transferT);
194
195 G4double posPhi, wirePhi;
196 posPhi=hitPosition.phi();
197 if(posPhi<0)posPhi += 2*
pi;
198 wirePhi=mdcGeoPointer->
SignalWire(layerId,cellId).
Phi(hitPosition.z());
199
200 G4int posFlag;
201 if(posPhi<=wirePhi){
202 posFlag = 0;
203 }else{
204 posFlag = 1;
205 }
206
207 if(posPhi < 1. && wirePhi > 5.)posFlag = 1;
208 if(posPhi > 5. && wirePhi < 1.)posFlag = 0;
209
210 G4ThreeVector hitLine=pointOut-pointIn;
211 G4double enterAngle=hitLine.phi()-wirePhi;
212 while(enterAngle<-
pi/2.)enterAngle+=
pi;
213 while(enterAngle>
pi/2.)enterAngle-=
pi;
214
216 G4double betaGamma=aStep->GetPreStepPoint()->GetBeta() * aStep->GetPreStepPoint()->GetGamma();
217 if(betaGamma<0.01)return false;
218
219
220 G4double eCount=dedxSample(betaGamma,
charge, theta);
221 edep=eCount;
222 }
223
226
230 newHit->
SetPos(hitPosition);
235
236
238
239 driftT=mdcCalPointer->
D2T(driftD);
240 globalT+=transferT;
241 driftT+=globalT;
242
245
246 if (hitPointer[layerId][cellId] == -1) {
247 hitsCollection->insert(newHit);
248 G4int NbHits = hitsCollection->entries();
249 hitPointer[layerId][cellId]=NbHits-1;
250 }
251 else
252 {
253 G4int pointer=hitPointer[layerId][cellId];
254 if (g4TrackID == trackID) {
255 G4double preDriftT=(*hitsCollection)[pointer]->GetDriftT();
256 }
257
258 G4double preDriftT = (*hitsCollection)[pointer]->GetDriftT();
259 if (driftT < preDriftT) {
260 (*hitsCollection)[pointer]->SetTrackID(truthID);
261
262 (*hitsCollection)[pointer]->SetDriftD(driftD);
263 (*hitsCollection)[pointer]->SetDriftT(driftT);
264 (*hitsCollection)[pointer]->SetPos(hitPosition);
265 (*hitsCollection)[pointer]->SetGlobalT(globalT);
266 (*hitsCollection)[pointer]->SetTheta(theta);
267 (*hitsCollection)[pointer]->SetPosFlag(posFlag);
268 (*hitsCollection)[pointer]->SetEnterAngle(enterAngle);
269 }
270
271 delete newHit;
272 }
273
274
275 if(truthCollection){
276 if(g4TrackID==trackID){
277 G4int pointer=truthPointer[layerId][cellId];
278 if(pointer==-1){
284 truthHit->
SetPos (hitPosition);
291
292 truthCollection->insert(truthHit);
293 G4int NbHits = truthCollection->entries();
294 truthPointer[layerId][cellId]=NbHits-1;
295 }
296 else {
297 if(truthID == (*truthCollection)[pointer]->GetTrackID()){
298 G4double preDriftT=(*truthCollection)[pointer]->GetDriftT();
299 if(driftT<preDriftT){
300 (*truthCollection)[pointer]->SetDriftD(driftD);
301 (*truthCollection)[pointer]->SetDriftT(driftT);
302 (*truthCollection)[pointer]->SetPos(hitPosition);
303 (*truthCollection)[pointer]->SetGlobalT(globalT);
304 (*truthCollection)[pointer]->SetTheta(theta);
305 (*truthCollection)[pointer]->SetPosFlag(posFlag);
306 (*truthCollection)[pointer]->SetEnterAngle(enterAngle);
307 }
308 edepTemp=(*truthCollection)[pointer]->GetEdep();
309 (*truthCollection)[pointer]->SetEdep(edepTemp+edep);
310 } else {
316 truthHit->
SetPos(hitPosition);
323
324 truthCollection->insert(truthHit);
325 G4int NbHits = truthCollection->entries();
326 truthPointer[layerId][cellId]=NbHits-1;
327 }
328 }
329 }
330 }
331
332
333
334
335 return true;
336}
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