CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OMTFinputMaker.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <vector>
3 #include <iostream>
4 #include <algorithm>
5 
10 
15 
18 
22 
23  myInput = new OMTFinput();
24 
25  katownik.reset(new AngleConverter());
26 }
30 
31  katownik->checkAndUpdateGeometry(es);
32 }
36 
37  if(myInput) delete myInput;
38 
39 }
42 bool OMTFinputMaker::acceptDigi(uint32_t rawId,
43  unsigned int iProcessor,
45 
46  unsigned int aMin = OMTFConfiguration::barrelMin[iProcessor];
47  unsigned int aMax = OMTFConfiguration::barrelMax[iProcessor];
48  unsigned int aSector = 99;
49 
51  DetId detId(rawId);
52  if (detId.det() != DetId::Muon)
53  edm::LogError("Critical OMTFinputMaker") << "PROBLEM: hit in unknown Det, detID: "<<detId.det()<<std::endl;
54  switch (detId.subdetId()) {
55  case MuonSubdetId::RPC: {
56  RPCDetId aId(rawId);
57 
59  if(type==l1t::tftype::omtf_pos &&
60  (aId.region()<0 ||
61  (aId.region()==0 && aId.ring()!=2) ||
62  (aId.region()==0 && aId.station()==4) ||
63  (aId.region()==0 && aId.station()==2 && aId.layer()==2 && aId.roll()==1) ||
64  (aId.region()==0 && aId.station()==3 && aId.roll()==1) ||
65  (aId.region()==1 && aId.station()==4) ||
67  (aId.region()==1 && aId.station()>0 && aId.ring()<3))
68  ) return false;
69 
70  if(type==l1t::tftype::omtf_neg &&
71  (aId.region()>0 ||
72  (aId.region()==0 && aId.ring()!=-2) ||
73  (aId.region()==0 && aId.station()==4) ||
74  (aId.region()==0 && aId.station()==2 && aId.layer()==2 && aId.roll()==1) ||
75  (aId.region()==0 && aId.station()==3 && aId.roll()==1) ||
76  (aId.region()==-1 && aId.station()==4) ||
77  //RPC RE1/2 temporarily not used (aId.region()==1 && aId.station()==1 && aId.ring()<2) ||
78  (aId.region()==-1 && aId.station()>0 && aId.ring()<3))
79  ) return false;
80 
81  if(type==l1t::tftype::bmtf && aId.region()!=0) return false;
82 
83  if(type==l1t::tftype::emtf_pos &&
84  (aId.region()<=0 ||
85  (aId.station()==1 && aId.ring()==3))) return false;
86  if(type==l1t::tftype::emtf_neg &&
87  (aId.region()>=0 ||
88  (aId.station()==1 && aId.ring()==3))) return false;
90  if(aId.region()==0) aSector = aId.sector();
91  if(aId.region()!=0){
92  aSector = (aId.sector()-1)*6+aId.subsector();
93  aMin = OMTFConfiguration::endcap10DegMin[iProcessor];
94  aMax = OMTFConfiguration::endcap10DegMax[iProcessor];
95  }
96 
97  break;
98  }
99  case MuonSubdetId::DT: {
100  DTChamberId dt(rawId);
101 
102  if(type==l1t::tftype::omtf_pos && dt.wheel()!=2) return false;
103  if(type==l1t::tftype::omtf_neg && dt.wheel()!=-2) return false;
104  if(type==l1t::tftype::emtf_pos || type==l1t::tftype::emtf_neg) return false;
105 
106  aSector = dt.sector();
107  break;
108  }
109  case MuonSubdetId::CSC: {
110 
111  CSCDetId csc(rawId);
112  if(type==l1t::tftype::omtf_pos &&
113  (csc.endcap()==2 || csc.ring()==1 || csc.station()==4)) return false;
114  if(type==l1t::tftype::omtf_neg &&
115  (csc.endcap()==1 || csc.ring()==1 || csc.station()==4)) return false;
116 
117  if(type==l1t::tftype::emtf_pos &&
118  (csc.endcap()==2 || (csc.station()==1 && csc.ring()==3))
119  ) return false;
120  if(type==l1t::tftype::emtf_neg &&
121  (csc.endcap()==1 || (csc.station()==1 && csc.ring()==3))
122  ) return false;
123 
124  aSector = csc.chamber();
125 
126  aMin = OMTFConfiguration::endcap10DegMin[iProcessor];
127  aMax = OMTFConfiguration::endcap10DegMax[iProcessor];
128 
129  if( (type==l1t::tftype::emtf_pos || type==l1t::tftype::emtf_neg) &&
130  csc.station()>1 && csc.ring()==1){
131  aMin = OMTFConfiguration::endcap20DegMin[iProcessor];
132  aMax = OMTFConfiguration::endcap20DegMax[iProcessor];
133  }
134  break;
135  }
136  }
137 
138  if(aMax>aMin && aSector>=aMin && aSector<=aMax) return true;
139  if(aMax<aMin && (aSector>=aMin || aSector<=aMax)) return true;
140 
141  return false;
142 }
145 unsigned int OMTFinputMaker::getInputNumber(unsigned int rawId,
146  unsigned int iProcessor,
147  l1t::tftype type){
148 
149  unsigned int iInput = 99;
150  unsigned int aSector = 99;
151  int aMin = OMTFConfiguration::barrelMin[iProcessor];
152  int iRoll = 1;
153  int nInputsPerSector = 2;
154 
155  DetId detId(rawId);
156  if (detId.det() != DetId::Muon)
157  edm::LogError("Critical OMTFinputMaker") << "PROBLEM: hit in unknown Det, detID: "<<detId.det()<<std::endl;
158  switch (detId.subdetId()) {
159  case MuonSubdetId::RPC: {
160  RPCDetId rpc(rawId);
161  if(rpc.region()==0){
162  nInputsPerSector = 4;
163  aSector = rpc.sector();
166  if(iProcessor==5 && aSector<3) aMin = 0;
167  //Use division into rolls
168  iRoll = rpc.roll();
171  if(rpc.station()==2 && rpc.layer()==2 && rpc.roll()==2) iRoll = 1;
172  if(rpc.station()==3) iRoll = 1;
173 
175  if(type==l1t::tftype::bmtf)iRoll = 1;
176  }
177  if(rpc.region()!=0){
178  aSector = (rpc.sector()-1)*6+rpc.subsector();
179  aMin = OMTFConfiguration::endcap10DegMin[iProcessor];
182  if(iProcessor==5 && aSector<5) aMin = -3;
183  }
184  break;
185  }
186  case MuonSubdetId::DT: {
187  DTChamberId dt(rawId);
188  aSector = dt.sector();
191  if(iProcessor==5 && aSector<3) aMin = 0;
192  break;
193  }
194  case MuonSubdetId::CSC: {
195  CSCDetId csc(rawId);
196  aSector = csc.chamber();
197  aMin = OMTFConfiguration::endcap10DegMin[iProcessor];
200  if(iProcessor==5 && aSector<5) aMin = -3;
204  if( (type==l1t::tftype::emtf_pos || type==l1t::tftype::emtf_neg) &&
205  csc.station()>1 && csc.ring()==1){
206  aMin = OMTFConfiguration::endcap20DegMin[iProcessor];
207  if(iProcessor==5 && aSector<3) aMin = -1;
208  }
209  break;
210  }
211  }
212 
214  iInput = (aSector - aMin)*nInputsPerSector;
216  iInput+=iRoll-1;
217 
218  return iInput;
219 }
223  const L1MuDTChambThContainer *dtThDigis,
224  unsigned int iProcessor,
225  l1t::tftype type){
226 
227  if(!dtPhDigis) return;
228 
229  for (const auto digiIt: *dtPhDigis->getContainer()) {
230 
231  DTChamberId detid(digiIt.whNum(),digiIt.stNum(),digiIt.scNum()+1);
232 
234  if(!acceptDigi(detid.rawId(), iProcessor, type)) continue;
239  if (digiIt.bxNum()!= 0 || digiIt.BxCnt()!= 0 || digiIt.Ts2Tag()!= 0 || digiIt.code()<4) continue;
240 
241  unsigned int hwNumber = OMTFConfiguration::getLayerNumber(detid.rawId());
243 
244  unsigned int iLayer = OMTFConfiguration::hwToLogicLayer[hwNumber];
245  int iPhi = katownik->getGlobalPhi(detid.rawId(), digiIt);
246  int iEta = katownik->getGlobalEta(detid.rawId(), digiIt, dtThDigis);
247  unsigned int iInput= getInputNumber(detid.rawId(), iProcessor, type);
248 
249  myInput->addLayerHit(iLayer,iInput,iPhi,iEta);
250  myInput->addLayerHit(iLayer+1,iInput,digiIt.phiB(),iEta);
251  }
252 
253 }
257  unsigned int iProcessor,
258  l1t::tftype type){
259 
260  if(!cscDigis) return;
261 
262  auto chamber = cscDigis->begin();
263  auto chend = cscDigis->end();
264  for( ; chamber != chend; ++chamber ) {
265 
266  unsigned int rawid = (*chamber).first;
268  if(!acceptDigi(rawid, iProcessor, type)) continue;
269 
270  auto digi = (*chamber).second.first;
271  auto dend = (*chamber).second.second;
272  for( ; digi != dend; ++digi ) {
273 
276  if (abs(digi->getBX()- 6)>0) continue;
277 
278  unsigned int hwNumber = OMTFConfiguration::getLayerNumber(rawid);
280 
281  unsigned int iLayer = OMTFConfiguration::hwToLogicLayer[hwNumber];
282  int iPhi = katownik->getGlobalPhi(rawid, *digi);
283  int iEta = katownik->getGlobalEta(rawid, *digi);
287  if(abs(iEta)>1.26/2.61*240) continue;
288  unsigned int iInput= getInputNumber(rawid, iProcessor, type);
289  myInput->addLayerHit(iLayer,iInput,iPhi,iEta);
290  }
291  }
292 }
296  const RPCDigi &b) { return a.strip() < b.strip(); };
300  unsigned int iProcessor,
301  l1t::tftype type){
302 
303  if(!rpcDigis) return;
304 
305  std::ostringstream myStr;
306 
307  typedef std::pair<RPCDigi *, RPCDigi *> halfDigi;
308 
309  auto chamber = rpcDigis->begin();
310  auto chend = rpcDigis->end();
311  for( ; chamber != chend; ++chamber ) {
312  unsigned int rawid = (*chamber).first;
313 
315  if(!acceptDigi(rawid, iProcessor, type)) continue;
316 
320  std::vector<RPCDigi> digisCopy;
321  std::copy_if((*chamber).second.first, (*chamber).second.second, std::back_inserter(digisCopy), [](const RPCDigi & aDigi){return (aDigi.bx()==0);});
322  std::sort(digisCopy.begin(),digisCopy.end(),rpcPrimitiveCmp);
323  std::vector<halfDigi> result;
324  for(auto &stripIt: digisCopy) {
325  if(result.empty()) result.push_back(halfDigi(&stripIt,&stripIt));
326  else if (stripIt.strip() - result.back().second->strip() == 1) result.back().second = &stripIt;
327  else if (stripIt.strip() - result.back().second->strip() > 1) result.push_back(halfDigi(&stripIt,&stripIt));
328  }
329  for(auto halfDigiIt:result){
330  /* This code should be used when LUT for RPC angle converiosn will be implemented.
331  int strip1 = halfDigiIt.first->strip();
332  int strip2 = halfDigiIt.second->strip();
333  int clusterHalfStrip = strip1 + strip2;
334  int iPhi = katownik->getGlobalPhi(rawid,clusterHalfStrip);
335  */
337  float phi1 = katownik->getGlobalPhi(rawid,*halfDigiIt.first);
338  float phi2 = katownik->getGlobalPhi(rawid,*halfDigiIt.second);
339  float phi = (phi1+phi2)/2.0;
342  if(phi1*phi2<0 && fabs(phi1)>M_PI/2.0) phi = (M_PI-phi)*(1 - 2*std::signbit(phi));
343  int iPhi = phi/(2.0*M_PI)*OMTFConfiguration::nPhiBins;
345  int iEta = katownik->getGlobalEta(rawid,*halfDigiIt.first);
346  unsigned int hwNumber = OMTFConfiguration::getLayerNumber(rawid);
347  unsigned int iLayer = OMTFConfiguration::hwToLogicLayer[hwNumber];
348  unsigned int iInput= getInputNumber(rawid, iProcessor, type);
349 
350  myInput->addLayerHit(iLayer,iInput,iPhi,iEta);
351 
352  myStr<<" RPC halfDigi "
353  <<" begin: "<<halfDigiIt.first->strip()<<" end: "<<halfDigiIt.second->strip()
354  <<" iPhi: "<<iPhi
355  <<" iEta: "<<iEta
356  <<" hwNumber: "<<hwNumber
357  <<" iInput: "<<iInput
358  <<" iLayer: "<<iLayer
359  <<std::endl;
360  }
361  }
362  edm::LogInfo("OMTFInputMaker")<<myStr.str();
363 }
367  const L1MuDTChambThContainer *dtThDigis,
368  const CSCCorrelatedLCTDigiCollection *cscDigis,
369  const RPCDigiCollection *rpcDigis,
370  unsigned int iProcessor,
371  l1t::tftype type){
372  myInput->clear();
373 
374  processDT(dtPhDigis, dtThDigis, iProcessor, type);
375  processCSC(cscDigis, iProcessor, type);
376  processRPC(rpcDigis, iProcessor, type);
377 
378  return myInput;
379 
380 }
383 
int chamber() const
Definition: CSCDetId.h:68
type
Definition: HCALResponse.h:21
float dt
Definition: AMPTWrapper.h:126
void clear()
Reset vectors with data.
Definition: OMTFinput.cc:95
static std::vector< unsigned int > endcap20DegMax
int bx() const
Definition: RPCDigi.cc:47
static std::vector< unsigned int > endcap10DegMin
static std::vector< unsigned int > barrelMax
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void processRPC(const RPCDigiCollection *rpcDigis, unsigned int iProcessor, l1t::tftype type)
void initialize(const edm::EventSetup &es)
int endcap() const
Definition: CSCDetId.h:93
static const int CSC
Definition: MuonSubdetId.h:13
int strip() const
Definition: RPCDigi.cc:45
void processCSC(const CSCCorrelatedLCTDigiCollection *cscDigis, unsigned int iProcessor, l1t::tftype type)
int roll() const
Definition: RPCDetId.h:120
int ring() const
Definition: RPCDetId.h:72
static std::vector< unsigned int > barrelMin
tuple result
Definition: query.py:137
void processDT(const L1MuDTChambPhContainer *dtPhDigis, const L1MuDTChambThContainer *dtThDigis, unsigned int iProcessor, l1t::tftype type)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< AngleConverter > katownik
static unsigned int nPhiBins
#define end
Definition: vmac.h:37
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
#define M_PI
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)
static std::map< int, int > hwToLogicLayer
unsigned int getInputNumber(unsigned int rawId, unsigned int iProcessor, l1t::tftype type)
double b
Definition: hdecay.h:120
Phi_Container const * getContainer() const
OMTFinput * myInput
Output object.
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
return(e1-e2)*(e1-e2)+dp *dp
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)
Method translating trigger digis into input matrix with global phi coordinates.
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)
static const int RPC
Definition: MuonSubdetId.h:14
int sector() const
Definition: DTChamberId.h:61
double a
Definition: hdecay.h:121
bool addLayerHit(unsigned int iLayer, unsigned int iInput, int iPhi, int iEta)
Definition: OMTFinput.cc:45
int station() const
Definition: CSCDetId.h:86
static const int DT
Definition: MuonSubdetId.h:12
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
static std::vector< unsigned int > endcap10DegMax
static std::vector< unsigned int > endcap20DegMin
static uint32_t getLayerNumber(uint32_t rawId)
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96