00001
00009 #include "RecoMuon/CosmicMuonProducer/interface/CosmicMuonUtilities.h"
00010
00011 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00012 #include "DataFormats/GeometrySurface/interface/PlaneBuilder.h"
00013
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015
00016 using namespace edm;
00017 using namespace std;
00018
00019
00020
00021
00022 CosmicMuonUtilities::CosmicMuonUtilities() {
00023 }
00024
00025
00026
00027
00028 CosmicMuonUtilities::~CosmicMuonUtilities() {
00029 }
00030
00031 void CosmicMuonUtilities::reverseDirection(TrajectoryStateOnSurface& tsos, const MagneticField* mgfield) const {
00032
00033 GlobalTrajectoryParameters gtp(tsos.globalPosition(),
00034 -tsos.globalMomentum(),
00035 -tsos.charge(),
00036 mgfield);
00037 TrajectoryStateOnSurface newTsos(gtp, tsos.cartesianError(), tsos.surface());
00038 tsos = newTsos;
00039 return;
00040
00041 }
00042
00043 string CosmicMuonUtilities::print(const MuonTransientTrackingRecHit::ConstMuonRecHitContainer& hits) const {
00044
00045 stringstream output;
00046
00047 for (ConstMuonRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
00048 if ( !(*ir)->isValid() ) {
00049 output << "invalid RecHit"<<endl;
00050 continue;
00051 }
00052
00053 const GlobalPoint& pos = (*ir)->globalPosition();
00054 output
00055 << "pos"<<pos
00056 << "radius "<<pos.perp()
00057 << " dim " << (*ir)->dimension()
00058 << " det " << (*ir)->det()->geographicalId().det()
00059 << " sub det " << (*ir)->det()->subDetector()<<endl;
00060 }
00061 return output.str();
00062
00063 }
00064
00065 string CosmicMuonUtilities::print(const MuonTransientTrackingRecHit::MuonRecHitContainer& hits) const {
00066
00067 stringstream output;
00068
00069 for (MuonRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
00070 if ( !(*ir)->isValid() ) {
00071 output << "invalid RecHit"<<endl;
00072 continue;
00073 }
00074
00075 const GlobalPoint& pos = (*ir)->globalPosition();
00076 output
00077 << "pos"<<pos
00078 << "radius "<<pos.perp()
00079 << " dim " << (*ir)->dimension()
00080 << " det " << (*ir)->det()->geographicalId().det()
00081 << " sub det " << (*ir)->det()->subDetector()<<endl;
00082 }
00083 return output.str();
00084
00085 }
00086
00087 TrajectoryStateOnSurface CosmicMuonUtilities::stepPropagate(const TrajectoryStateOnSurface& tsos,
00088 const ConstRecHitPointer& hit,
00089 const Propagator& prop ) const {
00090
00091 const std::string metname = "Muon|RecoMuon|CosmicMuonUtilities";
00092
00093 GlobalPoint start = tsos.globalPosition();
00094 GlobalPoint dest = hit->globalPosition();
00095 GlobalVector StepVector = dest - start;
00096 GlobalVector UnitStepVector = StepVector.unit();
00097 GlobalPoint GP =start;
00098 TrajectoryStateOnSurface currTsos(tsos);
00099 TrajectoryStateOnSurface predTsos;
00100 float totalDis = StepVector.mag();
00101 LogTrace(metname)<<"stepPropagate: propagate from: "<<start<<" to "<<dest;
00102 LogTrace(metname)<<"stepPropagate: their distance: "<<totalDis;
00103
00104 int steps = 3;
00105
00106 float oneStep = totalDis/steps;
00107 Basic3DVector<float> Basic3DV(StepVector.x(),StepVector.y(),StepVector.z());
00108 for ( int istep = 0 ; istep < steps - 1 ; istep++) {
00109 GP += oneStep*UnitStepVector;
00110 Surface::PositionType pos(GP.x(),GP.y(),GP.z());
00111 LogTrace(metname)<<"stepPropagate: a middle plane: "<<pos<<endl;
00112 Surface::RotationType rot( Basic3DV , float(0));
00113 PlaneBuilder::ReturnType SteppingPlane = PlaneBuilder().plane(pos,rot);
00114 TrajectoryStateOnSurface predTsos = prop.propagate(currTsos, *SteppingPlane);
00115 if (predTsos.isValid()) {
00116 currTsos=predTsos;
00117 LogTrace(metname)<<"stepPropagate: middle state "<< currTsos.globalPosition()<<endl;
00118 }
00119 }
00120
00121 predTsos = prop.propagate(currTsos, hit->det()->surface());
00122
00123 return predTsos;
00124 }
00125
00126
00127 string CosmicMuonUtilities::print(const TransientTrackingRecHit::ConstRecHitContainer& hits) const {
00128
00129 stringstream output;
00130
00131 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
00132 if ( !(*ir)->isValid() ) {
00133 output << "invalid RecHit"<<endl;
00134 continue;
00135 }
00136
00137 const GlobalPoint& pos = (*ir)->globalPosition();
00138 output
00139 << "pos"<<pos
00140 << "radius "<<pos.perp()
00141 << " dim " << (*ir)->dimension()
00142 << " det " << (*ir)->det()->geographicalId().det()
00143 << " sub det " << (*ir)->det()->subDetector()<<endl;
00144 }
00145
00146 return output.str();
00147 }