17 #include "cetlib/container_algorithms.h" 18 #include "cetlib_except/exception.h" 22 #include "TGeoMatrix.h" 52 TGeoVolume *vc = path[depth]->GetVolume();
54 throw cet::exception(
"Geometry") <<
"cannot find detector outline volume - bail ungracefully\n";
60 int nd = vc->GetNdaughters();
61 TGeoNode
const* pActiveVolNode =
nullptr;
62 for(
int i = 0; i < nd; ++i){
63 if(strncmp(vc->GetNode(i)->GetName(),
"volTPCActive", 12) != 0)
continue;
65 pActiveVolNode = vc->GetNode(i);
66 TGeoVolume *vca = pActiveVolNode->GetVolume();
75 <<
"\ndetector active volume is " <<
fActiveVolume->GetName();
79 if (pActiveVolNode) ActiveHMatrix.Multiply(pActiveVolNode->GetMatrix());
81 std::array<double, 3> localActiveCenter, worldActiveCenter;
82 localActiveCenter.fill(0.0);
83 ActiveHMatrix.LocalToMaster
84 (localActiveCenter.data(), worldActiveCenter.data());
85 fActiveCenter = geo::vect::makeFromCoords<geo::Point_t>(worldActiveCenter);
105 double const* rotMatrix =
fTrans.
Matrix().GetRotationMatrix();
106 if(rotMatrix[0] != 1){
107 if(std::abs(rotMatrix[2]) == 1){
112 if(std::abs(rotMatrix[1]) == 1){
118 if(rotMatrix[4] != 1){
119 if(std::abs(rotMatrix[3]) == 1){
124 if(std::abs(rotMatrix[5]) == 1){
130 if(rotMatrix[8] != 1){
131 if(std::abs(rotMatrix[6]) == 1){
136 if(std::abs(rotMatrix[7]) == 1){
152 const char* nm = path[depth]->GetName();
153 if( (strncmp(nm,
"volTPCPlane", 11) == 0) ){
159 unsigned int deeper = depth+1;
160 if(deeper >= path.size()){
161 throw cet::exception(
"BadTGeoNode") <<
"exceeded maximum TGeoNode depth\n";
164 const TGeoVolume *v = path[depth]->GetVolume();
165 int nd = v->GetNdaughters();
166 for(
int i = 0; i < nd; ++i){
167 path[deeper] = v->GetNode(i);
177 fPlanes.emplace_back(path, depth);
197 <<
"DetectDriftDirection(): no planes in TPC " << std::string(
ID())
204 auto const driftVector = PlaneCenter - TPCcenter;
206 if ((std::abs(driftVector.X()) > std::abs(driftVector.Y()))
207 && (std::abs(driftVector.X()) > std::abs(driftVector.Z())))
210 return (driftVector.X() > 0)? +1: -1;
212 else if (std::abs(driftVector.Y()) > std::abs(driftVector.Z()))
215 return (driftVector.Y() > 0)? +2: -2;
219 return (driftVector.Z() > 0)? +3: -3;
233 double xyz[3] = {0.};
234 fPlanes[0].LocalToWorld(origin,xyz);
235 double xyz1[3] = {0.};
241 for(
size_t p = 0; p < this->
Nplanes(); ++p){
242 fPlanes[p].LocalToWorld(origin,xyz1);
257 for(
size_t p = 0; p < this->
Nplanes(); ++p)
260 for(
size_t p = 0; p <
fPlanes.size(); ++p)
fPlanes[p].SortWires(sorter);
273 for (
unsigned int plane = 0; plane <
Nplanes(); ++plane) {
292 throw cet::exception(
"PlaneOutOfRange") <<
"Request for non-existant plane " << iplane <<
"\n";
304 <<
"TPCGeo[" << ((
void*)
this) <<
"]::Plane(): no plane for view #" 305 << (size_t) view <<
"\n";
319 auto smallestPlane = iPlane;
320 double smallestSurface = smallestPlane->Width() * smallestPlane->Depth();
321 while (++iPlane != pend) {
322 double const surface = iPlane->Width() * iPlane->Depth();
323 if (surface > smallestSurface)
continue;
324 smallestSurface = surface;
325 smallestPlane = iPlane;
327 return *smallestPlane;
334 unsigned int maxWires = 0;
336 unsigned int maxWiresInPlane = plane.Nwires();
337 if (maxWiresInPlane > maxWires) maxWires = maxWiresInPlane;
345 std::set<geo::View_t> views;
371 geo::Point_t cathodeCenter = GetActiveVolumeCenter<geo::Point_t>();
387 cathodeCenter.SetZ(cathodeCenter.Z() +
ActiveLength() / 2.0);
390 cathodeCenter.SetZ(cathodeCenter.Z() -
ActiveLength() / 2.0);
396 <<
"CathodeCenter(): Can't determine the cathode plane (code=" 399 return cathodeCenter;
407 return { activeBox.CenterX(), activeBox.CenterY(), activeBox.MinZ() };
420 unsigned int p2)
const 436 switch (driftDirCode) {
469 <<
"Unable to detect drift direction (result: " << driftDirCode
508 auto const& activeCenter = GetActiveVolumeCenter<geo::Point_t>();
529 for(
size_t p = 0; p <
Nplanes(); ++p)
556 auto by_distance = [&TPCcenter, &driftAxis](
auto const& a,
561 cet::sort_all(planes, by_distance);
geo::TPCID const & ID() const
Returns the identifier of this TPC.
void InitTPCBoundaries()
Recomputes the TPC boundary.
geo::Point_t GetCathodeCenterImpl() const
void round01(Vector &v, Scalar tol)
Returns a vector with all components rounded if close to 0, -1 or +1.
Vector DriftDir() const
Returns the direction of the drift (vector pointing toward the planes).
geo::BoxBoundedGeo fActiveBox
Box of the active volume.
std::vector< double > fPlane0Pitch
Pitch between planes.
double PlanePitch(unsigned int p1=0, unsigned int p2=1) const
Returns the center of the TPC volume in world coordinates [cm].
void MakePlane(GeoNodePath_t &path, size_t depth)
constexpr auto dot(Vector const &a, Vector const &b)
Return cross product of two vectors.
Drift direction is unknown.
void FindPlane(GeoNodePath_t &path, size_t depth)
double fLength
Length of total volume.
TPCGeo(GeoNodePath_t &path, size_t depth)
geo::Point3DBase_t< TPCGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML TPC frame.
double ComputeDriftDistance() const
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
double ActiveHalfHeight() const
Half height (associated with y coordinate) of active TPC volume [cm].
Drift towards positive values.
unsigned int Nplanes() const
Number of planes in this tpc.
double fActiveHalfWidth
Half width of active volume.
Point GetCathodeCenter() const
geo::Point_t GetFrontFaceCenterImpl() const
The data type to uniquely identify a Plane.
constexpr Vector Yaxis()
Returns a y axis vector of the specified type.
Point GetBoxCenter() const
Returns the centre of the box representing the plane.
geo::BoxBoundedGeo const & ActiveBoundingBox() const
Returns the box of the active volume of this TPC.
std::vector< geo::PlaneID::PlaneID_t > fViewToPlaneNumber
Index of the plane for each view (InvalidID if none).
std::vector< PlaneGeo > fPlanes
List of planes in this plane.
double HalfLength() const
Length is associated with z coordinate [cm].
void UpdateAfterSorting(geo::TPCID tpcid)
Performs all updates after cryostat has sorted TPCs.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Drift towards negative X values.
void SortSubVolumes(geo::GeoObjectSorter const &sorter)
Apply sorting to the PlaneGeo objects.
geo::Vector_t fHeightDir
Direction height refers to.
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local TPC frame to world frame.
geo::TPCID fID
ID of this TPC.
Class for approximate comparisons.
unsigned int PlaneID_t
Type for the ID number.
View_t View() const
Which coordinate does this plane measure.
geo::Vector_t fWidthDir
Direction width refers to.
double ActiveHalfLength() const
Length (associated with z coordinate) of active TPC volume [cm].
double fHalfWidth
Half width of total volume.
auto makeVector3DComparison(RealType threshold)
Creates a Vector3DComparison from a RealComparisons object.
geo::PlaneGeo const & SmallestPlane() const
Returns the wire plane with the smallest surface.
double fActiveLength
Length of active volume.
double ActiveHalfWidth() const
Half width (associated with x coordinate) of active TPC volume [cm].
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
void UpdatePlaneViewCache()
Refills the plane vs. view cache of the TPC.
constexpr Vector Xaxis()
Returns a x axis vector of the specified type.
TGeoVolume * fTotalVolume
Total volume of TPC, called volTPC in GDML file.
DriftDirection_t fDriftDirection
Direction of the electron drift in the TPC.
double WirePitch(unsigned plane=0) const
Returns the center of the TPC volume in world coordinates [cm].
The data type to uniquely identify a TPC.
unsigned int MaxWires() const
Returns the largest number of wires among the planes in this TPC.
double Plane0Pitch(unsigned int p) const
Returns the center of the TPC volume in world coordinates [cm].
void SortPlanes(std::vector< geo::PlaneGeo > &) const
Sorts (in place) the specified PlaneGeo objects by drift distance.
double ActiveLength() const
Length (associated with z coordinate) of active TPC volume [cm].
std::vector< std::vector< double > > fPlaneLocation
xyz locations of planes in the TPC.
Encapsulate the geometry of a wire.
auto Xcoord(Vector &v)
Returns an object to manage the coordinate X of the vector v.
double HalfHeight() const
Height is associated with y coordinate [cm].
constexpr Vector Zaxis()
Returns a z axis vector of the specified type.
TGeoVolume * fActiveVolume
Active volume of LAr, called volTPCActive in GDML file.
static const PlaneID_t InvalidID
Special code for an invalid ID.
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Drift towards positive X values.
Encapsulate the construction of a single detector plane.
double DistanceFromPlane(geo::Point_t const &point) const
Returns the distance of the specified point from the wire plane.
PlaneGeo const * PlanePtr(unsigned int iplane) const
Returns the plane number iplane from this TPC.
void SetBoundaries(Coord_t x_min, Coord_t x_max, Coord_t y_min, Coord_t y_max, Coord_t z_min, Coord_t z_max)
Sets the boundaries in world coordinates as specified.
short int DetectDriftDirection() const
Returns the expected drift direction based on geometry.
geo::Vector_t fLengthDir
Direction length refers to.
LocalTransformation_t fTrans
TPC-to-world transformation.
geo::WireGeo::GeoNodePath_t GeoNodePath_t
void ResetDriftDirection()
Recomputes the drift direction; needs planes to have been initialised.
Drift towards negative values.
geo::Vector_t fDriftDir
Direction electrons drift along.
std::set< geo::View_t > Views() const
Returns a set of all views covered in this TPC.
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
Vector normalize(Vector const &v)
Returns a vector parallel to v and with norm 1.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Namespace collecting geometry-related classes utilities.
geo::Point_t fActiveCenter
Center of the active volume, in world coordinates [cm].
const double * PlaneLocation(unsigned int p) const
Returns the coordinates of the center of the specified plane [cm].
double fHalfHeight
Half height of total volume.
double HalfWidth() const
Width is associated with x coordinate [cm].
constexpr Point origin()
Returns a origin position with a point of the specified type.
cet::coded_exception< error, detail::translate > exception
double WirePitch() const
Return the wire pitch (in centimeters). It is assumed constant.
Encapsulate the construction of a single detector plane.
double fActiveHalfHeight
Half height of active volume.
Point GetCenter() const
Returns the center of the TPC volume in world coordinates [cm].