GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
testIsInsideModule.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 
87 void dumpBox(TPCModule const * module)
88 {
89  for (double x = -100; x < 100; x+=2)
90  {
91  if (module->isInsideModule( x,100 ))
92  cout << x<<"\t"<<100<<"\t 0\t 0"<<endl;
93  else
94  cout <<"0\t 0\t"<< x<<"\t"<<100<<endl;
95 
96  if (module->isInsideModule( x,-100 ))
97  cout << x<<"\t"<<-100<<"\t 0\t 0"<<endl;
98  else
99  cout <<"0\t 0\t"<< x<<"\t"<<-100<<endl;
100  }
101 
102  for (double y = -100; y < 100; y+=2)
103  {
104  if (module->isInsideModule( 100 , y ))
105  cout << 100<<"\t"<<y<<"\t 0\t 0"<<endl;
106  else
107  cout <<"0\t 0\t"<< 100<<"\t"<<y<<endl;
108 
109  if (module->isInsideModule( -100 , y ))
110  cout << -100<<"\t"<<y<<"\t 0\t 0"<<endl;
111  else
112  cout <<"0\t 0\t"<< -100<<"\t"<<y<<endl;
113  }
114 }
115 
116 int main(int argc,char* argv[] )
117 {
118  if (argc != 2)
119  {
120  cout << "Tool to test the isInsideModule function of TPCModule."<< endl;
121  cout << "usage: testDistanceToModue gearfile.xml" << endl;
122  return 1;
123  }
124 
125  GearXML *xmlmgr = new GearXML(argv[1]);
126  GearMgr *mgr = xmlmgr->createGearMgr();
127 
128  TPCParameters const & mTPC = mgr->getTPCParameters();
129 
130  const std::vector<TPCModule *> & moduleVec = mTPC.getModules();
131 
132  for (std::vector<TPCModule *>::const_iterator moduleIter = moduleVec.begin();
133  moduleIter < moduleVec.end(); moduleIter++)
134  {
135 // dumpModuleExtentDistances(*moduleIter);
136  dumpPlaneExtent(*moduleIter);
137 // dumpCoordinates(*moduleIter);
138  dumpBox(*moduleIter);
139  }
140 
141  delete xmlmgr; delete mgr;
142 }
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 bool isInsideModule(double c0, double c1) const =0
True if global coordinate (c0,c1) is within this modules area of amplification/interest.
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 int getNRows() const =0
The number of rows.
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.
A wrapper Class for PadRowLayout2D which converts between the actual pad layouts local coodinate syst...
Definition: TPCModule.h:41
virtual Vector2D getPadCenter(int padIndex) const =0
The center of the pad in 2d coordinates, (x,y) or (r,phi).