CMS 3D CMS Logo

DTHitQualityUtils.cc

Go to the documentation of this file.
00001 
00002 /*
00003  *  See header file for a description of this class.
00004  *
00005  *  $Date: 2007/10/25 12:01:15 $
00006  *  $Revision: 1.5 $
00007  *  \author S. Bolognesi and G. Cerminara - INFN Torino
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 // Constructor
00025 DTHitQualityUtils::DTHitQualityUtils(){
00026   //DTHitQualityUtils::setDebug(debug);
00027   if(debug)
00028     cout << "[DTHitQualityUtils] Constructor called!!" << endl;
00029 }
00030 
00031 // Destructor
00032 DTHitQualityUtils::~DTHitQualityUtils(){
00033   if(debug)
00034     cout << "[DTHitQualityUtils] Destructor called!!" << endl;
00035 }
00036 
00037 
00038 // Return a map between simhits of a layer,superlayer or chamber and the wireId of their cell
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 // Extract mu simhits from a map of simhits by wire and map them by wire
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 // Find the sim hit from muon track in a vector of simhits
00072 // If no mu sim hit is found then it returns a null pointer
00073 const PSimHit* DTHitQualityUtils::findMuSimHit(const PSimHitContainer& hits) {
00074   //PSimHitContainer muHits;
00075   vector<const PSimHit*> muHits;
00076  
00077    // Loop over simhits
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; //FIXME: Throw of exception???
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 // Find Innermost and outermost SimHit from Mu in a SL (they identify a simulated segment)
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 // Find direction and position of a segment (in local RF) from outer and inner mu SimHit in the RF of object Det
00160 // (Concrete implementation of Det are MuBarSL and MuBarChamber)
00161 pair<LocalVector, LocalPoint>
00162 DTHitQualityUtils::findMuSimSegmentDirAndPos(const pair<const PSimHit*, const PSimHit*>& inAndOutSimHit,
00163                                              const DetId detId, const DTGeometry *muonGeom) {
00164 
00165   //FIXME: What should happen if outSimHit = inSimHit???? Now, this case is not considered
00166   const PSimHit* innermostMuSimHit = inAndOutSimHit.first;
00167   const PSimHit* outermostMuSimHit = inAndOutSimHit.second;
00168 
00169   //Find simulated segment direction from SimHits position
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   //SimHit position extrapolated at z=0 in the Det RF
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 // Find the angles from a segment direction:
00186 // NB: For 4D RecHits: 
00187 //                        Alpha = angle measured by SL RPhi
00188 //                        Beta  = angle measured by SL RZ
00189 //     For 2D RecHits: only Alpha makes sense
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 

Generated on Tue Jun 9 17:49:04 2009 for CMSSW by  doxygen 1.5.4