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  :     FWBtlClusterProxyBuilder
0005 //
0006 //
0007 // Original Author:
0008 //         Created:  Thu Nov 24 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 FWBtlClusterProxyBuilder : public FWProxyBuilderBase {
0022 public:
0023   FWBtlClusterProxyBuilder(void) {}
0024   ~FWBtlClusterProxyBuilder(void) override {}
0025 
0026   REGISTER_PROXYBUILDER_METHODS();
0027 
0028   // Disable default copy constructor
0029   FWBtlClusterProxyBuilder(const FWBtlClusterProxyBuilder&) = delete;
0030   // Disable default assignment operator
0031   const FWBtlClusterProxyBuilder& operator=(const FWBtlClusterProxyBuilder&) = delete;
0032 
0033 private:
0034   using FWProxyBuilderBase::build;
0035   void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) override;
0036 };
0037 
0038 void FWBtlClusterProxyBuilder::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 BTL 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 BTL 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 BTL cluster local position:
0066       float x_local =
0067           (cluster.getClusterErrorX() < 0. ? (cluster.x() + 0.5f) * pars[0] + pars[2] : cluster.getClusterPosX());
0068       float y_local = (cluster.y() + 0.5f) * pars[1] + pars[3];
0069 
0070       const float localPoint[3] = {x_local, y_local, 0.0};
0071 
0072       float globalPoint[3];
0073       geom->localToGlobal(id, localPoint, globalPoint);
0074 
0075       pointSet->SetNextPoint(globalPoint[0], globalPoint[1], globalPoint[2]);
0076 
0077     }  // cluster loop
0078 
0079   }  // detSet loop
0080 
0081   setupAddElement(pointSet, itemHolder);
0082 }
0083 
0084 REGISTER_FWPROXYBUILDER(FWBtlClusterProxyBuilder,
0085                         FTLClusterCollection,
0086                         "BTLclusters",
0087                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);