MaterialPropertyLoader.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file MaterialPropertyLoader.cxx
3 //
4 /// \author bjpjones@mit.edu
5 ////////////////////////////////////////////////////////////////////////
6 // Class to set material properties for different materials in
7 // the detector. Currently mainly used to set optical properties
8 // for LAr and other optical components
9 //
10 
11 
12 
14 #include "CoreUtils/ServiceUtil.h"
15 
16 #include "Geant4/G4Material.hh"
17 #include "Geant4/G4MaterialPropertiesTable.hh"
19 
22 #include "CoreUtils/ServiceUtil.h"
23 
24 namespace gar {
25  namespace garg4 {
26 
27  //----------------------------------------------
29  std::string const& Property,
30  std::map<double, double> const& PropertyVector,
31  double Unit)
32  {
33  std::map<double,double> PropVectorWithUnit;
34  for(auto const& itr : PropertyVector){
35  PropVectorWithUnit[itr.first * CLHEP::eV] = itr.second * Unit;
36  }
37 
38  fPropertyList[Material][Property] = PropVectorWithUnit;
39 
40  MF_LOG_INFO("MaterialPropertyLoader")
41  <<"Added property "
42  << Material<< " "
43  << Property;
44  }
45 
46  //----------------------------------------------
48  std::string const& Property,
49  double PropertyValue,
50  double Unit)
51  {
52  fConstPropertyList[Material][Property]=PropertyValue*Unit;
53 
54  MF_LOG_INFO("MaterialPropertyLoader")
55  << "Added const property "
56  << Material
57  << " "
58  << Property
59  << " = "
60  << PropertyValue;
61  }
62 
63  //----------------------------------------------
65  double PropertyValue,
66  double Unit)
67  {
68  fBirksConstants[Material] = PropertyValue * Unit;
69  MF_LOG_INFO("MaterialPropertyLoader")
70  << "Set Birks constant "
71  << Material;
72  }
73 
74  //----------------------------------------------
75  void MaterialPropertyLoader::UpdateGeometry(G4LogicalVolumeStore * lvs)
76  {
77  std::map<std::string,G4MaterialPropertiesTable*> MaterialTables;
78  std::map<std::string,bool> MaterialsSet;
79 
80  MF_LOG_INFO("MaterialPropertyLoader")
81  << "UPDATING GEOMETRY";
82 
83  // Loop over each material with a property vector and create a new material table for it
84  for(auto const& itr : fPropertyList) {
85  std::string Material = itr.first;
86  MaterialsSet[Material] = true;
87  MaterialTables[Material] = new G4MaterialPropertiesTable;
88  }
89 
90  // Loop over each material with a const property,
91  // if material table does not exist, create one
92  for(auto const& itr : fConstPropertyList){
93  std::string Material = itr.first;
94  if(!MaterialsSet[Material]){
95  MaterialsSet[Material] = true;
96  MaterialTables[Material] = new G4MaterialPropertiesTable;
97  }
98  }
99 
100  // For each property vector, convert to an array of g4doubles and
101  // feed to materials table Lots of firsts and seconds! See annotation
102  // in MaterialPropertyLoader.h to follow what each element is
103 
104  for(auto const& itr : fPropertyList){
105  std::string Material = itr.first;
106  for(auto const& jitr : itr.second){
107  std::string Property = jitr.first;
108  std::vector<G4double> g4MomentumVector;
109  std::vector<G4double> g4PropertyVector;
110 
111  for(auto const& kitr : jitr.second){
112  g4MomentumVector.push_back(kitr.first);
113  g4PropertyVector.push_back(kitr.second);
114  }
115  int NoOfElements = g4MomentumVector.size();
116  MaterialTables[Material]->AddProperty(Property.c_str(),
117  &g4MomentumVector[0],
118  &g4PropertyVector[0],
119  NoOfElements);
120  MF_LOG_INFO("MaterialPropertyLoader")
121  << "Added property "
122  << Property
123  << " to material table "
124  << Material;
125  }
126  }
127 
128  //Add each const property element
129  for(auto const& itr : fConstPropertyList){
130  std::string Material = itr.first;
131  for(auto const& jitr : itr.second){
132  std::string Property = jitr.first;
133  G4double PropertyValue = jitr.second;
134  MaterialTables[Material]->AddConstProperty(Property.c_str(), PropertyValue);
135 
136  MF_LOG_INFO("MaterialPropertyLoader")
137  << "Added const property "
138  << Property
139  << " to material table "
140  << Material;
141  }
142  }
143 
144  //Loop through geometry elements and apply relevant material table where materials match
145  for ( G4LogicalVolumeStore::iterator i = lvs->begin(); i != lvs->end(); ++i ){
146  G4LogicalVolume* volume = (*i);
147  G4Material* TheMaterial = volume->GetMaterial();
148  std::string Material = TheMaterial->GetName();
149  for(auto const& jitr : MaterialTables){
150  if(Material == jitr.first){
151  TheMaterial->SetMaterialPropertiesTable(jitr.second);
152  //Birks Constant, for some reason, must be set separately
153  if(fBirksConstants[Material]!=0)
154  TheMaterial->GetIonisation()->SetBirksConstant(fBirksConstants[Material]);
155  volume->SetMaterial(TheMaterial);
156  }
157  }
158  }
159  }
160 
161  //--------------------------------------------------------------------------
163  std::map<std::string,std::map<double, double> > const& Reflectances,
164  std::map<std::string,std::map<double, double> > const& DiffuseFractions)
165  {
166  std::map<double, double> ReflectanceToStore;
167  std::map<double, double> DiffuseToStore;
168 
169  for(auto const& itMat : Reflectances){
170  std::string ReflectancePropName = std::string("REFLECTANCE_") + itMat.first;
171  ReflectanceToStore.clear();
172  for(auto const& itEn : itMat.second){
173  ReflectanceToStore[itEn.first] = itEn.second;
174  }
175  SetMaterialProperty("GAr", ReflectancePropName, ReflectanceToStore,1);
176  }
177 
178  for(auto const& itMat : DiffuseFractions){
179  std::string DiffusePropName = std::string("DIFFUSE_REFLECTANCE_FRACTION_") + itMat.first;
180  DiffuseToStore.clear();
181  for(auto const& itEn : itMat.second){
182  DiffuseToStore[itEn.first] = itEn.second;
183  }
184  SetMaterialProperty("GAr",
185  DiffusePropName,
186  DiffuseToStore,
187  1);
188  }
189 
190  }
191 
192  //--------------------------------------------------------------------------
194  {
195 // const detinfo::GArProperties* GarProp = gar::providerFrom<detinfo::GArPropertiesService>();
196 // const detinfo::DetectorProperties* DetProp = gar::providerFrom<detinfo::DetectorPropertiesService>();
197 
198  const detinfo::ECALProperties* EcalProp = gar::providerFrom<detinfo::ECALPropertiesService>();
199 
200  SetMaterialConstProperty("Scintillator", "DENSITY", 1.06, CLHEP::g/CLHEP::cm3);
201  SetBirksConstant("Scintillator", EcalProp->ScintBirksConstant(), CLHEP::mm/CLHEP::MeV);
202  }
203 
204  } // garg4
205 } // gar
virtual double ScintBirksConstant() const =0
intermediate_table::iterator iterator
static constexpr double g
Definition: Units.h:144
std::map< std::string, double > fBirksConstants
std::string string
Definition: nybbler.cc:12
void SetBirksConstant(std::string const &, double, double)
static constexpr double cm3
Definition: Units.h:70
static const std::string volume[nvol]
void UpdateGeometry(G4LogicalVolumeStore *)
static constexpr double MeV
Definition: Units.h:129
static constexpr double eV
Definition: Units.h:127
void SetMaterialConstProperty(std::string const &Material, std::string const &Property, double Value, double Unit)
std::map< std::string, std::map< std::string, double > > fConstPropertyList
#define MF_LOG_INFO(category)
void SetMaterialProperty(std::string const &Material, std::string const &Property, std::map< double, double > const &Values, double Unit)
General GArSoft Utilities.
std::map< std::string, std::map< std::string, std::map< double, double > > > fPropertyList
void SetReflectances(std::string const &, std::map< std::string, std::map< double, double > > const &, std::map< std::string, std::map< double, double > > const &)
static constexpr double mm
Definition: Units.h:65
Definition: types.h:32