70{
71 if(verboseLevel>5)
72 {
73 G4cout << "AFP_SiDSensitiveDetector::ProcessHits" << G4endl;
74 }
75
76 int nTrackID=-1;
77 int nParticleEncoding=-1;
78 float fKineticEnergy=0.0;
79 float fEnergyDeposit=0.0;
80 float fPreStepX=0.0;
81 float fPreStepY=0.0;
82 float fPreStepZ=0.0;
83 float fPostStepX=0.0;
84 float fPostStepY=0.0;
85 float fPostStepZ=0.0;
86 float fGlobalTime=0.0;
87 int nStationID=-1;
88 int nDetectorID=-1;
89
90
91
92 bool bIsSIDAuxVSID=false;
93
94
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();
101
102 nTrackID=pTrack->GetTrackID();
103 fKineticEnergy = pPreStepPoint->GetKineticEnergy();
104 fEnergyDeposit = pStep->GetTotalEnergyDeposit();
105
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();
113 fGlobalTime = pStep->GetPreStepPoint()->GetGlobalTime()/CLHEP::picosecond;
114
115
116 G4TouchableHandle touch1 = pPreStepPoint->GetTouchableHandle();
117 G4VPhysicalVolume* volume = touch1->GetVolume();
118 G4String VolumeName = volume->GetName();
119
120
121
122
123
124 if(verboseLevel>5)
125 {
126 G4cout << "hit volume name is " << VolumeName << G4endl;
127
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;
130 }
131
132 char* ppv1, *ppv2;
133 char szbuff[32];
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,']');
139 if(!ppv2 || !ppv1){
140 G4cout << "ERROR: Invalid format of volume name " << VolumeName << G4endl;
141 return false;
142 }
143 else *ppv2='\0';
144
145 nStationID=10*(szbuff[3]-0x30)+(szbuff[4]-0x30);
146 nDetectorID=
atoi(ppv1+1);
147
149
151#if G4VERSION_NUMBER < 1100
152 if (VolumeName.contains("SIDSensor") || (bIsSIDAuxVSID=VolumeName.contains("SIDVacuumSensor"))){
153#else
154 if (G4StrUtil::contains(VolumeName, "SIDSensor") || (bIsSIDAuxVSID=G4StrUtil::contains(VolumeName, "SIDVacuumSensor"))){
155#endif
156
157 if(!bIsSIDAuxVSID && !(fEnergyDeposit>0.0))
158 {
159
160 }
161 else
162 {
163 if (bIsSIDAuxVSID)
164 {
165 m_HitColl->Emplace(
m_nHitID,nTrackID,nParticleEncoding,fKineticEnergy,fEnergyDeposit,
166 fPreStepX,fPreStepY,fPreStepZ,fPostStepX,fPostStepY,fPostStepZ,
167 fGlobalTime,nStationID,nDetectorID,bIsSIDAuxVSID,-1,-1);
168
169
170
171
172 }
173 else
174 {
175
177
178
179 const G4TouchableHistory* myTouch = static_cast<const G4TouchableHistory*>(pPreStepPoint->GetTouchable());
180
181
182
183
184 const G4AffineTransform transformation = myTouch->GetHistory()->GetTopTransform();
185 const G4ThreeVector localPosition_pre = transformation.TransformPoint(PreStepPointPos);
186 const G4ThreeVector localPosition_post = transformation.TransformPoint(PostStepPointPos);
187
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.);
194
195 G4double BarpX = static_cast<G4ReflectedSolid *>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normpX);
196 G4double BarnX = static_cast<G4ReflectedSolid *>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normnX);
197 G4double BarpY = static_cast<G4ReflectedSolid *>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normpY);
198 G4double BarnY = static_cast<G4ReflectedSolid *>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normnY);
199 G4double BarpZ = static_cast<G4ReflectedSolid *>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normpZ);
200 G4double BarnZ = static_cast<G4ReflectedSolid *>(myTouch->GetSolid())->DistanceToOut(localPosition_pre, normnZ);
201
202 G4double BarHalfX = .5 * (BarpX+BarnX);
203 G4double BarHalfY = .5 * (BarpY+BarnY);
204 G4double BarHalfZ = .5 * (BarpZ+BarnZ);
205
206
207
208 G4double x_det = BarHalfX + localPosition_pre.x();
209 G4double y_det = BarHalfY + localPosition_pre.y();
210 G4double z_det = BarHalfZ + localPosition_pre.z();
211
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();
215
216
217 G4double track_length_XY = sqrt(
pow(x_det_post-x_det,2)+
pow(y_det_post-y_det,2));
218
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);
221
222
223 G4double tan_phi = (y_det_post-y_det)/(x_det_post-x_det);
224
225 if(verboseLevel>5)
226 {
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;
230 }
231 if (angle_phi_global < 0.) angle_phi_global = 2.*
M_PI + angle_phi_global;
232 if(verboseLevel>5)
233 {
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;
236 }
237 if (angle_phi < 0.) angle_phi = 2.*
M_PI + angle_phi;
238 if(verboseLevel>5)
239 {
240 G4cout << "AFP_SiDSensitiveDetector::ProcessHits: angle_phi in 0:2pi = " << angle_phi << G4endl;
241 }
246
247 signed int sign_pixels_x = 0;
248 signed int sign_pixels_y = 0;
249
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));
252
253 if (number_pixels_x > 0)
254 {
255 sign_pixels_x = (post_pixel_x-pre_pixel_x)/number_pixels_x;
256 }
257 if (number_pixels_y > 0)
258 {
259 sign_pixels_y = (post_pixel_y-pre_pixel_y)/number_pixels_y;
260 }
261
264
265 if(verboseLevel>5)
266 {
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;
270 }
271 signed int first = -1;
272
273 G4double x_next_pixel = -9999.;
274 G4double y_next_pixel = -9999.;
275
276 G4double x_border = -9999.;
277 G4double y_border = -9999.;
278
279 G4double pixel_track_length_XY = -1.;
280 G4double angle_2pixel = 10.;
281
282
283
284 int act_pixel_x = pre_pixel_x;
285 int act_pixel_y = pre_pixel_y;
286
287
288
289
290 if(verboseLevel>5)
291 {
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;
294 }
295 if ((number_pixels_x == 0) && (number_pixels_y == 0))
296 {
297
298 if(verboseLevel>5)
299 {
300 G4cout << "AFP_SiDSensitiveDetector::ProcessHits: pre and post in the same pixel " << G4endl;
301 }
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))
303 {
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));
310
312 }
313 else if(verboseLevel>5)
314 {
315 G4cout << "AFP_SiDSensitiveDetector::ProcessHits: hit outside of pixel's sensitive area " << G4endl;
316 }
317 }
318 else
319 {
320 if(verboseLevel>5)
321 {
322 G4cout << "AFP_SiDSensitiveDetector::ProcessHits: pre and post in diferent pixels " << G4endl;
323 }
324
325
326 while ( (number_pixels_x >= 0) && (number_pixels_y >= 0) )
327 {
328
329 if ((angle_phi >= 0.) && (angle_phi < M_PI_2))
330 {
333 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
334
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; }
337
338 if (angle_2pixel > angle_phi)
339 {
341 }
342 else
343 {
345 }
346 }
347
348 else if ((angle_phi >= M_PI_2) && (angle_phi <
M_PI))
349 {
352 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
353
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; }
356
357 if (angle_2pixel > angle_phi)
358 {
360 }
361 else
362 {
364 }
365 }
366
367 else if ((angle_phi >=
M_PI) && (angle_phi < 3.*M_PI_2))
368 {
371 if(verboseLevel>5) { G4cout << "AFP_SiDSensitiveDetector::ProcessHits: next pixel corner, x = " << x_next_pixel << ", y =" << y_next_pixel << G4endl; }
372
373 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
374
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; }
377
378 if (angle_2pixel > angle_phi)
379 {
381 }
382 else
383 {
385 }
386 }
387
388 else if ((angle_phi >= 3.*M_PI_2) && (angle_phi < 2.*
M_PI))
389 {
392 angle_2pixel = atan2(y_next_pixel-y_det,x_next_pixel-x_det);
393
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; }
396
397 if (angle_2pixel > angle_phi)
398 {
400 }
401 else
402 {
404 }
405 }
406
407 else
408 {
409 if(verboseLevel>5) { G4cout << "AFP_SiDSensitiveDetector::ProcessHits: something is wrong here!!! " << G4endl; }
410 }
411
412
413 if (first == -1 ) {
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");
416 }
417
418 if(verboseLevel>5)
419 {
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;
422 }
423
424 if (first == 0 )
425 {
426
427 if(verboseLevel>5) { G4cout << "AFP_SiDSensitiveDetector::ProcessHits: cross is x, " << G4endl; }
428 x_border = x_next_pixel;
429
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;
432
433 y_border = tan_phi*(x_border-x_det) + y_det;
434
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))
436 {
437 pixel_track_length_XY = sqrt(
pow(x_border-x_det,2)+
pow(y_border-y_det,2));
438
439 if(verboseLevel>5)
440 {
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;
445 }
446
447
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));
454
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; }
457
459
461 }
462
463 x_det = x_border;
464 y_det = y_border;
465
467 number_pixels_x = number_pixels_x - 1;
468
469 if(verboseLevel>5) { G4cout << "AFP_SiDSensitiveDetector::ProcessHits: remaining number of pixels in x = " << number_pixels_x << ", in y = " << number_pixels_y << G4endl; }
470
471 act_pixel_x = act_pixel_x + sign_pixels_x;
472 }
473
474 if (first == 1 )
475 {
476
477 if(verboseLevel>5) { G4cout << "AFP_SiDSensitiveDetector::ProcessHits: cross is y, " << G4endl; }
478 y_border = y_next_pixel;
479
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;
482
483 x_border = (y_border-y_det)/tan_phi + x_det;
484
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))
486 {
487 pixel_track_length_XY = sqrt(
pow(x_border-x_det,2)+
pow(y_border-y_det,2));
488
489 if(verboseLevel>5)
490 {
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;
495 }
496
497
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));
504
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; }
507
509
511 }
512
513 y_det = y_border;
514 x_det = x_border;
515
517 number_pixels_y = number_pixels_y - 1;
518
519 if(verboseLevel>5) { G4cout << "AFP_SiDSensitiveDetector::ProcessHits: remaining number of pixels in x = " << number_pixels_x << ", in y = " << number_pixels_y << G4endl; }
520
521
522 act_pixel_y = act_pixel_y + sign_pixels_y;
523 }
524 }
525 }
526 }
527 }
528 }
529
530 return true;
531}
constexpr int pow(int base, int exp) noexcept
static constexpr int SiDMaxCnt
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...