Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-31 23:02:27

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 
0030 private:
0031   TFile* rootfile;
0032   TTree* tthtree;
0033   int Event;
0034   static const int numMaxTrks = 100;
0035   int CMNumTrk;
0036   float CMTrkVtx[numMaxTrks];
0037   float CMTrkPt[numMaxTrks];
0038   float CMTrkP[numMaxTrks];
0039   float CMTrkIP[numMaxTrks];
0040   int HPNumTrk;
0041   float HPTrkVtx[numMaxTrks];
0042   float HPTrkPt[numMaxTrks];
0043   float HPTrkP[numMaxTrks];
0044   float HPTrkIP[numMaxTrks];
0045   int SiNumTrk;
0046   float SiTrkVtx[numMaxTrks];
0047   float SiTrkPt[numMaxTrks];
0048   float SiTrkP[numMaxTrks];
0049   float SiTrkIP[numMaxTrks];
0050 };
0051 
0052 PixelTrackRoot::PixelTrackRoot(const edm::ParameterSet& conf) {
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   rootfile->cd();
0061   tthtree->Write();
0062   rootfile->Close();
0063   delete rootfile;
0064   edm::LogInfo("PixelTrackRoot") << " DTOR";
0065 }
0066 
0067 void PixelTrackRoot::analyze(const edm::Event& ev, const edm::EventSetup& es) {
0068   typedef reco::TrackCollection::const_iterator IT;
0069   edm::Handle<reco::TrackCollection> trackCollection1;
0070   ev.getByLabel("tracks1", trackCollection1);
0071   const reco::TrackCollection tracks1 = *(trackCollection1.product());
0072   CMNumTrk = tracks1.size();
0073   Event = ev.id().event();
0074   int i = 0;
0075   for (IT it = tracks1.begin(); it != tracks1.end(); it++) {
0076     // myfillCM(*it);
0077     CMTrkP[i] = it->p();
0078     CMTrkVtx[i] = 10 * (it->vertex().z());
0079     CMTrkPt[i] = it->pt();
0080     CMTrkIP[i] = it->dz();
0081     i++;
0082   }
0083   i = 0;
0084   edm::Handle<reco::TrackCollection> trackCollection2;
0085   ev.getByLabel("tracks2", trackCollection2);
0086   const reco::TrackCollection tracks2 = *(trackCollection2.product());
0087   HPNumTrk = tracks2.size();
0088   for (IT it = tracks2.begin(); it != tracks2.end(); it++) {
0089     //myfillHP(*it);
0090     //   store();
0091     HPTrkP[i] = it->p();
0092     HPTrkVtx[i] = 10 * (it->vertex().z());
0093     HPTrkPt[i] = it->pt();
0094     HPTrkIP[i] = it->dz();
0095     i++;
0096   }
0097   i = 0;
0098   edm::Handle<reco::TrackCollection> silTracks;
0099   ev.getByLabel("trackp", silTracks);
0100   const reco::TrackCollection SiliconTrks = *(silTracks.product());
0101   //  std::cout << "Silicon Tracks Size: "<< SiliconTrks.size()<<std::endl;
0102   SiNumTrk = SiliconTrks.size();
0103   for (IT it = SiliconTrks.begin(); it != SiliconTrks.end(); it++) {
0104     //myfillHP(*it);
0105     //   store();
0106     SiTrkP[i] = it->p();
0107     SiTrkVtx[i] = 10 * (it->vertex().z());
0108     SiTrkPt[i] = it->pt();
0109     SiTrkIP[i] = it->dz();
0110     i++;
0111   }
0112 
0113   store();
0114 }
0115 void PixelTrackRoot::book() {
0116   tthtree->Branch("Event", &Event, "Event/I");
0117   tthtree->Branch("CMNumTracks", &CMNumTrk, "CMNumTrk/I");
0118   tthtree->Branch("CMTrackVtx", &CMTrkVtx, "CMTrkVtx[CMNumTrk]/F");
0119   tthtree->Branch("CMTrkPT", &CMTrkPt, "CMTrkPt[CMNumTrk]/F");
0120   tthtree->Branch("CMTrkMomentum", &CMTrkP, "CMTrkP[CMNumTrk]/F");
0121   tthtree->Branch("CMTrkImpactParam", &CMTrkIP, "CMTrkIP[CMNumTrk]/F");
0122   tthtree->Branch("HPNumTracks", &HPNumTrk, "HPNumTrk/I");
0123   tthtree->Branch("HPTrackVtx", &HPTrkVtx, "HPTrkVtx[HPNumTrk]/F");
0124   tthtree->Branch("HPTrkPT", &HPTrkPt, "HPTrkPt[HPNumTrk]/F");
0125   tthtree->Branch("HPTrkMomentum", &HPTrkP, "HPTrkP[HPNumTrk]/F");
0126   tthtree->Branch("TrkImpactParam", &HPTrkIP, "HPTrkIP[HPNumTrk]/F");
0127   tthtree->Branch("SiNumTracks", &SiNumTrk, "SiNumTrk/I");
0128   tthtree->Branch("SiTrackVtx", &SiTrkVtx, "SiTrkVtx[SiNumTrk]/F");
0129   tthtree->Branch("SiTrkPT", &SiTrkPt, "SiTrkPt[SiNumTrk]/F");
0130   tthtree->Branch("SiTrkMomentum", &SiTrkP, "SiTrkP[SiNumTrk]/F");
0131   tthtree->Branch("SiTrkImpactParam", &SiTrkIP, "SiTrkIP[SiNumTrk]/F");
0132 }
0133 
0134 void PixelTrackRoot::store() { tthtree->Fill(); }
0135 
0136 DEFINE_FWK_MODULE(PixelTrackRoot);