#include <PrintMaterialBudgetInfo.h>
Public Member Functions | |
PrintMaterialBudgetInfo (edm::ParameterSet const &p) | |
~PrintMaterialBudgetInfo () | |
Private Member Functions | |
void | dumpElementMassFraction (std::ostream &elementOut=std::cout) |
void | dumpHeader (std::ostream &out=std::cout) |
void | dumpHierarchyLeaf (G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=std::cout, std::ostream &texOut=std::cout) |
void | dumpLaTeXFooter (std::ostream &out=std::cout) |
void | dumpLaTeXHeader (std::ostream &out=std::cout) |
void | printInfo (G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=std::cout, std::ostream &texOut=std::cout) |
std::string | stringLaTeXSuperscript (std::string stringname) |
std::string | stringLaTeXUnderscore (std::string stringname) |
void | update (const BeginOfJob *job) |
This routine will be called when the appropriate signal arrives. | |
void | update (const BeginOfRun *run) |
This routine will be called when the appropriate signal arrives. | |
Private Attributes | |
std::vector< std::string > | elementNames |
std::ofstream | elementOutputFile |
std::vector< double > | elementTotalWeight |
std::vector< double > | elementWeightFraction |
G4NavigationHistory | fHistory |
unsigned int | levelFound |
std::string | name |
int | nchar |
std::ofstream | texOutputFile |
mpvpv | thePVTree |
G4VPhysicalVolume * | theTopPV |
bool | volumeFound |
std::ofstream | weightOutputFile |
Definition at line 24 of file PrintMaterialBudgetInfo.h.
PrintMaterialBudgetInfo::PrintMaterialBudgetInfo | ( | edm::ParameterSet const & | p | ) |
Definition at line 32 of file PrintMaterialBudgetInfo.cc.
References gather_cfg::cout, elementNames, elementOutputFile, elementTotalWeight, elementWeightFraction, edm::ParameterSet::getUntrackedParameter(), name, nchar, texOutputFile, volumeFound, and weightOutputFile.
{ name = p.getUntrackedParameter<std::string>("Name","*"); nchar = name.find("*"); name.assign(name,0,nchar); std::cout << "PrintMaterialBudget selected volume " << name << std::endl; volumeFound = false; std::string weightFileName = name+".weight"; weightOutputFile.open( weightFileName.c_str() ); std::string elementFileName = name+".element"; elementOutputFile.open( elementFileName.c_str() ); std::string texFileName = name+"_table.tex"; texOutputFile.open( texFileName.c_str() ); std::cout << "PrintMaterialBudget output file " << weightFileName << std::endl; std::cout << "PrintMaterialBudget output file " << elementFileName << std::endl; std::cout << "PrintMaterialBudget output file " << texFileName << std::endl; elementNames.clear(); elementTotalWeight.clear(); elementWeightFraction.clear(); }
PrintMaterialBudgetInfo::~PrintMaterialBudgetInfo | ( | ) |
Definition at line 52 of file PrintMaterialBudgetInfo.cc.
{}
void PrintMaterialBudgetInfo::dumpElementMassFraction | ( | std::ostream & | elementOut = std::cout | ) | [private] |
Definition at line 222 of file PrintMaterialBudgetInfo.cc.
References python::multivaluedict::append(), elementNames, elementTotalWeight, elementWeightFraction, and findQualityFiles::size.
Referenced by update().
{ // calculate mass fraction double totalWeight = 0.0; double totalFraction = 0.0; for(unsigned int iElement = 0; iElement<(unsigned int)elementTotalWeight.size(); iElement++) { totalWeight+=elementTotalWeight[iElement]; } // calculate element mass fractions for(unsigned int iElement = 0; iElement<(unsigned int)elementTotalWeight.size(); iElement++) { elementWeightFraction[iElement] = elementTotalWeight[iElement]/totalWeight; totalFraction+=elementWeightFraction[iElement]; } // header elementOut << "Element" << "\t\t" << "Index" << "\t" << "Total Mass" << "\t" << "Mass Fraction " << "\t" << std::endl; // dump for(unsigned int iElement = 0; iElement<(unsigned int)elementTotalWeight.size(); iElement++) { if(elementNames[iElement]!="rr") { if(elementNames[iElement].size()<8) elementNames[iElement].append("\t"); elementOut << elementNames[iElement] << "\t" << iElement << "\t" << G4BestUnit(elementTotalWeight[iElement],"Mass") << "\t" << elementWeightFraction[iElement] << std::endl; } } elementOut << "\n\t\tTotal Weight without Air " << G4BestUnit(totalWeight,"Mass") << "\tTotal Fraction " << totalFraction << std::endl; }
void PrintMaterialBudgetInfo::dumpHeader | ( | std::ostream & | out = std::cout | ) | [private] |
Definition at line 79 of file PrintMaterialBudgetInfo.cc.
Referenced by update().
{ out << "Geom." << "\t" << "Volume" << "\t" << "\t" << "Copy" << "\t" << "Solid" << "\t" << "\t" << "Material" << "\t" << "Density" << "\t" << "\t" << "Mass" << "\t" << "\t" << std::endl; out << "Level" << "\t" << "Name" << "\t" << "\t" << "Number" << "\t" << "Name" << "\t" << "\t" << "Name" << "\t" << "\t" << "[g/cm3]" << "\t" << "\t" << "[g] " << "\t" << "\t" << std::endl; }
void PrintMaterialBudgetInfo::dumpHierarchyLeaf | ( | G4VPhysicalVolume * | pv, |
G4LogicalVolume * | lv, | ||
unsigned int | leafDepth, | ||
std::ostream & | weightOut = std::cout , |
||
std::ostream & | texOut = std::cout |
||
) | [private] |
Definition at line 132 of file PrintMaterialBudgetInfo.cc.
References levelFound, name, nchar, printInfo(), and volumeFound.
Referenced by update().
{ if( volumeFound && ( leafDepth <= levelFound ) ) return; if( volumeFound && ( leafDepth > levelFound ) ) printInfo(pv, lv, leafDepth, weightOut, texOut); // choose mother volume std::string lvname = lv->GetName(); lvname.assign(lvname,0,nchar); if (lvname == name) { volumeFound = true; levelFound = leafDepth; printInfo(pv, lv, leafDepth, weightOut, texOut); texOut << " \\hline" << std::endl; } //----- Get LV daughters from list of PV daughters mmlvpv lvpvDaughters; std::set< G4LogicalVolume* > lvDaughters; int NoDaughters = lv->GetNoDaughters(); while ((NoDaughters--)>0) { G4VPhysicalVolume* pvD = lv->GetDaughter(NoDaughters); lvpvDaughters.insert(mmlvpv::value_type(pvD->GetLogicalVolume(), pvD)); lvDaughters.insert(pvD->GetLogicalVolume()); } std::set< G4LogicalVolume* >::const_iterator scite; mmlvpv::const_iterator mmcite; //----- Dump daughters PV and LV for (scite = lvDaughters.begin(); scite != lvDaughters.end(); scite++) { std::pair< mmlvpv::iterator, mmlvpv::iterator > mmER = lvpvDaughters.equal_range(*scite); //----- Dump daughters PV of this LV for (mmcite = mmER.first ; mmcite != mmER.second; mmcite++) dumpHierarchyLeaf((*mmcite).second, *scite, leafDepth+1, weightOut, texOut ); } }
void PrintMaterialBudgetInfo::dumpLaTeXFooter | ( | std::ostream & | out = std::cout | ) | [private] |
Definition at line 125 of file PrintMaterialBudgetInfo.cc.
Referenced by update().
{ out << " \\hline" << std::endl << " \\end{tabular}" << std::endl << " \\end{center}" << std::endl << "\\end{table}" << std::endl; }
void PrintMaterialBudgetInfo::dumpLaTeXHeader | ( | std::ostream & | out = std::cout | ) | [private] |
Definition at line 98 of file PrintMaterialBudgetInfo.cc.
References name.
Referenced by update().
{ out << "\\begin{table}[h!]" << std::endl << " \\caption{\\textsf {" << name << "} volume list.}" << std::endl << " \\label{tab: " << name << "}" << std::endl << " \\begin{center}" << std::endl << " \\begin{tabular}{ccccccc}" << std::endl << " \\hline" << std::endl; out << " Geom." << "\t & " << " Volume" << "\t & " << " Copy" << "\t & " << " Solid" << "\t & " << " Material" << "\t & " << " Density" << "\t & " << " Mass" << "\t \\\\ " << std::endl; out << " Level" << "\t & " << " Name" << "\t & " << " Number" << "\t & " << " Name" << "\t & " << " Name" << "\t & " << " " << "\t & " << " " << "\t \\\\ " << std::endl << " \\hline\\hline" << std::endl; }
void PrintMaterialBudgetInfo::printInfo | ( | G4VPhysicalVolume * | pv, |
G4LogicalVolume * | lv, | ||
unsigned int | leafDepth, | ||
std::ostream & | weightOut = std::cout , |
||
std::ostream & | texOut = std::cout |
||
) | [private] |
Definition at line 174 of file PrintMaterialBudgetInfo.cc.
References elementNames, elementTotalWeight, stringLaTeXSuperscript(), stringLaTeXUnderscore(), and CommonMethods::weight().
Referenced by dumpHierarchyLeaf().
{ double density = lv->GetMaterial()->GetDensity(); double weight = lv->GetMass(false,false); std::string volumeName = lv->GetName(); if(volumeName.size()<8) volumeName.append("\t"); std::string solidName = lv->GetSolid()->GetName(); if(solidName.size()<8) solidName.append("\t"); std::string materialName = lv->GetMaterial()->GetName(); if(materialName.size()<8) materialName.append("\t"); //----- dump info weightOut << leafDepth << "\t" << volumeName << "\t" << pv->GetCopyNo() << "\t" << solidName << "\t" << materialName << "\t" << G4BestUnit(density,"Volumic Mass") << "\t" << G4BestUnit(weight,"Mass") << "\t" << std::endl; // texOut << "\t" << leafDepth << "\t & " << stringLaTeXUnderscore(volumeName) << "\t & " << pv->GetCopyNo() << "\t & " << stringLaTeXUnderscore(solidName) << "\t & " << stringLaTeXUnderscore(materialName) << "\t & " << stringLaTeXSuperscript(G4BestUnit(density,"Volumic Mass")) << "\t & " << stringLaTeXSuperscript(G4BestUnit(weight,"Mass")) << "\t \\\\ " << std::endl; // for(unsigned int iElement = 0; iElement<(unsigned int)lv->GetMaterial()->GetNumberOfElements(); iElement++) { // exclude Air in element weight fraction computation if(materialName.find("Air")) { std::string elementName = lv->GetMaterial()->GetElement(iElement)->GetName(); double elementMassFraction = lv->GetMaterial()->GetFractionVector()[iElement]; double elementWeight = weight*elementMassFraction; unsigned int elementIndex = (unsigned int)lv->GetMaterial()->GetElement(iElement)->GetIndex(); elementNames[elementIndex] = elementName; elementTotalWeight[elementIndex] += elementWeight; } } }
std::string PrintMaterialBudgetInfo::stringLaTeXSuperscript | ( | std::string | stringname | ) | [private] |
Definition at line 272 of file PrintMaterialBudgetInfo.cc.
References i.
Referenced by printInfo().
{ // To replace 'm3' with 'm$^3$' to compile LaTeX output std::string stringoutput = stringname.substr(0,1); for (unsigned int i=1; i<stringname.length() ; i++) { if (stringname.substr(i-1,1) == "m" && stringname.substr(i,1) == "3") { stringoutput += "$^3$"; } else { stringoutput += stringname.substr(i,1); } } return stringoutput; }
std::string PrintMaterialBudgetInfo::stringLaTeXUnderscore | ( | std::string | stringname | ) | [private] |
void PrintMaterialBudgetInfo::update | ( | const BeginOfJob * | ) | [inline, private, virtual] |
This routine will be called when the appropriate signal arrives.
Implements Observer< const BeginOfJob * >.
Definition at line 32 of file PrintMaterialBudgetInfo.h.
{};
void PrintMaterialBudgetInfo::update | ( | const BeginOfRun * | ) | [private, virtual] |
This routine will be called when the appropriate signal arrives.
Implements Observer< const BeginOfRun * >.
Definition at line 54 of file PrintMaterialBudgetInfo.cc.
References dumpElementMassFraction(), dumpHeader(), dumpHierarchyLeaf(), dumpLaTeXFooter(), dumpLaTeXHeader(), elementNames, elementOutputFile, elementTotalWeight, elementWeightFraction, texOutputFile, theTopPV, and weightOutputFile.
{ // Physical Volume theTopPV = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume(); // Logical Volume G4LogicalVolume* lv = theTopPV->GetLogicalVolume(); unsigned int leafDepth = 0; // the first time fill the vectors of elements if( elementNames.size()==0 && elementTotalWeight.size()==0 && elementWeightFraction.size()==0) { for(unsigned int iElement = 0; iElement < lv->GetMaterial()->GetElement(iElement)->GetElementTable()->size(); iElement++) { // first element in table is 0 elementNames.push_back("rr"); elementTotalWeight.push_back(0); elementWeightFraction.push_back(0); } } dumpHeader(weightOutputFile); dumpLaTeXHeader(texOutputFile); dumpHierarchyLeaf(theTopPV, lv, leafDepth, weightOutputFile, texOutputFile); dumpElementMassFraction(elementOutputFile); dumpLaTeXFooter(texOutputFile); // }
std::vector<std::string> PrintMaterialBudgetInfo::elementNames [private] |
Definition at line 54 of file PrintMaterialBudgetInfo.h.
Referenced by dumpElementMassFraction(), printInfo(), PrintMaterialBudgetInfo(), and update().
std::ofstream PrintMaterialBudgetInfo::elementOutputFile [private] |
Definition at line 52 of file PrintMaterialBudgetInfo.h.
Referenced by PrintMaterialBudgetInfo(), and update().
std::vector<double> PrintMaterialBudgetInfo::elementTotalWeight [private] |
Definition at line 55 of file PrintMaterialBudgetInfo.h.
Referenced by dumpElementMassFraction(), printInfo(), PrintMaterialBudgetInfo(), and update().
std::vector<double> PrintMaterialBudgetInfo::elementWeightFraction [private] |
Definition at line 56 of file PrintMaterialBudgetInfo.h.
Referenced by dumpElementMassFraction(), PrintMaterialBudgetInfo(), and update().
G4NavigationHistory PrintMaterialBudgetInfo::fHistory [private] |
Definition at line 48 of file PrintMaterialBudgetInfo.h.
unsigned int PrintMaterialBudgetInfo::levelFound [private] |
Definition at line 50 of file PrintMaterialBudgetInfo.h.
Referenced by dumpHierarchyLeaf().
std::string PrintMaterialBudgetInfo::name [private] |
Definition at line 44 of file PrintMaterialBudgetInfo.h.
Referenced by dumpHierarchyLeaf(), dumpLaTeXHeader(), and PrintMaterialBudgetInfo().
int PrintMaterialBudgetInfo::nchar [private] |
Definition at line 45 of file PrintMaterialBudgetInfo.h.
Referenced by dumpHierarchyLeaf(), and PrintMaterialBudgetInfo().
std::ofstream PrintMaterialBudgetInfo::texOutputFile [private] |
Definition at line 53 of file PrintMaterialBudgetInfo.h.
Referenced by PrintMaterialBudgetInfo(), and update().
mpvpv PrintMaterialBudgetInfo::thePVTree [private] |
Definition at line 46 of file PrintMaterialBudgetInfo.h.
G4VPhysicalVolume* PrintMaterialBudgetInfo::theTopPV [private] |
Definition at line 47 of file PrintMaterialBudgetInfo.h.
Referenced by update().
bool PrintMaterialBudgetInfo::volumeFound [private] |
Definition at line 49 of file PrintMaterialBudgetInfo.h.
Referenced by dumpHierarchyLeaf(), and PrintMaterialBudgetInfo().
std::ofstream PrintMaterialBudgetInfo::weightOutputFile [private] |
Definition at line 51 of file PrintMaterialBudgetInfo.h.
Referenced by PrintMaterialBudgetInfo(), and update().