CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Validation/Geometry/src/MaterialBudgetCategorizer.cc

Go to the documentation of this file.
00001 #include "Validation/Geometry/interface/MaterialBudgetCategorizer.h"
00002 //#include "Utilities/UI/interface/SimpleConfigurable.h"
00003 
00004 #include "G4LogicalVolumeStore.hh"
00005 #include "G4Material.hh"
00006 #include "G4UnitsTable.hh"
00007 #include "G4EmCalculator.hh"
00008 #include "G4UnitsTable.hh"
00009 
00010 // rr
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 // rr
00014 
00015 #include <fstream>
00016 #include <vector>
00017 
00018 using namespace std;
00019 
00020 MaterialBudgetCategorizer::MaterialBudgetCategorizer()
00021 {
00022   buildMaps();
00023 }
00024 
00025 void MaterialBudgetCategorizer::buildMaps()
00026 {
00027   //----- Build map volume name - volume index
00028   G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
00029   G4LogicalVolumeStore::iterator ite;
00030   int ii = 0;
00031   for (ite = lvs->begin(); ite != lvs->end(); ite++) {
00032     theVolumeMap[(*ite)->GetName()] = ii++;
00033   }
00034   
00035   //----- Build map material name - volume index
00036   const G4MaterialTable* matTable = G4Material::GetMaterialTable();
00037   G4int matSize = matTable->size();
00038   for( ii = 0; ii < matSize; ii++ ) {
00039     theMaterialMap[ (*matTable)[ii]->GetName()] = ii+1;
00040   }
00041   
00042   // rr
00043 
00044   //----- Build map material name
00045   for( int ii = 0; ii < matSize; ii++ ) {
00046     float sup,sen,cab,col,ele,oth,air;
00047     sup=sen=cab=col=ele=0.;
00048     oth=1.;
00049     air=0;
00050     cout << " material " << (*matTable)[ii]->GetName() << " prepared"
00051          << endl;
00052     if((*matTable)[ii]->GetName()=="Air"
00053        ||
00054        (*matTable)[ii]->GetName()=="Vacuum"
00055        ) {
00056       air=1.000; 
00057       oth=0.000;
00058     }
00059     // actually this class does not work if there are spaces into material names --> Recover material properties
00060     if((*matTable)[ii]->GetName()=="Carbon fibre str.") { 
00061       sup=1.000; 
00062       oth=0.000;
00063     }
00064     // X0
00065     theX0Map[ (*matTable)[ii]->GetName() ].push_back(sup); // sup
00066     theX0Map[ (*matTable)[ii]->GetName() ].push_back(sen); // sen
00067     theX0Map[ (*matTable)[ii]->GetName() ].push_back(cab); // cab
00068     theX0Map[ (*matTable)[ii]->GetName() ].push_back(col); // col
00069     theX0Map[ (*matTable)[ii]->GetName() ].push_back(ele); // ele
00070     theX0Map[ (*matTable)[ii]->GetName() ].push_back(oth); // oth
00071     theX0Map[ (*matTable)[ii]->GetName() ].push_back(air); // air
00072     // L0
00073     theL0Map[ (*matTable)[ii]->GetName() ].push_back(sup); // sup
00074     theL0Map[ (*matTable)[ii]->GetName() ].push_back(sen); // sen
00075     theL0Map[ (*matTable)[ii]->GetName() ].push_back(cab); // cab
00076     theL0Map[ (*matTable)[ii]->GetName() ].push_back(col); // col
00077     theL0Map[ (*matTable)[ii]->GetName() ].push_back(ele); // ele
00078     theL0Map[ (*matTable)[ii]->GetName() ].push_back(oth); // oth
00079     theL0Map[ (*matTable)[ii]->GetName() ].push_back(air); // air
00080   }
00081   //
00082   
00083   //----- Build map material name - X0 contributes
00084   cout << endl << endl << "MaterialBudgetCategorizer::Fill X0 Map" << endl;
00085   std::string theMaterialX0FileName = edm::FileInPath("Validation/Geometry/data/trackerMaterials.x0").fullPath();
00086   buildCategoryMap(theMaterialX0FileName, theX0Map);
00087   //----- Build map material name - L0 contributes
00088   cout << endl << endl << "MaterialBudgetCategorizer::Fill L0 Map" << endl;
00089   std::string theMaterialL0FileName = edm::FileInPath("Validation/Geometry/data/trackerMaterials.l0").fullPath();
00090   buildCategoryMap(theMaterialL0FileName, theL0Map);
00091   // summary of all the materials loaded
00092   cout << endl << endl << "MaterialBudgetCategorizer::Material Summary --------" << endl;
00093   G4EmCalculator calc;
00094   for( ii = 0; ii < matSize; ii++ ) {
00095     //    edm::LogInfo("MaterialBudgetCategorizer")
00096     cout << " material " << (*matTable)[ii]->GetName()
00097          << endl
00098          << "\t density = " << G4BestUnit((*matTable)[ii]->GetDensity(),"Volumic Mass")
00099          << endl
00100          << "\t X0 = "      << (*matTable)[ii]->GetRadlen()             << " mm"
00101          << endl
00102          << "\t Energy threshold for photons for 100 mm range = "
00103          << G4BestUnit(calc.ComputeEnergyCutFromRangeCut(100, G4String("gamma"), (*matTable)[ii]->GetName()) , "Energy")
00104          << endl
00105          << " SUP " << theX0Map[ (*matTable)[ii]->GetName() ][0] 
00106          << " SEN " << theX0Map[ (*matTable)[ii]->GetName() ][1]
00107          << " CAB " << theX0Map[ (*matTable)[ii]->GetName() ][2]
00108          << " COL " << theX0Map[ (*matTable)[ii]->GetName() ][3]
00109          << " ELE " << theX0Map[ (*matTable)[ii]->GetName() ][4]
00110          << " OTH " << theX0Map[ (*matTable)[ii]->GetName() ][5]
00111          << " AIR " << theX0Map[ (*matTable)[ii]->GetName() ][6]
00112          << endl
00113          << "\t Lambda0 = " << (*matTable)[ii]->GetNuclearInterLength() << " mm"
00114          << endl
00115          << " SUP " << theL0Map[ (*matTable)[ii]->GetName() ][0] 
00116          << " SEN " << theL0Map[ (*matTable)[ii]->GetName() ][1]
00117          << " CAB " << theL0Map[ (*matTable)[ii]->GetName() ][2]
00118          << " COL " << theL0Map[ (*matTable)[ii]->GetName() ][3]
00119          << " ELE " << theL0Map[ (*matTable)[ii]->GetName() ][4]
00120          << " OTH " << theL0Map[ (*matTable)[ii]->GetName() ][5]
00121          << " AIR " << theL0Map[ (*matTable)[ii]->GetName() ][6]
00122          << endl;
00123     if( theX0Map[ (*matTable)[ii]->GetName() ][5] == 1 || theL0Map[ (*matTable)[ii]->GetName() ][5] == 1 )
00124       std::cout << "WARNING: material with no category: " << (*matTable)[ii]->GetName() << std::endl;
00125   }
00126   //
00127   // rr
00128   
00129 }
00130 
00131 void MaterialBudgetCategorizer::buildCategoryMap(std::string theMaterialFileName, std::map<std::string,std::vector<float> >& theMap) {
00132   //  const G4MaterialTable* matTable = G4Material::GetMaterialTable();
00133   //  G4int matSize = matTable->size();
00134   
00135   std::ifstream theMaterialFile(theMaterialFileName.c_str());
00136   if (!theMaterialFile) 
00137     cms::Exception("LogicError") <<" File not found " << theMaterialFile;
00138   
00139   // fill everything as "other"
00140   float sup,sen,cab,col,ele,oth,air;
00141   sup=sen=cab=col=ele=0.;
00142   oth=1.;
00143   air=0;
00144   
00145   //
00146   std::string materialName;
00147   while(theMaterialFile) {
00148     theMaterialFile >> materialName;
00149     theMaterialFile >> sup >> sen >> cab >> col >> ele;
00150     oth = 0.000;
00151     air = 0.000;
00152     theMap[materialName].clear();        // clear before re-filling
00153     theMap[materialName].push_back(sup); // sup
00154     theMap[materialName].push_back(sen); // sen
00155     theMap[materialName].push_back(cab); // cab
00156     theMap[materialName].push_back(col); // col
00157     theMap[materialName].push_back(ele); // ele
00158     theMap[materialName].push_back(oth); // oth
00159     theMap[materialName].push_back(air); // air
00160     cout << " material " << materialName << " filled " 
00161          << " SUP " << sup 
00162          << " SEN " << sen 
00163          << " CAB " << cab 
00164          << " COL " << col 
00165          << " ELE " << ele 
00166          << " OTH " << oth 
00167          << " AIR " << air 
00168          << endl;
00169   }
00170   
00171 }