Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:16:46

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework includes
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/FieldTypes.h>
0017 #include <DD4hep/MatrixHelpers.h>
0018 #include <DD4hep/DetFactoryHelper.h>
0019 
0020 // C/C++ include files
0021 #include <cmath>
0022 
0023 using namespace dd4hep;
0024 
0025 static Handle<NamedObject> convert_constant_field(Detector&, xml_h field, Handle<NamedObject> object) {
0026   xml_doc_t doc = xml_elt_t(field).document();
0027   ConstantField* fld = object.data<ConstantField>();
0028   field.setAttr(_U(name), object->GetName());
0029   field.setAttr(_U(type), object->GetTitle());
0030   field.setAttr(_U(lunit), "mm");
0031   //field.setAttr(_U(funit),"tesla");
0032   if (fld->type == CartesianField::ELECTRIC)
0033     field.setAttr(_U(field), "electric");
0034   else if (fld->type == CartesianField::MAGNETIC)
0035     field.setAttr(_U(field), "magnetic");
0036 
0037   xml_elt_t strength = xml_elt_t(doc, _U(strength));
0038   strength.setAttr(_U(x), fld->direction.X());
0039   strength.setAttr(_U(y), fld->direction.Y());
0040   strength.setAttr(_U(z), fld->direction.Z());
0041   field.append(strength);
0042   return object;
0043 }
0044 DECLARE_XML_PROCESSOR(ConstantField_Convert2Detector,convert_constant_field)
0045 
0046 static Handle<NamedObject> convert_solenoid(Detector&, xml_h field, Handle<NamedObject> object) {
0047   char text[128];
0048   SolenoidField* fld = object.data<SolenoidField>();
0049   field.setAttr(_U(name), object->GetName());
0050   field.setAttr(_U(type), object->GetTitle());
0051   field.setAttr(_U(lunit), "mm");
0052   field.setAttr(_U(funit), "tesla");
0053   ::snprintf(text, sizeof(text), "%g/mm", fld->outerRadius);
0054   field.setAttr(_U(outer_radius), dd4hep::_toDouble(text));
0055   ::snprintf(text, sizeof(text), "%g/mm", fld->innerRadius);
0056   field.setAttr(_U(inner_radius), dd4hep::_toDouble(text));
0057   ::snprintf(text, sizeof(text), "%g/tesla", fld->innerField);
0058   field.setAttr(_U(inner_field), dd4hep::_toDouble(text));
0059   ::snprintf(text, sizeof(text), "%g/tesla", fld->outerField);
0060   field.setAttr(_U(outer_field), dd4hep::_toDouble(text));
0061   field.setAttr(_U(zmin), fld->minZ);
0062   field.setAttr(_U(zmax), fld->maxZ);
0063   return object;
0064 }
0065 DECLARE_XML_PROCESSOR(solenoid_Convert2Detector,convert_solenoid)
0066 DECLARE_XML_PROCESSOR(SolenoidMagnet_Convert2Detector,convert_solenoid)
0067 
0068 static Handle<NamedObject> convert_dipole(Detector&, xml_h field, Handle<NamedObject> object) {
0069   char text[128];
0070   xml_doc_t    doc = xml_elt_t(field).document();
0071   DipoleField* fld = object.data<DipoleField>();
0072   field.setAttr(_U(lunit), "mm");
0073   field.setAttr(_U(funit), "tesla");
0074   ::snprintf(text, sizeof(text), "%g/mm", fld->rmax);
0075   field.setAttr(_U(rmax), dd4hep::_toDouble(text));
0076   ::snprintf(text, sizeof(text), "%g/mm", fld->zmax);
0077   field.setAttr(_U(zmax), dd4hep::_toDouble(text));
0078   ::snprintf(text, sizeof(text), "%g/mm", fld->zmin);
0079   field.setAttr(_U(zmin), dd4hep::_toDouble(text));
0080   for (auto c : fld->coefficents )  {
0081     xml_elt_t coeff = xml_elt_t(doc, _U(dipole_coeff));
0082     coeff.setValue(dd4hep::_toString(c));
0083     field.append(coeff);
0084   }
0085   return object;
0086 }
0087 DECLARE_XML_PROCESSOR(DipoleMagnet_Convert2Detector,convert_dipole)
0088 //DECLARE_XML_PROCESSOR(DipoleField_Convert2Detector,convert_dipole)
0089 
0090 
0091 static Handle<NamedObject> convert_multipole(Detector&, xml_h field, Handle<NamedObject> object) {
0092   xml_doc_t       doc = xml_elt_t(field).document();
0093   MultipoleField* ptr = object.data<MultipoleField>();
0094   RotationZYX     rot;
0095   Position        pos;
0096 
0097   field.setAttr(_U(lunit), "mm");
0098   field.setAttr(_U(funit), "tesla");
0099 
0100   field.setAttr(_U(name), object->GetName());
0101   field.setAttr(_U(type), object->GetTitle());
0102   field.setAttr(_U(Z), ptr->B_z);
0103   detail::matrix::_decompose(ptr->transform, pos, rot);
0104   xml_elt_t x_pos = xml_elt_t(doc, _U(position));
0105   x_pos.setAttr(_U(x),pos.x());
0106   x_pos.setAttr(_U(y),pos.y());
0107   x_pos.setAttr(_U(z),pos.z());
0108   field.append(x_pos);
0109 
0110   xml_elt_t x_rot = xml_elt_t(doc, _U(rotation));
0111   x_pos.setAttr(_U(x),rot.Theta());
0112   x_pos.setAttr(_U(y),rot.Phi());
0113   x_pos.setAttr(_U(z),rot.Psi());
0114   field.append(x_rot);
0115   if ( ptr->volume.isValid() )  {
0116     // Disentangle shape ?
0117   }
0118 
0119   for( double c : ptr->coefficents )  {
0120     xml_dim_t x_coeff = xml_elt_t(doc, _U(coefficient));
0121     x_coeff.setAttr(_U(value),c);
0122     field.append(x_coeff);
0123   }
0124   return object;
0125 }
0126 DECLARE_XML_PROCESSOR(MultipoleMagnet_Convert2Detector,convert_multipole)