]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/macro/hits.C
update for changes in Config.C
[u/mrichter/AliRoot.git] / AliGeant4 / macro / hits.C
CommitLineData
ab99804f 1// $Id$
2
3#include <iostream.h>
4
5void hits()
6{
7 hits("FMD","1");
8 hits("ITS","5");
9 hits("MUON","0");
10 hits("PMD","0");
11 hits("START","0");
12 hits("TOF","0");
13 hits("TPC","1");
14 hits("PHOS","1");
15}
16
17void hits(const TString& detName, const TString& detVersion)
18{
19 // labels
20 TString g3 = "G3: ";
21 TString g4 = "G4: ";
22
23 // construct file names
24 TString top = getenv("ALICE_ROOT");
25 TString f1NameEnd = "test10.root";
26 TString f2NameEnd = "test20.root";
27 TString g3File1Name = top + "/test/" + f1NameEnd;
28 TString g3File2Name = top + "/test/" + f2NameEnd;
29 TString g4File1Name = top + "/AliGeant4/test/" + f1NameEnd;
30 TString g4File2Name = top + "/AliGeant4/test/" + f2NameEnd;
31
32 cout << "Files: " << endl;
33 cout << g3File1Name << endl;
34 cout << g3File2Name << endl;
35 cout << g4File1Name << endl;
36 cout << g4File2Name << endl;
37
38 // link shared libs
39 if (gClassTable->GetID("AliRun") < 0) {
40 gROOT->LoadMacro("loadlibs.C");
41 loadlibs();
42 }
43 cout << "AliRoot libraries were loaded." << endl;
44
45 // set histogram ranges
46 Int_t nbin;
47 Int_t g3xmin; Int_t g4xmin; Int_t g3xmax; Int_t g4xmax;
48 Int_t g3ymin; Int_t g4ymin; Int_t g3ymax; Int_t g4ymax;
49 Int_t g3zmin; Int_t g4zmin; Int_t g3zmax; Int_t g4zmax;
50 SetHistogramRanges(detName, nbin,
51 g3xmin, g3xmax, g4xmin, g4xmax,
52 g3ymin, g3ymax, g4ymin, g4ymax,
53 g3zmin, g3zmax, g4zmin, g4zmax);
54
55
56 // create histograms
57 TH1F* g3x = new TH1F("g3x", g3 + detName + " hits per x", nbin, g3xmin, g3xmax);
58 TH1F* g3xh = new TH1F("g3xh", g3 + detName + " hits per x", nbin, g3xmin, g3xmax);
59 TH1F* g4x = new TH1F("g4x", g4 + detName + " hits per x", nbin, g4xmin, g4xmax);
60 TH1F* g4xh = new TH1F("g4xh", g4 + detName + " hits per x", nbin, g4xmin, g4xmax);
61
62 TH1F* g3z = new TH1F("g3z", g3 + detName + " hits per z", nbin, g3zmin, g3zmax);
63 TH1F* g3zh = new TH1F("g3zh", g3 + detName + " hits per z", nbin, g3zmin, g3zmax);
64 TH1F* g4z = new TH1F("g4z", g4 + detName + " hits per z", nbin, g4zmin, g4zmax);
65 TH1F* g4zh = new TH1F("g4zh", g4 + detName + " hits per z", nbin, g4zmin, g4zmax);
66
67 TH1F* g3y = 0;
68 TH1F* g3yh = 0;
69 TH1F* g4y = 0;
70 TH1F* g4yh = 0;
71 if (detName == "PHOS") {
72 TH1F* g3y = new TH1F("g3y", g3 + detName + " hits per y", nbin, g3ymin, g3ymax);
73 TH1F* g3yh = new TH1F("g3yh", g3 + detName + " hits per y", nbin, g3ymin, g3ymax);
74 TH1F* g4y = new TH1F("g4y", g4 + detName + " hits per y", nbin, g4ymin, g4ymax);
75 TH1F* g4yh = new TH1F("g4yh", g4 + detName + " hits per y", nbin, g4ymin, g4ymax);
76 }
77
78 cout << "Histograms were created." << endl;
79
80 // fill histograms
81 AliDetector* detector;
82
f2b0ecac 83 //detector = LoadDetector(g3File1Name, detName, g3);
84 //FillHistogram(detector, g3, g3x, g3y, g3z);
ab99804f 85
f2b0ecac 86 //detector = LoadDetector(g3File2Name, detName, g3);
87 FillHistogram(detector, g3, g3xh, g3yh, g3zh);
ab99804f 88
f2b0ecac 89 detector = LoadDetector(g4File1Name, detName, g4);
90 FillHistogram(detector, g4, g4x, g4y, g4z);
ab99804f 91
f2b0ecac 92 //detector = LoadDetector(g4File2Name, detName, g4);
93 FillHistogram(detector, g4, g4xh, g4yh, g4zh);
ab99804f 94
95 // compose picture name
96 TString gifNameBase = "hits" + detName + "v" + detVersion;
97 TString title = detName + " hits";
98
99 // draw histohrams
100 DrawHistograms(title, gifNameBase + "_x.gif", g3x, g4x, g3xh, g4xh);
101 DrawHistograms(title, gifNameBase + "_y.gif", g3y, g4y, g3yh, g4yh);
102 DrawHistograms(title, gifNameBase + "_z.gif", g3z, g4z, g3zh, g4zh);
103}
104
105void SetHistogramRanges(TString& detName, Int_t& nbin,
106 Int_t& g3xmin, Int_t& g3xmax,
107 Int_t& g4xmin, Int_t& g4xmax,
108 Int_t& g3ymin, Int_t& g3ymax,
109 Int_t& g4ymin, Int_t& g4ymax,
110 Int_t& g3zmin, Int_t& g3zmax,
111 Int_t& g4zmin, Int_t& g4zmax)
112{
113 nbin = 200;
114
115 g3xmin = 0; g4xmin = g3xmin;
116 g3xmax = 1; g4xmax = g3xmax;
117 g3ymin = 0; g4ymin = g3xmin;
118 g3ymax = 1; g4ymax = g3xmax;
119 g3zmin = 0; g4zmin = g3zmin;
120 g3zmax = 1; g4zmax = g3zmax;
121
122 if (detName == "FMD") {
123 g3xmin = -70; g4xmin = g3xmin;
124 g3xmax = 70; g4xmax = g3xmax;
125 g3zmin = -300; g4zmin = g3zmin;
126 g3zmax = 300; g4zmax = g3zmax;
127 }
128 else if (detName == "ITS") {
129 g3xmin = -60; g4xmin = g3xmin;
130 g3xmax = 60; g4xmax = g3xmax;
131 g3zmin = -60; g4zmin = g3zmin;
132 g3zmax = 60; g4zmax = g3zmax;
133 }
134 else if (detName == "MUON") {
135 g3xmin = -450; g4xmin = g3xmin;
136 g3xmax = 450; g4xmax = g3xmax;
137 g3zmin = 400; g4zmin = g3zmin;
138 g3zmax = 1800; g4zmax = g3zmax;
139 }
140 else if (detName == "PHOS") {
141 g3xmin = -400; g4xmin = g3xmin;
142 g3xmax = 400; g4xmax = g3xmax;
143 g3ymin = -500; g4ymin = g3ymin;
144 g3ymax = -250; g4ymax = g3ymax;
145 g3zmin = -80; g4zmin = g3zmin;
146 g3zmax = 80; g4zmax = g3zmax;
147 }
148 else if (detName == "PMD") {
149 g3xmin = -200; g4xmin = g3xmin*10;
150 g3xmax = 200; g4xmax = g3xmax*10;
151 g3zmin = -582; g4zmin = g3zmin*10;
152 g3zmax = -578; g4zmax = g3zmax*10;
153 }
154 else if (detName == "START") {
155 g3xmin = -10; g4xmin = g3xmin;
156 g3xmax = 10; g4xmax = g3xmax;
157 g3zmin = -80; g4zmin = g3zmin;
158 g3zmax = 80; g4zmax = g3zmax;
159 }
160 else if (detName == "TOF") {
161 g3xmin = -400; g4xmin = g3xmin;
162 g3xmax = 400; g4xmax = g3xmax;
163 g3zmin = -400; g4zmin = g3zmin;
164 g3zmax = 400; g4zmax = g3zmax;
165 }
166 else if (detName == "TPC") {
167 g3xmin = -300; g4xmin = g3xmin;
168 g3xmax = 300; g4xmax = g3xmax;
169 g3zmin = -300; g4zmin = g3zmin;
170 g3zmax = 300; g4zmax = g3zmax;
171 }
172}
173
174AliDetector* LoadDetector(TString& fileName, TString& detName, TString& label)
175{
176 // connect the Root files
177 TFile* file = new TFile(fileName);
178 if (!file) {
179 cerr << "Root file was not found." << endl;
180 return 0;
181 }
182
183 // get AliRun object from file
184 if (gAlice) delete gAlice;
185 gAlice = 0;
186 gAlice = (AliRun*)file->Get("gAlice");
187 if (!gAlice) {
188 cerr << label << "AliRun object not found in a file." << endl;
189 return 0;
190 }
191
192 // import the hits trees
193 Int_t nparticles = gAlice->GetEvent(0);
194 if (nparticles <= 0) {
195 cerr << label << "No particles in a file." << endl;
196 return 0;
197 }
198 cout << label << "got nparticles = " << nparticles << endl;
199
200 // get detector
201 AliDetector* detector = gAlice->GetDetector(detName);
202 if (!detector) {
203 cerr << label << "No detector " << detName << " in a file." << endl;
204 return 0;
205 }
206
207 return detector;
208}
209
f2b0ecac 210void FillHistogram(AliDetector* detector, TString& label,
ab99804f 211 TH1F* hx, TH1F* hy, TH1F* hz)
212{
213 Int_t nofHits = 0;
214 // get number of primary tracks
215 Int_t ntracks = gAlice->TreeH()->GetEntries();
216 cout << label << "got ntracks = " << ntracks << endl;
217
218 // loop on tracks in the hits container
219 for (Int_t i=0; i<ntracks; i++)
220 // loop on hits
221 for(AliHit* hit= detector->FirstHit(i); hit; hit=detector->NextHit()) {
222 Float_t x = hit->X();
223 Float_t y = hit->Y();
224 Float_t z = hit->Z();
225 if (hx) hx->Fill(x);
226 if (hy) hy->Fill(y);
227 if (hz) hz->Fill(z);
228 nofHits++;
229 }
230
231 cout << label << "filled " << nofHits << " hits" << endl;
232}
233
ab99804f 234void DrawHistograms(TString& title, TString& gifName,
235 TH1F* h1, TH1F* h2, TH1F* h3, TH1F* h4)
236{
237// Create canvas, set the view range, show histograms.
238// ---
239
240 if (h1 && h2 && h3 && h4) {
241 // create canvas
242 //TCanvas* canvas = new TCanvas("c1",detName + " hits", 400, 10, 800, 600);
243 TCanvas* canvas = new TCanvas("c1", title, 400, 10, 800, 600);
244 canvas->Divide(2,2);
245
246 // draw histograms
247 canvas->cd(1); h1->Draw();
248 canvas->cd(2); h2->Draw();
249 canvas->cd(3); h3->Draw();
250 canvas->cd(4); h4->Draw();
251
252 // save gif
253 //canvas->SaveAs(gifNameBase + "_x.gif");
254 canvas->SaveAs(gifName);
255 }
256}