Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-22 02:30:55

0001 // -*- C++ -*-
0002 //
0003 // Package:    CSCOverlapsTrackPreparation
0004 // Class:      CSCOverlapsTrackPreparation
0005 //
0006 /**\class CSCOverlapsTrackPreparation CSCOverlapsTrackPreparation.cc Alignment/CSCOverlapsTrackPreparation/src/CSCOverlapsTrackPreparation.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jim Pivarski
0015 //         Created:  Wed Dec 12 13:31:55 CST 2007
0016 // $Id: CSCOverlapsTrackPreparation.cc,v 1.8 2011/03/22 09:49:50 innocent Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDProducer.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/EventSetup.h"
0028 #include "FWCore/Framework/interface/ESHandle.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 
0032 // references
0033 #include "DataFormats/TrackReco/interface/Track.h"
0034 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0035 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0036 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0037 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0038 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0039 #include "MagneticField/Engine/interface/MagneticField.h"
0040 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0041 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
0042 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0043 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHitBuilder.h"
0044 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0045 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0046 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0047 #include "CondFormats/Alignment/interface/Definitions.h"
0048 #include "DataFormats/GeometrySurface/interface/Surface.h"
0049 
0050 #include "FWCore/ServiceRegistry/interface/Service.h"
0051 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0052 #include "TTree.h"
0053 
0054 // products
0055 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0056 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0057 
0058 //
0059 // class decleration
0060 //
0061 
0062 class CSCOverlapsTrackPreparation : public edm::one::EDProducer<> {
0063 public:
0064   explicit CSCOverlapsTrackPreparation(const edm::ParameterSet&);
0065   ~CSCOverlapsTrackPreparation() override;
0066 
0067 private:
0068   enum { kNothing, kSimpleFit, kAllButOne, kExtrapolate };
0069 
0070   void beginJob() override;
0071   void produce(edm::Event&, const edm::EventSetup&) override;
0072   void endJob() override;
0073 
0074   // ----------member data ---------------------------
0075   edm::InputTag m_src;
0076 
0077   const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> cscGeomToken_;
0078   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0079   const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> globalGeomToken_;
0080 };
0081 
0082 //
0083 // constants, enums and typedefs
0084 //
0085 
0086 //
0087 // static data member definitions
0088 //
0089 
0090 //
0091 // constructors and destructor
0092 //
0093 CSCOverlapsTrackPreparation::CSCOverlapsTrackPreparation(const edm::ParameterSet& iConfig)
0094     : m_src(iConfig.getParameter<edm::InputTag>("src")),
0095       cscGeomToken_(esConsumes<edm::Transition::BeginRun>()),
0096       magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()),
0097       globalGeomToken_(esConsumes<edm::Transition::BeginRun>()) {
0098   produces<std::vector<Trajectory>>();
0099   produces<TrajTrackAssociationCollection>();
0100 }
0101 
0102 CSCOverlapsTrackPreparation::~CSCOverlapsTrackPreparation() {
0103   // do anything here that needs to be done at desctruction time
0104   // (e.g. close files, deallocate resources etc.)
0105 }
0106 
0107 //
0108 // member functions
0109 //
0110 
0111 // ------------ method called to produce the data  ------------
0112 void CSCOverlapsTrackPreparation::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0113   edm::Handle<reco::TrackCollection> tracks;
0114   iEvent.getByLabel(m_src, tracks);
0115 
0116   const CSCGeometry* cscGeometry = &iSetup.getData(cscGeomToken_);
0117   const MagneticField* magneticField = &iSetup.getData(magneticFieldToken_);
0118   const GlobalTrackingGeometry* globalGeometry = &iSetup.getData(globalGeomToken_);
0119 
0120   MuonTransientTrackingRecHitBuilder muonTransBuilder;
0121 
0122   // Create a collection of Trajectories, to put in the Event
0123   auto trajectoryCollection = std::make_unique<std::vector<Trajectory>>();
0124 
0125   // Remember which trajectory is associated with which track
0126   std::map<edm::Ref<std::vector<Trajectory>>::key_type, edm::Ref<reco::TrackCollection>::key_type> reference_map;
0127   edm::Ref<std::vector<Trajectory>>::key_type trajCounter = 0;
0128   edm::Ref<reco::TrackCollection>::key_type trackCounter = 0;
0129 
0130   for (reco::TrackCollection::const_iterator track = tracks->begin(); track != tracks->end(); ++track) {
0131     trackCounter++;
0132 
0133     // now we'll actually put hits on the new trajectory
0134     // these must be in lock-step
0135     edm::OwnVector<TrackingRecHit> clonedHits;
0136     std::vector<TrajectoryMeasurement::ConstRecHitPointer> transHits;
0137     std::vector<TrajectoryStateOnSurface> TSOSes;
0138 
0139     for (auto const& hit : track->recHits()) {
0140       DetId id = hit->geographicalId();
0141       if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
0142         const Surface& layerSurface = cscGeometry->idToDet(id)->surface();
0143         TrajectoryMeasurement::ConstRecHitPointer hitPtr(muonTransBuilder.build(hit, globalGeometry));
0144 
0145         AlgebraicVector5 params;  // meaningless, CSCOverlapsAlignmentAlgorithm does the fit internally
0146         params[0] = 1.;           // straight-forward direction
0147         params[1] = 0.;
0148         params[2] = 0.;
0149         params[3] = 0.;  // center of the chamber
0150         params[4] = 0.;
0151         LocalTrajectoryParameters localTrajectoryParameters(params, 1., false);
0152         LocalTrajectoryError localTrajectoryError(0.001, 0.001, 0.001, 0.001, 0.001);
0153 
0154         // these must be in lock-step
0155         clonedHits.push_back(hit->clone());
0156         transHits.push_back(hitPtr);
0157         TSOSes.push_back(
0158             TrajectoryStateOnSurface(localTrajectoryParameters, localTrajectoryError, layerSurface, &*magneticField));
0159       }  // end if CSC
0160     }    // end loop over hits
0161 
0162     assert(clonedHits.size() == transHits.size());
0163     assert(transHits.size() == TSOSes.size());
0164 
0165     // build the trajectory
0166     if (!clonedHits.empty()) {
0167       PTrajectoryStateOnDet const PTraj =
0168           trajectoryStateTransform::persistentState(*(TSOSes.begin()), clonedHits.begin()->geographicalId().rawId());
0169       TrajectorySeed trajectorySeed(PTraj, clonedHits, alongMomentum);
0170       Trajectory trajectory(trajectorySeed, alongMomentum);
0171 
0172       edm::OwnVector<TrackingRecHit>::const_iterator clonedHit = clonedHits.begin();
0173       std::vector<TrajectoryMeasurement::ConstRecHitPointer>::const_iterator transHitPtr = transHits.begin();
0174       std::vector<TrajectoryStateOnSurface>::const_iterator TSOS = TSOSes.begin();
0175       for (; clonedHit != clonedHits.end(); ++clonedHit, ++transHitPtr, ++TSOS) {
0176         trajectory.push(TrajectoryMeasurement(*TSOS, *TSOS, *TSOS, (*transHitPtr)));
0177       }
0178 
0179       trajectoryCollection->push_back(trajectory);
0180 
0181       // Remember which Trajectory is associated with which Track
0182       trajCounter++;
0183       reference_map[trajCounter] = trackCounter;
0184 
0185     }  // end if there are any clonedHits/TSOSes to work with
0186   }    // end loop over tracks
0187 
0188   unsigned int numTrajectories = trajectoryCollection->size();
0189 
0190   // insert the trajectories into the Event
0191   edm::OrphanHandle<std::vector<Trajectory>> ohTrajs = iEvent.put(std::move(trajectoryCollection));
0192 
0193   // create the trajectory <-> track association map
0194   auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
0195 
0196   for (trajCounter = 0; trajCounter < numTrajectories; trajCounter++) {
0197     edm::Ref<reco::TrackCollection>::key_type trackCounter = reference_map[trajCounter];
0198 
0199     trajTrackMap->insert(edm::Ref<std::vector<Trajectory>>(ohTrajs, trajCounter),
0200                          edm::Ref<reco::TrackCollection>(tracks, trackCounter));
0201   }
0202   // and put it in the Event, also
0203   iEvent.put(std::move(trajTrackMap));
0204 }
0205 
0206 // ------------ method called once each job just before starting event loop  ------------
0207 void CSCOverlapsTrackPreparation::beginJob() {}
0208 
0209 // ------------ method called once each job just after ending the event loop  ------------
0210 void CSCOverlapsTrackPreparation::endJob() {}
0211 
0212 //define this as a plug-in
0213 DEFINE_FWK_MODULE(CSCOverlapsTrackPreparation);