1 Int_t ITSReadPlotData(char *filename = "galice.root", Int_t evNum = 0) {
3 /*********************************************************************
5 * Macro used to read hits, digits and recpoints for a module *
6 * It draws 3 TH2Fs where stores the 2-D coordinates of these *
7 * data for a specified module (for which the macro asks when *
8 * it starts, with some checks to avoid wrong detector coords. *
10 * Only a little 'experimental' warning: *
11 * with all the tests I have made, I wasn't able to plot the *
12 * digits fo the 5th layer... *
13 * I skipped this problem with an alert to beware th user, while *
14 * in this situation the macro plots only recpoints and hits *
16 * Author: Alberto Pulvirenti *
18 *********************************************************************/
21 extern Int_t GetModuleHits (TObject* its, Int_t ID[0], Float_t*& X, Float_t*& Y, Float_t*& Z, Bool_t*& St);
22 extern Int_t GetModuleRecPoints (TObject *its, Int_t ID[0], Float_t*& X, Float_t*& Z);
23 extern Int_t GetModuleDigits(TObject *its, Int_t ID[0], Int_t dtype, Float_t*& X, Float_t*& Z);
24 extern void AssignCoords(TArrayI *ID);
26 // First of all, here are put some variable declarations
27 // that are useful in the following part:
28 Int_t nparticles; // number of particles
29 // ITS module coordinates [layer = 1, ladder = 2, det = 3] and absolute ID[0] of module [0]
31 Int_t nmodules, dtype; // Total number of modules and module type (SSD, SPD, SDD)
32 Float_t *x = 0, *y = 0, *z = 0; // Arrays where to store read coords
33 Bool_t *St = 0; // Status of the track (hits only)
35 // It's necessary to load the gAlice shared libs
36 // if they aren't already stored in memory...
37 if (gClassTable->GetID("AliRun") < 0) {
38 gROOT->LoadMacro("loadlibs.C");
41 // Anyway, this macro needs to read a gAlice file, so it
42 // clears the gAlice object if there is already one in memory...
50 // Now is opened the Root input file containing Geometry, Kine and Hits
51 // by default its name must be "galice.root".
52 // When the file is opened, its contens are shown.
53 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
54 if (!file) file = new TFile(filename);
57 // Then, the macro gets the AliRun object from file.
58 // If this object is not present, an error occurs
59 // and the execution is stopped.
60 // Anyway, this operation needs some time,
61 // don't worry about an apparent absence of output and actions...
62 cout << "\nSearching in '" << filename << "' for an AliRun object ... " << flush;
63 gAlice = (AliRun*)file->Get("gAlice");
65 cout << "FOUND!" << endl;
67 cout<<"NOT FOUND! The Macro can't continue!" << endl;
71 // Then, the macro selects the event number specified. Default is 0.
72 nparticles = gAlice->GetEvent(evNum);
73 cout << "\nNumber of particles = " << nparticles << endl;
75 cout << "With no particles I can't do much... Goodbye!" << endl;
79 // The next step is filling the ITS from the AliRun object.
80 AliITS *ITS = (AliITS*)gAlice->GetModule("ITS");
81 ITS->InitModules(-1, nmodules);
82 cout << "Number of ITS modules = " << nmodules << endl;
83 cout << "\nFilling modules (it takes a while, now)..." << flush;
84 ITS->FillModules(0, 0, nmodules, " ", " ");
85 cout << "DONE!" << endl;
86 AliITSgeom *gm = ITS->GetITSgeom();
87 AliITSDetType *det = ITS->DetType(dtype);
88 AliITSsegmentation *seg = det->GetSegmentationModel();
93 // The macro asks if the user wants to put a detector ID[0]
94 // or prefers to input layer, ladder and detector.
95 for (Int_t i = 0; i < 4; i++) ID[i] = -1;
98 cout << "\nSelection modes:" << endl;
99 cout << "1) by layer - ladder - detector numbers" << endl;
100 cout << "2) by unique detector ID" << endl;
101 cout << "0) exit macro" << endl;
102 cout << "\nEnter your choice: ";
104 } while (answ < 0 || answ > 2);
107 // input = 0 ---> EXIT
111 // input = 1 ---> SELECTION BY COORD
113 cout << "\nLayer number [1-6, 0 to exit]: ";
115 if (!ID[1]) return 0;
116 } while (ID[1] < 0 || ID[1] > 6);
118 // Detector type: 0 --> SPD, 1 --> SDD, 2 --> SSD.
119 // Layer 1,2 --> 0 / Layer 3,4 --> 1 / Layer 5,6 --> 2
120 dtype = (ID[1] - 1) / 2;
122 // Once fixed the layer number, the macro calculates the max number
123 // for ladder and detector from geometry, and accepts only suitable values.
125 ID[2] = gm->GetNladders(ID[1]);
126 cout << "Ladder number [1-" << ID[2] << ", 0 to exit]: ";
128 if (!ID[2]) return 0;
129 } while (ID[2] < 0 || ID[2] > gm->GetNladders(ID[1]));
131 ID[3] = gm->GetNdetectors(ID[1]);
132 cout << "Detector number [1-" << ID[3] << ", 0 to exit]: ";
134 if (!ID[3]) return 0;
135 } while (ID[3] < 0 || ID[3] > gm->GetNdetectors(ID[1]));
138 // input = 2 ---> SELECTION BY ID[0]
140 ID[0] = gm->GetIndexMax();
141 cout << "\n Detector ID number [0-" << ID[0] << ", -1 to exit]: ";
143 if (ID[0] == -1) return 0;
144 } while (ID[0] < 0 || ID[0] > gm->GetIndexMax());
149 // If ID[0] = -1 the chioce was by coords, so it's necessary to assign the ID:
150 ID[0] = gm->GetModuleIndex(ID[1], ID[2], ID[3]);
152 // Else we must get the layer, ladder and detector by the ID;
153 // ...but first we must remember that the ID goest from 0 to NModules - 1!
155 ID[1] = ITS->GetModule(ID[0])->GetLayer();
156 ID[2] = ITS->GetModule(ID[0])->GetLadder();
157 ID[3] = ITS->GetModule(ID[0])->GetDet();
160 // Defines the histograms inside the `for' cycle, so they are destroyed at the end
161 // of every read sequqnce, in order to mek another withour segmentation faults
163 Float_t xm = 0.0, ym = 0.0, zm = 0.0;
165 case 0: xm = 1.5; zm = 7.0; break;
166 case 1: xm = 7.5; zm = 8.0; break;
167 case 2: xm = 7.5; zm = 4.5; break;
169 sprintf(msg, "Module index=%d lay=%d lad=%d det=%d", ID[0], ID[1], ID[2], ID[3]);
170 TH2F *hhits = new TH2F("hhits", msg, 500, -xm, xm, 500, -zm, zm); // Histogram of hits
171 TH2F *hrecs = new TH2F("hrecs", msg, 500, -xm, xm, 500, -zm, zm); // Histogram of recpoints
172 TH2F *hdigits = new TH2F("hdigits", msg, 500, -xm, xm, 500, -zm, zm); // Histogram of digits
177 Int_t hits = GetModuleHits(ITS, ID[0], x, y, z, St);
179 cout << "No hits in module!" << endl;
182 for (Int_t i = 0; i < hits; i++) if (!St[i]) hhits->Fill(x[i], z[i]);
184 // Reads recpoints...
185 Int_t recs = GetModuleRecPoints(ITS, ID[0], x, z);
187 cout << "No recpoints in module!" << endl;
190 for (Int_t i = 0; i < recs; i++) hrecs->Fill(x[i], z[i]);
193 Int_t digits = GetModuleDigits(ITS, ID[0], dtype, x, z);
195 cout << "No digits in module!" << endl;
198 for (Int_t i = 0; i < digits; i++) hdigits->Fill(x[i], z[i]);
200 // Draws read data...
201 // HITS -------> red (2) crosses.
202 // DIGITS -----> green (8) boxes.
203 // REC-POINTS -> blue (4) St. Andrew's crosses.
205 TCanvas *viewer = new TCanvas("viewer", "Module viewer canvas", 0, 0, 800, 800);
208 hdigits->SetMarkerStyle(25);
209 hdigits->SetMarkerColor(8);
210 hdigits->SetMarkerSize(2);
211 hdigits->SetStats(kFALSE);
212 hdigits->SetXTitle("Local X (cm)");
213 hdigits->SetYTitle("Local Z (cm)");
216 hhits->SetMarkerStyle(5);
217 hhits->SetMarkerColor(2);
218 hhits->SetMarkerSize(3);
219 hhits->SetStats(kFALSE);
222 hrecs->SetMarkerStyle(2);
223 hrecs->SetMarkerColor(4);
224 hrecs->SetMarkerSize(3);
225 hrecs->SetStats(kFALSE);
228 TLegend *legend = new TLegend(0.7, 0.8, 0.9, 0.9);
229 legend->SetMargin(0.2);
230 legend->AddEntry(hhits, "hits","P");
231 legend->AddEntry(hrecs, "recpoints","P");
232 legend->AddEntry(hdigits, "digits","P");
233 legend->SetTextSizePixels(14);
239 cout << "Done. Goodbye" << endl;
243 Int_t GetModuleHits (TObject* its, Int_t ID, Float_t*& X, Float_t*& Y, Float_t*& Z, Bool_t*& St) {
244 // First of all, the macro selects the specified module,
245 // then gets the array of hits in it and their number.
246 AliITS *ITS = (AliITS*) its;
247 AliITSmodule *module = ITS->GetModule(ID);
248 TObjArray *hits_array = module->GetHits();
249 Int_t hits_num = hits_array->GetEntriesFast();
251 // Now, if this count returns 0, there's nothing to do,
252 // while, if it doesn't, the first thing to do is dimensioning
253 // the coordinate arrays, and then the loop can start.
260 if (St) delete [] St;
261 X = new Float_t[hits_num];
262 Y = new Float_t[hits_num];
263 Z = new Float_t[hits_num];
264 St = new Int_t[hits_num];
267 for (Int_t j = 0; j < hits_num; j++) {
268 AliITShit *hit = (AliITShit*) hits_array->At(j);
272 St[j] = hit->StatusEntering();
277 Int_t GetModuleRecPoints (TObject *its, Int_t ID, Float_t*& X, Float_t*& Z) {
279 // First of all, the macro selects the specified module,
280 // then gets the array of recpoints in it and their number.
281 AliITS *ITS = (AliITS*) its;
282 TTree *TR = gAlice->TreeR();
283 ITS->ResetRecPoints();
285 TClonesArray *recs_array = ITS->RecPoints();
286 Int_t recs_num = recs_array->GetEntries();
288 // Now, if this count returns 0, there's nothing to do,
289 // while, if it doesn't, the first thing to do is dimensioning
290 // the coordinate and energy loss arrays, and then the loop can start.
296 X = new Float_t[recs_num];
297 Z = new Float_t[recs_num];
299 for(Int_t j = 0; j < recs_num; j++) {
300 AliITSRecPoint *recp = (AliITSRecPoint*)recs_array->At(j);
307 Int_t GetModuleDigits(TObject *its, Int_t ID, Int_t dtype, Float_t*& X, Float_t*& Z) {
309 // First of all, the macro selects the specified module,
310 // then gets the array of recpoints in it and their number.
311 AliITS *ITS = (AliITS*)its;
312 TTree *TD = gAlice->TreeD();
315 TClonesArray *digits_array = ITS->DigitsAddress(dtype);
316 AliITSgeom *gm = ITS->GetITSgeom();
317 AliITSDetType *det = ITS->DetType(dtype);
318 AliITSsegmentation *seg = det->GetSegmentationModel();
319 TArrayI ssdone(5000); // used to match p and n side digits of strips
320 TArrayI pair(5000); // as above
321 Int_t digits_num = digits_array->GetEntries();
322 // Now, if this count returns 0, there's nothing to do,
323 // while, if it doesn't, the first thing to do is dimensioning
324 // the coordinate and energy loss arrays, and then the loop can start.
327 Int_t layer, ladder, detec;
328 gm->GetModuleId(ID,layer,ladder,detec);
329 seg->SetLayer(layer);
337 X = new Float_t[digits_num];
338 Z = new Float_t[digits_num];
341 // Get the coordinates of the module
343 for (Int_t j = 0; j < digits_num; j++) {
348 for (Int_t j = 0; j < digits_num; j++) {
350 digit = (AliITSdigit*)digits_array->UncheckedAt(j);
351 Int_t iz=digit->fCoord1; // cell number z
352 Int_t ix=digit->fCoord2; // cell number x
353 // Get local coordinates of the element (microns)
355 seg->DetToLocal(ix, iz, X[j], Z[j]);
357 // SSD: if iz==0 ---> N side; if iz==1 P side
358 if (ssdone[j] == 0) {
361 Bool_t pside = (iz == 1);
362 Bool_t impaired = kTRUE;
365 if (pside) pstrip = ix; else nstrip = ix;
366 for (Int_t k = 0; k < digits_num; k++) {
367 if (ssdone[k] == 0 && impaired) {
368 AliITSdigitSSD *sdigit=(AliITSdigitSSD*)digits_array->UncheckedAt(k);
369 if (sdigit->fCoord1 != iz && sdigit->GetTracks()[0] == digit->GetTracks()[0]) {
372 if (pside) nstrip = sdigit->fCoord2; else pstrip = sdigit->fCoord2;
377 if (!impaired) seg->GetPadCxz(pstrip, nstrip, X[j], Z[j]);
378 X[j] /= 10000.0; // convert microns to cm
379 Z[j] /= 10000.0; // convert microns to cm