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