CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoMuon/CosmicMuonProducer/src/CosmicMuonUtilities.cc

Go to the documentation of this file.
00001 
00009 #include "RecoMuon/CosmicMuonProducer/interface/CosmicMuonUtilities.h"
00010 
00011 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00012 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00013 #include "DataFormats/GeometrySurface/interface/PlaneBuilder.h"
00014 #include "DataFormats/Math/interface/deltaPhi.h"
00015 
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 using namespace edm;
00019 using namespace std;
00020 
00021 //
00022 // constructor
00023 //
00024 CosmicMuonUtilities::CosmicMuonUtilities() {
00025 }
00026 
00027 
00028 //
00029 // destructor
00030 //
00031 CosmicMuonUtilities::~CosmicMuonUtilities() {
00032 }
00033 
00034 
00035 void CosmicMuonUtilities::reverseDirection(TrajectoryStateOnSurface& tsos, const MagneticField* mgfield) const {
00036 
00037    GlobalTrajectoryParameters gtp(tsos.globalPosition(),
00038                                   -tsos.globalMomentum(),
00039                                   -tsos.charge(),
00040                                   mgfield);
00041    TrajectoryStateOnSurface newTsos(gtp, tsos.cartesianError(), tsos.surface()); 
00042    tsos = newTsos;
00043 
00044    return;
00045 
00046 }
00047 
00048 
00049 //
00050 //
00051 //
00052 string CosmicMuonUtilities::print(const MuonTransientTrackingRecHit::ConstMuonRecHitContainer& hits) const {
00053 
00054    stringstream output;
00055 
00056     for (ConstMuonRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
00057     if ( !(*ir)->isValid() ) {
00058       output << "invalid RecHit"<<endl;
00059       continue;
00060     }
00061 
00062     const GlobalPoint& pos = (*ir)->globalPosition();
00063     output
00064     << "pos"<<pos
00065     << "radius "<<pos.perp()
00066     << "  dim " << (*ir)->dimension()
00067     << "  det " << (*ir)->det()->geographicalId().det()
00068     << "  sub det " << (*ir)->det()->subDetector()<<endl;
00069   }
00070 
00071   return output.str();
00072 
00073 }
00074 
00075 
00076 //
00077 //
00078 //
00079 string CosmicMuonUtilities::print(const MuonTransientTrackingRecHit::MuonRecHitContainer& hits) const {
00080 
00081    stringstream output;
00082 
00083     for (MuonRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
00084     if ( !(*ir)->isValid() ) {
00085       output << "invalid RecHit"<<endl;
00086       continue;
00087     }
00088 
00089     const GlobalPoint& pos = (*ir)->globalPosition();
00090     output
00091     << "pos"<<pos
00092     << "radius "<<pos.perp()
00093     << "  dim " << (*ir)->dimension()
00094     << "  det " << (*ir)->det()->geographicalId().det()
00095     << "  sub det " << (*ir)->det()->subDetector()<<endl;
00096   }
00097 
00098   return output.str();
00099 
00100 }
00101 
00102 
00103 //
00104 //
00105 //
00106 string CosmicMuonUtilities::print(const TransientTrackingRecHit::ConstRecHitContainer& hits) const {
00107 
00108     stringstream output;
00109 
00110     for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
00111     if ( !(*ir)->isValid() ) {
00112       output << "invalid RecHit"<<endl;
00113       continue;
00114     }
00115 
00116     const GlobalPoint& pos = (*ir)->globalPosition();
00117     output
00118     << "pos"<<pos
00119     << "radius "<<pos.perp()
00120     << "  dim " << (*ir)->dimension()
00121     << "  det " << (*ir)->det()->geographicalId().det()
00122     << "  sub det " << (*ir)->det()->subDetector()<<endl;
00123   }
00124 
00125   return output.str();
00126 
00127 }
00128 
00129 
00130 //
00131 //
00132 //
00133 bool CosmicMuonUtilities::isTraversing(const Trajectory& t) const {
00134 
00135   TransientTrackingRecHit::ConstRecHitContainer hits = t.recHits();
00136 
00137   if ( hits.empty() ) return false;
00138 
00139   ConstRecHitContainer::const_iterator frontHit = hits.begin();
00140   ConstRecHitContainer::const_iterator backHit  = hits.end() - 1;
00141 
00142   // find first valid hit at both ends of the trajectory
00143   while ( !(*frontHit)->isValid() && frontHit != backHit) {++frontHit;}
00144   while ( !(*backHit)->isValid() && backHit != frontHit)  {--backHit;}
00145 
00146   if ( frontHit == backHit )  return false;
00147 
00148   GlobalPoint frontPos = (*frontHit)->globalPosition();
00149   GlobalPoint backPos = (*backHit)->globalPosition();
00150 
00151   // are there separate muon hits in 2 different hemispheres
00152   GlobalVector deltaPos(frontPos - backPos);
00153   if ( deltaPos.mag() < 100.0 ) return false;
00154   if ( fabs(deltaPos.z() ) > 500.0 ) return true;
00155   if ( deltaPos.perp() > 350.0 ) return true;
00156   GlobalPoint middle((frontPos.x()+backPos.x())/2, 
00157                      (frontPos.y()+backPos.y())/2, 
00158                      (frontPos.z()+backPos.z())/2);
00159 
00160   return ( (middle.perp() < frontPos.perp()) && (middle.perp() < backPos.perp()) );
00161 
00162 }
00163 
00164 
00165 //
00166 //
00167 //
00168 TrajectoryStateOnSurface CosmicMuonUtilities::stepPropagate(const TrajectoryStateOnSurface& tsos,
00169                                                             const ConstRecHitPointer& hit,
00170                                                             const Propagator& prop ) const {
00171 
00172   const std::string metname = "Muon|RecoMuon|CosmicMuonUtilities";
00173 
00174   GlobalPoint start = tsos.globalPosition();
00175   GlobalPoint dest = hit->globalPosition();
00176   GlobalVector StepVector = dest - start;
00177   GlobalVector UnitStepVector = StepVector.unit();
00178   GlobalPoint GP =start;
00179   TrajectoryStateOnSurface currTsos(tsos);
00180   TrajectoryStateOnSurface predTsos;
00181   float totalDis = StepVector.mag();
00182   LogTrace(metname)<<"stepPropagate: propagate from: "<<start<<" to "<<dest;
00183   LogTrace(metname)<<"stepPropagate: their distance: "<<totalDis;
00184 
00185   int steps = 3; // need to optimize
00186 
00187   float oneStep = totalDis/steps;
00188   Basic3DVector<float> Basic3DV(StepVector.x(),StepVector.y(),StepVector.z());
00189   for ( int istep = 0 ; istep < steps - 1 ; istep++) {
00190         GP += oneStep*UnitStepVector;
00191         Surface::PositionType pos(GP.x(),GP.y(),GP.z());
00192         LogTrace(metname)<<"stepPropagate: a middle plane: "<<pos<<endl;
00193         Surface::RotationType rot( Basic3DV , float(0));
00194         PlaneBuilder::ReturnType SteppingPlane = PlaneBuilder().plane(pos,rot);
00195         TrajectoryStateOnSurface predTsos = prop.propagate(currTsos, *SteppingPlane);
00196         if (predTsos.isValid()) {
00197             currTsos=predTsos;
00198             LogTrace(metname)<<"stepPropagate: middle state "<< currTsos.globalPosition()<<endl;
00199         }
00200  }
00201 
00202   predTsos = prop.propagate(currTsos, hit->det()->surface());
00203 
00204   return predTsos;
00205 
00206 }