Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExN05PionShowerModel.cc
Go to the documentation of this file.
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 // $Id$
28 //
29 #include "ExN05PionShowerModel.hh"
30 #include "ExN05EnergySpot.hh"
31 
32 #include "Randomize.hh"
33 
34 #include "G4PionMinus.hh"
35 #include "G4PionPlus.hh"
37 #include "G4VSensitiveDetector.hh"
38 #include "G4TouchableHistory.hh"
39 
40 #include "G4Colour.hh"
41 #include "G4PhysicalConstants.hh"
42 #include "G4SystemOfUnits.hh"
43 
45 : G4VFastSimulationModel(modelName, envelope)
46 {
47  fFakeStep = new G4Step();
48  fFakePreStepPoint = fFakeStep->GetPreStepPoint();
49  fFakePostStepPoint = fFakeStep->GetPostStepPoint();
50  fTouchableHandle = new G4TouchableHistory();
51  fpNavigator = new G4Navigator();
52  fNaviSetup = false;
53 }
54 
56 : G4VFastSimulationModel(modelName)
57 {
58  fFakeStep = new G4Step();
59  fFakePreStepPoint = fFakeStep->GetPreStepPoint();
60  fFakePostStepPoint = fFakeStep->GetPostStepPoint();
61  fTouchableHandle = new G4TouchableHistory();
62  fpNavigator = new G4Navigator();
63  fNaviSetup = false;
64 }
65 
67 {
68  delete fFakeStep;
69  delete fpNavigator;
70 }
71 
73 {
74  return
75  &particleType == G4PionMinus::PionMinusDefinition() ||
76  &particleType == G4PionPlus::PionPlusDefinition();
77 }
78 
80 {
81  // Applies the parameterisation always:
82  // ie as soon as the pion enters the envelope
83  return true;
84 }
85 
86 void ExN05PionShowerModel::DoIt(const G4FastTrack& fastTrack,
87  G4FastStep& fastStep)
88 {
89  // G4cout << "ExN05PionShowerModel::DoIt" << G4endl;
90 
91  // Kill the parameterised particle:
92  fastStep.KillPrimaryTrack();
93  fastStep.ProposePrimaryTrackPathLength(0.0);
95 
96  // split into "energy spots" energy according to the shower shape:
97  Explode(fastTrack);
98 
99  // and put those energy spots into the crystals:
100  BuildDetectorResponse();
101 }
102 
103 void ExN05PionShowerModel::Explode(const G4FastTrack& fastTrack)
104 {
105  //-----------------------------------------------------
106  // Non-physical shower generated: exp along z and
107  // transverse.
108  //-----------------------------------------------------
109 
110  // center of the shower, we put at the middle of the ghost:
111  G4ThreeVector showerCenter;
112  G4double distOut;
113  distOut = fastTrack.GetEnvelopeSolid()->
114  DistanceToOut(fastTrack.GetPrimaryTrackLocalPosition(),
115  fastTrack.GetPrimaryTrackLocalDirection());
116  showerCenter = fastTrack.GetPrimaryTrackLocalPosition() +
117  (distOut/2.)*fastTrack.GetPrimaryTrackLocalDirection();
118 
119  showerCenter = fastTrack.GetInverseAffineTransformation()->
120  TransformPoint(showerCenter);
121 
122  // axis of the shower, in global reference frame:
123  G4ThreeVector xShower, yShower, zShower;
124  zShower = fastTrack.GetPrimaryTrack()->GetMomentumDirection();
125  xShower = zShower.orthogonal();
126  yShower = zShower.cross(xShower);
127 
128  // shoot the energy spots:
129  G4double Energy = fastTrack.GetPrimaryTrack()->GetKineticEnergy();
130  G4int nSpot = 50;
131  G4double deposit = Energy/double(nSpot);
132  ExN05EnergySpot eSpot;
133  eSpot.SetEnergy(deposit);
134  G4ThreeVector ePoint;
135 
136  // clear the spot list before use
137  feSpotList.clear();
138 
139  G4double z, r, phi;
140  for (int i = 0; i < nSpot; i++)
141  {
142  z = G4RandGauss::shoot(0,20*cm);
143  r = G4RandGauss::shoot(0,10*cm);
144  phi = G4UniformRand()*twopi;
145  ePoint = showerCenter +
146  z*zShower +
147  r*std::cos(phi)*xShower + r*std::sin(phi)*yShower;
148  eSpot.SetPosition(ePoint);
149  feSpotList.push_back(eSpot);
150  }
151 }
152 
153 
154 void ExN05PionShowerModel::BuildDetectorResponse()
155 {
156  // Does the assignation of the energy spots to the sensitive volumes:
157  for (size_t i = 0; i < feSpotList.size(); i++)
158  {
159  // Draw the energy spot:
160  G4Colour red(1.,0.,0.);
161  feSpotList[i].Draw(&red);
162  // feSpotList[i].Print();
163 
164  // "converts" the energy spot into the fake
165  // G4Step to pass to sensitive detector:
166  AssignSpotAndCallHit(feSpotList[i]);
167  }
168 }
169 
170 
171 void ExN05PionShowerModel::AssignSpotAndCallHit(const ExN05EnergySpot &eSpot)
172 {
173  //
174  // "converts" the energy spot into the fake
175  // G4Step to pass to sensitive detector:
176  //
177  FillFakeStep(eSpot);
178 
179  //
180  // call sensitive part: taken/adapted from the stepping:
181  // Send G4Step information to Hit/Dig if the volume is sensitive
182  //
183  G4VPhysicalVolume* pCurrentVolume =
184  fFakeStep->GetPreStepPoint()->GetPhysicalVolume();
185  G4VSensitiveDetector* pSensitive;
186 
187  if( pCurrentVolume != 0 )
188  {
189  pSensitive = pCurrentVolume->GetLogicalVolume()->
190  GetSensitiveDetector();
191  if( pSensitive != 0 )
192  {
193  pSensitive->Hit(fFakeStep);
194  }
195  }
196 }
197 
198 
199 void ExN05PionShowerModel::FillFakeStep(const ExN05EnergySpot &eSpot)
200 {
201  //-----------------------------------------------------------
202  // find in which volume the spot is.
203  //-----------------------------------------------------------
204  if (!fNaviSetup)
205  {
206  fpNavigator->
208  GetNavigatorForTracking()->GetWorldVolume());
209  fpNavigator->
210  LocateGlobalPointAndUpdateTouchableHandle(eSpot.GetPosition(),
211  G4ThreeVector(0.,0.,0.),
212  fTouchableHandle,
213  false);
214  fNaviSetup = true;
215  }
216  else
217  {
218  fpNavigator->
219  LocateGlobalPointAndUpdateTouchableHandle(eSpot.GetPosition(),
220  G4ThreeVector(0.,0.,0.),
221  fTouchableHandle);
222  }
223  //--------------------------------------
224  // Fills attribute of the G4Step needed
225  // by our sensitive detector:
226  //-------------------------------------
227  // set touchable volume at PreStepPoint:
228  fFakePreStepPoint->SetTouchableHandle(fTouchableHandle);
229  // set total energy deposit:
230  fFakeStep->SetTotalEnergyDeposit(eSpot.GetEnergy());
231 }