CMS 3D CMS Logo

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 
11 
12 #include <fstream>
13 #include <vector>
14 
16 {
17  //----- Build map volume name - volume index
18  G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
19  G4LogicalVolumeStore::iterator ite;
20  int ii = 0;
21  for (ite = lvs->begin(); ite != lvs->end(); ite++) {
22  theVolumeMap[(*ite)->GetName()] = ii++;
23  }
24 
25  if ( mode.compare("Tracker") == 0 ) {
26  std::string theMaterialX0FileName = edm::FileInPath("Validation/Geometry/data/trackerMaterials.x0").fullPath();
27  buildCategoryMap(theMaterialX0FileName, theX0Map);
28  std::string theMaterialL0FileName = edm::FileInPath("Validation/Geometry/data/trackerMaterials.l0").fullPath();
29  buildCategoryMap(theMaterialL0FileName, theL0Map);
30  } else if ( mode.compare("HGCal") == 0 ){
31  std::string thehgcalMaterialX0FileName = edm::FileInPath("Validation/Geometry/data/hgcalMaterials.x0").fullPath();
32  buildHGCalCategoryMap(thehgcalMaterialX0FileName, theHGCalX0Map);
33  std::string thehgcalMaterialL0FileName = edm::FileInPath("Validation/Geometry/data/hgcalMaterials.l0").fullPath();
34  buildHGCalCategoryMap(thehgcalMaterialL0FileName, theHGCalL0Map);
35  }
36 }
37 
39  std::map<std::string,std::vector<float> >& theMap)
40 {
41 
42  std::ifstream theMaterialFile(theMaterialFileName);
43 
44  if (!theMaterialFile)
45  cms::Exception("LogicError") << " File not found " << theMaterialFileName;
46 
47  float sup,sen,cab,col,ele,oth,air;
48  sup=sen=cab=col=ele=0.;
49 
50  std::string materialName;
51 
52  while(theMaterialFile) {
53  theMaterialFile >> materialName;
54  theMaterialFile >> sup >> sen >> cab >> col >> ele;
55 
56  if (materialName[0] == '#') //Ignore comments
57  continue;
58 
59  oth = 0.000;
60  air = 0.000;
61  theMap[materialName].clear(); // clear before re-filling
62  theMap[materialName].push_back(sup); // sup
63  theMap[materialName].push_back(sen); // sen
64  theMap[materialName].push_back(cab); // cab
65  theMap[materialName].push_back(col); // col
66  theMap[materialName].push_back(ele); // ele
67  theMap[materialName].push_back(oth); // oth
68  theMap[materialName].push_back(air); // air
69  edm::LogInfo("MaterialBudget")
70  << "MaterialBudgetCategorizer: Material " << materialName << " filled: "
71  << "\n\tSUP " << sup
72  << "\n\tSEN " << sen
73  << "\n\tCAB " << cab
74  << "\n\tCOL " << col
75  << "\n\tELE " << ele
76  << "\n\tOTH " << oth
77  << "\n\tAIR " << air
78  << "\n\tAdd up to: " << sup + sen + cab + col + ele + oth + air;
79  }
80 }
81 
83  std::map<std::string,std::vector<float> >& theMap)
84 {
85 
86  std::ifstream theMaterialFile(theMaterialFileName);
87  if (!theMaterialFile)
88  cms::Exception("LogicError") <<" File not found " << theMaterialFileName;
89 
90  // fill everything as "other"
91  float Air,Cables,Copper,H_Scintillator,Lead,M_NEMA_FR4_plate,Silicon,StainlessSteel,WCu, oth;
92  Air=Cables=Copper=H_Scintillator=Lead=M_NEMA_FR4_plate=Silicon=StainlessSteel=WCu=0.;
93 
94  std::string materialName;
95  while(theMaterialFile) {
96  theMaterialFile >> materialName;
97  theMaterialFile >> Air >> Cables >> Copper >> H_Scintillator >> Lead >> M_NEMA_FR4_plate >> Silicon >> StainlessSteel >> WCu;
98  // Skip comments
99  if (materialName[0] == '#')
100  continue;
101  // Substitute '*' with spaces
102  std::replace(materialName.begin(), materialName.end(), '*', ' ');
103  oth = 0.000;
104  theMap[materialName].clear(); // clear before re-filling
105  theMap[materialName].push_back(Air ); // Air
106  theMap[materialName].push_back(Cables ); // Cables
107  theMap[materialName].push_back(Copper ); // Copper
108  theMap[materialName].push_back(H_Scintillator ); // H_Scintillator
109  theMap[materialName].push_back(Lead ); // Lead
110  theMap[materialName].push_back(M_NEMA_FR4_plate); // M_NEMA_FR4_plate
111  theMap[materialName].push_back(Silicon ); // Silicon
112  theMap[materialName].push_back(StainlessSteel ); // StainlessSteel
113  theMap[materialName].push_back(WCu ); // WCu
114  theMap[materialName].push_back(oth ); // oth
115  edm::LogInfo("MaterialBudget")
116  << "MaterialBudgetCategorizer: material " << materialName << " filled "
117  << std::endl
118  << "\tAir " << Air << std::endl
119  << "\tCables " << Cables << std::endl
120  << "\tCopper " << Copper << std::endl
121  << "\tH_Scintillator " << H_Scintillator << std::endl
122  << "\tLead " << Lead << std::endl
123  << "\tM_NEMA_FR4_plate " << M_NEMA_FR4_plate << std::endl
124  << "\tSilicon " << Silicon << std::endl
125  << "\tStainlessSteel " << StainlessSteel << std::endl
126  << "\tWCu " << WCu << std::endl
127  << "\tOTH " << oth;
128  }
129 
130 }
std::map< std::string, int > theVolumeMap
def replace(string, replacements)
std::map< std::string, std::vector< float > > theX0Map
std::map< std::string, std::vector< float > > theHGCalL0Map
void buildCategoryMap(std::string theMaterialFileName, std::map< std::string, std::vector< float > > &theMap)
ii
Definition: cuy.py:590
std::map< std::string, std::vector< float > > theL0Map
std::map< std::string, std::vector< float > > theHGCalX0Map
col
Definition: cuy.py:1010
std::string fullPath() const
Definition: FileInPath.cc:197
void buildHGCalCategoryMap(std::string theMaterialFileName, std::map< std::string, std::vector< float > > &theMap)