Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
28 //
29 //
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 G4bool WLSPrimaryGeneratorAction::first = false;
55 
58 {
59  detector = DC;
60  theIntegralTable = NULL;
61 
62  particleGun = new G4GeneralParticleSource();
63 
64  gunMessenger = new WLSPrimaryGeneratorMessenger(this);
65 
66  // G4String particleName;
67  // G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
68 
69  timeConstant = 0.;
70 
71 // particleGun->SetParticleDefinition(particleTable->
72 // FindParticle(particleName="opticalphoton"));
73 }
74 
76 {
77  delete particleGun;
78  delete gunMessenger;
79  if (theIntegralTable) {
81  delete theIntegralTable;
82  }
83 }
84 
86 {
87  timeConstant = time;
88 }
89 
91 {
92  if (theIntegralTable) return;
93 
94  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
95 
96  G4int numOfMaterials = G4Material::GetNumberOfMaterials();
97 
98  if(!theIntegralTable)theIntegralTable = new G4PhysicsTable(numOfMaterials);
99 
100  for (G4int i=0 ; i < numOfMaterials; i++) {
101 
102  G4PhysicsOrderedFreeVector* aPhysicsOrderedFreeVector =
104 
105  G4Material* aMaterial = (*theMaterialTable)[i];
106 
107  G4MaterialPropertiesTable* aMaterialPropertiesTable =
108  aMaterial->GetMaterialPropertiesTable();
109 
110  if (aMaterialPropertiesTable) {
111  G4MaterialPropertyVector* theWLSVector =
112  aMaterialPropertiesTable->GetProperty("WLSCOMPONENT");
113 
114  if (theWLSVector) {
115  G4double currentIN = (*theWLSVector)[0];
116  if (currentIN >= 0.0) {
117  G4double currentPM = theWLSVector->Energy(0);
118  G4double currentCII = 0.0;
119  aPhysicsOrderedFreeVector->
120  InsertValues(currentPM , currentCII);
121  G4double prevPM = currentPM;
122  G4double prevCII = currentCII;
123  G4double prevIN = currentIN;
124 
125  for (size_t j = 1;
126  j < theWLSVector->GetVectorLength();
127  j++)
128  {
129  currentPM = theWLSVector->Energy(j);
130  currentIN = (*theWLSVector)[j];
131  currentCII = 0.5 * (prevIN + currentIN);
132  currentCII = prevCII + (currentPM - prevPM) * currentCII;
133  aPhysicsOrderedFreeVector->
134  InsertValues(currentPM, currentCII);
135  prevPM = currentPM;
136  prevCII = currentCII;
137  prevIN = currentIN;
138  }
139  }
140  }
141  }
142  theIntegralTable->insertAt(i,aPhysicsOrderedFreeVector);
143  }
144 }
145 
147 {
148  if (!first) {
149  first = true;
151  }
152 
153 
154 #ifdef use_sampledEnergy
155  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
156 
157  G4double sampledEnergy = 3*eV;
158 
159  for (size_t j=0 ; j<theMaterialTable->size() ; j++) {
160  G4Material* fMaterial = (*theMaterialTable)[j];
161  if (fMaterial->GetName() == "PMMA" ) {
162  G4MaterialPropertiesTable* aMaterialPropertiesTable =
163  fMaterial->GetMaterialPropertiesTable();
164  const G4MaterialPropertyVector* WLSIntensity =
165  aMaterialPropertiesTable->GetProperty("WLSCOMPONENT");
166 
167  if (WLSIntensity) {
168  G4int MaterialIndex = fMaterial->GetIndex();
169  G4PhysicsOrderedFreeVector* WLSIntegral =
170  (G4PhysicsOrderedFreeVector*)((*theIntegralTable)(MaterialIndex));
171 
172  G4double CIImax = WLSIntegral->GetMaxValue();
173  G4double CIIvalue = G4UniformRand()*CIImax;
174 
175  sampledEnergy = WLSIntegral->GetEnergy(CIIvalue);
176  }
177  }
178  }
179 
180  //particleGun->SetParticleEnergy(sampledEnergy);
181 #endif
182 
183  if(particleGun->GetParticleDefinition()->GetParticleName()=="opticalphoton"){
185  SetOptPhotonTime();
186  }
187 
188  particleGun->GeneratePrimaryVertex(anEvent);
189 }
190 
191 void WLSPrimaryGeneratorAction::SetOptPhotonPolar()
192 {
193  G4double angle = G4UniformRand() * 360.0*deg;
194  SetOptPhotonPolar(angle);
195 }
196 
198 {
199  if (particleGun->GetParticleDefinition()->GetParticleName()!="opticalphoton")
200  {
201  G4cout << "-> warning from WLSPrimaryGeneratorAction::SetOptPhotonPolar()"
202  << ": the particleGun is not an opticalphoton" << G4endl;
203  return;
204  }
205 
206  G4ThreeVector normal (1., 0., 0.);
207  G4ThreeVector kphoton = particleGun->GetParticleMomentumDirection();
208  G4ThreeVector product = normal.cross(kphoton);
209  G4double modul2 = product*product;
210 
211  G4ThreeVector e_perpend (0., 0., 1.);
212  if (modul2 > 0.) e_perpend = (1./std::sqrt(modul2))*product;
213  G4ThreeVector e_paralle = e_perpend.cross(kphoton);
214 
215  G4ThreeVector polar = std::cos(angle)*e_paralle + std::sin(angle)*e_perpend;
216  particleGun->SetParticlePolarization(polar);
217 
218 }
219 
220 void WLSPrimaryGeneratorAction::SetOptPhotonTime()
221 {
222  G4double time = -std::log(G4UniformRand())*timeConstant;
223  particleGun->SetParticleTime(time);
224 }