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