Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-27 18:27:31

0001 #include <memory>
0002 
0003 #include "FWCore/Framework/interface/Frameworkfwd.h"
0004 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0005 
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 
0011 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0012 #include "DataFormats/TrackReco/interface/Track.h"
0013 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0014 
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0017 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0018 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0019 
0020 #include <iostream>
0021 #include <string>
0022 
0023 using namespace edm;
0024 
0025 class TrackAnalyzer : public edm::one::EDAnalyzer<> {
0026 public:
0027   TrackAnalyzer(const edm::ParameterSet& pset) : theGToken_(esConsumes()) {}
0028 
0029   ~TrackAnalyzer() {}
0030 
0031   virtual void analyze(const edm::Event& event, const edm::EventSetup& setup) {
0032     //
0033     // extract tracker geometry
0034     //
0035     edm::ESHandle<TrackerGeometry> theG = setup.getHandle(theGToken_);
0036 
0037     using namespace std;
0038 
0039     std::cout << "\nEvent ID = " << event.id() << std::endl;
0040 
0041     edm::Handle<reco::TrackCollection> trackCollection;
0042     event.getByLabel("ctfWithMaterialTracks", trackCollection);
0043     //event.getByType(trackCollection);
0044 
0045     const reco::TrackCollection tC = *(trackCollection.product());
0046 
0047     std::cout << "Reconstructed " << tC.size() << " tracks" << std::endl;
0048 
0049     int i = 1;
0050     for (reco::TrackCollection::const_iterator track = tC.begin(); track != tC.end(); track++) {
0051       std::cout << "Track number " << i << std::endl;
0052       std::cout << "\tmomentum: " << track->momentum() << std::endl;
0053       std::cout << "\tPT: " << track->pt() << std::endl;
0054       std::cout << "\tvertex: " << track->vertex() << std::endl;
0055       std::cout << "\timpact parameter: " << track->d0() << std::endl;
0056       std::cout << "\tcharge: " << track->charge() << std::endl;
0057       std::cout << "\tnormalizedChi2: " << track->normalizedChi2() << std::endl;
0058 
0059       i++;
0060       cout << "\tFrom EXTRA : " << endl;
0061       cout << "\t\touter PT " << track->outerPt() << endl;
0062       std::cout << "\t direction: " << track->seedDirection() << std::endl;
0063       if (!track->seedRef().isNull())
0064         std::cout << "\t direction from seedRef: " << track->seedRef()->direction() << std::endl;
0065       //
0066       // try and access Hits
0067       //
0068       cout << "\t\tNumber of RecHits " << track->recHitsSize() << endl;
0069       for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); it++) {
0070         if ((*it)->isValid()) {
0071           cout << "\t\t\tRecHit on det " << (*it)->geographicalId().rawId() << endl;
0072           cout << "\t\t\tRecHit in LP " << (*it)->localPosition() << endl;
0073           cout << "\t\t\tRecHit in GP "
0074                << theG->idToDet((*it)->geographicalId())->surface().toGlobal((*it)->localPosition()) << endl;
0075         } else {
0076           cout << "\t\t Invalid Hit On " << (*it)->geographicalId().rawId() << endl;
0077         }
0078       }
0079     }
0080   }
0081 
0082 private:
0083   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> theGToken_;
0084 };
0085 
0086 DEFINE_FWK_MODULE(TrackAnalyzer);