CMS 3D CMS Logo

EcalSelectiveReadout.cc
Go to the documentation of this file.
1 //emacs settings:-*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil -*-"
2 /*
3  */
4 
10 #include <string>
11 #include <iomanip>
12 #include <cassert>
13 #include <atomic>
14 //#include <iostream> //for debugging
15 
16 using std::vector;
17 
18 const char EcalSelectiveReadout::srpFlagMarker[] = {'.', 'S', 'N', 'C', '4', '5', '6', '7'};
19 
21  : theTriggerMap(nullptr), theElecMap(nullptr), dEta(dEta_), dPhi(dPhi_) {}
22 
24  //init superCrystalInterest (sets all elts to 'UNKNOWN'):
25  for (size_t iCap = 0; iCap < nEndcaps; ++iCap) {
26  for (int iDccPhi = 0; iDccPhi < nDccPerEe; ++iDccPhi) {
27  for (int iDccCh = 0; iDccCh < maxDccChs; ++iDccCh) {
28  eeRuInterest_[iCap][iDccPhi][iDccCh] = UNKNOWN;
29  }
30  }
31  }
32 }
33 
34 void EcalSelectiveReadout::runSelectiveReadout0(const ttFlag_t ttFlags[nTriggerTowersInEta][nTriggerTowersInPhi]) {
35  //printDccChMap(std::cout);
36 
37  //classifies the trigger towers (single,center,neighbor,low interest)
38  classifyTriggerTowers(ttFlags);
39 
40  //count number of TT in each interest class for debugging display
41  int nTriggerTowerE[] = {0, 0, 0, 0, 0, 0, 0, 0};
42  int nTriggerTowerB[] = {0, 0, 0, 0, 0, 0, 0, 0};
43  static std::atomic<int> ncall{0};
44  if (ncall < 10) {
45  ++ncall;
46  for (size_t iPhi = 0; iPhi < nTriggerTowersInPhi; ++iPhi) {
47  for (size_t iEta = 0; iEta < nTriggerTowersInEta; ++iEta) {
48  if (iEta < nEndcapTriggerTowersInEta || iEta >= nBarrelTriggerTowersInEta + nEndcapTriggerTowersInEta) {
49  //in endcaps
50  ++nTriggerTowerE[towerInterest[iEta][iPhi]];
51  } else { //in barrel
52  ++nTriggerTowerB[towerInterest[iEta][iPhi]];
53  }
54 
55  assert(towerInterest[iEta][iPhi] >= 0 && towerInterest[iEta][iPhi] <= 0x7);
56  }
57  }
58  edm::LogInfo("EcalSelectiveReadout") << "without forced bit + with forced bit set:\n"
59  << nTriggerTowerB[LOWINTEREST] << " + "
60  << nTriggerTowerB[LOWINTEREST | FORCED_MASK]
61  << " low interest TT(s) in barrel\n"
62  << nTriggerTowerB[SINGLE] << " + " << nTriggerTowerB[SINGLE | FORCED_MASK]
63  << " single TT(s) in barrel\n"
64  << nTriggerTowerB[NEIGHBOUR] << " + "
65  << nTriggerTowerB[NEIGHBOUR | FORCED_MASK]
66  << " neighbor interest TT(s) in barrel\n"
67  << nTriggerTowerB[CENTER] << " + " << nTriggerTowerB[CENTER | FORCED_MASK]
68  << " centre interest TT(s) in barrel\n"
69  << nTriggerTowerE[LOWINTEREST] << " + "
70  << nTriggerTowerE[LOWINTEREST | FORCED_MASK]
71  << " low interest TT(s) in endcap\n"
72  << nTriggerTowerE[SINGLE] << " + " << nTriggerTowerE[SINGLE | FORCED_MASK]
73  << " single TT(s) in endcap\n"
74  << nTriggerTowerE[NEIGHBOUR] << " + "
75  << nTriggerTowerE[NEIGHBOUR | FORCED_MASK] << " neighbor TT(s) in endcap\n"
76  << nTriggerTowerE[CENTER] << " + " << nTriggerTowerE[CENTER | FORCED_MASK]
77  << " center TT(s) in endcap\n";
78  }
79  //end TT interest class composition debugging display
80 
81  //For the endcap the TT classification must be mapped to the SC:
83 
84 #ifndef ECALSELECTIVEREADOUT_NOGEOM
85  const std::vector<DetId>& endcapDetIds = theGeometry->getValidDetIds(DetId::Ecal, EcalEndcap);
86  for (std::vector<DetId>::const_iterator eeDetIdItr = endcapDetIds.begin(); eeDetIdItr != endcapDetIds.end();
87  ++eeDetIdItr) {
88  // for each superCrystal, the interest is the highest interest
89  // of any trigger tower associated with at least one crystal from this SC.
90  // The forced bit must be set if the flag of one of these trigger towers has
91  // the forced bit set.
92  EcalTrigTowerDetId trigTower = theTriggerMap->towerOf(*eeDetIdItr);
93  assert(trigTower.rawId() != 0);
94  EEDetId eeDetId(*eeDetIdItr);
95  int iz = (eeDetId.zside() > 0) ? 1 : 0;
96  //Following statement will set properly the actual 2-bit flag value
97  //and the forced bit: TTF forced bit is propagated to every RU that
98  //overlaps with the corresponding TT.
99  combineFlags(eeRuInterest(eeDetId), getTowerInterest(trigTower));
100  }
101 #else //ECALSELECTIVEREADOUT_NOGEOM defined
102  EEDetId xtal;
103  for (int iZ0 = 0; iZ0 < 2; ++iZ0) { //0->EE-, 1->EE+
104  for (unsigned iX0 = 0; iX0 < nEndcapXBins; ++iX0) {
105  for (unsigned iY0 = 0; iY0 < nEndcapYBins; ++iY0) {
106  if (!(xtal.validDetId(iX0 + 1, iY0 + 1, (iZ0 > 0 ? 1 : -1)))) {
107  continue;
108  }
109  xtal = EEDetId(iX0 + 1, iY0 + 1, (iZ0 > 0 ? 1 : -1));
110  //works around a EEDetId bug. To remove once the bug fixed.
111  if (39 <= iX0 && iX0 <= 60 && 45 <= iY0 && iY0 <= 54) {
112  continue;
113  }
114  // for each superCrystal, the interest is the highest interest
115  // of any trigger tower associated with any crystal in this SC
116  EcalTrigTowerDetId trigTower = theTriggerMap->towerOf(xtal);
117  assert(trigTower.rawId() != 0);
118  //Following statement will set properly the actual 2-bit flag value
119  //and the forced bit: TTF forced bit is propagated to every RU that
120  //overlaps with the corresponding TT.
121  combineFlags(eeRuInterest(xtal), getTowerInterest(trigTower));
122 
123  assert(0 <= eeRuInterest(xtal) && eeRuInterest(xtal) <= 0x7);
124 
125  } //next iY0
126  } //next iX0
127  } //next iZ0
128 #endif //ECALSELECTIVEREADOUT_NOGEOM not defined
129 }
130 
132  EcalTrigTowerDetId thisTower = theTriggerMap->towerOf(ebDetId);
133  return getTowerInterest(thisTower);
134 }
135 
137  // int iz = (eeDetId.zside() > 0) ? 1 : 0;
138  // int superCrystalX = (eeDetId.ix()-1) / 5;
139  // int superCrystalY = (eeDetId.iy()-1) / 5;
140  // return supercrystalInterest[iz][superCrystalX][superCrystalY];
141  return const_cast<EcalSelectiveReadout*>(this)->eeRuInterest(eeDetId);
142 }
143 
145  return const_cast<EcalSelectiveReadout*>(this)->eeRuInterest(scDetId);
146 }
147 
149  const EcalElectronicsId& id = theElecMap->getElectronicsId(eeDetId);
150  const int iZ0 = id.zside() > 0 ? 1 : 0;
151  const int iDcc0 = id.dccId() - 1;
152  const int iDccPhi0 = (iDcc0 < 9) ? iDcc0 : (iDcc0 - 45);
153  const int iDccCh0 = id.towerId() - 1;
154  assert(0 <= iDccPhi0 && iDccPhi0 < nDccPerEe);
155  assert(0 <= iDccCh0 && iDccCh0 < maxDccChs);
156 
157  assert(eeRuInterest_[iZ0][iDccPhi0][iDccCh0] == UNKNOWN ||
158  (0 <= eeRuInterest_[iZ0][iDccPhi0][iDccCh0] && eeRuInterest_[iZ0][iDccPhi0][iDccCh0] <= 7));
159 
160  return eeRuInterest_[iZ0][iDccPhi0][iDccCh0];
161 }
162 
164  std::pair<int, int> dccAndDccCh = theElecMap->getDCCandSC(scDetId);
165  const int iZ0 = (scDetId.zside() > 0) ? 1 : 0;
166  const int iDcc0 = dccAndDccCh.first - 1;
167  const int iDccPhi0 = (iDcc0 < 9) ? iDcc0 : (iDcc0 - 45);
168  const int iDccCh0 = dccAndDccCh.second - 1;
169  assert(0 <= iDccPhi0 && iDccPhi0 <= nDccPerEe);
170  assert(0 <= iDccCh0 && iDccCh0 <= maxDccChs);
171 
172  assert(-1 <= eeRuInterest_[iZ0][iDccPhi0][iDccCh0] && eeRuInterest_[iZ0][iDccPhi0][iDccCh0] <= 7);
173 
174  return eeRuInterest_[iZ0][iDccPhi0][iDccCh0];
175 }
176 
178  // remember, array indices start at zero
179  int iEta = tower.ieta() < 0 ? tower.ieta() + nTriggerTowersInEta / 2 : tower.ieta() + nTriggerTowersInEta / 2 - 1;
180  int iPhi = tower.iphi() - 1;
181 
182  assert(-1 <= towerInterest[iEta][iPhi] && int(towerInterest[iEta][iPhi]) < 8);
183 
184  return towerInterest[iEta][iPhi];
185 }
186 
187 void EcalSelectiveReadout::classifyTriggerTowers(const ttFlag_t ttFlags[nTriggerTowersInEta][nTriggerTowersInPhi]) {
188  //starts with a all low interest map:
189  for (int iEta = 0; iEta < (int)nTriggerTowersInEta; ++iEta) {
190  for (int iPhi = 0; iPhi < (int)nTriggerTowersInPhi; ++iPhi) {
191  towerInterest[iEta][iPhi] = LOWINTEREST;
192  }
193  }
194 
195  for (int iEta = 0; iEta < (int)nTriggerTowersInEta; ++iEta) {
196  for (int iPhi = 0; iPhi < (int)nTriggerTowersInPhi; ++iPhi) {
197  //copy forced bit from ttFlags to towerInterests:
198  towerInterest[iEta][iPhi] = (towerInterest_t)(towerInterest[iEta][iPhi] | (ttFlags[iEta][iPhi] & FORCED_MASK));
199  if ((ttFlags[iEta][iPhi] & ~FORCED_MASK) == TTF_HIGH_INTEREST) {
200  //flags this tower as a center tower
201  towerInterest[iEta][iPhi] = CENTER;
202  //flags the neighbours of this tower
203  for (int iEtaNeigh = std::max<int>(0, iEta - dEta);
204  iEtaNeigh <= std::min<int>(nTriggerTowersInEta - 1, iEta + dEta);
205  ++iEtaNeigh) {
206  for (int iPhiNeigh = iPhi - dPhi; iPhiNeigh <= iPhi + dPhi; ++iPhiNeigh) {
207  //beware, iPhiNeigh must be moved to [0,72] interval
208  //=> %nTriggerTowersInPhi required
209  int iPhiNeigh_ = iPhiNeigh % (int)nTriggerTowersInPhi;
210  if (iPhiNeigh_ < 0) {
211  iPhiNeigh_ += nTriggerTowersInPhi;
212  }
213  combineFlags(towerInterest[iEtaNeigh][iPhiNeigh_], NEIGHBOUR);
214  }
215  }
216  } else if ((ttFlags[iEta][iPhi] & ~FORCED_MASK) == TTF_MID_INTEREST) {
217  combineFlags(towerInterest[iEta][iPhi], SINGLE);
218  }
219  }
220  }
221 
222  //dealing with pseudo-TT in the two innest eta-ring of the endcaps
223  //=>choose the highest priority SRF of the 2 pseudo-TT constituting
224  //a TT. Note that for S and C, the 2 pseudo-TT must already have the
225  //same mask.
226  const size_t innerEtas[] = {0, 1, nTriggerTowersInEta - 2, nTriggerTowersInEta - 1};
227  for (size_t i = 0; i < 4; ++i) {
228  size_t iEta = innerEtas[i];
229  for (size_t iPhi = 0; iPhi < nTriggerTowersInPhi; iPhi += 2) {
230  const towerInterest_t srf = std::max(towerInterest[iEta][iPhi], towerInterest[iEta][iPhi + 1]);
231  towerInterest[iEta][iPhi] = srf;
232  towerInterest[iEta][iPhi + 1] = srf;
233  }
234  }
235 }
236 
237 void EcalSelectiveReadout::printHeader(std::ostream& os) const {
238  os << "#SRP flag map\n#\n"
239  "# +-->Phi/Y "
240  << srpFlagMarker[0]
241  << ": low interest\n"
242  "# | "
243  << srpFlagMarker[1]
244  << ": single\n"
245  "# | "
246  << srpFlagMarker[2]
247  << ": neighbour\n"
248  "# V Eta/X "
249  << srpFlagMarker[3]
250  << ": center\n"
251  "# "
252  << srpFlagMarker[4]
253  << ": forced low interest\n"
254  "# "
255  << srpFlagMarker[5]
256  << ": forced single\n"
257  "# "
258  << srpFlagMarker[6]
259  << ": forced neighbout\n"
260  "# "
261  << srpFlagMarker[7]
262  << ": forced center\n"
263  "#\n";
264 }
265 
266 void EcalSelectiveReadout::print(std::ostream& os) const {
267  //EE-
268  printEndcap(0, os);
269 
270  //EB
271  printBarrel(os);
272 
273  //EE+
274  printEndcap(1, os);
275 }
276 
277 void EcalSelectiveReadout::printBarrel(std::ostream& os) const {
279  for (size_t iPhi = 0; iPhi < nTriggerTowersInPhi; ++iPhi) {
280  towerInterest_t srFlag = towerInterest[iEta][iPhi];
281  os << srpFlagMarker[srFlag];
282  }
283  os << "\n"; //one phi per line
284  }
285 }
286 
287 void EcalSelectiveReadout::printEndcap(int endcap, std::ostream& os) const {
288  for (size_t iX = 0; iX < nSupercrystalXBins; ++iX) {
289  for (size_t iY = 0; iY < nSupercrystalYBins; ++iY) {
290  towerInterest_t srFlag;
291  char c;
292  if (!EcalScDetId::validDetId(iX + 1, iY + 1, endcap >= 1 ? 1 : -1)) {
293  // srFlag = UNKNOWN;
294  c = ' ';
295  } else {
296  srFlag = getSuperCrystalInterest(
297  EcalScDetId(iX + 1, iY + 1, endcap >= 1 ? 1 : -1)); //supercrystalInterest[endcap][iX][iY];
298  c = srFlag == UNKNOWN ? '?' : srpFlagMarker[srFlag];
299  }
300  os << c;
301  }
302  os << "\n"; //one Y supercystal column per line
303  } //next supercrystal X-index
304 }
305 
306 std::ostream& operator<<(std::ostream& os, const EcalSelectiveReadout& selectiveReadout) {
307  selectiveReadout.print(os);
308  return os;
309 }
310 
311 void EcalSelectiveReadout::printDccChMap(std::ostream& os) const {
312  for (int i = -1; i <= 68; ++i) {
313  if ((i + 1) % 10 == 0)
314  os << "//";
315  os << std::setw(2) << i << ": " << (char)('0' + i);
316  if (i % 10 == 9)
317  os << "\n";
318  else
319  os << " ";
320  }
321 
322  os << "\n";
323 
324  for (int endcap = 0; endcap < 2; ++endcap) {
325  os << "Sc2DCCch0: " << (endcap ? "EE+" : "EE-") << "\n";
326  for (size_t iY = 0; iY < nSupercrystalYBins; ++iY) {
327  os << "Sc2DCCch0: ";
328  for (size_t iX = 0; iX < nSupercrystalXBins; ++iX) {
329  //if(iX) os << ",";
330  if (!EcalScDetId::validDetId(iX + 1, iY + 1, endcap >= 1 ? 1 : -1)) {
331  //os << std::setw(2) << -1;
332  os << (char)('0' - 1);
333  } else {
334  //os << std::setw(2) << theElecMap->getDCCandSC(EcalScDetId(iX+1, iY+1, endcap>0?1:-1)).second-1;
335  os << (char)('0' + (theElecMap->getDCCandSC(EcalScDetId(iX + 1, iY + 1, endcap > 0 ? 1 : -1)).second - 1));
336  }
337  }
338  os << "\n";
339  }
340  os << "\n";
341  }
342  os << "\n";
343 }
EcalElectronicsId.h
EcalSelectiveReadout::printEndcap
void printEndcap(int endcap, std::ostream &s) const
Definition: EcalSelectiveReadout.cc:287
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
EcalSelectiveReadout::nEndcapXBins
const static size_t nEndcapXBins
Definition: EcalSelectiveReadout.h:110
EcalSelectiveReadout::printHeader
void printHeader(std::ostream &os) const
print out header for the map: see print(std::ostream&)
Definition: EcalSelectiveReadout.cc:237
EcalElectronicsId::zside
int zside() const
zside = +1 or -1
Definition: EcalElectronicsId.cc:27
EBDetId
Definition: EBDetId.h:17
EcalScDetId::zside
int zside() const
Definition: EcalScDetId.h:64
EcalSelectiveReadout::TTF_MID_INTEREST
Definition: EcalSelectiveReadout.h:84
EcalScDetId::validDetId
static bool validDetId(int ix, int iy, int iz)
Definition: EcalScDetId.cc:59
edm::LogInfo
Definition: MessageLogger.h:254
hgcalTowerProducer_cfi.tower
tower
Definition: hgcalTowerProducer_cfi.py:3
cms::cuda::assert
assert(be >=bs)
EcalSelectiveReadout::printBarrel
void printBarrel(std::ostream &os) const
Definition: EcalSelectiveReadout.cc:277
EcalSelectiveReadout::towerInterest_t
towerInterest_t
Definition: EcalSelectiveReadout.h:69
EcalTrigTowerDetId
Definition: EcalTrigTowerDetId.h:14
makeMuonMisalignmentScenario.endcap
endcap
Definition: makeMuonMisalignmentScenario.py:320
EcalSelectiveReadout
Definition: EcalSelectiveReadout.h:62
HLT_2018_cff.dEta
dEta
Definition: HLT_2018_cff.py:12289
EcalSelectiveReadout::nDccPerEe
const static int nDccPerEe
Definition: EcalSelectiveReadout.h:152
EcalSelectiveReadout::getCrystalInterest
towerInterest_t getCrystalInterest(const EBDetId &ebDetId) const
Definition: EcalSelectiveReadout.cc:131
EDMException.h
EcalSelectiveReadout::EcalSelectiveReadout
EcalSelectiveReadout(int dEta=1, int dPhi=1)
Definition: EcalSelectiveReadout.cc:20
srpFlagMarker
const char srpFlagMarker[]
Definition: GenABIO.cc:163
EcalSelectiveReadout::CENTER
Definition: EcalSelectiveReadout.h:74
EcalSelectiveReadout::NEIGHBOUR
Definition: EcalSelectiveReadout.h:73
EcalScDetId
Definition: EcalScDetId.h:24
HLT_2018_cff.dPhi
dPhi
Definition: HLT_2018_cff.py:12290
EcalSelectiveReadout::nBarrelTriggerTowersInEta
const static size_t nBarrelTriggerTowersInEta
Definition: EcalSelectiveReadout.h:137
EcalSelectiveReadout::SINGLE
Definition: EcalSelectiveReadout.h:72
EcalSelectiveReadout::FORCED_MASK
static const int FORCED_MASK
Definition: EcalSelectiveReadout.h:64
EcalElectronicsId
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
Definition: EcalElectronicsId.h:18
EEDetId
Definition: EEDetId.h:14
EcalSubdetector.h
EcalEndcap
Definition: EcalSubdetector.h:10
EcalSelectiveReadout::TTF_HIGH_INTEREST
Definition: EcalSelectiveReadout.h:86
EcalSelectiveReadout.h
EcalSelectiveReadout::classifyTriggerTowers
void classifyTriggerTowers(const ttFlag_t ttFlags[nTriggerTowersInEta][nTriggerTowersInPhi])
Definition: EcalSelectiveReadout.cc:187
EcalSelectiveReadout::nTriggerTowersInEta
const static size_t nTriggerTowersInEta
Definition: EcalSelectiveReadout.h:140
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
EcalSelectiveReadout::nEndcapTriggerTowersInEta
const static size_t nEndcapTriggerTowersInEta
Definition: EcalSelectiveReadout.h:134
createfilelist.int
int
Definition: createfilelist.py:10
EcalSelectiveReadout::getTowerInterest
towerInterest_t getTowerInterest(const EcalTrigTowerDetId &towerId) const
Definition: EcalSelectiveReadout.cc:177
EcalSelectiveReadout::combineFlags
void combineFlags(T &var, T val) const
Definition: EcalSelectiveReadout.h:299
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
DetId::Ecal
Definition: DetId.h:27
EcalSelectiveReadout::getSuperCrystalInterest
towerInterest_t getSuperCrystalInterest(const EcalScDetId &scDetId) const
Definition: EcalSelectiveReadout.cc:144
EcalSelectiveReadout::nSupercrystalXBins
const static size_t nSupercrystalXBins
Definition: EcalSelectiveReadout.h:119
EcalSelectiveReadout::eeRuInterest
towerInterest_t & eeRuInterest(const EEDetId &id)
Definition: EcalSelectiveReadout.cc:148
EcalSelectiveReadout::LOWINTEREST
Definition: EcalSelectiveReadout.h:71
EcalSelectiveReadout::nEndcaps
const static size_t nEndcaps
Definition: EcalSelectiveReadout.h:131
EcalSelectiveReadout::print
void print(std::ostream &os) const
print out the map
Definition: EcalSelectiveReadout.cc:266
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
EcalSelectiveReadout::nEndcapYBins
const static size_t nEndcapYBins
Definition: EcalSelectiveReadout.h:113
EcalSelectiveReadout::runSelectiveReadout0
void runSelectiveReadout0(const ttFlag_t towerFlags[nTriggerTowersInEta][nTriggerTowersInPhi])
Definition: EcalSelectiveReadout.cc:34
EcalSelectiveReadout::resetEeRuInterest
void resetEeRuInterest()
Definition: EcalSelectiveReadout.cc:23
EcalSelectiveReadout::maxDccChs
const static int maxDccChs
Definition: EcalSelectiveReadout.h:148
EcalSelectiveReadout::ttFlag_t
ttFlag_t
Definition: EcalSelectiveReadout.h:81
EEDetId::validDetId
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
L1TowerCalibrationProducer_cfi.iEta
iEta
Definition: L1TowerCalibrationProducer_cfi.py:60
EcalSelectiveReadout::nSupercrystalYBins
const static size_t nSupercrystalYBins
Definition: EcalSelectiveReadout.h:122
operator<<
std::ostream & operator<<(std::ostream &os, const EcalSelectiveReadout &selectiveReadout)
Definition: EcalSelectiveReadout.cc:306
EcalSelectiveReadout::nTriggerTowersInPhi
const static size_t nTriggerTowersInPhi
Definition: EcalSelectiveReadout.h:143
EcalSelectiveReadout::UNKNOWN
Definition: EcalSelectiveReadout.h:70