Project
Loading...
Searching...
No Matches
MaterialManager.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef ALICEO2_BASE_MATERIALMANAGER_H_
16#define ALICEO2_BASE_MATERIALMANAGER_H_
17
18#include "Rtypes.h"
19#include <map>
20#include <unordered_map>
21#include <initializer_list>
22#include <iosfwd>
23
24class TGeoMedium;
25
26namespace o2
27{
28namespace base
29{
30// put processes and cuts in namespace to make them available from there
32enum class EProc { kPAIR = 0,
33 kCOMP,
34 kPHOT,
35 kPFIS,
36 kDRAY,
37 kANNI,
38 kBREM,
39 kHADR,
40 kMUNU,
41 kDCAY,
42 kLOSS,
43 kMULS,
44 kCKOV,
45 kLABS,
46 kRAYL
47};
48
50enum class ECut { kCUTGAM = 0,
51 kCUTELE,
52 kCUTNEU,
53 kCUTHAD,
54 kCUTMUO,
55 kBCUTE,
56 kBCUTM,
57 kDCUTE,
58 kDCUTM,
59 kPPCUTM,
60 kTOFMAX };
61// Central class managing creation of material, mixtures, mediums through
62// the VMC interface. All material creations should go through this class.
63// Also manages material indices and offers ways to retrieve them
64// given a name (such as a given module name).
66{
67 public:
69 {
70 static MaterialManager inst;
71 return inst;
72 }
73
74 // Module composition
75 void Material(const char* modname, Int_t imat, const char* name, Float_t a, Float_t z, Float_t dens, Float_t radl,
76 Float_t absl, Float_t* buf = nullptr, Int_t nwbuf = 0);
77
78 void Mixture(const char* modname, Int_t imat, const char* name, Float_t* a, Float_t* z, Float_t dens, Int_t nlmat,
79 Float_t* wmat);
80
81 void Medium(const char* modname, Int_t numed, const char* name, Int_t nmat, Int_t isvol, Int_t ifield, Float_t fieldm,
82 Float_t tmaxfd, Float_t stemax, Float_t deemax, Float_t epsil, Float_t stmin, Float_t* ubuf = nullptr,
83 Int_t nbuf = 0);
84
90 //
92 enum class ESpecial : bool { kTRUE = true,
93 kFALSE = false };
94 void DefaultProcesses(const std::initializer_list<std::pair<EProc, int>>& parIDValMap)
95 {
96 Processes(ESpecial::kFALSE, -1, parIDValMap);
97 }
101 void SpecialProcesses(const char* modname, int localindex,
102 const std::initializer_list<std::pair<EProc, int>>& parIDValMap)
103 {
104 int globalindex = getMediumID(modname, localindex);
105 if (globalindex != -1) {
106 Processes(ESpecial::kTRUE, globalindex, parIDValMap);
107 }
108 }
110 void DefaultProcess(EProc parID, int val) { Process(ESpecial::kFALSE, -1, parID, val); }
111
113 void SpecialProcess(const char* modname, int localindex, EProc parID, int val);
114
117 void DefaultCuts(const std::initializer_list<std::pair<ECut, Float_t>>& parIDValMap)
118 {
119 Cuts(ESpecial::kFALSE, -1, parIDValMap);
120 }
121
125 void SpecialCuts(const char* modname, int localindex,
126 const std::initializer_list<std::pair<ECut, Float_t>>& parIDValMap);
127
129 void DefaultCut(ECut parID, Float_t val) { Cut(ESpecial::kFALSE, -1, parID, val); }
130
132 void SpecialCut(const char* modname, int localindex, ECut parID, Float_t val);
133
135 void SetLowEnergyNeutronTransport(bool flag) { mLowNeut = flag; }
136
138 void loadCutsAndProcessesFromFile(const char* modname, const char* filename);
139 void loadCutsAndProcessesFromJSON(ESpecial special = ESpecial::kFALSE, std::string const& filename = "");
140 void writeCutsAndProcessesToJSON(std::string const& filename = "");
141
143 void enableSpecialProcesses(bool val = true) { mApplySpecialProcesses = val; }
144 bool specialProcessesEnabled() const { return mApplySpecialProcesses; }
145 void enableSpecialCuts(bool val = true) { mApplySpecialCuts = val; }
146 bool specialCutsEnabled() const { return mApplySpecialCuts; }
147
148 // returns global material ID given a "local" material ID for this detector
149 // returns -1 in case local ID not found
150 int getMaterialID(const char* modname, int imat) const;
151
152 // returns global medium ID given a "local" medium ID for this detector
153 // returns -1 in case local ID not found
154 int getMediumID(const char* modname, int imed) const;
155
156 // various methods to get the TGeoMedium instance
157 TGeoMedium* getTGeoMedium(const std::string& modname, int localid);
158 TGeoMedium* getTGeoMedium(const char* mediumname);
159
162 void getMediumIDMappingAsVector(const char* modname, std::vector<int>& mapping) const;
163
165 const char* getProcessName(EProc process) const;
166
167 const char* getCutName(ECut cut) const;
168
170 const char* getModuleFromMediumID(int globalindex) const;
171
173 const char* getMediumNameFromMediumID(int globalindex) const;
174
176 void getMediaWithSpecialProcess(EProc process, std::vector<int>& mediumProcessVector) const;
177
179 void getMediaWithSpecialCut(ECut cut, std::vector<Float_t>& mediumCutVector) const;
180
182 void getDefaultProcesses(std::vector<std::pair<EProc, int>>& processVector);
183
185 void getDefaultCuts(std::vector<std::pair<ECut, Float_t>>& cutVector);
186
188 void getSpecialProcesses(int globalindex, std::vector<std::pair<EProc, int>>& processVector);
189
191 void getSpecialProcesses(const char* modname, int localindex, std::vector<std::pair<EProc, int>>& processVector);
192
194 void getSpecialCuts(int globalindex, std::vector<std::pair<ECut, Float_t>>& cutVector);
195
197 void getSpecialCuts(const char* modname, int localindex, std::vector<std::pair<ECut, Float_t>>& cutVector);
198
200 void printProcesses(std::ostream& stream) const;
202 void printCuts(std::ostream& stream) const;
203
204 // print out all registered materials
205 void printMaterials() const;
206
207 // print out all registered media
208 void printMedia() const;
209
212 static void printContainingMedia(std::string const& volumename);
213
214 private:
215 MaterialManager() = default;
216
217 bool mDensityMapInitialized = false;
218 std::unordered_map<std::string, float> mDensityMap;
219
220 void initDensityMap();
221 float getDensity(std::string const& modname, std::string const& matname);
222
223 // Hide details by providing these private methods so it cannot happen that special settings
224 // are applied as default settings by accident using a boolean flag
225 void Processes(ESpecial special, int globalindex, const std::initializer_list<std::pair<EProc, int>>& parIDValMap);
226 void Cuts(ESpecial special, int globalindex, const std::initializer_list<std::pair<ECut, Float_t>>& parIDValMap);
227 void Process(ESpecial special, int globalindex, EProc parID, int val);
228 void Cut(ESpecial special, int globalindex, ECut parID, Float_t val);
229
230 // insert material name
231 void insertMaterialName(const char* uniquename, int index);
232 void insertMediumName(const char* uniquename, int index);
233 void insertTGeoMedium(std::string modname, int localindex);
234
235 // lookup structures
236 std::map<std::string, std::map<int, int>>
237 mMaterialMap; // map of module name -> map of local index to global index for Materials
238 std::map<std::string, std::map<int, int>> mMediumMap; // map of module name -> map of local index to global index for Media
239
240 std::map<int, std::map<EProc, int>> mMediumProcessMap; // map of global medium id to parameter-value map of processes
241 std::map<int, std::map<ECut, Float_t>> mMediumCutMap; // map of global medium id to parameter-value map of cuts
242 std::map<ECut, Float_t> mDefaultCutMap; // map of global cuts
243 std::map<EProc, int> mDefaultProcessMap; // map of global processes
244
245 // a map allowing to lookup TGeoMedia from detector name and local medium index
246 std::map<std::pair<std::string, int>, TGeoMedium*> mTGeoMediumMap;
247
248 // finally, we'd like to keep track of tracking parameters and processes activated per medium
249
250 std::map<std::string, int> mMaterialNameToGlobalIndexMap; // map of unique material name to global index
251 std::map<std::string, int> mMediumNameToGlobalIndexMap; // map of unique material name to global index
252
258 // \note Currently, the naming convention of GEANT4 v10.3.3 is used.
259 // \note This might be overhead so far but makes the MaterialManager and therefore O2 finally capable of
260 // forwarding cuts/processes to arbitrary engines.
261 // \todo Is there a more elegant implementation?
263 const static std::unordered_map<ECut, const char*> mCutIDToName;
265 const static std::unordered_map<EProc, const char*> mProcessIDToName;
266
268 bool mApplySpecialProcesses = true;
269 bool mApplySpecialCuts = true;
271 bool mLowNeut = false;
272
273 public:
275};
276
278{
279 auto it = mProcessIDToName.find(process);
280 if (it != mProcessIDToName.end()) {
281 return it->second;
282 }
283 return "UNKNOWN";
284}
285
286inline const char* MaterialManager::getCutName(ECut cut) const
287{
288 auto it = mCutIDToName.find(cut);
289 if (it != mCutIDToName.end()) {
290 return it->second;
291 }
292 return "UNKNOWN";
293}
294
295} // namespace base
296} // namespace o2
297
298#endif
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to process
void printCuts(std::ostream &stream) const
Print all cuts for all media as well as defaults.
void SpecialProcesses(const char *modname, int localindex, const std::initializer_list< std::pair< EProc, int > > &parIDValMap)
void getSpecialCuts(int globalindex, std::vector< std::pair< ECut, Float_t > > &cutVector)
Get special cuts for global medium ID.
void SpecialCuts(const char *modname, int localindex, const std::initializer_list< std::pair< ECut, Float_t > > &parIDValMap)
const char * getCutName(ECut cut) const
void getMediumIDMappingAsVector(const char *modname, std::vector< int > &mapping) const
void getDefaultProcesses(std::vector< std::pair< EProc, int > > &processVector)
Fill vector with default processes.
void printProcesses(std::ostream &stream) const
Print all processes for all media as well as defaults.
void enableSpecialCuts(bool val=true)
void writeCutsAndProcessesToJSON(std::string const &filename="")
void loadCutsAndProcessesFromFile(const char *modname, const char *filename)
load cuts and process flags from a data file (like AliRoot did)
void loadCutsAndProcessesFromJSON(ESpecial special=ESpecial::kFALSE, std::string const &filename="")
void getMediaWithSpecialProcess(EProc process, std::vector< int > &mediumProcessVector) const
get global medium IDs where special process is set along with process value
int getMediumID(const char *modname, int imed) const
void getSpecialProcesses(int globalindex, std::vector< std::pair< EProc, int > > &processVector)
Get special processes for global medium ID.
static MaterialManager & Instance()
ClassDefNV(MaterialManager, 0)
const char * getMediumNameFromMediumID(int globalindex) const
Get medium name from global medium ID.
void DefaultCuts(const std::initializer_list< std::pair< ECut, Float_t > > &parIDValMap)
void getMediaWithSpecialCut(ECut cut, std::vector< Float_t > &mediumCutVector) const
get global medium IDs where special cut is set along with cut value
static void printContainingMedia(std::string const &volumename)
void Mixture(const char *modname, Int_t imat, const char *name, Float_t *a, Float_t *z, Float_t dens, Int_t nlmat, Float_t *wmat)
void SpecialProcess(const char *modname, int localindex, EProc parID, int val)
Custom setting of process or cut given parameter name and value.
void DefaultCut(ECut parID, Float_t val)
set default cut
void Medium(const char *modname, Int_t numed, const char *name, Int_t nmat, Int_t isvol, Int_t ifield, Float_t fieldm, Float_t tmaxfd, Float_t stemax, Float_t deemax, Float_t epsil, Float_t stmin, Float_t *ubuf=nullptr, Int_t nbuf=0)
void DefaultProcess(EProc parID, int val)
set default process
const char * getProcessName(EProc process) const
Get the names of processes and cuts providing an respective enum member.
void SpecialCut(const char *modname, int localindex, ECut parID, Float_t val)
Custom setting of process or cut given parameter name and value.
void SetLowEnergyNeutronTransport(bool flag)
Set flag fro low energy neutron transport.
void Material(const char *modname, Int_t imat, const char *name, Float_t a, Float_t z, Float_t dens, Float_t radl, Float_t absl, Float_t *buf=nullptr, Int_t nwbuf=0)
void enableSpecialProcesses(bool val=true)
Set flags whether to use special cuts and process settings.
const char * getModuleFromMediumID(int globalindex) const
Get module name which has medium of a certain global medium ID.
ESpecial
scoped enum to decide whether settings are done globally or for a certain medium
int getMaterialID(const char *modname, int imat) const
void getDefaultCuts(std::vector< std::pair< ECut, Float_t > > &cutVector)
Fill vector with default cuts.
TGeoMedium * getTGeoMedium(const std::string &modname, int localid)
void DefaultProcesses(const std::initializer_list< std::pair< EProc, int > > &parIDValMap)
GLuint const GLchar * name
Definition glcorearb.h:781
GLuint GLfloat * val
Definition glcorearb.h:1582
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLuint GLuint stream
Definition glcorearb.h:1806
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glcorearb.h:2514
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
ECut
cuts available
EProc
processes available
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()