Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:     Muon
0004 // Class  :     FWCSCWireDigiProxyBuilder
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author: mccauley
0010 //         Created:  Sun Jan  6 23:57:00 EST 2008
0011 //
0012 
0013 #include "TEveStraightLineSet.h"
0014 #include "TEveCompound.h"
0015 
0016 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
0017 #include "Fireworks/Core/interface/FWEventItem.h"
0018 #include "Fireworks/Core/interface/FWGeometry.h"
0019 #include "Fireworks/Core/interface/fwLog.h"
0020 
0021 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
0022 
0023 #include <cmath>
0024 
0025 class FWCSCWireDigiProxyBuilder : public FWProxyBuilderBase {
0026 public:
0027   FWCSCWireDigiProxyBuilder() {}
0028   ~FWCSCWireDigiProxyBuilder() override {}
0029 
0030   REGISTER_PROXYBUILDER_METHODS();
0031 
0032   FWCSCWireDigiProxyBuilder(const FWCSCWireDigiProxyBuilder&) = delete;
0033   const FWCSCWireDigiProxyBuilder& operator=(const FWCSCWireDigiProxyBuilder&) = delete;
0034 
0035 private:
0036   using FWProxyBuilderBase::build;
0037   void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) override;
0038 
0039   // NOTE: these parameters are not available via a public interface
0040   // from the geometry or topology so must be hard-coded.
0041   double getYOfFirstWire(const int station, const int ring, const double length);
0042   double getAverageWireSpacing(const int station, const int ring);
0043 };
0044 
0045 double FWCSCWireDigiProxyBuilder::getYOfFirstWire(const int station, const int ring, const double length) {
0046   double yAlignmentFrame = 3.49;
0047   double alignmentPinToFirstWire;
0048 
0049   if (station == 1) {
0050     if (ring == 1 || ring == 4) {
0051       alignmentPinToFirstWire = 1.065;
0052       yAlignmentFrame = 0.0;
0053     }
0054 
0055     else  // ME12, ME 13
0056       alignmentPinToFirstWire = 2.85;
0057   }
0058 
0059   else if (station == 4 && ring == 1)
0060     alignmentPinToFirstWire = 3.04;
0061 
0062   else if (station == 3 && ring == 1)
0063     alignmentPinToFirstWire = 2.84;
0064 
0065   else  // ME21, ME22, ME32, ME42
0066     alignmentPinToFirstWire = 2.87;
0067 
0068   return (yAlignmentFrame - length) + alignmentPinToFirstWire;
0069 }
0070 
0071 double FWCSCWireDigiProxyBuilder::getAverageWireSpacing(const int station, const int ring) {
0072   // return radialExtentOfTheWirePlane / numOfWireGroups
0073   // These numbers come from cscSpec.xml
0074 
0075   if (ring == 2) {
0076     if (station == 1)
0077       return 174.81 / 64;
0078     else
0079       return 323.38 / 64;
0080   }
0081 
0082   if (station == 1 && (ring == 1 || ring == 4))
0083     return 150.5 / 48;
0084   if (station == 1 && ring == 3)
0085     return 164.47 / 32;
0086   if (station == 2 && ring == 1)
0087     return 189.97 / 112;
0088   if (station == 3 && ring == 1)
0089     return 170.01 / 96;
0090   if (station == 4 && ring == 1)
0091     return 149.73 / 96;
0092 
0093   return 0.0;
0094 }
0095 
0096 void FWCSCWireDigiProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) {
0097   const CSCWireDigiCollection* digis = nullptr;
0098 
0099   iItem->get(digis);
0100 
0101   if (!digis) {
0102     fwLog(fwlog::kWarning) << "Failed to get CSCWireDigis" << std::endl;
0103     return;
0104   }
0105   const FWGeometry* geom = iItem->getGeom();
0106 
0107   for (CSCWireDigiCollection::DigiRangeIterator dri = digis->begin(), driEnd = digis->end(); dri != driEnd; ++dri) {
0108     const CSCDetId& cscDetId = (*dri).first;
0109     unsigned int rawid = cscDetId.rawId();
0110     const CSCWireDigiCollection::Range& range = (*dri).second;
0111 
0112     if (!geom->contains(rawid)) {
0113       fwLog(fwlog::kWarning) << "Failed to get geometry of CSC chamber with detid: " << rawid << std::endl;
0114 
0115       TEveCompound* compound = createCompound();
0116       setupAddElement(compound, product);
0117 
0118       continue;
0119     }
0120 
0121     const float* shape = geom->getShapePars(rawid);
0122 
0123     float length = shape[4];
0124     float topWidth = shape[2];
0125     float bottomWidth = shape[1];
0126 
0127     // NOTE: do not use parameters right now: need to sort out what is finally needed
0128     //const float* parameters = iItem->getGeom()->getParameters( rawid );
0129     //float wireSpacing  = parameters[6];
0130     double wireSpacing = getAverageWireSpacing(cscDetId.station(), cscDetId.ring());
0131     //float wireAngle    = parameters[7];
0132     //float cosWireAngle = cos(wireAngle);
0133 
0134     double yOfFirstWire = getYOfFirstWire(cscDetId.station(), cscDetId.ring(), length);
0135 
0136     for (CSCWireDigiCollection::const_iterator dit = range.first; dit != range.second; ++dit) {
0137       TEveStraightLineSet* wireDigiSet = new TEveStraightLineSet();
0138       wireDigiSet->SetLineWidth(3);
0139       setupAddElement(wireDigiSet, product);
0140 
0141       int wireGroup = (*dit).getWireGroup();
0142       float yOfWire = yOfFirstWire + ((wireGroup - 1) * wireSpacing);
0143       float wireLength = yOfWire * (topWidth - bottomWidth) / length;
0144       wireLength += bottomWidth * 2.0;
0145 
0146       float localPointLeft[3] = {static_cast<float>(-wireLength * 0.5), yOfWire, static_cast<float>(0.0)};
0147 
0148       // NOTE: This is only an approximation for slanted wires.
0149       // Need to improve the determination of the x coordinate.
0150       float localPointRight[3] = {
0151           static_cast<float>(wireLength * 0.5), yOfWire, static_cast<float>(0.0)
0152           //wireLength*0.5, yOfWire + wireLength*tan(wireAngle), 0.0
0153       };
0154 
0155       float globalPointLeft[3];
0156       float globalPointRight[3];
0157 
0158       geom->localToGlobal(rawid, localPointLeft, globalPointLeft, localPointRight, globalPointRight);
0159 
0160       wireDigiSet->AddLine(globalPointLeft[0],
0161                            globalPointLeft[1],
0162                            globalPointLeft[2],
0163                            globalPointRight[0],
0164                            globalPointRight[1],
0165                            globalPointRight[2]);
0166     }
0167   }
0168 }
0169 
0170 REGISTER_FWPROXYBUILDER(FWCSCWireDigiProxyBuilder,
0171                         CSCWireDigiCollection,
0172                         "CSCWireDigi",
0173                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);