GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
testtpcproto.cc
1 #include "gearimpl/RectangularPadRowLayout.h"
2 #include "gearimpl/Util.h"
3 #include "gearxml/GearXML.h"
4 #include "gear/GearMgr.h"
5 #include "gear/GEAR.h"
6 
7 #include <iostream>
8 #include <assert.h>
9 
10 #include <exception>
11 #include <typeinfo>
12 #include <cstdlib>
13 
14 #ifdef GEAR_USE_AIDA
15 #include "AIDA/AIDA.h"
16 using namespace AIDA ;
17 #endif
18 
19 
20 using namespace gear ;
21 
22 void testRectangularPadRowLayout( const RectangularPadRowLayout& pl ) ;
23 
24 
25 void gear_unexpected(){
26 
27  try {
28 
29  throw ;
30 
31  } catch( std::exception& e) {
32 
33  std::cout << " A runtime error has occured : "
34  << e.what()
35  << std::endl
36  << " the program will have to be terminated - sorry." << std::endl ;
37  exit(1) ;
38 
39  }
40 
41  catch(...) {
42 
43  std::cout << " An unknown runtime error has occured : "
44  << std::endl
45  << " the program will have to be terminated - sorry." << std::endl ;
46  exit(1) ;
47  }
48 }
49 
50 
55 int main(int argc, char**argv){
56 
57 
58  std::set_terminate( gear_unexpected ) ;
59 
60  if( argc < 2 ) {
61  std::cout << " testgear: Testprogram for TPC prototype description " << std::endl
62  << " usage: testtpcproto input.xml " << std::endl ;
63  exit(1) ;
64  }
65 
66  std::string fileName( argv[1] ) ;
67 
68  GearXML gearXML( fileName ) ;
69 
70  GearMgr* gearMgr = gearXML.createGearMgr() ;
71 
72 
73  std::cout << " testtpcproto - instantiated GearMgr from file " << fileName
74  << std::endl ;
75 
76  std::cout << *gearMgr << std::endl ;
77 
78 
79  try{
80  const RectangularPadRowLayout& pl =
81  dynamic_cast<const RectangularPadRowLayout&>( gearMgr->getTPCParameters().getPadLayout() );
82 
83  testRectangularPadRowLayout( pl ) ;
84  }
85  catch(std::bad_cast& e){
86  std::cout << " wrong type of layout - expected RectangularPadRowLayout ! " << std::endl ;
87  }
88 
89  // --- test writing of XML file ---------
90 
91  GearXML::createXMLFile( gearMgr, "testgear_out.xml" ) ;
92 
93 }
94 
95 
96 
97 void testRectangularPadRowLayout( const RectangularPadRowLayout& pl ) {
98 
99 
100 #ifdef GEAR_USE_AIDA
101 
102  std::string storeName("aidaroot.root");
103 
104  IAnalysisFactory * myaida = AIDA_createAnalysisFactory() ;
105 
106  ITreeFactory * mytreefactory = myaida->createTreeFactory() ;
107 
108  ITree * mytree = mytreefactory->create(storeName,"root",false,true,"none") ;
109  // mytreefactory->create(storeName,storeType,readOnly,createNew,options)
110 
111  IHistogramFactory * myhistofactory = myaida->createHistogramFactory( *mytree ) ;
112 
113 #endif
114 
115  double xmin = pl.getPlaneExtent()[0] ;
116  double xmax = pl.getPlaneExtent()[1] ;
117  double ymin = pl.getPlaneExtent()[2] ;
118  double ymax = pl.getPlaneExtent()[3] ;
119 
120 
121  int nRow = pl.getNRows() ;
122 
123  std::cout << " RectangularPadRowLayout : " << std::endl
124  << " xMin: " << xmin << std::endl
125  << " xMax: " << xmax << std::endl
126  << " yMin: " << ymin << std::endl
127  << " yMax: " << ymax << std::endl
128  << " padHeight: " << pl.getPadHeight(0) << std::endl
129  << " padWidth: " << pl.getPadWidth(0) << std::endl
130  << " nRows : " << nRow << std::endl
131  << std::endl
132  << std::endl ;
133 
134 #ifdef GEAR_USE_AIDA
135  IHistogram2D *padMap = myhistofactory->createHistogram2D("padMap",
136  500, xmin, xmax,
137  500, ymin, ymax );
138 #endif
139 
140  int nPadTotal = 0 ;
141 
142  for( int i = 0 ; i < nRow ; i++) {
143 
144  if( i==0 || i == nRow-1 )
145  std::cout << " --------- row : " << i << std::endl ;
146 
147  const std::vector<int>& pads = pl.getPadsInRow( i ) ;
148 
149  int nPad = pads.size() ;
150  nPadTotal += nPad ;
151 
152  for( int j = 0 ; j < nPad ; j++) {
153 
154  int iRow = pl.getRowNumber( pads[j] ) ;
155  int iPad = pl.getPadNumber( pads[j] ) ;
156 
157  if( j != 0 ) {
158 
159  int ln = pl.getLeftNeighbour( pl.getPadIndex( iRow , iPad ) ) ;
160 
161  assert( pl.getPadNumber( ln ) == iPad - 1 ) ;
162  }
163 
164  if( j != nPad-1 ) {
165 
166  int rn = pl.getRightNeighbour( pl.getPadIndex( iRow , iPad ) ) ;
167 
168  assert( pl.getPadNumber( rn ) == iPad + 1 ) ;
169  }
170 
171 
172  Vector2D p = pl.getPadCenter( pads[j] ) ;
173 
174 
175 #ifdef GEAR_USE_AIDA
176  for(unsigned k=0;k<1000;++k){
177  double x = xmin + ( xmax - xmin ) * rand()/ double(RAND_MAX ) ;
178  double y = ymin + ( ymax - ymin ) * rand()/ double(RAND_MAX ) ;
179 
180  if( pl.isInsidePad( x , y ) )
181  padMap->fill( x , y ) ;
182 
183  }
184 #endif
185 
186  if( (i==0 && j < 10 ) || ( i == nRow-1 && j > nPad-9 ) ) {
187 
188  std::cout << " pad: "
189  << " [" << iRow << "," << iPad << "] "
190  << " - ( " << p[0] << " , " << p[1] << ") "
191  << std::endl ;
192  }
193 
194  assert( pl.getNearestPad( p[0] , p[1] ) == pads[j] ) ;
195  assert( pl.isInsidePad( p[0] , p[1] , pads[j] ) ) ;
196  }
197  }
198 
199  assert( nPadTotal == pl.getNPads() ) ;
200 
201 #ifdef GEAR_USE_AIDA
202  mytree->commit();
203  // mytree->close();
204 #endif
205 
206 
207  //---------------------------------
208 }
209 
virtual int getNPads() const
The total number of pads in the TPC.
virtual int getRowNumber(int padIndex) const
The number of the row that contains the pad at padIndex - numbering starts at y==0 (bottom)...
virtual const TPCParameters & getTPCParameters() const =0
Get the TPCParameters.
virtual int getNearestPad(double x, double y) const
The index of the pad nearest to the given point in 2d coordinates (x,y,) or (r,phi).
virtual int getPadIndex(int rowNum, int padNum) const
Create a padIndex for the given row and pad ( column ) number.
Implementation of GEAR using XML.
Definition: GearXML.h:18
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 double getPadWidth(int padIndex) const
The width of the pad at padIndex in mm.
virtual Vector2D getPadCenter(int padIndex) const
The center of the pad in 2d coordinates, (x,y) or (r,phi).
virtual int getPadNumber(int padIndex) const
The pad number (column) within the row - numbering starts at x==0 (left).
virtual bool isInsidePad(double x, double y, int padIndex) const
True if coordinate (x,y) is within the given pad.
virtual int getRightNeighbour(int padIndex) const
The index of the right neighbour pad.
virtual double getPadHeight(int padIndex) const
The height of the pad in mm.
virtual const std::vector< double > & getPlaneExtent() const
Extent of the sensitive plane - [xmin,xmax,ymin,ymax] CARTESIAN or [rmin,rmax,phimin,phimax] POLAR.
virtual int getLeftNeighbour(int padIndex) const
The index of the left neighbour pad.
virtual const PadRowLayout2D & getPadLayout() const =0
Kept for backward compatibility.
Abstract interface for a manager class that returns the Gear classes for the relevant subdetectors...
Definition: GearMgr.h:36
Implementation of PadRowLayout2D for a rectangular row based layout where all pads in a given row are...
virtual int getNRows() const
The number of rows.