Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-03 04:10:02

0001 /*
0002  *  FWDTDigiProxyBuilder.cc
0003  *  FWorks
0004  *
0005  *  Created by Ianna Osborne on 6/7/10.
0006  *
0007  */
0008 
0009 #include "TEveGeoNode.h"
0010 #include "TEvePointSet.h"
0011 #include "TEveCompound.h"
0012 #include "TGeoArb8.h"
0013 #include "TEveBox.h"
0014 
0015 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
0016 #include "Fireworks/Core/interface/FWEventItem.h"
0017 #include "Fireworks/Core/interface/FWGeometry.h"
0018 #include "Fireworks/Core/interface/fwLog.h"
0019 
0020 #include "DataFormats/DTDigi/interface/DTDigiCollection.h"
0021 
0022 namespace {
0023   void addTube(TEveBox* shape, const FWGeometry::GeomDetInfo& info, float localPos[3], const float* pars) {
0024     const Float_t width = pars[0] / 2.;
0025     const Float_t thickness = pars[1] / 2.;
0026     const Float_t length = pars[2] / 2.;
0027 
0028     const Float_t vtx[24] = {localPos[0] - width, -length, -thickness, localPos[0] - width, length,  -thickness,
0029                              localPos[0] + width, length,  -thickness, localPos[0] + width, -length, -thickness,
0030                              localPos[0] - width, -length, thickness,  localPos[0] - width, length,  thickness,
0031                              localPos[0] + width, length,  thickness,  localPos[0] + width, -length, thickness};
0032 
0033     double array[16] = {info.matrix[0],
0034                         info.matrix[3],
0035                         info.matrix[6],
0036                         0.,
0037                         info.matrix[1],
0038                         info.matrix[4],
0039                         info.matrix[7],
0040                         0.,
0041                         info.matrix[2],
0042                         info.matrix[5],
0043                         info.matrix[8],
0044                         0.,
0045                         info.translation[0],
0046                         info.translation[1],
0047                         info.translation[2],
0048                         1.};
0049 
0050     shape->SetVertices(vtx);
0051     shape->SetTransMatrix(array);
0052     shape->SetDrawFrame(false);
0053     shape->SetMainTransparency(75);
0054   }
0055 }  // namespace
0056 
0057 class FWDTDigiProxyBuilder : public FWProxyBuilderBase {
0058 public:
0059   FWDTDigiProxyBuilder(void) {}
0060   ~FWDTDigiProxyBuilder(void) override {}
0061 
0062   bool haveSingleProduct(void) const override { return false; }
0063 
0064   REGISTER_PROXYBUILDER_METHODS();
0065 
0066   // Disable default copy constructor
0067   FWDTDigiProxyBuilder(const FWDTDigiProxyBuilder&) = delete;
0068   // Disable default assignment operator
0069   const FWDTDigiProxyBuilder& operator=(const FWDTDigiProxyBuilder&) = delete;
0070 
0071 private:
0072   using FWProxyBuilderBase::buildViewType;
0073   void buildViewType(const FWEventItem* iItem,
0074                      TEveElementList* product,
0075                      FWViewType::EType,
0076                      const FWViewContext*) override;
0077 };
0078 
0079 void FWDTDigiProxyBuilder::buildViewType(const FWEventItem* iItem,
0080                                          TEveElementList* product,
0081                                          FWViewType::EType type,
0082                                          const FWViewContext*) {
0083   const DTDigiCollection* digis = nullptr;
0084   iItem->get(digis);
0085 
0086   if (!digis) {
0087     return;
0088   }
0089   const FWGeometry* geom = iItem->getGeom();
0090 
0091   for (DTDigiCollection::DigiRangeIterator dri = digis->begin(), dre = digis->end(); dri != dre; ++dri) {
0092     const DTLayerId& layerId = (*dri).first;
0093     unsigned int rawid = layerId.rawId();
0094     const DTDigiCollection::Range& range = (*dri).second;
0095 
0096     if (!geom->contains(rawid)) {
0097       fwLog(fwlog::kWarning) << "failed to get geometry of DT with detid: " << rawid << std::endl;
0098 
0099       TEveCompound* compound = createCompound();
0100       setupAddElement(compound, product);
0101 
0102       continue;
0103     }
0104 
0105     const float* pars = geom->getParameters(rawid);
0106     FWGeometry::IdToInfoItr det = geom->find(rawid);
0107 
0108     int superLayer = layerId.superlayerId().superLayer();
0109 
0110     float localPos[3] = {0.0, 0.0, 0.0};
0111 
0112     // Loop over the digis of this DetUnit
0113     for (DTDigiCollection::const_iterator it = range.first; it != range.second; ++it) {
0114       // The x wire position in the layer, starting from its wire number.
0115       float firstChannel = pars[3];
0116       float nChannels = pars[5];
0117       localPos[0] = ((*it).wire() - (firstChannel - 1) - 0.5) * pars[0] - nChannels / 2.0 * pars[0];
0118 
0119       if (type == FWViewType::k3D || type == FWViewType::kISpy) {
0120         TEveBox* box = new TEveBox;
0121         setupAddElement(box, product);
0122         ::addTube(box, *det, localPos, pars);
0123       } else if (((type == FWViewType::kRhoPhi || type == FWViewType::kRhoPhiPF) && superLayer != 2) ||
0124                  (type == FWViewType::kRhoZ && superLayer == 2)) {
0125         TEvePointSet* pointSet = new TEvePointSet;
0126         pointSet->SetMarkerStyle(24);
0127         setupAddElement(pointSet, product);
0128 
0129         float globalPos[3];
0130         geom->localToGlobal(*det, localPos, globalPos);
0131         pointSet->SetNextPoint(globalPos[0], globalPos[1], globalPos[2]);
0132 
0133         TEveBox* box = new TEveBox;
0134         setupAddElement(box, product);
0135         ::addTube(box, *det, localPos, pars);
0136       } else {
0137         TEveCompound* compound = createCompound();
0138         setupAddElement(compound, product);
0139       }
0140     }
0141   }
0142 }
0143 
0144 REGISTER_FWPROXYBUILDER(FWDTDigiProxyBuilder,
0145                         DTDigiCollection,
0146                         "DT Digis",
0147                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);