CMS 3D CMS Logo

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