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));
138 printout(
INFO,
"DDCMSDetElementCreator",
"++ Summary: %-24s %d.",
"Total DetElements:",
totalCount);
139 printout(
INFO,
"DDCMSDetElementCreator",
"+++++++++++++++ Readout structure generation ++++++++++++++++++++++++");
142 string roName =
f.first.name() +
string(
"Hits");
145 id_str <<
"system:" << num_bits;
146 for (
const auto&
q :
f.second) {
148 if (
q.second < 1 << 0)
150 else if (
q.second < 1 << 1)
152 else if (
q.second < 1 << 2)
154 else if (
q.second < 1 << 3)
156 else if (
q.second < 1 << 4)
158 else if (
q.second < 1 << 5)
160 else if (
q.second < 1 << 6)
162 else if (
q.second < 1 << 7)
164 else if (
q.second < 1 << 8)
166 else if (
q.second < 1 << 9)
168 else if (
q.second < 1 << 10)
170 else if (
q.second < 1 << 11)
172 else if (
q.second < 1 << 12)
174 else if (
q.second < 1 << 13)
176 else if (
q.second < 1 << 14)
178 else if (
q.second < 1 << 15)
181 id_str <<
",Lv" <<
q.first <<
":" <<
bits;
184 string idspec = id_str.str();
185 str <<
"<readout name=\"" << roName <<
"\">" << endl
186 <<
"\t<id>" << idspec <<
"</id> <!-- Number of bits: " << num_bits <<
" -->" << endl
187 <<
"</readout>" << endl;
190 IDDescriptor dsc(roName, idspec);
193 ro.setIDDescriptor(dsc);
195 dd4hep::SensitiveDetector sd =
m_description.sensitiveDetector(
f.first.name());
196 sd.setHitsCollection(ro.name());
199 "DDCMSDetElementCreator",
200 "++ Setting up readout for subdetector:%-24s id:%04X",
204 printout(
INFO,
"DDCMSDetElementCreator",
"+++++++++++++++ ID Descriptor generation ++++++++++++++++++++++++++++");
205 printout(
INFO,
"",
str.str().c_str());
210 ::snprintf(volId,
sizeof(volId),
"Lv%d",
p.second.first);
212 "DDCMSDetElementCreator",
213 "++ Set volid (%-24s): %-6s = %3d -> %s (%p)",
214 volume.isSensitive() ? volume.sensitiveDetector().name() :
"Not Sensitive",
219 place.addPhysVolID(volId,
p.second.second);
222 "DDCMSDetElementCreator",
223 "++ Instrumented %ld subdetectors with %d DetElements %d sensitives out of %d volumes and %ld sensitive " 234 dd4hep::DetElement det(
name,
id);
235 det.setPlacement(volume);
243 }
else if (
m_stack.size() == 3) {
254 det.setPlacement(volume);
256 det.placement().addPhysVolID(
"system", det.id());
265 double fracSi = volume.volume().material().fraction(
m_silicon);
266 if (fracSi > 90
e-2) {
268 data.sensitive =
true;
269 data.hasSensitive =
true;
271 int idx = volume->GetMotherVolume()->GetIndex(volume.ptr()) + 1;
295 if (
data.sensitive) {
311 if (
data.volumeCount > 0) {
314 data.hasSensitive =
true;
317 data.hasSensitive = (
data.daughterCount > 0);
320 if (
data.hasSensitive) {
323 if (!
data.element.isValid()) {
327 if (!
parent.element.isValid()) {
332 "DDCMSDetElementCreator",
333 "++ Assign detector element: %s (%p, %ld children) to %s (%p) with %ld vols",
336 data.element.children().size(),
343 parent.hasSensitive =
true;
348 int volumeLevel =
level;
349 int idx =
data.volume->GetMotherVolume()->GetIndex(
data.volume.ptr()) + 1;
356 if (!added &&
data.element.isValid()) {
359 "Level:%3d Orpahaned DetElement:%s Daugthers:%d Parent:%s",
Basic3DVector & operator=(const Basic3DVector &)=default
Assignment operator.
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.
TracksUtilities< TrackerTraits > helper
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