From ad3a754d34f345dac5bade28f30401c2295799ba Mon Sep 17 00:00:00 2001 From: Markus FRANK <Markus.Frank@cern.ch> Date: Fri, 13 Nov 2020 11:39:12 +0100 Subject: [PATCH] Improve examples DDCMS and DDG4_MySensDet --- DDCore/include/DD4hep/detail/ObjectsInterna.h | 6 +- DDCore/src/Objects.cpp | 44 +++-- DDCore/src/ObjectsInterna.cpp | 2 - DDCore/src/VolumeProcessor.cpp | 4 +- DDCore/src/Volumes.cpp | 62 ++----- DDCore/src/plugins/VisVolNameProcessor.cpp | 65 +++++-- examples/DDCMS/data/cms_csc.xml | 41 +---- examples/DDCMS/data/cms_ecal.xml | 39 ----- examples/DDCMS/data/cms_tracker.xml | 36 +--- examples/DDCMS/data/csc.xml | 2 +- examples/DDCMS/data/dd4hep-config.xml | 6 + examples/DDCMS/data/dd4hep-csc.xml | 95 ++++++++++ examples/DDCMS/data/dd4hep-ecal.xml | 162 ++++-------------- examples/DDCMS/data/ecal-vis.xml | 50 ------ examples/DDCMS/data/world-close.xml | 4 + examples/DDCMS/data/world-open.xml | 41 +++++ examples/DDCMS/include/DDCMS/DDCMSTags.h | 8 +- examples/DDCMS/src/DDCMS.cpp | 13 +- .../src/plugins/DDDefinitions2Objects.cpp | 124 +++++++++++++- examples/DDG4_MySensDet/src/MyTrackerHit.cpp | 33 +--- examples/DDG4_MySensDet/src/MyTrackerHit.h | 46 +++-- .../DDG4_MySensDet/src/MyTrackerSDAction.cpp | 3 + examples/DDG4_MySensDet/src/dumpData.cpp | 83 +++++++++ 23 files changed, 528 insertions(+), 441 deletions(-) create mode 100644 examples/DDCMS/data/dd4hep-csc.xml delete mode 100644 examples/DDCMS/data/ecal-vis.xml create mode 100644 examples/DDCMS/data/world-close.xml create mode 100644 examples/DDCMS/data/world-open.xml create mode 100644 examples/DDG4_MySensDet/src/dumpData.cpp diff --git a/DDCore/include/DD4hep/detail/ObjectsInterna.h b/DDCore/include/DD4hep/detail/ObjectsInterna.h index 143dbbbf0..cef152fc6 100644 --- a/DDCore/include/DD4hep/detail/ObjectsInterna.h +++ b/DDCore/include/DD4hep/detail/ObjectsInterna.h @@ -88,9 +88,9 @@ namespace dd4hep { class VisAttrObject: public NamedObject { public: unsigned long magic; - TColor* col = nullptr; - int color = 0; - float alpha = 0; + TColor* color = nullptr; + TColor* colortr = nullptr; + float alpha = 0; unsigned char drawingStyle = VisAttr::SOLID; unsigned char lineStyle = VisAttr::SOLID; unsigned char showDaughters = true; diff --git a/DDCore/src/Objects.cpp b/DDCore/src/Objects.cpp index 3f9ed6b6e..17d60b0f4 100644 --- a/DDCore/src/Objects.cpp +++ b/DDCore/src/Objects.cpp @@ -285,7 +285,7 @@ string Material::toString() const { VisAttr::VisAttr(const string& nam) { Object* obj = new Object(); assign(obj, nam, "vis"); - obj->color = 2; + obj->color = gROOT->GetColor(kWhite); obj->alpha = 0.9f; setLineStyle (SOLID); setDrawingStyle(SOLID); @@ -296,7 +296,7 @@ VisAttr::VisAttr(const string& nam) { VisAttr::VisAttr(const char* nam) { Object* obj = new Object(); assign(obj, nam, "vis"); - obj->color = 2; + obj->color = gROOT->GetColor(kWhite); obj->alpha = 0.9f; setLineStyle (SOLID); setDrawingStyle(SOLID); @@ -345,32 +345,38 @@ void VisAttr::setDrawingStyle(int value) { /// Get alpha value float VisAttr::alpha() const { - Object& o = object<Object>(); - if ( o.col ) { - return o.alpha; - } - return 0.0f; + return object<Object>().alpha; } /// Get object color int VisAttr::color() const { - return object<Object>().color; + return object<Object>().color->GetNumber(); } /// Set object color void VisAttr::setColor(float alpha, float red, float green, float blue) { - Object& o = object<Object>(); - Int_t col = TColor::GetColor(red, green, blue); - o.alpha = alpha; - o.color = col;//TColor::GetColorTransparent(o.alpha=alpha, col); - o.col = gROOT->GetColor(o.color); + Object& o = object<Object>(); + Int_t col = TColor::GetColor(red, green, blue); + o.alpha = alpha; + o.color = gROOT->GetColor(col); + if ( !o.color ) { + except("VisAttr","+++ %s Failed to allocate Color: r:%02X g:%02X b:%02X", + this->name(), int(red*255.), int(green*255.), int(blue*255)); + } +#if ROOT_VERSION_CODE >= ROOT_VERSION(5,34,25) + o.colortr = new TColor(gROOT->GetListOfColors()->GetLast()+1, + o.color->GetRed(), o.color->GetGreen(), o.color->GetBlue()); + o.colortr->SetAlpha(alpha); +#else + o.colortr = o.color; +#endif } /// Get RGB values of the color (if valid) bool VisAttr::rgb(float& red, float& green, float& blue) const { Object& o = object<Object>(); - if ( o.col ) { - o.col->GetRGB(red, green, blue); + if ( o.color ) { + o.color->GetRGB(red, green, blue); return true; } return false; @@ -379,9 +385,9 @@ bool VisAttr::rgb(float& red, float& green, float& blue) const { /// Get alpha and RGB values of the color (if valid) bool VisAttr::argb(float& alpha, float& red, float& green, float& blue) const { Object& o = object<Object>(); - if ( o.col ) { + if ( o.color ) { alpha = o.alpha; - o.col->GetRGB(red, green, blue); + o.color->GetRGB(red, green, blue); return true; } return false; @@ -390,10 +396,10 @@ bool VisAttr::argb(float& alpha, float& red, float& green, float& blue) const { /// String representation of this object string VisAttr::toString() const { const VisAttr::Object* obj = &object<Object>(); - TColor* col = obj->col; + TColor* c = obj->color; char text[256]; ::snprintf(text, sizeof(text), "%-20s RGB:%-8s [%d] %7.2f Style:%d %d ShowDaughters:%3s Visible:%3s", ptr()->GetName(), - col->AsHexString(), obj->color, col->GetAlpha(), int(obj->drawingStyle), int(obj->lineStyle), + c->AsHexString(), c->GetNumber(), c->GetAlpha(), int(obj->drawingStyle), int(obj->lineStyle), yes_no(obj->showDaughters), yes_no(obj->visible)); return text; } diff --git a/DDCore/src/ObjectsInterna.cpp b/DDCore/src/ObjectsInterna.cpp index 4b2766751..76e788bf2 100644 --- a/DDCore/src/ObjectsInterna.cpp +++ b/DDCore/src/ObjectsInterna.cpp @@ -27,8 +27,6 @@ DD4HEP_INSTANTIATE_HANDLE_NAMED(VisAttrObject); /// Standard constructor VisAttrObject::VisAttrObject() : magic(magic_word()) { InstanceCount::increment(this); - this->col = gROOT->GetColor(kWhite); - this->alpha = 0.0; } /// Default destructor diff --git a/DDCore/src/VolumeProcessor.cpp b/DDCore/src/VolumeProcessor.cpp index 86a10a963..a5819bd5c 100644 --- a/DDCore/src/VolumeProcessor.cpp +++ b/DDCore/src/VolumeProcessor.cpp @@ -29,9 +29,9 @@ int PlacedVolumeProcessor::process(PlacedVolume pv, int level, bool recursive) if ( recursive ) { for (Int_t idau = 0, ndau = node->GetNdaughters(); idau < ndau; ++idau) { PlacedVolume placement(node->GetDaughter(idau)); - if ( placement.data() ) { + //if ( placement.data() ) { ret += process(placement,level+1,recursive); - } + //} } } return ret; diff --git a/DDCore/src/Volumes.cpp b/DDCore/src/Volumes.cpp index 0bfeaf13d..31ac55580 100644 --- a/DDCore/src/Volumes.cpp +++ b/DDCore/src/Volumes.cpp @@ -815,37 +815,29 @@ Material Volume::material() const { const Volume& Volume::setVisAttributes(const VisAttr& attr) const { if ( attr.isValid() ) { VisAttr::Object* vis = attr.data<VisAttr::Object>(); - Color_t bright = vis->color;//kBlue;//TColor::GetColorBright(vis->color); - Color_t dark = vis->color;//kRed;//TColor::GetColorDark(vis->color); - TColor* c = vis->col;//gROOT->GetColor(dark); + TColor* c = vis->color; int draw_style = vis->drawingStyle; int line_style = vis->lineStyle; - + int col_num = c->GetNumber(); + int col_tr_num = vis->colortr->GetNumber(); m_element->SetVisibility(vis->visible ? kTRUE : kFALSE); m_element->SetVisContainers(kTRUE); m_element->SetVisDaughters(vis->showDaughters ? kTRUE : kFALSE); printout(DEBUG,"setVisAttributes", - "Set color %3d [%02X,%02X,%02X] DrawingStyle:%9s LineStyle:%6s for volume %s", - int(vis->color), - c ? int(255*c->GetRed()) : 0xFF, + "Set color %3d transparent(alpha:%.3f): %3d [%02X,%02X,%02X] DrawingStyle:%9s LineStyle:%6s for volume %s", + col_num, vis->alpha, col_tr_num, + c ? int(255*c->GetRed()) : 0xFF, c ? int(255*c->GetGreen()) : 0xFF, - c ? int(255*c->GetBlue()) : 0xFF, + c ? int(255*c->GetBlue()) : 0xFF, draw_style == VisAttr::SOLID ? "Solid" : "Wireframe", line_style == VisAttr::SOLID ? "Solid" : "Dashed", name() ); m_element->SetLineWidth(10); - m_element->SetLineColor(dark); + m_element->SetLineColor(col_num); + m_element->SetFillColor(col_tr_num); if (draw_style == VisAttr::SOLID) { - m_element->SetLineColor(bright); -#if ROOT_VERSION_CODE >= ROOT_VERSION(5,34,25) - m_element->SetFillColorAlpha(bright,vis->alpha); -#else - m_element->SetFillColor(bright); -#endif m_element->SetFillStyle(1001); // Root: solid - // Suggested by Nikiforos. Not optimal. - //m_element->GetMedium()->GetMaterial()->SetTransparency((1-vis->alpha)*100); #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0) // As suggested by Valentin Volkl https://sft.its.cern.ch/jira/browse/DDFORHEP-20 @@ -854,7 +846,7 @@ const Volume& Volume::setVisAttributes(const VisAttr& attr) const { // a transparency>50 will make a volume invisible in the normal pad. // Hence: possibly restrict transparency to a maximum of 50. // but let's see first how this behaves. - m_element->SetTransparency((1-vis->alpha)*100); + m_element->SetTransparency((1.0-vis->alpha)*100); #endif } else { @@ -869,24 +861,6 @@ const Volume& Volume::setVisAttributes(const VisAttr& attr) const { m_element->SetLineStyle(2); else m_element->SetLineStyle(line_style); - - - /* - m_element->SetVisibility(kTRUE); - m_element->SetAttBit(TGeoAtt::kVisContainers, kTRUE); - m_element->SetVisDaughters(kTRUE); - printout(INFO,"setVisAttributes","Set Line color for volume %s",name()); - m_element->SetLineColor(bright); - m_element->SetFillColor(bright); - m_element->SetFillStyle(1001); // Root: solid - if (line_style == VisAttr::SOLID) - m_element->SetFillStyle(1); - else if (line_style == VisAttr::DASHED) - m_element->SetFillStyle(2); - else - m_element->SetFillStyle(line_style); - m_element->SetLineWidth(10); - */ } Volume::Object* o = _userExtension(*this); if ( o ) o->vis = attr; @@ -899,19 +873,6 @@ const Volume& Volume::setVisAttributes(const Detector& description, const string VisAttr attr = description.visAttributes(nam); setVisAttributes(attr); } - else { - /* - string tag = this->name(); - if ( ::strstr(tag.c_str(),"_slice") ) // Slices turned off by default - setVisAttributes(description.visAttributes("InvisibleNoDaughters")); - else if ( ::strstr(tag.c_str(),"_layer") ) // Layers turned off, but daughters possibly visible - setVisAttributes(description.visAttributes("InvisibleWithDaughters")); - else if ( ::strstr(tag.c_str(),"_module") ) // Tracker modules similar to layers - setVisAttributes(description.visAttributes("InvisibleWithDaughters")); - else if ( ::strstr(tag.c_str(),"_module_component") ) // Tracker modules similar to layers - setVisAttributes(description.visAttributes("InvisibleNoDaughters")); - */ - } return *this; } @@ -928,8 +889,7 @@ const Volume& Volume::setAttributes(const Detector& description, const string& r /// Access the visualisation attributes VisAttr Volume::visAttributes() const { Object* o = _data(*this, false); - if (o) - return o->vis; + if (o) return o->vis; return VisAttr(); } diff --git a/DDCore/src/plugins/VisVolNameProcessor.cpp b/DDCore/src/plugins/VisVolNameProcessor.cpp index e1e9bff14..89a0e2020 100644 --- a/DDCore/src/plugins/VisVolNameProcessor.cpp +++ b/DDCore/src/plugins/VisVolNameProcessor.cpp @@ -15,9 +15,12 @@ // Framework include files #include <DD4hep/VolumeProcessor.h> + // C/C++ include files -#include <vector> +#include <map> +#include <regex> +/// Namespace for the AIDA detector description toolkit namespace dd4hep { /// DD4hep DetElement creator for the CMS geometry. @@ -29,7 +32,9 @@ namespace dd4hep { */ class VisVolNameProcessor : public PlacedVolumeProcessor { public: + typedef std::map<std::string,std::regex> Matches; Detector& description; + Matches matches; std::string name; size_t numApplied = 0; bool show = false; @@ -41,6 +46,8 @@ namespace dd4hep { VisVolNameProcessor(Detector& desc); /// Default destructor virtual ~VisVolNameProcessor(); + /// Set volume matches + void set_match(const std::vector<std::string>& matches); /// Callback to output PlacedVolume information of an single Placement virtual int operator()(PlacedVolume pv, int level); }; @@ -72,39 +79,64 @@ using namespace dd4hep; /// Initializing constructor VisVolNameProcessor::VisVolNameProcessor(Detector& desc) - : description(desc), name("VisVolNameProcessor") + : description(desc), name() { } /// Default destructor VisVolNameProcessor::~VisVolNameProcessor() { if ( show ) { - printout(ALWAYS,name,"++ %8ld vis-attrs applied.", numApplied); + printout(ALWAYS,name,"++ %8ld vis-attrs '%s' applied.", + numApplied, visattr.isValid() ? visattr.name() : ""); } } +/// Set volume matches +void VisVolNameProcessor::set_match(const std::vector<std::string>& vals) { + for( const auto& v : vals ) + matches[v] = regex(v); +} + /// Callback to output PlacedVolume information of an single Placement int VisVolNameProcessor::operator()(PlacedVolume pv, int /* level */) { - Volume vol = pv.volume(); - if ( vol.visAttributes().ptr() != visattr.ptr() && name == vol.name() ) { - vol.setVisAttributes(visattr); - ++numApplied; + Volume vol = pv.volume(); + if ( vol.visAttributes().ptr() != visattr.ptr() ) { + string vol_nam = vol.name(); + for ( const auto& m : matches ) { + if ( std::regex_match(vol_nam, m.second) ) { + printout(ALWAYS,m.first,"++ Set visattr %s to %s", + visattr.isValid() ? visattr.name() : "", vol_nam.c_str()); + vol.setVisAttributes(visattr); + ++numApplied; + return 1; + } + //printout(ALWAYS,m.first,"++ FAILED %s",vol_nam.c_str()); + } } return 1; } static void* create_object(Detector& description, int argc, char** argv) { + string vis_name; + vector<string> vol_names; DetectorHelper helper(description); VisVolNameProcessor* proc = new VisVolNameProcessor(description); for ( int i=0; i<argc; ++i ) { if ( argv[i] ) { if ( ::strncmp(argv[i],"-name",4) == 0 ) { - string name = argv[++i]; - proc->name = name; - proc->visattr = description.visAttributes(name); - if ( !proc->visattr.ptr() ) { - except(name,"+++ Unknown visual attribute: %s",name.c_str()); - } + proc->name = argv[++i]; + vol_names.push_back(proc->name); + if ( vis_name.empty() ) vis_name = proc->name; + continue; + } + else if ( ::strncmp(argv[i],"-match",4) == 0 ) { + vol_names.push_back(argv[++i]); + if ( vis_name.empty() ) vis_name = vol_names.back(); + if ( proc->name.empty() ) proc->name = vol_names.back(); + continue; + } + else if ( ::strncmp(argv[i],"-vis",4) == 0 ) { + vis_name = argv[++i]; continue; } else if ( ::strncmp(argv[i],"-show",4) == 0 ) { @@ -113,12 +145,17 @@ static void* create_object(Detector& description, int argc, char** argv) { } cout << "Usage: DD4hep_VisVolNameProcessor -arg [-arg] \n" - " -min-density <number> Minimal density to show the volume. \n" + " -match <regex> Regular expression matching volume name \n" " -show Print setup to output device (stdout) \n" "\tArguments given: " << arguments(argc,argv) << endl << flush; ::exit(EINVAL); } } + proc->set_match(vol_names); + proc->visattr = description.visAttributes(vis_name); + if ( !proc->visattr.ptr() ) { + except(proc->name,"+++ Unknown visual attribute: %s",vis_name.c_str()); + } PlacedVolumeProcessor* placement_proc = proc; return (void*)placement_proc; } diff --git a/examples/DDCMS/data/cms_csc.xml b/examples/DDCMS/data/cms_csc.xml index 1eb3d2d69..463890b02 100644 --- a/examples/DDCMS/data/cms_csc.xml +++ b/examples/DDCMS/data/cms_csc.xml @@ -1,50 +1,21 @@ <?xml version="1.0"?> <DDDefinition> - - <debug> - </debug> - - - <open_geometry/> - <close_geometry/> - - - <ConstantsSection label="" eval="true"> - <Constant name="world_x" value="5*m"/> - <Constant name="world_y" value="5*m"/> - <Constant name="world_z" value="5*m"/> - <Constant name="fm" value="1e-12*m"/> - <Constant name="Air" value="materials:Air" type="string"/> - <Constant name="Vacuum" value="materials:Vacuum" type="string"/> - </ConstantsSection> - <ConstantsSection label="servicescylinderb.xml" eval="true"> - <Constant name="zero" value="0.0*fm"/> - </ConstantsSection> - <ConstantsSection label="servicescylinderf.xml" eval="true"> - <Constant name="zero" value="0.0*fm"/> - </ConstantsSection> - - <IncludeSection> - <Include ref="materials.xml"/> - <Include ref="rotations.xml"/> - - <Include ref="cms.xml"/> <Include ref="cmsextent.xml"/> <Include ref="cavernData.xml"/> - + <Include ref="cms.xml"/> <Include ref='muonBase.xml'/> <Include ref='mf.xml'/> <Include ref='csc.xml'/> </IncludeSection> - <PosPartSection label=""> + <PosPartSection label=""> <PosPart copyNumber="1"> - <!--<rParent name="world_volume"/>--> - <rParent name="cms:OCMS"/> - <rChild name="muonBase:MUON"/> - </PosPart> + <!--<rParent name="world_volume"/>--> + <rParent name="world_volume"/> + <rChild name="muonBase:MUON"/> + </PosPart> </PosPartSection> diff --git a/examples/DDCMS/data/cms_ecal.xml b/examples/DDCMS/data/cms_ecal.xml index e67ab19c8..c1c0554e8 100644 --- a/examples/DDCMS/data/cms_ecal.xml +++ b/examples/DDCMS/data/cms_ecal.xml @@ -1,45 +1,6 @@ <?xml version="1.0"?> <DDDefinition> - <debug> -<!-- - <debug_placements/> - <debug_rotations/> - <debug_includes/> - <debug_materials/> - - <debug_shapes/> - <debug_volumes/> - <debug_namespaces/> - <debug_visattr/> - <debug_constants/> - <debug_algorithms/> ---> - </debug> - - <open_geometry/> -<!-- - <close_geometry/> ---> - - <ConstantsSection label="" eval="true"> - <Constant name="world_x" value="5*m"/> - <Constant name="world_y" value="5*m"/> - <Constant name="world_z" value="5*m"/> - <Constant name="fm" value="1e-12*m"/> - <Constant name="Air" value="materials:Air" type="string"/> - <Constant name="Vacuum" value="materials:Vacuum" type="string"/> - </ConstantsSection> - <ConstantsSection label="servicescylinderb.xml" eval="true"> - <Constant name="zero" value="0.0*fm"/> - </ConstantsSection> - <ConstantsSection label="servicescylinderf.xml" eval="true"> - <Constant name="zero" value="0.0*fm"/> - </ConstantsSection> - <IncludeSection> - <Include ref="materials.xml"/> - <Include ref="rotations.xml"/> - <Include ref="trackermaterial.xml"/> <Include ref="ecalmaterial.xml"/> <Include ref="caloBase.xml"/> <Include ref="eecon.xml"/> diff --git a/examples/DDCMS/data/cms_tracker.xml b/examples/DDCMS/data/cms_tracker.xml index 8ef370641..d4fed8f56 100644 --- a/examples/DDCMS/data/cms_tracker.xml +++ b/examples/DDCMS/data/cms_tracker.xml @@ -1,38 +1,5 @@ <?xml version="1.0"?> <DDDefinition> - <debug> -<!-- - <debug_rotations/> - <debug_materials/> - - <debug_shapes/> - <debug_volumes/> - <debug_includes/> - <debug_namespaces/> - <debug_placements/> - <debug_visattr/> - <debug_algorithms/> - <debug_constants/> ---> - </debug> - <open_geometry/> - <close_geometry/> - - <ConstantsSection label="" eval="true"> - <Constant name="world_x" value="5*m"/> - <Constant name="world_y" value="5*m"/> - <Constant name="world_z" value="5*m"/> - <Constant name="fm" value="1e-12*m"/> - <Constant name="Air" value="materials:Air" type="string"/> - <Constant name="Vacuum" value="materials:Vacuum" type="string"/> - </ConstantsSection> - <ConstantsSection label="servicescylinderb.xml" eval="true"> - <Constant name="zero" value="0.0*fm"/> - </ConstantsSection> - <ConstantsSection label="servicescylinderf.xml" eval="true"> - <Constant name="zero" value="0.0*fm"/> - </ConstantsSection> - <DisabledAlgo name="track:DDTOBRadCableAlgo"/> <ConstantsSection label="pixfwd" eval="true"> <Constant name="AnchorZ" value="0.*mm"/> @@ -43,11 +10,10 @@ </ConstantsSection> <IncludeSection> - <Include ref="materials.xml"/> + <Include ref="trackermaterial.xml"/> <Include ref="tibtidcommonmaterial.xml"/> - <Include ref="vacuum.xml"/> <Include ref="cmsextent.xml"/> <Include ref="cavernData.xml"/> <Include ref="cms.xml"/> diff --git a/examples/DDCMS/data/csc.xml b/examples/DDCMS/data/csc.xml index 00b7f2f08..f9835dd42 100644 --- a/examples/DDCMS/data/csc.xml +++ b/examples/DDCMS/data/csc.xml @@ -1,7 +1,7 @@ <?xml version="1.0"?> <DDDefinition xmlns="http://www.cern.ch/cms/DDL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cern.ch/cms/DDL ../../../../DetectorDescription/Schema/DDLSchema.xsd"> <!--22/10/2020, Sergio Lo Meo (sergio.lo.meo@cern.ch) : fixed overlaps and deleted subtraction solids --> - <ConstantsSection label="ChamberSpecsConstants" eval="true"> + <ConstantsSection label="csc.xml" eval="true"> <Constant name="ME11GasGap" value="7.0*mm"/> <Constant name="ME11LayerOffset" value="-17.0014*mm"/> <Constant name="ME11LayerSpacing" value="2.2*cm"/> diff --git a/examples/DDCMS/data/dd4hep-config.xml b/examples/DDCMS/data/dd4hep-config.xml index 4d46c9ca8..1d4b494f9 100644 --- a/examples/DDCMS/data/dd4hep-config.xml +++ b/examples/DDCMS/data/dd4hep-config.xml @@ -105,6 +105,9 @@ <vis name="vis-invisible-daughters" alpha="1.0" r="0.1" g="0.1" b="0.8" showDaughters="true" visible="false"/> </display> + <plugin name="DD4hep_XMLLoader"> + <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/world-open.xml"/> + </plugin> <plugin name="DD4hep_XMLLoader"> <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/cms_tracker.xml"/> </plugin> @@ -340,4 +343,7 @@ <arg value="-volids"/> </plugin> --> + <plugin name="DD4hep_XMLLoader"> + <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/world-close.xml"/> + </plugin> </plugins> diff --git a/examples/DDCMS/data/dd4hep-csc.xml b/examples/DDCMS/data/dd4hep-csc.xml new file mode 100644 index 000000000..4246dafd3 --- /dev/null +++ b/examples/DDCMS/data/dd4hep-csc.xml @@ -0,0 +1,95 @@ +<plugins> +<!-- + + # Configuration file top load the CMS geometry + + This XML script extends the raw geometry defintiion from CMS (see cms_tracker.xml for details). + * We load the primary geometry entities and instantiate them. + Note: TEC, and PixbarFWD do not work and cannot be converted; + * Here the DetElement structure and the readout structures are defined to run Geant4 + Note: TEC, and PixbarFWD do not work and cannot be used for Geant4. To be investigated. + * Here we also define the visualization attributes to get nicer pictures. + + M.Frank CERN EP/LBC October 2017 + +--> + + <display> + <vis name="vis-invisible-daughters" alpha="0.3" r="0.1" g="0.1" b="0.8" showDaughters="true" visible="false"/> + <vis name="csc:MELayer" alpha="0.3" r="0.3" g="0.3" b="1.0" showDaughters="true" visible="true"/> + <vis name="csc:MESpaceDiv" alpha="0.5" r="0.5" g="1.0" b="0.5" showDaughters="true" visible="true"/> + <vis name="csc:MESpace" alpha="0.5" r="1.0" g="0.3" b="0.3" showDaughters="true" visible="true"/> + <vis name="csc:ME" alpha="0.9" r="0.3" g="0.3" b="1.0" showDaughters="true" visible="true"/> + <vis name="muon:MUON" alpha="0.3" r="0.7" g="0.7" b="0.7" showDaughters="true" visible="true"/> + </display> + + <plugin name="DD4hep_XMLLoader"> + <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/world-open.xml"/> + </plugin> + <plugin name="DD4hep_XMLLoader"> + <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/cms_csc.xml"/> + </plugin> + + <!-- + <plugin name="DD4hep_VolumeDump"> + <arg value="-materials"/> + <arg value="-vis"/> + </plugin> + --> + + <plugin name="DD4hep_PlacedVolumeProcessor"> + <arg value="-recursive"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="csc:MESpace"/> + <arg value="-match"/> <arg value="csc:ME..Space"/> + <arg value="-show"/> + </plugin> + + <plugin name="DD4hep_PlacedVolumeProcessor"> + <arg value="-recursive"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="csc:MESpaceDiv"/> + <arg value="-match"/> <arg value="csc:ME..SpaceDivi.(.*)"/> + <arg value="-show"/> + </plugin> + + <plugin name="DD4hep_PlacedVolumeProcessor"> + <arg value="-recursive"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="csc:ME"/> + <arg value="-match"/> <arg value="csc:ME.."/> + <arg value="-show"/> + </plugin> + + <plugin name="DD4hep_PlacedVolumeProcessor"> + <arg value="-recursive"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="muon:MUON"/> + <arg value="-match"/> <arg value="muonBase:MUON"/> + <arg value="-show"/> + </plugin> + + <plugin name="DD4hep_PlacedVolumeProcessor"> + <arg value="-recursive"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="csc:MELayer"/> + <arg value="-match"/> <arg value="csc:ME..Layer"/> + <arg value="-show"/> + </plugin> + + <plugin name="DD4hep_PlacedVolumeProcessor"> + <arg value="-recursive"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-match"/> <arg value="mf:MEP"/> + <arg value="-match"/> <arg value="mf:MEN"/> + <arg value="-match"/> <arg value="mf:ME.Ring."/> + <arg value="-match"/> <arg value="mf:ME..Ring."/> + <arg value="-match"/> <arg value="mf:RR.."/> + <arg value="-vis"/> <arg value="vis-invisible-daughters"/> + <arg value="-show"/> + </plugin> + + <plugin name="DD4hep_XMLLoader"> + <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/world-close.xml"/> + </plugin> +</plugins> diff --git a/examples/DDCMS/data/dd4hep-ecal.xml b/examples/DDCMS/data/dd4hep-ecal.xml index 55a3d7817..947fbb0f6 100644 --- a/examples/DDCMS/data/dd4hep-ecal.xml +++ b/examples/DDCMS/data/dd4hep-ecal.xml @@ -15,162 +15,64 @@ --> <display> - - <vis name="solid-light-grey" alpha="0.5" r="0.5" g="0.5" b="0.5" showDaughters="true" visible="false"/> - <vis name="solid-verylight-grey" alpha="0.6" r="0.5" g="0.5" b="0.5" showDaughters="true" visible="true"/> - <vis name="solid-red" alpha="1.0" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/> - <vis name="solid-verylight-red" alpha="0.6" r="1.0" g="0.8" b="0.8" showDaughters="true" visible="true"/> - <vis name="solid-green" alpha="1.0" r="0.0" g="0.9" b="0.2" showDaughters="true" visible="true"/> - <vis name="solid-light-green" alpha="0.4" r="0.0" g="0.4" b="0.0" showDaughters="true" visible="false"/> - <vis name="solid-verylight-green" alpha="0.6" r="0.8" g="1.0" b="0.8" showDaughters="true" visible="true"/> - <vis name="solid-blue" alpha="1.0" r="0.0" g="0.0" b="1.0" showDaughters="true" visible="true"/> - <vis name="solid-light-blue" alpha="1.0" r="0.0" g="0.0" b="1.0" showDaughters="true" visible="true"/> - <vis name="solid-verylight-blue" alpha="0.6" r="0.8" g="0.8" b="1.0" showDaughters="true" visible="true"/> - <vis name="solid-verylight-yellow" alpha="0.3" r="1.0" g="1.0" b="0.2" showDaughters="true" visible="true"/> - <vis name="CMS_Invisible" alpha="0.5" r="0.9" g="0.9" b="0.9" showDaughters="true" visible="false"/> - - <vis name="vis-active-material" alpha="1.0" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/> - <vis name="vis-invisible-daughters" alpha="1.0" r="0.1" g="0.1" b="0.8" showDaughters="true" visible="false"/> - - <vis name="eregalgo:ECAL" alpha="1.0" r="0.1" g="0.1" b="0.1" showDaughters="true" visible="true"/> - <vis name="eregalgo:EREG" alpha="0.3" r="1.0" g="0.1" b="1.0" showDaughters="true" visible="true"/> - <vis name="eehier:ENCA" alpha="1.0" r="0.1" g="0.1" b="0.1" showDaughters="true" visible="true"/> - <vis name="eehier:EEDee" alpha="1.0" r="0.1" g="1.0" b="0.1" showDaughters="true" visible="true"/> - <vis name="eehier:EEFrontQuad" alpha="0.3" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/> - <vis name="eehier:EEBackQuad" alpha="0.3" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/> - <vis name="eehier:EEFrontDee" alpha="0.5" r="0.0" g="1.0" b="0.1" showDaughters="true" visible="true"/> - <vis name="eehier:EEBackDee" alpha="0.5" r="0.0" g="1.0" b="0.1" showDaughters="true" visible="true"/> - <vis name="eregalgo:EESCEnv1" alpha="0.5" r="0.0" g="0.0" b="0.9" showDaughters="false" visible="true"/> - <vis name="eregalgo:EESCEnv2" alpha="0.5" r="0.0" g="0.0" b="0.9" showDaughters="false" visible="true"/> - <vis name="eregalgo:EESCEnv3" alpha="0.5" r="0.0" g="0.0" b="0.9" showDaughters="false" visible="true"/> - <vis name="eregalgo:EESCEnv4" alpha="0.5" r="0.0" g="0.0" b="0.9" showDaughters="false" visible="true"/> - <vis name="eregalgo:EESCEnv5" alpha="0.5" r="0.0" g="0.0" b="0.9" showDaughters="false" visible="true"/> - <vis name="eregalgo:EESCEnv6" alpha="0.5" r="0.0" g="0.0" b="0.9" showDaughters="false" visible="true"/> - <vis name="EESCAlv4" alpha="0.5" r="0.8" g="0.1" b="0.1" showDaughters="true" visible="true"/> - <vis name="EFRY" alpha="0.7" r="0.0" g="0.9" b="0.2" showDaughters="true" visible="true"/> + <vis name="ecal:ECAL" alpha="1.0" r="0.1" g="0.1" b="0.1" showDaughters="true" visible="true"/> + <vis name="ecal:EEDee" alpha="0.5" r="0.1" g="1.0" b="0.1" showDaughters="true" visible="true"/> + <vis name="ecal:EEQuad" alpha="0.3" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/> + <vis name="ecal:EESCEnv" alpha="0.5" r="0.0" g="0.0" b="0.9" showDaughters="false" visible="true"/> + <vis name="ecal:EREG" alpha="0.3" r="1.0" g="0.1" b="1.0" showDaughters="true" visible="true"/> + <vis name="ecal:EFRY" alpha="0.7" r="0.0" g="0.9" b="0.2" showDaughters="true" visible="true"/> </display> <plugin name="DD4hep_XMLLoader"> - <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/cms_ecal.xml"/> + <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/world-open.xml"/> </plugin> - <plugin name="DD4hep_PlacedVolumeProcessor"> - <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eregalgo:ECAL"/> - <arg value="-show"/> - </plugin> - <plugin name="DD4hep_PlacedVolumeProcessor"> - <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eehier:ENCA"/> - <arg value="-show"/> - </plugin> - <plugin name="DD4hep_PlacedVolumeProcessor"> - <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eehier:EEDee"/> - <arg value="-show"/> - </plugin> - <plugin name="DD4hep_PlacedVolumeProcessor"> - <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eehier:EEFrontDee"/> - <arg value="-show"/> - </plugin> - <plugin name="DD4hep_PlacedVolumeProcessor"> - <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eehier:EEBackDee"/> - <arg value="-show"/> - </plugin> - <plugin name="DD4hep_PlacedVolumeProcessor"> - <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eehier:EEFrontQuad"/> - <arg value="-show"/> - </plugin> - <plugin name="DD4hep_PlacedVolumeProcessor"> - <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eehier:EEBackQuad"/> - <arg value="-show"/> - </plugin> - <plugin name="DD4hep_PlacedVolumeProcessor"> - <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eregalgo:EESCEnv1"/> - <arg value="-show"/> - </plugin> - <plugin name="DD4hep_PlacedVolumeProcessor"> - <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eregalgo:EESCEnv2"/> - <arg value="-show"/> + <plugin name="DD4hep_XMLLoader"> + <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/cms_ecal.xml"/> </plugin> <plugin name="DD4hep_PlacedVolumeProcessor"> <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eregalgo:EESCEnv3"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="ecal:ECAL"/> + <arg value="-match"/> <arg value="eregalgo:ECAL"/> + <arg value="-match"/> <arg value="eehier:ENCA"/> <arg value="-show"/> </plugin> <plugin name="DD4hep_PlacedVolumeProcessor"> <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eregalgo:EESCEnv4"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="ecal:EEDee"/> + <arg value="-match"/> <arg value="eehier:EEDee"/> + <arg value="-match"/> <arg value="eehier:EEBackDee"/> + <arg value="-match"/> <arg value="eehier:EEFrontDee"/> <arg value="-show"/> </plugin> <plugin name="DD4hep_PlacedVolumeProcessor"> <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eregalgo:EESCEnv5"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="ecal:EEQuad"/> + <arg value="-match"/> <arg value="eehier:EEFrontQuad"/> + <arg value="-match"/> <arg value="eehier:EEBackQuad"/> <arg value="-show"/> </plugin> <plugin name="DD4hep_PlacedVolumeProcessor"> <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eregalgo:EESCEnv6"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="ecal:EESCEnv"/> + <arg value="-match"/> <arg value="eregalgo:EESCEnv."/> <arg value="-show"/> </plugin> <plugin name="DD4hep_PlacedVolumeProcessor"> <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="eregalgo:EREG"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="ecal:EREG"/> + <arg value="-match"/> <arg value="eregalgo:EREG"/> <arg value="-show"/> </plugin> <plugin name="DD4hep_PlacedVolumeProcessor"> <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="EFRY"/> + <arg value="-processor"/> <arg value="DD4hep_VisVolNameProcessor"/> + <arg value="-vis"/> <arg value="ecal:EFRY"/> + <arg value="-match"/> <arg value="EFRY"/> <arg value="-show"/> </plugin> <!-- @@ -180,6 +82,6 @@ </plugin> --> <plugin name="DD4hep_XMLLoader"> - <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/cms_close_geom.xml"/> + <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/world-close.xml"/> </plugin> </plugins> diff --git a/examples/DDCMS/data/ecal-vis.xml b/examples/DDCMS/data/ecal-vis.xml deleted file mode 100644 index 78456ec6b..000000000 --- a/examples/DDCMS/data/ecal-vis.xml +++ /dev/null @@ -1,50 +0,0 @@ -<plugins> -<!-- - - # Configuration file top load the CMS geometry - - This XML script extends the raw geometry defintiion from CMS (see cms_tracker.xml for details). - * We load the primary geometry entities and instantiate them. - Note: TEC, and PixbarFWD do not work and cannot be converted; - * Here the DetElement structure and the readout structures are defined to run Geant4 - Note: TEC, and PixbarFWD do not work and cannot be used for Geant4. To be investigated. - * Here we also define the visualization attributes to get nicer pictures. - - M.Frank CERN EP/LBC October 2017 - ---> - - <display> - - <vis name="solid-light-grey" alpha="0.5" r="0.5" g="0.5" b="0.5" showDaughters="true" visible="false"/> - <vis name="solid-verylight-grey" alpha="0.6" r="0.5" g="0.5" b="0.5" showDaughters="true" visible="true"/> - <vis name="solid-red" alpha="1.0" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/> - <vis name="solid-verylight-red" alpha="0.6" r="1.0" g="0.8" b="0.8" showDaughters="true" visible="true"/> - <vis name="solid-green" alpha="1.0" r="0.0" g="0.9" b="0.2" showDaughters="true" visible="true"/> - <vis name="solid-light-green" alpha="0.4" r="0.0" g="0.4" b="0.0" showDaughters="true" visible="false"/> - <vis name="solid-verylight-green" alpha="0.6" r="0.8" g="1.0" b="0.8" showDaughters="true" visible="true"/> - <vis name="solid-blue" alpha="1.0" r="0.0" g="0.0" b="1.0" showDaughters="true" visible="true"/> - <vis name="solid-light-blue" alpha="1.0" r="0.0" g="0.0" b="1.0" showDaughters="true" visible="true"/> - <vis name="solid-verylight-blue" alpha="0.6" r="0.8" g="0.8" b="1.0" showDaughters="true" visible="true"/> - <vis name="solid-verylight-yellow" alpha="0.3" r="1.0" g="1.0" b="0.2" showDaughters="true" visible="true"/> - <vis name="CMS_Invisible" alpha="0.5" r="0.9" g="0.9" b="0.9" showDaughters="true" visible="false"/> - - <vis name="vis-active-material" alpha="1.0" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/> - <vis name="vis-invisible-daughters" alpha="1.0" r="0.1" g="0.1" b="0.8" showDaughters="true" visible="false"/> - - <vis name="EFRY" alpha="0.7" r="0.0" g="0.9" b="0.2" showDaughters="true" visible="true"/> - </display> - - <plugin name="DD4hep_XMLLoader"> - <arg value="file:${DD4hepExamplesINSTALL}/examples/DDCMS/data/cms_ecal.xml"/> - </plugin> - - <plugin name="DD4hep_PlacedVolumeProcessor"> - <arg value="-recursive"/> - <arg value="-processor"/> - <arg value="DD4hep_VisVolNameProcessor"/> - <arg value="-name"/> - <arg value="EFRY"/> - <arg value="-show"/> - </plugin> -</plugins> diff --git a/examples/DDCMS/data/world-close.xml b/examples/DDCMS/data/world-close.xml new file mode 100644 index 000000000..dced56372 --- /dev/null +++ b/examples/DDCMS/data/world-close.xml @@ -0,0 +1,4 @@ +<?xml version="1.0"?> +<DDDefinition> + <close_geometry/> +</DDDefinition> diff --git a/examples/DDCMS/data/world-open.xml b/examples/DDCMS/data/world-open.xml new file mode 100644 index 000000000..ca0ff9e49 --- /dev/null +++ b/examples/DDCMS/data/world-open.xml @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<DDDefinition> + <debug> +<!-- + <debug_includes/> + <debug_constants/> + <debug_rotations/> + <debug_materials/> + + <debug_shapes/> + <debug_volumes/> + <debug_namespaces/> + <debug_placements/> + <debug_visattr/> + <debug_algorithms/> +--> + </debug> + <open_geometry/> + + <ConstantsSection label="" eval="true"> + <Constant name="world_x" value="5*m"/> + <Constant name="world_y" value="5*m"/> + <Constant name="world_z" value="5*m"/> + <Constant name="fm" value="1e-12*m"/> + <Constant name="Air" value="materials:Air" type="string"/> + <Constant name="Vacuum" value="materials:Vacuum" type="string"/> + </ConstantsSection> + <ConstantsSection label="servicescylinderb.xml" eval="true"> + <Constant name="zero" value="0.0*fm"/> + </ConstantsSection> + <ConstantsSection label="servicescylinderf.xml" eval="true"> + <Constant name="zero" value="0.0*fm"/> + </ConstantsSection> + + <IncludeSection> + <Include ref="materials.xml"/> + <Include ref="vacuum.xml"/> + <Include ref="rotations.xml"/> + </IncludeSection> + +</DDDefinition> diff --git a/examples/DDCMS/include/DDCMS/DDCMSTags.h b/examples/DDCMS/include/DDCMS/DDCMSTags.h index b3ce55e2b..4d4d0364a 100644 --- a/examples/DDCMS/include/DDCMS/DDCMSTags.h +++ b/examples/DDCMS/include/DDCMS/DDCMSTags.h @@ -33,6 +33,7 @@ namespace dd4hep { UNICODE(DDCMS); UNICODE(DDDefinition); + UNICODE(Division); UNICODE(ConstantsSection); UNICODE(Constant); @@ -46,6 +47,7 @@ namespace dd4hep { UNICODE(atomicNumber); UNICODE(MaterialFraction); + UNICODE(nReplicas); UNICODE(RotationSection); UNICODE(ReflectionRotation); UNICODE(rReflectionRotation); @@ -59,7 +61,11 @@ namespace dd4hep { UNICODE(phiZ); UNICODE(numSide); - + UNICODE(parent); + UNICODE(width); + UNICODE(axis); + UNICODE(offset); + UNICODE(TransformationSection); UNICODE(Transformation); diff --git a/examples/DDCMS/src/DDCMS.cpp b/examples/DDCMS/src/DDCMS.cpp index dbed15840..61c3e10c2 100644 --- a/examples/DDCMS/src/DDCMS.cpp +++ b/examples/DDCMS/src/DDCMS.cpp @@ -203,17 +203,24 @@ const Rotation3D& Namespace::rotation(const string& nam) const { return s_null; else if ( nam.find(":NULL") == nam.length()-5 ) return s_null; - string n = nam; + + string n = this->name + nam; + i = context->rotations.find(n); + if ( i != context->rotations.end() ) + return (*i).second; + + n = nam; if ( (idx=nam.find(NAMESPACE_SEP)) != string::npos ) { n[idx] = NAMESPACE_SEP; i = context->rotations.find(n); if ( i != context->rotations.end() ) return (*i).second; } + printout(ERROR,"Namespace","[%s] Cannot find rotation identifier: '%s'",this->name.c_str(), nam.c_str()); for (const auto& r : context->rotations ) { - cout << r.first << endl; + printout(ERROR,"Namespace","[%s] Known rotation: '%s'",this->name.c_str(), r.first.c_str()); } - throw runtime_error("Unknown rotation identifier:"+nam); + throw runtime_error("Unknown rotation identifier: '"+nam+"'"); } /// Add rotation matrix to current namespace diff --git a/examples/DDCMS/src/plugins/DDDefinitions2Objects.cpp b/examples/DDCMS/src/plugins/DDDefinitions2Objects.cpp index 933697cd2..0cf5955aa 100644 --- a/examples/DDCMS/src/plugins/DDDefinitions2Objects.cpp +++ b/examples/DDCMS/src/plugins/DDDefinitions2Objects.cpp @@ -51,8 +51,9 @@ namespace dd4hep { namespace { static UInt_t unique_mat_id = 0xAFFEFEED; - - + double convertRadToDeg(double r) { + return r*360e0/(2e0*M_PI); + } class disabled_algo; class include_constants; class include_load; @@ -76,6 +77,7 @@ namespace dd4hep { class transform3d; class pospartsection; + class division; class pospart; class logicalpartsection; @@ -141,9 +143,12 @@ namespace dd4hep { template <> void Converter<logicalpartsection>::operator()(xml_h element) const; template <> void Converter<logicalpart>::operator()(xml_h element) const; + /// Converter for <PosPartSection/> tags template <> void Converter<pospartsection>::operator()(xml_h element) const; /// Converter for <PosPart/> tags template <> void Converter<pospart>::operator()(xml_h element) const; + /// Converter for <Division/> tags + template <> void Converter<division>::operator()(xml_h element) const; /// Generic converter for solids: <SolidSection/> tags template <> void Converter<solidsection>::operator()(xml_h element) const; @@ -227,7 +232,9 @@ template <> void Converter<rotationsection>::operator()(xml_h element) const { template <> void Converter<pospartsection>::operator()(xml_h element) const { Namespace _ns(_param<ParsingContext>(), element); + xml_coll_t(element, _CMU(Division)).for_each(Converter<division>(description,_ns.context,optional)); xml_coll_t(element, _CMU(PosPart)).for_each(Converter<pospart>(description,_ns.context,optional)); + xml_coll_t(element, _CMU(Algorithm)).for_each(Converter<algorithm>(description,_ns.context,optional)); } /// Generic converter for <LogicalPartSection/> tags @@ -877,7 +884,10 @@ template <> void Converter<trd1>::operator()(xml_h element) const { printout(_ns.context->debug.shapes ? ALWAYS : DEBUG, "DDCMS", "+ Trd1: dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2:%.3f dy2:%.3f", dz, dx1, dy1, dx2, dy2); - _ns.addSolid(nam, Trapezoid(dx1, dx2, dy1, dy2, dz)); + if ( dy1 == dy2 ) + _ns.addSolid(nam, Trd1(dx1, dx2, dy1, dz)); + else + _ns.addSolid(nam, Trd2(dx1, dx2, dy1, dy2, dz)); } /// Converter for <Tubs/> tags @@ -1036,6 +1046,114 @@ template <> void Converter<include_constants>::operator()(xml_h element) const xml_coll_t(element, _CMU(ConstantsSection)).for_each(Converter<constantssection>(description,param,optional)); } +namespace { + + // The meaning of the axis index is the following: + // for all volumes having shapes like box, trd1, trd2, trap, gtra or para - 1,2,3 means X,Y,Z; + // for tube, tubs, cone, cons - 1 means Rxy, 2 means phi and 3 means Z; + // for pcon and pgon - 2 means phi and 3 means Z; + // for spheres 1 means R and 2 means phi. + + enum class DDAxes { x = 1, y = 2, z = 3, rho = 1, phi = 2, undefined }; + const std::map<std::string, DDAxes> axesmap{{"x", DDAxes::x}, + {"y", DDAxes::y}, + {"z", DDAxes::z}, + {"rho", DDAxes::rho}, + {"phi", DDAxes::phi}, + {"undefined", DDAxes::undefined}}; +} // namespace + +/// Converter for <Division/> tags +template <> +void Converter<division>::operator()(xml_h element) const { + Namespace ns(_param<ParsingContext>()); + xml_dim_t e(element); + string childName = e.nameStr(); + if (strchr(childName.c_str(), NAMESPACE_SEP) == nullptr) + childName = ns.prepend(childName); + + string parentName = ns.attr<string>(e, _CMU(parent)); + if (strchr(parentName.c_str(), NAMESPACE_SEP) == nullptr) + parentName = ns.prepend(parentName); + string axis = ns.attr<string>(e, _CMU(axis)); + + // If you divide a tube of 360 degrees the offset displaces + // the starting angle, but you still fill the 360 degrees + double offset = e.hasAttr(_CMU(offset)) ? ns.attr<double>(e, _CMU(offset)) : 0e0; + double width = e.hasAttr(_CMU(width)) ? ns.attr<double>(e, _CMU(width)) : 0e0; + int nReplicas = e.hasAttr(_CMU(nReplicas)) ? ns.attr<int>(e, _CMU(nReplicas)) : 0; + + printout(ns.context->debug.placements ? ALWAYS : DEBUG, + "DD4CMS", + "+++ Start executing Division of %s along %s (%d) with offset %6.3f and %6.3f to produce %s....", + parentName.c_str(), + axis.c_str(), + axesmap.at(axis), + offset, + width, + childName.c_str()); + + Volume parent = ns.volume(parentName); + + const TGeoShape* shape = parent.solid(); + TClass* cl = shape->IsA(); + if (cl == TGeoTubeSeg::Class()) { + const TGeoTubeSeg* sh = (const TGeoTubeSeg*)shape; + double widthInDeg = convertRadToDeg(width); + double startInDeg = convertRadToDeg(offset); + int numCopies = (int)((sh->GetPhi2() - sh->GetPhi1()) / widthInDeg); + + printout(ns.context->debug.placements ? ALWAYS : DEBUG, + "DD4CMS", + "+++ ...divide %s along %s (%d) with offset %6.3f deg and %6.3f deg to produce %d copies", + parent.solid().type(), + axis.c_str(), + axesmap.at(axis), + startInDeg, + widthInDeg, + numCopies); + Volume child = parent.divide(childName, static_cast<int>(axesmap.at(axis)), numCopies, startInDeg, widthInDeg); + + ns.context->volumes[childName] = child; + printout(ns.context->debug.placements ? ALWAYS : DEBUG, + "DD4CMS", + "+++ %s Parent: %-24s [%s] Child: %-32s [%s] is multivolume [%s]", + e.tag().c_str(), + parentName.c_str(), + parent.isValid() ? "VALID" : "INVALID", + child.name(), + child.isValid() ? "VALID" : "INVALID", + child->IsVolumeMulti() ? "YES" : "NO"); + } else if (cl == TGeoTrd1::Class() ) { + double dy = static_cast<const TGeoTrd1*>(shape)->GetDy(); + printout(ns.context->debug.placements ? ALWAYS : DEBUG, + "DD4CMS", + "+++ ...divide %s along %s (%d) with offset %6.3f cm and %6.3f cm to produce %d copies in %6.3f", + parent.solid().type(), + axis.c_str(), + axesmap.at(axis), + -dy + offset + width, + width, + nReplicas, + dy); + + Volume child = parent.divide(childName, static_cast<int>(axesmap.at(axis)), nReplicas, -dy + offset + width, width); + + ns.context->volumes[childName] = child; + printout(ns.context->debug.placements ? ALWAYS : DEBUG, + "DD4CMS", + "+++ %s Parent: %-24s [%s] Child: %-32s [%s] is multivolume [%s]", + e.tag().c_str(), + parentName.c_str(), + parent.isValid() ? "VALID" : "INVALID", + child.name(), + child.isValid() ? "VALID" : "INVALID", + child->IsVolumeMulti() ? "YES" : "NO"); + } else { + printout(ERROR, "DD4CMS", "++ FAILED Division of a %s is not implemented yet!", parent.solid().type()); + } +} + /// Converter for <Algorithm/> tags template <> void Converter<algorithm>::operator()(xml_h element) const { Namespace _ns(_param<ParsingContext>()); diff --git a/examples/DDG4_MySensDet/src/MyTrackerHit.cpp b/examples/DDG4_MySensDet/src/MyTrackerHit.cpp index 8a6385eb7..532526e4d 100644 --- a/examples/DDG4_MySensDet/src/MyTrackerHit.cpp +++ b/examples/DDG4_MySensDet/src/MyTrackerHit.cpp @@ -20,35 +20,10 @@ using namespace SomeExperiment; /// Assignment operator MyTrackerHit& MyTrackerHit::operator=(const MyTrackerHit& c) { if ( &c != this ) { - position = c.position; - momentum = c.momentum; - length = c.length; - truth = c.truth; + this->dd4hep::sim::Geant4Tracker::Hit::operator=(c); + this->step_length = c.step_length; + this->postPos = c.postPos; + this->prePos = c.prePos; } return *this; } - -/// Clear hit content -MyTrackerHit& MyTrackerHit::clear() { - position.SetXYZ(0, 0, 0); - momentum.SetXYZ(0, 0, 0); - length = 0.0; - truth.clear(); - return *this; -} - -/// Store Geant4 point and step information into tracker hit structure. -MyTrackerHit& MyTrackerHit::storePoint(const G4Step* step, const G4StepPoint* pnt) { - G4Track* trk = step->GetTrack(); - G4ThreeVector pos = pnt->GetPosition(); - G4ThreeVector mom = pnt->GetMomentum(); - - truth.trackID = trk->GetTrackID(); - truth.pdgID = trk->GetDefinition()->GetPDGEncoding(); - truth.deposit = step->GetTotalEnergyDeposit(); - truth.time = trk->GetGlobalTime(); - position.SetXYZ(pos.x(), pos.y(), pos.z()); - momentum.SetXYZ(mom.x(), mom.y(), mom.z()); - length = 0; - return *this; -} diff --git a/examples/DDG4_MySensDet/src/MyTrackerHit.h b/examples/DDG4_MySensDet/src/MyTrackerHit.h index ecec30933..759d2eb85 100644 --- a/examples/DDG4_MySensDet/src/MyTrackerHit.h +++ b/examples/DDG4_MySensDet/src/MyTrackerHit.h @@ -36,42 +36,39 @@ namespace SomeExperiment { * \version 1.0 * \ingroup DD4HEP_SIMULATION */ - class MyTrackerHit /* : public dd4hep::sim::Geant4HitData */ { + class MyTrackerHit : public dd4hep::sim::Geant4Tracker::Hit { public: - /// dd4hep::sim::Geant4HitData: cellID - long long int cellID = 0; - /// dd4hep::sim::Geant4HitData: User flag to classify hits - long flag = 0; - /// dd4hep::sim::Geant4HitData: Original Geant 4 track identifier of the creating track (debugging) - long g4ID = -1; - - - /// Hit position - dd4hep::Position position; - /// Hit direction - dd4hep::Direction momentum; - /// Length of the track segment contributing to this hit - double length = 0; - /// Monte Carlo / Geant4 information - dd4hep::sim::Geant4HitData::MonteCarloContrib truth; - /// Energy deposit in the tracker hit - double energyDeposit = 0; + dd4hep::Position prePos; + dd4hep::Position postPos; + double step_length; public: /// Default constructor MyTrackerHit() = default; /// Initializing constructor MyTrackerHit(int track_id, int pdg_id, double deposit, double time_stamp) - : length(0.0), truth(track_id, pdg_id, deposit, time_stamp, 0.), energyDeposit(deposit) {} + : dd4hep::sim::Geant4Tracker::Hit(track_id,pdg_id,deposit,time_stamp) {} /// Default destructor virtual ~MyTrackerHit() = default; /// Assignment operator MyTrackerHit& operator=(const MyTrackerHit& c); - /// Clear hit content - MyTrackerHit& clear(); - /// Store Geant4 point and step information into tracker hit structure. - MyTrackerHit& storePoint(const G4Step* step, const G4StepPoint* pnt); + }; + + /// Helper to dump data file + /** + * Usage: + * $> root.exe + * .... + * root [0] gSystem->Load("libDDG4Plugins.so"); + * root [1] gSystem->Load("libDDG4_MySensDet.so"); + * root [2] SomeExperiment::Dump::dumpData(<num-ebents>,<file-name>); + * + */ + class Dump { + public: + /// Standalone function to dump data from a root file + static int dumpData(int num_evts, const char* file_name); }; } @@ -86,6 +83,7 @@ namespace SomeExperiment { #pragma link C++ namespace dd4hep::sim; #pragma link C++ namespace SomeExperiment; #pragma link C++ class SomeExperiment::MyTrackerHit+; +#pragma link C++ class SomeExperiment::Dump; #endif #endif // EXAMPLES_DDG4_MYSENSDET_SRC_MYTRACKERHIT_H diff --git a/examples/DDG4_MySensDet/src/MyTrackerSDAction.cpp b/examples/DDG4_MySensDet/src/MyTrackerSDAction.cpp index 13af17abc..f61171c5c 100644 --- a/examples/DDG4_MySensDet/src/MyTrackerSDAction.cpp +++ b/examples/DDG4_MySensDet/src/MyTrackerSDAction.cpp @@ -71,6 +71,9 @@ namespace dd4hep { hit->position = position; hit->momentum = 0.5*(h. preMom() + h.postMom()); hit->length = hit_len; + hit->step_length = hit_len; + hit->prePos = prePos; + hit->postPos = postPos; collection(m_collectionID)->add(hit); mark(h.track); if ( 0 == hit->cellID ) { diff --git a/examples/DDG4_MySensDet/src/dumpData.cpp b/examples/DDG4_MySensDet/src/dumpData.cpp new file mode 100644 index 000000000..583ac4f00 --- /dev/null +++ b/examples/DDG4_MySensDet/src/dumpData.cpp @@ -0,0 +1,83 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#include "MyTrackerHit.h" +#include <TFile.h> +#include <TBranch.h> +#include <TTree.h> + +#include <iostream> +#include <vector> +#include <cerrno> + +using namespace std; + +namespace SomeExperiment { + + void dump_branch(int num_evts, TBranch* b) { + typedef vector<dd4hep::sim::Geant4Tracker::Hit*> TrHits; + int num_evt; + num_evt = b->GetEntries(); + if ( num_evt > 0 ) { + TrHits* hits = new TrHits(); + b->SetAddress(&hits); + for(int ievt=0; ievt<num_evts; ++ievt ) { + int nbyte = b->GetEntry(ievt); + if ( nbyte > 0 ) { + cout << "Tracker hits: " << nbyte << " bytes " << hits->size() << endl; + for(size_t i=0; i<min(hits->size(),10UL); ++i) { + MyTrackerHit* hit = (MyTrackerHit*)hits->at(i); + cout << b->GetName() << " Event " << ievt + << " Hit " << (int)i + << " type: " << typeid(*hit).name() + << " deposit:" << hit->energyDeposit + << " step-len:" << hit->step_length + << " prePos:" << hit->prePos + << " postPos:" << hit->postPos + << endl; + } + } + else { + cout << b->GetName() << " Event " << ievt << " NO DATA." << endl; + } + } + } + } + + /// Standalone function to dump data from a root file + int Dump::dumpData(int num_evts, const char* file_name) { + if ( !file_name ) { + cout << "Illegal file name: Input file cannot be opened!" << endl; + return ENOENT; + } + TFile* f = TFile::Open(file_name); + if ( !f ) { + cout << "File " << file_name << " cannot be opened!" << endl; + return ENOENT; + } + TTree* t = (TTree*)f->Get("EVENT"); + if ( !t ) { + f->Close(); + cout << "File " << file_name << " cannot be read!" << endl; + cout << "No branch with name EVENT!" << endl; + return ENOENT; + } + t->Print(); + dump_branch(num_evts,t->GetBranch("SiliconDownHits")); + dump_branch(num_evts,t->GetBranch("SiliconUpperHits")); + f->Close(); + delete f; + return 0; + } +} + + -- GitLab