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