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