CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
CSCTFUnpacker Class Reference
Inheritance diagram for CSCTFUnpacker:
edm::stream::EDProducer<>

Public Member Functions

 CSCTFUnpacker (const edm::ParameterSet &pset)
 
void produce (edm::Event &e, const edm::EventSetup &c) override
 
 ~CSCTFUnpacker (void) override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Attributes

int m_maxBX
 
int m_minBX
 
CSCTriggerMappingmapping
 
edm::InputTag producer
 
edm::EDGetTokenT< FEDRawDataCollectionRaw_token
 
std::vector< int > slot2sector
 
bool swapME1strips
 
CSCTFEvent tfEvent
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 19 of file CSCTFUnpacker.cc.

Constructor & Destructor Documentation

◆ CSCTFUnpacker()

CSCTFUnpacker::CSCTFUnpacker ( const edm::ParameterSet pset)

Definition at line 75 of file CSCTFUnpacker.cc.

References CSCTriggerMapping::addRecord(), makeMuonMisalignmentScenario::endcap, Exception, ntuplemaker::fill, LogDebug, m_maxBX, m_minBX, mapping, csctfunpacker_cfi::mappingFile, producer, muonDTDigis_cfi::pset, Raw_token, nano_mu_digi_cff::sector, FCDTask_cfi::slot, slot2sector, relativeConstraints::station, AlCaHLTBitMon_QueryRunRegistry::string, and swapME1strips.

75  : edm::stream::EDProducer<>(), mapping(nullptr) {
76  LogDebug("CSCTFUnpacker|ctor") << "Started ...";
77 
78  // Edges of the time window, which LCTs are put into (unlike tracks, which are always centred around 0):
79  m_minBX = pset.getParameter<int>("MinBX"); //3
80  m_maxBX = pset.getParameter<int>("MaxBX"); //9
81 
82  // Swap: if(swapME1strips && me1b && !zplus) strip = 65 - strip; // 1-64 -> 64-1 :
83  swapME1strips = pset.getParameter<bool>("swapME1strips");
84 
85  // Initialize slot<->sector assignment
86  slot2sector = pset.getParameter<std::vector<int>>("slot2sector");
87  LogDebug("CSCTFUnpacker|ctor") << "Verifying slot<->sector map from 'vint32 slot2sector'";
88  for (int slot = 0; slot < 22; slot++)
89  if (slot2sector[slot] < 0 || slot2sector[slot] > 12)
90  throw cms::Exception("Invalid configuration") << "CSCTFUnpacker: sector index is set out of range (slot2sector["
91  << slot << "]=" << slot2sector[slot] << ", should be [0-12])";
92  // Just for safety (in case of bad data):
93  slot2sector.resize(32);
94 
95  // As we use standard CSC digi containers, we have to initialize mapping:
96  std::string mappingFile = pset.getParameter<std::string>("mappingFile");
97  if (mappingFile.length()) {
98  LogDebug("CSCTFUnpacker|ctor") << "Define ``mapping'' only if you want to screw up real geometry";
100  } else {
101  LogDebug("CSCTFUnpacker|ctor") << "Generating default hw<->geometry mapping";
102  class M : public CSCTriggerSimpleMapping {
103  void fill(void) override {}
104  };
105  mapping = new M();
106  for (int endcap = 1; endcap <= 2; endcap++)
107  for (int station = 1; station <= 4; station++)
108  for (int sector = 1; sector <= 6; sector++)
109  for (int csc = 1; csc <= 9; csc++) {
110  if (station == 1) {
113  } else
115  }
116  }
117 
118  producer = pset.getParameter<edm::InputTag>("producer");
119 
120  produces<CSCCorrelatedLCTDigiCollection>();
121  produces<L1CSCTrackCollection>();
122  produces<L1CSCStatusDigiCollection>();
123  produces<CSCTriggerContainer<csctf::TrackStub>>("DT");
124 
125  Raw_token = consumes<FEDRawDataCollection>(producer);
126 }
edm::InputTag producer
edm::EDGetTokenT< FEDRawDataCollection > Raw_token
void addRecord(int rendcap, int rstation, int rsector, int rsubsector, int rcscid, int cendcap, int cstation, int csector, int csubsector, int ccscid)
std::vector< int > slot2sector
Definition: L1Track.h:19
CSCTriggerMapping * mapping
#define LogDebug(id)

◆ ~CSCTFUnpacker()

CSCTFUnpacker::~CSCTFUnpacker ( void  )
override

Definition at line 128 of file CSCTFUnpacker.cc.

References mapping.

128  {
129  if (mapping)
130  delete mapping;
131 }
CSCTriggerMapping * mapping

Member Function Documentation

◆ produce()

void CSCTFUnpacker::produce ( edm::Event e,
const edm::EventSetup c 
)
override

Definition at line 133 of file CSCTFUnpacker.cc.

References CSCSPRecord::AFs(), newFWLiteAna::base, CSCSPHeader::BXN(), CSCSPRecord::BXs(), CSCSPEvent::counters(), FEDRawData::data(), TauDecayModes::dec, CSCTriggerMapping::detId(), MillePedeFileConverter_cfg::e, CSCSPHeader::endcap(), makeMuonMisalignmentScenario::endcap, FEDRawDataCollection::FEDData(), PixelSLinkDataInputSource_cfi::fedid, CSCSPEvent::header(), l1ctLayer2EG_cff::id, createfilelist::int, CSCSPHeader::L1A(), CSCSPRecord::LCT(), m_maxBX, m_minBX, mapping, FEDNumbering::MAXCSCTFFEDID, CSCSPRecord::mbStubs(), FEDNumbering::MINCSCTFFEDID, eostools::move(), CSCSPHeader::nTBINs(), CSCSPCounters::orbit_counter(), topSingleLeptonDQM_PU_cfi::pattern, CSCSPRecord::ptSpy(), quality, Raw_token, CSCSPEvent::record(), nano_mu_digi_cff::sector, CSCSPHeader::sector(), CSCSPRecord::SEs(), FEDRawData::size(), CSCSPHeader::slot(), slot2sector, CSCSPRecord::SMs(), CSCTFEvent::SPs_fast(), relativeConstraints::station, mps_update::status, CSCSPHeader::status(), nano_mu_digi_cff::strip, nano_mu_digi_cff::subsector, swapME1strips, tfEvent, HLT_2024v14_cff::track, CSCSPCounters::track_counter(), CSCSPRecord::tracks(), DiMuonV_cfg::tracks, CSCTFEvent::unpack(), CSCSPRecord::VPs(), and nano_mu_digi_cff::wireGroup.

133  {
134  // Get a handle to the FED data collection
136  e.getByToken(Raw_token, rawdata);
137 
138  // create the collection of CSC wire and strip digis as well as of DT stubs, which we receive from DTTF
139  auto LCTProduct = std::make_unique<CSCCorrelatedLCTDigiCollection>();
140  auto trackProduct = std::make_unique<L1CSCTrackCollection>();
141  auto statusProduct = std::make_unique<L1CSCStatusDigiCollection>();
142  auto dtProduct = std::make_unique<CSCTriggerContainer<csctf::TrackStub>>();
143 
145  const FEDRawData& fedData = rawdata->FEDData(fedid);
146  if (fedData.size() == 0)
147  continue;
148  //LogDebug("CSCTFUnpacker|produce");
149  //if( monitor ) monitor->process((unsigned short*)fedData.data());
150  unsigned int unpacking_status = tfEvent.unpack((unsigned short*)fedData.data(), fedData.size() / 2);
151  if (unpacking_status == 0) {
152  // There may be several SPs in event
153  std::vector<const CSCSPEvent*> SPs = tfEvent.SPs_fast();
154  // Cycle over all of them
155  for (std::vector<const CSCSPEvent*>::const_iterator spItr = SPs.begin(); spItr != SPs.end(); spItr++) {
156  const CSCSPEvent* sp = *spItr;
157 
159  status.sp_slot = sp->header().slot();
160  status.l1a_bxn = sp->header().BXN();
161  status.fmm_status = sp->header().status();
162  status.track_cnt = sp->counters().track_counter();
163  status.orbit_cnt = sp->counters().orbit_counter();
164 
165  // Finds central LCT BX
166  // assumes window is odd number of bins
167  int central_lct_bx = (m_maxBX + m_minBX) / 2;
168 
169  // Find central SP BX
170  // assumes window is odd number of bins
171  int central_sp_bx = int(sp->header().nTBINs() / 2);
172 
173  for (unsigned int tbin = 0; tbin < sp->header().nTBINs(); tbin++) {
174  status.se |= sp->record(tbin).SEs();
175  status.sm |= sp->record(tbin).SMs();
176  status.bx |= sp->record(tbin).BXs();
177  status.af |= sp->record(tbin).AFs();
178  status.vp |= sp->record(tbin).VPs();
179 
180  for (unsigned int FPGA = 0; FPGA < 5; FPGA++)
181  for (unsigned int MPClink = 0; MPClink < 3; ++MPClink) {
182  std::vector<CSCSP_MEblock> lct = sp->record(tbin).LCT(FPGA, MPClink);
183  if (lct.empty())
184  continue;
185 
186  status.link_status[lct[0].spInput() - 1] |= (1 << lct[0].receiver_status_frame1()) |
187  (1 << lct[0].receiver_status_frame2()) |
188  ((lct[0].aligment_fifo() ? 1 : 0) << 4);
189  status.mpc_link_id |= (lct[0].link() << 2) | lct[0].mpc();
190 
191  int station = (FPGA ? FPGA : 1);
192  int endcap = 0, sector = 0;
193  if (slot2sector[sp->header().slot()]) {
194  endcap = slot2sector[sp->header().slot()] / 7 + 1;
195  sector = slot2sector[sp->header().slot()];
196  if (sector > 6)
197  sector -= 6;
198  } else {
199  endcap = (sp->header().endcap() ? 1 : 2);
200  sector = sp->header().sector();
201  }
202  int subsector = (FPGA > 1 ? 0 : FPGA + 1);
203  int cscid = lct[0].csc();
204 
205  try {
206  CSCDetId id = mapping->detId(endcap, station, sector, subsector, cscid, 0);
207  // corrlcts now have no layer associated with them
208  LCTProduct->insertDigi(id,
210  lct[0].vp(),
211  lct[0].quality(),
212  lct[0].wireGroup(),
213  (swapME1strips && cscid <= 3 && station == 1 &&
214  endcap == 2 && lct[0].strip() < 65
215  ? 65 - lct[0].strip()
216  : lct[0].strip()),
217  lct[0].pattern(),
218  lct[0].l_r(),
219  (lct[0].tbin() + (central_lct_bx - central_sp_bx)),
220  lct[0].link(),
221  lct[0].BXN(),
222  0,
223  cscid));
224  } catch (cms::Exception& e) {
225  edm::LogInfo("CSCTFUnpacker|produce")
226  << e.what() << "Not adding digi to collection in event " << sp->header().L1A()
227  << " (endcap=" << endcap << ",station=" << station << ",sector=" << sector
228  << ",subsector=" << subsector << ",cscid=" << cscid << ",spSlot=" << sp->header().slot() << ")";
229  }
230  }
231 
232  std::vector<CSCSP_MBblock> mbStubs = sp->record(tbin).mbStubs();
233  for (std::vector<CSCSP_MBblock>::const_iterator iter = mbStubs.begin(); iter != mbStubs.end(); iter++) {
234  int endcap, sector;
235  if (slot2sector[sp->header().slot()]) {
236  endcap = slot2sector[sp->header().slot()] / 7 + 1;
237  sector = slot2sector[sp->header().slot()];
238  if (sector > 6)
239  sector -= 6;
240  } else {
241  endcap = (sp->header().endcap() ? 1 : 2);
242  sector = sp->header().sector();
243  }
244  const unsigned int csc2dt[6][2] = {{2, 3}, {4, 5}, {6, 7}, {8, 9}, {10, 11}, {12, 1}};
245  DTChamberId id((endcap == 1 ? 2 : -2), 1, csc2dt[sector - 1][iter->id() - 1]);
247  iter->vq(),
248  iter->quality(),
249  iter->cal(),
250  iter->flag(),
251  iter->bc0(),
252  iter->phi_bend(),
253  tbin + (central_lct_bx - central_sp_bx),
254  iter->id(),
255  iter->bxn(),
256  iter->timingError(),
257  iter->BXN());
258  csctf::TrackStub dtStub(base, id, iter->phi(), 0);
259  dtProduct->push_back(dtStub);
260  }
261 
262  std::vector<CSCSP_SPblock> tracks = sp->record(tbin).tracks();
263  unsigned int trkNumber = 0;
264  for (std::vector<CSCSP_SPblock>::const_iterator iter = tracks.begin(); iter != tracks.end();
265  iter++, trkNumber++) {
267  if (slot2sector[sp->header().slot()]) {
268  track.first.m_endcap = slot2sector[sp->header().slot()] / 7 + 1;
269  track.first.m_sector = slot2sector[sp->header().slot()];
270  if (track.first.m_sector > 6)
271  track.first.m_sector -= 6;
272  } else {
273  track.first.m_endcap = (sp->header().endcap() ? 1 : 2);
274  track.first.m_sector = sp->header().sector();
275  }
276 
277  track.first.m_lphi = iter->phi();
278  track.first.m_ptAddress = iter->ptLUTaddress();
279  track.first.m_fr = iter->f_r();
280  track.first.m_ptAddress |= (iter->f_r() << 21);
281 
282  track.first.setStationIds(iter->ME1_id(), iter->ME2_id(), iter->ME3_id(), iter->ME4_id(), iter->MB_id());
283  track.first.setTbins(
284  iter->ME1_tbin(), iter->ME2_tbin(), iter->ME3_tbin(), iter->ME4_tbin(), iter->MB_tbin());
285  track.first.setBx(iter->tbin() - central_sp_bx);
286  track.first.setBits(iter->syncErr(), iter->bx0(), iter->bc0());
287 
288  track.first.setLocalPhi(iter->phi());
289  track.first.setEtaPacked(iter->eta());
290  track.first.setChargePacked(iter->charge());
291 
292  track.first.m_output_link = iter->id();
293  if (track.first.m_output_link) {
294  track.first.m_rank =
295  (iter->f_r() ? sp->record(tbin).ptSpy() & 0x7F : (sp->record(tbin).ptSpy() & 0x7F00) >> 8);
296  track.first.setChargeValidPacked(
297  (iter->f_r() ? (sp->record(tbin).ptSpy() & 0x80) >> 8 : (sp->record(tbin).ptSpy() & 0x8000) >> 15));
298  } else {
299  track.first.m_rank = 0;
300  track.first.setChargeValidPacked(0);
301  }
302  track.first.setFineHaloPacked(iter->halo());
303 
304  track.first.m_winner = iter->MS_id() & (1 << trkNumber);
305 
306  std::vector<CSCSP_MEblock> lcts = iter->LCTs();
307  for (std::vector<CSCSP_MEblock>::const_iterator lct = lcts.begin(); lct != lcts.end(); lct++) {
308  int station = (lct->spInput() > 6 ? (lct->spInput() - 1) / 3 : 1);
309  int subsector = (lct->spInput() > 6 ? 0 : (lct->spInput() - 1) / 3 + 1);
310  try {
311  CSCDetId id =
312  mapping->detId(track.first.m_endcap, station, track.first.m_sector, subsector, lct->csc(), 0);
313  track.second.insertDigi(id,
315  lct->vp(),
316  lct->quality(),
317  lct->wireGroup(),
318  (swapME1strips && lct->csc() <= 3 && station == 1 &&
319  track.first.m_endcap == 2 && lct[0].strip() < 65
320  ? 65 - lct[0].strip()
321  : lct[0].strip()),
322  lct->pattern(),
323  lct->l_r(),
324  (lct->tbin() + (central_lct_bx - central_sp_bx)),
325  lct->link(),
326  lct->BXN(),
327  0,
328  lct->csc()));
329  } catch (cms::Exception& e) {
330  edm::LogInfo("CSCTFUnpacker|produce")
331  << e.what() << "Not adding track digi to collection in event" << sp->header().L1A()
332  << " (endcap=" << track.first.m_endcap << ",station=" << station
333  << ",sector=" << track.first.m_sector << ",subsector=" << subsector << ",cscid=" << lct->csc()
334  << ",spSlot=" << sp->header().slot() << ")";
335  }
336  }
337 
338  std::vector<CSCSP_MBblock> mbStubs = iter->dtStub();
339  for (std::vector<CSCSP_MBblock>::const_iterator iter = mbStubs.begin(); iter != mbStubs.end(); iter++) {
340  CSCDetId id = mapping->detId(track.first.m_endcap, 1, track.first.m_sector, iter->id(), 1, 0);
341  track.second.insertDigi(id,
342  CSCCorrelatedLCTDigi(iter->phi(),
343  iter->vq(),
344  iter->quality() + 100,
345  iter->cal(),
346  iter->flag(),
347  iter->bc0(),
348  iter->phi_bend(),
349  tbin + (central_lct_bx - central_sp_bx),
350  iter->id(),
351  iter->bxn(),
352  iter->timingError(),
353  iter->BXN()));
354  }
355 
356  trackProduct->push_back(track);
357  }
358  }
359  statusProduct->second.push_back(status);
360  }
361  } else {
362  edm::LogError("CSCTFUnpacker|produce")
363  << " problem of unpacking TF event: 0x" << std::hex << unpacking_status << std::dec << " code";
364  }
365 
366  statusProduct->first = unpacking_status;
367 
368  } //end of fed cycle
369  e.put(std::move(dtProduct), "DT");
370  e.put(std::move(LCTProduct)); // put processed lcts into the event.
371  e.put(std::move(trackProduct));
372  e.put(std::move(statusProduct));
373 }
unsigned int SEs(void) const
Definition: CSCSPRecord.h:84
unsigned int unpack(const unsigned short *buf, unsigned int length)
Definition: CSCTFEvent.cc:6
const CSCSPCounters & counters(void) const
Definition: CSCSPEvent.h:18
std::vector< const CSCSPEvent * > SPs_fast(void) const
Definition: CSCTFEvent.h:32
unsigned int BXs(void) const
Definition: CSCSPRecord.h:87
std::pair< csc::L1Track, CSCCorrelatedLCTDigiCollection > L1CSCTrack
base
Main Program
Definition: newFWLiteAna.py:92
unsigned int status(void) const
Definition: CSCSPHeader.h:95
std::vector< CSCSP_SPblock > tracks(void) const
Definition: CSCSPRecord.cc:104
unsigned int AFs(void) const
Definition: CSCSPRecord.h:86
unsigned int L1A(void) const
Definition: CSCSPHeader.h:76
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:48
int track_counter(void) const
Definition: CSCSPCounters.h:33
edm::EDGetTokenT< FEDRawDataCollection > Raw_token
Log< level::Error, false > LogError
string quality
unsigned int endcap(void) const
Definition: CSCSPHeader.h:87
unsigned int BXN(void) const
Definition: CSCSPHeader.h:75
unsigned int nTBINs(void) const
Definition: CSCSPHeader.h:97
int orbit_counter(void) const
Definition: CSCSPCounters.h:34
std::vector< int > slot2sector
unsigned int VPs(void) const
Definition: CSCSPRecord.h:83
unsigned int sector(void) const
Definition: CSCSPHeader.h:81
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
const CSCSPRecord & record(unsigned int tbin) const
Definition: CSCSPEvent.h:21
const CSCSPHeader & header(void) const
Definition: CSCSPEvent.h:17
Log< level::Info, false > LogInfo
CSCTriggerMapping * mapping
std::vector< CSCSP_MBblock > mbStubs(void) const
Definition: CSCSPRecord.cc:115
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
CSCDetId detId(int endcap, int station, int sector, int subsector, int cscid, int layer=0) const
CSCTFEvent tfEvent
def move(src, dest)
Definition: eostools.py:511
unsigned int slot(void) const
Definition: CSCSPHeader.h:78
std::vector< CSCSP_MEblock > LCT(unsigned int mpc, unsigned int link) const
Definition: CSCSPRecord.cc:96
unsigned int SMs(void) const
Definition: CSCSPRecord.h:85
unsigned int ptSpy(void) const
Definition: CSCSPRecord.h:89

Member Data Documentation

◆ m_maxBX

int CSCTFUnpacker::m_maxBX
private

Definition at line 21 of file CSCTFUnpacker.cc.

Referenced by CSCTFUnpacker(), and produce().

◆ m_minBX

int CSCTFUnpacker::m_minBX
private

Definition at line 21 of file CSCTFUnpacker.cc.

Referenced by CSCTFUnpacker(), and produce().

◆ mapping

CSCTriggerMapping* CSCTFUnpacker::mapping
private

◆ producer

edm::InputTag CSCTFUnpacker::producer
private

Definition at line 33 of file CSCTFUnpacker.cc.

Referenced by CSCTFUnpacker().

◆ Raw_token

edm::EDGetTokenT<FEDRawDataCollection> CSCTFUnpacker::Raw_token
private

Definition at line 35 of file CSCTFUnpacker.cc.

Referenced by CSCTFUnpacker(), and produce().

◆ slot2sector

std::vector<int> CSCTFUnpacker::slot2sector
private

Definition at line 30 of file CSCTFUnpacker.cc.

Referenced by CSCTFUnpacker(), and produce().

◆ swapME1strips

bool CSCTFUnpacker::swapME1strips
private

Definition at line 22 of file CSCTFUnpacker.cc.

Referenced by CSCTFUnpacker(), and produce().

◆ tfEvent

CSCTFEvent CSCTFUnpacker::tfEvent
private

Definition at line 26 of file CSCTFUnpacker.cc.

Referenced by produce().