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