19 void hits(const TString& detName, const TString& detVersion)
21 cout << detName << endl;
27 // construct file names
28 TString top = getenv("ALICE_ROOT");
29 TString f1NameEnd = "test10.root";
30 TString f2NameEnd = "test20.root";
32 TString g3File1Name = top + "/test/" + f1NameEnd;
33 TString g3File2Name = top + "/test/" + f2NameEnd;
34 TString g4File1Name = top + "/AliGeant4/test/" + f1NameEnd;
35 TString g4File2Name = top + "/AliGeant4/test/" + f2NameEnd;
37 cout << "Files: " << endl;
38 cout << g3File1Name << endl;
39 cout << g3File2Name << endl;
40 cout << g4File1Name << endl;
41 cout << g4File2Name << endl;
44 if (gClassTable->GetID("AliRun") < 0) {
45 gROOT->LoadMacro("loadlibs.C");
48 cout << "AliRoot libraries were loaded." << endl;
50 // set histogram ranges
52 Int_t g3xmin; Int_t g4xmin; Int_t g3xmax; Int_t g4xmax;
53 Int_t g3ymin; Int_t g4ymin; Int_t g3ymax; Int_t g4ymax;
54 Int_t g3zmin; Int_t g4zmin; Int_t g3zmax; Int_t g4zmax;
55 SetHistogramRanges(detName, nbin,
56 g3xmin, g3xmax, g4xmin, g4xmax,
57 g3ymin, g3ymax, g4ymin, g4ymax,
58 g3zmin, g3zmax, g4zmin, g4zmax);
62 TH1F* g3x = new TH1F("g3x", g3 + detName + " hits per x", nbin, g3xmin, g3xmax);
63 TH1F* g3xh = new TH1F("g3xh", g3 + detName + " hits per x", nbin, g3xmin, g3xmax);
64 TH1F* g4x = new TH1F("g4x", g4 + detName + " hits per x", nbin, g4xmin, g4xmax);
65 TH1F* g4xh = new TH1F("g4xh", g4 + detName + " hits per x", nbin, g4xmin, g4xmax);
67 TH1F* g3z = new TH1F("g3z", g3 + detName + " hits per z", nbin, g3zmin, g3zmax);
68 TH1F* g3zh = new TH1F("g3zh", g3 + detName + " hits per z", nbin, g3zmin, g3zmax);
69 TH1F* g4z = new TH1F("g4z", g4 + detName + " hits per z", nbin, g4zmin, g4zmax);
70 TH1F* g4zh = new TH1F("g4zh", g4 + detName + " hits per z", nbin, g4zmin, g4zmax);
76 if (detName == "PHOS") {
77 TH1F* g3y = new TH1F("g3y", g3 + detName + " hits per y", nbin, g3ymin, g3ymax);
78 TH1F* g3yh = new TH1F("g3yh", g3 + detName + " hits per y", nbin, g3ymin, g3ymax);
79 TH1F* g4y = new TH1F("g4y", g4 + detName + " hits per y", nbin, g4ymin, g4ymax);
80 TH1F* g4yh = new TH1F("g4yh", g4 + detName + " hits per y", nbin, g4ymin, g4ymax);
83 cout << "Histograms were created." << endl;
86 AliDetector* detector;
88 detector = LoadDetector(g3File1Name, detName, g3);
89 FillHistogram(detector, g3, g3x, g3y, g3z);
91 detector = LoadDetector(g3File2Name, detName, g3);
92 FillHistogram(detector, g3, g3xh, g3yh, g3zh);
93 //TH1F* g3xh = LoadHistograms("g3xh");
94 //TH1F* g3zh = LoadHistograms("g3zh");
96 detector = LoadDetector(g4File1Name, detName, g4);
97 FillHistogram(detector, g4, g4x, g4y, g4z);
99 detector = LoadDetector(g4File2Name, detName, g4);
100 FillHistogram(detector, g4, g4xh, g4yh, g4zh);
102 // compose picture name
103 TString gifNameBase = "hits" + detName + "v" + detVersion;
104 TString title = detName + " hits";
106 // draw histograms (G3, G4 in one canvas)
107 DrawHistograms(title, gifNameBase + ".gif", g3xh, g4xh, g3zh, g4zh);
108 if (detName == "PHOS")
109 DrawHistograms(title, gifNameBase + "2.gif", g3yh, g4yh, g3zh, g4zh);
111 //DrawHistograms(title, gifNameBase + "_x.gif", g3x, g4x, g3xh, g4xh);
112 //DrawHistograms(title, gifNameBase + "_y.gif", g3y, g4y, g3yh, g4yh);
113 //DrawHistograms(title, gifNameBase + "_z.gif", g3z, g4z, g3zh, g4zh);
115 // draw histograms (one by one)
116 DrawHistogram(title, "g3x_"+ gifNameBase + ".gif", g3xh);
117 DrawHistogram(title, "g4x_"+ gifNameBase + ".gif", g4xh);
118 DrawHistogram(title, "g3z_"+ gifNameBase + ".gif", g3zh);
119 DrawHistogram(title, "g4z_"+ gifNameBase + ".gif", g4zh);
123 void SetHistogramRanges(TString& detName, Int_t& nbin,
124 Int_t& g3xmin, Int_t& g3xmax,
125 Int_t& g4xmin, Int_t& g4xmax,
126 Int_t& g3ymin, Int_t& g3ymax,
127 Int_t& g4ymin, Int_t& g4ymax,
128 Int_t& g3zmin, Int_t& g3zmax,
129 Int_t& g4zmin, Int_t& g4zmax)
133 g3xmin = 0; g4xmin = g3xmin;
134 g3xmax = 1; g4xmax = g3xmax;
135 g3ymin = 0; g4ymin = g3xmin;
136 g3ymax = 1; g4ymax = g3xmax;
137 g3zmin = 0; g4zmin = g3zmin;
138 g3zmax = 1; g4zmax = g3zmax;
140 if (detName == "FMD") {
141 g3xmin = -50; g4xmin = g3xmin;
142 g3xmax = 50; g4xmax = g3xmax;
143 g3zmin = -700; g4zmin = g3zmin;
144 g3zmax = 150; g4zmax = g3zmax;
146 else if (detName == "ITS") {
147 g3xmin = -60; g4xmin = g3xmin;
148 g3xmax = 60; g4xmax = g3xmax;
149 g3zmin = -60; g4zmin = g3zmin;
150 g3zmax = 60; g4zmax = g3zmax;
152 else if (detName == "MUON") {
153 g3xmin = -450; g4xmin = g3xmin;
154 g3xmax = 450; g4xmax = g3xmax;
155 g3zmin = 400; g4zmin = g3zmin;
156 g3zmax = 1800; g4zmax = g3zmax;
158 else if (detName == "PHOS") {
159 g3xmin = -400; g4xmin = g3xmin;
160 g3xmax = 400; g4xmax = g3xmax;
161 g3ymin = 250; g4ymin = g3ymin;
162 g3ymax = 500; g4ymax = g3ymax;
163 g3zmin = -80; g4zmin = g3zmin;
164 g3zmax = 80; g4zmax = g3zmax;
166 else if (detName == "PMD") {
167 g3xmin = -200; g4xmin = g3xmin*10;
168 g3xmax = 200; g4xmax = g3xmax*10;
169 g3zmin = -582; g4zmin = g3zmin*10;
170 g3zmax = -578; g4zmax = g3zmax*10;
172 else if (detName == "RICH") {
173 g3xmin = -250; g4xmin = g3xmin;
174 g3xmax = 250; g4xmax = g3xmax;
175 g3zmin = -250; g4zmin = g3zmin;
176 g3zmax = 250; g4zmax = g3zmax;
178 else if (detName == "START") {
179 g3xmin = -10; g4xmin = g3xmin;
180 g3xmax = 10; g4xmax = g3xmax;
181 g3zmin = -80; g4zmin = g3zmin;
182 g3zmax = 80; g4zmax = g3zmax;
184 else if (detName == "TOF") {
185 g3xmin = -400; g4xmin = g3xmin;
186 g3xmax = 400; g4xmax = g3xmax;
187 g3zmin = -400; g4zmin = g3zmin;
188 g3zmax = 400; g4zmax = g3zmax;
190 else if (detName == "TPC") {
191 g3xmin = -300; g4xmin = g3xmin;
192 g3xmax = 300; g4xmax = g3xmax;
193 g3zmin = -300; g4zmin = g3zmin;
194 g3zmax = 300; g4zmax = g3zmax;
198 AliDetector* LoadDetector(TString& fileName, TString& detName, TString& label)
200 // connect the Root files
201 TFile* file = new TFile(fileName);
203 cerr << "Root file was not found." << endl;
207 // get AliRun object from file
208 if (gAlice) delete gAlice;
210 gAlice = (AliRun*)file->Get("gAlice");
212 cerr << label << "AliRun object not found in a file." << endl;
216 // import the hits trees
217 Int_t nparticles = gAlice->GetEvent(0);
218 if (nparticles <= 0) {
219 cerr << label << "No particles in a file." << endl;
222 cout << label << "got nparticles = " << nparticles << endl;
225 AliDetector* detector = gAlice->GetDetector(detName);
227 cerr << label << "No detector " << detName << " in a file." << endl;
234 void FillHistogram(AliDetector* detector, TString& label,
235 TH1F* hx, TH1F* hy, TH1F* hz)
238 // get number of primary tracks
239 Int_t ntracks = gAlice->TreeH()->GetEntries();
240 cout << label << "got ntracks = " << ntracks << endl;
242 // loop on tracks in the hits container
243 for (Int_t i=0; i<ntracks; i++) {
245 for(AliHit* hit= detector->FirstHit(i); hit; hit=detector->NextHit()) {
247 TString detName = detector->GetName();
248 if (detName == "PHOS") {
250 FillPHOSHit(detector, hit, hx, hy, hz);
253 FillHit(hit, hx, hy, hz);
260 TFile* file = new TFile("tmp.root","recreate");
265 cout << label << "filled " << nofHits << " hits" << endl;
268 TH1F* LoadHistograms(TString name)
270 TFile* file = new TFile("tmp.root");
271 return (TH1F*)file->Get(name);
274 void FillHit(AliHit* hit, TH1F* hx, TH1F* hy, TH1F* hz)
276 if (hx) hx->Fill(hit->X());
277 if (hy) hy->Fill(hit->Y());
278 if (hz) hz->Fill(hit->Z());
281 void FillPHOSHit(AliDetector* detector, AliHit* hit,
282 TH1F* hx, TH1F* hy, TH1F* hz)
285 Float_t id = ((AliPHOSHit*)hit)->GetId();
288 ((AliPHOS*)detector)->GetGeometry()->RelPosInAlice(id, pos);
290 if (hx) hx->Fill(pos.X());
291 if (hy) hy->Fill(pos.Y());
292 if (hz) hz->Fill(pos.Z());
295 void DrawHistograms(TString& title, TString& gifName,
296 TH1F* h1, TH1F* h2, TH1F* h3, TH1F* h4)
298 // Create canvas, set the view range, show histograms.
301 if (h1 && h2 && h3 && h4) {
303 TCanvas* canvas1 = new TCanvas("c1", title, 400, 10, 400, 300);
304 TCanvas* canvas2 = new TCanvas("c2", title, 400, 10, 400, 300);
305 TCanvas* canvas3 = new TCanvas("c3", title, 400, 10, 400, 300);
306 TCanvas* canvas4 = new TCanvas("c4", title, 400, 10, 400, 300);
307 //canvas->Divide(2,2);
310 canvas1->cd(1); h1->Draw();
311 canvas2->cd(1); h2->Draw();
312 canvas3->cd(1); h3->Draw();
313 canvas4->cd(1); h4->Draw();
316 //canvas->SaveAs(gifNameBase + "_x.gif");
317 canvas1->SaveAs(gifName+"1");
318 canvas2->SaveAs(gifName+"2");
319 canvas3->SaveAs(gifName+"3");
320 canvas4->SaveAs(gifName+"4");
324 void DrawHistogram(TString& title, TString& gifName, TH1F* h)
326 // Create canvas, set the view range, show histograms.
331 TCanvas* canvas = new TCanvas("c", title, 400, 10, 400, 300);
337 canvas->SaveAs(gifName);