CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Geometry/HcalTowerAlgo/src/HcalTrigTowerGeometry.cc

Go to the documentation of this file.
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     // short fibers don't count
00038     if(cellId.depth() == 1 || useShortFibers_) {
00039       // first do eta
00040       int hfRing = cellId.ietaAbs();
00041       int ieta = firstHFTower(); 
00042       // find the tower that contains this ring
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       // now for phi
00054       // HF towers are quad, 18 in phi.
00055       // go two cells per trigger tower.
00056 
00057       int iphi = (((cellId.iphi()+shift)/HfTowerPhiSize) * HfTowerPhiSize + shift)%72; // 71+1 --> 1, 3+5 --> 5
00058       if (useHFQuadPhiRings_ || cellId.ietaAbs() < theTopology->firstHFQuadPhiRing())
00059         results.push_back( HcalTrigTowerDetId(ieta, iphi) );
00060     }
00061       
00062   } else {
00063     // the first twenty rings are one-to-one
00064     if(cellId.ietaAbs() < theTopology->firstHEDoublePhiRing()) {    
00065       results.push_back( HcalTrigTowerDetId(cellId.ieta(), cellId.iphi()) );
00066     } else {
00067       // the remaining rings are two-to-one in phi
00068       int iphi1 = cellId.iphi();
00069       int ieta = cellId.ieta();
00070       // the last eta ring in HE is split.  Recombine.
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   // Written, tested by E. Berry (Princeton)
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   // HB
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   // HO
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   // HE 
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     // Special for double-phi cells
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     // Special for split-eta cells
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   // HF 
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; // Find the minimum phi segment
00151       if ( !useUpgradeConfigurationHFTowers_ ) cell_iphi -= 2; // The first trigger tower starts at HCAL iphi = 71, not HCAL iphi = 1
00152       cell_iphi += iHFTowerPhiSegment;       // Get all of the HCAL iphi values in this trigger tower
00153       cell_iphi += 72;                       // Don't want to take the mod of a negative number
00154       cell_iphi =  cell_iphi % 72;           // There are, at most, 72 cells.
00155       if ( !useUpgradeConfigurationHFTowers_) cell_iphi += 1;// There is no cell at iphi = 0
00156       
00157       if (cell_iphi%2 == 0) continue;        // These cells don't exist.
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;  // These cells don't exist.
00164 
00165         theTopology->depthBinInformation(HcalForward, cell_ieta, n_depths, min_depth);  
00166 
00167         // Negative tower_ieta -> negative cell_ieta
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   // the first three come from rings 29-31, 32-34, 35-37. The last has 4 rings: 38-41
00197   return (ietaAbs == nTowers()) ? 4 : 3;
00198   
00199 }
00200 
00201 
00202 int HcalTrigTowerGeometry::firstHFRingInTower(int ietaTower) const {
00203   // count up to the correct HF ring
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   // negative in, negative out.
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     // the last tower is split, so get tower 29, too
00222     if(ietaAbs == theTopology->lastHERing()-1) {
00223       eta2 = theHBHEEtaBounds[ietaAbs+1];
00224     } 
00225   } else {
00226     // count from 0
00227     int hfIndex = firstHFRingInTower(ietaAbs) - theTopology->firstHFRing();
00228     eta1 = theHFEtaBounds[hfIndex];
00229     eta2 = theHFEtaBounds[hfIndex + hfTowerEtaSize(ieta)];
00230   }
00231 
00232   // get the signs and order right
00233   if(ieta < 0) {
00234     double tmp = eta1;
00235     eta1 = -eta2;
00236     eta2 = -tmp;
00237   }
00238 }