CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
CSCTFUnpacker Class Reference

#include <CSCTFUnpacker.h>

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
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

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<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 22 of file CSCTFUnpacker.h.

Constructor & Destructor Documentation

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

Definition at line 34 of file CSCTFUnpacker.cc.

References CSCTriggerMapping::addRecord(), makeMuonMisalignmentScenario::endcap, Exception, ntuplemaker::fill, edm::ParameterSet::getParameter(), LogDebug, m_maxBX, m_minBX, mapping, csctfunpacker_cfi::mappingFile, producer, Raw_token, slot2sector, relativeConstraints::station, AlCaHLTBitMon_QueryRunRegistry::string, and swapME1strips.

34  : edm::stream::EDProducer<>(), mapping(nullptr) {
35  LogDebug("CSCTFUnpacker|ctor") << "Started ...";
36 
37  // Edges of the time window, which LCTs are put into (unlike tracks, which are always centred around 0):
38  m_minBX = pset.getParameter<int>("MinBX"); //3
39  m_maxBX = pset.getParameter<int>("MaxBX"); //9
40 
41  // Swap: if(swapME1strips && me1b && !zplus) strip = 65 - strip; // 1-64 -> 64-1 :
42  swapME1strips = pset.getParameter<bool>("swapME1strips");
43 
44  // Initialize slot<->sector assignment
45  slot2sector = pset.getParameter<std::vector<int>>("slot2sector");
46  LogDebug("CSCTFUnpacker|ctor") << "Verifying slot<->sector map from 'vint32 slot2sector'";
47  for (int slot = 0; slot < 22; slot++)
48  if (slot2sector[slot] < 0 || slot2sector[slot] > 12)
49  throw cms::Exception("Invalid configuration") << "CSCTFUnpacker: sector index is set out of range (slot2sector["
50  << slot << "]=" << slot2sector[slot] << ", should be [0-12])";
51  // Just for safety (in case of bad data):
52  slot2sector.resize(32);
53 
54  // As we use standard CSC digi containers, we have to initialize mapping:
55  std::string mappingFile = pset.getParameter<std::string>("mappingFile");
56  if (mappingFile.length()) {
57  LogDebug("CSCTFUnpacker|ctor") << "Define ``mapping'' only if you want to screw up real geometry";
58  mapping = new CSCTriggerMappingFromFile(mappingFile);
59  } else {
60  LogDebug("CSCTFUnpacker|ctor") << "Generating default hw<->geometry mapping";
61  class M : public CSCTriggerSimpleMapping {
62  void fill(void) override {}
63  };
64  mapping = new M();
65  for (int endcap = 1; endcap <= 2; endcap++)
66  for (int station = 1; station <= 4; station++)
67  for (int sector = 1; sector <= 6; sector++)
68  for (int csc = 1; csc <= 9; csc++) {
69  if (station == 1) {
70  mapping->addRecord(endcap, station, sector, 1, csc, endcap, station, sector, 1, csc);
71  mapping->addRecord(endcap, station, sector, 2, csc, endcap, station, sector, 2, csc);
72  } else
73  mapping->addRecord(endcap, station, sector, 0, csc, endcap, station, sector, 0, csc);
74  }
75  }
76 
77  producer = pset.getParameter<edm::InputTag>("producer");
78 
79  produces<CSCCorrelatedLCTDigiCollection>();
80  produces<L1CSCTrackCollection>();
81  produces<L1CSCStatusDigiCollection>();
82  produces<CSCTriggerContainer<csctf::TrackStub>>("DT");
83 
84  Raw_token = consumes<FEDRawDataCollection>(producer);
85 }
#define LogDebug(id)
T getParameter(std::string const &) const
edm::InputTag producer
Definition: CSCTFUnpacker.h:36
edm::EDGetTokenT< FEDRawDataCollection > Raw_token
Definition: CSCTFUnpacker.h:38
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: CSCTFUnpacker.h:33
Definition: L1Track.h:19
CSCTriggerMapping * mapping
Definition: CSCTFUnpacker.h:27
CSCTFUnpacker::~CSCTFUnpacker ( void  )
override

Definition at line 87 of file CSCTFUnpacker.cc.

References mapping.

87  {
88  if (mapping)
89  delete mapping;
90 }
CSCTriggerMapping * mapping
Definition: CSCTFUnpacker.h:27

Member Function Documentation

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

Definition at line 92 of file CSCTFUnpacker.cc.

References L1CSCSPStatusDigi::af, CSCSPRecord::AFs(), newFWLiteAna::base, L1CSCSPStatusDigi::bx, CSCSPHeader::BXN(), CSCSPRecord::BXs(), CSCSPEvent::counters(), FEDRawData::data(), TauDecayModes::dec, CSCTriggerMapping::detId(), CSCSPHeader::endcap(), makeMuonMisalignmentScenario::endcap, FEDRawDataCollection::FEDData(), PixelSLinkDataInputSource_cfi::fedid, L1CSCSPStatusDigi::fmm_status, edm::Event::getByToken(), CSCSPEvent::header(), triggerObjects_cff::id, createfilelist::int, CSCSPHeader::L1A(), L1CSCSPStatusDigi::l1a_bxn, CSCSPRecord::LCT(), MainPageGenerator::link, L1CSCSPStatusDigi::link_status, m_maxBX, m_minBX, mapping, FEDNumbering::MAXCSCTFFEDID, CSCSPRecord::mbStubs(), FEDNumbering::MINCSCTFFEDID, eostools::move(), L1CSCSPStatusDigi::mpc_link_id, CSCSPHeader::nTBINs(), L1CSCSPStatusDigi::orbit_cnt, CSCSPCounters::orbit_counter(), topSingleLeptonDQM_PU_cfi::pattern, CSCSPRecord::ptSpy(), edm::Event::put(), qcdUeDQM_cfi::quality, Raw_token, CSCSPEvent::record(), L1CSCSPStatusDigi::se, CSCSPHeader::sector(), CSCSPRecord::SEs(), FEDRawData::size(), CSCSPHeader::slot(), slot2sector, L1CSCSPStatusDigi::sm, CSCSPRecord::SMs(), L1CSCSPStatusDigi::sp_slot, CSCTFEvent::SPs_fast(), relativeConstraints::station, mps_update::status, CSCSPHeader::status(), digitizers_cfi::strip, swapME1strips, tfEvent, HLT_2018_cff::track, L1CSCSPStatusDigi::track_cnt, CSCSPCounters::track_counter(), PDWG_EXOHSCP_cff::tracks, CSCSPRecord::tracks(), CSCTFEvent::unpack(), L1CSCSPStatusDigi::vp, CSCSPRecord::VPs(), and cms::Exception::what().

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

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

Member Data Documentation

int CSCTFUnpacker::m_maxBX
private

Definition at line 24 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), and produce().

int CSCTFUnpacker::m_minBX
private

Definition at line 24 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), and produce().

CSCTriggerMapping* CSCTFUnpacker::mapping
private

Definition at line 27 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), produce(), and ~CSCTFUnpacker().

edm::InputTag CSCTFUnpacker::producer
private

Definition at line 36 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker().

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

Definition at line 38 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), and produce().

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

Definition at line 33 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), and produce().

bool CSCTFUnpacker::swapME1strips
private

Definition at line 25 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), and produce().

CSCTFEvent CSCTFUnpacker::tfEvent
private

Definition at line 29 of file CSCTFUnpacker.h.

Referenced by produce().