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" 41 dd4hep::DetElement element{};
42 bool sensitive =
false;
43 bool hasSensitive =
false;
45 int daughterCount = 0;
46 int sensitiveCount = 0;
59 using Detectors = std::map<std::string, dd4hep::DetElement>;
60 using Counters = std::map<dd4hep::DetElement, Count>;
61 using LeafCount = std::map<std::pair<dd4hep::DetElement, int>, std::pair<int, int> >;
80 if (volume.isValid()) {
85 except(
"DD4CMS",
"++ Cannot deduce name from invalid PlacedVolume handle!");
93 except(
"DDCMSDetElementCreator",
"++ Failed to extract SILICON from the element table.");
100 stringstream
str, id_str;
102 printout(
INFO,
"DDCMSDetElementCreator",
"+++++++++++++++ Summary of sensitve elements ++++++++++++++++++++++++");
105 "DDCMSDetElementCreator",
106 "++ Summary: SD: %-24s %7d DetElements %7d sensitives out of %7d volumes",
107 (
c.first.name() +
string(
":")).c_str(),
111 total.elements +=
c.second.elements;
112 total.sensitives +=
c.second.sensitives;
113 total.volumes +=
c.second.volumes;
116 "DDCMSDetElementCreator",
117 "++ 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;
128 "DDCMSDetElementCreator",
129 "++ Summary: SD: %-24s system:%04X Lvl:%3d Sensitives: %6d [Max: %6d].",
130 (de.name() +
string(
":")).c_str(),
135 fields[de].push_back(make_pair(
l.first.second,
l.second.first));
136 totalDepth +=
l.second.second;
139 printout(
INFO,
"DDCMSDetElementCreator",
"++ Summary: %-24s %d.",
"Total DetElements:",
totalCount);
140 printout(
INFO,
"DDCMSDetElementCreator",
"+++++++++++++++ Readout structure generation ++++++++++++++++++++++++");
143 string roName =
f.first.name() +
string(
"Hits");
146 id_str <<
"system:" << num_bits;
147 for (
const auto&
q :
f.second) {
149 if (
q.second < 1 << 0)
151 else if (
q.second < 1 << 1)
153 else if (
q.second < 1 << 2)
155 else if (
q.second < 1 << 3)
157 else if (
q.second < 1 << 4)
159 else if (
q.second < 1 << 5)
161 else if (
q.second < 1 << 6)
163 else if (
q.second < 1 << 7)
165 else if (
q.second < 1 << 8)
167 else if (
q.second < 1 << 9)
169 else if (
q.second < 1 << 10)
171 else if (
q.second < 1 << 11)
173 else if (
q.second < 1 << 12)
175 else if (
q.second < 1 << 13)
177 else if (
q.second < 1 << 14)
179 else if (
q.second < 1 << 15)
182 id_str <<
",Lv" <<
q.first <<
":" << bits;
185 string idspec = id_str.str();
186 str <<
"<readout name=\"" << roName <<
"\">" << endl
187 <<
"\t<id>" << idspec <<
"</id> <!-- Number of bits: " << num_bits <<
" -->" << endl
188 <<
"</readout>" << endl;
191 IDDescriptor dsc(roName, idspec);
194 ro.setIDDescriptor(dsc);
196 dd4hep::SensitiveDetector sd =
m_description.sensitiveDetector(
f.first.name());
197 sd.setHitsCollection(ro.name());
200 "DDCMSDetElementCreator",
201 "++ Setting up readout for subdetector:%-24s id:%04X",
205 printout(
INFO,
"DDCMSDetElementCreator",
"+++++++++++++++ ID Descriptor generation ++++++++++++++++++++++++++++");
206 printout(
INFO,
"",
str.str().c_str());
211 ::snprintf(volId,
sizeof(volId),
"Lv%d",
p.second.first);
213 "DDCMSDetElementCreator",
214 "++ Set volid (%-24s): %-6s = %3d -> %s (%p)",
215 volume.isSensitive() ? volume.sensitiveDetector().name() :
"Not Sensitive",
220 place.addPhysVolID(volId,
p.second.second);
223 "DDCMSDetElementCreator",
224 "++ Instrumented %ld subdetectors with %d DetElements %d sensitives out of %d volumes and %ld sensitive " 235 dd4hep::DetElement det(
name,
id);
236 det.setPlacement(volume);
244 }
else if (
m_stack.size() == 3) {
255 det.setPlacement(volume);
257 det.placement().addPhysVolID(
"system", det.id());
266 double fracSi = volume.volume().material().fraction(
m_silicon);
267 if (fracSi > 90
e-2) {
269 data.sensitive =
true;
270 data.hasSensitive =
true;
272 int idx = volume->GetMotherVolume()->GetIndex(volume.ptr()) + 1;
296 if (
data.sensitive) {
312 if (
data.volumeCount > 0) {
315 data.hasSensitive =
true;
318 data.hasSensitive = (
data.daughterCount > 0);
321 if (
data.hasSensitive) {
324 if (!
data.element.isValid()) {
328 if (!
parent.element.isValid()) {
333 "DDCMSDetElementCreator",
334 "++ Assign detector element: %s (%p, %ld children) to %s (%p) with %ld vols",
337 data.element.children().size(),
344 parent.hasSensitive =
true;
349 int volumeLevel =
level;
350 int idx =
data.volume->GetMotherVolume()->GetIndex(
data.volume.ptr()) + 1;
357 if (!added &&
data.element.isValid()) {
360 "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)
ret
prodAgent to be discontinued
std::map< std::string, dd4hep::DetElement > Detectors
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
dd4hep::PlacedVolume PlacedVolume
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)
std::map< dd4hep::PlacedVolume, std::pair< int, int > > m_allPlacements