CMS 3D CMS Logo

L1RCT.cc
Go to the documentation of this file.
2 
3 #include <vector>
4 using std::vector;
5 
6 #include <fstream>
7 #include <string>
8 
9 #include <iostream>
10 using std::cerr;
11 using std::cout;
12 using std::endl;
13 using std::ostream;
14 
15 #include <iomanip>
16 
17 //#include "DataFormats/L1CaloTrigger/interface/L1CaloEmCand.h"
18 
22 
23 // Main method to process a single event, hence the name.
24 // First it sets up all the neighbors, sharing the pointers to the proper
25 // regions. This is done via the neighborMap auxiliary class, which
26 // is very dry and contains the proper mappings from crate,card,and
27 // region numbers to the crate,card, and region numbers of the neighbors.
28 // The next step is to pass along the pointers for the regions
29 // to their corresponding Electron Isolation Card
30 // This is done in the crate method fillElectronIsolationCards
31 // Then the actual processing of the data begins with the
32 // processReceiverCards and processElectronIsolationCards methods.
33 // Next the region sums, tau bits, mip bits, and electron
34 // candidates are passed onto the Jet Summary Card, and that's where
35 // the data flow ends for the Regional CaloTrigger.
37  for (int i = 0; i < 18; i++)
38  crates.at(i).processReceiverCards();
40  for (int i = 0; i < 18; i++) {
41  crates.at(i).fillElectronIsolationCards();
42  crates.at(i).processElectronIsolationCards();
43  crates.at(i).fillJetSummaryCard();
44  crates.at(i).processJetSummaryCard();
45  }
46 }
47 
49  for (int i = 0; i < 18; i++) {
51  crates.push_back(c);
52  }
53 }
54 
55 L1RCT::L1RCT(const L1RCTLookupTables *rctLookupTables)
56  : rctLookupTables_(rctLookupTables), empty(), neighborMap(),
57  barrel(18, std::vector<std::vector<unsigned short>>(
58  7, std::vector<unsigned short>(64))),
59  hf(18, std::vector<unsigned short>(8)) {
60  makeCrates();
61 }
62 
63 void L1RCT::input() {
64  for (int i = 0; i < 18; i++) {
65  crates.at(i).input(barrel.at(i), hf.at(i));
66  }
67 }
68 
70  const std::vector<std::vector<std::vector<unsigned short>>> &barrelIn,
71  const std::vector<std::vector<unsigned short>> &hfIn) {
72  for (int i = 0; i < 18; i++) {
73  crates.at(i).input(barrelIn.at(i), hfIn.at(i));
74  }
75 }
76 
77 // This is a method for taking input from a file. Any entries in excess
78 // of 18*7*64 will simply be ignored. This *only* fills input for a single
79 // event. At the moment you cannot put a ton of data and have it be
80 // read as separate events.
81 void L1RCT::fileInput(const char *filename) { // added "const" also in .h
82  unsigned short x;
83  std::ifstream instream(filename);
84  if (instream) {
85  for (int i = 0; i < 18; i++) {
86  for (int j = 0; j < 7; j++) {
87  for (int k = 0; k < 64; k++) {
88  if (instream >> x) {
89  unsigned short bit = x / 256; // added J.Leonard Aug. 16 06
90  unsigned short energy = x & 255; //
91  unsigned short input = energy * 2 + bit; //
92  barrel.at(i).at(j).at(k) = input;
93  } else
94  break;
95  }
96  }
97  for (int j = 0; j < 8; j++) {
98  if (instream >> x) {
99  hf.at(i).at(j) = x;
100  } else
101  break;
102  }
103  }
104  }
105  input();
106 }
107 
108 // takes hcal and ecal digi input, including HF
109 void L1RCT::digiInput(const EcalTrigPrimDigiCollection &ecalCollection,
110  const HcalTrigPrimDigiCollection &hcalCollection) {
111  // fills input vectors with 0's in case ecal or hcal collection not used
112  for (int i = 0; i < 18; i++) {
113  for (int j = 0; j < 7; j++) {
114  for (int k = 0; k < 64; k++) {
115  barrel.at(i).at(j).at(k) = 0;
116  }
117  }
118  for (int j = 0; j < 8; j++) {
119  hf.at(i).at(j) = 0;
120  }
121  }
122 
123  int nEcalDigi = ecalCollection.size();
124  if (nEcalDigi > 4032) {
125  nEcalDigi = 4032;
126  }
127  for (int i = 0; i < nEcalDigi; i++) {
128  short ieta = (short)ecalCollection[i].id().ieta();
129  // Note absIeta counts from 1-28 (not 0-27)
130  unsigned short absIeta = (unsigned short)abs(ieta);
131  unsigned short cal_iphi = (unsigned short)ecalCollection[i].id().iphi();
132  unsigned short iphi =
133  (72 + 18 - cal_iphi) % 72; // transform TOWERS (not regions) into local
134  // rct (intuitive) phi bins
135 
136  // map digis to crates, cards, and towers
137  unsigned short crate = 999, card = 999, tower = 999;
138  crate = rctLookupTables_->rctParameters()->calcCrate(iphi, ieta);
139  card = rctLookupTables_->rctParameters()->calcCard(iphi, absIeta);
140  tower = rctLookupTables_->rctParameters()->calcTower(iphi, absIeta);
141 
142  unsigned short energy = ecalCollection[i].compressedEt();
143  unsigned short fineGrain =
144  (unsigned short)ecalCollection[i].fineGrain(); // 0 or 1
145  unsigned short ecalInput = energy * 2 + fineGrain;
146 
147  // put input into correct crate/card/tower of barrel
148  if ((crate < 18) && (card < 7) &&
149  (tower < 32)) { // changed 64 to 32 Sept. 19 J. Leonard, rm -1 7Nov07
150  barrel.at(crate).at(card).at(tower) = ecalInput; // rm -1
151  } else {
152  std::cerr << "L1RCT: ecal out of range! tower = " << tower << " iphi is "
153  << iphi << " absieta is " << absIeta << std::endl;
154  }
155  }
156 
157  // same for hcal, once we get the hcal digis, just need to add 32 to towers:
158  // just copied and pasted and changed names where necessary
159  int nHcalDigi = hcalCollection.size();
160  // if (nHcalDigi != 4176){ std::cout << "L1RCT: Warning: There are " <<
161  // nHcalDigi << "hcal digis instead of 4176!" << std::endl;}
162  // incl HF 4032 + 144 = 4176
163  for (int i = 0; i < nHcalDigi; i++) {
164  if (hcalCollection[i].id().version() != 0) {
165  continue;
166  }
167  short ieta = (short)hcalCollection[i].id().ieta();
168  unsigned short absIeta = (unsigned short)abs(ieta);
169  unsigned short cal_iphi = (unsigned short)hcalCollection[i].id().iphi();
170  // All Hcal primitives (including HF) are reported
171  // with phi bin numbering in the range 0-72.
172  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
173  // transform Hcal TOWERS (1-72)into local rct (intuitive) phi bins (72 bins)
174  // 0-71 Use local iphi to work out the region and crate (for HB/HE and HF)
175  // HF regions need to have local iphi 0-17
176  if (absIeta >= 29) {
177  iphi = iphi / 4;
178  }
179 
180  // map digis to crates, cards, and towers
181  unsigned short crate = 999, card = 999, tower = 999;
182  crate = rctLookupTables_->rctParameters()->calcCrate(iphi, ieta);
183  if (absIeta < 29) {
184  card = rctLookupTables_->rctParameters()->calcCard(iphi, absIeta);
185  }
186  tower = rctLookupTables_->rctParameters()->calcTower(iphi, absIeta);
187 
188  unsigned short energy =
189  hcalCollection[i].SOI_compressedEt(); // access only sample of interest
190  unsigned short fineGrain =
191  (unsigned short)hcalCollection[i].SOI_fineGrain();
192  unsigned short hcalInput = energy * 2 + fineGrain;
193  if (absIeta <= 28) {
194  // put input into correct crate/card/tower of barrel
195  if ((crate < 18) && (card < 7) &&
196  (tower < 32)) { // changed 64 to 32 Sept. 19 J. Leonard, rm -1 7Nov07
197  barrel.at(crate).at(card).at(tower + 32) =
198  hcalInput; // hcal towers are ecal + 32 see RC.cc; rm -1 7Nov07
199  } else {
200  std::cout << "L1RCT: hcal out of range! tower = " << tower
201  << std::endl;
202  }
203  } else if ((absIeta >= 29) && (absIeta <= 32)) {
204  // put input into correct crate/region of HF
205  if ((crate < 18) && (tower < 8)) {
206  hf.at(crate).at(tower) = hcalInput;
207  } else {
208  std::cout << "L1RCT: hf out of range! region = " << tower << std::endl;
209  }
210  }
211  }
212 
213  input();
214 
215  return;
216 }
217 
218 // As the name implies, it will randomly generate input for the
219 // regional calotrigger.
221  for (int i = 0; i < 18; i++) {
222  for (int j = 0; j < 7; j++) {
223  for (int k = 0; k < 64; k++) {
224  barrel.at(i).at(j).at(k) = rand() % 511;
225  }
226  }
227  for (int j = 0; j < 8; j++) {
228  hf.at(i).at(j) = rand() % 255; // changed from 1023 (10 bits)
229  }
230  }
231  input();
232  return;
233 }
234 
235 // This method handles the bulk of the pointer passing, giving
236 // to each region pointers to its neighbors. If it does *not*
237 // have a neighbor in that direction then it passes it a pointer
238 // to an empty region that contains no data and is disconnected
239 // from anything else. This makes the electron finding algorithm simpler
240 // as then all regions can be treated equally.
244  L1RCTRegion *west;
245  L1RCTRegion *east;
246  L1RCTRegion *se;
247  L1RCTRegion *sw;
248  L1RCTRegion *nw;
249  L1RCTRegion *ne;
250  L1RCTRegion *primary;
251 
252  for (int i = 0; i < 18; i++) {
253  for (int j = 0; j < 7; j++) {
254  for (int k = 0; k < 2; k++) {
255 
256  primary = crates.at(i).getReceiverCard(j)->getRegion(k);
257 
258  vector<int> northIndices = neighborMap.north(i, j, k);
259  if (northIndices.at(0) != -1)
260  north = crates.at(northIndices.at(0))
261  .getReceiverCard(northIndices.at(1))
262  ->getRegion(northIndices.at(2));
263  else
264  north = &empty;
265 
266  vector<int> southIndices = neighborMap.south(i, j, k);
267  if (southIndices.at(0) != -1)
268  south = crates.at(southIndices.at(0))
269  .getReceiverCard(southIndices.at(1))
270  ->getRegion(southIndices.at(2));
271  else
272  south = &empty;
273 
274  vector<int> westIndices = neighborMap.west(i, j, k);
275  if (westIndices.at(0) != -1)
276  west = crates.at(westIndices.at(0))
277  .getReceiverCard(westIndices.at(1))
278  ->getRegion(westIndices.at(2));
279  else
280  west = &empty;
281 
282  vector<int> eastIndices = neighborMap.east(i, j, k);
283  if (eastIndices.at(0) != -1)
284  east = crates.at(eastIndices.at(0))
285  .getReceiverCard(eastIndices.at(1))
286  ->getRegion(eastIndices.at(2));
287  else
288  east = &empty;
289 
290  vector<int> seIndices = neighborMap.se(i, j, k);
291  if (seIndices.at(0) != -1)
292  se = crates.at(seIndices.at(0))
293  .getReceiverCard(seIndices.at(1))
294  ->getRegion(seIndices.at(2));
295  else
296  se = &empty;
297 
298  vector<int> swIndices = neighborMap.sw(i, j, k);
299  if (swIndices.at(0) != -1)
300  sw = crates.at(swIndices.at(0))
301  .getReceiverCard(swIndices.at(1))
302  ->getRegion(swIndices.at(2));
303  else
304  sw = &empty;
305 
306  vector<int> neIndices = neighborMap.ne(i, j, k);
307  if (neIndices.at(0) != -1)
308  ne = crates.at(neIndices.at(0))
309  .getReceiverCard(neIndices.at(1))
310  ->getRegion(neIndices.at(2));
311  else
312  ne = &empty;
313 
314  vector<int> nwIndices = neighborMap.nw(i, j, k);
315  if (nwIndices.at(0) != -1)
316  nw = crates.at(nwIndices.at(0))
317  .getReceiverCard(nwIndices.at(1))
318  ->getRegion(nwIndices.at(2));
319  else
320  nw = &empty;
321 
322  primary->setNorthEt(north->giveNorthEt());
323  primary->setNorthHE_FG(north->giveNorthHE_FG());
324  primary->setSouthEt(south->giveSouthEt());
325  primary->setSouthHE_FG(south->giveSouthHE_FG());
326  primary->setEastEt(east->giveEastEt());
327  primary->setEastHE_FG(east->giveEastHE_FG());
328  primary->setWestEt(west->giveWestEt());
329  primary->setWestHE_FG(west->giveWestHE_FG());
330  primary->setSEEt(se->giveSEEt());
331  primary->setSEHE_FG(se->giveSEHE_FG());
332  primary->setSWEt(sw->giveSWEt());
333  primary->setSWHE_FG(sw->giveSWHE_FG());
334  primary->setNWEt(nw->giveNWEt());
335  primary->setNWHE_FG(nw->giveNWHE_FG());
336  primary->setNEEt(ne->giveNEEt());
337  primary->setNEHE_FG(ne->giveNEHE_FG());
338  }
339  }
340  }
341 }
342 
343 void L1RCT::print() {
344  for (int i = 0; i < 18; i++) {
345  std::cout << "Crate " << i << std::endl;
346  crates.at(i).print();
347  }
348 }
349 
350 // Returns the top four isolated electrons from given crate
351 // in a vector of L1CaloEmCands
353  std::vector<unsigned short> isoEmObjects =
354  crates.at(crate).getIsolatedEGObjects();
355  L1CaloEmCollection isoEmCands;
356  for (uint16_t i = 0; i < 4; i++) {
357  unsigned rgn = ((isoEmObjects.at(i)) & 1);
358  unsigned crd = (((isoEmObjects.at(i)) / 2) & 7);
359  unsigned energy = ((isoEmObjects.at(i)) / 16);
360  unsigned rank = rctLookupTables_->emRank(energy);
361  L1CaloEmCand isoCand(rank, rgn, crd, crate, true, i,
362  0); // includes emcand index
363  isoEmCands.push_back(isoCand);
364  }
365  return isoEmCands;
366 }
367 
368 // Returns the top four nonisolated electrons from the given crate
369 // in a vector of L1CaloEmCands
371  std::vector<unsigned short> nonIsoEmObjects =
372  crates.at(crate).getNonisolatedEGObjects();
373  L1CaloEmCollection nonIsoEmCands;
374  for (uint16_t i = 0; i < 4; i++) {
375  unsigned rgn = ((nonIsoEmObjects.at(i)) & 1);
376  unsigned crd = (((nonIsoEmObjects.at(i)) / 2) & 7);
377  unsigned energy = ((nonIsoEmObjects.at(i)) / 16);
378  unsigned rank = rctLookupTables_->emRank(energy);
379  L1CaloEmCand nonIsoCand(rank, rgn, crd, crate, false, i,
380  0); // includes emcand index
381  nonIsoEmCands.push_back(nonIsoCand);
382  }
383  return nonIsoEmCands;
384 }
385 
386 vector<L1CaloRegion> L1RCT::getRegions(unsigned crate) {
387  // barrel regions
388  std::bitset<14> taus((long)crates.at(crate).getTauBits());
389  std::bitset<14> mips((long)crates.at(crate).getMIPBits());
390  std::bitset<14> quiets((long)crates.at(crate).getQuietBits());
391  std::bitset<14> overflows((long)crates.at(crate).getOverFlowBits());
392  std::vector<unsigned short> barrelEnergies =
393  crates.at(crate).getBarrelRegions();
394  std::vector<L1CaloRegion> regionCollection;
395  for (unsigned card = 0; card < 7; card++) {
396  for (unsigned rgn = 0; rgn < 2; rgn++) {
397  bool tau = taus[card * 2 + rgn];
398  bool mip = mips[card * 2 + rgn];
399  bool quiet = quiets[card * 2 + rgn];
400  bool overflow = overflows[card * 2 + rgn];
401  unsigned barrelEnergy = barrelEnergies.at(card * 2 + rgn);
402  L1CaloRegion region(barrelEnergy, overflow, tau, mip, quiet, crate, card,
403  rgn);
404  regionCollection.push_back(region);
405  }
406  }
407 
408  // hf regions
409  std::vector<unsigned short> hfEnergies = crates.at(crate).getHFRegions();
410  // fine grain bits -- still have to work out digi input
411  std::vector<unsigned short> hfFineGrainBits =
412  crates.at(crate).getHFFineGrainBits();
413  for (unsigned hfRgn = 0; hfRgn < 8;
414  hfRgn++) { // region number, see diagram on paper. make sure know how hf
415  // regions come in.
416  unsigned energy = hfEnergies.at(hfRgn);
417  bool fineGrain = hfFineGrainBits.at(hfRgn);
418  L1CaloRegion hfRegion(energy, fineGrain, crate, hfRgn);
419  regionCollection.push_back(hfRegion);
420  }
421  return regionCollection;
422 }
void setNEEt(unsigned short ne)
Definition: L1RCTRegion.cc:184
std::vector< unsigned short > giveSouthHE_FG() const
Definition: L1RCTRegion.cc:121
std::vector< std::vector< unsigned short > > hf
Definition: L1RCT.h:124
void setSWHE_FG(unsigned short sw)
Definition: L1RCTRegion.cc:207
std::vector< L1CaloEmCand > L1CaloEmCollection
std::vector< int > west(int crate, int card, int region)
std::vector< unsigned short > giveWestEt() const
Definition: L1RCTRegion.cc:132
void setNEHE_FG(unsigned short ne)
Definition: L1RCTRegion.cc:185
std::vector< int > north(int crate, int card, int region)
void setNorthHE_FG(const std::vector< unsigned short > &north)
Definition: L1RCTRegion.cc:105
std::vector< int > sw(int crate, int card, int region)
std::vector< int > south(int crate, int card, int region)
std::vector< L1CaloRegion > getRegions(unsigned crate)
Definition: L1RCT.cc:386
std::vector< unsigned short > giveEastHE_FG() const
Definition: L1RCTRegion.cc:165
void setNWHE_FG(unsigned short nw)
Definition: L1RCTRegion.cc:196
Level-1 Region Calorimeter Trigger EM candidate.
Definition: L1CaloEmCand.h:18
std::vector< unsigned short > giveWestHE_FG() const
Definition: L1RCTRegion.cc:143
std::vector< L1RCTCrate > crates
Definition: L1RCT.h:114
L1CaloEmCollection getNonisolatedEGObjects(unsigned crate)
Definition: L1RCT.cc:370
void setWestHE_FG(const std::vector< unsigned short > &west)
Definition: L1RCTRegion.cc:149
void setSEEt(unsigned short se)
Definition: L1RCTRegion.cc:219
unsigned short giveNEHE_FG() const
Definition: L1RCTRegion.cc:183
void randomInput()
Definition: L1RCT.cc:220
unsigned short calcTower(unsigned short rct_iphi, unsigned short absIeta) const
void makeCrates()
Definition: L1RCT.cc:48
unsigned short giveSEHE_FG() const
Definition: L1RCTRegion.cc:218
L1CaloEmCollection getIsolatedEGObjects(unsigned crate)
Definition: L1RCT.cc:352
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int emRank(unsigned short energy) const
unsigned short giveSWEt() const
Definition: L1RCTRegion.cc:198
unsigned short giveSEEt() const
Definition: L1RCTRegion.cc:211
void setSWEt(unsigned short sw)
Definition: L1RCTRegion.cc:206
void print()
Definition: L1RCT.cc:343
int k[5][pyjets_maxn]
unsigned short calcCard(unsigned short rct_iphi, unsigned short absIeta) const
std::vector< int > nw(int crate, int card, int region)
void setSouthHE_FG(const std::vector< unsigned short > &south)
Definition: L1RCTRegion.cc:127
void setNorthEt(const std::vector< unsigned short > &north)
Definition: L1RCTRegion.cc:95
void input()
Definition: L1RCT.cc:63
std::vector< int > ne(int crate, int card, int region)
std::vector< unsigned short > giveNorthEt() const
Definition: L1RCTRegion.cc:89
void setSEHE_FG(unsigned short se)
Definition: L1RCTRegion.cc:220
L1RCTNeighborMap neighborMap
Definition: L1RCT.h:106
void setWestEt(const std::vector< unsigned short > &west)
Definition: L1RCTRegion.cc:138
const L1RCTParameters * rctParameters() const
void processEvent()
Definition: L1RCT.cc:36
void setEastHE_FG(const std::vector< unsigned short > &east)
Definition: L1RCTRegion.cc:171
void setEastEt(const std::vector< unsigned short > &east)
Definition: L1RCTRegion.cc:160
unsigned short giveNWHE_FG() const
Definition: L1RCTRegion.cc:194
void fileInput(const char *filename)
Definition: L1RCT.cc:81
void setNWEt(unsigned short nw)
Definition: L1RCTRegion.cc:195
std::vector< int > east(int crate, int card, int region)
size_type size() const
void digiInput(const EcalTrigPrimDigiCollection &ecalCollection, const HcalTrigPrimDigiCollection &hcalCollection)
Definition: L1RCT.cc:109
L1RCTRegion empty
Definition: L1RCT.h:99
Signal rand(Signal arg)
Definition: vlib.cc:442
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:22
std::vector< unsigned short > giveEastEt() const
Definition: L1RCTRegion.cc:154
void setSouthEt(const std::vector< unsigned short > &south)
Definition: L1RCTRegion.cc:116
void shareNeighbors()
Definition: L1RCT.cc:241
unsigned short giveSWHE_FG() const
Definition: L1RCTRegion.cc:205
std::vector< int > se(int crate, int card, int region)
unsigned short giveNEEt() const
Definition: L1RCTRegion.cc:176
const L1RCTLookupTables * rctLookupTables_
Definition: L1RCT.h:90
std::vector< unsigned short > giveNorthHE_FG() const
Definition: L1RCTRegion.cc:99
unsigned short giveNWEt() const
Definition: L1RCTRegion.cc:187
unsigned short calcCrate(unsigned short rct_iphi, short ieta) const
std::vector< unsigned short > giveSouthEt() const
Definition: L1RCTRegion.cc:110
std::vector< std::vector< std::vector< unsigned short > > > barrel
Definition: L1RCT.h:123