File indexing completed on 2023-03-17 11:01:40
0001 #include "TEveGeoNode.h"
0002 #include "TEveGeoShape.h"
0003 #include "TEveStraightLineSet.h"
0004 #include "TGeoArb8.h"
0005 #include "TEvePointSet.h"
0006
0007 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0008 #include "Fireworks/Core/interface/FWEventItem.h"
0009 #include "Fireworks/Core/interface/FWGeometry.h"
0010 #include "Fireworks/Core/interface/fwLog.h"
0011
0012 #include "DataFormats/GEMRecHit/interface/ME0SegmentCollection.h"
0013
0014 class FWME0SegmentProxyBuilder : public FWSimpleProxyBuilderTemplate<ME0Segment> {
0015 public:
0016 FWME0SegmentProxyBuilder(void) {}
0017 ~FWME0SegmentProxyBuilder(void) override {}
0018
0019 REGISTER_PROXYBUILDER_METHODS();
0020
0021 FWME0SegmentProxyBuilder(const FWME0SegmentProxyBuilder&) = delete;
0022 const FWME0SegmentProxyBuilder& operator=(const FWME0SegmentProxyBuilder&) = delete;
0023
0024 private:
0025 void build(const ME0Segment& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext*) override;
0026 };
0027
0028 void FWME0SegmentProxyBuilder::build(const ME0Segment& iData,
0029 unsigned int iIndex,
0030 TEveElement& oItemHolder,
0031 const FWViewContext*) {
0032 const FWGeometry* geom = item()->getGeom();
0033 unsigned int rawid = iData.me0DetId().rawId();
0034
0035 if (!geom->contains(rawid)) {
0036 fwLog(fwlog::kError) << "failed to get geometry of ME0 chamber with rawid: " << rawid << std::endl;
0037 return;
0038 }
0039
0040 TEveStraightLineSet* segmentSet = new TEveStraightLineSet();
0041
0042 segmentSet->SetLineWidth(5);
0043 setupAddElement(segmentSet, &oItemHolder);
0044
0045 TEveGeoShape* shape = item()->getGeom()->getEveShape(rawid);
0046 if (shape) {
0047 if (TGeoBBox* box = dynamic_cast<TGeoBBox*>(shape->GetShape())) {
0048 LocalPoint pos = iData.localPosition();
0049 LocalVector dir = iData.localDirection();
0050 LocalVector unit = dir.unit();
0051
0052 double localPosition[3] = {pos.x(), pos.y(), pos.z()};
0053 double localDirectionIn[3] = {dir.x(), dir.y(), dir.z()};
0054 double localDirectionOut[3] = {-dir.x(), -dir.y(), -dir.z()};
0055
0056 Double_t distIn = box->DistFromInside(localPosition, localDirectionIn);
0057 Double_t distOut = box->DistFromInside(localPosition, localDirectionOut);
0058 LocalVector vIn = unit * distIn;
0059 LocalVector vOut = -unit * distOut;
0060 float localSegmentInnerPoint[3] = {static_cast<float>(localPosition[0] + vIn.x()),
0061 static_cast<float>(localPosition[1] + vIn.y()),
0062 static_cast<float>(localPosition[2] + vIn.z())};
0063
0064 float localSegmentOuterPoint[3] = {static_cast<float>(localPosition[0] + vOut.x()),
0065 static_cast<float>(localPosition[1] + vOut.y()),
0066 static_cast<float>(localPosition[2] + vOut.z())};
0067
0068 float globalSegmentInnerPoint[3];
0069 float globalSegmentOuterPoint[3];
0070
0071 geom->localToGlobal(
0072 rawid, localSegmentInnerPoint, globalSegmentInnerPoint, localSegmentOuterPoint, globalSegmentOuterPoint);
0073
0074 segmentSet->AddLine(globalSegmentInnerPoint[0],
0075 globalSegmentInnerPoint[1],
0076 globalSegmentInnerPoint[2],
0077 globalSegmentOuterPoint[0],
0078 globalSegmentOuterPoint[1],
0079 globalSegmentOuterPoint[2]);
0080
0081
0082 TEvePointSet* pointSet = new TEvePointSet;
0083
0084 pointSet->SetMarkerSize(0.5);
0085 pointSet->SetMarkerColor(1);
0086 setupAddElement(pointSet, &oItemHolder);
0087 auto recHits = iData.specificRecHits();
0088 for (auto rh = recHits.begin(); rh != recHits.end(); rh++) {
0089 auto me0id = rh->me0Id();
0090 LocalPoint hpos = rh->localPosition();
0091 float hitLocalPos[3] = {hpos.x(), hpos.y(), hpos.z()};
0092 float hitGlobalPoint[3];
0093 geom->localToGlobal(me0id, hitLocalPos, hitGlobalPoint);
0094 pointSet->SetNextPoint(hitGlobalPoint[0], hitGlobalPoint[1], hitGlobalPoint[2]);
0095 }
0096 }
0097 }
0098 }
0099
0100 REGISTER_FWPROXYBUILDER(FWME0SegmentProxyBuilder,
0101 ME0Segment,
0102 "ME0-segments",
0103 FWViewType::kAll3DBits | FWViewType::kAllRPZBits);