CMS 3D CMS Logo

RPCIntegrator.cc
Go to the documentation of this file.
4 
6 
8 
9 #include <cmath>
10 
11 using namespace cmsdt;
12 
14  : m_debug_(pset.getUntrackedParameter<bool>("debug")),
15  m_max_quality_to_overwrite_t0_(pset.getParameter<int>("max_quality_to_overwrite_t0")),
16  m_bx_window_(pset.getParameter<int>("bx_window")),
17  m_phi_window_(pset.getParameter<double>("phi_window")),
18  m_storeAllRPCHits_(pset.getParameter<bool>("storeAllRPCHits")) {
19  if (m_debug_)
20  LogDebug("RPCIntegrator") << "RPCIntegrator constructor";
21 
24 }
25 
27  if (m_debug_)
28  LogDebug("RPCIntegrator") << "RPCIntegrator destructor";
29 }
30 
31 void RPCIntegrator::initialise(const edm::EventSetup& iEventSetup, double shift_back_fromDT) {
32  if (m_debug_)
33  LogDebug("RPCIntegrator") << "RPCIntegrator initialisation";
34 
35  if (m_debug_)
36  LogDebug("RPCIntegrator") << "Getting RPC geometry";
37 
38  if (auto handle = iEventSetup.getHandle(dtGeomH_)) {
39  dtGeo_ = handle.product();
40  }
41 
42  if (auto handle = iEventSetup.getHandle(rpcGeomH_)) {
43  rpcGeo_ = handle.product();
44  }
45 
46  shift_back_ = shift_back_fromDT;
47 }
48 
50 
52  RPCMetaprimitives_.clear();
53  rpcRecHits_translated_.clear();
54  for (const auto& rpcIt : *rpcRecHits) {
55  RPCDetId rpcDetId = (RPCDetId)(rpcIt).rpcId();
56  GlobalPoint global_position = RPCGlobalPosition(rpcDetId, rpcIt);
57  int rpc_region = rpcDetId.region();
58  if (rpc_region != 0)
59  continue; // Region = 0 Barrel
60 
61  // set everyone to rpc single hit (3) not matched to DT flag for now
62  // change last two elements if dt bx centered at zero again
63  RPCMetaprimitives_.emplace_back(
64  rpcDetId, &rpcIt, global_position, RPC_HIT, rpcIt.BunchX() + BX_SHIFT, rpcIt.time() + BX_SHIFT * LHC_CLK_FREQ);
65  }
66 }
67 void RPCIntegrator::matchWithDTAndUseRPCTime(std::vector<metaPrimitive>& dt_metaprimitives) {
68  for (auto dt_metaprimitive = dt_metaprimitives.begin(); dt_metaprimitive != dt_metaprimitives.end();
69  dt_metaprimitive++) {
70  RPCMetaprimitive* bestMatch_rpcRecHit = matchDTwithRPC(&*dt_metaprimitive);
71  if (bestMatch_rpcRecHit) {
72  (*dt_metaprimitive).rpcFlag = RPC_CONFIRM;
73  if ((*dt_metaprimitive).quality < m_max_quality_to_overwrite_t0_) {
74  (*dt_metaprimitive).t0 = bestMatch_rpcRecHit->rpc_t0 + 25 * shift_back_;
75  (*dt_metaprimitive).rpcFlag = RPC_TIME;
76  }
77  }
78  }
79 }
80 
82  std::vector<L1Phase2MuDTPhDigi> rpc_only_segments;
83  for (auto& rpc_mp_it_layer1 : RPCMetaprimitives_) {
84  RPCDetId rpc_id_l1 = rpc_mp_it_layer1.rpc_id;
85  const RPCRecHit* rpc_cluster_l1 = rpc_mp_it_layer1.rpc_cluster;
86  GlobalPoint rpc_gp_l1 = rpc_mp_it_layer1.global_position;
87  if (rpc_id_l1.station() > 2 || rpc_id_l1.layer() != 1 ||
88  (rpc_mp_it_layer1.rpcFlag == RPC_ASSOCIATE && !m_storeAllRPCHits_))
89  continue;
90  // only one RPC layer in station three and four &&
91  // avoid duplicating pairs &&
92  // avoid building RPC only segment if DT segment was already there
93  int min_dPhi = std::numeric_limits<int>::max();
94  RPCMetaprimitive* bestMatch_rpc_mp_layer2 = nullptr;
95  for (auto& rpc_mp_it_layer2 : RPCMetaprimitives_) {
96  RPCDetId rpc_id_l2 = rpc_mp_it_layer2.rpc_id;
97  const RPCRecHit* rpc_cluster_l2 = rpc_mp_it_layer2.rpc_cluster;
98  GlobalPoint rpc_gp_l2 = rpc_mp_it_layer2.global_position;
99  if (rpc_id_l2.station() == rpc_id_l1.station() && rpc_id_l2.ring() == rpc_id_l1.ring() &&
100  rpc_id_l2.layer() != rpc_id_l1.layer() // ensure to have layer 1 --> layer 2
101  && rpc_id_l2.sector() == rpc_id_l1.sector() && rpc_cluster_l2->BunchX() == rpc_cluster_l1->BunchX() &&
102  (rpc_mp_it_layer2.rpcFlag != RPC_ASSOCIATE || m_storeAllRPCHits_)) {
103  // avoid building RPC only segment with a hit already matched to DT,
104  // except if one aske to store all RPC info
105  float tmp_dPhi = rpc_gp_l1.phi() - rpc_gp_l2.phi();
106  if (std::abs(tmp_dPhi) < std::abs(min_dPhi)) {
107  min_dPhi = tmp_dPhi;
108  bestMatch_rpc_mp_layer2 = &rpc_mp_it_layer2;
109  }
110  }
111  }
112  if (bestMatch_rpc_mp_layer2) {
113  rpc_mp_it_layer1.rpcFlag = 6;
114  // need a new flag (will be removed later) to differentiate
115  // between "has been matched to DT" and "Has been used in an RPC only segment"
116  bestMatch_rpc_mp_layer2->rpcFlag = 6;
117  double phiB = phiBending(&rpc_mp_it_layer1, &*bestMatch_rpc_mp_layer2);
118  // Arbitrarily choose the phi from layer 1
119  double global_phi = rpc_mp_it_layer1.global_position.phi();
120  double t0 = (rpc_mp_it_layer1.rpc_t0 + bestMatch_rpc_mp_layer2->rpc_t0) / 2;
121  // RPC only segment have rpcFlag==2
122  L1Phase2MuDTPhDigi rpc_only_segment =
123  createL1Phase2MuDTPhDigi(rpc_id_l1, rpc_mp_it_layer1.rpc_bx, t0, global_phi, phiB, 2);
124  rpc_only_segments.push_back(rpc_only_segment);
125  }
126  }
127  rpcRecHits_translated_.insert(rpcRecHits_translated_.end(), rpc_only_segments.begin(), rpc_only_segments.end());
128 }
129 
131  for (auto rpc_mp_it = RPCMetaprimitives_.begin(); rpc_mp_it != RPCMetaprimitives_.end(); rpc_mp_it++) {
132  RPCDetId rpcDetId = rpc_mp_it->rpc_id;
133  if (rpc_mp_it->rpcFlag == 6)
134  rpc_mp_it->rpcFlag = RPC_ASSOCIATE;
136  rpcDetId, rpc_mp_it->rpc_bx, rpc_mp_it->rpc_t0, rpc_mp_it->global_position.phi(), -10000, rpc_mp_it->rpcFlag);
137  rpcRecHits_translated_.push_back(rpc_out);
138  }
139 }
140 
142  if (m_debug_)
143  LogDebug("RPCIntegrator") << "RPCIntegrator removeRPCHitsUsed method";
144  if (!m_storeAllRPCHits_) {
145  // Remove RPC hit attached to a DT or RPC segment if required by user
146  // (avoid having two TP's corresponding to the same physical hit)
147  auto rpcRecHit_translated_ = rpcRecHits_translated_.begin();
148  while (rpcRecHit_translated_ != rpcRecHits_translated_.end()) {
149  if (rpcRecHit_translated_->rpcFlag() == RPC_ASSOCIATE || rpcRecHit_translated_->rpcFlag() == 6) {
150  rpcRecHit_translated_ = rpcRecHits_translated_.erase(rpcRecHit_translated_);
151  } else {
152  ++rpcRecHit_translated_;
153  }
154  }
155  }
156 }
157 
159  // metaprimitive dtChId is still in convention with [1 - 12]
160  // because at this stage the BX of metaprimitive is not yet computed...
161  // will also have to subtract 20*25 ns because of the recent change
162  int dt_bx = (int)round(dt_metaprimitive->t0 / 25.) - shift_back_;
163  DTChamberId dt_chId = DTChamberId(dt_metaprimitive->rawId);
164  int dt_sector = dt_chId.sector();
165  if (dt_sector == 13)
166  dt_sector = 4;
167  if (dt_sector == 14)
168  dt_sector = 10;
169  RPCMetaprimitive* bestMatch_rpcRecHit = nullptr;
170  float min_dPhi = std::numeric_limits<float>::max();
171  for (auto rpc_mp_it = RPCMetaprimitives_.begin(); rpc_mp_it != RPCMetaprimitives_.end(); rpc_mp_it++) {
172  RPCDetId rpc_det_id = rpc_mp_it->rpc_id;
173  if (rpc_det_id.ring() == dt_chId.wheel() // ring() in barrel RPC corresponds to the wheel
174  && rpc_det_id.station() == dt_chId.station() && rpc_det_id.sector() == dt_sector &&
175  std::abs(rpc_mp_it->rpc_bx - dt_bx) <= m_bx_window_) {
176  // Select the RPC hit closest in phi to the DT meta primitive
177 
178  // just a trick to apply the phi window cut on what could be accessed to fine tune it
179  int delta_phi =
180  (int)round((phi_DT_MP_conv(rpc_mp_it->global_position.phi(), rpc_det_id.sector()) - dt_metaprimitive->phi) *
182  if (std::abs(delta_phi) < min_dPhi && std::abs(delta_phi) < m_phi_window_) {
183  min_dPhi = std::abs(delta_phi);
184  bestMatch_rpcRecHit = &*rpc_mp_it;
185  }
186  }
187  }
188  if (bestMatch_rpcRecHit) {
189  bestMatch_rpcRecHit->rpcFlag = RPC_ASSOCIATE;
190  }
191  return bestMatch_rpcRecHit;
192 }
193 
195  RPCDetId rpcDetId, int rpc_bx, double rpc_time, double rpc_global_phi, double phiB, int rpc_flag) {
196  if (m_debug_)
197  LogDebug("RPCIntegrator") << "Creating DT TP out of RPC recHits";
198  int rpc_wheel = rpcDetId.ring(); // In barrel, wheel is accessed via ring() method ([-2,+2])
199  int trigger_sector = rpcDetId.sector() - 1; // DT Trigger sector:[0,11] while RPC sector:[1,12]
200  int rpc_station = rpcDetId.station();
201  int rpc_layer = rpcDetId.layer();
202  int rpc_trigger_phi = phiInDTTPFormat(rpc_global_phi, rpcDetId.sector());
203  int rpc_trigger_phiB = (phiB == -10000) ? phiB : (int)round(phiB * cmsdt::PHIBRES_CONV);
204  int rpc_quality = -1; // dummy for rpc
205  int rpc_index = 0; // dummy for rpc
206  return L1Phase2MuDTPhDigi(rpc_bx,
207  rpc_wheel,
208  trigger_sector,
209  rpc_station,
210  rpc_layer, //this would be the layer in the new dataformat
211  rpc_trigger_phi,
212  rpc_trigger_phiB,
213  rpc_quality,
214  rpc_index,
215  rpc_time,
216  -1, // no chi2 for RPC
217  rpc_flag);
218 }
219 
221  DTChamberId DT_chamber(rpc_hit_1->rpc_id.ring(), rpc_hit_1->rpc_id.station(), rpc_hit_1->rpc_id.sector());
222  LocalPoint lp_rpc_hit_1_dtconv = dtGeo_->chamber(DT_chamber)->toLocal(rpc_hit_1->global_position);
223  LocalPoint lp_rpc_hit_2_dtconv = dtGeo_->chamber(DT_chamber)->toLocal(rpc_hit_2->global_position);
224  double slope = (lp_rpc_hit_1_dtconv.x() - lp_rpc_hit_2_dtconv.x()) / distance_between_two_rpc_layers_;
225  double average_x = (lp_rpc_hit_1_dtconv.x() + lp_rpc_hit_2_dtconv.x()) / 2;
226  GlobalPoint seg_middle_global =
227  dtGeo_->chamber(DT_chamber)->toGlobal(LocalPoint(average_x, 0., 0.)); // for station 1 and 2, z = 0
228  double seg_phi = phi_DT_MP_conv(seg_middle_global.phi(), rpc_hit_1->rpc_id.sector());
229  double psi = atan(slope);
230  double phiB = hasPosRF_rpc(rpc_hit_1->rpc_id.ring(), rpc_hit_1->rpc_id.sector()) ? psi - seg_phi : -psi - seg_phi;
231  return phiB;
232 }
233 
234 int RPCIntegrator::phiInDTTPFormat(double rpc_global_phi, int rpcSector) {
235  double rpc_localDT_phi;
236  rpc_localDT_phi = phi_DT_MP_conv(rpc_global_phi, rpcSector) * cmsdt::PHIBRES_CONV;
237  return (int)round(rpc_localDT_phi);
238 }
239 
240 double RPCIntegrator::phi_DT_MP_conv(double rpc_global_phi, int rpcSector) {
241  // Adaptation of https://github.com/cms-sw/cmssw/blob/master/L1Trigger/L1TTwinMux/src/RPCtoDTTranslator.cc#L349
242 
243  if (rpcSector == 1)
244  return rpc_global_phi;
245  else {
246  float conversion = 1 / 6.;
247  if (rpc_global_phi >= 0)
248  return rpc_global_phi - (rpcSector - 1) * M_PI * conversion;
249  else
250  return rpc_global_phi + (13 - rpcSector) * M_PI * conversion;
251  }
252 }
253 
255  RPCDetId rpcid = RPCDetId(rpcId);
256  const LocalPoint& rpc_lp = rpcIt.localPosition();
257  const GlobalPoint& rpc_gp = rpcGeo_->idToDet(rpcid)->surface().toGlobal(rpc_lp);
258 
259  return rpc_gp;
260 }
261 
262 bool RPCIntegrator::hasPosRF_rpc(int wh, int sec) const { return (wh > 0 || (wh == 0 && sec % 4 > 1)); }
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:81
double m_phi_window_
Definition: RPCIntegrator.h:86
int station() const
Return the station number.
Definition: DTChamberId.h:45
void storeRPCSingleHits()
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
constexpr float PHIBRES_CONV
Definition: constants.h:364
LocalPoint localPosition() const override
Return the 3-dimensional local position.
Definition: RPCRecHit.h:37
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
int m_max_quality_to_overwrite_t0_
Definition: RPCIntegrator.h:84
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
static const double slope[3]
void matchWithDTAndUseRPCTime(std::vector< cmsdt::metaPrimitive > &dt_metaprimitives)
L1Phase2MuDTPhDigi createL1Phase2MuDTPhDigi(RPCDetId rpcDetId, int rpc_bx, double rpc_time, double rpc_global_phi, double phiB, int rpc_flag)
void removeRPCHitsUsed()
double phi_DT_MP_conv(double rpc_global_phi, int rpcSector)
int ring() const
Definition: RPCDetId.h:59
std::vector< RPCMetaprimitive > RPCMetaprimitives_
Definition: RPCIntegrator.h:80
GlobalPoint global_position
Definition: RPCIntegrator.h:37
std::map< std::string, int, std::less< std::string > > psi
RPCGeometry const * rpcGeo_
Definition: RPCIntegrator.h:92
T x() const
Definition: PV3DBase.h:59
GlobalPoint RPCGlobalPosition(RPCDetId rpcId, const RPCRecHit &rpcIt) const
double shift_back_
Definition: RPCIntegrator.h:99
int BunchX() const
Definition: RPCRecHit.h:73
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void makeRPCOnlySegments()
RPCIntegrator(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
#define M_PI
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
constexpr int BX_SHIFT
Definition: constants.h:396
void conversion(EventAux const &from, EventAuxiliary &to)
Definition: EventAux.cc:9
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
static constexpr double distance_between_two_rpc_layers_
Definition: RPCIntegrator.h:97
std::vector< L1Phase2MuDTPhDigi > rpcRecHits_translated_
Definition: RPCIntegrator.h:79
const bool m_debug_
Definition: RPCIntegrator.h:83
constexpr int LHC_CLK_FREQ
Definition: constants.h:222
int station() const
Definition: RPCDetId.h:78
bool hasPosRF_rpc(int wh, int sec) const
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
void prepareMetaPrimitives(edm::Handle< RPCRecHitCollection > rpcRecHits)
double phiBending(RPCMetaprimitive *rpc_hit_1, RPCMetaprimitive *rpc_hit_2)
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
int sector() const
Definition: DTChamberId.h:52
bool m_storeAllRPCHits_
Definition: RPCIntegrator.h:87
int phiInDTTPFormat(double rpc_global_phi, int rpcSector)
edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomH_
Definition: RPCIntegrator.h:88
int layer() const
Definition: RPCDetId.h:85
void initialise(const edm::EventSetup &iEventSetup, double shift_back_fromDT)
const GeomDet * idToDet(DetId) const override
Definition: RPCGeometry.cc:32
RPCMetaprimitive * matchDTwithRPC(cmsdt::metaPrimitive *dt_metaprimitive)
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > rpcGeomH_
Definition: RPCIntegrator.h:89
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
#define LogDebug(id)
DTGeometry const * dtGeo_
Definition: RPCIntegrator.h:91