CMS 3D CMS Logo

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