ProtoDUNEDPCRPGeo.cxx
Go to the documentation of this file.
1 // ProtoDUNEDPCRPGeo.cxx
2 //
3 #include <iostream>
4 #include <string>
5 
6 #include "ProtoDUNEDPCRPGeo.h"
7 
8 using std::string;
9 using std::cout;
10 using std::cerr;
11 using std::endl;
12 using geo::Point_t;
14 
15 // ctor
17 {
18  fLemsPerRow = 6;
19  fLemWidth = 50.0; // in cm
20 
21  // geometry service
23 }
24 
25 //
26 // dtor
28 {;}
29 
30 
31 //
33 {
34  const string myname = "protoana::ProtoDUNEDPCRPGeo::GetCRPGeoInfo: ";
35 
36  crpgeoinfo crp_geo_info;
37 
38  // find TPC volume
39  geo::TPCGeo const* tpc = nullptr;
40  try{
41  tpc = fGeom->PositionToTPCptr( pnt );
42  }
43  catch(cet::exception &e){
44  cout<<e;
45  }
46 
47  if( not tpc ) return crp_geo_info;
48  crp_geo_info.crpid = tpc->ID().TPC;
49 
50  // determine drift coordinate
51  int dcoord = std::abs(tpc->DetectDriftDirection())-1; //x:0, y:1, z:2
52  int tcoord1 = 0;
53  int tcoord2 = 0;
54  if(dcoord == 0)
55  {
56  tcoord1 = 1; // Y
57  tcoord2 = 2; // Z
58  }
59  else if(dcoord == 1)
60  {
61  tcoord1 = 0; // X
62  tcoord2 = 2; // Z
63  }
64  else // wrong CRP drift
65  {
66  cout<<myname<<"Bad drift direction "<<dcoord<<endl;
67  return crp_geo_info;
68  }
69 
70 
71  double xyz[3] = {pnt.X(), pnt.Y(), pnt.Z()};
72  crp_geo_info.danode = tpc->PlaneLocation(0)[dcoord] - xyz[dcoord];
73 
74  // point coordinate in the plane
75  float planeX = xyz[ tcoord2 ] - tpc->PlaneLocation(0)[ tcoord2 ];
76  float planeY = xyz[ tcoord1 ] - tpc->PlaneLocation(0)[ tcoord1 ];
77 
78  // cout<<"Input : "<<xyz[0]<<" "<<xyz[1]<<" "<<xyz[2]<<endl;
79  // cout<<"Plane : "
80  // <<tpc->PlaneLocation(0)[0]<<" "
81  // <<tpc->PlaneLocation(0)[1]<<" "
82  // <<tpc->PlaneLocation(0)[2]<<endl;
83  // cout<<"Danode : "<<crp_geo_info.danode<<endl;
84  // cout<<"Plane coord : "<<planeX<<" "<<planeY<<endl;
85 
86  // distance to the CRP edge
87  float activeHalfWidth = 0.5 * fLemsPerRow * fLemWidth;
88  crp_geo_info.dedge = std::min( (activeHalfWidth - std::abs(planeX)),
89  (activeHalfWidth - std::abs(planeY)) );
90  if( crp_geo_info.dedge < 0 || crp_geo_info.dedge > activeHalfWidth ){
91  cout<<myname<<"Bad distance to CRP edge "<<crp_geo_info.dedge<<endl;
92  return crp_geo_info;
93  }
94 
95  // 2d index of each LEM: CRP edges should be about -150.0 -> 150.0 cm
96  int LemsHalfRow = fLemsPerRow / 2;
97  int icol = int(planeX / fLemWidth); // column index along Z axis
98  if( planeX < 0 ) icol += (LemsHalfRow - 1);
99  else icol += (LemsHalfRow);
100 
101  int irow = int(planeY / fLemWidth); // row index in other coordinate
102  if( planeY < 0 ) irow += (LemsHalfRow - 1);
103  else irow += (LemsHalfRow);
104 
105  crp_geo_info.lemid = icol * fLemsPerRow + irow;
106  if( crp_geo_info.lemid >= fLemsPerRow * fLemsPerRow || crp_geo_info.lemid < 0 ){
107  // bad LEM index;
108  cout<<myname<<"Bad LEM index "<<crp_geo_info.lemid<<endl;
109  return crp_geo_info;
110  }
111 
112  // assumed center of each LEM
113  float lemX = (icol + 0.5) * fLemWidth - activeHalfWidth;
114  float lemY = (irow + 0.5) * fLemWidth - activeHalfWidth;
115 
116  // position wrt to LEM center
117  float inlemX = planeX - lemX;
118  float inlemY = planeY - lemY;
119  crp_geo_info.dlem = std::min( (0.5 * fLemWidth - std::abs(inlemX)),
120  (0.5 * fLemWidth - std::abs(inlemY)) );
121  // cout<<"LEM IDs : "<<icol<<" "<<irow<<" "<<crp_geo_info.lemid<<"\n";
122  // cout<<"LEM pos : "<<lemX<<" "<<lemY<<"\n";
123  // cout<<"In LEM pos : "<<inlemX<<" "<<inlemY<<"\n";
124  // cout<<"Distance to LEM border : "<<crp_geo_info.dlem<<endl;
125 
126  if( crp_geo_info.dlem < 0 || crp_geo_info.dlem > 0.5*fLemWidth ){
127  cout<<myname<<"Bad distance to LEM border "<<crp_geo_info.dlem<<endl;
128  return crp_geo_info;
129  }
130 
131  crp_geo_info.valid = true;
132 
133  return crp_geo_info;
134 }
std::string string
Definition: nybbler.cc:12
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >> Point_t
Geometry information for a single TPC.
Definition: TPCGeo.h:38
geo::TPCGeo const * PositionToTPCptr(geo::Point_t const &point) const
Returns the TPC at specified location.
crpgeoinfo GetCRPGeoInfo(geo::Point_t const &pnt) const
T abs(T value)
const double e
geo::Geometry const * fGeom
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
struct protoana::crpgeoinfo crpgeoinfo
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)