CMS 3D CMS Logo

RPCtoDTTranslator.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: RPCtoDTTranslator
4 //
5 // RPCtoDTTranslator
6 //
7 //
8 // Author :
9 // G. Flouris U Ioannina Mar. 2015
10 // modifications: G Karathanasis U Athens
11 //--------------------------------------------------
12 
13 #include <iostream>
14 #include <iomanip>
15 #include <iterator>
16 #include <cmath>
17 #include <map>
18 
26 
27 using namespace std;
28 
29 RPCtoDTTranslator::RPCtoDTTranslator(RPCDigiCollection const& inrpcDigis) : m_rpcDigis{inrpcDigis} {}
30 
31 namespace {
32  constexpr int max_rpc_bx = 2;
33  constexpr int min_rpc_bx = -2;
34 
35  struct rpc_hit {
36  int bx;
37  int station;
38  int sector;
39  int wheel;
40  RPCDetId detid;
41  int strip;
42  int roll;
43  int layer;
44  rpc_hit(int pbx, int pstation, int psector, int pwheel, RPCDetId pdet, int pstrip, int proll, int player)
45  : bx(pbx),
46  station(pstation),
47  sector(psector),
48  wheel(pwheel),
49  detid(pdet),
50  strip(pstrip),
51  roll(proll),
52  layer(player) {}
53  };
54 
55  //Need to shift the index so that index 0
56  // corresponds to min_rpc_bx
57  class BxToHit {
58  public:
59  BxToHit() : m_hits{} {} //zero initializes
60 
61  static bool outOfRange(int iBX) { return (iBX > max_rpc_bx or iBX < min_rpc_bx); }
62 
63  int& operator[](int iBX) { return m_hits[iBX - min_rpc_bx]; }
64 
65  size_t size() const { return m_hits.size(); }
66 
67  private:
68  std::array<int, max_rpc_bx - min_rpc_bx + 1> m_hits;
69  };
70 } // namespace
71 
72 void RPCtoDTTranslator::run(const RPCGeometry& rpcGeometry) {
73  std::vector<L1MuDTChambPhDigi> l1ttma_out;
74  std::vector<L1MuDTChambPhDigi> l1ttma_hits_out;
75 
76  std::vector<rpc_hit> vrpc_hit_layer1, vrpc_hit_layer2, vrpc_hit_st3, vrpc_hit_st4;
77 
79  for (auto chamber = m_rpcDigis.begin(); chamber != m_rpcDigis.end(); ++chamber) {
80  RPCDetId detid = (*chamber).first;
81  for (auto digi = (*chamber).second.first; digi != (*chamber).second.second; ++digi) {
82  if (detid.region() != 0)
83  continue; //Region = 0 Barrel
84  if (BxToHit::outOfRange(digi->bx()))
85  continue;
86  if (detid.layer() == 1)
87  vrpc_hit_layer1.emplace_back(digi->bx(),
88  detid.station(),
89  detid.sector(),
90  detid.ring(),
91  detid,
92  digi->strip(),
93  detid.roll(),
94  detid.layer());
95  if (detid.station() == 3)
96  vrpc_hit_st3.emplace_back(digi->bx(),
97  detid.station(),
98  detid.sector(),
99  detid.ring(),
100  detid,
101  digi->strip(),
102  detid.roll(),
103  detid.layer());
104  if (detid.layer() == 2)
105  vrpc_hit_layer2.emplace_back(digi->bx(),
106  detid.station(),
107  detid.sector(),
108  detid.ring(),
109  detid,
110  digi->strip(),
111  detid.roll(),
112  detid.layer());
113  if (detid.station() == 4)
114  vrpc_hit_st4.emplace_back(digi->bx(),
115  detid.station(),
116  detid.sector(),
117  detid.ring(),
118  detid,
119  digi->strip(),
120  detid.roll(),
121  detid.layer());
122  }
123  }
124 
125  vector<int> vcluster_size;
126  int cluster_id = -1;
127  int itr = 0;
128  // int hits[5][4][12][2][5][3][100]= {{{{{{{0}}}}}}};
129  std::map<RPCHitCleaner::detId_Ext, int> hits;
130  int cluster_size = 0;
131  for (auto chamber = m_rpcDigis.begin(); chamber != m_rpcDigis.end(); ++chamber) {
132  RPCDetId detid = (*chamber).first;
133  int strip_n1 = -10000;
134  int bx_n1 = -10000;
135  if (detid.region() != 0)
136  continue; //Region = 0 Barrel
137  for (auto digi = (*chamber).second.first; digi != (*chamber).second.second; ++digi) {
138  if (fabs(digi->bx()) > 3)
139  continue;
140  //Create cluster ids and store their size
141  //if((digi->strip()+1!=strip_n1)|| digi->bx()!=bx_n1){
142  if (abs(digi->strip() - strip_n1) != 1 || digi->bx() != bx_n1) {
143  if (itr != 0)
144  vcluster_size.push_back(cluster_size);
145  cluster_size = 0;
146  cluster_id++;
147  }
148  itr++;
149  cluster_size++;
151  //hits[(detid.ring()+2)][(detid.station()-1)][(detid.sector()-1)][(detid.layer()-1)][(digi->bx()+2)][detid.roll()-1][digi->strip()]= cluster_id ;
152  RPCHitCleaner::detId_Ext tmp{detid, digi->bx(), digi->strip()};
153  hits[tmp] = cluster_id;
155  strip_n1 = digi->strip();
156  bx_n1 = digi->bx();
157  }
158  }
159  vcluster_size.push_back(cluster_size);
160 
161  for (int wh = -2; wh <= 2; wh++) {
162  for (int sec = 1; sec <= 12; sec++) {
163  for (int st = 1; st <= 4; st++) {
164  int rpcbx = 0;
165  std::vector<int> delta_phib;
166  bool found_hits = false;
167  std::vector<int> rpc2dt_phi, rpc2dt_phib;
169  int itr1 = 0;
170  for (unsigned int l1 = 0; l1 < vrpc_hit_layer1.size(); l1++) {
171  RPCHitCleaner::detId_Ext tmp{vrpc_hit_layer1[l1].detid, vrpc_hit_layer1[l1].bx, vrpc_hit_layer1[l1].strip};
172  int id = hits[tmp];
173  int phi1 = radialAngle(vrpc_hit_layer1[l1].detid, rpcGeometry, vrpc_hit_layer1[l1].strip);
174  if (vcluster_size[id] == 2 && itr1 == 0) {
175  itr1++;
176  continue;
177  }
178  if (vcluster_size[id] == 2 && itr1 == 1) {
179  itr1 = 0;
180  phi1 = phi1 + (radialAngle(vrpc_hit_layer1[l1 - 1].detid, rpcGeometry, vrpc_hit_layer1[l1 - 1].strip));
181  phi1 /= 2;
182  }
183  int itr2 = 0;
184  for (unsigned int l2 = 0; l2 < vrpc_hit_layer2.size(); l2++) {
185  if (vrpc_hit_layer1[l1].station != st || vrpc_hit_layer2[l2].station != st)
186  continue;
187  if (vrpc_hit_layer1[l1].sector != sec || vrpc_hit_layer2[l2].sector != sec)
188  continue;
189  if (vrpc_hit_layer1[l1].wheel != wh || vrpc_hit_layer2[l2].wheel != wh)
190  continue;
191  if (vrpc_hit_layer1[l1].bx != vrpc_hit_layer2[l2].bx)
192  continue;
193  RPCHitCleaner::detId_Ext tmp{vrpc_hit_layer2[l2].detid, vrpc_hit_layer2[l2].bx, vrpc_hit_layer2[l2].strip};
194  int id = hits[tmp];
195 
196  if (vcluster_size[id] == 2 && itr2 == 0) {
197  itr2++;
198  continue;
199  }
200 
201  //int phi1 = radialAngle(vrpc_hit_layer1[l1].detid, c, vrpc_hit_layer1[l1].strip) ;
202  int phi2 = radialAngle(vrpc_hit_layer2[l2].detid, rpcGeometry, vrpc_hit_layer2[l2].strip);
203  if (vcluster_size[id] == 2 && itr2 == 1) {
204  itr2 = 0;
205  phi2 = phi2 + (radialAngle(vrpc_hit_layer2[l2 - 1].detid, rpcGeometry, vrpc_hit_layer2[l2 - 1].strip));
206  phi2 /= 2;
207  }
208  int average = l1t::bitShift(((phi1 + phi2) / 2), 2); //10-bit->12-bit
209  rpc2dt_phi.push_back(average); //Convert and store to 12-bit
210  //int xin = localX(vrpc_hit_layer1[l1].detid, c, vrpc_hit_layer1[l1].strip);
211  //int xout = localX(vrpc_hit_layer2[l2].detid, c, vrpc_hit_layer2[l2].strip);
212  //cout<<(phi1<<2)<<" "<<l1<<" "<<vrpc_hit_layer1[l1].station<<endl;
213  //cout<<(phi2<<2)<<" "<<l1<<" "<<vrpc_hit_layer1[l1].station<<endl;
214  int xin = localXX(l1t::bitShift(phi1, 2), 1, vrpc_hit_layer1[l1].station);
215  int xout = localXX(l1t::bitShift(phi2, 2), 2, vrpc_hit_layer2[l2].station);
216  if (vcluster_size[id] == 2 && itr2 == 1) {
217  int phi1_n1 = radialAngle(vrpc_hit_layer1[l1 - 1].detid, rpcGeometry, vrpc_hit_layer1[l1 - 1].strip);
218  int phi2_n1 = radialAngle(vrpc_hit_layer2[l2 - 1].detid, rpcGeometry, vrpc_hit_layer2[l2 - 1].strip);
219  xin += localXX(l1t::bitShift(phi1_n1, 2), 1, vrpc_hit_layer1[l1].station);
220  xout += localXX(l1t::bitShift(phi2_n1, 2), 2, vrpc_hit_layer2[l2].station);
221  xin /= 2;
222  xout /= 2;
223  }
224  //cout<<">>"<<xin<<" "<<xout<<endl;
225  int phi_b = bendingAngle(xin, xout, average);
226  //cout<<"phib "<<phi_b<<endl;
227  rpc2dt_phib.push_back(phi_b);
228  //delta_phib to find the highest pt primitve
229  delta_phib.push_back(abs(phi_b));
230  found_hits = true;
231  rpcbx = vrpc_hit_layer1[l1].bx;
232  }
233  }
234  if (found_hits) {
235  //cout<<"found_hits"<<endl;
236  int min_index = std::distance(delta_phib.begin(), std::min_element(delta_phib.begin(), delta_phib.end())) + 0;
237  //cout<<min_index<<endl;
238  l1ttma_out.emplace_back(rpcbx, wh, sec - 1, st, rpc2dt_phi[min_index], rpc2dt_phib[min_index], 3, 0, 0, 2);
239  }
241  BxToHit hit;
242  itr1 = 0;
243  for (unsigned int l1 = 0; l1 < vrpc_hit_layer1.size(); l1++) {
244  if (vrpc_hit_layer1[l1].station != st || st > 2 || vrpc_hit_layer1[l1].sector != sec ||
245  vrpc_hit_layer1[l1].wheel != wh)
246  continue;
247  //int id = hits[vrpc_hit_layer1[l1].wheel+2][(vrpc_hit_layer1[l1].station-1)][(vrpc_hit_layer1[l1].sector-1)][(vrpc_hit_layer1[l1].layer-1)][(vrpc_hit_layer1[l1].bx+2)][vrpc_hit_layer1[l1].roll-1][vrpc_hit_layer1[l1].strip];
248  RPCHitCleaner::detId_Ext tmp{vrpc_hit_layer1[l1].detid, vrpc_hit_layer1[l1].bx, vrpc_hit_layer1[l1].strip};
249  int id = hits[tmp];
250  if (vcluster_size[id] == 2 && itr1 == 0) {
251  itr1++;
252  continue;
253  }
254  int phi2 = radialAngle(vrpc_hit_layer1[l1].detid, rpcGeometry, vrpc_hit_layer1[l1].strip);
255  phi2 = l1t::bitShift(phi2, 2);
256  if (vcluster_size[id] == 2 && itr1 == 1) {
257  itr1 = 0;
258  phi2 =
259  phi2 + l1t::bitShift(
260  radialAngle(vrpc_hit_layer1[l1 - 1].detid, rpcGeometry, vrpc_hit_layer1[l1 - 1].strip), 2);
261  phi2 /= 2;
262  }
263 
264  l1ttma_hits_out.emplace_back(
265  vrpc_hit_layer1[l1].bx, wh, sec - 1, st, phi2, 0, 3, hit[vrpc_hit_layer1[l1].bx], 0, 2);
266  hit[vrpc_hit_layer1[l1].bx]++;
267  }
268  itr1 = 0;
269  for (unsigned int l2 = 0; l2 < vrpc_hit_layer2.size(); l2++) {
270  if (vrpc_hit_layer2[l2].station != st || st > 2 || vrpc_hit_layer2[l2].sector != sec ||
271  vrpc_hit_layer2[l2].wheel != wh)
272  continue;
273  RPCHitCleaner::detId_Ext tmp{vrpc_hit_layer2[l2].detid, vrpc_hit_layer2[l2].bx, vrpc_hit_layer2[l2].strip};
274  int id = hits[tmp];
275  // int id = hits[vrpc_hit_layer2[l2].wheel+2][(vrpc_hit_layer2[l2].station-1)][(vrpc_hit_layer2[l2].sector-1)][(vrpc_hit_layer2[l2].layer-1)][(vrpc_hit_layer2[l2].bx+2)][vrpc_hit_layer2[l2].roll-1][vrpc_hit_layer2[l2].strip];
276  if (vcluster_size[id] == 2 && itr1 == 0) {
277  itr1++;
278  continue;
279  }
280  int phi2 = radialAngle(vrpc_hit_layer2[l2].detid, rpcGeometry, vrpc_hit_layer2[l2].strip);
281  phi2 = l1t::bitShift(phi2, 2);
282  if (vcluster_size[id] == 2 && itr1 == 1) {
283  itr1 = 0;
284  phi2 =
285  phi2 + l1t::bitShift(
286  radialAngle(vrpc_hit_layer2[l2 - 1].detid, rpcGeometry, vrpc_hit_layer2[l2 - 1].strip), 2);
287  phi2 /= 2;
288  }
289  l1ttma_hits_out.emplace_back(
290  vrpc_hit_layer2[l2].bx, wh, sec - 1, st, phi2, 0, 3, hit[vrpc_hit_layer2[l2].bx], 0, 2);
291  hit[vrpc_hit_layer2[l2].bx]++;
292  }
293  itr1 = 0;
294 
295  for (unsigned int l1 = 0; l1 < vrpc_hit_st3.size(); l1++) {
296  if (st != 3 || vrpc_hit_st3[l1].station != 3 || vrpc_hit_st3[l1].wheel != wh ||
297  vrpc_hit_st3[l1].sector != sec)
298  continue;
299  RPCHitCleaner::detId_Ext tmp{vrpc_hit_st3[l1].detid, vrpc_hit_st3[l1].bx, vrpc_hit_st3[l1].strip};
300  int id = hits[tmp];
301  //int id = hits[vrpc_hit_st3[l1].wheel+2][(vrpc_hit_st3[l1].station-1)][(vrpc_hit_st3[l1].sector-1)][(vrpc_hit_st3[l1].layer-1)][(vrpc_hit_st3[l1].bx+2)][vrpc_hit_st3[l1].roll-1][vrpc_hit_st3[l1].strip];
302  if (vcluster_size[id] == 2 && itr1 == 0) {
303  itr1++;
304  continue;
305  }
306  int phi2 = radialAngle(vrpc_hit_st3[l1].detid, rpcGeometry, vrpc_hit_st3[l1].strip);
307  phi2 = l1t::bitShift(phi2, 2);
308  if (vcluster_size[id] == 2 && itr1 == 1) {
309  itr1 = 0;
310  phi2 = phi2 +
311  l1t::bitShift(radialAngle(vrpc_hit_st3[l1 - 1].detid, rpcGeometry, vrpc_hit_st3[l1 - 1].strip), 2);
312  phi2 /= 2;
313  }
314  l1ttma_hits_out.emplace_back(
315  vrpc_hit_st3[l1].bx, wh, sec - 1, st, phi2, 0, 3, hit[vrpc_hit_st3[l1].bx], 0, 2);
316  hit[vrpc_hit_st3[l1].bx]++;
317  }
318  itr1 = 0;
319 
320  for (unsigned int l1 = 0; l1 < vrpc_hit_st4.size(); l1++) {
321  if (st != 4 || vrpc_hit_st4[l1].station != 4 || vrpc_hit_st4[l1].wheel != wh ||
322  vrpc_hit_st4[l1].sector != sec)
323  continue;
324  //int id = hits[vrpc_hit_st4[l1].wheel+2][(vrpc_hit_st4[l1].station-1)][(vrpc_hit_st4[l1].sector-1)][(vrpc_hit_st4[l1].layer-1)][(vrpc_hit_st4[l1].bx+2)][vrpc_hit_st4[l1].roll-1][vrpc_hit_st4[l1].strip];
325  RPCHitCleaner::detId_Ext tmp{vrpc_hit_st4[l1].detid, vrpc_hit_st4[l1].bx, vrpc_hit_st4[l1].strip};
326  int id = hits[tmp];
327  if (vcluster_size[id] == 2 && itr1 == 0) {
328  itr1++;
329  continue;
330  }
331  int phi2 = radialAngle(vrpc_hit_st4[l1].detid, rpcGeometry, vrpc_hit_st4[l1].strip);
332  phi2 = l1t::bitShift(phi2, 2);
333  if (vcluster_size[id] == 2 && itr1 == 1) {
334  itr1 = 0;
335  phi2 = phi2 +
336  l1t::bitShift(radialAngle(vrpc_hit_st4[l1 - 1].detid, rpcGeometry, vrpc_hit_st4[l1 - 1].strip), 2);
337  phi2 /= 2;
338  }
339  l1ttma_hits_out.emplace_back(
340  vrpc_hit_st4[l1].bx, wh, sec - 1, st, phi2, 0, 3, hit[vrpc_hit_st4[l1].bx], 0, 2);
341  hit[vrpc_hit_st4[l1].bx]++;
342  //l1ttma_out.push_back(rpc2dt_out);
343 
344  //break;
345  }
346  }
347  }
348  }
350  m_rpcdt_translated.setContainer(l1ttma_out);
352  m_rpchitsdt_translated.setContainer(l1ttma_hits_out);
353 }
354 
356 int RPCtoDTTranslator::radialAngle(RPCDetId detid, const RPCGeometry& rpcGeometry, int strip) {
357  int radialAngle;
358  // from phiGlobal to radialAngle of the primitive in sector sec in [1..12] <- RPC scheme
359 
360  const RPCRoll* roll = rpcGeometry.roll(detid);
361  GlobalPoint stripPosition = roll->toGlobal(roll->centreOfStrip(strip));
362 
363  double globalphi = stripPosition.phi();
364  int sector = (roll->id()).sector();
365  if (sector == 1)
366  radialAngle = int(globalphi * 1024);
367  else {
368  if (globalphi >= 0)
369  radialAngle = int((globalphi - (sector - 1) * Geom::pi() / 6.) * 1024);
370  else
371  radialAngle = int((globalphi + (13 - sector) * Geom::pi() / 6.) * 1024);
372  }
373  return radialAngle;
374 }
375 
377 int RPCtoDTTranslator::localX(RPCDetId detid, const RPCGeometry& rpcGeometry, int strip) {
378  const RPCRoll* roll = rpcGeometry.roll(detid);
379 
381  GlobalPoint p1cmPRG = roll->toGlobal(LocalPoint(1, 0, 0));
382  GlobalPoint m1cmPRG = roll->toGlobal(LocalPoint(-1, 0, 0));
383  float phip1cm = p1cmPRG.phi();
384  float phim1cm = m1cmPRG.phi();
385  int direction = (phip1cm - phim1cm) / abs(phip1cm - phim1cm);
387 
388  return direction * roll->centreOfStrip(strip).x();
389 }
390 
391 int RPCtoDTTranslator::bendingAngle(int xin, int xout, int phi) {
392  // use chamber size and max angle in hw units 512
393  int atanv = (int)(atan((xout - xin) / 34.6) * 512);
394  if (atanv > 512)
395  return 512;
396  int rvalue = atanv - phi / 8;
397  return rvalue;
398 }
399 
401  //R[stat][layer] - radius of rpc station/layer from center of CMS
402  double R[2][2] = {{410.0, 444.8}, {492.7, 527.3}};
403  double rvalue = R[station - 1][layer - 1] * tan(phi / 4096.);
404  return rvalue;
405 }
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:81
size
Write out results.
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
static int bendingAngle(int, int, int)
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
int ring() const
Definition: RPCDetId.h:59
RPCtoDTTranslator(const RPCDigiCollection &inrpcDigis)
const RPCRoll * roll(RPCDetId id) const
Return a roll given its id.
Definition: RPCGeometry.cc:50
static int localX(RPCDetId, const RPCGeometry &, int)
function - will be replaced by LUTs(?)
const RPCDigiCollection & m_rpcDigis
void setContainer(Phi_Container inputSegments)
L1MuDTChambPhContainer m_rpcdt_translated
Output PhContainer.
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void run(const RPCGeometry &)
int roll() const
Definition: RPCDetId.h:92
L1MuDTChambPhContainer m_rpchitsdt_translated
int station() const
Definition: RPCDetId.h:78
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
static int localXX(int, int, int)
int layer() const
Definition: RPCDetId.h:85
constexpr double pi()
Definition: Pi.h:31
T operator[](int i) const
tmp
align.sh
Definition: createJobs.py:716
static int radialAngle(RPCDetId, const RPCGeometry &, int)
function - will be replaced by LUTs(?)
int bitShift(int num, int bits)
Definition: BitShift.h:6