CMS 3D CMS Logo

DTHitQualityUtils.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author S. Bolognesi and G. Cerminara - INFN Torino
6  */
7 
13 
14 #include <iostream>
15 
16 using namespace std;
17 using namespace edm;
18 
19 std::atomic<bool> DTHitQualityUtils::debug{false};
20 
21 // Return a map between simhits of a layer,superlayer or chamber and the wireId
22 // of their cell
23 map<DTWireId, PSimHitContainer> DTHitQualityUtils::mapSimHitsPerWire(const PSimHitContainer &simhits) {
24  map<DTWireId, PSimHitContainer> hitWireMapResult;
25 
26  for (PSimHitContainer::const_iterator simhit = simhits.begin(); simhit != simhits.end(); simhit++) {
27  hitWireMapResult[DTWireId((*simhit).detUnitId())].push_back(*simhit);
28  }
29 
30  return hitWireMapResult;
31 }
32 
33 // Extract mu simhits from a map of simhits by wire and map them by wire
34 map<DTWireId, const PSimHit *> DTHitQualityUtils::mapMuSimHitsPerWire(
35  const map<DTWireId, PSimHitContainer> &simHitWireMap) {
36  map<DTWireId, const PSimHit *> ret;
37 
38  for (map<DTWireId, PSimHitContainer>::const_iterator wireAndSimHit = simHitWireMap.begin();
39  wireAndSimHit != simHitWireMap.end();
40  wireAndSimHit++) {
41  const PSimHit *muHit = findMuSimHit((*wireAndSimHit).second);
42  if (muHit != nullptr) {
43  ret[(*wireAndSimHit).first] = (muHit);
44  }
45  }
46  return ret;
47 }
48 
49 // Find the sim hit from muon track in a vector of simhits
50 // If no mu sim hit is found then it returns a null pointer
52  // PSimHitContainer muHits;
53  vector<const PSimHit *> muHits;
54 
55  // Loop over simhits
56  for (PSimHitContainer::const_iterator hit = hits.begin(); hit != hits.end(); hit++) {
57  if (abs((*hit).particleType()) == 13)
58  muHits.push_back(&(*hit));
59  }
60 
61  if (muHits.empty())
62  return nullptr; // FIXME: Throw of exception???
63  else if (muHits.size() > 1)
64  if (debug)
65  cout << "[DTHitQualityUtils]***WARNING: # muSimHits in a wire = " << muHits.size() << endl;
66 
67  return (muHits.front());
68 }
69 
70 // Find Innermost and outermost SimHit from Mu in a SL (they identify a
71 // simulated segment)
72 pair<const PSimHit *, const PSimHit *> DTHitQualityUtils::findMuSimSegment(
73  const map<DTWireId, const PSimHit *> &mapWireAndMuSimHit) {
74  int outSL = 0;
75  int inSL = 4;
76  int outLayer = 0;
77  int inLayer = 5;
78  const PSimHit *inSimHit = nullptr;
79  const PSimHit *outSimHit = nullptr;
80 
81  for (map<DTWireId, const PSimHit *>::const_iterator wireAndMuSimHit = mapWireAndMuSimHit.begin();
82  wireAndMuSimHit != mapWireAndMuSimHit.end();
83  wireAndMuSimHit++) {
84  const DTWireId wireId = (*wireAndMuSimHit).first;
85  const PSimHit *theMuHit = (*wireAndMuSimHit).second;
86 
87  int sl = ((wireId.layerId()).superlayerId()).superLayer();
88  int layer = (wireId.layerId()).layer();
89 
90  if (sl == outSL) {
91  if (layer > outLayer) {
92  outLayer = layer;
93  outSimHit = theMuHit;
94  }
95  }
96  if (sl > outSL) {
97  outSL = sl;
98  outLayer = layer;
99  outSimHit = theMuHit;
100  }
101  if (sl == inSL) {
102  if (layer < inLayer) {
103  inLayer = layer;
104  inSimHit = theMuHit;
105  }
106  }
107  if (sl < inSL) {
108  inSL = sl;
109  inLayer = layer;
110  inSimHit = theMuHit;
111  }
112  }
113 
114  if (inSimHit != nullptr) {
115  if (debug)
116  cout << "Innermost SimHit on SL: " << inSL << " layer: " << inLayer << endl;
117  } else {
118  cout << "[DTHitQualityUtils]***Error: No Innermost SimHit found!!!" << endl;
119  abort();
120  }
121 
122  if (outSimHit != nullptr) {
123  if (debug)
124  cout << "Outermost SimHit on SL: " << outSL << " layer: " << outLayer << endl;
125  } else {
126  cout << "[DTHitQualityUtils]***Error: No Outermost SimHit found!!!" << endl;
127  abort();
128  }
129 
130  // //Check that outermost and innermost SimHit are not the same
131  // if(outSimHit == inSimHit) {
132  // cout << "[DTHitQualityUtils]***Warning: outermost and innermost SimHit
133  // are the same!" << endl; abort();
134  // }
135  return make_pair(inSimHit, outSimHit);
136 }
137 
138 // Find direction and position of a segment (in local RF) from outer and inner
139 // mu SimHit in the RF of object Det (Concrete implementation of Det are MuBarSL
140 // and MuBarChamber)
141 pair<LocalVector, LocalPoint> DTHitQualityUtils::findMuSimSegmentDirAndPos(
142  const pair<const PSimHit *, const PSimHit *> &inAndOutSimHit, const DetId detId, const DTGeometry *muonGeom) {
143  // FIXME: What should happen if outSimHit = inSimHit???? Now, this case is not
144  // considered
145  const PSimHit *innermostMuSimHit = inAndOutSimHit.first;
146  const PSimHit *outermostMuSimHit = inAndOutSimHit.second;
147 
148  // Find simulated segment direction from SimHits position
149  const DTLayer *layerIn = muonGeom->layer((DTWireId(innermostMuSimHit->detUnitId())).layerId());
150  const DTLayer *layerOut = muonGeom->layer((DTWireId(outermostMuSimHit->detUnitId())).layerId());
151  GlobalPoint inGlobalPos = layerIn->toGlobal(innermostMuSimHit->localPosition());
152  GlobalPoint outGlobalPos = layerOut->toGlobal(outermostMuSimHit->localPosition());
153  LocalVector simHitDirection = (muonGeom->idToDet(detId))->toLocal(inGlobalPos - outGlobalPos);
154  simHitDirection = -simHitDirection.unit();
155 
156  // SimHit position extrapolated at z=0 in the Det RF
157  LocalPoint outLocalPos = (muonGeom->idToDet(detId))->toLocal(outGlobalPos);
158  LocalPoint simSegLocalPosition =
159  outLocalPos + simHitDirection * (-outLocalPos.z() / (simHitDirection.mag() * cos(simHitDirection.theta())));
160 
161  return make_pair(simHitDirection, simSegLocalPosition);
162 }
163 
164 // Find the angles from a segment direction:
165 // atan(dx/dz) = "phi" angle in the chamber RF
166 // atan(dy/dz) = "theta" angle in the chamber RF (note: this has opposite sign
167 // in the SLZ RF!)
168 pair<double, double> DTHitQualityUtils::findSegmentAlphaAndBeta(const LocalVector &direction) {
169  return make_pair(atan(direction.x() / direction.z()), atan(direction.y() / direction.z()));
170 }
171 
172 // Find error on angle (squared) from localDirectionError, which is the error on
173 // tan(Angle)
174 double DTHitQualityUtils::sigmaAngle(double Angle, double sigma2TanAngle) {
175  double XdivZ = tan(Angle);
176  double sigma2Angle = 1 / (1 + XdivZ * XdivZ);
177  sigma2Angle *= sigma2Angle * sigma2TanAngle;
178 
179  return sigma2Angle;
180 }
std::pair< double, double > findSegmentAlphaAndBeta(const LocalVector &direction)
std::map< DTWireId, edm::PSimHitContainer > mapSimHitsPerWire(const edm::PSimHitContainer &simhits)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
T y() const
Definition: PV3DBase.h:63
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
std::atomic< bool > debug
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
T mag() const
Definition: PV3DBase.h:67
Local3DPoint localPosition() const
Definition: PSimHit.h:52
std::map< DTWireId, const PSimHit * > mapMuSimHitsPerWire(const std::map< DTWireId, edm::PSimHitContainer > &simHitWireMap)
Create a map between the Mu SimHits and corresponding MuBarWireId ;.
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const PSimHit * findMuSimHit(const edm::PSimHitContainer &hits)
Select the SimHit from a muon in a vector of SimHits.
std::pair< const PSimHit *, const PSimHit * > findMuSimSegment(const std::map< DTWireId, const PSimHit * > &mapWireAndMuSimHit)
Vector3DBase unit() const
Definition: Vector3DBase.h:57
Definition: DetId.h:18
#define debug
Definition: HDRShower.cc:19
std::pair< LocalVector, LocalPoint > findMuSimSegmentDirAndPos(const std::pair< const PSimHit *, const PSimHit * > &inAndOutSimHit, const DetId detId, const DTGeometry *muonGeom)
Definition: Angle.h:17
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:62
HLT enums.
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:93
std::vector< PSimHit > PSimHitContainer
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:127
double sigmaAngle(double Angle, double sigma2TanAngle)
T x() const
Definition: PV3DBase.h:62
unsigned int detUnitId() const
Definition: PSimHit.h:97