00001
00014 #ifndef GEOMETRY_HH
00015 #define GEOMETRY_HH
00016
00017 #include "LArUtilBase.hh"
00018 #include <TMath.h>
00019 #include <TVector3.h>
00020 #include <set>
00021
00022 namespace larutil {
00026 class Geometry : public LArUtilBase{
00027
00028 private:
00029
00031 Geometry(bool default_load=true);
00032
00034 virtual ~Geometry(){};
00035
00036 static Geometry* _me;
00037
00038 public:
00039
00041 static const Geometry* GetME(bool default_load=true)
00042 {
00043 if(!_me) _me = new Geometry(default_load);
00044 return _me;
00045 }
00046
00047
00048
00050 UInt_t Nchannels() const
00051 { return fChannelToWireMap.size(); }
00052
00054 UInt_t NOpChannels() const
00055 { return fOpChannelVtx.size(); }
00056
00058 UInt_t Nviews() const
00059 { return fWirePitch.size(); }
00060
00062 UInt_t Nplanes() const
00063 { return fPlanePitch.size(); }
00064
00066 UInt_t Nwires(UInt_t p) const;
00067
00069
00070
00072 larlight::GEO::SigType_t SignalType(const UInt_t channel) const;
00073
00075 larlight::GEO::SigType_t PlaneToSignalType(const UChar_t plane) const;
00076
00078 larlight::GEO::View_t View(const UInt_t channel) const;
00079
00081 larlight::GEO::View_t PlaneToView(const UChar_t plane) const;
00082
00084 std::set<larlight::GEO::View_t> const Views() const;
00085
00087 UInt_t PlaneWireToChannel(const UInt_t plane,
00088 const UInt_t wire) const;
00089
00091 UChar_t ChannelToPlane(const UInt_t ch) const;
00092
00094 UInt_t ChannelToWire(const UInt_t ch)const;
00095
00097 UInt_t NearestChannel(const Double_t worldLoc[3],
00098 const UInt_t PlaneNo) const;
00099
00101 UInt_t NearestChannel(const std::vector<Double_t> &worldLoc,
00102 const UInt_t PlaneNo) const;
00103
00105 UInt_t NearestChannel(const TVector3& worldLoc,
00106 const UInt_t PlaneNo) const;
00107
00109 UInt_t NearestWire(const Double_t worldLoc[3],
00110 const UInt_t PlaneNo) const;
00111
00113 UInt_t NearestWire(const std::vector<Double_t> &worldLoc,
00114 const UInt_t PlaneNo) const;
00115
00117 UInt_t NearestWire(const TVector3& worldLoc,
00118 const UInt_t PlaneNo) const;
00119
00121 Double_t DetHalfWidth() const
00122 { return fDetHalfWidth; }
00123
00125 Double_t DetHalfHeight() const
00126 { return fDetHalfHeight; }
00127
00129 Double_t DetLength() const
00130 { return fDetLength; }
00131
00133 Double_t CryostatHalfWidth() const
00134 { return fCryoHalfWidth; }
00135
00137 Double_t CryostatHalfHeight() const
00138 { return fCryoHalfHeight; }
00139
00141 Double_t CryostatLength() const
00142 { return fCryoLength; }
00143
00145
00146
00147 private:
00148
00149 Double_t fDetLength;
00150 Double_t fDetHalfWidth;
00151 Double_t fDetHalfHeight;
00152
00153 Double_t fCryoLength;
00154 Double_t fCryoHalfWidth;
00155 Double_t fCryoHalfHeight;
00156
00157 public:
00158
00160 Double_t PlanePitch(const UChar_t p1 = 0,const UChar_t p2 = 1) const;
00161
00163 Double_t WirePitch(const UInt_t w1=0,
00164 const UInt_t w2=1,
00165 const UChar_t plane = 0) const;
00166
00168 Double_t WirePitch(const larlight::GEO::View_t view) const;
00169
00171 Double_t WireAngleToVertical(larlight::GEO::View_t view) const;
00172
00174
00175
00176
00177
00178
00179
00180
00181
00182
00189 bool ValueInRange(const Double_t value, Double_t min, Double_t max) const
00190 { if(min>max) std::swap(min,max); return ( (min <= value) && (value <= max) ); }
00191
00192 void WireEndPoints(const UChar_t plane,
00193 const UInt_t wire,
00194 Double_t *xyzStart,
00195 Double_t *xyzEnd) const;
00196
00197 bool ChannelsIntersect(const UInt_t c1, const UInt_t c2, Double_t &y, Double_t &z) const;
00198
00199 void IntersectionPoint(const UInt_t wire1, const UInt_t wire2,
00200 const UChar_t plane1, const UChar_t plane2,
00201 Double_t start_w1[3], Double_t end_w1[3],
00202 Double_t start_w2[3], Double_t end_w2[3],
00203 Double_t &y, Double_t &z) const;
00204
00205 void IntersectionPoint(const UInt_t wire1, const UInt_t wire2,
00206 const UChar_t plane1, const UChar_t plane2,
00207 Double_t &y, Double_t &z) const;
00208
00209
00211
00212
00214 UInt_t GetClosestOpChannel(const Double_t * xyz) const;
00215
00217 UInt_t GetClosestOpChannel(const Double_t * xyz, Double_t &dist) const;
00218
00220 void GetOpChannelPosition(const UInt_t i, Double_t *xyz) const;
00221
00222 const std::vector<Double_t>& PlaneOriginVtx(UChar_t plane);
00223
00224 void PlaneOriginVtx(UChar_t plane, Double_t *vtx) const;
00225
00226 virtual bool LoadData(bool force_reload=false);
00227
00228 protected:
00229
00230 virtual bool ReadTree();
00231
00232 virtual void ClearData();
00233
00234 private:
00235
00236
00237 std::vector<UChar_t> fChannelToPlaneMap;
00238 std::vector<UShort_t> fChannelToWireMap;
00239 std::vector<std::vector<UShort_t> > fPlaneWireToChannelMap;
00240
00241
00242 std::vector<larlight::GEO::SigType_t> fSignalType;
00243 std::vector<larlight::GEO::View_t> fViewType;
00244 std::vector<Double_t> fPlanePitch;
00245
00246
00247
00248 std::vector<std::vector<std::vector<Double_t > > > fWireStartVtx;
00249 std::vector<std::vector<std::vector<Double_t > > > fWireEndVtx;
00250
00251 std::vector<std::vector<Double_t> > fPlaneOriginVtx;
00252
00253
00254 std::vector<Double_t> fWirePitch;
00255 std::vector<Double_t> fWireAngle;
00256
00257 std::vector<std::vector<Float_t> > fOpChannelVtx;
00258
00259
00260 std::vector<Double_t> fOrthVectorsY;
00261 std::vector<Double_t> fOrthVectorsZ;
00262 std::vector<Double_t> fFirstWireProj;
00263 };
00264 }
00265
00266 #endif
00267
00268