Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
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 <G4TransportationManager.hh>
36#include <G4TransportationProcessType.hh>
37#include <G4TransportationWithMsc.hh>
38
39//
40// static methods
41//
42
43//_____________________________________________________________________________
44TG4EmModel TG4EmModelPhysics::GetEmModel(const G4String& modelName)
45{
47
48 if (modelName == GetEmModelName(kPAIModel)) {
49 return kPAIModel;
50 }
51 else if (modelName == GetEmModelName(kPAIPhotonModel)) {
52 return kPAIPhotonModel;
53 }
54 else if (modelName == GetEmModelName(kSpecialUrbanMscModel)) {
56 }
57 else if (modelName == GetEmModelName(kNoEmModel)) {
58 return kNoEmModel;
59 }
60 else {
61 TG4Globals::Exception("TG4EmModelPhysics", "GetEmModel",
62 TString(modelName.data()) + " unknown model name.");
63 return kNoEmModel;
64 }
65}
66
67//_____________________________________________________________________________
68G4String TG4EmModelPhysics::GetEmModelName(G4int modelType)
69{
71
72 switch (modelType) {
73 case kPAIModel:
74 return "PAI";
75 case kPAIPhotonModel:
76 return "PAIPhoton";
78 return "SpecialUrbanMsc";
79 case kNoEmModel:
80 return "";
81 default:
82 TG4Globals::Exception("TG4EmModelPhysics", "GetEmModelName",
83 TString("Unknown model type ") + TString(modelType));
84 return "";
85 }
86}
87
88//
89// ctors, dtor
90//
91
92//_____________________________________________________________________________
95// fMessenger(this),
96// fEmModels()
97{
99
100 VerboseLevel(1);
101}
102
103//_____________________________________________________________________________
105 G4int theVerboseLevel, const G4String& name)
106 : TG4VPhysicsConstructor(name, theVerboseLevel)
107// fMessenger(this),
108// fEmModels()
109{
111
112 VerboseLevel(1);
113}
114
115//_____________________________________________________________________________
120
121//
122// private methods
123//
124
125//_____________________________________________________________________________
127 const G4ParticleDefinition* particle, const std::vector<G4String>& regions)
128{
131
132 if (!particle->GetProcessManager()) {
133 TString message;
134 message = "Cannot add EM model to ";
135 message += particle->GetParticleName().c_str();
136 message += " : particle has not defined process manager";
137 TG4Globals::Warning("TG4EmModelPhysics", "AddMOdel", message);
138 return;
139 }
140
141 // Get process name
142 G4ProcessVector* processVector =
143 particle->GetProcessManager()->GetProcessList();
144 for (size_t i = 0; i < processVector->length(); i++) {
145 // G4String processName;
146 // G4String currentProcessName = (*processVector)[i]->GetProcessName();
147
148 G4int subType = 0;
149 G4int currentSubType = (*processVector)[i]->GetProcessSubType();
150
151 if (VerboseLevel() > 2) {
152 G4cout << "TG4EmModelPhysics::AddModel, processing "
153 << (*processVector)[i]->GetProcessName() << G4endl;
154 }
155
156 // PAI applied to ionisation
157 if (currentSubType == fIonisation &&
158 (emModel == kPAIModel || emModel == kPAIPhotonModel)) {
159 subType = currentSubType;
160 }
161
162 // UrbanMsc applied to msc or transportation with msc
163 G4bool applyToTransportationProcess = false;
164 if (emModel == kSpecialUrbanMscModel &&
165 ((currentSubType == fMultipleScattering) ||
166 (currentSubType == TRANSPORTATION &&
167 (*processVector)[i]->GetProcessName() == "TransportationWithMsc"))) {
168 subType = currentSubType;
169 applyToTransportationProcess = (currentSubType == TRANSPORTATION);
170 }
171
172 if (subType == 0) continue;
173
174 // Get process name
175 G4String processName = (*processVector)[i]->GetProcessName();
176
177 // Get the physics process if it is wrapped with biasing
178 G4BiasingProcessInterface* biasingProcess =
179 dynamic_cast<G4BiasingProcessInterface*>((*processVector)[i]);
180 if (biasingProcess) {
181 processName = biasingProcess->GetWrappedProcess()->GetProcessName();
182 if (VerboseLevel() > 2) {
183 G4cout << "Unwrapping biasing process: " << processName << G4endl;
184 }
185 }
186
187 // CreateEM model
188 //
189 G4VEmModel* g4EmModel = 0;
190 G4VEmFluctuationModel* g4FluctModel = 0;
191
192 if (emModel == kPAIModel) {
193 // PAI
194 G4PAIModel* pai = new G4PAIModel(particle, "PAIModel");
195 if (verboseLevel > 2) {
196 G4cout << "New G4PAIModel" << G4endl;
197 }
198 g4EmModel = pai;
199 g4FluctModel = pai;
200 }
201 else if (emModel == kPAIPhotonModel) {
202 // PAIPhoton
203 if (verboseLevel > 2) {
204 G4cout << "New G4PAIPhotModel" << G4endl;
205 }
206 G4PAIPhotModel* paiPhot = new G4PAIPhotModel(particle, "PAIPhotModel");
207 g4EmModel = paiPhot;
208 g4FluctModel = paiPhot;
209 }
210 else if (emModel == kSpecialUrbanMscModel) {
211 // SpecialUrbanMsc
212 if (verboseLevel > 2) {
213 G4cout << "New TG4SpecialUrbanMscModel" << G4endl;
214 }
215 g4EmModel = new TG4SpecialUrbanMscModel();
216 g4FluctModel = 0;
217 }
218
219 for (G4int j = 0; j < G4int(regions.size()); ++j) {
220
221 G4String regionName = regions[j];
222
223 if (VerboseLevel() > 2) {
224 G4cout << "Adding EM model: " << GetEmModelName(emModel)
225 << " to particle: " << particle->GetParticleName()
226 << " process: " << processName
227 << " region(=material): " << regionName << G4endl;
228 }
229
230 if (applyToTransportationProcess) {
231 // the transportation process is not handled with EmConfigurator
232 // the model must be set directly to the process
233 G4TransportationWithMsc* transportWithMsc =
234 static_cast<G4TransportationWithMsc*>((*processVector)[i]);
235 auto region = G4RegionStore::GetInstance()->GetRegion(regionName);
236 if (region != nullptr) {
237 if (VerboseLevel() > 2) {
238 G4cout << "[special UrbanMsc model added to G4TransportationWithMsc]"
239 << G4endl;
240 }
241 transportWithMsc->
242 AddMscModel(static_cast<G4VMscModel*>(g4EmModel), -1, region);
243 }
244 else {
245 TString message;
246 message = "Failed to get region by name ";
247 message += regionName.c_str();
248 TG4Globals::Warning("TG4EmModelPhysics", "AddModel", message);
249 }
250 }
251 else {
252 G4LossTableManager::Instance()->EmConfigurator()->SetExtraEmModel(
253 particle->GetParticleName(), processName, g4EmModel, regionName, 0.0,
254 DBL_MAX, g4FluctModel);
255 }
256 }
257
258 if (!regions.size()) {
259 // If no regions were defined, set the model to the default region.
260 G4LogicalVolume* worldLV =
261 TG4GeometryServices::Instance()->GetWorld()->GetLogicalVolume();
262 G4String regionName = worldLV->GetRegion()->GetName();
263
264 G4LossTableManager::Instance()->EmConfigurator()->SetExtraEmModel(
265 particle->GetParticleName(), processName, g4EmModel, regionName, 0.0,
266 DBL_MAX, g4FluctModel);
267 }
268 }
269}
270
271//_____________________________________________________________________________
273 const std::vector<TG4ModelConfiguration*>& models)
274{
277
278 if (VerboseLevel() > 1) {
279 G4cout << "TG4EmModelPhysics::AddModels" << G4endl;
280 std::vector<TG4ModelConfiguration*>::const_iterator it;
281 for (it = models.begin(); it != models.end(); it++) {
282 (*it)->Print();
283 }
284 }
285
286 std::vector<TG4ModelConfiguration*>::const_iterator it;
287 for (it = models.begin(); it != models.end(); it++) {
288
289 // Get model configuration
290 TG4EmModel emModel = GetEmModel((*it)->GetModelName());
291 G4String particles = (*it)->GetParticles();
292 const std::vector<G4String>& regions = (*it)->GetRegions();
293
294 if (!regions.size()) {
295 // add warning
296 TString message;
297 message = "No regions are defined for ";
298 message += (*it)->GetModelName().data();
299 TG4Globals::Warning("TG4EmModelPhysics", "AddModels", message);
300 continue;
301 }
302
303 // Add selected models
304 auto aParticleIterator = GetParticleIterator();
305 aParticleIterator->reset();
306 while ((*aParticleIterator)()) {
307 G4ParticleDefinition* particle = aParticleIterator->value();
308 G4String particleName = particle->GetParticleName();
309
310 // skip particles which are not in selection
311 if (particles != "all" &&
312 particles.find(particle->GetParticleName()) == std::string::npos) {
313 continue;
314 }
315
316 // skip also monopole (experimental)
317 if (particle->GetParticleName() == "monopole") {
318 G4cout << "TG4EmModelPhysics::AddModels - skipping monopole" << G4endl;
319 continue;
320 }
321
322 AddModel(emModel, particle, regions);
323 }
324 }
325}
326
327//
328// protected methods
329//
330
331//_____________________________________________________________________________
336
337//_____________________________________________________________________________
339{
342
343 if (VerboseLevel() > 2) {
344 G4cout << "TGEmModelPhysics::ConstructProcess " << G4endl;
345 }
346
347 // Get model configurations vector from geometry manager
348 TG4ModelConfigurationManager* emModelsManager =
350
351 const std::vector<TG4ModelConfiguration*>& models =
352 emModelsManager->GetVector();
353
354 // Do nothing if no models were set
355 if (models.size() == 0) {
356 if (VerboseLevel() > 1) {
357 G4cout << "No EM models are defined." << G4endl;
358 }
359 return;
360 }
361
362 // Add user selected models to G4 EM configurator
363 AddModels(models);
364
365 // Let G4 EM configurator to add all previously declared models to
366 // corresponding processes
367 G4LossTableManager::Instance()->EmConfigurator()->AddModels();
368
369 if (VerboseLevel() > 0) {
370 G4cout << "### Selected EmModels added to EM processes" << G4endl;
371 }
372}
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.
Abstract base class for physics constructors with verbose.
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.