Use two-level selection, implement callback QuadSelected() to print out the digit...
[u/mrichter/AliRoot.git] / EVE / Alieve / ITSModule.cxx
CommitLineData
5a5a1232 1#include "ITSModule.h"
2
3#include <AliITSdigitSPD.h>
4#include <AliITSdigitSDD.h>
5#include <AliITSdigitSSD.h>
6
7#include <TStyle.h>
8
9using namespace Reve;
10using namespace Alieve;
5a5a1232 11
9efc978d 12
13Bool_t ITSModule::fgStaticInitDone = kFALSE;
14
15FrameBox* ITSModule::fgSPDFrameBox = 0;
16FrameBox* ITSModule::fgSDDFrameBox = 0;
17FrameBox* ITSModule::fgSSDFrameBox = 0;
18
19RGBAPalette* ITSModule::fgSPDPalette = 0;
20RGBAPalette* ITSModule::fgSDDPalette = 0;
21RGBAPalette* ITSModule::fgSSDPalette = 0;
22
23//__________________________________________________________________________
24// ITSModule
25//
26//
5a5a1232 27
28ClassImp(ITSModule)
29
30/**************************************************************************/
31
9efc978d 32ITSModule::ITSModule(const Text_t* n, const Text_t* t) :
33 QuadSet(n, t),
265ecb21 34 fInfo(0),
35 fID(-1), fDetID(-1),
36 fLayer(-1), fLadder(-1), fDet(-1),
9efc978d 37 fDx(0), fDz(0), fDy(0)
27db2029 38{}
5a5a1232 39
9c8221e9 40ITSModule::ITSModule(Int_t gid, ITSDigitsInfo* info) :
41 QuadSet(Form("ITS module %d", gid)),
27db2029 42 fInfo (0),
265ecb21 43 fID(-1), fDetID(-1),
44 fLayer(-1), fLadder(-1), fDet(-1),
9efc978d 45 fDx(0), fDz(0), fDy(0)
5a5a1232 46{
27db2029 47 SetDigitsInfo(info);
9c8221e9 48 SetID(gid);
5a5a1232 49}
50
51ITSModule::~ITSModule()
52{
53 if(fInfo) fInfo->DecRefCount();
54}
55
56/**************************************************************************/
57
9efc978d 58void ITSModule::InitStatics(ITSDigitsInfo* info)
59{
60 if (fgStaticInitDone) return;
9c8221e9 61 fgStaticInitDone = kTRUE;
9efc978d 62
63 {
64 Float_t dx = info->fSegSPD->Dx()*0.00005;
65 Float_t dz = 3.48;
66
67 fgSPDFrameBox = new FrameBox();
68 fgSPDFrameBox->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
69 fgSPDFrameBox->SetFrameColor((Color_t) 31);
5bdbb9ca 70 fgSPDPalette = new RGBAPalette(0, 1);
9efc978d 71 }
72
73 {
74 Float_t dx = info->fSegSDD->Dx()*0.0001;
75 Float_t dz = info->fSegSDD->Dz()*0.00005;
76
77 fgSDDFrameBox = new FrameBox();
78 fgSDDFrameBox->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
79 fgSDDFrameBox->SetFrameColor((Color_t) 32);
5bdbb9ca 80 fgSDDPalette = new RGBAPalette(5, 80);
81 fgSDDPalette->SetLimits(0, 512); // Set proper ADC range.
9efc978d 82 }
83
84 {
85 Float_t dx = info->fSegSSD->Dx()*0.00005;
86 Float_t dz = info->fSegSSD->Dz()*0.00005;
87
88 fgSSDFrameBox = new FrameBox();
89 fgSSDFrameBox->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
90 fgSSDFrameBox->SetFrameColor((Color_t) 33);
5bdbb9ca 91 fgSSDPalette = new RGBAPalette(2, 100);
92 fgSSDPalette->SetLimits(0, 1024); // Set proper ADC range.
9efc978d 93 }
94
95}
96
97/**************************************************************************/
98
9c8221e9 99void ITSModule::SetDigitsInfo(ITSDigitsInfo* info)
5a5a1232 100{
9c8221e9 101 if (fInfo == info) return;
102 if (fInfo) fInfo->DecRefCount();
103 fInfo = info;
104 if (fInfo) fInfo->IncRefCount();
105}
106
107/**************************************************************************/
108
109void ITSModule::SetID(Int_t gid)
110{
111 static const Exc_t eH("ITSModule::SetID ");
9efc978d 112
9c8221e9 113 if(fInfo == 0)
114 throw(eH + "ITSDigitsInfo not set.");
115
116 if (gid < fInfo->fGeom->GetStartSPD() || gid > fInfo->fGeom->GetLastSSD())
117 throw(eH + Form("%d is not valid. ID range from %d to %d", gid,
118 fInfo->fGeom->GetStartSPD(), fInfo->fGeom->GetLastSSD()));
119
120 fID = gid;
121
122 if (!fgStaticInitDone) InitStatics(fInfo);
123
124 fInfo->fGeom->GetModuleId(fID, fLayer, fLadder, fDet);
ba6cfb13 125 TString strLadder = "Ladder";
126 TString strSensor = "Sensor";
127 TString symname;
9c8221e9 128 Int_t id, nsector, nstave, nladder, rest;
ba6cfb13 129
9efc978d 130 if (fID <= fInfo->fGeom->GetLastSPD())
131 {
132 // SPD
133
9c8221e9 134 SetFrame(fgSPDFrameBox);
135 SetPalette(fgSPDPalette);
136
9efc978d 137 symname += strLadder;
138 if (fID < 80)
139 {
ba6cfb13 140 nsector = fID/8;
9efc978d 141 rest = fID - 8*nsector;
142 nstave = 1;
143 }
144 else
145 {
146 id = fID - 80;
ba6cfb13 147 nsector = id/8;
9efc978d 148 rest = id - 8*nsector;
149 nstave = 1;
ba6cfb13 150 }
9efc978d 151 if (rest < 4) nstave = 0;
152 rest -= 4*nstave;
153 symname += rest;
154 SetName(symname);
155 fDetID = 0;
156 fDx = fInfo->fSegSPD->Dx()*0.00005;
157 fDz = 3.48;
158 fDy = fInfo->fSegSPD->Dy()*0.00005;
159
5a5a1232 160 }
9efc978d 161 else if (fID <= fInfo->fGeom->GetLastSDD())
162 {
163 // SDD
164
9c8221e9 165 SetFrame(fgSDDFrameBox);
166 SetPalette(fgSDDPalette);
167
9efc978d 168 symname += strSensor;
169 if (fID < 324)
170 {
171 id = fID - 240;
ba6cfb13 172 nladder = id/6;
9efc978d 173 rest = id - 6*nladder;
174 }
175 else
176 {
177 id = fID - 324;
ba6cfb13 178 nladder = id/8;
9efc978d 179 rest = id - 8*nladder;
ba6cfb13 180 }
9efc978d 181 symname += rest;
182 SetName(symname);
183 fDetID = 1;
184 fDx = fInfo->fSegSDD->Dx()*0.0001;
185 fDz = fInfo->fSegSDD->Dz()*0.00005;
186 fDy = fInfo->fSegSDD->Dy()*0.00005;
187
5a5a1232 188 }
9efc978d 189 else
190 {
191 // SSD
192
9c8221e9 193 SetFrame(fgSSDFrameBox);
194 SetPalette(fgSSDPalette);
195
9efc978d 196 symname += strSensor;
197 if (fID < 1248)
198 {
199 id = fID - 500;
ba6cfb13 200 nladder = id/22;
9efc978d 201 rest = id - nladder*22;
202 }
203 else
204 {
205 id = fID - 1248;
ba6cfb13 206 nladder = id/25;
9efc978d 207 rest = id - nladder*25;
ba6cfb13 208 }
9efc978d 209 symname += rest;
210 SetName(symname);
211 fDetID = 2;
212 fInfo->fSegSSD->SetLayer(fLayer);
213 fDx = fInfo->fSegSSD->Dx()*0.00005;
214 fDz = fInfo->fSegSSD->Dz()*0.00005;
215 fDy = fInfo->fSegSSD->Dy()*0.00005;
216
5a5a1232 217 }
218
219 LoadQuads();
220 ComputeBBox();
221 SetTrans();
222}
223
224void ITSModule::LoadQuads()
225{
9efc978d 226 // Here we still use 'z' for the name of axial coordinates.
227 // The transforamtion matrix aplied rotates y -> z.
228 // We need this as QuadSet offers optimized treatment for
229 // quads in the x-y plane.
230
5a5a1232 231 // printf("its module load quads \n");
9efc978d 232
5a5a1232 233 TClonesArray *digits;
9efc978d 234 Float_t x, z, dpx, dpz;
235 Int_t i, j, ndigits;
236 digits = fInfo->GetDigits(fID, fDetID);
5a5a1232 237 ndigits = digits->GetEntriesFast();
5a5a1232 238
9efc978d 239 switch(fDetID)
240 {
241
242 case 0: { // SPD
243 AliITSsegmentationSPD* seg = fInfo->fSegSPD;
244
697c88e6 245 Reset(QT_RectangleXZFixedY, kFALSE, 32);
5a5a1232 246
9efc978d 247 for (Int_t k=0; k<ndigits; ++k)
248 {
249 AliITSdigitSPD *d = (AliITSdigitSPD*) digits->UncheckedAt(k);
5a5a1232 250 j = d->GetCoord1();
251 i = d->GetCoord2();
9efc978d 252 x = -0.5*seg->Dx() + i*seg->Dpx(0);
253 x *= 0.0001;
254 fInfo->GetSPDLocalZ(j, z);
5a5a1232 255 dpx = seg->Dpx(i)*0.0001;
256 dpz = seg->Dpz(j)*0.0001;
257
9efc978d 258 AddQuad(x, z, dpx, dpz);
259 QuadValue(1); // In principle could have color based on number of neigbours
ffa36681 260 QuadId(d);
5a5a1232 261 }
9efc978d 262 break;
5a5a1232 263 }
5a5a1232 264
9efc978d 265 case 1: { // SDD
266 AliITSsegmentationSDD *seg = fInfo->fSegSDD;
5a5a1232 267
697c88e6 268 Reset(QT_RectangleXZFixedY, kFALSE, 32);
9efc978d 269
270 for (Int_t k=0; k<ndigits; ++k)
271 {
272 AliITSdigitSDD* d = (AliITSdigitSDD*) digits->UncheckedAt(k);
273
274 // if (d->GetSignal() > fgSDDThreshold)
275 {
276 j = d->GetCoord1();
277 i = d->GetCoord2();
278 seg->DetToLocal(i, j, x, z);
279 dpx = seg->Dpx(i)*0.0001;
280 dpz = seg->Dpz(j)*0.0001;
281
697c88e6 282 AddQuad(x-2*dpx, z, 4*dpx, dpz);
9efc978d 283 QuadValue(d->GetSignal());
ffa36681 284 QuadId(d);
5a5a1232 285 }
9efc978d 286 }
287 break;
288 }
289
290 case 2: { // SSD
291 AliITSsegmentationSSD* seg = fInfo->fSegSSD;
292
697c88e6 293 Reset(QT_LineXZFixedY, kFALSE, 32);
9efc978d 294
295 Float_t ap, an; // positive/negative angles -> offsets
296 seg->Angles(ap, an);
297 ap = TMath::Tan(ap) * fDz;
298 an = - TMath::Tan(an) * fDz;
299
300 for (Int_t k=0; k<ndigits; ++k)
301 {
302 AliITSdigitSSD *d = (AliITSdigitSSD*) digits->UncheckedAt(k);
303 // if(d->GetSignal() > fgSSDThreshold)
304 {
305 j = d->GetCoord1();
306 i = d->GetCoord2();
307 seg->DetToLocal(i,j,x,z);
308
309 Float_t a = ( d->GetCoord1() == 1) ? ap : an;
310
e974c097 311 AddLine(x-a, -fDz, 2*a, 2*fDz);
9efc978d 312 QuadValue(d->GetSignal());
ffa36681 313 QuadId(d);
9efc978d 314 // printf("%3d -> %3d -> %8x\n", d->GetSignal(), ci, fQuads.back().color);
5a5a1232 315 }
5a5a1232 316 }
9efc978d 317 break;
5a5a1232 318 }
5a5a1232 319
9efc978d 320 } // end switch
321
322 RefitPlex();
5a5a1232 323}
324
325/**************************************************************************/
326
327void ITSModule::SetTrans()
328{
9efc978d 329 Double_t x[9];
330 fHMTrans.UnitTrans();
331
332 // column major
333 fInfo->fGeom->GetRotMatrix(fID, x);
334 fHMTrans.SetBaseVec(1, x[0], x[3], x[6]);
335 fHMTrans.SetBaseVec(2, x[1], x[4], x[7]);
336 fHMTrans.SetBaseVec(3, x[2], x[5], x[8]);
337 // translation
338 fInfo->fGeom->GetTrans(fID, x);
339 fHMTrans.SetBaseVec(4, x);
5a5a1232 340}
341
342/**************************************************************************/
343
ffa36681 344void ITSModule::QuadSelected(Int_t idx)
345{
346 // Override control-click from QuadSet
347
348 QuadBase* qb = GetQuad(idx);
349 TObject* obj = qb->fId.GetObject();
350 AliITSdigit* d = dynamic_cast<AliITSdigit*>(obj);
351 printf("ITSModule::QuadSelected "); Print();
352 printf(" idx=%d, value=%d, obj=0x%lx, digit=0x%lx\n",
353 idx, qb->fValue, (ULong_t)obj, (ULong_t)d);
354 if (d)
355 printf(" coord1=%3d coord2=%3d signal=%d\n",
356 d->GetCoord1(), d->GetCoord2(), d->GetSignal());
357
358}
359
360/**************************************************************************/
361
5a5a1232 362void ITSModule::Print(Option_t* ) const
363{
364 printf("ID %d, layer %d, ladder %d, det %d \n", fID, fLayer, fLadder, fDetID);
365}