]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveITSDigitsInfo.cxx
Move contents of EVE/Alieve to EVE/EveDet as most code will remain there.
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveITSDigitsInfo.cxx
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  **************************************************************************/
9
10 #include <TMath.h>
11 #include <TVector3.h>
12
13 #include <TEveTreeTools.h>
14 #include <TEveTrans.h>
15
16 #include "AliEveITSDigitsInfo.h"
17 #include <AliITSCalibrationSDD.h>
18 #include <AliITSdigit.h>
19 #include <AliITSdigitSPD.h>
20
21 #include <AliRawReader.h>
22 #include <AliITSRawStreamSPD.h>
23 #include <AliITSRawStreamSDD.h>
24 #include <AliITSRawStreamSSD.h>
25
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().
30
31 ClassImp(AliEveITSModuleSelection)
32
33 AliEveITSModuleSelection::AliEveITSModuleSelection():
34   fType(-1),
35   fLayer(-1),
36   fMinPhi(-TMath::Pi()),
37   fMaxPhi(TMath::Pi()),
38   fMinTheta(-TMath::Pi()),
39   fMaxTheta(TMath::Pi())
40 {
41   // Constructor.
42 }
43
44
45 //______________________________________________________________________________
46 //
47 // Stores ITS geometry information and event-data in format suitable
48 // for visualization.
49
50 ClassImp(AliEveITSDigitsInfo)
51
52 /******************************************************************************/
53
54 AliEveITSDigitsInfo::AliEveITSDigitsInfo() :
55   TObject(),
56   TEveRefCnt(),
57   fSPDmap(), fSDDmap(), fSSDmap(),
58   fTree (0),
59   fGeom (0),
60   fSegSPD(0), fSegSDD(0), fSegSSD(0)
61 {
62   // Default constructor.
63
64   InitInternals();
65 }
66
67 void AliEveITSDigitsInfo::InitInternals()
68 {
69   // Initialize internal geometry structures, in particular the
70   // module-id to transformation-matrix mapping and segmentation
71   // classes and data-structures.
72
73   static const TEveException eH("AliEveITSDigitsInfo::InitInternals ");
74
75   fGeom = new AliITSgeom();
76   fGeom->ReadNewFile("$REVESYS/alice-data/ITSgeometry.det");
77   if (fGeom == 0)
78     throw(eH + "can not load ITS geometry \n");
79
80   SetITSSegmentation();
81
82   // create tables for scaling
83   fSPDMinVal = 0;
84   fSDDMinVal = 5;
85   fSSDMinVal = 2;
86
87   fSPDMaxVal = 1;
88   fSDDMaxVal = 80;
89   fSSDMaxVal = 100;
90
91   fSPDHighLim = 1;
92   fSDDHighLim = 512;
93   fSSDHighLim = 1024;
94
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;
101
102   // spd lowest resolution
103   Int_t nx = 8; // fSegSPD->Npx()/8; // 32
104   Int_t nz = 6; // fSegSPD->Npz()/2; // 128
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
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;
127 }
128
129 /******************************************************************************/
130
131 AliEveITSDigitsInfo:: ~AliEveITSDigitsInfo()
132 {
133   // Destructor.
134   // Deletes the data-maps and the tree.
135
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
151 void AliEveITSDigitsInfo::SetTree(TTree* tree)
152 {
153   // Set digit-tree to be used for digit retrieval. Data is loaded on
154   // demand.
155
156   fTree = tree;
157 }
158
159 void AliEveITSDigitsInfo::ReadRaw(AliRawReader* raw, Int_t mode)
160 {
161   // Read raw-data into internal structures. AliITSdigit is used to
162   // store raw-adata for all sub-detectors.
163
164   if ((mode & 1) || (mode & 2)){
165     AliITSRawStreamSPD inputSPD(raw);
166     TClonesArray* digits = 0;
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       {
175         digits = fSPDmap[module];
176         if (digits == 0)
177           fSPDmap[module] = digits = new TClonesArray("AliITSdigit", 16);
178       }
179
180       AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
181       d->SetCoord1(column);
182       d->SetCoord2(row);
183       d->SetSignal(1);
184
185       // printf("SPD: %d %d %d\n",module,column,row);
186     }
187     raw->Reset();
188   }
189
190   if ((mode & 4) || (mode & 8)){
191     AliITSRawStreamSDD input(raw);
192     TClonesArray* digits = 0;
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       {
202         digits = fSDDmap[module];
203         if (digits == 0)
204           fSDDmap[module] = digits = new TClonesArray("AliITSdigit", 0);
205       }
206
207       AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
208       d->SetCoord1(anode);
209       d->SetCoord2(time);
210       d->SetSignal(signal);
211
212       // printf("SDD: %d %d %d %d\n",module,anode,time,signal);
213     }
214     raw->Reset();
215   }
216
217   if ((mode & 16) || (mode & 32)){
218     AliITSRawStreamSSD input(raw);
219     TClonesArray* digits = 0;
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       {
229         digits = fSSDmap[module];
230         if (digits == 0)
231           fSSDmap[module] = digits = new TClonesArray("AliITSdigit", 0);
232       }
233
234       AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
235       d->SetCoord1(side);
236       d->SetCoord2(strip);
237       d->SetSignal(signal);
238
239       // printf("SSD: %d %d %d %d\n",module,side,strip,signal);
240     }
241     raw->Reset();
242   }
243 }
244
245 /******************************************************************************/
246
247 void AliEveITSDigitsInfo::SetITSSegmentation()
248 {
249   // Create the segmentation objects and fill internal
250   // data-structures.
251
252   // SPD
253   fSegSPD = new AliITSsegmentationSPD(fGeom);
254
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   }
274
275   // SDD
276   fSegSDD = new AliITSsegmentationSDD(fGeom);
277
278   // SSD
279   fSegSSD = new AliITSsegmentationSSD(fGeom);
280 }
281
282 /******************************************************************************/
283
284 TClonesArray* AliEveITSDigitsInfo::GetDigits(Int_t mod, Int_t subdet)
285 {
286   // Return TClonesArray of digits for specified module and sub-detector-id.
287
288   switch(subdet)
289   {
290     case 0:
291     {
292       TClonesArray* digitsSPD = 0;
293       map<Int_t, TClonesArray*>::iterator i = fSPDmap.find(mod);
294       if (i == fSPDmap.end()) {
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;
304       } else {
305         return i->second;
306       }
307       break;
308     }
309     case 1:
310     {
311       TClonesArray* digitsSDD = 0;
312       map<Int_t, TClonesArray*>::iterator i = fSDDmap.find(mod);
313       if (i == fSDDmap.end()) {
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 {
324         return i->second;
325       }
326       break;
327     }
328     case 2:
329     {
330       TClonesArray* digitsSSD = 0;
331       map<Int_t, TClonesArray*>::iterator i = fSSDmap.find(mod);
332       if (i == fSSDmap.end()) {
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 {
344         return i->second;
345       }
346       break;
347     }
348     default:
349       return 0;
350   }
351   return 0;
352 }
353
354 /******************************************************************************/
355
356 void AliEveITSDigitsInfo::GetModuleIDs(AliEveITSModuleSelection* sel,
357                                        std::vector<UInt_t>& ids)
358 {
359   // Fill the id-vector with ids of modules that satisfy conditions
360   // given by the AliEveITSModuleSelection object.
361
362   Int_t idx0 = 0, idx1 = 0;
363   switch(sel->GetType())
364   {
365     case 0:
366       idx0 = 0;
367       idx1 = fGeom->GetLastSPD();
368       break;
369     case 1:
370       idx0 = fGeom->GetLastSPD()+1;
371       idx1 = fGeom->GetLastSDD();
372       break;
373     case 2:
374       idx0 = fGeom->GetLastSDD()+1;
375       idx1 = fGeom->GetLastSSD();
376       break;
377     default:
378       idx1 = 0;
379       idx1 = fGeom->GetLastSSD();
380       break;
381   }
382
383   TVector3 v;
384   Double_t x[9];
385   Int_t lay, lad, det;
386   TEveTrans mx;
387   for (Int_t id = idx0; id<idx1; ++id)
388   {
389     fGeom->GetModuleId(id, lay, lad, det);
390     if (sel->GetLayer() == lay || sel->GetLayer() == -1)
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);
401       if (v.Phi()   <= sel->GetMaxPhi()   && v.Phi()   >= sel->GetMinPhi()   &&
402           v.Theta() <= sel->GetMaxTheta() && v.Theta() >= sel->GetMinTheta())
403       {
404         ids.push_back(id);
405       }
406     }
407   }
408 }
409
410 /******************************************************************************/
411
412 void AliEveITSDigitsInfo::Print(Option_t* ) const
413 {
414   // Print information about stored geometry and segmentation.
415
416   printf("*********************************************************\n");
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));
422   iz = 32;
423   printf("SPD dimesion of pixel (%d,%d) are (%f,%f)\n", ix, iz, fSegSPD->Dpx(ix)*0.001, fSegSPD->Dpz(iz)*0.001);
424
425   printf("*********************************************************\n");
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;
432   printf("*********************************************************\n");
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);
439   fSegSSD->SetLayer(6);  fSegSSD->Angles(ap,an);
440   printf("SSD layer 6 stereoP %f stereoN %f angle\n", ap, an);
441 }
442
443
444 /*
445   printf("num cells %d,%d scaled %d,%d \n",fSegSPD->Npz(),fSegSPD->Npx(),Nz,Nx);
446   printf("%d digits in AliEveITSModule %d\n",ne, module);
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 */