CMS 3D CMS Logo

OMTFinputMaker.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <vector>
3 #include <iostream>
4 #include <algorithm>
5 
10 
18 
24 void OMTFinputMaker::initialize(const edm::EventSetup& es, const OMTFConfiguration *omtfConfig){
25 
27 
28  myOmtfConfig = omtfConfig;
29 
30 }
36 bool OMTFinputMaker::acceptDigi(uint32_t rawId,
37  unsigned int iProcessor,
39 
40  unsigned int aMin = myOmtfConfig->getBarrelMin()[iProcessor];
41  unsigned int aMax = myOmtfConfig->getBarrelMax()[iProcessor];
42  unsigned int aSector = 99;
43 
45  DetId detId(rawId);
46  if (detId.det() != DetId::Muon)
47  edm::LogError("Critical OMTFinputMaker") << "PROBLEM: hit in unknown Det, detID: "<<detId.det()<<std::endl;
48  switch (detId.subdetId()) {
49  case MuonSubdetId::RPC: {
50  RPCDetId aId(rawId);
51 
53  if(type==l1t::tftype::omtf_pos &&
54  (aId.region()<0 ||
55  (aId.region()==0 && aId.ring()!=2) ||
56  (aId.region()==0 && aId.station()==4) ||
57  (aId.region()==0 && aId.station()==2 && aId.layer()==2 && aId.roll()==1) ||
58  (aId.region()==0 && aId.station()==3 && aId.roll()==1) ||
59  (aId.region()==1 && aId.station()==4) ||
61  (aId.region()==1 && aId.station()>0 && aId.ring()<3))
62  ) return false;
63 
64  if(type==l1t::tftype::omtf_neg &&
65  (aId.region()>0 ||
66  (aId.region()==0 && aId.ring()!=-2) ||
67  (aId.region()==0 && aId.station()==4) ||
68  (aId.region()==0 && aId.station()==2 && aId.layer()==2 && aId.roll()==1) ||
69  (aId.region()==0 && aId.station()==3 && aId.roll()==1) ||
70  (aId.region()==-1 && aId.station()==4) ||
71  //RPC RE1/2 temporarily not used (aId.region()==1 && aId.station()==1 && aId.ring()<2) ||
72  (aId.region()==-1 && aId.station()>0 && aId.ring()<3))
73  ) return false;
74 
75  if(type==l1t::tftype::bmtf && aId.region()!=0) return false;
76 
77  if(type==l1t::tftype::emtf_pos &&
78  (aId.region()<=0 ||
79  (aId.station()==1 && aId.ring()==3))) return false;
80  if(type==l1t::tftype::emtf_neg &&
81  (aId.region()>=0 ||
82  (aId.station()==1 && aId.ring()==3))) return false;
84  if(aId.region()==0) aSector = aId.sector();
85  if(aId.region()!=0){
86  aSector = (aId.sector()-1)*6+aId.subsector();
87  aMin = myOmtfConfig->getEndcap10DegMin()[iProcessor];
88  aMax = myOmtfConfig->getEndcap10DegMax()[iProcessor];
89  }
90 
91  break;
92  }
93  case MuonSubdetId::DT: {
94  DTChamberId dt(rawId);
95 
96  if(type==l1t::tftype::omtf_pos && dt.wheel()!=2) return false;
97  if(type==l1t::tftype::omtf_neg && dt.wheel()!=-2) return false;
98  if(type==l1t::tftype::emtf_pos || type==l1t::tftype::emtf_neg) return false;
99 
100  aSector = dt.sector();
101  break;
102  }
103  case MuonSubdetId::CSC: {
104 
105  CSCDetId csc(rawId);
106  if(type==l1t::tftype::omtf_pos &&
107  (csc.endcap()==2 || csc.ring()==1 || csc.station()==4)) return false;
108  if(type==l1t::tftype::omtf_neg &&
109  (csc.endcap()==1 || csc.ring()==1 || csc.station()==4)) return false;
110 
111  if(type==l1t::tftype::emtf_pos &&
112  (csc.endcap()==2 || (csc.station()==1 && csc.ring()==3))
113  ) return false;
114  if(type==l1t::tftype::emtf_neg &&
115  (csc.endcap()==1 || (csc.station()==1 && csc.ring()==3))
116  ) return false;
117 
118  aSector = csc.chamber();
119  aMin = myOmtfConfig->getEndcap10DegMin()[iProcessor];
120  aMax = myOmtfConfig->getEndcap10DegMax()[iProcessor];
121 
122  if( (type==l1t::tftype::emtf_pos || type==l1t::tftype::emtf_neg) &&
123  csc.station()>1 && csc.ring()==1){
124  aMin = myOmtfConfig->getEndcap20DegMin()[iProcessor];
125  aMax = myOmtfConfig->getEndcap20DegMax()[iProcessor];
126  }
127  break;
128  }
129  }
130 
131  if(aMax>aMin && aSector>=aMin && aSector<=aMax) return true;
132  if(aMax<aMin && (aSector>=aMin || aSector<=aMax)) return true;
133 
134  return false;
135 }
138 unsigned int OMTFinputMaker::getInputNumber(unsigned int rawId,
139  unsigned int iProcessor,
140  l1t::tftype type){
141 
142  unsigned int iInput = 99;
143  unsigned int aSector = 99;
144  int aMin = myOmtfConfig->getBarrelMin()[iProcessor];
145  int iRoll = 1;
146  int nInputsPerSector = 2;
147 
148  DetId detId(rawId);
149  if (detId.det() != DetId::Muon) edm::LogError("Critical OMTFinputMaker") << "PROBLEM: hit in unknown Det, detID: "<<detId.det()<<std::endl;
150  switch (detId.subdetId()) {
151  case MuonSubdetId::RPC: {
152  RPCDetId rpc(rawId);
153  if(rpc.region()==0){
154  nInputsPerSector = 4;
155  aSector = rpc.sector();
158  if(iProcessor==5 && aSector<3) aMin = -1;
159  //Use division into rolls
160  iRoll = rpc.roll();
163  if(rpc.station()==2 && rpc.layer()==2 && rpc.roll()==2) iRoll = 1;
165  if(rpc.station()==3){
166  iRoll = 1;
167  nInputsPerSector = 2;
168  }
170  if(type==l1t::tftype::bmtf)iRoll = 1;
171  }
172  if(rpc.region()!=0){
173  aSector = (rpc.sector()-1)*6+rpc.subsector();
174  aMin = myOmtfConfig->getEndcap10DegMin()[iProcessor];
177  if(iProcessor==5 && aSector<5) aMin = -4;
178  }
179  break;
180  }
181  case MuonSubdetId::DT: {
182  DTChamberId dt(rawId);
183  aSector = dt.sector();
186  if(iProcessor==5 && aSector<3) aMin = -1;
187  break;
188  }
189  case MuonSubdetId::CSC: {
190  CSCDetId csc(rawId);
191  aSector = csc.chamber();
192  aMin = myOmtfConfig->getEndcap10DegMin()[iProcessor];
195  if(iProcessor==5 && aSector<5) aMin = -4;
199  if( (type==l1t::tftype::emtf_pos || type==l1t::tftype::emtf_neg) &&
200  csc.station()>1 && csc.ring()==1){
201  aMin = myOmtfConfig->getEndcap20DegMin()[iProcessor];
202  if(iProcessor==5 && aSector<3) aMin = -2;
203  }
204  break;
205  }
206  }
207 
209  iInput = (aSector - aMin)*nInputsPerSector;
211  iInput+=iRoll-1;
212 
213  return iInput;
214 }
218  const L1MuDTChambThContainer *dtThDigis,
219  unsigned int iProcessor,
220  l1t::tftype type, int bxTrg)
221 {
222 
224  if(!dtPhDigis) return result;
225 
226  for (const auto digiIt: *dtPhDigis->getContainer()) {
227 
228  DTChamberId detid(digiIt.whNum(),digiIt.stNum(),digiIt.scNum()+1);
229 
231  if(!acceptDigi(detid.rawId(), iProcessor, type)) continue;
232 
237  // FIXME (MK): at least Ts2Tag selection is not correct! Check it
238 // if (digiIt.bxNum()!= 0 || digiIt.BxCnt()!= 0 || digiIt.Ts2Tag()!= 0 || digiIt.code()<4) continue;
239 
240  if (digiIt.bxNum()!= bxTrg) continue;
241 
242  if (myOmtfConfig->fwVersion() <= 4) {
243  if (digiIt.code() != 4 && digiIt.code() != 5 && digiIt.code() != 6) continue;
244  } else {
245  if (digiIt.code() != 2 && digiIt.code() != 3 && digiIt.code() != 4 && digiIt.code() != 5 && digiIt.code() != 6) continue;
246  }
247 
248  unsigned int hwNumber = myOmtfConfig->getLayerNumber(detid.rawId());
249  if(myOmtfConfig->getHwToLogicLayer().find(hwNumber)==myOmtfConfig->getHwToLogicLayer().end()) continue;
250 
251  auto iter = myOmtfConfig->getHwToLogicLayer().find(hwNumber);
252  unsigned int iLayer = iter->second;
253  int iPhi = myAngleConverter.getProcessorPhi(iProcessor, type, digiIt);
254  int iEta = myAngleConverter.getGlobalEta(detid.rawId(), digiIt, dtThDigis);
255  unsigned int iInput= getInputNumber(detid.rawId(), iProcessor, type);
256  bool allowOverwrite = false;
257  result.addLayerHit(iLayer,iInput,iPhi,iEta, allowOverwrite);
258  result.addLayerHit(iLayer+1,iInput,digiIt.phiB(),iEta, allowOverwrite);
259  }
260 
261  return result;
262 
263 }
267  unsigned int iProcessor,
268  l1t::tftype type, int bxTrg){
269 
271  if(!cscDigis) return result;
272 
273  auto chamber = cscDigis->begin();
274  auto chend = cscDigis->end();
275  for( ; chamber != chend; ++chamber ) {
276 
277  unsigned int rawid = (*chamber).first;
279  if(!acceptDigi(rawid, iProcessor, type)) continue;
280  auto digi = (*chamber).second.first;
281  auto dend = (*chamber).second.second;
282  for( ; digi != dend; ++digi ) {
283 
285  if (digi->getBX()-CSCConstants::LCT_CENTRAL_BX != bxTrg) continue;
286 
287  unsigned int hwNumber = myOmtfConfig->getLayerNumber(rawid);
288  if(myOmtfConfig->getHwToLogicLayer().find(hwNumber)==myOmtfConfig->getHwToLogicLayer().end()) continue;
289 
290  unsigned int iLayer = myOmtfConfig->getHwToLogicLayer().at(hwNumber);
291  int iPhi = myAngleConverter.getProcessorPhi(iProcessor, type, CSCDetId(rawid), *digi);
292  int iEta = myAngleConverter.getGlobalEta(rawid, *digi);
296  //if(abs(iEta)>1.26/2.61*240) continue;
297  //if (abs(iEta) > 115) continue;
298  unsigned int iInput= getInputNumber(rawid, iProcessor, type);
299 // std::cout <<" ADDING CSC hit, proc: "<<iProcessor<<" iPhi : " << iPhi <<" iEta: "<< iEta << std::endl;
300  bool allowOverwrite = false;
301  result.addLayerHit(iLayer,iInput,iPhi,iEta,allowOverwrite);
302  }
303  }
304  return result;
305 }
308 bool rpcPrimitiveCmp(const RPCDigi &a, const RPCDigi &b) { return a.strip() < b.strip(); };
312  unsigned int iProcessor,
313  l1t::tftype type, int bxTrg){
314 
316  if(!rpcDigis) return result;
317  std::stringstream str;
318 
319 // std::cout <<" RPC HITS, processor : " << iProcessor << std::endl;
320 
321  const RPCDigiCollection & rpcDigiCollection = *rpcDigis;
322  for (auto rollDigis : rpcDigiCollection) {
323  RPCDetId roll = rollDigis.first;
324  unsigned int rawid = roll.rawId();
325  int nClusters = 0;
326  if(!acceptDigi(rawid, iProcessor, type)) continue;
330 // for (auto tdigi = rollDigis.second.first; tdigi != rollDigis.second.second; tdigi++) { std::cout << "RPC DIGIS: " << roll.rawId()<< " "<<roll<<" digi: " << tdigi->strip() <<" bx: " << tdigi->bx() << std::endl; }
331  std::vector<RPCDigi> digisCopy;
332 // std::copy_if(rollDigis.second.first, rollDigis.second.second, std::back_inserter(digisCopy), [](const RPCDigi & aDigi){return (aDigi.bx()==0);} );
333  for (auto pDigi=rollDigis.second.first; pDigi != rollDigis.second.second; pDigi++) { if (pDigi->bx()==bxTrg) digisCopy.push_back( *pDigi); }
334  std::sort(digisCopy.begin(),digisCopy.end(),rpcPrimitiveCmp);
335  typedef std::pair<unsigned int, unsigned int> Cluster;
336  std::vector<Cluster> clusters;
337  for(auto & digi: digisCopy) {
338  if(clusters.empty()) clusters.push_back(Cluster(digi.strip(),digi.strip()));
339  else if (digi.strip() - clusters.back().second == 1) clusters.back().second = digi.strip();
340  else if (digi.strip() - clusters.back().second > 1) clusters.push_back(Cluster(digi.strip(),digi.strip()));
341  }
342 
343  for (auto & cluster: clusters) {
344 // int iPhiHalfStrip1 = myAngleConverter.getProcessorPhi(iProcessor, type, roll, cluster.first);
345 // int iPhiHalfStrip2 = myAngleConverter.getProcessorPhi(iProcessor, type, roll, cluster.second);
346  int iPhi = myAngleConverter.getProcessorPhi(iProcessor, type, roll, cluster.first, cluster.second);
347  int cSize = abs(int(cluster.first)-int(cluster.second))+1;
348 // std::cout << " HStrip_1: " << iPhiHalfStrip1 <<" HStrip_2: "<<iPhiHalfStrip2<<" iPhi: " << iPhi << " cluster: ["<< cluster.first << ", "<< cluster.second <<"]"<< std::endl;
349  if (cSize>3) continue;
350  int iEta = myAngleConverter.getGlobalEta(rawid, cluster.first);
351  unsigned int hwNumber = myOmtfConfig->getLayerNumber(rawid);
352  unsigned int iLayer = myOmtfConfig->getHwToLogicLayer().at(hwNumber);
353  unsigned int iInput= getInputNumber(rawid, iProcessor, type);
354 // std::cout <<"ADDING HIT: iLayer = " << iLayer << " iInput: " << iInput << " iPhi: " << iPhi << std::endl;
355  if (iLayer==17 && (iInput==0 || iInput==1)) continue; // FIXME (MK) there is no RPC link for that input, because it is taken by DAQ link
356  bool outres =
357  result.addLayerHit(iLayer,iInput,iPhi,iEta);
358 // if (cSize>2) flag |= 2;
359 // if (!outres) flag |= 1;
360  nClusters++;
361 
362  str <<" RPC halfDigi "
363  <<" begin: "<<cluster.first<<" end: "<<cluster.second
364  <<" iPhi: "<<iPhi
365  <<" iEta: "<<iEta
366  <<" hwNumber: "<<hwNumber
367  <<" iInput: "<<iInput
368  <<" iLayer: "<<iLayer
369  <<" out: " << outres
370  <<std::endl;
371  }
372 // if (nClusters > 2) flag=1;
373  }
374 
375  edm::LogInfo("OMTFInputMaker")<<str.str();
376  return result;
377 }
381  const L1MuDTChambThContainer *dtThDigis,
382  const CSCCorrelatedLCTDigiCollection *cscDigis,
383  const RPCDigiCollection *rpcDigis,
384  unsigned int iProcessor,
386  int bx){
388  result += processDT(dtPhDigis, dtThDigis, iProcessor, type, bx);
389  result += processCSC(cscDigis, iProcessor, type, bx);
390  result += processRPC(rpcDigis, iProcessor, type, bx);
391  return result;
392 }
int chamber() const
Definition: CSCDetId.h:68
type
Definition: HCALResponse.h:21
bool addLayerHit(unsigned int iLayer, unsigned int iInput, int iPhi, int iEta, bool allowOverwrite=true)
Definition: OMTFinput.cc:46
float dt
Definition: AMPTWrapper.h:126
const std::vector< unsigned int > & getBarrelMax() const
const std::map< int, int > & getHwToLogicLayer() const
unsigned int fwVersion() const
OMTFinput buildInputForProcessor(const L1MuDTChambPhContainer *dtPhDigis, const L1MuDTChambThContainer *dtThDigis, const CSCCorrelatedLCTDigiCollection *cscDigis, const RPCDigiCollection *rpcDigis, unsigned int iProcessor, l1t::tftype type=l1t::tftype::omtf_pos, int bx=0)
Method translating trigger digis into input matrix with global phi coordinates.
void initialize(const edm::EventSetup &es, const OMTFConfiguration *)
OMTFinput processRPC(const RPCDigiCollection *rpcDigis, unsigned int iProcessor, l1t::tftype type, int bx)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
int getGlobalEta(unsigned int rawid, const L1MuDTChambPhDigi &aDigi, const L1MuDTChambThContainer *dtThDigis)
Convert local eta coordinate to global digital microGMT scale.
const std::vector< unsigned int > & getEndcap10DegMin() const
unsigned int nPhiBins() const
const OMTFConfiguration * myOmtfConfig
int endcap() const
Definition: CSCDetId.h:93
int getProcessorPhi(unsigned int iProcessor, l1t::tftype part, const L1MuDTChambPhDigi &digi) const
int strip() const
Definition: RPCDigi.h:27
int roll() const
Definition: RPCDetId.h:120
OMTFinput processCSC(const CSCCorrelatedLCTDigiCollection *cscDigis, unsigned int iProcessor, l1t::tftype type, int bx)
const std::vector< unsigned int > & getEndcap20DegMax() const
int ring() const
Definition: RPCDetId.h:72
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
AngleConverter myAngleConverter
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::vector< unsigned int > & getEndcap10DegMax() const
int ring() const
Definition: CSCDetId.h:75
int layer() const
Definition: RPCDetId.h:108
Definition: DetId.h:18
bool acceptDigi(uint32_t rawId, unsigned int iProcessor, l1t::tftype type)
uint32_t getLayerNumber(uint32_t rawId) const
const std::vector< unsigned int > & getBarrelMin() const
unsigned int getInputNumber(unsigned int rawId, unsigned int iProcessor, l1t::tftype type)
static constexpr int RPC
Definition: MuonSubdetId.h:14
double b
Definition: hdecay.h:120
Phi_Container const * getContainer() const
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
int subsector() const
SubSector id : some sectors are divided along the phi direction in subsectors (from 1 to 4 in Barrel...
Definition: RPCDetId.h:114
bool rpcPrimitiveCmp(const RPCDigi &a, const RPCDigi &b)
int sector() const
Definition: DTChamberId.h:61
double a
Definition: hdecay.h:121
void checkAndUpdateGeometry(const edm::EventSetup &, unsigned int)
Update the Geometry with current Event Setup.
int station() const
Definition: CSCDetId.h:86
const std::vector< unsigned int > & getEndcap20DegMin() const
static constexpr int DT
Definition: MuonSubdetId.h:12
#define str(s)
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
static constexpr int CSC
Definition: MuonSubdetId.h:13
OMTFinput processDT(const L1MuDTChambPhContainer *dtPhDigis, const L1MuDTChambThContainer *dtThDigis, unsigned int iProcessor, l1t::tftype type, int bx)
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96