GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
testgear.cc
1 
2 #include "gearimpl/FixedPadSizeDiskLayout.h"
3 #include "gearimpl/Util.h"
4 #include "gearxml/GearXML.h"
5 #include "gear/GearMgr.h"
6 #include "gear/GEAR.h"
7 
8 #ifdef CGA
9 #include "gearcga/CGAGearDistanceProperties.h"
10 #include "gearcga/CGAGearPointProperties.h"
11 #endif
12 
13 #include <iostream>
14 #include <assert.h>
15 
16 #include <exception>
17 #include <typeinfo>
18 #include <cstdlib>
19 
20 #include <sstream>
21 #include <fstream>
22 
23 using namespace gear ;
24 
25 void testFixedPadSizeDiskLayout( const FixedPadSizeDiskLayout& pl ) ;
26 
27 
28 void gear_unexpected(){
29 
30  try {
31 
32  throw ;
33 
34  } catch( std::exception& e) {
35 
36  std::cout << " A runtime error has occured : "
37  << e.what()
38  << std::endl
39  << " the program will have to be terminated - sorry." << std::endl ;
40  exit(1) ;
41  }
42 }
43 
44 
49 int main(int argc, char**argv){
50 
51 
52  std::set_terminate( gear_unexpected ) ;
53 
54  if( argc < 2 ) {
55  std::cout << " testgear: Testprogram for gear classes. " << std::endl
56  << " usage: testgear input.xml " << std::endl ;
57  exit(1) ;
58  }
59 
60  std::string fileName( argv[1] ) ;
61 
62  GearXML gearXML( fileName ) ;
63 
64  GearMgr* gearMgr = gearXML.createGearMgr() ;
65 
66 
67  std::cout << " testgear - instantiated GearMgr from file " << fileName
68  << std::endl ;
69 
70  std::cout << *gearMgr << std::endl ;
71 
72  Point3D p( 1.,2.,3. ) ;
73 
74  std::cout << " testgear - old point 3d : "
75  << p[0] << ", "
76  << p[1] << ", "
77  << p[2] << std::endl ;
78 
79 
80 
81 
82  try{
83  // Please note that this is the old, deperated method which only works for
84  // TPCs with only one pad plane.
85  // In general a TPC can have several modules. Use
86  // const std::vector< TPCModule * > & TPCParametes::getModules()
87  // for more realistic examples. You will get an expection if you run
88  // a multi module gear file with this programme.
89  const PadRowLayout2D & pl = gearMgr->getTPCParameters().getPadLayout() ;
90 
91  // The following tests are only needed because testFixedPadSizeDiskLayout() is only working for
92  // the FixedPadSizeDiskLayout. (see comments in testFixedPadSizeDiskLayout() )
93  // Please note that gear code should work independently of the implementation and only use
94  // functionality of PadRowLayout2D, so it can be used with any geometry.
95  // You could use pl right away without the type casting and impl checking.
96 
97  // This code is in here to demonstrate how to access the underlying implemntation
98  // in case you need some specialities of the pad layout (like the row() member function of
99  // RectangularPadRowLayout).
100  // Please do this only for specialised code which whould fale on other geometries.
101 
102  if (pl.getPadLayoutImplType() != PadRowLayout2D::TPCMODULE){
103  std::cout << " wrong type of layout - TPCParameters should return a TPCModule ! " << std::endl ;
104  throw gear::Exception("wrong type of layout - TPCParameters should return a TPCModule");
105  }
106 
107  const TPCModule & module = dynamic_cast<const TPCModule &>(pl);
108 
109  if ( module.getLocalPadLayout().getPadLayoutImplType() != PadRowLayout2D::FIXEDPADSIZEDISKLAYOUT) {
110  std::cout << " wrong type of layout - expected FixedPadSizeDiskLayout ! " << std::endl ;
111  }
112  else{
113  testFixedPadSizeDiskLayout( dynamic_cast<const FixedPadSizeDiskLayout &>(module.getLocalPadLayout()) ) ;
114  }
115  }
117  std::cout << " oops - no TPC available :( " << std::endl ;
118  }
119 
120  // --- test writing of XML file ---------
121 
122  GearXML::createXMLFile( gearMgr, "testgear_out.xml" ) ;
123 
124 
125  // ----- getting Bz from the field map
126  try{
127  double bfield = gearMgr->getBField().at( 0, 0, 0 ).z() ;
128 
129  std::cout << std::endl
130  << " -- Bz at origin [double bfield = gearMgr->getBField().at( Vector3D(0,0,0) ).z() ;] : " << bfield
131  << std::endl << std::endl ;
132 
133 
134  }catch( gear::UnknownParameterException& e ){
135  std::cout << " oops - no BField available :( " << std::endl ;
136  }
137 
138 
139  // --- testing gearcga ---
140 #ifdef CGA
141  std::ifstream inFile("mokka.steer");
142  std::stringstream steer;
143  std::string line ;
144  while( ! inFile.eof() ) {
145  getline( inFile, line ) ;
146  steer << line << std::endl ;
147  }
148 
149  CGAGearDistanceProperties * distProp = new CGAGearDistanceProperties(steer.str(), "ProtoDesy0205", "", "", "", "");
150 
151  // Vector3D initial, final;
152  Vector3D initial, final;
153  std::vector<std::string> matNames, lvNames;
154  initial[0] = 0.0;
155  initial[1] = 0.0;
156  initial[2] = 0.0;
157  final[0] = 0.0;
158  final[1] = 1000.0;
159  final[2] = 1000.0;
160 
161  try{
162  matNames = distProp->getMaterialNames(initial, final);
163  for(unsigned int i=0; i<matNames.size();i++)
164  std::cout << matNames[i].c_str() << std::endl;
165  double bDl = distProp->getBdL(initial, final);
166  std::cout << "Bdl=" << bDl << std::endl;
167  double eDl = distProp->getEdL(initial, final);
168  std::cout << "Edl=" << eDl << std::endl;
169  }
170  catch(NotImplementedException e){}
171 
172  CGAGearPointProperties * pointProp = new CGAGearPointProperties(steer.str(), "ProtoDesy0205", "", "", "", "");
173 
174  const Vector3D position(0.0, 1730.0, 0.0);
175  try{
176  std::cout << "Material: " <<
177  pointProp->getMaterialName(position) << " Density: " <<
178  pointProp->getDensity(position) << std::endl;
179 
180  lvNames = pointProp->getListOfLogicalVolumes(position);
181  for(unsigned int i=0; i<lvNames.size();i++)
182  std::cout << lvNames[i].c_str() << std::endl;
183  Vector3D B = pointProp->getB(position);
184  std::cout << "B=(" << B[0] << "," << B[1] << "," << B[2] <<
185  ")" << std::endl;
186  }
187  catch(NotImplementedException e){}
188 #endif //ifdef CGA
189 }
190 
191 
192 
193 // Except for an uncaught gear::Exception this code would also work for
194 // all other pad layout, because it only uses member functions of the
195 // common PadRowLayout2D base class.
196 void testFixedPadSizeDiskLayout( const FixedPadSizeDiskLayout& pl ) {
197 
198 // const DoubleVec& ext = pl.getPlaneExtent() ;
199 
200 // double rMin = ext[0] ;
201 // double rMax = ext[1] ;
202 
203 // // getPadWidth() returns phi - need to multiply by r
204 // double padWidth = pl.getPadWidth(0) * pl.getPadCenter(0).first ;
205 
206  int nRow = pl.getNRows() ;
207 
208 // std::cout << " FixedPadSizeDiskLayout : " << std::endl
209 // << " rMin: " << rMin << std::endl
210 // << " rMax: " << rMax << std::endl
211 // << " padHeight: " << pl.getPadHeight(0) << std::endl
212 // << " padWidth: " << padWidth << std::endl
213 // << " nRows : " << nRow << std::endl
214 // << std::endl
215 // << std::endl ;
216 
217  int nPadTotal = 0 ;
218 
219  std::cout << " First (innermost) 10 pads and last (outermost) 10 pads : " << std::endl ;
220 
221  for( int i = 0 ; i < nRow ; i++) {
222 
223  if( i==0 || i == nRow-1 )
224  std::cout << " --------- row : " << i << std::endl ;
225 
226  const std::vector<int>& pads = pl.getPadsInRow( i ) ;
227 
228  int nPad = pads.size() ;
229  nPadTotal += nPad ;
230 
231  for( int j = 0 ; j < nPad ; j++) {
232 
233 
234  int iRow = pl.getRowNumber( pads[j] ) ;
235  int iPad = pl.getPadNumber( pads[j] ) ;
236 
237  // This is the part which only works for FixedPadSizeDiskLayout:
238  // getLeftNeighbour() and getRightNeighbour() can throw a gear::Exception
239  // in the other implementations, because there are pads at the edge of the pad plane
240  // which have no neighbour.
241  if( j == 0 ) {
242  int ln = pl.getRightNeighbour( pl.getPadIndex( iRow , iPad ) ) ;
243  assert( pl.getPadNumber( ln ) == nPad-1 ) ;
244  }
245 
246  if( j == nPad-1 ) {
247  int rn = pl.getLeftNeighbour( pl.getPadIndex( iRow , iPad ) ) ;
248  assert( pl.getPadNumber( rn ) == 0 ) ;
249  }
250 
251  Vector2D p = pl.getPadCenter( pads[j] ) ;
252 
253  if( (i==0 && j < 10 ) || ( i == nRow-1 && j > nPad-9 ) ) {
254 
255  std::cout << " pad: "
256  << " [" << iRow << "," << iPad << "] "
257  << " - ( " << p[0] << " , " << p[1] << ") "
258  << std::endl ;
259  }
260 
261  assert( pl.getNearestPad( p[0] , p[1] ) == pads[j] ) ;
262  assert( pl.isInsidePad( p[0] , p[1] , pads[j] ) ) ;
263 
264 // if( !( pl.isInsidePad( p[0] , p[1] , pads[j] ) )) {
265 // std::cout << " center is not in pad :( ! " << std::endl ;
266 // }
267  }
268  }
269  assert( nPadTotal == pl.getNPads() ) ;
270 
271 
272 
273  //---------------------------------
274  Vector3D r ;
275  r[0] = 1. ;
276  r[1] = 2. ;
277  r[2] = 3. ;
278 
279  Vector3D r1( r ) ;
280  Vector3D r2( r1[0] , r1[1] , r1[2] ) ;
281  Vector3D r3 ;
282 
283  std::cout << " test of Vector3D r : " << r[0] << ", " << r[1] << ", " << r[2] << std::endl ;
284  std::cout << " test of Vector3D r1 : " << r1[0] << ", " << r1[1] << ", " << r1[2] << std::endl ;
285  std::cout << " test of Vector3D r2: " << r2[0] << ", " << r2[1] << ", " << r2[2] << std::endl ;
286  std::cout << " test of Vector3D r3: " << r3[0] << ", " << r3[1] << ", " << r3[2] << std::endl ;
287 
288 }
289 
virtual int getNRows() const
The number of rows.
virtual const TPCParameters & getTPCParameters() const =0
Get the TPCParameters.
virtual Vector3D getB(const Vector3D &pos) const
The magnetic field vector at pos in [Tesla].
Abstract description of a planar subdetector with pads (cells) that are positioned in rows (circular ...
virtual int getPadNumber(int padIndex) const
The pad number (column) within the row - numbering starts at phi/x =.
Base exception class for GEAR - all other exceptions extend this.
Definition: GEAR.h:41
CGA Implementation of the abstract interface that returns the (material) properties along a given dis...
virtual double getDensity(const Vector3D &pos) const
Density in kg/m^3 at pos.
Implementation of PadRowLayout2D for a disk with fixed sized keystone pads.
virtual int getNearestPad(double c0, double c1) const
The index of the pad nearest to the given point in 2d coordinates (x,y,) or (r,phi).
virtual const BField & getBField() const =0
Get the B field map.
Implementation of GEAR using XML.
Definition: GearXML.h:18
NotImplementedException used for features that are not implemented.
Definition: GEAR.h:81
virtual Vector3D at(Vector3D point) const =0
Returns the B field vector in Tesla at given point.
virtual int getRightNeighbour(int padIndex) const
The index of the right neighbour pad.
Simple three dimensional vector providing the components for cartesian, cylindrical and spherical coo...
Definition: Vector3D.h:18
virtual const PadRowLayout2D & getLocalPadLayout() const =0
Returns a reference to the instance of the underlaying pad layout.
UnknownParameterException call Processor::end().
Definition: GEAR.h:99
static void createXMLFile(GearMgr *mgr, const std::string &fileName)
Write an XML file to disk from the given GearMgr object.
Definition: GearXML.cc:50
virtual int getPadLayoutImplType() const =0
The type of the row layout implementation: PadRowLayout2D.RECTANGULARPADROWLAYOUT, PadRowLayout2D.FIXEDPADSIZEDISKLAYOUT, PadRowLayout2D.FIXEDPADANGLEDISKLAYOUT or PadRowLayout2D.TPCMODULE.
virtual bool isInsidePad(double c0, double c1, int padIndex) const
True if coordinate (c0,c1) is within the given pad.
double z()
Cartesian cartesian z coordinate.
Definition: Vector3D.h:62
virtual const std::vector< std::string > & getMaterialNames(const Vector3D &p0, const Vector3D &p1) const
List of matrial names along the distance between [p0,p1] .
virtual std::vector< std::string > getListOfLogicalVolumes(const Vector3D &pos) const
Names of (geant4) logical volumes in heirarchy starting at given pos ending with the world volume...
virtual const PadRowLayout2D & getPadLayout() const =0
Kept for backward compatibility.
virtual const std::string & getMaterialName(const Vector3D &pos) const
Name of material at pos.
Abstract interface for a manager class that returns the Gear classes for the relevant subdetectors...
Definition: GearMgr.h:36
CGA implementation of the abstract interface that returns the (material) properties of a given point ...
virtual int getLeftNeighbour(int padIndex) const
The index of the left neighbour pad.
virtual int getNPads() const
The total number of pads in the TPC.
virtual double getBdL(const Vector3D &p0, const Vector3D &p1) const
The integrated magnetic field along the distance between [p0,p1] in Tesla*mm.
virtual int getPadIndex(int rowNum, int padNum) const
Create a padIndex for the given row and pad ( column ) number.
virtual const std::vector< int > & getPadsInRow(int rowNumber) const
Indices of all pads in row rowNumber (row indices start from 0 at the bottom (CARTESIAN) or at the ce...
virtual int getRowNumber(int padIndex) const
The number of the row that contains the pad at padIndex - numbering starts at r/y==0.
virtual Vector2D getPadCenter(int padIndex) const
The center of the pad in 2d coordinates, (x,y) or (r,phi).
A wrapper Class for PadRowLayout2D which converts between the actual pad layouts local coodinate syst...
Definition: TPCModule.h:41
virtual double getEdL(const Vector3D &p0, const Vector3D &p1) const
The integrated electric field along the distance between [p0,p1] in mVolt.