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(std::vector<std::vector<std::vector<unsigned short> > > barrelIn,
74  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  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) 0-71
174  // 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 
189  unsigned short energy = hcalCollection[i].SOI_compressedEt(); // access only sample of interest
190  unsigned short fineGrain = (unsigned short) hcalCollection[i].SOI_fineGrain();
191  unsigned short hcalInput = energy*2 + fineGrain;
192  if (absIeta <= 28){
193  // put input into correct crate/card/tower of barrel
194  if ((crate<18) && (card<7) && (tower<32)) { // changed 64 to 32 Sept. 19 J. Leonard, rm -1 7Nov07
195  barrel.at(crate).at(card).at(tower + 32) = hcalInput; // hcal towers are ecal + 32 see RC.cc; rm -1 7Nov07
196  }
197  else { std::cout << "L1RCT: hcal out of range! tower = " << tower << std::endl; }
198  }
199  else if ((absIeta >= 29) && (absIeta <= 32)){
200  // put input into correct crate/region of HF
201  if ((crate<18) && (tower<8)) {
202  hf.at(crate).at(tower) = hcalInput;
203  }
204  else { std::cout << "L1RCT: hf out of range! region = " << tower << std::endl; }
205  }
206 
207  }
208 
209  input();
210 
211  return;
212 
213 }
214 
215 //As the name implies, it will randomly generate input for the
216 //regional calotrigger.
218 {
219  for(int i = 0; i<18;i++){
220  for(int j = 0; j<7;j++){
221  for(int k = 0; k<64; k++){
222  barrel.at(i).at(j).at(k) = rand()%511;
223  }
224  }
225  for(int j = 0; j<8;j++){
226  hf.at(i).at(j) = rand()%255; // changed from 1023 (10 bits)
227  }
228  }
229  input();
230  return;
231 }
232 
233 
234 //This method handles the bulk of the pointer passing, giving
235 //to each region pointers to its neighbors. If it does *not*
236 //have a neighbor in that direction then it passes it a pointer
237 //to an empty region that contains no data and is disconnected
238 //from anything else. This makes the electron finding algorithm simpler
239 //as then all regions can be treated equally.
243  L1RCTRegion *west;
244  L1RCTRegion *east;
245  L1RCTRegion *se;
246  L1RCTRegion *sw;
247  L1RCTRegion *nw;
248  L1RCTRegion *ne;
249  L1RCTRegion *primary;
250 
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)).getReceiverCard(northIndices.at(1))->getRegion(northIndices.at(2));
261  else north = &empty;
262 
263  vector<int> southIndices = neighborMap.south(i,j,k);
264  if(southIndices.at(0) != -1)
265  south = crates.at(southIndices.at(0)).getReceiverCard(southIndices.at(1))->getRegion(southIndices.at(2));
266  else south = &empty;
267 
268  vector<int> westIndices = neighborMap.west(i,j,k);
269  if(westIndices.at(0) != -1)
270  west = crates.at(westIndices.at(0)).getReceiverCard(westIndices.at(1))->getRegion(westIndices.at(2));
271  else west = &empty;
272 
273  vector<int> eastIndices = neighborMap.east(i,j,k);
274  if(eastIndices.at(0) != -1)
275  east = crates.at(eastIndices.at(0)).getReceiverCard(eastIndices.at(1))->getRegion(eastIndices.at(2));
276  else east = &empty;
277 
278  vector<int> seIndices = neighborMap.se(i,j,k);
279  if(seIndices.at(0) != -1)
280  se = crates.at(seIndices.at(0)).getReceiverCard(seIndices.at(1))->getRegion(seIndices.at(2));
281  else se = &empty;
282 
283  vector<int> swIndices = neighborMap.sw(i,j,k);
284  if(swIndices.at(0) != -1)
285  sw= crates.at(swIndices.at(0)).getReceiverCard(swIndices.at(1))->getRegion(swIndices.at(2));
286  else sw = &empty;
287 
288  vector<int> neIndices = neighborMap.ne(i,j,k);
289  if(neIndices.at(0) != -1)
290  ne= crates.at(neIndices.at(0)).getReceiverCard(neIndices.at(1))->getRegion(neIndices.at(2));
291  else ne = &empty;
292 
293  vector<int> nwIndices = neighborMap.nw(i,j,k);
294  if(nwIndices.at(0) != -1)
295  nw= crates.at(nwIndices.at(0)).getReceiverCard(nwIndices.at(1))->getRegion(nwIndices.at(2));
296  else nw = &empty;
297 
298  primary->setNorthEt(north->giveNorthEt());
299  primary->setNorthHE_FG(north->giveNorthHE_FG());
300  primary->setSouthEt(south->giveSouthEt());
301  primary->setSouthHE_FG(south->giveSouthHE_FG());
302  primary->setEastEt(east->giveEastEt());
303  primary->setEastHE_FG(east->giveEastHE_FG());
304  primary->setWestEt(west->giveWestEt());
305  primary->setWestHE_FG(west->giveWestHE_FG());
306  primary->setSEEt(se->giveSEEt());
307  primary->setSEHE_FG(se->giveSEHE_FG());
308  primary->setSWEt(sw->giveSWEt());
309  primary->setSWHE_FG(sw->giveSWHE_FG());
310  primary->setNWEt(nw->giveNWEt());
311  primary->setNWHE_FG(nw->giveNWHE_FG());
312  primary->setNEEt(ne->giveNEEt());
313  primary->setNEHE_FG(ne->giveNEHE_FG());
314 
315 
316 
317  }
318  }
319  }
320 
321 }
322 
324  for(int i = 0; i<18; i++){
325  std::cout << "Crate " << i << std::endl;
326  crates.at(i).print();
327  }
328 }
329 
330 // Returns the top four isolated electrons from given crate
331 // in a vector of L1CaloEmCands
333  std::vector<unsigned short> isoEmObjects = crates.at(crate).getIsolatedEGObjects();
334  L1CaloEmCollection isoEmCands;
335  for (uint16_t i = 0; i < 4; i++){
336  unsigned rgn = ((isoEmObjects.at(i)) & 1);
337  unsigned crd = (((isoEmObjects.at(i))/2) & 7);
338  unsigned energy = ((isoEmObjects.at(i))/16);
339  unsigned rank = rctLookupTables_->emRank(energy);
340  L1CaloEmCand isoCand(rank, rgn, crd, crate, 1, i, 0); // includes emcand index
341  isoEmCands.push_back(isoCand);
342  }
343  return isoEmCands;
344 }
345 
346 
347 // Returns the top four nonisolated electrons from the given crate
348 // in a vector of L1CaloEmCands
350  std::vector<unsigned short> nonIsoEmObjects = crates.at(crate).getNonisolatedEGObjects();
351  L1CaloEmCollection nonIsoEmCands;
352  for (uint16_t i = 0; i < 4; i++){
353  unsigned rgn = ((nonIsoEmObjects.at(i)) & 1);
354  unsigned crd = (((nonIsoEmObjects.at(i))/2) & 7);
355  unsigned energy = ((nonIsoEmObjects.at(i))/16);
356  unsigned rank = rctLookupTables_->emRank(energy);
357  L1CaloEmCand nonIsoCand(rank, rgn, crd, crate, 0, i, 0); // includes emcand index
358  nonIsoEmCands.push_back(nonIsoCand);
359  }
360  return nonIsoEmCands;
361 }
362 
363 vector<L1CaloRegion> L1RCT::getRegions(unsigned crate){
364  // barrel regions
365  std::bitset<14> taus( (long) crates.at(crate).getTauBits());
366  std::bitset<14> mips( (long) crates.at(crate).getMIPBits());
367  std::bitset<14> quiets( (long) crates.at(crate).getQuietBits());
368  std::bitset<14> overflows( (long) crates.at(crate).getOverFlowBits());
369  std::vector<unsigned short> barrelEnergies = crates.at(crate).getBarrelRegions();
370  std::vector<L1CaloRegion> regionCollection;
371  for (unsigned card = 0; card < 7; card++){
372  for (unsigned rgn = 0; rgn < 2; rgn++){
373  bool tau = taus[card*2+rgn];
374  bool mip = mips[card*2+rgn];
375  bool quiet = quiets[card*2+rgn];
376  bool overflow = overflows[card*2+rgn];
377  unsigned barrelEnergy = barrelEnergies.at(card*2+rgn);
378  L1CaloRegion region(barrelEnergy, overflow, tau, mip, quiet, crate, card, rgn);
379  regionCollection.push_back(region);
380  }
381  }
382 
383  // hf regions
384  std::vector<unsigned short> hfEnergies = crates.at(crate).getHFRegions();
385  // fine grain bits -- still have to work out digi input
386  std::vector<unsigned short> hfFineGrainBits = crates.at(crate).getHFFineGrainBits();
387  for (unsigned hfRgn = 0; hfRgn<8; hfRgn++){ // region number, see diagram on paper. make sure know how hf regions come in.
388  unsigned energy = hfEnergies.at(hfRgn);
389  bool fineGrain = hfFineGrainBits.at(hfRgn);
390  L1CaloRegion hfRegion(energy, fineGrain, crate, hfRgn);
391  regionCollection.push_back(hfRegion);
392  }
393  return regionCollection;
394 }
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
void setNorthEt(std::vector< unsigned short > north)
Definition: L1RCTRegion.cc:103
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)
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:363
std::vector< unsigned short > giveEastHE_FG() const
Definition: L1RCTRegion.cc:173
void setNWHE_FG(unsigned short nw)
Definition: L1RCTRegion.cc:214
#define abs(x)
Definition: mlp_lapack.h:159
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:349
void setSEEt(unsigned short se)
Definition: L1RCTRegion.cc:245
unsigned short giveNEHE_FG() const
Definition: L1RCTRegion.cc:191
void setEastHE_FG(std::vector< unsigned short > east)
Definition: L1RCTRegion.cc:179
void randomInput()
Definition: L1RCT.cc:217
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:332
void setWestHE_FG(std::vector< unsigned short > west)
Definition: L1RCTRegion.cc:157
void setSouthHE_FG(std::vector< unsigned short > south)
Definition: L1RCTRegion.cc:135
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:323
int k[5][pyjets_maxn]
void setSouthEt(std::vector< unsigned short > south)
Definition: L1RCTRegion.cc:124
unsigned short calcCard(unsigned short rct_iphi, unsigned short absIeta) const
std::vector< int > nw(int crate, int card, int region)
void input()
Definition: L1RCT.cc:66
void setNorthHE_FG(std::vector< unsigned short > north)
Definition: L1RCTRegion.cc:113
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
const L1RCTParameters * rctParameters() const
void processEvent()
Definition: L1RCT.cc:36
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 setEastEt(std::vector< unsigned short > east)
Definition: L1RCTRegion.cc:168
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 shareNeighbors()
Definition: L1RCT.cc:240
unsigned short giveSWHE_FG() const
Definition: L1RCTRegion.cc:225
void setWestEt(std::vector< unsigned short > west)
Definition: L1RCTRegion.cc:146
std::vector< int > se(int crate, int card, int region)
Definition: DDAxes.h:10
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