CMS 3D CMS Logo

EMTFBlockGEM.cc
Go to the documentation of this file.
1 // Code to unpack the "GEM Data Record"
2 
4 
5 #include "EMTFCollections.h"
6 #include "EMTFUnpackerTools.h"
7 
8 namespace l1t {
9  namespace stage2 {
10  namespace emtf {
11 
12  class GEMBlockUnpacker : public Unpacker {
13  public:
14  virtual int checkFormat(const Block& block);
15  // virtual bool checkFormat() override; // Return "false" if block format does not match expected format
16  bool unpack(const Block& block, UnpackerCollections* coll) override;
17  // virtual bool packBlock(const Block& block, UnpackerCollections *coll) override;
18  };
19 
20  // class GEMBlockPacker : public Packer {
21  // public:
22  // virtual bool unpack(const Block& block, UnpackerCollections *coll) override;
23  // };
24 
25  } // namespace emtf
26  } // namespace stage2
27 } // namespace l1t
28 
29 namespace l1t {
30  namespace stage2 {
31  namespace emtf {
32 
34  auto payload = block.payload();
35  int errors = 0;
36 
37  // Check the number of 16-bit words
38  if (payload.size() != 4) {
39  errors += 1;
40  edm::LogError("L1T|EMTF") << "Payload size in 'GEM Data Record' is different than expected";
41  }
42 
43  // Check that each word is 16 bits
44  for (size_t i = 0; i < 4; ++i) {
45  if (GetHexBits(payload[i], 16, 31) != 0) {
46  errors += 1;
47  edm::LogError("L1T|EMTF") << "Payload[" << i << "] has more than 16 bits in 'GEM Data Record'";
48  }
49  }
50 
51  uint16_t GEMa = payload[0];
52  uint16_t GEMb = payload[1];
53  uint16_t GEMc = payload[2];
54  uint16_t GEMd = payload[3];
55 
56  // Check Format
57  if (GetHexBits(GEMa, 15, 15) != 1) {
58  errors += 1;
59  edm::LogError("L1T|EMTF") << "Format identifier bits in GEMa are incorrect";
60  }
61  if (GetHexBits(GEMb, 15, 15) != 1) {
62  errors += 1;
63  edm::LogError("L1T|EMTF") << "Format identifier bits in GEMb are incorrect";
64  }
65  if (GetHexBits(GEMc, 15, 15) != 1) {
66  errors += 1;
67  edm::LogError("L1T|EMTF") << "Format identifier bits in GEMc are incorrect";
68  }
69  if (GetHexBits(GEMd, 15, 15) != 0) {
70  errors += 1;
71  edm::LogError("L1T|EMTF") << "Format identifier bits in GEMd are incorrect";
72  }
73 
74  return errors;
75  }
76 
91  int& ring,
92  int& sector,
93  int& subsector,
94  int& neighbor,
95  int& layer, // is this correct for the GEM case?
96  const int evt_sector,
97  const int cluster_id, // used to differentiate between GEM layer 1/2
98  const int link) {
99  station = -99; // station is not encoded in the GEM frame
100  ring = 1; // GEMs are only in GE1/1 and GE2/1
101  sector = -99;
102  subsector = -99;
103  neighbor = -99;
104  layer = -99; // the GEM layer is 1 or 2, depending on the cluster ID
105 
106  // Neighbor indicated by link == 6
107  sector = (link != 6 ? evt_sector : (evt_sector == 1 ? 6 : evt_sector - 1));
108  subsector = (link != 6 ? link : 0); // TODO: verify subsector 0 in the neighbouring sector?
109  neighbor = (link == 6 ? 1 : 0); // TODO: verify that 6 is for the neighbour, not 0 (as written in EMTFBlockRPC)
110  layer = (cluster_id % 8); // + 1 if layer should be 1 or 2, otherwise layer is 0 or 1
111  }
112 
122  // std::cout << "Inside EMTFBlockGEM.cc: unpack" << std::endl;
123 
124  // Get the payload for this block, made up of 16-bit words (0xffff)
125  // Format defined in MTF7Payload::getBlock() in src/Block.cc
126  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
127  auto payload = block.payload();
128 
129  // Check Format of Payload
130  l1t::emtf::GEM GEM_;
131  for (int err = 0; err < checkFormat(block); ++err) {
132  GEM_.add_format_error();
133  }
134 
135  // Assign payload to 16-bit words
136  uint16_t GEMa = payload[0];
137  uint16_t GEMb = payload[1];
138  uint16_t GEMc = payload[2];
139  uint16_t GEMd = payload[3];
140 
141  // res is a pointer to a collection of EMTFDaqOut class objects
142  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
144  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
145  int iOut = res->size() - 1;
146 
147  EMTFHitCollection* res_hit;
148  res_hit = static_cast<EMTFCollections*>(coll)->getEMTFHits();
149  EMTFHit Hit_;
150 
151  // TODO: Verify this is correct for GEM
153  res_GEM = static_cast<EMTFCollections*>(coll)->getEMTFGEMPadClusters();
154 
156  // Unpack the GEM Data Record
158 
159  GEM_.set_pad(GetHexBits(GEMa, 0, 8));
160  GEM_.set_partition(GetHexBits(GEMa, 9, 11));
161  GEM_.set_cluster_size(GetHexBits(GEMa, 12, 14));
162 
163  GEM_.set_cluster_id(GetHexBits(GEMb, 8, 11));
164  GEM_.set_link(GetHexBits(GEMb, 12, 14));
165 
166  GEM_.set_gem_bxn(GetHexBits(GEMc, 0, 11));
167  GEM_.set_bc0(GetHexBits(GEMc, 14, 14));
168 
169  GEM_.set_tbin(GetHexBits(GEMd, 0, 2));
170  GEM_.set_vp(GetHexBits(GEMd, 3, 3));
171 
172  // GEM_.set_dataword(uint64_t dataword);
173 
174  // Convert specially-encoded GEM quantities
175  // TODO: is the RPC or CSC method for this function better... - JS 06.07.20
176  int _station, _ring, _sector, _subsector, _neighbor, _layer;
177  convert_GEM_location(_station,
178  _ring,
179  _sector,
180  _subsector,
181  _neighbor,
182  _layer,
183  (res->at(iOut)).PtrEventHeader()->Sector(),
184  GEM_.ClusterID(),
185  GEM_.Link());
186 
187  // Rotate by 20 deg to match GEM convention in CMSSW) // FIXME VERIFY
188  // int _sector_gem = (_subsector < 5) ? _sector : (_sector % 6) + 1; //
189  int _sector_gem = _sector;
190  // Rotate by 2 to match GEM convention in CMSSW (GEMDetId.h) // FIXME VERIFY
191  int _subsector_gem = ((_subsector + 1) % 6) + 1;
192  // Define chamber number) // FIXME VERIFY
193  int _chamber = (_sector_gem - 1) * 6 + _subsector_gem;
194  // Define CSC-like subsector) // FIXME WHY?? VERIFY
195  int _subsector_csc = (_station != 1) ? 0 : ((_chamber % 6 > 2) ? 1 : 2);
196 
197  Hit_.set_station(_station);
198  Hit_.set_ring(_ring);
199  Hit_.set_sector(_sector);
200  Hit_.set_subsector(_subsector_csc);
201  Hit_.set_chamber(_chamber);
202  Hit_.set_neighbor(_neighbor);
203 
204  // Fill the EMTFHit
205  ImportGEM(Hit_, GEM_, (res->at(iOut)).PtrEventHeader()->Endcap(), (res->at(iOut)).PtrEventHeader()->Sector());
206 
207  // Set the stub number for this hit
208  // Each chamber can send up to 2 stubs per BX // FIXME is this true for GEM, are stubs relevant for GEMs?
209  // Also count stubs in corresponding CSC chamber; GEM hit counting is on top of LCT counting
210  Hit_.set_stub_num(0);
211  // See if matching hit is already in event record
212  bool exact_duplicate = false;
213  for (auto const& iHit : *res_hit) {
214  if (Hit_.BX() == iHit.BX() && Hit_.Endcap() == iHit.Endcap() && Hit_.Station() == iHit.Station() &&
215  Hit_.Chamber() == iHit.Chamber()) {
216  if ((iHit.Is_CSC() == 1 && iHit.Ring() == 2) ||
217  (iHit.Is_GEM() == 1)) { // Copied from RPC, but GEM has no ring 2/3...
218  if (Hit_.Neighbor() == iHit.Neighbor()) {
219  Hit_.set_stub_num(Hit_.Stub_num() + 1);
220  if (iHit.Is_GEM() == 1 && iHit.Ring() == Hit_.Ring() && iHit.Roll() == Hit_.Roll() &&
221  iHit.Pad() == Hit_.Pad()) {
222  exact_duplicate = true;
223  }
224  }
225  }
226  }
227  } // End loop: for (auto const & iHit : *res_hit)
228 
229  if (exact_duplicate)
230  edm::LogWarning("L1T|EMTF") << "EMTF unpacked duplicate GEM digis: BX " << Hit_.BX() << ", endcap "
231  << Hit_.Endcap() << ", station " << Hit_.Station() << ", neighbor "
232  << Hit_.Neighbor() << ", ring " << Hit_.Ring() << ", chamber " << Hit_.Chamber()
233  << ", roll " << Hit_.Roll() << ", pad " << Hit_.Pad() << std::endl;
234 
235  (res->at(iOut)).push_GEM(GEM_);
236  if (!exact_duplicate)
237  res_hit->push_back(Hit_);
238 
239  if (!exact_duplicate)
240  res_GEM->insertDigi(Hit_.GEM_DetId(), Hit_.CreateGEMPadDigiCluster());
241 
242  // Finished with unpacking one GEM Data Record
243  return true;
244 
245  } // End bool GEMBlockUnpacker::unpack
246 
247  // bool GEMBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
248  // std::cout << "Inside GEMBlockPacker::pack" << std::endl;
249  // return true;
250  // } // End bool GEMBlockPacker::pack
251 
252  } // End namespace emtf
253  } // End namespace stage2
254 } // End namespace l1t
255 
257 // DEFINE_L1T_PACKER(l1t::stage2::emtf::GEMBlockPacker);
l1t::EMTFDaqOutCollection
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:179
mps_fire.i
i
Definition: mps_fire.py:428
MainPageGenerator.link
link
Definition: MainPageGenerator.py:271
l1t::emtf::GEM::set_link
void set_link(const int bits)
Definition: GEM.h:34
l1t::emtf::GEM::Link
int Link() const
Returns the input link of the cluster.
Definition: GEM.h:51
relativeConstraints.station
station
Definition: relativeConstraints.py:67
l1t::emtf::GEM::set_tbin
void set_tbin(const int bits)
Definition: GEM.h:37
l1t::stage2::emtf::ImportGEM
void ImportGEM(EMTFHit &_hit, const l1t::emtf::GEM &_GEM, const int _endcap, const int _evt_sector)
Definition: EMTFUnpackerTools.cc:63
l1t::EMTFHit::Endcap
int Endcap() const
Definition: EMTFHit.h:191
EMTFCollections.h
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
l1t::emtf::GEM::ClusterID
int ClusterID() const
Returns the the cluster ID within the link.
Definition: GEM.h:49
l1t::EMTFHit::GEM_DetId
GEMDetId GEM_DetId() const
Definition: EMTFHit.h:124
l1t::stage2::emtf::GEMBlockUnpacker
Definition: EMTFBlockGEM.cc:12
l1t::EMTFHit::BX
int BX() const
Definition: EMTFHit.h:244
l1t::EMTFHit::set_chamber
void set_chamber(int bits)
Definition: EMTFHit.h:137
l1t::EMTFHit::set_subsector
void set_subsector(int bits)
Definition: EMTFHit.h:135
l1t::EMTFHit::CreateGEMPadDigiCluster
GEMPadDigiCluster CreateGEMPadDigiCluster() const
Definition: EMTFHit.cc:98
l1t::emtf::GEM::set_vp
void set_vp(const int bits)
Definition: GEM.h:38
errors
Definition: errors.py:1
l1t::emtf::GEM::set_gem_bxn
void set_gem_bxn(const int bits)
Definition: GEM.h:35
l1t::EMTFHit::Neighbor
int Neighbor() const
Definition: EMTFHit.h:203
emtf
Definition: Event.h:15
l1t::EMTFHit::Roll
int Roll() const
Definition: EMTFHit.h:202
UnpackerFactory.h
jets_cff.payload
payload
Definition: jets_cff.py:32
l1t::EMTFHit::set_station
void set_station(int bits)
Definition: EMTFHit.h:130
GEMPadDigiClusterCollection
l1t::Unpacker
Definition: Unpacker.h:11
l1t::emtf::GEM::set_pad
void set_pad(const int bits)
Definition: GEM.h:30
l1t::emtf::GEM
Definition: GEM.h:11
l1t::EMTFHit::Pad
int Pad() const
Repurpose "strip" as GEM pad for GEM sourced hits.
Definition: EMTFHit.h:230
l1t::EMTFHit
Definition: EMTFHit.h:25
l1t::stage2::emtf::GEMBlockUnpacker::checkFormat
virtual int checkFormat(const Block &block)
Definition: EMTFBlockGEM.cc:33
l1t
delete x;
Definition: CaloConfig.h:22
l1t::emtf::GEM::set_cluster_id
void set_cluster_id(const int bits)
Definition: GEM.h:33
l1t::emtf::GEM::set_bc0
void set_bc0(const int bits)
Definition: GEM.h:36
l1t::emtf::GEM::set_partition
void set_partition(const int bits)
Definition: GEM.h:31
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::GEM::set_cluster_size
void set_cluster_size(const int bits)
Definition: GEM.h:32
l1t::EMTFHit::set_sector
void set_sector(int bits)
Definition: EMTFHit.h:132
l1t::stage2::emtf::convert_GEM_location
void convert_GEM_location(int &station, int &ring, int &sector, int &subsector, int &neighbor, int &layer, const int evt_sector, const int cluster_id, const int link)
Converts station, ring, sector, subsector, neighbor, and segment from the GEM output.
Definition: EMTFBlockGEM.cc:90
l1t::stage2::emtf::GEMBlockUnpacker::unpack
bool unpack(const Block &block, UnpackerCollections *coll) override
Unpack the GEM payload in the EMTF DAQ payload.
Definition: EMTFBlockGEM.cc:121
l1t::EMTFHit::Ring
int Ring() const
Definition: EMTFHit.h:193
EMTFUnpackerTools.h
l1t::UnpackerCollections
Definition: UnpackerCollections.h:9
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::EMTFHit::Stub_num
int Stub_num() const
Definition: EMTFHit.h:245
l1t::emtf::GEM::add_format_error
void add_format_error()
Definition: GEM.h:39
l1t::Block
Definition: Block.h:70
l1t::EMTFHit::Chamber
int Chamber() const
Definition: EMTFHit.h:199
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::set_ring
void set_ring(int bits)
Definition: EMTFHit.h:131
debug_messages_cfi.errors
errors
Definition: debug_messages_cfi.py:54