Geant4 VMC Version 6.7
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
TG4EmModelPhysics.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2015 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
15#include "TG4EmModelPhysics.h"
16#include "TG4GeometryManager.h"
17#include "TG4GeometryServices.h"
18#include "TG4Globals.h"
22
23#include <TVirtualMC.h>
24#include <TVirtualMCDecayer.h>
25
26#include <G4BiasingProcessInterface.hh>
27#include <G4EmConfigurator.hh>
28#include <G4LogicalVolumeStore.hh>
29#include <G4LossTableManager.hh>
30#include <G4PAIModel.hh>
31#include <G4PAIPhotModel.hh>
32#include <G4ParticleDefinition.hh>
33#include <G4ProcessManager.hh>
34#include <G4RegionStore.hh>
35#include <G4TransportationProcessType.hh>
36
37//
38// static methods
39//
40
41//_____________________________________________________________________________
42TG4EmModel TG4EmModelPhysics::GetEmModel(const G4String& modelName)
43{
45
46 if (modelName == GetEmModelName(kPAIModel)) {
47 return kPAIModel;
48 }
49 else if (modelName == GetEmModelName(kPAIPhotonModel)) {
50 return kPAIPhotonModel;
51 }
52 else if (modelName == GetEmModelName(kSpecialUrbanMscModel)) {
54 }
55 else if (modelName == GetEmModelName(kNoEmModel)) {
56 return kNoEmModel;
57 }
58 else {
59 TG4Globals::Exception("TG4EmModelPhysics", "GetEmModel",
60 TString(modelName.data()) + " unknown model name.");
61 return kNoEmModel;
62 }
63}
64
65//_____________________________________________________________________________
66G4String TG4EmModelPhysics::GetEmModelName(G4int modelType)
67{
69
70 switch (modelType) {
71 case kPAIModel:
72 return "PAI";
73 case kPAIPhotonModel:
74 return "PAIPhoton";
76 return "SpecialUrbanMsc";
77 case kNoEmModel:
78 return "";
79 default:
80 TG4Globals::Exception("TG4EmModelPhysics", "GetEmModelName",
81 TString("Unknown model type ") + TString(modelType));
82 return "";
83 }
84}
85
86//
87// ctors, dtor
88//
89
90//_____________________________________________________________________________
93// fMessenger(this),
94// fEmModels()
95{
97
98 VerboseLevel(1);
99}
100
101//_____________________________________________________________________________
103 G4int theVerboseLevel, const G4String& name)
104 : TG4VPhysicsConstructor(name, theVerboseLevel)
105// fMessenger(this),
106// fEmModels()
107{
109
110 VerboseLevel(1);
111}
112
113//_____________________________________________________________________________
118
119//
120// private methods
121//
122
123//_____________________________________________________________________________
125 const G4ParticleDefinition* particle, const std::vector<G4String>& regions)
126{
129
130 if (!particle->GetProcessManager()) {
131 TString message;
132 message = "Cannot add EM model to ";
133 message += particle->GetParticleName().c_str();
134 message += " : particle has not defined process manager";
135 TG4Globals::Warning("TG4EmModelPhysics", "AddMOdel", message);
136 return;
137 }
138
139 // Get process name
140 G4ProcessVector* processVector =
141 particle->GetProcessManager()->GetProcessList();
142 for (size_t i = 0; i < processVector->length(); i++) {
143 // G4String processName;
144 // G4String currentProcessName = (*processVector)[i]->GetProcessName();
145
146 G4int subType = 0;
147 G4int currentSubType = (*processVector)[i]->GetProcessSubType();
148
149 if (VerboseLevel() > 2) {
150 G4cout << "TG4EmModelPhysics::AddModel, processing "
151 << (*processVector)[i]->GetProcessName() << G4endl;
152 }
153
154 // PAI applied to ionisation
155 if (currentSubType == fIonisation &&
156 (emModel == kPAIModel || emModel == kPAIPhotonModel)) {
157 subType = currentSubType;
158 }
159
160 // UrbanMsc applied to msc or transportation with msc
161 G4bool applyToTransportationProcess = false;
162 if (emModel == kSpecialUrbanMscModel &&
163 ((currentSubType == fMultipleScattering) ||
164 (currentSubType == TRANSPORTATION_WITH_MSC))) {
165 subType = currentSubType;
166 applyToTransportationProcess = (currentSubType == TRANSPORTATION);
167 }
168
169 if (subType == 0) continue;
170
171 // Get process name
172 G4String processName = (*processVector)[i]->GetProcessName();
173
174 // Get the physics process if it is wrapped with biasing
175 G4BiasingProcessInterface* biasingProcess =
176 dynamic_cast<G4BiasingProcessInterface*>((*processVector)[i]);
177 if (biasingProcess) {
178 processName = biasingProcess->GetWrappedProcess()->GetProcessName();
179 if (VerboseLevel() > 2) {
180 G4cout << "Unwrapping biasing process: " << processName << G4endl;
181 }
182 }
183
184 if (applyToTransportationProcess) {
185 // the transportation process with msc is not handled with EmConfigurator
186 // via "msc" process name
187 processName = "msc";
188 }
189
190 // CreateEM model
191 //
192 G4VEmModel* g4EmModel = 0;
193 G4VEmFluctuationModel* g4FluctModel = 0;
194
195 if (emModel == kPAIModel) {
196 // PAI
197 G4PAIModel* pai = new G4PAIModel(particle, "PAIModel");
198 if (verboseLevel > 2) {
199 G4cout << "New G4PAIModel" << G4endl;
200 }
201 g4EmModel = pai;
202 g4FluctModel = pai;
203 }
204 else if (emModel == kPAIPhotonModel) {
205 // PAIPhoton
206 if (verboseLevel > 2) {
207 G4cout << "New G4PAIPhotModel" << G4endl;
208 }
209 G4PAIPhotModel* paiPhot = new G4PAIPhotModel(particle, "PAIPhotModel");
210 g4EmModel = paiPhot;
211 g4FluctModel = paiPhot;
212 }
213 else if (emModel == kSpecialUrbanMscModel) {
214 // SpecialUrbanMsc
215 if (verboseLevel > 2) {
216 G4cout << "New TG4SpecialUrbanMscModel" << G4endl;
217 }
218 g4EmModel = new TG4SpecialUrbanMscModel();
219 g4FluctModel = 0;
220 }
221
222 for (G4int j = 0; j < G4int(regions.size()); ++j) {
223
224 G4String regionName = regions[j];
225
226 if (VerboseLevel() > 2) {
227 G4cout << "Adding EM model: " << GetEmModelName(emModel)
228 << " to particle: " << particle->GetParticleName()
229 << " process: " << processName
230 << " region(=material): " << regionName << G4endl;
231 }
232
233 G4LossTableManager::Instance()->EmConfigurator()->SetExtraEmModel(
234 particle->GetParticleName(), processName, g4EmModel, regionName, 0.0,
235 DBL_MAX, g4FluctModel);
236 }
237
238 if (!regions.size()) {
239 // If no regions were defined, set the model to the default region.
240 G4LogicalVolume* worldLV =
241 TG4GeometryServices::Instance()->GetWorld()->GetLogicalVolume();
242 G4String regionName = worldLV->GetRegion()->GetName();
243
244 G4LossTableManager::Instance()->EmConfigurator()->SetExtraEmModel(
245 particle->GetParticleName(), processName, g4EmModel, regionName, 0.0,
246 DBL_MAX, g4FluctModel);
247 }
248 }
249}
250
251//_____________________________________________________________________________
253 const std::vector<TG4ModelConfiguration*>& models)
254{
257
258 if (VerboseLevel() > 1) {
259 G4cout << "TG4EmModelPhysics::AddModels" << G4endl;
260 std::vector<TG4ModelConfiguration*>::const_iterator it;
261 for (it = models.begin(); it != models.end(); it++) {
262 (*it)->Print();
263 }
264 }
265
266 std::vector<TG4ModelConfiguration*>::const_iterator it;
267 for (it = models.begin(); it != models.end(); it++) {
268
269 // Get model configuration
270 TG4EmModel emModel = GetEmModel((*it)->GetModelName());
271 const std::vector<G4String>& regions = (*it)->GetRegions();
272
273 if (!regions.size()) {
274 // add warning
275 TString message;
276 message = "No regions are defined for ";
277 message += (*it)->GetModelName().data();
278 TG4Globals::Warning("TG4EmModelPhysics", "AddModels", message);
279 continue;
280 }
281
282 // Add selected models
283 auto aParticleIterator = GetParticleIterator();
284 aParticleIterator->reset();
285 while ((*aParticleIterator)()) {
286 G4ParticleDefinition* particle = aParticleIterator->value();
287 G4String particleName = particle->GetParticleName();
288
289 // skip particles which are not in the model configuration selection
290 if (! (*it)->HasParticle(particleName) ) continue;
291
292 // skip also monopole (experimental)
293 if (particle->GetParticleName() == "monopole") {
294 G4cout << "TG4EmModelPhysics::AddModels - skipping monopole" << G4endl;
295 continue;
296 }
297
298 AddModel(emModel, particle, regions);
299 }
300 }
301}
302
303//
304// protected methods
305//
306
307//_____________________________________________________________________________
312
313//_____________________________________________________________________________
315{
318
319 if (VerboseLevel() > 2) {
320 G4cout << "TGEmModelPhysics::ConstructProcess " << G4endl;
321 }
322
323 // Get model configurations vector from geometry manager
324 TG4ModelConfigurationManager* emModelsManager =
326
327 const std::vector<TG4ModelConfiguration*>& models =
328 emModelsManager->GetVector();
329
330 // Do nothing if no models were set
331 if (models.size() == 0) {
332 if (VerboseLevel() > 1) {
333 G4cout << "No EM models are defined." << G4endl;
334 }
335 return;
336 }
337
338 // Add user selected models to G4 EM configurator
339 AddModels(models);
340
341 // Let G4 EM configurator to add all previously declared models to
342 // corresponding processes
343 G4LossTableManager::Instance()->EmConfigurator()->AddModels();
344
345 if (VerboseLevel() > 0) {
346 G4cout << "### Selected EmModels added to EM processes" << G4endl;
347 }
348}
Definition of the TG4EmModelPhysics class.
Definition of the TG4GeometryManager class.
Definition of the TG4GeometryServices class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4ModelConfigurationManager class.
Definition of the TG4ModelConfiguration class.
Definition of the TG4SpecialUrbanMscModel class.
static G4String GetEmModelName(G4int modelType)
virtual void ConstructParticle()
Construct particles.
TG4EmModelPhysics(const G4String &name="EmModel")
virtual void ConstructProcess()
Construct physics processes.
void AddModel(TG4EmModel model, const G4ParticleDefinition *particle, const std::vector< G4String > &regions)
static TG4EmModel GetEmModel(const G4String &modelName)
void AddModels(const std::vector< TG4ModelConfiguration * > &models)
TG4ModelConfigurationManager * GetEmModelsManager() const
static TG4GeometryManager * Instance()
G4VPhysicalVolume * GetWorld() const
static TG4GeometryServices * Instance()
static void Warning(const TString &className, const TString &methodName, const TString &text)
static void Exception(const TString &className, const TString &methodName, const TString &text)
The model configuration vector with suitable setters and a messenger.
const ModelConfigurationVector & GetVector() const
Laszlo Urban model adapted for ALICE EMCAL requirements.
TG4VPhysicsConstructor(const G4String &name)
virtual G4int VerboseLevel() const
TG4EmModel
Enumeration for EM physics models supported in this class.
@ kPAIPhotonModel
PAIPhot model.
@ kPAIModel
PAI model.
@ kSpecialUrbanMscModel
Special UrbanMsc model adapted for ALICE EMCAL.
@ kNoEmModel
No extra EM model.