Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 #include <vector>
0004 #include "TEveGeoNode.h"
0005 #include "TEveLine.h"
0006 #include "TEveCompound.h"
0007 #include "TEveGeoShape.h"
0008 
0009 #include "Fireworks/Core/interface/fwLog.h"
0010 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0011 #include "Fireworks/Core/interface/FWEventItem.h"
0012 #include "Fireworks/Core/interface/FWGeometry.h"
0013 #include "Fireworks/Tracks/interface/TrackUtils.h"
0014 
0015 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0016 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0017 
0018 class FWSiStripClusterProxyBuilder : public FWProxyBuilderBase {
0019 public:
0020   FWSiStripClusterProxyBuilder(void);
0021   ~FWSiStripClusterProxyBuilder(void) override;
0022 
0023   REGISTER_PROXYBUILDER_METHODS();
0024 
0025   //    virtual void cleanLocal();
0026   void itemBeingDestroyed(const FWEventItem*) override;
0027 
0028 protected:
0029   using FWProxyBuilderBase::build;
0030   void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) override;
0031   void localModelChanges(const FWModelId& iId,
0032                          TEveElement* iCompound,
0033                          FWViewType::EType viewType,
0034                          const FWViewContext* vc) override;
0035 
0036 public:
0037   FWSiStripClusterProxyBuilder(const FWSiStripClusterProxyBuilder&) = delete;
0038   const FWSiStripClusterProxyBuilder& operator=(const FWSiStripClusterProxyBuilder&) = delete;
0039 
0040 private:
0041   TEveElementList* m_shapeList;
0042 };
0043 
0044 FWSiStripClusterProxyBuilder::FWSiStripClusterProxyBuilder() : m_shapeList(nullptr) {
0045   m_shapeList = new TEveElementList("shapePool");
0046   m_shapeList->IncDenyDestroy();
0047 }
0048 
0049 FWSiStripClusterProxyBuilder::~FWSiStripClusterProxyBuilder() { m_shapeList->DecDenyDestroy(); }
0050 
0051 void FWSiStripClusterProxyBuilder::itemBeingDestroyed(const FWEventItem* iItem) {
0052   m_shapeList->DestroyElements();
0053   FWProxyBuilderBase::itemBeingDestroyed(iItem);
0054 }
0055 
0056 void FWSiStripClusterProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) {
0057   const edmNew::DetSetVector<SiStripCluster>* clusters = nullptr;
0058   iItem->get(clusters);
0059   if (nullptr == clusters)
0060     return;
0061   int cntEl = 0;
0062 
0063   for (TEveElement::List_i ei = product->BeginChildren(); ei != product->EndChildren(); ++ei) {
0064     TEveElement* holder = *ei;
0065     if (holder->HasChildren()) {
0066       holder->SetRnrSelfChildren(false, false);
0067       holder->RemoveElement(holder->LastChild());
0068     }
0069   }
0070 
0071   // check if need to create more shapes
0072   int sdiff = clusters->size() - m_shapeList->NumChildren();
0073   for (int i = 0; i <= sdiff; ++i)
0074     m_shapeList->AddElement(new TEveGeoShape("Det"));
0075 
0076   TEveElement::List_i shapeIt = m_shapeList->BeginChildren();
0077   for (edmNew::DetSetVector<SiStripCluster>::const_iterator set = clusters->begin(), setEnd = clusters->end();
0078        set != setEnd;
0079        ++set) {
0080     unsigned int id = set->detId();
0081     const FWGeometry::GeomDetInfo& info = *iItem->getGeom()->find(id);
0082 
0083     double array[16] = {info.matrix[0],
0084                         info.matrix[3],
0085                         info.matrix[6],
0086                         0.,
0087                         info.matrix[1],
0088                         info.matrix[4],
0089                         info.matrix[7],
0090                         0.,
0091                         info.matrix[2],
0092                         info.matrix[5],
0093                         info.matrix[8],
0094                         0.,
0095                         info.translation[0],
0096                         info.translation[1],
0097                         info.translation[2],
0098                         1.};
0099 
0100     // note TEveGeoShape owns shape
0101     TEveGeoShape* shape = (TEveGeoShape*)(*shapeIt);
0102     shape->SetShape(iItem->getGeom()->getShape(info));
0103     shape->SetTransMatrix(array);
0104     shape->SetRnrSelf(true);
0105     shapeIt++;
0106 
0107     for (edmNew::DetSet<SiStripCluster>::const_iterator ic = set->begin(), icEnd = set->end(); ic != icEnd; ++ic) {
0108       TEveCompound* itemHolder = nullptr;
0109       TEveLine* line = nullptr;
0110 
0111       if (cntEl < product->NumChildren()) {
0112         TEveElement::List_i pit = product->BeginChildren();
0113         std::advance(pit, cntEl);
0114         itemHolder = (TEveCompound*)*pit;
0115         itemHolder->SetRnrSelfChildren(true, true);
0116 
0117         line = (TEveLine*)(itemHolder->FirstChild());
0118         setupAddElement(shape, itemHolder);
0119       } else {
0120         itemHolder = createCompound();
0121         setupAddElement(itemHolder, product);
0122         line = new TEveLine("line");
0123         setupAddElement(line, itemHolder);
0124         setupAddElement(shape, itemHolder);
0125       }
0126       shape->SetMainTransparency(75);
0127 
0128       // setup line pnts
0129       float localTop[3] = {0.0, 0.0, 0.0};
0130       float localBottom[3] = {0.0, 0.0, 0.0};
0131       fireworks::localSiStrip((*ic).firstStrip(), localTop, localBottom, iItem->getGeom()->getParameters(id), id);
0132       float globalTop[3];
0133       float globalBottom[3];
0134       iItem->getGeom()->localToGlobal(id, localTop, globalTop, localBottom, globalBottom);
0135       line->SetPoint(0, globalTop[0], globalTop[1], globalTop[2]);
0136       line->SetPoint(1, globalBottom[0], globalBottom[1], globalBottom[2]);
0137 
0138       cntEl++;
0139     }
0140   }
0141 }
0142 void FWSiStripClusterProxyBuilder::localModelChanges(const FWModelId& iId,
0143                                                      TEveElement* iCompound,
0144                                                      FWViewType::EType viewType,
0145                                                      const FWViewContext* vc) {
0146   increaseComponentTransparency(iId.index(), iCompound, "Det", 60);
0147 }
0148 
0149 REGISTER_FWPROXYBUILDER(FWSiStripClusterProxyBuilder,
0150                         edmNew::DetSetVector<SiStripCluster>,
0151                         "SiStripCluster",
0152                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);