Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:43:53

0001 #ifndef HTrackAssociator_HCaloDetIdAssociator_h
0002 #define HTrackAssociator_HCaloDetIdAssociator_h 1
0003 // -*- C++ -*-
0004 //
0005 // Package:    HTrackAssociator
0006 // Class:      HCaloDetIdAssociator
0007 //
0008 /*
0009 
0010  Description: <one line class summary>
0011 
0012  Implementation:
0013      <Notes on implementation>
0014 */
0015 //
0016 // Original Author:  Dmytro Kovalskyi
0017 // Modified for ECAL+HCAL by Michal Szleper
0018 //
0019 
0020 #include "Calibration/Tools/interface/DetIdAssociator.h"
0021 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0022 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0023 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0024 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0025 
0026 class HCaloDetIdAssociator : public HDetIdAssociator {
0027 public:
0028   HCaloDetIdAssociator() : HDetIdAssociator(72, 70, 0.087), geometry_(nullptr){};
0029   HCaloDetIdAssociator(const int nPhi, const int nEta, const double etaBinSize)
0030       : HDetIdAssociator(nPhi, nEta, etaBinSize), geometry_(nullptr){};
0031 
0032   virtual void setGeometry(const CaloGeometry* ptr) { geometry_ = ptr; };
0033 
0034 protected:
0035   void check_setup() override {
0036     HDetIdAssociator::check_setup();
0037     if (geometry_ == nullptr)
0038       throw cms::Exception("CaloGeometry is not set");
0039   };
0040 
0041   GlobalPoint getPosition(const DetId& id) override {
0042     GlobalPoint point = (id.det() == DetId::Hcal)
0043                             ? (static_cast<const HcalGeometry*>(geometry_->getSubdetectorGeometry(id)))->getPosition(id)
0044                             : geometry_->getPosition(id);
0045     return point;
0046   };
0047 
0048   std::set<DetId> getASetOfValidDetIds() override {
0049     std::set<DetId> setOfValidIds;
0050     const std::vector<DetId>& vectOfValidIds = geometry_->getValidDetIds(DetId::Calo, 1);
0051     for (std::vector<DetId>::const_iterator it = vectOfValidIds.begin(); it != vectOfValidIds.end(); ++it)
0052       setOfValidIds.insert(*it);
0053 
0054     return setOfValidIds;
0055   };
0056 
0057   std::vector<GlobalPoint> getDetIdPoints(const DetId& id) override {
0058     std::vector<GlobalPoint> points;
0059     if (!geometry_->getSubdetectorGeometry(id)) {
0060       LogDebug("CaloDetIdAssociator") << "Cannot find sub-detector geometry for " << id.rawId() << "\n";
0061     } else {
0062       if (!(geometry_->getSubdetectorGeometry(id))->getGeometry(id)) {
0063         LogDebug("CaloDetIdAssociator") << "Cannot find CaloCell geometry for " << id.rawId() << "\n";
0064       } else {
0065         const CaloCellGeometry::CornersVec& cor(geometry_->getSubdetectorGeometry(id)->getGeometry(id)->getCorners());
0066         points.assign(cor.begin(), cor.end());
0067         points.push_back(getPosition(id));
0068       }
0069     }
0070 
0071     return points;
0072   };
0073 
0074   bool insideElement(const GlobalPoint& point, const DetId& id) override {
0075     return geometry_->getSubdetectorGeometry(id)->getGeometry(id)->inside(point);
0076   };
0077 
0078   const CaloGeometry* geometry_;
0079 };
0080 #endif