00001
00002
00003
00004
00005
00006 #include "SimCalorimetry/EcalSelectiveReadoutAlgos/src/EcalSelectiveReadout.h"
00007 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00008 #include "FWCore/Utilities/interface/EDMException.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include <string>
00011 #include <iostream>
00012
00013 using std::vector;
00014
00015 const char EcalSelectiveReadout::srpFlagMarker[] = {'.', 'S', 'N', 'C', 'F'};
00016
00017
00018 EcalSelectiveReadout::EcalSelectiveReadout(int dEta_, int dPhi_):
00019 dEta(dEta_), dPhi(dPhi_){
00020 }
00021
00022 void EcalSelectiveReadout::resetSupercrystalInterest(){
00023
00024 for(size_t iCap=0; iCap < nEndcaps; ++iCap){
00025 for(size_t iSCX = 0; iSCX < nSupercrystalXBins; ++iSCX){
00026 for(size_t iSCY = 0; iSCY < nSupercrystalYBins; ++iSCY){
00027 supercrystalInterest[iCap][iSCX][iSCY] = UNKNOWN;
00028 }
00029 }
00030 }
00031 }
00032
00033 void
00034 EcalSelectiveReadout::runSelectiveReadout0(const ttFlag_t ttFlags[nTriggerTowersInEta][nTriggerTowersInPhi]) {
00035
00036 classifyTriggerTowers(ttFlags);
00037
00038
00039 int nTriggerTowerE[] = {0, 0, 0, 0};
00040 int nTriggerTowerB[] = {0, 0, 0, 0};
00041
00042 static int ncall = 0;
00043 if(ncall < 10){
00044 ++ncall;
00045 for(size_t iPhi = 0; iPhi < nTriggerTowersInPhi; ++iPhi){
00046 for(size_t iEta = 0; iEta < nTriggerTowersInEta; ++iEta){
00047 if(iEta < nEndcapTriggerTowersInEta
00048 || iEta >= nBarrelTriggerTowersInEta + nEndcapTriggerTowersInEta){
00049
00050 ++nTriggerTowerE[towerInterest[iEta][iPhi]];
00051 } else{
00052 ++nTriggerTowerB[towerInterest[iEta][iPhi]];
00053 }
00054 }
00055 }
00056 edm::LogInfo("EcalSelectiveReadout")
00057 << nTriggerTowerB[LOWINTEREST] << " low interest TT in barrel\n"
00058 << nTriggerTowerB[SINGLE] << " single TT in barrel\n"
00059 << nTriggerTowerB[NEIGHBOUR] << " neighbor interest TT in barrel\n"
00060 << nTriggerTowerB[CENTER] << " centre interest TT in barrel\n"
00061 << nTriggerTowerE[LOWINTEREST] << " low interest TT in endcap\n"
00062 << nTriggerTowerE[SINGLE] << " single TT in endcap\n"
00063 << nTriggerTowerE[NEIGHBOUR] << " neighbor TT in endcap\n"
00064 << nTriggerTowerE[CENTER] << " center TT in endcap\n";
00065 }
00066
00067
00068
00069 resetSupercrystalInterest();
00070
00071 #ifndef ECALSELECTIVEREADOUT_NOGEOM
00072 const std::vector<DetId>& endcapDetIds = theGeometry->getValidDetIds(DetId::Ecal, EcalEndcap);
00073 for(std::vector<DetId>::const_iterator eeDetIdItr = endcapDetIds.begin();
00074 eeDetIdItr != endcapDetIds.end(); ++eeDetIdItr){
00075
00076
00077 EcalTrigTowerDetId trigTower = theTriggerMap->towerOf(*eeDetIdItr);
00078 assert(trigTower.rawId() != 0);
00079 EEDetId eeDetId(*eeDetIdItr);
00080 int iz = (eeDetId.zside() > 0) ? 1 : 0;
00081 int superCrystalX = (eeDetId.ix()-1) / 5;
00082 int superCrystalY = (eeDetId.iy()-1) / 5;
00083 setHigher(supercrystalInterest[iz][superCrystalX][superCrystalY],
00084 getTowerInterest(trigTower));
00085 }
00086 #else //ECALSELECTIVEREADOUT_NOGEOM not defined
00087 EEDetId xtal;
00088 for(int iZ0=0; iZ0<2; ++iZ0){
00089 for(unsigned iX0=0; iX0<nEndcapXBins; ++iX0){
00090 for(unsigned iY0=0; iY0<nEndcapYBins; ++iY0){
00091
00092 if (!(xtal.validDetId(iX0+1, iY0+1, (iZ0>0?1:-1)))){
00093 continue;
00094 }
00095 xtal = EEDetId(iX0+1, iY0+1, (iZ0>0?1:-1));
00096
00097 if(39 <= iX0 && iX0 <= 60 && 45 <= iY0 && iY0 <= 54){
00098 continue;
00099 }
00100
00101
00102 EcalTrigTowerDetId trigTower = theTriggerMap->towerOf(xtal);
00103 assert(trigTower.rawId() != 0);
00104 int superCrystalX = iX0 / 5;
00105 int superCrystalY = iY0 / 5;
00106 setHigher(supercrystalInterest[iZ0][superCrystalX][superCrystalY],
00107 getTowerInterest(trigTower));
00108 }
00109 }
00110 }
00111 #endif
00112 }
00113
00114 EcalSelectiveReadout::towerInterest_t
00115 EcalSelectiveReadout::getCrystalInterest(const EBDetId & ebDetId) const
00116 {
00117 EcalTrigTowerDetId thisTower = theTriggerMap->towerOf(ebDetId);
00118 return getTowerInterest(thisTower);
00119 }
00120
00121
00122 EcalSelectiveReadout::towerInterest_t
00123 EcalSelectiveReadout::getCrystalInterest(const EEDetId & eeDetId) const
00124 {
00125 int iz = (eeDetId.zside() == 1) ? 1 : 0;
00126 int superCrystalX = (eeDetId.ix()-1) / 5;
00127 int superCrystalY = (eeDetId.iy()-1) / 5;
00128 return supercrystalInterest[iz][superCrystalX][superCrystalY];
00129 }
00130 EcalSelectiveReadout::towerInterest_t
00131
00132 EcalSelectiveReadout::getSuperCrystalInterest(const EcalScDetId& scDetId) const
00133 {
00134 int iz = (scDetId.zside() == 1) ? 1 : 0;
00135 int superCrystalX = scDetId.ix()-1;
00136 int superCrystalY = scDetId.iy()-1;
00137 return supercrystalInterest[iz][superCrystalX][superCrystalY];
00138 }
00139
00140
00141
00142 EcalSelectiveReadout::towerInterest_t
00143 EcalSelectiveReadout::getTowerInterest(const EcalTrigTowerDetId & tower) const
00144 {
00145
00146 int iEta = tower.ieta()<0? tower.ieta() + nTriggerTowersInEta/2
00147 : tower.ieta() + nTriggerTowersInEta/2 -1;
00148 int iPhi = tower.iphi() - 1;
00149 return towerInterest[iEta][iPhi];
00150 }
00151
00152 void
00153 EcalSelectiveReadout::classifyTriggerTowers(const ttFlag_t ttFlags[nTriggerTowersInEta][nTriggerTowersInPhi])
00154 {
00155
00156 for(int iEta=0; iEta < (int)nTriggerTowersInEta; ++iEta){
00157 for(int iPhi=0; iPhi < (int)nTriggerTowersInPhi; ++iPhi){
00158 towerInterest[iEta][iPhi] = LOWINTEREST;
00159 }
00160 }
00161
00162 for(int iEta=0; iEta < (int)nTriggerTowersInEta; ++iEta){
00163 for(int iPhi=0; iPhi < (int)nTriggerTowersInPhi; ++iPhi){
00164 if(ttFlags[iEta][iPhi] == TTF_HIGH_INTEREST){
00165
00166 towerInterest[iEta][iPhi] = CENTER;
00167
00168 for(int iEtaNeigh = std::max<int>(0,iEta-dEta);
00169 iEtaNeigh <= std::min<int>(nTriggerTowersInEta-1, iEta+dEta);
00170 ++iEtaNeigh){
00171 for(int iPhiNeigh = iPhi-dPhi;
00172 iPhiNeigh <= iPhi+dPhi;
00173 ++iPhiNeigh){
00174
00175
00176 int iPhiNeigh_ = iPhiNeigh%(int)nTriggerTowersInPhi;
00177 if(iPhiNeigh_<0) {
00178 iPhiNeigh_ += nTriggerTowersInPhi;
00179 }
00180 setHigher(towerInterest[iEtaNeigh][iPhiNeigh_],
00181 NEIGHBOUR);
00182 }
00183 }
00184 } else if(ttFlags[iEta][iPhi] == TTF_MID_INTEREST){
00185 setHigher(towerInterest[iEta][iPhi], SINGLE);
00186 } else if(ttFlags[iEta][iPhi] & TTF_FORCED_RO_MASK){
00187 setHigher(towerInterest[iEta][iPhi], FORCED_RO);
00188 }
00189 }
00190 }
00191
00192
00193
00194
00195
00196 const size_t innerEtas[] = {0, 1,
00197 nTriggerTowersInEta-2, nTriggerTowersInEta-1};
00198 for(size_t i=0; i < 4; ++i){
00199 size_t iEta = innerEtas[i];
00200 for(size_t iPhi = 0 ; iPhi < nTriggerTowersInPhi; iPhi+=2){
00201 const towerInterest_t srf = std::max(towerInterest[iEta][iPhi],
00202 towerInterest[iEta][iPhi+1]);
00203 towerInterest[iEta][iPhi] = srf;
00204 towerInterest[iEta][iPhi+1] = srf;
00205 }
00206 }
00207 }
00208
00209 void EcalSelectiveReadout::printHeader(std::ostream & os) const{
00210 os << "#SRP flag map\n#\n"
00211 "# +-->Phi/Y " << srpFlagMarker[0] << ": low interest\n"
00212 "# | " << srpFlagMarker[1] << ": single\n"
00213 "# | " << srpFlagMarker[2] << ": neighbour\n"
00214 "# V Eta/X " << srpFlagMarker[3] << ": center\n"
00215 "# " << srpFlagMarker[4] << ": forced readout\n"
00216 "#\n";
00217 }
00218
00219 void EcalSelectiveReadout::print(std::ostream & os) const
00220 {
00221
00222 printEndcap(0, os);
00223
00224
00225 printBarrel(os);
00226
00227
00228 printEndcap(1, os);
00229 }
00230
00231
00232 void EcalSelectiveReadout::printBarrel(std::ostream & os) const
00233 {
00234 for(size_t iEta = nEndcapTriggerTowersInEta;
00235 iEta < nEndcapTriggerTowersInEta
00236 + nBarrelTriggerTowersInEta;
00237 ++iEta){
00238 for(size_t iPhi = 0; iPhi < nTriggerTowersInPhi; ++iPhi){
00239 towerInterest_t srFlag
00240 = towerInterest[iEta][iPhi];
00241 os << srpFlagMarker[srFlag];
00242 }
00243 os << "\n";
00244 }
00245 }
00246
00247
00248 void EcalSelectiveReadout::printEndcap(int endcap, std::ostream & os) const
00249 {
00250 for(size_t iX=0; iX<nSupercrystalXBins; ++iX){
00251 for(size_t iY=0; iY<nSupercrystalYBins; ++iY){
00252 towerInterest_t srFlag
00253 = supercrystalInterest[endcap][iX][iY];
00254 os << (srFlag==UNKNOWN?
00255 ' ':srpFlagMarker[srFlag]);
00256 }
00257 os << "\n";
00258 }
00259 }
00260
00261
00262 std::ostream & operator<<(std::ostream & os, const EcalSelectiveReadout & selectiveReadout)
00263 {
00264 selectiveReadout.print(os);
00265 return os;
00266 }