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