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