source: trunk/examples/novice/N05/src/ExN05PionShowerModel.cc @ 1288

Last change on this file since 1288 was 1230, checked in by garnier, 14 years ago

update to geant4.9.3

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