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 
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["<<slot<<"]="<<slot2sector[slot]<<", should be [0-12])";
50  // Just for safety (in case of bad data):
51  slot2sector.resize(32);
52 
53  // As we use standard CSC digi containers, we have to initialize mapping:
54  std::string mappingFile = pset.getParameter<std::string>("mappingFile");
55  if( mappingFile.length() ){
56  LogDebug("CSCTFUnpacker|ctor") << "Define ``mapping'' only if you want to screw up real geometry";
57  mapping = new CSCTriggerMappingFromFile(mappingFile);
58  } else {
59  LogDebug("CSCTFUnpacker|ctor") << "Generating default hw<->geometry mapping";
60  class M: public CSCTriggerSimpleMapping{ void fill(void) override{} };
61  mapping = new M();
62  for(int endcap=1; endcap<=2; endcap++)
63  for(int station=1; station<=4; station++)
64  for(int sector=1; sector<=6; sector++)
65  for(int csc=1; csc<=9; csc++){
66  if( station==1 ){
67  mapping->addRecord(endcap,station,sector,1,csc,endcap,station,sector,1,csc);
68  mapping->addRecord(endcap,station,sector,2,csc,endcap,station,sector,2,csc);
69  } else
70  mapping->addRecord(endcap,station,sector,0,csc,endcap,station,sector,0,csc);
71  }
72  }
73 
74  producer = pset.getParameter<edm::InputTag>("producer");
75 
76  produces<CSCCorrelatedLCTDigiCollection>();
77  produces<L1CSCTrackCollection>();
78  produces<L1CSCStatusDigiCollection>();
79  produces<CSCTriggerContainer<csctf::TrackStub> >("DT");
80 
81  Raw_token = consumes<FEDRawDataCollection>(producer);
82 
83 }
84 
86  if( mapping ) delete mapping;
87 }
88 
90  // Get a handle to the FED data collection
92  e.getByToken(Raw_token,rawdata);
93 
94  // create the collection of CSC wire and strip digis as well as of DT stubs, which we receive from DTTF
95  auto LCTProduct = std::make_unique<CSCCorrelatedLCTDigiCollection>();
96  auto trackProduct = std::make_unique<L1CSCTrackCollection>();
97  auto statusProduct = std::make_unique<L1CSCStatusDigiCollection>();
98  auto dtProduct = std::make_unique<CSCTriggerContainer<csctf::TrackStub>>();
99 
100  for(int fedid=FEDNumbering::MINCSCTFFEDID; fedid<=FEDNumbering::MAXCSCTFFEDID; fedid++){
101  const FEDRawData& fedData = rawdata->FEDData(fedid);
102  if( fedData.size()==0 ) continue;
103  //LogDebug("CSCTFUnpacker|produce");
104  //if( monitor ) monitor->process((unsigned short*)fedData.data());
105  unsigned int unpacking_status = tfEvent.unpack((unsigned short*)fedData.data(),fedData.size()/2);
106  if( unpacking_status==0 ){
107  // There may be several SPs in event
108  std::vector<const CSCSPEvent*> SPs = tfEvent.SPs_fast();
109  // Cycle over all of them
110  for(std::vector<const CSCSPEvent *>::const_iterator spItr=SPs.begin(); spItr!=SPs.end(); spItr++){
111  const CSCSPEvent *sp = *spItr;
112 
114  status.sp_slot = sp->header().slot();
115  status.l1a_bxn = sp->header().BXN();
116  status.fmm_status = sp->header().status();
117  status.track_cnt = sp->counters().track_counter();
118  status.orbit_cnt = sp->counters().orbit_counter();
119 
120  // Finds central LCT BX
121  // assumes window is odd number of bins
122  int central_lct_bx = (m_maxBX + m_minBX)/2;
123 
124  // Find central SP BX
125  // assumes window is odd number of bins
126  int central_sp_bx = int(sp->header().nTBINs()/2);
127 
128  for(unsigned int tbin=0; tbin<sp->header().nTBINs(); tbin++){
129 
130  status.se |= sp->record(tbin).SEs();
131  status.sm |= sp->record(tbin).SMs();
132  status.bx |= sp->record(tbin).BXs();
133  status.af |= sp->record(tbin).AFs();
134  status.vp |= sp->record(tbin).VPs();
135 
136  for(unsigned int FPGA=0; FPGA<5; FPGA++)
137  for(unsigned int MPClink=0; MPClink<3; ++MPClink){
138  std::vector<CSCSP_MEblock> lct = sp->record(tbin).LCT(FPGA,MPClink);
139  if( lct.empty() ) continue;
140 
141  status.link_status[lct[0].spInput()] |=
142  (1<<lct[0].receiver_status_frame1())|
143  (1<<lct[0].receiver_status_frame2())|
144  ((lct[0].aligment_fifo()?1:0)<<4);
145  status.mpc_link_id |= (lct[0].link()<<2)|lct[0].mpc();
146 
147  int station = ( FPGA ? FPGA : 1 );
148  int endcap=0, sector=0;
149  if( slot2sector[sp->header().slot()] ){
150  endcap = slot2sector[sp->header().slot()]/7 + 1;
151  sector = slot2sector[sp->header().slot()];
152  if( sector>6 ) sector -= 6;
153  } else {
154  endcap = (sp->header().endcap()?1:2);
155  sector = sp->header().sector();
156  }
157  int subsector = ( FPGA>1 ? 0 : FPGA+1 );
158  int cscid = lct[0].csc() ;
159 
160  try{
161  CSCDetId id = mapping->detId(endcap,station,sector,subsector,cscid,0);
162  // corrlcts now have no layer associated with them
163  LCTProduct->insertDigi(id,
165  0,lct[0].vp(),lct[0].quality(),lct[0].wireGroup(),
166  (swapME1strips && cscid<=3 && station==1 && endcap==2 && lct[0].strip()<65 ? 65 - lct[0].strip() : lct[0].strip() ),
167  lct[0].pattern(),lct[0].l_r(),
168  (lct[0].tbin()+(central_lct_bx-central_sp_bx)),
169  lct[0].link(), lct[0].BXN(), 0, cscid )
170  );
171  } catch(cms::Exception &e) {
172  edm::LogInfo("CSCTFUnpacker|produce") << e.what() << "Not adding digi to collection in event "
173  <<sp->header().L1A()<<" (endcap="<<endcap<<",station="<<station<<",sector="<<sector<<",subsector="<<subsector<<",cscid="<<cscid<<",spSlot="<<sp->header().slot()<<")";
174  }
175 
176  }
177 
178  std::vector<CSCSP_MBblock> mbStubs = sp->record(tbin).mbStubs();
179  for(std::vector<CSCSP_MBblock>::const_iterator iter=mbStubs.begin(); iter!=mbStubs.end(); iter++){
180  int endcap, sector;
181  if( slot2sector[sp->header().slot()] ){
182  endcap = slot2sector[sp->header().slot()]/7 + 1;
183  sector = slot2sector[sp->header().slot()];
184  if( sector>6 ) sector -= 6;
185  } else {
186  endcap = (sp->header().endcap()?1:2);
187  sector = sp->header().sector();
188  }
189  const unsigned int csc2dt[6][2] = {{2,3},{4,5},{6,7},{8,9},{10,11},{12,1}};
190  DTChamberId id((endcap==1?2:-2),1, csc2dt[sector-1][iter->id()-1]);
191  CSCCorrelatedLCTDigi base(0,iter->vq(),iter->quality(),iter->cal(),iter->flag(),iter->bc0(),iter->phi_bend(),tbin+(central_lct_bx-central_sp_bx),iter->id(),iter->bxn(),iter->timingError(),iter->BXN());
192  csctf::TrackStub dtStub(base,id,iter->phi(),0);
193  dtProduct->push_back(dtStub);
194  }
195 
196  std::vector<CSCSP_SPblock> tracks = sp->record(tbin).tracks();
197  unsigned int trkNumber=0;
198  for(std::vector<CSCSP_SPblock>::const_iterator iter=tracks.begin(); iter!=tracks.end(); iter++,trkNumber++){
200  if( slot2sector[sp->header().slot()] ){
201  track.first.m_endcap = slot2sector[sp->header().slot()]/7 + 1;
202  track.first.m_sector = slot2sector[sp->header().slot()];
203  if( track.first.m_sector>6 ) track.first.m_sector -= 6;
204  } else {
205  track.first.m_endcap = (sp->header().endcap()?1:2);
206  track.first.m_sector = sp->header().sector();
207  }
208 
209  track.first.m_lphi = iter->phi();
210  track.first.m_ptAddress = iter->ptLUTaddress();
211  track.first.m_fr = iter->f_r();
212  track.first.m_ptAddress|=(iter->f_r() << 21);
213 
214  track.first.setStationIds(iter->ME1_id(),iter->ME2_id(),iter->ME3_id(),iter->ME4_id(),iter->MB_id());
215  track.first.setTbins(iter->ME1_tbin(), iter->ME2_tbin(), iter->ME3_tbin(), iter->ME4_tbin(), iter->MB_tbin() );
216  track.first.setBx(iter->tbin()-central_sp_bx);
217  track.first.setBits(iter->syncErr(), iter->bx0(), iter->bc0());
218 
219  track.first.setLocalPhi(iter->phi());
220  track.first.setEtaPacked(iter->eta());
221  track.first.setChargePacked(iter->charge());
222 
223  track.first.m_output_link = iter->id();
224  if( track.first.m_output_link ){
225  track.first.m_rank = (iter->f_r()?sp->record(tbin).ptSpy()&0x7F:(sp->record(tbin).ptSpy()&0x7F00)>>8);
226  track.first.setChargeValidPacked((iter->f_r()?(sp->record(tbin).ptSpy()&0x80)>>8:(sp->record(tbin).ptSpy()&0x8000)>>15));
227  } else {
228  track.first.m_rank = 0;
229  track.first.setChargeValidPacked(0);
230  }
231  track.first.setFineHaloPacked(iter->halo());
232 
233  track.first.m_winner = iter->MS_id()&(1<<trkNumber);
234 
235  std::vector<CSCSP_MEblock> lcts = iter->LCTs();
236  for(std::vector<CSCSP_MEblock>::const_iterator lct=lcts.begin(); lct!=lcts.end(); lct++){
237  int station = ( lct->spInput()>6 ? (lct->spInput()-1)/3 : 1 );
238  int subsector = ( lct->spInput()>6 ? 0 : (lct->spInput()-1)/3 + 1 );
239  try{
240  CSCDetId id = mapping->detId(track.first.m_endcap,station,track.first.m_sector,subsector,lct->csc(),0);
241  track.second.insertDigi(id,
243  0,lct->vp(),lct->quality(),lct->wireGroup(),
244  (swapME1strips && lct->csc()<=3 && station==1 && track.first.m_endcap==2 && lct[0].strip()<65 ? 65 - lct[0].strip() : lct[0].strip() ),
245  lct->pattern(),lct->l_r(),
246  (lct->tbin()+(central_lct_bx-central_sp_bx)),
247  lct->link(), lct->BXN(), 0, lct->csc() )
248  );
249  } catch(cms::Exception &e) {
250  edm::LogInfo("CSCTFUnpacker|produce") << e.what() << "Not adding track digi to collection in event"
251  <<sp->header().L1A()<<" (endcap="<<track.first.m_endcap<<",station="<<station<<",sector="<<track.first.m_sector<<",subsector="<<subsector<<",cscid="<<lct->csc()<<",spSlot="<<sp->header().slot()<<")";
252  }
253  }
254 
255  std::vector<CSCSP_MBblock> mbStubs = iter->dtStub();
256  for(std::vector<CSCSP_MBblock>::const_iterator iter=mbStubs.begin(); iter!=mbStubs.end(); iter++){
257  CSCDetId id = mapping->detId(track.first.m_endcap,1,track.first.m_sector,iter->id(),1,0);
258  track.second.insertDigi(id,
259  CSCCorrelatedLCTDigi(iter->phi(),iter->vq(),iter->quality()+100,iter->cal(),iter->flag(),iter->bc0(),iter->phi_bend(),tbin+(central_lct_bx-central_sp_bx),iter->id(),iter->bxn(),iter->timingError(),iter->BXN())
260  );
261  }
262 
263  trackProduct->push_back( track );
264  }
265  }
266  statusProduct->second.push_back( status );
267  }
268  } else {
269  edm::LogError("CSCTFUnpacker|produce")<<" problem of unpacking TF event: 0x"<<std::hex<<unpacking_status<<std::dec<<" code";
270  }
271 
272  statusProduct->first = unpacking_status;
273 
274  } //end of fed cycle
275  e.put(std::move(dtProduct),"DT");
276  e.put(std::move(LCTProduct)); // put processed lcts into the event.
277  e.put(std::move(trackProduct));
278  e.put(std::move(statusProduct));
279 }
#define LogDebug(id)
unsigned int L1A(void) const
Definition: CSCSPHeader.h:75
T getParameter(std::string const &) const
unsigned int unpack(const unsigned short *buf, unsigned int length)
Definition: CSCTFEvent.cc:6
std::vector< CSCSP_MBblock > mbStubs(void) const
Definition: CSCSPRecord.cc:100
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
CSCTFUnpacker(const edm::ParameterSet &pset)
unsigned int SEs(void) const
Definition: CSCSPRecord.h:84
unsigned short l1a_bxn
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
unsigned long orbit_cnt
std::vector< CSCSP_MEblock > LCT(unsigned int mpc, unsigned int link) const
Definition: CSCSPRecord.cc:85
#define nullptr
unsigned int AFs(void) const
Definition: CSCSPRecord.h:86
edm::InputTag producer
Definition: CSCTFUnpacker.h:37
char const * what() const override
Definition: Exception.cc:103
unsigned long track_cnt
edm::EDGetTokenT< FEDRawDataCollection > Raw_token
Definition: CSCTFUnpacker.h:39
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:47
void addRecord(int rendcap, int rstation, int rsector, int rsubsector, int rcscid, int cendcap, int cstation, int csector, int csubsector, int ccscid)
unsigned int nTBINs(void) const
Definition: CSCSPHeader.h:92
~CSCTFUnpacker(void) override
int orbit_counter(void) const
Definition: CSCSPCounters.h:32
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void produce(edm::Event &e, const edm::EventSetup &c) override
std::vector< CSCSP_SPblock > tracks(void) const
Definition: CSCSPRecord.cc:92
const CSCSPRecord & record(unsigned int tbin) const
Definition: CSCSPEvent.h:21
int track_counter(void) const
Definition: CSCSPCounters.h:31
std::vector< int > slot2sector
Definition: CSCTFUnpacker.h:34
unsigned int SMs(void) const
Definition: CSCSPRecord.h:85
unsigned int sector(void) const
Definition: CSCSPHeader.h:80
unsigned short sm
unsigned int BXs(void) const
Definition: CSCSPRecord.h:87
base
Make Sure CMSSW is Setup ##.
unsigned short sp_slot
Definition: L1Track.h:19
const CSCSPCounters & counters(void) const
Definition: CSCSPEvent.h:18
unsigned short fmm_status
unsigned int BXN(void) const
Definition: CSCSPHeader.h:74
unsigned int endcap(void) const
Definition: CSCSPHeader.h:84
CSCTriggerMapping * mapping
Definition: CSCTFUnpacker.h:28
unsigned short se
std::vector< const CSCSPEvent * > SPs_fast(void) const
Definition: CSCTFEvent.h:24
const CSCSPHeader & header(void) const
Definition: CSCSPEvent.h:17
HLT enums.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
std::pair< csc::L1Track, CSCCorrelatedLCTDigiCollection > L1CSCTrack
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:30
unsigned short mpc_link_id
def move(src, dest)
Definition: eostools.py:511
unsigned int slot(void) const
Definition: CSCSPHeader.h:77
unsigned int status(void) const
Definition: CSCSPHeader.h:90