CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PrintMaterialBudgetInfo Class Reference
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
virtual void beginRun (edm::EventSetup const &)
 
bool isMT () const
 
const SimWatcheroperator= (const SimWatcher &)=delete
 
virtual void registerConsumes (edm::ConsumesCollector)
 
 SimWatcher ()
 
 SimWatcher (const SimWatcher &)=delete
 
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=G4cout)
 
void dumpHeader (std::ostream &out=G4cout)
 
void dumpHierarchyLeaf (G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=G4cout, std::ostream &texOut=G4cout)
 
void dumpLaTeXFooter (std::ostream &out=G4cout)
 
void dumpLaTeXHeader (std::ostream &out=G4cout)
 
void printInfo (G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=G4cout, std::ostream &texOut=G4cout)
 
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
 
bool volumeFound
 
std::ofstream weightOutputFile
 

Additional Inherited Members

- Protected Member Functions inherited from SimWatcher
void setMT (bool val)
 

Detailed Description

Definition at line 41 of file PrintMaterialBudgetInfo.cc.

Constructor & Destructor Documentation

◆ PrintMaterialBudgetInfo()

PrintMaterialBudgetInfo::PrintMaterialBudgetInfo ( edm::ParameterSet const &  p)

Definition at line 84 of file PrintMaterialBudgetInfo.cc.

References elementNames, elementOutputFile, elementTotalWeight, elementWeightFraction, ecalTB2006H4_GenSimDigiReco_cfg::G4cout, name, nchar, AlCaHLTBitMon_ParallelJobs::p, AlCaHLTBitMon_QueryRunRegistry::string, texOutputFile, volumeFound, and weightOutputFile.

84  {
85  name = p.getUntrackedParameter<std::string>("Name", "*");
86  nchar = name.find('*');
87  name.assign(name, 0, nchar);
88  G4cout << "PrintMaterialBudget selected volume " << name << G4endl;
89  volumeFound = false;
90  std::string weightFileName = name + ".weight";
91  weightOutputFile.open(weightFileName.c_str());
92  std::string elementFileName = name + ".element";
93  elementOutputFile.open(elementFileName.c_str());
94  std::string texFileName = name + "_table.tex";
95  texOutputFile.open(texFileName.c_str());
96  G4cout << "PrintMaterialBudget output file " << weightFileName << G4endl;
97  G4cout << "PrintMaterialBudget output file " << elementFileName << G4endl;
98  G4cout << "PrintMaterialBudget output file " << texFileName << G4endl;
99  elementNames.clear();
100  elementTotalWeight.clear();
101  elementWeightFraction.clear();
102 }
std::vector< std::string > elementNames
std::vector< double > elementWeightFraction
std::vector< double > elementTotalWeight

◆ ~PrintMaterialBudgetInfo()

PrintMaterialBudgetInfo::~PrintMaterialBudgetInfo ( )
override

Definition at line 104 of file PrintMaterialBudgetInfo.cc.

104 {}

Member Function Documentation

◆ dumpElementMassFraction()

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

Definition at line 289 of file PrintMaterialBudgetInfo.cc.

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

Referenced by update().

289  {
290  // calculate mass fraction
291  double totalWeight = 0.0;
292  double totalFraction = 0.0;
293  for (unsigned int iElement = 0; iElement < (unsigned int)elementTotalWeight.size(); iElement++) {
294  totalWeight += elementTotalWeight[iElement];
295  }
296  // calculate element mass fractions
297  for (unsigned int iElement = 0; iElement < (unsigned int)elementTotalWeight.size(); iElement++) {
298  elementWeightFraction[iElement] = elementTotalWeight[iElement] / totalWeight;
299  totalFraction += elementWeightFraction[iElement];
300  }
301  // header
302  elementOut << "Element"
303  << "\t\t"
304  << "Index"
305  << "\t"
306  << "Total Mass"
307  << "\t"
308  << "Mass Fraction "
309  << "\t" << G4endl;
310  // dump
311  for (unsigned int iElement = 0; iElement < (unsigned int)elementTotalWeight.size(); iElement++) {
312  if (elementNames[iElement] != "rr") {
313  if (elementNames[iElement].size() < 8)
314  elementNames[iElement].append("\t");
315  elementOut << elementNames[iElement] << "\t" << iElement << "\t"
316  << G4BestUnit(elementTotalWeight[iElement], "Mass") << "\t" << elementWeightFraction[iElement]
317  << G4endl;
318  }
319  }
320  elementOut << "\n\t\tTotal Weight without Air " << G4BestUnit(totalWeight, "Mass") << "\tTotal Fraction "
321  << totalFraction << G4endl;
322 }
size
Write out results.
std::vector< std::string > elementNames
std::vector< double > elementWeightFraction
std::vector< double > elementTotalWeight

◆ dumpHeader()

void PrintMaterialBudgetInfo::dumpHeader ( std::ostream &  out = G4cout)
private

Definition at line 132 of file PrintMaterialBudgetInfo.cc.

References MillePedeFileConverter_cfg::out.

Referenced by update().

132  {
133  out << "Geom."
134  << "\t"
135  << "Volume"
136  << "\t"
137  << "\t"
138  << "Copy"
139  << "\t"
140  << "Solid"
141  << "\t"
142  << "\t"
143  << "Material"
144  << "\t"
145  << "Density"
146  << "\t"
147  << "\t"
148  << "Mass"
149  << "\t"
150  << "\t" << G4endl;
151  out << "Level"
152  << "\t"
153  << "Name"
154  << "\t"
155  << "\t"
156  << "Number"
157  << "\t"
158  << "Name"
159  << "\t"
160  << "\t"
161  << "Name"
162  << "\t"
163  << "\t"
164  << "[g/cm3]"
165  << "\t"
166  << "\t"
167  << "[g] "
168  << "\t"
169  << "\t" << G4endl;
170 }

◆ dumpHierarchyLeaf()

void PrintMaterialBudgetInfo::dumpHierarchyLeaf ( G4VPhysicalVolume *  pv,
G4LogicalVolume *  lv,
unsigned int  leafDepth,
std::ostream &  weightOut = G4cout,
std::ostream &  texOut = G4cout 
)
private

Definition at line 211 of file PrintMaterialBudgetInfo.cc.

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

Referenced by update().

212  {
213  if (volumeFound && (leafDepth <= levelFound))
214  return;
215  if (volumeFound && (leafDepth > levelFound))
216  printInfo(pv, lv, leafDepth, weightOut, texOut);
217 
218  // choose mother volume
219  std::string lvname = lv->GetName();
220  lvname.assign(lvname, 0, nchar);
221  if (lvname == name) {
222  volumeFound = true;
223  levelFound = leafDepth;
224  printInfo(pv, lv, leafDepth, weightOut, texOut);
225  texOut << " \\hline" << G4endl;
226  }
227 
228  //----- Get LV daughters from list of PV daughters
229  mmlvpv lvpvDaughters;
230  std::set<G4LogicalVolume*> lvDaughters;
231  int NoDaughters = lv->GetNoDaughters();
232  while ((NoDaughters--) > 0) {
233  G4VPhysicalVolume* pvD = lv->GetDaughter(NoDaughters);
234  lvpvDaughters.insert(mmlvpv::value_type(pvD->GetLogicalVolume(), pvD));
235  lvDaughters.insert(pvD->GetLogicalVolume());
236  }
237 
238  std::set<G4LogicalVolume*>::const_iterator scite;
239  mmlvpv::const_iterator mmcite;
240 
241  //----- Dump daughters PV and LV
242  for (scite = lvDaughters.begin(); scite != lvDaughters.end(); scite++) {
243  std::pair<mmlvpv::iterator, mmlvpv::iterator> mmER = lvpvDaughters.equal_range(*scite);
244  //----- Dump daughters PV of this LV
245  for (mmcite = mmER.first; mmcite != mmER.second; mmcite++)
246  dumpHierarchyLeaf((*mmcite).second, *scite, leafDepth + 1, weightOut, texOut);
247  }
248 }
std::multimap< G4LogicalVolume *, G4VPhysicalVolume *, std::less< G4LogicalVolume * > > mmlvpv
void dumpHierarchyLeaf(G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=G4cout, std::ostream &texOut=G4cout)
void printInfo(G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=G4cout, std::ostream &texOut=G4cout)

◆ dumpLaTeXFooter()

void PrintMaterialBudgetInfo::dumpLaTeXFooter ( std::ostream &  out = G4cout)
private

Definition at line 206 of file PrintMaterialBudgetInfo.cc.

References MillePedeFileConverter_cfg::out.

Referenced by update().

206  {
207  out << " \\hline" << G4endl << " \\end{tabular}" << G4endl << " \\end{center}" << G4endl << "\\end{table}"
208  << G4endl;
209 }

◆ dumpLaTeXHeader()

void PrintMaterialBudgetInfo::dumpLaTeXHeader ( std::ostream &  out = G4cout)
private

Definition at line 172 of file PrintMaterialBudgetInfo.cc.

References name, and MillePedeFileConverter_cfg::out.

Referenced by update().

172  {
173  out << "\\begin{table}[h!]" << G4endl << " \\caption{\\textsf {" << name << "} volume list.}" << G4endl
174  << " \\label{tab: " << name << "}" << G4endl << " \\begin{center}" << G4endl << " \\begin{tabular}{ccccccc}"
175  << G4endl << " \\hline" << G4endl;
176  out << " Geom."
177  << "\t & "
178  << " Volume"
179  << "\t & "
180  << " Copy"
181  << "\t & "
182  << " Solid"
183  << "\t & "
184  << " Material"
185  << "\t & "
186  << " Density"
187  << "\t & "
188  << " Mass"
189  << "\t \\\\ " << G4endl;
190  out << " Level"
191  << "\t & "
192  << " Name"
193  << "\t & "
194  << " Number"
195  << "\t & "
196  << " Name"
197  << "\t & "
198  << " Name"
199  << "\t & "
200  << " "
201  << "\t & "
202  << " "
203  << "\t \\\\ " << G4endl << " \\hline\\hline" << G4endl;
204 }

◆ printInfo()

void PrintMaterialBudgetInfo::printInfo ( G4VPhysicalVolume *  pv,
G4LogicalVolume *  lv,
unsigned int  leafDepth,
std::ostream &  weightOut = G4cout,
std::ostream &  texOut = G4cout 
)
private

Definition at line 250 of file PrintMaterialBudgetInfo.cc.

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

Referenced by dumpHierarchyLeaf().

251  {
252  double density = lv->GetMaterial()->GetDensity();
253  double weight = lv->GetMass(false, false);
254 
255  std::string volumeName = lv->GetName();
256  if (volumeName.size() < 8)
257  volumeName.append("\t");
258 
259  std::string solidName = lv->GetSolid()->GetName();
260  if (solidName.size() < 8)
261  solidName.append("\t");
262 
263  std::string materialName = lv->GetMaterial()->GetName();
264  if (materialName.size() < 8)
265  materialName.append("\t");
266 
267  //----- dump info
268  weightOut << leafDepth << "\t" << volumeName << "\t" << pv->GetCopyNo() << "\t" << solidName << "\t" << materialName
269  << "\t" << G4BestUnit(density, "Volumic Mass") << "\t" << G4BestUnit(weight, "Mass") << "\t" << G4endl;
270  //
271  texOut << "\t" << leafDepth << "\t & " << stringLaTeXUnderscore(volumeName) << "\t & " << pv->GetCopyNo() << "\t & "
272  << stringLaTeXUnderscore(solidName) << "\t & " << stringLaTeXUnderscore(materialName) << "\t & "
273  << stringLaTeXSuperscript(G4BestUnit(density, "Volumic Mass")) << "\t & "
274  << stringLaTeXSuperscript(G4BestUnit(weight, "Mass")) << "\t \\\\ " << G4endl;
275  //
276  for (unsigned int iElement = 0; iElement < (unsigned int)lv->GetMaterial()->GetNumberOfElements(); iElement++) {
277  // exclude Air in element weight fraction computation
278  if (materialName.find("Air")) {
279  std::string elementName = lv->GetMaterial()->GetElement(iElement)->GetName();
280  double elementMassFraction = lv->GetMaterial()->GetFractionVector()[iElement];
281  double elementWeight = weight * elementMassFraction;
282  unsigned int elementIndex = (unsigned int)lv->GetMaterial()->GetElement(iElement)->GetIndex();
283  elementNames[elementIndex] = elementName;
284  elementTotalWeight[elementIndex] += elementWeight;
285  }
286  }
287 }
std::vector< std::string > elementNames
Definition: weight.py:1
std::vector< double > elementTotalWeight
std::string stringLaTeXSuperscript(std::string stringname)
std::string stringLaTeXUnderscore(std::string stringname)

◆ stringLaTeXSuperscript()

std::string PrintMaterialBudgetInfo::stringLaTeXSuperscript ( std::string  stringname)
private

Definition at line 339 of file PrintMaterialBudgetInfo.cc.

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

Referenced by printInfo().

339  {
340  // To replace 'm3' with 'm$^3$' to compile LaTeX output
341  std::string stringoutput = stringname.substr(0, 1);
342 
343  for (unsigned int i = 1; i < stringname.length(); i++) {
344  if (stringname.substr(i - 1, 1) == "m" && stringname.substr(i, 1) == "3") {
345  stringoutput += "$^3$";
346  } else {
347  stringoutput += stringname.substr(i, 1);
348  }
349  }
350 
351  return stringoutput;
352 }

◆ stringLaTeXUnderscore()

std::string PrintMaterialBudgetInfo::stringLaTeXUnderscore ( std::string  stringname)
private

Definition at line 324 of file PrintMaterialBudgetInfo.cc.

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

Referenced by printInfo().

324  {
325  // To replace '\' with '\_' to compile LaTeX output
326  std::string stringoutput;
327 
328  for (unsigned int i = 0; i < stringname.length(); i++) {
329  if (stringname.substr(i, 1) == "_") {
330  stringoutput += "\\_";
331  } else {
332  stringoutput += stringname.substr(i, 1);
333  }
334  }
335 
336  return stringoutput;
337 }

◆ update() [1/2]

void PrintMaterialBudgetInfo::update ( const BeginOfJob )
inlineoverrideprivatevirtual

◆ update() [2/2]

void PrintMaterialBudgetInfo::update ( const BeginOfRun )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun *>.

Definition at line 106 of file PrintMaterialBudgetInfo.cc.

References cms::cuda::assert(), dumpElementMassFraction(), dumpHeader(), dumpHierarchyLeaf(), dumpLaTeXFooter(), dumpLaTeXHeader(), elementNames, elementOutputFile, elementTotalWeight, elementWeightFraction, suppress, texOutputFile, and weightOutputFile.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

106  {
107  [[clang::suppress]] G4Random::setTheEngine(new CLHEP::RanecuEngine);
108  // Physical Volume
109  G4VPhysicalVolume* theTopPV =
110  G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
111  assert(theTopPV);
112  // Logical Volume
113  G4LogicalVolume* lv = theTopPV->GetLogicalVolume();
114  unsigned int leafDepth = 0;
115  // the first time fill the vectors of elements
116  if (elementNames.empty() && elementTotalWeight.empty() && elementWeightFraction.empty()) {
117  for (unsigned int iElement = 0; iElement < G4Element::GetNumberOfElements();
118  iElement++) { // first element in table is 0
119  elementNames.push_back("rr");
120  elementTotalWeight.push_back(0);
121  elementWeightFraction.push_back(0);
122  }
123  }
126  dumpHierarchyLeaf(theTopPV, lv, leafDepth, weightOutputFile, texOutputFile);
129  //
130 }
void dumpLaTeXFooter(std::ostream &out=G4cout)
std::vector< std::string > elementNames
assert(be >=bs)
void dumpLaTeXHeader(std::ostream &out=G4cout)
std::vector< double > elementWeightFraction
std::vector< double > elementTotalWeight
void dumpElementMassFraction(std::ostream &elementOut=G4cout)
void dumpHierarchyLeaf(G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=G4cout, std::ostream &texOut=G4cout)
void dumpHeader(std::ostream &out=G4cout)

Member Data Documentation

◆ elementNames

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

◆ elementOutputFile

std::ofstream PrintMaterialBudgetInfo::elementOutputFile
private

Definition at line 74 of file PrintMaterialBudgetInfo.cc.

Referenced by PrintMaterialBudgetInfo(), and update().

◆ elementTotalWeight

std::vector<double> PrintMaterialBudgetInfo::elementTotalWeight
private

◆ elementWeightFraction

std::vector<double> PrintMaterialBudgetInfo::elementWeightFraction
private

◆ fHistory

G4NavigationHistory PrintMaterialBudgetInfo::fHistory
private

Definition at line 70 of file PrintMaterialBudgetInfo.cc.

◆ levelFound

unsigned int PrintMaterialBudgetInfo::levelFound
private

Definition at line 72 of file PrintMaterialBudgetInfo.cc.

Referenced by dumpHierarchyLeaf().

◆ name

std::string PrintMaterialBudgetInfo::name
private

◆ nchar

int PrintMaterialBudgetInfo::nchar
private

Definition at line 68 of file PrintMaterialBudgetInfo.cc.

Referenced by dumpHierarchyLeaf(), and PrintMaterialBudgetInfo().

◆ texOutputFile

std::ofstream PrintMaterialBudgetInfo::texOutputFile
private

Definition at line 75 of file PrintMaterialBudgetInfo.cc.

Referenced by PrintMaterialBudgetInfo(), and update().

◆ thePVTree

mpvpv PrintMaterialBudgetInfo::thePVTree
private

Definition at line 69 of file PrintMaterialBudgetInfo.cc.

◆ volumeFound

bool PrintMaterialBudgetInfo::volumeFound
private

Definition at line 71 of file PrintMaterialBudgetInfo.cc.

Referenced by dumpHierarchyLeaf(), and PrintMaterialBudgetInfo().

◆ weightOutputFile

std::ofstream PrintMaterialBudgetInfo::weightOutputFile
private

Definition at line 73 of file PrintMaterialBudgetInfo.cc.

Referenced by PrintMaterialBudgetInfo(), and update().