Geant4  10.02.p01
WLSPrimaryGeneratorAction.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 // $Id: WLSPrimaryGeneratorAction.cc 88760 2015-03-09 12:21:59Z gcosmo $
27 //
30 //
31 //
32 #include "G4ios.hh"
33 #include "G4Event.hh"
34 
36 
37 #include "G4Material.hh"
39 
40 #include "G4ParticleTable.hh"
41 #include "G4ParticleDefinition.hh"
42 
43 #include "G4PhysicsTable.hh"
44 
45 #include "Randomize.hh"
46 
48 
51 
52 #include "G4SystemOfUnits.hh"
53 
54 #include "G4AutoLock.hh"
55 
56 namespace {
57  G4Mutex gen_mutex = G4MUTEX_INITIALIZER;
58 }
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
63 
66 {
67  fDetector = dc;
68  fIntegralTable = NULL;
69 
71 
73 
74  // G4String particleName;
75  // G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
76 
77  fTimeConstant = 0.;
78 
79 // fParticleGun->SetParticleDefinition(particleTable->
80 // FindParticle(particleName="opticalphoton"));
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
86 {
87  delete fParticleGun;
88  delete fGunMessenger;
89  if (fIntegralTable) {
91  delete fIntegralTable;
92  }
93 }
94 
95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
96 
98 {
99  fTimeConstant = time;
100 }
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103 
105 {
106  if (fIntegralTable) return;
107 
108  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
109 
110  G4int numOfMaterials = G4Material::GetNumberOfMaterials();
111 
112  if(!fIntegralTable)fIntegralTable = new G4PhysicsTable(numOfMaterials);
113 
114  for (G4int i=0 ; i < numOfMaterials; i++) {
115 
116  G4PhysicsOrderedFreeVector* aPhysicsOrderedFreeVector =
118 
119  G4Material* aMaterial = (*theMaterialTable)[i];
120 
121  G4MaterialPropertiesTable* aMaterialPropertiesTable =
122  aMaterial->GetMaterialPropertiesTable();
123 
124  if (aMaterialPropertiesTable) {
125  G4MaterialPropertyVector* theWLSVector =
126  aMaterialPropertiesTable->GetProperty("WLSCOMPONENT");
127 
128  if (theWLSVector) {
129  G4double currentIN = (*theWLSVector)[0];
130  if (currentIN >= 0.0) {
131  G4double currentPM = theWLSVector->Energy(0);
132  G4double currentCII = 0.0;
133  aPhysicsOrderedFreeVector->
134  InsertValues(currentPM , currentCII);
135  G4double prevPM = currentPM;
136  G4double prevCII = currentCII;
137  G4double prevIN = currentIN;
138 
139  for (size_t j = 1;
140  j < theWLSVector->GetVectorLength();
141  j++)
142  {
143  currentPM = theWLSVector->Energy(j);
144  currentIN = (*theWLSVector)[j];
145  currentCII = 0.5 * (prevIN + currentIN);
146  currentCII = prevCII + (currentPM - prevPM) * currentCII;
147  aPhysicsOrderedFreeVector->
148  InsertValues(currentPM, currentCII);
149  prevPM = currentPM;
150  prevCII = currentCII;
151  prevIN = currentIN;
152  }
153  }
154  }
155  }
156  fIntegralTable->insertAt(i,aPhysicsOrderedFreeVector);
157  }
158 }
159 
160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
161 
163 {
164  if (!fFirst) {
165  fFirst = true;
167  }
168 
169 #ifdef use_sampledEnergy
170  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
171 
172  G4double sampledEnergy = 3*eV;
173 
174  for (size_t j=0 ; j<theMaterialTable->size() ; j++) {
175  G4Material* fMaterial = (*theMaterialTable)[j];
176  if (fMaterial->GetName() == "PMMA" ) {
177  G4MaterialPropertiesTable* aMaterialPropertiesTable =
178  fMaterial->GetMaterialPropertiesTable();
179  const G4MaterialPropertyVector* WLSIntensity =
180  aMaterialPropertiesTable->GetProperty("WLSCOMPONENT");
181 
182  if (WLSIntensity) {
183  G4int MaterialIndex = fMaterial->GetIndex();
184  G4PhysicsOrderedFreeVector* WLSIntegral =
185  (G4PhysicsOrderedFreeVector*)((*fIntegralTable)(MaterialIndex));
186 
187  G4double CIImax = WLSIntegral->GetMaxValue();
188  G4double CIIvalue = G4UniformRand()*CIImax;
189 
190  sampledEnergy = WLSIntegral->GetEnergy(CIIvalue);
191  }
192  }
193  }
194 
195  //fParticleGun->SetParticleEnergy(sampledEnergy);
196 #endif
197 
198  //The code behing this line is not thread safe because polarization
199  //and time are randomly selected and GPS properties are global
200  G4AutoLock l(&gen_mutex);
201  if(fParticleGun->GetParticleDefinition()->GetParticleName()=="opticalphoton"){
204  }
205 
207 }
208 
209 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
210 
212 {
213  G4double angle = G4UniformRand() * 360.0*deg;
214  SetOptPhotonPolar(angle);
215 }
216 
217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
218 
220 {
221  if (fParticleGun->GetParticleDefinition()->GetParticleName()!="opticalphoton")
222  {
223  G4cout << "-> warning from WLSPrimaryGeneratorAction::SetOptPhotonPolar()"
224  << ": the ParticleGun is not an opticalphoton" << G4endl;
225  return;
226  }
227 
228  G4ThreeVector normal (1., 0., 0.);
230  G4ThreeVector product = normal.cross(kphoton);
231  G4double modul2 = product*product;
232 
233  G4ThreeVector e_perpend (0., 0., 1.);
234  if (modul2 > 0.) e_perpend = (1./std::sqrt(modul2))*product;
235  G4ThreeVector e_paralle = e_perpend.cross(kphoton);
236 
237  G4ThreeVector polar = std::cos(angle)*e_paralle + std::sin(angle)*e_perpend;
239 
240 }
241 
242 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
243 
245 {
246  G4double time = -std::log(G4UniformRand())*fTimeConstant;
248 }
G4MaterialPropertyVector * GetProperty(const char *key)
Definition of the WLSPrimaryGeneratorAction class.
CLHEP::Hep3Vector G4ThreeVector
size_t GetIndex() const
Definition: G4Material.hh:262
Andrea Dotti Feb 2015 GPS messenger design requires some explanation for what distributions parameter...
const G4String & GetName() const
Definition: G4Material.hh:178
Definition of the WLSPrimaryGeneratorMessenger class.
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:589
std::vector< G4Material * > G4MaterialTable
static G4double angle[DIM]
size_t GetVectorLength() const
int G4int
Definition: G4Types.hh:78
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
const G4String & GetParticleName() const
Definition of the WLSDetectorConstruction class.
void SetParticleTime(G4double aTime)
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:77
G4GeneralParticleSource * fParticleGun
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
static const double deg
Definition: G4SIunits.hh:151
WLSPrimaryGeneratorMessenger * fGunMessenger
bool G4bool
Definition: G4Types.hh:79
void SetParticlePolarization(G4ThreeVector aVal)
G4double Energy(size_t index) const
static size_t GetNumberOfMaterials()
Definition: G4Material.cc:596
WLSDetectorConstruction * fDetector
G4ParticleDefinition * GetParticleDefinition() const
G4double GetEnergy(G4double aValue)
static const double eV
Definition: G4SIunits.hh:212
G4int G4Mutex
Definition: G4Threading.hh:173
WLSPrimaryGeneratorAction(WLSDetectorConstruction *)
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
Definition: G4Material.hh:252
G4ThreeVector GetParticleMomentumDirection() const
virtual void GeneratePrimaries(G4Event *)
void insertAt(size_t, G4PhysicsVector *)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void clearAndDestroy()