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

Definition at line 52 of file PrintMaterialBudgetInfo.cc.

52 {}

Member Function Documentation

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

Definition at line 224 of file PrintMaterialBudgetInfo.cc.

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

Referenced by update().

224  {
225  // calculate mass fraction
226  double totalWeight = 0.0;
227  double totalFraction = 0.0;
228  for(unsigned int iElement = 0; iElement<(unsigned int)elementTotalWeight.size(); iElement++) {
229  totalWeight+=elementTotalWeight[iElement];
230  }
231  // calculate element mass fractions
232  for(unsigned int iElement = 0; iElement<(unsigned int)elementTotalWeight.size(); iElement++) {
233  elementWeightFraction[iElement] = elementTotalWeight[iElement]/totalWeight;
234  totalFraction+=elementWeightFraction[iElement];
235  }
236  // header
237  elementOut << "Element" << "\t\t"
238  << "Index" << "\t"
239  << "Total Mass" << "\t"
240  << "Mass Fraction " << "\t"
241  << std::endl;
242  // dump
243  for(unsigned int iElement = 0; iElement<(unsigned int)elementTotalWeight.size(); iElement++) {
244  if(elementNames[iElement]!="rr") {
245  if(elementNames[iElement].size()<8) elementNames[iElement].append("\t");
246  elementOut << elementNames[iElement] << "\t"
247  << iElement << "\t"
248  << G4BestUnit(elementTotalWeight[iElement],"Mass") << "\t"
249  << elementWeightFraction[iElement]
250  << std::endl;
251  }
252  }
253  elementOut << "\n\t\tTotal Weight without Air " << G4BestUnit(totalWeight,"Mass")
254  << "\tTotal Fraction " << totalFraction
255  << std::endl;
256 }
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 81 of file PrintMaterialBudgetInfo.cc.

Referenced by update().

81  {
82  out << "Geom." << "\t"
83  << "Volume" << "\t" << "\t"
84  << "Copy" << "\t"
85  << "Solid" << "\t" << "\t"
86  << "Material" << "\t"
87  << "Density" << "\t" << "\t"
88  << "Mass" << "\t" << "\t"
89  << std::endl;
90  out << "Level" << "\t"
91  << "Name" << "\t" << "\t"
92  << "Number" << "\t"
93  << "Name" << "\t" << "\t"
94  << "Name" << "\t" << "\t"
95  << "[g/cm3]" << "\t" << "\t"
96  << "[g] " << "\t" << "\t"
97  << std::endl;
98 }
void PrintMaterialBudgetInfo::dumpHierarchyLeaf ( G4VPhysicalVolume *  pv,
G4LogicalVolume *  lv,
unsigned int  leafDepth,
std::ostream &  weightOut = std::cout,
std::ostream &  texOut = std::cout 
)
private

Definition at line 134 of file PrintMaterialBudgetInfo.cc.

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

Referenced by update().

137  {
138 
139  if( volumeFound && ( leafDepth <= levelFound ) ) return;
140  if( volumeFound && ( leafDepth > levelFound ) ) printInfo(pv, lv, leafDepth, weightOut, texOut);
141 
142  // choose mother volume
143  std::string lvname = lv->GetName();
144  lvname.assign(lvname,0,nchar);
145  if (lvname == name) {
146  volumeFound = true;
147  levelFound = leafDepth;
148  printInfo(pv, lv, leafDepth, weightOut, texOut);
149  texOut << " \\hline" << std::endl;
150  }
151 
152  //----- Get LV daughters from list of PV daughters
153  mmlvpv lvpvDaughters;
154  std::set< G4LogicalVolume* > lvDaughters;
155  int NoDaughters = lv->GetNoDaughters();
156  while ((NoDaughters--)>0)
157  {
158  G4VPhysicalVolume* pvD = lv->GetDaughter(NoDaughters);
159  lvpvDaughters.insert(mmlvpv::value_type(pvD->GetLogicalVolume(), pvD));
160  lvDaughters.insert(pvD->GetLogicalVolume());
161  }
162 
163  std::set< G4LogicalVolume* >::const_iterator scite;
164  mmlvpv::const_iterator mmcite;
165 
166  //----- Dump daughters PV and LV
167  for (scite = lvDaughters.begin(); scite != lvDaughters.end(); scite++) {
168  std::pair< mmlvpv::iterator, mmlvpv::iterator > mmER = lvpvDaughters.equal_range(*scite);
169  //----- Dump daughters PV of this LV
170  for (mmcite = mmER.first ; mmcite != mmER.second; mmcite++)
171  dumpHierarchyLeaf((*mmcite).second, *scite, leafDepth+1, weightOut, texOut );
172  }
173 
174 }
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:6
void PrintMaterialBudgetInfo::dumpLaTeXFooter ( std::ostream &  out = std::cout)
private

Definition at line 127 of file PrintMaterialBudgetInfo.cc.

Referenced by update().

127  {
128  out << " \\hline" << std::endl
129  << " \\end{tabular}" << std::endl
130  << " \\end{center}" << std::endl
131  << "\\end{table}" << std::endl;
132 }
void PrintMaterialBudgetInfo::dumpLaTeXHeader ( std::ostream &  out = std::cout)
private

Definition at line 100 of file PrintMaterialBudgetInfo.cc.

References name.

Referenced by update().

100  {
101  out << "\\begin{table}[h!]" << std::endl
102  << " \\caption{\\textsf {" << name << "} volume list.}" << std::endl
103  << " \\label{tab: " << name << "}" << std::endl
104  << " \\begin{center}" << std::endl
105  << " \\begin{tabular}{ccccccc}" << std::endl
106  << " \\hline" << std::endl;
107  out << " Geom." << "\t & "
108  << " Volume" << "\t & "
109  << " Copy" << "\t & "
110  << " Solid" << "\t & "
111  << " Material" << "\t & "
112  << " Density" << "\t & "
113  << " Mass" << "\t \\\\ "
114  << std::endl;
115  out << " Level" << "\t & "
116  << " Name" << "\t & "
117  << " Number" << "\t & "
118  << " Name" << "\t & "
119  << " Name" << "\t & "
120  << " " << "\t & "
121  << " " << "\t \\\\ "
122  << std::endl
123  << " \\hline\\hline"
124  << std::endl;
125 }
void PrintMaterialBudgetInfo::printInfo ( G4VPhysicalVolume *  pv,
G4LogicalVolume *  lv,
unsigned int  leafDepth,
std::ostream &  weightOut = std::cout,
std::ostream &  texOut = std::cout 
)
private

Definition at line 176 of file PrintMaterialBudgetInfo.cc.

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

Referenced by dumpHierarchyLeaf(), and update().

177  {
178 
179  double density = lv->GetMaterial()->GetDensity();
180  double weight = lv->GetMass(false,false);
181 
182  std::string volumeName = lv->GetName();
183  if(volumeName.size()<8) volumeName.append("\t");
184 
185  std::string solidName = lv->GetSolid()->GetName();
186  if(solidName.size()<8) solidName.append("\t");
187 
188  std::string materialName = lv->GetMaterial()->GetName();
189  if(materialName.size()<8) materialName.append("\t");
190 
191  //----- dump info
192  weightOut << leafDepth << "\t"
193  << volumeName << "\t"
194  << pv->GetCopyNo() << "\t"
195  << solidName << "\t"
196  << materialName << "\t"
197  << G4BestUnit(density,"Volumic Mass") << "\t"
198  << G4BestUnit(weight,"Mass") << "\t"
199  << std::endl;
200  //
201  texOut << "\t"
202  << leafDepth << "\t & "
203  << stringLaTeXUnderscore(volumeName) << "\t & "
204  << pv->GetCopyNo() << "\t & "
205  << stringLaTeXUnderscore(solidName) << "\t & "
206  << stringLaTeXUnderscore(materialName) << "\t & "
207  << stringLaTeXSuperscript(G4BestUnit(density,"Volumic Mass")) << "\t & "
208  << stringLaTeXSuperscript(G4BestUnit(weight,"Mass")) << "\t \\\\ "
209  << std::endl;
210  //
211  for(unsigned int iElement = 0; iElement<(unsigned int)lv->GetMaterial()->GetNumberOfElements(); iElement++) {
212  // exclude Air in element weight fraction computation
213  if(materialName.find("Air")) {
214  std::string elementName = lv->GetMaterial()->GetElement(iElement)->GetName();
215  double elementMassFraction = lv->GetMaterial()->GetFractionVector()[iElement];
216  double elementWeight = weight*elementMassFraction;
217  unsigned int elementIndex = (unsigned int)lv->GetMaterial()->GetElement(iElement)->GetIndex();
218  elementNames[elementIndex] = elementName;
219  elementTotalWeight[elementIndex] += elementWeight;
220  }
221  }
222 }
std::vector< std::string > elementNames
Definition: weight.py:1
std::vector< double > elementTotalWeight
def pv(vc)
Definition: MetAnalyzer.py:6
std::string stringLaTeXSuperscript(std::string stringname)
std::string stringLaTeXUnderscore(std::string stringname)
std::string PrintMaterialBudgetInfo::stringLaTeXSuperscript ( std::string  stringname)
private

Definition at line 274 of file PrintMaterialBudgetInfo.cc.

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

Referenced by printInfo().

274  {
275  // To replace 'm3' with 'm$^3$' to compile LaTeX output
276  std::string stringoutput = stringname.substr(0,1);
277 
278  for (unsigned int i=1; i<stringname.length() ; i++) {
279  if (stringname.substr(i-1,1) == "m" && stringname.substr(i,1) == "3") {
280  stringoutput += "$^3$";
281  } else {
282  stringoutput += stringname.substr(i,1);
283  }
284  }
285 
286  return stringoutput;
287 
288 }
std::string PrintMaterialBudgetInfo::stringLaTeXUnderscore ( std::string  stringname)
private

Definition at line 258 of file PrintMaterialBudgetInfo.cc.

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

Referenced by printInfo().

258  {
259  // To replace '\' with '\_' to compile LaTeX output
260  std::string stringoutput;
261 
262  for (unsigned int i=0; i<stringname.length() ; i++) {
263  if (stringname.substr(i,1) == "_") {
264  stringoutput += "\\_";
265  } else {
266  stringoutput += stringname.substr(i,1);
267  }
268  }
269 
270  return stringoutput;
271 
272 }
void PrintMaterialBudgetInfo::update ( const BeginOfJob )
inlineprivatevirtual

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 findQualityFiles::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 )
privatevirtual

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 
56  G4Random::setTheEngine(new CLHEP::RanecuEngine);
57  // Physical Volume
58  theTopPV = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
59  assert(theTopPV);
60  // Logical Volume
61  G4LogicalVolume* lv = theTopPV->GetLogicalVolume();
62  unsigned int leafDepth = 0;
63  // the first time fill the vectors of elements
64  if( elementNames.size()==0 && elementTotalWeight.size()==0 && elementWeightFraction.size()==0) {
65  for(unsigned int iElement = 0;
66  iElement < G4Element::GetNumberOfElements();
67  iElement++) { // first element in table is 0
68  elementNames.push_back("rr");
69  elementTotalWeight.push_back(0);
70  elementWeightFraction.push_back(0);
71  }
72  }
78  //
79 }
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 52 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 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
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().