CMS 3D CMS Logo

EMTFBlockME.cc
Go to the documentation of this file.
1 // Code to unpack the "ME Data Record"
2 
4 
5 #include "EMTFCollections.h"
6 #include "EMTFUnpackerTools.h"
7 
8 // This is the "header" - no EMTFBlockME.h file is needed
9 namespace l1t {
10  namespace stage2 {
11  namespace emtf {
12 
13  class MEBlockUnpacker : public Unpacker { // "MEBlockUnpacker" inherits from "Unpacker"
14  public:
15  virtual int checkFormat(const Block& block);
16  bool unpack(const Block& block,
17  UnpackerCollections* coll) override; // Apparently it's always good to use override in C++
18  // virtual bool packBlock(const Block& block, UnpackerCollections *coll) override;
19  };
20 
21  // class MEBlockPacker : public Packer { // "MEBlockPacker" inherits from "Packer"
22  // public:
23  // virtual bool unpack(const Block& block, UnpackerCollections *coll) override; // Apparently it's always good to use override in C++
24  // };
25 
26  } // namespace emtf
27  } // namespace stage2
28 } // namespace l1t
29 
30 namespace l1t {
31  namespace stage2 {
32  namespace emtf {
33 
35  auto payload = block.payload();
36  int errors = 0;
37 
38  // Check the number of 16-bit words
39  if (payload.size() != 4) {
40  errors += 1;
41  edm::LogError("L1T|EMTF") << "Payload size in 'ME Data Record' is different than expected";
42  }
43 
44  // Check that each word is 16 bits
45  for (unsigned int i = 0; i < 4; i++) {
46  if (GetHexBits(payload[i], 16, 31) != 0) {
47  errors += 1;
48  edm::LogError("L1T|EMTF") << "Payload[" << i << "] has more than 16 bits in 'ME Data Record'";
49  }
50  }
51 
52  uint16_t MEa = payload[0];
53  uint16_t MEb = payload[1];
54  uint16_t MEc = payload[2];
55  uint16_t MEd = payload[3];
56 
57  //Check Format
58  if (GetHexBits(MEa, 15, 15) != 1) {
59  errors += 1;
60  edm::LogError("L1T|EMTF") << "Format identifier bits in MEa are incorrect";
61  }
62  if (GetHexBits(MEb, 15, 15) != 1) {
63  errors += 1;
64  edm::LogError("L1T|EMTF") << "Format identifier bits in MEb are incorrect";
65  }
66  if (GetHexBits(MEc, 15, 15) != 0) {
67  errors += 1;
68  edm::LogError("L1T|EMTF") << "Format identifier bits in MEc are incorrect";
69  }
70  if (GetHexBits(MEd, 15, 15) != 0) {
71  errors += 1;
72  edm::LogError("L1T|EMTF") << "Format identifier bits in MEd are incorrect";
73  }
74 
75  return errors;
76  }
77 
78  // Converts station, CSC_ID, sector, subsector, and neighbor from the ME output
79  std::vector<int> convert_ME_location(int _station, int _csc_ID, int _sector, bool _csc_ID_shift = false) {
80  int new_sector = _sector;
81  int new_csc_ID = _csc_ID;
82  if (_csc_ID_shift)
83  new_csc_ID += 1; // Before FW update on 05.05.16, shift by +1 from 0,1,2... convention to 1,2,3...
84  if (_station == 0) {
85  int arr[] = {1, new_csc_ID, new_sector, 1, 0};
86  std::vector<int> vec(arr, arr + 5);
87  return vec;
88  } else if (_station == 1) {
89  int arr[] = {1, new_csc_ID, new_sector, 2, 0};
90  std::vector<int> vec(arr, arr + 5);
91  return vec;
92  } else if (_station <= 4) {
93  int arr[] = {_station, new_csc_ID, new_sector, -1, 0};
94  std::vector<int> vec(arr, arr + 5);
95  return vec;
96  } else if (_station == 5)
97  new_sector = (_sector != 1) ? _sector - 1 : 6; // Indicates neighbor chamber, don't return yet
98  else {
99  int arr[] = {_station, _csc_ID, _sector, -99, -99};
100  std::vector<int> vec(arr, arr + 5);
101  return vec;
102  }
103 
104  // Mapping for chambers from neighboring sector
105  if (new_csc_ID == 1) {
106  int arr[] = {1, 3, new_sector, 2, 1};
107  std::vector<int> vec(arr, arr + 5);
108  return vec;
109  } else if (new_csc_ID == 2) {
110  int arr[] = {1, 6, new_sector, 2, 1};
111  std::vector<int> vec(arr, arr + 5);
112  return vec;
113  } else if (new_csc_ID == 3) {
114  int arr[] = {1, 9, new_sector, 2, 1};
115  std::vector<int> vec(arr, arr + 5);
116  return vec;
117  } else if (new_csc_ID == 4) {
118  int arr[] = {2, 3, new_sector, -1, 1};
119  std::vector<int> vec(arr, arr + 5);
120  return vec;
121  } else if (new_csc_ID == 5) {
122  int arr[] = {2, 9, new_sector, -1, 1};
123  std::vector<int> vec(arr, arr + 5);
124  return vec;
125  } else if (new_csc_ID == 6) {
126  int arr[] = {3, 3, new_sector, -1, 1};
127  std::vector<int> vec(arr, arr + 5);
128  return vec;
129  } else if (new_csc_ID == 7) {
130  int arr[] = {3, 9, new_sector, -1, 1};
131  std::vector<int> vec(arr, arr + 5);
132  return vec;
133  } else if (new_csc_ID == 8) {
134  int arr[] = {4, 3, new_sector, -1, 1};
135  std::vector<int> vec(arr, arr + 5);
136  return vec;
137  } else if (new_csc_ID == 9) {
138  int arr[] = {4, 9, new_sector, -1, 1};
139  std::vector<int> vec(arr, arr + 5);
140  return vec;
141  } else {
142  int arr[] = {_station, _csc_ID, _sector, -99, -99};
143  std::vector<int> vec(arr, arr + 5);
144  return vec;
145  }
146  }
147 
149  // std::cout << "Inside EMTFBlockME.cc: unpack" << std::endl;
150 
151  // Get the payload for this block, made up of 16-bit words (0xffff)
152  // Format defined in MTF7Payload::getBlock() in src/Block.cc
153  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
154  auto payload = block.payload();
155 
156  // Assign payload to 16-bit words
157  uint16_t MEa = payload[0];
158  uint16_t MEb = payload[1];
159  uint16_t MEc = payload[2];
160  uint16_t MEd = payload[3];
161 
162  // Check Format of Payload
163  l1t::emtf::ME ME_;
164  for (int err = 0; err < checkFormat(block); err++)
165  ME_.add_format_error();
166 
167  // res is a pointer to a collection of EMTFDaqOut class objects
168  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
170  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
171  int iOut = res->size() - 1;
172 
173  EMTFHitCollection* res_hit;
174  res_hit = static_cast<EMTFCollections*>(coll)->getEMTFHits();
175  EMTFHit Hit_;
176 
178  res_LCT = static_cast<EMTFCollections*>(coll)->getEMTFLCTs();
179 
181  // Unpack the ME Data Record
183 
184  ME_.set_clct_pattern(GetHexBits(MEa, 0, 3));
185  ME_.set_quality(GetHexBits(MEa, 4, 7));
186  ME_.set_wire(GetHexBits(MEa, 8, 14));
187 
188  ME_.set_strip(GetHexBits(MEb, 0, 7));
189  ME_.set_csc_ID(GetHexBits(MEb, 8, 11));
190  ME_.set_lr(GetHexBits(MEb, 12, 12));
191  ME_.set_bxe(GetHexBits(MEb, 13, 13));
192  ME_.set_bc0(GetHexBits(MEb, 14, 14));
193 
194  ME_.set_me_bxn(GetHexBits(MEc, 0, 11));
195  ME_.set_nit(GetHexBits(MEc, 12, 12));
196  ME_.set_cik(GetHexBits(MEc, 13, 13));
197  ME_.set_afff(GetHexBits(MEc, 14, 14));
198 
199  ME_.set_tbin(GetHexBits(MEd, 0, 2));
200  ME_.set_vp(GetHexBits(MEd, 3, 3));
201  ME_.set_station(GetHexBits(MEd, 4, 6));
202  ME_.set_af(GetHexBits(MEd, 7, 7));
203  ME_.set_epc(GetHexBits(MEd, 8, 11));
204  ME_.set_sm(GetHexBits(MEd, 12, 12));
205  ME_.set_se(GetHexBits(MEd, 13, 13));
206  ME_.set_afef(GetHexBits(MEd, 14, 14));
207 
208  // ME_.set_dataword ( uint64_t dataword);
209 
210  // Convert specially-encoded ME quantities
211  bool csc_ID_shift = (getAlgoVersion() <=
212  8348); // For FW versions <= 28.04.2016, shift by +1 from 0,1,2... convention to 1,2,3...
213  // Computed as (Year - 2000)*2^9 + Month*2^5 + Day (see Block.cc and EMTFBlockTrailers.cc)
214  std::vector<int> conv_vals =
215  convert_ME_location(ME_.Station(), ME_.CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), csc_ID_shift);
216 
217  Hit_.set_station(conv_vals.at(0));
218  Hit_.set_csc_ID(conv_vals.at(1));
219  Hit_.set_sector(conv_vals.at(2));
220  Hit_.set_subsector(conv_vals.at(3));
221  Hit_.set_neighbor(conv_vals.at(4));
222 
223  if (Hit_.Station() < 1 || Hit_.Station() > 4)
224  edm::LogWarning("L1T|EMTF") << "EMTF unpacked LCT station = " << Hit_.Station()
225  << ", outside proper [1, 4] range" << std::endl;
226  if (Hit_.CSC_ID() < 1 || Hit_.CSC_ID() > 9)
227  edm::LogWarning("L1T|EMTF") << "EMTF unpacked LCT CSC ID = " << Hit_.CSC_ID()
228  << ", outside proper [1, 9] range" << std::endl;
229  if (Hit_.Sector() < 1 || Hit_.Sector() > 6)
230  edm::LogWarning("L1T|EMTF") << "EMTF unpacked LCT sector = " << Hit_.Sector()
231  << ", outside proper [1, 6] range" << std::endl;
232 
233  // Fill the EMTFHit
234  ImportME(Hit_, ME_, (res->at(iOut)).PtrEventHeader()->Endcap(), (res->at(iOut)).PtrEventHeader()->Sector());
235 
236  // Set the stub number for this hit
237  // Each chamber can send up to 2 stubs per BX
238  ME_.set_stub_num(0);
239  Hit_.set_stub_num(0);
240  // See if matching hit is already in event record: exact duplicate, or from neighboring sector
241  bool exact_duplicate = false;
242  bool neighbor_duplicate = false;
243  for (auto const& iHit : *res_hit) {
244  if (iHit.Is_CSC() == 1 && Hit_.BX() == iHit.BX() && Hit_.Endcap() == iHit.Endcap() &&
245  Hit_.Station() == iHit.Station() && Hit_.Chamber() == iHit.Chamber() &&
246  (Hit_.Ring() % 3) == (iHit.Ring() % 3)) { // ME1/1a and ME1/1b (rings "4" and 1) are the same chamber
247 
248  if (Hit_.Ring() == iHit.Ring() && Hit_.Strip() == iHit.Strip() && Hit_.Wire() == iHit.Wire()) {
249  exact_duplicate = (Hit_.Neighbor() == iHit.Neighbor());
250  neighbor_duplicate = (Hit_.Neighbor() != iHit.Neighbor());
251  } else if (Hit_.Neighbor() == iHit.Neighbor()) {
252  ME_.set_stub_num(ME_.Stub_num() + 1);
253  Hit_.set_stub_num(Hit_.Stub_num() + 1);
254  }
255  }
256  } // End loop: for (auto const & iHit : *res_hit)
257 
258  if (exact_duplicate)
259  edm::LogWarning("L1T|EMTF") << "EMTF unpacked duplicate LCTs: BX " << Hit_.BX() << ", endcap "
260  << Hit_.Endcap() << ", station " << Hit_.Station() << ", sector " << Hit_.Sector()
261  << ", neighbor " << Hit_.Neighbor() << ", ring " << Hit_.Ring() << ", chamber "
262  << Hit_.Chamber() << ", strip " << Hit_.Strip() << ", wire " << Hit_.Wire()
263  << std::endl;
264 
265  (res->at(iOut)).push_ME(ME_);
266  if (!exact_duplicate)
267  res_hit->push_back(Hit_);
268  if (!exact_duplicate && !neighbor_duplicate) // Don't write duplicate LCTs from adjacent sectors
269  res_LCT->insertDigi(Hit_.CSC_DetId(), Hit_.CreateCSCCorrelatedLCTDigi());
270 
271  // Finished with unpacking one ME Data Record
272  return true;
273 
274  } // End bool MEBlockUnpacker::unpack
275 
276  // bool MEBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
277  // std::cout << "Inside MEBlockPacker::pack" << std::endl;
278  // return true;
279  // } // End bool MEBlockPacker::pack
280 
281  } // End namespace emtf
282  } // End namespace stage2
283 } // End namespace l1t
284 
286 // DEFINE_L1T_PACKER(l1t::stage2::MEBlockPacker);
l1t::emtf::ME::set_bc0
void set_bc0(int bits)
Definition: ME.h:45
l1t::EMTFDaqOutCollection
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:164
mps_fire.i
i
Definition: mps_fire.py:355
l1t::EMTFHit::CSC_DetId
CSCDetId CSC_DetId() const
Definition: EMTFHit.h:117
l1t::emtf::ME::set_vp
void set_vp(int bits)
Definition: ME.h:60
l1t::emtf::ME::Station
int Station() const
Definition: ME.h:83
l1t::EMTFHit::CSC_ID
int CSC_ID() const
Definition: EMTFHit.h:186
l1t::emtf::ME::CSC_ID
int CSC_ID() const
Definition: ME.h:72
l1t::emtf::ME::set_epc
void set_epc(int bits)
Definition: ME.h:57
l1t::emtf::ME
Definition: ME.h:11
l1t::emtf::ME::set_wire
void set_wire(int bits)
Definition: ME.h:42
l1t::emtf::ME::set_af
void set_af(int bits)
Definition: ME.h:58
MessageLogger_cfi.errors
errors
Definition: MessageLogger_cfi.py:18
l1t::EMTFHit::Sector
int Sector() const
Definition: EMTFHit.h:180
l1t::EMTFHit::Endcap
int Endcap() const
Definition: EMTFHit.h:177
EMTFCollections.h
l1t::EMTFHit::BX
int BX() const
Definition: EMTFHit.h:206
l1t::emtf::ME::set_stub_num
void set_stub_num(int bits)
Definition: ME.h:62
l1t::emtf::ME::set_quality
void set_quality(int bits)
Definition: ME.h:43
l1t::EMTFHit::set_subsector
void set_subsector(int bits)
Definition: EMTFHit.h:130
l1t::emtf::ME::set_tbin
void set_tbin(int bits)
Definition: ME.h:61
l1t::stage2::emtf::MEBlockUnpacker::unpack
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: EMTFBlockME.cc:148
errors
Definition: errors.py:1
l1t::EMTFHit::Neighbor
int Neighbor() const
Definition: EMTFHit.h:189
emtf
Definition: Event.h:15
l1t::stage2::emtf::convert_ME_location
std::vector< int > convert_ME_location(int _station, int _csc_ID, int _sector, bool _csc_ID_shift=false)
Definition: EMTFBlockME.cc:79
l1t::stage2::emtf::MEBlockUnpacker
Definition: EMTFBlockME.cc:13
l1t::emtf::ME::set_se
void set_se(int bits)
Definition: ME.h:55
UnpackerFactory.h
jets_cff.payload
payload
Definition: jets_cff.py:34
l1t::EMTFHit::set_station
void set_station(int bits)
Definition: EMTFHit.h:125
l1t::EMTFHit::set_csc_ID
void set_csc_ID(int bits)
Definition: EMTFHit.h:133
l1t::Unpacker
Definition: Unpacker.h:11
l1t::emtf::ME::set_csc_ID
void set_csc_ID(int bits)
Definition: ME.h:48
edm::LogWarning
Definition: MessageLogger.h:141
l1t::emtf::ME::add_format_error
void add_format_error()
Definition: ME.h:63
l1t::EMTFHit::Wire
int Wire() const
Definition: EMTFHit.h:195
edm::LogError
Definition: MessageLogger.h:183
l1t::stage2::emtf::MEBlockUnpacker::checkFormat
virtual int checkFormat(const Block &block)
Definition: EMTFBlockME.cc:34
l1t::EMTFHit
Definition: EMTFHit.h:22
runTheMatrix.err
err
Definition: runTheMatrix.py:288
l1t
delete x;
Definition: CaloConfig.h:22
l1t::emtf::ME::set_afef
void set_afef(int bits)
Definition: ME.h:54
l1t::emtf::ME::set_afff
void set_afff(int bits)
Definition: ME.h:50
l1t::emtf::ME::set_nit
void set_nit(int bits)
Definition: ME.h:52
groupFilesInBlocks.block
block
Definition: groupFilesInBlocks.py:150
l1t::EMTFHit::set_stub_num
void set_stub_num(int bits)
Definition: EMTFHit.h:154
CSCCorrelatedLCTDigiCollection
l1t::emtf::ME::set_station
void set_station(int bits)
Definition: ME.h:59
res
Definition: Electron.h:6
SiStripSourceConfigTier0_cff.stage2
stage2
Definition: SiStripSourceConfigTier0_cff.py:71
l1t::EMTFHit::set_neighbor
void set_neighbor(int bits)
Definition: EMTFHit.h:136
l1t::EMTFHit::set_sector
void set_sector(int bits)
Definition: EMTFHit.h:127
l1t::emtf::ME::set_strip
void set_strip(int bits)
Definition: ME.h:49
l1t::EMTFHit::Ring
int Ring() const
Definition: EMTFHit.h:179
EMTFUnpackerTools.h
l1t::emtf::ME::set_lr
void set_lr(int bits)
Definition: ME.h:47
l1t::UnpackerCollections
Definition: UnpackerCollections.h:9
l1t::EMTFHit::CreateCSCCorrelatedLCTDigi
CSCCorrelatedLCTDigi CreateCSCCorrelatedLCTDigi() const
Definition: EMTFHit.cc:69
l1t::emtf::ME::set_me_bxn
void set_me_bxn(int bits)
Definition: ME.h:53
l1t::EMTFHit::Station
int Station() const
Definition: EMTFHit.h:178
l1t::emtf::ME::set_sm
void set_sm(int bits)
Definition: ME.h:56
l1t::stage2::emtf::ImportME
void ImportME(EMTFHit &_hit, const l1t::emtf::ME _ME, const int _endcap, const int _evt_sector)
Definition: EMTFUnpackerTools.cc:8
DEFINE_L1T_UNPACKER
#define DEFINE_L1T_UNPACKER(type)
Definition: UnpackerFactory.h:23
l1t::emtf::ME::set_bxe
void set_bxe(int bits)
Definition: ME.h:46
l1t::EMTFHit::Stub_num
int Stub_num() const
Definition: EMTFHit.h:207
l1t::Block
Definition: Block.h:54
l1t::EMTFHit::Chamber
int Chamber() const
Definition: EMTFHit.h:185
l1t::emtf::ME::set_cik
void set_cik(int bits)
Definition: ME.h:51
l1t::stage2::emtf::GetHexBits
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
Definition: EMTFUnpackerTools.h:44
l1t::Unpacker::getAlgoVersion
unsigned int getAlgoVersion()
Definition: Unpacker.h:18
l1t::emtf::ME::Stub_num
int Stub_num() const
Definition: ME.h:86
l1t::emtf::ME::set_clct_pattern
void set_clct_pattern(int bits)
Definition: ME.h:44
l1t::EMTFHitCollection
std::vector< EMTFHit > EMTFHitCollection
Definition: EMTFHit.h:302
l1t::EMTFHit::Strip
int Strip() const
Definition: EMTFHit.h:196