DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
VisDensityProcessor.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DD4HEP_DDCORE_VISDENSITYPROCESSOR_H
14 #define DD4HEP_DDCORE_VISDENSITYPROCESSOR_H
15 
16 // Framework include files
17 #include <DD4hep/VolumeProcessor.h>
18 
20 namespace dd4hep {
21 
23  /* Set visualization attributes for sensitive volumes
24  *
25  * \author M.Frank
26  * \version 1.0
27  * \ingroup DD4HEP_CORE
28  */
30  public:
32  std::string name;
34  double minDensity = 5e0;
35  size_t numInactive = 0;
36  bool show = false;
38  void _show();
39  public:
43  virtual ~VisDensityProcessor();
45  virtual int operator()(PlacedVolume pv, int level);
46  };
47 }
48 #endif // DD4HEP_DDCORE_VISDENSITYPROCESSOR_H
49 
50 //==========================================================================
51 // AIDA Detector description implementation
52 //--------------------------------------------------------------------------
53 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
54 // All rights reserved.
55 //
56 // For the licensing terms see $DD4hepINSTALL/LICENSE.
57 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
58 //
59 // Author : M.Frank
60 //
61 //==========================================================================
62 
63 //#include <DD4hep/VisDensityProcessor.h>
64 #include <DD4hep/Printout.h>
65 #include <DD4hep/DetectorTools.h>
66 #include <DD4hep/DetectorHelper.h>
68 #include <sstream>
69 
70 using namespace dd4hep;
71 
73 VisDensityProcessor::VisDensityProcessor(Detector& desc) : description(desc), name("VisDensityProcessor")
74 {
75 }
76 
79  if ( show && minVis.isValid() ) {
80  printout(ALWAYS,name,"++ %8ld vis-attrs applied: %s", numInactive, minVis.name());
81  }
82 }
83 
86  if ( show && minVis.isValid() ) {
87  printout(ALWAYS,name,
88  "++ SETUP Minimal material density: %.4f [g/cm3] Vis: %s",
90  }
91 }
92 
95  Volume vol = pv.volume();
96  Material mat = vol.material();
97  if ( vol.visAttributes().ptr() != minVis.ptr() ) {
98  if ( mat.density() <= minDensity ) {
100  }
101  ++numInactive;
102  }
103  return 1;
104 }
105 
106 static void* create_object(Detector& description, int argc, char** argv) {
107  DetectorHelper helper(description);
108  VisDensityProcessor* proc = new VisDensityProcessor(description);
109  for ( int i=0; i<argc; ++i ) {
110  if ( argv[i] ) {
111  if ( ::strncmp(argv[i],"-vis",6) == 0 ) {
112  VisAttr vis = description.visAttributes(argv[++i]);
113  if ( vis.isValid() ) proc->minVis = std::move(vis);
114  continue;
115  }
116  else if ( ::strncmp(argv[i],"-min-vis",6) == 0 ) {
117  VisAttr vis = description.visAttributes(argv[++i]);
118  if ( vis.isValid() ) proc->minVis = std::move(vis);
119  continue;
120  }
121  else if ( ::strncmp(argv[i],"-min-density",6) == 0 ) {
122  double density = _toDouble(argv[++i]);
123  proc->minDensity = density;
124  continue;
125  }
126  else if ( ::strncmp(argv[i],"-name",4) == 0 ) {
127  std::string name = argv[++i];
128  proc->name = std::move(name);
129  continue;
130  }
131  else if ( ::strncmp(argv[i],"-show",4) == 0 ) {
132  proc->show = true;
133  continue;
134  }
135  std::cout <<
136  "Usage: DD4hep_VisDensityProcessor -arg [-arg] \n"
137  " -vis <name> Set the visualization attribute for inactive materials\n"
138  " -min-vis <name> Set the visualization attribute for inactive materials\n"
139  " -min-density <number> Minimal density to show the volume. \n"
140  " -show Print setup to output device (stdout) \n"
141  "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush;
142  ::exit(EINVAL);
143  }
144  }
145  proc->_show();
146  PlacedVolumeProcessor* placement_proc = proc;
147  return (void*)placement_proc;
148 }
149 
150 // first argument is the type from the xml file
151 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_VisDensityProcessor,create_object)
dd4hep::PlacedVolumeProcessor
Generic PlacedVolume processor.
Definition: VolumeProcessor.h:37
dd4hep::VisDensityProcessor
DD4hep DetElement creator for the CMS geometry.
Definition: VisDensityProcessor.cpp:29
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:163
dd4hep::VisAttr
Handle class describing visualization attributes.
Definition: Objects.h:324
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
DetectorHelper.h
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::VisDensityProcessor::minVis
VisAttr minVis
Definition: VisDensityProcessor.cpp:33
dd4hep::Volume::material
Material material() const
Access to the Volume material.
Definition: Volumes.cpp:1151
dd4hep::Material::density
double density() const
density of the underlying material
Definition: Objects.cpp:199
dd4hep::Material
Handle class describing a material.
Definition: Objects.h:272
dd4hep::Volume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:370
dd4hep::VisDensityProcessor::name
std::string name
Definition: VisDensityProcessor.cpp:32
VolumeProcessor.h
DetectorTools.h
dd4hep::VisDensityProcessor::~VisDensityProcessor
virtual ~VisDensityProcessor()
Default destructor.
Definition: VisDensityProcessor.cpp:78
DECLARE_DD4HEP_CONSTRUCTOR
#define DECLARE_DD4HEP_CONSTRUCTOR(name, func)
Definition: Factories.h:291
dd4hep::DetectorHelper
DetectorHelper: class to shortcut certain questions to the dd4hep detector description interface.
Definition: DetectorHelper.h:32
dd4hep::VisDensityProcessor::_show
void _show()
Print properties.
Definition: VisDensityProcessor.cpp:85
dd4hep::VisDensityProcessor::description
Detector & description
Definition: VisDensityProcessor.cpp:31
dd4hep::Detector::visAttributes
virtual const HandleMap & visAttributes() const =0
Accessor to the map of visualisation attributes.
DetFactoryHelper.h
dd4hep::VisDensityProcessor::numInactive
size_t numInactive
Definition: VisDensityProcessor.cpp:35
dd4hep::_toDouble
double _toDouble(const std::string &value)
String conversions: string to double value.
Definition: Handle.cpp:116
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep::Volume::setVisAttributes
const Volume & setVisAttributes(const VisAttr &obj) const
Set Visualization attributes to the volume.
Definition: Volumes.cpp:1156
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::VisDensityProcessor::VisDensityProcessor
VisDensityProcessor(Detector &desc)
Initializing constructor.
Definition: VisDensityProcessor.cpp:73
dd4hep::PlacedVolume::volume
Volume volume() const
Logical volume of this placement.
Definition: Volumes.cpp:468
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::VisDensityProcessor::minDensity
double minDensity
Definition: VisDensityProcessor.cpp:34
dd4hep::VisDensityProcessor::show
bool show
Definition: VisDensityProcessor.cpp:36
dd4hep::Volume::visAttributes
VisAttr visAttributes() const
Access the visualisation attributes.
Definition: Volumes.cpp:1239
Printout.h
dd4hep::VisDensityProcessor::operator()
virtual int operator()(PlacedVolume pv, int level)
Callback to output PlacedVolume information of an single Placement.
Definition: VisDensityProcessor.cpp:94