]>
Commit | Line | Data |
---|---|---|
3b868b75 | 1 | // $Header$ |
2 | ||
3 | #include "ITSScaledModule.h" | |
4 | ||
5 | #include <AliITSdigitSPD.h> | |
6 | #include <AliITSdigitSDD.h> | |
7 | #include <AliITSdigitSSD.h> | |
8 | ||
9 | using namespace Reve; | |
10 | using namespace Alieve; | |
11 | ||
12 | DigitScaleInfo* ITSScaledModule::fgDigitScaleInfo = 0; | |
13 | ||
14 | //______________________________________________________________________ | |
15 | // DigitScaleInfo | |
16 | // | |
17 | ClassImp(DigitScaleInfo) | |
18 | ||
19 | DigitScaleInfo::DigitScaleInfo(): | |
20 | fScale(1), | |
21 | fStatType (ST_Average), | |
22 | fAutoUpdatePalette(kTRUE) | |
23 | { | |
24 | } | |
25 | ||
26 | void DigitScaleInfo::ScaleChanged(Int_t s) | |
27 | { | |
28 | fScale = s; | |
29 | Emit("ScaleChanged(Int_t)",fScale); | |
30 | } | |
31 | ||
32 | void DigitScaleInfo::StatTypeChanged(Int_t t) | |
33 | { | |
34 | fStatType = t; | |
35 | Emit("StatTypeChanged(Int_t)",fStatType); | |
36 | } | |
37 | ||
38 | //______________________________________________________________________ | |
39 | // DigitScaleInfo | |
40 | // | |
41 | ScaledDigit::ScaledDigit(): | |
42 | TObject(), | |
43 | N(0), | |
44 | sum(0), sqr_sum(0), | |
45 | min_i(-1), min_j(-1), max_i(-1), max_j(-1) | |
46 | { | |
47 | } | |
48 | ||
49 | ScaledDigit::ScaledDigit(Int_t di, Int_t dj): | |
50 | TObject(), | |
51 | N(0), | |
52 | sum(0), sqr_sum(0), | |
53 | min_i(di), min_j(dj), max_i(di), max_j(dj) | |
54 | { | |
55 | } | |
56 | ||
57 | void ScaledDigit::Dump() const | |
58 | { | |
59 | printf("N %d, sum %f, sqr_sum %f",N, sum, sqr_sum); | |
60 | } | |
61 | ||
62 | //______________________________________________________________________ | |
63 | // ITSScaledModule | |
64 | // | |
65 | ||
66 | ClassImp(ITSScaledModule) | |
67 | ||
68 | ITSScaledModule::ITSScaledModule(Int_t gid, ITSDigitsInfo* info): | |
69 | ITSModule("ITSScaledModule", "ITSScaledModule"), | |
70 | fNx(-1), | |
71 | fNz(-1), | |
72 | fNCx(-1), | |
73 | fNCz(-1) | |
74 | { | |
75 | if(fgDigitScaleInfo == 0) | |
76 | { | |
77 | fgDigitScaleInfo = new DigitScaleInfo(); | |
78 | } | |
79 | ||
80 | fgDigitScaleInfo->IncRefCount(this); | |
81 | fgDigitScaleInfo->Connect("ScaleChanged(Int_t)", "Alieve::ITSScaledModule", this,"LoadQuads()"); | |
82 | fgDigitScaleInfo->Connect("StatTypeChanged(Int_t)", "Alieve::ITSScaledModule", this,"SetQuadValues()"); | |
83 | SetOwnIds(kTRUE); | |
84 | ||
85 | SetDigitsInfo(info); | |
86 | SetID(gid); | |
87 | } | |
88 | ||
89 | ITSScaledModule::~ITSScaledModule() | |
90 | { | |
91 | fgDigitScaleInfo->DecRefCount(); | |
92 | } | |
93 | ||
94 | /**************************************************************************/ | |
95 | ||
96 | void ITSScaledModule::LoadQuads() | |
97 | { | |
98 | // Here we still use 'z' for the name of axial coordinates. | |
99 | // The transforamtion matrix aplied rotates y -> z. | |
100 | // We need this as QuadSet offers optimized treatment for | |
101 | // quads in the x-y plane. | |
102 | ||
103 | TClonesArray *digits; | |
104 | Float_t x, z, zo, dpx, dpz; // orig cells size, pos | |
105 | Int_t i, j, ndigits; // orig cells idx | |
106 | Int_t c1, c2; // original coordinates | |
107 | ||
108 | Int_t id; | |
109 | map<Int_t, Int_t> dmap; | |
110 | map<Int_t, Int_t>::iterator miter; | |
111 | digits = fInfo->GetDigits(fID, fDetID); | |
112 | ndigits = digits->GetEntriesFast(); | |
113 | ||
114 | ScaledDigit* sd; | |
115 | Int_t scale = fgDigitScaleInfo->GetScale() -1; | |
116 | switch(fDetID) | |
117 | { | |
118 | case 0: | |
119 | { | |
120 | // SPD | |
121 | Reset(QT_RectangleXZFixedY, kFALSE, 32); | |
122 | ||
123 | fNCz = fInfo->fSPDScaleZ[scale]; | |
124 | fNCx = fInfo->fSPDScaleX[scale]; | |
125 | fNz = Int_t(fInfo->fSegSPD->Npz()/fNCz); | |
126 | fNx = Int_t(fInfo->fSegSPD->Npx()/fNCx); | |
127 | dpz = 2*fDz/fNz; | |
128 | dpx = 2*fDx/fNx; | |
129 | //printf("SPD orig cells (%d, %d) (%d, %d)\n", fInfo->fSegSPD->Npx(), fInfo->fSegSPD->Npz(), Nx, Nz); | |
130 | ||
131 | AliITSdigitSPD *od ; | |
132 | for (Int_t k=0; k<ndigits; ++k) | |
133 | { | |
134 | od = (AliITSdigitSPD*) digits->UncheckedAt(k); | |
135 | ||
136 | fInfo->GetSPDLocalZ(od->GetCoord1(),zo); | |
137 | c1 = od->GetCoord1(); c2 = od->GetCoord2(); | |
138 | i = Int_t((zo+fDz)/dpz); | |
139 | j = Int_t((od->GetCoord2()*fNx)/fInfo->fSegSPD->Npx()); | |
140 | id = j*fNx + i; | |
141 | ||
142 | miter = dmap.find(id); | |
143 | if(miter == dmap.end()) | |
144 | { | |
145 | dmap[id] = fPlex.Size(); | |
146 | z = dpz*(i) - fDz; | |
147 | x = dpx*(j) - fDx; | |
148 | AddQuad(x, z, dpx, dpz); | |
149 | sd = new ScaledDigit(c1, c2); | |
150 | QuadId(sd); | |
151 | } | |
152 | else | |
153 | { | |
154 | sd = dynamic_cast<ScaledDigit*>(GetId(miter->second)); | |
155 | if(c1 < sd->min_i) | |
156 | sd->min_i = c1; | |
157 | else if( c1 > sd->max_i) | |
158 | sd->max_i = c1; | |
159 | ||
160 | if(c2 < sd->min_j) | |
161 | sd->min_j = c2; | |
162 | else if( c2 > sd->max_j) | |
163 | sd->max_j = c2; | |
164 | } | |
165 | ||
166 | sd->N++; | |
167 | sd->sum += od->GetSignal(); | |
168 | sd->sqr_sum += od->GetSignal()*od->GetSignal(); | |
169 | } | |
170 | break; | |
171 | } | |
172 | case 1: | |
173 | { | |
174 | // SDD | |
175 | Reset(QT_RectangleXZFixedY, kFALSE, 32); | |
176 | ||
177 | fNCz = fInfo->fSDDScaleZ[scale]; | |
178 | fNCx = fInfo->fSDDScaleX[scale]; | |
179 | fNz = Int_t(fInfo->fSegSDD->Npz()/fNCz); | |
180 | fNx = Int_t(fInfo->fSegSDD->Npx()/fNCx); | |
181 | dpz = 2*fDz/fNz; | |
182 | dpx = 2*fDx/fNx; | |
183 | ||
184 | AliITSdigitSDD *od=0; | |
185 | for (Int_t k=0; k<ndigits; k++) { | |
186 | od=(AliITSdigitSDD*)digits->UncheckedAt(k); | |
187 | fInfo->fSegSDD->DetToLocal(od->GetCoord2(), od->GetCoord1(),x,z); | |
188 | z+= fDz; | |
189 | x+= fDx; | |
190 | i = Int_t(z/dpz); | |
191 | j = Int_t(x/dpx); | |
192 | //printf("Mod %d coord %d,%d out of %d,%d :: ORIG coord %d,%d out of %d,%d \n",fID, | |
193 | // i,j,Nz,Nx,od->GetCoord1(),od->GetCoord2(),fInfo->fSegSDD->Npz(),fInfo->fSegSDD->Npx()); | |
194 | ||
195 | id = j*fNx + i; | |
196 | c1 = od->GetCoord1(); c2 = od->GetCoord2(); | |
197 | ||
198 | miter = dmap.find(id); | |
199 | if(miter == dmap.end()) | |
200 | { | |
201 | dmap[id] = fPlex.Size(); | |
202 | z = dpz*(i) - fDz; | |
203 | x = dpx*(j) - fDx; | |
204 | AddQuad(x, z, dpx, dpz); | |
205 | sd = new ScaledDigit(od->GetCoord1(),od->GetCoord2()); | |
206 | QuadId(sd); | |
207 | } | |
208 | else | |
209 | { | |
210 | sd = dynamic_cast<ScaledDigit*>(GetId(miter->second)); | |
211 | if(c1 < sd->min_i) | |
212 | sd->min_i = c1; | |
213 | else if( c1 > sd->max_i) | |
214 | sd->max_i = c1; | |
215 | ||
216 | if(c2 < sd->min_j) | |
217 | sd->min_j = c2; | |
218 | else if( c2 > sd->max_j) | |
219 | sd->max_j = c2; | |
220 | } | |
221 | sd->N++; | |
222 | sd->sum += od->GetSignal(); | |
223 | sd->sqr_sum += od->GetSignal()*od->GetSignal(); | |
224 | } | |
225 | break; | |
226 | } | |
227 | case 2: | |
228 | { | |
229 | // SSD | |
230 | Reset(QT_LineXZFixedY, kFALSE, 32); | |
231 | ||
232 | AliITSsegmentationSSD* seg = fInfo->fSegSSD; | |
233 | Float_t ap, an; // positive/negative angles -> offsets | |
234 | seg->Angles(ap, an); | |
235 | ap = TMath::Tan(ap) * fDz; | |
236 | an = - TMath::Tan(an) * fDz; | |
237 | ||
238 | fNCx = fInfo->fSSDScale[scale]; | |
239 | fNz = 1; | |
240 | fNx = Int_t(fInfo->fSegSSD->Npx()/fNCx); | |
241 | dpz = 2*fDz/fNz; | |
242 | dpx = 2*fDx/fNx; | |
243 | ||
244 | AliITSdigitSSD *od=0; | |
245 | for (Int_t k=0; k<ndigits; k++) { | |
246 | od=(AliITSdigitSSD*)digits->UncheckedAt(k); | |
247 | if(od->GetCoord1() == 1) | |
248 | i = 1; // p side | |
249 | else | |
250 | i= -1; // n side | |
251 | j = Int_t(od->GetCoord2()/fNCx); | |
252 | c1 = od->GetCoord1(); c2 = od->GetCoord2(); | |
253 | id = j*i; | |
254 | ||
255 | miter = dmap.find(id); | |
256 | ScaledDigit* sd; | |
257 | if(miter == dmap.end()) | |
258 | { | |
259 | // printf("orig digit %d,%d scaled %d,%d \n",od->GetCoord1(),od->GetCoord2(),i,j); | |
260 | dmap[id] = fPlex.Size(); | |
261 | z = dpz*(i) - fDz; | |
262 | x = dpx*(j) - fDx; | |
263 | Float_t a = ( od->GetCoord1() == 1) ? ap : an; | |
264 | AddLine(x-a, -fDz, 2*a, 2*fDz); | |
265 | ||
266 | sd = new ScaledDigit(c1, c2); | |
267 | QuadId(sd); | |
268 | } | |
269 | else | |
270 | { | |
271 | sd = dynamic_cast<ScaledDigit*>(GetId(miter->second)); | |
272 | if(c1 < sd->min_i) | |
273 | sd->min_i = c1; | |
274 | else if( c1 > sd->max_i) | |
275 | sd->max_i = c1; | |
276 | ||
277 | if(c2 < sd->min_j) | |
278 | sd->min_j = c2; | |
279 | else if( c2 > sd->max_j) | |
280 | sd->max_j = c2; | |
281 | } | |
282 | sd->N++; | |
283 | sd->sum += od->GetSignal(); | |
284 | sd->sqr_sum += od->GetSignal()*od->GetSignal(); | |
285 | } // for digits | |
286 | break; | |
287 | } // end case 2 | |
288 | } // end switch | |
289 | ||
290 | SetQuadValues(); | |
291 | RefitPlex(); | |
292 | } | |
293 | ||
294 | /**************************************************************************/ | |
295 | ||
296 | void ITSScaledModule::SetQuadValues() | |
297 | { | |
298 | Int_t N = fPlex.Size(); | |
299 | for (Int_t i = 0 ; i< N; i++) | |
300 | { | |
301 | ScaledDigit* sd = dynamic_cast<ScaledDigit*>(GetId(i)); | |
302 | Int_t v = 0; | |
303 | switch(fgDigitScaleInfo->GetStatType()) { | |
304 | case DigitScaleInfo::ST_Occup: v = sd->N; break; | |
305 | case DigitScaleInfo::ST_Average: v = Int_t(sd->sum/(1.* sd->N)); break; | |
306 | case DigitScaleInfo::ST_Rms: v = Int_t(TMath::Sqrt(sd->sqr_sum)/(1.*sd->N)); break; | |
307 | } | |
308 | QuadBase* qb = GetQuad(i); | |
309 | qb->fValue = v; | |
310 | } | |
311 | } | |
312 | ||
313 | /**************************************************************************/ | |
314 | ||
315 | void ITSScaledModule::QuadSelected(Int_t idx) | |
316 | { | |
317 | // Override control-click from QuadSet | |
318 | printf("ITSScaledModule::QuadSelected "); Print(); | |
319 | ||
320 | QuadBase* qb = GetQuad(idx); | |
321 | TObject* obj = qb->fId.GetObject(); | |
322 | ScaledDigit* sd = dynamic_cast<ScaledDigit*>(obj); | |
323 | TClonesArray *digits = fInfo->GetDigits(fID, fDetID); | |
324 | Int_t ndigits = digits->GetEntriesFast(); | |
325 | ||
326 | printf("%d digits in cell scaleX = %d, scaleZ = %d \n", sd->N, fNCx, fNCz); | |
327 | ||
328 | Int_t il = 0; | |
329 | for(Int_t k=0; k<ndigits; k++) | |
330 | { | |
331 | AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k); | |
332 | ||
333 | if(d->GetCoord1()>=sd->min_i && d->GetCoord1()<=sd->max_i && | |
334 | d->GetCoord2()>=sd->min_j && d->GetCoord2()<=sd->max_j) | |
335 | { | |
336 | printf("%3d, %3d: %3d", d->GetCoord1(), d->GetCoord2(), d->GetSignal()); | |
337 | printf(" | "); | |
338 | il++; | |
339 | if(il>5) { | |
340 | printf("\n"); | |
341 | il = 0; | |
342 | } | |
343 | } | |
344 | } | |
345 | if(il) printf("\n"); | |
346 | } |