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