Newer
Older
Markus Frank
committed
//==========================================================================
Pere Mato
committed
// AIDA Detector description implementation for LCD
Markus Frank
committed
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
Markus Frank
committed
// All rights reserved.
Pere Mato
committed
//
Markus Frank
committed
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
Pere Mato
committed
//
Markus Frank
committed
// Author : M.Frank
//
//==========================================================================
Pere Mato
committed
Pere Mato
committed
#include "DD4hep/LCDD.h"
Pere Mato
committed
#include "DD4hep/IDDescriptor.h"
Markus Frank
committed
#include "DD4hep/InstanceCount.h"
Pere Mato
committed
Pere Mato
committed
#include "TROOT.h"
#include "TColor.h"
#include "TGeoMatrix.h"
Pere Mato
committed
#include "TGeoManager.h"
#include "TGeoElement.h"
#include "TGeoMaterial.h"
Pere Mato
committed
#include <sstream>
#include <iomanip>
Pere Mato
committed
using namespace DD4hep::Geometry;
Author::Author(LCDD& /* lcdd */) {
Markus Frank
committed
/// Access the auhor's name
std::string Author::authorName() const {
Markus Frank
committed
return m_element->GetName();
}
/// Set the author's name
void Author::setAuthorName(const std::string& nam) {
Markus Frank
committed
m_element->SetName(nam.c_str());
}
/// Access the auhor's email address
std::string Author::authorEmail() const {
Markus Frank
committed
return m_element->GetTitle();
}
/// Set the author's email address
void Author::setAuthorEmail(const std::string& addr) {
Markus Frank
committed
m_element->SetTitle(addr.c_str());
}
Header::Header(const string& author_name, const string& descr_url) {
Object* obj_ptr = new Object();
assign(obj_ptr, author_name, descr_url);
const std::string Header::name() const {
/// Accessor: set object name
void Header::setName(const std::string& new_name) {
m_element->SetName(new_name.c_str());
const std::string Header::title() const {
/// Accessor: set object title
void Header::setTitle(const std::string& new_title) {
m_element->SetTitle(new_title.c_str());
}
/// Accessor to object url
const std::string& Header::url() const {
return data<Object>()->url;
}
/// Accessor: set object url
void Header::setUrl(const std::string& new_url) {
data<Object>()->url = new_url;
}
/// Accessor to object author
const std::string& Header::author() const {
return data<Object>()->author;
}
/// Accessor: set object author
void Header::setAuthor(const std::string& new_author) {
data<Object>()->author = new_author;
}
/// Accessor to object status
const std::string& Header::status() const {
return data<Object>()->status;
}
/// Accessor: set object status
void Header::setStatus(const std::string& new_status) {
data<Object>()->status = new_status;
}
/// Accessor to object version
const std::string& Header::version() const {
return data<Object>()->version;
}
/// Accessor: set object version
void Header::setVersion(const std::string& new_version) {
data<Object>()->version = new_version;
}
/// Accessor to object comment
const std::string& Header::comment() const {
return data<Object>()->comment;
}
/// Accessor: set object comment
void Header::setComment(const std::string& new_comment) {
data<Object>()->comment = new_comment;
Pere Mato
committed
/// Constructor to be used when creating a new DOM tree
Constant::Constant(const string& nam, const string& val, const string& typ) {
m_element = new Object(nam, val, typ);
Pere Mato
committed
/// Constructor to be used when creating a new DOM tree
Constant::Constant(const string& nam) {
m_element = new Object(nam.c_str(), "", "number");
}
/// Access the constant
string Constant::dataType() const {
return m_element->dataType;
}
throw runtime_error("DD4hep: Attempt to access internals from invalid Constant handle!");
Pere Mato
committed
}
/// String representation of this object
string Constant::toString() const {
Pere Mato
committed
stringstream os;
os << m_element->GetName() << " \"" << m_element->GetTitle() << "\" ";
if ( m_element->dataType == "string" ) os << "Value:" << m_element->GetTitle();
else os << "Value:" << _toDouble(m_element->GetTitle());
Pere Mato
committed
return os.str();
}
/// Constructor to be used when creating a new DOM tree
Atom::Atom(const string& nam, const string& formula, int Z, int N, double density) {
Pere Mato
committed
TGeoElementTable* t = TGeoElement::GetElementTable();
TGeoElement* e = t->FindElement(nam.c_str());
t->AddElement(nam.c_str(), formula.c_str(), Z, N, density);
e = t->FindElement(nam.c_str());
Pere Mato
committed
}
m_element = e;
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/// proton number of the underlying material
double Material::Z() const {
Handle < TGeoMedium > val(*this);
if (val.isValid()) {
TGeoMaterial* m = val->GetMaterial();
if (m)
return m->GetZ();
throw runtime_error("DD4hep: The medium " + string(val->GetName()) + " has an invalid material reference!");
}
throw runtime_error("DD4hep: Attempt to access proton number from invalid material handle!");
}
/// atomic number of the underlying material
double Material::A() const {
Handle < TGeoMedium > val(*this);
if (val.isValid()) {
TGeoMaterial* m = val->GetMaterial();
if (m)
return m->GetA();
throw runtime_error("DD4hep: The medium " + string(val->GetName()) + " has an invalid material reference!");
}
throw runtime_error("DD4hep: Attempt to access atomic number from invalid material handle!");
}
/// density of the underlying material
double Material::density() const {
Handle < TGeoMedium > val(*this);
if (val.isValid()) {
TGeoMaterial* m = val->GetMaterial();
if (m)
return m->GetDensity();
throw runtime_error("DD4hep: The medium " + string(val->GetName()) + " has an invalid material reference!");
}
throw runtime_error("DD4hep: Attempt to access density from invalid material handle!");
}
Markus Frank
committed
/// Access the radiation length of the underlying material
Handle < TGeoMedium > val(*this);
if (val.isValid()) {
if (m)
return m->GetRadLen();
throw runtime_error("DD4hep: The medium " + string(val->GetName()) + " has an invalid material reference!");
throw runtime_error("DD4hep: Attempt to access radiation length from invalid material handle!");
/// Access the radiation length of the underlying material
double Material::intLength() const {
Handle < TGeoMedium > val(*this);
if (val.isValid()) {
TGeoMaterial* m = val->GetMaterial();
if (m)
return m->GetIntLen();
throw runtime_error("The medium " + string(val->GetName()) + " has an invalid material reference!");
}
throw runtime_error("Attempt to access interaction length from invalid material handle!");
}
Pere Mato
committed
/// String representation of this object
string Material::toString() const {
Handle < TGeoMedium > val(*this);
Pere Mato
committed
stringstream os;
os << val->GetName() << " " << val->GetTitle() << " id:" << hex << val->GetId() << " Pointer:" << val->GetPointerName();
Pere Mato
committed
return os.str();
/// Constructor to be used when creating a new entity
VisAttr::VisAttr(const string& nam) {
obj->color = 2;
setLineStyle (SOLID);
setDrawingStyle(SOLID);
setShowDaughters(true);
Markus Frank
committed
}
/// Constructor to be used when creating a new entity
VisAttr::VisAttr(const char* nam) {
obj->color = 2;
setLineStyle (SOLID);
setShowDaughters(true);
/// Get Flag to show/hide daughter elements
bool VisAttr::showDaughters() const {
return object<Object>().showDaughters;
}
/// Set Flag to show/hide daughter elements
void VisAttr::setShowDaughters(bool value) {
object<Object>().showDaughters = value;
/// Get visibility flag
bool VisAttr::visible() const {
}
/// Set visibility flag
void VisAttr::setVisible(bool value) {
/// Get line style
int VisAttr::lineStyle() const {
}
void VisAttr::setLineStyle(int value) {
/// Get drawing style
int VisAttr::drawingStyle() const {
return object<Object>().drawingStyle;
}
void VisAttr::setDrawingStyle(int value) {
object<Object>().drawingStyle = value;
/// Get alpha value
float VisAttr::alpha() const {
//NamedObject* obj = first_value<NamedObject>(*this);
//obj->SetAlpha(value);
}
void VisAttr::setAlpha(float value) {
//NamedObject* obj = first_value<NamedObject>(*this);
//obj->SetAlpha(value);
}
/// Get object color
}
void VisAttr::setColor(float red, float green, float blue) {
o.color = TColor::GetColor(red, green, blue);
o.col = gROOT->GetColor(o.color);
}
/// Get RGB values of the color (if valid)
bool VisAttr::rgb(float& red, float& green, float& blue) const {
if (o.col) {
TColor* c = (TColor*) o.col;
c->GetRGB(red, green, blue);
return true;
}
return false;
Pere Mato
committed
}
/// String representation of this object
string VisAttr::toString() const {
const VisAttr::Object* obj = &object<Object>();
Pere Mato
committed
TColor* col = gROOT->GetColor(obj->color);
char text[256];
::snprintf(text, sizeof(text), "%-20s RGB:%-8s [%d] %7.2f Style:%d %d ShowDaughters:%3s Visible:%3s", ptr()->GetName(),
Markus Frank
committed
col->AsHexString(), obj->color, col->GetAlpha(), int(obj->drawingStyle), int(obj->lineStyle),
yes_no(obj->showDaughters), yes_no(obj->visible));
Pere Mato
committed
return text;
/// Constructor to be used when creating a new aligment entry
AlignmentEntry::AlignmentEntry(const string& path) {
TGeoPhysicalNode* obj = new TGeoPhysicalNode(path.c_str());
}
/// Align the PhysicalNode (translation only)
int AlignmentEntry::align(const Position& pos, bool check, double overlap) {
return align(pos, RotationZYX(), check, overlap);
}
/// Align the PhysicalNode (rotation only)
int AlignmentEntry::align(const RotationZYX& rot, bool check, double overlap) {
return align(Position(), rot, check, overlap);
}
/// Align the PhysicalNode (translation + rotation)
int AlignmentEntry::align(const Position& pos, const RotationZYX& rot, bool check, double overlap) {
Markus Frank
committed
TGeoHMatrix* new_matrix = dynamic_cast<TGeoHMatrix*>(m_element->GetOriginalMatrix()->MakeClone());
TGeoRotation rotation("", rot.Phi() * RAD_2_DEGREE, rot.Theta() * RAD_2_DEGREE, rot.Psi() * RAD_2_DEGREE);
TGeoCombiTrans m(pos.X(), pos.Y(), pos.Z(), 0);
Markus Frank
committed
m.SetRotation(rotation);
new_matrix->Multiply(&m);
m_element->Align(new_matrix, 0, check, overlap);
throw runtime_error("DD4hep: Cannot align non existing physical node.");
Limit& Limit::operator=(const Limit& c) {
if (this != &c) {
name = c.name;
unit = c.unit;
value = c.value;
content = c.content;
/// Equality operator
bool Limit::operator==(const Limit& c) const {
return value == c.value && name == c.name && particles == c.particles;
bool Limit::operator<(const Limit& c) const {
if (value < c.value)
return true;
if (name < c.name)
return true;
if (particles < c.particles)
return true;
/// Conversion to a string representation
string Limit::toString() const {
string res = name + " = " + content;
if (!unit.empty())
res += unit + " ";
res + " (" + particles + ")";
return res;
}
/// Constructor to be used when creating a new DOM tree
LimitSet::LimitSet(const string& nam) {
assign(new Object(), nam, "limitset");
/// Add new limit. Returns true if the new limit was added, false if it already existed.
bool LimitSet::addLimit(const Limit& limit) {
pair<Object::iterator, bool> ret = data<Object>()->insert(limit);
return ret.second;
}
/// Accessor to limits container
Markus Frank
committed
const set<Limit>& LimitSet::limits() const {
const Object* o = data<Object>();
return *o;
}
/// Constructor to be used when creating a new DOM tree
Region::Region(const string& nam) {
Pere Mato
committed
p->magic = magic_word();
p->store_secondaries = false;
p->threshold = 10.0;
p->cut = 10.0;
Andre Sailer
committed
p->use_default_cut = true;
p->was_threshold_set = false;
Region& Region::setStoreSecondaries(bool value) {
object<Object>().store_secondaries = value;
return *this;
}
Region& Region::setThreshold(double value) {
Andre Sailer
committed
object<Object>().was_threshold_set = true;
return *this;
}
Region& Region::setCut(double value) {
Andre Sailer
committed
object<Object>().use_default_cut = false;
return *this;
}
/// Access references to user limits
vector<string>& Region::limits() const {
return object<Object>().user_limits;
}
/// Access cut value
double Region::cut() const {
}
/// Access production threshold
double Region::threshold() const {
}
/// Access secondaries flag
bool Region::storeSecondaries() const {
return object<Object>().store_secondaries;
Andre Sailer
committed
bool Region::useDefaultCut() const {
return object<Object>().use_default_cut;
}
bool Region::wasThresholdSet() const {
return object<Object>().was_threshold_set;
}
#undef setAttr
#if 0
Markus Frank
committed
/** @class IDSpec Objects.h
Markus Frank
committed
* @author M.Frank
* @version 1.0
*/
struct IDSpec : public Ref_t {
Markus Frank
committed
/// Constructor to be used when reading the already parsed DOM tree
Markus Frank
committed
IDSpec(const Handle<Q>& e) : Ref_t(e) {}
/// Constructor to be used when creating a new DOM tree
IDSpec(LCDD& doc, const std::string& name, const IDDescriptor& dsc);
void addField(const std::string& name, const std::pair<int,int>& field);
};
IDSpec::IDSpec(LCDD& lcdd, const string& name, const IDDescriptor& dsc)
Markus Frank
committed
: RefElement(doc,Tag_idspec,name)
{
const IDDescriptor::FieldIDs& f = dsc.ids();
const IDDescriptor::FieldMap& m = dsc.fields();
object<Object>().Attr_length = dsc.maxBit();
for(const auto& i : f ) {
const string& nam = i.second;
const pair<int,int>& fld = m.find(nam)->second;
addField(nam,fld);
}
}
void IDSpec::addField(const string& name, const pair<int,int>& field) {
addField(Strng_t(name),field);
}
void IDSpec::addField(const string& name, const pair<int,int>& field) {
Element e(document(),Tag_idfield);
e.object<Object>().Attr_signed = field.second<0;
e.object<Object>().Attr_label = name;
e.object<Object>().Attr_start = field.first;
e.object<Object>().Attr_length = abs(field.second);
m_element.append(e);
}
#endif