17 #include "cetlib_except/exception.h" 21 #include "TGeoMatrix.h" 51 TGeoVolume *vc = path[depth]->GetVolume();
53 throw cet::exception(
"Geometry") <<
"cannot find detector outline volume - bail ungracefully\n";
59 int nd = vc->GetNdaughters();
60 TGeoNode
const* pActiveVolNode =
nullptr;
61 for(
int i = 0; i < nd; ++i){
62 if(strncmp(vc->GetNode(i)->GetName(),
"volTPCActive", 12) != 0)
continue;
64 pActiveVolNode = vc->GetNode(i);
65 TGeoVolume *vca = pActiveVolNode->GetVolume();
74 <<
"\ndetector active volume is " <<
fActiveVolume->GetName();
78 if (pActiveVolNode) ActiveHMatrix.Multiply(pActiveVolNode->GetMatrix());
80 std::array<double, 3> localActiveCenter, worldActiveCenter;
81 localActiveCenter.fill(0.0);
82 ActiveHMatrix.LocalToMaster
83 (localActiveCenter.data(), worldActiveCenter.data());
84 fActiveCenter = geo::vect::makeFromCoords<geo::Point_t>(worldActiveCenter);
104 double const* rotMatrix =
fTrans.
Matrix().GetRotationMatrix();
105 if(rotMatrix[0] != 1){
106 if(std::abs(rotMatrix[2]) == 1){
111 if(std::abs(rotMatrix[1]) == 1){
117 if(rotMatrix[4] != 1){
118 if(std::abs(rotMatrix[3]) == 1){
123 if(std::abs(rotMatrix[5]) == 1){
129 if(rotMatrix[8] != 1){
130 if(std::abs(rotMatrix[6]) == 1){
135 if(std::abs(rotMatrix[7]) == 1){
151 const char* nm = path[depth]->GetName();
152 if( (strncmp(nm,
"volTPCPlane", 11) == 0) ){
158 unsigned int deeper = depth+1;
159 if(deeper >= path.size()){
160 throw cet::exception(
"BadTGeoNode") <<
"exceeded maximum TGeoNode depth\n";
163 const TGeoVolume *v = path[depth]->GetVolume();
164 int nd = v->GetNdaughters();
165 for(
int i = 0; i < nd; ++i){
166 path[deeper] = v->GetNode(i);
176 fPlanes.emplace_back(path, depth);
196 <<
"DetectDriftDirection(): no planes in TPC " << std::string(
ID())
203 auto const driftVector = PlaneCenter - TPCcenter;
205 if ((std::abs(driftVector.X()) > std::abs(driftVector.Y()))
206 && (std::abs(driftVector.X()) > std::abs(driftVector.Z())))
209 return (driftVector.X() > 0)? +1: -1;
211 else if (std::abs(driftVector.Y()) > std::abs(driftVector.Z()))
214 return (driftVector.Y() > 0)? +2: -2;
218 return (driftVector.Z() > 0)? +3: -3;
232 double xyz[3] = {0.};
233 fPlanes[0].LocalToWorld(origin,xyz);
234 double xyz1[3] = {0.};
240 for(
size_t p = 0; p < this->
Nplanes(); ++p){
241 fPlanes[p].LocalToWorld(origin,xyz1);
256 for(
size_t p = 0; p < this->
Nplanes(); ++p)
259 for(
size_t p = 0; p <
fPlanes.size(); ++p)
fPlanes[p].SortWires(sorter);
272 for (
unsigned int plane = 0; plane <
Nplanes(); ++plane) {
291 throw cet::exception(
"PlaneOutOfRange") <<
"Request for non-existant plane " << iplane <<
"\n";
303 <<
"TPCGeo[" << ((
void*)
this) <<
"]::Plane(): no plane for view #" 304 << (size_t) view <<
"\n";
318 auto smallestPlane = iPlane;
319 double smallestSurface = smallestPlane->Width() * smallestPlane->Depth();
320 while (++iPlane != pend) {
321 double const surface = iPlane->Width() * iPlane->Depth();
322 if (surface > smallestSurface)
continue;
323 smallestSurface = surface;
324 smallestPlane = iPlane;
326 return *smallestPlane;
333 unsigned int maxWires = 0;
335 unsigned int maxWiresInPlane = plane.Nwires();
336 if (maxWiresInPlane > maxWires) maxWires = maxWiresInPlane;
344 std::set<geo::View_t> views;
370 geo::Point_t cathodeCenter = GetActiveVolumeCenter<geo::Point_t>();
386 cathodeCenter.SetZ(cathodeCenter.Z() +
ActiveLength() / 2.0);
389 cathodeCenter.SetZ(cathodeCenter.Z() -
ActiveLength() / 2.0);
395 <<
"CathodeCenter(): Can't determine the cathode plane (code=" 398 return cathodeCenter;
406 return { activeBox.CenterX(), activeBox.CenterY(), activeBox.MinZ() };
419 unsigned int p2)
const 435 switch (driftDirCode) {
468 <<
"Unable to detect drift direction (result: " << driftDirCode
507 auto const& activeCenter = GetActiveVolumeCenter<geo::Point_t>();
528 for(
size_t p = 0; p <
Nplanes(); ++p)
560 std::vector<std::pair<geo::PlaneGeo*, double>> planesWithDistance;
561 planesWithDistance.reserve(planes.size());
563 double const driftDistance
565 planesWithDistance.emplace_back(&plane, driftDistance);
571 std::sort(planesWithDistance.begin(), planesWithDistance.end(),
572 [](
auto const& a,
auto const& b){
return a.second < b.second; }
578 std::vector<geo::PlaneGeo> sortedPlanes;
579 sortedPlanes.reserve(planesWithDistance.size());
580 for (
auto const& pair: planesWithDistance)
581 sortedPlanes.push_back(std::move(*(pair.first)));
583 planes = std::move(sortedPlanes);
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].