CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PlotRecTracks.cc
Go to the documentation of this file.
5 
7 
11 
15 
21 
25 
28 
31 
34 
36 
38 
40 
41 using namespace std;
42 
43 /*****************************************************************************/
45  (const edm::EventSetup& es_, std::string trackProducer_,
46  ofstream& file_) : es(es_), trackProducer(trackProducer_), file(file_)
47 {
48  // Get tracker geometry
49  edm::ESHandle<TrackerGeometry> trackerHandle;
50  es.get<TrackerDigiGeometryRecord>().get(trackerHandle);
51  theTracker = trackerHandle.product();
52 
53  // Get magnetic field
55  es.get<IdealMagneticFieldRecord>().get(magField);
56  theMagField = magField.product();
57 
58  // Get propagator
59  edm::ESHandle<Propagator> thePropagatorHandle;
60  es.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",
61  thePropagatorHandle);
62  thePropagator = thePropagatorHandle.product();
63 
64  // KFTrajectoryFitter
65 /*
66  edm::ESHandle<TrajectoryFitter> theFitterHandle;
67  es.get<TrackingComponentsRecord>().get("KFTrajectoryFitter", theFitterHandle);
68  theFitter = theFitterHandle.product();
69 */
70 }
71 
72 /*****************************************************************************/
74 {
75 }
76 
77 /*****************************************************************************/
78 string PlotRecTracks::getPixelInfo(const TrackingRecHit* recHit, const TrackerTopology* tTopo, const ostringstream& o, const ostringstream& d)
79 {
80  const SiPixelRecHit* pixelRecHit =
81  dynamic_cast<const SiPixelRecHit *>(recHit);
82 
83  DetId id = recHit->geographicalId();
84  LocalPoint lpos = recHit->localPosition();
85  GlobalPoint p = theTracker->idToDet(id)->toGlobal(lpos);
86 
87  SiPixelRecHit::ClusterRef const& cluster = pixelRecHit->cluster();
88  std::vector<SiPixelCluster::Pixel> pixels = cluster->pixels();
89 
90  std::vector<PSimHit> simHits = theHitAssociator->associateHit(*recHit);
91 
92  std::string info = ", Text[StyleForm[\"" + o.str() + "\", URL->\"Track " + o.str()
93 + d.str();
94 
95  {
96  ostringstream o;
97  o << "simTrack (trackId=" << simHits[0].trackId()
98  << " pid=" << simHits[0].particleType()
99  << " proc=" << simHits[0].processType() << ")";
100 
101  info += " | " + o.str();
102  }
103 
104  {
105  ostringstream o;
106  o << theTracker->idToDet(id)->subDetector();
107 
108  info += " | " + o.str();
109  }
110 
111  info += HitInfo::getInfo(*recHit, tTopo);
112 
113  info += "\"]";
114 
115  {
116  ostringstream o;
117  o << ", {" << p.x() << "," << p.y() << ",(" << p.z() << "-zs)*mz},"
118  << " {" << 0 << "," << -1 << "}]";
119 
120  info += o.str();
121  }
122 
123  return info;
124 }
125 
126 /*****************************************************************************/
128  (const TrackingRecHit* recHit, const TrackerTopology* tTopo, const ostringstream& o, const ostringstream& d)
129 {
130  DetId id = recHit->geographicalId();
131  LocalPoint lpos = recHit->localPosition();
132  GlobalPoint p = theTracker->idToDet(id)->toGlobal(lpos);
133 
134  std::vector<PSimHit> simHits = theHitAssociator->associateHit(*recHit);
135 
136  std::string info = ", Text[StyleForm[\"" + o.str() + "\", URL->\"Track " + o.str() + d.str();
137  const SiStripMatchedRecHit2D* stripMatchedRecHit =
138  dynamic_cast<const SiStripMatchedRecHit2D *>(recHit);
139  const ProjectedSiStripRecHit2D* stripProjectedRecHit =
140  dynamic_cast<const ProjectedSiStripRecHit2D *>(recHit);
141  const SiStripRecHit2D* stripRecHit =
142  dynamic_cast<const SiStripRecHit2D *>(recHit);
143 
144  {
145  ostringstream o;
146  o << "simTrackId=" << simHits[0].trackId() ;
147 
148  info += " | " + o.str();
149  }
150 
151  {
152  ostringstream o;
153  o << theTracker->idToDet(id)->subDetector();
154 
155  info += " | " + o.str();
156  }
157 
158  info += HitInfo::getInfo(*recHit, tTopo);
159 
160  if(stripMatchedRecHit != 0) info += " matched";
161  if(stripProjectedRecHit != 0) info += " projected";
162  if(stripRecHit != 0) info += " single";
163 
164 
165  info += "\"]";
166 
167  {
168  ostringstream o;
169  o << ", {" << p.x() << "," << p.y() << ",(" << p.z() << "-zs)*mz},"
170  << " {" << 0 << "," << -1 << "}]";
171 
172  info += o.str();
173  }
174 
175  return info;
176 }
177 
178 /*****************************************************************************/
180  (const reco::Track& track)
181 {
182  GlobalPoint position(track.outerX(),
183  track.outerY(),
184  track.outerZ());
185 
186  GlobalVector momentum(track.outerPx(),
187  track.outerPy(),
188  track.outerPz());
189 
191  track.charge(),theMagField);
192 
193  FreeTrajectoryState fts(gtp,track.outerStateCovariance());
194 
195  return fts;
196 }
197 
198 /*****************************************************************************/
200 {
201  //Retrieve tracker topology from geometry
202  edm::ESHandle<TrackerTopology> tTopoHandle;
203  es.get<IdealGeometryRecord>().get(tTopoHandle);
204  const TrackerTopology* const tTopo = tTopoHandle.product();
205 
206  theHitAssociator = new TrackerHitAssociator(ev);
207 
208  file << ", If[rt, {AbsolutePointSize[6]";
209 
210  edm::Handle<reco::TrackCollection> recTrackHandle;
211  ev.getByLabel(trackProducer, recTrackHandle);
212 
213  edm::Handle<std::vector<Trajectory> > trajectoryHandle;
214  ev.getByLabel(trackProducer, trajectoryHandle);
215 
216  const reco::TrackCollection* recTracks = recTrackHandle.product();
217  const std::vector<Trajectory>* trajectories = trajectoryHandle.product();
218 
219  edm::LogVerbatim("MinBiasTracking")
220  << " [EventPlotter] recTracks (" << trackProducer << ") "
221  << recTracks->size();
222 
223  PlotRecHits theRecHits(es,file);
224 
225  file << ", RGBColor[0,0,0.4]";
226  reco::TrackCollection::const_iterator recTrack = recTracks->begin();
227 
228  int i = 0;
229  for(std::vector<Trajectory>::const_iterator it = trajectories->begin();
230  it!= trajectories->end();
231  it++, i++, recTrack++)
232  {
233 /*
234 cerr << " track[" << i << "] " << recTrack->chi2() << " " << it->chiSquared() << std::endl;
235 
236 */
237 //theFitter->fit(*it);
238 
239  ostringstream o; o << i;
240 
241  ostringstream d; d << fixed << std::setprecision(2)
242  << " | d0=" << recTrack->d0() << " cm"
243  << " | z0=" << recTrack->dz() << " cm"
244  << " | pt=" << recTrack->pt() << " GeV/c";
245 
246  const Trajectory* trajectory = &(*it);
247 
248  for(std::vector<TrajectoryMeasurement>::const_reverse_iterator
249  meas = trajectory->measurements().rbegin();
250  meas!= trajectory->measurements().rend(); meas++)
251  {
252  const TrackingRecHit* recHit = meas->recHit()->hit();
253 
254  if(recHit->isValid())
255  {
256  DetId id = recHit->geographicalId();
257 
258  if(theTracker->idToDet(id)->subDetector() ==
260  theTracker->idToDet(id)->subDetector() ==
262  {
263  // Pixel
264  const SiPixelRecHit* pixelRecHit =
265  dynamic_cast<const SiPixelRecHit *>(recHit);
266 
267  if(pixelRecHit != 0)
268  {
269  theRecHits.printPixelRecHit(pixelRecHit);
270  file << getPixelInfo(recHit, tTopo, o, d);
271  }
272  }
273  else
274  {
275  // Strip
276  const SiStripMatchedRecHit2D* stripMatchedRecHit =
277  dynamic_cast<const SiStripMatchedRecHit2D *>(recHit);
278  const ProjectedSiStripRecHit2D* stripProjectedRecHit =
279  dynamic_cast<const ProjectedSiStripRecHit2D *>(recHit);
280  const SiStripRecHit2D* stripRecHit =
281  dynamic_cast<const SiStripRecHit2D *>(recHit);
282 
283  if(stripMatchedRecHit != 0)
284  {
285  auto m = stripMatchedRecHit->monoHit();
286  auto s = stripMatchedRecHit->stereoHit();
287  theRecHits.printStripRecHit(&m);
288  theRecHits.printStripRecHit(&s);
289 
290  DetId id = stripMatchedRecHit->geographicalId();
291  LocalPoint lpos = stripMatchedRecHit->localPosition();
292  GlobalPoint p = theTracker->idToDet(id)->toGlobal(lpos);
293 
294  file << ", Point[{"<< p.x()<<","<<p.y()<<",("<<p.z()<<"-zs)*mz}]" << std::endl;
295  }
296 
297  if(stripProjectedRecHit != 0)
298  theRecHits.printStripRecHit(&(stripProjectedRecHit->originalHit()));
299 
300  if(stripRecHit != 0)
301  theRecHits.printStripRecHit(stripRecHit);
302 
303  if(stripMatchedRecHit != 0 ||
304  stripProjectedRecHit != 0 ||
305  stripRecHit != 0)
306  file << getStripInfo(recHit, tTopo, o,d);
307  }
308  }
309  }
310  }
311 
312  PlotUtils plotUtils;
313 
314  // Trajectory
315  recTrack = recTracks->begin();
316 
317  for(std::vector<Trajectory>::const_iterator it = trajectories->begin();
318  it!= trajectories->end();
319  it++, recTrack++)
320  {
321  int algo;
322  switch(recTrack->algo())
323  {
324  case reco::TrackBase::iter1: algo = 0; break;
325  case reco::TrackBase::iter2: algo = 1; break;
326  case reco::TrackBase::iter3: algo = 2; break;
327  default: algo = 0;
328  }
329 
330  if(algo == 0) file << ", RGBColor[1,0,0]";
331  if(algo == 1) file << ", RGBColor[0.2,0.6,0.2]";
332  if(algo == 2) file << ", RGBColor[0.2,0.2,0.6]";
333 
334  std::vector<TrajectoryMeasurement> meas = it->measurements();
335 
336  for(std::vector<TrajectoryMeasurement>::reverse_iterator im = meas.rbegin();
337  im!= meas.rend(); im++)
338  {
339  if(im == meas.rbegin())
340  {
341  GlobalPoint p2 = (*(im )).updatedState().globalPosition();
342  GlobalVector v2 = (*(im )).updatedState().globalDirection();
343  GlobalPoint p1 = GlobalPoint(recTrack->vertex().x(),
344  recTrack->vertex().y(),
345  recTrack->vertex().z());
346 
347  plotUtils.printHelix(p1,p2,v2, file, recTrack->charge());
348  }
349 
350  if(im+1 != meas.rend())
351  {
352  GlobalPoint p1 = (*(im )).updatedState().globalPosition();
353  GlobalPoint p2 = (*(im+1)).updatedState().globalPosition();
354  GlobalVector v2 = (*(im+1)).updatedState().globalDirection();
355 
356  plotUtils.printHelix(p1,p2,v2, file, recTrack->charge());
357  }
358  }
359 
360  // Ecal
361  GlobalPoint p1 = (*(meas.rend()-1)).forwardPredictedState().globalPosition();
362  FreeTrajectoryState fts = getTrajectoryAtOuterPoint(*recTrack);
365 
366  // Ecal Barrel
367  Cylinder::ConstCylinderPointer theCylinder =
368  Cylinder::build(129.f, Surface::PositionType(0.,0.,0), rot);
369  tsos = thePropagator->propagate(fts,*theCylinder);
370 
371  if(tsos.isValid() &&
372  fabs(tsos.globalPosition().z()) < 320.9)
373  {
374  GlobalPoint p2 = tsos.globalPosition();
375  GlobalVector v2 = tsos.globalDirection();
376  plotUtils.printHelix(p1,p2,v2, file, recTrack->charge());
377  }
378  else
379  {
380  // ECAL Endcap
381  Plane::ConstPlanePointer thePlanePos =
382  Plane::build(Surface::PositionType(0.,0.,320.9), rot);
383  tsos = thePropagator->propagate(fts,*thePlanePos);
384 
385  if(tsos.isValid())
386  {
387  GlobalPoint p2 = tsos.globalPosition();
388  GlobalVector v2 = tsos.globalDirection();
389  plotUtils.printHelix(p1,p2,v2, file, recTrack->charge());
390  }
391  else
392  {
393  // ECAL Endcap
394  Plane::ConstPlanePointer thePlaneNeg =
395  Plane::build(Surface::PositionType(0.,0.,-320.9), rot);
396  tsos = thePropagator->propagate(fts,*thePlaneNeg);
397 
398  if(tsos.isValid())
399  {
400  GlobalPoint p2 = tsos.globalPosition();
401  GlobalVector v2 = tsos.globalDirection();
402  plotUtils.printHelix(p1,p2,v2, file, recTrack->charge());
403  }
404  }
405  }
406  }
407 
408  file << "}]";
409 
410  delete theHitAssociator;
411 }
PlotRecTracks(const edm::EventSetup &es_, std::string trackProducer_, std::ofstream &file_)
int i
Definition: DBlmapReader.cc:9
void printHelix(const GlobalPoint &p1, const GlobalPoint &p2, const GlobalVector &n2, std::ofstream &outFile, int charge)
Definition: PlotUtils.cc:7
double outerPy() const
y coordinate of momentum vector at the outermost hit position
Definition: Track.h:73
void printRecTracks(const edm::Event &ev, const edm::EventSetup &es)
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
double outerZ() const
z coordinate of the outermost hit position
Definition: Track.h:81
DataContainer const & measurements() const
Definition: Trajectory.h:215
void printPixelRecHit(const SiPixelRecHit *recHit)
Definition: PlotRecHits.cc:35
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:51
static PlanePointer build(Args &&...args)
Definition: Plane.h:36
T z() const
Definition: PV3DBase.h:64
double f[11][100]
double outerX() const
x coordinate of the outermost hit position
Definition: Track.h:77
double p2[4]
Definition: TauolaWrapper.h:90
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
double outerPz() const
z coordinate of momentum vector at the outermost hit position
Definition: Track.h:75
void printStripRecHit(const SiStripRecHit2D *recHit)
Definition: PlotRecHits.cc:86
Definition: DetId.h:20
std::string getStripInfo(const TrackingRecHit *recHit, const TrackerTopology *tTopo, const std::ostringstream &o, const std::ostringstream &d)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
bool isValid() const
tuple simHits
Definition: trackerHits.py:16
T const * product() const
Definition: Handle.h:74
double p1[4]
Definition: TauolaWrapper.h:89
double outerY() const
y coordinate of the outermost hit position
Definition: Track.h:79
int charge() const
track electric charge
Definition: TrackBase.h:113
FreeTrajectoryState getTrajectoryAtOuterPoint(const reco::Track &track)
std::string getPixelInfo(const TrackingRecHit *recHit, const TrackerTopology *tTopo, const std::ostringstream &o, const std::ostringstream &d)
DetId geographicalId() const
static std::string getInfo(const DetId &id, const TrackerTopology *tTopo)
Definition: HitInfo.cc:25
T x() const
Definition: PV3DBase.h:62
virtual LocalPoint localPosition() const =0
const SiStripRecHit2D & originalHit() const
double outerPx() const
x coordinate of momentum vector at the outermost hit position
Definition: Track.h:71
GlobalVector globalDirection() const
Pixel Reconstructed Hit.