CMS 3D CMS Logo

CSCTFUnpacker.cc
Go to the documentation of this file.
2 
3 //Framework stuff
7 
8 //Digi
13 
14 //Digi collections
19 
20 //Unique key
23 
24 //Don't know what
27 
29 //#include <DataFormats/MuonDetId/interface/CSCTriggerNumbering.h>
30 
31 //#include <iostream>
32 #include <sstream>
33 
34 CSCTFUnpacker::CSCTFUnpacker(const edm::ParameterSet& pset) : 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";
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 }
86 
88  if (mapping)
89  delete mapping;
90 }
91 
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 }
CSCTFUnpacker.h
CSCTriggerMapping::detId
CSCDetId detId(int endcap, int station, int sector, int subsector, int cscid, int layer=0) const
Definition: CSCTriggerMapping.cc:25
CSCSPRecord::BXs
unsigned int BXs(void) const
Definition: CSCSPRecord.h:87
Handle.h
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
CSCSPRecord::ptSpy
unsigned int ptSpy(void) const
Definition: CSCSPRecord.h:89
CSCTFUnpacker::m_maxBX
int m_maxBX
Definition: CSCTFUnpacker.h:24
CSCCorrelatedLCTDigiCollection.h
CSCSPRecord::tracks
std::vector< CSCSP_SPblock > tracks(void) const
Definition: CSCSPRecord.cc:104
CSCSPRecord::AFs
unsigned int AFs(void) const
Definition: CSCSPRecord.h:86
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
MessageLogger.h
CSCSPHeader::L1A
unsigned int L1A(void) const
Definition: CSCSPHeader.h:76
CSCSPEvent::header
const CSCSPHeader & header(void) const
Definition: CSCSPEvent.h:17
L1CSCTrack
std::pair< csc::L1Track, CSCCorrelatedLCTDigiCollection > L1CSCTrack
Definition: L1CSCTrackCollection.h:7
CSCTFUnpacker::~CSCTFUnpacker
~CSCTFUnpacker(void) override
Definition: CSCTFUnpacker.cc:87
MainPageGenerator.link
link
Definition: MainPageGenerator.py:271
CSCTFUnpacker::swapME1strips
bool swapME1strips
Definition: CSCTFUnpacker.h:25
mps_update.status
status
Definition: mps_update.py:69
CSCTFUnpacker::CSCTFUnpacker
CSCTFUnpacker(const edm::ParameterSet &pset)
Definition: CSCTFUnpacker.cc:34
relativeConstraints.station
station
Definition: relativeConstraints.py:67
edm
HLT enums.
Definition: AlignableModifier.h:19
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
CSCSPHeader::status
unsigned int status(void) const
Definition: CSCSPHeader.h:95
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
CSCSPRecord::SEs
unsigned int SEs(void) const
Definition: CSCSPRecord.h:84
CSCSPEvent::record
const CSCSPRecord & record(unsigned int tbin) const
Definition: CSCSPEvent.h:21
CSCTriggerMappingFromFile
Definition: CSCTriggerMappingFromFile.h:13
CSCSPEvent
Definition: CSCSPEvent.h:9
CSCCorrelatedLCTDigi.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
makeMuonMisalignmentScenario.endcap
endcap
Definition: makeMuonMisalignmentScenario.py:320
edm::Handle
Definition: AssociativeIterator.h:50
CSCSPHeader::endcap
unsigned int endcap(void) const
Definition: CSCSPHeader.h:87
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
csctf::TrackStub
Definition: TrackStub.h:22
CSCDetId.h
FEDRawData
Definition: FEDRawData.h:19
L1CSCStatusDigiCollection.h
csc
Definition: L1Track.h:19
L1Track.h
CSCTriggerMappingFromFile.h
Service.h
CSCSPCounters::orbit_counter
int orbit_counter(void) const
Definition: CSCSPCounters.h:34
CSCTFUnpacker::tfEvent
CSCTFEvent tfEvent
Definition: CSCTFUnpacker.h:29
CSCTFUnpacker::mapping
CSCTriggerMapping * mapping
Definition: CSCTFUnpacker.h:27
DTChamberId.h
CSCSPEvent::counters
const CSCSPCounters & counters(void) const
Definition: CSCSPEvent.h:18
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
CSCTriggerMapping::addRecord
void addRecord(int rendcap, int rstation, int rsector, int rsubsector, int rcscid, int cendcap, int cstation, int csector, int csubsector, int ccscid)
Definition: CSCTriggerMapping.cc:31
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
CSCTFEvent::SPs_fast
std::vector< const CSCSPEvent * > SPs_fast(void) const
Definition: CSCTFEvent.h:32
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
CSCTFUnpacker::m_minBX
int m_minBX
Definition: CSCTFUnpacker.h:24
CSCSPHeader::sector
unsigned int sector(void) const
Definition: CSCSPHeader.h:81
Event.h
L1CSCTrackCollection.h
CSCTriggerContainer.h
CSCDetId
Definition: CSCDetId.h:26
L1CSCSPStatusDigi.h
createfilelist.int
int
Definition: createfilelist.py:10
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
CSCSPHeader::BXN
unsigned int BXN(void) const
Definition: CSCSPHeader.h:75
CSCSPRecord::VPs
unsigned int VPs(void) const
Definition: CSCSPRecord.h:83
edm::EventSetup
Definition: EventSetup.h:57
CSCSPHeader::nTBINs
unsigned int nTBINs(void) const
Definition: CSCSPHeader.h:97
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
PixelSLinkDataInputSource_cfi.fedid
fedid
Definition: PixelSLinkDataInputSource_cfi.py:6
csctfunpacker_cfi.mappingFile
mappingFile
Definition: csctfunpacker_cfi.py:14
CSCTFEvent::unpack
unsigned int unpack(const unsigned short *buf, unsigned int length)
Definition: CSCTFEvent.cc:6
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
CSCTriggerSimpleMapping
Definition: CSCTriggerSimpleMapping.h:13
CSCTFUnpacker::producer
edm::InputTag producer
Definition: CSCTFUnpacker.h:36
CSCTFUnpacker::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: CSCTFUnpacker.cc:92
eostools.move
def move(src, dest)
Definition: eostools.py:511
FEDNumbering::MAXCSCTFFEDID
Definition: FEDNumbering.h:54
qcdUeDQM_cfi.quality
quality
Definition: qcdUeDQM_cfi.py:31
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
Exception
Definition: hltDiff.cc:246
CSCSPRecord::LCT
std::vector< CSCSP_MEblock > LCT(unsigned int mpc, unsigned int link) const
Definition: CSCSPRecord.cc:96
CSCSPRecord::SMs
unsigned int SMs(void) const
Definition: CSCSPRecord.h:85
CSCSPRecord::mbStubs
std::vector< CSCSP_MBblock > mbStubs(void) const
Definition: CSCSPRecord.cc:115
CSCTFUnpacker::slot2sector
std::vector< int > slot2sector
Definition: CSCTFUnpacker.h:33
FEDNumbering::MINCSCTFFEDID
Definition: FEDNumbering.h:53
cms::Exception
Definition: Exception.h:70
DTChamberId
Definition: DTChamberId.h:14
CSCTFMonitorInterface.h
CSCSPHeader::slot
unsigned int slot(void) const
Definition: CSCSPHeader.h:78
edm::Event
Definition: Event.h:73
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
TrackStub.h
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:29
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
edm::InputTag
Definition: InputTag.h:15
CSCTFUnpacker::Raw_token
edm::EDGetTokenT< FEDRawDataCollection > Raw_token
Definition: CSCTFUnpacker.h:38
CSCCorrelatedLCTDigi
Definition: CSCCorrelatedLCTDigi.h:19
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
L1CSCSPStatusDigi
Definition: L1CSCSPStatusDigi.h:8
CSCSPCounters::track_counter
int track_counter(void) const
Definition: CSCSPCounters.h:33
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37