00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "Validation/DTRecHits/interface/DTHitQualityUtils.h"
00012 #include "DataFormats/DetId/interface/DetId.h"
00013 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00014 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00015 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00016
00017 #include <iostream>
00018
00019 using namespace std;
00020 using namespace edm;
00021
00022 bool DTHitQualityUtils::debug;
00023
00024
00025 DTHitQualityUtils::DTHitQualityUtils(){
00026
00027 if(debug)
00028 cout << "[DTHitQualityUtils] Constructor called!!" << endl;
00029 }
00030
00031
00032 DTHitQualityUtils::~DTHitQualityUtils(){
00033 if(debug)
00034 cout << "[DTHitQualityUtils] Destructor called!!" << endl;
00035 }
00036
00037
00038
00039 map<DTWireId, PSimHitContainer >
00040 DTHitQualityUtils::mapSimHitsPerWire(const PSimHitContainer& simhits) {
00041 map<DTWireId, PSimHitContainer > hitWireMapResult;
00042
00043 for(PSimHitContainer::const_iterator simhit = simhits.begin();
00044 simhit != simhits.end();
00045 simhit++) {
00046 hitWireMapResult[DTWireId((*simhit).detUnitId())].push_back(*simhit);
00047 }
00048
00049 return hitWireMapResult;
00050 }
00051
00052
00053 map<DTWireId, const PSimHit*>
00054 DTHitQualityUtils::mapMuSimHitsPerWire(const map<DTWireId, PSimHitContainer>& simHitWireMap) {
00055
00056 map<DTWireId, const PSimHit*> ret;
00057
00058 for(map<DTWireId, PSimHitContainer>::const_iterator wireAndSimHit = simHitWireMap.begin();
00059 wireAndSimHit != simHitWireMap.end();
00060 wireAndSimHit++) {
00061
00062 const PSimHit* muHit = findMuSimHit((*wireAndSimHit).second);
00063 if(muHit != 0) {
00064 ret[(*wireAndSimHit).first]=(muHit);
00065 }
00066 }
00067 return ret;
00068 }
00069
00070
00071
00072
00073 const PSimHit* DTHitQualityUtils::findMuSimHit(const PSimHitContainer& hits) {
00074
00075 vector<const PSimHit*> muHits;
00076
00077
00078 for (PSimHitContainer::const_iterator hit=hits.begin();
00079 hit != hits.end(); hit++) {
00080 if (abs((*hit).particleType())==13) muHits.push_back(&(*hit));
00081 }
00082
00083 if (muHits.size()==0)
00084 return 0;
00085 else if (muHits.size()>1)
00086 if(debug)
00087 cout << "[DTHitQualityUtils]***WARNING: # muSimHits in a wire = " << muHits.size() << endl;
00088
00089 return (muHits.front());
00090 }
00091
00092
00093
00094 pair<const PSimHit*, const PSimHit*>
00095 DTHitQualityUtils::findMuSimSegment(const map<DTWireId, const PSimHit*>& mapWireAndMuSimHit) {
00096
00097 int outSL = 0;
00098 int inSL = 4;
00099 int outLayer = 0;
00100 int inLayer = 5;
00101 const PSimHit *inSimHit = 0;
00102 const PSimHit *outSimHit = 0;
00103
00104 for(map<DTWireId, const PSimHit*>::const_iterator wireAndMuSimHit = mapWireAndMuSimHit.begin();
00105 wireAndMuSimHit != mapWireAndMuSimHit.end();
00106 wireAndMuSimHit++) {
00107
00108 const DTWireId wireId = (*wireAndMuSimHit).first;
00109 const PSimHit *theMuHit = (*wireAndMuSimHit).second;
00110
00111 int sl = ((wireId.layerId()).superlayerId()).superLayer();
00112 int layer = (wireId.layerId()).layer();
00113
00114 if(sl == outSL) {
00115 if(layer > outLayer) {
00116 outLayer = layer;
00117 outSimHit = theMuHit;
00118 }
00119 }
00120 if(sl > outSL) {
00121 outSL = sl;
00122 outLayer = layer;
00123 outSimHit = theMuHit;
00124 }
00125 if(sl == inSL) {
00126 if(layer < inLayer) {
00127 inLayer = layer;
00128 inSimHit = theMuHit;
00129 }
00130 }
00131 if(sl < inSL) {
00132 inSL = sl;
00133 inLayer = layer;
00134 inSimHit = theMuHit;
00135 }
00136 }
00137
00138 if(inSimHit != 0) {
00139 if(debug)
00140 cout << "Innermost SimHit on SL: " << inSL << " layer: " << inLayer << endl;
00141 } else {
00142 cout << "[DTHitQualityUtils]***Error: No Innermost SimHit found!!!" << endl;
00143 abort();
00144 }
00145
00146 if(outSimHit != 0) {
00147 if(debug)
00148 cout << "Outermost SimHit on SL: " << outSL << " layer: " << outLayer << endl;
00149 } else {
00150 cout << "[DTHitQualityUtils]***Error: No Outermost SimHit found!!!" << endl;
00151 abort();
00152 }
00153
00154 return make_pair(inSimHit, outSimHit);
00155 }
00156
00157
00158
00159
00160
00161 pair<LocalVector, LocalPoint>
00162 DTHitQualityUtils::findMuSimSegmentDirAndPos(const pair<const PSimHit*, const PSimHit*>& inAndOutSimHit,
00163 const DetId detId, const DTGeometry *muonGeom) {
00164
00165
00166 const PSimHit* innermostMuSimHit = inAndOutSimHit.first;
00167 const PSimHit* outermostMuSimHit = inAndOutSimHit.second;
00168
00169
00170 const DTLayer* layerIn = muonGeom->layer((DTWireId(innermostMuSimHit->detUnitId())).layerId());
00171 const DTLayer* layerOut = muonGeom->layer((DTWireId(outermostMuSimHit->detUnitId())).layerId());
00172 GlobalPoint inGlobalPos = layerIn->toGlobal(innermostMuSimHit->localPosition());
00173 GlobalPoint outGlobalPos = layerOut->toGlobal(outermostMuSimHit->localPosition());
00174 LocalVector simHitDirection = (muonGeom->idToDet(detId))->toLocal(inGlobalPos - outGlobalPos);
00175 simHitDirection = -simHitDirection.unit();
00176
00177
00178 LocalPoint outLocalPos = (muonGeom->idToDet(detId))->toLocal(outGlobalPos);
00179 LocalPoint simSegLocalPosition =
00180 outLocalPos + simHitDirection*(-outLocalPos.z()/(simHitDirection.mag()*cos(simHitDirection.theta())));
00181
00182 return make_pair(simHitDirection, simSegLocalPosition);
00183 }
00184
00185
00186
00187
00188
00189
00190 pair<double, double> DTHitQualityUtils::findSegmentAlphaAndBeta(const LocalVector& direction) {
00191 return make_pair(atan(direction.x()/direction.z()), atan(direction.y()/direction.z()));
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202