00001
00002
00003
00005
00006 #include "Geometry/HcalCommonData/interface/HcalNumberingFromDDD.h"
00007
00008 #include "DetectorDescription/Base/interface/DDException.h"
00009 #include "DetectorDescription/Core/interface/DDFilter.h"
00010 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00011 #include "DetectorDescription/Core/interface/DDSolid.h"
00012 #include "DetectorDescription/Core/interface/DDValue.h"
00013
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015
00016 #include "CLHEP/Units/PhysicalConstants.h"
00017 #include "CLHEP/Units/SystemOfUnits.h"
00018 #include <iostream>
00019
00020 HcalNumberingFromDDD::HcalNumberingFromDDD(std::string & name,
00021 const DDCompactView & cpv) {
00022 edm::LogInfo("HCalGeom") << "Creating HcalNumberingFromDDD";
00023 initialize(name, cpv);
00024 }
00025
00026 HcalNumberingFromDDD::~HcalNumberingFromDDD() {
00027 edm::LogInfo("HCalGeom") << "Deleting HcalNumberingFromDDD";
00028 }
00029
00030 HcalNumberingFromDDD::HcalID HcalNumberingFromDDD::unitID(int det,
00031 Hep3Vector point,
00032 int depth,
00033 int lay) const {
00034
00035 double hx = point.x();
00036 double hy = point.y();
00037 double hz = point.z();
00038 double hR = sqrt(hx*hx+hy*hy+hz*hz);
00039 double htheta = (hR == 0. ? 0. : acos(std::max(std::min(hz/hR,1.0),-1.0)));
00040 double hsintheta = sin(htheta);
00041 double hphi = (hR*hsintheta == 0. ? 0. :atan2(hy,hx));
00042 double heta = (fabs(hsintheta) == 1.? 0. : -log(fabs(tan(htheta/2.))) );
00043
00044 int hsubdet=0;
00045 double etaR;
00046
00047
00048 if (det == 5) {
00049 hsubdet = static_cast<int>(HcalForward);
00050 hR = sqrt(hx*hx+hy*hy);
00051 etaR = (heta >= 0. ? hR : -hR);
00052 } else {
00053 etaR = heta;
00054 if (det == 3) {
00055 hsubdet = static_cast<int>(HcalBarrel);
00056 } else {
00057 hsubdet = static_cast<int>(HcalEndcap);
00058 }
00059 }
00060
00061 LogDebug("HCalGeom") << "HcalNumberingFromDDD: point = " << point << " det "
00062 << hsubdet << " eta/R " << etaR << " phi " << hphi;
00063
00064 HcalNumberingFromDDD::HcalID tmp = unitID(hsubdet,etaR,hphi,depth,lay);
00065 return tmp;
00066
00067 }
00068
00069 HcalNumberingFromDDD::HcalID HcalNumberingFromDDD::unitID(double eta,double fi,
00070 int depth,
00071 int lay) const {
00072
00073 int ieta = 0;
00074 double heta = fabs(eta);
00075 for (int i = 0; i < nEta; i++)
00076 if (heta > etaTable[i]) ieta = i + 1;
00077 int hsubdet=0;
00078 double etaR;
00079 if (ieta <= etaMin[1]) {
00080 if ((ieta <= etaMin[1] && depth==3) || ieta > etaMax[0]) {
00081 hsubdet = static_cast<int>(HcalEndcap);
00082 } else {
00083 hsubdet = static_cast<int>(HcalBarrel);
00084 }
00085 etaR = eta;
00086 } else {
00087 hsubdet = static_cast<int>(HcalForward);
00088 double theta = 2.*atan(exp(-heta));
00089 double hR = zVcal*tan(theta);
00090 etaR = (eta >= 0. ? hR : -hR);
00091 }
00092
00093 HcalNumberingFromDDD::HcalID tmp = unitID(hsubdet,etaR,fi,depth,lay);
00094 return tmp;
00095 }
00096
00097
00098 HcalNumberingFromDDD::HcalID HcalNumberingFromDDD::unitID(int det,
00099 double etaR,
00100 double phi,
00101 int depth,
00102 int lay) const {
00103
00104 int ieta=0;
00105 double fioff, fibin;
00106 double hetaR = fabs(etaR);
00107
00108
00109 if (det == static_cast<int>(HcalForward)) {
00110 fioff = phioff[2];
00111 ieta = etaMax[2];
00112 for (int i = nR-1; i > 0; i--)
00113 if (hetaR < rTable[i]) ieta = etaMin[2] + nR - i - 1;
00114 fibin = phibin[nEta+ieta-etaMin[2]-1];
00115 if (ieta > etaMax[2]-2 ) {
00116 fioff += 0.5*fibin;
00117 }
00118 } else {
00119 ieta = 1;
00120 for (int i = 0; i < nEta-1; i++)
00121 if (hetaR > etaTable[i]) ieta = i + 1;
00122 if (det == static_cast<int>(HcalBarrel)) {
00123 fioff = phioff[0];
00124 if (ieta > etaMax[0]) ieta = etaMax[0];
00125 } else {
00126 fioff = phioff[1];
00127 if (ieta <= etaMin[1]) ieta = etaMin[1];
00128 }
00129 fibin = phibin[ieta-1];
00130 }
00131
00132 int nphi = int((twopi+0.1*fibin)/fibin);
00133 int zside = etaR>0 ? 1: 0;
00134 double hphi = phi+fioff;
00135 if (hphi < 0) hphi += twopi;
00136 int iphi = int(hphi/fibin) + 1;
00137 if (iphi > nphi) iphi = 1;
00138
00139 LogDebug("HCalGeom") << "HcalNumberingFromDDD: etaR = " << etaR << " : "
00140 << zside << "/" << ieta << " phi " << hphi << " : "
00141 << iphi;
00142 HcalNumberingFromDDD::HcalID tmp = unitID(det,zside,depth,ieta,iphi,lay);
00143 return tmp;
00144
00145 }
00146
00147 HcalNumberingFromDDD::HcalID HcalNumberingFromDDD::unitID(int det, int zside,
00148 int depth, int etaR,
00149 int phi,
00150 int lay) const {
00151
00152
00153 if (det == static_cast<int>(HcalForward)) {
00154 } else {
00155 if (lay >= 0) {
00156 double fibin = phibin[etaR-1];
00157 int depth0 = depth1[etaR-1];
00158 int kphi = phi + int((phioff[3]+0.1)/fibin);
00159 kphi = (kphi-1)%4 + 1;
00160 if (etaR == nOff[0] && (kphi == 2 || kphi == 3)) depth0--;
00161 if (lay <= depth2[etaR-1]) {
00162 if (lay <= depth0) depth = 1;
00163 else depth = 2;
00164 } else if (lay <= depth3[etaR-1]) {
00165 depth = 3;
00166 } else depth = 4;
00167 } else if (det == static_cast<int>(HcalBarrel)) {
00168 if (depth==3) depth = 2;
00169 }
00170 if (det != static_cast<int>(HcalBarrel)) {
00171 if (etaR <= etaMin[1]) depth = 3;
00172 }
00173 }
00174 if (etaR == nOff[1] && depth > 2 && det == static_cast<int>(HcalEndcap))
00175 etaR = nOff[1]-1;
00176 if (det == static_cast<int>(HcalBarrel) && depth == 4) {
00177 det = static_cast<int>(HcalOuter);
00178 }
00179
00180 const double fiveDegInRad = 2*M_PI/72;
00181
00182 int iphi_skip=phi;
00183 int units=0;
00184 if (det==HcalForward) units=int(phibin[nEta+etaR-etaMin[2]-1]/fiveDegInRad+0.5);
00185 else units=int(phibin[etaR-1]/fiveDegInRad+0.5);
00186
00187 if (units==2) iphi_skip = (phi-1)*2+1;
00188 else if (units==4) iphi_skip = (phi-1)*4-1;
00189 if (iphi_skip < 0) iphi_skip += 72;
00190
00191 LogDebug("HCalGeom") << "HcalNumberingFromDDD: phi units=" << units
00192 << " iphi_skip=" << iphi_skip;
00193
00194 HcalNumberingFromDDD::HcalID tmp(det,zside,depth,etaR,phi,iphi_skip,lay);
00195
00196 LogDebug("HCalGeom") << "HcalNumberingFromDDD: det = " << det << " "
00197 << tmp.subdet << " zside = " << tmp.zside << " depth = "
00198 << tmp.depth << " eta/R = " << tmp.etaR << " phi = "
00199 << tmp.phi << " layer = " << tmp.lay;
00200 return tmp;
00201 }
00202
00203 HcalCellType::HcalCell HcalNumberingFromDDD::cell(int det, int zside,
00204 int depth, int etaR,
00205 int iphi, bool corr) const {
00206
00207 int idet = det;
00208 double etaMn = etaMin[0];
00209 double etaMx = etaMax[0];
00210 if (idet==static_cast<int>(HcalEndcap)) {
00211 etaMn = etaMin[1]; etaMx = etaMax[1];
00212 } else if (idet==static_cast<int>(HcalForward)) {
00213 etaMn = etaMin[2]; etaMx = etaMax[2];
00214 }
00215 if (corr) {
00216 if (etaR >= nOff[2] && depth == 3 && idet == static_cast<int>(HcalBarrel))
00217 idet = static_cast<int>(HcalEndcap);
00218 }
00219 double eta = 0, deta = 0, phi = 0, dphi = 0, rz = 0, drz = 0;
00220 bool ok = false, flagrz = true;
00221 if ((idet==static_cast<int>(HcalBarrel)||idet==static_cast<int>(HcalEndcap)||
00222 idet==static_cast<int>(HcalOuter)||idet==static_cast<int>(HcalForward))
00223 && etaR >=etaMn && etaR <= etaMx)
00224 ok = true;
00225 if (idet == static_cast<int>(HcalEndcap)) {
00226 if (depth < 3 && etaR <= etaMin[1]) ok = false;
00227 else if (depth > 2 && etaR == nOff[1]) ok = false;
00228 }
00229 if (ok) {
00230 int maxlay = (int)(rHB.size());
00231 if (idet == static_cast<int>(HcalEndcap)) maxlay = (int)(zHE.size());
00232 eta = getEta(idet, etaR, zside, depth);
00233 deta = deltaEta(idet, etaR, depth);
00234 double fibin, fioff;
00235 if (idet == static_cast<int>(HcalBarrel)||
00236 idet == static_cast<int>(HcalOuter)) {
00237 fioff = phioff[0];
00238 fibin = phibin[etaR-1];
00239 } else if (idet == static_cast<int>(HcalEndcap)) {
00240 fioff = phioff[1];
00241 fibin = phibin[etaR-1];
00242 } else {
00243 fioff = phioff[2];
00244 fibin = phibin[nEta+etaR-etaMin[2]-1];
00245 if (etaR > etaMax[2]-2 ) fioff += 0.5*fibin;
00246 }
00247 phi = fioff + (iphi - 0.5)*fibin;
00248 dphi = 0.5*fibin;
00249 if (idet == static_cast<int>(HcalForward)) {
00250 int ir = nR + etaMin[2] - etaR - 1;
00251 if (ir > 0 && ir < nR) {
00252 rz = 0.5*(rTable[ir]+rTable[ir-1]);
00253 drz = 0.5*(rTable[ir]-rTable[ir-1]);
00254 } else {
00255 ok = false;
00256 LogDebug("HCalGeom") << "HcalNumberingFromDDD: wrong eta " << etaR
00257 << " (" << ir << "/" << nR << ") Detector "
00258 << idet;
00259 }
00260 if (depth != 1 && depth != 2) {
00261 ok = false;
00262 LogDebug("HCalGeom") << "HcalNumberingFromDDD: wrong depth " << depth
00263 << " in Detector " << idet;
00264 }
00265 } else if (etaR <= nEta) {
00266 int depth0 = depth1[etaR-1];
00267 int kphi = iphi + int((phioff[3]+0.1)/fibin);
00268 kphi = (kphi-1)%4 + 1;
00269 if (etaR == nOff[0] && (kphi == 2 || kphi == 3)) depth0--;
00270 int laymin, laymax;
00271 if (depth == 1) {
00272 laymin = 1;
00273 laymax = depth0;
00274 } else if (depth == 2) {
00275 laymin = depth0+1;
00276 laymax = depth2[etaR-1];
00277 if (etaR==etaMax[0] && idet==static_cast<int>(HcalBarrel) &&
00278 nOff.size()>3) laymax = nOff[3];
00279 } else if (depth == 3) {
00280 laymin = depth2[etaR-1]+1;
00281 laymax = depth3[etaR-1];
00282 if (etaR<=etaMin[1] && idet==static_cast<int>(HcalEndcap)) {
00283 if (nOff.size() > 4) laymin = nOff[4];
00284 else laymin = 1;
00285 }
00286 } else {
00287 laymin = depth3[etaR-1]+1;
00288 laymax = maxlay;
00289 }
00290 if (laymin <= maxlay && laymax <= maxlay && laymin <= laymax) {
00291 if (idet == static_cast<int>(HcalEndcap)) {
00292 flagrz = false;
00293 rz = 0.5*(zHE[laymax-1]+zHE[laymin-1]);
00294 drz = 0.5*(zHE[laymax-1]-zHE[laymin-1]);
00295 } else {
00296 rz = 0.5*(rHB[laymax-1]+rHB[laymin-1]);
00297 drz = 0.5*(rHB[laymax-1]-rHB[laymin-1]);
00298 }
00299 } else {
00300 ok = false;
00301 LogDebug("HCalGeom") << "HcalNumberingFromDDD: wrong depth " << depth
00302 << " (Layer minimum " << laymin << " maximum "
00303 << laymax << " maxLay " << maxlay << ")";
00304 }
00305 } else {
00306 ok = false;
00307 LogDebug("HCalGeom") << "HcalNumberingFromDDD: wrong eta " << etaR
00308 << "/" << nEta << " Detector " << idet;
00309 }
00310 } else {
00311 ok = false;
00312 LogDebug("HCalGeom") << "HcalNumberingFromDDD: wrong eta " << etaR
00313 << " det " << idet;
00314 }
00315 HcalCellType::HcalCell tmp(ok,eta,deta,phi,dphi,rz,drz,flagrz);
00316
00317 LogDebug("HCalGeom") << "HcalNumberingFromDDD: det/side/depth/etaR/phi "
00318 << det << "/" << zside << "/" << depth << "/" << etaR
00319 << "/" << iphi << " Cell Flag " << tmp.ok << " "
00320 << tmp.eta << " " << tmp.deta << " phi " << tmp.phi
00321 << " " << tmp.dphi << " r(z) " << tmp.rz << " "
00322 << tmp.drz << " " << tmp.flagrz;
00323 return tmp;
00324 }
00325
00326 std::vector<double> HcalNumberingFromDDD::getEtaTable() const {
00327
00328 std::vector<double> tmp = etaTable;
00329 return tmp;
00330 }
00331
00332 std::vector<HcalCellType::HcalCellType> HcalNumberingFromDDD::HcalCellTypes() const{
00333
00334 std::vector<HcalCellType::HcalCellType> cellTypes =HcalCellTypes(HcalBarrel);
00335 LogDebug ("HCalGeom") << "HcalNumberingFromDDD: " << cellTypes.size()
00336 << " cells of type HCal Barrel";
00337 for (unsigned int i=0; i<cellTypes.size(); i++)
00338 LogDebug ("HCalGeom") << "Cell " << i << " " << cellTypes[i];
00339
00340 std::vector<HcalCellType::HcalCellType> hoCells =HcalCellTypes(HcalOuter);
00341 LogDebug ("HCalGeom") << "HcalNumberingFromDDD: " << hoCells.size()
00342 << " cells of type HCal Outer";
00343 for (unsigned int i=0; i<hoCells.size(); i++)
00344 LogDebug ("HCalGeom") << "Cell " << i << " " << hoCells[i];
00345
00346 cellTypes.insert(cellTypes.end(), hoCells.begin(), hoCells.end());
00347 std::vector<HcalCellType::HcalCellType> heCells =HcalCellTypes(HcalEndcap);
00348 LogDebug ("HCalGeom") << "HcalNumberingFromDDD: " << heCells.size()
00349 << " cells of type HCal Endcap";
00350 for (unsigned int i=0; i<heCells.size(); i++)
00351 LogDebug ("HCalGeom") << "Cell " << i << " " << heCells[i];
00352
00353 cellTypes.insert(cellTypes.end(), heCells.begin(), heCells.end());
00354 std::vector<HcalCellType::HcalCellType> hfCells =HcalCellTypes(HcalForward);
00355 LogDebug ("HCalGeom") << "HcalNumberingFromDDD: " << hfCells.size()
00356 << " cells of type HCal Forward";
00357 for (unsigned int i=0; i<hfCells.size(); i++)
00358 LogDebug ("HCalGeom") << "Cell " << i << " " << hfCells[i];
00359
00360 cellTypes.insert(cellTypes.end(), hfCells.begin(), hfCells.end());
00361 return cellTypes;
00362 }
00363
00364 std::vector<HcalCellType::HcalCellType> HcalNumberingFromDDD::HcalCellTypes(HcalSubdetector subdet) const {
00365
00366 std::vector<HcalCellType::HcalCellType> cellTypes;
00367 if (subdet == HcalForward) {
00368 if (dzVcal < 0) return cellTypes;
00369 }
00370
00371 int dmin, dmax, indx, nz, nmod;
00372 switch(subdet) {
00373 case HcalEndcap:
00374 dmin = 1; dmax = 3; indx = 1, nz = nzHE, nmod = nmodHE;
00375 break;
00376 case HcalForward:
00377 dmin = 1; dmax = 2; indx = 2, nz = 2, nmod = 18;
00378 break;
00379 case HcalOuter:
00380 dmin = 4; dmax = 4; indx = 0, nz = nzHB, nmod = nmodHB;
00381 break;
00382 default:
00383 dmin = 1; dmax = 3; indx = 0, nz = nzHB, nmod = nmodHB;
00384 break;
00385 }
00386
00387 int phi = 1, zside = 1;
00388 bool cor = false;
00389
00390
00391 int subdet0 = static_cast<int>(subdet);
00392 for (int depth=dmin; depth<=dmax; depth++) {
00393 int shift = getShift(subdet, depth);
00394 double gain = getGain (subdet, depth);
00395 for (int eta=etaMin[indx]; eta<= etaMax[indx]; eta++) {
00396 HcalCellType::HcalCell temp1 = cell(subdet0, zside, depth, eta, phi,cor);
00397 if (temp1.ok) {
00398 HcalCellType::HcalCellType temp2(subdet, eta, phi, depth, temp1,
00399 shift, gain, nz, nmod);
00400 cellTypes.push_back(temp2);
00401 }
00402 }
00403 }
00404 return cellTypes;
00405 }
00406
00407 double HcalNumberingFromDDD::getEta(int det, int etaR, int zside,
00408 int depth) const {
00409
00410 double tmp = 0;
00411 if (det == static_cast<int>(HcalForward)) {
00412 int ir = nR + etaMin[2] - etaR - 1;
00413 if (ir > 0 && ir < nR)
00414 tmp = 0.5*(getEta(rTable[ir-1],zVcal)+getEta(rTable[ir],zVcal));
00415 } else {
00416 if (etaR > 0 && etaR < nEta) {
00417 if (etaR == nOff[1]-1 && depth > 2) {
00418 tmp = 0.5*(etaTable[etaR+1]+etaTable[etaR-1]);
00419 } else {
00420 tmp = 0.5*(etaTable[etaR]+etaTable[etaR-1]);
00421 }
00422 }
00423 }
00424 if (zside == 0) tmp = -tmp;
00425 LogDebug("HCalGeom") << "HcalNumberingFromDDD::getEta " << etaR << " "
00426 << zside << " " << depth << " ==> " << tmp;
00427 return tmp;
00428 }
00429
00430 double HcalNumberingFromDDD::getEta(double r, double z) const {
00431
00432 double tmp = 0;
00433 if (z != 0) tmp = -log(tan(0.5*atan(r/z)));
00434 LogDebug("HCalGeom") << "HcalNumberingFromDDD::getEta " << r << " " << z
00435 << " ==> " << tmp;
00436 return tmp;
00437 }
00438
00439 double HcalNumberingFromDDD::deltaEta(int det, int etaR, int depth) const {
00440
00441 double tmp = 0;
00442 if (det == static_cast<int>(HcalForward)) {
00443 int ir = nR + etaMin[2] - etaR - 1;
00444 if (ir > 0 && ir < nR)
00445 tmp = 0.5*(getEta(rTable[ir-1],zVcal)-getEta(rTable[ir],zVcal));
00446 } else {
00447 if (etaR > 0 && etaR < nEta) {
00448 if (etaR == nOff[1]-1 && depth > 2) {
00449 tmp = 0.5*(etaTable[etaR+1]-etaTable[etaR-1]);
00450 } else {
00451 tmp = 0.5*(etaTable[etaR]-etaTable[etaR-1]);
00452 }
00453 }
00454 }
00455 LogDebug("HCalGeom") << "HcalNumberingFromDDD::deltaEta " << etaR << " "
00456 << depth << " ==> " << tmp;
00457 return tmp;
00458 }
00459
00460 void HcalNumberingFromDDD::initialize(std::string & name,
00461 const DDCompactView & cpv) {
00462
00463 std::string attribute = "ReadOutName";
00464 edm::LogInfo("HCalGeom") << "HcalNumberingFromDDD: Initailise for " << name
00465 << " as " << attribute;
00466
00467 DDSpecificsFilter filter;
00468 DDValue ddv(attribute,name,0);
00469 filter.setCriteria(ddv,DDSpecificsFilter::equals);
00470 DDFilteredView fv(cpv);
00471 fv.addFilter(filter);
00472 bool ok = fv.firstChild();
00473
00474 if (ok) {
00475
00476 loadSpecPars(fv);
00477
00478
00479 loadGeometry(fv);
00480 } else {
00481 edm::LogError("HCalGeom") << "HcalNumberingFromDDD: cannot get filtered "
00482 << " view for " << attribute << " matching "
00483 << name;
00484 throw DDException("HcalNumberingFromDDD: cannot match "+attribute+" to "+name);
00485 }
00486
00487 std::vector<HcalCellType::HcalCellType> cellTypes =HcalCellTypes();
00488 LogDebug ("HCalGeom") << "HcalNumberingFromDDD: " << cellTypes.size()
00489 << " cells of type HCal (All)";
00490 for (unsigned int i=0; i<cellTypes.size(); i++)
00491 LogDebug ("HCalGeom") << "Cell " << i << " " << cellTypes[i];
00492
00493 }
00494
00495 void HcalNumberingFromDDD::loadSpecPars(DDFilteredView fv) {
00496
00497 DDsvalues_type sv(fv.mergedSpecifics());
00498
00499
00500 int i, nphi=4;
00501 std::vector<double> tmp1 = getDDDArray("phioff",sv,nphi);
00502 phioff.resize(tmp1.size());
00503 for (i=0; i<nphi; i++) {
00504 phioff[i] = tmp1[i];
00505 LogDebug("HCalGeom") << "HcalNumberingFromDDD: phioff[" << i << "] = "
00506 << phioff[i]/deg;
00507 }
00508
00509
00510 nEta = -1;
00511 std::vector<double> tmp2 = getDDDArray("etaTable",sv,nEta);
00512 etaTable.resize(tmp2.size());
00513 for (i=0; i<nEta; i++) {
00514 etaTable[i] = tmp2[i];
00515 LogDebug("HCalGeom") << "HcalNumberingFromDDD: etaTable[" << i << "] = "
00516 << etaTable[i];
00517 }
00518
00519
00520 nR = -1;
00521 std::vector<double> tmp3 = getDDDArray("rTable",sv,nR);
00522 rTable.resize(tmp3.size());
00523 for (i=0; i<nR; i++) {
00524 rTable[i] = tmp3[i];
00525 LogDebug("HCalGeom") << "HcalNumberingFromDDD: rTable[" << i << "] = "
00526 << rTable[i]/cm;
00527 }
00528
00529
00530 nPhi = nEta + nR - 2;
00531 std::vector<double> tmp4 = getDDDArray("phibin",sv,nPhi);
00532 phibin.resize(tmp4.size());
00533 for (i=0; i<nPhi; i++) {
00534 phibin[i] = tmp4[i];
00535 LogDebug("HCalGeom") << "HcalNumberingFromDDD: phibin[" << i << "] = "
00536 << phibin[i]/deg;
00537 }
00538
00539
00540 nDepth = nEta - 1;
00541 std::vector<double> d1 = getDDDArray("depth1",sv,nDepth);
00542 nDepth = nEta - 1;
00543 std::vector<double> d2 = getDDDArray("depth2",sv,nDepth);
00544 nDepth = nEta - 1;
00545 std::vector<double> d3 = getDDDArray("depth3",sv,nDepth);
00546 LogDebug("HCalGeom") << "HcalNumberingFromDDD: " << nDepth << " Depths";
00547 depth1.resize(nDepth);
00548 depth2.resize(nDepth);
00549 depth3.resize(nDepth);
00550 for (i=0; i<nDepth; i++) {
00551 depth1[i] = static_cast<int>(d1[i]);
00552 depth2[i] = static_cast<int>(d2[i]);
00553 depth3[i] = static_cast<int>(d3[i]);
00554 LogDebug("HCalGeom") << "HcalNumberingFromDDD: depth1[" << i << "] = "
00555 << depth1[i] << " depth2[" << i << "] = "<< depth2[i]
00556 << " depth3[" << i << "] = " << depth3[i];
00557 }
00558
00559
00560 int ndx = 3;
00561 std::vector<double> tmp5 = getDDDArray("etaMin",sv,ndx);
00562 std::vector<double> tmp6 = getDDDArray("etaMax",sv,ndx);
00563 etaMin.resize(ndx);
00564 etaMax.resize(ndx);
00565 for (i=0; i<ndx; i++) {
00566 etaMin[i] = static_cast<int>(tmp5[i]);
00567 etaMax[i] = static_cast<int>(tmp6[i]);
00568 }
00569 etaMin[0] = 1;
00570 etaMax[1] = nEta-1;
00571 etaMax[2] = etaMin[2]+nR-2;
00572 for (i=0; i<ndx; i++)
00573 LogDebug("HCalGeom") << "HcalNumberingFromDDD: etaMin[" << i << "] = "
00574 << etaMin[i] << " etaMax[" << i << "] = "<< etaMax[i];
00575
00576
00577 int ngpar = 7;
00578 std::vector<double> gpar = getDDDArray("gparHF",sv,ngpar);
00579 zVcal = gpar[6];
00580 LogDebug("HCalGeom") << "HcalNumberingFromDDD: zVcal " << zVcal;
00581
00582
00583 int noff = 3;
00584 std::vector<double> nvec = getDDDArray("noff",sv,noff);
00585 nOff.resize(noff);
00586 for (i=0; i<noff; i++) {
00587 nOff[i] = static_cast<int>(nvec[i]);
00588 LogDebug("HCalGeom") << "HcalNumberingFromDDD: nOff[" << i << "] = "
00589 << nOff[i];
00590 }
00591
00592
00593 ndx = 4;
00594 gainHB = getDDDArray("HBGains",sv,ndx);
00595 std::vector<double> tmp7 = getDDDArray("HBShift",sv,ndx);
00596 shiftHB.resize(ndx);
00597 LogDebug("HCalGeom") << "HcalNumberingFromDDD:: Gain factor and Shift for "
00598 << "HB depth layers:";
00599 for (i=0; i<ndx; i++) {
00600 shiftHB[i] = static_cast<int>(tmp7[i]);
00601 LogDebug("HCalGeom") <<"HcalNumberingFromDDD:: gainHB[" << i << "] = "
00602 << gainHB[i] << " shiftHB[" << i << "] = "
00603 << shiftHB[i];
00604 }
00605
00606
00607 ndx = 4;
00608 gainHE = getDDDArray("HEGains",sv,ndx);
00609 std::vector<double> tmp8 = getDDDArray("HEShift",sv,ndx);
00610 shiftHE.resize(ndx);
00611 LogDebug("HCalGeom") << "HcalNumberingFromDDD:: Gain factor and Shift for "
00612 << "HE depth layers:";
00613 for (i=0; i<ndx; i++) {
00614 shiftHE[i] = static_cast<int>(tmp8[i]);
00615 LogDebug("HCalGeom") <<"HcalNumberingFromDDD:: gainHE[" << i << "] = "
00616 << gainHE[i] << " shiftHE[" << i << "] = "
00617 << shiftHE[i];
00618 }
00619
00620
00621 ndx = 4;
00622 gainHF = getDDDArray("HFGains",sv,ndx);
00623 std::vector<double> tmp9 = getDDDArray("HFShift",sv,ndx);
00624 shiftHF.resize(ndx);
00625 LogDebug("HCalGeom") << "HcalNumberingFromDDD:: Gain factor and Shift for "
00626 << "HF depth layers:";
00627 for (i=0; i<ndx; i++) {
00628 shiftHF[i] = static_cast<int>(tmp9[i]);
00629 LogDebug("HCalGeom") <<"HcalNumberingFromDDD:: gainHF[" << i << "] = "
00630 << gainHF[i] << " shiftHF[" << i << "] = "
00631 << shiftHF[i];
00632 }
00633 }
00634
00635 void HcalNumberingFromDDD::loadGeometry(DDFilteredView fv) {
00636
00637 bool dodet=true, hf=false;
00638 std::vector<double> rb(20,0.0), ze(20,0.0);
00639 std::vector<int> ib(20,0), ie(20,0);
00640 std::vector<int> izb, phib, ize, phie, izf, phif;
00641 double zf = 0;
00642 dzVcal = -1.;
00643
00644 while (dodet) {
00645 DDTranslation t = fv.translation();
00646 std::vector<int> copy = fv.copyNumbers();
00647 const DDSolid & sol = fv.logicalPart().solid();
00648 int idet = 0, lay = -1;
00649 int nsiz = (int)(copy.size());
00650 if (nsiz>0) lay = copy[nsiz-1]/10;
00651 if (nsiz>1) idet = copy[nsiz-2]/1000;
00652 if (idet == 3) {
00653
00654 LogDebug("HCalGeom") << "HB " << sol.name() << " Shape " << sol.shape()
00655 << " Layer " << lay << " R " << t.Rho();
00656 if (lay >=0 && lay < 20) {
00657 ib[lay]++;
00658 rb[lay] += t.Rho();
00659 }
00660 if (lay == 2) {
00661 int iz = copy[nsiz-5];
00662 int fi = copy[nsiz-4];
00663 unsigned int it1 = find(iz, izb);
00664 if (it1 == izb.size()) izb.push_back(iz);
00665 unsigned int it2 = find(fi, phib);
00666 if (it2 == phib.size()) phib.push_back(fi);
00667 }
00668 } else if (idet == 4) {
00669
00670 LogDebug("HCalGeom") << "HE " << sol.name() << " Shape " << sol.shape()
00671 << " Layer " << lay << " Z " << t.z();
00672 if (lay >=0 && lay < 20) {
00673 ie[lay]++;
00674 ze[lay] += fabs(t.z());
00675 }
00676 if (copy[nsiz-1] == 10) {
00677 int iz = copy[nsiz-6];
00678 int fi = copy[nsiz-4];
00679 unsigned int it1 = find(iz, ize);
00680 if (it1 == ize.size()) ize.push_back(iz);
00681 unsigned int it2 = find(fi, phie);
00682 if (it2 == phie.size()) phie.push_back(fi);
00683 }
00684 } else if (idet == 5) {
00685
00686 if (!hf) {
00687 const std::vector<double> & paras = sol.parameters();
00688 LogDebug("HCalGeom") << "HF " << sol.name() << " Shape " << sol.shape()
00689 << " Z " << t.z() << " with " << paras.size()
00690 << " Parameters";
00691 for (unsigned j=0; j<paras.size(); j++)
00692 LogDebug("HCalGeom") << "HF Parameter[" << j << "] = " << paras[j];
00693 zf = fabs(t.z());
00694 if (sol.shape() == ddpolycone_rrz) {
00695 int nz = (int)(paras.size())-3;
00696 zf += paras[3];
00697 dzVcal = 0.5*(paras[nz]-paras[3]);
00698 hf = true;
00699 } else if (sol.shape() == ddtubs || sol.shape() == ddcons) {
00700 dzVcal = paras[0];
00701 zf -= paras[0];
00702 hf = true;
00703 }
00704 }
00705 } else {
00706 LogDebug("HCalGeom") << "Unknown Detector " << idet << " for "
00707 << sol.name() << " Shape " << sol.shape() << " R "
00708 << t.Rho() << " Z " << t.z();
00709 }
00710 dodet = fv.next();
00711 }
00712
00713 int ibmx = 0, iemx = 0;
00714 for (int i = 0; i < 20; i++) {
00715 if (ib[i]>0) {
00716 rb[i] /= (double)(ib[i]);
00717 ibmx = i+1;
00718 }
00719 if (ie[i]>0) {
00720 ze[i] /= (double)(ie[i]);
00721 iemx = i+1;
00722 }
00723 }
00724
00725 LogDebug("HCalGeom") << "HcalNumberingFromDDD: Maximum Layer for HB "
00726 << ibmx << " for HE " << iemx << " Z for HF " << zf
00727 << " extent " << dzVcal;
00728 if (ibmx > 0) {
00729 rHB.resize(ibmx);
00730 for (int i=0; i<ibmx; i++) {
00731 rHB[i] = rb[i];
00732 LogDebug("HCalGeom") << "HcalNumberingFromDDD: rHB[" << i << "] = "
00733 << rHB[i];
00734 }
00735 }
00736 if (iemx > 0) {
00737 zHE.resize(iemx);
00738 for (int i=0; i<iemx; i++) {
00739 zHE[i] = ze[i];
00740 LogDebug("HCalGeom") << "HcalNumberingFromDDD: zHE[" << i << "] = "
00741 << zHE[i];
00742 }
00743 }
00744
00745 nzHB = (int)(izb.size());
00746 nmodHB = (int)(phib.size());
00747 LogDebug("HCalGeom") << "HcalNumberingFromDDD::loadGeometry: " << nzHB
00748 << " barrel half-sectors";
00749 for (int i=0; i<nzHB; i++)
00750 LogDebug("HCalGeom") << "Section " << i << " Copy number " << izb[i];
00751 LogDebug("HCalGeom") << "HcalNumberingFromDDD::loadGeometry: " << nmodHB
00752 << " barrel modules";
00753 for (int i=0; i<nmodHB; i++)
00754 LogDebug("HCalGeom") << "Module " << i << " Copy number " << phib[i];
00755
00756 nzHE = (int)(ize.size());
00757 nmodHE = (int)(phie.size());
00758 LogDebug("HCalGeom") << "HcalNumberingFromDDD::loadGeometry: " << nzHE
00759 << " endcap half-sectors";
00760 for (int i=0; i<nzHE; i++)
00761 LogDebug("HCalGeom") << "Section " << i << " Copy number " << ize[i];
00762 LogDebug("HCalGeom") << "HcalNumberingFromDDD::loadGeometry: " << nmodHE
00763 << " endcap modules";
00764 for (int i=0; i<nmodHE; i++)
00765 LogDebug("HCalGeom") << "Module " << i << " Copy number " << phie[i];
00766
00767 }
00768
00769 std::vector<double> HcalNumberingFromDDD::getDDDArray(const std::string & str,
00770 const DDsvalues_type & sv,
00771 int & nmin) const {
00772 LogDebug("HCalGeom") << "HcalNumberingFromDDD:getDDDArray called for "
00773 << str << " with nMin " << nmin;
00774 DDValue value(str);
00775 if (DDfetch(&sv,value)) {
00776 LogDebug("HCalGeom") << "HcalNumberingFromDDD: " << value;
00777 const std::vector<double> & fvec = value.doubles();
00778 int nval = fvec.size();
00779 if (nmin > 0) {
00780 if (nval < nmin) {
00781 edm::LogError("HCalGeom") << "HcalNumberingFromDDD : # of " << str
00782 << " bins " << nval << " < " << nmin
00783 << " ==> illegal";
00784 throw DDException("HcalNumberingFromDDD: cannot get array "+str);
00785 }
00786 } else {
00787 if (nval < 2) {
00788 edm::LogError("HCalGeom") << "HcalNumberingFromDDD : # of " << str
00789 << " bins " << nval << " < 2 ==> illegal"
00790 << " (nmin=" << nmin << ")";
00791 throw DDException("HcalNumberingFromDDD: cannot get array "+str);
00792 }
00793 }
00794 nmin = nval;
00795 return fvec;
00796 } else {
00797 edm::LogError("HCalGeom") << "HcalNumberingFromDDD: cannot get array "
00798 << str;
00799 throw DDException("HcalNumberingFromDDD: cannot get array "+str);
00800 }
00801 }
00802
00803 int HcalNumberingFromDDD::getShift(HcalSubdetector subdet, int depth) const {
00804
00805 int shift;
00806 switch(subdet) {
00807 case HcalEndcap:
00808 shift = shiftHE[depth-1];
00809 break;
00810 case HcalForward:
00811 shift = shiftHF[depth-1];
00812 break;
00813 default:
00814 shift = shiftHB[depth-1];
00815 break;
00816 }
00817 return shift;
00818 }
00819
00820 double HcalNumberingFromDDD::getGain(HcalSubdetector subdet, int depth) const {
00821
00822 double gain;
00823 switch(subdet) {
00824 case HcalEndcap:
00825 gain = gainHE[depth-1];
00826 break;
00827 case HcalForward:
00828 gain = gainHF[depth-1];
00829 break;
00830 default:
00831 gain = gainHB[depth-1];
00832 break;
00833 }
00834 return gain;
00835 }
00836
00837 unsigned int HcalNumberingFromDDD::find(int element,
00838 std::vector<int> array) const {
00839
00840 unsigned int id = array.size();
00841 for (unsigned int i = 0; i < array.size(); i++) {
00842 if (element == array[i]) {
00843 id = i;
00844 break;
00845 }
00846 }
00847 return id;
00848 }