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
 
G4VPhysicalVolume * theTopPV
 
bool volumeFound
 
std::ofstream weightOutputFile
 

Additional Inherited Members

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

Detailed Description

Definition at line 40 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 288 of file PrintMaterialBudgetInfo.cc.

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

Referenced by update().

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

References MillePedeFileConverter_cfg::out.

Referenced by update().

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

◆ dumpHierarchyLeaf()

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

Definition at line 210 of file PrintMaterialBudgetInfo.cc.

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

Referenced by update().

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

References MillePedeFileConverter_cfg::out.

Referenced by update().

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

◆ dumpLaTeXHeader()

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

Definition at line 171 of file PrintMaterialBudgetInfo.cc.

References name, and MillePedeFileConverter_cfg::out.

Referenced by update().

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

◆ printInfo()

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

Definition at line 249 of file PrintMaterialBudgetInfo.cc.

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

Referenced by dumpHierarchyLeaf().

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

◆ stringLaTeXSuperscript()

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

Definition at line 338 of file PrintMaterialBudgetInfo.cc.

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

Referenced by printInfo().

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

◆ stringLaTeXUnderscore()

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

Definition at line 323 of file PrintMaterialBudgetInfo.cc.

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

Referenced by printInfo().

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

◆ update() [1/2]

void PrintMaterialBudgetInfo::update ( const BeginOfJob )
inlineoverrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfJob *>.

Definition at line 48 of file PrintMaterialBudgetInfo.cc.

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

48 {};

◆ 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, texOutputFile, theTopPV, and weightOutputFile.

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

106  {
107  G4Random::setTheEngine(new CLHEP::RanecuEngine);
108  // Physical Volume
109  theTopPV = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
110  assert(theTopPV);
111  // Logical Volume
112  G4LogicalVolume* lv = theTopPV->GetLogicalVolume();
113  unsigned int leafDepth = 0;
114  // the first time fill the vectors of elements
115  if (elementNames.empty() && elementTotalWeight.empty() && elementWeightFraction.empty()) {
116  for (unsigned int iElement = 0; iElement < G4Element::GetNumberOfElements();
117  iElement++) { // first element in table is 0
118  elementNames.push_back("rr");
119  elementTotalWeight.push_back(0);
120  elementWeightFraction.push_back(0);
121  }
122  }
128  //
129 }
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 67 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 68 of file PrintMaterialBudgetInfo.cc.

◆ theTopPV

G4VPhysicalVolume* PrintMaterialBudgetInfo::theTopPV
private

Definition at line 69 of file PrintMaterialBudgetInfo.cc.

Referenced by update().

◆ 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().