Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 // -*- C++ -*-
0003 //
0004 // Package:     Tracks
0005 // Class  :     FWPhase2TrackerCluster1DProxyBuilder
0006 //
0007 //
0008 
0009 #include "TEveStraightLineSet.h"
0010 #include "TEveCompound.h"
0011 #include "TEveBox.h"
0012 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
0013 #include "Fireworks/Core/interface/FWEventItem.h"
0014 #include "Fireworks/Core/interface/FWGeometry.h"
0015 #include "Fireworks/Core/interface/fwLog.h"
0016 #include "Fireworks/Tracks/interface/TrackUtils.h"
0017 
0018 #include "DataFormats/Phase2TrackerCluster/interface/Phase2TrackerCluster1D.h"
0019 
0020 class FWPhase2TrackerCluster1DProxyBuilder : public FWProxyBuilderBase {
0021 public:
0022   FWPhase2TrackerCluster1DProxyBuilder(void) {}
0023   ~FWPhase2TrackerCluster1DProxyBuilder(void) override {}
0024 
0025   REGISTER_PROXYBUILDER_METHODS();
0026 
0027   FWPhase2TrackerCluster1DProxyBuilder(const FWPhase2TrackerCluster1DProxyBuilder&) = delete;
0028   const FWPhase2TrackerCluster1DProxyBuilder& operator=(const FWPhase2TrackerCluster1DProxyBuilder&) = delete;
0029 
0030 private:
0031   void localModelChanges(const FWModelId& iId,
0032                          TEveElement* parent,
0033                          FWViewType::EType viewType,
0034                          const FWViewContext* vc) override;
0035 
0036   using FWProxyBuilderBase::build;
0037   void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) override;
0038 };
0039 
0040 void FWPhase2TrackerCluster1DProxyBuilder::build(const FWEventItem* iItem,
0041                                                  TEveElementList* product,
0042                                                  const FWViewContext*) {
0043   const Phase2TrackerCluster1DCollectionNew* pixels = nullptr;
0044 
0045   iItem->get(pixels);
0046 
0047   if (!pixels) {
0048     fwLog(fwlog::kWarning) << "failed get SiPixelDigis" << std::endl;
0049     return;
0050   }
0051 
0052   for (Phase2TrackerCluster1DCollectionNew::const_iterator set = pixels->begin(), setEnd = pixels->end(); set != setEnd;
0053        ++set) {
0054     unsigned int id = set->detId();
0055 
0056     const FWGeometry* geom = iItem->getGeom();
0057     const float* pars = geom->getParameters(id);
0058     const float* shape = geom->getShapePars(id);
0059 
0060     const edmNew::DetSet<Phase2TrackerCluster1D>& clusters = *set;
0061 
0062     for (edmNew::DetSet<Phase2TrackerCluster1D>::const_iterator itc = clusters.begin(), edc = clusters.end();
0063          itc != edc;
0064          ++itc) {
0065       TEveElement* itemHolder = createCompound();
0066       product->AddElement(itemHolder);
0067 
0068       if (!geom->contains(id)) {
0069         fwLog(fwlog::kWarning) << "failed get geometry of Phase2TrackerCluster1D with detid: " << id << std::endl;
0070         continue;
0071       }
0072 
0073       float halfLength = shape[2];
0074       float pitchSecond = pars[1];
0075 
0076       // line
0077       //
0078       TEveStraightLineSet* lineSet = new TEveStraightLineSet;
0079       float localPointBeg[3] = {fireworks::phase2PixelLocalX((*itc).center(), pars, shape),
0080                                 float((*itc).column()) * pitchSecond - halfLength,
0081                                 0.0};
0082       float localPointEnd[3] = {fireworks::phase2PixelLocalX((*itc).center(), pars, shape),
0083                                 float((*itc).column() + 1.0) * pitchSecond - halfLength,
0084                                 0.0};
0085 
0086       float globalPointBeg[3];
0087       float globalPointEnd[3];
0088       geom->localToGlobal(id, localPointBeg, globalPointBeg);
0089       geom->localToGlobal(id, localPointEnd, globalPointEnd);
0090 
0091       lineSet->AddLine(globalPointBeg, globalPointEnd);
0092       lineSet->AddMarker(0, 0.5f);
0093 
0094       const FWDisplayProperties& dp = FWProxyBuilderBase::item()->defaultDisplayProperties();
0095       lineSet->SetMarkerColor(dp.color());
0096 
0097       setupAddElement(lineSet, itemHolder);
0098     }
0099   }
0100 }
0101 
0102 void FWPhase2TrackerCluster1DProxyBuilder::localModelChanges(const FWModelId& iId,
0103                                                              TEveElement* parent,
0104                                                              FWViewType::EType viewType,
0105                                                              const FWViewContext* vc) {
0106   if (TEveStraightLineSet* ls = dynamic_cast<TEveStraightLineSet*>(*parent->BeginChildren())) {
0107     Color_t c = FWProxyBuilderBase::item()->modelInfo(iId.index()).displayProperties().color();
0108     for (TEveProjectable::ProjList_i j = ls->BeginProjecteds(); j != ls->EndProjecteds(); ++j) {
0109       if (TEveStraightLineSet* pls = dynamic_cast<TEveStraightLineSet*>(*j)) {
0110         pls->SetMarkerColor(c);
0111         pls->ElementChanged();
0112       }
0113     }
0114 
0115     ls->SetMarkerColor(c);
0116     ls->ElementChanged();
0117   }
0118 }
0119 
0120 REGISTER_FWPROXYBUILDER(FWPhase2TrackerCluster1DProxyBuilder,
0121                         Phase2TrackerCluster1DCollectionNew,
0122                         "Phase2TrackerCluster1D",
0123                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);