CMS 3D CMS Logo

EMTFBlockRPC.cc
Go to the documentation of this file.
1 // Code to unpack the "RPC Data Record"
2 
4 
5 #include "EMTFCollections.h"
6 #include "EMTFUnpackerTools.h"
7 
8 // This is the "header" - no EMTFBlockRPC.h file is needed
9 namespace l1t {
10  namespace stage2 {
11  namespace emtf {
12 
13  class RPCBlockUnpacker : public Unpacker { // "RPCBlockUnpacker" inherits from "Unpacker"
14  public:
15  virtual int checkFormat(const Block& block);
16  // virtual bool checkFormat() override; // Return "false" if block format does not match expected format
17  bool unpack(const Block& block, 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 RPCBlockPacker : public Packer { // "RPCBlockPacker" 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  }
27  }
28 }
29 
30 namespace l1t {
31  namespace stage2 {
32  namespace emtf {
33 
35 
36  auto payload = block.payload();
37  int errors = 0;
38 
39  // Check the number of 16-bit words
40  if (payload.size() != 4) { errors += 1;
41  edm::LogError("L1T|EMTF") << "Payload size in 'RPC Data Record' is different than expected"; }
42 
43  // Check that each word is 16 bits
44  for (unsigned int i = 0; i < 4; i++) {
45  if (GetHexBits(payload[i], 16, 31) != 0) { errors += 1;
46  edm::LogError("L1T|EMTF") << "Payload[" << i << "] has more than 16 bits in 'RPC Data Record'"; }
47  }
48 
49  uint16_t RPCa = payload[0];
50  uint16_t RPCb = payload[1];
51  uint16_t RPCc = payload[2];
52  uint16_t RPCd = payload[3];
53 
54  // Check Format
55  if (GetHexBits(RPCa, 11, 15) != 0) { errors += 1;
56  edm::LogError("L1T|EMTF") << "Format identifier bits in RPCa are incorrect"; }
57  if (GetHexBits(RPCb, 5, 7) != 0) { errors += 1;
58  edm::LogError("L1T|EMTF") << "Format identifier bits in RPCb are incorrect"; }
59  if (GetHexBits(RPCb, 15, 15) != 0) { errors += 1;
60  edm::LogError("L1T|EMTF") << "Format identifier bits in RPCb are incorrect"; }
61  if (GetHexBits(RPCc, 12, 13) != 0) { errors += 1;
62  edm::LogError("L1T|EMTF") << "Format identifier bits in RPCc are incorrect"; }
63  if (GetHexBits(RPCc, 15, 15) != 1) { errors += 1;
64  edm::LogError("L1T|EMTF") << "Format identifier bits in RPCc are incorrect"; }
65  if (GetHexBits(RPCd, 4, 15) != 0) { errors += 1;
66  edm::LogError("L1T|EMTF") << "Format identifier bits in RPCd are incorrect"; }
67 
68  return errors;
69 
70  }
71 
72  // Converts station, ring, sector, subsector, neighbor, and segment from the RPC output
73  void convert_RPC_location(int& station, int& ring, int& sector, int& subsector, int& neighbor, int& segment,
74  const int evt_sector, const int frame, const int word, const int link) {
75  station = -99;
76  ring = -99;
77  sector = -99;
78  subsector = -99;
79  neighbor = -99;
80  segment = -99;
81 
82  // "link" is the "link index" field (0 - 6) in the EMTF DAQ document, not "link number" (1 - 7)
83  // Neighbor indicated by link == 0
84  sector = (link != 0 ? evt_sector : (evt_sector == 1 ? 6 : evt_sector - 1) );
85  subsector = (link != 0 ? link : 6);
86  neighbor = (link == 0 ? 1 : 0);
87  segment = (word % 2);
88 
89  if (frame == 0) {
90  station = (word < 2 ? 1 : 2);
91  ring = 2;
92  } else if (frame == 1) {
93  station = 3;
94  ring = (word < 2 ? 2 : 3);
95  } else if (frame == 2) {
96  station = 4;
97  ring = (word < 2 ? 2 : 3);
98  }
99  } // End function: void convert_RPC_location()
100 
102 
103  // std::cout << "Inside EMTFBlockRPC.cc: unpack" << std::endl;
104 
105  // Get the payload for this block, made up of 16-bit words (0xffff)
106  // Format defined in MTF7Payload::getBlock() in src/Block.cc
107  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
108  auto payload = block.payload();
109 
110  // Check Format of Payload
111  l1t::emtf::RPC RPC_;
112  for (int err = 0; err < checkFormat(block); err++) RPC_.add_format_error();
113 
114  // Assign payload to 16-bit words
115  uint16_t RPCa = payload[0];
116  uint16_t RPCb = payload[1];
117  uint16_t RPCc = payload[2];
118  uint16_t RPCd = payload[3];
119 
120  // res is a pointer to a collection of EMTFDaqOut class objects
121  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
123  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
124  int iOut = res->size() - 1;
125 
126  EMTFHitCollection* res_hit;
127  res_hit = static_cast<EMTFCollections*>(coll)->getEMTFHits();
128  EMTFHit Hit_;
129 
130  // Also unpack into RPC digis? - AWB 15.03.17
131 
133  // Unpack the RPC Data Record
135 
136  RPC_.set_phi ( GetHexBits(RPCa, 0, 10) );
137 
138  RPC_.set_theta ( GetHexBits(RPCb, 0, 4) );
139  RPC_.set_word ( GetHexBits(RPCb, 8, 9) );
140  RPC_.set_frame ( GetHexBits(RPCb, 10, 11) );
141  RPC_.set_link ( GetHexBits(RPCb, 12, 14) ); // Link index (0 - 6); link number runs 1 - 7
142 
143  RPC_.set_rpc_bxn ( GetHexBits(RPCc, 0, 11) );
144  RPC_.set_bc0 ( GetHexBits(RPCc, 14, 14) );
145 
146  RPC_.set_tbin ( GetHexBits(RPCd, 0, 2) );
147  RPC_.set_vp ( GetHexBits(RPCd, 3, 3) );
148 
149  // RPC_.set_dataword ( uint64_t dataword);
150 
151 
152  // Convert specially-encoded RPC quantities
153  int _station, _ring, _sector, _subsector, _neighbor, _segment;
154  convert_RPC_location( _station, _ring, _sector, _subsector, _neighbor, _segment,
155  (res->at(iOut)).PtrEventHeader()->Sector(), RPC_.Frame(), RPC_.Word(), RPC_.Link() );
156 
157  Hit_.set_station ( _station );
158  Hit_.set_ring ( _ring );
159  Hit_.set_sector ( _sector );
160  Hit_.set_subsector ( _subsector );
161  Hit_.set_sector_RPC ( _subsector < 5 ? _sector : (_sector % 6) + 1); // Rotate by 20 deg to match RPC convention in CMSSW
162  Hit_.set_subsector_RPC ( ((_subsector + 1) % 6) + 1 ); // Rotate by 2 to match RPC convention in CMSSW (RPCDetId.h)
163  Hit_.set_chamber ( (Hit_.Sector_RPC() - 1)*6 + Hit_.Subsector_RPC() );
164  Hit_.set_neighbor ( _neighbor );
165  Hit_.set_pc_segment ( _segment );
166  Hit_.set_fs_segment ( _segment );
167  Hit_.set_bt_segment ( _segment );
168 
169  // Fill the EMTFHit
170  ImportRPC( Hit_, RPC_, (res->at(iOut)).PtrEventHeader()->Endcap(), (res->at(iOut)).PtrEventHeader()->Sector() );
171 
172  // Set the stub number for this hit
173  // Each chamber can send up to 2 stubs per BX
174  // Also count stubs in corresponding CSC chamber; RPC hit counting is on top of LCT counting
175  Hit_.set_stub_num(0);
176  // // See if matching hit is already in event record (from neighboring sector)
177  // bool duplicate_hit_exists = false;
178  for (auto const & iHit : *res_hit) {
179 
180  if ( Hit_.BX() == iHit.BX() &&
181  Hit_.Endcap() == iHit.Endcap() &&
182  Hit_.Station() == iHit.Station() &&
183  Hit_.Chamber() == iHit.Chamber() ) {
184 
185  if ( (iHit.Is_CSC() == 1 && iHit.Ring() == 2) ||
186  (iHit.Is_RPC() == 1) ) { // RPC rings 2 and 3 both map to CSC ring 2
187 
188  if ( Hit_.Neighbor() == iHit.Neighbor() ) {
189  Hit_.set_stub_num( Hit_.Stub_num() + 1);
190  } // else if ( iHit.Is_RPC() == 1 &&
191  // iHit.Ring() == Hit_.Ring() &&
192  // iHit.Theta_fp() == Hit_.Theta_fp() &&
193  // iHit.Phi_fp() == Hit_.Phi_fp() ) {
194  // duplicate_hit_exists = true;
195  // }
196  }
197  }
198  } // End loop: for (auto const & iHit : *res_hit)
199 
200  (res->at(iOut)).push_RPC(RPC_);
201  res_hit->push_back(Hit_);
202 
203  // Finished with unpacking one RPC Data Record
204  return true;
205 
206  } // End bool RPCBlockUnpacker::unpack
207 
208  // bool RPCBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
209  // std::cout << "Inside RPCBlockPacker::pack" << std::endl;
210  // return true;
211  // } // End bool RPCBlockPacker::pack
212 
213  } // End namespace emtf
214  } // End namespace stage2
215 } // End namespace l1t
216 
218 // DEFINE_L1T_PACKER(l1t::stage2::RPCBlockPacker);
void set_subsector_RPC(int bits)
Definition: EMTFHit.h:76
void set_neighbor(int bits)
Definition: EMTFHit.h:81
void set_stub_num(int bits)
Definition: EMTFHit.h:99
void set_station(int bits)
Definition: EMTFHit.h:70
void convert_RPC_location(int &station, int &ring, int &sector, int &subsector, int &neighbor, int &segment, const int evt_sector, const int frame, const int word, const int link)
Definition: EMTFBlockRPC.cc:73
void add_format_error()
Definition: RPC.h:31
Definition: Event.h:15
delete x;
Definition: CaloConfig.h:22
bool unpack(const Block &block, UnpackerCollections *coll) override
std::vector< uint32_t > payload() const
Definition: Block.h:60
void set_word(int bits)
Definition: RPC.h:24
Definition: Electron.h:4
void set_ring(int bits)
Definition: EMTFHit.h:71
int Chamber() const
Definition: EMTFHit.h:130
void ImportRPC(EMTFHit &_hit, const l1t::emtf::RPC _RPC, const int _endcap, const int _evt_sector)
void set_frame(int bits)
Definition: RPC.h:25
payload
payload postfix for testing
void set_theta(int bits)
Definition: RPC.h:23
void set_bt_segment(int bits)
Definition: EMTFHit.h:109
void set_tbin(int bits)
Definition: RPC.h:29
int BX() const
Definition: EMTFHit.h:151
int Subsector_RPC() const
Definition: EMTFHit.h:129
int Word() const
Definition: RPC.h:36
std::vector< EMTFHit > EMTFHitCollection
Definition: EMTFHit.h:241
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:130
void set_bc0(int bits)
Definition: RPC.h:28
int Sector_RPC() const
Definition: EMTFHit.h:126
void set_pc_segment(int bits)
Definition: EMTFHit.h:86
int Frame() const
Definition: RPC.h:37
void set_fs_segment(int bits)
Definition: EMTFHit.h:106
void set_sector_RPC(int bits)
Definition: EMTFHit.h:73
void set_sector(int bits)
Definition: EMTFHit.h:72
JetCorrectorParametersCollection coll
Definition: classes.h:10
int Station() const
Definition: EMTFHit.h:123
void set_phi(int bits)
Definition: RPC.h:22
void set_link(int bits)
Definition: RPC.h:26
#define DEFINE_L1T_UNPACKER(type)
void set_rpc_bxn(int bits)
Definition: RPC.h:27
int Endcap() const
Definition: EMTFHit.h:122
Definition: errors.py:1
int Stub_num() const
Definition: EMTFHit.h:152
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
void set_vp(int bits)
Definition: RPC.h:30
int Link() const
Definition: RPC.h:38
void set_chamber(int bits)
Definition: EMTFHit.h:77
int Neighbor() const
Definition: EMTFHit.h:134
virtual int checkFormat(const Block &block)
Definition: EMTFBlockRPC.cc:34
void set_subsector(int bits)
Definition: EMTFHit.h:75