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  :     FWCSCSegmentProxyBuilder
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 "TGeoArb8.h"
0017 
0018 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0019 #include "Fireworks/Core/interface/FWEventItem.h"
0020 #include "Fireworks/Core/interface/FWGeometry.h"
0021 #include "Fireworks/Core/interface/fwLog.h"
0022 
0023 #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
0024 
0025 class FWCSCSegmentProxyBuilder : public FWSimpleProxyBuilderTemplate<CSCSegment> {
0026 public:
0027   FWCSCSegmentProxyBuilder(void) {}
0028   ~FWCSCSegmentProxyBuilder(void) override {}
0029 
0030   REGISTER_PROXYBUILDER_METHODS();
0031 
0032   FWCSCSegmentProxyBuilder(const FWCSCSegmentProxyBuilder&) = delete;
0033   const FWCSCSegmentProxyBuilder& operator=(const FWCSCSegmentProxyBuilder&) = delete;
0034 
0035 private:
0036   using FWSimpleProxyBuilderTemplate<CSCSegment>::build;
0037   void build(const CSCSegment& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext*) override;
0038 };
0039 
0040 void FWCSCSegmentProxyBuilder::build(const CSCSegment& iData,
0041                                      unsigned int iIndex,
0042                                      TEveElement& oItemHolder,
0043                                      const FWViewContext*) {
0044   const FWGeometry* geom = item()->getGeom();
0045   unsigned int rawid = iData.cscDetId().rawId();
0046 
0047   if (!geom->contains(rawid)) {
0048     fwLog(fwlog::kError) << "failed to get geometry of CSC chamber with rawid: " << rawid << std::endl;
0049     return;
0050   }
0051 
0052   TEveStraightLineSet* segmentSet = new TEveStraightLineSet();
0053   // FIXME: This should be set elsewhere.
0054   segmentSet->SetLineWidth(3);
0055   setupAddElement(segmentSet, &oItemHolder);
0056 
0057   TEveGeoShape* shape = item()->getGeom()->getEveShape(rawid);
0058   if (TGeoTrap* trap = dynamic_cast<TGeoTrap*>(shape->GetShape()))  // Trapezoidal
0059   {
0060     LocalPoint pos = iData.localPosition();
0061     LocalVector dir = iData.localDirection();
0062     LocalVector unit = dir.unit();
0063 
0064     Double_t localPosition[3] = {pos.x(), pos.y(), pos.z()};
0065     Double_t localDirectionIn[3] = {dir.x(), dir.y(), dir.z()};
0066     Double_t localDirectionOut[3] = {-dir.x(), -dir.y(), -dir.z()};
0067 
0068     float distIn = trap->DistFromInside(localPosition, localDirectionIn);
0069     float distOut = trap->DistFromInside(localPosition, localDirectionOut);
0070     LocalVector vIn = unit * distIn;
0071     LocalVector vOut = -unit * distOut;
0072     float localSegmentInnerPoint[3] = {static_cast<float>(localPosition[0] + vIn.x()),
0073                                        static_cast<float>(localPosition[1] + vIn.y()),
0074                                        static_cast<float>(localPosition[2] + vIn.z())};
0075 
0076     float localSegmentOuterPoint[3] = {static_cast<float>(localPosition[0] + vOut.x()),
0077                                        static_cast<float>(localPosition[1] + vOut.y()),
0078                                        static_cast<float>(localPosition[2] + vOut.z())};
0079 
0080     float globalSegmentInnerPoint[3];
0081     float globalSegmentOuterPoint[3];
0082 
0083     geom->localToGlobal(
0084         rawid, localSegmentInnerPoint, globalSegmentInnerPoint, localSegmentOuterPoint, globalSegmentOuterPoint);
0085 
0086     segmentSet->AddLine(globalSegmentInnerPoint[0],
0087                         globalSegmentInnerPoint[1],
0088                         globalSegmentInnerPoint[2],
0089                         globalSegmentOuterPoint[0],
0090                         globalSegmentOuterPoint[1],
0091                         globalSegmentOuterPoint[2]);
0092   }
0093 }
0094 
0095 REGISTER_FWPROXYBUILDER(FWCSCSegmentProxyBuilder,
0096                         CSCSegment,
0097                         "CSC-segments",
0098                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);