-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathFairMCApplication.h
More file actions
377 lines (334 loc) · 12.7 KB
/
Copy pathFairMCApplication.h
File metadata and controls
377 lines (334 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/********************************************************************************
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
// -------------------------------------------------------------------------
// ----- FairMCApplication header file -----
// ----- Created 06/01/04 by M. Al-Turany -----
// -------------------------------------------------------------------------
#ifndef FAIR_MC_APPLICATION_H
#define FAIR_MC_APPLICATION_H
#include "FairRadGridManager.h"
#include "FairRunInfo.h" // for FairRunInfo
#include <Rtypes.h> // for Int_t, Bool_t, Double_t, etc
#include <TLorentzVector.h> // for TLorentzVector
#include <TString.h> // for TString
#include <TVirtualMC.h> // for TVirtualMC
#include <TVirtualMCApplication.h> // for TVirtualMCApplication
#include <list> // for list
#include <map> // for map, multimap, etc
#include <memory> // for std::unique_ptr
#include <vector> // for std::vector
class FairDetector;
class FairEventHeader;
class FairField;
class FairGenericStack;
class FairModule;
class FairMCEventHeader;
class FairPrimaryGenerator;
class FairRadLenManager;
class FairRadMapManager;
class FairRootManager;
class FairTask;
class FairTrajFilter;
class FairVolume;
class FairModule;
class FairRunSim;
class TChain;
class TIterator;
class TObjArray;
class TRefArray;
class TTask;
class TVirtualMC;
enum class FairMCApplicationState { kUnknownState, kConstructGeometry, kInitGeometry };
/**
* The Main Application ( Interface to MonteCarlo application )
* @author M. Al-Turany, D. Bertini
* @version 0.1
* @since 12.01.04
*/
class FairMCApplication : public TVirtualMCApplication
{
public:
/** Standard constructor
*@param name name
*@param title title
*@param ModList a TObjArray containing all detectors and modules used in this simulation
*@param MatName material file name
*/
FairMCApplication(const char* name, const char* title, TObjArray* ModList, const char* MatName);
/** default constructor
*/
FairMCApplication();
FairMCApplication(const FairMCApplication&) = delete;
FairMCApplication& operator=(const FairMCApplication&) = delete;
FairMCApplication(FairMCApplication&&) = delete;
FairMCApplication& operator=(FairMCApplication&&) = delete;
/** default destructor
*/
~FairMCApplication() override;
/** Singelton instance
*/
static FairMCApplication* Instance();
virtual void AddDecayModes();
/** Add user defined particles (optional) */
void AddParticles() override; // MC Application
/** Add user defined ions (optional)
Called by TVirtualMC.
TGeant3 calls AddIons() first, then InitGeometry().
TGeant4 calls InitGeometry() first, then AddIons().
This function also initializes event generators.*/
void AddIons() override; // MC Application
/**
*Add user defined Tasks to be executed after each event (optional)
* @param fTask: Task that has to be excuted during simulation
*/
void AddTask(TTask* fTask);
/** Define actions at the beginning of the event */
void BeginEvent() override; // MC Application
/** Define actions at the beginning of primary track */
void BeginPrimary() override; // MC Application
/** Construct user geometry */
void ConstructGeometry() override; // MC Application
/** Align or misalign geometry before actual run */
Bool_t MisalignGeometry() override;
/** Define parameters for optical processes (optional) */
void ConstructOpGeometry() override; // MC Application
/** set sensitive detectors following TVirtualMCSensitiveDetector logic */
void ConstructSensitiveDetectors() override; // MC Application
/** Define actions just before sensitive->EndOfEvent */
void EndOfEvent() override; // MC Application
/** Define actions at the end of event */
void FinishEvent() override; // MC Application
/** Define actions at the end of primary track */
void FinishPrimary() override; // MC Application
/** Define actions at the end of run */
void FinishRun();
/** Generate primary particles */
void GeneratePrimaries() override; // MC Application
/** Return detector by name */
FairDetector* GetDetector(const char* DetName);
/** Return Field used in simulation*/
FairField* GetField() { return fxField; }
/**Return primary generator*/
FairPrimaryGenerator* GetGenerator();
/**Return list of tasks*/
TTask* GetListOfTasks();
FairGenericStack* GetStack();
TChain* GetChain();
/** Initialize geometry
Called by TVirtualMC.
TGeant3 calls AddIons() first, then InitGeometry().
TGeant4 calls InitGeometry() first, then AddIons().
This function also registers detectors.*/
void InitGeometry() override; // MC Application
/** Initialize MC engine */
void InitMC(const char* setup, const char* cuts);
/** Initialize Tasks if any*/
void InitTasks();
/**Define actions at the end of each track */
void PostTrack() override; // MC Application
/** Define actions at the beginning of each track*/
void PreTrack() override; // MC Application
/** Clone for worker (used in MT mode only) */
TVirtualMCApplication* CloneForWorker() const override;
/** Init application on worker (used in MT mode only) */
void InitOnWorker() override;
/** Finish run on worker (used in MT mode only) */
void FinishRunOnWorker() override;
/** Run the MC engine
* @param nofEvents : number of events to simulate
*/
void RunMC(Int_t nofEvents);
/**
* Set the magnetic field for simulation
* @param field: magnetic field
*/
void SetField(FairField* field);
/**
* Set the event generator for simulation
* @param fxGenerator: Event generator(s)
*/
void SetGenerator(FairPrimaryGenerator* fxGenerator);
/**
* Set the parameter containers needed by Tasks(if any)
*/
void SetParTask();
/**
* Switch for using Pythia as external decayer
* @param decayer: if TRUE pythia will decay particles specifid in the Decay Config macro (see
* SetPythiaDecayerConfig)
*/
void SetPythiaDecayer(Bool_t decayer) { fPythiaDecayer = decayer; }
/**
* set the decay configuration macro to be used by Pythia
*/
void SetPythiaDecayerConfig(const TString decayerConf) { fPythiaDecayerConfig = decayerConf; }
/**
* Switch for using the radiation length manager
*/
void SetRadiationLengthReg(Bool_t RadLen);
/**
* Switch for using the radiation map manager
*/
void SetRadiationMapReg(Bool_t RadMap);
/**
* Switch for debuging the tracking
*/
void SetTrackingDebugMode(Bool_t set) { fDebug = set; }
/**
* Switch for using 2 or 3 body phase-space decay
* @param decay: if TRUE 2/3 body phase space decay will be used for particle specified in the User Decay Config
* macro (see SetUserDecayConfig)
*/
void SetUserDecay(Bool_t decay) { fUserDecay = decay; }
/**
* set the decay configuration macro to be used by user decay
*/
void SetUserDecayConfig(const TString decayerConf) { fUserDecayConfig = decayerConf; }
/** Define action at each step, dispatch the action to the corresponding detectors */
void Stepping() override; // MC Application
/** Stop the run*/
virtual void StopRun();
/** Stop the run*/
virtual void StopMCRun();
/**Define maximum radius for tracking (optional) */
Double_t TrackingRmax() const override; // MC Application
/** Define maximum z for tracking (optional) */
Double_t TrackingZmax() const override; // MC Application
void AddMeshList(TObjArray* meshList);
/**
* Set if the current event should be written to the output file.
* The default value which is set back after each event is to store
* the event.
*/
void SetSaveCurrentEvent(Bool_t set) { fSaveCurrentEvent = set; }
/**
* Get the current application state.
*/
FairMCApplicationState GetState() const { return fState; }
/**
* Add module to the list of sensitive detectors.
*/
void AddSensitiveModule(std::string volName, FairModule* module);
/**
* Return non-owning pointer to FairRadGridManager
*/
auto GetRadGridMan() { return fRadGridMan.get(); }
/**
* Return the MT state of TVirtualMC
*/
auto GetIsMT() { return fMC ? fMC->IsMT() : false; }
/**
* Method introduced temporarily. It should go awway with DEPRACATED Bool_t FairDetector::ProcessHits()
*/
FairVolume* GetFairVolume();
private:
// methods
Int_t GetIonPdg(Int_t z, Int_t a) const;
/** Register output */
void RegisterOutput();
void UndoGeometryModifications();
/** Simulation Stack */
std::unique_ptr<FairGenericStack> fStack; //!
protected:
// data members
/**
* \brief Main instance
*
* Only set for instances created by \ref CloneForWorker
* and points to the instance from which the clone was
* created
*/
const FairMCApplication* fParent{nullptr}; //!
/**List of active detector */
TRefArray* fActiveDetectors;
/**List of FairTask*/
FairTask* fFairTaskList; //!
/**Module list in simulation*/
TObjArray* fModules;
/**flag for using Pythia as external decayer */
Bool_t fPythiaDecayer;
/** Pythia decay config macro*/
TString fPythiaDecayerConfig; //!
/**Pointer to thr I/O Manager */
FairRootManager* fRootManager; //!
/**Magnetic Field Pointer*/
FairField* fxField; //
/**Primary generator*/
FairPrimaryGenerator* fEvGen; //
/**MC Engine 1= Geant3, 2 = Geant4*/
Int_t fMcVersion; // mc Version
/** Track visualization manager */
FairTrajFilter* fTrajFilter; //!
/**Flag for accepted tracks for visualization*/
Bool_t fTrajAccepted; //!
/**Flag for using user decay*/
Bool_t fUserDecay;
/**User decay config macro*/
TString fUserDecayConfig; //!
/** Debug flag*/
Bool_t fDebug; //!
/**dispatcher internal use */
std::multimap<Int_t, FairVolume*> fVolMap; //!
/** Track position*/
/**dispatcher internal use RadLeng*/
std::map<Int_t, Int_t> fModVolMap; //!
TLorentzVector fTrkPos; //!
/** Flag for Radiation length register mode */
Bool_t fRadLength; //!
/**Radiation length Manager*/
FairRadLenManager* fRadLenMan; //!
/** Flag for Radiation map register mode */
Bool_t fRadMap; //!
/**Radiation Map Manager*/
FairRadMapManager* fRadMapMan; //!
/**Radiation map Grid Manager*/
std::unique_ptr<FairRadGridManager> fRadGridMan{}; //!
FairEventHeader* fEventHeader; //!
FairMCEventHeader* fMCEventHeader; //!
/** list of senstive detectors used in the simuation session*/
std::list<FairDetector*> listActiveDetectors; //!
/** list of all detectors used in the simuation session*/
std::list<FairDetector*> listDetectors; //!
/** Pointer to the current MC engine //!
*/
TVirtualMC* fMC;
FairRunSim* fRun{nullptr}; //!
/** Flag if the current event should be saved */
Bool_t fSaveCurrentEvent;
/** Current state */
FairMCApplicationState fState; //!
ClassDefOverride(FairMCApplication, 5);
private:
/** Private special copy constructor, needed for CloneForWorker */
FairMCApplication(const FairMCApplication&, std::unique_ptr<FairRunSim>);
FairRunInfo fRunInfo; //!
Bool_t fGeometryIsInitialized;
/**
* List of modules, mirrors fModules
*/
std::vector<FairModule*> fListModules{}; //!
/**
* List of sensitive detectors.
* To be used with TVirtualMCSensitiveDetector.
*/
std::map<std::string, FairModule*> fMapSensitiveDetectors;
/**
* Owned Modules (inside the worker)
*/
std::vector<std::unique_ptr<FairModule>> fOwnedModules; //!
/**
* Clean up the FairRunSim created in CloneForWorker
*/
std::unique_ptr<FairRunSim> fWorkerRunSim; //!
};
// inline functions
inline FairMCApplication* FairMCApplication::Instance()
{
return static_cast<FairMCApplication*>(TVirtualMCApplication::Instance());
}
#endif