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