Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:49

0001 // -*- C++ -*-
0002 //
0003 // Package:     Muons
0004 // Class  :     FWDTSegmentProxyBuilder
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Sun Jan  6 23:57:00 EST 2008
0011 //
0012 
0013 #include "TEveGeoNode.h"
0014 #include "TEveGeoShape.h"
0015 #include "TEveStraightLineSet.h"
0016 #include "TEvePointSet.h"
0017 #include "TGeoArb8.h"
0018 
0019 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0020 #include "Fireworks/Core/interface/FWEventItem.h"
0021 #include "Fireworks/Core/interface/FWGeometry.h"
0022 #include "Fireworks/Core/interface/fwLog.h"
0023 
0024 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0025 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
0026 
0027 #include <vector>
0028 
0029 class FWDTSegmentProxyBuilder : public FWSimpleProxyBuilderTemplate<DTRecSegment4D> {
0030 public:
0031   FWDTSegmentProxyBuilder(void) {}
0032   ~FWDTSegmentProxyBuilder(void) override {}
0033 
0034   bool haveSingleProduct() const override { return false; }
0035 
0036   REGISTER_PROXYBUILDER_METHODS();
0037 
0038   FWDTSegmentProxyBuilder(const FWDTSegmentProxyBuilder&) = delete;
0039   const FWDTSegmentProxyBuilder& operator=(const FWDTSegmentProxyBuilder&) = delete;
0040 
0041 private:
0042   using FWSimpleProxyBuilderTemplate<DTRecSegment4D>::buildViewType;
0043   void buildViewType(const DTRecSegment4D& iData,
0044                      unsigned int iIndex,
0045                      TEveElement& oItemHolder,
0046                      FWViewType::EType type,
0047                      const FWViewContext*) override;
0048 };
0049 
0050 void FWDTSegmentProxyBuilder::buildViewType(const DTRecSegment4D& iData,
0051                                             unsigned int iIndex,
0052                                             TEveElement& oItemHolder,
0053                                             FWViewType::EType type,
0054                                             const FWViewContext*) {
0055   unsigned int rawid = iData.chamberId().rawId();
0056   const FWGeometry* geom = item()->getGeom();
0057 
0058   if (!geom->contains(rawid)) {
0059     fwLog(fwlog::kError) << "failed to get geometry of DT chamber with detid: " << rawid << std::endl;
0060     return;
0061   }
0062 
0063   TEveStraightLineSet* segmentSet = new TEveStraightLineSet();
0064   // FIXME: This should be set elsewhere.
0065   segmentSet->SetLineWidth(3);
0066   setupAddElement(segmentSet, &oItemHolder);
0067 
0068   TEveGeoShape* shape = item()->getGeom()->getEveShape(rawid);
0069   if (shape) {
0070     if (TGeoBBox* box = dynamic_cast<TGeoBBox*>(shape->GetShape())) {
0071       LocalPoint pos = iData.localPosition();
0072       LocalVector dir = iData.localDirection();
0073       LocalVector unit = dir.unit();
0074 
0075       double localPosition[3] = {pos.x(), pos.y(), pos.z()};
0076       double localDirectionIn[3] = {dir.x(), dir.y(), dir.z()};
0077       double localDirectionOut[3] = {-dir.x(), -dir.y(), -dir.z()};
0078 
0079       // In RhoZ view, draw segments at the middle of the chamber, otherwise they won't align with 1D rechits,
0080       // for which only one coordinate is known.
0081       if (type == FWViewType::kRhoZ) {
0082         localPosition[0] = 0;
0083         localDirectionIn[0] = 0;
0084         localDirectionOut[0] = 0;
0085       }
0086 
0087       Double_t distIn = box->DistFromInside(localPosition, localDirectionIn);
0088       Double_t distOut = box->DistFromInside(localPosition, localDirectionOut);
0089       LocalVector vIn = unit * distIn;
0090       LocalVector vOut = -unit * distOut;
0091       float localSegmentInnerPoint[3] = {static_cast<float>(localPosition[0] + vIn.x()),
0092                                          static_cast<float>(localPosition[1] + vIn.y()),
0093                                          static_cast<float>(localPosition[2] + vIn.z())};
0094 
0095       float localSegmentOuterPoint[3] = {static_cast<float>(localPosition[0] + vOut.x()),
0096                                          static_cast<float>(localPosition[1] + vOut.y()),
0097                                          static_cast<float>(localPosition[2] + vOut.z())};
0098 
0099       float globalSegmentInnerPoint[3];
0100       float globalSegmentOuterPoint[3];
0101 
0102       geom->localToGlobal(
0103           rawid, localSegmentInnerPoint, globalSegmentInnerPoint, localSegmentOuterPoint, globalSegmentOuterPoint);
0104 
0105       segmentSet->AddLine(globalSegmentInnerPoint[0],
0106                           globalSegmentInnerPoint[1],
0107                           globalSegmentInnerPoint[2],
0108                           globalSegmentOuterPoint[0],
0109                           globalSegmentOuterPoint[1],
0110                           globalSegmentOuterPoint[2]);
0111 
0112       // Draw hits included in the segment
0113       TEvePointSet* pointSet = new TEvePointSet;
0114       // FIXME: This should be set elsewhere.
0115       pointSet->SetMarkerSize(1.5);
0116       setupAddElement(pointSet, &oItemHolder);
0117 
0118       std::vector<DTRecHit1D> recHits;
0119       const DTChamberRecSegment2D* phiSeg = iData.phiSegment();
0120       const DTSLRecSegment2D* zSeg = iData.zSegment();
0121       if (phiSeg) {
0122         std::vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
0123         copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits));
0124       }
0125       if (zSeg) {
0126         std::vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
0127         copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits));
0128       }
0129 
0130       for (std::vector<DTRecHit1D>::const_iterator rh = recHits.begin(); rh != recHits.end(); ++rh) {
0131         DTLayerId layerId = (*rh).wireId().layerId();
0132         LocalPoint hpos = (*rh).localPosition();
0133         float hitLocalPos[3] = {hpos.x(), hpos.y(), hpos.z()};
0134         if (type == FWViewType::kRhoZ) {
0135           // In RhoZ view, draw hits at the middle of the layer in the global Z coordinate,
0136           // otherwise they won't align with 1D rechits, for which only one coordinate is known.
0137           if (layerId.superLayer() == 2) {
0138             hitLocalPos[1] = 0;
0139           } else {
0140             hitLocalPos[0] = 0;
0141           }
0142         }
0143         float hitGlobalPoint[3];
0144         geom->localToGlobal(layerId, hitLocalPos, hitGlobalPoint);
0145         pointSet->SetNextPoint(hitGlobalPoint[0], hitGlobalPoint[1], hitGlobalPoint[2]);
0146       }
0147     }
0148   }
0149 }
0150 
0151 REGISTER_FWPROXYBUILDER(FWDTSegmentProxyBuilder,
0152                         DTRecSegment4D,
0153                         "DT-segments",
0154                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);