GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
FTDParametersXML.cc
1 /* C++ */
2 #include "gearxml/FTDParametersXML.h"
3 
4 #include "gearxml/XMLHandlerMgr.h"
5 #include "gearxml/GearParametersXML.h"
6 
7 #include "gearxml/tinyxml.h"
8 #include "gearimpl/FTDParametersImpl.h"
9 
10 #include "gear/GearMgr.h"
11 
12 #include <vector>
13 #include <string>
14 
15 namespace gear
16 {
18  {
19  //std::cout << "FTDParameters::toXML called" << std::endl ; //debug
20 
21  // check whether parameter is valid FTDParameter
22  const FTDParameters* param = dynamic_cast<const FTDParameters*> ( &parameters ) ;
23 
24  if( param == 0 )
25  {
26  throw Exception( "FTDParametersXML::toXML given parameters not of correct type. "
27  "needs to be gear::FTDParameters." ) ;
28  }
29  // Set up FTD-Detector as Element
30  TiXmlElement det("detector") ;
31 
32  //std::cout << "FTDParameters::toXML strType == '" << strType << "'"<< std::endl ; // debug
33 
34  // layerLayout
35  const FTDLayerLayout & ftdLayers = param->getFTDLayerLayout() ;
36  TiXmlElement layers("layers") ;
37 
38  for( int i=0 ; i < ftdLayers.getNLayers() ; i++ )
39  {
40  //std::cout << " layer #petals " << ftdLayers.getNPetals( i ) << std::endl ; //debug
41  TiXmlElement layer("layer" ) ;
42  layer.SetAttribute( "nPetals" , ftdLayers.getNPetals(i) ) ;
43  layer.SetAttribute( "nSensors" , ftdLayers.getNSensors(i) ) ;
44  layer.SetAttribute( "isDoubleSided" , ftdLayers.isDoubleSided(i) ) ;
45  std::string strType;
46  switch( (int)ftdLayers.getSensorType(i) )
47  {
48  case ( FTDParameters::PIXEL ) :
49  strType = "PIXEL";
50  break ;
51  case ( FTDParameters::STRIP ) :
52  strType = "STRIP" ;
53  break ;
54  default :
55  strType = "Unknown" ;
56  }
57  layer.SetAttribute( "sensorType", strType );
58  layer.SetDoubleAttribute( "petalOpenningAngle" , ftdLayers.getPhiHalfDistance(i) ) ;
59  layer.SetDoubleAttribute( "phi0" , ftdLayers.getPhi0(i) ) ;
60  layer.SetDoubleAttribute( "alpha" , ftdLayers.getAlpha(i) ) ;
61  layer.SetDoubleAttribute("zoffset", ftdLayers.getZoffset(i) );
62  layer.SetDoubleAttribute("zsign0", ftdLayers.getZoffsetSign0(i) );
63  layer.SetDoubleAttribute( "zposition" , ftdLayers.getZposition(i) ) ;
64 
65  TiXmlElement support("support") ;
66  //support.SetDoubleAttribute( "zposition" , ftdLayers.getSupportZposition(i) ) ;
67  support.SetDoubleAttribute( "thickness" , ftdLayers.getSupportThickness(i) ) ;
68  support.SetDoubleAttribute( "width" , ftdLayers.getSupportWidth( i ) ) ;
69  support.SetDoubleAttribute( "lengthMin" , ftdLayers.getSupportLengthMin(i) ) ;
70  support.SetDoubleAttribute( "lengthMax" , ftdLayers.getSupportLengthMax(i) ) ;
71  support.SetDoubleAttribute( "rInner" , ftdLayers.getSupportRinner( i ) ) ;
72  support.SetDoubleAttribute( "radLength" , ftdLayers.getSupportRadLength( i ) ) ;
73 
74  TiXmlElement sens("sensitive" ) ;
75  //sens.SetDoubleAttribute( "zposition" , ftdLayers.getSensitiveZposition(i) ) ;
76  sens.SetDoubleAttribute( "thickness" , ftdLayers.getSensitiveThickness( i ) ) ;
77  sens.SetDoubleAttribute( "width" , ftdLayers.getSensitiveWidth( i ) ) ;
78  sens.SetDoubleAttribute( "lengthMin" , ftdLayers.getSensitiveLengthMin( i ) ) ;
79  sens.SetDoubleAttribute( "lengthMax" , ftdLayers.getSensitiveLengthMax( i ) ) ;
80  sens.SetDoubleAttribute( "rInner" , ftdLayers.getSensitiveRinner( i ) ) ;
81  sens.SetDoubleAttribute( "radLength" , ftdLayers.getSensitiveRadLength( i ) ) ;
82 
83  // assemble layer
84  layer.InsertEndChild(support);
85  layer.InsertEndChild(sens) ;
86  layers.InsertEndChild(layer) ;
87  }
88  // assemble layers
89  det.InsertEndChild(layers) ;
90 
91  // Assemble Detector
92  GearParametersXML::getXMLForParameters( &det , &parameters ) ;
93 
94  return det ;
95  }
96 
97  GearParameters* FTDParametersXML::fromXML( const TiXmlElement* xmlElement, GearMgr* gearMgr) const
98  {
99 
100 
101 
102  // create FTDParameters
103  FTDParametersImpl* ftdParam = new FTDParametersImpl() ;
104 
105  // layers
106  const TiXmlNode* xmlLayers = xmlElement->FirstChildElement( "layers" ) ;
107  const TiXmlNode* xmlLayer = 0 ;
108 
109  while( ( xmlLayer = xmlLayers->IterateChildren( "layer" , xmlLayer ) ) != 0 )
110  {
111  int nPetals = atoi( getXMLAttribute( xmlLayer , "nPetals" ).c_str() );
112  int nSensors = atoi( getXMLAttribute( xmlLayer , "nSensors" ).c_str() );
113  bool isDoubleSided = atoi( getXMLAttribute( xmlLayer , "isDoubleSided" ).c_str() );
114  std::string type= getXMLAttribute( xmlLayer, "sensorType" );
115  int sensorType;
116  if( type == "PIXEL" )
117  {
118  sensorType = FTDParameters::PIXEL ;
119  }
120  else if( type =="STRIP" )
121  {
122  sensorType = FTDParameters::STRIP;
123  }
124  else
125  {
126  throw Exception( "FTDParametersXML::fromXML technology of sensorType not known: " + type +
127  " - Needs to be 'PIXEL' or 'STRIP'." ) ;
128  }
129  double petalOpAngle = atof( getXMLAttribute( xmlLayer , "petalOpenningAngle" ).c_str() );
130  double phi0 = atof( getXMLAttribute( xmlLayer , "phi0" ).c_str() );
131  double alpha = atof( getXMLAttribute( xmlLayer , "alpha" ).c_str() );
132  double zposition = atof( getXMLAttribute( xmlLayer , "zposition" ).c_str() );
133  double zoffset = atof( getXMLAttribute( xmlLayer , "zoffset" ).c_str() );
134  double zsign0 = atof( getXMLAttribute( xmlLayer , "zsign0" ).c_str() );
135 
136  const TiXmlNode* xmlLad = xmlLayer->FirstChildElement( "support" ) ;
137  const TiXmlNode* xmlSen = xmlLayer->FirstChildElement( "sensitive" ) ;
138 
139  //double lzposition = atof( getXMLAttribute( xmlLad , "zposition" ).c_str() );
140  double lThick = atof( getXMLAttribute( xmlLad , "thickness" ).c_str() );
141  double lWidth = atof( getXMLAttribute( xmlLad , "width" ).c_str() ) ;
142  double lLengthMin = atof( getXMLAttribute( xmlLad , "lengthMin" ).c_str() ) ;
143  double lLengthMax = atof( getXMLAttribute( xmlLad , "lengthMax" ).c_str() ) ;
144  double lRinner = atof( getXMLAttribute( xmlLad , "rInner" ).c_str() ) ;
145  double lRadLen = atof( getXMLAttribute( xmlLad , "radLength" ).c_str() ) ;
146 
147  //double szposition = atof( getXMLAttribute( xmlSen ,"zposition" ).c_str() );
148  double sThick = atof( getXMLAttribute( xmlSen , "thickness" ).c_str() ) ;
149  double sWidth = atof( getXMLAttribute( xmlSen , "width" ).c_str() ) ;
150  double sLengthMin = atof( getXMLAttribute( xmlSen , "lengthMin" ).c_str() ) ;
151  double sLengthMax = atof( getXMLAttribute( xmlSen , "lengthMax" ).c_str() ) ;
152  double sRinner = atof( getXMLAttribute( xmlSen , "rInner" ).c_str() ) ;
153  double sRadLen = atof( getXMLAttribute( xmlSen , "radLength" ).c_str() ) ;
154 
155  ftdParam->addLayer( nPetals, nSensors, isDoubleSided, sensorType, petalOpAngle, phi0 ,alpha, zposition, zoffset, zsign0,
156  //lzposition,
157  lRinner, lThick, lLengthMin, lLengthMax, lWidth, lRadLen,
158  //szposition,
159  sRinner, sThick, sLengthMin, sLengthMax, sWidth, sRadLen ) ;
160  } // end loop
161 
162 
163  // now read the generic parameters
164  GearParametersXML::setParametersFromXML( xmlElement, ftdParam ) ;
165 
166 
167  // ------- add to GearMgr ----
168  if( gearMgr != 0 )
169  {
170  gearMgr->setFTDParameters( ftdParam ) ;
171 
172  }
173 
174  return ftdParam ;
175  } // fromXML
176 
177 } // namespace
178 
179 
virtual double getSupportLengthMax(int layerIndex) const =0
The length (x-direction) of the largest edge of the trapezoid support in layer layerIndex - layer ind...
virtual double getZoffsetSign0(const int &layerIndex) const =0
Z-offset sign of the petal 0 in a staggered setup - the z position of the petals is zposition + zsign...
virtual double getSensitiveThickness(int layerIndex) const =0
The thickness in mm of the sensitive area in petals in layer layerIndex.
virtual double getSupportRinner(int layerIndex) const =0
The R-min of the support petals in the XY-plane in mm, for the layer layerIndex - layer indexing star...
Base exception class for GEAR - all other exceptions extend this.
Definition: GEAR.h:41
virtual double getPhi0(const int &layerIndex) const =0
Azimuthal angle of the first petal (angle between petal centroid and x-axis for the petal indexed as ...
virtual double getSupportLengthMin(int layerIndex) const =0
The length (x-direction) of the smallest edge of the trapezoid support in layer layerIndex - layer in...
virtual double getZposition(const int &layerIndex) const =0
The z-position of the centroid of the disk structure.
virtual int getNSensors(int layerIndex) const =0
The number of sensors per petal on a specific layer - Sensor indexing is defined as follows: (illustr...
virtual double getSupportThickness(int layerIndex) const =0
The thickness in mm of the supports in layerIndex - layer indexing starting at 0 for the layer closes...
static void setParametersFromXML(const TiXmlElement *xmlElement, GearParametersImpl *gearParams)
Static helper function that can be used by other subclass handlers to read parameters.
virtual int getSensorType(int layerIndex) const =0
The sensor type of the disk: pixel or micro-strip The return value corresponds to the following value...
virtual double getPhiHalfDistance(int layerIndex) const =0
Angular half-width of the petals of a layer - half of the opening angle of the trapezoid.
virtual int getNPetals(int layerIndex) const =0
The number of petals in the layer layerIndex - layer indexing starts at 0 for the layer closest to IP...
Abstract interface for a set of parameters that can be used to describe the geometrical properties of...
Abstract description of layers in a FTD detector.
virtual void addLayer(int nPetals, int nSensors, bool isDoubleSided, int sensorType, double petalOpAngle, double phi0, double alpha, double zposition, double zoffset, double zsign0, double supportRinner, double supportThickness, double supportLengthMin, double supportLengthMax, double supportWidth, double supportRadLength, double sensitiveRinner, double sensitiveThickness, double sensitiveLengthMin, double sensitiveLengthMax, double sensitiveWidth, double sensitiveRadLength)
adding a Layer to the vertex one layer consists of a number of petals and sensitive areas (nPetals) t...
static void getXMLForParameters(TiXmlElement *xmlElement, const GearParameters *gearParams)
Static helper function that can be used by other subclass handlers to create XML for parameters...
virtual double getZoffset(const int &layerIndex) const =0
Z-offset of the petals in a staggered setup - the z position of the even numbered petals is getZposit...
virtual void setFTDParameters(FTDParameters *ftdParameters)=0
Set the FTDParameters.
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:370
virtual const FTDLayerLayout & getFTDLayerLayout() const =0
The layer layout in the Vertex.
virtual double getSensitiveLengthMax(int layerIndex) const =0
Same as getPetalLengthMax() except for the sensitive part of the petal.
virtual double getSensitiveLengthMin(int layerIndex) const =0
Same as getPetalLengthMin() except for the sensitive part of the petal.
std::string getXMLAttribute(const TiXmlNode *node, const std::string &name)
Helper method used for parsing XML.
virtual double getSensitiveRadLength(int layerIndex) const =0
The radiation length in sensitive volumes in layer layerIndex - layer indexing starts at 0 for the la...
virtual double getAlpha(int layerIndex) const =0
Angle of rotation in the own plane of a petal in a tilted configuration.
Geometry properties of a FTD detector needed for reconstruction code.
Definition: FTDParameters.h:29
Geometry properties of a FTD detector needed for reconstruction code.
The element is a container class.
Definition: tinyxml.h:827
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cc:218
virtual double getSupportWidth(int layerIndex) const =0
The width of the support in layer in mm for petals in layer layerIndex - layer indexing starting at 0...
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
Definition: tinyxml.cc:738
virtual int getNLayers() const =0
The total number of layers.
virtual TiXmlElement toXML(const GearParameters &parameters) const
Creates an XML node for the given parameters.
Abstract interface for a manager class that returns the Gear classes for the relevant subdetectors...
Definition: GearMgr.h:36
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
Definition: tinyxml.cc:376
void SetAttribute(const char *name, const char *value)
Sets an attribute of name to a given value.
Definition: tinyxml.cc:746
virtual double getSensitiveWidth(int layerIndex) const =0
The width of the sensitive area in petals in layer layerIndex in mm.
virtual double getSensitiveRinner(int layerIndex) const =0
The R-min of the petal in the XY-plane in mm for sensors in layer layerIndex - layer indexing starts ...
virtual bool isDoubleSided(int layerIndex) const =0
Whether the petals on a layer have sensors in front and back.
virtual GearParameters * fromXML(const TiXmlElement *xmlElement, GearMgr *gearMgr=0) const
Creates the appropriate GearParameters subclass from the given XML element (node) ...
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cc:482
virtual double getSupportRadLength(int layerIndex) const =0
The radiation length in the support structure petals of layer layerIndex - layer indexing starts at 0...