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";
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);
117 void SetHistogramRanges(TString& detName, Int_t& nbin,
118 Int_t& g3xmin, Int_t& g3xmax,
119 Int_t& g4xmin, Int_t& g4xmax,
120 Int_t& g3ymin, Int_t& g3ymax,
121 Int_t& g4ymin, Int_t& g4ymax,
122 Int_t& g3zmin, Int_t& g3zmax,
123 Int_t& g4zmin, Int_t& g4zmax)
127 g3xmin = 0; g4xmin = g3xmin;
128 g3xmax = 1; g4xmax = g3xmax;
129 g3ymin = 0; g4ymin = g3xmin;
130 g3ymax = 1; g4ymax = g3xmax;
131 g3zmin = 0; g4zmin = g3zmin;
132 g3zmax = 1; g4zmax = g3zmax;
134 if (detName == "FMD") {
135 g3xmin = -50; g4xmin = g3xmin;
136 g3xmax = 50; g4xmax = g3xmax;
137 g3zmin = -700; g4zmin = g3zmin;
138 g3zmax = 150; g4zmax = g3zmax;
140 else if (detName == "ITS") {
141 g3xmin = -60; g4xmin = g3xmin;
142 g3xmax = 60; g4xmax = g3xmax;
143 g3zmin = -60; g4zmin = g3zmin;
144 g3zmax = 60; g4zmax = g3zmax;
146 else if (detName == "MUON") {
147 g3xmin = -450; g4xmin = g3xmin;
148 g3xmax = 450; g4xmax = g3xmax;
149 g3zmin = 400; g4zmin = g3zmin;
150 g3zmax = 1800; g4zmax = g3zmax;
152 else if (detName == "PHOS") {
153 g3xmin = -400; g4xmin = g3xmin;
154 g3xmax = 400; g4xmax = g3xmax;
155 g3ymin = 250; g4ymin = g3ymin;
156 g3ymax = 500; g4ymax = g3ymax;
157 g3zmin = -80; g4zmin = g3zmin;
158 g3zmax = 80; g4zmax = g3zmax;
160 else if (detName == "PMD") {
161 g3xmin = -200; g4xmin = g3xmin*10;
162 g3xmax = 200; g4xmax = g3xmax*10;
163 g3zmin = -582; g4zmin = g3zmin*10;
164 g3zmax = -578; g4zmax = g3zmax*10;
166 else if (detName == "RICH") {
167 g3xmin = -250; g4xmin = g3xmin;
168 g3xmax = 250; g4xmax = g3xmax;
169 g3zmin = -250; g4zmin = g3zmin;
170 g3zmax = 250; g4zmax = g3zmax;
172 else if (detName == "START") {
173 g3xmin = -10; g4xmin = g3xmin;
174 g3xmax = 10; g4xmax = g3xmax;
175 g3zmin = -80; g4zmin = g3zmin;
176 g3zmax = 80; g4zmax = g3zmax;
178 else if (detName == "TOF") {
179 g3xmin = -400; g4xmin = g3xmin;
180 g3xmax = 400; g4xmax = g3xmax;
181 g3zmin = -400; g4zmin = g3zmin;
182 g3zmax = 400; g4zmax = g3zmax;
184 else if (detName == "TPC") {
185 g3xmin = -300; g4xmin = g3xmin;
186 g3xmax = 300; g4xmax = g3xmax;
187 g3zmin = -300; g4zmin = g3zmin;
188 g3zmax = 300; g4zmax = g3zmax;
192 AliDetector* LoadDetector(TString& fileName, TString& detName, TString& label)
194 // connect the Root files
195 TFile* file = new TFile(fileName);
197 cerr << "Root file was not found." << endl;
201 // get AliRun object from file
202 if (gAlice) delete gAlice;
204 gAlice = (AliRun*)file->Get("gAlice");
206 cerr << label << "AliRun object not found in a file." << endl;
210 // import the hits trees
211 Int_t nparticles = gAlice->GetEvent(0);
212 if (nparticles <= 0) {
213 cerr << label << "No particles in a file." << endl;
216 cout << label << "got nparticles = " << nparticles << endl;
219 AliDetector* detector = gAlice->GetDetector(detName);
221 cerr << label << "No detector " << detName << " in a file." << endl;
228 void FillHistogram(AliDetector* detector, TString& label,
229 TH1F* hx, TH1F* hy, TH1F* hz)
232 // get number of primary tracks
233 Int_t ntracks = gAlice->TreeH()->GetEntries();
234 cout << label << "got ntracks = " << ntracks << endl;
236 // loop on tracks in the hits container
237 for (Int_t i=0; i<ntracks; i++) {
239 for(AliHit* hit= detector->FirstHit(i); hit; hit=detector->NextHit()) {
241 TString detName = detector->GetName();
242 if (detName == "PHOS") {
244 FillPHOSHit(detector, hit, hx, hy, hz);
247 FillHit(hit, hx, hy, hz);
254 TFile* file = new TFile("tmp.root","recreate");
259 cout << label << "filled " << nofHits << " hits" << endl;
262 TH1F* LoadHistograms(TString name)
264 TFile* file = new TFile("tmp.root");
265 return (TH1F*)file->Get(name);
268 void FillHit(AliHit* hit, TH1F* hx, TH1F* hy, TH1F* hz)
270 if (hx) hx->Fill(hit->X());
271 if (hy) hy->Fill(hit->Y());
272 if (hz) hz->Fill(hit->Z());
275 void FillPHOSHit(AliDetector* detector, AliHit* hit,
276 TH1F* hx, TH1F* hy, TH1F* hz)
279 Float_t id = ((AliPHOSHit*)hit)->GetId();
282 ((AliPHOS*)detector)->GetGeometry()->RelPosInAlice(id, pos);
284 if (hx) hx->Fill(pos.X());
285 if (hy) hy->Fill(pos.Y());
286 if (hz) hz->Fill(pos.Z());
289 void DrawHistograms(TString& title, TString& gifName,
290 TH1F* h1, TH1F* h2, TH1F* h3, TH1F* h4)
292 // Create canvas, set the view range, show histograms.
295 if (h1 && h2 && h3 && h4) {
297 TCanvas* canvas = new TCanvas("c1", title, 400, 10, 800, 600);
301 canvas->cd(1); h1->Draw();
302 canvas->cd(2); h2->Draw();
303 canvas->cd(3); h3->Draw();
304 canvas->cd(4); h4->Draw();
307 //canvas->SaveAs(gifNameBase + "_x.gif");
308 canvas->SaveAs(gifName);