58 auto _ThePoints = std::make_unique<RPCRecHitCollection>();
60 std::vector<uint32_t> extrapolatedRolls;
62 if (all4DSegments->size() > 8) {
64 LogDebug(
"DTSegtoRPC") <<
"Too many segments in this event we are not doing the extrapolation" << std::endl;
70 std::map<DTChamberId, int> DTSegmentCounter;
73 for (segment = all4DSegments->begin(); segment != all4DSegments->end(); ++segment) {
74 DTSegmentCounter[segment->chamberId()]++;
77 const float bunchCrossTimeDiff = 25.;
80 for (segment = all4DSegments->begin(); segment != all4DSegments->end(); ++segment) {
84 LogDebug(
"DTSegtoRPC") <<
"DT \t \t This Segment is in Chamber id: " << DTId << std::endl;
86 LogDebug(
"DTSegtoRPC") <<
"DT \t \t Number of segments in this DT = " << DTSegmentCounter[DTId] << std::endl;
88 LogDebug(
"DTSegtoRPC") <<
"DT \t \t Is the only one in this DT? and is not in the 4th Station?" << std::endl;
90 if (DTSegmentCounter[DTId] != 1 || DTId.
station() == 4) {
92 LogDebug(
"DTSegtoRPC") <<
"DT \t \t More than one segment in this chamber, or we are in Station 4" 97 int dtWheel = DTId.
wheel();
99 int dtSector = DTId.
sector();
101 LocalPoint segmentPosition = segment->localPosition();
102 LocalVector segmentDirection = segment->localDirection();
110 LogDebug(
"DTSegtoRPC") <<
"DT \t \t Is the segment 4D?" << std::endl;
112 if (segment->dimension() != 4) {
114 LogDebug(
"DTSegtoRPC") <<
"DT \t \t no" << std::endl;
119 LogDebug(
"DTSegtoRPC") <<
"DT \t \t yes" << std::endl;
121 LogDebug(
"DTSegtoRPC") <<
"DT \t \t DT Segment Dimension " << segment->dimension() << std::endl;
123 float Xo = segmentPosition.
x();
124 float Yo = segmentPosition.
y();
125 float Zo = segmentPosition.
z();
126 float dx = segmentDirection.
x();
127 float dy = segmentDirection.
y();
128 float dz = segmentDirection.
z();
130 float myPhiTime = -9999.;
131 float myPhiTimeErr = -9999.;
134 if (segment->hasPhi()) {
135 myPhiTime = segment->phiSegment()->t0();
136 myPhiBx = round(segment->phiSegment()->t0() / bunchCrossTimeDiff);
138 LogDebug(
"DTSegtoRPC") <<
"segment t0 = " << myPhiTime <<
"\tround = " << myPhiBx << std::endl;
140 if (!(myPhiBx <= maxPhiBX && myPhiBx >=
minPhiBX))
144 LogDebug(
"DTSegtoRPC") <<
"Creating the DTIndex" << std::endl;
147 LogDebug(
"DTSegtoRPC") <<
"Getting the Rolls for the given index" << std::endl;
148 std::set<RPCDetId> rollsForThisDT = dtMap->
getRolls(theindex);
151 LogDebug(
"DTSegtoRPC") <<
"DT \t \t Number of rolls for this DT = " << rollsForThisDT.size() << std::endl;
153 assert(!rollsForThisDT.empty());
156 LogDebug(
"DTSegtoRPC") <<
"DT \t \t Loop over all the rolls asociated to this DT" << std::endl;
157 for (std::set<RPCDetId>::iterator iteraRoll = rollsForThisDT.begin(); iteraRoll != rollsForThisDT.end();
159 const RPCRoll* rollasociated = rpcGeo->
roll(*iteraRoll);
167 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t RollName: " << nameRoll << std::endl;
169 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Doing the extrapolation to this roll" << std::endl;
171 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t DT Segment Direction in DTLocal " << segmentDirection << std::endl;
173 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t DT Segment Point in DTLocal " << segmentPosition << std::endl;
177 LocalPoint CenterRollinDTFrame = DTSurface.toLocal(CenterPointRollGlobal);
180 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Center (0,0,0) Roll In DTLocal" << CenterRollinDTFrame << std::endl;
182 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Center (0,0,0) of the Roll in Global" << CenterPointRollGlobal
185 float D = CenterRollinDTFrame.
z();
187 float X = Xo +
dx *
D /
dz;
188 float Y = Yo +
dy *
D /
dz;
195 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t xmin of this Roll " <<
xmin <<
"cm" << std::endl;
198 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t xmax of this Roll " <<
xmax <<
"cm" << std::endl;
199 float rsize = fabs(
xmax.x() -
xmin.x());
201 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Roll Size " << rsize <<
"cm" << std::endl;
204 float stripw = top_->
pitch();
207 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Strip Lenght " << stripl <<
"cm" << std::endl;
209 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Strip Width " << stripw <<
"cm" << std::endl;
211 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t X Predicted in DTLocal= " <<
X <<
"cm" << std::endl;
213 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Y Predicted in DTLocal= " <<
Y <<
"cm" << std::endl;
215 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Z Predicted in DTLocal= " <<
Z <<
"cm" << std::endl;
217 float extrapolatedDistance =
sqrt((
X - Xo) * (
X - Xo) + (
Y - Yo) * (
Y - Yo) + (
Z - Zo) * (
Z - Zo));
220 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Is the distance of extrapolation less than MaxD? =" 221 << extrapolatedDistance <<
"cm" 222 <<
"MaxD=" <<
MaxD <<
"cm" << std::endl;
224 if (extrapolatedDistance <=
MaxD) {
226 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t yes" << std::endl;
229 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Point ExtraPolated in Global" << GlobalPointExtrapolated
231 LocalPoint PointExtrapolatedRPCFrame = RPCSurface.toLocal(GlobalPointExtrapolated);
234 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Point Extrapolated in RPCLocal" << PointExtrapolatedRPCFrame
237 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Corner of the Roll = (" << rsize * eyr <<
"," << stripl * eyr
240 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Info About the Point Extrapolated in X Abs (" 241 << fabs(PointExtrapolatedRPCFrame.
x()) <<
"," 242 << fabs(PointExtrapolatedRPCFrame.
y()) <<
"," 243 << fabs(PointExtrapolatedRPCFrame.
z()) <<
")" << std::endl;
245 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t Does the extrapolation go inside this roll?" << std::endl;
247 if (fabs(PointExtrapolatedRPCFrame.
z()) < 1. && fabs(PointExtrapolatedRPCFrame.
x()) < rsize * eyr &&
248 fabs(PointExtrapolatedRPCFrame.
y()) < stripl * eyr) {
250 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t \t yes" << std::endl;
252 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t \t Creating the RecHit" << std::endl;
254 RPCRecHit RPCPoint(rpcId, myPhiBx, PointExtrapolatedRPCFrame);
255 RPCPoint.setTimeAndError(myPhiTime, myPhiTimeErr);
258 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t \t Clearing the vector" << std::endl;
259 RPCPointVector.clear();
261 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t \t Pushing back" << std::endl;
262 RPCPointVector.push_back(RPCPoint);
264 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t \t Putting the vector" << std::endl;
265 _ThePoints->put(rpcId, RPCPointVector.begin(), RPCPointVector.end());
268 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t \t Filling container with " << nameRoll
269 <<
" Point.x=" << PointExtrapolatedRPCFrame.
x()
270 <<
" Point.y=" << PointExtrapolatedRPCFrame.
y()
271 <<
" size=" << RPCPointVector.size() << std::endl;
275 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t \t No the prediction is outside of this roll" << std::endl;
279 LogDebug(
"DTSegtoRPC") <<
"DT \t \t \t No, Exrtrapolation too long!, canceled" << std::endl;
286 if (all4DSegments->size() > 0) {
288 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t Loop Over all4DSegments " << all4DSegments->size() << std::endl;
289 extrapolatedRolls.clear();
290 for (segment = all4DSegments->begin(); segment != all4DSegments->end(); ++segment) {
293 float myPhiTime = -9999.;
294 float myPhiTimeErr = -9999.;
297 if (segment->hasPhi()) {
298 myPhiTime = segment->phiSegment()->t0();
299 myPhiBx = round(segment->phiSegment()->t0() / bunchCrossTimeDiff);
301 LogDebug(
"DTSegtoRPC") <<
"segment t0 = " << myPhiTime <<
"\tround = " << myPhiBx << std::endl;
303 if (!(myPhiBx <= maxPhiBX && myPhiBx >=
minPhiBX))
307 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t This Segment is in Chamber id: " << DTId << std::endl;
309 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t Number of segments in this DT = " << DTSegmentCounter[DTId]
312 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t Is the only one in this DT? and is in the Station 4?" << std::endl;
314 if (DTSegmentCounter[DTId] == 1 && DTId.
station() == 4) {
316 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t yes" << std::endl;
317 int dtWheel = DTId.
wheel();
318 int dtStation = DTId.
station();
319 int dtSector = DTId.
sector();
321 LocalPoint segmentPosition = segment->localPosition();
322 LocalVector segmentDirection = segment->localDirection();
325 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t The Segment in MB4 is 2D?" << std::endl;
326 if (segment->dimension() == 2) {
328 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t yes" << std::endl;
329 const LocalVector& segmentDirectionMB4 = segmentDirection;
330 const LocalPoint& segmentPositionMB4 = segmentPosition;
338 <<
"MB4 \t \t \t \t Loop on segments in =sector && MB3 && adjacent sectors && y dim=4" << std::endl;
339 for (segMB3 = all4DSegments->begin(); segMB3 != all4DSegments->end(); ++segMB3) {
343 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t Segment in Chamber =" << dtid3 << std::endl;
349 && dtid3.
station() == 3 && DTSegmentCounter[dtid3] == 1 && segMB3->dimension() == 4) {
358 const BoundPlane& DTSurface3 = gdet3->surface();
360 LocalVector segmentDirectionMB3 = segMB3->localDirection();
361 GlobalPoint segmentPositionMB3inGlobal = DTSurface3.toGlobal(segMB3->localPosition());
362 GlobalPoint segmentPositionMB4inGlobal = DTSurface4.toGlobal(segmentPosition);
364 LocalVector segDirMB3inMB4Frame = DTSurface4.toLocal(DTSurface3.toGlobal(segmentDirectionMB3));
366 GlobalVector segDirMB4inGlobalFrame = DTSurface4.toGlobal(segmentDirectionMB4);
367 GlobalVector segDirMB3inGlobalFrame = DTSurface3.toGlobal(segmentDirectionMB3);
369 float dx = segDirMB4inGlobalFrame.
x();
370 float dy = segDirMB4inGlobalFrame.
y();
372 float dx3 = segDirMB3inGlobalFrame.
x();
373 float dy3 = segDirMB3inGlobalFrame.
y();
375 double cosAng = fabs(
dx * dx3 +
dy * dy3 /
sqrt((dx3 * dx3 + dy3 * dy3) * (
dx *
dx +
dy *
dy)));
379 <<
"MB4 \t \t \t \t cosAng" << cosAng <<
"Beetween " << dtid3 <<
" and " << DTId << std::endl;
382 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t dx=" <<
dx <<
" dy=" <<
dy << std::endl;
383 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t dx3=" << dx3 <<
" dy3=" <<
dy << std::endl;
384 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t cosAng=" << cosAng << std::endl;
387 float DistanceBetweenSegments = ((segmentPositionMB3inGlobal) - (segmentPositionMB4inGlobal)).
mag();
392 <<
"MB4 \t \t \t \t Distance between segments=" << DistanceBetweenSegments << std::endl;
396 <<
"MB4 \t \t We found compatible Segments (similar direction and close enough) in " << dtid3
397 <<
" and " << DTId << std::endl;
399 if (dtSector == 13) {
402 if (dtSector == 14) {
407 LogDebug(
"DTSegtoRPC") <<
"Creating the DTIndex" << std::endl;
410 LogDebug(
"DTSegtoRPC") <<
"Getting the Rolls for the given index" << std::endl;
411 std::set<RPCDetId> rollsForThisDT = dtMap->
getRolls(theindex);
415 <<
"MB4 \t \t Number of rolls for this DT = " << rollsForThisDT.size() << std::endl;
417 assert(!rollsForThisDT.empty());
420 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t Loop over all the rolls asociated to this DT" << std::endl;
421 for (std::set<RPCDetId>::iterator iteraRoll = rollsForThisDT.begin();
422 iteraRoll != rollsForThisDT.end();
424 const RPCRoll* rollasociated = rpcGeo->
roll(*iteraRoll);
432 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t RollName: " << nameRoll << std::endl;
434 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t Doing the extrapolation to this roll" << std::endl;
437 LocalPoint CenterRollinMB4Frame = DTSurface4.toLocal(CenterPointRollGlobal);
439 DTSurface4.toLocal(segmentPositionMB3inGlobal);
441 LocalVector segmentDirectionMB3inMB4Frame = DTSurface4.toLocal(segDirMB3inGlobalFrame);
444 float Dxz = CenterRollinMB4Frame.
z();
445 float Xo4 = segmentPositionMB4.
x();
446 float dxl = segmentDirectionMB4.
x();
447 float dzl = segmentDirectionMB4.
z();
449 float X = Xo4 + dxl * Dxz / dzl;
453 float Yo34 = segmentPositionMB3inMB4Frame.
y();
454 float dy34 = segmentDirectionMB3inMB4Frame.
y();
455 float dz34 = segmentDirectionMB3inMB4Frame.
z();
458 (segmentPositionMB3inMB4Frame.
z());
462 <<
"MB4 \t \t \t The distance to extrapolate in Y from MB3 is " <<
Dy <<
"cm" << std::endl;
464 float Y = Yo34 + dy34 *
Dy / dz34;
470 float rsize = fabs(
xmax.x() -
xmin.x());
472 float stripw = top_->
pitch();
475 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t Strip Lenght " << stripl <<
"cm" << std::endl;
477 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t Strip Width " << stripw <<
"cm" << std::endl;
480 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t X Predicted in MB4DTLocal= " <<
X <<
"cm" << std::endl;
482 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t Y Predicted in MB4DTLocal= " <<
Y <<
"cm" << std::endl;
484 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t Z Predicted in MB4DTLocal= " <<
Z <<
"cm" << std::endl;
486 float extrapolatedDistance =
sqrt((
Y - Yo34) * (
Y - Yo34) +
Dy *
Dy);
490 <<
"MB4 \t \t \t segmentPositionMB3inMB4Frame" << segmentPositionMB3inMB4Frame << std::endl;
493 <<
"MB4 \t \t \t segmentPositionMB4inMB4Frame" << segmentPosition << std::endl;
497 <<
"MB4 \t \t \t segmentDirMB3inMB4Frame" << segDirMB3inMB4Frame << std::endl;
500 <<
"MB4 \t \t \t segmentDirMB4inMB4Frame" << segmentDirectionMB4 << std::endl;
504 <<
"MB4 \t \t \t CenterRB4PositioninMB4Frame" << CenterRollinMB4Frame << std::endl;
507 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t Is the extrapolation distance =" << extrapolatedDistance
508 <<
"less than " <<
MaxDrb4 << std::endl;
510 if (extrapolatedDistance <=
MaxDrb4) {
512 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t yes" << std::endl;
518 <<
"MB4 \t \t \t Point ExtraPolated in Global" << GlobalPointExtrapolated << std::endl;
520 LocalPoint PointExtrapolatedRPCFrame = RPCSurfaceRB4.toLocal(GlobalPointExtrapolated);
523 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t Point Extrapolated in RPCLocal" 524 << PointExtrapolatedRPCFrame << std::endl;
526 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t Corner of the Roll = (" << rsize * eyr <<
"," 527 << stripl * eyr <<
")" << std::endl;
530 <<
"MB4 \t \t \t Info About the Point Extrapolated in X Abs (" 531 << fabs(PointExtrapolatedRPCFrame.
x()) <<
"," << fabs(PointExtrapolatedRPCFrame.
y())
532 <<
"," << fabs(PointExtrapolatedRPCFrame.
z()) <<
")" << std::endl;
536 <<
"MB4 \t \t \t Does the extrapolation go inside this roll?" << std::endl;
538 if (fabs(PointExtrapolatedRPCFrame.
z()) < 5. &&
539 fabs(PointExtrapolatedRPCFrame.
x()) < rsize * eyr &&
540 fabs(PointExtrapolatedRPCFrame.
y()) < stripl * eyr) {
542 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t yes" << std::endl;
544 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t Creating the RecHit" << std::endl;
546 RPCRecHit RPCPointMB4(rpcId, myPhiBx, PointExtrapolatedRPCFrame);
547 RPCPointMB4.setTimeAndError(myPhiTime, myPhiTimeErr);
550 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t Clearing the RPCPointVector" << std::endl;
551 RPCPointVector.clear();
553 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t Pushing Back" << std::endl;
554 RPCPointVector.push_back(RPCPointMB4);
556 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t Putting for " << rpcId << std::endl;
558 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t Filling container with " << nameRoll
559 <<
" Point.x=" << PointExtrapolatedRPCFrame.
x()
560 <<
" Point.y=" << PointExtrapolatedRPCFrame.
y()
561 <<
" size=" << RPCPointVector.size() << std::endl;
563 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t Number of rolls already extrapolated in RB4 = " 564 << extrapolatedRolls.size() << std::endl;
565 if (
find(extrapolatedRolls.begin(), extrapolatedRolls.end(), rpcId.
rawId()) ==
566 extrapolatedRolls.end()) {
567 extrapolatedRolls.push_back(rpcId.
rawId());
568 _ThePoints->put(rpcId, RPCPointVector.begin(), RPCPointVector.end());
572 <<
"MB4 \t \t \t \t roll already extrapolated " << rpcId << std::endl;
576 <<
"MB4 \t \t \t \t Extrapolations done after this point = " << extrapolatedRolls.size()
579 for (uint32_t
m = 0;
m < extrapolatedRolls.size();
m++)
580 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t" << extrapolatedRolls.at(
m) << std::endl;
584 <<
"MB4 \t \t \t \t No the prediction is outside of this roll" << std::endl;
589 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t No, Exrtrapolation too long!, canceled" << std::endl;
595 <<
"MB4 \t \t \t \t I found segments in MB4 and MB3 adjacent wheel and/or sector but " 596 "not compatibles, Diferent Directions" 602 <<
"MB4 \t \t \t No the same station or same wheel or segment dim in mb3 not 4D" << std::endl;
607 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t Is NOT a 2D Segment" << std::endl;
611 LogDebug(
"DTSegtoRPC") <<
"MB4 \t \t \t \t There is not just one segment or is not in station 4" 617 LogDebug(
"DTSegtoRPC") <<
"MB4 \t This event doesn't have 4D Segment" << std::endl;
int station() const
Return the station number.
double MaxDistanceBetweenSegments
LocalPoint localPosition(float strip) const override
Point3DBase< Scalar, LocalTag > LocalPoint
int distsector(int sector1, int sector2)
float pitch() const override
edm::ESGetToken< DTObjectMap, MuonGeometryRecord > dtMapToken_
const RPCRoll * roll(RPCDetId id) const
Return a roll given its id.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::set< RPCDetId > const & getRolls(DTStationIndex index) const
float stripLength() const override
C::const_iterator const_iterator
constant access iterator type
edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeoToken_
const GeomDet * idToDet(DetId) const override
const Plane & surface() const
The nominal surface of the GeomDet.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
DecomposeProduct< arg, typename Div::arg > D
constexpr uint32_t rawId() const
get the raw id
int distwheel(int wheel1, int wheel2)
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > rpcGeoToken_
int wheel() const
Return the wheel number.
const Topology & topology() const override