Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-01 03:29:18

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