CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTHitQualityUtils.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * $Date: 2008/12/03 12:17:41 $
6  * $Revision: 1.7 $
7  * \author S. Bolognesi and G. Cerminara - INFN Torino
8  */
9 
10 
16 
17 #include <iostream>
18 
19 using namespace std;
20 using namespace edm;
21 
23 
24 // Constructor
26  //DTHitQualityUtils::setDebug(debug);
27 }
28 
29 // Destructor
31 }
32 
33 
34 // Return a map between simhits of a layer,superlayer or chamber and the wireId of their cell
35 map<DTWireId, PSimHitContainer >
37  map<DTWireId, PSimHitContainer > hitWireMapResult;
38 
39  for(PSimHitContainer::const_iterator simhit = simhits.begin();
40  simhit != simhits.end();
41  simhit++) {
42  hitWireMapResult[DTWireId((*simhit).detUnitId())].push_back(*simhit);
43  }
44 
45  return hitWireMapResult;
46 }
47 
48 // Extract mu simhits from a map of simhits by wire and map them by wire
49 map<DTWireId, const PSimHit*>
50 DTHitQualityUtils::mapMuSimHitsPerWire(const map<DTWireId, PSimHitContainer>& simHitWireMap) {
51 
52  map<DTWireId, const PSimHit*> ret;
53 
54  for(map<DTWireId, PSimHitContainer>::const_iterator wireAndSimHit = simHitWireMap.begin();
55  wireAndSimHit != simHitWireMap.end();
56  wireAndSimHit++) {
57 
58  const PSimHit* muHit = findMuSimHit((*wireAndSimHit).second);
59  if(muHit != 0) {
60  ret[(*wireAndSimHit).first]=(muHit);
61  }
62  }
63  return ret;
64 }
65 
66 
67 // Find the sim hit from muon track in a vector of simhits
68 // If no mu sim hit is found then it returns a null pointer
70  //PSimHitContainer muHits;
71  vector<const PSimHit*> muHits;
72 
73  // Loop over simhits
74  for (PSimHitContainer::const_iterator hit=hits.begin();
75  hit != hits.end(); hit++) {
76  if (abs((*hit).particleType())==13) muHits.push_back(&(*hit));
77  }
78 
79  if (muHits.size()==0)
80  return 0; //FIXME: Throw of exception???
81  else if (muHits.size()>1)
82  if(debug)
83  cout << "[DTHitQualityUtils]***WARNING: # muSimHits in a wire = " << muHits.size() << endl;
84 
85  return (muHits.front());
86 }
87 
88 
89 // Find Innermost and outermost SimHit from Mu in a SL (they identify a simulated segment)
90 pair<const PSimHit*, const PSimHit*>
91 DTHitQualityUtils::findMuSimSegment(const map<DTWireId, const PSimHit*>& mapWireAndMuSimHit) {
92 
93  int outSL = 0;
94  int inSL = 4;
95  int outLayer = 0;
96  int inLayer = 5;
97  const PSimHit *inSimHit = 0;
98  const PSimHit *outSimHit = 0;
99 
100  for(map<DTWireId, const PSimHit*>::const_iterator wireAndMuSimHit = mapWireAndMuSimHit.begin();
101  wireAndMuSimHit != mapWireAndMuSimHit.end();
102  wireAndMuSimHit++) {
103 
104  const DTWireId wireId = (*wireAndMuSimHit).first;
105  const PSimHit *theMuHit = (*wireAndMuSimHit).second;
106 
107  int sl = ((wireId.layerId()).superlayerId()).superLayer();
108  int layer = (wireId.layerId()).layer();
109 
110  if(sl == outSL) {
111  if(layer > outLayer) {
112  outLayer = layer;
113  outSimHit = theMuHit;
114  }
115  }
116  if(sl > outSL) {
117  outSL = sl;
118  outLayer = layer;
119  outSimHit = theMuHit;
120  }
121  if(sl == inSL) {
122  if(layer < inLayer) {
123  inLayer = layer;
124  inSimHit = theMuHit;
125  }
126  }
127  if(sl < inSL) {
128  inSL = sl;
129  inLayer = layer;
130  inSimHit = theMuHit;
131  }
132  }
133 
134  if(inSimHit != 0) {
135  if(debug)
136  cout << "Innermost SimHit on SL: " << inSL << " layer: " << inLayer << endl;
137  } else {
138  cout << "[DTHitQualityUtils]***Error: No Innermost SimHit found!!!" << endl;
139  abort();
140  }
141 
142  if(outSimHit != 0) {
143  if(debug)
144  cout << "Outermost SimHit on SL: " << outSL << " layer: " << outLayer << endl;
145  } else {
146  cout << "[DTHitQualityUtils]***Error: No Outermost SimHit found!!!" << endl;
147  abort();
148  }
149 
150  // //Check that outermost and innermost SimHit are not the same
151  // if(outSimHit == inSimHit) {
152  // cout << "[DTHitQualityUtils]***Warning: outermost and innermost SimHit are the same!" << endl;
153  // abort();
154  // }
155  return make_pair(inSimHit, outSimHit);
156 }
157 
158 
159 
160 // Find direction and position of a segment (in local RF) from outer and inner mu SimHit in the RF of object Det
161 // (Concrete implementation of Det are MuBarSL and MuBarChamber)
162 pair<LocalVector, LocalPoint>
163 DTHitQualityUtils::findMuSimSegmentDirAndPos(const pair<const PSimHit*, const PSimHit*>& inAndOutSimHit,
164  const DetId detId, const DTGeometry *muonGeom) {
165 
166  //FIXME: What should happen if outSimHit = inSimHit???? Now, this case is not considered
167  const PSimHit* innermostMuSimHit = inAndOutSimHit.first;
168  const PSimHit* outermostMuSimHit = inAndOutSimHit.second;
169 
170  //Find simulated segment direction from SimHits position
171  const DTLayer* layerIn = muonGeom->layer((DTWireId(innermostMuSimHit->detUnitId())).layerId());
172  const DTLayer* layerOut = muonGeom->layer((DTWireId(outermostMuSimHit->detUnitId())).layerId());
173  GlobalPoint inGlobalPos = layerIn->toGlobal(innermostMuSimHit->localPosition());
174  GlobalPoint outGlobalPos = layerOut->toGlobal(outermostMuSimHit->localPosition());
175  LocalVector simHitDirection = (muonGeom->idToDet(detId))->toLocal(inGlobalPos - outGlobalPos);
176  simHitDirection = -simHitDirection.unit();
177 
178  //SimHit position extrapolated at z=0 in the Det RF
179  LocalPoint outLocalPos = (muonGeom->idToDet(detId))->toLocal(outGlobalPos);
180  LocalPoint simSegLocalPosition =
181  outLocalPos + simHitDirection*(-outLocalPos.z()/(simHitDirection.mag()*cos(simHitDirection.theta())));
182 
183  return make_pair(simHitDirection, simSegLocalPosition);
184 }
185 
186 // Find the angles from a segment direction:
187 // NB: For 4D RecHits:
188 // Alpha = angle measured by SL RPhi
189 // Beta = angle measured by SL RZ
190 // For 2D RecHits: only Alpha makes sense
191 pair<double, double> DTHitQualityUtils::findSegmentAlphaAndBeta(const LocalVector& direction) {
192  //return make_pair(atan(direction.x()/direction.z()), atan(direction.y()/direction.z()));
193  return make_pair((direction.x()/direction.z()), (direction.y()/direction.z()));
194 }
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
virtual const GeomDet * idToDet(DetId) const
Definition: DTGeometry.cc:78
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:47
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.
#define abs(x)
Definition: mlp_lapack.h:159
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:112
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
static std::pair< double, double > findSegmentAlphaAndBeta(const LocalVector &direction)
Find the angles from a segment direction:
Vector3DBase unit() const
Definition: Vector3DBase.h:57
Definition: DetId.h:20
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...
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:64
virtual ~DTHitQualityUtils()
Destructor.
tuple cout
Definition: gather_cfg.py:121
std::vector< PSimHit > PSimHitContainer
static std::map< DTWireId, edm::PSimHitContainer > mapSimHitsPerWire(const edm::PSimHitContainer &simhits)
#define debug
Definition: MEtoEDMFormat.h:34
T x() const
Definition: PV3DBase.h:62
unsigned int detUnitId() const
Definition: PSimHit.h:93