All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fiducial_volume.cxx
Go to the documentation of this file.
5 
6 namespace single_photon
7 {
8 
9 void setTPCGeom(para_all& paras){
10 
11  //copy these from CAFMaker/CAFMaker_module.c
12  const geo::GeometryCore *geometry = lar::providerFrom<geo::Geometry>();
13  for (auto const &cryo: geometry->IterateCryostats()) {
14  geo::GeometryCore::TPC_iterator iTPC = geometry->begin_TPC(cryo.ID()),
15  tend = geometry->end_TPC(cryo.ID());
16 
17  std::vector<geo::BoxBoundedGeo> this_tpc_volumes;
18  while (iTPC != tend) {
19  geo::TPCGeo const& TPC = *iTPC;
20  this_tpc_volumes.push_back(TPC.ActiveBoundingBox());
21  iTPC++;
22  }
23  paras.fTPCVolumes.push_back(std::move(this_tpc_volumes));
24  }
25 
26  // then combine them into active volumes
27  for (const std::vector<geo::BoxBoundedGeo> &tpcs: paras.fTPCVolumes) {
28  paras.s_tpc_active_XMin = std::min_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MinX() < rhs.MinX(); })->MinX();
29  paras.s_tpc_active_YMin = std::min_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MinY() < rhs.MinY(); })->MinY();
30  paras.s_tpc_active_ZMin = std::min_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MinZ() < rhs.MinZ(); })->MinZ();
31 
32  paras.s_tpc_active_XMax = std::max_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MaxX() < rhs.MaxX(); })->MaxX();
33  paras.s_tpc_active_YMax = std::max_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MaxY() < rhs.MaxY(); })->MaxY();
34  paras.s_tpc_active_ZMax = std::max_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MaxZ() < rhs.MaxZ(); })->MaxZ();
35  if(g_is_verbose){
36  std::cout<<""<<__FUNCTION__<<" || Active TPC info: X:("<<paras.s_tpc_active_XMin<<","<<paras.s_tpc_active_XMax<<")";
37  std::cout<<" Y:("<<paras.s_tpc_active_YMin<<","<<paras.s_tpc_active_YMax<<")";
38  std::cout<<" Z:("<<paras.s_tpc_active_ZMin<<","<<paras.s_tpc_active_ZMax<<")"<<std::endl;
39  }
40  }
41 
42 }
43 
44 
45 /* inside TPC or not? */
46 bool isInTPCActive(std::vector<double> & vec, para_all& paras){
47  if( vec.size() != 3){
48  throw cet::exception("single_photon") << " The coordinate dimension is not 3!";
49  }
50 
51  bool is_x = (vec[0] > paras.s_tpc_active_XMin && vec[0]< paras.s_tpc_active_XMax );
52  bool is_y = (vec[1] > paras.s_tpc_active_YMin && vec[1]< paras.s_tpc_active_YMax );
53  bool is_z = (vec[2] > paras.s_tpc_active_ZMin && vec[2]< paras.s_tpc_active_ZMax );
54  bool inside = is_x&&is_y&&is_z;
55 
56  return inside;
57 }
58 
59 
60 /* returns minimum distance to the TPC active boundary; returns -999 if the point is not in TPC active volume */
61 double distToTPCActive(std::vector<double>&vec, para_all& paras){
62  if(!isInTPCActive(vec, paras)) return -999;
63  double min_x = std::min( fabs(vec[0] - paras.s_tpc_active_XMin) , fabs(vec[0] - paras.s_tpc_active_XMax));
64  double min_y = std::min( fabs(vec[1] - paras.s_tpc_active_YMin) , fabs(vec[1] - paras.s_tpc_active_YMax));
65  double min_z = std::min( fabs(vec[2] - paras.s_tpc_active_ZMin) , fabs(vec[2] - paras.s_tpc_active_ZMax));
66 
67  return ( (min_x<min_y) ? std::min(min_x,min_z) : std::min(min_y,min_z) );
68 }
69 
70 
71 /* returns minimum distance to the TPCActive boundary around the Cathode Plane Assemble; returns -999 if the point is not in TPC active volume */
72 double distToCPA(std::vector<double>&vec, para_all& paras){
73  if(!isInTPCActive(vec, paras)) return -999;
74  double dx = std::min( fabs(vec[0] - (-0.45)) , fabs(vec[0] - 0.45));
75 
76  return dx;
77 }
78 
79 
80 
81 
82 // int isInSCB(std::vector<double> & vec){
83 // return isInSCB(0.0,vec);
84 // }
85 
86 int distToSCB(double & dist, std::vector<double> &vec, para_all& paras){
87  //CHECK!
88  dist = distToTPCActive( vec, paras);
89  int is_it_in = 0;
90  if(isInTPCActive( vec, paras)) is_it_in++;
91  return is_it_in;
92  //NOT USE SCB YET, bring it back later!
93  //
94  // //this one returns the distance to the boundary
95  // bool ans = false;
96  // double dist_yx = 999999;
97  //
98  // int iseg = 0;
99  // if (!isInTPCActive(vec)){
100  // dist=-1;
101  // return 0; // is it in active volume?
102  // }
103  // double cut = 0.0;
104  //
105  // TVector3 pt(&vec[0]);
106  //
107  // Int_t z_idx = (Int_t)pt.Z()/100; // Int_t: signed integer 4 bytes
108  //
109  // Int_t z_idx_YX = z_idx;//YX-view effective z index, it is only different for z > 10m area, where we want to appliy 9m<z<10m YX boundary, still need to keep the original z_idx bc it's needed in ZX-view
110  // if (z_idx_YX==10) z_idx_YX-=1;
111  // double tbi = -10000.; //means "to be initialized"
112  //
113  //
114  // double ptX[6] = {0.+cut, tbi, m_SCB_YX_TOP_x2_array-cut, m_SCB_YX_BOT_x2_array-cut, tbi, 0.+cut};
115  // double ptY[6] = {m_SCB_YX_TOP_y1_array-cut, m_SCB_YX_TOP_y1_array-cut, tbi, tbi, m_SCB_YX_BOT_y1_array+cut, m_SCB_YX_BOT_y1_array+cut};
116  //
117  // TGeoPolygon *polyXY = new TGeoPolygon(6);
118  //
119  // ptX[1] = m_SCB_YX_TOP_x1_array[z_idx_YX+1];
120  // ptX[4] = m_SCB_YX_BOT_x1_array[z_idx_YX+1];
121  // ptY[2] = m_SCB_YX_TOP_y2_array[z_idx_YX+1];
122  // ptY[3] = m_SCB_YX_BOT_y2_array[z_idx_YX+1];
123  //
124  // polyXY->SetXY(ptX,ptY);
125  // polyXY->FinishPolygon();
126  // double testpt[2] = {pt.X(), pt.Y()};
127  //
128  // //cout << "is testpt ("<< pt.X()<<", "<<pt.Y()<<") contrained? "<< polyXY->Contains(testpt)<<endl;
129  // //cout << "area ? " << polyXY->Area()<< endl;
130  //
131  // //polyXY->Draw();
132  //
133  // Bool_t XY_contain = polyXY->Contains(testpt);
134  // dist_yx = polyXY->Safety(testpt, iseg); // Compute minimum distance from testpt to any segment.
135  //
136  // if(0<z_idx && z_idx<10){
137  // double up_z = pt.Z()-s_tpc_active_z_low; // gonna bet, if it's middle enough to be up_z or down_z is smaller than the safefy in this z regime (1m,10m), it is safe to set up_z = z-0, down_z=1036.8-z
138  // double down_z = s_tpc_active_z_high-pt.Z();
139  // double min_z = std::min(up_z,down_z);
140  //
141  // XY_contain ? dist = std::min(dist_yx,min_z) : dist = -1 ;
142  //
143  // delete polyXY;
144  // return (XY_contain ? 1 : 0 );
145  // }
146  //
147  // //up or down
148  // double top_y = s_tpc_active_y_high-pt.Y();
149  // double bottom_y = pt.Y()+s_tpc_active_y_high;
150  // double min_y = std::min(top_y, bottom_y);
151  //
152  //
153  // // if z_idx==0 or z_idx==10, they need xz view,
154  // /// ZX view has Y dependence: Y sub-range from -116 to 116cm per 24cm
155  // Int_t y_idx = (pt.Y()+116.)/24;
156  // if (pt.Y()<-116. && pt.Y()>-116.5) y_idx = 0; //just the 0.5cm
157  // if(y_idx<0 || y_idx>9) {
158  // dist = -1;
159  // delete polyXY;
160  // return 0;
161  // }
162  //
163  // Bool_t ZX_contain = false;
164  // double arbit_out = 55555;
165  //
166  // double d_dist = -1;
167  //
168  // //upstream
169  // if(z_idx==0){
170  // double ptX_Up[5] = {0.+cut, m_SCB_ZX_Up_x1_array, m_SCB_ZX_Up_x2_array-cut, m_SCB_ZX_Up_x2_array-cut, 0+cut};
171  // double ptZ_Up[5] = {0.+cut,0.+cut,m_SCB_ZX_Up_z2_array, arbit_out, arbit_out};
172  //
173  // TGeoPolygon *polyXZ_Up = new TGeoPolygon(5);
174  // polyXZ_Up->SetXY(ptX_Up,ptZ_Up);
175  // polyXZ_Up->FinishPolygon();
176  //
177  // double testpt_Up[2] = {pt.X(), pt.Z()};
178  // ZX_contain = polyXZ_Up->Contains(testpt_Up);
179  // d_dist = polyXZ_Up->Safety(testpt_Up,iseg);
180  // delete polyXZ_Up;
181  //
182  // }
183  // if (z_idx==10){
184  // double ptX_Dw[5] = {0.+cut,m_SCB_ZX_Dw_x2_array-cut, m_SCB_ZX_Dw_x2_array-cut, tbi, 0.+cut};
185  // double ptZ_Dw[5] = {-arbit_out,-arbit_out,tbi,m_SCB_ZX_Dw_z1_array-cut, m_SCB_ZX_Dw_z1_array-cut};
186  //
187  // ptX_Dw[3] = m_SCB_ZX_Dw_x1_array[y_idx+1];
188  // ptZ_Dw[2] = m_SCB_ZX_Dw_z2_array[y_idx+1];
189  //
190  // TGeoPolygon *polyXZ_Dw = new TGeoPolygon(5);
191  // polyXZ_Dw->SetXY(ptX_Dw,ptZ_Dw);
192  // polyXZ_Dw->FinishPolygon();
193  //
194  // double testpt_Dw[2] = {pt.X(), pt.Z()};
195  // ZX_contain = polyXZ_Dw->Contains(testpt_Dw);
196  // d_dist = polyXZ_Dw->Safety(testpt_Dw,iseg);
197  // delete polyXZ_Dw;
198  // }
199  //
200  // delete polyXY;
201  //
202  // ans = XY_contain && ZX_contain;
203  // ans ? dist = std::min(d_dist,min_y) : dist=-1;
204  //
205  // return (ans ? 1 : 0);
206 }
207 
208 
209 }
Utilities related to art service access.
const geo::GeometryCore * geometry
Geometry information for a single TPC.
Definition: TPCGeo.h:38
geo::BoxBoundedGeo const & ActiveBoundingBox() const
Returns the box of the active volume of this TPC.
Definition: TPCGeo.h:320
BEGIN_PROLOG TPC
TPC_iterator begin_TPC() const
Returns an iterator pointing to the first TPC in the detector.
void setTPCGeom(para_all &paras)
int distToSCB(double &dist, std::vector< double > &vec, para_all &paras)
double distToCPA(std::vector< double > &vec, para_all &paras)
Description of geometry of one entire detector.
bool isInTPCActive(std::vector< double > &vec, para_all &paras)
Provides a base class aware of world box coordinates.
IteratorBox< cryostat_iterator,&GeometryCore::begin_cryostat,&GeometryCore::end_cryostat > IterateCryostats() const
Enables ranged-for loops on all cryostats of the detector.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
double distToTPCActive(std::vector< double > &vec, para_all &paras)
Forward iterator browsing all geometry elements in the detector.
Definition: GeometryCore.h:727
BEGIN_PROLOG could also be cout
TPC_iterator end_TPC() const
Returns an iterator pointing after the last TPC in the detector.
std::vector< std::vector< geo::BoxBoundedGeo > > fTPCVolumes
Definition: variables.h:49