00001 #include "Validation/CheckOverlap/interface/CheckOverlap.h"
00002
00003 #include "SimG4Core/Notification/interface/BeginOfJob.h"
00004 #include "SimG4Core/Notification/interface/BeginOfRun.h"
00005
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00010
00011 #include "G4Run.hh"
00012 #include "G4PhysicalVolumeStore.hh"
00013 #include "G4PVPlacement.hh"
00014 #include "G4PVParameterised.hh"
00015 #include "G4LogicalVolume.hh"
00016 #include "G4Material.hh"
00017 #include "G4TransportationManager.hh"
00018
00019 #include <set>
00020
00021 CheckOverlap::CheckOverlap(const edm::ParameterSet &p) : topLV(0) {
00022 nodeName = p.getUntrackedParameter<std::string>("NodeName", "");
00023 nPoints = p.getUntrackedParameter<int>("Resolution", 1000);
00024 edm::LogInfo("G4cout") << "CheckOverlap:: initialised with Node Name "
00025 << " " << nodeName << " and Resolution "
00026 << nPoints;
00027 }
00028
00029 CheckOverlap::~CheckOverlap() {}
00030
00031 void CheckOverlap::update(const BeginOfRun * run) {
00032
00033 edm::LogInfo("G4cout") << "Node Name " << nodeName;
00034 if (nodeName != "") {
00035 const G4PhysicalVolumeStore * pvs = G4PhysicalVolumeStore::GetInstance();
00036 std::vector<G4VPhysicalVolume *>::const_iterator pvcite;
00037 int i = 0;
00038 for (pvcite = pvs->begin(); pvcite != pvs->end(); pvcite++) {
00039 edm::LogInfo("G4cout") << "Name of node " << (++i) << " : "
00040 << (*pvcite)->GetName();
00041 if ((*pvcite)->GetName() == (G4String)(nodeName)) {
00042 topLV = (*pvcite)->GetLogicalVolume();
00043 break;
00044 }
00045 }
00046 } else {
00047 G4VPhysicalVolume * theTopPV = getTopPV();
00048 topLV = theTopPV->GetLogicalVolume();
00049 }
00050 if (topLV != 0) edm::LogInfo("G4cout") << "Top LV Name " << topLV->GetName();
00051 else edm::LogInfo("G4cout") << "No Top LV Found";
00052
00053 if (topLV)
00054 checkHierarchyLeafPVLV(topLV, 0);
00055 }
00056
00057 void CheckOverlap::checkHierarchyLeafPVLV(G4LogicalVolume * lv,
00058 uint leafDepth) {
00059
00060
00061 mmlvpv lvpvDaughters;
00062 std::set< G4LogicalVolume * > lvDaughters;
00063 int NoDaughters = lv->GetNoDaughters();
00064 while ((NoDaughters--)>0) {
00065 G4VPhysicalVolume * pvD = lv->GetDaughter(NoDaughters);
00066 lvpvDaughters.insert(mmlvpv::value_type(pvD->GetLogicalVolume(), pvD));
00067 lvDaughters.insert(pvD->GetLogicalVolume());
00068 }
00069
00070 std::set< G4LogicalVolume * >::const_iterator scite;
00071 mmlvpv::const_iterator mmcite;
00072
00073
00074 for (scite = lvDaughters.begin(); scite != lvDaughters.end(); scite++) {
00075 std::pair< mmlvpv::iterator, mmlvpv::iterator > mmER = lvpvDaughters.equal_range(*scite);
00076
00077 for (mmcite = mmER.first ; mmcite != mmER.second; mmcite++)
00078 checkPV((*mmcite).second, leafDepth+1);
00079
00080 checkHierarchyLeafPVLV(*scite, leafDepth+1);
00081 }
00082 }
00083
00084 void CheckOverlap::checkPV(G4VPhysicalVolume * pv, uint leafDepth) {
00085
00086
00087 #ifndef G4V7
00088 std::string mother = "World";
00089 if (pv->GetMotherLogical()) mother = pv->GetMotherLogical()->GetName();
00090 if (!pv->IsReplicated()) {
00091 G4PVPlacement* pvplace = dynamic_cast<G4PVPlacement* >(pv);
00092 G4bool ok = pvplace->CheckOverlaps(nPoints);
00093 edm::LogInfo("G4cout") << "Placed PV " << pvplace->GetName()
00094 << " Number " << pvplace->GetCopyNo()
00095 << " in mother " << mother << " at depth "
00096 << leafDepth << " Status " << ok;
00097 if (ok) {
00098 if(pv->GetRotation() == 0) {
00099 edm::LogInfo("G4cout") << "Translation " << pv->GetTranslation()
00100 << " and with no rotation";
00101 } else {
00102 edm::LogInfo("G4cout") << "Translation " << pv->GetTranslation()
00103 << " and with rotation "<< *(pv->GetRotation());
00104 }
00105 G4LogicalVolume* lv = pv->GetLogicalVolume();
00106 dumpLV(lv, "Self");
00107 if (pv->GetMotherLogical()) {
00108 lv = pv->GetMotherLogical();
00109 dumpLV (lv, "Mother");
00110 }
00111 }
00112 } else {
00113 if (pv->GetParameterisation() != 0) {
00114 G4PVParameterised* pvparam = dynamic_cast<G4PVParameterised* >(pv);
00115 G4bool ok = pvparam->CheckOverlaps(nPoints);
00116 edm::LogInfo("G4cout") << "Parametrized PV " << pvparam->GetName()
00117 << " in mother " << mother << " at depth "
00118 << leafDepth << " Status " << ok;
00119 }
00120 }
00121 #endif
00122 }
00123
00124 G4VPhysicalVolume * CheckOverlap::getTopPV() {
00125 return G4TransportationManager::GetTransportationManager()
00126 ->GetNavigatorForTracking()->GetWorldVolume();
00127 }
00128
00129 void CheckOverlap::dumpLV(G4LogicalVolume* lv, std::string str) {
00130 edm::LogInfo("G4cout") << "Dump of " << str << " Logical Volume "
00131 << lv->GetName() << " Solid: "
00132 << lv->GetSolid()->GetName() << " Material: "
00133 << lv->GetMaterial()->GetName();
00134 edm::LogInfo("G4cout") << *(lv->GetSolid());
00135 }
00136