CMS 3D CMS Logo

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