GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
testDistanceToModule.cc
1 #include <gearimpl/TPCModuleImpl.h>
2 #include <gearimpl/RectangularPadRowLayout.h>
3 #include <gearimpl/FixedPadSizeDiskLayout.h>
4 #include <gearimpl/GearMgrImpl.h>
5 #include <gearimpl/TPCParametersImpl.h>
6 #include <gear/PadRowLayout2D.h>
7 #include <gearxml/XMLHandlerMgr.h>
8 #include <gearxml/TPCParametersXML.h>
9 #include <gearxml/tinyxml.h>
10 #include <gearxml/GearXML.h>
11 #include <iostream>
12 #include <cmath>
13 #include <complex>
14 
15 using namespace gear;
16 using namespace std;
17 
18 void dumpCoordinates( PadRowLayout2D *layout)
19 {
20  cout << "#--------------------------------" << endl;
21  for (int row = 0; row < layout->getNRows() ; row++)
22  {
23  const std::vector< int > & padsInRow = layout->getPadsInRow (row);
24 // for (unsigned int i=0; i < (padsInRow.size() < 10 ? padsInRow.size() : 10 ); i++)
25  for (unsigned int i=0; i < padsInRow.size() ; i++)
26  {
27  Vector2D padCenter = layout->getPadCenter(padsInRow[i]);
28 
29  cout << padCenter[0] << "\t" << padCenter[1] << endl;
30  }
31  }
32 }
33 
34 void dumpPlaneExtent(TPCModule const * module)
35 {
36 
37  // now the local plane extent
38  PadRowLayout2D const & localPadPlane = module->getLocalPadLayout();
39  // define step in y/phi
40  // one degree for phi
41  // one mm for y
42  double local_y_phi_step;
43 
44  switch (localPadPlane.getCoordinateType())
45  {
46  case PadRowLayout2D::POLAR :
47  {
48  local_y_phi_step = M_PI/180.;
49  }
50  break;
51  case PadRowLayout2D::CARTESIAN :
52  {
53  local_y_phi_step = 1.;
54  }
55  break;
56  default:
57  throw gear::Exception("dumpPlaneExtent: unkown coorinate type");
58  }
59 
60  for (double y_phi = localPadPlane.getPlaneExtent()[2]; y_phi < localPadPlane.getPlaneExtent()[3] ; y_phi += local_y_phi_step)
61  {
62  gear::Vector2D globalCoords = module->localToGlobal(localPadPlane.getPlaneExtent()[0] , y_phi);
63  cout << "0\t 0\t 0\t 0\t"<<globalCoords[0] << "\t"<< globalCoords[1] <<endl;
64  }
65 
66  for (double r = localPadPlane.getPlaneExtent()[0]; r < localPadPlane.getPlaneExtent()[1]; r +=1)
67  {
68  gear::Vector2D globalCoords = module->localToGlobal(r, localPadPlane.getPlaneExtent()[3]);
69  cout << "0\t 0\t 0\t 0\t"<<globalCoords[0] << "\t"<< globalCoords[1] <<endl;
70  }
71 
72  // scan y_phi in 5 degree steps
73  for (double y_phi = localPadPlane.getPlaneExtent()[3]; y_phi > localPadPlane.getPlaneExtent()[2] ; y_phi -= local_y_phi_step)
74  {
75  gear::Vector2D globalCoords = module->localToGlobal(localPadPlane.getPlaneExtent()[1] , y_phi);
76  cout << "0\t 0\t 0\t 0\t"<<globalCoords[0] << "\t"<< globalCoords[1] <<endl;
77  }
78 
79  for (double r = localPadPlane.getPlaneExtent()[1]; r > localPadPlane.getPlaneExtent()[0]; r -=1)
80  {
81  gear::Vector2D globalCoords = module->localToGlobal(r, localPadPlane.getPlaneExtent()[2]);
82  cout << "0\t 0\t 0\t 0\t"<<globalCoords[0] << "\t"<< globalCoords[1] <<endl;
83  }
84 }
85 
86 void dumpModuleExtentDistances(TPCModule const * module)
87 {
88  // define step in y/phi
89  // one degree for phi
90  // one mm for y
91  double y_phi_step;
92 
93  switch (module->getTPCCoordinateType())
94  {
95  case PadRowLayout2D::POLAR :
96  {
97  y_phi_step = M_PI/180.;
98  }
99  break;
100  case PadRowLayout2D::CARTESIAN :
101  {
102  y_phi_step = 1.;
103  }
104  break;
105  default:
106  throw gear::Exception("dumpPlaneExtent: unkown coorinate type");
107  }
108 
109 
110  // scan y_phi in 5 degree steps
111  for (double y_phi = module->getModuleExtent()[2]; y_phi < module->getModuleExtent()[3] ; y_phi += y_phi_step)
112  cout << module->getModuleExtent()[0] << "\t"<<y_phi
113  << "\t 0\t 0\t 0\t 0\t"<< module->getDistanceToModule( module->getModuleExtent()[0] , y_phi)
114  <<endl;
115 
116 
117  for (double r = module->getModuleExtent()[0]; r < module->getModuleExtent()[1]; r +=1)
118  cout << r << "\t"<< module->getModuleExtent()[3]
119  << "\t 0\t 0\t 0\t 0\t"<< module->getDistanceToModule( r , module->getModuleExtent()[3])
120  <<endl;
121 
122  // scan y_phi in 5 degree steps
123  for (double y_phi = module->getModuleExtent()[3]; y_phi > module->getModuleExtent()[2] ; y_phi -= y_phi_step)
124  cout << module->getModuleExtent()[1] << "\t"<<y_phi
125  << "\t 0\t 0\t 0\t 0\t"<< module->getDistanceToModule( module->getModuleExtent()[1] , y_phi)
126  <<endl;
127 
128  for (double r = module->getModuleExtent()[1]; r > module->getModuleExtent()[0]; r -=1)
129  cout << r << "\t"<< module->getModuleExtent()[2]
130  << "\t 0\t 0\t 0\t 0\t"<< module->getDistanceToModule( r , module->getModuleExtent()[2])
131  <<endl;
132 
133  // now the local plane extent
134  PadRowLayout2D const & localPadPlane = module->getLocalPadLayout();
135  // define step in y/phi
136  // one degree for phi
137  // one mm for y
138  double local_y_phi_step;
139 
140  switch (localPadPlane.getCoordinateType())
141  {
142  case PadRowLayout2D::POLAR :
143  {
144  local_y_phi_step = M_PI/180.;
145  }
146  break;
147  case PadRowLayout2D::CARTESIAN :
148  {
149  local_y_phi_step = 1.;
150  }
151  break;
152  default:
153  throw gear::Exception("dumpModuleExtent: unkown coorinate type");
154  }
155 
156  for (double y_phi = module->getLocalModuleExtent()[2]; y_phi < module->getLocalModuleExtent()[3] ; y_phi += local_y_phi_step)
157  {
158  gear::Vector2D globalCoords = module->localToGlobal(module->getLocalModuleExtent()[0] , y_phi);
159  cout << "0\t 0\t"<<globalCoords[0] << "\t"<< globalCoords[1] << "\t 0\t 0\t 0"<<endl;
160  }
161 
162  for (double r = module->getLocalModuleExtent()[0]; r < module->getLocalModuleExtent()[1]; r +=1)
163  {
164  gear::Vector2D globalCoords = module->localToGlobal(r, module->getLocalModuleExtent()[3]);
165  cout << "0\t 0\t"<<globalCoords[0] << "\t"<< globalCoords[1] << "\t 0\t 0\t 0"<<endl;
166  }
167 
168  // scan y_phi in 5 degree steps
169  for (double y_phi = module->getLocalModuleExtent()[3]; y_phi > module->getLocalModuleExtent()[2] ; y_phi -= local_y_phi_step)
170  {
171  gear::Vector2D globalCoords = module->localToGlobal(module->getLocalModuleExtent()[1] , y_phi);
172  cout << "0\t 0\t"<<globalCoords[0] << "\t"<< globalCoords[1] << "\t 0\t 0\t 0"<<endl;
173  }
174 
175  for (double r = module->getLocalModuleExtent()[1]; r > module->getLocalModuleExtent()[0]; r -=1)
176  {
177  gear::Vector2D globalCoords = module->localToGlobal(r, module->getLocalModuleExtent()[2]);
178  cout << "0\t 0\t"<<globalCoords[0] << "\t"<< globalCoords[1]
179  << "\t 0\t 0\t 0"<<endl;
180  }
181 }
182 
183 void dumpBox(TPCModule const * module)
184 {
185  for (double x = -100; x < 100; x+=2)
186  {
187  cout << x<<"\t"<<100<<"\t 0\t 0\t 0 \t 0\t"
188  << module->getDistanceToModule( x,100 )
189  <<endl;
190  cout << x<<"\t"<<-100<<"\t 0\t 0\t 0 \t 0\t"
191  << module->getDistanceToModule( x,-100 )
192  <<endl;
193  }
194 
195  for (double y = -100; y < 100; y+=2)
196  {
197  cout << 100<<"\t"<<y<<"\t 0\t 0\t 0 \t 0\t"
198  << module->getDistanceToModule( 100,y )
199  <<endl;
200  cout << -100<<"\t"<<y<<"\t 0\t 0\t 0 \t 0\t"
201  << module->getDistanceToModule( -100,y )
202  <<endl;
203  }
204 }
205 
206 int main(int argc,char* argv[] )
207 {
208  if (argc != 2)
209  {
210  cout << "usage: testDistanceToModue gearfile.xml" << endl;
211  return 1;
212  }
213 
214  GearXML *xmlmgr = new GearXML(argv[1]);
215  GearMgr *mgr = xmlmgr->createGearMgr();
216 
217  TPCParameters const & mTPC = mgr->getTPCParameters();
218 
219  const std::vector<TPCModule *> & moduleVec = mTPC.getModules();
220 
221  for (std::vector<TPCModule *>::const_iterator moduleIter = moduleVec.begin();
222  moduleIter < moduleVec.end(); moduleIter++)
223  {
224  dumpModuleExtentDistances(*moduleIter);
225  dumpPlaneExtent(*moduleIter);
226  dumpCoordinates(*moduleIter);
227  dumpBox(*moduleIter);
228  }
229 
230  delete xmlmgr; delete mgr;
231 }
virtual const TPCParameters & getTPCParameters() const =0
Get the TPCParameters.
Abstract description of a planar subdetector with pads (cells) that are positioned in rows (circular ...
Proposal for an abstract interface that defines the geometry properties of a TPC like detector needed...
Definition: TPCParameters.h:24
GearMgr * createGearMgr()
Creates an instance of GearMgr from the data given in the XML file.
Definition: GearXML.cc:473
Base exception class for GEAR - all other exceptions extend this.
Definition: GEAR.h:41
Implementation of GEAR using XML.
Definition: GearXML.h:18
virtual Vector2D localToGlobal(double c0, double c1) const =0
Returns the global coordinates for a point in local coordinates.
virtual const std::vector< TPCModule * > & getModules() const =0
Returns vector of all modules in this TPC (endplate).
virtual const PadRowLayout2D & getLocalPadLayout() const =0
Returns a reference to the instance of the underlaying pad layout.
virtual int getCoordinateType() const =0
The type of the row layouts coordinate system: PadRowLayout2D.CARTESIAN or PadRowLayout2D.POLAR.
virtual const std::vector< double > & getLocalModuleExtent() const =0
The module extent in local coordinates.
virtual int getNRows() const =0
The number of rows.
virtual int getTPCCoordinateType() const =0
Returns the TPCs coordinate type.
Abstract interface for a manager class that returns the Gear classes for the relevant subdetectors...
Definition: GearMgr.h:36
virtual const std::vector< int > & getPadsInRow(int rowNumber) const =0
Indices of all pads in row rowNumber (row indices start from 0 at the bottom (CARTESIAN) or at the ce...
virtual const std::vector< double > & getPlaneExtent() const =0
Extent of the sensitive plane - [xmin,xmax,ymin,ymax] CARTESIAN or [rmin,rmax,phimin,phimax] POLAR.
virtual const std::vector< double > & getModuleExtent() const =0
Maximal extent of the sensitive plane, defined relative to global origin - [xmin,xmax,ymin,ymax] CARTESIAN or [rmin,rmax,phimin,phimax] POLAR, may contain dead space due to conversion from local to global coordinate system.
A wrapper Class for PadRowLayout2D which converts between the actual pad layouts local coodinate syst...
Definition: TPCModule.h:41
virtual double getDistanceToModule(double c0, double c1) const =0
Returns distastance from a global coodinate (c0,c1), to the module&#39;s nearest boundery; (c0...
virtual Vector2D getPadCenter(int padIndex) const =0
The center of the pad in 2d coordinates, (x,y) or (r,phi).