CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MaterialBudgetCategorizer.cc
Go to the documentation of this file.
2 
3 #include "G4LogicalVolumeStore.hh"
4 #include "G4Material.hh"
5 #include "G4UnitsTable.hh"
6 #include "G4EmCalculator.hh"
7 #include "G4UnitsTable.hh"
8 
9 // rr
12 // rr
13 
14 #include <fstream>
15 #include <vector>
16 
17 using namespace std;
18 
20 {
21  buildMaps();
22 }
23 
25 {
26  //----- Build map volume name - volume index
27  G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
28  G4LogicalVolumeStore::iterator ite;
29  int ii = 0;
30  for (ite = lvs->begin(); ite != lvs->end(); ite++) {
31  theVolumeMap[(*ite)->GetName()] = ii++;
32  }
33 
34  //----- Build map material name - volume index
35  const G4MaterialTable* matTable = G4Material::GetMaterialTable();
36  G4int matSize = matTable->size();
37  for( ii = 0; ii < matSize; ii++ ) {
38  theMaterialMap[ (*matTable)[ii]->GetName()] = ii+1;
39  }
40 
41  // rr
42 
43  //----- Build map material name
44  for( int ii = 0; ii < matSize; ii++ ) {
45  float sup,sen,cab,col,ele,oth,air;
46  sup=sen=cab=col=ele=0.;
47  oth=1.;
48  air=0;
49  cout << " material " << (*matTable)[ii]->GetName() << " prepared"
50  << endl;
51  if((*matTable)[ii]->GetName()=="Air"
52  ||
53  (*matTable)[ii]->GetName()=="Vacuum"
54  ) {
55  air=1.000;
56  oth=0.000;
57  }
58  // actually this class does not work if there are spaces into material names --> Recover material properties
59  if((*matTable)[ii]->GetName()=="Carbon fibre str.") {
60  sup=1.000;
61  oth=0.000;
62  }
63  // X0
64  theX0Map[ (*matTable)[ii]->GetName() ].push_back(sup); // sup
65  theX0Map[ (*matTable)[ii]->GetName() ].push_back(sen); // sen
66  theX0Map[ (*matTable)[ii]->GetName() ].push_back(cab); // cab
67  theX0Map[ (*matTable)[ii]->GetName() ].push_back(col); // col
68  theX0Map[ (*matTable)[ii]->GetName() ].push_back(ele); // ele
69  theX0Map[ (*matTable)[ii]->GetName() ].push_back(oth); // oth
70  theX0Map[ (*matTable)[ii]->GetName() ].push_back(air); // air
71  // L0
72  theL0Map[ (*matTable)[ii]->GetName() ].push_back(sup); // sup
73  theL0Map[ (*matTable)[ii]->GetName() ].push_back(sen); // sen
74  theL0Map[ (*matTable)[ii]->GetName() ].push_back(cab); // cab
75  theL0Map[ (*matTable)[ii]->GetName() ].push_back(col); // col
76  theL0Map[ (*matTable)[ii]->GetName() ].push_back(ele); // ele
77  theL0Map[ (*matTable)[ii]->GetName() ].push_back(oth); // oth
78  theL0Map[ (*matTable)[ii]->GetName() ].push_back(air); // air
79  }
80  //
81 
82  //----- Build map material name - X0 contributes
83  cout << endl << endl << "MaterialBudgetCategorizer::Fill X0 Map" << endl;
84  std::string theMaterialX0FileName = edm::FileInPath("Validation/Geometry/data/trackerMaterials.x0").fullPath();
85  buildCategoryMap(theMaterialX0FileName, theX0Map);
86  //----- Build map material name - L0 contributes
87  cout << endl << endl << "MaterialBudgetCategorizer::Fill L0 Map" << endl;
88  std::string theMaterialL0FileName = edm::FileInPath("Validation/Geometry/data/trackerMaterials.l0").fullPath();
89  buildCategoryMap(theMaterialL0FileName, theL0Map);
90  // summary of all the materials loaded
91  cout << endl << endl << "MaterialBudgetCategorizer::Material Summary --------" << endl;
92  G4EmCalculator calc;
93  for( ii = 0; ii < matSize; ii++ ) {
94  // edm::LogInfo("MaterialBudgetCategorizer")
95  cout << " material " << (*matTable)[ii]->GetName()
96  << endl
97  << "\t density = " << G4BestUnit((*matTable)[ii]->GetDensity(),"Volumic Mass")
98  << endl
99  << "\t X0 = " << (*matTable)[ii]->GetRadlen() << " mm"
100  << endl
101  << "\t Energy threshold for photons for 100 mm range = "
102  << G4BestUnit(calc.ComputeEnergyCutFromRangeCut(100, G4String("gamma"), (*matTable)[ii]->GetName()) , "Energy")
103  << endl
104  << " SUP " << theX0Map[ (*matTable)[ii]->GetName() ][0]
105  << " SEN " << theX0Map[ (*matTable)[ii]->GetName() ][1]
106  << " CAB " << theX0Map[ (*matTable)[ii]->GetName() ][2]
107  << " COL " << theX0Map[ (*matTable)[ii]->GetName() ][3]
108  << " ELE " << theX0Map[ (*matTable)[ii]->GetName() ][4]
109  << " OTH " << theX0Map[ (*matTable)[ii]->GetName() ][5]
110  << " AIR " << theX0Map[ (*matTable)[ii]->GetName() ][6]
111  << endl
112  << "\t Lambda0 = " << (*matTable)[ii]->GetNuclearInterLength() << " mm"
113  << endl
114  << " SUP " << theL0Map[ (*matTable)[ii]->GetName() ][0]
115  << " SEN " << theL0Map[ (*matTable)[ii]->GetName() ][1]
116  << " CAB " << theL0Map[ (*matTable)[ii]->GetName() ][2]
117  << " COL " << theL0Map[ (*matTable)[ii]->GetName() ][3]
118  << " ELE " << theL0Map[ (*matTable)[ii]->GetName() ][4]
119  << " OTH " << theL0Map[ (*matTable)[ii]->GetName() ][5]
120  << " AIR " << theL0Map[ (*matTable)[ii]->GetName() ][6]
121  << endl;
122  if( theX0Map[ (*matTable)[ii]->GetName() ][5] == 1 || theL0Map[ (*matTable)[ii]->GetName() ][5] == 1 )
123  std::cout << "WARNING: material with no category: " << (*matTable)[ii]->GetName() << std::endl;
124  }
125  //
126  // rr
127 
128 }
129 
130 void MaterialBudgetCategorizer::buildCategoryMap(std::string theMaterialFileName, std::map<std::string,std::vector<float> >& theMap) {
131  // const G4MaterialTable* matTable = G4Material::GetMaterialTable();
132  // G4int matSize = matTable->size();
133 
134  std::ifstream theMaterialFile(theMaterialFileName.c_str());
135  if (!theMaterialFile)
136  cms::Exception("LogicError") <<" File not found " << theMaterialFile;
137 
138  // fill everything as "other"
139  float sup,sen,cab,col,ele,oth,air;
140  sup=sen=cab=col=ele=0.;
141  oth=1.;
142  air=0;
143 
144  //
145  std::string materialName;
146  while(theMaterialFile) {
147  theMaterialFile >> materialName;
148  theMaterialFile >> sup >> sen >> cab >> col >> ele;
149  oth = 0.000;
150  air = 0.000;
151  theMap[materialName].clear(); // clear before re-filling
152  theMap[materialName].push_back(sup); // sup
153  theMap[materialName].push_back(sen); // sen
154  theMap[materialName].push_back(cab); // cab
155  theMap[materialName].push_back(col); // col
156  theMap[materialName].push_back(ele); // ele
157  theMap[materialName].push_back(oth); // oth
158  theMap[materialName].push_back(air); // air
159  cout << " material " << materialName << " filled "
160  << " SUP " << sup
161  << " SEN " << sen
162  << " CAB " << cab
163  << " COL " << col
164  << " ELE " << ele
165  << " OTH " << oth
166  << " AIR " << air
167  << endl;
168  }
169 
170 }
int ii
Definition: cuy.py:588
void buildCategoryMap(std::string theMaterialFileName, std::map< std::string, std::vector< float > > &theMap)
tuple cout
Definition: gather_cfg.py:121
std::string fullPath() const
Definition: FileInPath.cc:165
int col
Definition: cuy.py:1008