CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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, 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
tuple cout
Definition: gather_cfg.py:41
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 222 of file PrintMaterialBudgetInfo.cc.

References python.multivaluedict::append(), elementNames, elementTotalWeight, elementWeightFraction, and findQualityFiles::size.

Referenced by update().

222  {
223  // calculate mass fraction
224  double totalWeight = 0.0;
225  double totalFraction = 0.0;
226  for(unsigned int iElement = 0; iElement<(unsigned int)elementTotalWeight.size(); iElement++) {
227  totalWeight+=elementTotalWeight[iElement];
228  }
229  // calculate element mass fractions
230  for(unsigned int iElement = 0; iElement<(unsigned int)elementTotalWeight.size(); iElement++) {
231  elementWeightFraction[iElement] = elementTotalWeight[iElement]/totalWeight;
232  totalFraction+=elementWeightFraction[iElement];
233  }
234  // header
235  elementOut << "Element" << "\t\t"
236  << "Index" << "\t"
237  << "Total Mass" << "\t"
238  << "Mass Fraction " << "\t"
239  << std::endl;
240  // dump
241  for(unsigned int iElement = 0; iElement<(unsigned int)elementTotalWeight.size(); iElement++) {
242  if(elementNames[iElement]!="rr") {
243  if(elementNames[iElement].size()<8) elementNames[iElement].append("\t");
244  elementOut << elementNames[iElement] << "\t"
245  << iElement << "\t"
246  << G4BestUnit(elementTotalWeight[iElement],"Mass") << "\t"
247  << elementWeightFraction[iElement]
248  << std::endl;
249  }
250  }
251  elementOut << "\n\t\tTotal Weight without Air " << G4BestUnit(totalWeight,"Mass")
252  << "\tTotal Fraction " << totalFraction
253  << std::endl;
254 }
std::vector< std::string > elementNames
std::vector< double > elementWeightFraction
std::vector< double > elementTotalWeight
tuple size
Write out results.
void PrintMaterialBudgetInfo::dumpHeader ( std::ostream &  out = std::cout)
private

Definition at line 79 of file PrintMaterialBudgetInfo.cc.

Referenced by update().

79  {
80  out << "Geom." << "\t"
81  << "Volume" << "\t" << "\t"
82  << "Copy" << "\t"
83  << "Solid" << "\t" << "\t"
84  << "Material" << "\t"
85  << "Density" << "\t" << "\t"
86  << "Mass" << "\t" << "\t"
87  << std::endl;
88  out << "Level" << "\t"
89  << "Name" << "\t" << "\t"
90  << "Number" << "\t"
91  << "Name" << "\t" << "\t"
92  << "Name" << "\t" << "\t"
93  << "[g/cm3]" << "\t" << "\t"
94  << "[g] " << "\t" << "\t"
95  << std::endl;
96 }
tuple out
Definition: dbtoconf.py:99
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().

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

Definition at line 125 of file PrintMaterialBudgetInfo.cc.

Referenced by update().

125  {
126  out << " \\hline" << std::endl
127  << " \\end{tabular}" << std::endl
128  << " \\end{center}" << std::endl
129  << "\\end{table}" << std::endl;
130 }
tuple out
Definition: dbtoconf.py:99
void PrintMaterialBudgetInfo::dumpLaTeXHeader ( std::ostream &  out = std::cout)
private

Definition at line 98 of file PrintMaterialBudgetInfo.cc.

References name.

Referenced by update().

98  {
99  out << "\\begin{table}[h!]" << std::endl
100  << " \\caption{\\textsf {" << name << "} volume list.}" << std::endl
101  << " \\label{tab: " << name << "}" << std::endl
102  << " \\begin{center}" << std::endl
103  << " \\begin{tabular}{ccccccc}" << std::endl
104  << " \\hline" << std::endl;
105  out << " Geom." << "\t & "
106  << " Volume" << "\t & "
107  << " Copy" << "\t & "
108  << " Solid" << "\t & "
109  << " Material" << "\t & "
110  << " Density" << "\t & "
111  << " Mass" << "\t \\\\ "
112  << std::endl;
113  out << " Level" << "\t & "
114  << " Name" << "\t & "
115  << " Number" << "\t & "
116  << " Name" << "\t & "
117  << " Name" << "\t & "
118  << " " << "\t & "
119  << " " << "\t \\\\ "
120  << std::endl
121  << " \\hline\\hline"
122  << std::endl;
123 }
tuple out
Definition: dbtoconf.py:99
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().

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

Definition at line 272 of file PrintMaterialBudgetInfo.cc.

References i.

Referenced by printInfo().

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

Definition at line 256 of file PrintMaterialBudgetInfo.cc.

References i.

Referenced by printInfo().

256  {
257  // To replace '\' with '\_' to compile LaTeX output
258  std::string stringoutput;
259 
260  for (unsigned int i=0; i<stringname.length() ; i++) {
261  if (stringname.substr(i,1) == "_") {
262  stringoutput += "\\_";
263  } else {
264  stringoutput += stringname.substr(i,1);
265  }
266  }
267 
268  return stringoutput;
269 
270 }
int i
Definition: DBlmapReader.cc:9
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.

Referenced by python.Vispa.Gui.VispaWidget.VispaWidget::autosize(), python.Vispa.Views.LineDecayView.LineDecayContainer::createObject(), python.Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), python.Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), python.Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), python.Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), python.Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), python.Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), python.Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), python.Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), python.Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), python.Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), python.Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), python.Vispa.Gui.FindDialog.FindDialog::reset(), python.Vispa.Gui.PortConnection.PointToPointConnection::select(), python.Vispa.Gui.VispaWidget.VispaWidget::select(), python.Vispa.Views.LineDecayView.LineDecayContainer::select(), python.Vispa.Gui.VispaWidget.VispaWidget::setText(), python.Vispa.Gui.VispaWidget.VispaWidget::setTitle(), python.Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), python.Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and python.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 python.Vispa.Gui.VispaWidget.VispaWidget::autosize(), python.Vispa.Views.LineDecayView.LineDecayContainer::createObject(), python.Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), python.Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), python.Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), python.Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), python.Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), python.Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), python.Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), python.Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), python.Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), python.Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), python.Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), python.Vispa.Gui.FindDialog.FindDialog::reset(), python.Vispa.Gui.PortConnection.PointToPointConnection::select(), python.Vispa.Gui.VispaWidget.VispaWidget::select(), python.Vispa.Views.LineDecayView.LineDecayContainer::select(), python.Vispa.Gui.VispaWidget.VispaWidget::setText(), python.Vispa.Gui.VispaWidget.VispaWidget::setTitle(), python.Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), python.Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and python.Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

54  {
55 
56  // Physical Volume
57  theTopPV = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
58  // Logical Volume
59  G4LogicalVolume* lv = theTopPV->GetLogicalVolume();
60  unsigned int leafDepth = 0;
61  // the first time fill the vectors of elements
62  if( elementNames.size()==0 && elementTotalWeight.size()==0 && elementWeightFraction.size()==0) {
63  for(unsigned int iElement = 0;
64  iElement < lv->GetMaterial()->GetElement(iElement)->GetElementTable()->size();
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 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().