File indexing completed on 2025-07-03 07:54:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DD4HEP_DETELEMENT_H
0014 #define DD4HEP_DETELEMENT_H
0015
0016
0017 #include <DD4hep/Handle.h>
0018 #include <DD4hep/Callback.h>
0019 #include <DD4hep/Objects.h>
0020 #include <DD4hep/Volumes.h>
0021 #include <DD4hep/Readout.h>
0022 #include <DD4hep/Alignments.h>
0023 #include <DD4hep/Segmentations.h>
0024 #include <DD4hep/ObjectExtensions.h>
0025
0026
0027 #include <map>
0028
0029
0030 namespace dd4hep {
0031
0032
0033 class Detector;
0034 class DetElementObject;
0035 class SensitiveDetectorObject;
0036
0037
0038
0039
0040
0041
0042
0043 class SensitiveDetector: public Handle<SensitiveDetectorObject> {
0044 public:
0045
0046
0047 SensitiveDetector() : Handle<SensitiveDetectorObject>() { }
0048
0049
0050 SensitiveDetector(Object* obj_pointer)
0051 : Handle<SensitiveDetectorObject>(obj_pointer) { }
0052
0053
0054 SensitiveDetector(Handle<SensitiveDetectorObject>&& sd)
0055 : Handle<SensitiveDetectorObject>(sd) { }
0056
0057
0058 SensitiveDetector(const Handle<SensitiveDetectorObject>& sd)
0059 : Handle<SensitiveDetectorObject>(sd) { }
0060
0061
0062 SensitiveDetector(SensitiveDetector&& sd) = default;
0063
0064
0065 SensitiveDetector(const SensitiveDetector& sd) = default;
0066
0067
0068 template <typename Q> SensitiveDetector(const Handle<Q>& e)
0069 : Handle<SensitiveDetectorObject>(e) { }
0070
0071
0072 SensitiveDetector(const std::string& name, const std::string& type = "sensitive");
0073
0074
0075 SensitiveDetector& operator=(SensitiveDetector&& sd) = default;
0076
0077
0078 SensitiveDetector& operator=(const SensitiveDetector& sd) = default;
0079
0080
0081 template <typename T> bool operator ==(const Handle<T>& e) const {
0082 return ptr() == e.ptr();
0083 }
0084
0085 template <typename T> bool operator !=(const Handle<T>& e) const {
0086 return ptr() != e.ptr();
0087 }
0088
0089
0090 std::string type() const;
0091
0092
0093 SensitiveDetector& setType(const std::string& typ);
0094
0095
0096 SensitiveDetector& setVerbose(bool value);
0097
0098
0099 bool verbose() const;
0100
0101
0102 SensitiveDetector& setCombineHits(bool value);
0103
0104
0105 bool combineHits() const;
0106
0107
0108 SensitiveDetector& setHitsCollection(const std::string& spec);
0109
0110
0111 const std::string& hitsCollection() const;
0112
0113
0114 SensitiveDetector& setReadout(Readout readout);
0115
0116
0117 Readout readout() const;
0118
0119
0120 IDDescriptor idSpec() const;
0121
0122
0123 SensitiveDetector& setEnergyCutoff(double value);
0124
0125
0126 double energyCutoff() const;
0127
0128
0129 SensitiveDetector& setRegion(Region reg);
0130
0131
0132 Region region() const;
0133
0134
0135 SensitiveDetector& setLimitSet(LimitSet limits);
0136
0137
0138 LimitSet limits() const;
0139
0140
0141 void* addExtension(unsigned long long int key, ExtensionEntry* entry) const;
0142
0143
0144 void* extension(unsigned long long int key) const;
0145
0146
0147 void* extension(unsigned long long int key, bool alert) const;
0148
0149
0150 template <typename IFACE, typename CONCRETE> IFACE* addExtension(CONCRETE* c) const {
0151 return (IFACE*) this->addExtension(detail::typeHash64<IFACE>(),
0152 new detail::DeleteExtension<IFACE,CONCRETE>(c));
0153 }
0154
0155
0156 template <typename IFACE> IFACE* extension() const {
0157 return (IFACE*) this->extension(detail::typeHash64<IFACE>());
0158 }
0159 };
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187 class DetElement: public Handle<DetElementObject> {
0188 public:
0189
0190
0191
0192
0193
0194
0195 class Processor {
0196 public:
0197
0198 Processor();
0199
0200 virtual ~Processor();
0201
0202 virtual int processElement(DetElement detector) = 0;
0203 };
0204
0205 typedef std::map<std::string, DetElement> Children;
0206
0207 enum CopyParameters {
0208 COPY_NONE = 0,
0209 COPY_PLACEMENT = 1 << 0,
0210 COPY_PARENT = 1 << 1,
0211 COPY_ALIGNMENT = 1 << 2,
0212 PROPAGATE_PARENT_ID = 1 << 3,
0213 LAST
0214 };
0215
0216 enum UpdateParam {
0217 CONDITIONS_CHANGED = 1<<0,
0218 PLACEMENT_CHANGED = 1<<1,
0219 SOMETHING_CHANGED = 1<<2,
0220 PLACEMENT_ELEMENT = 1<<20,
0221 PLACEMENT_HIGHEST = 1<<21,
0222 PLACEMENT_DETECTOR = 1<<22,
0223 PLACEMENT_NONE
0224 };
0225
0226
0227 void check(bool condition, const std::string& msg) const;
0228
0229 protected:
0230
0231
0232
0233
0234
0235
0236
0237
0238 template <typename Q, typename T> class DetElementExtension : public ExtensionEntry {
0239 protected:
0240 T* ptr = 0;
0241 mutable Q* iface = 0;
0242 public:
0243
0244 DetElementExtension() = delete;
0245
0246 DetElementExtension(T* p) : ptr(p) { iface = dynamic_cast<Q*>(p); }
0247
0248 DetElementExtension(const DetElementExtension& copy) = default;
0249
0250 DetElementExtension& operator=(const DetElementExtension& copy) = default;
0251
0252 virtual ~DetElementExtension() = default;
0253
0254 T* copy(DetElement de) const { return new T(*ptr,de); }
0255
0256 virtual void destruct() const override { delete ptr; }
0257
0258 virtual void* object() const override
0259 { return iface ? iface : (iface=dynamic_cast<Q*>(ptr)); }
0260
0261 virtual void* copy(void* det) const override
0262 { return copy(DetElement((Object*)det)); }
0263
0264 virtual ExtensionEntry* clone(void* det) const override
0265 { return new DetElementExtension<Q,T>((T*)this->copy(det)); }
0266
0267 virtual unsigned long long int hash64() const override
0268 { return detail::typeHash64<Q>(); }
0269 };
0270
0271
0272 void i_addUpdateCall(unsigned int callback_type, const Callback& callback) const;
0273
0274 public:
0275
0276
0277 DetElement() = default;
0278
0279
0280 DetElement(DetElement&& e) = default;
0281
0282
0283 DetElement(const DetElement& e) = default;
0284
0285
0286 DetElement(Object* obj) : Handle<DetElementObject>(obj) { }
0287
0288
0289 DetElement(Object* obj, const std::string& name, const std::string& type);
0290
0291
0292 template <typename Q> DetElement(const Handle<Q>& e) : Handle<DetElementObject>(e) {}
0293
0294
0295 DetElement(NamedObject* obj) : Handle<DetElementObject>(obj) { }
0296
0297 #ifdef __MAKECINT__
0298
0299 DetElement(const Ref_t& e) : Handle<DetElementObject>(e) { }
0300 #endif
0301
0302 DetElement(const std::string& name, const std::string& type, int id);
0303
0304
0305 DetElement(const std::string& name, int id);
0306
0307
0308 DetElement(DetElement parent, const std::string& name, int id);
0309
0310
0311 DetElement& operator=(DetElement&& sd) = default;
0312
0313 DetElement& operator=(const DetElement& e) = default;
0314
0315
0316 Object& _data() const {
0317 return object<Object>();
0318 }
0319
0320
0321 bool operator <(const DetElement e) const {
0322 return ptr() < e.ptr();
0323 }
0324
0325 template <typename T> bool operator ==(const Handle<T>& e) const {
0326 return ptr() == e.ptr();
0327 }
0328
0329 template <typename T> bool operator !=(const Handle<T>& e) const {
0330 return ptr() != e.ptr();
0331 }
0332
0333
0334 DetElement clone(int flag) const;
0335
0336
0337 DetElement clone(const std::string& new_name) const;
0338
0339
0340 DetElement clone(const std::string& new_name, int new_id) const;
0341
0342
0343 std::pair<DetElement,Volume> reflect(const std::string& new_name) const;
0344
0345
0346 std::pair<DetElement,Volume> reflect(const std::string& new_name, int new_id) const;
0347
0348 std::pair<DetElement,Volume> reflect(const std::string& new_name, int new_id, SensitiveDetector sd) const;
0349
0350
0351 void* addExtension(ExtensionEntry* entry) const;
0352
0353
0354 void* extension(unsigned long long int key, bool alert) const;
0355
0356
0357 template <typename IFACE, typename CONCRETE> IFACE* addExtension(CONCRETE* c) const {
0358 CallbackSequence::checkTypes(typeid(IFACE), typeid(CONCRETE), dynamic_cast<IFACE*>(c));
0359 return (IFACE*) this->addExtension(new DetElementExtension<IFACE,CONCRETE>(c));
0360 }
0361
0362 template <typename IFACE> IFACE* extension() const {
0363 return (IFACE*) this->extension(detail::typeHash64<IFACE>(),true);
0364 }
0365
0366 template <typename IFACE> IFACE* extension(bool alert) const {
0367 return (IFACE*) this->extension(detail::typeHash64<IFACE>(),alert);
0368 }
0369
0370 template <typename Q, typename T>
0371 void callAtUpdate(unsigned int typ, Q* pointer,
0372 void (T::*pmf)(unsigned long typ, DetElement& det, void* opt_par)) const
0373 {
0374 CallbackSequence::checkTypes(typeid(T), typeid(Q), dynamic_cast<T*>(pointer));
0375 i_addUpdateCall(typ, Callback(pointer).make(pmf));
0376 }
0377
0378 void removeAtUpdate(unsigned int type, void* pointer) const;
0379
0380
0381 int id() const;
0382
0383 DetElement& setCombineHits(bool value, SensitiveDetector& sens);
0384
0385 bool combineHits() const;
0386
0387
0388
0389
0390 std::string type() const;
0391
0392 DetElement& setType(const std::string& typ);
0393
0394
0395 unsigned int typeFlag() const;
0396
0397
0398 DetElement& setTypeFlag(unsigned int types);
0399
0400
0401 unsigned int key() const;
0402
0403 int level() const;
0404
0405 const std::string& path() const;
0406
0407 const std::string& placementPath() const;
0408
0409
0410 DetElement& setAttributes(const Detector& description,
0411 const Volume& volume,
0412 const std::string& region,
0413 const std::string& limits,
0414 const std::string& vis);
0415
0416
0417 DetElement& setVisAttributes(const Detector& description, const std::string& name, const Volume& volume);
0418
0419 DetElement& setRegion(const Detector& description, const std::string& name, const Volume& volume);
0420
0421 DetElement& setLimitSet(const Detector& description, const std::string& name, const Volume& volume);
0422
0423
0424 Volume volume() const;
0425
0426 Solid solid() const;
0427
0428
0429
0430
0431
0432
0433 PlacedVolume placement() const;
0434
0435
0436
0437
0438
0439 PlacedVolume idealPlacement() const;
0440
0441 DetElement& setPlacement(const PlacedVolume& volume);
0442
0443 VolumeID volumeID() const;
0444
0445
0446 DetElement& add(DetElement sub_element);
0447
0448 const Children& children() const;
0449
0450 DetElement child(const std::string& name) const;
0451
0452 DetElement child(const std::string& child_name, bool throw_if_not_found) const;
0453
0454 DetElement parent() const;
0455
0456 DetElement world() const;
0457
0458
0459 Alignment nominal() const;
0460
0461 Alignment survey() const;
0462 };
0463 }
0464
0465 #include <DD4hep/AlignmentData.h>
0466
0467 #endif