1 #include "DD4hep/VolumeProcessor.h" 2 #include "DD4hep/detail/DetectorInterna.h" 3 #include "DD4hep/DetFactoryHelper.h" 4 #include "DD4hep/DetectorHelper.h" 5 #include "DD4hep/Printout.h" 27 int operator()( dd4hep::PlacedVolume volume,
int level )
override;
29 int process( dd4hep::PlacedVolume volume,
int level,
bool recursive )
override;
33 dd4hep::DetElement addSubdetector(
const std::string& nam, dd4hep::PlacedVolume volume,
bool valid );
34 dd4hep::DetElement createElement(
const char* debugTag, dd4hep::PlacedVolume volume,
int id );
35 void createTopLevelDetectors( dd4hep::PlacedVolume volume );
40 Data( dd4hep::PlacedVolume
v ) : volume( v ) {}
42 Data& operator=(
const Data& d ) =
default;
44 dd4hep::PlacedVolume volume {
nullptr};
45 dd4hep::DetElement element {};
46 bool sensitive =
false;
47 bool hasSensitive =
false;
49 int daughterCount = 0;
50 int sensitiveCount = 0;
64 using Detectors = std::map<std::string, dd4hep::DetElement>;
65 using Counters = std::map<dd4hep::DetElement, Count>;
66 using LeafCount = std::map<std::pair<dd4hep::DetElement, int>, std::pair<int, int> >;
86 if( volume.isValid()) {
91 except(
"DD4CMS",
"++ Cannot deduce name from invalid PlacedVolume handle!");
96 : m_description( desc )
101 except(
"DDCMSDetElementCreator",
102 "++ Failed to extract SILICON from the element table." );
110 stringstream
str, id_str;
112 printout(
INFO,
"DDCMSDetElementCreator",
"+++++++++++++++ Summary of sensitve elements ++++++++++++++++++++++++" );
114 printout(
INFO,
"DDCMSDetElementCreator",
"++ Summary: SD: %-24s %7d DetElements %7d sensitives out of %7d volumes",
115 (
c.first.name() +
string(
":")).c_str(),
c.second.elements,
c.second.sensitives,
c.second.volumes );
120 printout(
INFO,
"DDCMSDetElementCreator",
"++ Summary: %-24s %7d DetElements %7d sensitives out of %7d volumes",
122 printout(
INFO,
"DDCMSDetElementCreator",
"+++++++++++++++ Summary of geometry depth analysis ++++++++++++++++++" );
124 map<dd4hep::DetElement, vector<pair<int,int> > >
fields;
126 dd4hep::DetElement de =
l.first.first;
127 printout(
INFO,
"DDCMSDetElementCreator",
"++ Summary: SD: %-24s system:%04X Lvl:%3d Sensitives: %6d [Max: %6d].",
128 ( de.name() +
string(
":")).c_str(), de.id(),
129 l.first.second,
l.second.second,
l.second.first );
130 fields[de].push_back( make_pair(
l.first.second,
l.second.first ));
131 totalDepth +=
l.second.second;
134 printout(
INFO,
"DDCMSDetElementCreator",
"++ Summary: %-24s %d.",
"Total DetElements:", totalCount );
135 printout(
INFO,
"DDCMSDetElementCreator",
"+++++++++++++++ Readout structure generation ++++++++++++++++++++++++" );
137 for(
const auto&
f : fields ) {
138 string roName =
f.first.name() +
string(
"Hits");
141 id_str <<
"system:" << num_bits;
142 for(
const auto&
q :
f.second ) {
144 if (
q.second < 1<<0 ) bits = 1;
145 else if (
q.second < 1<<1 ) bits = 1;
146 else if (
q.second < 1<<2 ) bits = 2;
147 else if (
q.second < 1<<3 ) bits = 3;
148 else if (
q.second < 1<<4 ) bits = 4;
149 else if (
q.second < 1<<5 ) bits = 5;
150 else if (
q.second < 1<<6 ) bits = 6;
151 else if (
q.second < 1<<7 ) bits = 7;
152 else if (
q.second < 1<<8 ) bits = 8;
153 else if (
q.second < 1<<9 ) bits = 9;
154 else if (
q.second < 1<<10 ) bits = 10;
155 else if (
q.second < 1<<11 ) bits = 11;
156 else if (
q.second < 1<<12 ) bits = 12;
157 else if (
q.second < 1<<13 ) bits = 13;
158 else if (
q.second < 1<<14 ) bits = 14;
159 else if (
q.second < 1<<15 ) bits = 15;
161 id_str <<
",Lv" <<
q.first <<
":" <<
bits;
164 string idspec = id_str.str();
165 str <<
"<readout name=\"" << roName <<
"\">" << endl
168 <<
"</id> <!-- Number of bits: " << num_bits <<
" -->" << endl
169 <<
"</readout>" << endl;
172 IDDescriptor dsc( roName, idspec );
174 Readout ro( roName );
175 ro.setIDDescriptor( dsc );
177 dd4hep::SensitiveDetector
sd =
m_description.sensitiveDetector(
f.first.name());
178 sd.setHitsCollection( ro.name());
180 printout(
INFO,
"DDCMSDetElementCreator",
181 "++ Setting up readout for subdetector:%-24s id:%04X",
182 f.first.name(),
f.first.id());
184 printout(
INFO,
"DDCMSDetElementCreator",
"+++++++++++++++ ID Descriptor generation ++++++++++++++++++++++++++++");
185 printout(
INFO,
"", str.str().c_str());
188 dd4hep::PlacedVolume place =
p.first;
190 ::snprintf( volId,
sizeof(volId),
"Lv%d",
p.second.first );
191 printout(
DEBUG,
"DDCMSDetElementCreator",
192 "++ Set volid (%-24s): %-6s = %3d -> %s (%p)",
193 volume.isSensitive() ? volume.sensitiveDetector().name() :
"Not Sensitive",
194 volId,
p.second.second, place.name(), place.ptr());
195 place.addPhysVolID( volId,
p.second.second);
197 printout( ALWAYS,
"DDCMSDetElementCreator",
198 "++ Instrumented %ld subdetectors with %d DetElements %d sensitives out of %d volumes and %ld sensitive placements.",
206 dd4hep::DetElement det( name,
id );
207 det.setPlacement( volume );
218 else if(
m_stack.size() == 3 ) {
229 det.setPlacement( volume );
231 det.placement().addPhysVolID(
"system", det.id());
242 double fracSi = volume.volume().material().fraction(
m_silicon );
243 if( fracSi > 90
e-2 ) {
248 int idx = volume->GetMotherVolume()->GetIndex( volume.ptr())+1;
250 cnt.first =
std::max( cnt.first, idx );
275 if(
data.sensitive ) {
291 if(
data.volumeCount > 0 ) {
294 data.hasSensitive =
true;
298 data.hasSensitive = (
data.daughterCount > 0 );
301 if(
data.hasSensitive ) {
304 if( !
data.element.isValid()) {
308 if( !
parent.element.isValid()) {
312 printout(
DEBUG,
"DDCMSDetElementCreator",
313 "++ Assign detector element: %s (%p, %ld children) to %s (%p) with %ld vols",
314 data.element.name(),
data.element.ptr(),
data.element.children().size(),
320 parent.hasSensitive =
true;
325 int volumeLevel =
level;
326 int idx =
data.volume->GetMotherVolume()->GetIndex(
data.volume.ptr())+1;
330 cnt_det.first =
std::max( cnt_det.first, idx );
333 if ( !added &&
data.element.isValid() ) {
334 printout(
WARNING,
"MEMORY-LEAK",
"Level:%3d Orpahaned DetElement:%s Daugthers:%d Parent:%s",
static void * createObject(dd4hep::Detector &description, int, char **)
void createTopLevelDetectors(dd4hep::PlacedVolume volume)
~DDCMSDetElementCreator() override
dd4hep::Detector & m_description
dd4hep::DetElement createElement(const char *debugTag, dd4hep::PlacedVolume volume, int id)
TrainProcessor *const proc
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
std::map< std::string, dd4hep::DetElement > Detectors
std::map< dd4hep::PlacedVolume, std::pair< int, int > > m_allPlacements
DDCMSDetElementCreator(dd4hep::Detector &)
int process(dd4hep::PlacedVolume volume, int level, bool recursive) override
Callback to output PlacedVolume information of an entire Placement.
DECLARE_DD4HEP_CONSTRUCTOR(DDCMS_DetElementCreator, createObject)
std::map< dd4hep::DetElement, Count > Counters
Namespace of DDCMS conversion namespace.
std::vector< Data > VolumeStack
std::string detElementName(dd4hep::PlacedVolume volume)
dd4hep::DetElement m_currentDetector
char data[epos_bytes_allocation]
std::map< std::pair< dd4hep::DetElement, int >, std::pair< int, int > > LeafCount
int operator()(dd4hep::PlacedVolume volume, int level) override
Callback to output PlacedVolume information of an single Placement.
dd4hep::DetElement addSubdetector(const std::string &nam, dd4hep::PlacedVolume volume, bool valid)
dd4hep::SensitiveDetector m_currentSensitive
dd4hep::DetElement m_tracker
Data(dd4hep::PlacedVolume v)