test
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 33 of file PrintMaterialBudgetInfo.cc.

References gather_cfg::cout, elementNames, elementOutputFile, elementTotalWeight, elementWeightFraction, edm::ParameterSet::getUntrackedParameter(), name, nchar, AlCaHLTBitMon_QueryRunRegistry::string, texOutputFile, volumeFound, and weightOutputFile.

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

Definition at line 53 of file PrintMaterialBudgetInfo.cc.

53 {}

Member Function Documentation

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

Definition at line 225 of file PrintMaterialBudgetInfo.cc.

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

Referenced by update().

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

Referenced by update().

82  {
83  out << "Geom." << "\t"
84  << "Volume" << "\t" << "\t"
85  << "Copy" << "\t"
86  << "Solid" << "\t" << "\t"
87  << "Material" << "\t"
88  << "Density" << "\t" << "\t"
89  << "Mass" << "\t" << "\t"
90  << std::endl;
91  out << "Level" << "\t"
92  << "Name" << "\t" << "\t"
93  << "Number" << "\t"
94  << "Name" << "\t" << "\t"
95  << "Name" << "\t" << "\t"
96  << "[g/cm3]" << "\t" << "\t"
97  << "[g] " << "\t" << "\t"
98  << std::endl;
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 135 of file PrintMaterialBudgetInfo.cc.

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

Referenced by update().

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

Definition at line 128 of file PrintMaterialBudgetInfo.cc.

Referenced by update().

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

Definition at line 101 of file PrintMaterialBudgetInfo.cc.

References name.

Referenced by update().

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

Definition at line 177 of file PrintMaterialBudgetInfo.cc.

References elementNames, elementTotalWeight, AlCaHLTBitMon_QueryRunRegistry::string, stringLaTeXSuperscript(), stringLaTeXUnderscore(), and histoStyle::weight.

Referenced by dumpHierarchyLeaf().

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

Definition at line 275 of file PrintMaterialBudgetInfo.cc.

References i, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by printInfo().

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

Definition at line 259 of file PrintMaterialBudgetInfo.cc.

References i, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by printInfo().

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

References assert(), 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().

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