diff --git a/DDEve/include/DDEve/Utilities.h b/DDEve/include/DDEve/Utilities.h index 2f1f93d20597f0b938d45305c1c8b45af9515678..e9c34026231fa2abd23052851c8d0ff0ba27d532 100644 --- a/DDEve/include/DDEve/Utilities.h +++ b/DDEve/include/DDEve/Utilities.h @@ -23,10 +23,10 @@ namespace DD4hep { namespace Utilities { - bool findNodeWithMatrix(TGeoNode* p, TGeoNode* n, TGeoHMatrix* mat, std::string* sub_path=0); + int findNodeWithMatrix(TGeoNode* p, TGeoNode* n, TGeoHMatrix* mat, std::string* sub_path=0); std::pair<bool,TEveElement*> - createEveShape(int level, int max_level, TEveElement* p, TGeoNode* n, TGeoHMatrix mat); + createEveShape(int level, int max_level, TEveElement* p, TGeoNode* n, TGeoHMatrix mat, const std::string& node_name); std::pair<bool,TEveElement*> LoadDetElement(Geometry::DetElement element,int levels, TEveElement* parent); diff --git a/DDEve/src/Display.cpp b/DDEve/src/Display.cpp index 924d847ed05151c1c08973be434a113d465577b0..25fde02c45b3a1e3e19dd100495e5d0def42a947 100644 --- a/DDEve/src/Display.cpp +++ b/DDEve/src/Display.cpp @@ -97,7 +97,7 @@ Display::CalodataContext& Display::CalodataContext::operator=(const CalodataCont /// Standard constructor Display::Display(TEveManager* eve) : m_eve(eve), m_lcdd(0), m_evtHandler(0), m_geoGlobal(0), m_eveGlobal(0), - m_viewMenu(0), m_dd4Menu(0), m_visLevel(7), m_loadLevel(3) + m_viewMenu(0), m_dd4Menu(0), m_visLevel(7), m_loadLevel(1) { TEveBrowser* br = m_eve->GetBrowser(); TGMenuBar* bar = br->GetMenuBar(); @@ -567,12 +567,29 @@ void Display::LoadGeoChildren(TEveElement* start, int levels, bool redraw) { printout(INFO,"Display","+++ Load children of %s to %d levels",Utilities::GetName(start),levels); if ( 0 != n ) { TGeoHMatrix mat; - Utilities::findNodeWithMatrix(lcdd().world().placement().ptr(),n,&mat); - pair<bool,TEveElement*> e = Utilities::createEveShape(0, levels, start, n, mat); - if ( e.first ) { // newly created - start->AddElement(e.second); + const char* node_name = n->GetName(); + int level = Utilities::findNodeWithMatrix(lcdd().world().placement().ptr(),n,&mat); + if ( level > 0 ) { + pair<bool,TEveElement*> e(false,0); + const DetElement::Children& c = world.children(); + for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) { + DetElement de = (*i).second; + if ( de.placement().ptr() == n ) { + e = Utilities::createEveShape(0, levels, start, n, mat, de.name()); + break; + } + } + if ( !e.first && !e.second ) { + e = Utilities::createEveShape(0, levels, start, n, mat, node_name); + } + if ( e.first ) { // newly created + start->AddElement(e.second); + } + printout(INFO,"Display","+++ Import geometry node %s with %d levels.",node_name, levels); + } + else { + printout(INFO,"Display","+++ FAILED to import geometry node %s with %d levels.",node_name, levels); } - printout(INFO,"Display","+++ Import geometry node %s with %d levels.",n->GetName(), levels); } else { LoadGeoChildren(0,levels,false); diff --git a/DDEve/src/EveUserContextMenu.cpp b/DDEve/src/EveUserContextMenu.cpp index e7359182be567b22dd8f95f411acc51747bddd39..a33d8ebe737923b1344cb3ca53cfa1333a76b9de 100644 --- a/DDEve/src/EveUserContextMenu.cpp +++ b/DDEve/src/EveUserContextMenu.cpp @@ -39,17 +39,20 @@ TEveManager& EveUserContextMenu::manager() const { /// Set everything (in-) visible void EveUserContextMenu::VisibleAll(bool visible, TObject* target, void* /* user_param */) { - m_display->MakeNodesVisible((TEveElement*)target,visible,9999); + TEveElement* element = dynamic_cast<TEveElement*>(target); + if ( element ) m_display->MakeNodesVisible(element,visible,9999); } /// Set self (in-) visible void EveUserContextMenu::VisibleSelf(bool visible, TObject* target, void* /* user_param */) { - m_display->MakeNodesVisible((TEveElement*)target,visible,0); + TEveElement* element = dynamic_cast<TEveElement*>(target); + if ( element ) m_display->MakeNodesVisible(element,visible,0); } /// Set the children (in-) visible void EveUserContextMenu::VisibleChildren(bool visible, TObject* target, void* /* user_param */) { - m_display->MakeNodesVisible((TEveElement*)target,visible,1); + TEveElement* element = dynamic_cast<TEveElement*>(target); + if ( element ) m_display->MakeNodesVisible(element,visible,1); } /// Show all @@ -84,12 +87,14 @@ void EveUserContextMenu::HideChildren(TObject* target, void* user_param) { /// Load next level children and add them to all scenes void EveUserContextMenu::LoadChildren(TObject* target, void* /* user_param */) { - m_display->LoadGeoChildren((TEveElement*)target, 1, true); + TEveElement* element = dynamic_cast<TEveElement*>(target); + if ( element ) m_display->LoadGeoChildren(element, 1, true); } /// Load all children and add them to all scenes void EveUserContextMenu::DeepLoadChildren(TObject* target, void* /* user_param */) { - m_display->LoadGeoChildren((TEveElement*)target, 9999, true); + TEveElement* element = dynamic_cast<TEveElement*>(target); + if ( element ) m_display->LoadGeoChildren(element, 9999, true); } /// Install the geometry context menu diff --git a/DDEve/src/Utilities.cpp b/DDEve/src/Utilities.cpp index 8fc6fd557bdaf21d62e8b294ad4478a631f79c2b..d69fe5ae65915733ad21ec0f275abf25608687cb 100644 --- a/DDEve/src/Utilities.cpp +++ b/DDEve/src/Utilities.cpp @@ -59,23 +59,32 @@ void Utilities::MakeNodesVisible(TEveElement* e, bool visible, int level) { } std::pair<bool,TEveElement*> -Utilities::createEveShape(int level, int max_level, TEveElement* p, TGeoNode* n, TGeoHMatrix mat) { +Utilities::createEveShape(int level, int max_level, TEveElement* p, TGeoNode* n, TGeoHMatrix mat, const std::string& nam) { TGeoVolume* vol = n ? n->GetVolume() : 0; bool created = false; - if ( 0 == vol || level >= max_level ) return make_pair(created,(TEveElement*)0); + if ( 0 == vol || level > max_level ) return make_pair(created,(TEveElement*)0); VisAttr vis(Volume(vol).visAttributes()); TGeoShape* geoShape = vol->GetShape(); TEveElement* element = 0; if ( p ) { - element = (TEveGeoShape*)p->FindChild(n->GetName()); + TGeoNode* pn = (TGeoNode*)p->GetUserData(); + if ( pn == n ) { + element = p; + } + if ( !element ) { + element = (TEveGeoShape*)p->FindChild(n->GetName()); + } + if ( !element && !nam.empty() ) { + element = (TEveGeoShape*)p->FindChild(nam.c_str()); + } if ( element ) goto Daughters; } if ( geoShape->IsA() == TGeoShapeAssembly::Class() ) { - //printout(INFO,"createEveShape","+++ SKIP assembly Shape %s.",n->GetName()); + //printout(INFO,"createEveShape","+++ Assembly Shape %s Userdata:%p.",n->GetName(),n); ElementList* shape = new ElementList(n->GetName(),n->GetName(),true,true); shape->SetUserData(n); shape->SetMainTransparency(true); @@ -92,15 +101,14 @@ Utilities::createEveShape(int level, int max_level, TEveElement* p, TGeoNode* n, } else if ( 0 == element ) { TEveGeoShape* shape = new TEveGeoShape(n->GetName()); - //printout(INFO,"createEveShape","+++ Create TEveGeoShape %s [%s].", - //n->GetName(),geoShape->IsA()->GetName()); + //printout(INFO,"createEveShape","+++ Create TEveGeoShape %s [%s] Userdata:%p.", + //n->GetName(),geoShape->IsA()->GetName(),n); created = true; if ( vis.isValid() ) { float r,g,b; vis.rgb(r,g,b); shape->SetMainColorRGB(r,g,b); } - shape->SetUserData(n); shape->SetMainTransparency(true); shape->SetMainAlpha(0.5); shape->SetPickable(kTRUE); @@ -118,15 +126,18 @@ Utilities::createEveShape(int level, int max_level, TEveElement* p, TGeoNode* n, shape->SetUserData(n); element = shape; } + else { + printout(INFO,"createEveShape","Weird!! %s",n->GetName()); + } Daughters: for (Int_t idau = 0, ndau = n->GetNdaughters(); idau < ndau; ++idau) { TGeoNode* daughter = n->GetDaughter(idau); - TGeoHMatrix dau_mat = mat; + TGeoHMatrix dau_mat(mat); TGeoMatrix* matrix = daughter->GetMatrix(); dau_mat.Multiply(matrix); pair<bool,TEveElement*> dau_shape = - createEveShape(level+1, max_level, element, daughter, dau_mat); + createEveShape(level+1, max_level, element, daughter, dau_mat, daughter->GetName()); if ( dau_shape.first ) { element->AddElement(dau_shape.second); } @@ -134,29 +145,30 @@ Utilities::createEveShape(int level, int max_level, TEveElement* p, TGeoNode* n, return make_pair(created,element); } -bool Utilities::findNodeWithMatrix(TGeoNode* p, TGeoNode* n, TGeoHMatrix* mat, string* sub_path) { - if ( p == n ) return true; +int Utilities::findNodeWithMatrix(TGeoNode* p, TGeoNode* n, TGeoHMatrix* mat, string* sub_path) { + if ( p == n ) return 1; + TGeoHMatrix dau_mat; for (Int_t idau = 0, ndau = p->GetNdaughters(); idau < ndau; ++idau) { string spath; TGeoNode* daughter = p->GetDaughter(idau); TGeoHMatrix* daughter_matrix = 0; if ( mat ) { - TGeoHMatrix dau_mat = *mat; - TGeoMatrix* matrix = daughter->GetMatrix(); + TGeoMatrix* matrix = daughter->GetMatrix(); + dau_mat = *mat; dau_mat.Multiply(matrix); daughter_matrix = &dau_mat; } - bool found = findNodeWithMatrix(daughter,n,daughter_matrix,sub_path ? &spath : 0); - if ( found ) { + int level = findNodeWithMatrix(daughter,n,daughter_matrix,sub_path ? &spath : 0); + if ( level>0 ) { if ( sub_path ) { *sub_path += "/"; *sub_path += spath; } if ( mat ) *mat = *daughter_matrix; - return true; + return level+1; } } - return false; + return 0; } std::pair<bool,TEveElement*> Utilities::LoadDetElement(Geometry::DetElement de,int levels, TEveElement* parent) { @@ -167,7 +179,7 @@ std::pair<bool,TEveElement*> Utilities::LoadDetElement(Geometry::DetElement de,i TGeoMatrix* matrix = n->GetMatrix(); gGeoManager = 0; gGeoManager = new TGeoManager(); - std::pair<bool,TEveElement*> e = createEveShape(0, levels, parent, n, *matrix); + std::pair<bool,TEveElement*> e = createEveShape(0, levels, parent, n, *matrix, de.name()); TEveElementList* list = dynamic_cast<TEveElementList*>(e.second); if ( list ) { list->SetName(de.name()); diff --git a/DDG4/examples/CLICSidSimu.py b/DDG4/examples/CLICSidSimu.py index 8e86f15871a1100b0b2499fa3e66babeded822de..712bb471db99b6293aa69f35a5de935441aa2499 100644 --- a/DDG4/examples/CLICSidSimu.py +++ b/DDG4/examples/CLICSidSimu.py @@ -16,7 +16,6 @@ from SystemOfUnits import * def run(): install_dir = os.environ['DD4hepINSTALL'] example_dir = install_dir+'/examples/DDG4/examples'; - DDG4.setPrintLevel(Output.DEBUG) kernel = DDG4.Kernel() kernel.UI = "UI" kernel.loadGeometry("file:"+install_dir+"/examples/CLICSiD/compact/compact.xml") @@ -125,20 +124,20 @@ def run(): act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiVertexBarrelHandler','SiVertexBarrel') seq.add(act) seq.add(f1) - seq.add(f4) + #seq.add(f4) act.add(f1) seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiVertexEndcap') act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiVertexEndcapHandler','SiVertexEndcap') seq.add(act) seq.add(f1) - seq.add(f4) + #seq.add(f4) seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerBarrel') act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerBarrelHandler','SiTrackerBarrel') seq.add(act) seq.add(f1) - seq.add(f4) + #seq.add(f4) seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerEndcap') act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerEndcapHandler','SiTrackerEndcap') @@ -211,6 +210,7 @@ def run(): kernel.configure() kernel.initialize() + #DDG4.setPrintLevel(Output.DEBUG) kernel.run() kernel.terminate() diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp index aafb4299869363a25fa18c3568ba467ec9de6be9..63a1425ac2cd16b027f984ee90f80aa0e47bdeb2 100644 --- a/DDG4/plugins/Geant4SDActions.cpp +++ b/DDG4/plugins/Geant4SDActions.cpp @@ -131,6 +131,7 @@ namespace DD4hep { Position direction = postPos - prePos; Position position = mean_direction(prePos,postPos); double hit_len = direction.R(); + if (hit_len > 0) { double new_len = mean_length(h.preMom(),h.postMom())/hit_len; direction *= new_len/hit_len; diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index 6d67a3b518e66988eac0acd7aad1438df1d76414..f403d3c512a4f5fae3f6ce0c2c811177fdf333b9 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -534,8 +534,8 @@ void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume "access Geant4 region."); } } - - printout(m_outputLevel, "Geant4Converter", "++ Convert Volume %-32s: %p %s/%s assembly:%s sensitive:%s", n.c_str(), v, + PrintLevel lvl = m_outputLevel; //string(det.name())=="SiTrackerBarrel" ? WARNING : m_outputLevel; + printout(lvl, "Geant4Converter", "++ Convert Volume %-32s: %p %s/%s assembly:%s sensitive:%s", n.c_str(), v, s->IsA()->GetName(), v->IsA()->GetName(), yes_no(assembly), yes_no(det.isValid())); if (assembly) { diff --git a/DDG4/src/Geant4TestActions.cpp b/DDG4/src/Geant4TestActions.cpp index 87dd0200c9862e7b2b67a2d9b02e7938fdd52bb2..dae7a52e51a652cbdf071375d6600b1a30e24825 100644 --- a/DDG4/src/Geant4TestActions.cpp +++ b/DDG4/src/Geant4TestActions.cpp @@ -32,7 +32,7 @@ namespace { }; } -#define PRINT info +#define PRINT print /// Standard constructor diff --git a/examples/CLICSiD/eve/CLICSiD_Events.root b/examples/CLICSiD/eve/CLICSiD_Events.root index 05d67470318af1197e7672af9b2c04e99eb03a92..cc3644720ecced0290d1086f685502e7438b0809 100644 Binary files a/examples/CLICSiD/eve/CLICSiD_Events.root and b/examples/CLICSiD/eve/CLICSiD_Events.root differ diff --git a/examples/CLICSiD/eve/DDEve.xml b/examples/CLICSiD/eve/DDEve.xml index 1e5483e1ead683b99bf97e21abdd9915cfb85770..79f6887f5fecfdd833935bf0c2b000a28af76666 100644 --- a/examples/CLICSiD/eve/DDEve.xml +++ b/examples/CLICSiD/eve/DDEve.xml @@ -1,5 +1,5 @@ <ddeve> - <display visLevel="7" loadLevel="2"/> + <display visLevel="7" loadLevel="1"/> <calodata name="Ecal" hits="EcalBarrelHits" towerH="100" emax="20" n_eta="200" eta_min="-5" eta_max="5" n_phi="200" phi_min="-pi" phi_max="pi" @@ -36,8 +36,8 @@ <detelement name="SiTrackerBarrel" load_geo="-1" show="4" alpha="0.5"/> </view> <view name="3D Trackers R-Phi (Local)" type="RhoPhiProjection" structure="false" sensitive="true"> - <detelement name="SiVertexBarrel" load_geo="4" show="4" alpha="0.5"/> - <detelement name="SiTrackerBarrel" load_geo="4" show="4" alpha="0.5"/> + <detelement name="SiVertexBarrel" load_geo="3" show="4" alpha="0.5"/> + <detelement name="SiTrackerBarrel" load_geo="3" show="4" alpha="0.5"/> </view> <!-- <detelement name="SiTrackerEndcap" load_geo="-1" show="2" alpha="0.5"/> @@ -53,16 +53,16 @@ <detelement name="SiTrackerForward" load_geo="-1" show="2" alpha="0.5"/> </view> <view name="3D Vertex" type="View3D" structure="false" sensitive="true"> - <detelement name="SiVertexBarrel" load_geo="2" show="2" alpha="0.5"/> - <detelement name="SiVertexEndcap" load_geo="2" show="2" alpha="0.5"/> + <detelement name="SiVertexBarrel" load_geo="1" show="2" alpha="0.5"/> + <detelement name="SiVertexEndcap" load_geo="1" show="2" alpha="0.5"/> </view> <view name="3D Calorimeters" type="View3D" show="2" load_geo="2" structure="false" sensitive="true"> - <detelement name="EcalBarrel" load_geo="3" show="0" alpha="0.5"/> - <detelement name="EcalEndcap" load_geo="3" show="0" alpha="0.5"/> - <detelement name="HcalPlug" load_geo="3" show="0" alpha="0.5"/> - <detelement name="HcalBarrel" load_geo="3" show="0" alpha="0.5"/> - <detelement name="HcalEndcap" load_geo="3" show="0" alpha="0.5"/> + <detelement name="EcalBarrel" load_geo="2" show="0" alpha="0.5"/> + <detelement name="EcalEndcap" load_geo="2" show="0" alpha="0.5"/> + <detelement name="HcalPlug" load_geo="2" show="0" alpha="0.5"/> + <detelement name="HcalBarrel" load_geo="2" show="0" alpha="0.5"/> + <detelement name="HcalEndcap" load_geo="2" show="0" alpha="0.5"/> <!-- <detelement name="MuonBarrel" load_geo="1" show="0" alpha="0.5"/> <detelement name="MuonEndcap" load_geo="1" show="0" alpha="0.5"/>