Add functions to show spd/sdd/ssd only.
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveITSDigitsInfo.cxx
CommitLineData
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 *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
5a5a1232 9
0879c50b 10#include "AliEveITSDigitsInfo.h"
11#include <EveBase/AliEveEventManager.h>
5a5a1232 12
0879c50b 13#include <AliITS.h>
14#include <AliITSInitGeometry.h>
12f6a2f3 15#include <AliITSgeomTGeo.h>
0879c50b 16#include <AliITSsegmentationSPD.h>
17#include <AliITSsegmentationSDD.h>
18#include <AliITSsegmentationSSD.h>
19#include <AliITSDDLModuleMapSDD.h>
20
5a5a1232 21#include <AliITSCalibrationSDD.h>
22#include <AliITSdigit.h>
23#include <AliITSdigitSPD.h>
24
0879c50b 25#include <AliCDBEntry.h>
26#include <AliCDBManager.h>
27
b3bc5327 28#include <AliRawReader.h>
29#include <AliITSRawStreamSPD.h>
30#include <AliITSRawStreamSDD.h>
74917814 31#include <AliITSRawStreamSDDCompressed.h>
b3bc5327 32#include <AliITSRawStreamSSD.h>
d810d0de 33
12f6a2f3 34#include <TGeoMatrix.h>
a15e6d7d 35#include <TEveTrans.h>
a15e6d7d 36
0879c50b 37#include <TMath.h>
38#include <TVector3.h>
39
a15e6d7d 40//==============================================================================
41//==============================================================================
42// AliEveITSModuleSelection
43//==============================================================================
44
54f770b4 45//______________________________________________________________________________
46//
47// Helper for selecting a range of ITS modules by type, layer, phi and
48// theta. Taken as an argument to AliEveITSDigitsInfo::GetModuleIDs().
3d598e88 49
d810d0de 50ClassImp(AliEveITSModuleSelection)
3d598e88 51
d810d0de 52AliEveITSModuleSelection::AliEveITSModuleSelection():
3d598e88 53 fType(-1),
54 fLayer(-1),
32e219c2 55 fMinPhi(-TMath::Pi()),
56 fMaxPhi(TMath::Pi()),
57 fMinTheta(-TMath::Pi()),
58 fMaxTheta(TMath::Pi())
54f770b4 59{
60 // Constructor.
61}
62
b3bc5327 63
a15e6d7d 64//==============================================================================
65//==============================================================================
66// AliEveITSDigitsInfo
67//==============================================================================
68
54f770b4 69//______________________________________________________________________________
70//
71// Stores ITS geometry information and event-data in format suitable
72// for visualization.
3d598e88 73
d810d0de 74ClassImp(AliEveITSDigitsInfo)
5a5a1232 75
4516a822 76AliITSDDLModuleMapSDD* AliEveITSDigitsInfo::fgDDLMapSDD = 0;
77
57ffa5fb 78/******************************************************************************/
5a5a1232 79
d810d0de 80AliEveITSDigitsInfo::AliEveITSDigitsInfo() :
265ecb21 81 TObject(),
84aff7a4 82 TEveRefCnt(),
9af86b69 83 fTree (0),
fd31e9de 84 fSegSPD (0), fSegSDD (0), fSegSSD (0),
c76ea574 85 fSPDMinVal (0), fSSDMinVal (0), fSDDMinVal (0),
86 fSPDMaxVal (0), fSSDMaxVal (0), fSDDMaxVal (0),
9af86b69 87 fSPDHighLim (0), fSDDHighLim (0), fSSDHighLim (0),
88 fSPDmap (), fSDDmap (), fSSDmap ()
5a5a1232 89{
54f770b4 90 // Default constructor.
91
b3bc5327 92 InitInternals();
5a5a1232 93}
94
d810d0de 95void AliEveITSDigitsInfo::InitInternals()
5a5a1232 96{
54f770b4 97 // Initialize internal geometry structures, in particular the
98 // module-id to transformation-matrix mapping and segmentation
99 // classes and data-structures.
100
a15e6d7d 101 static const TEveException kEH("AliEveITSDigitsInfo::InitInternals ");
5a5a1232 102
0879c50b 103 AliEveEventManager::AssertGeometry();
5a5a1232 104
105 SetITSSegmentation();
d4b6a94c 106
5a5a1232 107 // create tables for scaling
d4b6a94c 108 fSPDMinVal = 0;
109 fSDDMinVal = 5;
110 fSSDMinVal = 2;
111
112 fSPDMaxVal = 1;
113 fSDDMaxVal = 80;
114 fSSDMaxVal = 100;
115
32e219c2 116 fSPDHighLim = 1;
117 fSDDHighLim = 512;
118 fSSDHighLim = 1024;
d4b6a94c 119
d54c094e 120 // lowest scale factor refers to unscaled ITS module
121 fSPDScaleX[0] = 1;
122 fSPDScaleZ[0] = 1;
123 fSDDScaleX[0] = 1;
124 fSDDScaleZ[0] = 1;
125 fSSDScale [0] = 1;
d4b6a94c 126
b3bc5327 127 // spd lowest resolution
5a5a1232 128 Int_t nx = 8; // fSegSPD->Npx()/8; // 32
129 Int_t nz = 6; // fSegSPD->Npz()/2; // 128
51346b82 130 fSPDScaleX[1] = Int_t(nx);
131 fSPDScaleZ[1] = Int_t(nz);
132 fSPDScaleX[2] = Int_t(nx*2);
133 fSPDScaleZ[2] = Int_t(nz*2);
134 fSPDScaleX[3] = Int_t(nx*3);
135 fSPDScaleZ[3] = Int_t(nz*3);
136 fSPDScaleX[4] = Int_t(nx*4);
137 fSPDScaleZ[4] = Int_t(nz*4);
5a5a1232 138
5a5a1232 139 fSDDScaleX[1] = 2;
140 fSDDScaleZ[1] = 2;
141 fSDDScaleX[2] = 8;
142 fSDDScaleZ[2] = 8;
143 fSDDScaleX[3] = 16;
144 fSDDScaleZ[3] = 16;
145 fSDDScaleX[4] = 25;
146 fSDDScaleZ[4] = 25;
147
148 fSSDScale[1] = 3;
149 fSSDScale[2] = 9;
150 fSSDScale[3] = 20;
151 fSSDScale[4] = 30;
4516a822 152
153 if (fgDDLMapSDD == 0)
154 {
155 fgDDLMapSDD = new AliITSDDLModuleMapSDD();
156 AliCDBManager *man = AliCDBManager::Instance();
157 Bool_t cacheStatus = man->GetCacheFlag();
158 AliCDBEntry *ddlMapSDD = man->Get("ITS/Calib/DDLMapSDD");
159
160 if (!ddlMapSDD)
161 {
162 AliWarning("SDD DDL map file retrieval from OCDB failed! - Use default DDL map");
163 }
164 else
165 {
166 AliITSDDLModuleMapSDD *ddlsdd = (AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
167 if (!ddlsdd)
168 {
169 AliWarning("SDD DDL map object not found in OCDB file! - Use default DDL map");
170 }
171 else
172 {
173 if (!cacheStatus)
174 ddlMapSDD->SetObject(0);
175 ddlMapSDD->SetOwner(kTRUE);
176 fgDDLMapSDD->SetDDLMap(ddlsdd);
177 }
0879c50b 178 }
4516a822 179
180 if (!cacheStatus)
181 delete ddlMapSDD;
0879c50b 182 }
5a5a1232 183}
184
57ffa5fb 185/******************************************************************************/
5a5a1232 186
4516a822 187AliEveITSDigitsInfo::~AliEveITSDigitsInfo()
b3bc5327 188{
54f770b4 189 // Destructor.
2452f391 190 // Deletes the data-maps.
191 // The tree, if it was passed into the object, is not touched.
54f770b4 192
fd31e9de 193 std::map<Int_t, TClonesArray*>::iterator j;
0879c50b 194 for (j = fSPDmap.begin(); j != fSPDmap.end(); ++j)
b3bc5327 195 delete j->second;
0879c50b 196 for (j = fSDDmap.begin(); j != fSDDmap.end(); ++j)
b3bc5327 197 delete j->second;
0879c50b 198 for (j = fSSDmap.begin(); j != fSSDmap.end(); ++j)
b3bc5327 199 delete j->second;
4516a822 200
51346b82 201 delete fSegSPD; delete fSegSDD; delete fSegSSD;
b3bc5327 202}
203
57ffa5fb 204/******************************************************************************/
b3bc5327 205
d810d0de 206void AliEveITSDigitsInfo::SetTree(TTree* tree)
b3bc5327 207{
208 // Set digit-tree to be used for digit retrieval. Data is loaded on
209 // demand.
210
211 fTree = tree;
212}
213
d810d0de 214void AliEveITSDigitsInfo::ReadRaw(AliRawReader* raw, Int_t mode)
b3bc5327 215{
216 // Read raw-data into internal structures. AliITSdigit is used to
217 // store raw-adata for all sub-detectors.
218
0879c50b 219 if ((mode & 1) || (mode & 2))
220 {
b3bc5327 221 AliITSRawStreamSPD inputSPD(raw);
222 TClonesArray* digits = 0;
b3bc5327 223 while (inputSPD.Next())
224 {
225 Int_t module = inputSPD.GetModuleID();
226 Int_t column = inputSPD.GetColumn();
227 Int_t row = inputSPD.GetRow();
51346b82 228
b3bc5327 229 if (inputSPD.IsNewModule())
230 {
f8495fba 231 digits = fSPDmap[module];
232 if (digits == 0)
233 fSPDmap[module] = digits = new TClonesArray("AliITSdigit", 16);
b3bc5327 234 }
235
f8495fba 236 AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
b3bc5327 237 d->SetCoord1(column);
238 d->SetCoord2(row);
239 d->SetSignal(1);
b3bc5327 240
241 // printf("SPD: %d %d %d\n",module,column,row);
242 }
b3bc5327 243 raw->Reset();
244 }
245
0879c50b 246 if ((mode & 4) || (mode & 8))
247 {
4516a822 248 AliITSRawStream* inputSDD = AliITSRawStreamSDD::CreateRawStreamSDD(raw);
249 inputSDD->SetDDLModuleMap(fgDDLMapSDD);
b3bc5327 250 TClonesArray* digits = 0;
74917814 251 while (inputSDD->Next())
b3bc5327 252 {
74917814 253 Int_t module = inputSDD->GetModuleID();
b3bc5327 254
74917814 255 digits = fSDDmap[module];
256 if (digits == 0)
257 fSDDmap[module] = digits = new TClonesArray("AliITSdigit", 0);
b3bc5327 258
74917814 259 if (inputSDD->IsCompletedModule()==kFALSE && inputSDD->IsCompletedDDL()==kFALSE)
cb35cec3 260 {
74917814 261 Int_t anode = inputSDD->GetCoord1()+inputSDD->GetChannel()*AliITSsegmentationSDD::GetNAnodesPerHybrid();
262 Int_t time = inputSDD->GetCoord2();
263 Int_t signal = inputSDD->GetSignal();
cb35cec3 264 AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
265 d->SetCoord1(anode);
266 d->SetCoord2(time);
267 d->SetSignal(signal);
268 }
b3bc5327 269 // printf("SDD: %d %d %d %d\n",module,anode,time,signal);
270 }
74917814 271 delete inputSDD;
b3bc5327 272 raw->Reset();
273 }
274
0879c50b 275 if ((mode & 16) || (mode & 32))
276 {
b3bc5327 277 AliITSRawStreamSSD input(raw);
278 TClonesArray* digits = 0;
b3bc5327 279 while (input.Next())
280 {
281 Int_t module = input.GetModuleID();
282 Int_t side = input.GetSideFlag();
283 Int_t strip = input.GetStrip();
284 Int_t signal = input.GetSignal();
285
20807c14 286 // !!!! IsNewModule() is false in the beginning of the stream, so we also
287 // !!!! check for digits == 0. Should be fixed in SSD stream.
288 if (input.IsNewModule() || digits == 0)
b3bc5327 289 {
f8495fba 290 digits = fSSDmap[module];
291 if (digits == 0)
292 fSSDmap[module] = digits = new TClonesArray("AliITSdigit", 0);
b3bc5327 293 }
294
f8495fba 295 AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
b3bc5327 296 d->SetCoord1(side);
297 d->SetCoord2(strip);
298 d->SetSignal(signal);
b3bc5327 299
300 // printf("SSD: %d %d %d %d\n",module,side,strip,signal);
301 }
b3bc5327 302 raw->Reset();
303 }
304}
305
57ffa5fb 306/******************************************************************************/
b3bc5327 307
d810d0de 308void AliEveITSDigitsInfo::SetITSSegmentation()
5a5a1232 309{
54f770b4 310 // Create the segmentation objects and fill internal
311 // data-structures.
312
5a5a1232 313 // SPD
c93f2d9b 314 fSegSPD = new AliITSsegmentationSPD("TGeo");
54f770b4 315
4516a822 316 Float_t fNzSPD = 160;
317 Float_t fHlSPD = 3.48;
318 Float_t fZ1pitchSPD = 0.0425, fZ2pitchSPD = 0.0625;
5a5a1232 319
8cc1d3b4 320 fSPDZCoord[0] = fZ1pitchSPD - fHlSPD;
4516a822 321 for (Int_t m=1; m<fNzSPD; m++)
322 {
323 Float_t dz = fZ1pitchSPD;
324 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 || m==127 || m==128)
325 {
326 dz = fZ2pitchSPD;
327 }
328 fSPDZCoord[m] = fSPDZCoord[m-1] + dz;
5a5a1232 329 }
51346b82 330
4516a822 331 for (Int_t m=0; m<fNzSPD; m++)
332 {
333 Float_t dz = fZ1pitchSPD;
334 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 || m==127 || m==128)
335 {
336 dz = fZ2pitchSPD;
337 }
338 fSPDZCoord[m] -= dz;
5a5a1232 339 }
51346b82 340
5a5a1232 341 // SDD
c93f2d9b 342 fSegSDD = new AliITSsegmentationSDD("TGeo");
0879c50b 343 // !!!! Set default drift speed, eventually need to get it from CDB.
344 fSegSDD->SetDriftSpeed(7.3);
5a5a1232 345
346 // SSD
c93f2d9b 347 fSegSSD = new AliITSsegmentationSSD("TGeo");
5a5a1232 348}
349
57ffa5fb 350/******************************************************************************/
5a5a1232 351
d810d0de 352TClonesArray* AliEveITSDigitsInfo::GetDigits(Int_t mod, Int_t subdet)
5a5a1232 353{
54f770b4 354 // Return TClonesArray of digits for specified module and sub-detector-id.
355
356 switch(subdet)
357 {
358 case 0:
359 {
fd31e9de 360 std::map<Int_t, TClonesArray*>::iterator i = fSPDmap.find(mod);
4516a822 361 if (i != fSPDmap.end())
362 {
6ddaaee3 363 return i->second;
364 }
4516a822 365 else if (fTree)
366 {
367 TClonesArray *digitsSPD = 0;
368 TBranch *br = fTree->GetBranch("ITSDigitsSPD");
369 br->SetAddress(&digitsSPD);
370 br->GetEntry(mod);
371 fSPDmap[mod] = digitsSPD;
372 return digitsSPD;
373 }
6ddaaee3 374 break;
5a5a1232 375 }
4516a822 376
54f770b4 377 case 1:
378 {
fd31e9de 379 std::map<Int_t, TClonesArray*>::iterator i = fSDDmap.find(mod);
4516a822 380 if (i != fSDDmap.end())
381 {
6ddaaee3 382 return i->second;
383 }
4516a822 384 else if (fTree)
385 {
386 TClonesArray *digitsSDD = 0;
387 TBranch *br = fTree->GetBranch("ITSDigitsSDD");
388 br->SetAddress(&digitsSDD);
389 br->GetEntry(mod);
390 fSDDmap[mod] = digitsSDD;
391 return digitsSDD;
392 }
6ddaaee3 393 break;
5a5a1232 394 }
4516a822 395
54f770b4 396 case 2:
397 {
fd31e9de 398 std::map<Int_t, TClonesArray*>::iterator i = fSSDmap.find(mod);
4516a822 399 if (i != fSSDmap.end())
400 {
6ddaaee3 401 return i->second;
402 }
4516a822 403 else if (fTree)
404 {
405 TClonesArray *digitsSSD = 0;
406 TBranch *br = fTree->GetBranch("ITSDigitsSSD");
407 br->SetAddress(&digitsSSD);
408 br->GetEntry(mod);
409 fSSDmap[mod] = digitsSSD;
410 return digitsSSD;
411 }
6ddaaee3 412 break;
5a5a1232 413 }
54f770b4 414 }
4516a822 415
03ecfe88 416 return 0;
5a5a1232 417}
418
57ffa5fb 419/******************************************************************************/
54f770b4 420
421void AliEveITSDigitsInfo::GetModuleIDs(AliEveITSModuleSelection* sel,
422 std::vector<UInt_t>& ids)
3d598e88 423{
54f770b4 424 // Fill the id-vector with ids of modules that satisfy conditions
425 // given by the AliEveITSModuleSelection object.
426
3d598e88 427 Int_t idx0 = 0, idx1 = 0;
51346b82 428 switch(sel->GetType())
3d598e88 429 {
430 case 0:
431 idx0 = 0;
12f6a2f3 432 idx1 = AliITSgeomTGeo::GetModuleIndex(3, 1, 1) - 1;
3d598e88 433 break;
434 case 1:
12f6a2f3 435 idx0 = AliITSgeomTGeo::GetModuleIndex(3, 1, 1);
436 idx1 = AliITSgeomTGeo::GetModuleIndex(5, 1, 1) - 1;
3d598e88 437 break;
438 case 2:
12f6a2f3 439 idx0 = AliITSgeomTGeo::GetModuleIndex(5, 1, 1);
440 idx1 = AliITSgeomTGeo::GetNModules() - 1;
3d598e88 441 break;
442 default:
443 idx1 = 0;
12f6a2f3 444 idx1 = AliITSgeomTGeo::GetNModules() - 1;
54f770b4 445 break;
3d598e88 446 }
447
12f6a2f3 448 TVector3 v;
84aff7a4 449 TEveTrans mx;
12f6a2f3 450 Int_t lay, lad, det;
451 for (Int_t id = idx0; id < idx1; ++id)
54f770b4 452 {
12f6a2f3 453 AliITSgeomTGeo::GetModuleId(id, lay, lad, det);
51346b82 454 if (sel->GetLayer() == lay || sel->GetLayer() == -1)
3d598e88 455 {
456 // check data from matrix
12f6a2f3 457 mx.SetFrom(*AliITSgeomTGeo::GetMatrix(id));
3d598e88 458 mx.GetPos(v);
51346b82 459 if (v.Phi() <= sel->GetMaxPhi() && v.Phi() >= sel->GetMinPhi() &&
460 v.Theta() <= sel->GetMaxTheta() && v.Theta() >= sel->GetMinTheta())
54f770b4 461 {
3d598e88 462 ids.push_back(id);
54f770b4 463 }
3d598e88 464 }
465 }
466}
5a5a1232 467
57ffa5fb 468/******************************************************************************/
5a5a1232 469
d810d0de 470void AliEveITSDigitsInfo::Print(Option_t* ) const
5a5a1232 471{
54f770b4 472 // Print information about stored geometry and segmentation.
473
5a5a1232 474 printf("*********************************************************\n");
54f770b4 475 printf("SPD module dimension (%f,%f)\n", fSegSPD->Dx()*0.0001, fSegSPD->Dz()*0.0001);
12f6a2f3 476 printf("SPD first,last module: %d, %d\n",
477 AliITSgeomTGeo::GetModuleIndex(1,1,1),
478 AliITSgeomTGeo::GetModuleIndex(3,1,1) - 1);
54f770b4 479 printf("SPD num cells per module (x::%d,z::%d)\n", fSegSPD->Npx(), fSegSPD->Npz());
480 Int_t iz = 0, ix = 0;
481 printf("SPD dimesion of (%d,%d) in pixel(%f,%f)\n", ix, iz, fSegSPD->Dpx(ix), fSegSPD->Dpz(iz));
5a5a1232 482 iz = 32;
54f770b4 483 printf("SPD dimesion of pixel (%d,%d) are (%f,%f)\n", ix, iz, fSegSPD->Dpx(ix)*0.001, fSegSPD->Dpz(iz)*0.001);
51346b82 484
5a5a1232 485 printf("*********************************************************\n");
54f770b4 486 printf("SDD module dimension (%f,%f)\n", fSegSDD->Dx()*0.0001, fSegSDD->Dz()*0.0001);
12f6a2f3 487 printf("SDD first,last module: %d, %d\n",
488 AliITSgeomTGeo::GetModuleIndex(3,1,1),
489 AliITSgeomTGeo::GetModuleIndex(5,1,1) - 1);
54f770b4 490 printf("SDD num cells per module (x::%d,z::%d)\n", fSegSDD->Npx(), fSegSDD->Npz());
491 printf("SDD dimesion of pixel are (%f,%f)\n", fSegSDD->Dpx(1)*0.001, fSegSDD->Dpz(1)*0.001);
492
493 Float_t ap, an;
5a5a1232 494 printf("*********************************************************\n");
54f770b4 495 printf("SSD module dimension (%f,%f)\n", fSegSSD->Dx()*0.0001, fSegSSD->Dz()*0.0001);
12f6a2f3 496 printf("SSD first, last module: %d, %d\n",
497 AliITSgeomTGeo::GetModuleIndex(5,1,1),
498 AliITSgeomTGeo::GetNModules() - 1);
54f770b4 499 printf("SSD strips in module %d\n", fSegSSD->Npx());
500 printf("SSD strip sizes are (%f,%f)\n", fSegSSD->Dpx(1), fSegSSD->Dpz(1));
501 fSegSSD->SetLayer(5); fSegSSD->Angles(ap,an);
51346b82 502 printf("SSD layer 5 stereoP %f stereoN %f angle\n", ap, an);
5a5a1232 503 fSegSSD->SetLayer(6); fSegSSD->Angles(ap,an);
51346b82 504 printf("SSD layer 6 stereoP %f stereoN %f angle\n", ap, an);
5a5a1232 505}
506
507
508/*
509 printf("num cells %d,%d scaled %d,%d \n",fSegSPD->Npz(),fSegSPD->Npx(),Nz,Nx);
d810d0de 510 printf("%d digits in AliEveITSModule %d\n",ne, module);
5a5a1232 511 Float_t zn = i*(3.48*2)/Nz - 3.48 ;
512 Float_t xo = -fSegSPD->Dx()*0.00005 + fSegSPD->Dpx(0)*od->GetCoord2()*0.0001;
513 Float_t xn = -fSegSPD->Dx()*0.00005 + j*0.0001*fSegSPD->Dx()/Nx;
514 Float_t dpx = 0.0001*fSegSPD->Dx()/Nx;
515 Float_t dpz = 3.48*2/Nz;
516 printf("Z::original (%3f) scaled (%3f, %3f) \n", zo, zn-dpz/2, zn+dpz/2);
517 printf("X::original (%3f) scaled (%3f, %3f) \n", xo, xn-dpx/2, xn+dpx/2);
518 printf("%d,%d maped to %d,%d \n", od->GetCoord1(), od->GetCoord2(), i,j );
51346b82 519*/