Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
/** \file RecoAnalyzerTC.cc
 *  function to get some information about the TrackCandidates
 *
 *  $Date: 2007/05/14 07:39:33 $
 *  $Revision: 1.3 $
 *  \author Maarten Thomas
 */

#include "Alignment/LaserAlignment/test/RecoAnalyzer.h"
#include "FWCore/Framework/interface/Event.h" 
#include "FWCore/Framework/interface/ESHandle.h" 
#include "FWCore/Framework/interface/EventSetup.h" 
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" 
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" 
#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h" 
#include "DataFormats/GeometryVector/interface/GlobalPoint.h" 
#include "DataFormats/DetId/interface/DetId.h" 
#include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h" 
#include "DataFormats/TrackCandidate/interface/TrackCandidate.h" 
#include "DataFormats/TrackReco/interface/Track.h" 
#include "DataFormats/TrackReco/interface/TrackFwd.h" 

void RecoAnalyzer::trackerTC(edm::Event const& theEvent, edm::EventSetup const& theSetup)
{
  // label of the source
  std::string src = "ckfTrackCandidates";
  std::string srcTracks = "ctfWithMaterialTracks";
  
  // access the tracker
  edm::ESHandle<TrackerGeometry> theTrackerGeometry;
  theSetup.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
  const TrackerGeometry& theTracker(*theTrackerGeometry);

  // get the TrackCandidate Collection
  edm::Handle<TrackCandidateCollection> theTCCollection;
  theEvent.getByLabel(src, theTCCollection );
  // get the Track Collection
  edm::Handle<reco::TrackCollection> theTrackCollection;
  theEvent.getByLabel(srcTracks, theTrackCollection);
  
  int numberOfTC = 0;

  for (TrackCandidateCollection::const_iterator i=theTCCollection->begin(); i!=theTCCollection->end();i++)
  {
    const TrackCandidate * theTC = &(*i);
    const TrackCandidate::range& recHitVec=theTC->recHits();

    std::cout << " ******* hits of TrackCandidate " << numberOfTC << " *******" << std::endl;
      // loop over the RecHits
    for (edm::OwnVector<TrackingRecHit>::const_iterator j=recHitVec.first; j!=recHitVec.second; j++)
    {    
      if ( (*j).isValid() )
      {
        GlobalPoint HitPosition = theTracker.idToDet((*j).geographicalId())->surface().toGlobal((*j).localPosition());

        std::cout << " HitPosition (x, y, z, R, phi) = " << HitPosition.x() << " " << HitPosition.y() << " " << HitPosition.z() << " " 
          << HitPosition.perp() << " " << HitPosition.phi() << std::endl;
      }
    }
    numberOfTC++;
  }

  int nTracks = 0;
  std::cout << " Number of Tracks in this event: " << theTrackCollection->size() << std::endl;
  for(auto const& track : *theTrackCollection)
  {
    nTracks++;
    std::cout << " Hits in Track " << nTracks << ": " << std::endl;
    for(auto const& hit : track->recHits())
    {
        if ( hit->isValid() )
        {
          GlobalPoint HitPosition = theTracker.idToDet(hit->geographicalId())->surface().toGlobal(hit->localPosition());

          std::cout << "   HitPosition in Track (x, y, z, R, phi) = " << HitPosition.x() << " " << HitPosition.y() << " " << HitPosition.z() << " " 
            << HitPosition.perp() << " " << HitPosition.phi() << std::endl;
        }
    }
  }

}