Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:21:25

0001 #include "SimG4Core/Geometry/interface/CMSG4RegionReporter.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 #include "G4Region.hh"
0005 #include "G4RegionStore.hh"
0006 #include "G4LogicalVolume.hh"
0007 #include "G4ProductionCuts.hh"
0008 #include <CLHEP/Units/SystemOfUnits.h>
0009 
0010 #include <iostream>
0011 #include <iomanip>
0012 #include <fstream>
0013 
0014 CMSG4RegionReporter::CMSG4RegionReporter() {}
0015 
0016 CMSG4RegionReporter::~CMSG4RegionReporter() {}
0017 
0018 void CMSG4RegionReporter::ReportRegions(const std::string& ss) {
0019   std::ofstream fout(ss.c_str(), std::ios::out);
0020   if (fout.fail()) {
0021     edm::LogWarning("SimG4CoreGeometry") << "CMSG4RegionReporter: file <" << ss
0022                                          << "> is not opened - no report provided";
0023     return;
0024   }
0025   G4RegionStore* regStore = G4RegionStore::GetInstance();
0026 
0027   unsigned int numRegions = regStore->size();
0028 
0029   unsigned int i;
0030 
0031   fout << "\n";
0032   fout << "#---------------------------------------------------------------------";
0033   fout << "------------------------------------"
0034        << "\n";
0035   fout << "## List of Regions, root logical volumes and cuts. "
0036        << "\n";
0037   fout << "## Number of regions = " << numRegions << "\n";
0038 
0039   //  Banner
0040   fout << "# " << std::setw(24) << " Region, " << std::setw(38) << " LogicalVolume, "
0041        << " Cuts:Gamma, Electron, Positron, Proton, Units"
0042        << "\n";
0043   fout << "#---------------------------------------------------------------------";
0044   fout << "------------------------------------"
0045        << "\n";
0046 
0047   for (i = 0; i < numRegions; ++i) {
0048     G4Region* region = regStore->at(i);
0049     G4ProductionCuts* prodCuts = region->GetProductionCuts();
0050 
0051     G4LogicalVolume* lv;
0052 
0053     G4double lengthUnit = CLHEP::mm;
0054     G4String lengthUnitName = "mm";
0055     unsigned int pmax = 4;  // g, e-, e+, proton
0056 
0057     std::vector<G4LogicalVolume*>::iterator rootLVItr = region->GetRootLogicalVolumeIterator();
0058     size_t numRootLV = region->GetNumberOfRootVolumes();
0059 
0060     for (size_t iLV = 0; iLV < numRootLV; ++iLV, ++rootLVItr) {
0061       // Cover each root logical volume in this region
0062 
0063       //Set the couple to the proper logical volumes in that region
0064       lv = *rootLVItr;
0065 
0066       // fout << " Region=" << region->GetName()
0067       //     << " Logical-Volume = " << lv->GetName();
0068       char quote = '"';
0069       std::ostringstream regName, lvName;
0070       regName << quote << region->GetName() << quote;
0071       lvName << quote << lv->GetName() << quote;
0072       fout << " " << std::setw(26) << regName.str() << " ,";
0073       fout << " " << std::setw(36) << lvName.str() << " ,";
0074 
0075       unsigned int ic;
0076       for (ic = 0; ic < pmax; ++ic) {
0077         G4double cutLength = prodCuts->GetProductionCut(ic);
0078         fout << " " << std::setw(5) << cutLength / lengthUnit;
0079         if (ic < pmax - 1) {
0080           fout << " , ";
0081         } else {
0082           fout << " ,   " << lengthUnitName;
0083         }
0084       }
0085       fout << "\n";
0086     }
0087   }
0088   fout << "#---------------------------------------------------------------------";
0089   fout << "------------------------------------"
0090        << "\n";
0091   fout << "\n";
0092   fout.close();
0093 }