73 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits" << G4endl;
77 int nParticleEncoding=-1;
78 float fKineticEnergy=0.0;
79 float fEnergyDeposit=0.0;
86 float fGlobalTime=0.0;
92 bool bIsSIDAuxVSID=
false;
95 G4Track* pTrack = pStep->GetTrack();
96 G4ParticleDefinition* pParticleDefinition = pTrack->GetDefinition();
97 G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
98 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
99 G4ThreeVector PreStepPointPos = pPreStepPoint->GetPosition();
100 G4ThreeVector PostStepPointPos = pPostStepPoint->GetPosition();
102 nTrackID=pTrack->GetTrackID();
103 fKineticEnergy = pPreStepPoint->GetKineticEnergy();
104 fEnergyDeposit = pStep->GetTotalEnergyDeposit();
106 fPreStepX = PreStepPointPos.x();
107 fPreStepY = PreStepPointPos.y();
108 fPreStepZ = PreStepPointPos.z();
109 fPostStepX = PostStepPointPos.x();
110 fPostStepY = PostStepPointPos.y();
111 fPostStepZ = PostStepPointPos.z();
112 nParticleEncoding = pParticleDefinition->GetPDGEncoding();
116 G4TouchableHandle touch1 = pPreStepPoint->GetTouchableHandle();
117 G4VPhysicalVolume* volume = touch1->GetVolume();
118 G4String VolumeName = volume->GetName();
126 G4cout <<
"hit volume name is " << VolumeName << G4endl;
128 G4cout <<
"global, x_pre: " << fPreStepX <<
", y_pre: " << fPreStepY <<
", z_pre: " << fPreStepZ << G4endl;
129 G4cout <<
"global, x_post: " << fPostStepX <<
", y_post: " << fPostStepY <<
", z_post: " << fPostStepZ << G4endl;
134 memset(&szbuff[0],0,
sizeof(szbuff));
135 strncpy(szbuff,VolumeName.data(),
sizeof(szbuff));
136 szbuff[
sizeof(szbuff)-1] =
'\0';
137 ppv1=strchr(szbuff,
'[');
138 ppv2=strchr(szbuff,
']');
140 G4cout <<
"ERROR: Invalid format of volume name " << VolumeName << G4endl;
145 nStationID=10*(szbuff[3]-0x30)+(szbuff[4]-0x30);
146 nDetectorID=
atoi(ppv1+1);
151 #if G4VERSION_NUMBER < 1100
152 if (VolumeName.contains(
"SIDSensor") || (bIsSIDAuxVSID=VolumeName.contains(
"SIDVacuumSensor"))){
157 if(!bIsSIDAuxVSID && !(fEnergyDeposit>0.0))
165 m_HitColl->Emplace(
m_nHitID,nTrackID,nParticleEncoding,fKineticEnergy,fEnergyDeposit,
166 fPreStepX,fPreStepY,fPreStepZ,fPostStepX,fPostStepY,fPostStepZ,
167 fGlobalTime,nStationID,nDetectorID,bIsSIDAuxVSID,-1,-1);
179 const G4TouchableHistory* myTouch =
static_cast<const G4TouchableHistory*
>(pPreStepPoint->GetTouchable());
184 const G4AffineTransform transformation = myTouch->GetHistory()->GetTopTransform();
185 const G4ThreeVector localPosition_pre = transformation.TransformPoint(PreStepPointPos);
186 const G4ThreeVector localPosition_post = transformation.TransformPoint(PostStepPointPos);
188 const G4ThreeVector normpX( 1., 0., 0.);
189 const G4ThreeVector normnX(-1., 0., 0.);
190 const G4ThreeVector normpY( 0., 1., 0.);
191 const G4ThreeVector normnY( 0.,-1., 0.);
192 const G4ThreeVector normpZ( 0., 0., 1.);
193 const G4ThreeVector normnZ( 0., 0.,-1.);
195 G4double BarpX = ((G4ReflectedSolid *)(myTouch->GetSolid()))->DistanceToOut(localPosition_pre, normpX);
196 G4double BarnX = ((G4ReflectedSolid *)(myTouch->GetSolid()))->DistanceToOut(localPosition_pre, normnX);
197 G4double BarpY = ((G4ReflectedSolid *)(myTouch->GetSolid()))->DistanceToOut(localPosition_pre, normpY);
198 G4double BarnY = ((G4ReflectedSolid *)(myTouch->GetSolid()))->DistanceToOut(localPosition_pre, normnY);
199 G4double BarpZ = ((G4ReflectedSolid *)(myTouch->GetSolid()))->DistanceToOut(localPosition_pre, normpZ);
200 G4double BarnZ = ((G4ReflectedSolid *)(myTouch->GetSolid()))->DistanceToOut(localPosition_pre, normnZ);
202 G4double BarHalfX = .5 * (BarpX+BarnX);
203 G4double BarHalfY = .5 * (BarpY+BarnY);
204 G4double BarHalfZ = .5 * (BarpZ+BarnZ);
208 G4double x_det = BarHalfX + localPosition_pre.x();
209 G4double y_det = BarHalfY + localPosition_pre.y();
210 G4double z_det = BarHalfZ + localPosition_pre.z();
212 G4double x_det_post = BarHalfX + localPosition_post.x();
213 G4double y_det_post = BarHalfY + localPosition_post.y();
214 G4double z_det_post = BarHalfZ + localPosition_post.z();
217 G4double track_length_XY = sqrt(
pow(x_det_post-x_det,2)+
pow(y_det_post-y_det,2));
219 G4double angle_phi_global = atan2(fPostStepY-fPreStepY,fPostStepX-fPreStepX);
220 G4double angle_phi = atan2(y_det_post-y_det,x_det_post-x_det);
223 G4double tan_phi = (y_det_post-y_det)/(x_det_post-x_det);
227 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: local, x_det: " << x_det <<
", y_det: " << y_det <<
", z_det: " << z_det << G4endl;
228 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: local, x_det_post: " << x_det_post <<
", y_det_post: " << y_det_post <<
", z_det_post: " << z_det_post << G4endl;
229 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_phi_global in -pi:pi = " << angle_phi_global << G4endl;
231 if (angle_phi_global < 0.) angle_phi_global = 2.*
M_PI + angle_phi_global;
234 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_phi_global in 0:2pi = " << angle_phi_global << G4endl;
235 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_phi in -pi:pi = " << angle_phi << G4endl;
237 if (angle_phi < 0.) angle_phi = 2.*
M_PI + angle_phi;
240 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_phi in 0:2pi = " << angle_phi << G4endl;
247 signed int sign_pixels_x = 0;
248 signed int sign_pixels_y = 0;
250 int number_pixels_x = (
int) (std::abs((post_pixel_x-pre_pixel_x)*1.0));
251 int number_pixels_y = (
int) (std::abs((post_pixel_y-pre_pixel_y)*1.0));
253 if (number_pixels_x > 0)
255 sign_pixels_x = (post_pixel_x-pre_pixel_x)/number_pixels_x;
257 if (number_pixels_y > 0)
259 sign_pixels_y = (post_pixel_y-pre_pixel_y)/number_pixels_y;
267 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: pre: pixel["<< pre_pixel_x - n_death_pixels <<
"]["<< pre_pixel_y - n_lower_pixels <<
"] was hit" << G4endl;
268 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: post: pixel["<< post_pixel_x - n_death_pixels<<
"]["<< post_pixel_y - n_lower_pixels<<
"] was hit" << G4endl;
269 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: chip's length in x: " << 2.*BarHalfX <<
", in y: " << 2.*BarHalfY <<
", in z: " << 2.*BarHalfZ << G4endl;
271 signed int first = -1;
273 G4double x_next_pixel = -9999.;
274 G4double y_next_pixel = -9999.;
276 G4double x_border = -9999.;
277 G4double y_border = -9999.;
279 G4double pixel_track_length_XY = -1.;
280 G4double angle_2pixel = 10.;
284 int act_pixel_x = pre_pixel_x;
285 int act_pixel_y = pre_pixel_y;
292 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual pixel in x = " << act_pixel_x <<
", in y = " << act_pixel_y << G4endl;
293 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual compensated pixel in x = " << act_pixel_x - n_death_pixels <<
", in y = " << act_pixel_y - n_lower_pixels << G4endl;
295 if ((number_pixels_x == 0) && (number_pixels_y == 0))
300 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: pre and post in the same pixel " << G4endl;
302 if (( pre_pixel_y - n_lower_pixels <= 80) && (pre_pixel_x -n_death_pixels <= 336) && ( pre_pixel_y - n_lower_pixels > 0) && (pre_pixel_x - n_death_pixels > 0))
304 m_HitColl->Emplace(
m_nHitID,nTrackID,nParticleEncoding,fKineticEnergy,fEnergyDeposit,
305 fPreStepX,fPreStepY,fPreStepZ,fPostStepX,fPostStepY,fPostStepZ,
306 fGlobalTime,nStationID,nDetectorID,bIsSIDAuxVSID,
307 (pre_pixel_y - n_lower_pixels - 1),
308 (pre_pixel_x - n_death_pixels - 1));
313 else if(verboseLevel>5)
315 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: hit outside of pixel's sensitive area " << G4endl;
322 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: pre and post in diferent pixels " << G4endl;
326 while ( (number_pixels_x >= 0) && (number_pixels_y >= 0) )
329 if ((angle_phi >= 0.) && (angle_phi < M_PI_2))
333 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
335 if (angle_2pixel < 0.) angle_2pixel = 2*
M_PI + angle_2pixel;
336 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_2pixel in 0:2pi = " << angle_2pixel << G4endl; }
338 if (angle_2pixel > angle_phi)
348 else if ((angle_phi >= M_PI_2) && (angle_phi <
M_PI))
352 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
354 if (angle_2pixel < 0.) angle_2pixel = 2*
M_PI + angle_2pixel;
355 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_2pixel in 0:2pi = " << angle_2pixel << G4endl; }
357 if (angle_2pixel > angle_phi)
367 else if ((angle_phi >=
M_PI) && (angle_phi < 3.*M_PI_2))
371 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: next pixel corner, x = " << x_next_pixel <<
", y =" << y_next_pixel << G4endl; }
373 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
375 if (angle_2pixel < 0.) angle_2pixel = 2*
M_PI + angle_2pixel;
376 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_2pixel in 0:2pi = " << angle_2pixel << G4endl; }
378 if (angle_2pixel > angle_phi)
388 else if ((angle_phi >= 3.*M_PI_2) && (angle_phi < 2.*
M_PI))
392 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
394 if (angle_2pixel < 0.) angle_2pixel = 2*
M_PI + angle_2pixel;
395 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_2pixel in 0:2pi = " << angle_2pixel << G4endl; }
397 if (angle_2pixel > angle_phi)
409 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: something is wrong here!!! " << G4endl; }
414 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: something is wrong here!!! " << G4endl; }
415 throw std::runtime_error(
"AFP_SiSensitiveDetector::ProcessHits: something is wrong here");
420 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual pixel in x = " << act_pixel_x <<
", in y = " << act_pixel_y << G4endl;
421 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual compensated pixel in x = " << act_pixel_x - n_death_pixels <<
", in y = " << act_pixel_y - n_lower_pixels << G4endl;
427 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: cross is x, " << G4endl; }
428 x_border = x_next_pixel;
430 if ((sign_pixels_x >= 0) && (x_border > x_det_post)) x_border = x_det_post;
431 if ((sign_pixels_x < 0) && (x_border < x_det_post)) x_border = x_det_post;
433 y_border = tan_phi*(x_border-x_det) + y_det;
435 if (( act_pixel_y - n_lower_pixels <= 80) && (act_pixel_x -n_death_pixels <= 336) && ( act_pixel_y - n_lower_pixels > 0) && (act_pixel_x - n_death_pixels > 0))
437 pixel_track_length_XY = sqrt(
pow(x_border-x_det,2)+
pow(y_border-y_det,2));
441 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: overall energy = " << fEnergyDeposit << G4endl;
442 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: track XY length = " << track_length_XY << G4endl;
443 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual XY length = " << pixel_track_length_XY << G4endl;
444 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: deposited energy = " << fEnergyDeposit*(pixel_track_length_XY/track_length_XY) << G4endl;
449 fEnergyDeposit*(pixel_track_length_XY/track_length_XY),
450 fPreStepX,fPreStepY,fPreStepZ,fPostStepX,fPostStepY,fPostStepZ,
451 fGlobalTime,nStationID,nDetectorID,bIsSIDAuxVSID,
452 (act_pixel_y - n_lower_pixels - 1),
453 (act_pixel_x - n_death_pixels - 1));
455 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits:pixel["<< act_pixel_x - n_death_pixels <<
"]["<< act_pixel_y - n_lower_pixels <<
"] will be stored, with energy "
456 << fEnergyDeposit*(pixel_track_length_XY/track_length_XY) << G4endl; }
467 number_pixels_x = number_pixels_x - 1;
469 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: remaining number of pixels in x = " << number_pixels_x <<
", in y = " << number_pixels_y << G4endl; }
471 act_pixel_x = act_pixel_x + sign_pixels_x;
477 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: cross is y, " << G4endl; }
478 y_border = y_next_pixel;
480 if ((sign_pixels_y >= 0) && (y_border > y_det_post)) y_border = y_det_post;
481 if ((sign_pixels_y < 0) && (y_border < y_det_post)) y_border = y_det_post;
483 x_border = (y_border-y_det)/tan_phi + x_det;
485 if (( act_pixel_y - n_lower_pixels <= 80) && (act_pixel_x -n_death_pixels <= 336) && ( act_pixel_y - n_lower_pixels > 0) && (act_pixel_x - n_death_pixels > 0))
487 pixel_track_length_XY = sqrt(
pow(x_border-x_det,2)+
pow(y_border-y_det,2));
491 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: overall energy = " << fEnergyDeposit << G4endl;
492 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: track XY length = " << track_length_XY << G4endl;
493 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual XY length = " << pixel_track_length_XY << G4endl;
494 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: deposited energy = " << fEnergyDeposit*(pixel_track_length_XY/track_length_XY) << G4endl;
499 fEnergyDeposit*(pixel_track_length_XY/track_length_XY),
500 fPreStepX,fPreStepY,fPreStepZ,fPostStepX,fPostStepY,fPostStepZ,
501 fGlobalTime,nStationID,nDetectorID,bIsSIDAuxVSID,
502 (act_pixel_y - n_lower_pixels - 1),
503 (act_pixel_x - n_death_pixels - 1));
505 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits:pixel["<< act_pixel_x - n_death_pixels <<
"]["<< act_pixel_y - n_lower_pixels <<
"] will be stored, with energy "
506 << fEnergyDeposit*(pixel_track_length_XY/track_length_XY) << G4endl; }
517 number_pixels_y = number_pixels_y - 1;
519 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: remaining number of pixels in x = " << number_pixels_x <<
", in y = " << number_pixels_y << G4endl; }
522 act_pixel_y = act_pixel_y + sign_pixels_y;