ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParallelWorldScoringProcess.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ParallelWorldScoringProcess.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 //
29 
31 
32 #include "G4ios.hh"
33 #include "G4SystemOfUnits.hh"
34 #include "G4Step.hh"
35 #include "G4Navigator.hh"
36 #include "G4VTouchable.hh"
37 #include "G4VPhysicalVolume.hh"
38 #include "G4ParticleChange.hh"
39 #include "G4PathFinder.hh"
41 #include "G4ParticleChange.hh"
42 #include "G4StepPoint.hh"
43 #include "G4FieldTrackUpdator.hh"
44 #include "G4ParticleDefinition.hh"
45 
46 #include "G4SDManager.hh"
47 #include "G4VSensitiveDetector.hh"
48 
49 //--------------------------------
50 // Constructor with name and type:
51 //--------------------------------
54 :G4VProcess(processName,theType), fGhostNavigator(0), fNavigatorID(-1), fFieldTrack('0')
55 {
57 
58  fGhostStep = new G4Step();
61 
64 
65  fGhostWorld = 0;
66  fGhostSafety = 0.;
67  fOnBoundary = false;
68 
69  if (verboseLevel>0)
70  {
71  G4cout << GetProcessName() << " is created " << G4endl;
72  }
73 }
74 
75 // -----------
76 // Destructor:
77 // -----------
79 {
80  delete fGhostStep;
81 }
82 
83 //------------------------------------------------------
84 //
85 // SetParallelWorld
86 //
87 //------------------------------------------------------
89 SetParallelWorld(G4String parallelWorldName)
90 {
91 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
92 // Get pointers of the parallel world and its navigator
93 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
94  fGhostWorldName = parallelWorldName;
97 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
98 }
99 
102 {
103 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
104 // Get pointer of navigator
105 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
106  fGhostWorldName = parallelWorld->GetName();
107  fGhostWorld = parallelWorld;
109 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
110 }
111 
114 {
115  G4int pdgCode = partDef->GetPDGEncoding();
116  if(pdgCode==0)
117  {
118  G4String partName = partDef->GetParticleName();
119  if(partName=="opticalphoton") return false;
120  if(partName=="geantino") return false;
121  if(partName=="chargedgeantino") return false;
122  }
123  else
124  {
125  if(pdgCode==22) return false; // gamma
126  if(pdgCode==11) return false; // electron
127  if(pdgCode==2212) return false; // proton
128  if(pdgCode==-12) return false; // anti_nu_e
129  if(pdgCode==12) return false; // nu_e
130  if(pdgCode==-14) return false; // anti_nu_mu
131  if(pdgCode==14) return false; // nu_mu
132  if(pdgCode==-16) return false; // anti_nu_tau
133  if(pdgCode==16) return false; // nu_tau
134  }
135  return true;
136 }
137 
138 
139 //------------------------------------------------------
140 //
141 // StartTracking
142 //
143 //------------------------------------------------------
145 {
146 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
147 // Activate navigator and get the navigator ID
148 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
149 // G4cout << " G4ParallelWorldScoringProcess::StartTracking" << G4endl;
150  if(fGhostNavigator)
152  else
153  {
154  G4Exception("G4ParallelWorldScoringProcess::StartTracking",
155  "ProcParaWorld000",FatalException,
156  "G4ParallelWorldScoringProcess is used for tracking without having a parallel world assigned");
157  }
158 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
159 
160 // G4cout << "G4ParallelWorldScoringProcess::StartTracking <<<<<<<<<<<<<<<<<< " << G4endl;
161 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
162 // Let PathFinder initialize
163 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
165 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
166 
167 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168 // Setup initial touchables for the first step
169 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
174 
175  // Initialize
176  fGhostSafety = -1.;
177  fOnBoundary = false;
180 }
181 
182 //----------------------------------------------------------
183 //
184 // AtRestGetPhysicalInteractionLength()
185 //
186 //----------------------------------------------------------
187 G4double
189  const G4Track& /*track*/,
191 {
192  *condition = Forced;
193  return DBL_MAX;
194 }
195 
196 //------------------------------------
197 //
198 // AtRestDoIt()
199 //
200 //------------------------------------
202  const G4Track& track,
203  const G4Step& step)
204 {
206  G4VSensitiveDetector* aSD = 0;
209  fOnBoundary = false;
210  CopyStep(step);
212 
214 
218  {
221  }
222  else
224 
225  if (verboseLevel>1) Verbose(step);
226 
228  if(sd)
229  {
230  sd->Hit(fGhostStep);
231  }
232 
233  pParticleChange->Initialize(track);
234  return pParticleChange;
235 }
236 
237 //----------------------------------------------------------
238 //
239 // PostStepGetPhysicalInteractionLength()
240 //
241 //----------------------------------------------------------
242 G4double
244  const G4Track& /*track*/,
245  G4double /*previousStepSize*/,
247 {
248  // I must be invoked anyway to score the hit.
249  *condition = StronglyForced;
250  return DBL_MAX;
251 }
252 
253 //------------------------------------
254 //
255 // PostStepDoIt()
256 //
257 //------------------------------------
259  const G4Track& track,
260  const G4Step& step)
261 {
263  G4VSensitiveDetector* aSD = 0;
266  CopyStep(step);
268 
269  // fPathFinder->Locate( track.GetPosition(),
270  // track.GetMomentumDirection(),
271  // true);
272 
273  // fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
274  // step.GetPostStepPoint()->GetMomentumDirection());
275 
276  if(fOnBoundary)
277  {
278 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
279 // Locate the point and get new touchable
280 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
281  //?? fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
282  //?? step.GetPostStepPoint()->GetMomentumDirection());
284 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
285  }
286  else
287  {
288 // Do I need this ??????????????????????????????????????????????????????????
289 // fGhostNavigator->LocateGlobalPointWithinVolume(track.GetPosition());
290 // ?????????????????????????????????????????????????????????????????????????
291 
292  // fPathFinder->ReLocate(track.GetPosition());
293 
294  // reuse the touchable
296  }
297 
300 
302  {
305  }
306  else
308 
309  if (verboseLevel>1) Verbose(step);
310 
312  if(sd)
313  {
314  sd->Hit(fGhostStep);
315  }
316 
317  pParticleChange->Initialize(track); // Does not change the track properties
318  return pParticleChange;
319 }
320 
321 
322 //---------------------------------------
323 //
324 // AlongStepGetPhysicalInteractionLength
325 //
326 //---------------------------------------
328  const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
329  G4double& proposedSafety, G4GPILSelection* selection)
330 {
331  static G4ThreadLocal G4FieldTrack *endTrack_G4MT_TLS_ = 0 ; if (!endTrack_G4MT_TLS_) endTrack_G4MT_TLS_ = new G4FieldTrack ('0') ; G4FieldTrack &endTrack = *endTrack_G4MT_TLS_;
332  static G4ThreadLocal ELimited *eLimited_G4MT_TLS_ = 0 ; if (!eLimited_G4MT_TLS_) eLimited_G4MT_TLS_ = new ELimited ; ELimited &eLimited = *eLimited_G4MT_TLS_;
333 
334  *selection = NotCandidateForSelection;
335  G4double returnedStep = DBL_MAX;
336 
337  if (previousStepSize > 0.)
338  { fGhostSafety -= previousStepSize; }
339 // else
340 // { fGhostSafety = -1.; }
341  if (fGhostSafety < 0.) fGhostSafety = 0.0;
342 
343  // ------------------------------------------
344  // Determination of the proposed STEP LENGTH:
345  // ------------------------------------------
346  if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
347  {
348  // I have no chance to limit
349  returnedStep = currentMinimumStep;
350  fOnBoundary = false;
351  proposedSafety = fGhostSafety - currentMinimumStep;
352  }
353  else // (currentMinimumStep > fGhostSafety: I may limit the Step)
354  {
356 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
357 // ComputeStep
358 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
359  returnedStep
360  = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
361  track.GetCurrentStepNumber(),fGhostSafety,eLimited,
362  endTrack,track.GetVolume());
363 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
364  if(eLimited == kDoNot)
365  {
366  // Track is not on the boundary
367  fOnBoundary = false;
368  fGhostSafety = fGhostNavigator->ComputeSafety(endTrack.GetPosition());
369  }
370  else
371  {
372  // Track is on the boundary
373  fOnBoundary = true;
374  // fEndGhostSafety = 0.0; // Will apply at the end of the step ...
375  }
376  proposedSafety = fGhostSafety;
377  if(eLimited == kUnique || eLimited == kSharedOther) {
378  *selection = CandidateForSelection;
379  }else if (eLimited == kSharedTransport) {
380  returnedStep *= (1.0 + 1.0e-9);
381  // Expand to disable its selection in Step Manager comparison
382  }
383  }
384 
385  // ----------------------------------------------
386  // Returns the fGhostSafety as the proposedSafety
387  // The SteppingManager will take care of keeping
388  // the smallest one.
389  // ----------------------------------------------
390  return returnedStep;
391 }
392 
394  const G4Track& track, const G4Step& )
395 {
396  // Dummy ParticleChange ie: does nothing
397  // Expecting G4Transportation to move the track
398  pParticleChange->Initialize(track);
399  return pParticleChange;
400 }
401 
402 
404 {
406 
407  fGhostStep->SetTrack(step.GetTrack());
412 
413  *fGhostPreStepPoint = *(step.GetPreStepPoint());
415 
416 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
417 // Set StepStatus for ghost world
418 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
420  if(fOnBoundary)
424 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
425 }
426 
428 {
429  G4cout << "In mass geometry ------------------------------------------------" << G4endl;
430  G4cout << " StepLength : " << step.GetStepLength()/mm << " TotalEnergyDeposit : "
431  << step.GetTotalEnergyDeposit()/MeV << G4endl;
432  G4cout << " PreStepPoint : "
433  << step.GetPreStepPoint()->GetPhysicalVolume()->GetName() << " - ";
436  else
437  { G4cout << "NoProcessAssigned"; }
438  G4cout << G4endl;
439  G4cout << " " << step.GetPreStepPoint()->GetPosition() << G4endl;
440  G4cout << " PostStepPoint : ";
441  if(step.GetPostStepPoint()->GetPhysicalVolume())
442  { G4cout << step.GetPostStepPoint()->GetPhysicalVolume()->GetName(); }
443  else
444  { G4cout << "OutOfWorld"; }
445  G4cout << " - ";
448  else
449  { G4cout << "NoProcessAssigned"; }
450  G4cout << G4endl;
451  G4cout << " " << step.GetPostStepPoint()->GetPosition() << G4endl;
452 
453  G4cout << "In ghost geometry ------------------------------------------------" << G4endl;
454  G4cout << " StepLength : " << fGhostStep->GetStepLength()/mm
455  << " TotalEnergyDeposit : "
457  G4cout << " PreStepPoint : "
460  << " ]" << " - ";
463  else
464  { G4cout << "NoProcessAssigned"; }
465  G4cout << G4endl;
467  G4cout << " PostStepPoint : ";
469  {
472  << " ]";
473  }
474  else
475  { G4cout << "OutOfWorld"; }
476  G4cout << " - ";
479  else
480  { G4cout << "NoProcessAssigned"; }
481  G4cout << G4endl;
482  G4cout << " " << fGhostStep->GetPostStepPoint()->GetPosition() << " == "
484  << G4endl;
485 
486 }
487