CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CSCSegtoRPC.cc
Go to the documentation of this file.
11 #include "CSCSegtoRPC.h"
12 #include "CSCStationIndex.h"
13 #include "CSCObjectMap.h"
14 
16  : rpcGeoToken_(iC.esConsumes()), cscGeoToken_(iC.esConsumes()), cscMapToken_(iC.esConsumes()) {}
17 
18 std::unique_ptr<RPCRecHitCollection> CSCSegtoRPC::thePoints(const CSCSegmentCollection* allCSCSegments,
19  const edm::EventSetup& iSetup,
20  bool debug,
21  double eyr) {
25 
26  double MaxD = 80.;
27 
28  if (debug)
29  std::cout << "CSC \t Number of CSC Segments in this event = " << allCSCSegments->size() << std::endl;
30 
31  auto _ThePoints = std::make_unique<RPCRecHitCollection>();
32  edm::OwnVector<RPCRecHit> RPCPointVector;
33 
34  if (allCSCSegments->size() == 0) {
35  if (debug)
36  std::cout << "CSC 0 segments skiping event" << std::endl;
37  } else {
38  std::map<CSCDetId, int> CSCSegmentsCounter;
40 
41  int segmentsInThisEventInTheEndcap = 0;
42 
43  for (segment = allCSCSegments->begin(); segment != allCSCSegments->end(); ++segment) {
44  CSCSegmentsCounter[segment->cscDetId()]++;
45  segmentsInThisEventInTheEndcap++;
46  }
47 
48  if (debug)
49  std::cout << "CSC \t loop over all the CSCSegments " << std::endl;
50  for (segment = allCSCSegments->begin(); segment != allCSCSegments->end(); ++segment) {
51  CSCDetId CSCId = segment->cscDetId();
52 
53  if (debug)
54  std::cout << "CSC \t \t This Segment is in Chamber id: " << CSCId << std::endl;
55  if (debug)
56  std::cout << "CSC \t \t Number of segments in this CSC = " << CSCSegmentsCounter[CSCId] << std::endl;
57  if (debug)
58  std::cout << "CSC \t \t Is the only one in this CSC? is not ind the ring 1 or station 4? Are there more than 2 "
59  "segments in the event?"
60  << std::endl;
61 
62  if (CSCSegmentsCounter[CSCId] == 1 && CSCId.station() != 4 && CSCId.ring() != 1 && allCSCSegments->size() >= 2) {
63  if (debug)
64  std::cout << "CSC \t \t yes" << std::endl;
65  int cscEndCap = CSCId.endcap();
66  int cscStation = CSCId.station();
67  int cscRing = CSCId.ring();
68  int rpcRegion = 1;
69  if (cscEndCap == 2)
70  rpcRegion = -1; //Relacion entre las endcaps
71  int rpcRing = cscRing;
72  if (cscRing == 4)
73  rpcRing = 1;
74  int rpcStation = cscStation;
75  int rpcSegment = CSCId.chamber();
76 
77  LocalPoint segmentPosition = segment->localPosition();
78  LocalVector segmentDirection = segment->localDirection();
79  float dz = segmentDirection.z();
80 
81  if (debug)
82  std::cout << "CSC \t \t \t Information about the segment"
83  << "RecHits =" << segment->nRecHits() << "Angle =" << acos(dz) * 180 / 3.1415926 << std::endl;
84 
85  if (debug)
86  std::cout << "CSC \t \t Is a good Segment? dim = 4, 4 <= nRecHits <= 10 Incident angle int range 45 < "
87  << acos(dz) * 180 / 3.1415926 << " < 135? " << std::endl;
88 
89  if ((segment->dimension() == 4) && (segment->nRecHits() <= 10 && segment->nRecHits() >= 4)) {
90  //&& acos(dz)*180/3.1415926 > 45. && acos(dz)*180/3.1415926 < 135.){
91  //&& segment->chi2()< ??)Add 3 segmentes in the endcaps???
92 
93  if (debug)
94  std::cout << "CSC \t \t yes" << std::endl;
95  if (debug)
96  std::cout << "CSC \t \t CSC Segment Dimension " << segment->dimension() << std::endl;
97 
98  float Xo = segmentPosition.x();
99  float Yo = segmentPosition.y();
100  float Zo = segmentPosition.z();
101  float dx = segmentDirection.x();
102  float dy = segmentDirection.y();
103  float dz = segmentDirection.z();
104 
105  if (debug)
106  std::cout << "Creating the CSCIndex" << std::endl;
107  CSCStationIndex theindex(rpcRegion, rpcStation, rpcRing, rpcSegment);
108  if (debug)
109  std::cout << "Getting the Rolls for the given index" << std::endl;
110  std::set<RPCDetId> rollsForThisCSC = cscMap->getRolls(theindex);
111  if (debug)
112  std::cout << "CSC \t \t Getting chamber from Geometry" << std::endl;
113  const CSCChamber* TheChamber = cscGeo->chamber(CSCId);
114  if (debug)
115  std::cout << "CSC \t \t Getting ID from Chamber" << std::endl;
116  const CSCDetId TheId = TheChamber->id();
117 
118  if (debug)
119  std::cout << "CSC \t \t Number of rolls for this CSC = " << rollsForThisCSC.size() << std::endl;
120 
121  if (debug)
122  std::cout << "CSC \t \t Printing The Id" << TheId << std::endl;
123 
124  if (rpcRing != 1 && rpcStation != 4) { //They don't exist!
125 
126  assert(!rollsForThisCSC.empty());
127 
128  if (debug)
129  std::cout << "CSC \t \t Loop over all the rolls asociated to this CSC" << std::endl;
130  for (std::set<RPCDetId>::iterator iteraRoll = rollsForThisCSC.begin(); iteraRoll != rollsForThisCSC.end();
131  iteraRoll++) {
132  const RPCRoll* rollasociated = rpcGeo->roll(*iteraRoll);
133  RPCDetId rpcId = rollasociated->id();
134 
135  if (debug)
136  std::cout << "CSC \t \t \t We are in the roll getting the surface" << rpcId << std::endl;
137  const BoundPlane& RPCSurface = rollasociated->surface();
138 
139  if (debug)
140  std::cout << "CSC \t \t \t RollID: " << rpcId << std::endl;
141 
142  if (debug)
143  std::cout << "CSC \t \t \t Doing the extrapolation to this roll" << std::endl;
144  if (debug)
145  std::cout << "CSC \t \t \t CSC Segment Direction in CSCLocal " << segmentDirection << std::endl;
146  if (debug)
147  std::cout << "CSC \t \t \t CSC Segment Point in CSCLocal " << segmentPosition << std::endl;
148 
149  GlobalPoint CenterPointRollGlobal = RPCSurface.toGlobal(LocalPoint(0, 0, 0));
150  if (debug)
151  std::cout << "CSC \t \t \t Center (0,0,0) of the Roll in Global" << CenterPointRollGlobal << std::endl;
152  GlobalPoint CenterPointCSCGlobal = TheChamber->toGlobal(LocalPoint(0, 0, 0));
153  if (debug)
154  std::cout << "CSC \t \t \t Center (0,0,0) of the CSC in Global" << CenterPointCSCGlobal << std::endl;
155  GlobalPoint segmentPositionInGlobal =
156  TheChamber->toGlobal(segmentPosition); //new way to convert to global
157  if (debug)
158  std::cout << "CSC \t \t \t Segment Position in Global" << segmentPositionInGlobal << std::endl;
159  LocalPoint CenterRollinCSCFrame = TheChamber->toLocal(CenterPointRollGlobal);
160 
161  if (debug) { //to check CSC RPC phi relation!
162  float rpcphi = 0;
163  float cscphi = 0;
164 
165  (CenterPointRollGlobal.barePhi() < 0) ? rpcphi = 2 * 3.141592 + CenterPointRollGlobal.barePhi()
166  : rpcphi = CenterPointRollGlobal.barePhi();
167 
168  (CenterPointCSCGlobal.barePhi() < 0) ? cscphi = 2 * 3.1415926536 + CenterPointCSCGlobal.barePhi()
169  : cscphi = CenterPointCSCGlobal.barePhi();
170 
171  float df = fabs(cscphi - rpcphi);
172  float dr = fabs(CenterPointRollGlobal.perp() - CenterPointCSCGlobal.perp());
173  float diffz = CenterPointRollGlobal.z() - CenterPointCSCGlobal.z();
174  float dfg = df * 180. / 3.14159265;
175 
176  if (debug)
177  std::cout << "CSC \t \t \t z of RPC=" << CenterPointRollGlobal.z() << "z of CSC"
178  << CenterPointCSCGlobal.z() << " dfg=" << dfg << std::endl;
179 
180  RPCGeomServ rpcsrv(rpcId);
181 
182  if (dr > 200. || fabs(dz) > 55. || dfg > 1.) {
183  //if(rpcRegion==1&&dfg>1.&&dr>100.){
184  if (debug)
185  std::cout << "\t \t \t CSC Station= " << CSCId.station() << " Ring= " << CSCId.ring()
186  << " Chamber= " << CSCId.chamber() << " cscphi=" << cscphi * 180 / 3.14159265
187  << "\t RPC Station= " << rpcId.station() << " ring= " << rpcId.ring() << " segment =-> "
188  << rpcsrv.segment() << " rollphi=" << rpcphi * 180 / 3.14159265 << "\t dfg=" << dfg
189  << " dz=" << diffz << " dr=" << dr << std::endl;
190  }
191  }
192 
193  float D = CenterRollinCSCFrame.z();
194 
195  float X = Xo + dx * D / dz;
196  float Y = Yo + dy * D / dz;
197  float Z = D;
198 
199  const TrapezoidalStripTopology* top_ =
200  dynamic_cast<const TrapezoidalStripTopology*>(&(rollasociated->topology()));
201  LocalPoint xmin = top_->localPosition(0.);
202  if (debug)
203  std::cout << "CSC \t \t \t xmin of this Roll " << xmin << "cm" << std::endl;
204  LocalPoint xmax = top_->localPosition((float)rollasociated->nstrips());
205  if (debug)
206  std::cout << "CSC \t \t \t xmax of this Roll " << xmax << "cm" << std::endl;
207  float rsize = fabs(xmax.x() - xmin.x());
208  if (debug)
209  std::cout << "CSC \t \t \t Roll Size " << rsize << "cm" << std::endl;
210  float stripl = top_->stripLength();
211  float stripw = top_->pitch();
212 
213  if (debug)
214  std::cout << "CSC \t \t \t Strip Lenght " << stripl << "cm" << std::endl;
215  if (debug)
216  std::cout << "CSC \t \t \t Strip Width " << stripw << "cm" << std::endl;
217 
218  if (debug)
219  std::cout << "CSC \t \t \t X Predicted in CSCLocal= " << X << "cm" << std::endl;
220  if (debug)
221  std::cout << "CSC \t \t \t Y Predicted in CSCLocal= " << Y << "cm" << std::endl;
222  if (debug)
223  std::cout << "CSC \t \t \t Z Predicted in CSCLocal= " << Z << "cm" << std::endl;
224 
225  float extrapolatedDistance = sqrt((X - Xo) * (X - Xo) + (Y - Yo) * (Y - Yo) + (Z - Zo) * (Z - Zo));
226 
227  if (debug)
228  std::cout << "CSC \t \t \t Is the distance of extrapolation less than MaxD? =" << extrapolatedDistance
229  << "cm"
230  << " MaxD=" << MaxD << "cm" << std::endl;
231 
232  if (extrapolatedDistance <= MaxD) {
233  if (debug)
234  std::cout << "CSC \t \t \t yes" << std::endl;
235 
236  GlobalPoint GlobalPointExtrapolated = TheChamber->toGlobal(LocalPoint(X, Y, Z));
237  if (debug)
238  std::cout << "CSC \t \t \t Point ExtraPolated in Global" << GlobalPointExtrapolated << std::endl;
239 
240  LocalPoint PointExtrapolatedRPCFrame = RPCSurface.toLocal(GlobalPointExtrapolated);
241 
242  if (debug)
243  std::cout << "CSC \t \t \t Point Extrapolated in RPCLocal" << PointExtrapolatedRPCFrame << std::endl;
244  if (debug)
245  std::cout << "CSC \t \t \t Corner of the Roll = (" << rsize * eyr << "," << stripl * eyr << ")"
246  << std::endl;
247  if (debug)
248  std::cout << "CSC \t \t \t Info About the Point Extrapolated in X Abs ("
249  << fabs(PointExtrapolatedRPCFrame.x()) << "," << fabs(PointExtrapolatedRPCFrame.y()) << ","
250  << fabs(PointExtrapolatedRPCFrame.z()) << ")" << std::endl;
251  if (debug)
252  std::cout << "CSC \t \t \t dz=" << fabs(PointExtrapolatedRPCFrame.z())
253  << " dx=" << fabs(PointExtrapolatedRPCFrame.x())
254  << " dy=" << fabs(PointExtrapolatedRPCFrame.y()) << std::endl;
255 
256  if (debug)
257  std::cout << "CSC \t \t \t Does the extrapolation go inside this roll????" << std::endl;
258 
259  if (fabs(PointExtrapolatedRPCFrame.z()) < 1. && fabs(PointExtrapolatedRPCFrame.x()) < rsize * eyr &&
260  fabs(PointExtrapolatedRPCFrame.y()) < stripl * eyr) {
261  if (debug)
262  std::cout << "CSC \t \t \t \t yes" << std::endl;
263  if (debug)
264  std::cout << "CSC \t \t \t \t Creating the RecHit" << std::endl;
265  RPCRecHit RPCPoint(rpcId, 0, PointExtrapolatedRPCFrame);
266  if (debug)
267  std::cout << "CSC \t \t \t \t Clearing the vector" << std::endl;
268  RPCPointVector.clear();
269  if (debug)
270  std::cout << "CSC \t \t \t \t Pushing back" << std::endl;
271  RPCPointVector.push_back(RPCPoint);
272  if (debug)
273  std::cout << "CSC \t \t \t \t Putting the vector" << std::endl;
274  _ThePoints->put(rpcId, RPCPointVector.begin(), RPCPointVector.end());
275  }
276  }
277  }
278  }
279  }
280  }
281  }
282  }
283  return _ThePoints;
284 }
int chamber() const
Definition: CSCDetId.h:62
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
T perp() const
Definition: PV3DBase.h:69
CSCDetId id() const
Get the (concrete) DetId.
Definition: CSCChamber.h:34
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
CSCSegtoRPC(edm::ConsumesCollector iC)
Definition: CSCSegtoRPC.cc:15
int nstrips() const
Definition: RPCRoll.cc:24
T y() const
Definition: PV3DBase.h:60
#define X(str)
Definition: MuonsGrabber.cc:38
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
edm::ESGetToken< CSCGeometry, MuonGeometryRecord > cscGeoToken_
Definition: CSCSegtoRPC.h:27
assert(be >=bs)
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
int endcap() const
Definition: CSCDetId.h:85
T barePhi() const
Definition: PV3DBase.h:65
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
RPCDetId id() const
Definition: RPCRoll.cc:16
int ring() const
Definition: RPCDetId.h:59
T sqrt(T t)
Definition: SSEVec.h:19
T z() const
Definition: PV3DBase.h:61
int ring() const
Definition: CSCDetId.h:68
virtual int segment()
Definition: RPCGeomServ.cc:361
#define debug
Definition: HDRShower.cc:19
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
const Topology & topology() const override
Definition: RPCRoll.cc:18
std::unique_ptr< RPCRecHitCollection > thePoints(CSCSegmentCollection const *allCSCSegments, edm::EventSetup const &iSetup, bool debug, double eyr)
Definition: CSCSegtoRPC.cc:18
int station() const
Definition: CSCDetId.h:79
tuple cout
Definition: gather_cfg.py:144
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
float stripLength() const override
det heigth (strip length in the middle)
edm::ESGetToken< CSCObjectMap, MuonGeometryRecord > cscMapToken_
Definition: CSCSegtoRPC.h:28
T x() const
Definition: PV3DBase.h:59
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > rpcGeoToken_
Definition: CSCSegtoRPC.h:26
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
LocalPoint localPosition(float strip) const override
int station() const
Definition: RPCDetId.h:78