GEAR  1.6.1
 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_unexpected( gear_unexpected ) ;
53  std::set_terminate( gear_unexpected ) ;
54 
55  if( argc < 2 ) {
56  std::cout << " testgear: Testprogram for gear classes. " << std::endl
57  << " usage: testgear input.xml " << std::endl ;
58  exit(1) ;
59  }
60 
61  std::string fileName( argv[1] ) ;
62 
63  GearXML gearXML( fileName ) ;
64 
65  GearMgr* gearMgr = gearXML.createGearMgr() ;
66 
67 
68  std::cout << " testgear - instantiated GearMgr from file " << fileName
69  << std::endl ;
70 
71  std::cout << *gearMgr << std::endl ;
72 
73  Point3D p( 1.,2.,3. ) ;
74 
75  std::cout << " testgear - old point 3d : "
76  << p[0] << ", "
77  << p[1] << ", "
78  << p[2] << std::endl ;
79 
80 
81 
82 
83  try{
84  // Please note that this is the old, deperated method which only works for
85  // TPCs with only one pad plane.
86  // In general a TPC can have several modules. Use
87  // const std::vector< TPCModule * > & TPCParametes::getModules()
88  // for more realistic examples. You will get an expection if you run
89  // a multi module gear file with this programme.
90  const PadRowLayout2D & pl = gearMgr->getTPCParameters().getPadLayout() ;
91 
92  // The following tests are only needed because testFixedPadSizeDiskLayout() is only working for
93  // the FixedPadSizeDiskLayout. (see comments in testFixedPadSizeDiskLayout() )
94  // Please note that gear code should work independently of the implementation and only use
95  // functionality of PadRowLayout2D, so it can be used with any geometry.
96  // You could use pl right away without the type casting and impl checking.
97 
98  // This code is in here to demonstrate how to access the underlying implemntation
99  // in case you need some specialities of the pad layout (like the row() member function of
100  // RectangularPadRowLayout).
101  // Please do this only for specialised code which whould fale on other geometries.
102 
103  if (pl.getPadLayoutImplType() != PadRowLayout2D::TPCMODULE){
104  std::cout << " wrong type of layout - TPCParameters should return a TPCModule ! " << std::endl ;
105  throw gear::Exception("wrong type of layout - TPCParameters should return a TPCModule");
106  }
107 
108  const TPCModule & module = dynamic_cast<const TPCModule &>(pl);
109 
110  if ( module.getLocalPadLayout().getPadLayoutImplType() != PadRowLayout2D::FIXEDPADSIZEDISKLAYOUT) {
111  std::cout << " wrong type of layout - expected FixedPadSizeDiskLayout ! " << std::endl ;
112  }
113  else{
114  testFixedPadSizeDiskLayout( dynamic_cast<const FixedPadSizeDiskLayout &>(module.getLocalPadLayout()) ) ;
115  }
116  }
118  std::cout << " oops - no TPC available :( " << std::endl ;
119  }
120 
121  // --- test writing of XML file ---------
122 
123  GearXML::createXMLFile( gearMgr, "testgear_out.xml" ) ;
124 
125 
126  // ----- getting Bz from the field map
127  try{
128  double bfield = gearMgr->getBField().at( 0, 0, 0 ).z() ;
129 
130  std::cout << std::endl
131  << " -- Bz at origin [double bfield = gearMgr->getBField().at( Vector3D(0,0,0) ).z() ;] : " << bfield
132  << std::endl << std::endl ;
133 
134 
135  }catch( gear::UnknownParameterException& e ){
136  std::cout << " oops - no BField available :( " << std::endl ;
137  }
138 
139 
140  // --- testing gearcga ---
141 #ifdef CGA
142  std::ifstream inFile("mokka.steer");
143  std::stringstream steer;
144  std::string line ;
145  while( ! inFile.eof() ) {
146  getline( inFile, line ) ;
147  steer << line << std::endl ;
148  }
149 
150  CGAGearDistanceProperties * distProp = new CGAGearDistanceProperties(steer.str(), "ProtoDesy0205", "", "", "", "");
151 
152  // Vector3D initial, final;
153  Vector3D initial, final;
154  std::vector<std::string> matNames, lvNames;
155  initial[0] = 0.0;
156  initial[1] = 0.0;
157  initial[2] = 0.0;
158  final[0] = 0.0;
159  final[1] = 1000.0;
160  final[2] = 1000.0;
161 
162  try{
163  matNames = distProp->getMaterialNames(initial, final);
164  for(unsigned int i=0; i<matNames.size();i++)
165  std::cout << matNames[i].c_str() << std::endl;
166  double bDl = distProp->getBdL(initial, final);
167  std::cout << "Bdl=" << bDl << std::endl;
168  double eDl = distProp->getEdL(initial, final);
169  std::cout << "Edl=" << eDl << std::endl;
170  }
171  catch(NotImplementedException e){}
172 
173  CGAGearPointProperties * pointProp = new CGAGearPointProperties(steer.str(), "ProtoDesy0205", "", "", "", "");
174 
175  const Vector3D position(0.0, 1730.0, 0.0);
176  try{
177  std::cout << "Material: " <<
178  pointProp->getMaterialName(position) << " Density: " <<
179  pointProp->getDensity(position) << std::endl;
180 
181  lvNames = pointProp->getListOfLogicalVolumes(position);
182  for(unsigned int i=0; i<lvNames.size();i++)
183  std::cout << lvNames[i].c_str() << std::endl;
184  Vector3D B = pointProp->getB(position);
185  std::cout << "B=(" << B[0] << "," << B[1] << "," << B[2] <<
186  ")" << std::endl;
187  }
188  catch(NotImplementedException e){}
189 #endif //ifdef CGA
190 }
191 
192 
193 
194 // Except for an uncaught gear::Exception this code would also work for
195 // all other pad layout, because it only uses member functions of the
196 // common PadRowLayout2D base class.
197 void testFixedPadSizeDiskLayout( const FixedPadSizeDiskLayout& pl ) {
198 
199 // const DoubleVec& ext = pl.getPlaneExtent() ;
200 
201 // double rMin = ext[0] ;
202 // double rMax = ext[1] ;
203 
204 // // getPadWidth() returns phi - need to multiply by r
205 // double padWidth = pl.getPadWidth(0) * pl.getPadCenter(0).first ;
206 
207  int nRow = pl.getNRows() ;
208 
209 // std::cout << " FixedPadSizeDiskLayout : " << std::endl
210 // << " rMin: " << rMin << std::endl
211 // << " rMax: " << rMax << std::endl
212 // << " padHeight: " << pl.getPadHeight(0) << std::endl
213 // << " padWidth: " << padWidth << std::endl
214 // << " nRows : " << nRow << std::endl
215 // << std::endl
216 // << std::endl ;
217 
218  int nPadTotal = 0 ;
219 
220  std::cout << " First (innermost) 10 pads and last (outermost) 10 pads : " << std::endl ;
221 
222  for( int i = 0 ; i < nRow ; i++) {
223 
224  if( i==0 || i == nRow-1 )
225  std::cout << " --------- row : " << i << std::endl ;
226 
227  const std::vector<int>& pads = pl.getPadsInRow( i ) ;
228 
229  int nPad = pads.size() ;
230  nPadTotal += nPad ;
231 
232  for( int j = 0 ; j < nPad ; j++) {
233 
234 
235  int iRow = pl.getRowNumber( pads[j] ) ;
236  int iPad = pl.getPadNumber( pads[j] ) ;
237 
238  // This is the part which only works for FixedPadSizeDiskLayout:
239  // getLeftNeighbour() and getRightNeighbour() can throw a gear::Exception
240  // in the other implementations, because there are pads at the edge of the pad plane
241  // which have no neighbour.
242  if( j == 0 ) {
243  int ln = pl.getRightNeighbour( pl.getPadIndex( iRow , iPad ) ) ;
244  assert( pl.getPadNumber( ln ) == nPad-1 ) ;
245  }
246 
247  if( j == nPad-1 ) {
248  int rn = pl.getLeftNeighbour( pl.getPadIndex( iRow , iPad ) ) ;
249  assert( pl.getPadNumber( rn ) == 0 ) ;
250  }
251 
252  Vector2D p = pl.getPadCenter( pads[j] ) ;
253 
254  if( (i==0 && j < 10 ) || ( i == nRow-1 && j > nPad-9 ) ) {
255 
256  std::cout << " pad: "
257  << " [" << iRow << "," << iPad << "] "
258  << " - ( " << p[0] << " , " << p[1] << ") "
259  << std::endl ;
260  }
261 
262  assert( pl.getNearestPad( p[0] , p[1] ) == pads[j] ) ;
263  assert( pl.isInsidePad( p[0] , p[1] , pads[j] ) ) ;
264 
265 // if( !( pl.isInsidePad( p[0] , p[1] , pads[j] ) )) {
266 // std::cout << " center is not in pad :( ! " << std::endl ;
267 // }
268  }
269  }
270  assert( nPadTotal == pl.getNPads() ) ;
271 
272 
273 
274  //---------------------------------
275  Vector3D r ;
276  r[0] = 1. ;
277  r[1] = 2. ;
278  r[2] = 3. ;
279 
280  Vector3D r1( r ) ;
281  Vector3D r2( r1[0] , r1[1] , r1[2] ) ;
282  Vector3D r3 ;
283 
284  std::cout << " test of Vector3D r : " << r[0] << ", " << r[1] << ", " << r[2] << std::endl ;
285  std::cout << " test of Vector3D r1 : " << r1[0] << ", " << r1[1] << ", " << r1[2] << std::endl ;
286  std::cout << " test of Vector3D r2: " << r2[0] << ", " << r2[1] << ", " << r2[2] << std::endl ;
287  std::cout << " test of Vector3D r3: " << r3[0] << ", " << r3[1] << ", " << r3[2] << std::endl ;
288 
289 }
290 
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.