1 #ifndef RECOTOOL_CFALGOVOLUMEOVERLAP_CXX 2 #define RECOTOOL_CFALGOVOLUMEOVERLAP_CXX 45 if ( clusters.size() == 1 )
48 if (
_verbose) { std::cout <<
"Number of clusters taken into account: " << clusters.size() << std::endl; }
54 std::vector<std::vector<util::PxHit> >
Hits(3, std::vector<util::PxHit>());
56 for (
size_t c=0; c < clusters.size(); c++)
57 Hits.at( clusters.at(c)->Plane() ) = clusters.at(c)->GetHitVector();
64 std::vector<int> StartWires;
65 std::vector<int> EndWires;
66 std::vector<float> StartTimes;
67 std::vector<float> EndTimes;
69 for (
int pl=0; pl < 3; pl++){
70 StartWires.push_back(9999);
71 EndWires.push_back(0);
72 StartTimes.push_back(9999);
73 EndTimes.push_back(0);
76 for (
size_t h=0; h < Hits.size(); h++){
77 for (
auto&
hit: Hits.at(h) ){
78 if ( Hits.at(h).size() == 0 ){
79 std::cout <<
"Need to insert fake hit ranges...";
82 if (
int(
hit.w /
_w2cm) < StartWires.at(h) ) { StartWires.at(h) = int(
hit.w /
_w2cm); }
83 if (
int(
hit.w /
_w2cm) > EndWires.at(h) ) { EndWires.at(h) = int(
hit.w /
_w2cm); }
84 if (
hit.t < StartTimes.at(h) ) { StartTimes.at(h) =
hit.t; }
85 if (
hit.t > EndTimes.at(h) ) { EndTimes.at(h) =
hit.t; }
96 for (
size_t h=0; h < Hits.size(); h++){
97 if ( StartWires.at(h) == 9999 ) { StartWires.at(h) = 1; }
98 if ( EndWires.at(h) == 0 ) { EndWires.at(h) = geo->
Nwires(h)-1; }
99 if ( StartTimes.at(h) == 9999 ) { StartTimes.at(h) = 0; }
100 if ( EndTimes.at(h) == 0 ) { EndTimes.at(h) = 9999; }
105 if ( (StartTimes.at(1) > EndTimes.at(0)) or (StartTimes.at(1) > EndTimes.at(2)) or
106 (StartTimes.at(2) > EndTimes.at(0)) or (StartTimes.at(2) > EndTimes.at(1)) or
107 (StartTimes.at(0) > EndTimes.at(1)) or (StartTimes.at(0) > EndTimes.at(2)) ){
108 if (
_verbose) { std::cout <<
"No Time-Overlap!" << std::endl << std::endl; }
112 float Tmin=9999, Tmax=0;
113 ( StartTimes.at(1) > StartTimes.at(0) ) ? (Tmin = StartTimes.at(1)) : (Tmin = StartTimes.at(0));
114 if (StartTimes.at(2) > Tmin) { Tmin = StartTimes.at(2); }
115 ( EndTimes.at(1) < EndTimes.at(0) ) ? (Tmax = EndTimes.at(1)) : (Tmax = EndTimes.at(0));
116 if (EndTimes.at(2) < Tmax) { Tmax = EndTimes.at(2); }
117 float Trange = Tmax-Tmin;
120 Double_t xyzStart0WireStart[3] = {0., 0., 0.};
121 Double_t xyzStart0WireEnd[3] = {0., 0., 0.};
122 Double_t xyzEnd0WireStart[3] = {0., 0., 0.};
123 Double_t xyzEnd0WireEnd[3] = {0., 0., 0.};
124 Double_t xyzStart1WireStart[3] = {0., 0., 0.};
125 Double_t xyzStart1WireEnd[3] = {0., 0., 0.};
126 Double_t xyzEnd1WireStart[3] = {0., 0., 0.};
127 Double_t xyzEnd1WireEnd[3] = {0., 0., 0.};
128 Double_t xyzStart2WireStart[3] = {0., 0., 0.};
129 Double_t xyzStart2WireEnd[3] = {0., 0., 0.};
130 Double_t xyzEnd2WireStart[3] = {0., 0., 0.};
131 Double_t xyzEnd2WireEnd[3] = {0., 0., 0.};
134 std::cout <<
"Wire Ranges:" << std::endl;
135 std::cout <<
"U-Plane: [ " << StartWires.at(0) <<
", " << EndWires.at(0) <<
"]" << std::endl;
136 std::cout <<
"V-Plane: [ " << StartWires.at(1) <<
", " << EndWires.at(1) <<
"]" << std::endl;
137 std::cout <<
"Y-Plane: [ " << StartWires.at(2) <<
", " << EndWires.at(2) <<
"]" << std::endl;
138 std::cout << std::endl;
149 geo->
WireEndPoints(0, 0, 0, StartWires.at(0), xyzStart0WireStart, xyzStart0WireEnd);
150 geo->
WireEndPoints(0, 0, 0, EndWires.at(0), xyzEnd0WireStart, xyzEnd0WireEnd);
151 geo->
WireEndPoints(0, 0, 1, StartWires.at(1), xyzStart1WireStart, xyzStart1WireEnd);
152 geo->
WireEndPoints(0, 0, 1, EndWires.at(1), xyzEnd1WireStart, xyzEnd1WireEnd);
153 geo->
WireEndPoints(0, 0, 2, StartWires.at(2), xyzStart2WireStart, xyzStart2WireEnd);
154 geo->
WireEndPoints(0, 0, 2, EndWires.at(2), xyzEnd2WireStart, xyzEnd2WireEnd);
158 double zMin = xyzStart2WireStart[2];
160 double zMax = xyzEnd2WireStart[2];
168 double slopeU = tan(30*3.14/180.);
169 double slopeV = tan(-30*3.14/180.);
172 double bUup = xyzStart0WireStart[1] - xyzStart0WireStart[2] * slopeU;
173 double bUdn = xyzEnd0WireStart[1] - xyzEnd0WireStart[2] * slopeU;
174 double bVdn = xyzStart1WireStart[1] - xyzStart1WireStart[2] * slopeV;
175 double bVup = xyzEnd1WireStart[1] - xyzEnd1WireStart[2] * slopeV;
177 if ( bUup < bUdn ) { std::cout <<
"Uup and Udn are mixed up!" << std::endl; }
178 if ( bVdn > bVup ) { std::cout <<
"Vup and Vdn are mixed up!" << std::endl; }
185 double VdnZmin = slopeV * zMin + bVdn;
186 double VdnZmax = slopeV * zMax + bVdn;
187 double VupZmin = slopeV * zMin + bVup;
188 double VupZmax = slopeV * zMax + bVup;
189 double UdnZmin = slopeU * zMin + bUdn;
190 double UdnZmax = slopeU * zMax + bUdn;
191 double UupZmin = slopeU * zMin + bUup;
192 double UupZmax = slopeU * zMax + bUup;
195 std::cout <<
"Y-Plane and U-Plane points [Z,Y]:" << std::endl;
196 std::cout <<
"\t\t[ " << zMin <<
", " << UdnZmin <<
"]" << std::endl;
197 std::cout <<
"\t\t[ " << zMin <<
", " << UupZmin <<
"]" << std::endl;
198 std::cout <<
"\t\t[ " << zMax <<
", " << UupZmax <<
"]" << std::endl;
199 std::cout <<
"\t\t[ " << zMax <<
", " << UdnZmax <<
"]" << std::endl;
200 std::cout <<
"Y-Plane and V-Plane points [Z,Y]:" << std::endl;
201 std::cout <<
"\t\t[ " << zMin <<
", " << VdnZmin <<
"]" << std::endl;
202 std::cout <<
"\t\t[ " << zMin <<
", " << VupZmin <<
"]" << std::endl;
203 std::cout <<
"\t\t[ " << zMax <<
", " << VupZmax <<
"]" << std::endl;
204 std::cout <<
"\t\t[ " << zMax <<
", " << VdnZmax <<
"]" << std::endl;
215 std::vector< std::pair<float,float> > WireIntersection;
219 zInt = (bUup-bVup)/(slopeV-slopeU);
220 if ( (zInt > zMin) and (zInt < zMax) )
221 WireIntersection.push_back( std::make_pair( zInt, slopeV*zInt+bVup ) );
223 if ( (VupZmax < UupZmax) and (VupZmax > UdnZmax) )
224 WireIntersection.push_back( std::make_pair( zMax, VupZmax ) );
226 if ( (VupZmin < UupZmin) and ( VupZmin > UdnZmin) )
227 WireIntersection.push_back( std::make_pair( zMin, VupZmin ) );
229 zInt = (bUdn-bVup)/(slopeV-slopeU);
230 if ( (zInt > zMin) and (zInt < zMax) )
231 WireIntersection.push_back( std::make_pair( zInt, slopeV*zInt+bVup ) );
235 zInt = (bUup-bVdn)/(slopeV-slopeU);
236 if ( (zInt > zMin) and (zInt < zMax) )
237 WireIntersection.push_back( std::make_pair( zInt, slopeV*zInt+bVdn ) );
239 if ( (VdnZmax < UupZmax) and (VdnZmax > UdnZmax) )
240 WireIntersection.push_back( std::make_pair( zMax, VdnZmax ) );
242 if ( (VdnZmin < UupZmin) and ( VdnZmin > UdnZmin) )
243 WireIntersection.push_back( std::make_pair( zMin, VdnZmin ) );
245 zInt = (bUdn-bVdn)/(slopeV-slopeU);
246 if ( (zInt > zMin) and (zInt < zMax) )
247 WireIntersection.push_back( std::make_pair( zInt, slopeV*zInt+bVdn ) );
251 if ( (UupZmax < VupZmax) and ( UupZmax > VdnZmax) )
252 WireIntersection.push_back( std::make_pair( zMax, UupZmax ) );
254 if ( (UdnZmax < VupZmax) and ( UdnZmax > VdnZmax) )
255 WireIntersection.push_back( std::make_pair( zMax, UdnZmax ) );
259 if ( (UupZmin < VupZmin) and ( UupZmin > VdnZmin) )
260 WireIntersection.push_back( std::make_pair( zMin, UupZmin ) );
262 if ( (UdnZmin < VupZmin) and ( UdnZmin > VdnZmin) )
263 WireIntersection.push_back( std::make_pair( zMin, UdnZmin ) );
266 if ( WireIntersection.size() == 0 ){
267 if (
_verbose) { std::cout <<
"No intersection..." << std::endl << std::endl; }
276 double PolyArea = -1;
281 std::vector< std::pair<float,float> > TPCCorners;
282 TPCCorners.push_back( std::make_pair(0., -geo->
DetHalfHeight()) );
285 TPCCorners.push_back( std::make_pair(0., geo->
DetHalfHeight()) );
289 std::cout <<
"Wire Overlap contained in TPC" << std::endl;
290 std::cout <<
"Intersection Polygon Coordinates [Z,Y]: " << std::endl;
291 for (
unsigned int s=0;
s < WirePolygon.
Size();
s++)
292 std::cout <<
"\t\t[ " << WirePolygon.
Point(
s).first <<
", " << WirePolygon.
Point(
s).second <<
"]" << std::endl;
293 std::cout << std::endl;
295 PolyArea = WirePolygon.
Area();
299 std::cout <<
"Wire overlap not fully contained in TPC" << std::endl;
300 std::cout <<
"Intersection Polygon Coordinates [Z,Y]: " << std::endl;
301 for (
unsigned int s=0;
s < WirePolygon.
Size();
s++)
302 std::cout <<
"\t\t[ " << WirePolygon.
Point(
s).first <<
", " << WirePolygon.
Point(
s).second <<
"]" << std::endl;
303 std::cout << std::endl;
306 Polygon2D IntersectionPolygon(TPCPolygon, WirePolygon);
307 PolyArea = IntersectionPolygon.
Area();
311 if (
_verbose) { std::cout <<
"Intersection area: " << PolyArea << std::endl << std::endl; }
312 return Trange*PolyArea;
bool Contained(const Polygon2D &poly2) const
Double_t TimeToCm() const
const std::pair< float, float > & Point(unsigned int p) const
Double_t WireToCm() const
unsigned int Size() const
Create Intersection Polygon.
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
Detector simulation of raw signals on wires.
Class def header for a class CFAlgoVolumeOverlap.
art::PtrVector< recob::Hit > Hits
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
Namespace collecting geometry-related classes utilities.
void UntanglePolygon()
check if poly2 is inside poly1