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 };
77 
78 //
79 // constants, enums and typedefs
80 //
81 
82 //
83 // static data member definitions
84 //
85 
86 //
87 // constructors and destructor
88 //
90  : m_src(iConfig.getParameter<edm::InputTag>("src"))
91 {
92  produces<std::vector<Trajectory> >();
93  produces<TrajTrackAssociationCollection>();
94 }
95 
96 
98 {
99  // do anything here that needs to be done at desctruction time
100  // (e.g. close files, deallocate resources etc.)
101 }
102 
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to produce the data ------------
109 void
112  iEvent.getByLabel(m_src, tracks);
113 
114  edm::ESHandle<CSCGeometry> cscGeometry;
115  iSetup.get<MuonGeometryRecord>().get(cscGeometry);
116 
118  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
119 
121  iSetup.get<GlobalTrackingGeometryRecord>().get(globalGeometry);
122 
123 
124  MuonTransientTrackingRecHitBuilder muonTransBuilder;
125 
126  // Create a collection of Trajectories, to put in the Event
127  auto trajectoryCollection = std::make_unique<std::vector<Trajectory>>();
128 
129  // Remember which trajectory is associated with which track
130  std::map<edm::Ref<std::vector<Trajectory> >::key_type, edm::Ref<reco::TrackCollection>::key_type> reference_map;
131  edm::Ref<std::vector<Trajectory> >::key_type trajCounter = 0;
133 
134  for (reco::TrackCollection::const_iterator track = tracks->begin(); track != tracks->end(); ++track) {
135  trackCounter++;
136 
137  // now we'll actually put hits on the new trajectory
138  // these must be in lock-step
140  std::vector<TrajectoryMeasurement::ConstRecHitPointer> transHits;
141  std::vector<TrajectoryStateOnSurface> TSOSes;
142 
143  for (trackingRecHit_iterator hit = track->recHitsBegin(); hit != track->recHitsEnd(); ++hit) {
144  DetId id = (*hit)->geographicalId();
145  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
146  const Surface &layerSurface = cscGeometry->idToDet(id)->surface();
147  TrajectoryMeasurement::ConstRecHitPointer hitPtr(muonTransBuilder.build(&**hit, globalGeometry));
148 
149  AlgebraicVector5 params; // meaningless, CSCOverlapsAlignmentAlgorithm does the fit internally
150  params[0] = 1.; // straight-forward direction
151  params[1] = 0.;
152  params[2] = 0.;
153  params[3] = 0.; // center of the chamber
154  params[4] = 0.;
155  LocalTrajectoryParameters localTrajectoryParameters(params, 1., false);
156  LocalTrajectoryError localTrajectoryError(0.001, 0.001, 0.001, 0.001, 0.001);
157 
158  // these must be in lock-step
159  clonedHits.push_back((*hit)->clone());
160  transHits.push_back(hitPtr);
161  TSOSes.push_back(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 = trajectoryStateTransform::persistentState(*(TSOSes.begin()), clonedHits.begin()->geographicalId().rawId());
171  TrajectorySeed trajectorySeed(PTraj, clonedHits, alongMomentum);
172  Trajectory trajectory(trajectorySeed, alongMomentum);
173 
174  edm::OwnVector<TrackingRecHit>::const_iterator clonedHit = clonedHits.begin();
175  std::vector<TrajectoryMeasurement::ConstRecHitPointer>::const_iterator transHitPtr = transHits.begin();
176  std::vector<TrajectoryStateOnSurface>::const_iterator TSOS = TSOSes.begin();
177  for (; clonedHit != clonedHits.end(); ++clonedHit, ++transHitPtr, ++TSOS) {
178  trajectory.push(TrajectoryMeasurement(*TSOS, *TSOS, *TSOS, (*transHitPtr)));
179  }
180 
181  trajectoryCollection->push_back(trajectory);
182 
183  // Remember which Trajectory is associated with which Track
184  trajCounter++;
185  reference_map[trajCounter] = trackCounter;
186 
187  } // end if there are any clonedHits/TSOSes to work with
188  } // end loop over tracks
189 
190  unsigned int numTrajectories = trajectoryCollection->size();
191 
192  // insert the trajectories into the Event
193  edm::OrphanHandle<std::vector<Trajectory> > ohTrajs = iEvent.put(std::move(trajectoryCollection));
194 
195  // create the trajectory <-> track association map
196  auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
197 
198  for (trajCounter = 0; trajCounter < numTrajectories; trajCounter++) {
199  edm::Ref<reco::TrackCollection>::key_type trackCounter = reference_map[trajCounter];
200 
201  trajTrackMap->insert(edm::Ref<std::vector<Trajectory> >(ohTrajs, trajCounter), edm::Ref<reco::TrackCollection>(tracks, trackCounter));
202  }
203  // and put it in the Event, also
204  iEvent.put(std::move(trajTrackMap));
205 }
206 
207 // ------------ method called once each job just before starting event loop ------------
209 
210 // ------------ method called once each job just after ending the event loop ------------
212 
213 //define this as a plug-in
RecHitPointer build(const TrackingRecHit *p, edm::ESHandle< GlobalTrackingGeometry > trackingGeometry) const
Call the MuonTransientTrackingRecHit::specificBuild.
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:169
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
const GeomDet * idToDet(DetId) const override
Definition: CSCGeometry.cc:99
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
size_type size() const
Definition: OwnVector.h:264
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
iterator begin()
Definition: OwnVector.h:244
void push_back(D *&d)
Definition: OwnVector.h:290
int iEvent
Definition: GenABIO.cc:230
bool empty() const
Definition: OwnVector.h:269
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
CSCOverlapsTrackPreparation(const edm::ParameterSet &)
Definition: DetId.h:18
TrajectoryStateOnSurface TSOS
Definition: TestHits.cc:19
iterator end()
Definition: OwnVector.h:249
ROOT::Math::SVector< double, 5 > AlgebraicVector5
TrackingRecHit::ConstRecHitPointer ConstRecHitPointer
HLT enums.
T get() const
Definition: EventSetup.h:63
static constexpr int CSC
Definition: MuonSubdetId.h:13
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:510