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  // Also unpack into RPC digis? - AWB 15.03.17
127 
129  // Unpack the RPC Data Record
131 
132  RPC_.set_phi ( GetHexBits(RPCa, 0, 10) );
133 
134  RPC_.set_theta ( GetHexBits(RPCb, 0, 4) );
135  RPC_.set_word ( GetHexBits(RPCb, 8, 9) );
136  RPC_.set_frame ( GetHexBits(RPCb, 10, 11) );
137  RPC_.set_link ( GetHexBits(RPCb, 12, 14) ); // Link index (0 - 6); link number runs 1 - 7
138 
139  RPC_.set_rpc_bxn ( GetHexBits(RPCc, 0, 11) );
140  RPC_.set_bc0 ( GetHexBits(RPCc, 14, 14) );
141 
142  RPC_.set_tbin ( GetHexBits(RPCd, 0, 2) );
143  RPC_.set_vp ( GetHexBits(RPCd, 3, 3) );
144 
145  // RPC_.set_dataword ( uint64_t dataword);
146 
147 
148  // Convert specially-encoded RPC quantities
149  int _station, _ring, _sector, _subsector, _neighbor, _segment;
150  convert_RPC_location( _station, _ring, _sector, _subsector, _neighbor, _segment,
151  (res->at(iOut)).PtrEventHeader()->Sector(), RPC_.Frame(), RPC_.Word(), RPC_.Link() );
152 
153  Hit_.set_station ( _station );
154  Hit_.set_ring ( _ring );
155  Hit_.set_sector ( _sector );
156  Hit_.set_subsector ( _subsector );
157  Hit_.set_sector_RPC ( _subsector < 5 ? _sector : (_sector % 6) + 1); // Rotate by 20 deg to match RPC convention in CMSSW
158  Hit_.set_subsector_RPC ( ((_subsector + 1) % 6) + 1 ); // Rotate by 2 to match RPC convention in CMSSW (RPCDetId.h)
159  Hit_.set_chamber ( (Hit_.Sector_RPC() - 1)*6 + Hit_.Subsector_RPC() );
160  Hit_.set_neighbor ( _neighbor );
161  Hit_.set_pc_segment ( _segment );
162  Hit_.set_fs_segment ( _segment );
163  Hit_.set_bt_segment ( _segment );
164 
165  // Fill the EMTFHit
166  ImportRPC( Hit_, RPC_, (res->at(iOut)).PtrEventHeader()->Endcap(), (res->at(iOut)).PtrEventHeader()->Sector() );
167 
168  // Set the stub number for this hit
169  // Each chamber can send up to 2 stubs per BX
170  // Also count stubs in corresponding CSC chamber; RPC hit counting is on top of LCT counting
171  Hit_.set_stub_num(0);
172  // // See if matching hit is already in event record (from neighboring sector)
173  // bool duplicate_hit_exists = false;
174  for (auto const & iHit : *res_hit) {
175 
176  if ( Hit_.BX() == iHit.BX() &&
177  Hit_.Endcap() == iHit.Endcap() &&
178  Hit_.Station() == iHit.Station() &&
179  Hit_.Chamber() == iHit.Chamber() ) {
180 
181  if ( (iHit.Is_CSC() == 1 && iHit.Ring() == 2) ||
182  (iHit.Is_RPC() == 1) ) { // RPC rings 2 and 3 both map to CSC ring 2
183 
184  if ( Hit_.Neighbor() == iHit.Neighbor() ) {
185  Hit_.set_stub_num( Hit_.Stub_num() + 1);
186  } // else 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  // duplicate_hit_exists = true;
191  // }
192  }
193  }
194  } // End loop: for (auto const & iHit : *res_hit)
195 
196  (res->at(iOut)).push_RPC(RPC_);
197  res_hit->push_back(Hit_);
198 
199  // Finished with unpacking one RPC Data Record
200  return true;
201 
202  } // End bool RPCBlockUnpacker::unpack
203 
204  // bool RPCBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
205  // std::cout << "Inside RPCBlockPacker::pack" << std::endl;
206  // return true;
207  // } // End bool RPCBlockPacker::pack
208 
209  } // End namespace emtf
210  } // End namespace stage2
211 } // End namespace l1t
212 
214 // DEFINE_L1T_PACKER(l1t::stage2::RPCBlockPacker);
void set_subsector_RPC(int bits)
Definition: EMTFHit.h:88
void set_neighbor(int bits)
Definition: EMTFHit.h:93
const std::vector< uint32_t > & payload() const
Definition: Block.h:60
void set_stub_num(int bits)
Definition: EMTFHit.h:111
void set_station(int bits)
Definition: EMTFHit.h:82
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:83
int Chamber() const
Definition: EMTFHit.h:147
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
void set_theta(int bits)
Definition: RPC.h:25
void set_bt_segment(int bits)
Definition: EMTFHit.h:121
void set_tbin(int bits)
Definition: RPC.h:31
int BX() const
Definition: EMTFHit.h:168
int Subsector_RPC() const
Definition: EMTFHit.h:146
int Word() const
Definition: RPC.h:38
std::vector< EMTFHit > EMTFHitCollection
Definition: EMTFHit.h:270
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:130
void set_bc0(int bits)
Definition: RPC.h:30
int Sector_RPC() const
Definition: EMTFHit.h:143
void set_pc_segment(int bits)
Definition: EMTFHit.h:98
int Frame() const
Definition: RPC.h:39
void set_fs_segment(int bits)
Definition: EMTFHit.h:118
void set_sector_RPC(int bits)
Definition: EMTFHit.h:85
void set_sector(int bits)
Definition: EMTFHit.h:84
JetCorrectorParametersCollection coll
Definition: classes.h:10
int Station() const
Definition: EMTFHit.h:140
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:139
Definition: errors.py:1
int Stub_num() const
Definition: EMTFHit.h:169
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
void set_vp(int bits)
Definition: RPC.h:32
int Link() const
Definition: RPC.h:40
void set_chamber(int bits)
Definition: EMTFHit.h:89
int Neighbor() const
Definition: EMTFHit.h:151
virtual int checkFormat(const Block &block)
Definition: EMTFBlockRPC.cc:34
void set_subsector(int bits)
Definition: EMTFHit.h:87