CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/Geometry/HcalCommonData/src/HcalNumberingFromDDD.cc

Go to the documentation of this file.
00001 
00002 // File: HcalNumberingFromDDD.cc
00003 // Description: Usage of DDD to get to numbering scheme for hadron calorimeter
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/GlobalPhysicalConstants.h"
00017 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00018 #include <iostream>
00019 
00020 //#define DebugLog
00021 
00022 HcalNumberingFromDDD::HcalNumberingFromDDD(std::string & name,
00023                                            const DDCompactView & cpv) {
00024   edm::LogInfo("HCalGeom") << "Creating HcalNumberingFromDDD";
00025   initialize(name, cpv);
00026 }
00027 
00028 HcalNumberingFromDDD::~HcalNumberingFromDDD() {
00029   edm::LogInfo("HCalGeom") << "Deleting HcalNumberingFromDDD";
00030 }
00031 
00032 HcalNumberingFromDDD::HcalID HcalNumberingFromDDD::unitID(int det,
00033                                                           CLHEP::Hep3Vector point,
00034                                                           int depth,
00035                                                           int lay) const {
00036 
00037 
00038   double hx  = point.x();
00039   double hy  = point.y();
00040   double hz  = point.z();
00041   double hR  = sqrt(hx*hx+hy*hy+hz*hz);
00042   double htheta = (hR == 0. ? 0. : acos(std::max(std::min(hz/hR,1.0),-1.0)));
00043   double hsintheta = sin(htheta);
00044   double hphi = (hR*hsintheta == 0. ? 0. :atan2(hy,hx));
00045   double heta = (fabs(hsintheta) == 1.? 0. : -log(fabs(tan(htheta/2.))) );
00046 
00047   int    hsubdet=0;
00048   double etaR;
00049 
00050   //First eta index
00051   if (det == 5) { // Forward HCal
00052     hsubdet = static_cast<int>(HcalForward);
00053     hR      = sqrt(hx*hx+hy*hy);
00054     etaR    = (heta >= 0. ? hR : -hR);
00055   } else { // Barrel or Endcap
00056     etaR    = heta;
00057     if (det == 3) {
00058       hsubdet = static_cast<int>(HcalBarrel);
00059       if (zho.size() > 4) etaR = getEtaHO(heta,hx,hy,hz);
00060     } else {
00061       hsubdet = static_cast<int>(HcalEndcap);
00062     }
00063   }
00064 
00065 #ifdef DebugLog
00066   LogDebug("HCalGeom") << "HcalNumberingFromDDD: point = " << point << " det "
00067                        << hsubdet << " eta/R " << etaR << " phi " << hphi;
00068 #endif
00069   HcalNumberingFromDDD::HcalID tmp = unitID(hsubdet,etaR,hphi,depth,lay);
00070   return tmp;
00071 
00072 }
00073 
00074 HcalNumberingFromDDD::HcalID HcalNumberingFromDDD::unitID(double eta,double fi,
00075                                                           int depth, 
00076                                                           int lay) const {
00077 
00078   int    ieta = 0;
00079   double heta = fabs(eta);
00080   for (int i = 0; i < nEta; i++)
00081     if (heta > etaTable[i]) ieta = i + 1;
00082   int    hsubdet=0;
00083   double etaR;
00084   if (ieta <= etaMin[1]) {
00085     if ((ieta <= etaMin[1] && depth==3) || ieta > etaMax[0]) {
00086       hsubdet = static_cast<int>(HcalEndcap);
00087     } else {
00088       hsubdet = static_cast<int>(HcalBarrel);
00089     }
00090     etaR    = eta;
00091   } else {
00092     hsubdet = static_cast<int>(HcalForward);
00093     double theta = 2.*atan(exp(-heta));
00094     double hR    = zVcal*tan(theta);
00095     etaR    = (eta >= 0. ? hR : -hR);
00096   }
00097 
00098   HcalNumberingFromDDD::HcalID tmp = unitID(hsubdet,etaR,fi,depth,lay);
00099   return tmp;
00100 }
00101 
00102 
00103 HcalNumberingFromDDD::HcalID HcalNumberingFromDDD::unitID(int det,
00104                                                           double etaR,
00105                                                           double phi,
00106                                                           int depth,
00107                                                           int lay) const {
00108 
00109   int ieta=0;
00110   double fioff, fibin;
00111   double hetaR = fabs(etaR);
00112 
00113   //First eta index
00114   if (det == static_cast<int>(HcalForward)) { // Forward HCal
00115     fioff   = phioff[2];
00116     ieta    = etaMax[2];
00117     for (int i = nR-1; i > 0; i--)
00118       if (hetaR < rTable[i]) ieta = etaMin[2] + nR - i - 1;
00119     fibin   = phibin[nEta+ieta-etaMin[2]-1];
00120     if  (ieta > etaMax[2]-2 ) {   // HF double-phi  
00121       fioff += 0.5*fibin;
00122     }
00123   } else { // Barrel or Endcap
00124     ieta  = 1;
00125     for (int i = 0; i < nEta-1; i++)
00126       if (hetaR > etaTable[i]) ieta = i + 1;
00127     if (det == static_cast<int>(HcalBarrel)) {
00128       fioff   = phioff[0];
00129       if (ieta > etaMax[0])  ieta = etaMax[0];
00130       if (lay == 18 && nOff.size() > 13) {
00131         if (hetaR > etaHO[1] && ieta == nOff[13]) ieta++;
00132       }
00133     } else {
00134       fioff   = phioff[1];
00135       if (ieta <= etaMin[1]) ieta = etaMin[1];
00136     }
00137     fibin = phibin[ieta-1];
00138   }
00139 
00140   int    nphi  = int((CLHEP::twopi+0.1*fibin)/fibin);
00141   int    zside = etaR>0 ? 1: 0;
00142   double hphi  = phi+fioff;
00143   if (hphi < 0)    hphi += CLHEP::twopi;
00144   int    iphi  = int(hphi/fibin) + 1;
00145   if (iphi > nphi) iphi = 1;
00146 
00147 #ifdef DebugLog
00148   LogDebug("HCalGeom") << "HcalNumberingFromDDD: etaR = " << etaR << " : "
00149                        << zside << "/" << ieta << " phi " << hphi << " : "
00150                        << iphi;
00151 #endif
00152   HcalNumberingFromDDD::HcalID tmp = unitID(det,zside,depth,ieta,iphi,lay);
00153   return tmp;
00154 
00155 }
00156 
00157 HcalNumberingFromDDD::HcalID HcalNumberingFromDDD::unitID(int det, int zside,
00158                                                           int depth, int etaR,
00159                                                           int phi, 
00160                                                           int lay) const {
00161 
00162   //Modify the depth index
00163   if (det == static_cast<int>(HcalForward)) { // Forward HCal
00164   } else {
00165     if (lay >= 0) {
00166       double fibin = phibin[etaR-1];
00167       int   depth0 = depth1[etaR-1];
00168       int   kphi   = phi + int((phioff[3]+0.1)/fibin);
00169       kphi         = (kphi-1)%4 + 1;
00170       if (etaR == nOff[0] && (kphi == 2 || kphi == 3)) depth0--;
00171       if (lay <= depth2[etaR-1]) {
00172         if (lay <= depth0) depth = 1;
00173         else               depth = 2;
00174       } else if (lay <= depth3[etaR-1]) {
00175         depth = 3;
00176       } else               depth = 4;
00177     } else if (det == static_cast<int>(HcalBarrel)) {
00178       if (depth==3) depth = 2;
00179     }
00180     if (det != static_cast<int>(HcalBarrel)) {
00181       if (etaR <= etaMin[1]) depth = 3;
00182     }
00183   }
00184   if (etaR == nOff[1] && depth > 2 && det == static_cast<int>(HcalEndcap))
00185     etaR = nOff[1]-1;
00186   if (det == static_cast<int>(HcalBarrel) && depth == 4) {
00187     det = static_cast<int>(HcalOuter);
00188   }
00189 
00190   int units     = unitPhi(det, etaR);
00191   int iphi_skip = phi;
00192   if      (units==2) iphi_skip  = (phi-1)*2+1;
00193   else if (units==4) iphi_skip  = (phi-1)*4-1;
00194   if (iphi_skip < 0) iphi_skip += 72;
00195 
00196 #ifdef DebugLog
00197   LogDebug("HCalGeom") << "HcalNumberingFromDDD: phi units=" <<  units  
00198                        <<  "  iphi_skip=" << iphi_skip; 
00199 #endif
00200   HcalNumberingFromDDD::HcalID tmp(det,zside,depth,etaR,phi,iphi_skip,lay);
00201 
00202 #ifdef DebugLog
00203   LogDebug("HCalGeom") << "HcalNumberingFromDDD: det = " << det << " " 
00204                        << tmp.subdet << " zside = " << tmp.zside << " depth = "
00205                        << tmp.depth << " eta/R = " << tmp.etaR << " phi = " 
00206                        << tmp.phi << " layer = " << tmp.lay;
00207 #endif
00208   return tmp;
00209 }
00210 
00211 HcalCellType::HcalCell HcalNumberingFromDDD::cell(int det, int zside, 
00212                                                   int depth, int etaR,
00213                                                   int iphi, bool corr) const {
00214 
00215   int idet = det;
00216   double etaMn = etaMin[0];
00217   double etaMx = etaMax[0];
00218   if (idet==static_cast<int>(HcalEndcap)) {
00219     etaMn = etaMin[1]; etaMx = etaMax[1];
00220   } else if (idet==static_cast<int>(HcalForward)) {
00221     etaMn = etaMin[2]; etaMx = etaMax[2];
00222   }
00223   if (corr) {
00224     if (etaR >= nOff[2] && depth == 3 && idet == static_cast<int>(HcalBarrel))
00225       idet = static_cast<int>(HcalEndcap);
00226   }
00227   double eta = 0, deta = 0, phi = 0, dphi = 0, rz = 0, drz = 0;
00228   bool   ok = false, flagrz = true;
00229   if ((idet==static_cast<int>(HcalBarrel)||idet==static_cast<int>(HcalEndcap)||
00230        idet==static_cast<int>(HcalOuter)||idet==static_cast<int>(HcalForward))
00231       && etaR >=etaMn && etaR <= etaMx)
00232     ok = true;
00233   if (idet == static_cast<int>(HcalEndcap)) {
00234     if      (depth < 3 && etaR <= etaMin[1]) ok = false;
00235     else if (depth > 2 && etaR == nOff[1])   ok = false;
00236   }
00237   if (ok) {
00238     int maxlay = (int)(rHB.size());
00239     if (idet == static_cast<int>(HcalEndcap)) maxlay = (int)(zHE.size());
00240     eta  = getEta(idet, etaR, zside, depth);
00241     deta = deltaEta(idet, etaR, depth);
00242     double fibin, fioff;
00243     if      (idet == static_cast<int>(HcalBarrel)||
00244              idet == static_cast<int>(HcalOuter)) {
00245       fioff = phioff[0];
00246       fibin = phibin[etaR-1];
00247     } else if (idet == static_cast<int>(HcalEndcap)) {
00248       fioff = phioff[1];
00249       fibin = phibin[etaR-1];
00250     } else {
00251       fioff = phioff[2];
00252       fibin = phibin[nEta+etaR-etaMin[2]-1];
00253       if  (etaR > etaMax[2]-2 ) fioff += 0.5*fibin; 
00254     }
00255     phi  = fioff + (iphi - 0.5)*fibin;
00256     dphi = 0.5*fibin;
00257     if (idet == static_cast<int>(HcalForward)) {
00258       int ir = nR + etaMin[2] - etaR - 1;
00259       if (ir > 0 && ir < nR) {
00260         rz     = 0.5*(rTable[ir]+rTable[ir-1]);
00261         drz    = 0.5*(rTable[ir]-rTable[ir-1]);
00262       } else {
00263         ok     = false;
00264 #ifdef DebugLog
00265         LogDebug("HCalGeom") << "HcalNumberingFromDDD: wrong eta " << etaR 
00266                              << " ("  << ir << "/" << nR << ") Detector "
00267                              << idet;
00268 #endif
00269       }
00270       if (depth != 1 && depth != 2) {
00271         ok     = false;
00272 #ifdef DebugLog
00273         LogDebug("HCalGeom") << "HcalNumberingFromDDD: wrong depth " << depth
00274                              << " in Detector " << idet;
00275 #endif
00276       }
00277     } else if (etaR <= nEta) {
00278       int depth0 = depth1[etaR-1];
00279       int kphi   = iphi + int((phioff[3]+0.1)/fibin);
00280       kphi       = (kphi-1)%4 + 1;
00281       if (etaR == nOff[0] && (kphi == 2 || kphi == 3)) depth0--;
00282       int laymin, laymax;
00283       if (depth == 1) {
00284         laymin = 1;
00285         if (idet==static_cast<int>(HcalEndcap)) laymin = 2;
00286         laymax = depth0;
00287         if (nOff.size() > 12) {
00288           if (etaR == nOff[6]) {
00289             laymin = nOff[7];
00290             laymax = nOff[8];
00291           } else if (etaR == nOff[9]) {
00292             laymin = nOff[10];
00293           }
00294         }
00295       } else if (depth == 2) {
00296         laymin = depth0+1;
00297         laymax = depth2[etaR-1];
00298         if (etaR==etaMax[0] && idet==static_cast<int>(HcalBarrel) &&
00299             nOff.size()>3) laymax = nOff[3];
00300         if (nOff.size() > 12) {
00301           if (etaR == nOff[9]) laymax = nOff[11];
00302           if (etaR == nOff[6]) laymax = nOff[12];
00303         }
00304       } else  if (depth == 3) {
00305         laymin = depth2[etaR-1]+1;
00306         laymax = depth3[etaR-1];
00307         if (etaR<=etaMin[1] && idet==static_cast<int>(HcalEndcap)) {
00308           if (nOff.size() > 4) laymin = nOff[4];
00309           if (nOff.size() > 5) laymax = nOff[5];
00310         }
00311       } else {
00312         laymin = depth3[etaR-1]+1;
00313         laymax = maxlay;
00314       }
00315       if (idet == static_cast<int>(HcalOuter) && nOff.size() > 13) {
00316         if (etaR > nOff[13] && laymin <= laymax) laymin = laymax;
00317       }
00318       double d1=0, d2=0;
00319       if (laymin <= maxlay && laymax <= maxlay && laymin <= laymax) {
00320         if (idet == static_cast<int>(HcalEndcap)) {
00321           flagrz = false;
00322           if (depth == 1 || laymin <= 1) d1 = zHE[laymin-1] - dzHE[laymin-1];
00323           else                           d1 = zHE[laymin-2] + dzHE[laymin-2];
00324           d2     = zHE[laymax-1] + dzHE[laymax-1];
00325         } else {
00326           if (idet == static_cast<int>(HcalOuter) ||
00327               depth == 1 || laymin <=1) d1 = rHB[laymin-1] - drHB[laymin-1];
00328           else                          d1 = rHB[laymin-2] + drHB[laymin-1];
00329           d2     = rHB[laymax-1] + drHB[laymax-1];
00330         }
00331         rz     = 0.5*(d2+d1);
00332         drz    = 0.5*(d2-d1);
00333       } else {
00334         ok = false;
00335 #ifdef DebugLog
00336         LogDebug("HCalGeom") << "HcalNumberingFromDDD: wrong depth " << depth
00337                              << " (Layer minimum " << laymin << " maximum " 
00338                              << laymax << " maxLay " << maxlay << ")";
00339 #endif
00340       }
00341     } else {
00342       ok = false;
00343 #ifdef DebugLog
00344       LogDebug("HCalGeom") << "HcalNumberingFromDDD: wrong eta " << etaR
00345                            << "/" << nEta << " Detector " << idet;
00346 #endif
00347     }
00348   } else {
00349     ok = false;
00350 #ifdef DebugLog
00351     LogDebug("HCalGeom") << "HcalNumberingFromDDD: wrong eta " << etaR 
00352                          << " det " << idet;
00353 #endif
00354   }
00355   HcalCellType::HcalCell tmp(ok,eta,deta,phi,dphi,rz,drz,flagrz);
00356 
00357 #ifdef DebugLog
00358   LogDebug("HCalGeom") << "HcalNumberingFromDDD: det/side/depth/etaR/phi "
00359                        << det  << "/" << zside << "/" << depth << "/" << etaR
00360                        << "/" << iphi << " Cell Flag " << tmp.ok << " " 
00361                        << tmp.eta << " " << tmp.deta << " phi " << tmp.phi 
00362                        << " " << tmp.dphi << " r(z) " << tmp.rz  << " " 
00363                        << tmp.drz << " " << tmp.flagrz;
00364 #endif
00365   return tmp;
00366 }
00367 
00368 std::vector<double> HcalNumberingFromDDD::getEtaTable() const {
00369 
00370   std::vector<double> tmp = etaTable;
00371   return tmp;
00372 }
00373 
00374 unsigned int HcalNumberingFromDDD::numberOfCells(HcalSubdetector subdet) const{
00375 
00376   unsigned int num = 0;
00377   std::vector<HcalCellType> cellTypes = HcalCellTypes(subdet);
00378   for (unsigned int i=0; i<cellTypes.size(); i++) {
00379     num += (unsigned int)(cellTypes[i].nPhiBins());
00380     if (cellTypes[i].nHalves() > 1) 
00381       num += (unsigned int)(cellTypes[i].nPhiBins());
00382     num -= (unsigned int)(cellTypes[i].nPhiMissingBins());
00383   }
00384 #ifdef DebugLog
00385   LogDebug ("HCalGeom") << "HcalNumberingFromDDD:numberOfCells " 
00386                         << cellTypes.size()  << " " << num 
00387                         << " for subdetector " << subdet;
00388 #endif
00389   return num;
00390 }
00391 
00392 std::vector<HcalCellType> HcalNumberingFromDDD::HcalCellTypes() const{
00393 
00394   std::vector<HcalCellType> cellTypes =HcalCellTypes(HcalBarrel);
00395 #ifdef DebugLog
00396   LogDebug ("HCalGeom") << "HcalNumberingFromDDD: " << cellTypes.size()
00397                         << " cells of type HCal Barrel";
00398   for (unsigned int i=0; i<cellTypes.size(); i++)
00399     LogDebug ("HCalGeom") << "Cell " << i << " " << cellTypes[i];
00400 #endif
00401 
00402   std::vector<HcalCellType> hoCells   =HcalCellTypes(HcalOuter);
00403 #ifdef DebugLog
00404   LogDebug ("HCalGeom") << "HcalNumberingFromDDD: " << hoCells.size()
00405                         << " cells of type HCal Outer";
00406   for (unsigned int i=0; i<hoCells.size(); i++)
00407     LogDebug ("HCalGeom") << "Cell " << i << " " << hoCells[i];
00408 #endif
00409   cellTypes.insert(cellTypes.end(), hoCells.begin(), hoCells.end());
00410 
00411   std::vector<HcalCellType> heCells   =HcalCellTypes(HcalEndcap);
00412 #ifdef DebugLog
00413   LogDebug ("HCalGeom") << "HcalNumberingFromDDD: " << heCells.size()
00414                         << " cells of type HCal Endcap";
00415   for (unsigned int i=0; i<heCells.size(); i++)
00416     LogDebug ("HCalGeom") << "Cell " << i << " " << heCells[i];
00417 #endif
00418   cellTypes.insert(cellTypes.end(), heCells.begin(), heCells.end());
00419 
00420   std::vector<HcalCellType> hfCells   =HcalCellTypes(HcalForward);
00421 #ifdef DebugLog
00422   LogDebug ("HCalGeom") << "HcalNumberingFromDDD: " << hfCells.size()
00423                         << " cells of type HCal Forward";
00424   for (unsigned int i=0; i<hfCells.size(); i++)
00425     LogDebug ("HCalGeom") << "Cell " << i << " " << hfCells[i];
00426 #endif
00427   cellTypes.insert(cellTypes.end(), hfCells.begin(), hfCells.end());
00428 
00429   return cellTypes;
00430 }
00431 
00432 std::vector<HcalCellType> HcalNumberingFromDDD::HcalCellTypes(HcalSubdetector subdet) const {
00433 
00434   std::vector<HcalCellType> cellTypes;
00435   if (subdet == HcalForward) {
00436     if (dzVcal < 0) return cellTypes;
00437   }
00438 
00439   int    dmin, dmax, indx, nz, nmod;
00440   double hsize = 0;
00441   switch(subdet) {
00442   case HcalEndcap:
00443     dmin = 1; dmax = 3; indx = 1; nz = nzHE; nmod = nmodHE;
00444     break;
00445   case HcalForward:
00446     dmin = 1; dmax = 2; indx = 2; nz = 2; nmod = 18; 
00447     break;
00448   case HcalOuter:
00449     dmin = 4; dmax = 4; indx = 0; nz = nzHB; nmod = nmodHB;
00450     break;
00451   default:
00452     dmin = 1; dmax = 3; indx = 0; nz = nzHB; nmod = nmodHB;
00453     break;
00454   }
00455 
00456   int phi = 1, zside  = 1;
00457   bool cor = false;
00458 
00459   // Get the Cells 
00460   int subdet0 = static_cast<int>(subdet);
00461   for (int depth=dmin; depth<=dmax; depth++) {
00462     int    shift = getShift(subdet, depth);
00463     double gain  = getGain (subdet, depth);
00464     if (subdet == HcalForward) {
00465       if (depth == 1) hsize = dzVcal;
00466       else            hsize = dzVcal-0.5*dlShort;
00467     }
00468     for (int eta=etaMin[indx]; eta<= etaMax[indx]; eta++) {
00469       HcalCellType::HcalCell temp1 = cell(subdet0,zside,depth,eta,phi,cor);
00470       if (temp1.ok) {
00471         int units = unitPhi (subdet0, eta);
00472         HcalCellType temp2(subdet, eta, phi, depth, temp1,
00473                                          shift, gain, nz, nmod, hsize, units);
00474         if (subdet == HcalOuter && nOff.size() > 17) {
00475           if (eta == nOff[15]) {
00476             std::vector<int> missPlus, missMinus;
00477             int kk = 18;
00478             for (int miss=0; miss<nOff[16]; miss++) {
00479               missPlus.push_back(nOff[kk]);
00480               kk++;
00481             }
00482             for (int miss=0; miss<nOff[17]; miss++) {
00483               missMinus.push_back(nOff[kk]);
00484               kk++;
00485             }
00486             temp2.setMissingPhi(missPlus, missMinus);
00487           }
00488         }
00489         cellTypes.push_back(temp2);
00490       }
00491     }
00492   }
00493   return cellTypes;
00494 }
00495 
00496 void HcalNumberingFromDDD::printTile() {
00497  
00498   std::cout << "Tile Information for HB:\n" << "========================\n\n";
00499   for (int eta=etaMin[0]; eta<= etaMax[0]; eta++) {
00500     int dmax = 1;
00501     if (depth1[eta-1] < 17) dmax = 2;
00502     for (int depth=1; depth<=dmax; depth++) 
00503       tileHB(eta, depth);
00504   }
00505 
00506   std::cout << "\nTile Information for HE:\n" <<"========================\n\n";
00507   for (int eta=etaMin[1]; eta<= etaMax[1]; eta++) {
00508     int dmin=1, dmax=3;
00509     if (eta == etaMin[1]) {
00510       dmin = 3;
00511     } else if (depth1[eta-1] > 18) {
00512       dmax = 1;
00513     } else if (depth2[eta-1] > 18) {
00514       dmax = 2;
00515     }
00516     for (int depth=dmin; depth<=dmax; depth++)
00517       tileHE(eta, depth);
00518   }
00519 }
00520 
00521 double HcalNumberingFromDDD::getEta(int det, int etaR, int zside,
00522                                     int depth) const {
00523 
00524   double tmp = 0;
00525   if (det == static_cast<int>(HcalForward)) {
00526     int ir = nR + etaMin[2] - etaR - 1;
00527     if (ir > 0 && ir < nR) {
00528       double z = zVcal;
00529       if (depth != 1) z += dlShort;
00530       tmp = 0.5*(getEta(rTable[ir-1],z)+getEta(rTable[ir],z));
00531     }
00532   } else {
00533     if (etaR > 0 && etaR < nEta) {
00534       if (etaR == nOff[1]-1 && depth > 2) {
00535         tmp = 0.5*(etaTable[etaR+1]+etaTable[etaR-1]);
00536       } else if (det == static_cast<int>(HcalOuter) && nOff.size() > 13) {
00537         if (etaR == nOff[13]) {
00538           tmp = 0.5*(etaHO[0]+etaTable[etaR-1]);
00539         } else if (etaR == nOff[13]+1) {
00540           tmp = 0.5*(etaTable[etaR]+etaHO[1]);
00541         } else if (etaR == nOff[14]) {
00542           tmp = 0.5*(etaHO[2]+etaTable[etaR-1]);
00543         } else if (etaR == nOff[14]+1) {
00544           tmp = 0.5*(etaTable[etaR]+etaHO[3]);
00545         } else {
00546           tmp = 0.5*(etaTable[etaR]+etaTable[etaR-1]);
00547         }
00548       } else {
00549         tmp = 0.5*(etaTable[etaR]+etaTable[etaR-1]);
00550       }
00551     }
00552   } 
00553   if (zside == 0) tmp = -tmp;
00554 #ifdef DebugLog
00555   LogDebug("HCalGeom") << "HcalNumberingFromDDD::getEta " << etaR << " " 
00556                        << zside << " " << depth << " ==> " << tmp;
00557 #endif
00558   return tmp;
00559 }
00560  
00561 double HcalNumberingFromDDD::getEta(double r, double z) const {
00562 
00563   double tmp = 0;
00564   if (z != 0) tmp = -log(tan(0.5*atan(r/z)));
00565 #ifdef DebugLog
00566   LogDebug("HCalGeom") << "HcalNumberingFromDDD::getEta " << r << " " << z 
00567                        << " ==> " << tmp;
00568 #endif
00569   return tmp;
00570 }
00571 
00572 double HcalNumberingFromDDD::deltaEta(int det, int etaR, int depth) const {
00573 
00574   double tmp = 0;
00575   if (det == static_cast<int>(HcalForward)) {
00576     int ir = nR + etaMin[2] - etaR - 1;
00577     if (ir > 0 && ir < nR) {
00578       double z = zVcal;
00579       if (depth != 1) z += dlShort;
00580       tmp = 0.5*(getEta(rTable[ir-1],z)-getEta(rTable[ir],z));
00581     }
00582   } else {
00583     if (etaR > 0 && etaR < nEta) {
00584       if (etaR == nOff[1]-1 && depth > 2) {
00585         tmp = 0.5*(etaTable[etaR+1]-etaTable[etaR-1]);
00586       } else if (det == static_cast<int>(HcalOuter) && nOff.size() > 13) {
00587         if (etaR == nOff[13]) {
00588           tmp = 0.5*(etaHO[0]-etaTable[etaR-1]);
00589         } else if (etaR == nOff[13]+1) {
00590           tmp = 0.5*(etaTable[etaR]-etaHO[1]);
00591         } else if (etaR == nOff[14]) {
00592           tmp = 0.5*(etaHO[2]-etaTable[etaR-1]);
00593         } else if (etaR == nOff[14]+1) {
00594           tmp = 0.5*(etaTable[etaR]-etaHO[3]);
00595         } else {
00596           tmp = 0.5*(etaTable[etaR]-etaTable[etaR-1]);
00597         }
00598       } else {
00599         tmp = 0.5*(etaTable[etaR]-etaTable[etaR-1]);
00600       }
00601     } 
00602   }
00603 #ifdef DebugLog
00604   LogDebug("HCalGeom") << "HcalNumberingFromDDD::deltaEta " << etaR << " " 
00605                        << depth << " ==> " << tmp;
00606 #endif
00607   return tmp;
00608 }
00609 
00610 void HcalNumberingFromDDD::initialize(std::string & name, 
00611                                       const DDCompactView & cpv) {
00612 
00613   std::string attribute = "ReadOutName";
00614   edm::LogInfo("HCalGeom") << "HcalNumberingFromDDD: Initailise for " << name 
00615                            << " as " << attribute;
00616 
00617   DDSpecificsFilter filter;
00618   DDValue           ddv(attribute,name,0);
00619   filter.setCriteria(ddv,DDSpecificsFilter::equals);
00620   DDFilteredView fv(cpv);
00621   fv.addFilter(filter);
00622   bool ok = fv.firstChild();
00623 
00624   if (ok) {
00625     //Load the SpecPars
00626     loadSpecPars(fv);
00627 
00628     //Load the Geometry parameters
00629     loadGeometry(fv);
00630   } else {
00631     edm::LogError("HCalGeom") << "HcalNumberingFromDDD: cannot get filtered "
00632                               << " view for " << attribute << " matching "
00633                               << name;
00634     throw DDException("HcalNumberingFromDDD: cannot match "+attribute+" to "+name);
00635   }
00636 
00637 #ifdef DebugLog
00638   std::vector<HcalCellType> cellTypes = HcalCellTypes();
00639   LogDebug ("HCalGeom") << "HcalNumberingFromDDD: " << cellTypes.size()
00640                         << " cells of type HCal (All)";
00641   for (unsigned int i=0; i<cellTypes.size(); i++)
00642     LogDebug ("HCalGeom") << "Cell " << i << " " << cellTypes[i];
00643 #endif
00644 }
00645 
00646 void HcalNumberingFromDDD::loadSpecPars(DDFilteredView fv) {
00647 
00648   DDsvalues_type sv(fv.mergedSpecifics());
00649 
00650   // Phi Offset
00651   int i, nphi=4;
00652   std::vector<double> tmp1 = getDDDArray("phioff",sv,nphi);
00653   phioff.resize(tmp1.size());
00654   for (i=0; i<nphi; i++) {
00655     phioff[i] = tmp1[i];
00656 #ifdef DebugLog
00657     LogDebug("HCalGeom") << "HcalNumberingFromDDD: phioff[" << i << "] = "
00658                          << phioff[i]/CLHEP::deg;
00659 #endif
00660   }
00661 
00662   //Eta table
00663   nEta     = -1;
00664   std::vector<double> tmp2 = getDDDArray("etaTable",sv,nEta);
00665   etaTable.resize(tmp2.size());
00666   for (i=0; i<nEta; i++) {
00667     etaTable[i] = tmp2[i];
00668 #ifdef DebugLog
00669     LogDebug("HCalGeom") << "HcalNumberingFromDDD: etaTable[" << i << "] = "
00670                          << etaTable[i];
00671 #endif
00672   }
00673 
00674   //R table
00675   nR     = -1;
00676   std::vector<double> tmp3 = getDDDArray("rTable",sv,nR);
00677   rTable.resize(tmp3.size());
00678   for (i=0; i<nR; i++) {
00679     rTable[i] = tmp3[i];
00680 #ifdef DebugLog
00681     LogDebug("HCalGeom") << "HcalNumberingFromDDD: rTable[" << i << "] = "
00682                          << rTable[i]/CLHEP::cm;
00683 #endif
00684   }
00685 
00686   //Phi bins
00687   nPhi   = nEta + nR - 2;
00688   std::vector<double> tmp4 = getDDDArray("phibin",sv,nPhi);
00689   phibin.resize(tmp4.size());
00690   for (i=0; i<nPhi; i++) {
00691     phibin[i] = tmp4[i];
00692 #ifdef DebugLog
00693     LogDebug("HCalGeom") << "HcalNumberingFromDDD: phibin[" << i << "] = "
00694                          << phibin[i]/CLHEP::deg;
00695 #endif
00696   }
00697 
00698   //Layer boundaries for depths 1, 2, 3, 4
00699   nDepth            = nEta - 1;
00700   std::vector<double> d1 = getDDDArray("depth1",sv,nDepth);
00701   nDepth            = nEta - 1;
00702   std::vector<double> d2 = getDDDArray("depth2",sv,nDepth);
00703   nDepth            = nEta - 1;
00704   std::vector<double> d3 = getDDDArray("depth3",sv,nDepth);
00705 #ifdef DebugLog
00706   LogDebug("HCalGeom") << "HcalNumberingFromDDD: " << nDepth << " Depths";
00707 #endif
00708   depth1.resize(nDepth);
00709   depth2.resize(nDepth);
00710   depth3.resize(nDepth);
00711   for (i=0; i<nDepth; i++) {
00712     depth1[i] = static_cast<int>(d1[i]);
00713     depth2[i] = static_cast<int>(d2[i]);
00714     depth3[i] = static_cast<int>(d3[i]);
00715 #ifdef DebugLog
00716     LogDebug("HCalGeom") << "HcalNumberingFromDDD: depth1[" << i << "] = " 
00717                          << depth1[i] << " depth2[" << i << "]  = "<< depth2[i]
00718                          << " depth3[" << i << "] = " << depth3[i];
00719 #endif
00720   }
00721 
00722   // Minimum and maximum eta boundaries
00723   int ndx  = 3;
00724   std::vector<double>  tmp5 = getDDDArray("etaMin",sv,ndx);
00725   std::vector<double>  tmp6 = getDDDArray("etaMax",sv,ndx);
00726   etaMin.resize(ndx);
00727   etaMax.resize(ndx);
00728   for (i=0; i<ndx; i++) {
00729     etaMin[i] = static_cast<int>(tmp5[i]);
00730     etaMax[i] = static_cast<int>(tmp6[i]);
00731   }
00732   etaMin[0] = 1;
00733   etaMax[1] = nEta-1;
00734   etaMax[2] = etaMin[2]+nR-2;
00735 #ifdef DebugLog
00736   for (i=0; i<ndx; i++) 
00737     LogDebug("HCalGeom") << "HcalNumberingFromDDD: etaMin[" << i << "] = "
00738                          << etaMin[i] << " etaMax[" << i << "] = "<< etaMax[i];
00739 #endif
00740 
00741   // Geometry parameters for HF
00742   int ngpar = 7;
00743   std::vector<double> gpar = getDDDArray("gparHF",sv,ngpar);
00744   dlShort = gpar[0];
00745   zVcal   = gpar[4];
00746 #ifdef DebugLog
00747   LogDebug("HCalGeom") << "HcalNumberingFromDDD: dlShort " << dlShort
00748                        << " zVcal " << zVcal;
00749 #endif
00750 
00751   // nOff
00752   int noff = 3;
00753   std::vector<double>  nvec = getDDDArray("noff",sv,noff);
00754   nOff.resize(noff);
00755   for (i=0; i<noff; i++) {
00756     nOff[i] = static_cast<int>(nvec[i]);
00757 #ifdef DebugLog
00758     LogDebug("HCalGeom") << "HcalNumberingFromDDD: nOff[" << i << "] = " 
00759                          << nOff[i];
00760 #endif
00761   }
00762 
00763   //Gains and Shifts for HB depths
00764   ndx                  = 4;
00765   gainHB               = getDDDArray("HBGains",sv,ndx);
00766   std::vector<double>  tmp7 = getDDDArray("HBShift",sv,ndx);
00767   shiftHB.resize(ndx);
00768 #ifdef DebugLog
00769   LogDebug("HCalGeom") << "HcalNumberingFromDDD:: Gain factor and Shift for "
00770                        << "HB depth layers:";
00771 #endif
00772   for (i=0; i<ndx; i++) {
00773     shiftHB[i] = static_cast<int>(tmp7[i]);
00774 #ifdef DebugLog
00775     LogDebug("HCalGeom") <<"HcalNumberingFromDDD:: gainHB[" <<  i << "] = " 
00776                          << gainHB[i] << " shiftHB[" << i << "] = " 
00777                          << shiftHB[i];
00778 #endif
00779   }
00780 
00781   //Gains and Shifts for HB depths
00782   ndx                  = 4;
00783   gainHE               = getDDDArray("HEGains",sv,ndx);
00784   std::vector<double>  tmp8 = getDDDArray("HEShift",sv,ndx);
00785   shiftHE.resize(ndx);
00786 #ifdef DebugLog
00787   LogDebug("HCalGeom") << "HcalNumberingFromDDD:: Gain factor and Shift for "
00788                        << "HE depth layers:";
00789 #endif
00790   for (i=0; i<ndx; i++) {
00791     shiftHE[i] = static_cast<int>(tmp8[i]);
00792 #ifdef DebugLog
00793     LogDebug("HCalGeom") <<"HcalNumberingFromDDD:: gainHE[" <<  i << "] = " 
00794                          << gainHE[i] << " shiftHE[" << i << "] = " 
00795                          << shiftHE[i];
00796 #endif
00797   }
00798 
00799   //Gains and Shifts for HF depths
00800   ndx                  = 4;
00801   gainHF               = getDDDArray("HFGains",sv,ndx);
00802   std::vector<double>  tmp9 = getDDDArray("HFShift",sv,ndx);
00803   shiftHF.resize(ndx);
00804 #ifdef DebugLog
00805   LogDebug("HCalGeom") << "HcalNumberingFromDDD:: Gain factor and Shift for "
00806                        << "HF depth layers:";
00807 #endif
00808   for (i=0; i<ndx; i++) {
00809     shiftHF[i] = static_cast<int>(tmp9[i]);
00810 #ifdef DebugLog
00811     LogDebug("HCalGeom") <<"HcalNumberingFromDDD:: gainHF[" <<  i << "] = " 
00812                          << gainHF[i] << " shiftHF[" << i << "] = " 
00813                          << shiftHF[i];
00814 #endif
00815   }
00816 }
00817 
00818 void HcalNumberingFromDDD::loadGeometry(DDFilteredView fv) {
00819 
00820   bool dodet=true, hf=false;
00821   std::vector<double> rb(20,0.0), ze(20,0.0), thkb(20,-1.0), thke(20,-1.0);
00822   std::vector<int>    ib(20,0),   ie(20,0);
00823   std::vector<int>    izb, phib, ize, phie, izf, phif;
00824   std::vector<double> rxb;
00825   rhoxb.clear(); zxb.clear(); dyxb.clear(); dzxb.clear();
00826   layb.clear(); laye.clear();
00827   zxe.clear(); rhoxe.clear(); dyxe.clear(); dx1e.clear(); dx2e.clear();
00828   double zf = 0;
00829   dzVcal = -1.;
00830 
00831   while (dodet) {
00832     DDTranslation    t    = fv.translation();
00833     std::vector<int> copy = fv.copyNumbers();
00834     const DDSolid & sol  = fv.logicalPart().solid();
00835     int idet = 0, lay = -1;
00836     int nsiz = (int)(copy.size());
00837     if (nsiz>0) lay  = copy[nsiz-1]/10;
00838     if (nsiz>1) idet = copy[nsiz-2]/1000;
00839     double dx=0, dy=0, dz=0, dx1=0, dx2=0;
00840     if (sol.shape() == 1) {
00841       const DDBox & box = static_cast<DDBox>(fv.logicalPart().solid());
00842       dx = box.halfX();
00843       dy = box.halfY();
00844       dz = box.halfZ();
00845     } else if (sol.shape() == 3) {
00846       const DDTrap & trp = static_cast<DDTrap>(fv.logicalPart().solid());
00847       dx1= trp.x1();
00848       dx2= trp.x2();
00849       dx = 0.25*(trp.x1()+trp.x2()+trp.x3()+trp.x4());
00850       dy = 0.5*(trp.y1()+trp.y2());
00851       dz = trp.halfZ();
00852     } else if (sol.shape() == 2) {
00853       const DDTubs & tub = static_cast<DDTubs>(fv.logicalPart().solid());
00854       dx = tub.rIn();
00855       dy = tub.rOut();
00856       dz = tub.zhalf();
00857     }
00858     if (idet == 3) {
00859       // HB
00860 #ifdef DebugLog
00861       LogDebug("HCalGeom") << "HB " << sol.name() << " Shape " << sol.shape()
00862                            << " Layer " << lay << " R " << t.Rho();
00863 #endif
00864       if (lay >=0 && lay < 20) {
00865         ib[lay]++;
00866         rb[lay] += t.Rho();
00867         if (thkb[lay] <= 0) {
00868           if (lay < 17) thkb[lay] = dx;
00869           else          thkb[lay] = std::min(dx,dy);
00870         }
00871         if (lay < 17) {
00872           bool found = false;
00873           for (unsigned int k=0; k<rxb.size(); k++) {
00874             if (std::abs(rxb[k]-t.Rho()) < 0.01) {
00875               found = true;
00876               break;
00877             }
00878           }
00879           if (!found) {
00880             rxb.push_back(t.Rho());
00881             rhoxb.push_back(t.Rho()*std::cos(t.phi()));
00882             zxb.push_back(std::abs(t.z()));
00883             dyxb.push_back(2.*dy);
00884             dzxb.push_back(2.*dz);
00885             layb.push_back(lay);
00886           }
00887         }
00888       }
00889       if (lay == 2) {
00890         int iz = copy[nsiz-5];
00891         int fi = copy[nsiz-4];
00892         unsigned int it1 = find(iz, izb);
00893         if (it1 == izb.size())  izb.push_back(iz);
00894         unsigned int it2 = find(fi, phib);
00895         if (it2 == phib.size()) phib.push_back(fi);
00896       }
00897       if (lay == 18) {
00898         int ifi=-1, ich=-1;
00899         if (nsiz>2) ifi = copy[nsiz-3];
00900         if (nsiz>3) ich = copy[nsiz-4];
00901         double z1 = std::abs((t.z()) + dz);
00902         double z2 = std::abs((t.z()) - dz);
00903         if (std::abs(z1-z2) < 0.01) z1 = 0;
00904         if (ifi == 1 && ich == 4) {
00905           if (z1 > z2) {
00906             double tmp = z1;
00907             z1 = z2;
00908             z2 = tmp;
00909           }
00910           bool sok = true;
00911           for (unsigned int kk=0; kk<zho.size(); kk++) {
00912             if (std::abs(z2-zho[kk]) < 0.01) {
00913               sok = false;
00914               break;
00915             }   else if (z2 < zho[kk]) {
00916               zho.resize(zho.size()+2);
00917               for (unsigned int kz=zho.size()-1; kz>kk+1; kz=kz-2) {
00918                 zho[kz]   = zho[kz-2];
00919                 zho[kz-1] = zho[kz-3];
00920               }
00921               zho[kk+1] = z2;
00922               zho[kk]   = z1;
00923               sok = false;
00924               break;
00925             }
00926           }
00927           if (sok) {
00928             zho.push_back(z1);
00929             zho.push_back(z2);
00930           }
00931 #ifdef DebugLog
00932           LogDebug("HCalGeom") << "Detector " << idet << " Lay " << lay << " fi " << ifi << " " << ich << " z " << z1 << " " << z2;
00933 #endif
00934         }
00935       }
00936     } else if (idet == 4) {
00937       // HE
00938 #ifdef DebugLog
00939       LogDebug("HCalGeom") << "HE " << sol.name() << " Shape " << sol.shape()
00940                            << " Layer " << lay << " Z " << t.z();
00941 #endif
00942       if (lay >=0 && lay < 20) {
00943         ie[lay]++;
00944         ze[lay] += std::abs(t.z());
00945         if (thke[lay] <= 0) thke[lay] = dz;
00946         bool found = false;
00947         for (unsigned int k=0; k<zxe.size(); k++) {
00948           if (std::abs(zxe[k]-std::abs(t.z())) < 0.01) {
00949             found = true;
00950             break;
00951           }
00952         }
00953         if (!found) {
00954           zxe.push_back(std::abs(t.z()));
00955           rhoxe.push_back(t.Rho()*std::cos(t.phi()));
00956           dyxe.push_back(dy*std::cos(t.phi()));
00957           dx1 -= 0.5*(t.rho()-dy)*std::cos(t.phi())*std::tan(10*CLHEP::deg);
00958           dx2 -= 0.5*(t.rho()+dy)*std::cos(t.phi())*std::tan(10*CLHEP::deg);
00959           dx1e.push_back(-dx1);
00960           dx2e.push_back(-dx2);
00961           laye.push_back(lay);
00962         }
00963       }
00964       if (copy[nsiz-1] == 21) {
00965         int iz = copy[nsiz-7];
00966         int fi = copy[nsiz-5];
00967         unsigned int it1 = find(iz, ize);
00968         if (it1 == ize.size())  ize.push_back(iz);
00969         unsigned int it2 = find(fi, phie);
00970         if (it2 == phie.size()) phie.push_back(fi);
00971       }
00972     } else if (idet == 5) {
00973       // HF
00974       if (!hf) {
00975         const std::vector<double> & paras = sol.parameters();
00976 #ifdef DebugLog
00977         LogDebug("HCalGeom") << "HF " << sol.name() << " Shape " << sol.shape()
00978                              << " Z " << t.z() << " with " << paras.size()
00979                              << " Parameters";
00980         for (unsigned j=0; j<paras.size(); j++)
00981           LogDebug("HCalGeom") << "HF Parameter[" << j << "] = " << paras[j];
00982 #endif
00983         zf  = fabs(t.z());
00984         if (sol.shape() == ddpolycone_rrz) {
00985           int nz  = (int)(paras.size())-3;
00986           zf     += paras[3];
00987           dzVcal  = 0.5*(paras[nz]-paras[3]);
00988           hf      = true;
00989         } else if (sol.shape() == ddtubs || sol.shape() == ddcons) {
00990           dzVcal  = paras[0];
00991           zf     -= paras[0];
00992           hf      = true;
00993         }
00994       }
00995 #ifdef DebugLog
00996     } else {
00997       LogDebug("HCalGeom") << "Unknown Detector " << idet << " for " 
00998                            << sol.name() << " Shape " << sol.shape() << " R " 
00999                            << t.Rho() << " Z " << t.z();
01000 #endif
01001     }
01002     dodet = fv.next();
01003   }
01004 
01005   int ibmx = 0, iemx = 0;
01006   for (int i = 0; i < 20; i++) {
01007     if (ib[i]>0) {
01008       rb[i] /= (double)(ib[i]);
01009       ibmx   = i+1;
01010     }
01011     if (ie[i]>0) {
01012       ze[i] /= (double)(ie[i]);
01013       iemx   = i+1;
01014     }
01015 #ifdef DebugLog
01016     LogDebug("HCalGeom") << "Index " << i << " Barrel " << ib[i] << " "
01017                          << rb[i] << " Endcap " << ie[i] << " " << ze[i];
01018 #endif
01019   }
01020   for (int i = 4; i >= 0; i--) {
01021     if (ib[i] == 0) {rb[i] = rb[i+1]; thkb[i] = thkb[i+1];}
01022     if (ie[i] == 0) {ze[i] = ze[i+1]; thke[i] = thke[i+1];}
01023 #ifdef DebugLog
01024     if (ib[i] == 0 || ie[i] == 0)
01025       LogDebug("HCalGeom") << "Index " << i << " Barrel " << ib[i] << " "
01026                            << rb[i] << " Endcap " << ie[i] << " " << ze[i];
01027 #endif
01028   }
01029 
01030 #ifdef DebugLog
01031   for (unsigned int k=0; k<layb.size(); ++k)
01032     std::cout << "HB: " << layb[k] << " R " << rxb[k] << " " << rhoxb[k] << " Z " << zxb[k] << " DY " << dyxb[k] << " DZ " << dzxb[k] << "\n";
01033   for (unsigned int k=0; k<laye.size(); ++k) 
01034     std::cout << "HE: " << laye[k] << " R " << rhoxe[k] << " Z " << zxe[k] << " X1|X2 " << dx1e[k] << "|" << dx2e[k] << " DY " << dyxe[k] << "\n";
01035 
01036   printTile();
01037   LogDebug("HCalGeom") << "HcalNumberingFromDDD: Maximum Layer for HB " 
01038                        << ibmx << " for HE " << iemx << " Z for HF " << zf 
01039                        << " extent " << dzVcal;
01040 #endif
01041 
01042   if (ibmx > 0) {
01043     rHB.resize(ibmx);
01044     drHB.resize(ibmx);
01045     for (int i=0; i<ibmx; i++) {
01046       rHB[i]  = rb[i];
01047       drHB[i] = thkb[i];
01048 #ifdef DebugLog
01049       LogDebug("HCalGeom") << "HcalNumberingFromDDD: rHB[" << i << "] = "
01050                            << rHB[i] << " drHB[" << i << "] = " << drHB[i];
01051 #endif
01052     }
01053   }
01054   if (iemx > 0) {
01055     zHE.resize(iemx);
01056     dzHE.resize(iemx);
01057     for (int i=0; i<iemx; i++) {
01058       zHE[i]  = ze[i];
01059       dzHE[i] = thke[i];
01060 #ifdef DebugLog
01061       LogDebug("HCalGeom") << "HcalNumberingFromDDD: zHE[" << i << "] = "
01062                            << zHE[i] << " dzHE[" << i << "] = " << dzHE[i];
01063 #endif
01064     }
01065   }
01066 
01067   nzHB   = (int)(izb.size());
01068   nmodHB = (int)(phib.size());
01069 #ifdef DebugLog
01070   LogDebug("HCalGeom") << "HcalNumberingFromDDD::loadGeometry: " << nzHB
01071                        << " barrel half-sectors";
01072   for (int i=0; i<nzHB; i++)
01073     LogDebug("HCalGeom") << "Section " << i << " Copy number " << izb[i];
01074   LogDebug("HCalGeom") << "HcalNumberingFromDDD::loadGeometry: " << nmodHB
01075                        << " barrel modules";
01076   for (int i=0; i<nmodHB; i++)
01077     LogDebug("HCalGeom") << "Module " << i << " Copy number " << phib[i];
01078 #endif
01079 
01080   nzHE   = (int)(ize.size());
01081   nmodHE = (int)(phie.size());
01082 #ifdef DebugLog
01083   LogDebug("HCalGeom") << "HcalNumberingFromDDD::loadGeometry: " << nzHE
01084                        << " endcap half-sectors";
01085   for (int i=0; i<nzHE; i++)
01086     LogDebug("HCalGeom") << "Section " << i << " Copy number " << ize[i];
01087   LogDebug("HCalGeom") << "HcalNumberingFromDDD::loadGeometry: " << nmodHE
01088                        << " endcap modules";
01089   for (int i=0; i<nmodHE; i++)
01090     LogDebug("HCalGeom") << "Module " << i << " Copy number " << phie[i];
01091 #endif
01092 
01093 #ifdef DebugLog
01094   LogDebug("HCalGeom") << "HO has Z of size " << zho.size();
01095   for (unsigned int kk=0; kk<zho.size(); kk++)
01096     LogDebug("HCalGeom") << "ZHO[" << kk << "] = " << zho[kk];
01097 #endif
01098   if (ibmx > 17 && zho.size() > 4) {
01099     rminHO   = rHB[17]-100.0;
01100     etaHO[0] = getEta(0.5*(rHB[17]+rHB[18]), zho[1]);
01101     etaHO[1] = getEta(rHB[18]+drHB[18], zho[2]);
01102     etaHO[2] = getEta(rHB[18]-drHB[18], zho[3]);
01103     etaHO[3] = getEta(rHB[18]+drHB[18], zho[4]);
01104   } else {
01105     rminHO   =-1.0;
01106     etaHO[0] = etaTable[4];
01107     etaHO[1] = etaTable[4];
01108     etaHO[2] = etaTable[10];
01109     etaHO[3] = etaTable[10];
01110   }
01111 #ifdef DebugLog
01112   LogDebug("HCalGeom") << "HO Eta boundaries " << etaHO[0] << " " << etaHO[1]
01113                        << " " << etaHO[2] << " " << etaHO[3];
01114   std::cout << "HO Parameters " << rminHO << " " << zho.size();
01115   for (int i=0; i<4; ++i) std::cout << " eta[" << i << "] = " << etaHO[i];
01116   for (unsigned int i=0; i<zho.size(); ++i) std::cout << " zho[" << i << "] = " << zho[i];
01117   std::cout << std::endl;
01118 #endif
01119 }
01120 
01121 std::vector<double> HcalNumberingFromDDD::getDDDArray(const std::string & str, 
01122                                                       const DDsvalues_type & sv,
01123                                                       int & nmin) const {
01124 #ifdef DebugLog
01125   LogDebug("HCalGeom") << "HcalNumberingFromDDD:getDDDArray called for " 
01126                        << str << " with nMin "  << nmin;
01127 #endif
01128   DDValue value(str);
01129   if (DDfetch(&sv,value)) {
01130 #ifdef DebugLog
01131     LogDebug("HCalGeom") << "HcalNumberingFromDDD: " << value;
01132 #endif
01133     const std::vector<double> & fvec = value.doubles();
01134     int nval = fvec.size();
01135     if (nmin > 0) {
01136       if (nval < nmin) {
01137         edm::LogError("HCalGeom") << "HcalNumberingFromDDD : # of " << str 
01138                                   << " bins " << nval << " < " << nmin 
01139                                   << " ==> illegal";
01140         throw DDException("HcalNumberingFromDDD: cannot get array "+str);
01141       }
01142     } else {
01143       if (nval < 2) {
01144         edm::LogError("HCalGeom") << "HcalNumberingFromDDD : # of " << str
01145                                   << " bins " << nval << " < 2 ==> illegal"
01146                                   << " (nmin=" << nmin << ")";
01147         throw DDException("HcalNumberingFromDDD: cannot get array "+str);
01148       }
01149     }
01150     nmin = nval;
01151     return fvec;
01152   } else {
01153     edm::LogError("HCalGeom") << "HcalNumberingFromDDD: cannot get array "
01154                               << str;
01155     throw DDException("HcalNumberingFromDDD: cannot get array "+str);
01156   }
01157 }
01158 
01159 int HcalNumberingFromDDD::getShift(HcalSubdetector subdet, int depth) const {
01160 
01161   int shift;
01162   switch(subdet) {
01163   case HcalEndcap:
01164     shift = shiftHE[depth-1];
01165     break;
01166   case HcalForward:
01167     shift = shiftHF[depth-1];
01168     break;
01169   default:
01170     shift = shiftHB[depth-1];
01171     break;
01172   }
01173   return shift;
01174 }
01175 
01176 double HcalNumberingFromDDD::getGain(HcalSubdetector subdet, int depth) const {
01177 
01178   double gain;
01179   switch(subdet) {
01180   case HcalEndcap:
01181     gain = gainHE[depth-1];
01182     break;
01183   case HcalForward:
01184     gain = gainHF[depth-1];
01185     break;
01186   default:
01187     gain = gainHB[depth-1];
01188     break;
01189   }
01190   return gain;
01191 }
01192 
01193 unsigned int HcalNumberingFromDDD::find(int element, 
01194                                         std::vector<int> array) const {
01195 
01196   unsigned int id = array.size();
01197   for (unsigned int i = 0; i < array.size(); i++) {
01198     if (element == array[i]) {
01199       id = i;
01200       break;
01201     }
01202   }
01203   return id;
01204 }
01205 
01206 int HcalNumberingFromDDD::unitPhi(int det, int etaR) const {
01207 
01208   const double fiveDegInRad = 2*M_PI/72;
01209   int units=0;
01210   if (det == static_cast<int>(HcalForward))
01211     units=int(phibin[nEta+etaR-etaMin[2]-1]/fiveDegInRad+0.5);
01212   else 
01213     units=int(phibin[etaR-1]/fiveDegInRad+0.5);
01214 
01215   return units;
01216 }
01217 
01218 void HcalNumberingFromDDD::tileHB(int eta, int depth) {
01219 
01220   double etaL   = etaTable[eta-1];
01221   double thetaL = 2.*atan(exp(-etaL));
01222   double etaH   = etaTable[eta];
01223   double thetaH = 2.*atan(exp(-etaH));
01224   int    layL=0, layH=0;
01225   if (depth == 1) {
01226     layH = depth1[eta-1];
01227   } else {
01228     layL = depth1[eta-1];
01229     layH = depth2[eta-1];
01230   }
01231   std::cout << "\ntileHB:: eta|depth " << eta << "|" << depth << " theta " << thetaH/CLHEP::deg << ":" << thetaL/CLHEP::deg << " Layer " << layL << ":" << layH-1 << "\n";
01232   for (int lay=layL; lay<layH; ++lay) {
01233     std::vector<double> area(2,0);
01234     int kk=0;
01235     for (unsigned int k=0; k<layb.size(); ++k) {
01236       if (lay == layb[k]) {
01237         double zmin = rhoxb[k]*std::cos(thetaL)/std::sin(thetaL);
01238         double zmax = rhoxb[k]*std::cos(thetaH)/std::sin(thetaH);
01239         double dz   = (std::min(zmax,dzxb[k]) - zmin);
01240         if (dz > 0) {
01241           area[kk] = dz*dyxb[k];
01242           kk++;
01243         }
01244       }
01245     }
01246     if (area[0] > 0) std::cout << std::setw(2) << lay << " Area " << std::setw(8) << area[0] << " " << std::setw(8) << area[1] << "\n";
01247   }
01248 }
01249 
01250 void HcalNumberingFromDDD::tileHE(int eta, int depth) {
01251 
01252   double etaL   = etaTable[eta-1];
01253   double thetaL = 2.*atan(exp(-etaL));
01254   double etaH   = etaTable[eta];
01255   double thetaH = 2.*atan(exp(-etaH));
01256   int    layL=0, layH=0;
01257   if (eta == 16) {
01258     layH = depth3[eta-1];
01259   } else if (depth == 1) {
01260     layH = depth1[eta-1];
01261   } else if (depth == 2) {
01262     layL = depth1[eta-1];
01263     layH = depth2[eta-1];
01264   } else {
01265     layL = depth2[eta-1];
01266     layH = depth3[eta-1];
01267   }
01268   double phib  = phibin[eta-1];
01269   int nphi = 2;
01270   if (phib > 6*CLHEP::deg) nphi = 1;
01271   std::cout << "\ntileHE:: Eta/depth " << eta << "|" << depth << " theta " << thetaH/CLHEP::deg << ":" << thetaL/CLHEP::deg << " Layer " << layL << ":" << layH-1 << " phi " << nphi << "\n";
01272   for (int lay=layL; lay<layH; ++lay) {
01273     std::vector<double> area(4,0);
01274     int kk=0;
01275     for (unsigned int k=0; k<laye.size(); ++k) {
01276       if (lay == laye[k]) {
01277         double rmin = zxe[k]*std::tan(thetaH);
01278         double rmax = zxe[k]*std::tan(thetaL);
01279         if ((lay != 0 || eta == 18) && 
01280             (lay != 1 || (eta == 18 && rhoxe[k]-dyxe[k] > 1000) || (eta != 18 && rhoxe[k]-dyxe[k] < 1000)) &&
01281             rmin+30 < rhoxe[k]+dyxe[k] && rmax > rhoxe[k]-dyxe[k]) {
01282           rmin = std::max(rmin,rhoxe[k]-dyxe[k]);
01283           rmax = std::min(rmax,rhoxe[k]+dyxe[k]);
01284           double dx1 = rmin*std::tan(phib);
01285           double dx2 = rmax*std::tan(phib);
01286           double ar1=0, ar2=0;
01287           if (nphi == 1) {
01288             ar1 = 0.5*(rmax-rmin)*(dx1+dx2-4.*dx1e[k]);
01289           } else {
01290             ar1 = 0.5*(rmax-rmin)*(dx1+dx2-2.*dx1e[k]);
01291             ar2 = 0.5*(rmax-rmin)*((rmax+rmin)*tan(10.*CLHEP::deg)-4*dx1e[k])-ar1;
01292           }
01293           area[kk] = ar1;
01294           area[kk+2] = ar2;
01295           kk++;
01296         }
01297       }
01298     }
01299     if (area[0] > 0 && area[1] > 0) {
01300       int lay0 = lay-1;
01301       if (eta == 18) lay0++;
01302       if (nphi == 1) {
01303         std::cout << std::setw(2) << lay0 << " Area " << std::setw(8) << area[0] << " " << std::setw(8) << area[1] << "\n";
01304       } else {
01305         std::cout << std::setw(2) << lay0 << " Area " << std::setw(8) << area[0] << " " << std::setw(8) << area[1] << ":" << std::setw(8) << area[2] << " " << std::setw(8) << area[3] << "\n";
01306       }
01307     }
01308   }
01309 }
01310 
01311 double HcalNumberingFromDDD::getEtaHO(double& etaR, double& x, double& y, 
01312                                       double& z) const {
01313 
01314   double eta  = fabs(etaR);
01315   double r    = std::sqrt(x*x+y*y);
01316   if (r > rminHO) {
01317     double zz = fabs(z);
01318     if (zz > zho[3]) {
01319       if (eta <= etaTable[10]) eta = etaTable[10]+0.001;
01320     } else if (zz > zho[1]) {
01321       if (eta <=  etaTable[4]) eta = etaTable[4]+0.001;
01322     }
01323   }
01324   eta = (z >= 0. ? eta : -eta);
01325   //  std::cout << "R " << r << " Z " << z << " eta " << etaR << ":" << eta <<"\n";
01326   //  if (eta != etaR) std::cout << "**** Check *****\n";
01327   return eta;
01328 }