Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <memory>
00022
00023
00024 #include "FWCore/Framework/interface/Frameworkfwd.h"
00025 #include "FWCore/Framework/interface/EDProducer.h"
00026 #include "FWCore/Framework/interface/Event.h"
00027 #include "FWCore/Framework/interface/EventSetup.h"
00028 #include "FWCore/Framework/interface/ESHandle.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031
00032
00033 #include "DataFormats/TrackReco/interface/Track.h"
00034 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00035 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00036 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00037 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00038 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00039 #include "MagneticField/Engine/interface/MagneticField.h"
00040 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00041 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
00042 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00043 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHitBuilder.h"
00044 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00045 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00046 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00047 #include "CondFormats/Alignment/interface/Definitions.h"
00048 #include "DataFormats/GeometrySurface/interface/Surface.h"
00049
00050 #include "FWCore/ServiceRegistry/interface/Service.h"
00051 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00052 #include "TTree.h"
00053
00054
00055 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00056 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00057
00058
00059
00060
00061
00062 class CSCOverlapsTrackPreparation : public edm::EDProducer {
00063 public:
00064 explicit CSCOverlapsTrackPreparation(const edm::ParameterSet&);
00065 ~CSCOverlapsTrackPreparation();
00066
00067 private:
00068 enum {kNothing, kSimpleFit, kAllButOne, kExtrapolate};
00069
00070 virtual void beginJob();
00071 virtual void produce(edm::Event&, const edm::EventSetup&);
00072 virtual void endJob();
00073
00074
00075 edm::InputTag m_src;
00076 };
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 CSCOverlapsTrackPreparation::CSCOverlapsTrackPreparation(const edm::ParameterSet& iConfig)
00090 : m_src(iConfig.getParameter<edm::InputTag>("src"))
00091 {
00092 produces<std::vector<Trajectory> >();
00093 produces<TrajTrackAssociationCollection>();
00094 }
00095
00096
00097 CSCOverlapsTrackPreparation::~CSCOverlapsTrackPreparation()
00098 {
00099
00100
00101 }
00102
00103
00104
00105
00106
00107
00108
00109 void
00110 CSCOverlapsTrackPreparation::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00111 edm::Handle<reco::TrackCollection> tracks;
00112 iEvent.getByLabel(m_src, tracks);
00113
00114 edm::ESHandle<CSCGeometry> cscGeometry;
00115 iSetup.get<MuonGeometryRecord>().get(cscGeometry);
00116
00117 edm::ESHandle<MagneticField> magneticField;
00118 iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
00119
00120 edm::ESHandle<GlobalTrackingGeometry> globalGeometry;
00121 iSetup.get<GlobalTrackingGeometryRecord>().get(globalGeometry);
00122
00123 TrajectoryStateTransform transformer;
00124 MuonTransientTrackingRecHitBuilder muonTransBuilder;
00125
00126
00127 std::auto_ptr<std::vector<Trajectory> > trajectoryCollection(new std::vector<Trajectory>);
00128
00129
00130 std::map<edm::Ref<std::vector<Trajectory> >::key_type, edm::Ref<reco::TrackCollection>::key_type> reference_map;
00131 edm::Ref<std::vector<Trajectory> >::key_type trajCounter = 0;
00132 edm::Ref<reco::TrackCollection>::key_type trackCounter = 0;
00133
00134 for (reco::TrackCollection::const_iterator track = tracks->begin(); track != tracks->end(); ++track) {
00135 trackCounter++;
00136
00137
00138
00139 edm::OwnVector<TrackingRecHit> clonedHits;
00140 std::vector<TrajectoryMeasurement::ConstRecHitPointer> transHits;
00141 std::vector<TrajectoryStateOnSurface> TSOSes;
00142
00143 for (trackingRecHit_iterator hit = track->recHitsBegin(); hit != track->recHitsEnd(); ++hit) {
00144 DetId id = (*hit)->geographicalId();
00145 if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
00146 const Surface &layerSurface = cscGeometry->idToDet(id)->surface();
00147 TrajectoryMeasurement::ConstRecHitPointer hitPtr(muonTransBuilder.build(&**hit, globalGeometry));
00148
00149 AlgebraicVector params(5);
00150 params[0] = 1.;
00151 params[1] = 0.;
00152 params[2] = 0.;
00153 params[3] = 0.;
00154 params[4] = 0.;
00155 LocalTrajectoryParameters localTrajectoryParameters(params, 1., false);
00156 LocalTrajectoryError localTrajectoryError(0.001, 0.001, 0.001, 0.001, 0.001);
00157
00158
00159 clonedHits.push_back((*hit)->clone());
00160 transHits.push_back(hitPtr);
00161 TSOSes.push_back(TrajectoryStateOnSurface(localTrajectoryParameters, localTrajectoryError, layerSurface, &*magneticField));
00162 }
00163 }
00164
00165 assert(clonedHits.size() == transHits.size());
00166 assert(transHits.size() == TSOSes.size());
00167
00168
00169 if (clonedHits.size() > 0) {
00170 PTrajectoryStateOnDet *PTraj = transformer.persistentState(*(TSOSes.begin()), clonedHits.begin()->geographicalId().rawId());
00171 TrajectorySeed trajectorySeed(*PTraj, clonedHits, alongMomentum);
00172 Trajectory trajectory(trajectorySeed, alongMomentum);
00173
00174 edm::OwnVector<TrackingRecHit>::const_iterator clonedHit = clonedHits.begin();
00175 std::vector<TrajectoryMeasurement::ConstRecHitPointer>::const_iterator transHitPtr = transHits.begin();
00176 std::vector<TrajectoryStateOnSurface>::const_iterator TSOS = TSOSes.begin();
00177 for (; clonedHit != clonedHits.end(); ++clonedHit, ++transHitPtr, ++TSOS) {
00178 trajectory.push(TrajectoryMeasurement(*TSOS, *TSOS, *TSOS, (*transHitPtr)));
00179 }
00180
00181 trajectoryCollection->push_back(trajectory);
00182
00183
00184 trajCounter++;
00185 reference_map[trajCounter] = trackCounter;
00186
00187 }
00188 }
00189
00190 unsigned int numTrajectories = trajectoryCollection->size();
00191
00192
00193 edm::OrphanHandle<std::vector<Trajectory> > ohTrajs = iEvent.put(trajectoryCollection);
00194
00195
00196 std::auto_ptr<TrajTrackAssociationCollection> trajTrackMap(new TrajTrackAssociationCollection());
00197
00198 for (trajCounter = 0; trajCounter < numTrajectories; trajCounter++) {
00199 edm::Ref<reco::TrackCollection>::key_type trackCounter = reference_map[trajCounter];
00200
00201 trajTrackMap->insert(edm::Ref<std::vector<Trajectory> >(ohTrajs, trajCounter), edm::Ref<reco::TrackCollection>(tracks, trackCounter));
00202 }
00203
00204 iEvent.put(trajTrackMap);
00205 }
00206
00207
00208 void CSCOverlapsTrackPreparation::beginJob() {}
00209
00210
00211 void CSCOverlapsTrackPreparation::endJob() {}
00212
00213
00214 DEFINE_FWK_MODULE(CSCOverlapsTrackPreparation);