00001 #include "Calibration/EcalCalibAlgos/interface/EcalGeomPhiSymHelper.h" 00002 00003 #include "FWCore/Framework/interface/ESHandle.h" 00004 00005 00006 // Geometry 00007 #include "Geometry/Records/interface/CaloGeometryRecord.h" 00008 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" 00009 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" 00010 #include "Geometry/CaloGeometry/interface/CaloGeometry.h" 00011 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h" 00012 00013 //Channel status 00014 00015 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" 00016 #include "CondFormats/EcalObjects/interface/EcalChannelStatusCode.h" 00017 #include <fstream> 00018 00019 void EcalGeomPhiSymHelper::setup(const CaloGeometry* geometry, 00020 const EcalChannelStatus* chStatus, 00021 int statusThresold){ 00022 00023 00024 for (int ieta=0; ieta<kBarlRings; ieta++) nBads_barl[ieta] = 0; 00025 for (int ring=0; ring<kEndcEtaRings; ring++) nBads_endc[ring] = 0; 00026 00027 for (int ix=0; ix<kEndcWedgesX; ix++) { 00028 for (int iy=0; iy<kEndcWedgesY; iy++) { 00029 00030 cellPhi_[ix][iy]=0.; 00031 cellArea_[ix][iy]=0.; 00032 endcapRing_[ix][iy]=-1; 00033 } 00034 } 00035 00036 00037 // loop over all barrel crystals 00038 const std::vector<DetId>& barrelCells = geometry->getValidDetIds(DetId::Ecal, EcalBarrel); 00039 std::vector<DetId>::const_iterator barrelIt; 00040 00041 for (barrelIt=barrelCells.begin(); barrelIt!=barrelCells.end(); barrelIt++) { 00042 EBDetId eb(*barrelIt); 00043 00044 int sign = eb.zside()>0 ? 1 : 0; 00045 00046 int chs= (*chStatus)[*barrelIt].getStatusCode() & 0x001F; 00047 if( chs <= statusThresold) 00048 goodCell_barl[abs(eb.ieta())-1][eb.iphi()-1][sign] = true; 00049 00050 if( !goodCell_barl[abs(eb.ieta())-1][eb.iphi()-1][sign] ) 00051 nBads_barl[abs(eb.ieta())-1]++; 00052 00053 } 00054 00055 00056 00057 const CaloSubdetectorGeometry *endcapGeometry = 00058 geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap); 00059 00060 for (int ix=0; ix<kEndcWedgesX; ix++) { 00061 for (int iy=0; iy<kEndcWedgesY; iy++) { 00062 cellPos_[ix][iy] = GlobalPoint(0.,0.,0.); 00063 cellPhi_[ix][iy]=0.; 00064 cellArea_[ix][iy]=0.; 00065 endcapRing_[ix][iy]=-1; 00066 } 00067 } 00068 00069 const std::vector<DetId>& endcapCells = geometry->getValidDetIds(DetId::Ecal, EcalEndcap); 00070 std::vector<DetId>::const_iterator endcapIt; 00071 for (endcapIt=endcapCells.begin(); endcapIt!=endcapCells.end(); endcapIt++) { 00072 00073 const CaloCellGeometry *cellGeometry = endcapGeometry->getGeometry(*endcapIt); 00074 EEDetId ee(*endcapIt); 00075 int ix=ee.ix()-1; 00076 int iy=ee.iy()-1; 00077 00078 int sign = ee.zside()>0 ? 1 : 0; 00079 00080 // store all crystal positions 00081 cellPos_[ix][iy] = cellGeometry->getPosition(); 00082 cellPhi_[ix][iy] = cellGeometry->getPosition().phi(); 00083 00084 // calculate and store eta-phi area for each crystal front face Shoelace formuls 00085 const CaloCellGeometry::CornersVec& cellCorners (cellGeometry->getCorners()) ; 00086 cellArea_[ix][iy]=0.; 00087 00088 for (int i=0; i<4; i++) { 00089 int iplus1 = i==3 ? 0 : i+1; 00090 cellArea_[ix][iy] += 00091 cellCorners[i].eta()*float(cellCorners[iplus1].phi()) - 00092 cellCorners[iplus1].eta()*float(cellCorners[i].phi()); 00093 00094 } 00095 00096 00097 cellArea_[ix][iy] = fabs(cellArea_[ix][iy])/2.; 00098 /* 00099 const double deltaPhi = 00100 (dynamic_cast<const EcalEndcapGeometry*>(endcapGeometry))->deltaPhi(ee); 00101 00102 const double deltaEta = 00103 (dynamic_cast<const EcalEndcapGeometry*>(endcapGeometry))->deltaEta(ee) ; 00104 00105 cellArea_[ix][iy] = deltaEta*deltaPhi; 00106 */ 00107 int chs= (*chStatus)[*endcapIt].getStatusCode() & 0x001F; 00108 if( chs <= statusThresold) 00109 goodCell_endc[ix][iy][sign] = true; 00110 00111 00112 } 00113 00114 // get eta boundaries for each endcap ring 00115 etaBoundary_[0]=1.479; 00116 etaBoundary_[39]=3.; //It was 4. !!! 00117 for (int ring=1; ring<kEndcEtaRings; ring++) { 00118 double eta_ring_minus1= cellPos_[ring-1][50].eta() ; 00119 double eta_ring = cellPos_[ring][50].eta() ; 00120 etaBoundary_[ring]=(eta_ring+eta_ring_minus1)/2.; 00121 std::cout << "Eta ring " << ring << " : " << eta_ring << std::endl; 00122 } 00123 00124 00125 00126 00127 00128 // determine to which ring each endcap crystal belongs, 00129 // the number of crystals in each ring, 00130 // and the mean eta-phi area of the crystals in each ring 00131 00132 for (int ring=0; ring<kEndcEtaRings; ring++) { 00133 nRing_[ring]=0; 00134 meanCellArea_[ring]=0.; 00135 for (int ix=0; ix<kEndcWedgesX; ix++) { 00136 for (int iy=0; iy<kEndcWedgesY; iy++) { 00137 if (fabs(cellPos_[ix][iy].eta())>etaBoundary_[ring] && 00138 fabs(cellPos_[ix][iy].eta())<etaBoundary_[ring+1]) { 00139 meanCellArea_[ring]+=cellArea_[ix][iy]; 00140 endcapRing_[ix][iy]=ring; 00141 nRing_[ring]++; 00142 00143 00144 00145 for(int sign=0; sign<kSides; sign++){ 00146 if( !goodCell_endc[ix][iy][sign] ) 00147 nBads_endc[ring]++; 00148 } //sign 00149 00150 } //if 00151 } //ix 00152 } //iy 00153 00154 meanCellArea_[ring]/=nRing_[ring]; 00155 00156 00157 } //ring 00158 00159 // fill phi_endc[ip][ring] vector 00160 for (int ring=0; ring<kEndcEtaRings; ring++) { 00161 00162 for (int i=0; i<kMaxEndciPhi; i++) 00163 phi_endc_[i][ring]=0.; 00164 00165 float philast=-999.; 00166 for (int ip=0; ip<nRing_[ring]; ip++) { 00167 float phimin=999.; 00168 for (int ix=0; ix<kEndcWedgesX; ix++) { 00169 for (int iy=0; iy<kEndcWedgesY; iy++) { 00170 if (endcapRing_[ix][iy]==ring) { 00171 if (cellPhi_[ix][iy]<phimin && cellPhi_[ix][iy]>philast) { 00172 phimin=cellPhi_[ix][iy]; 00173 } //if edges 00174 } //if ring 00175 } //iy 00176 } //ix 00177 phi_endc_[ip][ring]=phimin; 00178 philast=phimin; 00179 } //ip 00180 00181 } //ring 00182 00183 // Print out detid->ring association 00184 std::fstream eeringsf("endcaprings.dat",std::ios::out); 00185 for (endcapIt=endcapCells.begin(); endcapIt!=endcapCells.end();endcapIt++){ 00186 EEDetId eedet(*endcapIt); 00187 eeringsf<< eedet.hashedIndex()<< " " 00188 << endcapRing_[eedet.ix()-1][eedet.iy()-1] << " " 00189 << cellPhi_ [eedet.ix()-1][eedet.iy()-1] << " " 00190 << cellArea_[eedet.ix()-1][eedet.iy()-1]/ 00191 meanCellArea_[endcapRing_[eedet.ix()-1][eedet.iy()-1]] << std::endl; 00192 00193 } 00194 }