Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:26:52

0001 
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/Frameworkfwd.h"
0004 #include "FWCore/Framework/interface/EDAnalyzer.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0014 #include "DataFormats/TrackReco/interface/Track.h"
0015 //#include "DataFormats/TrackReco/interface/print.h"
0016 
0017 #include "./PixelTrackRoot.h"
0018 using namespace std;
0019 
0020 class PixelTrackRoot : public edm::EDAnalyzer {
0021 public:
0022   explicit PixelTrackRoot(const edm::ParameterSet& conf);
0023   ~PixelTrackRoot();
0024   virtual void beginJob() { }
0025   virtual void analyze(const edm::Event& ev, const edm::EventSetup& es);
0026   virtual void endJob() { }
0027   void book();
0028   void store();
0029 private:
0030   TFile *rootfile;
0031   TTree *tthtree;
0032   int Event;
0033   static const int numMaxTrks=100;
0034   int CMNumTrk;
0035   float CMTrkVtx[numMaxTrks];
0036   float CMTrkPt[numMaxTrks];
0037   float CMTrkP[numMaxTrks];
0038   float CMTrkIP[numMaxTrks];
0039   int HPNumTrk;
0040   float HPTrkVtx[numMaxTrks];
0041   float HPTrkPt[numMaxTrks];
0042   float HPTrkP[numMaxTrks];
0043   float HPTrkIP[numMaxTrks];
0044   int SiNumTrk;
0045   float SiTrkVtx[numMaxTrks];
0046   float SiTrkPt[numMaxTrks];
0047   float SiTrkP[numMaxTrks];
0048   float SiTrkIP[numMaxTrks];
0049 };
0050 
0051 PixelTrackRoot::PixelTrackRoot(const edm::ParameterSet& conf)
0052 {
0053   rootfile = new TFile("pixel_parameters.root","RECREATE");
0054   tthtree = new TTree("T","pixTracTestCP");
0055   book();
0056   edm::LogInfo("PixelTrackRoot")<<" CTOR";
0057 }
0058 
0059 PixelTrackRoot::~PixelTrackRoot()
0060 {
0061   rootfile->cd();
0062   tthtree->Write();
0063   rootfile->Close();
0064   delete rootfile;
0065   edm::LogInfo("PixelTrackRoot")<<" DTOR";
0066 }
0067 
0068 void PixelTrackRoot::analyze(
0069     const edm::Event& ev, const edm::EventSetup& es)
0070 { 
0071   typedef reco::TrackCollection::const_iterator IT;
0072   edm::Handle<reco::TrackCollection> trackCollection1;
0073   ev.getByLabel("tracks1",trackCollection1);
0074   const reco::TrackCollection tracks1 = *(trackCollection1.product());
0075   CMNumTrk= tracks1.size();
0076   Event=ev.id().event();
0077   int i =0;
0078   for (IT it=tracks1.begin(); it!=tracks1.end(); it++){
0079 // myfillCM(*it);
0080         CMTrkP[i]=it->p();
0081         CMTrkVtx[i]=10*(it->vertex().z());
0082         CMTrkPt[i]=it->pt();
0083         CMTrkIP[i]=it->dz();
0084         i++;
0085   }
0086   i=0;
0087    edm::Handle<reco::TrackCollection> trackCollection2;
0088    ev.getByLabel("tracks2",trackCollection2);
0089    const reco::TrackCollection tracks2 = *(trackCollection2.product());
0090   HPNumTrk = tracks2.size();
0091   for (IT it=tracks2.begin(); it!=tracks2.end(); it++) {
0092 //myfillHP(*it);
0093 //   store(); 
0094         HPTrkP[i]=it->p();
0095         HPTrkVtx[i]=10*(it->vertex().z());
0096         HPTrkPt[i]=it->pt();
0097         HPTrkIP[i]=it->dz();
0098         i++;
0099     }
0100   i=0;
0101   edm::Handle<reco::TrackCollection> silTracks;
0102   ev.getByLabel("trackp",silTracks);
0103    const reco::TrackCollection SiliconTrks = *(silTracks.product());
0104 //  std::cout << "Silicon Tracks Size: "<< SiliconTrks.size()<<std::endl;
0105   SiNumTrk = SiliconTrks.size();
0106   for (IT it=SiliconTrks.begin(); it!=SiliconTrks.end(); it++) {
0107 //myfillHP(*it);
0108 //   store();
0109         SiTrkP[i]=it->p();
0110         SiTrkVtx[i]=10*(it->vertex().z());
0111         SiTrkPt[i]=it->pt();
0112         SiTrkIP[i]=it->dz();
0113         i++;
0114         }
0115 
0116 store();
0117 }
0118 void PixelTrackRoot::book()
0119 {
0120   tthtree->Branch("Event",&Event,"Event/I");
0121   tthtree->Branch("CMNumTracks", &CMNumTrk,"CMNumTrk/I");
0122   tthtree->Branch("CMTrackVtx", &CMTrkVtx,"CMTrkVtx[CMNumTrk]/F");
0123   tthtree->Branch("CMTrkPT", &CMTrkPt,"CMTrkPt[CMNumTrk]/F");
0124   tthtree->Branch("CMTrkMomentum", &CMTrkP,"CMTrkP[CMNumTrk]/F");
0125   tthtree->Branch("CMTrkImpactParam",&CMTrkIP,"CMTrkIP[CMNumTrk]/F");
0126   tthtree->Branch("HPNumTracks", &HPNumTrk,"HPNumTrk/I");
0127   tthtree->Branch("HPTrackVtx", &HPTrkVtx,"HPTrkVtx[HPNumTrk]/F");
0128   tthtree->Branch("HPTrkPT", &HPTrkPt,"HPTrkPt[HPNumTrk]/F");
0129   tthtree->Branch("HPTrkMomentum", &HPTrkP,"HPTrkP[HPNumTrk]/F");
0130   tthtree->Branch("TrkImpactParam",&HPTrkIP,"HPTrkIP[HPNumTrk]/F");
0131    tthtree->Branch("SiNumTracks", &SiNumTrk,"SiNumTrk/I");
0132   tthtree->Branch("SiTrackVtx", &SiTrkVtx,"SiTrkVtx[SiNumTrk]/F");
0133   tthtree->Branch("SiTrkPT", &SiTrkPt,"SiTrkPt[SiNumTrk]/F");
0134   tthtree->Branch("SiTrkMomentum", &SiTrkP,"SiTrkP[SiNumTrk]/F");
0135   tthtree->Branch("SiTrkImpactParam",&SiTrkIP,"SiTrkIP[SiNumTrk]/F");
0136   
0137 }
0138 
0139 void PixelTrackRoot::store(){
0140 tthtree->Fill();
0141 }
0142  
0143 DEFINE_FWK_MODULE(PixelTrackRoot);