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 () override
 
- 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) 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

Detailed Description

Definition at line 24 of file PrintMaterialBudgetInfo.h.

Constructor & Destructor Documentation

◆ PrintMaterialBudgetInfo()

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

Definition at line 32 of file PrintMaterialBudgetInfo.cc.

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 }

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

◆ ~PrintMaterialBudgetInfo()

PrintMaterialBudgetInfo::~PrintMaterialBudgetInfo ( )
override

Definition at line 52 of file PrintMaterialBudgetInfo.cc.

52 {}

Member Function Documentation

◆ dumpElementMassFraction()

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

Definition at line 242 of file PrintMaterialBudgetInfo.cc.

242  {
243  // calculate mass fraction
244  double totalWeight = 0.0;
245  double totalFraction = 0.0;
246  for (unsigned int iElement = 0; iElement < (unsigned int)elementTotalWeight.size(); iElement++) {
247  totalWeight += elementTotalWeight[iElement];
248  }
249  // calculate element mass fractions
250  for (unsigned int iElement = 0; iElement < (unsigned int)elementTotalWeight.size(); iElement++) {
251  elementWeightFraction[iElement] = elementTotalWeight[iElement] / totalWeight;
252  totalFraction += elementWeightFraction[iElement];
253  }
254  // header
255  elementOut << "Element"
256  << "\t\t"
257  << "Index"
258  << "\t"
259  << "Total Mass"
260  << "\t"
261  << "Mass Fraction "
262  << "\t" << std::endl;
263  // dump
264  for (unsigned int iElement = 0; iElement < (unsigned int)elementTotalWeight.size(); iElement++) {
265  if (elementNames[iElement] != "rr") {
266  if (elementNames[iElement].size() < 8)
267  elementNames[iElement].append("\t");
268  elementOut << elementNames[iElement] << "\t" << iElement << "\t"
269  << G4BestUnit(elementTotalWeight[iElement], "Mass") << "\t" << elementWeightFraction[iElement]
270  << std::endl;
271  }
272  }
273  elementOut << "\n\t\tTotal Weight without Air " << G4BestUnit(totalWeight, "Mass") << "\tTotal Fraction "
274  << totalFraction << std::endl;
275 }

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

Referenced by update().

◆ dumpHeader()

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

Definition at line 79 of file PrintMaterialBudgetInfo.cc.

79  {
80  out << "Geom."
81  << "\t"
82  << "Volume"
83  << "\t"
84  << "\t"
85  << "Copy"
86  << "\t"
87  << "Solid"
88  << "\t"
89  << "\t"
90  << "Material"
91  << "\t"
92  << "Density"
93  << "\t"
94  << "\t"
95  << "Mass"
96  << "\t"
97  << "\t" << std::endl;
98  out << "Level"
99  << "\t"
100  << "Name"
101  << "\t"
102  << "\t"
103  << "Number"
104  << "\t"
105  << "Name"
106  << "\t"
107  << "\t"
108  << "Name"
109  << "\t"
110  << "\t"
111  << "[g/cm3]"
112  << "\t"
113  << "\t"
114  << "[g] "
115  << "\t"
116  << "\t" << std::endl;
117 }

References MillePedeFileConverter_cfg::out.

Referenced by update().

◆ dumpHierarchyLeaf()

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

Definition at line 164 of file PrintMaterialBudgetInfo.cc.

165  {
166  if (volumeFound && (leafDepth <= levelFound))
167  return;
168  if (volumeFound && (leafDepth > levelFound))
169  printInfo(pv, lv, leafDepth, weightOut, texOut);
170 
171  // choose mother volume
172  std::string lvname = lv->GetName();
173  lvname.assign(lvname, 0, nchar);
174  if (lvname == name) {
175  volumeFound = true;
176  levelFound = leafDepth;
177  printInfo(pv, lv, leafDepth, weightOut, texOut);
178  texOut << " \\hline" << std::endl;
179  }
180 
181  //----- Get LV daughters from list of PV daughters
182  mmlvpv lvpvDaughters;
183  std::set<G4LogicalVolume*> lvDaughters;
184  int NoDaughters = lv->GetNoDaughters();
185  while ((NoDaughters--) > 0) {
186  G4VPhysicalVolume* pvD = lv->GetDaughter(NoDaughters);
187  lvpvDaughters.insert(mmlvpv::value_type(pvD->GetLogicalVolume(), pvD));
188  lvDaughters.insert(pvD->GetLogicalVolume());
189  }
190 
191  std::set<G4LogicalVolume*>::const_iterator scite;
192  mmlvpv::const_iterator mmcite;
193 
194  //----- Dump daughters PV and LV
195  for (scite = lvDaughters.begin(); scite != lvDaughters.end(); scite++) {
196  std::pair<mmlvpv::iterator, mmlvpv::iterator> mmER = lvpvDaughters.equal_range(*scite);
197  //----- Dump daughters PV of this LV
198  for (mmcite = mmER.first; mmcite != mmER.second; mmcite++)
199  dumpHierarchyLeaf((*mmcite).second, *scite, leafDepth + 1, weightOut, texOut);
200  }
201 }

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

Referenced by update().

◆ dumpLaTeXFooter()

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

Definition at line 157 of file PrintMaterialBudgetInfo.cc.

157  {
158  out << " \\hline" << std::endl
159  << " \\end{tabular}" << std::endl
160  << " \\end{center}" << std::endl
161  << "\\end{table}" << std::endl;
162 }

References MillePedeFileConverter_cfg::out.

Referenced by update().

◆ dumpLaTeXHeader()

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

Definition at line 119 of file PrintMaterialBudgetInfo.cc.

119  {
120  out << "\\begin{table}[h!]" << std::endl
121  << " \\caption{\\textsf {" << name << "} volume list.}" << std::endl
122  << " \\label{tab: " << name << "}" << std::endl
123  << " \\begin{center}" << std::endl
124  << " \\begin{tabular}{ccccccc}" << std::endl
125  << " \\hline" << std::endl;
126  out << " Geom."
127  << "\t & "
128  << " Volume"
129  << "\t & "
130  << " Copy"
131  << "\t & "
132  << " Solid"
133  << "\t & "
134  << " Material"
135  << "\t & "
136  << " Density"
137  << "\t & "
138  << " Mass"
139  << "\t \\\\ " << std::endl;
140  out << " Level"
141  << "\t & "
142  << " Name"
143  << "\t & "
144  << " Number"
145  << "\t & "
146  << " Name"
147  << "\t & "
148  << " Name"
149  << "\t & "
150  << " "
151  << "\t & "
152  << " "
153  << "\t \\\\ " << std::endl
154  << " \\hline\\hline" << std::endl;
155 }

References name, and MillePedeFileConverter_cfg::out.

Referenced by update().

◆ printInfo()

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

Definition at line 203 of file PrintMaterialBudgetInfo.cc.

204  {
205  double density = lv->GetMaterial()->GetDensity();
206  double weight = lv->GetMass(false, false);
207 
208  std::string volumeName = lv->GetName();
209  if (volumeName.size() < 8)
210  volumeName.append("\t");
211 
212  std::string solidName = lv->GetSolid()->GetName();
213  if (solidName.size() < 8)
214  solidName.append("\t");
215 
216  std::string materialName = lv->GetMaterial()->GetName();
217  if (materialName.size() < 8)
218  materialName.append("\t");
219 
220  //----- dump info
221  weightOut << leafDepth << "\t" << volumeName << "\t" << pv->GetCopyNo() << "\t" << solidName << "\t" << materialName
222  << "\t" << G4BestUnit(density, "Volumic Mass") << "\t" << G4BestUnit(weight, "Mass") << "\t" << std::endl;
223  //
224  texOut << "\t" << leafDepth << "\t & " << stringLaTeXUnderscore(volumeName) << "\t & " << pv->GetCopyNo() << "\t & "
225  << stringLaTeXUnderscore(solidName) << "\t & " << stringLaTeXUnderscore(materialName) << "\t & "
226  << stringLaTeXSuperscript(G4BestUnit(density, "Volumic Mass")) << "\t & "
227  << stringLaTeXSuperscript(G4BestUnit(weight, "Mass")) << "\t \\\\ " << std::endl;
228  //
229  for (unsigned int iElement = 0; iElement < (unsigned int)lv->GetMaterial()->GetNumberOfElements(); iElement++) {
230  // exclude Air in element weight fraction computation
231  if (materialName.find("Air")) {
232  std::string elementName = lv->GetMaterial()->GetElement(iElement)->GetName();
233  double elementMassFraction = lv->GetMaterial()->GetFractionVector()[iElement];
234  double elementWeight = weight * elementMassFraction;
235  unsigned int elementIndex = (unsigned int)lv->GetMaterial()->GetElement(iElement)->GetIndex();
236  elementNames[elementIndex] = elementName;
237  elementTotalWeight[elementIndex] += elementWeight;
238  }
239  }
240 }

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

Referenced by dumpHierarchyLeaf().

◆ stringLaTeXSuperscript()

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

Definition at line 292 of file PrintMaterialBudgetInfo.cc.

292  {
293  // To replace 'm3' with 'm$^3$' to compile LaTeX output
294  std::string stringoutput = stringname.substr(0, 1);
295 
296  for (unsigned int i = 1; i < stringname.length(); i++) {
297  if (stringname.substr(i - 1, 1) == "m" && stringname.substr(i, 1) == "3") {
298  stringoutput += "$^3$";
299  } else {
300  stringoutput += stringname.substr(i, 1);
301  }
302  }
303 
304  return stringoutput;
305 }

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

Referenced by printInfo().

◆ stringLaTeXUnderscore()

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

Definition at line 277 of file PrintMaterialBudgetInfo.cc.

277  {
278  // To replace '\' with '\_' to compile LaTeX output
279  std::string stringoutput;
280 
281  for (unsigned int i = 0; i < stringname.length(); i++) {
282  if (stringname.substr(i, 1) == "_") {
283  stringoutput += "\\_";
284  } else {
285  stringoutput += stringname.substr(i, 1);
286  }
287  }
288 
289  return stringoutput;
290 }

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

Referenced by printInfo().

◆ 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 32 of file PrintMaterialBudgetInfo.h.

32 {};

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

◆ 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 54 of file PrintMaterialBudgetInfo.cc.

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

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

Member Data Documentation

◆ elementNames

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

◆ elementOutputFile

std::ofstream PrintMaterialBudgetInfo::elementOutputFile
private

Definition at line 58 of file PrintMaterialBudgetInfo.h.

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 54 of file PrintMaterialBudgetInfo.h.

◆ levelFound

unsigned int PrintMaterialBudgetInfo::levelFound
private

Definition at line 56 of file PrintMaterialBudgetInfo.h.

Referenced by dumpHierarchyLeaf().

◆ name

std::string PrintMaterialBudgetInfo::name
private

◆ nchar

int PrintMaterialBudgetInfo::nchar
private

Definition at line 51 of file PrintMaterialBudgetInfo.h.

Referenced by dumpHierarchyLeaf(), and PrintMaterialBudgetInfo().

◆ texOutputFile

std::ofstream PrintMaterialBudgetInfo::texOutputFile
private

Definition at line 59 of file PrintMaterialBudgetInfo.h.

Referenced by PrintMaterialBudgetInfo(), and update().

◆ thePVTree

mpvpv PrintMaterialBudgetInfo::thePVTree
private

Definition at line 52 of file PrintMaterialBudgetInfo.h.

◆ theTopPV

G4VPhysicalVolume* PrintMaterialBudgetInfo::theTopPV
private

Definition at line 53 of file PrintMaterialBudgetInfo.h.

Referenced by update().

◆ volumeFound

bool PrintMaterialBudgetInfo::volumeFound
private

Definition at line 55 of file PrintMaterialBudgetInfo.h.

Referenced by dumpHierarchyLeaf(), and PrintMaterialBudgetInfo().

◆ weightOutputFile

std::ofstream PrintMaterialBudgetInfo::weightOutputFile
private

Definition at line 57 of file PrintMaterialBudgetInfo.h.

Referenced by PrintMaterialBudgetInfo(), and update().

mps_fire.i
i
Definition: mps_fire.py:428
mmlvpv
std::multimap< G4LogicalVolume *, G4VPhysicalVolume *, std::less< G4LogicalVolume * > > mmlvpv
Definition: PrintGeomInfoAction.h:19
PrintMaterialBudgetInfo::texOutputFile
std::ofstream texOutputFile
Definition: PrintMaterialBudgetInfo.h:59
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
generateEDF.totalWeight
totalWeight
Definition: generateEDF.py:688
cms::cuda::assert
assert(be >=bs)
PrintMaterialBudgetInfo::levelFound
unsigned int levelFound
Definition: PrintMaterialBudgetInfo.h:56
PrintMaterialBudgetInfo::dumpElementMassFraction
void dumpElementMassFraction(std::ostream &elementOut=std::cout)
Definition: PrintMaterialBudgetInfo.cc:242
PrintMaterialBudgetInfo::elementNames
std::vector< std::string > elementNames
Definition: PrintMaterialBudgetInfo.h:60
PrintMaterialBudgetInfo::volumeFound
bool volumeFound
Definition: PrintMaterialBudgetInfo.h:55
PrintMaterialBudgetInfo::nchar
int nchar
Definition: PrintMaterialBudgetInfo.h:51
PrintMaterialBudgetInfo::printInfo
void printInfo(G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=std::cout, std::ostream &texOut=std::cout)
Definition: PrintMaterialBudgetInfo.cc:203
PrintMaterialBudgetInfo::elementTotalWeight
std::vector< double > elementTotalWeight
Definition: PrintMaterialBudgetInfo.h:61
PrintMaterialBudgetInfo::elementWeightFraction
std::vector< double > elementWeightFraction
Definition: PrintMaterialBudgetInfo.h:62
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PrintMaterialBudgetInfo::dumpHierarchyLeaf
void dumpHierarchyLeaf(G4VPhysicalVolume *pv, G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &weightOut=std::cout, std::ostream &texOut=std::cout)
Definition: PrintMaterialBudgetInfo.cc:164
PrintMaterialBudgetInfo::dumpLaTeXFooter
void dumpLaTeXFooter(std::ostream &out=std::cout)
Definition: PrintMaterialBudgetInfo.cc:157
PrintMaterialBudgetInfo::theTopPV
G4VPhysicalVolume * theTopPV
Definition: PrintMaterialBudgetInfo.h:53
mps_setup.append
append
Definition: mps_setup.py:85
PrintMaterialBudgetInfo::elementOutputFile
std::ofstream elementOutputFile
Definition: PrintMaterialBudgetInfo.h:58
createfilelist.int
int
Definition: createfilelist.py:10
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
PrintMaterialBudgetInfo::stringLaTeXSuperscript
std::string stringLaTeXSuperscript(std::string stringname)
Definition: PrintMaterialBudgetInfo.cc:292
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
PrintMaterialBudgetInfo::dumpHeader
void dumpHeader(std::ostream &out=std::cout)
Definition: PrintMaterialBudgetInfo.cc:79
PrintMaterialBudgetInfo::name
std::string name
Definition: PrintMaterialBudgetInfo.h:50
PrintMaterialBudgetInfo::stringLaTeXUnderscore
std::string stringLaTeXUnderscore(std::string stringname)
Definition: PrintMaterialBudgetInfo.cc:277
PrintMaterialBudgetInfo::dumpLaTeXHeader
void dumpLaTeXHeader(std::ostream &out=std::cout)
Definition: PrintMaterialBudgetInfo.cc:119
PrintMaterialBudgetInfo::weightOutputFile
std::ofstream weightOutputFile
Definition: PrintMaterialBudgetInfo.h:57
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
weight
Definition: weight.py:1
fastSimProducer_cff.density
density
Definition: fastSimProducer_cff.py:61
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443