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