File indexing completed on 2025-01-18 09:14:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include "MyTrackerHit.h"
0014 #include <TFile.h>
0015 #include <TBranch.h>
0016 #include <TTree.h>
0017
0018 #include <iostream>
0019 #include <vector>
0020 #include <cerrno>
0021
0022 using namespace std;
0023
0024 namespace SomeExperiment {
0025
0026 void dump_branch(int num_evts, TBranch* b) {
0027 typedef vector<dd4hep::sim::Geant4Tracker::Hit*> TrHits;
0028 int num_evt;
0029 num_evt = b->GetEntries();
0030 if ( num_evt > 0 ) {
0031 TrHits* hits = new TrHits();
0032 b->SetAddress(&hits);
0033 for(int ievt=0; ievt<num_evts; ++ievt ) {
0034 int nbyte = b->GetEntry(ievt);
0035 if ( nbyte > 0 ) {
0036 cout << "Tracker hits: " << nbyte << " bytes " << hits->size() << endl;
0037 for(size_t i=0; i<min(hits->size(),10UL); ++i) {
0038 MyTrackerHit* hit = (MyTrackerHit*)hits->at(i);
0039 cout << b->GetName() << " Event " << ievt
0040 << " Hit " << (int)i
0041 << " type: " << typeid(*hit).name()
0042 << " deposit:" << hit->energyDeposit
0043 << " step-len:" << hit->step_length
0044 << " prePos:" << hit->prePos
0045 << " postPos:" << hit->postPos
0046 << endl;
0047 }
0048 }
0049 else {
0050 cout << b->GetName() << " Event " << ievt << " NO DATA." << endl;
0051 }
0052 }
0053 }
0054 }
0055
0056
0057 int Dump::dumpData(int num_evts, const char* file_name) {
0058 if ( !file_name ) {
0059 cout << "Illegal file name: Input file cannot be opened!" << endl;
0060 return ENOENT;
0061 }
0062 TFile* f = TFile::Open(file_name);
0063 if ( !f ) {
0064 cout << "File " << file_name << " cannot be opened!" << endl;
0065 return ENOENT;
0066 }
0067 TTree* t = (TTree*)f->Get("EVENT");
0068 if ( !t ) {
0069 f->Close();
0070 cout << "File " << file_name << " cannot be read!" << endl;
0071 cout << "No branch with name EVENT!" << endl;
0072 return ENOENT;
0073 }
0074 t->Print();
0075 dump_branch(num_evts,t->GetBranch("SiliconDownHits"));
0076 dump_branch(num_evts,t->GetBranch("SiliconUpperHits"));
0077 f->Close();
0078 delete f;
0079 return 0;
0080 }
0081 }
0082
0083