CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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),
57  empty(),
58  neighborMap(),
59  barrel(18, std::vector<std::vector<unsigned short>>(7, std::vector<unsigned short>(64))),
60  hf(18, std::vector<unsigned short>(8)) {
61  makeCrates();
62 }
63 
64 void L1RCT::input() {
65  for (int i = 0; i < 18; i++) {
66  crates.at(i).input(barrel.at(i), hf.at(i));
67  }
68 }
69 
70 void L1RCT::input(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 = (72 + 18 - cal_iphi) % 72; // transform TOWERS (not regions) into local
133  // rct (intuitive) phi bins
134 
135  // map digis to crates, cards, and towers
136  unsigned short crate = 999, card = 999, tower = 999;
137  crate = rctLookupTables_->rctParameters()->calcCrate(iphi, ieta);
138  card = rctLookupTables_->rctParameters()->calcCard(iphi, absIeta);
139  tower = rctLookupTables_->rctParameters()->calcTower(iphi, absIeta);
140 
141  unsigned short energy = ecalCollection[i].compressedEt();
142  unsigned short fineGrain = (unsigned short)ecalCollection[i].fineGrain(); // 0 or 1
143  unsigned short ecalInput = energy * 2 + fineGrain;
144 
145  // put input into correct crate/card/tower of barrel
146  if ((crate < 18) && (card < 7) && (tower < 32)) { // changed 64 to 32 Sept. 19 J. Leonard, rm -1 7Nov07
147  barrel.at(crate).at(card).at(tower) = ecalInput; // rm -1
148  } else {
149  std::cerr << "L1RCT: ecal out of range! tower = " << tower << " iphi is " << iphi << " absieta is " << absIeta
150  << std::endl;
151  }
152  }
153 
154  // same for hcal, once we get the hcal digis, just need to add 32 to towers:
155  // just copied and pasted and changed names where necessary
156  int nHcalDigi = hcalCollection.size();
157  // if (nHcalDigi != 4176){ std::cout << "L1RCT: Warning: There are " <<
158  // nHcalDigi << "hcal digis instead of 4176!" << std::endl;}
159  // incl HF 4032 + 144 = 4176
160  for (int i = 0; i < nHcalDigi; i++) {
161  if (hcalCollection[i].id().version() != 0) {
162  continue;
163  }
164  short ieta = (short)hcalCollection[i].id().ieta();
165  unsigned short absIeta = (unsigned short)abs(ieta);
166  unsigned short cal_iphi = (unsigned short)hcalCollection[i].id().iphi();
167  // All Hcal primitives (including HF) are reported
168  // with phi bin numbering in the range 0-72.
169  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
170  // transform Hcal TOWERS (1-72)into local rct (intuitive) phi bins (72 bins)
171  // 0-71 Use local iphi to work out the region and crate (for HB/HE and HF)
172  // HF regions need to have local iphi 0-17
173  if (absIeta >= 29) {
174  iphi = iphi / 4;
175  }
176 
177  // map digis to crates, cards, and towers
178  unsigned short crate = 999, card = 999, tower = 999;
179  crate = rctLookupTables_->rctParameters()->calcCrate(iphi, ieta);
180  if (absIeta < 29) {
181  card = rctLookupTables_->rctParameters()->calcCard(iphi, absIeta);
182  }
183  tower = rctLookupTables_->rctParameters()->calcTower(iphi, absIeta);
184 
185  unsigned short energy = hcalCollection[i].SOI_compressedEt(); // access only sample of interest
186  unsigned short fineGrain = (unsigned short)hcalCollection[i].SOI_fineGrain();
187  unsigned short hcalInput = energy * 2 + fineGrain;
188  if (absIeta <= 28) {
189  // put input into correct crate/card/tower of barrel
190  if ((crate < 18) && (card < 7) && (tower < 32)) { // changed 64 to 32 Sept. 19 J. Leonard, rm -1 7Nov07
191  barrel.at(crate).at(card).at(tower + 32) = hcalInput; // hcal towers are ecal + 32 see RC.cc; rm -1 7Nov07
192  } else {
193  std::cout << "L1RCT: hcal out of range! tower = " << tower << std::endl;
194  }
195  } else if ((absIeta >= 29) && (absIeta <= 32)) {
196  // put input into correct crate/region of HF
197  if ((crate < 18) && (tower < 8)) {
198  hf.at(crate).at(tower) = hcalInput;
199  } else {
200  std::cout << "L1RCT: hf out of range! region = " << tower << std::endl;
201  }
202  }
203  }
204 
205  input();
206 
207  return;
208 }
209 
210 // As the name implies, it will randomly generate input for the
211 // regional calotrigger.
213  for (int i = 0; i < 18; i++) {
214  for (int j = 0; j < 7; j++) {
215  for (int k = 0; k < 64; k++) {
216  barrel.at(i).at(j).at(k) = rand() % 511;
217  }
218  }
219  for (int j = 0; j < 8; j++) {
220  hf.at(i).at(j) = rand() % 255; // changed from 1023 (10 bits)
221  }
222  }
223  input();
224  return;
225 }
226 
227 // This method handles the bulk of the pointer passing, giving
228 // to each region pointers to its neighbors. If it does *not*
229 // have a neighbor in that direction then it passes it a pointer
230 // to an empty region that contains no data and is disconnected
231 // from anything else. This makes the electron finding algorithm simpler
232 // as then all regions can be treated equally.
236  L1RCTRegion *west;
237  L1RCTRegion *east;
238  L1RCTRegion *se;
239  L1RCTRegion *sw;
240  L1RCTRegion *nw;
241  L1RCTRegion *ne;
242  L1RCTRegion *primary;
243 
244  for (int i = 0; i < 18; i++) {
245  for (int j = 0; j < 7; j++) {
246  for (int k = 0; k < 2; k++) {
247  primary = crates.at(i).getReceiverCard(j)->getRegion(k);
248 
249  vector<int> northIndices = neighborMap.north(i, j, k);
250  if (northIndices.at(0) != -1)
251  north = crates.at(northIndices.at(0)).getReceiverCard(northIndices.at(1))->getRegion(northIndices.at(2));
252  else
253  north = &empty;
254 
255  vector<int> southIndices = neighborMap.south(i, j, k);
256  if (southIndices.at(0) != -1)
257  south = crates.at(southIndices.at(0)).getReceiverCard(southIndices.at(1))->getRegion(southIndices.at(2));
258  else
259  south = &empty;
260 
261  vector<int> westIndices = neighborMap.west(i, j, k);
262  if (westIndices.at(0) != -1)
263  west = crates.at(westIndices.at(0)).getReceiverCard(westIndices.at(1))->getRegion(westIndices.at(2));
264  else
265  west = &empty;
266 
267  vector<int> eastIndices = neighborMap.east(i, j, k);
268  if (eastIndices.at(0) != -1)
269  east = crates.at(eastIndices.at(0)).getReceiverCard(eastIndices.at(1))->getRegion(eastIndices.at(2));
270  else
271  east = &empty;
272 
273  vector<int> seIndices = neighborMap.se(i, j, k);
274  if (seIndices.at(0) != -1)
275  se = crates.at(seIndices.at(0)).getReceiverCard(seIndices.at(1))->getRegion(seIndices.at(2));
276  else
277  se = &empty;
278 
279  vector<int> swIndices = neighborMap.sw(i, j, k);
280  if (swIndices.at(0) != -1)
281  sw = crates.at(swIndices.at(0)).getReceiverCard(swIndices.at(1))->getRegion(swIndices.at(2));
282  else
283  sw = &empty;
284 
285  vector<int> neIndices = neighborMap.ne(i, j, k);
286  if (neIndices.at(0) != -1)
287  ne = crates.at(neIndices.at(0)).getReceiverCard(neIndices.at(1))->getRegion(neIndices.at(2));
288  else
289  ne = &empty;
290 
291  vector<int> nwIndices = neighborMap.nw(i, j, k);
292  if (nwIndices.at(0) != -1)
293  nw = crates.at(nwIndices.at(0)).getReceiverCard(nwIndices.at(1))->getRegion(nwIndices.at(2));
294  else
295  nw = &empty;
296 
297  primary->setNorthEt(north->giveNorthEt());
298  primary->setNorthHE_FG(north->giveNorthHE_FG());
299  primary->setSouthEt(south->giveSouthEt());
300  primary->setSouthHE_FG(south->giveSouthHE_FG());
301  primary->setEastEt(east->giveEastEt());
302  primary->setEastHE_FG(east->giveEastHE_FG());
303  primary->setWestEt(west->giveWestEt());
304  primary->setWestHE_FG(west->giveWestHE_FG());
305  primary->setSEEt(se->giveSEEt());
306  primary->setSEHE_FG(se->giveSEHE_FG());
307  primary->setSWEt(sw->giveSWEt());
308  primary->setSWHE_FG(sw->giveSWHE_FG());
309  primary->setNWEt(nw->giveNWEt());
310  primary->setNWHE_FG(nw->giveNWHE_FG());
311  primary->setNEEt(ne->giveNEEt());
312  primary->setNEHE_FG(ne->giveNEHE_FG());
313  }
314  }
315  }
316 }
317 
318 void L1RCT::print() {
319  for (int i = 0; i < 18; i++) {
320  std::cout << "Crate " << i << std::endl;
321  crates.at(i).print();
322  }
323 }
324 
325 // Returns the top four isolated electrons from given crate
326 // in a vector of L1CaloEmCands
328  std::vector<unsigned short> isoEmObjects = crates.at(crate).getIsolatedEGObjects();
329  L1CaloEmCollection isoEmCands;
330  for (uint16_t i = 0; i < 4; i++) {
331  unsigned rgn = ((isoEmObjects.at(i)) & 1);
332  unsigned crd = (((isoEmObjects.at(i)) / 2) & 7);
333  unsigned energy = ((isoEmObjects.at(i)) / 16);
334  unsigned rank = rctLookupTables_->emRank(energy);
335  L1CaloEmCand isoCand(rank, rgn, crd, crate, true, i,
336  0); // includes emcand index
337  isoEmCands.push_back(isoCand);
338  }
339  return isoEmCands;
340 }
341 
342 // Returns the top four nonisolated electrons from the given crate
343 // in a vector of L1CaloEmCands
345  std::vector<unsigned short> nonIsoEmObjects = crates.at(crate).getNonisolatedEGObjects();
346  L1CaloEmCollection nonIsoEmCands;
347  for (uint16_t i = 0; i < 4; i++) {
348  unsigned rgn = ((nonIsoEmObjects.at(i)) & 1);
349  unsigned crd = (((nonIsoEmObjects.at(i)) / 2) & 7);
350  unsigned energy = ((nonIsoEmObjects.at(i)) / 16);
351  unsigned rank = rctLookupTables_->emRank(energy);
352  L1CaloEmCand nonIsoCand(rank, rgn, crd, crate, false, i,
353  0); // includes emcand index
354  nonIsoEmCands.push_back(nonIsoCand);
355  }
356  return nonIsoEmCands;
357 }
358 
359 vector<L1CaloRegion> L1RCT::getRegions(unsigned crate) {
360  // barrel regions
361  std::bitset<14> taus((long)crates.at(crate).getTauBits());
362  std::bitset<14> mips((long)crates.at(crate).getMIPBits());
363  std::bitset<14> quiets((long)crates.at(crate).getQuietBits());
364  std::bitset<14> overflows((long)crates.at(crate).getOverFlowBits());
365  std::vector<unsigned short> barrelEnergies = crates.at(crate).getBarrelRegions();
366  std::vector<L1CaloRegion> regionCollection;
367  for (unsigned card = 0; card < 7; card++) {
368  for (unsigned rgn = 0; rgn < 2; rgn++) {
369  bool tau = taus[card * 2 + rgn];
370  bool mip = mips[card * 2 + rgn];
371  bool quiet = quiets[card * 2 + rgn];
372  bool overflow = overflows[card * 2 + rgn];
373  unsigned barrelEnergy = barrelEnergies.at(card * 2 + rgn);
374  L1CaloRegion region(barrelEnergy, overflow, tau, mip, quiet, crate, card, rgn);
375  regionCollection.push_back(region);
376  }
377  }
378 
379  // hf regions
380  std::vector<unsigned short> hfEnergies = crates.at(crate).getHFRegions();
381  // fine grain bits -- still have to work out digi input
382  std::vector<unsigned short> hfFineGrainBits = crates.at(crate).getHFFineGrainBits();
383  for (unsigned hfRgn = 0; hfRgn < 8; hfRgn++) { // region number, see diagram on paper. make sure know how hf
384  // regions come in.
385  unsigned energy = hfEnergies.at(hfRgn);
386  bool fineGrain = hfFineGrainBits.at(hfRgn);
387  L1CaloRegion hfRegion(energy, fineGrain, crate, hfRgn);
388  regionCollection.push_back(hfRegion);
389  }
390  return regionCollection;
391 }
void setNEEt(unsigned short ne)
Definition: L1RCTRegion.cc:168
std::vector< unsigned short > giveSouthHE_FG() const
Definition: L1RCTRegion.cc:105
std::vector< std::vector< unsigned short > > hf
Definition: L1RCT.h:111
void setSWHE_FG(unsigned short sw)
Definition: L1RCTRegion.cc:191
std::vector< L1CaloEmCand > L1CaloEmCollection
const edm::EventSetup & c
std::vector< int > west(int crate, int card, int region)
std::vector< unsigned short > giveWestEt() const
Definition: L1RCTRegion.cc:116
void setNEHE_FG(unsigned short ne)
Definition: L1RCTRegion.cc:169
std::vector< int > north(int crate, int card, int region)
void setNorthHE_FG(const std::vector< unsigned short > &north)
Definition: L1RCTRegion.cc:89
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:359
std::vector< unsigned short > giveEastHE_FG() const
Definition: L1RCTRegion.cc:149
void setNWHE_FG(unsigned short nw)
Definition: L1RCTRegion.cc:180
Level-1 Region Calorimeter Trigger EM candidate.
Definition: L1CaloEmCand.h:17
std::vector< unsigned short > giveWestHE_FG() const
Definition: L1RCTRegion.cc:127
std::vector< L1RCTCrate > crates
Definition: L1RCT.h:101
L1CaloEmCollection getNonisolatedEGObjects(unsigned crate)
Definition: L1RCT.cc:344
void setWestHE_FG(const std::vector< unsigned short > &west)
Definition: L1RCTRegion.cc:133
void setSEEt(unsigned short se)
Definition: L1RCTRegion.cc:201
unsigned short giveNEHE_FG() const
Definition: L1RCTRegion.cc:167
void randomInput()
Definition: L1RCT.cc:212
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:200
L1CaloEmCollection getIsolatedEGObjects(unsigned crate)
Definition: L1RCT.cc:327
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:182
unsigned short giveSEEt() const
Definition: L1RCTRegion.cc:193
void setSWEt(unsigned short sw)
Definition: L1RCTRegion.cc:190
void print()
Definition: L1RCT.cc:318
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:111
void setNorthEt(const std::vector< unsigned short > &north)
Definition: L1RCTRegion.cc:79
void input()
Definition: L1RCT.cc:64
std::vector< int > ne(int crate, int card, int region)
std::vector< unsigned short > giveNorthEt() const
Definition: L1RCTRegion.cc:73
void setSEHE_FG(unsigned short se)
Definition: L1RCTRegion.cc:202
L1RCTNeighborMap neighborMap
Definition: L1RCT.h:93
void setWestEt(const std::vector< unsigned short > &west)
Definition: L1RCTRegion.cc:122
const L1RCTParameters * rctParameters() const
void processEvent()
Definition: L1RCT.cc:36
void setEastHE_FG(const std::vector< unsigned short > &east)
Definition: L1RCTRegion.cc:155
void setEastEt(const std::vector< unsigned short > &east)
Definition: L1RCTRegion.cc:144
unsigned short giveNWHE_FG() const
Definition: L1RCTRegion.cc:178
void fileInput(const char *filename)
Definition: L1RCT.cc:81
void setNWEt(unsigned short nw)
Definition: L1RCTRegion.cc:179
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:86
tuple filename
Definition: lut2db_cfg.py:20
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:21
std::vector< unsigned short > giveEastEt() const
Definition: L1RCTRegion.cc:138
tuple cout
Definition: gather_cfg.py:144
void setSouthEt(const std::vector< unsigned short > &south)
Definition: L1RCTRegion.cc:100
void shareNeighbors()
Definition: L1RCT.cc:233
unsigned short giveSWHE_FG() const
Definition: L1RCTRegion.cc:189
std::vector< int > se(int crate, int card, int region)
unsigned short giveNEEt() const
Definition: L1RCTRegion.cc:160
const L1RCTLookupTables * rctLookupTables_
Definition: L1RCT.h:77
std::vector< unsigned short > giveNorthHE_FG() const
Definition: L1RCTRegion.cc:83
unsigned short giveNWEt() const
Definition: L1RCTRegion.cc:171
unsigned short calcCrate(unsigned short rct_iphi, short ieta) const
std::vector< unsigned short > giveSouthEt() const
Definition: L1RCTRegion.cc:94
std::vector< std::vector< std::vector< unsigned short > > > barrel
Definition: L1RCT.h:110