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 
25 
26 using namespace std;
27 
28 
30 
31  m_rpcDigis = inrpcDigis;
32 
33 }
34 
35 namespace {
36  constexpr int max_rpc_bx = 2;
37  constexpr int min_rpc_bx = -2;
38 
39  //Need to shift the index so that index 0
40  // corresponds to min_rpc_bx
41  class BxToHit {
42  public:
43  BxToHit(): m_hits{} {} //zero initializes
44 
45  static bool outOfRange(int iBX) {
46  return (iBX > max_rpc_bx or iBX < min_rpc_bx);
47  }
48 
49  int& operator[](int iBX) {
50  return m_hits[iBX-min_rpc_bx];
51  }
52 
53  size_t size() const { return m_hits.size(); }
54  private:
55  std::array<int,max_rpc_bx-min_rpc_bx+1> m_hits;
56  };
57 }
58 
59 
61 
62  std::vector<L1MuDTChambPhDigi> l1ttma_out;
63  std::vector<L1MuDTChambPhDigi> l1ttma_hits_out;
64 
65  std::vector<rpc_hit> vrpc_hit_layer1, vrpc_hit_layer2, vrpc_hit_st3, vrpc_hit_st4;
66 
68  for( auto chamber = m_rpcDigis.begin(); chamber != m_rpcDigis.end(); ++chamber ) {
69  RPCDetId detid = (*chamber).first;
70  for( auto digi = (*chamber).second.first ; digi != (*chamber).second.second; ++digi ) {
71  if(detid.region()!=0 ) continue; //Region = 0 Barrel
72  if(BxToHit::outOfRange(digi->bx())) continue;
73  if(detid.layer()==1) vrpc_hit_layer1.push_back({digi->bx(), detid.station(), detid.sector(), detid.ring(), detid, digi->strip(), detid.roll(), detid.layer()});
74  if(detid.station()==3) vrpc_hit_st3.push_back({digi->bx(), detid.station(), detid.sector(), detid.ring(), detid, digi->strip(), detid.roll(), detid.layer()});
75  if(detid.layer()==2) vrpc_hit_layer2.push_back({digi->bx(), detid.station(), detid.sector(), detid.ring(), detid, digi->strip(), detid.roll(), detid.layer()});
76  if(detid.station()==4) vrpc_hit_st4.push_back({digi->bx(), detid.station(), detid.sector(), detid.ring(), detid, digi->strip(), detid.roll(), detid.layer()});
77  }
78  }
79 
80  vector<int> vcluster_size ;
81  int cluster_id = -1;
82  int itr=0;
83 // int hits[5][4][12][2][5][3][100]= {{{{{{{0}}}}}}};
84  std::map<RPCHitCleaner::detId_Ext, int> hits;
85  int cluster_size = 0;
86  for( auto chamber = m_rpcDigis.begin(); chamber != m_rpcDigis.end(); ++chamber ){
87  RPCDetId detid = (*chamber).first;
88  int strip_n1 = -10000;
89  int bx_n1 = -10000;
90  if(detid.region()!=0 ) continue; //Region = 0 Barrel
91  for( auto digi = (*chamber).second.first ; digi != (*chamber).second.second; ++digi ){
92  if(fabs(digi->bx())>3 ) continue;
93  //Create cluster ids and store their size
94  //if((digi->strip()+1!=strip_n1)|| digi->bx()!=bx_n1){
95  if( abs(digi->strip()-strip_n1)!=1 || digi->bx()!=bx_n1){
96  if(itr!=0)vcluster_size.push_back(cluster_size);
97  cluster_size = 0;
98  cluster_id++;
99  }
100  itr++;
101  cluster_size++;
103  //hits[(detid.ring()+2)][(detid.station()-1)][(detid.sector()-1)][(detid.layer()-1)][(digi->bx()+2)][detid.roll()-1][digi->strip()]= cluster_id ;
104  RPCHitCleaner::detId_Ext tmp{detid,digi->bx(),digi->strip()};
105  hits[tmp] = cluster_id;
107  strip_n1 = digi->strip();
108  bx_n1 = digi->bx();
109  }
110  }
111  vcluster_size.push_back(cluster_size);
112 
113 
114 
115  for(int wh=-2; wh<=2; wh++){
116  for(int sec=1; sec<=12; sec++){
117  for(int st=1; st<=4; st++){
118  int rpcbx = 0;
119  std::vector<int> delta_phib;
120  bool found_hits = false;
121  std::vector<int> rpc2dt_phi, rpc2dt_phib;
123  int itr1=0, itr2=0;
124  int phi1=0, phi2=0;
125  for(unsigned int l1=0; l1<vrpc_hit_layer1.size(); l1++){
126  RPCHitCleaner::detId_Ext tmp{vrpc_hit_layer1[l1].detid,vrpc_hit_layer1[l1].bx,vrpc_hit_layer1[l1].strip};
127  int id = hits[tmp];
128  phi1 = radialAngle(vrpc_hit_layer1[l1].detid, c, vrpc_hit_layer1[l1].strip) ;
129  if(vcluster_size[id]==2 && itr1==0) {
130  itr1++;
131  continue;
132  }
133  if(vcluster_size[id]==2 && itr1==1 ) {
134  itr1 = 0;
135  phi1 = phi1 + (radialAngle(vrpc_hit_layer1[l1-1].detid, c, vrpc_hit_layer1[l1-1].strip));
136  phi1 /= 2;
137  }
138 
139  for(unsigned int l2=0; l2<vrpc_hit_layer2.size(); l2++){
140  if(vrpc_hit_layer1[l1].station!=st || vrpc_hit_layer2[l2].station!=st ) continue;
141  if(vrpc_hit_layer1[l1].sector!=sec || vrpc_hit_layer2[l2].sector!=sec ) continue;
142  if(vrpc_hit_layer1[l1].wheel!=wh || vrpc_hit_layer2[l2].wheel!=wh ) continue;
143  if(vrpc_hit_layer1[l1].bx!=vrpc_hit_layer2[l2].bx ) continue;
144  RPCHitCleaner::detId_Ext tmp{vrpc_hit_layer2[l2].detid,vrpc_hit_layer2[l2].bx,vrpc_hit_layer2[l2].strip};
145  int id = hits[tmp];
146 
147  if(vcluster_size[id]==2 && itr2==0) {
148  itr2++;
149  continue;
150  }
151 
152  //int phi1 = radialAngle(vrpc_hit_layer1[l1].detid, c, vrpc_hit_layer1[l1].strip) ;
153  phi2 = radialAngle(vrpc_hit_layer2[l2].detid, c, vrpc_hit_layer2[l2].strip) ;
154  if(vcluster_size[id]==2 && itr2==1) {
155  itr2 = 0;
156  phi2 = phi2 + (radialAngle(vrpc_hit_layer2[l2-1].detid, c, vrpc_hit_layer2[l2-1].strip));
157  phi2 /= 2;
158  }
159  int average = ( (phi1 + phi2)/2 )<<2; //10-bit->12-bit
160  rpc2dt_phi.push_back(average); //Convert and store to 12-bit
161  //int xin = localX(vrpc_hit_layer1[l1].detid, c, vrpc_hit_layer1[l1].strip);
162  //int xout = localX(vrpc_hit_layer2[l2].detid, c, vrpc_hit_layer2[l2].strip);
163  //cout<<(phi1<<2)<<" "<<l1<<" "<<vrpc_hit_layer1[l1].station<<endl;
164  //cout<<(phi2<<2)<<" "<<l1<<" "<<vrpc_hit_layer1[l1].station<<endl;
165  int xin = localXX((phi1<<2), 1, vrpc_hit_layer1[l1].station );
166  int xout = localXX((phi2<<2), 2, vrpc_hit_layer2[l2].station);
167  if(vcluster_size[id]==2 && itr2==1) {
168  int phi1_n1 = radialAngle(vrpc_hit_layer1[l1-1].detid, c, vrpc_hit_layer1[l1-1].strip);
169  int phi2_n1 = radialAngle(vrpc_hit_layer2[l2-1].detid, c, vrpc_hit_layer2[l2-1].strip);
170  xin += localXX((phi1_n1<<2), 1, vrpc_hit_layer1[l1].station );
171  xout += localXX((phi2_n1<<2), 2, vrpc_hit_layer2[l2].station );
172  xin /= 2;
173  xout /= 2;
174  }
175  //cout<<">>"<<xin<<" "<<xout<<endl;
176  int phi_b = bendingAngle(xin,xout,average);
177  //cout<<"phib "<<phi_b<<endl;
178  rpc2dt_phib.push_back(phi_b);
179  //delta_phib to find the highest pt primitve
180  delta_phib.push_back(abs(phi_b));
181  found_hits = true;
182  rpcbx = vrpc_hit_layer1[l1].bx;
183  }
184  }
185  if(found_hits){
186  //cout<<"found_hits"<<endl;
187  int min_index = std::distance(delta_phib.begin(), std::min_element(delta_phib.begin(), delta_phib.end())) + 0;
188  //cout<<min_index<<endl;
189  l1ttma_out.emplace_back( rpcbx, wh, sec-1, st, rpc2dt_phi[min_index], rpc2dt_phib[min_index], 3, 0, 0, 2);
190 
191  }
193  BxToHit hit;
194  itr1=0;
195  for(unsigned int l1=0; l1<vrpc_hit_layer1.size(); l1++){
196  if(vrpc_hit_layer1[l1].station!=st || st>2 || vrpc_hit_layer1[l1].sector!=sec || vrpc_hit_layer1[l1].wheel!=wh) continue;
197  //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];
198  RPCHitCleaner::detId_Ext tmp{vrpc_hit_layer1[l1].detid,vrpc_hit_layer1[l1].bx,vrpc_hit_layer1[l1].strip};
199  int id = hits[tmp];
200  if(vcluster_size[id]==2 && itr1==0) {
201  itr1++;
202  continue;
203  }
204  int phi2 = radialAngle(vrpc_hit_layer1[l1].detid, c, vrpc_hit_layer1[l1].strip);
205  phi2 = phi2<<2;
206  if(vcluster_size[id]==2 && itr1==1 ) {
207  itr1 = 0;
208  phi2 = phi2 + (radialAngle(vrpc_hit_layer1[l1-1].detid, c, vrpc_hit_layer1[l1-1].strip)<<2);
209  phi2 /= 2;
210  }
211 
212  l1ttma_hits_out.emplace_back(vrpc_hit_layer1[l1].bx, wh, sec-1, st, phi2, 0, 3, hit[vrpc_hit_layer1[l1].bx], 0, 2);
213  hit[vrpc_hit_layer1[l1].bx]++;
214  }
215  itr1 = 0;
216  for(unsigned int l2=0; l2<vrpc_hit_layer2.size(); l2++){
217  if(vrpc_hit_layer2[l2].station!=st || st>2 || vrpc_hit_layer2[l2].sector!=sec || vrpc_hit_layer2[l2].wheel!=wh) continue;
218  RPCHitCleaner::detId_Ext tmp{vrpc_hit_layer2[l2].detid,vrpc_hit_layer2[l2].bx,vrpc_hit_layer2[l2].strip};
219  int id = hits[tmp];
220 // 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];
221  if(vcluster_size[id]==2 && itr1==0) {
222  itr1++;
223  continue;
224  }
225  int phi2 = radialAngle(vrpc_hit_layer2[l2].detid, c, vrpc_hit_layer2[l2].strip);
226  phi2 = phi2<<2;
227  if(vcluster_size[id]==2 && itr1==1) {
228  itr1 = 0;
229  phi2 = phi2 + (radialAngle(vrpc_hit_layer2[l2-1].detid, c, vrpc_hit_layer2[l2-1].strip)<<2);
230  phi2 /= 2;
231  }
232  l1ttma_hits_out.emplace_back( vrpc_hit_layer2[l2].bx, wh, sec-1, st, phi2, 0, 3, hit[vrpc_hit_layer2[l2].bx] , 0, 2);
233  hit[vrpc_hit_layer2[l2].bx]++;
234 
235  }
236  itr1 = 0;
237 
238  for(unsigned int l1=0; l1<vrpc_hit_st3.size(); l1++){
239  if(st!=3 || vrpc_hit_st3[l1].station!=3 || vrpc_hit_st3[l1].wheel!=wh || vrpc_hit_st3[l1].sector!=sec) continue;
240  RPCHitCleaner::detId_Ext tmp{vrpc_hit_st3[l1].detid,vrpc_hit_st3[l1].bx,vrpc_hit_st3[l1].strip};
241  int id = hits[tmp];
242  //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];
243  if(vcluster_size[id]==2 && itr1==0) {
244  itr1++;
245  continue;
246  }
247  int phi2 = radialAngle(vrpc_hit_st3[l1].detid, c, vrpc_hit_st3[l1].strip);
248  phi2 = phi2<<2;
249  if(vcluster_size[id]==2 && itr1==1) {
250  itr1 = 0;
251  phi2 = phi2 + (radialAngle(vrpc_hit_st3[l1-1].detid, c, vrpc_hit_st3[l1-1].strip)<<2);
252  phi2 /= 2;
253  }
254  l1ttma_hits_out.emplace_back( vrpc_hit_st3[l1].bx, wh, sec-1, st, phi2, 0, 3, hit[vrpc_hit_st3[l1].bx], 0, 2);
255  hit[vrpc_hit_st3[l1].bx]++;
256 
257  }
258  itr1 = 0;
259 
260  for(unsigned int l1=0; l1<vrpc_hit_st4.size(); l1++){
261  if(st!=4 || vrpc_hit_st4[l1].station!=4 || vrpc_hit_st4[l1].wheel!=wh || vrpc_hit_st4[l1].sector!=sec) continue;
262  //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];
263  RPCHitCleaner::detId_Ext tmp{vrpc_hit_st4[l1].detid,vrpc_hit_st4[l1].bx,vrpc_hit_st4[l1].strip};
264  int id = hits[tmp];
265  if(vcluster_size[id]==2 && itr1==0) {
266  itr1++;
267  continue;
268  }
269  int phi2 = radialAngle(vrpc_hit_st4[l1].detid, c, vrpc_hit_st4[l1].strip);
270  phi2 = phi2<<2;
271  if(vcluster_size[id]==2 && itr1==1) {
272  itr1 = 0;
273  phi2 = phi2 + (radialAngle(vrpc_hit_st4[l1-1].detid, c, vrpc_hit_st4[l1-1].strip)<<2);
274  phi2 /= 2;
275  }
276  l1ttma_hits_out.emplace_back(vrpc_hit_st4[l1].bx, wh, sec-1, st, phi2, 0, 3, hit[vrpc_hit_st4[l1].bx] , 0, 2);
277  hit[vrpc_hit_st4[l1].bx]++;
278  //l1ttma_out.push_back(rpc2dt_out);
279 
280  //break;
281  }
282  }
283  }
284  }
286 m_rpcdt_translated.setContainer(l1ttma_out);
288 m_rpchitsdt_translated.setContainer(l1ttma_hits_out);
289 
290 }
291 
292 
295 
296  int radialAngle;
297  // from phiGlobal to radialAngle of the primitive in sector sec in [1..12] <- RPC scheme
298  edm::ESHandle<RPCGeometry> rpcGeometry;
299  c.get<MuonGeometryRecord>().get(rpcGeometry);
300 
301  const RPCRoll* roll = rpcGeometry->roll(detid);
302  GlobalPoint stripPosition = roll->toGlobal(roll->centreOfStrip(strip));
303 
304  double globalphi = stripPosition.phi();
305  int sector = (roll->id()).sector();
306  if ( sector == 1) radialAngle = int( globalphi*1024 );
307  else {
308  if ( globalphi >= 0) radialAngle = int( (globalphi-(sector-1)*Geom::pi()/6.)*1024 );
309  else radialAngle = int( (globalphi+(13-sector)*Geom::pi()/6.)*1024 );
310  }
311  return radialAngle;
312 }
313 
316  edm::ESHandle<RPCGeometry> rpcGeometry;
317  c.get<MuonGeometryRecord>().get(rpcGeometry);
318 
319  const RPCRoll* roll = rpcGeometry->roll(detid);
320 
322  GlobalPoint p1cmPRG = roll->toGlobal(LocalPoint(1,0,0));
323  GlobalPoint m1cmPRG = roll->toGlobal(LocalPoint(-1,0,0));
324  float phip1cm = p1cmPRG.phi();
325  float phim1cm = m1cmPRG.phi();
326  int direction = (phip1cm-phim1cm)/abs(phip1cm-phim1cm);
328 
329  return direction * roll->centreOfStrip(strip).x();
330 }
331 
332 int RPCtoDTTranslator::bendingAngle(int xin, int xout, int phi){
333  // use chamber size and max angle in hw units 512
334  int atanv = (int)(atan((xout-xin)/34.6) * 512);
335  if(atanv>512) return 512;
336  int rvalue = atanv - phi/8;
337  return rvalue;
338 }
339 
340 int RPCtoDTTranslator::localXX(int phi, int layer, int station){
341  //R[stat][layer] - radius of rpc station/layer from center of CMS
342  double R[2][2] = {{410.0,444.8},{492.7,527.3}};
343  double rvalue = R[station-1][layer-1]*tan(phi/4096.);
344  return rvalue;
345 }
size
Write out results.
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:52
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:32
static int bendingAngle(int, int, int)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
#define constexpr
RPCDetId id() const
Definition: RPCRoll.cc:24
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
T operator[](int i) const
int layer() const
Definition: RPCDetId.h:108
void run(const edm::EventSetup &c)
static int radialAngle(RPCDetId, const edm::EventSetup &, int)
function - will be replaced by LUTs(?)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
T get() const
Definition: EventSetup.h:63
static int localXX(int, int, int)
constexpr double pi()
Definition: Pi.h:31
T x() const
Definition: PV3DBase.h:62
RPCtoDTTranslator(RPCDigiCollection inrpcDigis)
const RPCRoll * roll(RPCDetId id) const
Return a roll given its id.
Definition: RPCGeometry.cc:75
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96
static int localX(RPCDetId, const edm::EventSetup &, int)
function - will be replaced by LUTs(?)