File indexing completed on 2024-04-06 11:59:19
0001 #include "Calibration/IsolatedParticles/interface/CaloConstants.h"
0002 #include "Calibration/IsolatedParticles/interface/DetIdFromEtaPhi.h"
0003 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0004 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0005 #include "DataFormats/Math/interface/Point3D.h"
0006 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0007 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0008 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010
0011 #include <sstream>
0012
0013 namespace spr {
0014
0015 const DetId findDetIdECAL(const CaloGeometry* geo, double eta, double phi, bool debug) {
0016 double radius = 0;
0017 int subdet = 0;
0018 double theta = 2.0 * std::atan(exp(-eta));
0019 if (std::abs(eta) > spr::etaBEEcal) {
0020 radius = spr::zFrontEE / std::abs(std::cos(theta));
0021 subdet = EcalEndcap;
0022 } else {
0023 radius = spr::rFrontEB / std::sin(theta);
0024 subdet = EcalBarrel;
0025 }
0026 const CaloSubdetectorGeometry* gECAL = geo->getSubdetectorGeometry(DetId::Ecal, subdet);
0027 if (debug)
0028 edm::LogVerbatim("IsoTrack") << "findDetIdECAL: eta " << eta << " theta " << theta << " phi " << phi << " radius "
0029 << radius << " subdet " << subdet;
0030 return spr::findDetIdCalo(gECAL, theta, phi, radius, debug);
0031 }
0032
0033 const DetId findDetIdHCAL(const CaloGeometry* geo, double eta, double phi, bool debug) {
0034 double radius = 0;
0035 double theta = 2.0 * std::atan(exp(-eta));
0036 if (std::abs(eta) > spr::etaBEHcal)
0037 radius = spr::zFrontHE / std::abs(std::cos(theta));
0038 else
0039 radius = spr::rFrontHB / std::sin(theta);
0040 const CaloSubdetectorGeometry* gHCAL = geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel);
0041 if (debug)
0042 edm::LogVerbatim("IsoTrack") << "findDetIdHCAL: eta " << eta << " theta " << theta << " phi " << phi << " radius "
0043 << radius;
0044 return spr::findDetIdCalo(gHCAL, theta, phi, radius, debug);
0045 }
0046
0047 const DetId findDetIdCalo(const CaloSubdetectorGeometry* geo, double theta, double phi, double radius, bool debug) {
0048 double rcyl = radius * std::sin(theta);
0049 double z = radius * std::cos(theta);
0050 GlobalPoint point(rcyl * std::cos(phi), rcyl * std::sin(phi), z);
0051 const DetId cell = geo->getClosestCell(point);
0052 if (debug) {
0053 std::ostringstream st1;
0054 if (cell.det() == DetId::Ecal) {
0055 if (cell.subdetId() == EcalBarrel)
0056 st1 << (EBDetId)(cell);
0057 else
0058 st1 << (EEDetId)(cell);
0059 } else {
0060 st1 << (HcalDetId)(cell);
0061 }
0062 edm::LogVerbatim("IsoTrack") << "findDetIdCalo: rcyl " << rcyl << " z " << z << " Point " << point << " DetId "
0063 << st1.str();
0064 }
0065 return cell;
0066 }
0067
0068 }