CMS 3D CMS Logo

RecHitProcessor.cc
Go to the documentation of this file.
10 
12 
14 
16  const edm::EventSetup &iSetup,
17  const edm::EDGetToken &recHitToken,
18  const edm::EDGetToken &rpcDigiToken,
19  const edm::EDGetToken &rpcDigiSimLinkToken,
21  std::vector<RecHitProcessor::CppfItem> &CppfVec1,
22  l1t::CPPFDigiCollection &cppfDigis,
23  const int MaxClusterSize) const {
25  iEvent.getByToken(recHitToken, recHits);
26 
28  iEvent.getByToken(rpcDigiToken, rpcDigis);
29 
31  iEvent.getByToken(rpcDigiSimLinkToken, theSimlinkDigis);
32 
33  const auto &rpcGeom = iSetup.getData(rpcGeomToken);
34 
35  for (const auto &&rpcdgIt : (*rpcDigis)) {
36  const RPCDetId &rpcId = rpcdgIt.first;
37  const RPCDigiCollection::Range &range = rpcdgIt.second;
38  if (rpcId.region() == 0)
39  continue;
40 
41  CPPFClusterizer clizer;
42  CPPFClusterContainer tcls = clizer.doAction(range);
43  CPPFMaskReClusterizer mrclizer;
45  CPPFClusterContainer cls = mrclizer.doAction(rpcId, tcls, mask);
46 
47  for (const auto &cl : cls) {
48  int isValid = rpcDigis.isValid();
49  int rawId = rpcId.rawId();
50  int Bx = cl.bx();
51  const int firststrip = cl.firstStrip();
52  const int clustersize = cl.clusterSize();
53  const int laststrip = cl.lastStrip();
54  const RPCRoll *roll = rpcGeom.roll(rpcId);
55  // Get Average Strip position
56  const float fstrip = (roll->centreOfStrip(firststrip)).x();
57  const float lstrip = (roll->centreOfStrip(laststrip)).x();
58  const float centreOfCluster = (fstrip + lstrip) / 2;
59  const double y = cl.hasY() ? cl.y() : 0;
60  LocalPoint lPos(centreOfCluster, y, 0);
61  if (roll->id().region() != 0) {
62  const auto &topo = dynamic_cast<const TrapezoidalStripTopology &>(roll->topology());
63  const double angle = topo.stripAngle((firststrip + laststrip) / 2.);
64  const double x = centreOfCluster - y * std::tan(angle);
65  lPos = LocalPoint(x, y, 0);
66  }
67  const BoundPlane &rollSurface = roll->surface();
68  GlobalPoint gPos = rollSurface.toGlobal(lPos);
69  float global_theta = emtf::rad_to_deg(gPos.theta().value());
70  float global_phi = emtf::rad_to_deg(gPos.phi().value());
71 
72  // Establish the average position of the rechit
73  int rechitstrip = firststrip;
74 
75  if (clustersize > 2) {
76  int medium = 0;
77  if (clustersize % 2 == 0)
78  medium = 0.5 * (clustersize);
79  else
80  medium = 0.5 * (clustersize - 1);
81  rechitstrip += medium;
82  }
83  if (clustersize > MaxClusterSize)
84  continue;
85  // This is just for test CPPFDigis with the RPC Geometry, It must be
86  // "true" in the normal runs
87  bool Geo = true;
89  // Set the EMTF Sector
90  int EMTFsector1 = 0;
91  int EMTFsector2 = 0;
92 
93  // sector 1
94  if ((global_phi > 15.) && (global_phi <= 16.3)) {
95  EMTFsector1 = 1;
96  EMTFsector2 = 6;
97  } else if ((global_phi > 16.3) && (global_phi <= 53.)) {
98  EMTFsector1 = 1;
99  EMTFsector2 = 0;
100  } else if ((global_phi > 53.) && (global_phi <= 75.)) {
101  EMTFsector1 = 1;
102  EMTFsector2 = 2;
103  }
104  // sector 2
105  else if ((global_phi > 75.) && (global_phi <= 76.3)) {
106  EMTFsector1 = 1;
107  EMTFsector2 = 2;
108  } else if ((global_phi > 76.3) && (global_phi <= 113.)) {
109  EMTFsector1 = 2;
110  EMTFsector2 = 0;
111  } else if ((global_phi > 113.) && (global_phi <= 135.)) {
112  EMTFsector1 = 2;
113  EMTFsector2 = 3;
114  }
115  // sector 3
116  // less than 180
117  else if ((global_phi > 135.) && (global_phi <= 136.3)) {
118  EMTFsector1 = 2;
119  EMTFsector2 = 3;
120  } else if ((global_phi > 136.3) && (global_phi <= 173.)) {
121  EMTFsector1 = 3;
122  EMTFsector2 = 0;
123  } else if ((global_phi > 173.) && (global_phi <= 180.)) {
124  EMTFsector1 = 3;
125  EMTFsector2 = 4;
126  }
127  // Greater than -180
128  else if ((global_phi < -165.) && (global_phi >= -180.)) {
129  EMTFsector1 = 3;
130  EMTFsector2 = 4;
131  }
132  // Fourth sector
133  else if ((global_phi > -165.) && (global_phi <= -163.7)) {
134  EMTFsector1 = 3;
135  EMTFsector2 = 4;
136  } else if ((global_phi > -163.7) && (global_phi <= -127.)) {
137  EMTFsector1 = 4;
138  EMTFsector2 = 0;
139  } else if ((global_phi > -127.) && (global_phi <= -105.)) {
140  EMTFsector1 = 4;
141  EMTFsector2 = 5;
142  }
143  // fifth sector
144  else if ((global_phi > -105.) && (global_phi <= -103.7)) {
145  EMTFsector1 = 4;
146  EMTFsector2 = 5;
147  } else if ((global_phi > -103.7) && (global_phi <= -67.)) {
148  EMTFsector1 = 5;
149  EMTFsector2 = 0;
150  } else if ((global_phi > -67.) && (global_phi <= -45.)) {
151  EMTFsector1 = 5;
152  EMTFsector2 = 6;
153  }
154  // sixth sector
155  else if ((global_phi > -45.) && (global_phi <= -43.7)) {
156  EMTFsector1 = 5;
157  EMTFsector2 = 6;
158  } else if ((global_phi > -43.7) && (global_phi <= -7.)) {
159  EMTFsector1 = 6;
160  EMTFsector2 = 0;
161  } else if ((global_phi > -7.) && (global_phi <= 15.)) {
162  EMTFsector1 = 6;
163  EMTFsector2 = 1;
164  }
165 
166  double EMTFLink1 = 0.;
167  double EMTFLink2 = 0.;
168  std::vector<RecHitProcessor::CppfItem>::iterator cppf1;
169  std::vector<RecHitProcessor::CppfItem>::iterator cppf;
170  for (cppf1 = CppfVec1.begin(); cppf1 != CppfVec1.end(); cppf1++) {
171  // Condition to save the CPPFDigi
172  if (((*cppf1).rawId == rawId) && ((*cppf1).strip == rechitstrip)) {
173  int old_strip = (*cppf1).strip;
174  int before = 0;
175  int after = 0;
176 
177  if (cppf1 != CppfVec1.begin())
178  before = (*(cppf1 - 2)).strip;
179  else if (cppf1 == CppfVec1.begin())
180  before = (*cppf1).strip;
181  if (cppf1 != CppfVec1.end())
182  after = (*(cppf1 + 2)).strip;
183  else if (cppf1 == CppfVec1.end())
184  after = (*cppf1).strip;
185  cppf = cppf1;
186 
187  if (clustersize == 2) {
188  if (firststrip == 1) {
189  if (before < after)
190  cppf = (cppf1 - 1);
191  else if (before > after)
192  cppf = (cppf1 + 1);
193  } else if (firststrip > 1) {
194  if (before < after)
195  cppf = (cppf1 + 1);
196  else if (before > after)
197  cppf = (cppf1 - 1);
198  }
199  }
200  // Using the RPCGeometry
201  if (Geo) {
202  std::shared_ptr<l1t::CPPFDigi> MainVariables1(new l1t::CPPFDigi(rpcId,
203  Bx,
204  (*cppf).int_phi,
205  (*cppf).int_theta,
206  isValid,
207  (*cppf).lb,
208  (*cppf).halfchannel,
209  EMTFsector1,
210  EMTFLink1,
211  old_strip,
212  clustersize,
213  global_phi,
214  global_theta));
215  std::shared_ptr<l1t::CPPFDigi> MainVariables2(new l1t::CPPFDigi(rpcId,
216  Bx,
217  (*cppf).int_phi,
218  (*cppf).int_theta,
219  isValid,
220  (*cppf).lb,
221  (*cppf).halfchannel,
222  EMTFsector2,
223  EMTFLink2,
224  old_strip,
225  clustersize,
226  global_phi,
227  global_theta));
228 
229  if ((EMTFsector1 > 0) && (EMTFsector2 == 0)) {
230  cppfDigis.push_back(*MainVariables1.get());
231  } else if ((EMTFsector1 > 0) && (EMTFsector2 > 0)) {
232  cppfDigis.push_back(*MainVariables1.get());
233  cppfDigis.push_back(*MainVariables2.get());
234  } else if ((EMTFsector1 == 0) && (EMTFsector2 == 0)) {
235  continue;
236  }
237  } // Geo is true
238  else {
239  global_phi = 0.;
240  global_theta = 0.;
241  std::shared_ptr<l1t::CPPFDigi> MainVariables1(new l1t::CPPFDigi(rpcId,
242  Bx,
243  (*cppf).int_phi,
244  (*cppf).int_theta,
245  isValid,
246  (*cppf).lb,
247  (*cppf).halfchannel,
248  EMTFsector1,
249  EMTFLink1,
250  old_strip,
251  clustersize,
252  global_phi,
253  global_theta));
254  std::shared_ptr<l1t::CPPFDigi> MainVariables2(new l1t::CPPFDigi(rpcId,
255  Bx,
256  (*cppf).int_phi,
257  (*cppf).int_theta,
258  isValid,
259  (*cppf).lb,
260  (*cppf).halfchannel,
261  EMTFsector2,
262  EMTFLink2,
263  old_strip,
264  clustersize,
265  global_phi,
266  global_theta));
267  if ((EMTFsector1 > 0) && (EMTFsector2 == 0)) {
268  cppfDigis.push_back(*MainVariables1.get());
269  } else if ((EMTFsector1 > 0) && (EMTFsector2 > 0)) {
270  cppfDigis.push_back(*MainVariables1.get());
271  cppfDigis.push_back(*MainVariables2.get());
272  } else if ((EMTFsector1 == 0) && (EMTFsector2 == 0)) {
273  continue;
274  }
275  }
276  } // Condition to save the CPPFDigi
277  } // Loop over the LUTVector
278  } //end loop over cludters
279  } //end loop over digis
280 } //end processlook function
281 
283  const edm::EventSetup &iSetup,
284  const edm::EDGetToken &recHitToken,
285  const edm::EDGetToken &rpcDigiToken,
286  const edm::EDGetToken &rpcDigiSimLinkToken,
288  l1t::CPPFDigiCollection &cppfDigis) const {
289  // Get the RPC Geometry
290  const auto &rpcGeom = iSetup.getData(rpcGeomToken);
291 
293  iEvent.getByToken(rpcDigiToken, rpcDigis);
294 
295  // Get the RecHits from the event
297  iEvent.getByToken(recHitToken, recHits);
298 
299  for (const auto &&rpcdgIt : (*rpcDigis)) {
300  const RPCDetId &rpcId = rpcdgIt.first;
301  const RPCDigiCollection::Range &range = rpcdgIt.second;
302  if (rpcId.region() == 0)
303  continue;
304 
305  CPPFClusterizer clizer;
306  CPPFClusterContainer tcls = clizer.doAction(range);
307  CPPFMaskReClusterizer mrclizer;
309  CPPFClusterContainer cls = mrclizer.doAction(rpcId, tcls, mask);
310 
311  for (const auto &cl : cls) {
312  int region = rpcId.region();
313  int isValid = rpcDigis.isValid();
314  // int rawId = rpcId.rawId();
315  int Bx = cl.bx();
316  const int firststrip = cl.firstStrip();
317  const int clustersize = cl.clusterSize();
318  const int laststrip = cl.lastStrip();
319  const RPCRoll *roll = rpcGeom.roll(rpcId);
320  // Get Average Strip position
321  const float fstrip = (roll->centreOfStrip(firststrip)).x();
322  const float lstrip = (roll->centreOfStrip(laststrip)).x();
323  const float centreOfCluster = (fstrip + lstrip) / 2;
324  const double y = cl.hasY() ? cl.y() : 0;
325  LocalPoint lPos(centreOfCluster, y, 0);
326  if (roll->id().region() != 0) {
327  const auto &topo = dynamic_cast<const TrapezoidalStripTopology &>(roll->topology());
328  const double angle = topo.stripAngle((firststrip + laststrip) / 2.);
329  const double x = centreOfCluster - y * std::tan(angle);
330  lPos = LocalPoint(x, y, 0);
331  }
332  const BoundPlane &rollSurface = roll->surface();
333  GlobalPoint gPos = rollSurface.toGlobal(lPos);
334  float global_theta = emtf::rad_to_deg(gPos.theta().value());
335  float global_phi = emtf::rad_to_deg(gPos.phi().value());
336 
337  // Endcap region only
338  if (region != 0) {
339  int int_theta =
340  (region == -1 ? 180. * 32. / 36.5 : 0.) + (float)region * global_theta * 32. / 36.5 - 8.5 * 32 / 36.5;
341  if (region == 1) {
342  if (global_theta < 8.5)
343  int_theta = 0;
344  if (global_theta > 45.)
345  int_theta = 31;
346  } else if (region == -1) {
347  if (global_theta < 135.)
348  int_theta = 31;
349  if (global_theta > 171.5)
350  int_theta = 0;
351  }
352  // Local EMTF
353  double local_phi = 0.;
354  int EMTFsector1 = 0;
355  int EMTFsector2 = 0;
356 
357  // sector 1
358  if ((global_phi > 15.) && (global_phi <= 16.3)) {
359  local_phi = global_phi - 15.;
360  EMTFsector1 = 1;
361  EMTFsector2 = 6;
362  } else if ((global_phi > 16.3) && (global_phi <= 53.)) {
363  local_phi = global_phi - 15.;
364  EMTFsector1 = 1;
365  EMTFsector2 = 0;
366  } else if ((global_phi > 53.) && (global_phi <= 75.)) {
367  local_phi = global_phi - 15.;
368  EMTFsector1 = 1;
369  EMTFsector2 = 2;
370  }
371  // sector 2
372  else if ((global_phi > 75.) && (global_phi <= 76.3)) {
373  local_phi = global_phi - 15.;
374  EMTFsector1 = 1;
375  EMTFsector2 = 2;
376  } else if ((global_phi > 76.3) && (global_phi <= 113.)) {
377  local_phi = global_phi - 75.;
378  EMTFsector1 = 2;
379  EMTFsector2 = 0;
380  } else if ((global_phi > 113.) && (global_phi <= 135.)) {
381  local_phi = global_phi - 75.;
382  EMTFsector1 = 2;
383  EMTFsector2 = 3;
384  }
385  // sector 3
386  // less than 180
387  else if ((global_phi > 135.) && (global_phi <= 136.3)) {
388  local_phi = global_phi - 75.;
389  EMTFsector1 = 2;
390  EMTFsector2 = 3;
391  } else if ((global_phi > 136.3) && (global_phi <= 173.)) {
392  local_phi = global_phi - 135.;
393  EMTFsector1 = 3;
394  EMTFsector2 = 0;
395  } else if ((global_phi > 173.) && (global_phi <= 180.)) {
396  local_phi = global_phi - 135.;
397  EMTFsector1 = 3;
398  EMTFsector2 = 4;
399  }
400  // Greater than -180
401  else if ((global_phi < -165.) && (global_phi >= -180.)) {
402  local_phi = global_phi + 225.;
403  EMTFsector1 = 3;
404  EMTFsector2 = 4;
405  }
406  // Fourth sector
407  else if ((global_phi > -165.) && (global_phi <= -163.7)) {
408  local_phi = global_phi + 225.;
409  EMTFsector1 = 3;
410  EMTFsector2 = 4;
411  } else if ((global_phi > -163.7) && (global_phi <= -127.)) {
412  local_phi = global_phi + 165.;
413  EMTFsector1 = 4;
414  EMTFsector2 = 0;
415  } else if ((global_phi > -127.) && (global_phi <= -105.)) {
416  local_phi = global_phi + 165.;
417  EMTFsector1 = 4;
418  EMTFsector2 = 5;
419  }
420  // fifth sector
421  else if ((global_phi > -105.) && (global_phi <= -103.7)) {
422  local_phi = global_phi + 165.;
423  EMTFsector1 = 4;
424  EMTFsector2 = 5;
425  } else if ((global_phi > -103.7) && (global_phi <= -67.)) {
426  local_phi = global_phi + 105.;
427  EMTFsector1 = 5;
428  EMTFsector2 = 0;
429  } else if ((global_phi > -67.) && (global_phi <= -45.)) {
430  local_phi = global_phi + 105.;
431  EMTFsector1 = 5;
432  EMTFsector2 = 6;
433  }
434  // sixth sector
435  else if ((global_phi > -45.) && (global_phi <= -43.7)) {
436  local_phi = global_phi + 105.;
437  EMTFsector1 = 5;
438  EMTFsector2 = 6;
439  } else if ((global_phi > -43.7) && (global_phi <= -7.)) {
440  local_phi = global_phi + 45.;
441  EMTFsector1 = 6;
442  EMTFsector2 = 0;
443  } else if ((global_phi > -7.) && (global_phi <= 15.)) {
444  local_phi = global_phi + 45.;
445  EMTFsector1 = 6;
446  EMTFsector2 = 1;
447  }
448 
449  int int_phi = int((local_phi + 22.0) * 15. + .5);
450  double EMTFLink1 = 0.;
451  double EMTFLink2 = 0.;
452  double lb = 0.;
453  double halfchannel = 0.;
454 
455  // Invalid hit
456  if (isValid == 0)
457  int_phi = 2047;
458  // Right integers range
459  assert(0 <= int_phi && int_phi < 1250);
460  assert(0 <= int_theta && int_theta < 32);
461 
462  std::shared_ptr<l1t::CPPFDigi> MainVariables1(new l1t::CPPFDigi(rpcId,
463  Bx,
464  int_phi,
465  int_theta,
466  isValid,
467  lb,
468  halfchannel,
469  EMTFsector1,
470  EMTFLink1,
471  firststrip,
472  clustersize,
473  global_phi,
474  global_theta));
475  std::shared_ptr<l1t::CPPFDigi> MainVariables2(new l1t::CPPFDigi(rpcId,
476  Bx,
477  int_phi,
478  int_theta,
479  isValid,
480  lb,
481  halfchannel,
482  EMTFsector2,
483  EMTFLink2,
484  firststrip,
485  clustersize,
486  global_phi,
487  global_theta));
488  if (int_theta == 31)
489  continue;
490  if ((EMTFsector1 > 0) && (EMTFsector2 == 0)) {
491  cppfDigis.push_back(*MainVariables1.get());
492  }
493  if ((EMTFsector1 > 0) && (EMTFsector2 > 0)) {
494  cppfDigis.push_back(*MainVariables1.get());
495  cppfDigis.push_back(*MainVariables2.get());
496  }
497  if ((EMTFsector1 == 0) && (EMTFsector2 == 0)) {
498  continue;
499  }
500  } // No barrel hits
501  } //end loop over clusters
502  } //end loop over digis
503 } // End function: void RecHitProcessor::process()
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
assert(be >=bs)
CPPFClusterContainer doAction(const RPCDigiCollection::Range &digiRange)
constexpr uint32_t mask
Definition: gpuClustering.h:26
std::set< CPPFCluster > CPPFClusterContainer
int iEvent
Definition: GenABIO.cc:224
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
void process(const edm::Event &iEvent, const edm::EventSetup &iSetup, const edm::EDGetToken &recHitToken, const edm::EDGetToken &rpcDigiToken, const edm::EDGetToken &rpcDigiSimLinkToken, const edm::ESGetToken< RPCGeometry, MuonGeometryRecord > &rpcGeomToken, l1t::CPPFDigiCollection &cppfDigis) const
CPPFClusterContainer doAction(const RPCDetId &id, CPPFClusterContainer &initClusters, const CPPFRollMask &mask) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::pair< const_iterator, const_iterator > Range
std::bitset< maskCPPFSIZE > CPPFRollMask
bool isValid() const
Definition: HandleBase.h:70
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
double rad_to_deg(double rad)
Definition: TrackTools.h:77
T1 value() const
Explicit access to value in case implicit conversion not OK.
Definition: Phi.h:75
void processLook(const edm::Event &iEvent, const edm::EventSetup &iSetup, const edm::EDGetToken &recHitToken, const edm::EDGetToken &rpcDigiToken, const edm::EDGetToken &rpcDigiSimLinkToken, const edm::ESGetToken< RPCGeometry, MuonGeometryRecord > &rpcGeomToken, std::vector< RecHitProcessor::CppfItem > &CppfVec1, l1t::CPPFDigiCollection &cppfDigis, const int MaxClusterSize) const
std::vector< CPPFDigi > CPPFDigiCollection
Definition: CPPFDigi.h:83
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11