File indexing completed on 2025-01-30 09:16:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DD4HEP_DDCORE_VISDENSITYPROCESSOR_H
0014 #define DD4HEP_DDCORE_VISDENSITYPROCESSOR_H
0015
0016
0017 #include <DD4hep/VolumeProcessor.h>
0018
0019
0020 namespace dd4hep {
0021
0022
0023
0024
0025
0026
0027
0028
0029 class VisDensityProcessor : public PlacedVolumeProcessor {
0030 public:
0031 Detector& description;
0032 std::string name;
0033 VisAttr minVis;
0034 double minDensity = 5e0;
0035 size_t numInactive = 0;
0036 bool show = false;
0037
0038 void _show();
0039 public:
0040
0041 VisDensityProcessor(Detector& desc);
0042
0043 virtual ~VisDensityProcessor();
0044
0045 virtual int operator()(PlacedVolume pv, int level);
0046 };
0047 }
0048 #endif
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 #include <DD4hep/Printout.h>
0065 #include <DD4hep/DetectorTools.h>
0066 #include <DD4hep/DetectorHelper.h>
0067 #include <DD4hep/DetFactoryHelper.h>
0068 #include <sstream>
0069
0070 using namespace dd4hep;
0071
0072
0073 VisDensityProcessor::VisDensityProcessor(Detector& desc) : description(desc), name("VisDensityProcessor")
0074 {
0075 }
0076
0077
0078 VisDensityProcessor::~VisDensityProcessor() {
0079 if ( show && minVis.isValid() ) {
0080 printout(ALWAYS,name,"++ %8ld vis-attrs applied: %s", numInactive, minVis.name());
0081 }
0082 }
0083
0084
0085 void VisDensityProcessor::_show() {
0086 if ( show && minVis.isValid() ) {
0087 printout(ALWAYS,name,
0088 "++ SETUP Minimal material density: %.4f [g/cm3] Vis: %s",
0089 minDensity,minVis.name());
0090 }
0091 }
0092
0093
0094 int VisDensityProcessor::operator()(PlacedVolume pv, int ) {
0095 Volume vol = pv.volume();
0096 Material mat = vol.material();
0097 if ( vol.visAttributes().ptr() != minVis.ptr() ) {
0098 if ( mat.density() <= minDensity ) {
0099 vol.setVisAttributes(minVis);
0100 }
0101 ++numInactive;
0102 }
0103 return 1;
0104 }
0105
0106 static void* create_object(Detector& description, int argc, char** argv) {
0107 DetectorHelper helper(description);
0108 VisDensityProcessor* proc = new VisDensityProcessor(description);
0109 for ( int i=0; i<argc; ++i ) {
0110 if ( argv[i] ) {
0111 if ( ::strncmp(argv[i],"-vis",6) == 0 ) {
0112 VisAttr vis = description.visAttributes(argv[++i]);
0113 if ( vis.isValid() ) proc->minVis = std::move(vis);
0114 continue;
0115 }
0116 else if ( ::strncmp(argv[i],"-min-vis",6) == 0 ) {
0117 VisAttr vis = description.visAttributes(argv[++i]);
0118 if ( vis.isValid() ) proc->minVis = std::move(vis);
0119 continue;
0120 }
0121 else if ( ::strncmp(argv[i],"-min-density",6) == 0 ) {
0122 double density = _toDouble(argv[++i]);
0123 proc->minDensity = density;
0124 continue;
0125 }
0126 else if ( ::strncmp(argv[i],"-name",4) == 0 ) {
0127 std::string name = argv[++i];
0128 proc->name = std::move(name);
0129 continue;
0130 }
0131 else if ( ::strncmp(argv[i],"-show",4) == 0 ) {
0132 proc->show = true;
0133 continue;
0134 }
0135 std::cout <<
0136 "Usage: DD4hep_VisDensityProcessor -arg [-arg] \n"
0137 " -vis <name> Set the visualization attribute for inactive materials\n"
0138 " -min-vis <name> Set the visualization attribute for inactive materials\n"
0139 " -min-density <number> Minimal density to show the volume. \n"
0140 " -show Print setup to output device (stdout) \n"
0141 "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush;
0142 ::exit(EINVAL);
0143 }
0144 }
0145 proc->_show();
0146 PlacedVolumeProcessor* placement_proc = proc;
0147 return (void*)placement_proc;
0148 }
0149
0150
0151 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_VisDensityProcessor,create_object)