CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/Alignment/MuonAlignmentAlgorithms/plugins/CSCOverlapsTrackPreparation.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    CSCOverlapsTrackPreparation
00004 // Class:      CSCOverlapsTrackPreparation
00005 // 
00013 //
00014 // Original Author:  Jim Pivarski
00015 //         Created:  Wed Dec 12 13:31:55 CST 2007
00016 // $Id: CSCOverlapsTrackPreparation.cc,v 1.7 2010/05/04 01:16:05 pivarski Exp $
00017 //
00018 //
00019 
00020 // system include files
00021 #include <memory>
00022 
00023 // user include files
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 // references
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 // products
00055 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00056 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00057 
00058 //
00059 // class decleration
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       // ----------member data ---------------------------
00075       edm::InputTag m_src;
00076 };
00077 
00078 //
00079 // constants, enums and typedefs
00080 //
00081 
00082 //
00083 // static data member definitions
00084 //
00085 
00086 //
00087 // constructors and destructor
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    // do anything here that needs to be done at desctruction time
00100    // (e.g. close files, deallocate resources etc.)
00101 }
00102 
00103 
00104 //
00105 // member functions
00106 //
00107 
00108 // ------------ method called to produce the data  ------------
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   // Create a collection of Trajectories, to put in the Event
00127   std::auto_ptr<std::vector<Trajectory> > trajectoryCollection(new std::vector<Trajectory>);
00128 
00129   // Remember which trajectory is associated with which track
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     // now we'll actually put hits on the new trajectory
00138     // these must be in lock-step
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);   // meaningless, CSCOverlapsAlignmentAlgorithm does the fit internally
00150         params[0] = 1.;  // straight-forward direction
00151         params[1] = 0.;
00152         params[2] = 0.;
00153         params[3] = 0.;  // center of the chamber
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         // these must be in lock-step
00159         clonedHits.push_back((*hit)->clone());
00160         transHits.push_back(hitPtr);
00161         TSOSes.push_back(TrajectoryStateOnSurface(localTrajectoryParameters, localTrajectoryError, layerSurface, &*magneticField));
00162       } // end if CSC
00163     } // end loop over hits
00164 
00165     assert(clonedHits.size() == transHits.size());
00166     assert(transHits.size() == TSOSes.size());
00167 
00168     // build the trajectory
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       // Remember which Trajectory is associated with which Track
00184       trajCounter++;
00185       reference_map[trajCounter] = trackCounter;
00186 
00187     } // end if there are any clonedHits/TSOSes to work with
00188   } // end loop over tracks
00189 
00190   unsigned int numTrajectories = trajectoryCollection->size();
00191 
00192   // insert the trajectories into the Event
00193   edm::OrphanHandle<std::vector<Trajectory> > ohTrajs = iEvent.put(trajectoryCollection);
00194 
00195   // create the trajectory <-> track association map
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   // and put it in the Event, also
00204   iEvent.put(trajTrackMap);
00205 }
00206 
00207 // ------------ method called once each job just before starting event loop  ------------
00208 void CSCOverlapsTrackPreparation::beginJob() {}
00209 
00210 // ------------ method called once each job just after ending the event loop  ------------
00211 void CSCOverlapsTrackPreparation::endJob() {}
00212 
00213 //define this as a plug-in
00214 DEFINE_FWK_MODULE(CSCOverlapsTrackPreparation);