File indexing completed on 2024-04-06 12:11:49
0001 #include "TEveGeoNode.h"
0002 #include "TEveGeoShape.h"
0003 #include "TEveStraightLineSet.h"
0004 #include "TGeoArb8.h"
0005
0006 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0007 #include "Fireworks/Core/interface/FWEventItem.h"
0008 #include "Fireworks/Core/interface/FWGeometry.h"
0009 #include "Fireworks/Core/interface/fwLog.h"
0010
0011 #include "DataFormats/GEMRecHit/interface/GEMSegmentCollection.h"
0012
0013 class FWGEMSegmentProxyBuilder : public FWSimpleProxyBuilderTemplate<GEMSegment> {
0014 public:
0015 FWGEMSegmentProxyBuilder() {}
0016 ~FWGEMSegmentProxyBuilder() override {}
0017
0018 bool haveSingleProduct() const override { return false; }
0019
0020 REGISTER_PROXYBUILDER_METHODS();
0021
0022 FWGEMSegmentProxyBuilder(const FWGEMSegmentProxyBuilder&) = delete;
0023 const FWGEMSegmentProxyBuilder& operator=(const FWGEMSegmentProxyBuilder&) = delete;
0024
0025 private:
0026 using FWSimpleProxyBuilderTemplate<GEMSegment>::buildViewType;
0027 void buildViewType(const GEMSegment& iData,
0028 unsigned int iIndex,
0029 TEveElement& oItemHolder,
0030 FWViewType::EType type,
0031 const FWViewContext*) override;
0032 };
0033
0034 void FWGEMSegmentProxyBuilder::buildViewType(const GEMSegment& iData,
0035 unsigned int iIndex,
0036 TEveElement& oItemHolder,
0037 FWViewType::EType type,
0038 const FWViewContext*) {
0039 const FWGeometry* geom = item()->getGeom();
0040 unsigned int rawid = iData.gemDetId().rawId();
0041
0042 if (!geom->contains(rawid)) {
0043 fwLog(fwlog::kError) << "failed to get geometry of GEM chamber with rawid: " << rawid << std::endl;
0044 return;
0045 }
0046
0047 TEveStraightLineSet* segmentSet = new TEveStraightLineSet();
0048
0049 segmentSet->SetLineWidth(3);
0050 segmentSet->SetMarkerColor(item()->defaultDisplayProperties().color());
0051 segmentSet->SetMarkerSize(0.5);
0052 setupAddElement(segmentSet, &oItemHolder);
0053 TEveGeoShape* shape = geom->getEveShape(rawid);
0054 if (shape) {
0055 if (TGeoTrap* box = dynamic_cast<TGeoTrap*>(shape->GetShape()))
0056 {
0057 shape->SetMainTransparency(75);
0058 shape->SetMainColor(item()->defaultDisplayProperties().color());
0059 segmentSet->AddElement(shape);
0060
0061 LocalPoint pos = iData.localPosition();
0062 LocalVector dir = iData.localDirection();
0063 LocalVector unit = dir.unit();
0064
0065 double localPosition[3] = {pos.x(), pos.y(), pos.z()};
0066 double localDirectionIn[3] = {dir.x(), dir.y(), dir.z()};
0067 double localDirectionOut[3] = {-dir.x(), -dir.y(), -dir.z()};
0068
0069 Double_t distIn = box->DistFromInside(localPosition, localDirectionIn);
0070 Double_t distOut = box->DistFromInside(localPosition, localDirectionOut);
0071 LocalVector vIn = unit * distIn;
0072 LocalVector vOut = -unit * distOut;
0073 float localSegmentInnerPoint[3] = {static_cast<float>(localPosition[0] + vIn.x()),
0074 static_cast<float>(localPosition[1] + vIn.y()),
0075 static_cast<float>(localPosition[2] + vIn.z())};
0076
0077 float localSegmentOuterPoint[3] = {static_cast<float>(localPosition[0] + vOut.x()),
0078 static_cast<float>(localPosition[1] + vOut.y()),
0079 static_cast<float>(localPosition[2] + vOut.z())};
0080
0081 float globalSegmentInnerPoint[3];
0082 float globalSegmentOuterPoint[3];
0083
0084 geom->localToGlobal(
0085 rawid, localSegmentInnerPoint, globalSegmentInnerPoint, localSegmentOuterPoint, globalSegmentOuterPoint);
0086 if (type == FWViewType::kRhoPhi && std::abs(dir.x()) < 0.1) {
0087 segmentSet->AddMarker(globalSegmentInnerPoint[0], globalSegmentInnerPoint[1], globalSegmentInnerPoint[2]);
0088 } else
0089 segmentSet->AddLine(globalSegmentInnerPoint[0],
0090 globalSegmentInnerPoint[1],
0091 globalSegmentInnerPoint[2],
0092 globalSegmentOuterPoint[0],
0093 globalSegmentOuterPoint[1],
0094 globalSegmentOuterPoint[2]);
0095 }
0096 }
0097 }
0098
0099 REGISTER_FWPROXYBUILDER(FWGEMSegmentProxyBuilder,
0100 GEMSegment,
0101 "GEM Segment",
0102 FWViewType::kAll3DBits | FWViewType::kAllRPZBits);