Go to the documentation of this file.00001 #include "SimG4Core/PrintGeomInfo/interface/PrintSensitive.h"
00002
00003 #include "SimG4Core/Notification/interface/BeginOfRun.h"
00004 #include "SimG4Core/Notification/interface/SimG4Exception.h"
00005
00006 #include "G4Run.hh"
00007 #include "G4VPhysicalVolume.hh"
00008 #include "G4LogicalVolume.hh"
00009 #include "G4TransportationManager.hh"
00010
00011 #include <set>
00012 #include <map>
00013
00014 PrintSensitive::PrintSensitive(const edm::ParameterSet &p) {
00015 name = p.getUntrackedParameter<std::string>("Name","*");
00016 nchar = name.find("*");
00017 name.assign(name,0,nchar);
00018 std::cout << "PrintSensitive:: Print position of all Sensitive Touchables: "
00019 << " for names (0-" << nchar << ") = " << name << "\n";
00020 }
00021
00022 PrintSensitive::~PrintSensitive() {}
00023
00024 void PrintSensitive::update(const BeginOfRun * run) {
00025
00026 G4VPhysicalVolume * theTopPV = getTopPV();
00027 dumpTouch(theTopPV, 0, false, std::cout);
00028 }
00029
00030 void PrintSensitive::dumpTouch(G4VPhysicalVolume * pv, unsigned int leafDepth,
00031 bool printIt, std::ostream & out) {
00032
00033 if (leafDepth == 0) fHistory.SetFirstEntry(pv);
00034 else fHistory.NewLevel(pv, kNormal, pv->GetCopyNo());
00035
00036 G4ThreeVector globalpoint = fHistory.GetTopTransform().Inverse().
00037 TransformPoint(G4ThreeVector(0,0,0));
00038 G4LogicalVolume * lv = pv->GetLogicalVolume();
00039
00040 std::string mother = "World";
00041 if (pv->GetMotherLogical()) mother = pv->GetMotherLogical()->GetName();
00042 std::string lvname = lv->GetName();
00043 lvname.assign(lvname,0,nchar);
00044 if (lvname == name) printIt = true;
00045
00046 if (lv->GetSensitiveDetector() && printIt) {
00047 out << leafDepth << " ### VOLUME = " << lv->GetName()
00048 << " Copy No " << pv->GetCopyNo() << " in " << mother
00049 << " global position of centre " << globalpoint << " (r="
00050 << globalpoint.perp() << ", phi=" << globalpoint.phi()/deg
00051 << ")\n";
00052 }
00053
00054 int NoDaughters = lv->GetNoDaughters();
00055 while ((NoDaughters--)>0) {
00056 G4VPhysicalVolume * pvD = lv->GetDaughter(NoDaughters);
00057 if (!pvD->IsReplicated()) dumpTouch(pvD, leafDepth+1, printIt, out);
00058 }
00059
00060 if (leafDepth > 0) fHistory.BackLevel();
00061 }
00062
00063 G4VPhysicalVolume * PrintSensitive::getTopPV() {
00064 return G4TransportationManager::GetTransportationManager()
00065 ->GetNavigatorForTracking()->GetWorldVolume();
00066 }