CMS 3D CMS Logo

List of all members | Public Member Functions
l1t::stage2::emtf::RPCBlockUnpacker Class Reference
Inheritance diagram for l1t::stage2::emtf::RPCBlockUnpacker:
l1t::Unpacker

Public Member Functions

virtual int checkFormat (const Block &block)
 
bool unpack (const Block &block, UnpackerCollections *coll) override
 
- Public Member Functions inherited from l1t::Unpacker
unsigned int getAlgoVersion ()
 
void setAlgoVersion (const unsigned int version)
 
 Unpacker ()
 
virtual ~Unpacker ()=default
 

Detailed Description

Definition at line 13 of file EMTFBlockRPC.cc.

Member Function Documentation

int l1t::stage2::emtf::RPCBlockUnpacker::checkFormat ( const Block block)
virtual

Definition at line 34 of file EMTFBlockRPC.cc.

References benchmark_cfg::errors, l1t::stage2::emtf::GetHexBits(), mps_fire::i, jets_cff::payload, and l1t::Block::payload().

Referenced by unpack().

34  {
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, 15, 15) != 0) { errors += 1;
56  edm::LogError("L1T|EMTF") << "Format identifier bits in RPCa are incorrect"; }
57  if (GetHexBits(RPCb, 15, 15) != 0) { errors += 1;
58  edm::LogError("L1T|EMTF") << "Format identifier bits in RPCb are incorrect"; }
59  if (GetHexBits(RPCc, 15, 15) != 1) { errors += 1;
60  edm::LogError("L1T|EMTF") << "Format identifier bits in RPCc are incorrect"; }
61  if (GetHexBits(RPCd, 15, 15) != 0) { errors += 1;
62  edm::LogError("L1T|EMTF") << "Format identifier bits in RPCd are incorrect"; }
63 
64  return errors;
65 
66  }
Definition: errors.py:1
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
bool l1t::stage2::emtf::RPCBlockUnpacker::unpack ( const Block block,
UnpackerCollections coll 
)
overridevirtual

Implements l1t::Unpacker.

Definition at line 97 of file EMTFBlockRPC.cc.

References l1t::emtf::RPC::add_format_error(), l1t::EMTFHit::BX(), l1t::EMTFHit::Chamber(), checkFormat(), coll, l1t::stage2::emtf::convert_RPC_location(), l1t::EMTFHit::CreateCPPFDigi(), DEFINE_L1T_UNPACKER, l1t::EMTFHit::Endcap(), l1t::emtf::RPC::Frame(), l1t::stage2::emtf::GetHexBits(), l1t::stage2::emtf::ImportRPC(), l1t::emtf::RPC::Link(), l1t::EMTFHit::Neighbor(), jets_cff::payload, l1t::Block::payload(), l1t::EMTFHit::Phi_fp(), l1t::EMTFHit::Ring(), l1t::EMTFHit::Sector(), l1t::EMTFHit::Sector_RPC(), l1t::emtf::RPC::set_bc0(), l1t::EMTFHit::set_bt_segment(), l1t::EMTFHit::set_chamber(), l1t::emtf::RPC::set_frame(), l1t::EMTFHit::set_fs_segment(), l1t::emtf::RPC::set_link(), l1t::EMTFHit::set_neighbor(), l1t::EMTFHit::set_pc_segment(), l1t::emtf::RPC::set_phi(), l1t::EMTFHit::set_ring(), l1t::emtf::RPC::set_rpc_bxn(), l1t::EMTFHit::set_sector(), l1t::EMTFHit::set_sector_RPC(), l1t::EMTFHit::set_station(), l1t::EMTFHit::set_stub_num(), l1t::EMTFHit::set_subsector(), l1t::EMTFHit::set_subsector_RPC(), l1t::emtf::RPC::set_tbin(), l1t::emtf::RPC::set_theta(), l1t::emtf::RPC::set_vp(), l1t::emtf::RPC::set_word(), l1t::EMTFHit::Station(), l1t::EMTFHit::Stub_num(), l1t::EMTFHit::Subsector_RPC(), l1t::EMTFHit::Theta_fp(), and l1t::emtf::RPC::Word().

97  {
98 
99  // std::cout << "Inside EMTFBlockRPC.cc: unpack" << std::endl;
100 
101  // Get the payload for this block, made up of 16-bit words (0xffff)
102  // Format defined in MTF7Payload::getBlock() in src/Block.cc
103  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
104  auto payload = block.payload();
105 
106  // Check Format of Payload
107  l1t::emtf::RPC RPC_;
108  for (int err = 0; err < checkFormat(block); err++) RPC_.add_format_error();
109 
110  // Assign payload to 16-bit words
111  uint16_t RPCa = payload[0];
112  uint16_t RPCb = payload[1];
113  uint16_t RPCc = payload[2];
114  uint16_t RPCd = payload[3];
115 
116  // res is a pointer to a collection of EMTFDaqOut class objects
117  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
119  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
120  int iOut = res->size() - 1;
121 
122  EMTFHitCollection* res_hit;
123  res_hit = static_cast<EMTFCollections*>(coll)->getEMTFHits();
124  EMTFHit Hit_;
125 
126  CPPFDigiCollection* res_CPPF;
127  res_CPPF = static_cast<EMTFCollections*>(coll)->getEMTFCPPFs();
128 
130  // Unpack the RPC Data Record
132 
133  RPC_.set_phi ( GetHexBits(RPCa, 0, 10) );
134 
135  RPC_.set_theta ( GetHexBits(RPCb, 0, 4) );
136  RPC_.set_word ( GetHexBits(RPCb, 8, 9) );
137  RPC_.set_frame ( GetHexBits(RPCb, 10, 11) );
138  RPC_.set_link ( GetHexBits(RPCb, 12, 14) ); // Link index (0 - 6); link number runs 1 - 7
139 
140  RPC_.set_rpc_bxn ( GetHexBits(RPCc, 0, 11) );
141  RPC_.set_bc0 ( GetHexBits(RPCc, 14, 14) );
142 
143  RPC_.set_tbin ( GetHexBits(RPCd, 0, 2) );
144  RPC_.set_vp ( GetHexBits(RPCd, 3, 3) );
145 
146  // RPC_.set_dataword ( uint64_t dataword);
147 
148 
149  // Convert specially-encoded RPC quantities
150  int _station, _ring, _sector, _subsector, _neighbor, _segment;
151  convert_RPC_location( _station, _ring, _sector, _subsector, _neighbor, _segment,
152  (res->at(iOut)).PtrEventHeader()->Sector(), RPC_.Frame(), RPC_.Word(), RPC_.Link() );
153 
154  Hit_.set_station ( _station );
155  Hit_.set_ring ( _ring );
156  Hit_.set_sector ( _sector );
157  Hit_.set_subsector ( _subsector );
158  Hit_.set_sector_RPC ( _subsector < 5 ? _sector : (_sector % 6) + 1); // Rotate by 20 deg to match RPC convention in CMSSW
159  Hit_.set_subsector_RPC ( ((_subsector + 1) % 6) + 1 ); // Rotate by 2 to match RPC convention in CMSSW (RPCDetId.h)
160  Hit_.set_chamber ( (Hit_.Sector_RPC() - 1)*6 + Hit_.Subsector_RPC() );
161  Hit_.set_neighbor ( _neighbor );
162  Hit_.set_pc_segment ( _segment );
163  Hit_.set_fs_segment ( _segment );
164  Hit_.set_bt_segment ( _segment );
165 
166  // Fill the EMTFHit
167  ImportRPC( Hit_, RPC_, (res->at(iOut)).PtrEventHeader()->Endcap(), (res->at(iOut)).PtrEventHeader()->Sector() );
168 
169  // Set the stub number for this hit
170  // Each chamber can send up to 2 stubs per BX
171  // Also count stubs in corresponding CSC chamber; RPC hit counting is on top of LCT counting
172  Hit_.set_stub_num(0);
173  // See if matching hit is already in event record
174  bool exact_duplicate = false;
175  for (auto const & iHit : *res_hit) {
176 
177  if ( Hit_.BX() == iHit.BX() &&
178  Hit_.Endcap() == iHit.Endcap() &&
179  Hit_.Station() == iHit.Station() &&
180  Hit_.Chamber() == iHit.Chamber() ) {
181 
182  if ( (iHit.Is_CSC() == 1 && iHit.Ring() == 2) ||
183  (iHit.Is_RPC() == 1) ) { // RPC rings 2 and 3 both map to CSC ring 2
184  if ( Hit_.Neighbor() == iHit.Neighbor() ) {
185  Hit_.set_stub_num( Hit_.Stub_num() + 1);
186  if ( iHit.Is_RPC() == 1 &&
187  iHit.Ring() == Hit_.Ring() &&
188  iHit.Theta_fp() == Hit_.Theta_fp() &&
189  iHit.Phi_fp() == Hit_.Phi_fp() ) {
190  exact_duplicate = true;
191  }
192  }
193  }
194  }
195  } // End loop: for (auto const & iHit : *res_hit)
196 
197  if (exact_duplicate) edm::LogWarning("L1T|EMTF") << "EMTF unpacked duplicate CPPF digis: BX " << Hit_.BX()
198  << ", endcap " << Hit_.Endcap() << ", station " << Hit_.Station()
199  << ", sector " << Hit_.Sector() << ", neighbor " << Hit_.Neighbor()
200  << ", ring " << Hit_.Ring() << ", chamber " << Hit_.Chamber()
201  << ", theta " << Hit_.Theta_fp() / 4 << ", phi " << Hit_.Phi_fp() / 4 << std::endl;
202 
203 
204  (res->at(iOut)).push_RPC(RPC_);
205  if (!exact_duplicate)
206  res_hit->push_back(Hit_);
207  if (!exact_duplicate)
208  res_CPPF->push_back( Hit_.CreateCPPFDigi() );
209 
210  // Finished with unpacking one RPC Data Record
211  return true;
212 
213  } // End bool RPCBlockUnpacker::unpack
void set_subsector_RPC(int bits)
Definition: EMTFHit.h:93
void set_neighbor(int bits)
Definition: EMTFHit.h:98
void set_stub_num(int bits)
Definition: EMTFHit.h:116
int Phi_fp() const
Definition: EMTFHit.h:175
void set_station(int bits)
Definition: EMTFHit.h:87
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:69
void add_format_error()
Definition: RPC.h:33
void set_word(int bits)
Definition: RPC.h:26
Definition: Electron.h:6
void set_ring(int bits)
Definition: EMTFHit.h:88
int Chamber() const
Definition: EMTFHit.h:152
void ImportRPC(EMTFHit &_hit, const l1t::emtf::RPC _RPC, const int _endcap, const int _evt_sector)
void set_frame(int bits)
Definition: RPC.h:27
int Sector() const
Definition: EMTFHit.h:147
void set_theta(int bits)
Definition: RPC.h:25
void set_bt_segment(int bits)
Definition: EMTFHit.h:126
void set_tbin(int bits)
Definition: RPC.h:31
int BX() const
Definition: EMTFHit.h:173
CPPFDigi CreateCPPFDigi() const
Definition: EMTFHit.cc:32
int Subsector_RPC() const
Definition: EMTFHit.h:151
int Word() const
Definition: RPC.h:38
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:130
void set_bc0(int bits)
Definition: RPC.h:30
l1t::EMTFHitCollection EMTFHitCollection
Definition: Common.h:25
int Ring() const
Definition: EMTFHit.h:146
int Sector_RPC() const
Definition: EMTFHit.h:148
void set_pc_segment(int bits)
Definition: EMTFHit.h:103
int Frame() const
Definition: RPC.h:39
void set_fs_segment(int bits)
Definition: EMTFHit.h:123
void set_sector_RPC(int bits)
Definition: EMTFHit.h:90
void set_sector(int bits)
Definition: EMTFHit.h:89
JetCorrectorParametersCollection coll
Definition: classes.h:10
int Station() const
Definition: EMTFHit.h:145
void set_phi(int bits)
Definition: RPC.h:24
void set_link(int bits)
Definition: RPC.h:28
void set_rpc_bxn(int bits)
Definition: RPC.h:29
int Endcap() const
Definition: EMTFHit.h:144
int Stub_num() const
Definition: EMTFHit.h:174
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
int Theta_fp() const
Definition: EMTFHit.h:176
void set_vp(int bits)
Definition: RPC.h:32
int Link() const
Definition: RPC.h:40
void set_chamber(int bits)
Definition: EMTFHit.h:94
int Neighbor() const
Definition: EMTFHit.h:156
virtual int checkFormat(const Block &block)
Definition: EMTFBlockRPC.cc:34
void set_subsector(int bits)
Definition: EMTFHit.h:92
std::vector< CPPFDigi > CPPFDigiCollection
Definition: CPPFDigi.h:68