GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
ZPlanarParametersXML.cc
1 #include "gearxml/ZPlanarParametersXML.h"
2 
3 #include "gearxml/XMLHandlerMgr.h"
4 #include "gearxml/GearParametersXML.h"
5 
6 #include "gearxml/tinyxml.h"
7 #include "gearimpl/ZPlanarParametersImpl.h"
8 
9 #include "gear/GearMgr.h"
10 
11 #include <vector>
12 #include <string>
13 #include <algorithm>
14 
15 namespace gear {
16 
18 
19  //std::cout << "ZPlanarParameters::toXML called" << std::endl ; //debug
20 
21  // check whether parameter is a valid ZPlanarParameter
22  const ZPlanarParameters* param = dynamic_cast<const ZPlanarParameters*> ( &parameters ) ;
23 
24  if( param == 0 ) {
25 
26  throw Exception( "ZPlanarParametersXML::toXML given parameters not of correct type. "
27  "needs to be gear::ZPlanarParameters." ) ;
28  }
29 
30  // Set up VXD-Detector as Element
31  TiXmlElement det("detector") ;
32 
33  //type
34  TiXmlElement type( "type" ) ;
35  std::string strType ;
36  switch( param->getType() ) {
37 
38  case ( ZPlanarParameters::CCD ) :
39  strType = "CCD" ;
40  break ;
41 
42  case ( ZPlanarParameters::CMOS ) :
43  strType = "CMOS" ;
44  break ;
45 
46  case ( ZPlanarParameters::HYBRID ) :
47  strType = "HYBRID" ;
48  break ;
49 
50  default :
51  strType = "Unknown" ;
52 
53  }
54 
55  type.SetAttribute( "technology", strType ) ;
56 
57  det.InsertEndChild( type ) ;
58 
59  //std::cout << "ZPlanarParameters::toXML strType == '" << strType << "'"<< std::endl ; // debug
60 
61  // shell
62  // std::cout << "ZPlanarParameters::toXML shell " << std::endl ; // debug
63  // std::cout << " halflength " << param->getShellHalfLength() << std::endl ; //debug
64  // std::cout << " gap " << param ->getShellGap() << std::endl ; // debug
65  // std::cout << " innerR " << param->getShellInnerRadius() << std::endl ; //debug
66  // std::cout << " outerR " << param->getShellOuterRadius() << std::endl ; //debug
67  // std::cout << " radLen " << param->getShellRadLength() << std::endl ; //debug
68 
69  TiXmlElement shell( "shell" ) ;
70  shell.SetDoubleAttribute( "halfLength" , param->getShellHalfLength() ) ;
71  shell.SetDoubleAttribute( "gap" , param->getShellGap() ) ;
72  shell.SetDoubleAttribute( "innerRadius" , param->getShellInnerRadius() ) ;
73  shell.SetDoubleAttribute( "outerRadius" , param->getShellOuterRadius() ) ;
74  shell.SetDoubleAttribute( "radLength" , param->getShellRadLength() ) ;
75  det.InsertEndChild( shell ) ;
76 
77  // layerLayout
78  const ZPlanarLayerLayout& layout = param->getZPlanarLayerLayout() ;
79  TiXmlElement layers("layers") ;
80 
81  for( int i=0 ; i < layout.getNLayers() ; i++ ) {
82 
83  //std::cout << " layer #ladders " << layout.getNLadders( i ) << std::endl ; //debug
84 
85  TiXmlElement layer("layer" ) ;
86  layer.SetAttribute( "nLadders" , layout.getNLadders( i ) ) ;
87  layer.SetDoubleAttribute( "phi0" , layout.getPhi0( i ) ) ;
88 
89  TiXmlElement ladder("ladder") ;
90  ladder.SetDoubleAttribute( "distance" , layout.getLadderDistance( i ) ) ;
91  ladder.SetDoubleAttribute( "thickness" , layout.getLadderThickness( i ) ) ;
92  ladder.SetDoubleAttribute( "width" , layout.getLadderWidth( i ) ) ;
93  ladder.SetDoubleAttribute( "length" , layout.getLadderLength( i ) ) ;
94  ladder.SetDoubleAttribute( "offset" , layout.getLadderOffset( i ) ) ;
95  ladder.SetDoubleAttribute( "radLength" , layout.getLadderRadLength( i ) ) ;
96 
97  TiXmlElement sens("sensitive" ) ;
98  sens.SetDoubleAttribute( "distance" , layout.getSensitiveDistance( i ) ) ;
99  sens.SetDoubleAttribute( "thickness" , layout.getSensitiveThickness( i ) ) ;
100  sens.SetDoubleAttribute( "width" , layout.getSensitiveWidth( i ) ) ;
101  sens.SetDoubleAttribute( "length" , layout.getSensitiveLength( i ) ) ;
102  sens.SetDoubleAttribute( "offset" , layout.getSensitiveOffset( i ) ) ;
103  sens.SetDoubleAttribute( "radLength" , layout.getSensitiveRadLength( i ) ) ;
104 
105  // assemble layer
106  layer.InsertEndChild(ladder);
107  layer.InsertEndChild(sens) ;
108  layers.InsertEndChild(layer) ;
109 
110  }
111 
112  // assemble layers
113  det.InsertEndChild(layers) ;
114 
115  // Assemble Detector
116  GearParametersXML::getXMLForParameters( &det , &parameters ) ;
117 
118  return det ;
119 
120  }
121 
122  GearParameters* ZPlanarParametersXML::fromXML( const TiXmlElement* xmlElement, GearMgr* gearMgr) const {
123 
124  // type
125 
126  const TiXmlElement* typeEle = 0 ;
127 
128  typeEle = xmlElement->FirstChildElement( "type" ) ;
129 
130  if( typeEle == 0 ) // old file with VXDParameters
131  typeEle = xmlElement->FirstChildElement( "vxdType" ) ;
132 
133 
134  int intType = 0 ;
135 
136  std::string type = getXMLAttribute( typeEle , "technology" ) ;
137 
138  //const char* strType = type.c_str() ;
139 
140  //std::cout << "ZPlanarParameters::fromXML vxdType == '" << strType << "'"
141  // << " string: " << type << std::endl ; // debug
142 
143  if( type == "CCD" ) {
144  intType = ZPlanarParameters::CCD ;
145  }
146  else if( type =="CMOS" ) {
147  intType = ZPlanarParameters::CMOS ;
148  }
149  else if( type == "HYBRID" ) {
150  intType = ZPlanarParameters::HYBRID ;
151  }
152  else{
153  throw Exception( "ZPlanarParametersXML::fromXML technology of vxdType not known: " + type +
154  " - Needs to be 'CCD', 'CMOS' or 'HYBRID'." ) ;
155  }
156 
157  const TiXmlElement* shell = xmlElement->FirstChildElement( "shell" ) ;
158 
159  double shellHalfLength = atof( getXMLAttribute( shell , "halfLength" ) .c_str() ) ;
160  double shellGap = atof( getXMLAttribute( shell , "gap" ) . c_str() ) ;
161  double shellInnerR = atof( getXMLAttribute( shell , "innerRadius" ) .c_str() ) ;
162  double shellOuterR = atof( getXMLAttribute( shell , "outerRadius" ) .c_str() ) ;
163  double shellRadLen = atof( getXMLAttribute( shell , "radLength" ) .c_str() ) ;
164 
165  // create VDXParameters
166  ZPlanarParametersImpl* param = new ZPlanarParametersImpl( intType , shellInnerR , shellOuterR , shellHalfLength , shellGap , shellRadLen ) ;
167 
168  // layers
169  const TiXmlNode* xmlLayers = xmlElement->FirstChildElement( "layers" ) ;
170  const TiXmlNode* xmlLayer = 0 ;
171 
172  while( ( xmlLayer = xmlLayers->IterateChildren( "layer" , xmlLayer ) ) != 0 ) {
173 
174  int nLadders = atoi( getXMLAttribute( xmlLayer , "nLadders" ).c_str() ) ;
175  double phi0 = atof( getXMLAttribute( xmlLayer , "phi0" ).c_str() ) ;
176 
177  const TiXmlNode* xmlLad = xmlLayer->FirstChildElement( "ladder" ) ;
178  const TiXmlNode* xmlSen = xmlLayer->FirstChildElement( "sensitive" ) ;
179 
180  double lDist = atof( getXMLAttribute( xmlLad , "distance" ).c_str() ) ;
181  double lThick = atof( getXMLAttribute( xmlLad , "thickness" ).c_str() ) ;
182  double lWidth = atof( getXMLAttribute( xmlLad , "width" ).c_str() ) ;
183  double lLength = atof( getXMLAttribute( xmlLad , "length" ).c_str() ) ;
184  double lOffset = atof( getXMLAttribute( xmlLad , "offset" ).c_str() ) ;
185  double lRadLen = atof( getXMLAttribute( xmlLad , "radLength" ).c_str() ) ;
186 
187  double sDist = atof( getXMLAttribute( xmlSen , "distance" ).c_str() ) ;
188  double sThick = atof( getXMLAttribute( xmlSen , "thickness" ).c_str() ) ;
189  double sWidth = atof( getXMLAttribute( xmlSen , "width" ).c_str() ) ;
190  double sLength = atof( getXMLAttribute( xmlSen , "length" ).c_str() ) ;
191  double sOffset = atof( getXMLAttribute( xmlSen , "offset" ).c_str() ) ;
192  double sRadLen = atof( getXMLAttribute( xmlSen , "radLength" ).c_str() ) ;
193 
194  param->addLayer( nLadders, phi0 ,
195  lDist, lOffset, lThick, lLength, lWidth, lRadLen,
196  sDist, sOffset, sThick, sLength, sWidth, sRadLen ) ;
197 
198  } // end loop
199 
200 
201  // now read the generic parameters
202  GearParametersXML::setParametersFromXML( xmlElement, param ) ;
203 
204 
205  //--------- add to proper section in GearMgr ----
206  if( gearMgr != 0 ) {
207 
208  std::string detName = getXMLAttribute( xmlElement , "name" ) ;
209 
210 
211  std::transform( detName.begin() , detName.end() ,
212  detName.begin(), tolower ) ;
213 
214 
215  if( detName.find("vxd") != std::string::npos ){
216 
217  gearMgr->setVXDParameters( param ) ;
218  }
219  else if( detName.find("sit") != std::string::npos ){
220 
221  gearMgr->setSITParameters( param ) ;
222  }
223  else if( detName.find("set") != std::string::npos ){
224 
225  gearMgr->setSETParameters( param ) ;
226  }
227 
228  }
229 
230  return param ;
231 
232  } // fromXML
233 
234 } // namespace
235 
236 
virtual double getShellOuterRadius() const =0
The outer radius of the support shell in mm.
Geometry properties of a vertex detector needed for reconstruction code.
virtual double getShellInnerRadius() const =0
The inner radius of the support shell in mm.
virtual double getPhi0(int layerIndex) const =0
Azimuthal angle of the (outward pointing) normal of the first ladder.
virtual double getLadderOffset(int layerIndex) const =0
The offset of the ladder in mm defines the shift of the ladder in the direction of increasing phi per...
Base exception class for GEAR - all other exceptions extend this.
Definition: GEAR.h:41
virtual double getSensitiveOffset(int layerIndex) const =0
Same as getLadderOffset() except for the sensitive part of the ladder.
virtual void setVXDParameters(ZPlanarParameters *vxdParameters)=0
Set the VXDParameters.
virtual void setSETParameters(ZPlanarParameters *setParameters)=0
Set the SETParameters.
virtual double getShellGap() const =0
The length of the gap in mm (gap position at z=0)
virtual double getLadderDistance(int layerIndex) const =0
The distance of ladders in layer layerIndex from the IP - layer indexing starts at 0 for the layer cl...
virtual double getLadderThickness(int layerIndex) const =0
The thickness in mm of the ladders in layerIndex - layer indexing starting at 0 for the layer closest...
virtual double getSensitiveRadLength(int layerIndex) const =0
The radiation length in sensitive volumes in layer layerIndex - layer indexing starts at 0 for the la...
static void setParametersFromXML(const TiXmlElement *xmlElement, GearParametersImpl *gearParams)
Static helper function that can be used by other subclass handlers to read parameters.
Abstract interface for a set of parameters that can be used to describe the geometrical properties of...
virtual double getSensitiveWidth(int layerIndex) const =0
The width of the sensitive area in ladders in layer layerIndex in mm.
virtual int getType() const =0
The type of detector - to be defined by users...
virtual double getLadderRadLength(int layerIndex) const =0
The radiation length in the support structure ladders of layer layerIndex - layer indexing starts at ...
Abstract description of layers in a Vertex detector.
static void getXMLForParameters(TiXmlElement *xmlElement, const GearParameters *gearParams)
Static helper function that can be used by other subclass handlers to create XML for parameters...
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:370
std::string getXMLAttribute(const TiXmlNode *node, const std::string &name)
Helper method used for parsing XML.
virtual void setSITParameters(ZPlanarParameters *sitParameters)=0
Set the SITParameters.
virtual int getNLayers() const =0
The total number of layers.
virtual double getSensitiveThickness(int layerIndex) const =0
The thickness in mm of the sensitive area in ladders in layer layerIndex.
virtual double getShellRadLength() const =0
The radiation length in the support shell.
virtual double getLadderWidth(int layerIndex) const =0
The width of the ladder in layer in mm for ladders in layer layerIndex - layer indexing starting at 0...
Geometry properties of a planar detector (parallel to z-axis) needed for reconstruction code...
The element is a container class.
Definition: tinyxml.h:827
virtual double getSensitiveLength(int layerIndex) const =0
The length of the sensitive area in ladders in z direction in mm for ladders in layer layerIndex...
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cc:218
virtual GearParameters * fromXML(const TiXmlElement *xmlElement, GearMgr *gearMgr=0) const
Creates the appropriate GearParameters subclass from the given XML element (node) ...
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
Definition: tinyxml.cc:738
virtual TiXmlElement toXML(const GearParameters &parameters) const
Creates an XML node for the given parameters.
virtual double getShellHalfLength() const =0
The half length (z) of the support shell in mm (w/o gap).
Abstract interface for a manager class that returns the Gear classes for the relevant subdetectors...
Definition: GearMgr.h:36
virtual double getSensitiveDistance(int layerIndex) const =0
The distance of sensitive area in ladders in layer layerIndex from the IP.
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 void addLayer(int nLadders, double phi0, double ladderDistance, double ladderOffset, double ladderThickness, double ladderLength, double ladderWidth, double ladderRadLength, double sensitiveDistance, double sensitiveOffset, double sensitiveThickness, double sensitiveLength, double sensitiveWidth, double sensitiveRadLength)
adding a Layer to the vertex one layer consiste of a number of ladders and sensitive areas (nLadders)...
virtual const ZPlanarLayerLayout & getZPlanarLayerLayout() const =0
The layer layout in the detector.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cc:482
virtual double getLadderLength(int layerIndex) const =0
The (half) length of the ladder in z direction in mm for ladders in layer layerIndex - layer indexing...
virtual int getNLadders(int layerIndex) const =0
The number of ladders in the layer layerIndex - layer indexing starts at 0 for the layer closest to I...