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  // Rotate by 20 deg to match RPC convention in CMSSW
181  int _sector_rpc = (_subsector < 5) ? _sector : (_sector % 6) + 1;
182  // Rotate by 2 to match RPC convention in CMSSW (RPCDetId.h)
183  int _subsector_rpc = ((_subsector + 1) % 6) + 1;
184  // Define chamber number
185  int _chamber = (_sector_rpc - 1) * 6 + _subsector_rpc;
186  // Define CSC-like subsector
187  int _subsector_csc = (_station != 1) ? 0 : ((_chamber % 6 > 2) ? 1 : 2);
188 
189  Hit_.set_station(_station);
190  Hit_.set_ring(_ring);
191  Hit_.set_sector(_sector);
192  Hit_.set_subsector(_subsector_csc);
193  Hit_.set_sector_RPC(_sector_rpc);
194  Hit_.set_subsector_RPC(_subsector_rpc);
195  Hit_.set_chamber(_chamber);
196  Hit_.set_neighbor(_neighbor);
197  Hit_.set_pc_segment(_segment);
198  Hit_.set_fs_segment(_segment);
199  Hit_.set_bt_segment(_segment);
200 
201  // Fill the EMTFHit
202  ImportRPC(Hit_, RPC_, (res->at(iOut)).PtrEventHeader()->Endcap(), (res->at(iOut)).PtrEventHeader()->Sector());
203 
204  // Set the stub number for this hit
205  // Each chamber can send up to 2 stubs per BX
206  // Also count stubs in corresponding CSC chamber; RPC hit counting is on top of LCT counting
207  Hit_.set_stub_num(0);
208  // See if matching hit is already in event record
209  bool exact_duplicate = false;
210  for (auto const& iHit : *res_hit) {
211  if (Hit_.BX() == iHit.BX() && Hit_.Endcap() == iHit.Endcap() && Hit_.Station() == iHit.Station() &&
212  Hit_.Chamber() == iHit.Chamber()) {
213  if ((iHit.Is_CSC() == 1 && iHit.Ring() == 2) ||
214  (iHit.Is_RPC() == 1)) { // RPC rings 2 and 3 both map to CSC ring 2
215  if (Hit_.Neighbor() == iHit.Neighbor()) {
216  Hit_.set_stub_num(Hit_.Stub_num() + 1);
217  if (iHit.Is_RPC() == 1 && iHit.Ring() == Hit_.Ring() && iHit.Theta_fp() == Hit_.Theta_fp() &&
218  iHit.Phi_fp() == Hit_.Phi_fp()) {
219  exact_duplicate = true;
220  }
221  }
222  }
223  }
224  } // End loop: for (auto const & iHit : *res_hit)
225 
226  if (exact_duplicate)
227  edm::LogWarning("L1T|EMTF") << "EMTF unpacked duplicate CPPF digis: BX " << Hit_.BX() << ", endcap "
228  << Hit_.Endcap() << ", station " << Hit_.Station() << ", sector " << Hit_.Sector()
229  << ", neighbor " << Hit_.Neighbor() << ", ring " << Hit_.Ring() << ", chamber "
230  << Hit_.Chamber() << ", theta " << Hit_.Theta_fp() / 4 << ", phi "
231  << Hit_.Phi_fp() / 4 << std::endl;
232 
233  (res->at(iOut)).push_RPC(RPC_);
234  if (!exact_duplicate)
235  res_hit->push_back(Hit_);
236  if (!exact_duplicate)
237  res_CPPF->push_back(Hit_.CreateCPPFDigi());
238 
239  // Finished with unpacking one RPC Data Record
240  return true;
241 
242  } // End bool RPCBlockUnpacker::unpack
243 
244  // bool RPCBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
245  // std::cout << "Inside RPCBlockPacker::pack" << std::endl;
246  // return true;
247  // } // End bool RPCBlockPacker::pack
248 
249  } // End namespace emtf
250  } // End namespace stage2
251 } // End namespace l1t
252 
254 // DEFINE_L1T_PACKER(l1t::stage2::RPCBlockPacker);
l1t::EMTFDaqOutCollection
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:179
l1t::emtf::RPC::set_bc0
void set_bc0(int bits)
Definition: RPC.h:36
mps_fire.i
i
Definition: mps_fire.py:428
l1t::stage2::emtf::ImportRPC
void ImportRPC(EMTFHit &_hit, const l1t::emtf::RPC _RPC, const int _endcap, const int _evt_sector)
Definition: EMTFUnpackerTools.cc:37
l1t::emtf::RPC::add_format_error
void add_format_error()
Definition: RPC.h:39
MainPageGenerator.link
link
Definition: MainPageGenerator.py:271
relativeConstraints.station
station
Definition: relativeConstraints.py:67
l1t::emtf::RPC
Definition: RPC.h:11
l1t::stage2::emtf::RPCBlockUnpacker::unpack
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: EMTFBlockRPC.cc:116
l1t::EMTFHit::Sector
int Sector() const
Definition: EMTFHit.h:194
l1t::EMTFHit::Endcap
int Endcap() const
Definition: EMTFHit.h:191
EMTFCollections.h
l1t::EMTFHit::set_pc_segment
void set_pc_segment(int bits)
Definition: EMTFHit.h:146
l1t::EMTFHit::set_fs_segment
void set_fs_segment(int bits)
Definition: EMTFHit.h:173
l1t::emtf::RPC::set_phi
void set_phi(int bits)
Definition: RPC.h:30
l1t::CPPFDigiCollection
std::vector< CPPFDigi > CPPFDigiCollection
Definition: CPPFDigi.h:83
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
l1t::EMTFHit::BX
int BX() const
Definition: EMTFHit.h:244
l1t::emtf::RPC::set_link
void set_link(int bits)
Definition: RPC.h:34
l1t::EMTFHit::set_chamber
void set_chamber(int bits)
Definition: EMTFHit.h:137
l1t::emtf::RPC::set_frame
void set_frame(int bits)
Definition: RPC.h:33
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
l1t::stage2::emtf::RPCBlockUnpacker
Definition: EMTFBlockRPC.cc:13
l1t::EMTFHit::set_subsector
void set_subsector(int bits)
Definition: EMTFHit.h:135
errors
Definition: errors.py:1
l1t::EMTFHit::Neighbor
int Neighbor() const
Definition: EMTFHit.h:203
emtf
Definition: Event.h:15
l1t::EMTFHit::Theta_fp
int Theta_fp() const
Definition: EMTFHit.h:247
UnpackerFactory.h
jets_cff.payload
payload
Definition: jets_cff.py:32
l1t::EMTFHit::set_station
void set_station(int bits)
Definition: EMTFHit.h:130
l1t::Unpacker
Definition: Unpacker.h:11
l1t::emtf::RPC::set_vp
void set_vp(int bits)
Definition: RPC.h:38
l1t::EMTFHit::CreateCPPFDigi
CPPFDigi CreateCPPFDigi() const
Definition: EMTFHit.cc:50
l1t::EMTFHit::set_sector_RPC
void set_sector_RPC(int bits)
Definition: EMTFHit.h:133
l1t::EMTFHit
Definition: EMTFHit.h:25
l1t
delete x;
Definition: CaloConfig.h:22
l1t::emtf::RPC::set_tbin
void set_tbin(int bits)
Definition: RPC.h:37
l1t::stage2::emtf::RPCBlockUnpacker::checkFormat
virtual int checkFormat(const Block &block)
Definition: EMTFBlockRPC.cc:35
groupFilesInBlocks.block
block
Definition: groupFilesInBlocks.py:150
l1t::EMTFHit::set_stub_num
void set_stub_num(int bits)
Definition: EMTFHit.h:168
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
res
Definition: Electron.h:6
SiStripSourceConfigTier0_cff.stage2
stage2
Definition: SiStripSourceConfigTier0_cff.py:71
l1t::EMTFHit::set_neighbor
void set_neighbor(int bits)
Definition: EMTFHit.h:141
l1t::emtf::RPC::Frame
int Frame() const
Definition: RPC.h:45
l1t::emtf::RPC::set_rpc_bxn
void set_rpc_bxn(int bits)
Definition: RPC.h:35
l1t::emtf::RPC::Word
int Word() const
Definition: RPC.h:44
l1t::EMTFHit::set_sector
void set_sector(int bits)
Definition: EMTFHit.h:132
l1t::emtf::RPC::set_word
void set_word(int bits)
Definition: RPC.h:32
l1t::EMTFHit::Ring
int Ring() const
Definition: EMTFHit.h:193
EMTFUnpackerTools.h
amptDefault_cfi.frame
frame
Definition: amptDefault_cfi.py:12
l1t::UnpackerCollections
Definition: UnpackerCollections.h:9
l1t::emtf::RPC::set_theta
void set_theta(int bits)
Definition: RPC.h:31
relativeConstraints.ring
ring
Definition: relativeConstraints.py:68
l1t::EMTFHit::Station
int Station() const
Definition: EMTFHit.h:192
DEFINE_L1T_UNPACKER
#define DEFINE_L1T_UNPACKER(type)
Definition: UnpackerFactory.h:23
l1t::stage2::emtf::convert_RPC_location
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
l1t::EMTFHit::Stub_num
int Stub_num() const
Definition: EMTFHit.h:245
l1t::Block
Definition: Block.h:70
l1t::emtf::RPC::Link
int Link() const
Definition: RPC.h:46
l1t::EMTFHit::Chamber
int Chamber() const
Definition: EMTFHit.h:199
l1t::EMTFHit::set_bt_segment
void set_bt_segment(int bits)
Definition: EMTFHit.h:176
l1t::stage2::emtf::GetHexBits
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
Definition: EMTFUnpackerTools.h:45
l1t::EMTFHitCollection
std::vector< EMTFHit > EMTFHitCollection
Definition: EMTFHit.h:342
l1t::EMTFHit::Phi_fp
int Phi_fp() const
Definition: EMTFHit.h:246
l1t::EMTFHit::set_subsector_RPC
void set_subsector_RPC(int bits)
Definition: EMTFHit.h:136
l1t::EMTFHit::set_ring
void set_ring(int bits)
Definition: EMTFHit.h:131
debug_messages_cfi.errors
errors
Definition: debug_messages_cfi.py:54