CMS 3D CMS Logo

CSCOverlapsTrackPreparation.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CSCOverlapsTrackPreparation
4 // Class: CSCOverlapsTrackPreparation
5 //
13 //
14 // Original Author: Jim Pivarski
15 // Created: Wed Dec 12 13:31:55 CST 2007
16 // $Id: CSCOverlapsTrackPreparation.cc,v 1.8 2011/03/22 09:49:50 innocent Exp $
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
32 
33 // references
50 
53 #include "TTree.h"
54 
55 // products
58 
59 //
60 // class decleration
61 //
62 
64 public:
66  ~CSCOverlapsTrackPreparation() override = default;
67  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
68 
69 private:
71 
72  void beginJob() override;
73  void produce(edm::Event&, const edm::EventSetup&) override;
74  void endJob() override;
75 
76  // ----------member data ---------------------------
78 
83 };
84 
85 //
86 // constants, enums and typedefs
87 //
88 
89 //
90 // static data member definitions
91 //
92 
93 //
94 // constructors and destructor
95 //
97  : m_src(iConfig.getParameter<edm::InputTag>("src")),
98  cscGeomToken_(esConsumes<edm::Transition::BeginRun>()),
99  magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()),
100  globalGeomToken_(esConsumes<edm::Transition::BeginRun>()),
101  trackToken_(consumes<reco::TrackCollection>(m_src)) {
102  produces<std::vector<Trajectory>>();
103  produces<TrajTrackAssociationCollection>();
104 }
105 
106 //
107 // member functions
108 //
111  desc.add<edm::InputTag>("src", edm::InputTag("ALCARECOMuAlBeamHaloOverlaps"));
112  descriptions.add("cscOverlapsTrackPreparation", desc);
113 }
114 
115 // ------------ method called to produce the data ------------
118 
119  const CSCGeometry* cscGeometry = &iSetup.getData(cscGeomToken_);
121  const GlobalTrackingGeometry* globalGeometry = &iSetup.getData(globalGeomToken_);
122 
123  MuonTransientTrackingRecHitBuilder muonTransBuilder;
124 
125  // Create a collection of Trajectories, to put in the Event
126  auto trajectoryCollection = std::make_unique<std::vector<Trajectory>>();
127 
128  // Remember which trajectory is associated with which track
129  std::map<edm::Ref<std::vector<Trajectory>>::key_type, edm::Ref<reco::TrackCollection>::key_type> reference_map;
130  edm::Ref<std::vector<Trajectory>>::key_type trajCounter = 0;
132 
133  for (reco::TrackCollection::const_iterator track = tracks->begin(); track != tracks->end(); ++track) {
134  trackCounter++;
135 
136  // now we'll actually put hits on the new trajectory
137  // these must be in lock-step
139  std::vector<TrajectoryMeasurement::ConstRecHitPointer> transHits;
140  std::vector<TrajectoryStateOnSurface> TSOSes;
141 
142  for (auto const& hit : track->recHits()) {
143  DetId id = hit->geographicalId();
144  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
145  const Surface& layerSurface = cscGeometry->idToDet(id)->surface();
146  TrajectoryMeasurement::ConstRecHitPointer hitPtr(muonTransBuilder.build(hit, globalGeometry));
147 
148  AlgebraicVector5 params; // meaningless, CSCOverlapsAlignmentAlgorithm does the fit internally
149  params[0] = 1.; // straight-forward direction
150  params[1] = 0.;
151  params[2] = 0.;
152  params[3] = 0.; // center of the chamber
153  params[4] = 0.;
154  LocalTrajectoryParameters localTrajectoryParameters(params, 1., false);
155  LocalTrajectoryError localTrajectoryError(0.001, 0.001, 0.001, 0.001, 0.001);
156 
157  // these must be in lock-step
158  clonedHits.push_back(hit->clone());
159  transHits.push_back(hitPtr);
160  TSOSes.push_back(
161  TrajectoryStateOnSurface(localTrajectoryParameters, localTrajectoryError, layerSurface, &*magneticField));
162  } // end if CSC
163  } // end loop over hits
164 
165  assert(clonedHits.size() == transHits.size());
166  assert(transHits.size() == TSOSes.size());
167 
168  // build the trajectory
169  if (!clonedHits.empty()) {
170  PTrajectoryStateOnDet const PTraj =
171  trajectoryStateTransform::persistentState(*(TSOSes.begin()), clonedHits.begin()->geographicalId().rawId());
172  TrajectorySeed trajectorySeed(PTraj, clonedHits, alongMomentum);
173  Trajectory trajectory(trajectorySeed, alongMomentum);
174 
175  edm::OwnVector<TrackingRecHit>::const_iterator clonedHit = clonedHits.begin();
176  std::vector<TrajectoryMeasurement::ConstRecHitPointer>::const_iterator transHitPtr = transHits.begin();
177  std::vector<TrajectoryStateOnSurface>::const_iterator TSOS = TSOSes.begin();
178  for (; clonedHit != clonedHits.end(); ++clonedHit, ++transHitPtr, ++TSOS) {
179  trajectory.push(TrajectoryMeasurement(*TSOS, *TSOS, *TSOS, (*transHitPtr)));
180  }
181 
182  trajectoryCollection->push_back(trajectory);
183 
184  // Remember which Trajectory is associated with which Track
185  trajCounter++;
186  reference_map[trajCounter] = trackCounter;
187 
188  } // end if there are any clonedHits/TSOSes to work with
189  } // end loop over tracks
190 
191  unsigned int numTrajectories = trajectoryCollection->size();
192 
193  // insert the trajectories into the Event
194  edm::OrphanHandle<std::vector<Trajectory>> ohTrajs = iEvent.put(std::move(trajectoryCollection));
195 
196  // create the trajectory <-> track association map
197  auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
198 
199  for (trajCounter = 0; trajCounter < numTrajectories; trajCounter++) {
200  edm::Ref<reco::TrackCollection>::key_type trackCounter = reference_map[trajCounter];
201 
202  trajTrackMap->insert(edm::Ref<std::vector<Trajectory>>(ohTrajs, trajCounter),
203  edm::Ref<reco::TrackCollection>(tracks, trackCounter));
204  }
205  // and put it in the Event, also
206  iEvent.put(std::move(trajTrackMap));
207 }
208 
209 // ------------ method called once each job just before starting event loop ------------
211 
212 // ------------ method called once each job just after ending the event loop ------------
214 
215 //define this as a plug-in
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:158
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
const edm::ESGetToken< CSCGeometry, MuonGeometryRecord > cscGeomToken_
assert(be >=bs)
iterator begin()
Definition: OwnVector.h:280
RecHitPointer build(const TrackingRecHit *p, edm::ESHandle< GlobalTrackingGeometry > trackingGeometry) const
Call the MuonTransientTrackingRecHit::specificBuild.
void push_back(D *&d)
Definition: OwnVector.h:326
int iEvent
Definition: GenABIO.cc:224
size_type size() const
Definition: OwnVector.h:300
ROOT::Math::SVector< double, 5 > AlgebraicVector5
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
CSCOverlapsTrackPreparation(const edm::ParameterSet &)
Definition: DetId.h:17
TrajectoryStateOnSurface TSOS
Definition: TestHits.cc:19
iterator end()
Definition: OwnVector.h:285
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TrackingRecHit::ConstRecHitPointer ConstRecHitPointer
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > globalGeomToken_
fixed size matrix
HLT enums.
bool empty() const
Definition: OwnVector.h:305
const edm::EDGetTokenT< reco::TrackCollection > trackToken_
static constexpr int CSC
Definition: MuonSubdetId.h:12
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
void produce(edm::Event &, const edm::EventSetup &) override
~CSCOverlapsTrackPreparation() override=default
def move(src, dest)
Definition: eostools.py:511
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const GeomDet * idToDet(DetId) const override
Definition: CSCGeometry.cc:91