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, 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  }
67 
68  // Converts station, ring, sector, subsector, neighbor, and segment from the RPC output
69  void convert_RPC_location(int& station, int& ring, int& sector, int& subsector, int& neighbor, int& segment,
70  const int evt_sector, const int frame, const int word, const int link) {
71  station = -99;
72  ring = -99;
73  sector = -99;
74  subsector = -99;
75  neighbor = -99;
76  segment = -99;
77 
78  // "link" is the "link index" field (0 - 6) in the EMTF DAQ document, not "link number" (1 - 7)
79  // Neighbor indicated by link == 0
80  sector = (link != 0 ? evt_sector : (evt_sector == 1 ? 6 : evt_sector - 1) );
81  subsector = (link != 0 ? link : 6);
82  neighbor = (link == 0 ? 1 : 0);
83  segment = (word % 2);
84 
85  if (frame == 0) {
86  station = (word < 2 ? 1 : 2);
87  ring = 2;
88  } else if (frame == 1) {
89  station = 3;
90  ring = (word < 2 ? 2 : 3);
91  } else if (frame == 2) {
92  station = 4;
93  ring = (word < 2 ? 2 : 3);
94  }
95  } // End function: void convert_RPC_location()
96 
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
214 
215  // bool RPCBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
216  // std::cout << "Inside RPCBlockPacker::pack" << std::endl;
217  // return true;
218  // } // End bool RPCBlockPacker::pack
219 
220  } // End namespace emtf
221  } // End namespace stage2
222 } // End namespace l1t
223 
225 // DEFINE_L1T_PACKER(l1t::stage2::RPCBlockPacker);
void set_subsector_RPC(int bits)
Definition: EMTFHit.h:93
void set_neighbor(int bits)
Definition: EMTFHit.h:98
const std::vector< uint32_t > & payload() const
Definition: Block.h:60
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
Definition: Event.h:15
delete x;
Definition: CaloConfig.h:22
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: EMTFBlockRPC.cc:97
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< EMTFHit > EMTFHitCollection
Definition: EMTFHit.h:276
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:130
void set_bc0(int bits)
Definition: RPC.h:30
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
#define DEFINE_L1T_UNPACKER(type)
void set_rpc_bxn(int bits)
Definition: RPC.h:29
int Endcap() const
Definition: EMTFHit.h:144
Definition: errors.py:1
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