10 #include "AliITSMapA2.h"
11 #include "AliITSsimulationSPD.h"
15 ClassImp(AliITSsimulationSPD)
16 ////////////////////////////////////////////////////////////////////////
18 // Written by Boris Batyunya
21 // AliITSsimulationSPD is the simulation of SPDs
22 //________________________________________________________________________
25 AliITSsimulationSPD::AliITSsimulationSPD()
36 //_____________________________________________________________________________
38 AliITSsimulationSPD::AliITSsimulationSPD(AliITSsegmentation *seg, AliITSresponse *resp) {
39 // standard constructor
44 fResponse->GetNoiseParam(fNoise,fBaseline);
46 fMapA2 = new AliITSMapA2(fSegmentation);
49 fNPixelsZ=fSegmentation->Npz();
50 fNPixelsX=fSegmentation->Npx();
54 //_____________________________________________________________________________
56 AliITSsimulationSPD::~AliITSsimulationSPD() {
68 //__________________________________________________________________________
69 AliITSsimulationSPD::AliITSsimulationSPD(const AliITSsimulationSPD &source){
71 if(&source == this) return;
72 this->fMapA2 = source.fMapA2;
73 this->fNoise = source.fNoise;
74 this->fBaseline = source.fBaseline;
75 this->fNPixelsX = source.fNPixelsX;
76 this->fNPixelsZ = source.fNPixelsZ;
77 this->fHis = source.fHis;
81 //_________________________________________________________________________
83 AliITSsimulationSPD::operator=(const AliITSsimulationSPD &source) {
84 // Assignment operator
85 if(&source == this) return *this;
86 this->fMapA2 = source.fMapA2;
87 this->fNoise = source.fNoise;
88 this->fBaseline = source.fBaseline;
89 this->fNPixelsX = source.fNPixelsX;
90 this->fNPixelsZ = source.fNPixelsZ;
91 this->fHis = source.fHis;
94 //_____________________________________________________________________________
96 void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t dummy)
100 const Float_t kEnToEl = 2.778e+8; // GeV->charge in electrons
102 const Float_t kconv = 10000.; // cm -> microns
104 Float_t spdLength = fSegmentation->Dz();
105 Float_t spdWidth = fSegmentation->Dx();
107 Float_t difCoef, dum;
108 fResponse->DiffCoeff(difCoef,dum);
110 Float_t zPix0 = 1e+6;
111 Float_t xPix0 = 1e+6;
112 Float_t yPix0 = 1e+6;
113 Float_t yPrev = 1e+6;
117 Float_t zPitch = fSegmentation->Dpz(0);
118 Float_t xPitch = fSegmentation->Dpx(0);
120 //cout << "pitch per z: " << zPitch << endl;
121 //cout << "pitch per r*phi: " << xPitch << endl;
123 TObjArray *fHits = mod->GetHits();
124 Int_t nhits = fHits->GetEntriesFast();
126 // cout << "module, nhits ="<<module<<","<<nhits<< endl;
128 // Array of pointers to the label-signal list
130 Int_t maxNDigits = fNPixelsX*fNPixelsZ + fNPixelsX ;;
131 Float_t **pList = new Float_t* [maxNDigits];
132 memset(pList,0,sizeof(Float_t*)*maxNDigits);
133 Int_t indexRange[4] = {0,0,0,0};
135 // Fill detector maps with GEANT hits
136 // loop over hits in the module
139 Int_t hit, iZi, jz, jx;
140 for (hit=0;hit<nhits;hit++) {
141 AliITShit *iHit = (AliITShit*) fHits->At(hit);
142 Int_t layer = iHit->GetLayer();
144 // work with the idtrack=entry number in the TreeH
146 mod->GetHitTrackAndHitIndex(hit,idtrack,idhit);
147 //Int_t idtrack=mod->GetHitTrackIndex(hit);
148 // or store straight away the particle position in the array
150 Int_t itrack = iHit->GetTrack();
153 if (lasttrack != itrack || hit==(nhits-1)) first = kTRUE;
155 // Int_t parent = iHit->GetParticle()->GetFirstMother();
156 Int_t partcode = iHit->GetParticle()->GetPdgCode();
158 // partcode (pdgCode): 11 - e-, 13 - mu-, 22 - gamma, 111 - pi0, 211 - pi+
159 // 310 - K0s, 321 - K+, 2112 - n, 2212 - p, 3122 - lambda
161 Float_t px = iHit->GetPXL();
162 Float_t py = iHit->GetPYL();
163 Float_t pz = iHit->GetPZL();
164 Float_t pmod = 1000*sqrt(px*px+py*py+pz*pz);
167 if(partcode == 11 && pmod < 6) dray = 1; // delta ray is e-
171 // Get hit z and x(r*phi) cordinates for each module (detector)
174 Float_t zPix = kconv*iHit->GetZL();
175 Float_t xPix = kconv*iHit->GetXL();
176 Float_t yPix = kconv*iHit->GetYL();
179 Int_t status = iHit->GetTrackStatus();
182 if(TMath::Abs(zPix) > spdLength/2.) {
183 printf("!! Zpix outside = %f\n",zPix);
184 if(status == 66) zP0=100;
189 if (TMath::Abs(xPix) > spdWidth/2.) {
190 printf("!! Xpix outside = %f\n",xPix);
191 if (status == 66) xP0=100;
195 Float_t zP = (zPix + spdLength/2.)/1000.;
196 Float_t xP = (xPix + spdWidth/2.)/1000.;
200 // enter Si or after event in Si
207 if (layer == 1 && status == 66 && yPix > 71.) {
213 if (layer == 2 && status == 66 && yPix < -71.) {
218 Float_t depEnergy = iHit->GetIonization();
219 // skip if the input point to Si
220 if(depEnergy <= 0.) continue;
221 // skip if the input point is outside of Si, but the next
222 // point is inside of Si
223 if(zP0 > 90 || xP0 > 90) continue;
224 // if track returns to the opposite direction:
225 if (layer == 1 && yPix > yPrev) {
229 if (layer == 2 && yPix < yPrev) {
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.
241 // ---------- the diffusion in Z (beam) direction -------
243 Float_t charge = depEnergy*kEnToEl; // charge in e-
246 Float_t sigmaDif = 0.;
247 Float_t zdif = zPix - zPix0;
248 Float_t xdif = xPix - xPix0;
249 Float_t ydif = yPix - yPix0;
251 if(TMath::Abs(ydif) < 0.1) continue; // Ydif is not zero
253 Float_t projDif = sqrt(xdif*xdif + zdif*zdif);
254 Int_t ndZ = (Int_t)TMath::Abs(zdif/zPitch) + 1;
255 Int_t ndX = (Int_t)TMath::Abs(xdif/xPitch) + 1;
257 // number of the steps along the track:
259 if(ndX > ndZ) nsteps = ndX;
260 if(nsteps < 6) nsteps = 6; // minimum number of the steps
262 if(TMath::Abs(projDif) > 5.0) tang = ydif/projDif;
263 Float_t dCharge = charge/nsteps; // charge in e- for one step
264 Float_t dZ = zdif/nsteps;
265 Float_t dX = xdif/nsteps;
267 if (TMath::Abs(projDif) < 5.0 ) {
269 drPath = TMath::Abs(drPath); // drift path in cm
270 sigmaDif = difCoef*sqrt(drPath); // sigma diffusion in cm
273 for (iZi = 1;iZi <= nsteps;iZi++) {
274 Float_t dZn = iZi*dZ;
275 Float_t dXn = iZi*dX;
276 Float_t zPixn = zPix0 + dZn;
277 Float_t xPixn = xPix0 + dXn;
279 if(TMath::Abs(projDif) >= 5.) {
280 Float_t dProjn = sqrt(dZn*dZn+dXn*dXn);
282 drPath = dProjn*tang*1.e-4; // drift path for iZi step in cm
283 drPath = TMath::Abs(drPath);
286 Float_t dProjn = projDif/nsteps;
287 drPath = (projDif-(iZi-1)*dProjn)*tang*1.e-4;
288 drPath = TMath::Abs(drPath);
290 sigmaDif = difCoef*sqrt(drPath);
291 sigmaDif = sigmaDif*kconv; // sigma diffusion in microns
293 zPixn = (zPixn + spdLength/2.);
294 xPixn = (xPixn + spdWidth/2.);
296 fSegmentation->GetPadIxz(xPixn,zPixn,nXpix,nZpix);
297 zPitch = fSegmentation->Dpz(nZpix);
298 fSegmentation->GetPadTxz(xPixn,zPixn);
299 // set the window for the integration
302 if(nZpix == 1) jzmin =2;
303 if(nZpix == fNPixelsZ) jzmax = 2;
307 if(nXpix == 1) jxmin =2;
308 if(nXpix == fNPixelsX) jxmax = 2;
310 Float_t zpix = nZpix;
311 Float_t dZright = zPitch*(zpix - zPixn);
312 Float_t dZleft = zPitch - dZright;
314 Float_t xpix = nXpix;
315 Float_t dXright = xPitch*(xpix - xPixn);
316 Float_t dXleft = xPitch - dXright;
323 for(jz=jzmin; jz <=jzmax; jz++) {
325 dZprev = -zPitch - dZleft;
334 dZnext = dZright + zPitch;
336 // kz changes from 1 to the fNofPixels(270)
337 Int_t kz = nZpix + jz -2;
339 Float_t zArg1 = dZprev/sigmaDif;
340 Float_t zArg2 = dZnext/sigmaDif;
341 Float_t zProb1 = TMath::Erfc(zArg1);
342 Float_t zProb2 = TMath::Erfc(zArg2);
343 Float_t dZCharge =0.5*(zProb1-zProb2)*dCharge;
346 // ----------- holes diffusion in X(r*phi) direction --------
349 for(jx=jxmin; jx <=jxmax; jx++) {
351 dXprev = -xPitch - dXleft;
360 dXnext = dXright + xPitch;
362 Int_t kx = nXpix + jx -2;
364 Float_t xArg1 = dXprev/sigmaDif;
365 Float_t xArg2 = dXnext/sigmaDif;
366 Float_t xProb1 = TMath::Erfc(xArg1);
367 Float_t xProb2 = TMath::Erfc(xArg2);
368 Float_t dXCharge =0.5*(xProb1-xProb2)*dZCharge;
374 indexRange[0]=indexRange[1]=index;
375 indexRange[2]=indexRange[3]=kx-1;
379 indexRange[0]=TMath::Min(indexRange[0],kz-1);
380 indexRange[1]=TMath::Max(indexRange[1],kz-1);
381 indexRange[2]=TMath::Min(indexRange[2],kx-1);
382 indexRange[3]=TMath::Max(indexRange[3],kx-1);
384 // build the list of digits for this module
385 Double_t signal=fMapA2->GetSignal(index,kx-1);
387 fMapA2->SetHit(index,kx-1,(double)signal);
394 if (status == 65) { // the step is inside of Si
401 GetList(itrack,idhit,pList,indexRange);
405 } // hit loop inside the module
408 // introduce the electronics effects and do zero-suppression
409 ChargeToSignal(pList);
418 //---------------------------------------------
419 void AliITSsimulationSPD::GetList(Int_t label,Int_t idhit,Float_t **pList,Int_t *indexRange)
421 // lop over nonzero digits
425 for(int k=0;k<4;k++) {
426 if (indexRange[k] < 0) indexRange[k]=0;
429 for(Int_t iz=indexRange[0];iz<indexRange[1]+1;iz++){
430 for(Int_t ix=indexRange[2];ix<indexRange[3]+1;ix++){
432 Float_t signal=fMapA2->GetSignal(iz,ix);
434 if (!signal) continue;
436 Int_t globalIndex = iz*fNPixelsX+ix; // GlobalIndex starts from 0!
437 if(!pList[globalIndex]){
440 // Create new list (9 elements - 3 signals and 3 tracks + 3 hits)
443 pList[globalIndex] = new Float_t [9];
447 *pList[globalIndex] = -3.;
448 *(pList[globalIndex]+1) = -3.;
449 *(pList[globalIndex]+2) = -3.;
450 *(pList[globalIndex]+3) = 0.;
451 *(pList[globalIndex]+4) = 0.;
452 *(pList[globalIndex]+5) = 0.;
453 *(pList[globalIndex]+6) = -1.;
454 *(pList[globalIndex]+7) = -1.;
455 *(pList[globalIndex]+8) = -1.;
458 *pList[globalIndex] = (float)label;
459 *(pList[globalIndex]+3) = signal;
460 *(pList[globalIndex]+6) = (float)idhit;
464 // check the signal magnitude
466 Float_t highest = *(pList[globalIndex]+3);
467 Float_t middle = *(pList[globalIndex]+4);
468 Float_t lowest = *(pList[globalIndex]+5);
470 signal -= (highest+middle+lowest);
473 // compare the new signal with already existing list
476 if(signal<lowest) continue; // neglect this track
479 *(pList[globalIndex]+5) = middle;
480 *(pList[globalIndex]+4) = highest;
481 *(pList[globalIndex]+3) = signal;
483 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
484 *(pList[globalIndex]+1) = *pList[globalIndex];
485 *pList[globalIndex] = label;
487 *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
488 *(pList[globalIndex]+7) = *(pList[globalIndex]+6);
489 *(pList[globalIndex]+6) = idhit;
491 else if (signal>middle){
492 *(pList[globalIndex]+5) = middle;
493 *(pList[globalIndex]+4) = signal;
495 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
496 *(pList[globalIndex]+1) = label;
498 *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
499 *(pList[globalIndex]+7) = idhit;
502 *(pList[globalIndex]+5) = signal;
503 *(pList[globalIndex]+2) = label;
504 *(pList[globalIndex]+8) = idhit;
507 } // end of loop pixels in x
508 } // end of loop over pixels in z
514 //---------------------------------------------
515 void AliITSsimulationSPD::ChargeToSignal(Float_t **pList)
517 // add noise and electronics, perform the zero suppression and add the
520 AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
523 TRandom *random = new TRandom();
524 Float_t threshold = (float)fResponse->MinVal();
526 Int_t digits[3], tracks[3], hits[3],gi,j1;
530 for(Int_t iz=0;iz<fNPixelsZ;iz++){
531 for(Int_t ix=0;ix<fNPixelsX;ix++){
532 electronics = fBaseline + fNoise*random->Gaus();
533 signal = (float)fMapA2->GetSignal(iz,ix);
534 signal += electronics;
535 gi =iz*fNPixelsX+ix; // global index
536 if (signal > threshold) {
542 tracks[j1] = (Int_t)(*(pList[gi]+j1));
543 hits[j1] = (Int_t)(*(pList[gi]+j1+6));
545 tracks[j1]=-2; //noise
551 if(tracks[0] == tracks[1] && tracks[0] == tracks[2]) {
557 if(tracks[0] == tracks[1] && tracks[0] != tracks[2]) {
561 if(tracks[0] == tracks[2] && tracks[0] != tracks[1]) {
565 if(tracks[1] == tracks[2] && tracks[0] != tracks[1]) {
571 aliITS->AddSimDigit(0,phys,digits,tracks,hits,charges);
573 if(pList[gi]) delete [] pList[gi];
581 //____________________________________________
583 void AliITSsimulationSPD::CreateHistograms()
585 // create 1D histograms for tests
587 printf("SPD - create histograms\n");
589 for (Int_t i=0;i<fNPixelsZ;i++) {
590 TString *spdname = new TString("spd_");
592 sprintf(pixelz,"%d",i+1);
593 spdname->Append(pixelz);
594 (*fHis)[i] = new TH1F(spdname->Data(),"SPD maps",
595 fNPixelsX,0.,(Float_t) fNPixelsX);
601 //____________________________________________
603 void AliITSsimulationSPD::ResetHistograms()
606 // Reset histograms for this detector
608 for ( int i=0;i<fNPixelsZ;i++ ) {
609 if ((*fHis)[i]) ((TH1F*)(*fHis)[i])->Reset();