d810d0de |
1 | // $Id$ |
2 | // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 |
3 | |
4 | /************************************************************************** |
5 | * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. * |
6 | * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for * |
7 | * full copyright notice. * |
8 | **************************************************************************/ |
5a5a1232 |
9 | |
3d598e88 |
10 | #include <TMath.h> |
11 | #include <TVector3.h> |
5a5a1232 |
12 | |
84aff7a4 |
13 | #include <TEveTreeTools.h> |
14 | #include <TEveTrans.h> |
5a5a1232 |
15 | |
d810d0de |
16 | #include "AliEveITSDigitsInfo.h" |
5a5a1232 |
17 | #include <AliITSCalibrationSDD.h> |
18 | #include <AliITSdigit.h> |
19 | #include <AliITSdigitSPD.h> |
20 | |
b3bc5327 |
21 | #include <AliRawReader.h> |
22 | #include <AliITSRawStreamSPD.h> |
23 | #include <AliITSRawStreamSDD.h> |
24 | #include <AliITSRawStreamSSD.h> |
d810d0de |
25 | |
54f770b4 |
26 | //______________________________________________________________________________ |
27 | // |
28 | // Helper for selecting a range of ITS modules by type, layer, phi and |
29 | // theta. Taken as an argument to AliEveITSDigitsInfo::GetModuleIDs(). |
3d598e88 |
30 | |
d810d0de |
31 | ClassImp(AliEveITSModuleSelection) |
3d598e88 |
32 | |
d810d0de |
33 | AliEveITSModuleSelection::AliEveITSModuleSelection(): |
3d598e88 |
34 | fType(-1), |
35 | fLayer(-1), |
32e219c2 |
36 | fMinPhi(-TMath::Pi()), |
37 | fMaxPhi(TMath::Pi()), |
38 | fMinTheta(-TMath::Pi()), |
39 | fMaxTheta(TMath::Pi()) |
54f770b4 |
40 | { |
41 | // Constructor. |
42 | } |
43 | |
b3bc5327 |
44 | |
54f770b4 |
45 | //______________________________________________________________________________ |
46 | // |
47 | // Stores ITS geometry information and event-data in format suitable |
48 | // for visualization. |
3d598e88 |
49 | |
d810d0de |
50 | ClassImp(AliEveITSDigitsInfo) |
5a5a1232 |
51 | |
52 | /**************************************************************************/ |
53 | |
d810d0de |
54 | AliEveITSDigitsInfo::AliEveITSDigitsInfo() : |
265ecb21 |
55 | TObject(), |
84aff7a4 |
56 | TEveRefCnt(), |
265ecb21 |
57 | fSPDmap(), fSDDmap(), fSSDmap(), |
58 | fTree (0), |
59 | fGeom (0), |
60 | fSegSPD(0), fSegSDD(0), fSegSSD(0) |
5a5a1232 |
61 | { |
54f770b4 |
62 | // Default constructor. |
63 | |
b3bc5327 |
64 | InitInternals(); |
5a5a1232 |
65 | } |
66 | |
d810d0de |
67 | void AliEveITSDigitsInfo::InitInternals() |
5a5a1232 |
68 | { |
54f770b4 |
69 | // Initialize internal geometry structures, in particular the |
70 | // module-id to transformation-matrix mapping and segmentation |
71 | // classes and data-structures. |
72 | |
d810d0de |
73 | static const TEveException eH("AliEveITSDigitsInfo::InitInternals "); |
5a5a1232 |
74 | |
b3bc5327 |
75 | fGeom = new AliITSgeom(); |
76 | fGeom->ReadNewFile("$REVESYS/alice-data/ITSgeometry.det"); |
54f770b4 |
77 | if (fGeom == 0) |
b3bc5327 |
78 | throw(eH + "can not load ITS geometry \n"); |
5a5a1232 |
79 | |
80 | SetITSSegmentation(); |
d4b6a94c |
81 | |
5a5a1232 |
82 | // create tables for scaling |
d4b6a94c |
83 | fSPDMinVal = 0; |
84 | fSDDMinVal = 5; |
85 | fSSDMinVal = 2; |
86 | |
87 | fSPDMaxVal = 1; |
88 | fSDDMaxVal = 80; |
89 | fSSDMaxVal = 100; |
90 | |
32e219c2 |
91 | fSPDHighLim = 1; |
92 | fSDDHighLim = 512; |
93 | fSSDHighLim = 1024; |
d4b6a94c |
94 | |
d54c094e |
95 | // lowest scale factor refers to unscaled ITS module |
96 | fSPDScaleX[0] = 1; |
97 | fSPDScaleZ[0] = 1; |
98 | fSDDScaleX[0] = 1; |
99 | fSDDScaleZ[0] = 1; |
100 | fSSDScale [0] = 1; |
d4b6a94c |
101 | |
b3bc5327 |
102 | // spd lowest resolution |
5a5a1232 |
103 | Int_t nx = 8; // fSegSPD->Npx()/8; // 32 |
104 | Int_t nz = 6; // fSegSPD->Npz()/2; // 128 |
5a5a1232 |
105 | fSPDScaleX[1] = Int_t(nx); |
106 | fSPDScaleZ[1] = Int_t(nz); |
107 | fSPDScaleX[2] = Int_t(nx*2); |
108 | fSPDScaleZ[2] = Int_t(nz*2); |
109 | fSPDScaleX[3] = Int_t(nx*3); |
110 | fSPDScaleZ[3] = Int_t(nz*3); |
111 | fSPDScaleX[4] = Int_t(nx*4); |
112 | fSPDScaleZ[4] = Int_t(nz*4); |
113 | |
5a5a1232 |
114 | fSDDScaleX[1] = 2; |
115 | fSDDScaleZ[1] = 2; |
116 | fSDDScaleX[2] = 8; |
117 | fSDDScaleZ[2] = 8; |
118 | fSDDScaleX[3] = 16; |
119 | fSDDScaleZ[3] = 16; |
120 | fSDDScaleX[4] = 25; |
121 | fSDDScaleZ[4] = 25; |
122 | |
123 | fSSDScale[1] = 3; |
124 | fSSDScale[2] = 9; |
125 | fSSDScale[3] = 20; |
126 | fSSDScale[4] = 30; |
5a5a1232 |
127 | } |
128 | |
129 | /**************************************************************************/ |
130 | |
d810d0de |
131 | AliEveITSDigitsInfo:: ~AliEveITSDigitsInfo() |
b3bc5327 |
132 | { |
54f770b4 |
133 | // Destructor. |
134 | // Deletes the data-maps and the tree. |
135 | |
b3bc5327 |
136 | map<Int_t, TClonesArray*>::iterator j; |
137 | for(j = fSPDmap.begin(); j != fSPDmap.end(); ++j) |
138 | delete j->second; |
139 | for(j = fSDDmap.begin(); j != fSDDmap.end(); ++j) |
140 | delete j->second; |
141 | for(j = fSSDmap.begin(); j != fSSDmap.end(); ++j) |
142 | delete j->second; |
143 | |
144 | delete fSegSPD; delete fSegSDD; delete fSegSSD; |
145 | delete fGeom; |
146 | delete fTree; |
147 | } |
148 | |
149 | /**************************************************************************/ |
150 | |
d810d0de |
151 | void AliEveITSDigitsInfo::SetTree(TTree* tree) |
b3bc5327 |
152 | { |
153 | // Set digit-tree to be used for digit retrieval. Data is loaded on |
154 | // demand. |
155 | |
156 | fTree = tree; |
157 | } |
158 | |
d810d0de |
159 | void AliEveITSDigitsInfo::ReadRaw(AliRawReader* raw, Int_t mode) |
b3bc5327 |
160 | { |
161 | // Read raw-data into internal structures. AliITSdigit is used to |
162 | // store raw-adata for all sub-detectors. |
163 | |
540e156e |
164 | if ((mode & 1) || (mode & 2)){ |
b3bc5327 |
165 | AliITSRawStreamSPD inputSPD(raw); |
166 | TClonesArray* digits = 0; |
b3bc5327 |
167 | while (inputSPD.Next()) |
168 | { |
169 | Int_t module = inputSPD.GetModuleID(); |
170 | Int_t column = inputSPD.GetColumn(); |
171 | Int_t row = inputSPD.GetRow(); |
172 | |
173 | if (inputSPD.IsNewModule()) |
174 | { |
f8495fba |
175 | digits = fSPDmap[module]; |
176 | if (digits == 0) |
177 | fSPDmap[module] = digits = new TClonesArray("AliITSdigit", 16); |
b3bc5327 |
178 | } |
179 | |
f8495fba |
180 | AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit(); |
b3bc5327 |
181 | d->SetCoord1(column); |
182 | d->SetCoord2(row); |
183 | d->SetSignal(1); |
b3bc5327 |
184 | |
185 | // printf("SPD: %d %d %d\n",module,column,row); |
186 | } |
b3bc5327 |
187 | raw->Reset(); |
188 | } |
189 | |
540e156e |
190 | if ((mode & 4) || (mode & 8)){ |
b3bc5327 |
191 | AliITSRawStreamSDD input(raw); |
192 | TClonesArray* digits = 0; |
b3bc5327 |
193 | while (input.Next()) |
194 | { |
195 | Int_t module = input.GetModuleID(); |
196 | Int_t anode = input.GetAnode(); |
197 | Int_t time = input.GetTime(); |
198 | Int_t signal = input.GetSignal(); |
199 | |
200 | if (input.IsNewModule()) |
201 | { |
f8495fba |
202 | digits = fSDDmap[module]; |
203 | if (digits == 0) |
204 | fSDDmap[module] = digits = new TClonesArray("AliITSdigit", 0); |
b3bc5327 |
205 | } |
206 | |
f8495fba |
207 | AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit(); |
b3bc5327 |
208 | d->SetCoord1(anode); |
209 | d->SetCoord2(time); |
210 | d->SetSignal(signal); |
b3bc5327 |
211 | |
212 | // printf("SDD: %d %d %d %d\n",module,anode,time,signal); |
213 | } |
b3bc5327 |
214 | raw->Reset(); |
215 | } |
216 | |
540e156e |
217 | if ((mode & 16) || (mode & 32)){ |
b3bc5327 |
218 | AliITSRawStreamSSD input(raw); |
219 | TClonesArray* digits = 0; |
b3bc5327 |
220 | while (input.Next()) |
221 | { |
222 | Int_t module = input.GetModuleID(); |
223 | Int_t side = input.GetSideFlag(); |
224 | Int_t strip = input.GetStrip(); |
225 | Int_t signal = input.GetSignal(); |
226 | |
227 | if (input.IsNewModule()) |
228 | { |
f8495fba |
229 | digits = fSSDmap[module]; |
230 | if (digits == 0) |
231 | fSSDmap[module] = digits = new TClonesArray("AliITSdigit", 0); |
b3bc5327 |
232 | } |
233 | |
f8495fba |
234 | AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit(); |
b3bc5327 |
235 | d->SetCoord1(side); |
236 | d->SetCoord2(strip); |
237 | d->SetSignal(signal); |
b3bc5327 |
238 | |
239 | // printf("SSD: %d %d %d %d\n",module,side,strip,signal); |
240 | } |
b3bc5327 |
241 | raw->Reset(); |
242 | } |
243 | } |
244 | |
245 | /**************************************************************************/ |
246 | |
d810d0de |
247 | void AliEveITSDigitsInfo::SetITSSegmentation() |
5a5a1232 |
248 | { |
54f770b4 |
249 | // Create the segmentation objects and fill internal |
250 | // data-structures. |
251 | |
5a5a1232 |
252 | // SPD |
253 | fSegSPD = new AliITSsegmentationSPD(fGeom); |
54f770b4 |
254 | |
5a5a1232 |
255 | Int_t m; |
256 | Float_t fNzSPD=160; |
257 | Float_t fZ1pitchSPD=0.0425; Float_t fZ2pitchSPD=0.0625; |
258 | Float_t fHlSPD=3.48; |
259 | |
260 | fSPDZCoord[0]=fZ1pitchSPD -fHlSPD; |
261 | for (m=1; m<fNzSPD; m++) { |
262 | Double_t dz=fZ1pitchSPD; |
263 | if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 || |
264 | m==127 || m==128) dz=fZ2pitchSPD; |
265 | fSPDZCoord[m]=fSPDZCoord[m-1]+dz; |
266 | } |
267 | |
268 | for (m=0; m<fNzSPD; m++) { |
269 | Double_t dz=1.*fZ1pitchSPD; |
270 | if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 || |
271 | m==127 || m==128) dz=1.*fZ2pitchSPD; |
272 | fSPDZCoord[m]-=dz; |
273 | } |
54f770b4 |
274 | |
5a5a1232 |
275 | // SDD |
b85e8cbd |
276 | fSegSDD = new AliITSsegmentationSDD(fGeom); |
5a5a1232 |
277 | |
278 | // SSD |
279 | fSegSSD = new AliITSsegmentationSSD(fGeom); |
280 | } |
281 | |
5a5a1232 |
282 | /**************************************************************************/ |
283 | |
d810d0de |
284 | TClonesArray* AliEveITSDigitsInfo::GetDigits(Int_t mod, Int_t subdet) |
5a5a1232 |
285 | { |
54f770b4 |
286 | // Return TClonesArray of digits for specified module and sub-detector-id. |
287 | |
288 | switch(subdet) |
289 | { |
290 | case 0: |
291 | { |
6ddaaee3 |
292 | TClonesArray* digitsSPD = 0; |
293 | map<Int_t, TClonesArray*>::iterator i = fSPDmap.find(mod); |
54f770b4 |
294 | if (i == fSPDmap.end()) { |
540e156e |
295 | if (fTree) { |
296 | TBranch* br = fTree->GetBranch("ITSDigitsSPD"); |
297 | br->SetAddress(&digitsSPD); |
298 | br->GetEntry(mod); |
299 | fSPDmap[mod] = digitsSPD; |
300 | return digitsSPD; |
301 | } |
302 | else |
303 | return NULL; |
6ddaaee3 |
304 | } else { |
305 | return i->second; |
306 | } |
307 | break; |
5a5a1232 |
308 | } |
54f770b4 |
309 | case 1: |
310 | { |
6ddaaee3 |
311 | TClonesArray* digitsSDD = 0; |
312 | map<Int_t, TClonesArray*>::iterator i = fSDDmap.find(mod); |
54f770b4 |
313 | if (i == fSDDmap.end()) { |
540e156e |
314 | if (fTree) { |
315 | TBranch* br = fTree->GetBranch("ITSDigitsSDD"); |
316 | br->SetAddress(&digitsSDD); |
317 | br->GetEntry(mod); |
318 | fSDDmap[mod] = digitsSDD; |
319 | return digitsSDD; |
320 | } |
321 | else |
322 | return NULL; |
323 | } else { |
6ddaaee3 |
324 | return i->second; |
325 | } |
326 | break; |
5a5a1232 |
327 | } |
54f770b4 |
328 | case 2: |
329 | { |
6ddaaee3 |
330 | TClonesArray* digitsSSD = 0; |
331 | map<Int_t, TClonesArray*>::iterator i = fSSDmap.find(mod); |
54f770b4 |
332 | if (i == fSSDmap.end()) { |
540e156e |
333 | if (fTree) { |
334 | TBranch* br = fTree->GetBranch("ITSDigitsSSD"); |
335 | br->SetAddress(&digitsSSD); |
336 | br->GetEntry(mod); |
337 | |
338 | fSSDmap[mod] = digitsSSD; |
339 | return digitsSSD; |
340 | } |
341 | else |
342 | return NULL; |
343 | } else { |
6ddaaee3 |
344 | return i->second; |
345 | } |
346 | break; |
5a5a1232 |
347 | } |
6ddaaee3 |
348 | default: |
349 | return 0; |
54f770b4 |
350 | } |
03ecfe88 |
351 | return 0; |
5a5a1232 |
352 | } |
353 | |
3d598e88 |
354 | /**************************************************************************/ |
54f770b4 |
355 | |
356 | void AliEveITSDigitsInfo::GetModuleIDs(AliEveITSModuleSelection* sel, |
357 | std::vector<UInt_t>& ids) |
3d598e88 |
358 | { |
54f770b4 |
359 | // Fill the id-vector with ids of modules that satisfy conditions |
360 | // given by the AliEveITSModuleSelection object. |
361 | |
3d598e88 |
362 | Int_t idx0 = 0, idx1 = 0; |
363 | switch(sel->fType) |
364 | { |
365 | case 0: |
366 | idx0 = 0; |
367 | idx1 = fGeom->GetLastSPD(); |
368 | break; |
369 | case 1: |
32e219c2 |
370 | idx0 = fGeom->GetLastSPD()+1; |
3d598e88 |
371 | idx1 = fGeom->GetLastSDD(); |
372 | break; |
373 | case 2: |
32e219c2 |
374 | idx0 = fGeom->GetLastSDD()+1; |
3d598e88 |
375 | idx1 = fGeom->GetLastSSD(); |
376 | break; |
377 | default: |
378 | idx1 = 0; |
379 | idx1 = fGeom->GetLastSSD(); |
54f770b4 |
380 | break; |
3d598e88 |
381 | } |
382 | |
383 | TVector3 v; |
384 | Double_t x[9]; |
385 | Int_t lay, lad, det; |
84aff7a4 |
386 | TEveTrans mx; |
54f770b4 |
387 | for (Int_t id = idx0; id<idx1; ++id) |
388 | { |
3d598e88 |
389 | fGeom->GetModuleId(id, lay, lad, det); |
54f770b4 |
390 | if (sel->fLayer == lay || sel->fLayer == -1) |
3d598e88 |
391 | { |
392 | // check data from matrix |
393 | mx.UnitTrans(); |
394 | fGeom->GetRotMatrix(id, x); |
395 | mx.SetBaseVec(1, x[0], x[3], x[6]); |
396 | mx.SetBaseVec(2, x[1], x[4], x[7]); |
397 | mx.SetBaseVec(3, x[2], x[5], x[8]); |
398 | fGeom->GetTrans(id, x); |
399 | mx.SetBaseVec(4, x); |
400 | mx.GetPos(v); |
54f770b4 |
401 | if (v.Phi() <= sel->fMaxPhi && v.Phi() >= sel->fMinPhi && |
402 | v.Theta() <= sel->fMaxTheta && v.Theta() >= sel->fMinTheta) |
403 | { |
3d598e88 |
404 | ids.push_back(id); |
54f770b4 |
405 | } |
3d598e88 |
406 | } |
407 | } |
408 | } |
5a5a1232 |
409 | |
410 | /**************************************************************************/ |
411 | |
d810d0de |
412 | void AliEveITSDigitsInfo::Print(Option_t* ) const |
5a5a1232 |
413 | { |
54f770b4 |
414 | // Print information about stored geometry and segmentation. |
415 | |
5a5a1232 |
416 | printf("*********************************************************\n"); |
54f770b4 |
417 | printf("SPD module dimension (%f,%f)\n", fSegSPD->Dx()*0.0001, fSegSPD->Dz()*0.0001); |
418 | printf("SPD first,last module:: %d,%d\n", fGeom->GetStartSPD(), fGeom->GetLastSPD() ); |
419 | printf("SPD num cells per module (x::%d,z::%d)\n", fSegSPD->Npx(), fSegSPD->Npz()); |
420 | Int_t iz = 0, ix = 0; |
421 | printf("SPD dimesion of (%d,%d) in pixel(%f,%f)\n", ix, iz, fSegSPD->Dpx(ix), fSegSPD->Dpz(iz)); |
5a5a1232 |
422 | iz = 32; |
54f770b4 |
423 | printf("SPD dimesion of pixel (%d,%d) are (%f,%f)\n", ix, iz, fSegSPD->Dpx(ix)*0.001, fSegSPD->Dpz(iz)*0.001); |
5a5a1232 |
424 | |
425 | printf("*********************************************************\n"); |
54f770b4 |
426 | printf("SDD module dimension (%f,%f)\n", fSegSDD->Dx()*0.0001, fSegSDD->Dz()*0.0001); |
427 | printf("SDD first,last module:: %d,%d\n", fGeom->GetStartSDD(), fGeom->GetLastSDD()); |
428 | printf("SDD num cells per module (x::%d,z::%d)\n", fSegSDD->Npx(), fSegSDD->Npz()); |
429 | printf("SDD dimesion of pixel are (%f,%f)\n", fSegSDD->Dpx(1)*0.001, fSegSDD->Dpz(1)*0.001); |
430 | |
431 | Float_t ap, an; |
5a5a1232 |
432 | printf("*********************************************************\n"); |
54f770b4 |
433 | printf("SSD module dimension (%f,%f)\n", fSegSSD->Dx()*0.0001, fSegSSD->Dz()*0.0001); |
434 | printf("SSD first,last module:: %d,%d\n", fGeom->GetStartSSD(), fGeom->GetLastSSD() ); |
435 | printf("SSD strips in module %d\n", fSegSSD->Npx()); |
436 | printf("SSD strip sizes are (%f,%f)\n", fSegSSD->Dpx(1), fSegSSD->Dpz(1)); |
437 | fSegSSD->SetLayer(5); fSegSSD->Angles(ap,an); |
438 | printf("SSD layer 5 stereoP %f stereoN %f angle\n", ap, an); |
5a5a1232 |
439 | fSegSSD->SetLayer(6); fSegSSD->Angles(ap,an); |
54f770b4 |
440 | printf("SSD layer 6 stereoP %f stereoN %f angle\n", ap, an); |
5a5a1232 |
441 | } |
442 | |
443 | |
444 | /* |
445 | printf("num cells %d,%d scaled %d,%d \n",fSegSPD->Npz(),fSegSPD->Npx(),Nz,Nx); |
d810d0de |
446 | printf("%d digits in AliEveITSModule %d\n",ne, module); |
5a5a1232 |
447 | Float_t zn = i*(3.48*2)/Nz - 3.48 ; |
448 | Float_t xo = -fSegSPD->Dx()*0.00005 + fSegSPD->Dpx(0)*od->GetCoord2()*0.0001; |
449 | Float_t xn = -fSegSPD->Dx()*0.00005 + j*0.0001*fSegSPD->Dx()/Nx; |
450 | Float_t dpx = 0.0001*fSegSPD->Dx()/Nx; |
451 | Float_t dpz = 3.48*2/Nz; |
452 | printf("Z::original (%3f) scaled (%3f, %3f) \n", zo, zn-dpz/2, zn+dpz/2); |
453 | printf("X::original (%3f) scaled (%3f, %3f) \n", xo, xn-dpx/2, xn+dpx/2); |
454 | printf("%d,%d maped to %d,%d \n", od->GetCoord1(), od->GetCoord2(), i,j ); |
455 | */ |