CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/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() {
00010   useShortFibers_=true;
00011   useHFQuadPhiRings_=true;
00012 }
00013 
00014 void HcalTrigTowerGeometry::setupHF(bool useShortFibers, bool useQuadRings) {
00015   useShortFibers_=useShortFibers;
00016   useHFQuadPhiRings_=useQuadRings;
00017 }
00018 
00019 std::vector<HcalTrigTowerDetId>
00020 HcalTrigTowerGeometry::towerIds(const HcalDetId & cellId) const {
00021 
00022   std::vector<HcalTrigTowerDetId> results;
00023 
00024   if(cellId.subdet() == HcalForward) {
00025     // short fibers don't count
00026     if(cellId.depth() == 1 || useShortFibers_) {
00027       // first do eta
00028       int hfRing = cellId.ietaAbs();
00029       int ieta = firstHFTower(); 
00030       // find the tower that contains this ring
00031       while(hfRing >= firstHFRingInTower(ieta+1)) {
00032         ++ieta;
00033       }
00034 
00035       ieta *= cellId.zside();
00036 
00037       // now for phi
00038       // HF towers are quad, 18 in phi.
00039       // go two cells per trigger tower.
00040       int iphi = (((cellId.iphi()+1)/4) * 4 + 1)%72; // 71+1 --> 1, 3+5 --> 5
00041       if (useHFQuadPhiRings_ || cellId.ietaAbs() < theTopology.firstHFQuadPhiRing())
00042         results.push_back( HcalTrigTowerDetId(ieta, iphi) );
00043     }
00044       
00045   } else {
00046     // the first twenty rings are one-to-one
00047     if(cellId.ietaAbs() < theTopology.firstHEDoublePhiRing()) {    
00048       results.push_back( HcalTrigTowerDetId(cellId.ieta(), cellId.iphi()) );
00049     } else {
00050       // the remaining rings are two-to-one in phi
00051       int iphi1 = cellId.iphi();
00052       int ieta = cellId.ieta();
00053       // the last eta ring in HE is split.  Recombine.
00054       if(ieta == theTopology.lastHERing()) --ieta;
00055       if(ieta == -theTopology.lastHERing()) ++ieta;
00056 
00057       results.push_back( HcalTrigTowerDetId(ieta, iphi1) );
00058       results.push_back( HcalTrigTowerDetId(ieta, iphi1+1) );
00059     }
00060   }
00061 
00062   return results;
00063 }
00064 
00065 
00066 std::vector<HcalDetId>
00067 HcalTrigTowerGeometry::detIds(const HcalTrigTowerDetId & hcalTrigTowerDetId) const {
00068   // Written, tested by E. Berry (Princeton)
00069   std::vector<HcalDetId> results;
00070 
00071   int tower_ieta = hcalTrigTowerDetId.ieta();
00072   int tower_iphi = hcalTrigTowerDetId.iphi();
00073 
00074   int cell_ieta = tower_ieta;
00075   int cell_iphi = tower_iphi;
00076 
00077   int min_depth, n_depths;
00078 
00079   // HB
00080   
00081   if (abs(cell_ieta) <= theTopology.lastHBRing()){
00082     theTopology.depthBinInformation(HcalBarrel, abs(tower_ieta), n_depths, min_depth);
00083     for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++)
00084       results.push_back(HcalDetId(HcalBarrel,cell_ieta,cell_iphi,cell_depth));
00085   }
00086 
00087   // HO
00088   
00089   if (abs(cell_ieta) <= theTopology.lastHORing()){ 
00090     theTopology.depthBinInformation(HcalOuter , abs(tower_ieta), n_depths, min_depth);  
00091     for (int ho_depth = min_depth; ho_depth <= min_depth + n_depths - 1; ho_depth++)
00092       results.push_back(HcalDetId(HcalOuter, cell_ieta,cell_iphi,ho_depth));
00093   }
00094 
00095   // HE 
00096 
00097   if (abs(cell_ieta) >= theTopology.firstHERing() && 
00098       abs(cell_ieta) <  theTopology.lastHERing()){   
00099 
00100     theTopology.depthBinInformation(HcalEndcap, abs(tower_ieta), n_depths, min_depth);
00101     
00102     // Special for double-phi cells
00103     if (abs(cell_ieta) >= theTopology.firstHEDoublePhiRing())
00104       if (tower_iphi%2 == 0) cell_iphi = tower_iphi - 1;
00105     
00106     for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++)
00107       results.push_back(HcalDetId(HcalEndcap, cell_ieta, cell_iphi, cell_depth));
00108     
00109     // Special for split-eta cells
00110     if (abs(tower_ieta) == 28){
00111       theTopology.depthBinInformation(HcalEndcap, abs(tower_ieta)+1, n_depths, min_depth);
00112       for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++){
00113         if (tower_ieta < 0) results.push_back(HcalDetId(HcalEndcap, tower_ieta - 1, cell_iphi, cell_depth));
00114         if (tower_ieta > 0) results.push_back(HcalDetId(HcalEndcap, tower_ieta + 1, cell_iphi, cell_depth));
00115       }
00116     }
00117     
00118   }
00119     
00120   // HF 
00121   
00122   if (abs(cell_ieta) >= theTopology.firstHFRing()){  
00123     
00124     int HfTowerPhiSize     = 72 / nPhiBins(tower_ieta);
00125     int HfTowerEtaSize     = hfTowerEtaSize(tower_ieta);
00126     int FirstHFRingInTower = firstHFRingInTower(abs(tower_ieta));
00127     
00128     for (int iHFTowerPhiSegment = 0; iHFTowerPhiSegment < HfTowerPhiSize; iHFTowerPhiSegment++){      
00129             
00130       cell_iphi =  (tower_iphi / HfTowerPhiSize) * HfTowerPhiSize; // Find the minimum phi segment
00131       cell_iphi -= 2;                        // The first trigger tower starts at HCAL iphi = 71, not HCAL iphi = 1
00132       cell_iphi += iHFTowerPhiSegment;       // Get all of the HCAL iphi values in this trigger tower
00133       cell_iphi += 72;                       // Don't want to take the mod of a negative number
00134       cell_iphi =  cell_iphi % 72;           // There are, at most, 72 cells.
00135       cell_iphi += 1;                        // There is no cell at iphi = 0
00136       
00137       if (cell_iphi%2 == 0) continue;        // These cells don't exist.
00138 
00139       for (int iHFTowerEtaSegment = 0; iHFTowerEtaSegment < HfTowerEtaSize; iHFTowerEtaSegment++){
00140                 
00141         cell_ieta = FirstHFRingInTower + iHFTowerEtaSegment;
00142 
00143         if (cell_ieta >= 40 && cell_iphi%4 == 1) continue;  // These cells don't exist.
00144 
00145         theTopology.depthBinInformation(HcalForward, cell_ieta, n_depths, min_depth);  
00146 
00147         // Negative tower_ieta -> negative cell_ieta
00148         if (tower_ieta < 0) cell_ieta *= -1;           
00149 
00150         for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++)
00151           results.push_back(HcalDetId(HcalForward, cell_ieta, cell_iphi, cell_depth));
00152         
00153       }    
00154     }
00155   }
00156 
00157   return results;
00158 }
00159 
00160 
00161 int HcalTrigTowerGeometry::hfTowerEtaSize(int ieta) const {
00162   int ietaAbs = abs(ieta); 
00163   assert(ietaAbs >= firstHFTower() && ietaAbs <= nTowers());
00164   // the first three come from rings 29-31, 32-34, 35-37. The last has 4 rings: 38-41
00165   return (ietaAbs == nTowers()) ? 4 : 3;
00166 }
00167 
00168 
00169 int HcalTrigTowerGeometry::firstHFRingInTower(int ietaTower) const {
00170   // count up to the correct HF ring
00171   int inputTower = abs(ietaTower);
00172   int result = theTopology.firstHFRing();
00173   for(int iTower = firstHFTower(); iTower != inputTower; ++iTower) {
00174     result += hfTowerEtaSize(iTower);
00175   }
00176   
00177   // negative in, negative out.
00178   if(ietaTower < 0) result *= -1;
00179   return result;
00180 }
00181 
00182 
00183 void HcalTrigTowerGeometry::towerEtaBounds(int ieta, double & eta1, double & eta2) const {
00184   int ietaAbs = abs(ieta);
00185   if(ietaAbs < firstHFTower()) {
00186     eta1 = theHBHEEtaBounds[ietaAbs-1];
00187     eta2 = theHBHEEtaBounds[ietaAbs];
00188     // the last tower is split, so get tower 29, too
00189     if(ietaAbs == theTopology.lastHERing()-1) {
00190       eta2 = theHBHEEtaBounds[ietaAbs+1];
00191     } 
00192   } else {
00193     // count from 0
00194     int hfIndex = firstHFRingInTower(ietaAbs) - theTopology.firstHFRing();
00195     eta1 = theHFEtaBounds[hfIndex];
00196     eta2 = theHFEtaBounds[hfIndex + hfTowerEtaSize(ieta)];
00197   }
00198 
00199   // get the signs and order right
00200   if(ieta < 0) {
00201     double tmp = eta1;
00202     eta1 = -eta2;
00203     eta2 = -tmp;
00204   }
00205 }