25 #include "TGeoMatrix.h"
26 #include "TGeoManager.h"
27 #include "TGeoElement.h"
28 #include "TGeoMaterial.h"
36 using namespace DD4hep::Geometry;
44 std::string Author::authorName()
const {
45 return m_element->GetName();
49 void Author::setAuthorName(
const std::string& nam) {
50 m_element->SetName(nam.c_str());
54 std::string Author::authorEmail()
const {
55 return m_element->GetTitle();
59 void Author::setAuthorEmail(
const std::string& addr) {
60 m_element->SetTitle(addr.c_str());
64 Header::Header(
const string& author_name,
const string& descr_url) {
66 assign(obj_ptr, author_name, descr_url);
70 const std::string Header::name()
const {
71 return m_element->GetName();
75 void Header::setName(
const std::string& new_name) {
76 m_element->SetName(new_name.c_str());
80 const std::string Header::title()
const {
81 return m_element->GetTitle();
85 void Header::setTitle(
const std::string& new_title) {
86 m_element->SetTitle(new_title.c_str());
90 const std::string& Header::url()
const {
91 return data<Object>()->url;
95 void Header::setUrl(
const std::string& new_url) {
96 data<Object>()->url = new_url;
100 const std::string& Header::author()
const {
101 return data<Object>()->author;
105 void Header::setAuthor(
const std::string& new_author) {
106 data<Object>()->author = new_author;
110 const std::string& Header::status()
const {
111 return data<Object>()->status;
115 void Header::setStatus(
const std::string& new_status) {
116 data<Object>()->status = new_status;
120 const std::string& Header::version()
const {
121 return data<Object>()->version;
125 void Header::setVersion(
const std::string& new_version) {
126 data<Object>()->version = new_version;
130 const std::string& Header::comment()
const {
131 return data<Object>()->comment;
135 void Header::setComment(
const std::string& new_comment) {
136 data<Object>()->comment = new_comment;
140 Constant::Constant(
const string& nam,
const string& val,
const string& typ) {
141 m_element =
new Object(nam, val, typ);
145 Constant::Constant(
const string& nam) {
146 m_element =
new Object(nam.c_str(),
"",
"number");
150 string Constant::dataType()
const {
154 throw runtime_error(
"DD4hep: Attempt to access internals from invalid Constant handle!");
160 os << m_element->GetName() <<
" \"" << m_element->GetTitle() <<
"\" ";
161 if ( m_element->dataType ==
"string" ) os <<
"Value:" << m_element->GetTitle();
162 else os <<
"Value:" <<
_toDouble(m_element->GetTitle());
167 Atom::Atom(
const string& nam,
const string& formula,
int Z,
int N,
double density) {
168 TGeoElementTable* t = TGeoElement::GetElementTable();
169 TGeoElement*
e = t->FindElement(nam.c_str());
171 t->AddElement(nam.c_str(), formula.c_str(), Z, N, density);
172 e = t->FindElement(nam.c_str());
178 double Material::Z()
const {
181 TGeoMaterial*
m = val->GetMaterial();
184 throw runtime_error(
"DD4hep: The medium " +
string(val->GetName()) +
" has an invalid material reference!");
186 throw runtime_error(
"DD4hep: Attempt to access proton number from invalid material handle!");
189 double Material::A()
const {
192 TGeoMaterial*
m = val->GetMaterial();
195 throw runtime_error(
"DD4hep: The medium " +
string(val->GetName()) +
" has an invalid material reference!");
197 throw runtime_error(
"DD4hep: Attempt to access atomic number from invalid material handle!");
201 double Material::density()
const {
204 TGeoMaterial*
m = val->GetMaterial();
206 return m->GetDensity();
207 throw runtime_error(
"DD4hep: The medium " +
string(val->GetName()) +
" has an invalid material reference!");
209 throw runtime_error(
"DD4hep: Attempt to access density from invalid material handle!");
213 double Material::radLength()
const {
216 TGeoMaterial*
m = val->GetMaterial();
218 return m->GetRadLen();
219 throw runtime_error(
"DD4hep: The medium " +
string(val->GetName()) +
" has an invalid material reference!");
221 throw runtime_error(
"DD4hep: Attempt to access radiation length from invalid material handle!");
225 double Material::intLength()
const {
228 TGeoMaterial*
m = val->GetMaterial();
230 return m->GetIntLen();
231 throw runtime_error(
"The medium " +
string(val->GetName()) +
" has an invalid material reference!");
233 throw runtime_error(
"Attempt to access interaction length from invalid material handle!");
240 os << val->GetName() <<
" " << val->GetTitle() <<
" id:" << hex << val->GetId() <<
" Pointer:" << val->GetPointerName();
245 VisAttr::VisAttr(
const string& nam) {
247 assign(obj, nam,
"vis");
249 setLineStyle (SOLID);
250 setDrawingStyle(SOLID);
251 setShowDaughters(
true);
256 VisAttr::VisAttr(
const char* nam) {
258 assign(obj, nam,
"vis");
260 setLineStyle (SOLID);
261 setDrawingStyle(SOLID);
262 setShowDaughters(
true);
267 bool VisAttr::showDaughters()
const {
268 return object<Object>().showDaughters;
272 void VisAttr::setShowDaughters(
bool value) {
273 object<Object>().showDaughters = value;
277 bool VisAttr::visible()
const {
278 return object<Object>().visible;
282 void VisAttr::setVisible(
bool value) {
283 object<Object>().visible = value;
287 int VisAttr::lineStyle()
const {
288 return object<Object>().lineStyle;
292 void VisAttr::setLineStyle(
int value) {
293 object<Object>().lineStyle = value;
297 int VisAttr::drawingStyle()
const {
298 return object<Object>().drawingStyle;
302 void VisAttr::setDrawingStyle(
int value) {
303 object<Object>().drawingStyle = value;
307 float VisAttr::alpha()
const {
310 return object<Object>().alpha;
314 void VisAttr::setAlpha(
float value) {
315 object<Object>().alpha = value;
321 int VisAttr::color()
const {
322 return object<Object>().color;
326 void VisAttr::setColor(
float red,
float green,
float blue) {
327 Object& o = object<Object>();
328 o.
color = TColor::GetColor(red, green, blue);
333 bool VisAttr::rgb(
float& red,
float& green,
float& blue)
const {
334 Object& o = object<Object>();
336 TColor* c = (TColor*) o.
col;
337 c->GetRGB(red, green, blue);
346 TColor* col = gROOT->GetColor(obj->
color);
348 ::snprintf(text,
sizeof(text),
"%-20s RGB:%-8s [%d] %7.2f Style:%d %d ShowDaughters:%3s Visible:%3s", ptr()->
GetName(),
355 AlignmentEntry::AlignmentEntry(
const string& path) {
356 TGeoPhysicalNode* obj =
new TGeoPhysicalNode(path.c_str());
357 assign(obj, path,
"*");
361 int AlignmentEntry::align(
const Position& pos,
bool check,
double overlap) {
366 int AlignmentEntry::align(
const RotationZYX& rot,
bool check,
double overlap) {
367 return align(
Position(), rot, check, overlap);
374 TGeoHMatrix* new_matrix =
dynamic_cast<TGeoHMatrix*
>(m_element->GetOriginalMatrix()->MakeClone());
376 TGeoCombiTrans
m(pos.X(), pos.Y(), pos.Z(), 0);
377 m.SetRotation(rotation);
378 new_matrix->Multiply(&
m);
379 m_element->Align(new_matrix, 0, check, overlap);
382 throw runtime_error(
"DD4hep: Cannot align non existing physical node.");
415 string res = name +
" = " + content;
418 res +
" (" + particles +
")";
423 LimitSet::LimitSet(
const string& nam) {
424 assign(
new Object(), nam,
"limitset");
428 bool LimitSet::addLimit(
const Limit& limit) {
429 pair<Object::iterator, bool> ret = data<Object>()->insert(limit);
434 const set<Limit>& LimitSet::limits()
const {
435 const Object* o = data<Object>();
440 Region::Region(
const string& nam) {
442 assign(p, nam,
"region");
449 Region& Region::setStoreSecondaries(
bool value) {
450 object<Object>().store_secondaries = value;
454 Region& Region::setThreshold(
double value) {
455 object<Object>().threshold = value;
460 object<Object>().cut = value;
465 vector<string>& Region::limits()
const {
466 return object<Object>().user_limits;
470 double Region::cut()
const {
471 return object<Object>().cut;
475 double Region::threshold()
const {
476 return object<Object>().threshold;
480 bool Region::storeSecondaries()
const {
481 return object<Object>().store_secondaries;
493 struct IDSpec :
public Ref_t {
495 template <
typename Q>
499 void addField(
const std::string& name,
const std::pair<int,int>& field);
503 : RefElement(doc,Tag_idspec,name)
507 object<Object>().Attr_length = dsc.
maxBit();
508 for(IDDescriptor::FieldIDs::const_iterator i=f.begin(); i!=f.end();++i) {
509 int ident = (*i).first;
510 const string& nam = (*i).second;
511 const pair<int,int>& fld = m.find(nam)->second;
516 void IDSpec::addField(
const string& name,
const pair<int,int>& field) {
517 addField(Strng_t(name),field);
520 void IDSpec::addField(
const string& name,
const pair<int,int>& field) {
521 Element
e(document(),Tag_idfield);
522 e.object<Object>().Attr_signed = field.second<0;
523 e.object<Object>().Attr_label = name;
524 e.object<Object>().Attr_start = field.first;
525 e.object<Object>().Attr_length = abs(field.second);
std::vector< std::pair< std::string, Field > > FieldMap
bool operator<(const TiXmlString &a, const TiXmlString &b)
bool isValid() const
Check the validity of the object held by the handle.
Concrete object implementation of the Region Handle.
const char * yes_no(bool value)
Helper function to print booleans in format YES/NO.
std::vector< std::pair< size_t, std::string > > FieldIDs
Concrete object implementation for the Constant handle.
Implementation of a named object.
ROOT::Math::RotationZYX RotationZYX
const char * GetName(T *p)
unsigned char showDaughters
bool operator==(const TiXmlString &a, const TiXmlString &b)
ROOT::Math::XYZVector Position
std::string dataType
Constant type.
unsigned char drawingStyle
Handle< NamedObject > Ref_t
Default Ref_t definition describing named objects.
Small object describing a limit structure acting on a particle type.
const FieldIDs & ids() const
Access the field-id container.
double _toDouble(const std::string &value)
String conversions: string to double value.
Handle class describing a region as used in simulation.
The main interface to the DD4hep detector description package.
Concrete object implementation of the LimitSet Handle.
Class implementing the ID encoding of detector response.
unsigned maxBit() const
The total number of encoding bits for this descriptor.
const FieldMap & fields() const
Access the fieldmap container.
unsigned long long int magic_word()
Access to the magic word, which is protecting some objects against memory corruptions.
Concrete object implementation of the VisAttr Handle.