GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
TrackerPlanesParametersXML.cc
1 #include "gearxml/TrackerPlanesParametersXML.h"
2 
3 #include "gearxml/XMLHandlerMgr.h"
4 #include "gearxml/GearParametersXML.h"
5 
6 #include "gearxml/tinyxml.h"
7 #include "gearimpl/TrackerPlanesParametersImpl.h"
8 
9 #include "gear/GearMgr.h"
10 
11 #include <iostream>
12 #include <vector>
13 #include <string>
14 
15 
16 #include <cstring>
17 
24 using namespace gear;
25 
26 namespace gear {
27 
29 
30 
31  // check whether parameter is valid TrackerPlanesParameter
32  const TrackerPlanesParameters* param = dynamic_cast<const TrackerPlanesParameters*> ( &parameters ) ;
33 
34  if( param == 0 ) {
35 
36  throw Exception( "TrackerPlanesParametersXML::toXML given parameters not of correct type. "
37  "needs to be gear::TrackerPlanesParameters." ) ;
38  }
39 
40  // Set up Beam telescope as Element
41  TiXmlElement det("detector") ;
42 
43  TiXmlElement setup_id( "LayoutID" ) ;
44  setup_id.SetAttribute("ID", param->getLayoutID()) ;
45  det.InsertEndChild( setup_id ) ;
46 
47 
48  TiXmlElement nplanes( "LayoutNumberOfLayers" ) ;
49  nplanes.SetAttribute("number", param->getLayoutNumberOfLayers()) ;
50  det.InsertEndChild( nplanes ) ;
51 
52  // layerLayout
53  const TrackerPlanesLayerLayout& trackerplanesLayerLayout = param->getTrackerPlanesLayerLayout() ;
54 
55  TiXmlElement layers("layers") ;
56 
57  for( int il=0 ; il < trackerplanesLayerLayout.getNLayers() ; il++ ) {
58  TiXmlElement xmlLayer("layer" ) ;
59 
60  TrackerPlanesLayerImpl* layer = const_cast<gear::TrackerPlanesLayerImpl* > (trackerplanesLayerLayout.getLayer(il));
61  if( layer == 0 ) continue;
62 
63  TrackerPlanesMaterialLayerImplVec& material = layer->getMaterialLayerVec();
64 
65  TrackerPlanesSensitiveLayerImplVec& sensitive = layer->getSensitiveLayerVec();
66 
67  for( unsigned i=0 ; i < material.size() ; i++ ) {
68  TrackerPlanesMaterialLayerImpl& ladder = material.at(i);
69 
70  TiXmlElement xmlLadder("ladder") ;
71  xmlLadder.SetAttribute( "ID" , ladder.getID() ) ;
72  xmlLadder.SetAttribute( "info" , ladder.getInfo() ) ;
73  xmlLadder.SetDoubleAttribute( "positionX" , ladder.getPositionX() ) ;
74  xmlLadder.SetDoubleAttribute( "positionY" , ladder.getPositionY() ) ;
75  xmlLadder.SetDoubleAttribute( "positionZ" , ladder.getPositionZ() ) ;
76  xmlLadder.SetDoubleAttribute( "rotationXY" , ladder.getRotationXY() ) ;
77  xmlLadder.SetDoubleAttribute( "rotationZX" , ladder.getRotationZX() ) ;
78  xmlLadder.SetDoubleAttribute( "rotationZY" , ladder.getRotationZY() ) ;
79  xmlLadder.SetDoubleAttribute( "sizeX" , ladder.getSizeX() ) ;
80  xmlLadder.SetDoubleAttribute( "sizeY" , ladder.getSizeY() ) ;
81  xmlLadder.SetDoubleAttribute( "thickness" , ladder.getThickness() ) ;
82  xmlLadder.SetDoubleAttribute( "radLength" , ladder.getRadLength() ) ;
83 
84  xmlLayer.InsertEndChild( xmlLadder ) ;
85  }
86 
87 
88  for( unsigned i=0 ; i < sensitive.size() ; i++ ) {
89  TrackerPlanesSensitiveLayerImpl& sensor = sensitive.at(i);
90 
91  TiXmlElement xmlSensor("sensitive" ) ;
92  xmlSensor.SetAttribute( "ID" , sensor.getID() ) ;
93  xmlSensor.SetAttribute( "info" , sensor.getInfo() ) ;
94  xmlSensor.SetDoubleAttribute( "positionX" , sensor.getPositionX() ) ;
95  xmlSensor.SetDoubleAttribute( "positionY" , sensor.getPositionY() ) ;
96  xmlSensor.SetDoubleAttribute( "positionZ" , sensor.getPositionZ() ) ;
97  xmlSensor.SetDoubleAttribute( "rotationXY" , sensor.getRotationXY() ) ;
98  xmlSensor.SetDoubleAttribute( "rotationZX" , sensor.getRotationZX() ) ;
99  xmlSensor.SetDoubleAttribute( "rotationZY" , sensor.getRotationZY() ) ;
100  xmlSensor.SetDoubleAttribute( "sizeX" , sensor.getSizeX() ) ;
101  xmlSensor.SetDoubleAttribute( "sizeY" , sensor.getSizeY() ) ;
102  xmlSensor.SetDoubleAttribute( "thickness" , sensor.getThickness() ) ;
103  xmlSensor.SetAttribute( "npixelX" , sensor.getNpixelX() ) ;
104  xmlSensor.SetAttribute( "npixelY" , sensor.getNpixelY() ) ;
105  xmlSensor.SetDoubleAttribute( "pitchX" , sensor.getPitchX() ) ;
106  xmlSensor.SetDoubleAttribute( "pitchY" , sensor.getPitchY() ) ;
107  xmlSensor.SetDoubleAttribute( "resolutionX" , sensor.getResolutionX() ) ;
108  xmlSensor.SetDoubleAttribute( "resolutionY" , sensor.getResolutionY() ) ;
109  xmlSensor.SetDoubleAttribute( "radLength" , sensor.getRadLength() ) ;
110 
111  xmlLayer.InsertEndChild( xmlSensor ) ;
112  }
113 
114  det.InsertEndChild( xmlLayer ) ;
115  }
116 
117  // Assemble Detector
118  GearParametersXML::getXMLForParameters( &det , &parameters ) ;
119 
120  return det ;
121 
122  }
123 
125 
126  // setup ID
127 
128  const TiXmlElement* trackerplanesID = xmlElement->FirstChildElement( "LayoutID" ) ;
129  int setupID = atoi( getXMLAttribute( trackerplanesID , "ID" ).c_str() ) ;
130 
131  int intType = 0;
132 
133  const TiXmlElement* trackerplanesNumber = xmlElement->FirstChildElement( "LayoutNumberOfLayers" ) ;
134  int nplanes = atoi( getXMLAttribute( trackerplanesNumber , "number" ).c_str() ) ;
135 
136 
137  // create TrackerPlanesParameters
138  TrackerPlanesParametersImpl* trackerplanesParam = new TrackerPlanesParametersImpl( setupID, intType , nplanes) ;
139 
140  // layers
141  const TiXmlNode* xmlLayers = xmlElement->FirstChildElement( "layers" ) ;
142 
143  const TiXmlNode* xmlLayer = 0 ;
144  while( ( xmlLayer = xmlLayers->IterateChildren( "layer" , xmlLayer ) ) != 0 ) {
145 
147 
148  int layerID = atoi( getXMLAttribute( xmlLayer, "ID" ).c_str() ) ;
149  std::cout << " layer ID " << layerID << std::endl;
150  layerImpl->setID( layerID ) ;
151 
152  std::string infoLayer = getOptionalXMLAttribute( xmlLayer, "info", "" ).c_str() ;
153  std::cout << " layer Info " << infoLayer << std::endl;
154  layerImpl->setInfo( infoLayer ) ;
155 
156  const TiXmlNode* xmlLad = 0 ;
157  while( ( xmlLad = xmlLayer->IterateChildren( "ladder" , xmlLad ) ) != 0 ) {
158 
159  int lID = atoi( getXMLAttribute( xmlLad , "ID" ).c_str() ) ;
160  std::string lInfo = getOptionalXMLAttribute( xmlLad, "info", "" ).c_str() ;
161  double lPosX = atof( getOptionalXMLAttribute( xmlLad , "positionX", "0." ).c_str() ) ;
162  double lPosY = atof( getOptionalXMLAttribute( xmlLad , "positionY", "0." ).c_str() ) ;
163  double lPosZ = atof( getOptionalXMLAttribute( xmlLad , "positionZ", "0." ).c_str() ) ;
164  double lRotXY = atof( getOptionalXMLAttribute( xmlLad , "rotationXY", "0." ).c_str() ) ;
165  double lRotZX = atof( getOptionalXMLAttribute( xmlLad , "rotationZX", "0." ).c_str() ) ;
166  double lRotZY = atof( getOptionalXMLAttribute( xmlLad , "rotationZY", "0." ).c_str() ) ;
167  double lSizX = atof( getOptionalXMLAttribute( xmlLad , "sizeX", "1." ).c_str() ) ;
168  double lSizY = atof( getOptionalXMLAttribute( xmlLad , "sizeY", "1." ).c_str() ) ;
169  double lThick = atof( getOptionalXMLAttribute( xmlLad , "thickness", "0.0" ).c_str() ) ;
170  double lRadLen = atof( getOptionalXMLAttribute( xmlLad , "radLength", "0.0" ).c_str() ) ;
171 
172  std::cout << " material layer ID " << lID << std::endl;
173 
174  layerImpl->addMaterialLayer( lID, lInfo, lPosX, lPosY, lPosZ, lRotXY, lRotZX, lRotZY, lSizX, lSizY, lThick, lRadLen);
175  }
176 
177  const TiXmlNode* xmlSen = 0 ;
178  while( ( xmlSen = xmlLayer->IterateChildren( "sensitive" , xmlSen ) ) != 0 ) {
179 
180  int sID = atoi( getXMLAttribute( xmlSen , "ID" ).c_str() ) ;
181  std::string sInfo = getOptionalXMLAttribute( xmlSen, "info", "" ).c_str() ;
182  double sPosX = atof( getOptionalXMLAttribute( xmlSen , "positionX", "0." ).c_str() ) ;
183  double sPosY = atof( getOptionalXMLAttribute( xmlSen , "positionY", "0." ).c_str() ) ;
184  double sPosZ = atof( getOptionalXMLAttribute( xmlSen , "positionZ", "0." ).c_str() ) ;
185  double sRotXY = atof( getOptionalXMLAttribute( xmlSen , "rotationXY", "0." ).c_str() ) ;
186  double sRotZX = atof( getOptionalXMLAttribute( xmlSen , "rotationZX", "0." ).c_str() ) ;
187  double sRotZY = atof( getOptionalXMLAttribute( xmlSen , "rotationZY", "0." ).c_str() ) ;
188  double sSizX = atof( getOptionalXMLAttribute( xmlSen , "sizeX", "1." ).c_str() ) ;
189  double sSizY = atof( getOptionalXMLAttribute( xmlSen , "sizeY", "1." ).c_str() ) ;
190  double sThick = atof( getOptionalXMLAttribute( xmlSen , "thickness", "0." ).c_str() ) ;
191  double sRadLen = atof( getOptionalXMLAttribute( xmlSen , "radLength", "0." ).c_str() ) ;
192 
193  int sNPixX = atoi(getOptionalXMLAttribute( xmlSen , "npixelX", "1" ).c_str() ) ;
194  int sNPixY = atoi(getOptionalXMLAttribute( xmlSen , "npixelY", "1" ).c_str() ) ;
195  double sPitX = atof(getOptionalXMLAttribute( xmlSen , "pitchX", "0." ).c_str() ) ;
196  double sPitY = atof(getOptionalXMLAttribute( xmlSen , "pitchY", "0." ).c_str() ) ;
197  double sResolX = atof(getOptionalXMLAttribute( xmlSen , "resolutionX", "0." ).c_str() ) ;
198  double sResolY = atof(getOptionalXMLAttribute( xmlSen , "resolutionY", "0." ).c_str() ) ;
199  std::cout << " sensitive layer ID " << sID << std::endl;
200 
201  layerImpl->addSensitiveLayer( sID, sInfo, sPosX, sPosY, sPosZ, sRotXY, sRotZX, sRotZY, sSizX, sSizY, sThick, sRadLen, sNPixX, sNPixY, sPitX, sPitY, sResolX, sResolY);
202  }
203 
204  trackerplanesParam->addLayer( layerImpl ) ; // ? many scattering ladders and multi sensitive scructure -> double layer?
205 
206  } // end loop
207 
208 
209 
210  // now read the generic parameters
211  GearParametersXML::setParametersFromXML( xmlElement, trackerplanesParam ) ;
212 
213  // ------- add to GearMgr ----
214  if( gearMgr != 0 ) {
215 
216  gearMgr->setTrackerPlanesParameters( trackerplanesParam ) ;
217 
218  }
219 
220  return trackerplanesParam ;
221 
222  } // fromXML
223 
224 } // namespace
225 
226 
virtual int getID() const
ID of sensitive volume of layer layerIndex - layer indexing starts at 0 for the layer closest to the ...
virtual GearParameters * fromXML(const TiXmlElement *xmlElement, GearMgr *gearMgr=0) const
Creates the appropriate GearParameters subclass from the given XML element (node) ...
virtual double getRotationXY() const
rotation angles according to Euler implementation scheme (in XY plane -&gt; around axis Z: gamma ) ...
virtual double getResolutionY() const
Intrinsic resolution of layer layerIndex - layer indexing starts at 0 for the layer closest to the be...
std::string getOptionalXMLAttribute(const TiXmlNode *node, const std::string &name, const std::string &defaultValue)
Helper method used for parsing XML.
virtual const TrackerPlanesLayerLayout & getTrackerPlanesLayerLayout() const =0
The layer layout of pixel beam telescope.
virtual int getNpixelX() const
Number of pixels in x direction in sensitive volume of layer layerIndex - layer indexing starts at 0 ...
Base exception class for GEAR - all other exceptions extend this.
Definition: GEAR.h:41
virtual double getRotationZX() const
rotation angles according to Euler implmentation scheme (in ZX plane -&gt; around axis Y: beta ) ...
virtual const TrackerPlanesLayerImpl * getLayer(unsigned int ID) const =0
a free parameter string field
virtual double getSizeY() const
Size in y direction of sensitive volume of layer layerIndex - layer indexing starts at 0 for the laye...
virtual double getPositionZ() const
z position of the center of sensitive volume of layer layerIndex - layer indexing starts at 0 for the...
virtual double getRotationZY() const
rotation angles according to Euler implmentation scheme (in ZY plane -&gt; around axis X: alfa ) ...
virtual double getSizeX() const
Size in x direction of sensitive volume of layer layerIndex - layer indexing starts at 0 for the laye...
virtual double getSizeY() const
Size in y direction of nonsensitive volume of layer layerIndex - layer indexing starts at 0 for the l...
virtual double getPositionY() const
y position of the center of nonsensitive volume of layer layerIndex - layer indexing starts at 0 for ...
virtual void addMaterialLayer(int ID, std::string info, double PositionX, double PositionY, double PositionZ, double RotationXY, double RotationZX, double RotationZY, double SizeX, double SizeY, double Thickness, double RadLength)
add methods
static void setParametersFromXML(const TiXmlElement *xmlElement, GearParametersImpl *gearParams)
Static helper function that can be used by other subclass handlers to read parameters.
virtual void setTrackerPlanesParameters(TrackerPlanesParameters *trackerplanesParameters)=0
Set the TrackerPlanesParameters.
virtual double getThickness() const
Thickness of nonsensitive volume of layer layerIndex - layer indexing starts at 0 for the layer close...
Abstract interface for a set of parameters that can be used to describe the geometrical properties of...
virtual int getLayoutID() const =0
ID of telescope setup.
Abstract description of layers in pixel beam telescope.
virtual double getPositionZ() const
z position of the center of nonsensitive volume of layer layerIndex - layer indexing starts at 0 for ...
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 getRotationZX() const
rotation angles according to Euler implmentation scheme (in ZX plane -&gt; around axis Y: beta ) ...
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:370
virtual void setInfo(std::string value)
get methods
virtual double getPositionX() const
x position of the center of sensitive volume of layer layerIndex - layer indexing starts at 0 for the...
std::string getXMLAttribute(const TiXmlNode *node, const std::string &name)
Helper method used for parsing XML.
virtual double getResolutionX() const
Intrinsic resolution of layer layerIndex - layer indexing starts at 0 for the layer closest to the be...
TrackerPlanesSensitiveLayerImplVec & getSensitiveLayerVec()
get methods
virtual int getNpixelY() const
Number of pixels in y direction in sensitive volume of layer layerIndex - layer indexing starts at 0 ...
virtual void addSensitiveLayer(int ID, std::string info, double PositionX, double PositionY, double PositionZ, double RotationXY, double RotationZX, double RotationZY, double SizeX, double SizeY, double Thickness, double RadLength, int NpixelX, int NpixelY, double PitchX, double PitchY, double ResolutionX, double ResolutionY)
add methods
virtual double getRotationZY() const
rotation angles according to Euler implmentation scheme (in ZY plane -&gt; around axis X: alfa ) ...
The element is a container class.
Definition: tinyxml.h:827
virtual double getPositionY() const
y position of the center of sensitive volume of layer layerIndex - layer indexing starts at 0 for the...
virtual double getSizeX() const
Size in x direction of nonsensitive volume of layer layerIndex - layer indexing starts at 0 for the l...
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cc:218
virtual double getRadLength() const
The radiation length of sensitive volume of layer layerIndex - layer indexing starts at 0 for the lay...
virtual double getPositionX() const
x position of the center of nonsensitive volume of layer layerIndex - layer indexing starts at 0 for ...
virtual int getLayoutNumberOfLayers() const =0
Number of telescope planes of TrackerPlanes detector.
virtual double getRotationXY() const
rotation angles according to Euler implementation scheme (in XY plane -&gt; around axis Z: gamma ) ...
virtual int getNLayers() const =0
The total number of layers.
Abstract description of layers in pixel beam telescope.
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
Definition: tinyxml.cc:738
virtual double getPitchY() const
Pitch size in y direction in sensitive volume of layer layerIndex - layer indexing starts at 0 for th...
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
virtual void addLayer(TrackerPlanesLayerImpl *_layer)
Adding a Layer to the TrackerPlanes detector (without parameters for layer rotation) ...
void SetAttribute(const char *name, const char *value)
Sets an attribute of name to a given value.
Definition: tinyxml.cc:746
Geometry properties of a pixel beam telescope needed for reconstruction code.
virtual double getRadLength() const
The radiation length of nonsensitive volume of layer layerIndex - layer indexing starts at 0 for the ...
virtual double getPitchX() const
Pitch size in x direction in sensitive volume of layer layerIndex - layer indexing starts at 0 for th...
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cc:482
virtual void setID(int value)
set methods
TrackerPlanesMaterialLayerImplVec & getMaterialLayerVec()
get methods
virtual double getThickness() const
Thickness of sensitive volume of layer layerIndex - layer indexing starts at 0 for the layer closest ...
virtual TiXmlElement toXML(const GearParameters &parameters) const
Creates an XML node for the given parameters.