GEAR  1.6.1
 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_unexpected( gear_unexpected ) ;
59  std::set_terminate( gear_unexpected ) ;
60 
61  if( argc < 2 ) {
62  std::cout << " testgear: Testprogram for TPC prototype description " << std::endl
63  << " usage: testtpcproto input.xml " << std::endl ;
64  exit(1) ;
65  }
66 
67  std::string fileName( argv[1] ) ;
68 
69  GearXML gearXML( fileName ) ;
70 
71  GearMgr* gearMgr = gearXML.createGearMgr() ;
72 
73 
74  std::cout << " testtpcproto - instantiated GearMgr from file " << fileName
75  << std::endl ;
76 
77  std::cout << *gearMgr << std::endl ;
78 
79 
80  try{
81  const RectangularPadRowLayout& pl =
82  dynamic_cast<const RectangularPadRowLayout&>( gearMgr->getTPCParameters().getPadLayout() );
83 
84  testRectangularPadRowLayout( pl ) ;
85  }
86  catch(std::bad_cast& e){
87  std::cout << " wrong type of layout - expected RectangularPadRowLayout ! " << std::endl ;
88  }
89 
90  // --- test writing of XML file ---------
91 
92  GearXML::createXMLFile( gearMgr, "testgear_out.xml" ) ;
93 
94 }
95 
96 
97 
98 void testRectangularPadRowLayout( const RectangularPadRowLayout& pl ) {
99 
100 
101 #ifdef GEAR_USE_AIDA
102 
103  std::string storeName("aidaroot.root");
104 
105  IAnalysisFactory * myaida = AIDA_createAnalysisFactory() ;
106 
107  ITreeFactory * mytreefactory = myaida->createTreeFactory() ;
108 
109  ITree * mytree = mytreefactory->create(storeName,"root",false,true,"none") ;
110  // mytreefactory->create(storeName,storeType,readOnly,createNew,options)
111 
112  IHistogramFactory * myhistofactory = myaida->createHistogramFactory( *mytree ) ;
113 
114 #endif
115 
116  double xmin = pl.getPlaneExtent()[0] ;
117  double xmax = pl.getPlaneExtent()[1] ;
118  double ymin = pl.getPlaneExtent()[2] ;
119  double ymax = pl.getPlaneExtent()[3] ;
120 
121 
122  int nRow = pl.getNRows() ;
123 
124  std::cout << " RectangularPadRowLayout : " << std::endl
125  << " xMin: " << xmin << std::endl
126  << " xMax: " << xmax << std::endl
127  << " yMin: " << ymin << std::endl
128  << " yMax: " << ymax << std::endl
129  << " padHeight: " << pl.getPadHeight(0) << std::endl
130  << " padWidth: " << pl.getPadWidth(0) << std::endl
131  << " nRows : " << nRow << std::endl
132  << std::endl
133  << std::endl ;
134 
135 #ifdef GEAR_USE_AIDA
136  IHistogram2D *padMap = myhistofactory->createHistogram2D("padMap",
137  500, xmin, xmax,
138  500, ymin, ymax );
139 #endif
140 
141  int nPadTotal = 0 ;
142 
143  for( int i = 0 ; i < nRow ; i++) {
144 
145  if( i==0 || i == nRow-1 )
146  std::cout << " --------- row : " << i << std::endl ;
147 
148  const std::vector<int>& pads = pl.getPadsInRow( i ) ;
149 
150  int nPad = pads.size() ;
151  nPadTotal += nPad ;
152 
153  for( int j = 0 ; j < nPad ; j++) {
154 
155  int iRow = pl.getRowNumber( pads[j] ) ;
156  int iPad = pl.getPadNumber( pads[j] ) ;
157 
158  if( j != 0 ) {
159 
160  int ln = pl.getLeftNeighbour( pl.getPadIndex( iRow , iPad ) ) ;
161 
162  assert( pl.getPadNumber( ln ) == iPad - 1 ) ;
163  }
164 
165  if( j != nPad-1 ) {
166 
167  int rn = pl.getRightNeighbour( pl.getPadIndex( iRow , iPad ) ) ;
168 
169  assert( pl.getPadNumber( rn ) == iPad + 1 ) ;
170  }
171 
172 
173  Vector2D p = pl.getPadCenter( pads[j] ) ;
174 
175 
176 #ifdef GEAR_USE_AIDA
177  for(unsigned k=0;k<1000;++k){
178  double x = xmin + ( xmax - xmin ) * rand()/ double(RAND_MAX ) ;
179  double y = ymin + ( ymax - ymin ) * rand()/ double(RAND_MAX ) ;
180 
181  if( pl.isInsidePad( x , y ) )
182  padMap->fill( x , y ) ;
183 
184  }
185 #endif
186 
187  if( (i==0 && j < 10 ) || ( i == nRow-1 && j > nPad-9 ) ) {
188 
189  std::cout << " pad: "
190  << " [" << iRow << "," << iPad << "] "
191  << " - ( " << p[0] << " , " << p[1] << ") "
192  << std::endl ;
193  }
194 
195  assert( pl.getNearestPad( p[0] , p[1] ) == pads[j] ) ;
196  assert( pl.isInsidePad( p[0] , p[1] , pads[j] ) ) ;
197  }
198  }
199 
200  assert( nPadTotal == pl.getNPads() ) ;
201 
202 #ifdef GEAR_USE_AIDA
203  mytree->commit();
204  // mytree->close();
205 #endif
206 
207 
208  //---------------------------------
209 }
210 
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.