 |
DD4hep
1.36.0
Detector Description Toolkit for High Energy Physics
|
Go to the documentation of this file.
24 #include <TGeoMatrix.h>
25 #include <TGeoManager.h>
26 #include <TGeoElement.h>
27 #include <TGeoMaterial.h>
61 Header::Header(
const std::string& author_name,
const std::string& descr_url) {
63 assign(obj_ptr, author_name, descr_url);
88 return data<Object>()->url;
93 data<Object>()->url = new_url;
98 return data<Object>()->author;
103 data<Object>()->author = new_author;
108 return data<Object>()->status;
113 data<Object>()->status = new_status;
118 return data<Object>()->version;
123 data<Object>()->version = new_version;
128 return data<Object>()->comment;
133 data<Object>()->comment = new_comment;
151 throw std::runtime_error(
"dd4hep: Attempt to access internals from invalid Constant handle!");
156 std::stringstream os;
164 Atom::Atom(
const std::string& nam,
const std::string& formula,
int Z,
int N,
double density) {
165 TGeoElementTable* t = TGeoElement::GetElementTable();
166 TGeoElement* e = t->FindElement(nam.c_str());
168 t->AddElement(nam.c_str(), formula.c_str(), Z, N, density);
169 e = t->FindElement(nam.c_str());
178 TGeoMaterial* mat = val->GetMaterial();
181 throw std::runtime_error(
"dd4hep: The medium " + std::string(val->GetName()) +
" has an invalid material reference!");
183 throw std::runtime_error(
"dd4hep: Attempt to access proton number from invalid material handle!");
189 TGeoMaterial* mat =
ptr()->GetMaterial();
192 throw std::runtime_error(
"dd4hep: The medium " + std::string(
ptr()->
GetName()) +
" has an invalid material reference!");
194 throw std::runtime_error(
"dd4hep: Attempt to access atomic number from invalid material handle!");
200 TGeoMaterial* mat =
ptr()->GetMaterial();
202 return mat->GetDensity();
203 throw std::runtime_error(
"dd4hep: The medium " + std::string(
ptr()->
GetName()) +
" has an invalid material reference!");
205 throw std::runtime_error(
"dd4hep: Attempt to access density from invalid material handle!");
211 TGeoMaterial* mat =
ptr()->GetMaterial();
213 return mat->GetRadLen();
214 throw std::runtime_error(
"dd4hep: The medium " + std::string(
ptr()->
GetName()) +
" has an invalid material reference!");
216 throw std::runtime_error(
"dd4hep: Attempt to access radiation length from invalid material handle!");
222 TGeoMaterial* mat =
ptr()->GetMaterial();
224 return mat->GetIntLen();
225 throw std::runtime_error(
"The medium " + std::string(
ptr()->
GetName()) +
" has an invalid material reference!");
227 throw std::runtime_error(
"Attempt to access interaction length from invalid material handle!");
232 double frac = 0e0, tot = 0e0;
233 TGeoElement* elt = atom.
access();
234 TGeoMaterial* mat =
access()->GetMaterial();
235 for (
int i=0, n=mat->GetNelements(); i<n; ++i ) {
236 TGeoElement* e = mat->GetElement(i);
237 if ( mat->IsMixture() ) {
238 TGeoMixture*
mix = (TGeoMixture*)mat;
239 tot +=
mix->GetWmixt()[i];
245 if ( mat->IsMixture() ) {
246 TGeoMixture*
mix = (TGeoMixture*)mat;
247 frac +=
mix->GetWmixt()[i];
254 return tot>1e-20 ? frac/tot : 0.0;
259 return access()->GetMaterial()->GetNproperties();
264 return access()->GetMaterial()->GetProperty(index);
269 return access()->GetMaterial()->GetProperty(nam);
274 return access()->GetMaterial()->GetProperty(nam.c_str());
279 auto* o =
access()->GetMaterial();
280 const char* p = o->GetPropertyRef(
name.c_str());
282 return default_value;
287 return access()->GetMaterial()->GetNconstProperties();
293 const auto* mat =
access()->GetMaterial();
294 double value = mat->GetConstProperty(index, &err);
295 if ( err != kTRUE )
return value;
296 throw std::runtime_error(
"Attempt to access non existing material const property with index: "+std::to_string(index));
302 auto* mat =
access()->GetMaterial();
303 double value = mat->GetConstProperty(nam.c_str(), &err);
304 if ( err != kTRUE )
return value;
305 throw std::runtime_error(
"Attempt to access non existing material const property: "+nam);
310 auto* o =
access()->GetMaterial();
311 const char* p = o->GetConstPropertyRef(
name.c_str());
313 return default_value;
319 TGeoMedium* val =
ptr();
320 std::stringstream out;
321 out << val->GetName() <<
" " << val->GetTitle()
322 <<
" id:" << std::hex << val->GetId()
323 <<
" Pointer:" << val->GetPointerName();
326 throw std::runtime_error(
"Attempt to convert invalid material handle to string!");
333 obj->
color = gROOT->GetColor(kWhite);
345 obj->
color = gROOT->GetColor(kWhite);
355 return object<Object>().showDaughters;
360 object<Object>().showDaughters = value;
365 return object<Object>().visible;
370 object<Object>().visible = value;
375 return object<Object>().lineStyle;
380 object<Object>().lineStyle = value;
385 return object<Object>().drawingStyle;
390 object<Object>().drawingStyle = value;
395 return object<Object>().alpha;
400 return object<Object>().color->GetNumber();
405 Object& o = object<Object>();
406 const auto num_before = gROOT->GetListOfColors()->GetLast();
409 TColor::SetColorThreshold(1.0f/31.0f);
410 Int_t col = TColor::GetColor(red, green, blue);
411 const auto num_after = gROOT->GetListOfColors()->GetLast();
412 if (num_before != num_after) {
413 printout(INFO,
"VisAttr",
"+++ %s Allocated a Color: r:%02X g:%02X b:%02X, this will not save to a ROOT file",
414 this->
name(),
int(red*255.),
int(green*255.),
int(blue*255));
417 o.
color = gROOT->GetColor(col);
419 except(
"VisAttr",
"+++ %s Failed to allocate Color: r:%02X g:%02X b:%02X",
420 this->
name(),
int(red*255.),
int(green*255.),
int(blue*255));
422 o.
colortr =
new TColor(gROOT->GetListOfColors()->GetLast()+1,
429 Object& o = object<Object>();
431 o.
color->GetRGB(red, green, blue);
438 bool VisAttr::argb(
float& alpha,
float& red,
float& green,
float& blue)
const {
439 Object& o = object<Object>();
442 o.
color->GetRGB(red, green, blue);
451 TColor* c = obj->
color;
453 std::snprintf(text,
sizeof(text),
"%-20s RGB:%-8s [%d] %7.2f Style:%d %d ShowDaughters:%3s Visible:%3s",
ptr()->
GetName(),
491 std::pair<Object::iterator, bool> ret = data<Object>()->limits.insert(limit);
497 const Object* o = data<Object>();
503 std::pair<Object::iterator, bool> ret = data<Object>()->cuts.insert(cut_obj);
509 return data<Object>()->cuts;
525 object<Object>().store_secondaries = value;
531 object<Object>().was_threshold_set =
true;
536 object<Object>().
cut = value;
537 object<Object>().use_default_cut =
false;
543 return object<Object>().user_limits;
548 return object<Object>().cut;
553 return object<Object>().threshold;
558 return object<Object>().store_secondaries;
562 return object<Object>().use_default_cut;
566 return object<Object>().was_threshold_set;
578 struct IDSpec :
public Ref_t {
580 template <
typename Q>
584 void addField(
const std::string& name,
const std::pair<int,int>& field);
588 : RefElement(doc,Tag_idspec,name)
592 object<Object>().Attr_length = dsc.
maxBit();
593 for(
const auto& i : f ) {
594 const std::string& nam = i.second;
595 const pair<int,int>& fld = m.find(nam)->second;
600 void IDSpec::addField(
const std::string& name,
const pair<int,int>& field) {
601 addField(Strng_t(name),field);
604 void IDSpec::addField(
const std::string& name,
const pair<int,int>& field) {
605 Element e(document(),Tag_idfield);
606 e.object<Object>().Attr_signed = field.second<0;
607 e.object<Object>().Attr_label = name;
608 e.object<Object>().Attr_start = field.first;
609 e.object<Object>().Attr_length = abs(field.second);
void setAuthorEmail(const std::string &addr)
Set the author's email address.
bool operator==(const Limit &c) const
Equality operator.
int color() const
Get object color.
const std::set< Limit > & cuts() const
Accessor to limits container.
Handle class describing an element in the periodic table.
std::string toString() const
String representation of this object.
bool argb(float &alpha, float &red, float &green, float &blue) const
Get alpha and RGB values of the color (if valid)
bool wasThresholdSet() const
Access was_threshold_set flag.
std::vector< std::pair< std::string, const Field * > > FieldMap
HeaderObject Object
Extern accessible definition of the contained element type.
std::string particles
Particle the limit should be applied to.
Author()=default
Default constructor.
const TGDMLMatrix * Property
std::string toString() const
String representation of this object.
Region & setStoreSecondaries(bool value)
Set flag to store secondaries.
bool storeSecondaries() const
Access secondaries flag.
unsigned maxBit() const
The total number of encoding bits for this descriptor.
Region & setCut(double value)
Set default production cut.
const char * GetName() const
Access name.
Region()=default
Default constructor.
const std::set< Limit > & limits() const
Accessor to limits container.
Property property(std::size_t index) const
Access to tabular properties of the material by index.
Small object describing a limit structure acting on a particle type.
Class implementing the ID encoding of the detector response.
std::string toString() const
Conversion to a string representation.
void setShowDaughters(bool value)
Set Flag to show/hide daughter elements.
std::string constPropertyRef(const std::string &name, const std::string &default_value="")
Access string property value from the material table.
bool isValid() const
Check the validity of the object held by the handle.
unsigned long long int magic_word()
Access to the magic word, which is protecting some objects against memory corruptions.
void setLineStyle(int style)
Set line style.
std::string propertyRef(const std::string &name, const std::string &default_value="")
Access string property value from the material table.
const char * name() const
Access the object name (or "" if not supported by the object)
std::vector< std::string > & limits() const
Access references to user limits.
double intLength() const
Access the interaction length of the underlying material.
double A() const
atomic number of the underlying material
double fraction(Atom atom) const
Access the fraction of an element within the material.
void SetName(const char *nam)
Set name (used by Handle)
float alpha() const
Get alpha value.
double density() const
density of the underlying material
std::string dataType() const
Access the constant.
int lineStyle() const
Get line style.
int drawingStyle() const
Get drawing style.
bool showDaughters() const
Get Flag to show/hide daughter elements.
void setDrawingStyle(int style)
Set drawing style.
double threshold() const
Access production threshold.
double constProperty(std::size_t index) const
Access to const properties of the material by index.
const char * GetName(T *p)
unsigned char showDaughters
void assign(Object *n, const std::string &nam, const std::string &title)
Assign a new named object. Note: object references must be managed by the user.
void setVisible(bool value)
Set visibility flag.
std::string name
Limit name.
void setAuthorName(const std::string &nam)
Set the author's name.
Concrete object implementation of the Region Handle.
double Z() const
proton number of the underlying material
std::vector< std::pair< size_t, std::string > > FieldIDs
unsigned char drawingStyle
void SetTitle(const char *tit)
Set Title (used by Handle)
std::string dataType
Constant type.
Handle class describing a region as used in simulation.
bool rgb(float &red, float &green, float &blue) const
Get RGB values of the color (if valid)
T * m_element
Single and only data member: Reference to the actual element.
std::string content
Content.
std::string authorName() const
Access the author's name.
double value
Double value.
Atom()=default
Default constructor.
const char * GetTitle() const
Get name (used by Handle)
double cut() const
Access cut value.
bool addCut(const Limit &limit)
Add new limit. Returns true if the new limit was added, false if it already existed.
std::string toString() const
String representation of this object.
const FieldMap & fields() const
Access the fieldmap container.
double _toDouble(const std::string &value)
String conversions: string to double value.
bool visible() const
Get visibility flag.
T * access() const
Checked object access. Throws invalid handle runtime exception if invalid handle.
bool operator<(const Limit &c) const
operator less
std::size_t numProperties() const
Access the number of properties attached to the material (if any)
TGeoMedium * ptr() const
Access to the held object.
bool useDefaultCut() const
Access use_default_cut flag.
Namespace for the AIDA detector description toolkit.
Implementation of a named object.
std::size_t numConstProperties() const
Access the number of const properties attached to the material (if any)
The main interface to the dd4hep detector description package.
Concrete object implementation of the LimitSet Handle.
double radLength() const
Access the radiation length of the underlying material.
std::set< Limit > limits
Particle specific limits.
void setColor(float alpha, float red, float green, float blue)
Set object color.
Constant()=default
Default constructor.
bool addLimit(const Limit &limit)
Add new limit. Returns true if the new limit was added, false if it already existed.
VisAttr()=default
Default constructor.
std::string authorEmail() const
Access the author's email address.
const FieldIDs & ids() const
Access the field-id container.
Concrete object implementation of the VisAttr Handle.
LimitSet()=default
Constructor to be used when reading the already parsed DOM tree.
Region & setThreshold(double value)
Set threshold in MeV.