CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/RecoMuon/TransientTrackingRecHit/src/MuonTransientTrackingRecHit.cc

Go to the documentation of this file.
00001 
00007 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00008 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00009 
00010 #include "DataFormats/GeometryCommonDetAlgo/interface/ErrorFrameTransformer.h"
00011 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00012 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 #include "FWCore/Utilities/interface/Exception.h"
00016 
00017 #include <map>
00018 
00019 typedef MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer;
00020 typedef MuonTransientTrackingRecHit::RecHitContainer   MuonRecHitContainer;
00021 
00022 
00023 MuonTransientTrackingRecHit::MuonTransientTrackingRecHit(const GeomDet* geom, const TrackingRecHit* rh) :
00024   GenericTransientTrackingRecHit(geom,*rh){}
00025 
00026 MuonTransientTrackingRecHit::MuonTransientTrackingRecHit(const MuonTransientTrackingRecHit& other ) :
00027   GenericTransientTrackingRecHit(other.det(), *(other.hit())) {}
00028 
00029 
00030 LocalVector MuonTransientTrackingRecHit::localDirection() const {
00031 
00032   if (dynamic_cast<const RecSegment*>(hit()) )
00033      return dynamic_cast<const RecSegment*>(hit())->localDirection(); 
00034   else return LocalVector(0.,0.,0.);
00035 
00036 }
00037 
00038 LocalError MuonTransientTrackingRecHit::localDirectionError() const {
00039 
00040   if (dynamic_cast<const RecSegment*>(hit()))
00041      return dynamic_cast<const RecSegment*>(hit())->localDirectionError();
00042   else return LocalError(0.,0.,0.);
00043 
00044 }
00045 
00046 GlobalVector MuonTransientTrackingRecHit::globalDirection() const
00047 {
00048   return  (det()->surface().toGlobal(localDirection()));
00049 }
00050 
00051 GlobalError MuonTransientTrackingRecHit::globalDirectionError() const
00052 {
00053   return ErrorFrameTransformer().transform( localDirectionError(), (det()->surface()));
00054 }
00055 
00056 
00057 AlgebraicSymMatrix MuonTransientTrackingRecHit::parametersError() const {
00058   
00059   AlgebraicSymMatrix err = GenericTransientTrackingRecHit::parametersError();
00060  
00061     LocalError lape = det()->localAlignmentError();
00062     if (lape.valid()) {
00063 
00064     // Just for speed up the code, the "else" branch can handle also the case of dim = 1.
00065     if(err.num_row() == 1) err[0][0] += lape.xx();
00066     else{
00067       AlgebraicSymMatrix lapeMatrix(5,0);
00068       lapeMatrix[3][3] = lape.xx();
00069       lapeMatrix[3][4] = lape.xy();
00070       lapeMatrix[4][4] = lape.yy();
00071       
00072       AlgebraicSymMatrix lapeMatrixProj = lapeMatrix.similarity(projectionMatrix());
00073       
00074       if(err.num_row() != lapeMatrixProj.num_row())
00075         throw cms::Exception("MuonTransientTrackingRecHit::parametersError") 
00076           <<"Discrepancy between alignment error matrix and error matrix: APE " 
00077           << lapeMatrixProj.num_row()
00078           << ", error matrix " << err.num_row() 
00079           << std::endl;
00080       
00081       err += lapeMatrixProj;
00082     }
00083   }
00084   return err;
00085 }
00086 
00087 double MuonTransientTrackingRecHit::chi2() const 
00088 {
00089   if (dynamic_cast<const RecSegment*>(hit()))
00090     return dynamic_cast<const RecSegment*>(hit())->chi2();
00091   else return 0.;
00092 }
00093 
00094 int MuonTransientTrackingRecHit::degreesOfFreedom() const 
00095 {
00096   if (dynamic_cast<const RecSegment*>(hit()))
00097     return dynamic_cast<const RecSegment*>(hit())->degreesOfFreedom();
00098   else return 0;
00099 }
00100 
00101 bool MuonTransientTrackingRecHit::isDT() const{
00102   return  (geographicalId().subdetId() == MuonSubdetId::DT);
00103 }
00104 
00105 bool MuonTransientTrackingRecHit::isCSC() const{
00106   return  (geographicalId().subdetId() == MuonSubdetId::CSC);
00107 }
00108 
00109 bool MuonTransientTrackingRecHit::isRPC() const{
00110   return  (geographicalId().subdetId() == MuonSubdetId::RPC);
00111 }
00112 
00113 // FIXME, now it is "on-demand". I have to change it.
00114 // FIXME check on mono hit!
00115 TransientTrackingRecHit::ConstRecHitContainer MuonTransientTrackingRecHit::transientHits() const{
00116 
00117   ConstRecHitContainer theSubTransientRecHits;
00118   
00119   // the sub rec hit of this TransientRecHit
00120   std::vector<const TrackingRecHit*> ownRecHits = recHits();
00121 
00122   if(ownRecHits.size() == 0){
00123     theSubTransientRecHits.push_back(this);
00124     return theSubTransientRecHits;
00125   }
00126   
00127   // the components of the geom det on which reside this rechit
00128   std::vector<const GeomDet *> geomDets = det()->components();
00129 
00130   if(isDT() && dimension() == 2 && ownRecHits.front()->dimension() == 1 
00131      && (geomDets.size() == 3 || geomDets.size() == 2) ){ // it is a phi segment!!
00132     
00133     std::vector<const GeomDet *> subGeomDets;
00134 
00135     int sl = 1;
00136     for(std::vector<const GeomDet *>::const_iterator geoDet = geomDets.begin();
00137         geoDet != geomDets.end(); ++geoDet){
00138       if(sl != 3){ // FIXME!! this maybe is not always true
00139         std::vector<const GeomDet *> tmp = (*geoDet)->components();
00140         std::copy(tmp.begin(),tmp.end(),back_inserter(subGeomDets));
00141       }
00142       ++sl;
00143     }
00144     geomDets.clear();
00145     geomDets = subGeomDets;
00146   }
00147   
00148   // Fill the GeomDet map
00149   std::map<DetId,const GeomDet*> gemDetMap;
00150   
00151   for (std::vector<const GeomDet*>::const_iterator subDet = geomDets.begin(); 
00152        subDet != geomDets.end(); ++subDet)
00153     gemDetMap[ (*subDet)->geographicalId() ] = *subDet;
00154   
00155   std::map<DetId,const GeomDet*>::iterator gemDetMap_iter;
00156   
00157   // Loop in order to check the ids
00158   for (std::vector<const TrackingRecHit*>::const_iterator rechit = ownRecHits.begin(); 
00159        rechit != ownRecHits.end(); ++rechit){
00160     
00161     gemDetMap_iter = gemDetMap.find( (*rechit)->geographicalId() );
00162     
00163     if(gemDetMap_iter != gemDetMap.end() )
00164       theSubTransientRecHits.push_back(new MuonTransientTrackingRecHit(gemDetMap_iter->second, 
00165                                                                          *rechit) );
00166     else if( (*rechit)->geographicalId() == det()->geographicalId() ) // Phi in DT is on Chamber
00167       theSubTransientRecHits.push_back(new MuonTransientTrackingRecHit(det(), 
00168                                                                        *rechit) );
00169   }
00170   return theSubTransientRecHits;
00171 
00172 }
00173 
00174 
00175 void MuonTransientTrackingRecHit::invalidateHit(){ 
00176   setType(bad); trackingRecHit_->setType(bad); 
00177 
00178 
00179   if (isDT()){
00180     if(dimension() > 1){ // MB4s have 2D, but formatted in 4D segments 
00181       std::vector<TrackingRecHit*> seg2D = recHits(); // 4D --> 2D
00182       // load 1D hits (2D --> 1D)
00183       for(std::vector<TrackingRecHit*>::iterator it = seg2D.begin(); it != seg2D.end(); ++it){
00184         std::vector<TrackingRecHit*> hits1D =  (*it)->recHits();
00185         (*it)->setType(bad);
00186         for(std::vector<TrackingRecHit*>::iterator it2 = hits1D.begin(); it2 != hits1D.end(); ++it2)
00187           (*it2)->setType(bad);
00188       }
00189     }
00190   }
00191   else if(isCSC())
00192     if(dimension() == 4){
00193       std::vector<TrackingRecHit*>  hits = recHits(); // load 2D hits (4D --> 1D)
00194       for(std::vector<TrackingRecHit*>::iterator it = hits.begin(); it != hits.end(); ++it)
00195         (*it)->setType(bad);
00196     }
00197   
00198   
00199 }