2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
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 **************************************************************************/
10 #include "AliEveITSDigitsInfo.h"
11 #include <EveBase/AliEveEventManager.h>
14 #include <AliITSInitGeometry.h>
15 #include <AliITSgeomTGeo.h>
16 #include <AliITSsegmentationSPD.h>
17 #include <AliITSsegmentationSDD.h>
18 #include <AliITSsegmentationSSD.h>
19 #include <AliITSDDLModuleMapSDD.h>
21 #include <AliITSCalibrationSPD.h>
22 #include <AliITSCalibrationSDD.h>
23 #include <AliITSCalibrationSSD.h>
24 #include <AliITSdigit.h>
25 #include <AliITSdigitSPD.h>
27 #include <AliCDBEntry.h>
28 #include <AliCDBManager.h>
30 #include <AliRawReader.h>
31 #include <AliITSRawStreamSPD.h>
32 #include <AliITSRawStreamSDD.h>
33 #include <AliITSRawStreamSDDCompressed.h>
34 #include <AliITSRawStreamSSD.h>
36 #include <TGeoMatrix.h>
37 #include <TEveTrans.h>
42 //==============================================================================
43 //==============================================================================
44 // AliEveITSModuleSelection
45 //==============================================================================
47 //______________________________________________________________________________
49 // Helper for selecting a range of ITS modules by type, layer, phi and
50 // theta. Taken as an argument to AliEveITSDigitsInfo::GetModuleIDs().
52 ClassImp(AliEveITSModuleSelection)
54 AliEveITSModuleSelection::AliEveITSModuleSelection():
57 fMinPhi(-TMath::Pi()),
59 fMinTheta(-TMath::Pi()),
60 fMaxTheta(TMath::Pi())
66 //==============================================================================
67 //==============================================================================
68 // AliEveITSDigitsInfo
69 //==============================================================================
71 //______________________________________________________________________________
73 // Stores ITS geometry information and event-data in format suitable
76 ClassImp(AliEveITSDigitsInfo)
78 AliITSDDLModuleMapSDD *AliEveITSDigitsInfo::fgDDLMapSDD = 0;
79 TObjArray *AliEveITSDigitsInfo::fgDeadModSPD = 0;
80 TObjArray *AliEveITSDigitsInfo::fgDeadModSDD = 0;
81 TObjArray *AliEveITSDigitsInfo::fgDeadModSSD = 0;
83 /******************************************************************************/
85 AliEveITSDigitsInfo::AliEveITSDigitsInfo() :
89 fSegSPD (0), fSegSDD (0), fSegSSD (0),
90 fSPDMinVal (0), fSSDMinVal (0), fSDDMinVal (0),
91 fSPDMaxVal (0), fSSDMaxVal (0), fSDDMaxVal (0),
92 fSPDHighLim (0), fSDDHighLim (0), fSSDHighLim (0),
93 fSPDmap (), fSDDmap (), fSSDmap ()
95 // Default constructor.
100 void AliEveITSDigitsInfo::InitInternals()
102 // Initialize internal geometry structures, in particular the
103 // module-id to transformation-matrix mapping and segmentation
104 // classes and data-structures.
106 static const TEveException kEH("AliEveITSDigitsInfo::InitInternals ");
108 AliEveEventManager::AssertGeometry();
110 SetITSSegmentation();
112 // create tables for scaling
125 // lowest scale factor refers to unscaled ITS module
132 // spd lowest resolution
133 Int_t nx = 8; // fSegSPD->Npx()/8; // 32
134 Int_t nz = 6; // fSegSPD->Npz()/2; // 128
135 fSPDScaleX[1] = Int_t(nx);
136 fSPDScaleZ[1] = Int_t(nz);
137 fSPDScaleX[2] = Int_t(nx*2);
138 fSPDScaleZ[2] = Int_t(nz*2);
139 fSPDScaleX[3] = Int_t(nx*3);
140 fSPDScaleZ[3] = Int_t(nz*3);
141 fSPDScaleX[4] = Int_t(nx*4);
142 fSPDScaleZ[4] = Int_t(nz*4);
158 if (fgDDLMapSDD == 0)
160 fgDDLMapSDD = new AliITSDDLModuleMapSDD();
161 AliCDBManager *man = AliCDBManager::Instance();
162 Bool_t cacheStatus = man->GetCacheFlag();
163 AliCDBEntry *ddlMapSDD = man->Get("ITS/Calib/DDLMapSDD");
167 AliWarning("SDD DDL map file retrieval from OCDB failed! - Use default DDL map");
171 AliITSDDLModuleMapSDD *ddlsdd = (AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
174 AliWarning("SDD DDL map object not found in OCDB file! - Use default DDL map");
179 ddlMapSDD->SetObject(0);
180 ddlMapSDD->SetOwner(kTRUE);
181 fgDDLMapSDD->SetDDLMap(ddlsdd);
189 if (fgDeadModSPD == 0)
191 AliCDBManager *cdb = AliCDBManager::Instance();
193 AliCDBEntry *deadSPD = cdb->Get("ITS/Calib/SPDDead");
197 AliWarning("SPD Calibration object retrieval failed!");
201 fgDeadModSPD = (TObjArray*)deadSPD->GetObject();
202 fgDeadModSPD->SetOwner(kTRUE);
206 // if (fgDeadModSDD == 0)
208 // AliCDBManager *cdb = AliCDBManager::Instance();
210 // AliCDBEntry *deadSDD = cdb->Get("ITS/Calib/SDDDead");
214 // AliWarning("SDD Calibration object retrieval failed!");
218 // fgDeadModSDD = (TObjArray*)deadSDD->GetObject();
219 // fgDeadModSDD->SetOwner(kTRUE);
223 // if (fgDeadModSSD == 0)
225 // AliCDBManager *cdb = AliCDBManager::Instance();
227 // AliCDBEntry *deadSSD = cdb->Get("ITS/Calib/SSDDead");
231 // AliWarning("SSD Calibration object retrieval failed!");
235 // fgDeadModSSD = (TObjArray*)deadSSD->GetObject();
236 // fgDeadModSSD->SetOwner(kTRUE);
241 /******************************************************************************/
243 AliEveITSDigitsInfo::~AliEveITSDigitsInfo()
246 // Deletes the data-maps.
247 // The tree, if it was passed into the object, is not touched.
249 std::map<Int_t, TClonesArray*>::iterator j;
250 for (j = fSPDmap.begin(); j != fSPDmap.end(); ++j)
252 for (j = fSDDmap.begin(); j != fSDDmap.end(); ++j)
254 for (j = fSSDmap.begin(); j != fSSDmap.end(); ++j)
257 delete fSegSPD; delete fSegSDD; delete fSegSSD;
260 /******************************************************************************/
262 void AliEveITSDigitsInfo::SetTree(TTree* tree)
264 // Set digit-tree to be used for digit retrieval. Data is loaded on
270 void AliEveITSDigitsInfo::ReadRaw(AliRawReader* raw, Int_t mode)
272 // Read raw-data into internal structures. AliITSdigit is used to
273 // store raw-adata for all sub-detectors.
275 if ((mode & 1) || (mode & 2))
277 AliITSRawStreamSPD inputSPD(raw);
278 TClonesArray* digits = 0;
279 while (inputSPD.Next())
281 Int_t module = inputSPD.GetModuleID();
282 Int_t column = inputSPD.GetColumn();
283 Int_t row = inputSPD.GetRow();
285 if (inputSPD.IsNewModule())
287 digits = fSPDmap[module];
289 fSPDmap[module] = digits = new TClonesArray("AliITSdigit", 16);
292 AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
293 d->SetCoord1(column);
297 // printf("SPD: %d %d %d\n",module,column,row);
302 if ((mode & 4) || (mode & 8))
304 AliITSRawStream* inputSDD = AliITSRawStreamSDD::CreateRawStreamSDD(raw);
305 inputSDD->SetDDLModuleMap(fgDDLMapSDD);
306 TClonesArray* digits = 0;
307 while (inputSDD->Next())
309 Int_t module = inputSDD->GetModuleID();
311 digits = fSDDmap[module];
313 fSDDmap[module] = digits = new TClonesArray("AliITSdigit", 0);
315 if (inputSDD->IsCompletedModule()==kFALSE && inputSDD->IsCompletedDDL()==kFALSE)
317 Int_t anode = inputSDD->GetCoord1()+inputSDD->GetChannel()*AliITSsegmentationSDD::GetNAnodesPerHybrid();
318 Int_t time = inputSDD->GetCoord2();
319 Int_t signal = inputSDD->GetSignal();
320 AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
323 d->SetSignal(signal);
325 // printf("SDD: %d %d %d %d\n",module,anode,time,signal);
331 if ((mode & 16) || (mode & 32))
333 AliITSRawStreamSSD input(raw);
334 TClonesArray* digits = 0;
337 Int_t module = input.GetModuleID();
338 Int_t side = input.GetSideFlag();
339 Int_t strip = input.GetStrip();
340 Int_t signal = input.GetSignal();
342 // !!!! IsNewModule() is false in the beginning of the stream, so we also
343 // !!!! check for digits == 0. Should be fixed in SSD stream.
344 if (input.IsNewModule() || digits == 0)
346 digits = fSSDmap[module];
348 fSSDmap[module] = digits = new TClonesArray("AliITSdigit", 0);
351 AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
354 d->SetSignal(signal);
356 // printf("SSD: %d %d %d %d\n",module,side,strip,signal);
362 /******************************************************************************/
364 void AliEveITSDigitsInfo::SetITSSegmentation()
366 // Create the segmentation objects and fill internal
370 fSegSPD = new AliITSsegmentationSPD("TGeo");
372 Float_t fNzSPD = 160;
373 Float_t fHlSPD = 3.48;
374 Float_t fZ1pitchSPD = 0.0425, fZ2pitchSPD = 0.0625;
376 fSPDZCoord[0] = fZ1pitchSPD - fHlSPD;
377 for (Int_t m=1; m<fNzSPD; m++)
379 Float_t dz = fZ1pitchSPD;
380 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 || m==127 || m==128)
384 fSPDZCoord[m] = fSPDZCoord[m-1] + dz;
387 for (Int_t m=0; m<fNzSPD; m++)
389 Float_t dz = fZ1pitchSPD;
390 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 || m==127 || m==128)
398 fSegSDD = new AliITSsegmentationSDD("TGeo");
399 // !!!! Set default drift speed, eventually need to get it from CDB.
400 fSegSDD->SetDriftSpeed(7.3);
403 fSegSSD = new AliITSsegmentationSSD("TGeo");
406 /******************************************************************************/
408 TClonesArray* AliEveITSDigitsInfo::GetDigits(Int_t mod, Int_t subdet) const
410 // Return TClonesArray of digits for specified module and sub-detector-id.
416 std::map<Int_t, TClonesArray*>::iterator i = fSPDmap.find(mod);
417 if (i != fSPDmap.end())
423 TClonesArray *digitsSPD = 0;
424 TBranch *br = fTree->GetBranch("ITSDigitsSPD");
425 br->SetAddress(&digitsSPD);
427 fSPDmap[mod] = digitsSPD;
435 std::map<Int_t, TClonesArray*>::iterator i = fSDDmap.find(mod);
436 if (i != fSDDmap.end())
442 TClonesArray *digitsSDD = 0;
443 TBranch *br = fTree->GetBranch("ITSDigitsSDD");
444 br->SetAddress(&digitsSDD);
446 fSDDmap[mod] = digitsSDD;
454 std::map<Int_t, TClonesArray*>::iterator i = fSSDmap.find(mod);
455 if (i != fSSDmap.end())
461 TClonesArray *digitsSSD = 0;
462 TBranch *br = fTree->GetBranch("ITSDigitsSSD");
463 br->SetAddress(&digitsSSD);
465 fSSDmap[mod] = digitsSSD;
475 /******************************************************************************/
477 void AliEveITSDigitsInfo::GetModuleIDs(AliEveITSModuleSelection* sel,
478 std::vector<UInt_t>& ids) const
480 // Fill the id-vector with ids of modules that satisfy conditions
481 // given by the AliEveITSModuleSelection object.
483 Int_t idx0 = 0, idx1 = 0;
484 switch(sel->GetType())
488 idx1 = AliITSgeomTGeo::GetModuleIndex(3, 1, 1) - 1;
491 idx0 = AliITSgeomTGeo::GetModuleIndex(3, 1, 1);
492 idx1 = AliITSgeomTGeo::GetModuleIndex(5, 1, 1) - 1;
495 idx0 = AliITSgeomTGeo::GetModuleIndex(5, 1, 1);
496 idx1 = AliITSgeomTGeo::GetNModules() - 1;
500 idx1 = AliITSgeomTGeo::GetNModules() - 1;
507 for (Int_t id = idx0; id < idx1; ++id)
509 AliITSgeomTGeo::GetModuleId(id, lay, lad, det);
510 if (sel->GetLayer() == lay || sel->GetLayer() == -1)
512 // check data from matrix
513 mx.SetFrom(*AliITSgeomTGeo::GetMatrix(id));
515 if (v.Phi() <= sel->GetMaxPhi() && v.Phi() >= sel->GetMinPhi() &&
516 v.Theta() <= sel->GetMaxTheta() && v.Theta() >= sel->GetMinTheta())
524 /******************************************************************************/
526 Bool_t AliEveITSDigitsInfo::HasData(Int_t module, Int_t det_id) const
528 // Return true if given module has data.
530 TClonesArray *digits = GetDigits(module, det_id);
531 return digits && digits->GetEntriesFast() > 0;
534 Bool_t AliEveITSDigitsInfo::IsDead (Int_t module, Int_t det_id) const
536 // Return true if given module is dead.
537 // Only implemented for SPD.
539 if (det_id == 0 && fgDeadModSPD)
540 return ((AliITSCalibrationSPD*) fgDeadModSPD->At(module))->IsBad();
541 if (det_id == 1 && fgDeadModSDD)
542 return ((AliITSCalibrationSDD*) fgDeadModSDD->At(module))->IsBad();
543 if (det_id == 2 && fgDeadModSSD)
544 return ((AliITSCalibrationSSD*) fgDeadModSSD->At(module))->IsBad();
548 /******************************************************************************/
550 void AliEveITSDigitsInfo::Print(Option_t* ) const
552 // Print information about stored geometry and segmentation.
554 printf("*********************************************************\n");
555 printf("SPD module dimension (%f,%f)\n", fSegSPD->Dx()*0.0001, fSegSPD->Dz()*0.0001);
556 printf("SPD first,last module: %d, %d\n",
557 AliITSgeomTGeo::GetModuleIndex(1,1,1),
558 AliITSgeomTGeo::GetModuleIndex(3,1,1) - 1);
559 printf("SPD num cells per module (x::%d,z::%d)\n", fSegSPD->Npx(), fSegSPD->Npz());
560 Int_t iz = 0, ix = 0;
561 printf("SPD dimesion of (%d,%d) in pixel(%f,%f)\n", ix, iz, fSegSPD->Dpx(ix), fSegSPD->Dpz(iz));
563 printf("SPD dimesion of pixel (%d,%d) are (%f,%f)\n", ix, iz, fSegSPD->Dpx(ix)*0.001, fSegSPD->Dpz(iz)*0.001);
565 printf("*********************************************************\n");
566 printf("SDD module dimension (%f,%f)\n", fSegSDD->Dx()*0.0001, fSegSDD->Dz()*0.0001);
567 printf("SDD first,last module: %d, %d\n",
568 AliITSgeomTGeo::GetModuleIndex(3,1,1),
569 AliITSgeomTGeo::GetModuleIndex(5,1,1) - 1);
570 printf("SDD num cells per module (x::%d,z::%d)\n", fSegSDD->Npx(), fSegSDD->Npz());
571 printf("SDD dimesion of pixel are (%f,%f)\n", fSegSDD->Dpx(1)*0.001, fSegSDD->Dpz(1)*0.001);
574 printf("*********************************************************\n");
575 printf("SSD module dimension (%f,%f)\n", fSegSSD->Dx()*0.0001, fSegSSD->Dz()*0.0001);
576 printf("SSD first, last module: %d, %d\n",
577 AliITSgeomTGeo::GetModuleIndex(5,1,1),
578 AliITSgeomTGeo::GetNModules() - 1);
579 printf("SSD strips in module %d\n", fSegSSD->Npx());
580 printf("SSD strip sizes are (%f,%f)\n", fSegSSD->Dpx(1), fSegSSD->Dpz(1));
581 fSegSSD->SetLayer(5); fSegSSD->Angles(ap,an);
582 printf("SSD layer 5 stereoP %f stereoN %f angle\n", ap, an);
583 fSegSSD->SetLayer(6); fSegSSD->Angles(ap,an);
584 printf("SSD layer 6 stereoP %f stereoN %f angle\n", ap, an);
589 printf("num cells %d,%d scaled %d,%d \n",fSegSPD->Npz(),fSegSPD->Npx(),Nz,Nx);
590 printf("%d digits in AliEveITSModule %d\n",ne, module);
591 Float_t zn = i*(3.48*2)/Nz - 3.48 ;
592 Float_t xo = -fSegSPD->Dx()*0.00005 + fSegSPD->Dpx(0)*od->GetCoord2()*0.0001;
593 Float_t xn = -fSegSPD->Dx()*0.00005 + j*0.0001*fSegSPD->Dx()/Nx;
594 Float_t dpx = 0.0001*fSegSPD->Dx()/Nx;
595 Float_t dpz = 3.48*2/Nz;
596 printf("Z::original (%3f) scaled (%3f, %3f) \n", zo, zn-dpz/2, zn+dpz/2);
597 printf("X::original (%3f) scaled (%3f, %3f) \n", xo, xn-dpx/2, xn+dpx/2);
598 printf("%d,%d maped to %d,%d \n", od->GetCoord1(), od->GetCoord2(), i,j );