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  :     FWEtlRecHitProxyBuilder
0005 //
0006 //
0007 // Original Author:
0008 //         Created:  Tue Dec 6 17: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/FTLRecHitCollections.h"
0020 
0021 class FWEtlRecHitProxyBuilder : public FWProxyBuilderBase {
0022 public:
0023   FWEtlRecHitProxyBuilder(void) {}
0024   ~FWEtlRecHitProxyBuilder(void) override {}
0025 
0026   REGISTER_PROXYBUILDER_METHODS();
0027 
0028   // Disable default copy constructor
0029   FWEtlRecHitProxyBuilder(const FWEtlRecHitProxyBuilder&) = delete;
0030   // Disable default assignment operator
0031   const FWEtlRecHitProxyBuilder& operator=(const FWEtlRecHitProxyBuilder&) = delete;
0032 
0033 private:
0034   using FWProxyBuilderBase::build;
0035   void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) override;
0036 };
0037 
0038 void FWEtlRecHitProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) {
0039   const FTLRecHitCollection* recHits = nullptr;
0040 
0041   iItem->get(recHits);
0042 
0043   if (!recHits) {
0044     fwLog(fwlog::kWarning) << "failed to get the ETL RecHit Collection" << std::endl;
0045     return;
0046   }
0047 
0048   const FWGeometry* geom = iItem->getGeom();
0049 
0050   for (const auto& hit : *recHits) {
0051     unsigned int id = hit.id().rawId();
0052 
0053     if (!geom->contains(id)) {
0054       fwLog(fwlog::kWarning) << "failed to get ETL geometry element with detid: " << id << std::endl;
0055       continue;
0056     }
0057 
0058     TEvePointSet* pointSet = new TEvePointSet();
0059 
0060     TEveElement* itemHolder = createCompound();
0061     product->AddElement(itemHolder);
0062 
0063     const float* pars = geom->getParameters(id);
0064 
0065     // --- Get the ETL RecHit local position:
0066     float x_local = (hit.row() + 0.5f) * pars[0] + pars[2];
0067     float y_local = (hit.column() + 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     setupAddElement(pointSet, itemHolder);
0077 
0078   }  // recHits loop
0079 }
0080 
0081 REGISTER_FWPROXYBUILDER(FWEtlRecHitProxyBuilder,
0082                         FTLRecHitCollection,
0083                         "ETLrechits",
0084                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);