00001 #include "Geometry/HcalTowerAlgo/interface/HcalDDDGeometryLoader.h"
00002 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00003 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00004 #include "Geometry/CaloGeometry/interface/IdealObliquePrism.h"
00005 #include "Geometry/CaloGeometry/interface/IdealZPrism.h"
00006 #include "Geometry/CaloEventSetup/interface/CaloGeometryLoader.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008
00009 #include<string>
00010
00011 typedef CaloCellGeometry::CCGFloat CCGFloat ;
00012
00013
00014
00015 HcalDDDGeometryLoader::HcalDDDGeometryLoader(const DDCompactView & cpv) {
00016 std::string name = "HcalHits";
00017 numberingFromDDD = new HcalNumberingFromDDD(name, cpv);
00018 }
00019
00020 HcalDDDGeometryLoader::~HcalDDDGeometryLoader() {
00021 delete numberingFromDDD;
00022 }
00023
00024
00025 HcalDDDGeometryLoader::ReturnType
00026 HcalDDDGeometryLoader::load(const HcalTopology& topo, DetId::Detector det, int subdet) {
00027
00028 HcalSubdetector hsub = static_cast<HcalSubdetector>(subdet);
00029
00030
00031 HcalDDDGeometry* gDDD ( new HcalDDDGeometry(topo) );
00032 ReturnType geom ( gDDD );
00033
00034 if ( geom->cornersMgr() == 0 ) {
00035 const unsigned int count (numberingFromDDD->numberOfCells(HcalBarrel ) +
00036 numberingFromDDD->numberOfCells(HcalEndcap ) +
00037 numberingFromDDD->numberOfCells(HcalForward) +
00038 numberingFromDDD->numberOfCells(HcalOuter ) );
00039 geom->allocateCorners( count ) ;
00040 }
00041
00042
00043
00044 if ( geom->parMgr() == 0 ) geom->allocatePar( 500, 3 ) ;
00045
00046 fill (hsub, gDDD, geom );
00047 return geom ;
00048 }
00049
00050 HcalDDDGeometryLoader::ReturnType
00051 HcalDDDGeometryLoader::load(const HcalTopology& topo) {
00052
00053 HcalDDDGeometry* gDDD ( new HcalDDDGeometry(topo) );
00054 ReturnType geom ( gDDD );
00055
00056 if( geom->cornersMgr() == 0 ) {
00057 const unsigned int count (numberingFromDDD->numberOfCells(HcalBarrel ) +
00058 numberingFromDDD->numberOfCells(HcalEndcap ) +
00059 numberingFromDDD->numberOfCells(HcalForward) +
00060 numberingFromDDD->numberOfCells(HcalOuter ) );
00061 geom->allocateCorners( count ) ;
00062 }
00063 if( geom->parMgr() == 0 ) geom->allocatePar( 500, 3 ) ;
00064
00065 fill(HcalBarrel, gDDD, geom);
00066 fill(HcalEndcap, gDDD, geom);
00067 fill(HcalForward, gDDD, geom);
00068 fill(HcalOuter, gDDD, geom);
00069 return geom ;
00070 }
00071
00072 void HcalDDDGeometryLoader::fill(HcalSubdetector subdet,
00073 HcalDDDGeometry* geometryDDD,
00074 CaloSubdetectorGeometry* geom ) {
00075
00076
00077 std::vector<HcalCellType> hcalCells = numberingFromDDD->HcalCellTypes(subdet);
00078 geometryDDD->insertCell(hcalCells);
00079 #ifdef DebugLog
00080 LogDebug("HCalGeom") << "HcalDDDGeometryLoader::fill gets "
00081 << hcalCells.size() << " cells for subdetector "
00082 << subdet;
00083 #endif
00084
00085
00086 double deg = M_PI/180.;
00087 std::vector<HcalDetId> hcalIds;
00088 for (unsigned int i=0; i<hcalCells.size(); i++) {
00089 int etaRing = hcalCells[i].etaBin();
00090 int depthBin = hcalCells[i].depthSegment();
00091 int phiInc = 4/hcalCells[i].nPhiModule();
00092 unsigned int iphi = 1;
00093 if (hcalCells[i].unitPhi() == 4) iphi = 3;
00094 double dphi = (hcalCells[i].phiBinWidth())*deg;
00095 double phi =-(hcalCells[i].phiOffset())*deg + 0.5*dphi;
00096 std::vector<int>missPlus = hcalCells[i].missingPhiPlus();
00097 std::vector<int>missMinus = hcalCells[i].missingPhiMinus();
00098 #ifdef DebugLog
00099 LogDebug("HCalGeom") << "HcalDDDGeometryLoader: Subdet " << subdet
00100 << " eta " << etaRing << " depth " << depthBin
00101 << " modules " << hcalCells[i].nPhiModule() << " "
00102 << phiInc << " phi " << phi/deg << " " << dphi/deg
00103 << " Missing " << missPlus.size() << "/"
00104 << missMinus.size();
00105 #endif
00106 for (int k = 0; k < hcalCells[i].nPhiBins(); k++) {
00107 bool ok = true;
00108 for (unsigned int kk = 0; kk < missPlus.size(); kk++)
00109 if (iphi == (unsigned int)(missPlus[kk])) ok = false;
00110 if (ok) {
00111 #ifdef DebugLog
00112 LogDebug("HCalGeom") << "HcalDDDGeometryLoader::fill Cell " << i
00113 << " eta " << etaRing << " phi " << iphi << "("
00114 << phi/deg << ", " << dphi/deg << ") depth "
00115 << depthBin;
00116 #endif
00117 HcalDetId id(subdet, etaRing, iphi, depthBin);
00118 hcalIds.push_back(id);
00119 makeCell(id,hcalCells[i],phi,dphi,geom) ;
00120 }
00121 if (hcalCells[i].nHalves() > 1) {
00122 ok = true;
00123 for (unsigned int kk = 0; kk < missMinus.size(); kk++)
00124 if (iphi == (unsigned int)(missMinus[kk])) ok = false;
00125 if (ok) {
00126 #ifdef DebugLog
00127 LogDebug("HCalGeom") << "HcalDDDGeometryLoader::fill Cell " << i
00128 << " eta " << -etaRing << " phi " << iphi <<" ("
00129 << phi/deg << ", " << dphi/deg << ") depth "
00130 << depthBin;
00131 #endif
00132 HcalDetId id(subdet, -etaRing, iphi, depthBin);
00133 hcalIds.push_back(id);
00134 makeCell(id,hcalCells[i],phi,dphi,geom) ;
00135 }
00136 }
00137 iphi += phiInc;
00138 phi += dphi;
00139 }
00140 }
00141
00142 edm::LogInfo("HCalGeom") << "Number of HCAL DetIds made for " << subdet
00143 << " is " << hcalIds.size();
00144 }
00145
00146 void
00147 HcalDDDGeometryLoader::makeCell( const HcalDetId& detId,
00148 HcalCellType hcalCell,
00149 double phi,
00150 double dphi,
00151 CaloSubdetectorGeometry* geom) const {
00152
00153
00154 double eta1 = hcalCell.etaMin();
00155 double eta2 = hcalCell.etaMax();
00156 HcalSubdetector subdet = detId.subdet();
00157 double eta = 0.5*(eta1+eta2) * detId.zside();
00158 double deta = (eta2-eta1);
00159 double theta = 2.0*atan(exp(-eta));
00160
00161
00162 bool rzType = hcalCell.depthType();
00163 bool isBarrel = (subdet == HcalBarrel || subdet == HcalOuter);
00164
00165 double z, r, thickness;
00166 #ifdef DebugLog
00167 double r0, r1, r2;
00168 #endif
00169 if (rzType) {
00170 r = hcalCell.depthMin();
00171 if (isBarrel) {
00172 z = r * sinh(eta);
00173 thickness = (hcalCell.depthMax() - r) * cosh(eta);
00174 #ifdef DebugLog
00175 r1 = r;
00176 r2 = hcalCell.depthMax();
00177 r0 = 0.5*(r1+r2);
00178 #endif
00179 } else {
00180 z = r * sinh(eta2);
00181 thickness = 2. * hcalCell.halfSize();
00182 r = z/sinh(std::abs(eta));
00183 #ifdef DebugLog
00184 r0 = z/sinh(std::abs(eta));
00185 r1 = z/sinh(std::abs(eta)+0.5*deta);
00186 r2 = z/sinh(std::abs(eta)-0.5*deta);
00187 #endif
00188 }
00189 #ifdef DebugLog
00190 LogDebug("HCalGeom") << "HcalDDDGeometryLoader::makeCell SubDet " << subdet
00191 << " eta = " << eta << " theta = " << theta
00192 << " r = " << r << " thickness = " << thickness
00193 << " r0-r2 (" << r0 << ":" << r1 << ":" << r2 << ")";
00194 #endif
00195 } else {
00196 z = hcalCell.depthMin();
00197 thickness = hcalCell.depthMax() - z;
00198 z *= detId.zside();
00199 r = z * tan(theta);
00200 thickness /= std::abs(cos(theta));
00201 #ifdef DebugLog
00202 r0 = z/sinh(std::abs(eta));
00203 r1 = z/sinh(std::abs(eta)+0.5*deta);
00204 r2 = z/sinh(std::abs(eta)-0.5*deta);
00205 LogDebug("HCalGeom") << "HcalDDDGeometryLoader::makeCell SubDet " << subdet
00206 << " eta = " << eta << " theta = " << theta
00207 << " z = " << z << " r = " << r << " thickness = "
00208 << thickness << " r0-r2 (" << r0 << ":" << r1 << ":"
00209 << r2 << ")";
00210 #endif
00211 }
00212
00213 double x = r * cos(phi);
00214 double y = r * sin(phi);
00215 GlobalPoint point(x,y,z);
00216
00217 #ifdef DebugLog
00218 LogDebug("HCalGeom") << "HcalDDDGeometryLoader::makeCell for " << detId
00219 << " Point " << point << " deta = " << deta
00220 << " dphi = " << dphi << " thickness = " << thickness
00221 << " isBarrel = " << isBarrel << " " << rzType;
00222 #endif
00223
00224 std::vector<CCGFloat> hp ;
00225 hp.reserve(3) ;
00226
00227 if (subdet==HcalForward)
00228 {
00229 hp.push_back(deta/2.) ;
00230 hp.push_back(dphi/2.) ;
00231 hp.push_back(thickness/2.) ;
00232 }
00233 else
00234 {
00235 const double sign ( isBarrel ? 1 : -1 ) ;
00236 hp.push_back(deta/2.) ;
00237 hp.push_back(dphi/2.) ;
00238 hp.push_back(sign*thickness/2.) ;
00239 }
00240 geom->newCell( point, point, point,
00241 CaloCellGeometry::getParmPtr( hp,
00242 geom->parMgr(),
00243 geom->parVecVec() ),
00244 detId ) ;
00245 }