68 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits" << G4endl;
72 int nParticleEncoding=-1;
73 float fKineticEnergy=0.0;
74 float fEnergyDeposit=0.0;
81 float fGlobalTime=0.0;
87 bool bIsSIDAuxVSID=
false;
90 G4Track* pTrack = pStep->GetTrack();
91 G4ParticleDefinition* pParticleDefinition = pTrack->GetDefinition();
92 G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
93 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
94 G4ThreeVector PreStepPointPos = pPreStepPoint->GetPosition();
95 G4ThreeVector PostStepPointPos = pPostStepPoint->GetPosition();
97 nTrackID=pTrack->GetTrackID();
98 fKineticEnergy = pPreStepPoint->GetKineticEnergy();
99 fEnergyDeposit = pStep->GetTotalEnergyDeposit();
101 fPreStepX = PreStepPointPos.x();
102 fPreStepY = PreStepPointPos.y();
103 fPreStepZ = PreStepPointPos.z();
104 fPostStepX = PostStepPointPos.x();
105 fPostStepY = PostStepPointPos.y();
106 fPostStepZ = PostStepPointPos.z();
107 nParticleEncoding = pParticleDefinition->GetPDGEncoding();
108 fGlobalTime = pStep->GetPreStepPoint()->GetGlobalTime()/CLHEP::picosecond;
111 G4TouchableHandle touch1 = pPreStepPoint->GetTouchableHandle();
112 G4VPhysicalVolume* volume = touch1->GetVolume();
113 G4String VolumeName = volume->GetName();
121 G4cout <<
"hit volume name is " << VolumeName << G4endl;
123 G4cout <<
"global, x_pre: " << fPreStepX <<
", y_pre: " << fPreStepY <<
", z_pre: " << fPreStepZ << G4endl;
124 G4cout <<
"global, x_post: " << fPostStepX <<
", y_post: " << fPostStepY <<
", z_post: " << fPostStepZ << G4endl;
129 memset(&szbuff[0],0,
sizeof(szbuff));
130 strncpy(szbuff,VolumeName.data(),
sizeof(szbuff));
131 szbuff[
sizeof(szbuff)-1] =
'\0';
132 ppv1=strchr(szbuff,
'[');
133 ppv2=strchr(szbuff,
']');
135 G4cout <<
"ERROR: Invalid format of volume name " << VolumeName << G4endl;
140 nStationID=10*(szbuff[3]-0x30)+(szbuff[4]-0x30);
141 nDetectorID=atoi(ppv1+1);
146#if G4VERSION_NUMBER < 1100
147 if (VolumeName.contains(
"SIDSensor") || (bIsSIDAuxVSID=VolumeName.contains(
"SIDVacuumSensor"))){
149 if (G4StrUtil::contains(VolumeName,
"SIDSensor") || (bIsSIDAuxVSID=G4StrUtil::contains(VolumeName,
"SIDVacuumSensor"))){
152 if(!bIsSIDAuxVSID && !(fEnergyDeposit>0.0))
160 m_HitColl->Emplace(
m_nHitID,nTrackID,nParticleEncoding,fKineticEnergy,fEnergyDeposit,
161 fPreStepX,fPreStepY,fPreStepZ,fPostStepX,fPostStepY,fPostStepZ,
162 fGlobalTime,nStationID,nDetectorID,bIsSIDAuxVSID,-1,-1);
167 if(
m_HitColl->HasReachedLimit(nStationID))
return 1;
170 const G4TouchableHistory* myTouch =
static_cast<const G4TouchableHistory*
>(pPreStepPoint->GetTouchable());
175 const G4AffineTransform transformation = myTouch->GetHistory()->GetTopTransform();
176 const G4ThreeVector localPosition_pre = transformation.TransformPoint(PreStepPointPos);
177 const G4ThreeVector localPosition_post = transformation.TransformPoint(PostStepPointPos);
179 const G4ThreeVector normpX( 1., 0., 0.);
180 const G4ThreeVector normnX(-1., 0., 0.);
181 const G4ThreeVector normpY( 0., 1., 0.);
182 const G4ThreeVector normnY( 0.,-1., 0.);
183 const G4ThreeVector normpZ( 0., 0., 1.);
184 const G4ThreeVector normnZ( 0., 0.,-1.);
186 G4double BarpX =
static_cast<G4ReflectedSolid *
>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normpX);
187 G4double BarnX =
static_cast<G4ReflectedSolid *
>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normnX);
188 G4double BarpY =
static_cast<G4ReflectedSolid *
>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normpY);
189 G4double BarnY =
static_cast<G4ReflectedSolid *
>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normnY);
190 G4double BarpZ =
static_cast<G4ReflectedSolid *
>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normpZ);
191 G4double BarnZ =
static_cast<G4ReflectedSolid *
>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normnZ);
193 G4double BarHalfX = .5 * (BarpX+BarnX);
194 G4double BarHalfY = .5 * (BarpY+BarnY);
195 G4double BarHalfZ = .5 * (BarpZ+BarnZ);
199 G4double x_det = BarHalfX + localPosition_pre.x();
200 G4double y_det = BarHalfY + localPosition_pre.y();
201 G4double z_det = BarHalfZ + localPosition_pre.z();
203 G4double x_det_post = BarHalfX + localPosition_post.x();
204 G4double y_det_post = BarHalfY + localPosition_post.y();
205 G4double z_det_post = BarHalfZ + localPosition_post.z();
208 G4double track_length_XY = sqrt(pow(x_det_post-x_det,2)+pow(y_det_post-y_det,2));
210 G4double angle_phi_global = atan2(fPostStepY-fPreStepY,fPostStepX-fPreStepX);
211 G4double angle_phi = atan2(y_det_post-y_det,x_det_post-x_det);
214 G4double tan_phi = (y_det_post-y_det)/(x_det_post-x_det);
218 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: local, x_det: " << x_det <<
", y_det: " << y_det <<
", z_det: " << z_det << G4endl;
219 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: local, x_det_post: " << x_det_post <<
", y_det_post: " << y_det_post <<
", z_det_post: " << z_det_post << G4endl;
220 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_phi_global in -pi:pi = " << angle_phi_global << G4endl;
222 if (angle_phi_global < 0.) angle_phi_global = 2.*
M_PI + angle_phi_global;
225 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_phi_global in 0:2pi = " << angle_phi_global << G4endl;
226 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_phi in -pi:pi = " << angle_phi << G4endl;
228 if (angle_phi < 0.) angle_phi = 2.*
M_PI + angle_phi;
231 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_phi in 0:2pi = " << angle_phi << G4endl;
238 signed int sign_pixels_x = 0;
239 signed int sign_pixels_y = 0;
241 int number_pixels_x = (int) (std::abs((post_pixel_x-pre_pixel_x)*1.0));
242 int number_pixels_y = (int) (std::abs((post_pixel_y-pre_pixel_y)*1.0));
244 if (number_pixels_x > 0)
246 sign_pixels_x = (post_pixel_x-pre_pixel_x)/number_pixels_x;
248 if (number_pixels_y > 0)
250 sign_pixels_y = (post_pixel_y-pre_pixel_y)/number_pixels_y;
258 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: pre: pixel["<< pre_pixel_x - n_death_pixels <<
"]["<< pre_pixel_y - n_lower_pixels <<
"] was hit" << G4endl;
259 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: post: pixel["<< post_pixel_x - n_death_pixels<<
"]["<< post_pixel_y - n_lower_pixels<<
"] was hit" << G4endl;
260 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: chip's length in x: " << 2.*BarHalfX <<
", in y: " << 2.*BarHalfY <<
", in z: " << 2.*BarHalfZ << G4endl;
262 signed int first = -1;
264 G4double x_next_pixel = -9999.;
265 G4double y_next_pixel = -9999.;
267 G4double x_border = -9999.;
268 G4double y_border = -9999.;
270 G4double pixel_track_length_XY = -1.;
271 G4double angle_2pixel = 10.;
275 int act_pixel_x = pre_pixel_x;
276 int act_pixel_y = pre_pixel_y;
283 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual pixel in x = " << act_pixel_x <<
", in y = " << act_pixel_y << G4endl;
284 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual compensated pixel in x = " << act_pixel_x - n_death_pixels <<
", in y = " << act_pixel_y - n_lower_pixels << G4endl;
286 if ((number_pixels_x == 0) && (number_pixels_y == 0))
291 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: pre and post in the same pixel " << G4endl;
293 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))
295 m_HitColl->Emplace(
m_nHitID,nTrackID,nParticleEncoding,fKineticEnergy,fEnergyDeposit,
296 fPreStepX,fPreStepY,fPreStepZ,fPostStepX,fPostStepY,fPostStepZ,
297 fGlobalTime,nStationID,nDetectorID,bIsSIDAuxVSID,
298 (pre_pixel_y - n_lower_pixels - 1),
299 (pre_pixel_x - n_death_pixels - 1));
302 else if(verboseLevel>5)
304 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: hit outside of pixel's sensitive area " << G4endl;
311 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: pre and post in diferent pixels " << G4endl;
315 while ( (number_pixels_x >= 0) && (number_pixels_y >= 0) )
318 if ((angle_phi >= 0.) && (angle_phi < M_PI_2))
322 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
324 if (angle_2pixel < 0.) angle_2pixel = 2*
M_PI + angle_2pixel;
325 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_2pixel in 0:2pi = " << angle_2pixel << G4endl; }
327 if (angle_2pixel > angle_phi)
337 else if ((angle_phi >= M_PI_2) && (angle_phi <
M_PI))
341 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
343 if (angle_2pixel < 0.) angle_2pixel = 2*
M_PI + angle_2pixel;
344 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_2pixel in 0:2pi = " << angle_2pixel << G4endl; }
346 if (angle_2pixel > angle_phi)
356 else if ((angle_phi >=
M_PI) && (angle_phi < 3.*M_PI_2))
360 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: next pixel corner, x = " << x_next_pixel <<
", y =" << y_next_pixel << G4endl; }
362 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
364 if (angle_2pixel < 0.) angle_2pixel = 2*
M_PI + angle_2pixel;
365 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_2pixel in 0:2pi = " << angle_2pixel << G4endl; }
367 if (angle_2pixel > angle_phi)
377 else if ((angle_phi >= 3.*M_PI_2) && (angle_phi < 2.*
M_PI))
381 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
383 if (angle_2pixel < 0.) angle_2pixel = 2*
M_PI + angle_2pixel;
384 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: angle_2pixel in 0:2pi = " << angle_2pixel << G4endl; }
386 if (angle_2pixel > angle_phi)
398 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: something is wrong here!!! " << G4endl; }
403 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: something is wrong here!!! " << G4endl; }
404 throw std::runtime_error(
"AFP_SiSensitiveDetector::ProcessHits: something is wrong here");
409 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual pixel in x = " << act_pixel_x <<
", in y = " << act_pixel_y << G4endl;
410 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual compensated pixel in x = " << act_pixel_x - n_death_pixels <<
", in y = " << act_pixel_y - n_lower_pixels << G4endl;
416 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: cross is x, " << G4endl; }
417 x_border = x_next_pixel;
419 if ((sign_pixels_x >= 0) && (x_border > x_det_post)) x_border = x_det_post;
420 if ((sign_pixels_x < 0) && (x_border < x_det_post)) x_border = x_det_post;
422 y_border = tan_phi*(x_border-x_det) + y_det;
424 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))
426 pixel_track_length_XY = sqrt(pow(x_border-x_det,2)+pow(y_border-y_det,2));
430 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: overall energy = " << fEnergyDeposit << G4endl;
431 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: track XY length = " << track_length_XY << G4endl;
432 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual XY length = " << pixel_track_length_XY << G4endl;
433 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: deposited energy = " << fEnergyDeposit*(pixel_track_length_XY/track_length_XY) << G4endl;
438 fEnergyDeposit*(pixel_track_length_XY/track_length_XY),
439 fPreStepX,fPreStepY,fPreStepZ,fPostStepX,fPostStepY,fPostStepZ,
440 fGlobalTime,nStationID,nDetectorID,bIsSIDAuxVSID,
441 (act_pixel_y - n_lower_pixels - 1),
442 (act_pixel_x - n_death_pixels - 1));
444 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 "
445 << fEnergyDeposit*(pixel_track_length_XY/track_length_XY) << G4endl; }
454 number_pixels_x = number_pixels_x - 1;
456 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: remaining number of pixels in x = " << number_pixels_x <<
", in y = " << number_pixels_y << G4endl; }
458 act_pixel_x = act_pixel_x + sign_pixels_x;
464 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: cross is y, " << G4endl; }
465 y_border = y_next_pixel;
467 if ((sign_pixels_y >= 0) && (y_border > y_det_post)) y_border = y_det_post;
468 if ((sign_pixels_y < 0) && (y_border < y_det_post)) y_border = y_det_post;
470 x_border = (y_border-y_det)/tan_phi + x_det;
472 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))
474 pixel_track_length_XY = sqrt(pow(x_border-x_det,2)+pow(y_border-y_det,2));
478 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: overall energy = " << fEnergyDeposit << G4endl;
479 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: track XY length = " << track_length_XY << G4endl;
480 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: actual XY length = " << pixel_track_length_XY << G4endl;
481 G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: deposited energy = " << fEnergyDeposit*(pixel_track_length_XY/track_length_XY) << G4endl;
486 fEnergyDeposit*(pixel_track_length_XY/track_length_XY),
487 fPreStepX,fPreStepY,fPreStepZ,fPostStepX,fPostStepY,fPostStepZ,
488 fGlobalTime,nStationID,nDetectorID,bIsSIDAuxVSID,
489 (act_pixel_y - n_lower_pixels - 1),
490 (act_pixel_x - n_death_pixels - 1));
492 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 "
493 << fEnergyDeposit*(pixel_track_length_XY/track_length_XY) << G4endl; }
502 number_pixels_y = number_pixels_y - 1;
504 if(verboseLevel>5) { G4cout <<
"AFP_SiDSensitiveDetector::ProcessHits: remaining number of pixels in x = " << number_pixels_x <<
", in y = " << number_pixels_y << G4endl; }
507 act_pixel_y = act_pixel_y + sign_pixels_y;