CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PrintMaterialBudgetInfo Class Reference

#include <PrintMaterialBudgetInfo.h>

Inheritance diagram for PrintMaterialBudgetInfo:
SimWatcher Observer< const BeginOfJob * > Observer< const BeginOfRun * >

Public Member Functions

 PrintMaterialBudgetInfo (edm::ParameterSet const &p)
 
 ~PrintMaterialBudgetInfo () override
 
- Public Member Functions inherited from SimWatcher
 SimWatcher ()
 
virtual ~SimWatcher ()
 
- Public Member Functions inherited from Observer< const BeginOfJob * >
 Observer ()
 
void slotForUpdate (const BeginOfJob * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const BeginOfRun * >
 Observer ()
 
void slotForUpdate (const BeginOfRun * iT)
 
virtual ~Observer ()
 

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) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const BeginOfRun *run) override
 This routine will be called when the appropriate signal arrives. More...
 

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
 

Additional Inherited Members

Detailed Description

Definition at line 24 of file PrintMaterialBudgetInfo.h.

Constructor & Destructor Documentation

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, AlCaHLTBitMon_QueryRunRegistry::string, texOutputFile, volumeFound, and weightOutputFile.

32  {
33  name = p.getUntrackedParameter<std::string>("Name", "*");
34  nchar = name.find("*");
35  name.assign(name, 0, nchar);
36  std::cout << "PrintMaterialBudget selected volume " << name << std::endl;
37  volumeFound = false;
38  std::string weightFileName = name + ".weight";
39  weightOutputFile.open(weightFileName.c_str());
40  std::string elementFileName = name + ".element";
41  elementOutputFile.open(elementFileName.c_str());
42  std::string texFileName = name + "_table.tex";
43  texOutputFile.open(texFileName.c_str());
44  std::cout << "PrintMaterialBudget output file " << weightFileName << std::endl;
45  std::cout << "PrintMaterialBudget output file " << elementFileName << std::endl;
46  std::cout << "PrintMaterialBudget output file " << texFileName << std::endl;
47  elementNames.clear();
48  elementTotalWeight.clear();
49  elementWeightFraction.clear();
50 }
std::vector< std::string > elementNames
std::vector< double > elementWeightFraction
std::vector< double > elementTotalWeight
PrintMaterialBudgetInfo::~PrintMaterialBudgetInfo ( )
override

Definition at line 52 of file PrintMaterialBudgetInfo.cc.

52 {}

Member Function Documentation

void PrintMaterialBudgetInfo::dumpElementMassFraction ( std::ostream &  elementOut = std::cout)
private

Definition at line 242 of file PrintMaterialBudgetInfo.cc.

References mps_setup::append, elementNames, elementTotalWeight, elementWeightFraction, createfilelist::int, and findQualityFiles::size.

Referenced by update().

242  {
243  // calculate mass fraction
244  double totalWeight = 0.0;
245  double totalFraction = 0.0;
246  for (unsigned int iElement = 0; iElement < (unsigned int)elementTotalWeight.size(); iElement++) {
247  totalWeight += elementTotalWeight[iElement];
248  }
249  // calculate element mass fractions
250  for (unsigned int iElement = 0; iElement < (unsigned int)elementTotalWeight.size(); iElement++) {
251  elementWeightFraction[iElement] = elementTotalWeight[iElement] / totalWeight;
252  totalFraction += elementWeightFraction[iElement];
253  }
254  // header
255  elementOut << "Element"
256  << "\t\t"
257  << "Index"
258  << "\t"
259  << "Total Mass"
260  << "\t"
261  << "Mass Fraction "
262  << "\t" << std::endl;
263  // dump
264  for (unsigned int iElement = 0; iElement < (unsigned int)elementTotalWeight.size(); iElement++) {
265  if (elementNames[iElement] != "rr") {
266  if (elementNames[iElement].size() < 8)
267  elementNames[iElement].append("\t");
268  elementOut << elementNames[iElement] << "\t" << iElement << "\t"
269  << G4BestUnit(elementTotalWeight[iElement], "Mass") << "\t" << elementWeightFraction[iElement]
270  << std::endl;
271  }
272  }
273  elementOut << "\n\t\tTotal Weight without Air " << G4BestUnit(totalWeight, "Mass") << "\tTotal Fraction "
274  << totalFraction << std::endl;
275 }
size
Write out results.
std::vector< std::string > elementNames
std::vector< double > elementWeightFraction
std::vector< double > elementTotalWeight
void PrintMaterialBudgetInfo::dumpHeader ( std::ostream &  out = std::cout)
private

Definition at line 79 of file PrintMaterialBudgetInfo.cc.

Referenced by update().

79  {
80  out << "Geom."
81  << "\t"
82  << "Volume"
83  << "\t"
84  << "\t"
85  << "Copy"
86  << "\t"
87  << "Solid"
88  << "\t"
89  << "\t"
90  << "Material"
91  << "\t"
92  << "Density"
93  << "\t"
94  << "\t"
95  << "Mass"
96  << "\t"
97  << "\t" << std::endl;
98  out << "Level"
99  << "\t"
100  << "Name"
101  << "\t"
102  << "\t"
103  << "Number"
104  << "\t"
105  << "Name"
106  << "\t"
107  << "\t"
108  << "Name"
109  << "\t"
110  << "\t"
111  << "[g/cm3]"
112  << "\t"
113  << "\t"
114  << "[g] "
115  << "\t"
116  << "\t" << std::endl;
117 }
void PrintMaterialBudgetInfo::dumpHierarchyLeaf ( G4VPhysicalVolume *  pv,
G4LogicalVolume *  lv,
unsigned int  leafDepth,
std::ostream &  weightOut = std::cout,
std::ostream &  texOut = std::cout 
)
private

Definition at line 164 of file PrintMaterialBudgetInfo.cc.

References levelFound, name, nchar, printInfo(), AlCaHLTBitMon_QueryRunRegistry::string, and volumeFound.

Referenced by update().

165  {
166  if (volumeFound && (leafDepth <= levelFound))
167  return;
168  if (volumeFound && (leafDepth > levelFound))
169  printInfo(pv, lv, leafDepth, weightOut, texOut);
170 
171  // choose mother volume
172  std::string lvname = lv->GetName();
173  lvname.assign(lvname, 0, nchar);
174  if (lvname == name) {
175  volumeFound = true;
176  levelFound = leafDepth;
177  printInfo(pv, lv, leafDepth, weightOut, texOut);
178  texOut << " \\hline" << std::endl;
179  }
180 
181  //----- Get LV daughters from list of PV daughters
182  mmlvpv lvpvDaughters;
183  std::set<G4LogicalVolume*> lvDaughters;
184  int NoDaughters = lv->GetNoDaughters();
185  while ((NoDaughters--) > 0) {
186  G4VPhysicalVolume* pvD = lv->GetDaughter(NoDaughters);
187  lvpvDaughters.insert(mmlvpv::value_type(pvD->GetLogicalVolume(), pvD));
188  lvDaughters.insert(pvD->GetLogicalVolume());
189  }
190 
191  std::set<G4LogicalVolume*>::const_iterator scite;
192  mmlvpv::const_iterator mmcite;
193 
194  //----- Dump daughters PV and LV
195  for (scite = lvDaughters.begin(); scite != lvDaughters.end(); scite++) {
196  std::pair<mmlvpv::iterator, mmlvpv::iterator> mmER = lvpvDaughters.equal_range(*scite);
197  //----- Dump daughters PV of this LV
198  for (mmcite = mmER.first; mmcite != mmER.second; mmcite++)
199  dumpHierarchyLeaf((*mmcite).second, *scite, leafDepth + 1, weightOut, texOut);
200  }
201 }
std::multimap< G4LogicalVolume *, G4VPhysicalVolume *, std::less< G4LogicalVolume * > > mmlvpv
void dumpHierarchyLeaf(G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=std::cout, std::ostream &texOut=std::cout)
void printInfo(G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=std::cout, std::ostream &texOut=std::cout)
def pv(vc)
Definition: MetAnalyzer.py:7
void PrintMaterialBudgetInfo::dumpLaTeXFooter ( std::ostream &  out = std::cout)
private

Definition at line 157 of file PrintMaterialBudgetInfo.cc.

Referenced by update().

157  {
158  out << " \\hline" << std::endl
159  << " \\end{tabular}" << std::endl
160  << " \\end{center}" << std::endl
161  << "\\end{table}" << std::endl;
162 }
void PrintMaterialBudgetInfo::dumpLaTeXHeader ( std::ostream &  out = std::cout)
private

Definition at line 119 of file PrintMaterialBudgetInfo.cc.

References name.

Referenced by update().

119  {
120  out << "\\begin{table}[h!]" << std::endl
121  << " \\caption{\\textsf {" << name << "} volume list.}" << std::endl
122  << " \\label{tab: " << name << "}" << std::endl
123  << " \\begin{center}" << std::endl
124  << " \\begin{tabular}{ccccccc}" << std::endl
125  << " \\hline" << std::endl;
126  out << " Geom."
127  << "\t & "
128  << " Volume"
129  << "\t & "
130  << " Copy"
131  << "\t & "
132  << " Solid"
133  << "\t & "
134  << " Material"
135  << "\t & "
136  << " Density"
137  << "\t & "
138  << " Mass"
139  << "\t \\\\ " << std::endl;
140  out << " Level"
141  << "\t & "
142  << " Name"
143  << "\t & "
144  << " Number"
145  << "\t & "
146  << " Name"
147  << "\t & "
148  << " Name"
149  << "\t & "
150  << " "
151  << "\t & "
152  << " "
153  << "\t \\\\ " << std::endl
154  << " \\hline\\hline" << std::endl;
155 }
void PrintMaterialBudgetInfo::printInfo ( G4VPhysicalVolume *  pv,
G4LogicalVolume *  lv,
unsigned int  leafDepth,
std::ostream &  weightOut = std::cout,
std::ostream &  texOut = std::cout 
)
private

Definition at line 203 of file PrintMaterialBudgetInfo.cc.

References elementNames, elementTotalWeight, createfilelist::int, AlCaHLTBitMon_QueryRunRegistry::string, stringLaTeXSuperscript(), and stringLaTeXUnderscore().

Referenced by dumpHierarchyLeaf(), and update().

204  {
205  double density = lv->GetMaterial()->GetDensity();
206  double weight = lv->GetMass(false, false);
207 
208  std::string volumeName = lv->GetName();
209  if (volumeName.size() < 8)
210  volumeName.append("\t");
211 
212  std::string solidName = lv->GetSolid()->GetName();
213  if (solidName.size() < 8)
214  solidName.append("\t");
215 
216  std::string materialName = lv->GetMaterial()->GetName();
217  if (materialName.size() < 8)
218  materialName.append("\t");
219 
220  //----- dump info
221  weightOut << leafDepth << "\t" << volumeName << "\t" << pv->GetCopyNo() << "\t" << solidName << "\t" << materialName
222  << "\t" << G4BestUnit(density, "Volumic Mass") << "\t" << G4BestUnit(weight, "Mass") << "\t" << std::endl;
223  //
224  texOut << "\t" << leafDepth << "\t & " << stringLaTeXUnderscore(volumeName) << "\t & " << pv->GetCopyNo() << "\t & "
225  << stringLaTeXUnderscore(solidName) << "\t & " << stringLaTeXUnderscore(materialName) << "\t & "
226  << stringLaTeXSuperscript(G4BestUnit(density, "Volumic Mass")) << "\t & "
227  << stringLaTeXSuperscript(G4BestUnit(weight, "Mass")) << "\t \\\\ " << std::endl;
228  //
229  for (unsigned int iElement = 0; iElement < (unsigned int)lv->GetMaterial()->GetNumberOfElements(); iElement++) {
230  // exclude Air in element weight fraction computation
231  if (materialName.find("Air")) {
232  std::string elementName = lv->GetMaterial()->GetElement(iElement)->GetName();
233  double elementMassFraction = lv->GetMaterial()->GetFractionVector()[iElement];
234  double elementWeight = weight * elementMassFraction;
235  unsigned int elementIndex = (unsigned int)lv->GetMaterial()->GetElement(iElement)->GetIndex();
236  elementNames[elementIndex] = elementName;
237  elementTotalWeight[elementIndex] += elementWeight;
238  }
239  }
240 }
std::vector< std::string > elementNames
Definition: weight.py:1
std::vector< double > elementTotalWeight
def pv(vc)
Definition: MetAnalyzer.py:7
std::string stringLaTeXSuperscript(std::string stringname)
std::string stringLaTeXUnderscore(std::string stringname)
std::string PrintMaterialBudgetInfo::stringLaTeXSuperscript ( std::string  stringname)
private

Definition at line 292 of file PrintMaterialBudgetInfo.cc.

References mps_fire::i, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by printInfo().

292  {
293  // To replace 'm3' with 'm$^3$' to compile LaTeX output
294  std::string stringoutput = stringname.substr(0, 1);
295 
296  for (unsigned int i = 1; i < stringname.length(); i++) {
297  if (stringname.substr(i - 1, 1) == "m" && stringname.substr(i, 1) == "3") {
298  stringoutput += "$^3$";
299  } else {
300  stringoutput += stringname.substr(i, 1);
301  }
302  }
303 
304  return stringoutput;
305 }
std::string PrintMaterialBudgetInfo::stringLaTeXUnderscore ( std::string  stringname)
private

Definition at line 277 of file PrintMaterialBudgetInfo.cc.

References mps_fire::i, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by printInfo().

277  {
278  // To replace '\' with '\_' to compile LaTeX output
279  std::string stringoutput;
280 
281  for (unsigned int i = 0; i < stringname.length(); i++) {
282  if (stringname.substr(i, 1) == "_") {
283  stringoutput += "\\_";
284  } else {
285  stringoutput += stringname.substr(i, 1);
286  }
287  }
288 
289  return stringoutput;
290 }
void PrintMaterialBudgetInfo::update ( const BeginOfJob )
inlineoverrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfJob * >.

Definition at line 32 of file PrintMaterialBudgetInfo.h.

References gather_cfg::cout, dumpElementMassFraction(), dumpHeader(), dumpHierarchyLeaf(), dumpLaTeXFooter(), dumpLaTeXHeader(), MillePedeFileConverter_cfg::out, printInfo(), MetAnalyzer::pv(), and writedatasetfile::run.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

32 {};
void PrintMaterialBudgetInfo::update ( const BeginOfRun )
overrideprivatevirtual

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.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

54  {
55  G4Random::setTheEngine(new CLHEP::RanecuEngine);
56  // Physical Volume
57  theTopPV = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
58  assert(theTopPV);
59  // Logical Volume
60  G4LogicalVolume* lv = theTopPV->GetLogicalVolume();
61  unsigned int leafDepth = 0;
62  // the first time fill the vectors of elements
63  if (elementNames.empty() && elementTotalWeight.empty() && elementWeightFraction.empty()) {
64  for (unsigned int iElement = 0; iElement < G4Element::GetNumberOfElements();
65  iElement++) { // first element in table is 0
66  elementNames.push_back("rr");
67  elementTotalWeight.push_back(0);
68  elementWeightFraction.push_back(0);
69  }
70  }
76  //
77 }
std::vector< std::string > elementNames
std::vector< double > elementWeightFraction
std::vector< double > elementTotalWeight
void dumpElementMassFraction(std::ostream &elementOut=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 dumpHeader(std::ostream &out=std::cout)
void dumpLaTeXHeader(std::ostream &out=std::cout)

Member Data Documentation

std::vector<std::string> PrintMaterialBudgetInfo::elementNames
private
std::ofstream PrintMaterialBudgetInfo::elementOutputFile
private

Definition at line 58 of file PrintMaterialBudgetInfo.h.

Referenced by PrintMaterialBudgetInfo(), and update().

std::vector<double> PrintMaterialBudgetInfo::elementTotalWeight
private
std::vector<double> PrintMaterialBudgetInfo::elementWeightFraction
private
G4NavigationHistory PrintMaterialBudgetInfo::fHistory
private

Definition at line 54 of file PrintMaterialBudgetInfo.h.

unsigned int PrintMaterialBudgetInfo::levelFound
private

Definition at line 56 of file PrintMaterialBudgetInfo.h.

Referenced by dumpHierarchyLeaf().

std::string PrintMaterialBudgetInfo::name
private
int PrintMaterialBudgetInfo::nchar
private

Definition at line 51 of file PrintMaterialBudgetInfo.h.

Referenced by dumpHierarchyLeaf(), and PrintMaterialBudgetInfo().

std::ofstream PrintMaterialBudgetInfo::texOutputFile
private

Definition at line 59 of file PrintMaterialBudgetInfo.h.

Referenced by PrintMaterialBudgetInfo(), and update().

mpvpv PrintMaterialBudgetInfo::thePVTree
private

Definition at line 52 of file PrintMaterialBudgetInfo.h.

G4VPhysicalVolume* PrintMaterialBudgetInfo::theTopPV
private

Definition at line 53 of file PrintMaterialBudgetInfo.h.

Referenced by update().

bool PrintMaterialBudgetInfo::volumeFound
private

Definition at line 55 of file PrintMaterialBudgetInfo.h.

Referenced by dumpHierarchyLeaf(), and PrintMaterialBudgetInfo().

std::ofstream PrintMaterialBudgetInfo::weightOutputFile
private

Definition at line 57 of file PrintMaterialBudgetInfo.h.

Referenced by PrintMaterialBudgetInfo(), and update().