FairRoot/PandaRoot
draw_track.C
Go to the documentation of this file.
1 
2 int draw_track(TString the_RunName = "test", Bool_t do_plot = kTRUE)
3 {
4 
5  if (do_plot) {
6  cout << "--I-- Cerenkovs will be plotted." << endl;
7  } else {
8  cout << "--I-- Cerenkovs will be listed." << endl;
9  }
10 
11 
12  TString fRootFile = TString("sim_dsk.").Append(the_RunName).Append(".root");
13 
14  // libs
15  gROOT->LoadMacro("$VMCWORKDIR/gconfig/rootlogon.C");
16  gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
17  rootlogon();
18  basiclibs();
19  gSystem->Load("libDsk");
20 
21  // select trees in RootFile
22  TFile* fFile = new TFile(fRootFile); // the sim file you want to analyse
23  TTree* fTree = fFile->Get("pndsim"); // for the tracks
24 
25  fTree->SetBranchStatus("*",0);
26 
28 // TClonesArray* aryParticles = 0;
29 // aryParticles = new TClonesArray("PndDskParticle");
30 // fTree->SetBranchAddress("DskParticle",&aryParticles);
31 // fTree->SetBranchStatus("DskParticle.*",1);
32 // PndDskParticle* fParticle = 0;
33 
34  fTree->SetBranchStatus("DskCerenkov.*",1);
35  TClonesArray* aryCerenkov = 0;
36  aryCerenkov = new TClonesArray("PndDskCerenkov");
37  fTree->SetBranchAddress("DskCerenkov",&aryCerenkov);
38  PndDskCerenkov* fCerenkov = 0;
39 
40  fTree->SetBranchStatus("DskTrackPoints.*",1);
41  TClonesArray* aryTrackPoints = 0;
42  aryTrackPoints = new TClonesArray("PndDskTrackPoint");
43  fTree->SetBranchAddress("DskTrackPoints",&aryTrackPoints);
44  PndDskTrackPoint* fTrackPoint = 0;
45 
46  Int_t fNofEvents = fTree->GetEntries();
47  Int_t fStepCnt; // count the steps for a track
48 
49  Int_t const maxPos = 1000; // ommit all tracks with more steps
50  Double_t posX[maxPos];
51  Double_t posY[maxPos];
52  Double_t posZ[maxPos];
53 
54  if (do_plot) {
55  // access to GeoManager
56  TGeoManager* geoMan = (TGeoManager*) fFile->Get("FAIRGeom");
57  // draw detector
58  geoMan->GetTopVolume()->Draw("ogl");
59  }
60 
61  // for all events
62  for (Int_t ev=0; ev<=fTree->GetEntriesFast(); ev++) {
63 
64  // get entry
65  fTree->GetEntry(ev);
66 
68  if ((
69  // every event
70 // ev > -1
71  // a special event
72  ev == 0
73  )
74  ) {
76 
77  // for all cerenkovs in event
78  for (Int_t iC=0; iC<aryCerenkov->GetEntriesFast(); iC++) {
79 
80  // get the current photon
81  fCerenkov = (PndDskCerenkov*)aryCerenkov->At(iC);
83 
84  // plot all detected photons
85  if ( fCerenkov->GetDetTime() > 0. ) {
86 
87 // if ( (fCerenkov->GetDetNumber() == 4)
88 // && (fCerenkov->GetDetTime() < 3.3)
89 // ) {
90 
91 
92 // if (((
93 // (fCerenkov->GetDetTime() > 0.730)
94 // &&(fCerenkov->GetDetTime() < 0.850)
95 // ) || (
96 // (fCerenkov->GetDetTime() > 2.700)
97 // &&(fCerenkov->GetDetTime() < 2.750)
98 // ) || (
99 // (fCerenkov->GetDetTime() > 3.250)
100 // &&(fCerenkov->GetDetTime() < 3.350)
101 // )
102 // ) && (
103 // (fCerenkov->GetDetNumber() != 3)
104 // )) {
105 // if ( (fCerenkov->GetDetNumber() > 1) && (fCerenkov->GetDetNumber() < 5) && (fCerenkov->GetNofReflections() < 100) ) {
107 
108  printf("ev: %4d id: %5d time: %6.3lf det: %4d\n",
109  ev,
110  fCerenkov->GetTrackID(),
111  fCerenkov->GetDetTime(),
112  fCerenkov->GetDetNumber()
113  );
114 
115  if (do_plot) {
116  // now get all TrackPoints to the selected TrackID
117  fStepCnt = 0;
118  for (Int_t iT=0; iT<aryTrackPoints->GetEntriesFast(); iT++) {
119 
120  fTrackPoint = (PndDskTrackPoint*)aryTrackPoints->At(iT);
121  if (fStepCnt>=maxPos) {
122  cout << "id = " << fCerenkov->GetTrackID()
123  << " omitted, cause it uses more than 10000 points!"
124  << endl;
125  break;
126  }
127  if (fTrackPoint->GetTrackID() == fCerenkov->GetTrackID()) {
128  posX[fStepCnt] = fTrackPoint->GetX();
129  posY[fStepCnt] = fTrackPoint->GetY();
130  posZ[fStepCnt] = fTrackPoint->GetZ();
131  fStepCnt++;
132  }
133 
134  }
135  // and draw it
136  if (fStepCnt > 0) { // should actually always be the case as the photon exists ...
137  FairVTrack *pt = new FairVTrack(fStepCnt);
138  if (fCerenkov->GetMotherTrackID() == 0) {
139  pt->SetLineColor(kRed);
140  } else {
141  pt->SetLineColor(kBlue);
142  }
143  pt->SetLineWidth(2);
144  for (Int_t n=0; n<fStepCnt; n++){
145  pt->SetPoint(n,posX[n],posY[n],posZ[n]);
146  }
147  pt->Draw("SAME");
148  }
149  }
150  }
151  }
152  }
153  }
154  return 0;
155 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
basiclibs()
TGeoManager * geoMan
int ev
int n
int draw_track(TString the_RunName="test", Bool_t do_plot=kTRUE)
Definition: draw_track.C:2
Int_t GetDetNumber() const
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
Double_t
Double_t GetDetTime() const
Int_t GetMotherTrackID() const