Release version of ITS code
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSSD.cxx
CommitLineData
b0f5e3fc 1
2#include <stdio.h>
3#include <TObjArray.h>
4
b0f5e3fc 5#include "AliITSsimulationSSD.h"
6#include "AliITSdictSSD.h"
7#include "AliITSdcsSSD.h"
8#include "AliITS.h"
9#include "AliRun.h"
10
11
12ClassImp(AliITSsimulationSSD);
13//------------------------------------------------------------
14AliITSsimulationSSD::AliITSsimulationSSD(AliITSsegmentation *seg,
15 AliITSresponse *resp){
16 // Constructor
17
18 fSegmentation = seg;
19 fResponse = resp;
20 fDCS = new AliITSdcsSSD(seg,resp);
21
22 fNstrips = fSegmentation->Npx();
23 fPitch = fSegmentation->Dpx(0);
24
e8189707 25 fP = new TArrayF(fNstrips+1);
26 fN = new TArrayF(fNstrips+1);
b0f5e3fc 27
e8189707 28 fTracksP = new AliITSdictSSD[fNstrips+1];
29 fTracksN = new AliITSdictSSD[fNstrips+1];
30
b0f5e3fc 31
32 fSteps = 10; // still hard-wired - set in SetDetParam and get it via
33 // fDCS together with the others eventually
34
b0f5e3fc 35}
36//___________________________________________________________________________
37AliITSsimulationSSD& AliITSsimulationSSD::operator=(AliITSsimulationSSD
38 &source){
39// Operator =
40 if(this==&source) return *this;
41
42 this->fDCS = new AliITSdcsSSD(*(source.fDCS));
43 this->fN = new TArrayF(*(source.fN));
44 this->fP = new TArrayF(*(source.fP));
45 this->fTracksP = new AliITSdictSSD(*(source.fTracksP));
46 this->fTracksN = new AliITSdictSSD(*(source.fTracksN));
47 this->fNstrips = source.fNstrips;
48 this->fPitch = source.fPitch;
49 this->fSteps = source.fSteps;
50 return *this;
51}
52//_____________________________________________________________
53AliITSsimulationSSD::AliITSsimulationSSD(AliITSsimulationSSD &source){
54 // copy constructor
55 *this = source;
56}
57//____________________________________________________________________________
58AliITSsimulationSSD::~AliITSsimulationSSD() {
59 // anihilator
e8189707 60
b0f5e3fc 61 if(fP) delete fP;
62 if(fN) delete fN;
63
64 if(fTracksP) delete fTracksP;
65 if(fTracksN) delete fTracksN;
66
67 delete fDCS;
68}
69//_______________________________________________________________
70//
71// Hit to digit
72//_______________________________________________________________
73//
74void AliITSsimulationSSD::DigitiseModule(AliITSmodule *mod,Int_t module,
75 Int_t dummy) {
76 // Digitizes one SSD module of hits.
77
78 TObjArray *hits = mod->GetHits();
79 Int_t nhits = hits->GetEntriesFast();
b0f5e3fc 80 if (!nhits) return;
81
82 Int_t i;
83 for(i=0; i<fNstrips; i++) {
84 (*fP)[i] = 0;
85 (*fN)[i] = 0;
86 fTracksP[i].ZeroTracks();
87 fTracksN[i].ZeroTracks();
88 }
89
90 for(i=0; i<nhits; i++) {
91 Int_t idtrack=mod->GetHitTrackIndex(i);
92 HitToDigit(i,idtrack,nhits,hits);
93 }
94
95
e8189707 96
b0f5e3fc 97 ApplyNoise();
98 ApplyCoupling();
99 ApplyThreshold();
100 ApplyDAQ();
101
102
103}
104
105//---------------------------------------------------------------
106
107void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
108 Int_t nhits,TObjArray *hits) {
109 // Turns one or more hits in an SSD module into one or more digits.
110
111 Int_t stripP, stripN, i;
112 Float_t dsP, dsN;
113 Float_t sP, sN;
114 Float_t eP, eN;
e8189707 115 Float_t arrayEP[10]; // hard-wired number of steps
bba587ca 116 Float_t arrayEN[10];
e8189707 117 Int_t track = -1;
b0f5e3fc 118
119 Float_t ionization = 0;
120 Float_t signal;
121
122 AliITSdictSSD *dict;
123
124
125 // check if this is the right order !!!!!
126
127 AliITShit *hitI = (AliITShit*)hits->At(hitNo++);
128 AliITShit *hitE = (AliITShit*)hits->At(hitNo);
129
130
131 while (!((hitE->StatusExiting()) ||
132 (hitE->StatusDisappeared()) ||
133 (hitE->StatusStop()))) {
134
135 if (++hitNo<nhits) {
136 ionization = hitE->GetIonization();
137 hitE = (AliITShit*)hits->At(hitNo);
138 }
139 }
140
141
142 if (hitI->GetTrack() == hitE->GetTrack())
e8189707 143 //track = idtrack;
b0f5e3fc 144 track = hitI->GetTrack();
145 else
146 printf("!!! Emergency !!!\n");
147
148
149 ionization += hitE->GetIonization();
150
151 const Float_t kconvm=10000.; // cm -> microns
152
153 Float_t xI, yI, zI;
154 hitI->GetPositionL(xI, yI, zI);
155
b0f5e3fc 156 xI *= kconvm;
157 yI *= kconvm;
158 zI *= kconvm;
159
160 Float_t xE, yE, zE;
161 hitE->GetPositionL(xE, yE, zE);
162
b0f5e3fc 163 xE *= kconvm;
164 yE *= kconvm;
165 zE *= kconvm;
166
167 Float_t dx = (xE - xI);
168 Float_t dz = (zE - zI);
169
170
171 // Debuging
172 /*
e8189707 173 fSegmentation->GetPadIxz(xI,zI,stripP,stripN);
b0f5e3fc 174
175 printf("%5d %8.3f %8.3f %8.3f %8.3f %d %d %d\n",
176 hitNo, xI, zI, dx, dz,
177 stripP, stripN, track);
178 printf("%10.5f %10d \n", ionization, hitI->fTrack);
179 */
180
181 // end of debuging
182
183
184 eP=0;
185 eN=0;
b0f5e3fc 186
e8189707 187 for (i=0; i<fSteps; i++) {
b0f5e3fc 188
189 // arrayEP[i] = gRandom->Landau(ionization/fSteps, ionization/(4*fSteps));
190 // arrayEN[i] = gRandom->Landau(ionization/fSteps, ionization/(4*fSteps));
191 arrayEP[i] = ionization/fSteps;
192 arrayEN[i] = ionization/fSteps;
193
194 eP += arrayEP[i];
195 eN += arrayEN[i];
196 }
197
198 const Float_t kconv = 1.0e9 / 3.6; // GeV -> e-hole pairs
199
200 for(i=0; i<fSteps; i++) {
201
202 arrayEP[i] = kconv * arrayEP[i] * (ionization / eP);
203 arrayEN[i] = kconv * arrayEN[i] * (ionization / eN);
204 }
205
206 dx /= fSteps;
207 dz /= fSteps;
208
209 Float_t sigmaP, sigmaN;
210 fResponse->SigmaSpread(sigmaP,sigmaN);
211
212 //printf("SigmaP SigmaN %f %f\n",sigmaP, sigmaN);
213
214 Float_t noiseP, noiseN;
215 fResponse->GetNoiseParam(noiseP,noiseN);
216
217 //printf("NoiseP NoiseN %f %f\n",noiseP, noiseN);
218
219 for(i=0; i<fSteps; i++) {
220
221 Int_t j;
222
e8189707 223 fSegmentation->GetPadIxz(xI,zI,stripP,stripN);
224 //printf("hitNo %d i xI zI stripP stripN %d %f %f %d %d\n",hitNo,i,xI, zI, stripP, stripN);
b0f5e3fc 225 dsP = Get2Strip(1,stripP,xI, zI); // Between 0-1
226 dsN = Get2Strip(0,stripN,xI, zI); // Between 0-1
227
228 sP = sigmaP * sqrt(300. * i / (fSteps));
229 sN = sigmaN * sqrt(300. * i /(fSteps-i));
230
231
232 sP = (i<2 && dsP>0.3 && dsP<0.7)? 20. : sP; // square of (microns)
233 sN = (i>fSteps-2 && dsN>0.3 && dsN<0.7)? 20. : sN; // square of (microns)
234
235 sP = (i==2 && dsP>0.4 && dsP<0.6)? 15. : sP; // square of (microns)
236 sN = (i==8 && dsN>0.4 && dsN<0.6)? 15. : sN; // square of (microns)
237
e8189707 238 for (j=-1; j<2; j++) {
b0f5e3fc 239 if (stripP+j<0 || stripP+j>fNstrips) continue;
b0f5e3fc 240 signal = arrayEP[i] * TMath::Abs( (F(j+0.5-dsP,sP)-F(j-0.5-dsP,sP)) );
241 //printf("SimSSD::HitsToDigits:%d arrayEP[%d]=%e signal=%e\n",j,i,arrayEP[i],signal);
242 if (signal > noiseP/fSteps) {
243 (*fP)[stripP+j] += signal;
244 dict = (fTracksP+stripP+j);
245 (*dict).AddTrack(track);
246 }
247 } // end for j loop over neighboring strips
e8189707 248
249 for (j=-1; j<2; j++) {
b0f5e3fc 250 if (stripN+j<0 || stripN+j>fNstrips) continue;
b0f5e3fc 251 signal = arrayEN[i] * TMath::Abs( (F(j+0.5-dsN,sN)-F(j-0.5-dsN,sN)) );
252 //printf("SimSSD::HitsToDigits:%d arrayEN[%d]=%e signal=%e\n",j,i,arrayEN[i],signal);
253 if (signal > noiseN/fSteps) {
254 (*fN)[stripN+j] += signal;
255 dict = (fTracksN+stripN+j); //co to jest
256 (*dict).AddTrack(track);
257 }
258 } // end for j loop over neighboring strips
259
260 xI += dx;
261 zI += dz;
262 }
263
264
265}
266
267
268//____________________________________________________________________
269//
270// Private Methods for Simulation
271//______________________________________________________________________
272//
273
274void AliITSsimulationSSD::ApplyNoise() {
275 // Apply Noise.
276 Float_t noiseP, noiseN;
277 fResponse->GetNoiseParam(noiseP,noiseN);
278
279 Int_t i;
280 for(i = 0; i<fNstrips; i++) {
281 (*fP)[i] += gRandom->Gaus(0,noiseP);
282 (*fN)[i] += gRandom->Gaus(0,noiseN);
283 }
284}
285
286//_________________________________________________________________________
287
288void AliITSsimulationSSD::ApplyCoupling() {
289 // Apply the effecto of electronic coupling between channels
b0f5e3fc 290 Int_t i;
291 for(i = 1; i<fNstrips-1; i++) {
292 (*fP)[i] += (*fP)[i-1]*fDCS->GetCouplingPL() + (*fP)[i+1]*fDCS->GetCouplingPR();
293 (*fN)[i] += (*fN)[i-1]*fDCS->GetCouplingNL() + (*fN)[i+1]*fDCS->GetCouplingNR();
294 }
295}
296
297//__________________________________________________________________________
298
299void AliITSsimulationSSD::ApplyThreshold() {
300 // Applies the effect of a threshold on the signals for digitization.
301 Float_t noiseP, noiseN;
302 fResponse->GetNoiseParam(noiseP,noiseN);
303
304 // or introduce the SetThresholds in fResponse
305
306 Int_t i;
307 for(i=0; i<fNstrips; i++) {
308 (*fP)[i] = ((*fP)[i] > noiseP*4) ? (*fP)[i] : 0;
309 (*fN)[i] = ((*fN)[i] > noiseN*4) ? (*fN)[i] : 0;
b0f5e3fc 310 }
311
312}
313
314//__________________________________________________________________________
315
316void AliITSsimulationSSD::ApplyDAQ() {
317 // Converts simulated signals to simulated ADC counts
318 AliITS *its=(AliITS*)gAlice->GetModule("ITS");
319
320 Float_t noiseP, noiseN;
321 fResponse->GetNoiseParam(noiseP,noiseN);
322
e8189707 323 char opt[30],dummy[20];
324 fResponse->ParamOptions(opt,dummy);
325
b0f5e3fc 326 Int_t i,j;
e8189707 327 if (strstr(opt,"SetInvalid")) {
328 // Set signal = 0 if invalid strip
329 for(i=0; i<fNstrips; i++) {
330 if (!(fDCS->IsValidP(i))) (*fP)[i] = 0;
331 if (!(fDCS->IsValidN(i))) (*fN)[i] = 0;
332 }
b0f5e3fc 333 }
334
e8189707 335 Int_t digits[3], tracks[3], hits[3];
b0f5e3fc 336 Float_t charges[3];
337 Float_t phys=0;
e8189707 338 for(i=0;i<3;i++) tracks[i]=0;
b0f5e3fc 339 for(i=0; i<fNstrips; i++) {
e8189707 340 if( (strstr(opt,"SetInvalid") && (*fP)[i] < noiseP*4) || !(*fP)[i]) continue;
b0f5e3fc 341 digits[0]=1;
342 digits[1]=i;
343 digits[2]=(int)(*fP)[i];
344 for(j=0; j<(fTracksP+i)->GetNTracks(); j++) {
e8189707 345 if(j>2) continue;
346 if((fTracksP+i)->GetNTracks()) tracks[j]=(fTracksP+i)->GetTrack(j);
347 else tracks[j]=-2;
348 charges[j] = 0;
349 hits[j] = -1;
b0f5e3fc 350 }
e8189707 351 its->AddSimDigit(2,phys,digits,tracks,hits,charges);
b0f5e3fc 352
b0f5e3fc 353 }
354
355
356 for(i=0; i<fNstrips; i++) {
e8189707 357 if( (strstr(opt,"SetInvalid") && (*fN)[i] < noiseN*4)|| !(*fN)[i]) continue;
b0f5e3fc 358 digits[0]=0;
359 digits[1]=i;
360 digits[2]=(int)(*fN)[i];
e8189707 361 for( j=0; j<(fTracksN+i)->GetNTracks(); j++) {
362 if(j>2) continue;
363 if((fTracksN+i)->GetNTracks()) tracks[j]=(fTracksN+i)->GetTrack(j);
364 else tracks[j]=-2;
365 charges[j] = 0;
366 hits[j] = -1;
b0f5e3fc 367 }
e8189707 368 its->AddSimDigit(2,phys,digits,tracks,hits,charges);
b0f5e3fc 369
b0f5e3fc 370 }
371
372}
373
374
375//____________________________________________________________________________
376
377Float_t AliITSsimulationSSD::F(Float_t x, Float_t s) {
378 // Computes the integral of a gaussian at the mean valuse x with sigma s.
e8189707 379
b0f5e3fc 380 //printf("SDD:F(%e,%e)\n",x,s);
381 return 0.5*TMath::Erf(x * fPitch / s) ;
382}
383
384//______________________________________________________________________
385
386Float_t AliITSsimulationSSD::Get2Strip(Int_t flag, Int_t iStrip, Float_t x, Float_t z){
387 // Returns the relative space between two strips.
388
389 // flag==1 for Pside, 0 for Nside
390
391 Float_t stereoP, stereoN;
392 fSegmentation->Angles(stereoP,stereoN);
393
394 Float_t tanP=TMath::Tan(stereoP);
395 Float_t tanN=TMath::Tan(stereoN);
396
397 Float_t dx = fSegmentation->Dx();
398 Float_t dz = fSegmentation->Dz();
399
400
401 x += dx/2;
402 z += dz/2;
403
404 if (flag) return (x - z*tanP) / fPitch - iStrip; // from 0 to 1
405 else return (x - tanN*(dz - z)) / fPitch - iStrip;
406}
407//____________________________________________________________________________