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
31 
32 // references
49 
52 #include "TTree.h"
53 
54 // products
57 
58 //
59 // class decleration
60 //
61 
63 public:
66 
67 private:
69 
70  void beginJob() override;
71  void produce(edm::Event&, const edm::EventSetup&) override;
72  void endJob() override;
73 
74  // ----------member data ---------------------------
76 
80 };
81 
82 //
83 // constants, enums and typedefs
84 //
85 
86 //
87 // static data member definitions
88 //
89 
90 //
91 // constructors and destructor
92 //
94  : m_src(iConfig.getParameter<edm::InputTag>("src")),
95  cscGeomToken_(esConsumes<edm::Transition::BeginRun>()),
96  magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()),
97  globalGeomToken_(esConsumes<edm::Transition::BeginRun>()) {
98  produces<std::vector<Trajectory>>();
99  produces<TrajTrackAssociationCollection>();
100 }
101 
103  // do anything here that needs to be done at desctruction time
104  // (e.g. close files, deallocate resources etc.)
105 }
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called to produce the data ------------
114  iEvent.getByLabel(m_src, tracks);
115 
116  const CSCGeometry* cscGeometry = &iSetup.getData(cscGeomToken_);
118  const GlobalTrackingGeometry* globalGeometry = &iSetup.getData(globalGeomToken_);
119 
120  MuonTransientTrackingRecHitBuilder muonTransBuilder;
121 
122  // Create a collection of Trajectories, to put in the Event
123  auto trajectoryCollection = std::make_unique<std::vector<Trajectory>>();
124 
125  // Remember which trajectory is associated with which track
126  std::map<edm::Ref<std::vector<Trajectory>>::key_type, edm::Ref<reco::TrackCollection>::key_type> reference_map;
127  edm::Ref<std::vector<Trajectory>>::key_type trajCounter = 0;
129 
130  for (reco::TrackCollection::const_iterator track = tracks->begin(); track != tracks->end(); ++track) {
131  trackCounter++;
132 
133  // now we'll actually put hits on the new trajectory
134  // these must be in lock-step
136  std::vector<TrajectoryMeasurement::ConstRecHitPointer> transHits;
137  std::vector<TrajectoryStateOnSurface> TSOSes;
138 
139  for (auto const& hit : track->recHits()) {
140  DetId id = hit->geographicalId();
141  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
142  const Surface& layerSurface = cscGeometry->idToDet(id)->surface();
143  TrajectoryMeasurement::ConstRecHitPointer hitPtr(muonTransBuilder.build(hit, globalGeometry));
144 
145  AlgebraicVector5 params; // meaningless, CSCOverlapsAlignmentAlgorithm does the fit internally
146  params[0] = 1.; // straight-forward direction
147  params[1] = 0.;
148  params[2] = 0.;
149  params[3] = 0.; // center of the chamber
150  params[4] = 0.;
151  LocalTrajectoryParameters localTrajectoryParameters(params, 1., false);
152  LocalTrajectoryError localTrajectoryError(0.001, 0.001, 0.001, 0.001, 0.001);
153 
154  // these must be in lock-step
155  clonedHits.push_back(hit->clone());
156  transHits.push_back(hitPtr);
157  TSOSes.push_back(
158  TrajectoryStateOnSurface(localTrajectoryParameters, localTrajectoryError, layerSurface, &*magneticField));
159  } // end if CSC
160  } // end loop over hits
161 
162  assert(clonedHits.size() == transHits.size());
163  assert(transHits.size() == TSOSes.size());
164 
165  // build the trajectory
166  if (!clonedHits.empty()) {
167  PTrajectoryStateOnDet const PTraj =
168  trajectoryStateTransform::persistentState(*(TSOSes.begin()), clonedHits.begin()->geographicalId().rawId());
169  TrajectorySeed trajectorySeed(PTraj, clonedHits, alongMomentum);
170  Trajectory trajectory(trajectorySeed, alongMomentum);
171 
172  edm::OwnVector<TrackingRecHit>::const_iterator clonedHit = clonedHits.begin();
173  std::vector<TrajectoryMeasurement::ConstRecHitPointer>::const_iterator transHitPtr = transHits.begin();
174  std::vector<TrajectoryStateOnSurface>::const_iterator TSOS = TSOSes.begin();
175  for (; clonedHit != clonedHits.end(); ++clonedHit, ++transHitPtr, ++TSOS) {
176  trajectory.push(TrajectoryMeasurement(*TSOS, *TSOS, *TSOS, (*transHitPtr)));
177  }
178 
179  trajectoryCollection->push_back(trajectory);
180 
181  // Remember which Trajectory is associated with which Track
182  trajCounter++;
183  reference_map[trajCounter] = trackCounter;
184 
185  } // end if there are any clonedHits/TSOSes to work with
186  } // end loop over tracks
187 
188  unsigned int numTrajectories = trajectoryCollection->size();
189 
190  // insert the trajectories into the Event
191  edm::OrphanHandle<std::vector<Trajectory>> ohTrajs = iEvent.put(std::move(trajectoryCollection));
192 
193  // create the trajectory <-> track association map
194  auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
195 
196  for (trajCounter = 0; trajCounter < numTrajectories; trajCounter++) {
197  edm::Ref<reco::TrackCollection>::key_type trackCounter = reference_map[trajCounter];
198 
199  trajTrackMap->insert(edm::Ref<std::vector<Trajectory>>(ohTrajs, trajCounter),
200  edm::Ref<reco::TrackCollection>(tracks, trackCounter));
201  }
202  // and put it in the Event, also
203  iEvent.put(std::move(trajTrackMap));
204 }
205 
206 // ------------ method called once each job just before starting event loop ------------
208 
209 // ------------ method called once each job just after ending the event loop ------------
211 
212 //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:164
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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
auto const & tracks
cannot be loose
TrackingRecHit::ConstRecHitPointer ConstRecHitPointer
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > globalGeomToken_
HLT enums.
bool empty() const
Definition: OwnVector.h:305
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
def move(src, dest)
Definition: eostools.py:511
const GeomDet * idToDet(DetId) const override
Definition: CSCGeometry.cc:91