00001 #include "Geometry/HcalTowerAlgo/interface/HcalTrigTowerGeometry.h"
00002 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00003 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
00004 #include "Geometry/HcalTowerAlgo/src/HcalHardcodeGeometryData.h"
00005
00006 #include <iostream>
00007 #include <cassert>
00008
00009 HcalTrigTowerGeometry::HcalTrigTowerGeometry( const HcalTopology* topology )
00010 : theTopology( topology )
00011 {
00012 useShortFibers_=true;
00013 useHFQuadPhiRings_=true;
00014 useUpgradeConfigurationHFTowers_=!true;
00015 }
00016
00017 void HcalTrigTowerGeometry::setupHF(bool useShortFibers, bool useQuadRings) {
00018 useShortFibers_=useShortFibers;
00019 useHFQuadPhiRings_=useQuadRings;
00020 }
00021
00022 std::vector<HcalTrigTowerDetId>
00023 HcalTrigTowerGeometry::towerIds(const HcalDetId & cellId) const {
00024
00025 std::vector<HcalTrigTowerDetId> results;
00026
00027 int HfTowerPhiSize, shift;
00028 if ( useUpgradeConfigurationHFTowers_ ) {
00029 HfTowerPhiSize = 1;
00030 shift = 0;
00031 } else {
00032 HfTowerPhiSize = 4;
00033 shift = 1;
00034 }
00035
00036 if(cellId.subdet() == HcalForward) {
00037
00038 if(cellId.depth() == 1 || useShortFibers_) {
00039
00040 int hfRing = cellId.ietaAbs();
00041 int ieta = firstHFTower();
00042
00043 while(hfRing >= firstHFRingInTower(ieta+1)) {
00044 ++ieta;
00045 }
00046
00047 if ( useUpgradeConfigurationHFTowers_ && ieta == 29) {
00048 ieta = 30;
00049 }
00050
00051 ieta *= cellId.zside();
00052
00053
00054
00055
00056
00057 int iphi = (((cellId.iphi()+shift)/HfTowerPhiSize) * HfTowerPhiSize + shift)%72;
00058 if (useHFQuadPhiRings_ || cellId.ietaAbs() < theTopology->firstHFQuadPhiRing())
00059 results.push_back( HcalTrigTowerDetId(ieta, iphi) );
00060 }
00061
00062 } else {
00063
00064 if(cellId.ietaAbs() < theTopology->firstHEDoublePhiRing()) {
00065 results.push_back( HcalTrigTowerDetId(cellId.ieta(), cellId.iphi()) );
00066 } else {
00067
00068 int iphi1 = cellId.iphi();
00069 int ieta = cellId.ieta();
00070
00071 if(ieta == theTopology->lastHERing()) --ieta;
00072 if(ieta == -theTopology->lastHERing()) ++ieta;
00073
00074 results.push_back( HcalTrigTowerDetId(ieta, iphi1) );
00075 results.push_back( HcalTrigTowerDetId(ieta, iphi1+1) );
00076 }
00077 }
00078
00079 return results;
00080 }
00081
00082
00083 std::vector<HcalDetId>
00084 HcalTrigTowerGeometry::detIds(const HcalTrigTowerDetId & hcalTrigTowerDetId) const {
00085
00086 std::vector<HcalDetId> results;
00087
00088 int tower_ieta = hcalTrigTowerDetId.ieta();
00089 int tower_iphi = hcalTrigTowerDetId.iphi();
00090
00091 int cell_ieta = tower_ieta;
00092 int cell_iphi = tower_iphi;
00093
00094 int min_depth, n_depths;
00095
00096
00097
00098 if (abs(cell_ieta) <= theTopology->lastHBRing()){
00099 theTopology->depthBinInformation(HcalBarrel, abs(tower_ieta), n_depths, min_depth);
00100 for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++)
00101 results.push_back(HcalDetId(HcalBarrel,cell_ieta,cell_iphi,cell_depth));
00102 }
00103
00104
00105
00106 if (abs(cell_ieta) <= theTopology->lastHORing()){
00107 theTopology->depthBinInformation(HcalOuter , abs(tower_ieta), n_depths, min_depth);
00108 for (int ho_depth = min_depth; ho_depth <= min_depth + n_depths - 1; ho_depth++)
00109 results.push_back(HcalDetId(HcalOuter, cell_ieta,cell_iphi,ho_depth));
00110 }
00111
00112
00113
00114 if (abs(cell_ieta) >= theTopology->firstHERing() &&
00115 abs(cell_ieta) < theTopology->lastHERing()){
00116
00117 theTopology->depthBinInformation(HcalEndcap, abs(tower_ieta), n_depths, min_depth);
00118
00119
00120 if (abs(cell_ieta) >= theTopology->firstHEDoublePhiRing())
00121 if (tower_iphi%2 == 0) cell_iphi = tower_iphi - 1;
00122
00123 for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++)
00124 results.push_back(HcalDetId(HcalEndcap, cell_ieta, cell_iphi, cell_depth));
00125
00126
00127 if (abs(tower_ieta) == 28){
00128 theTopology->depthBinInformation(HcalEndcap, abs(tower_ieta)+1, n_depths, min_depth);
00129 for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++){
00130 if (tower_ieta < 0) results.push_back(HcalDetId(HcalEndcap, tower_ieta - 1, cell_iphi, cell_depth));
00131 if (tower_ieta > 0) results.push_back(HcalDetId(HcalEndcap, tower_ieta + 1, cell_iphi, cell_depth));
00132 }
00133 }
00134
00135 }
00136
00137
00138
00139 if (abs(cell_ieta) >= theTopology->firstHFRing()){
00140
00141 int HfTowerPhiSize;
00142 if ( useUpgradeConfigurationHFTowers_ ) HfTowerPhiSize = 1;
00143 else HfTowerPhiSize = 72 / nPhiBins(tower_ieta);
00144
00145 int HfTowerEtaSize = hfTowerEtaSize(tower_ieta);
00146 int FirstHFRingInTower = firstHFRingInTower(abs(tower_ieta));
00147
00148 for (int iHFTowerPhiSegment = 0; iHFTowerPhiSegment < HfTowerPhiSize; iHFTowerPhiSegment++){
00149
00150 cell_iphi = (tower_iphi / HfTowerPhiSize) * HfTowerPhiSize;
00151 if ( !useUpgradeConfigurationHFTowers_ ) cell_iphi -= 2;
00152 cell_iphi += iHFTowerPhiSegment;
00153 cell_iphi += 72;
00154 cell_iphi = cell_iphi % 72;
00155 if ( !useUpgradeConfigurationHFTowers_) cell_iphi += 1;
00156
00157 if (cell_iphi%2 == 0) continue;
00158
00159 for (int iHFTowerEtaSegment = 0; iHFTowerEtaSegment < HfTowerEtaSize; iHFTowerEtaSegment++){
00160
00161 cell_ieta = FirstHFRingInTower + iHFTowerEtaSegment;
00162
00163 if (cell_ieta >= 40 && cell_iphi%4 == 1) continue;
00164
00165 theTopology->depthBinInformation(HcalForward, cell_ieta, n_depths, min_depth);
00166
00167
00168 int zside = 1;
00169 if (tower_ieta < 0) zside = -1;
00170
00171 cell_ieta *= zside;
00172
00173 for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++)
00174 results.push_back(HcalDetId(HcalForward, cell_ieta, cell_iphi, cell_depth));
00175
00176 if ( zside * cell_ieta == 30 ) {
00177 theTopology->depthBinInformation(HcalForward, 29 * zside, n_depths, min_depth);
00178 for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++)
00179 results.push_back(HcalDetId(HcalForward, 29 * zside , cell_iphi, cell_depth));
00180 }
00181
00182 }
00183 }
00184 }
00185
00186 return results;
00187 }
00188
00189
00190 int HcalTrigTowerGeometry::hfTowerEtaSize(int ieta) const {
00191
00192 if ( useUpgradeConfigurationHFTowers_ ) return 1;
00193
00194 int ietaAbs = abs(ieta);
00195 assert(ietaAbs >= firstHFTower() && ietaAbs <= nTowers());
00196
00197 return (ietaAbs == nTowers()) ? 4 : 3;
00198
00199 }
00200
00201
00202 int HcalTrigTowerGeometry::firstHFRingInTower(int ietaTower) const {
00203
00204 int inputTower = abs(ietaTower);
00205 int result = theTopology->firstHFRing();
00206 for(int iTower = firstHFTower(); iTower != inputTower; ++iTower) {
00207 result += hfTowerEtaSize(iTower);
00208 }
00209
00210
00211 if(ietaTower < 0) result *= -1;
00212 return result;
00213 }
00214
00215
00216 void HcalTrigTowerGeometry::towerEtaBounds(int ieta, double & eta1, double & eta2) const {
00217 int ietaAbs = abs(ieta);
00218 if(ietaAbs < firstHFTower()) {
00219 eta1 = theHBHEEtaBounds[ietaAbs-1];
00220 eta2 = theHBHEEtaBounds[ietaAbs];
00221
00222 if(ietaAbs == theTopology->lastHERing()-1) {
00223 eta2 = theHBHEEtaBounds[ietaAbs+1];
00224 }
00225 } else {
00226
00227 int hfIndex = firstHFRingInTower(ietaAbs) - theTopology->firstHFRing();
00228 eta1 = theHFEtaBounds[hfIndex];
00229 eta2 = theHFEtaBounds[hfIndex + hfTowerEtaSize(ieta)];
00230 }
00231
00232
00233 if(ieta < 0) {
00234 double tmp = eta1;
00235 eta1 = -eta2;
00236 eta2 = -tmp;
00237 }
00238 }