1 | // ESAF : Euso Simulation and Analysis Framework |
---|
2 | // $Id: ETreeShowerPainter.cc 2924 2011-06-12 20:22:13Z mabl $ |
---|
3 | // Author: Dmitry V.Naumov Aug, 1 2004 |
---|
4 | |
---|
5 | #include "ETreeShowerPainter.hh" |
---|
6 | #include "ESystemOfUnits.hh" |
---|
7 | #include "EShower.hh" |
---|
8 | #include "EShowerStep.hh" |
---|
9 | #include "EEvent.hh" |
---|
10 | |
---|
11 | #include <TTree.h> |
---|
12 | #include <TVirtualGeoTrack.h> |
---|
13 | #include <TGeoVolume.h> |
---|
14 | #include <TGeoManager.h> |
---|
15 | #include <TGeoTube.h> |
---|
16 | #include <TH1F.h> |
---|
17 | #include <iostream> |
---|
18 | #include <TGeoMatrix.h> |
---|
19 | #include <TMath.h> |
---|
20 | |
---|
21 | ClassImp(ETreeShowerPainter) |
---|
22 | |
---|
23 | using namespace sou; |
---|
24 | |
---|
25 | //_____________________________________________________________________________ |
---|
26 | ETreeShowerPainter::ETreeShowerPainter(TTree *etree) { |
---|
27 | // |
---|
28 | // Constructor |
---|
29 | // |
---|
30 | fTree = etree; |
---|
31 | fWorldBuild = kFALSE; |
---|
32 | fCurrentTrack = 0; |
---|
33 | fEv = NULL; |
---|
34 | fHistos = new TList; |
---|
35 | Build(); |
---|
36 | } |
---|
37 | |
---|
38 | //_____________________________________________________________________________ |
---|
39 | ETreeShowerPainter::~ETreeShowerPainter() { |
---|
40 | // |
---|
41 | // Destructor |
---|
42 | // |
---|
43 | } |
---|
44 | |
---|
45 | //_____________________________________________________________________________ |
---|
46 | void ETreeShowerPainter::Build() { |
---|
47 | |
---|
48 | if ( !fTree ) { |
---|
49 | Info("Build()","ETree object is NULL. Painter made zombie."); |
---|
50 | MakeZombie(); |
---|
51 | return; |
---|
52 | } |
---|
53 | |
---|
54 | fEv = new EEvent(); |
---|
55 | fEv->SetBranches(fTree); |
---|
56 | fEvTot = (Int_t)fTree->GetEntries(); |
---|
57 | BuildWorld(); |
---|
58 | for (Int_t i=0; i< fEvTot; i++) { |
---|
59 | Printf("Entry %d: %d bytes read", i, fTree->GetEntry(i)); |
---|
60 | EShower *shower = fEv->GetShower(); |
---|
61 | AddShower(shower); |
---|
62 | FillHistos(shower); |
---|
63 | } |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | //_____________________________________________________________________________ |
---|
68 | void ETreeShowerPainter::BuildWorld() { |
---|
69 | |
---|
70 | if(fWorldBuild) return; |
---|
71 | |
---|
72 | new TGeoManager("TreeShowerViewer","Tree Shower Viewer"); |
---|
73 | |
---|
74 | TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0); |
---|
75 | fVacuum = new TGeoMedium("Vacuum", 1, matVacuum); |
---|
76 | fTop = gGeoManager->MakeBox("fTop", fVacuum, 120, 120, 40); |
---|
77 | fFoVVolume = gGeoManager->MakeTube("fFoV",fVacuum, 0,230,20); |
---|
78 | gGeoManager->SetTopVolume(fTop); |
---|
79 | fTop->AddNode(fFoVVolume, 1, new TGeoTranslation(0,0,20)); |
---|
80 | gGeoManager->SetVisLevel(1); |
---|
81 | fFoVVolume->SetLineColor(kBlue); |
---|
82 | gGeoManager->CloseGeometry(); |
---|
83 | fWorldBuild = kTRUE; |
---|
84 | } |
---|
85 | |
---|
86 | //_____________________________________________________________________________ |
---|
87 | void ETreeShowerPainter::AddShower(EShower *fShower) { |
---|
88 | Int_t track_index = gGeoManager->AddTrack(fCurrentTrack++,1); |
---|
89 | TVirtualGeoTrack *current = gGeoManager->GetTrack(track_index); |
---|
90 | Int_t n = fShower->GetNumSteps(); |
---|
91 | for (Int_t i=0; i<n; i++) { |
---|
92 | double x = (fShower->GetStep(i)->GetPosi().X() + fShower->GetStep(i)->GetPosf().X())/2/km; |
---|
93 | double y = (fShower->GetStep(i)->GetPosi().Y() + fShower->GetStep(i)->GetPosf().Y())/2/km; |
---|
94 | double z = (fShower->GetStep(i)->GetPosi().Z() + fShower->GetStep(i)->GetPosf().Z())/2/km; |
---|
95 | double t = (fShower->GetStep(i)->GetTimei() + fShower->GetStep(i)->GetTimef())/2; |
---|
96 | current->AddPoint(x,y,z,t); |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | //_____________________________________________________________________________ |
---|
101 | void ETreeShowerPainter::Draw( Option_t *opt ) { |
---|
102 | |
---|
103 | fTop->Draw(); |
---|
104 | gGeoManager->DrawTracks(); |
---|
105 | } |
---|
106 | |
---|
107 | //_____________________________________________________________________________ |
---|
108 | void ETreeShowerPainter::DrawHistos(Option_t *opt) { |
---|
109 | TString option(opt); |
---|
110 | TH1F* th = 0; |
---|
111 | if (option == "Energy") |
---|
112 | th = BuildHistos("Energy",""); |
---|
113 | else if (option == "Theta") |
---|
114 | th = BuildHistos("Theta",""); |
---|
115 | else if (option == "Phi") |
---|
116 | th = BuildHistos("Phi",""); |
---|
117 | else if (option == "X1") |
---|
118 | th = BuildHistos("X1",""); |
---|
119 | else |
---|
120 | th = NULL; |
---|
121 | th->Draw(); |
---|
122 | } |
---|
123 | //_____________________________________________________________________________ |
---|
124 | void ETreeShowerPainter::FillHistos(EShower *fShower) { |
---|
125 | TH1F *th1 = BuildHistos("Energy", "Energy Distribution"); |
---|
126 | TH1F *th2 = BuildHistos("Theta", "Theta Distribution"); |
---|
127 | TH1F *th3 = BuildHistos("Phi", "Phi Distribution"); |
---|
128 | TH1F *th4 = BuildHistos("X1", "X1 Distribution"); |
---|
129 | |
---|
130 | th1->Fill(fShower->GetEnergy()/1.e19); |
---|
131 | th2->Fill(fShower->GetTheta()*TMath::RadToDeg()); |
---|
132 | th3->Fill(fShower->GetPhi()*TMath::RadToDeg()); |
---|
133 | th4->Fill(fShower->GetX1()/g*cm2); |
---|
134 | } |
---|
135 | //_____________________________________________________________________________ |
---|
136 | TH1F* ETreeShowerPainter::BuildHistos(const char *name, const char *title) { |
---|
137 | TH1F* th = (TH1F*)fHistos->FindObject(name); |
---|
138 | |
---|
139 | TString option(name); |
---|
140 | |
---|
141 | if (!th) { |
---|
142 | if (option == "Energy") { |
---|
143 | th = new TH1F( name, title, 100,0,100); |
---|
144 | th->SetXTitle("Energy/1.e19 eV"); |
---|
145 | } |
---|
146 | if (option == "Theta") { |
---|
147 | th = new TH1F( name, title, 100,0,90); |
---|
148 | th->SetXTitle("#Theta, deg"); |
---|
149 | } |
---|
150 | if (option == "Phi") { |
---|
151 | th = new TH1F( name, title, 100,0,360); |
---|
152 | th->SetXTitle("#Phi, deg"); |
---|
153 | } |
---|
154 | if (option == "X1") { |
---|
155 | th = new TH1F( name, title, 100,0,100); |
---|
156 | th->SetXTitle("X_{1}, g/cm^{2}"); |
---|
157 | } |
---|
158 | fHistos->Add(th); |
---|
159 | } |
---|
160 | th->SetStats(0); |
---|
161 | th->SetFillColor(9); |
---|
162 | |
---|
163 | return th; |
---|
164 | } |
---|
165 | |
---|
166 | |
---|