Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:     MTD
0004 // Class  :     FWEtlClusterProxyBuilder
0005 //
0006 //
0007 // Original Author:
0008 //         Created:  Thu Nov 28 10:00:00 CET 2022
0009 //
0010 
0011 #include "TEvePointSet.h"
0012 #include "TEveCompound.h"
0013 
0014 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
0015 #include "Fireworks/Core/interface/FWEventItem.h"
0016 #include "Fireworks/Core/interface/FWGeometry.h"
0017 #include "Fireworks/Core/interface/fwLog.h"
0018 
0019 #include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
0020 
0021 class FWEtlClusterProxyBuilder : public FWProxyBuilderBase {
0022 public:
0023   FWEtlClusterProxyBuilder(void) {}
0024   ~FWEtlClusterProxyBuilder(void) override {}
0025 
0026   REGISTER_PROXYBUILDER_METHODS();
0027 
0028   // Disable default copy constructor
0029   FWEtlClusterProxyBuilder(const FWEtlClusterProxyBuilder&) = delete;
0030   // Disable default assignment operator
0031   const FWEtlClusterProxyBuilder& operator=(const FWEtlClusterProxyBuilder&) = delete;
0032 
0033 private:
0034   using FWProxyBuilderBase::build;
0035   void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) override;
0036 };
0037 
0038 void FWEtlClusterProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) {
0039   const FTLClusterCollection* clusters = nullptr;
0040 
0041   iItem->get(clusters);
0042 
0043   if (!clusters) {
0044     fwLog(fwlog::kWarning) << "failed to get the ETL Cluster Collection" << std::endl;
0045     return;
0046   }
0047 
0048   const FWGeometry* geom = iItem->getGeom();
0049 
0050   TEvePointSet* pointSet = new TEvePointSet();
0051   TEveElement* itemHolder = createCompound();
0052   product->AddElement(itemHolder);
0053 
0054   for (const auto& detSet : *clusters) {
0055     unsigned int id = detSet.detId();
0056 
0057     if (!geom->contains(id)) {
0058       fwLog(fwlog::kWarning) << "failed to get ETL geometry element with detid: " << id << std::endl;
0059       continue;
0060     }
0061 
0062     const float* pars = geom->getParameters(id);
0063 
0064     for (const auto& cluster : detSet) {
0065       // --- Get the ETL cluster local position:
0066       float x_local = (cluster.x() + 0.5f) * pars[0] + pars[2];
0067       float y_local = (cluster.y() + 0.5f) * pars[1] + pars[3];
0068 
0069       const float localPoint[3] = {x_local, y_local, 0.0};
0070 
0071       float globalPoint[3];
0072       geom->localToGlobal(id, localPoint, globalPoint);
0073 
0074       pointSet->SetNextPoint(globalPoint[0], globalPoint[1], globalPoint[2]);
0075 
0076     }  // cluster loop
0077 
0078   }  // detSet loop
0079 
0080   setupAddElement(pointSet, itemHolder);
0081 }
0082 
0083 REGISTER_FWPROXYBUILDER(FWEtlClusterProxyBuilder,
0084                         FTLClusterCollection,
0085                         "ETLclusters",
0086                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);