CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Validation/CheckOverlap/src/CheckOverlap.cc

Go to the documentation of this file.
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 "G4LogicalVolumeStore.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   std::vector<std::string> defNames;
00023   nodeNames = p.getUntrackedParameter<std::vector<std::string> >("NodeNames", defNames);
00024   nPoints   = p.getUntrackedParameter<int>("Resolution", 1000);
00025   edm::LogInfo("G4cout") << "CheckOverlap:: initialised with " 
00026                          << nodeNames.size() << " Node Names and Resolution " 
00027                          << nPoints << " the names are:"; 
00028   for (unsigned int ii=0; ii<nodeNames.size(); ii++)
00029     edm::LogInfo("G4cout") << "CheckOverlap:: Node[" << ii << "] : " << nodeNames[ii]; 
00030 }
00031  
00032 CheckOverlap::~CheckOverlap() {}
00033   
00034 void CheckOverlap::update(const BeginOfRun * run) {
00035   
00036   if (nodeNames.size() > 0) {
00037     const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
00038     std::vector<G4LogicalVolume *>::const_iterator lvcite;
00039     int i = 0;
00040     for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
00041       for (unsigned int ii=0; ii<nodeNames.size(); ii++) {
00042         if ((*lvcite)->GetName() == (G4String)(nodeNames[ii])) {
00043           topLV.push_back((*lvcite));
00044           break;
00045         }
00046       }
00047       edm::LogInfo("G4cout") << "Name of node " << (++i) << " : " 
00048                              << (*lvcite)->GetName();
00049       if (topLV.size() == nodeNames.size()) break;
00050     }
00051   } else {
00052     G4VPhysicalVolume * theTopPV = getTopPV();
00053     topLV.push_back(theTopPV->GetLogicalVolume());
00054   }
00055 
00056   if (topLV.size() == 0) {
00057     edm::LogInfo("G4cout") << "No Top LV Found";
00058   } else {
00059     for (unsigned int ii=0; ii<topLV.size(); ii++) {
00060       edm::LogInfo("G4cout") << "Top LV Name " << topLV[ii]->GetName();
00061       checkHierarchyLeafPVLV(topLV[ii], 0);
00062     }
00063   }
00064 }
00065 
00066 void CheckOverlap::checkHierarchyLeafPVLV(G4LogicalVolume * lv, 
00067                                           unsigned int leafDepth) {
00068 
00069   //----- Get LV daughters from list of PV daughters
00070   mmlvpv lvpvDaughters;
00071   std::set< G4LogicalVolume * > lvDaughters;
00072   int NoDaughters = lv->GetNoDaughters();
00073   while ((NoDaughters--)>0) {
00074     G4VPhysicalVolume * pvD = lv->GetDaughter(NoDaughters);
00075     lvpvDaughters.insert(mmlvpv::value_type(pvD->GetLogicalVolume(), pvD));
00076     lvDaughters.insert(pvD->GetLogicalVolume());
00077   }
00078  
00079   std::set< G4LogicalVolume * >::const_iterator scite;
00080   mmlvpv::const_iterator mmcite;
00081 
00082   //----- Check daughters of LV
00083   for (scite = lvDaughters.begin(); scite != lvDaughters.end(); scite++) {
00084     std::pair< mmlvpv::iterator, mmlvpv::iterator > mmER = lvpvDaughters.equal_range(*scite);    
00085     //----- Check daughters PV of this LV
00086     for (mmcite = mmER.first ; mmcite != mmER.second; mmcite++) 
00087       checkPV((*mmcite).second, leafDepth+1);
00088     //----- Check daughters LV
00089     checkHierarchyLeafPVLV(*scite, leafDepth+1);
00090   }
00091 }
00092 
00093 void CheckOverlap::checkPV(G4VPhysicalVolume * pv, unsigned int leafDepth) {
00094 
00095   //----- PV info
00096 #ifndef G4V7
00097   std::string mother = "World";
00098   if (pv->GetMotherLogical()) mother = pv->GetMotherLogical()->GetName();
00099   if (!pv->IsReplicated()) {
00100     G4PVPlacement* pvplace = dynamic_cast<G4PVPlacement* >(pv);
00101     G4bool ok = pvplace->CheckOverlaps(nPoints);
00102     edm::LogInfo("G4cout") << "Placed PV " << pvplace->GetName() 
00103                            << " Number " << pvplace->GetCopyNo() 
00104                            << " in mother " << mother << " at depth " 
00105                            << leafDepth << " Status " << ok;
00106     if (ok) {
00107       if(pv->GetRotation() == 0) {
00108         edm::LogInfo("G4cout") << "Translation " << pv->GetTranslation()
00109                                << " and with no rotation";
00110       } else {
00111         edm::LogInfo("G4cout") << "Translation " << pv->GetTranslation()
00112                                << " and with rotation "<< *(pv->GetRotation());
00113       }
00114       G4LogicalVolume* lv = pv->GetLogicalVolume();
00115       dumpLV(lv, "Self");
00116       if (pv->GetMotherLogical()) {
00117         lv = pv->GetMotherLogical();
00118         dumpLV (lv, "Mother");
00119       }
00120     }
00121   } else {
00122     if (pv->GetParameterisation() != 0) {
00123       G4PVParameterised* pvparam = dynamic_cast<G4PVParameterised* >(pv);
00124       G4bool ok = pvparam->CheckOverlaps(nPoints);
00125       edm::LogInfo("G4cout") << "Parametrized PV " << pvparam->GetName()
00126                              << " in mother " << mother << " at depth "
00127                              << leafDepth << " Status " << ok;
00128     }
00129   }
00130 #endif
00131 }
00132 
00133 G4VPhysicalVolume * CheckOverlap::getTopPV() {
00134   return G4TransportationManager::GetTransportationManager()
00135     ->GetNavigatorForTracking()->GetWorldVolume();
00136 }
00137 
00138 void CheckOverlap::dumpLV(G4LogicalVolume* lv, std::string str) {
00139   edm::LogInfo("G4cout") << "Dump of " << str << " Logical Volume " 
00140                          << lv->GetName() << "  Solid: " 
00141                          << lv->GetSolid()->GetName() << "  Material: "
00142                          << lv->GetMaterial()->GetName();
00143   edm::LogInfo("G4cout") << *(lv->GetSolid());
00144 }
00145