Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:52

0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/Framework/interface/ModuleFactory.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0005 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0006 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0007 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
0008 #include "CalibTracker/Records/interface/SiStripRegionCablingRcd.h"
0009 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0010 #include "CalibFormats/SiStripObjects/interface/SiStripRegionCabling.h"
0011 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0012 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0013 
0014 using namespace sistrip;
0015 
0016 class SiStripRegionConnectivity : public edm::ESProducer {
0017 public:
0018   SiStripRegionConnectivity(const edm::ParameterSet&);
0019   ~SiStripRegionConnectivity() override;
0020 
0021   std::unique_ptr<SiStripRegionCabling> produceRegionCabling(const SiStripRegionCablingRcd&);
0022 
0023 private:
0024   edm::ESGetToken<SiStripDetCabling, SiStripDetCablingRcd> detcablingToken_;
0025   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkgeomToken_;
0026   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0027 
0028   /** Number of regions in eta,phi */
0029   uint32_t etadivisions_;
0030   uint32_t phidivisions_;
0031 
0032   /** Tracker extent in eta */
0033   double etamax_;
0034 };
0035 
0036 SiStripRegionConnectivity::SiStripRegionConnectivity(const edm::ParameterSet& pset)
0037     : etadivisions_(pset.getUntrackedParameter<unsigned int>("EtaDivisions", 10)),
0038       phidivisions_(pset.getUntrackedParameter<unsigned int>("PhiDivisions", 10)),
0039       etamax_(pset.getUntrackedParameter<double>("EtaMax", 2.4))
0040 
0041 {
0042   auto cc = setWhatProduced(this, &SiStripRegionConnectivity::produceRegionCabling);
0043   detcablingToken_ = cc.consumes();
0044   tkgeomToken_ = cc.consumes();
0045   tTopoToken_ = cc.consumes();
0046 }
0047 
0048 SiStripRegionConnectivity::~SiStripRegionConnectivity() {}
0049 
0050 std::unique_ptr<SiStripRegionCabling> SiStripRegionConnectivity::produceRegionCabling(
0051     const SiStripRegionCablingRcd& iRecord) {
0052   const auto& detcabling = iRecord.get(detcablingToken_);
0053   const auto& tkgeom = iRecord.get(tkgeomToken_);
0054   const auto& tTopo = iRecord.get(tTopoToken_);
0055 
0056   //here build an object of type SiStripRegionCabling using the information from class SiStripDetCabling **PLUS** the geometry.
0057 
0058   //Construct region cabling object
0059   auto RegionConnections = std::make_unique<SiStripRegionCabling>(etadivisions_, phidivisions_, etamax_);
0060 
0061   //Construct region cabling map
0062   SiStripRegionCabling::Cabling regioncabling(
0063       etadivisions_ * phidivisions_,
0064       SiStripRegionCabling::RegionCabling(
0065           SiStripRegionCabling::ALLSUBDETS,
0066           SiStripRegionCabling::WedgeCabling(SiStripRegionCabling::ALLLAYERS, SiStripRegionCabling::ElementCabling())));
0067 
0068   //Loop det cabling
0069   for (const auto& idet : detcabling.getDetCabling()) {
0070     if (!idet.first || (idet.first == sistrip::invalid32_))
0071       continue;
0072 
0073     // Check if geom det unit exists
0074     auto geom_det = tkgeom.idToDetUnit(DetId(idet.first));
0075     auto strip_det = dynamic_cast<StripGeomDetUnit const*>(geom_det);
0076     if (!strip_det) {
0077       continue;
0078     }
0079 
0080     //Calculate region from geometry
0081     double eta = tkgeom.idToDet(DetId(idet.first))->position().eta();
0082     double phi = tkgeom.idToDet(DetId(idet.first))->position().phi().value();
0083     uint32_t reg = RegionConnections->region(SiStripRegionCabling::Position(eta, phi));
0084 
0085     //Find subdet from det-id
0086     uint32_t subdet = static_cast<uint32_t>(SiStripRegionCabling::subdetFromDetId(idet.first));
0087 
0088     //Find layer from det-id
0089     uint32_t layer = tTopo.layer(idet.first);
0090 
0091     //@@ BELOW IS TEMP FIX TO HANDLE BUG IN DET CABLING
0092     const std::vector<const FedChannelConnection*>& conns = idet.second;
0093 
0094     //Update region cabling map
0095     regioncabling[reg][subdet][layer].push_back(SiStripRegionCabling::Element());
0096     auto& elem = regioncabling[reg][subdet][layer].back();
0097     elem.first = idet.first;
0098     elem.second.resize(conns.size());
0099     for (const auto& iconn : conns) {
0100       if ((iconn != nullptr) && (iconn->apvPairNumber() < conns.size())) {
0101         elem.second[iconn->apvPairNumber()] = *iconn;
0102       }
0103     }
0104   }
0105 
0106   //Add map to region cabling object
0107   RegionConnections->setRegionCabling(regioncabling);
0108 
0109   return RegionConnections;
0110 }
0111 
0112 DEFINE_FWK_EVENTSETUP_MODULE(SiStripRegionConnectivity);