]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - ITS/AliITSsimulationSPD.cxx
Corrections for memory leaks, random numbers, hit number; also some data members...
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSPD.cxx
... / ...
CommitLineData
1#include <iostream.h>
2#include <TRandom.h>
3#include <TH1.h>
4#include <TMath.h>
5#include <TString.h>
6#include <TParticle.h>
7
8
9#include "AliRun.h"
10#include "AliITS.h"
11#include "AliITShit.h"
12#include "AliITSdigit.h"
13#include "AliITSmodule.h"
14#include "AliITSMapA2.h"
15#include "AliITSsimulationSPD.h"
16#include "AliITSsegmentation.h"
17#include "AliITSresponse.h"
18
19
20
21
22ClassImp(AliITSsimulationSPD)
23////////////////////////////////////////////////////////////////////////
24// Version: 0
25// Written by Boris Batyunya
26// December 20 1999
27//
28// AliITSsimulationSPD is the simulation of SPDs
29//________________________________________________________________________
30
31
32AliITSsimulationSPD::AliITSsimulationSPD()
33{
34 // constructor
35 fResponse = 0;
36 fSegmentation = 0;
37 fMapA2=0;
38 fHis = 0;
39 fNoise=0.;
40 fBaseline=0.;
41 fNPixelsZ=0;
42 fNPixelsX=0;
43}
44
45
46//_____________________________________________________________________________
47
48AliITSsimulationSPD::AliITSsimulationSPD(AliITSsegmentation *seg, AliITSresponse *resp) {
49 // standard constructor
50
51 fHis = 0;
52 fResponse = resp;
53 fSegmentation = seg;
54
55 fResponse->GetNoiseParam(fNoise,fBaseline);
56
57 fMapA2 = new AliITSMapA2(fSegmentation);
58
59 //
60
61 fNPixelsZ=fSegmentation->Npz();
62 fNPixelsX=fSegmentation->Npx();
63
64}
65
66//_____________________________________________________________________________
67
68AliITSsimulationSPD::~AliITSsimulationSPD() {
69 // destructor
70
71 delete fMapA2;
72
73 if (fHis) {
74 fHis->Delete();
75 delete fHis;
76 }
77}
78
79
80//__________________________________________________________________________
81AliITSsimulationSPD::AliITSsimulationSPD(const AliITSsimulationSPD &source){
82 // Copy Constructor
83 if(&source == this) return;
84 this->fMapA2 = source.fMapA2;
85 this->fNoise = source.fNoise;
86 this->fBaseline = source.fBaseline;
87 this->fNPixelsX = source.fNPixelsX;
88 this->fNPixelsZ = source.fNPixelsZ;
89 this->fHis = source.fHis;
90 return;
91}
92
93//_________________________________________________________________________
94AliITSsimulationSPD&
95 AliITSsimulationSPD::operator=(const AliITSsimulationSPD &source) {
96 // Assignment operator
97 if(&source == this) return *this;
98 this->fMapA2 = source.fMapA2;
99 this->fNoise = source.fNoise;
100 this->fBaseline = source.fBaseline;
101 this->fNPixelsX = source.fNPixelsX;
102 this->fNPixelsZ = source.fNPixelsZ;
103 this->fHis = source.fHis;
104 return *this;
105 }
106//_____________________________________________________________________________
107
108void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t dummy)
109{
110 // digitize module
111
112 const Float_t kEnToEl = 2.778e+8; // GeV->charge in electrons
113 // for 3.6 eV/pair
114 const Float_t kconv = 10000.; // cm -> microns
115
116 Float_t spdLength = fSegmentation->Dz();
117 Float_t spdWidth = fSegmentation->Dx();
118
119 Float_t difCoef, dum;
120 fResponse->DiffCoeff(difCoef,dum);
121
122 Float_t zPix0 = 1e+6;
123 Float_t xPix0 = 1e+6;
124 Float_t yPrev = 1e+6;
125
126 Float_t zPitch = fSegmentation->Dpz(0);
127 Float_t xPitch = fSegmentation->Dpx(0);
128
129 TObjArray *fHits = mod->GetHits();
130 Int_t nhits = fHits->GetEntriesFast();
131 if (!nhits) return;
132
133 //cout<<"len,wid,dy,nx,nz,pitchx,pitchz ="<<spdLength<<","<<spdWidth<<","<<fSegmentation->Dy()<<","<<fNPixelsX<<","<<fNPixelsZ<<","<<xPitch<<","<<zPitch<<endl;
134 // Array of pointers to the label-signal list
135
136 Int_t maxNDigits = fNPixelsX*fNPixelsZ + fNPixelsX ;;
137 Float_t **pList = new Float_t* [maxNDigits];
138 memset(pList,0,sizeof(Float_t*)*maxNDigits);
139 Int_t indexRange[4] = {0,0,0,0};
140
141 // Fill detector maps with GEANT hits
142 // loop over hits in the module
143 static Bool_t first;
144 Int_t lasttrack=-2;
145 Int_t hit, iZi, jz, jx;
146 //cout<<"SPD: module,nhits ="<<module<<","<<nhits<<endl;
147 Int_t idhit=-1;
148 for (hit=0;hit<nhits;hit++) {
149 AliITShit *iHit = (AliITShit*) fHits->At(hit);
150 Int_t layer = iHit->GetLayer();
151 Float_t yPix0 = -73;
152 if(layer == 1) yPix0 = -77;
153
154 if(iHit->StatusEntering()) idhit=hit;
155 Int_t itrack = iHit->GetTrack();
156 Int_t dray = 0;
157
158 if (lasttrack != itrack || hit==(nhits-1)) first = kTRUE;
159
160 // Int_t parent = iHit->GetParticle()->GetFirstMother();
161 Int_t partcode = iHit->GetParticle()->GetPdgCode();
162
163// partcode (pdgCode): 11 - e-, 13 - mu-, 22 - gamma, 111 - pi0, 211 - pi+
164// 310 - K0s, 321 - K+, 2112 - n, 2212 - p, 3122 - lambda
165
166 /*
167 Float_t px = iHit->GetPXL(); // the momenta at the
168 Float_t py = iHit->GetPYL(); // each GEANT step
169 Float_t pz = iHit->GetPZL();
170 Float_t ptot = 1000*sqrt(px*px+py*py+pz*pz);
171 */
172
173 Float_t pmod = iHit->GetParticle()->P(); // total momentum at the
174 // vertex
175 pmod *= 1000;
176
177
178 if(partcode == 11 && pmod < 6) dray = 1; // delta ray is e-
179 // at p < 6 MeV/c
180
181
182 // Get hit z and x(r*phi) cordinates for each module (detector)
183 // in local system.
184
185 Float_t zPix = kconv*iHit->GetZL();
186 Float_t xPix = kconv*iHit->GetXL();
187 Float_t yPix = kconv*iHit->GetYL();
188
189 // Get track status
190 Int_t status = iHit->GetTrackStatus();
191 //cout<<"hit,status,y ="<<hit<<","<<status<<","<<yPix<<endl;
192
193 // Check boundaries
194 if(zPix > spdLength/2) {
195 //cout<<"!!!1 z outside ="<<zPix<<endl;
196 zPix = spdLength/2 - 10;
197 //cout<<"!!!2 z outside ="<<zPix<<endl;
198 }
199 if(zPix < 0 && zPix < -spdLength/2) {
200 //cout<<"!!!1 z outside ="<<zPix<<endl;
201 zPix = -spdLength/2 + 10;
202 //cout<<"!!!2 z outside ="<<zPix<<endl;
203 }
204 if(xPix > spdWidth/2) {
205 //cout<<"!!!1 x outside ="<<xPix<<endl;
206 xPix = spdWidth/2 - 10;
207 //cout<<"!!!2 x outside ="<<xPix<<endl;
208 }
209 if(xPix < 0 && xPix < -spdWidth/2) {
210 //cout<<"!!!1 x outside ="<<xPix<<endl;
211 xPix = -spdWidth/2 + 10;
212 //cout<<"!!!2 x outside ="<<xPix<<endl;
213 }
214 Int_t trdown = 0;
215
216 // enter Si or after event in Si
217 if (status == 66 ) {
218 zPix0 = zPix;
219 xPix0 = xPix;
220 yPrev = yPix;
221 }
222
223 Float_t depEnergy = iHit->GetIonization();
224 // skip if the input point to Si
225
226 if(depEnergy <= 0.) continue;
227
228 // if track returns to the opposite direction:
229 if (yPix < yPrev) {
230 trdown = 1;
231 }
232
233
234 // take into account the holes diffusion inside the Silicon
235 // the straight line between the entrance and exit points in Si is
236 // divided into the several steps; the diffusion is considered
237 // for each end point of step and charge
238 // is distributed between the pixels through the diffusion.
239
240
241 // ---------- the diffusion in Z (beam) direction -------
242
243 Float_t charge = depEnergy*kEnToEl; // charge in e-
244 Float_t drPath = 0.;
245 Float_t tang = 0.;
246 Float_t sigmaDif = 0.;
247 Float_t zdif = zPix - zPix0;
248 Float_t xdif = xPix - xPix0;
249 Float_t ydif = TMath::Abs(yPix - yPrev);
250 Float_t ydif0 = TMath::Abs(yPrev - yPix0);
251
252 if(ydif < 1) continue; // ydif is not zero
253
254 Float_t projDif = sqrt(xdif*xdif + zdif*zdif);
255
256 Int_t ndZ = (Int_t)TMath::Abs(zdif/zPitch) + 1;
257 Int_t ndX = (Int_t)TMath::Abs(xdif/xPitch) + 1;
258
259 // number of the steps along the track:
260 Int_t nsteps = ndZ;
261 if(ndX > ndZ) nsteps = ndX;
262 if(nsteps < 6) nsteps = 6; // minimum number of the steps
263
264 if (projDif < 5 ) {
265 drPath = (yPix-yPix0)*1.e-4;
266 drPath = TMath::Abs(drPath); // drift path in cm
267 sigmaDif = difCoef*sqrt(drPath); // sigma diffusion in cm
268 sigmaDif = sigmaDif*kconv; // sigma diffusion in microns
269 nsteps = 1;
270 }
271
272 if(projDif > 5) tang = ydif/projDif;
273 Float_t dCharge = charge/nsteps; // charge in e- for one step
274 Float_t dZ = zdif/nsteps;
275 Float_t dX = xdif/nsteps;
276
277 for (iZi = 1;iZi <= nsteps;iZi++) {
278 Float_t dZn = iZi*dZ;
279 Float_t dXn = iZi*dX;
280 Float_t zPixn = zPix0 + dZn;
281 Float_t xPixn = xPix0 + dXn;
282
283 if(projDif >= 5) {
284 Float_t dProjn = sqrt(dZn*dZn+dXn*dXn);
285 drPath = dProjn*tang*1.e-4; // drift path for iZi step in cm
286 if(trdown == 0) {
287 drPath = TMath::Abs(drPath) + ydif0*1.e-4;
288 }
289 if(trdown == 1) {
290 drPath = ydif0*1.e-4 - TMath::Abs(drPath);
291 drPath = TMath::Abs(drPath);
292 }
293 sigmaDif = difCoef*sqrt(drPath);
294 sigmaDif = sigmaDif*kconv; // sigma diffusion in microns
295 }
296
297 zPixn = (zPixn + spdLength/2.);
298 xPixn = (xPixn + spdWidth/2.);
299 Int_t nZpix, nXpix;
300 fSegmentation->GetPadIxz(xPixn,zPixn,nXpix,nZpix);
301 zPitch = fSegmentation->Dpz(nZpix);
302 fSegmentation->GetPadTxz(xPixn,zPixn);
303 // set the window for the integration
304 Int_t jzmin = 1;
305 Int_t jzmax = 3;
306 if(nZpix == 1) jzmin =2;
307 if(nZpix == fNPixelsZ) jzmax = 2;
308
309 Int_t jxmin = 1;
310 Int_t jxmax = 3;
311 if(nXpix == 1) jxmin =2;
312 if(nXpix == fNPixelsX) jxmax = 2;
313
314 Float_t zpix = nZpix;
315 Float_t dZright = zPitch*(zpix - zPixn);
316 Float_t dZleft = zPitch - dZright;
317
318 Float_t xpix = nXpix;
319 Float_t dXright = xPitch*(xpix - xPixn);
320 Float_t dXleft = xPitch - dXright;
321
322 Float_t dZprev = 0.;
323 Float_t dZnext = 0.;
324 Float_t dXprev = 0.;
325 Float_t dXnext = 0.;
326
327 for(jz=jzmin; jz <=jzmax; jz++) {
328 if(jz == 1) {
329 dZprev = -zPitch - dZleft;
330 dZnext = -dZleft;
331 }
332 if(jz == 2) {
333 dZprev = -dZleft;
334 dZnext = dZright;
335 }
336 if(jz == 3) {
337 dZprev = dZright;
338 dZnext = dZright + zPitch;
339 }
340 // kz changes from 1 to the fNofPixels(270)
341 Int_t kz = nZpix + jz -2;
342
343 Float_t zArg1 = dZprev/sigmaDif;
344 Float_t zArg2 = dZnext/sigmaDif;
345 Float_t zProb1 = TMath::Erfc(zArg1);
346 Float_t zProb2 = TMath::Erfc(zArg2);
347 Float_t dZCharge =0.5*(zProb1-zProb2)*dCharge;
348
349
350 // ----------- holes diffusion in X(r*phi) direction --------
351
352 if(dZCharge > 1.) {
353 for(jx=jxmin; jx <=jxmax; jx++) {
354 if(jx == 1) {
355 dXprev = -xPitch - dXleft;
356 dXnext = -dXleft;
357 }
358 if(jx == 2) {
359 dXprev = -dXleft;
360 dXnext = dXright;
361 }
362 if(jx == 3) {
363 dXprev = dXright;
364 dXnext = dXright + xPitch;
365 }
366 Int_t kx = nXpix + jx -2;
367
368 Float_t xArg1 = dXprev/sigmaDif;
369 Float_t xArg2 = dXnext/sigmaDif;
370 Float_t xProb1 = TMath::Erfc(xArg1);
371 Float_t xProb2 = TMath::Erfc(xArg2);
372 Float_t dXCharge =0.5*(xProb1-xProb2)*dZCharge;
373
374 if(dXCharge > 1.) {
375 Int_t index = kz-1;
376
377 if (first) {
378 indexRange[0]=indexRange[1]=index;
379 indexRange[2]=indexRange[3]=kx-1;
380 first=kFALSE;
381 }
382
383 indexRange[0]=TMath::Min(indexRange[0],kz-1);
384 indexRange[1]=TMath::Max(indexRange[1],kz-1);
385 indexRange[2]=TMath::Min(indexRange[2],kx-1);
386 indexRange[3]=TMath::Max(indexRange[3],kx-1);
387
388 // build the list of digits for this module
389 Double_t signal=fMapA2->GetSignal(index,kx-1);
390 signal+=dXCharge;
391 fMapA2->SetHit(index,kx-1,(double)signal);
392 } // dXCharge > 1 e-
393 } // jx loop
394 } // dZCharge > 1 e-
395 } // jz loop
396 } // iZi loop
397
398 if (status == 65) { // the step is inside of Si
399 zPix0 = zPix;
400 xPix0 = xPix;
401 }
402 yPrev = yPix;
403
404 if(dray == 0) {
405 GetList(itrack,idhit,pList,indexRange);
406 }
407
408 lasttrack=itrack;
409 } // hit loop inside the module
410
411
412 // introduce the electronics effects and do zero-suppression
413 ChargeToSignal(pList);
414
415 // clean memory
416
417 fMapA2->ClearMap();
418
419
420}
421
422//---------------------------------------------
423void AliITSsimulationSPD::GetList(Int_t label,Int_t idhit,Float_t **pList,Int_t *indexRange)
424{
425 // lop over nonzero digits
426
427
428 //set protection
429 for(int k=0;k<4;k++) {
430 if (indexRange[k] < 0) indexRange[k]=0;
431 }
432
433 for(Int_t iz=indexRange[0];iz<indexRange[1]+1;iz++){
434 for(Int_t ix=indexRange[2];ix<indexRange[3]+1;ix++){
435
436 Float_t signal=fMapA2->GetSignal(iz,ix);
437
438 if (!signal) continue;
439
440 Int_t globalIndex = iz*fNPixelsX+ix; // GlobalIndex starts from 0!
441 if(!pList[globalIndex]){
442
443 //
444 // Create new list (9 elements - 3 signals and 3 tracks + 3 hits)
445 //
446
447 pList[globalIndex] = new Float_t [9];
448
449 // set list to -3
450
451 *pList[globalIndex] = -3.;
452 *(pList[globalIndex]+1) = -3.;
453 *(pList[globalIndex]+2) = -3.;
454 *(pList[globalIndex]+3) = 0.;
455 *(pList[globalIndex]+4) = 0.;
456 *(pList[globalIndex]+5) = 0.;
457 *(pList[globalIndex]+6) = -1.;
458 *(pList[globalIndex]+7) = -1.;
459 *(pList[globalIndex]+8) = -1.;
460
461
462 *pList[globalIndex] = (float)label;
463 *(pList[globalIndex]+3) = signal;
464 *(pList[globalIndex]+6) = (float)idhit;
465 }
466 else{
467
468 // check the signal magnitude
469
470 Float_t highest = *(pList[globalIndex]+3);
471 Float_t middle = *(pList[globalIndex]+4);
472 Float_t lowest = *(pList[globalIndex]+5);
473
474 signal -= (highest+middle+lowest);
475
476 //
477 // compare the new signal with already existing list
478 //
479
480 if(signal<lowest) continue; // neglect this track
481
482 if (signal>highest){
483 *(pList[globalIndex]+5) = middle;
484 *(pList[globalIndex]+4) = highest;
485 *(pList[globalIndex]+3) = signal;
486
487 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
488 *(pList[globalIndex]+1) = *pList[globalIndex];
489 *pList[globalIndex] = label;
490
491 *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
492 *(pList[globalIndex]+7) = *(pList[globalIndex]+6);
493 *(pList[globalIndex]+6) = idhit;
494 }
495 else if (signal>middle){
496 *(pList[globalIndex]+5) = middle;
497 *(pList[globalIndex]+4) = signal;
498
499 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
500 *(pList[globalIndex]+1) = label;
501
502 *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
503 *(pList[globalIndex]+7) = idhit;
504 }
505 else{
506 *(pList[globalIndex]+5) = signal;
507 *(pList[globalIndex]+2) = label;
508 *(pList[globalIndex]+8) = idhit;
509 }
510 }
511 } // end of loop pixels in x
512 } // end of loop over pixels in z
513
514
515}
516
517
518//---------------------------------------------
519void AliITSsimulationSPD::ChargeToSignal(Float_t **pList)
520{
521 // add noise and electronics, perform the zero suppression and add the
522 // digit to the list
523
524 AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
525
526
527 Float_t threshold = (float)fResponse->MinVal();
528
529 Int_t digits[3], tracks[3], hits[3],gi,j1;
530 Float_t charges[3];
531 Float_t electronics;
532 Float_t signal,phys;
533 for(Int_t iz=0;iz<fNPixelsZ;iz++){
534 for(Int_t ix=0;ix<fNPixelsX;ix++){
535 electronics = fBaseline + fNoise*gRandom->Gaus();
536 signal = (float)fMapA2->GetSignal(iz,ix);
537 signal += electronics;
538 gi =iz*fNPixelsX+ix; // global index
539 if (signal > threshold) {
540 digits[0]=iz;
541 digits[1]=ix;
542 digits[2]=1;
543 for(j1=0;j1<3;j1++){
544 if (pList[gi]) {
545 //b.b. tracks[j1]=-3;
546 tracks[j1] = (Int_t)(*(pList[gi]+j1));
547 hits[j1] = (Int_t)(*(pList[gi]+j1+6));
548 }else {
549 tracks[j1]=-2; //noise
550 hits[j1] = -1;
551 }
552 charges[j1] = 0;
553 }
554
555 if(tracks[0] == tracks[1] && tracks[0] == tracks[2]) {
556 tracks[1] = -3;
557 hits[1] = -1;
558 tracks[2] = -3;
559 hits[2] = -1;
560 }
561 if(tracks[0] == tracks[1] && tracks[0] != tracks[2]) {
562 tracks[1] = -3;
563 hits[1] = -1;
564 }
565 if(tracks[0] == tracks[2] && tracks[0] != tracks[1]) {
566 tracks[2] = -3;
567 hits[2] = -1;
568 }
569 if(tracks[1] == tracks[2] && tracks[0] != tracks[1]) {
570 tracks[2] = -3;
571 hits[2] = -1;
572 }
573
574 phys=0;
575 aliITS->AddSimDigit(0,phys,digits,tracks,hits,charges);
576 }
577 if(pList[gi]) delete [] pList[gi];
578 }
579 }
580 delete [] pList;
581
582}
583
584
585//____________________________________________
586
587void AliITSsimulationSPD::CreateHistograms()
588{
589 // create 1D histograms for tests
590
591 printf("SPD - create histograms\n");
592
593 fHis=new TObjArray(fNPixelsZ);
594 for (Int_t i=0;i<fNPixelsZ;i++) {
595 TString spdName("spd_");
596 Char_t pixelz[4];
597 sprintf(pixelz,"%d",i+1);
598 spdName.Append(pixelz);
599 (*fHis)[i] = new TH1F(spdName.Data(),"SPD maps",
600 fNPixelsX,0.,(Float_t) fNPixelsX);
601 }
602}
603
604//____________________________________________
605
606void AliITSsimulationSPD::ResetHistograms()
607{
608 //
609 // Reset histograms for this detector
610 //
611
612 for ( int i=0;i<fNPixelsZ;i++ ) {
613 if ((*fHis)[i]) ((TH1F*)(*fHis)[i])->Reset();
614 }
615
616}
617
618
619
620
621
622
623
624
625