CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

PlotRecTracks Class Reference

#include <PlotRecTracks.h>

List of all members.

Public Member Functions

 PlotRecTracks (const edm::EventSetup &es_, std::string trackProducer_, std::ofstream &file_)
void printRecTracks (const edm::Event &ev)
 ~PlotRecTracks ()

Private Member Functions

std::string getPixelInfo (const TrackingRecHit *recHit, const std::ostringstream &o, const std::ostringstream &d)
std::string getStripInfo (const TrackingRecHit *recHit, const std::ostringstream &o, const std::ostringstream &d)
FreeTrajectoryState getTrajectoryAtOuterPoint (const reco::Track &track)

Private Attributes

const edm::EventSetupes
std::ofstream & file
const TrajectoryFittertheFitter
TrackerHitAssociatortheHitAssociator
const MagneticFieldtheMagField
const PropagatorthePropagator
const TrackerGeometrytheTracker
std::string trackProducer

Detailed Description

Definition at line 19 of file PlotRecTracks.h.


Constructor & Destructor Documentation

PlotRecTracks::PlotRecTracks ( const edm::EventSetup es_,
std::string  trackProducer_,
std::ofstream &  file_ 
) [explicit]

Definition at line 48 of file PlotRecTracks.cc.

References edm::ESHandle< T >::product().

                    : es(es_), trackProducer(trackProducer_), file(file_)
{
  // Get tracker geometry
  edm::ESHandle<TrackerGeometry> trackerHandle;
  es.get<TrackerDigiGeometryRecord>().get(trackerHandle);
  theTracker = trackerHandle.product();

  // Get magnetic field
  edm::ESHandle<MagneticField> magField;
  es.get<IdealMagneticFieldRecord>().get(magField);
  theMagField = magField.product();

  // Get propagator
  edm::ESHandle<Propagator> thePropagatorHandle;
  es.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",
                                          thePropagatorHandle);
  thePropagator = thePropagatorHandle.product();

  // KFTrajectoryFitter
/*
  edm::ESHandle<TrajectoryFitter> theFitterHandle;
  es.get<TrackingComponentsRecord>().get("KFTrajectoryFitter", theFitterHandle);
  theFitter = theFitterHandle.product();
*/
}
PlotRecTracks::~PlotRecTracks ( )

Definition at line 76 of file PlotRecTracks.cc.

{
}

Member Function Documentation

string PlotRecTracks::getPixelInfo ( const TrackingRecHit recHit,
const std::ostringstream &  o,
const std::ostringstream &  d 
) [private]

Definition at line 82 of file PlotRecTracks.cc.

References TrackingRecHit::geographicalId(), HitInfo::getInfo(), info, TrackingRecHit::localPosition(), python::connectstrParser::o, AlCaHLTBitMon_ParallelJobs::p, trackerHits::simHits, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

{
  const SiPixelRecHit* pixelRecHit =
    dynamic_cast<const SiPixelRecHit *>(recHit);

  DetId id = recHit->geographicalId();
  LocalPoint lpos = recHit->localPosition();
  GlobalPoint p = theTracker->idToDet(id)->toGlobal(lpos);

  SiPixelRecHit::ClusterRef const& cluster = pixelRecHit->cluster();
  std::vector<SiPixelCluster::Pixel> pixels = cluster->pixels();

  std::vector<PSimHit> simHits = theHitAssociator->associateHit(*recHit);

  std::string info = ", Text[StyleForm[\"" + o.str() + "\", URL->\"Track " + o.str()
+ d.str();

  {
  ostringstream o;
  o << "simTrack (trackId=" << simHits[0].trackId()
                 << " pid=" << simHits[0].particleType()
                << " proc=" << simHits[0].processType() << ")";

  info += " | " + o.str();
  }

  {
  ostringstream o;
  o << theTracker->idToDet(id)->subDetector();

  info += " | " + o.str();
  }

  info += HitInfo::getInfo(*recHit);

  info += "\"]";

  {
  ostringstream o;
  o << ", {" << p.x() << "," << p.y() << ",(" << p.z() << "-zs)*mz},"
    << " {" << 0 << "," << -1 << "}]";

  info += o.str();
  }

  return info;
}
string PlotRecTracks::getStripInfo ( const TrackingRecHit recHit,
const std::ostringstream &  o,
const std::ostringstream &  d 
) [private]

Definition at line 132 of file PlotRecTracks.cc.

References TrackingRecHit::geographicalId(), HitInfo::getInfo(), info, TrackingRecHit::localPosition(), python::connectstrParser::o, AlCaHLTBitMon_ParallelJobs::p, trackerHits::simHits, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

{
  DetId id = recHit->geographicalId();
  LocalPoint lpos = recHit->localPosition();
  GlobalPoint p = theTracker->idToDet(id)->toGlobal(lpos);

  std::vector<PSimHit> simHits = theHitAssociator->associateHit(*recHit);

  std::string info = ", Text[StyleForm[\"" + o.str() + "\", URL->\"Track " + o.str() + d.str(); 
  const SiStripMatchedRecHit2D* stripMatchedRecHit =
    dynamic_cast<const SiStripMatchedRecHit2D *>(recHit);
  const ProjectedSiStripRecHit2D* stripProjectedRecHit =
    dynamic_cast<const ProjectedSiStripRecHit2D *>(recHit);
  const SiStripRecHit2D* stripRecHit =
    dynamic_cast<const SiStripRecHit2D *>(recHit);

  {
  ostringstream o;
  o << "simTrackId=" << simHits[0].trackId() ;

  info += " | " + o.str();
  }

  {
  ostringstream o;
  o << theTracker->idToDet(id)->subDetector();

  info += " | " + o.str();
  }

  info += HitInfo::getInfo(*recHit);

  if(stripMatchedRecHit != 0)   info += " matched";
  if(stripProjectedRecHit != 0) info += " projected";
  if(stripRecHit != 0)          info += " single";
  
  
  info += "\"]";

  {
  ostringstream o;
  o << ", {" << p.x() << "," << p.y() << ",(" << p.z() << "-zs)*mz},"
    << " {" << 0 << "," << -1 << "}]";

  info += o.str();
  }

  return info;
}
FreeTrajectoryState PlotRecTracks::getTrajectoryAtOuterPoint ( const reco::Track track) [private]
void PlotRecTracks::printRecTracks ( const edm::Event ev)

Definition at line 203 of file PlotRecTracks.cc.

References newFWLiteAna::build, mergeVDriftHistosByStation::file, TrackingRecHit::geographicalId(), edm::Event::getByLabel(), TrajectoryStateOnSurface::globalDirection(), TrajectoryStateOnSurface::globalPosition(), i, TrackingRecHit::isValid(), TrajectoryStateOnSurface::isValid(), reco::TrackBase::iter1, reco::TrackBase::iter2, reco::TrackBase::iter3, m, Trajectory::measurements(), python::connectstrParser::o, ProjectedSiStripRecHit2D::originalHit(), AlCaHLTBitMon_ParallelJobs::p, p1, p2, GeomDetEnumerators::PixelBarrel, GeomDetEnumerators::PixelEndcap, PlotUtils::printHelix(), PlotRecHits::printPixelRecHit(), PlotRecHits::printStripRecHit(), edm::Handle< T >::product(), makeMuonMisalignmentScenario::rot, alignCSCRings::s, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

{
  theHitAssociator = new TrackerHitAssociator(ev);

  file << ", If[rt, {AbsolutePointSize[6]";

  edm::Handle<reco::TrackCollection> recTrackHandle;
  ev.getByLabel(trackProducer, recTrackHandle);

  edm::Handle<std::vector<Trajectory> > trajectoryHandle;
  ev.getByLabel(trackProducer, trajectoryHandle);

  const reco::TrackCollection* recTracks    =   recTrackHandle.product();
  const std::vector<Trajectory>*    trajectories = trajectoryHandle.product(); 

  edm::LogVerbatim("MinBiasTracking") 
       << " [EventPlotter] recTracks (" << trackProducer << ") "
       << recTracks->size();

  PlotRecHits theRecHits(es,file);

  file << ", RGBColor[0,0,0.4]";
  reco::TrackCollection::const_iterator recTrack = recTracks->begin();

  int i = 0;
  for(std::vector<Trajectory>::const_iterator it = trajectories->begin();
                                         it!= trajectories->end();
                                         it++, i++, recTrack++)
  {
/*
cerr << " track[" << i << "] " << recTrack->chi2() << " " << it->chiSquared() << std::endl;

*/
//theFitter->fit(*it);

    ostringstream o; o << i;

    ostringstream d; d << fixed << std::setprecision(2)
                       << " | d0=" << recTrack->d0() << " cm"
                       << " | z0=" << recTrack->dz() << " cm"
                       << " | pt=" << recTrack->pt() << " GeV/c";

    const Trajectory* trajectory = &(*it);

    for(std::vector<TrajectoryMeasurement>::const_reverse_iterator
        meas = trajectory->measurements().rbegin();
        meas!= trajectory->measurements().rend(); meas++)
    {
    const TrackingRecHit* recHit = meas->recHit()->hit();

    if(recHit->isValid())
    {
      DetId id = recHit->geographicalId();

      if(theTracker->idToDet(id)->subDetector() ==
           GeomDetEnumerators::PixelBarrel ||
         theTracker->idToDet(id)->subDetector() ==
           GeomDetEnumerators::PixelEndcap)
      {
        // Pixel
        const SiPixelRecHit* pixelRecHit =
          dynamic_cast<const SiPixelRecHit *>(recHit);

        if(pixelRecHit != 0)
        {
          theRecHits.printPixelRecHit(pixelRecHit);
          file << getPixelInfo(recHit, o,d);
        }
      }
      else
      {
        // Strip
        const SiStripMatchedRecHit2D* stripMatchedRecHit =
          dynamic_cast<const SiStripMatchedRecHit2D *>(recHit);
        const ProjectedSiStripRecHit2D* stripProjectedRecHit =
          dynamic_cast<const ProjectedSiStripRecHit2D *>(recHit);
        const SiStripRecHit2D* stripRecHit =
          dynamic_cast<const SiStripRecHit2D *>(recHit);

        if(stripMatchedRecHit != 0)
        {
          auto m = stripMatchedRecHit->monoHit();
          auto s = stripMatchedRecHit->stereoHit();
          theRecHits.printStripRecHit(&m);
          theRecHits.printStripRecHit(&s);

          DetId id = stripMatchedRecHit->geographicalId();
          LocalPoint lpos = stripMatchedRecHit->localPosition();
          GlobalPoint p = theTracker->idToDet(id)->toGlobal(lpos);

          file << ", Point[{"<< p.x()<<","<<p.y()<<",("<<p.z()<<"-zs)*mz}]" << std::endl;
        }

        if(stripProjectedRecHit != 0)
          theRecHits.printStripRecHit(&(stripProjectedRecHit->originalHit()));

        if(stripRecHit != 0)
          theRecHits.printStripRecHit(stripRecHit);

        if(stripMatchedRecHit != 0 ||
           stripProjectedRecHit != 0 ||
           stripRecHit != 0)
          file << getStripInfo(recHit, o,d);
      }
      }
    }
  }

  PlotUtils plotUtils;

  // Trajectory
  recTrack = recTracks->begin();

  for(std::vector<Trajectory>::const_iterator it = trajectories->begin();
                                         it!= trajectories->end();
                                         it++, recTrack++)
  {
    int algo;
    switch(recTrack->algo())
    {
      case reco::TrackBase::iter1: algo = 0; break;
      case reco::TrackBase::iter2: algo = 1; break;
      case reco::TrackBase::iter3: algo = 2; break;
      default: algo = 0;
    }

    if(algo == 0) file << ", RGBColor[1,0,0]";
    if(algo == 1) file << ", RGBColor[0.2,0.6,0.2]";
    if(algo == 2) file << ", RGBColor[0.2,0.2,0.6]";

    std::vector<TrajectoryMeasurement> meas = it->measurements();

    for(std::vector<TrajectoryMeasurement>::reverse_iterator im = meas.rbegin();
                                                        im!= meas.rend(); im++)
    {
      if(im == meas.rbegin())
      {
        GlobalPoint  p2 = (*(im  )).updatedState().globalPosition();
        GlobalVector v2 = (*(im  )).updatedState().globalDirection();
        GlobalPoint  p1 = GlobalPoint(recTrack->vertex().x(),
                                      recTrack->vertex().y(),
                                      recTrack->vertex().z());

        plotUtils.printHelix(p1,p2,v2, file, recTrack->charge());
      }

      if(im+1 != meas.rend())
      {
        GlobalPoint  p1 = (*(im  )).updatedState().globalPosition();
        GlobalPoint  p2 = (*(im+1)).updatedState().globalPosition();
        GlobalVector v2 = (*(im+1)).updatedState().globalDirection();

        plotUtils.printHelix(p1,p2,v2, file, recTrack->charge());
      }
    }

    // Ecal
    GlobalPoint p1 = (*(meas.rend()-1)).forwardPredictedState().globalPosition();
    FreeTrajectoryState fts = getTrajectoryAtOuterPoint(*recTrack);
    Surface::RotationType rot;
    TrajectoryStateOnSurface tsos;

    // Ecal Barrel
    Cylinder::ConstCylinderPointer theCylinder =
        Cylinder::build(Surface::PositionType(0.,0.,0), rot, 129.);
    tsos = thePropagator->propagate(fts,*theCylinder);

    if(tsos.isValid() &&
       fabs(tsos.globalPosition().z()) < 320.9)
    {
      GlobalPoint  p2 = tsos.globalPosition();
      GlobalVector v2 = tsos.globalDirection();
      plotUtils.printHelix(p1,p2,v2, file, recTrack->charge());
    }
    else
    { 
      // ECAL Endcap
      Plane::ConstPlanePointer thePlanePos =
          Plane::build(Surface::PositionType(0.,0.,320.9), rot);
      tsos = thePropagator->propagate(fts,*thePlanePos);
  
      if(tsos.isValid())
      {
        GlobalPoint  p2 = tsos.globalPosition();
        GlobalVector v2 = tsos.globalDirection();
        plotUtils.printHelix(p1,p2,v2, file, recTrack->charge());
      }
      else
      {
        // ECAL Endcap
        Plane::ConstPlanePointer thePlaneNeg =
            Plane::build(Surface::PositionType(0.,0.,-320.9), rot);
        tsos = thePropagator->propagate(fts,*thePlaneNeg);

        if(tsos.isValid())
        {
          GlobalPoint  p2 = tsos.globalPosition();
          GlobalVector v2 = tsos.globalDirection();
          plotUtils.printHelix(p1,p2,v2, file, recTrack->charge());
        }
      }
    }
  }

  file << "}]";

  delete theHitAssociator;
}

Member Data Documentation

Definition at line 36 of file PlotRecTracks.h.

std::ofstream& PlotRecTracks::file [private]

Definition at line 38 of file PlotRecTracks.h.

Definition at line 43 of file PlotRecTracks.h.

Definition at line 45 of file PlotRecTracks.h.

Definition at line 41 of file PlotRecTracks.h.

Definition at line 42 of file PlotRecTracks.h.

Definition at line 40 of file PlotRecTracks.h.

std::string PlotRecTracks::trackProducer [private]

Definition at line 37 of file PlotRecTracks.h.