ATLAS Offline Software
AFP_SiDSensitiveDetector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Class header
7 
8 // Athena headers
10 
11 // Geant4 headers
12 #include "G4Version.hh"
13 #include "G4TouchableHistory.hh"
14 #include "G4Step.hh"
15 #include "G4Track.hh"
16 #include "G4ParticleDefinition.hh"
17 #include "G4StepPoint.hh"
18 #include "G4ThreeVector.hh"
19 #include "G4Poisson.hh"
20 #include "G4VSolid.hh"
21 #include "G4ReflectedSolid.hh"
22 #include "G4Material.hh"
23 #include "G4MaterialPropertyVector.hh"
24 
25 // STL header
26 #include <sstream>
27 #include <cmath>
28 
29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30 
31 AFP_SiDSensitiveDetector::AFP_SiDSensitiveDetector(const std::string& name, const std::string& hitCollectionName)
32  : G4VSensitiveDetector( name )
33  , m_nHitID(-1)
34  , m_nEventNumber(0)
35  , m_nNumberOfSIDSimHits(0)
36  , m_delta_pixel_x(0.050)
37  , m_delta_pixel_y(0.250)
38  , m_HitColl(hitCollectionName)
39 {
40  for( int i=0; i < 4; i++){
41  m_nNOfSIDSimHits[i] = 0;
42  for( int j=0; j < 10; j++){
43  m_death_edge[i][j] = AFP_CONSTANTS::SiT_DeathEdge; //in mm, it is left edge as the movement is horizontal
45  }
46  }
47 }
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
52 {
54  for( int i=0; i < 4; i++)
55  {
56  m_nNOfSIDSimHits[i] = 0;
57  }
58 }
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 // Initialize from G4 - necessary to new the write handle for now
62 void AFP_SiDSensitiveDetector::Initialize(G4HCofThisEvent *)
63 {
64  if (!m_HitColl.isValid())m_HitColl = std::make_unique<AFP_SIDSimHitCollection>();
65 }
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
69 bool AFP_SiDSensitiveDetector::ProcessHits(G4Step* pStep, G4TouchableHistory*)
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  // int nPixelRow=-1;
90  // int nPixelCol=-1;
91 
92  bool bIsSIDAuxVSID=false;
93 
94  // step, track and particle info
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; // time w.r.t. prestep or poststep ??
114 
115  // name of physical volume
116  G4TouchableHandle touch1 = pPreStepPoint->GetTouchableHandle();
117  G4VPhysicalVolume* volume = touch1->GetVolume();
118  G4String VolumeName = volume->GetName();
119 
120  //G4ThreeVector ph0 = pStep->GetDeltaPosition().unit();
121  //if (fKineticEnergy<10000. && ph0.y()>.2) pTrack->SetTrackStatus(fKillTrackAndSecondaries);
122  //if (VolumeName.contains("TDQuarticBar")) return 1;
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  //scan station and detector id
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'; // idiomatic use of strncpy...
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 
148  m_nHitID++;
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  //hit in SID sensor but with zero deposited energy (transportation)
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  // G4cout << "pixel["<< act_pixel_x - n_death_pixels <<"]["<< act_pixel_y - n_lower_pixels
169  // << "] will be stored, with energy "<< fEnergyDeposit*(pixel_track_length_XY/track_length_XY)
170  // << G4endl;
171  // m_nNumberOfSIDSimHits++;
172  }
173  else
174  {
175  // Cut on maximum number of SID hits/station
176  if(m_nNOfSIDSimHits[nStationID] >= SiDMaxCnt) return 1;
177 
178  // Get the Touchable History:
179  const G4TouchableHistory* myTouch = static_cast<const G4TouchableHistory*>(pPreStepPoint->GetTouchable());
180  // Calculate the local step position.
181  // From a G4 FAQ:
182  // http://geant4-hn.slac.stanford.edu:5090/HyperNews/public/get/geometry/17/1.html
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 = ((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);
201 
202  G4double BarHalfX = .5 * (BarpX+BarnX);
203  G4double BarHalfY = .5 * (BarpY+BarnY);
204  G4double BarHalfZ = .5 * (BarpZ+BarnZ);
205 
206  // x should be 50 mu, y should be 250 mu, z should be 250mu
207 
208  G4double x_det = BarHalfX + localPosition_pre.x(); // we will remove death edge later - death_edge[nStationID][nDetectorID];
209  G4double y_det = BarHalfY + localPosition_pre.y(); // we will remove lower edge later - lower_edge[nStationID][nDetectorID];
210  G4double z_det = BarHalfZ + localPosition_pre.z();
211 
212  G4double x_det_post = BarHalfX + localPosition_post.x(); //- death_edge[nStationID][nDetectorID];
213  G4double y_det_post = BarHalfY + localPosition_post.y(); //- lower_edge[nStationID][nDetectorID];
214  G4double z_det_post = BarHalfZ + localPosition_post.z();
215 
216  //G4double track_length_XY = sqrt(pow(fPostStepX-fPreStepX,2)+pow(fPostStepY-fPreStepY,2));
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  //G4double tan_phi_global = (fPostStepY-fPreStepY)/(fPostStepX-fPreStepX);
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  }
242  signed int pre_pixel_x = (signed int)(x_det / m_delta_pixel_x);
243  signed int pre_pixel_y = (signed int)(y_det / m_delta_pixel_y);
244  signed int post_pixel_x = (signed int)(x_det_post / m_delta_pixel_x);
245  signed int post_pixel_y = (signed int)(y_det_post / m_delta_pixel_y);
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 
262  int n_death_pixels = (int)(m_death_edge[nStationID][nDetectorID]/m_delta_pixel_x);
263  int n_lower_pixels = (int)(m_lower_edge[nStationID][nDetectorID]/m_delta_pixel_y);
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  //number of pixel in death and lower edge
283 
284  int act_pixel_x = pre_pixel_x;
285  int act_pixel_y = pre_pixel_y;
286 
287  //G4double act_pos_x = x_det;
288  //G4double act_pos_y = y_det;
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 
311  m_nNOfSIDSimHits[nStationID]++;
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  // still not complete logic, last step must be cut
325 
326  while ( (number_pixels_x >= 0) && (number_pixels_y >= 0) )
327  {
328 
329  if ((angle_phi >= 0.) && (angle_phi < M_PI_2))
330  {
331  x_next_pixel = (act_pixel_x+1)*m_delta_pixel_x; //- death_edge[nStationID][nDetectorID];
332  y_next_pixel = (act_pixel_y+1)*m_delta_pixel_y; //- death_edge[nStationID][nDetectorID];
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  {
340  first = 0; // x border will be hit first
341  }
342  else
343  {
344  first = 1;
345  }
346  }
347 
348  else if ((angle_phi >= M_PI_2) && (angle_phi < M_PI))
349  {
350  x_next_pixel = (act_pixel_x+0)*m_delta_pixel_x; //- death_edge[nStationID][nDetectorID];
351  y_next_pixel = (act_pixel_y+1)*m_delta_pixel_y; //- death_edge[nStationID][nDetectorID];
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  {
359  first = 1; // y border will be hit first
360  }
361  else
362  {
363  first = 0;
364  }
365  }
366 
367  else if ((angle_phi >= M_PI) && (angle_phi < 3.*M_PI_2))
368  {
369  x_next_pixel = (act_pixel_x+0)*m_delta_pixel_x; //- death_edge[nStationID][nDetectorID];
370  y_next_pixel = (act_pixel_y+0)*m_delta_pixel_y; //- death_edge[nStationID][nDetectorID];
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  {
380  first = 0; // x border will be hit first
381  }
382  else
383  {
384  first = 1;
385  }
386  }
387 
388  else if ((angle_phi >= 3.*M_PI_2) && (angle_phi < 2.*M_PI))
389  {
390  x_next_pixel = (act_pixel_x+1)*m_delta_pixel_x; //- death_edge[nStationID][nDetectorID];
391  y_next_pixel = (act_pixel_y+0)*m_delta_pixel_y; //- death_edge[nStationID][nDetectorID];
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  {
399  first = 1; // y border will be hit first
400  }
401  else
402  {
403  first = 0;
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  // this logic has to be still checked, tracks is necessary fully in sensitive area, but logic is probably ok
448  m_HitColl->Emplace(m_nHitID,nTrackID,nParticleEncoding,fKineticEnergy,
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 
460  m_nNOfSIDSimHits[nStationID]++;
461  }
462 
463  x_det = x_border;
464  y_det = y_border;
465 
466  x_next_pixel = x_next_pixel + sign_pixels_x*m_delta_pixel_x;
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  // this logic has to be still checked, tracks is necessary fully in sensitive area, but logic is probably ok
498  m_HitColl->Emplace(m_nHitID,nTrackID,nParticleEncoding,fKineticEnergy,
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 
510  m_nNOfSIDSimHits[nStationID]++;
511  }
512 
513  y_det = y_border;
514  x_det = x_border;
515 
516  y_next_pixel = y_next_pixel + sign_pixels_y*m_delta_pixel_y;
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 }
532 
533 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
534 
536 {
537  if(verboseLevel>5)
538  {
539  G4cout << "AFP_SiDSensitiveDetector::EndOfAthenaEvent: Total number of hits in SiD: " << m_nNumberOfSIDSimHits << G4endl;
540  G4cout << "AFP_SiDSensitiveDetector::EndOfAthenaEvent: *************************************************************" << G4endl;
541  }
542  m_nEventNumber++;
544 
545  for( int i=0; i < 4; i++){
546  m_nNOfSIDSimHits[i] = 0;
547  }
548 }
AFP_SiDSensitiveDetector::EndOfAthenaEvent
void EndOfAthenaEvent()
Definition: AFP_SiDSensitiveDetector.cxx:535
AFP_SiDSensitiveDetector::m_delta_pixel_y
float m_delta_pixel_y
Definition: AFP_SiDSensitiveDetector.h:59
AFP_SiDSensitiveDetector::m_death_edge
float m_death_edge[4][10]
Definition: AFP_SiDSensitiveDetector.h:60
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
AFP_SiDSensitiveDetector::m_nNOfSIDSimHits
int m_nNOfSIDSimHits[4]
Definition: AFP_SiDSensitiveDetector.h:57
AFP_constants.h
AFP_SiDSensitiveDetector::AFP_SiDSensitiveDetector
AFP_SiDSensitiveDetector(const std::string &name, const std::string &hitCollectionName)
Definition: AFP_SiDSensitiveDetector.cxx:31
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
M_PI
#define M_PI
Definition: ActiveFraction.h:11
AFP_CONSTANTS::SiT_LowerEdge
static constexpr double SiT_LowerEdge
Definition: AFP_constants.h:68
AFP_SiDSensitiveDetector::ProcessHits
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
Definition: AFP_SiDSensitiveDetector.cxx:69
lumiFormat.i
int i
Definition: lumiFormat.py:85
AFP_SiDSensitiveDetector::m_nNumberOfSIDSimHits
int m_nNumberOfSIDSimHits
Definition: AFP_SiDSensitiveDetector.h:55
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AFP_CONSTANTS::SiT_DeathEdge
static constexpr double SiT_DeathEdge
Definition: AFP_constants.h:67
AFP_SiDSensitiveDetector::m_lower_edge
float m_lower_edge[4][10]
Definition: AFP_SiDSensitiveDetector.h:61
AFP_SiDSensitiveDetector::SiDMaxCnt
static constexpr int SiDMaxCnt
Definition: AFP_SiDSensitiveDetector.h:50
AFP_SiDSensitiveDetector::m_HitColl
SG::WriteHandle< AFP_SIDSimHitCollection > m_HitColl
Definition: AFP_SiDSensitiveDetector.h:64
DeMoScan.first
bool first
Definition: DeMoScan.py:536
AFP_SiDSensitiveDetector.h
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
AFP_SiDSensitiveDetector::m_nEventNumber
int m_nEventNumber
Definition: AFP_SiDSensitiveDetector.h:54
AFP_SiDSensitiveDetector::m_delta_pixel_x
float m_delta_pixel_x
Definition: AFP_SiDSensitiveDetector.h:59
AFP_SiDSensitiveDetector::StartOfAthenaEvent
void StartOfAthenaEvent()
Definition: AFP_SiDSensitiveDetector.cxx:51
AFP_SiDSensitiveDetector::m_nHitID
int m_nHitID
Definition: AFP_SiDSensitiveDetector.h:53
python.SystemOfUnits.picosecond
int picosecond
Definition: SystemOfUnits.py:123
AFP_SiDSensitiveDetector::Initialize
void Initialize(G4HCofThisEvent *) override final
Definition: AFP_SiDSensitiveDetector.cxx:62