CMS 3D CMS Logo

EMTFBlockME.cc
Go to the documentation of this file.
2 
3 #include "EMTFCollections.h"
4 #include "EMTFUnpackerTools.h"
5 #include "EMTFBlockME.h"
6 
7 namespace l1t {
8  namespace stage2 {
9  namespace emtf {
10 
12 
13  auto payload = block.payload();
14  int errors = 0;
15 
16  //Check the number of 16-bit words
17  if(payload.size() != 4) { errors += 1; edm::LogError("L1T|EMTF") << "Payload size in 'ME Data Record' is different than expected"; }
18 
19  //Check that each word is 16 bits
20  if(GetHexBits(payload[0], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[0] has more than 16 bits in 'ME Data Record'"; }
21  if(GetHexBits(payload[1], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'ME Data Record'"; }
22  if(GetHexBits(payload[2], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'ME Data Record'"; }
23  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'ME Data Record'"; }
24 
25  uint16_t MEa = payload[0];
26  uint16_t MEb = payload[1];
27  uint16_t MEc = payload[2];
28  uint16_t MEd = payload[3];
29 
30  //Check Format
31  if(GetHexBits(MEa, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in MEa are incorrect"; }
32  if(GetHexBits(MEb, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in MEb are incorrect"; }
33  if(GetHexBits(MEc, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in MEc are incorrect"; }
34  if(GetHexBits(MEd, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in MEd are incorrect"; }
35 
36  return errors;
37 
38  }
39 
40  // Converts station, CSC_ID, sector, subsector, and neighbor from the ME output
41  std::vector<int> convert_ME_location(int _station, int _csc_ID, int _sector) {
42  int new_sector = _sector;
43  int new_csc_ID = _csc_ID; // Before FW update on 05.05.16, shift by +1 from 0,1,2... convention to 1,2,3...
44  if (_station == 0) { int arr[] = { 1, new_csc_ID, new_sector, 1, 0}; std::vector<int> vec(arr, arr+5); return vec; }
45  else if (_station == 1) { int arr[] = { 1, new_csc_ID, new_sector, 2, 0}; std::vector<int> vec(arr, arr+5); return vec; }
46  else if (_station <= 4) { int arr[] = {_station, new_csc_ID, new_sector, -1, 0}; std::vector<int> vec(arr, arr+5); return vec; }
47  else if (_station == 5) new_sector = (_sector != 1) ? _sector-1 : 6;
48  else { int arr[] = {_station, _csc_ID, _sector, -99, -99}; std::vector<int> vec(arr, arr+5); return vec; }
49 
50  if (new_csc_ID == 1) { int arr[] = {1, 3, new_sector, 2, 1}; std::vector<int> vec(arr, arr+5); return vec; }
51  else if (new_csc_ID == 2) { int arr[] = {1, 6, new_sector, 2, 1}; std::vector<int> vec(arr, arr+5); return vec; }
52  else if (new_csc_ID == 3) { int arr[] = {1, 9, new_sector, 2, 1}; std::vector<int> vec(arr, arr+5); return vec; }
53  else if (new_csc_ID == 4) { int arr[] = {2, 3, new_sector, -1, 1}; std::vector<int> vec(arr, arr+5); return vec; }
54  else if (new_csc_ID == 5) { int arr[] = {2, 9, new_sector, -1, 1}; std::vector<int> vec(arr, arr+5); return vec; }
55  else if (new_csc_ID == 6) { int arr[] = {3, 3, new_sector, -1, 1}; std::vector<int> vec(arr, arr+5); return vec; }
56  else if (new_csc_ID == 7) { int arr[] = {3, 9, new_sector, -1, 1}; std::vector<int> vec(arr, arr+5); return vec; }
57  else if (new_csc_ID == 8) { int arr[] = {4, 3, new_sector, -1, 1}; std::vector<int> vec(arr, arr+5); return vec; }
58  else if (new_csc_ID == 9) { int arr[] = {4, 9, new_sector, -1, 1}; std::vector<int> vec(arr, arr+5); return vec; }
59  else { int arr[] = {_station, _csc_ID, _sector, -99, -99}; std::vector<int> vec(arr, arr+5); return vec; }
60  }
61 
62 
64 
65  // std::cout << "Inside EMTFBlockME.cc: unpack" << std::endl;
66 
67  // Get the payload for this block, made up of 16-bit words (0xffff)
68  // Format defined in MTF7Payload::getBlock() in src/Block.cc
69  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
70  auto payload = block.payload();
71 
72  // Assign payload to 16-bit words
73  uint16_t MEa = payload[0];
74  uint16_t MEb = payload[1];
75  uint16_t MEc = payload[2];
76  uint16_t MEd = payload[3];
77 
78  // Check Format of Payload
79  l1t::emtf::ME ME_;
80  for (int err = 0; err < checkFormat(block); err++) ME_.add_format_error();
81 
82  // res is a pointer to a collection of EMTFDaqOut class objects
83  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
85  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
86  int iOut = res->size() - 1;
87 
88  EMTFHitCollection* res_hit;
89  res_hit = static_cast<EMTFCollections*>(coll)->getEMTFHits();
90  EMTFHit Hit_;
91 
93  res_LCT = static_cast<EMTFCollections*>(coll)->getEMTFLCTs();
94 
95  // if (ME_.Format_Errors() > 0) goto write; // Temporarily disable for DQM operation - AWB 09.04.16
96 
98  // Unpack the ME Data Record
100 
101  ME_.set_clct_pattern ( GetHexBits(MEa, 0, 3) );
102  ME_.set_quality ( GetHexBits(MEa, 4, 7) );
103  ME_.set_wire ( GetHexBits(MEa, 8, 14) );
104 
105  ME_.set_strip ( GetHexBits(MEb, 0, 7) );
106  ME_.set_csc_ID ( GetHexBits(MEb, 8, 11) );
107  ME_.set_lr ( GetHexBits(MEb, 12, 12) );
108  ME_.set_bxe ( GetHexBits(MEb, 13, 13) );
109  ME_.set_bc0 ( GetHexBits(MEb, 14, 14) );
110 
111  ME_.set_me_bxn ( GetHexBits(MEc, 0, 11) );
112  ME_.set_nit ( GetHexBits(MEc, 12, 12) );
113  ME_.set_cik ( GetHexBits(MEc, 13, 13) );
114  ME_.set_afff ( GetHexBits(MEc, 14, 14) );
115 
116  ME_.set_tbin ( GetHexBits(MEd, 0, 2) );
117  ME_.set_vp ( GetHexBits(MEd, 3, 3) );
118  ME_.set_station ( GetHexBits(MEd, 4, 6) );
119  ME_.set_af ( GetHexBits(MEd, 7, 7) );
120  ME_.set_epc ( GetHexBits(MEd, 8, 11) );
121  ME_.set_sm ( GetHexBits(MEd, 12, 12) );
122  ME_.set_se ( GetHexBits(MEd, 13, 13) );
123  ME_.set_afef ( GetHexBits(MEd, 14, 14) );
124 
125  // ME_.set_dataword ( uint64_t dataword);
126 
127 
128  // Fill the EMTFHit
129  Hit_.ImportME( ME_ );
130  Hit_.set_endcap ( ((res->at(iOut)).PtrEventHeader()->Endcap() == 1) ? 1 : -1 );
131  // Hit_.set_layer();
132 
133  std::vector<int> conv_vals = convert_ME_location( ME_.Station(), ME_.CSC_ID(),
134  (res->at(iOut)).PtrEventHeader()->Sector() );
135  Hit_.set_station ( conv_vals.at(0) );
136  Hit_.set_csc_ID ( conv_vals.at(1) );
137  Hit_.set_sector ( conv_vals.at(2) );
138  Hit_.set_subsector ( conv_vals.at(3) );
139  Hit_.set_neighbor ( conv_vals.at(4) );
140 
141  Hit_.set_sector_index ( (Hit_.Endcap() == 1)
142  ? (res->at(iOut)).PtrEventHeader()->Sector() - 1
143  : (res->at(iOut)).PtrEventHeader()->Sector() + 5 );
144 
145  Hit_.set_ring ( calc_ring( Hit_.Station(), Hit_.CSC_ID(), Hit_.Strip() ) );
146  Hit_.set_chamber ( calc_chamber( Hit_.Station(), Hit_.Sector(),
147  Hit_.Subsector(), Hit_.Ring(), Hit_.CSC_ID() ) );
148 
149  Hit_.SetCSCDetId ( Hit_.CreateCSCDetId() );
151 
152  // Set the stub number for this hit
153  // Each chamber can send up to 2 stubs per BX
154  ME_.set_stub_num(0);
155  Hit_.set_stub_num(0);
156  // See if matching hit is already in event record (from neighboring sector)
157  bool duplicate_hit_exists = false;
158  for (uint iHit = 0; iHit < res_hit->size(); iHit++) {
159 
160  if ( Hit_.BX() == res_hit->at(iHit).BX() && Hit_.Station() == res_hit->at(iHit).Station() &&
161  ( Hit_.Ring() == res_hit->at(iHit).Ring() || abs(Hit_.Ring() - res_hit->at(iHit).Ring()) == 3 ) &&
162  Hit_.Chamber() == res_hit->at(iHit).Chamber() ) {
163 
164  if ( Hit_.Neighbor() == res_hit->at(iHit).Neighbor() ) {
165  ME_.set_stub_num( ME_.Stub_num() + 1 );
166  Hit_.set_stub_num( Hit_.Stub_num() + 1); }
167  else if ( Hit_.Ring() == res_hit->at(iHit).Ring() && Hit_.Strip() == res_hit->at(iHit).Strip() &&
168  Hit_.Wire() == res_hit->at(iHit).Wire() )
169  duplicate_hit_exists = true;
170  }
171  }
172  // write: // Temporarily disable for DQM operation - AWB 09.04.16
173 
174  (res->at(iOut)).push_ME(ME_);
175  res_hit->push_back(Hit_);
176  if (not duplicate_hit_exists) // Don't write duplicate LCTs from adjacent sectors
177  res_LCT->insertDigi( Hit_.CSC_DetId(), Hit_.CSC_LCTDigi() );
178 
179  // Finished with unpacking one ME Data Record
180  return true;
181 
182  } // End bool MEBlockUnpacker::unpack
183 
184  // bool MEBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
185  // std::cout << "Inside MEBlockPacker::pack" << std::endl;
186  // return true;
187  // } // End bool MEBlockPacker::pack
188 
189  } // End namespace emtf
190  } // End namespace stage2
191 } // End namespace l1t
192 
194 // DEFINE_L1T_PACKER(l1t::stage2::MEBlockPacker);
void set_bxe(int bits)
Definition: ME.h:28
void set_neighbor(int bits)
Definition: EMTFHit.h:73
void set_af(int bits)
Definition: ME.h:40
void SetCSCLCTDigi(CSCCorrelatedLCTDigi digi)
Definition: EMTFHit.h:51
void set_bc0(int bits)
Definition: ME.h:27
int Strip() const
Definition: EMTFHit.h:104
void set_sector_index(int bits)
Definition: EMTFHit.h:67
void set_stub_num(int bits)
Definition: EMTFHit.h:87
void set_station(int bits)
Definition: EMTFHit.h:64
void ImportME(const emtf::ME _ME)
int calc_chamber(int _station, int _sector, int _subsector, int _ring, int _csc_ID)
void set_vp(int bits)
Definition: ME.h:42
Definition: Event.h:15
CSCCorrelatedLCTDigi CSC_LCTDigi() const
Definition: EMTFHit.h:56
delete x;
Definition: CaloConfig.h:22
int CSC_ID() const
Definition: ME.h:54
void set_epc(int bits)
Definition: ME.h:39
std::vector< uint32_t > payload() const
Definition: Block.h:61
void set_wire(int bits)
Definition: ME.h:24
void set_endcap(int bits)
Definition: EMTFHit.h:63
Definition: Electron.h:4
void set_ring(int bits)
Definition: EMTFHit.h:65
int Chamber() const
Definition: EMTFHit.h:97
int Wire() const
Definition: EMTFHit.h:103
int Subsector() const
Definition: EMTFHit.h:96
void add_format_error()
Definition: ME.h:45
int Sector() const
Definition: EMTFHit.h:94
void set_tbin(int bits)
Definition: ME.h:43
virtual int checkFormat(const Block &block)
Definition: EMTFBlockME.cc:11
payload
payload postfix for testing
virtual bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: EMTFBlockME.cc:63
void set_se(int bits)
Definition: ME.h:37
CSCCorrelatedLCTDigi CreateCSCCorrelatedLCTDigi()
Definition: EMTFHitTools.cc:98
void set_stub_num(int bits)
Definition: ME.h:44
int BX() const
Definition: EMTFHit.h:114
void set_csc_ID(int bits)
Definition: EMTFHit.h:70
void set_quality(int bits)
Definition: ME.h:25
std::vector< EMTFHit > EMTFHitCollection
Definition: EMTFHit.h:158
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:130
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void set_csc_ID(int bits)
Definition: ME.h:30
void set_afef(int bits)
Definition: ME.h:36
CSCDetId CSC_DetId() const
Definition: EMTFHit.h:54
int Ring() const
Definition: EMTFHit.h:93
std::vector< int > convert_ME_location(int _station, int _csc_ID, int _sector)
Definition: EMTFBlockME.cc:41
void set_afff(int bits)
Definition: ME.h:32
void set_nit(int bits)
Definition: ME.h:34
void set_strip(int bits)
Definition: ME.h:31
void set_lr(int bits)
Definition: ME.h:29
int Stub_num() const
Definition: ME.h:68
void set_sector(int bits)
Definition: EMTFHit.h:66
JetCorrectorParametersCollection coll
Definition: classes.h:10
int Station() const
Definition: EMTFHit.h:92
void SetCSCDetId(CSCDetId id)
Definition: EMTFHit.h:49
CSCDetId CreateCSCDetId()
Definition: EMTFHitTools.cc:39
int calc_ring(int _station, int _csc_ID, int _strip)
void set_cik(int bits)
Definition: ME.h:33
int Station() const
Definition: ME.h:65
void set_station(int bits)
Definition: ME.h:41
#define DEFINE_L1T_UNPACKER(type)
int Endcap() const
Definition: EMTFHit.h:91
Definition: errors.py:1
int Stub_num() const
Definition: EMTFHit.h:115
void set_me_bxn(int bits)
Definition: ME.h:35
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
void set_sm(int bits)
Definition: ME.h:38
void set_clct_pattern(int bits)
Definition: ME.h:26
void set_chamber(int bits)
Definition: EMTFHit.h:69
int Neighbor() const
Definition: EMTFHit.h:101
void set_subsector(int bits)
Definition: EMTFHit.h:68
int CSC_ID() const
Definition: EMTFHit.h:98