Go to the documentation of this file.00001 #include "SimTracker/TrackAssociation/interface/CosmicParametersDefinerForTP.h"
00002 #include "FWCore/Utilities/interface/typelookup.h"
00003 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00004 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00005 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00006 #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
00007 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
00008 #include "MagneticField/Engine/interface/MagneticField.h"
00009 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00010 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00011 #include <Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h>
00012 #include <DataFormats/GeometrySurface/interface/Surface.h>
00013 #include <DataFormats/GeometrySurface/interface/GloballyPositioned.h>
00014 #include <Geometry/CommonDetUnit/interface/GeomDet.h>
00015 #include "FWCore/Framework/interface/Event.h"
00016 #include <FWCore/Framework/interface/ESHandle.h>
00017
00018 class TrajectoryStateClosestToBeamLineBuilder;
00019
00020
00021 ParticleBase::Vector
00022 CosmicParametersDefinerForTP::momentum(const edm::Event& iEvent, const edm::EventSetup& iSetup, const TrackingParticle& tp) const{
00023
00024 using namespace edm;
00025 using namespace std;
00026 using namespace reco;
00027
00028 ESHandle<TrackerGeometry> tracker;
00029 iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
00030
00031 edm::ESHandle<MagneticField> theMF;
00032 iSetup.get<IdealMagneticFieldRecord>().get(theMF);
00033
00034 edm::Handle<reco::BeamSpot> bs;
00035 iEvent.getByLabel(InputTag("offlineBeamSpot"),bs);
00036
00037
00038
00039
00040
00041 GlobalVector finalGV;
00042 GlobalPoint finalGP;
00043 double radius(9999);
00044 bool found(0);
00045 ParticleBase::Vector momentum(0,0,0);
00046
00047 const vector<PSimHit> & simHits = tp.trackPSimHit(DetId::Tracker);
00048 for(vector<PSimHit>::const_iterator it=simHits.begin(); it!=simHits.end(); ++it){
00049 const GeomDet* tmpDet = tracker->idToDet( DetId(it->detUnitId()) ) ;
00050 LocalVector lv = it->momentumAtEntry();
00051 Local3DPoint lp = it->localPosition ();
00052 GlobalVector gv = tmpDet->surface().toGlobal( lv );
00053 GlobalPoint gp = tmpDet->surface().toGlobal( lp );
00054 if(gp.perp()<radius){
00055 found=true;
00056 radius = gp.perp();
00057 finalGV = gv;
00058 finalGP = gp;
00059 }
00060 }
00061
00062
00063
00064
00065
00066 if(found)
00067 {
00068 FreeTrajectoryState ftsAtProduction(finalGP,finalGV,TrackCharge(tp.charge()),theMF.product());
00069 TSCBLBuilderNoMaterial tscblBuilder;
00070 TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction,*bs);
00071 if(tsAtClosestApproach.isValid()){
00072 GlobalVector p = tsAtClosestApproach.trackStateAtPCA().momentum();
00073 momentum = ParticleBase::Vector(p.x(), p.y(), p.z());
00074 }
00075 return momentum;
00076 }
00077 return momentum;
00078 }
00079
00080 ParticleBase::Point CosmicParametersDefinerForTP::vertex(const edm::Event& iEvent, const edm::EventSetup& iSetup, const TrackingParticle& tp) const{
00081
00082 using namespace edm;
00083 using namespace std;
00084 using namespace reco;
00085
00086 ESHandle<TrackerGeometry> tracker;
00087 iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
00088
00089 edm::ESHandle<MagneticField> theMF;
00090 iSetup.get<IdealMagneticFieldRecord>().get(theMF);
00091
00092 edm::Handle<reco::BeamSpot> bs;
00093 iEvent.getByLabel(InputTag("offlineBeamSpot"),bs);
00094
00095 GlobalVector finalGV;
00096 GlobalPoint finalGP;
00097 double radius(9999);
00098 bool found(0);
00099 ParticleBase::Point vertex(0,0,0);
00100
00101 const vector<PSimHit> & simHits = tp.trackPSimHit(DetId::Tracker);
00102 for(vector<PSimHit>::const_iterator it=simHits.begin(); it!=simHits.end(); ++it){
00103 const GeomDet* tmpDet = tracker->idToDet( DetId(it->detUnitId()) ) ;
00104 LocalVector lv = it->momentumAtEntry();
00105 Local3DPoint lp = it->localPosition ();
00106 GlobalVector gv = tmpDet->surface().toGlobal( lv );
00107 GlobalPoint gp = tmpDet->surface().toGlobal( lp );
00108 if(gp.perp()<radius){
00109 found=true;
00110 radius = gp.perp();
00111 finalGV = gv;
00112 finalGP = gp;
00113 }
00114 }
00115 if(found)
00116 {
00117 FreeTrajectoryState ftsAtProduction(finalGP,finalGV,TrackCharge(tp.charge()),theMF.product());
00118 TSCBLBuilderNoMaterial tscblBuilder;
00119 TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction,*bs);
00120 if(tsAtClosestApproach.isValid()){
00121 GlobalPoint v = tsAtClosestApproach.trackStateAtPCA().position();
00122 vertex = ParticleBase::Point(v.x()-bs->x0(),v.y()-bs->y0(),v.z()-bs->z0());
00123 }
00124 return vertex;
00125 }
00126 return vertex;
00127 }
00128
00129
00130 TYPELOOKUP_DATA_REG(CosmicParametersDefinerForTP);