6 #include "AliITSMap.h" // "AliITSMapA2.h"
7 #include "AliITSsimulationSPD.h"
8 #include "AliITSsegmentation.h"
9 #include "AliITSresponse.h"
11 ClassImp(AliITSsimulationSPD)
12 ////////////////////////////////////////////////////////////////////////
14 // Written by Boris Batyunya
17 // AliITSsimulationSPD is the simulation of SPDs
19 //________________________________________________________________________
21 AliITSsimulationSPD::AliITSsimulationSPD(){
29 //_____________________________________________________________________________
31 AliITSsimulationSPD::AliITSsimulationSPD(AliITSsegmentation *seg, AliITSresponse *resp) {
36 fResponse->GetNoiseParam(fNoise,fBaseline);
39 fMapA2 = new AliITSMapA2(fSegmentation);
42 fNPixelsZ=fSegmentation->Npz();
43 fNPixelsX=fSegmentation->Npx();
47 //_____________________________________________________________________________
49 AliITSsimulationSPD::~AliITSsimulationSPD() {
60 //__________________________________________________________________________
61 AliITSsimulationSPD::AliITSsimulationSPD(const AliITSsimulationSPD &source){
63 if(&source == this) return;
64 this->fMapA2 = source.fMapA2;
65 this->fNoise = source.fNoise;
66 this->fBaseline = source.fBaseline;
67 this->fNPixelsX = source.fNPixelsX;
68 this->fNPixelsZ = source.fNPixelsZ;
69 this->fHis = source.fHis;
73 //_________________________________________________________________________
75 AliITSsimulationSPD::operator=(const AliITSsimulationSPD &source) {
76 // Assignment operator
77 if(&source == this) return *this;
78 this->fMapA2 = source.fMapA2;
79 this->fNoise = source.fNoise;
80 this->fBaseline = source.fBaseline;
81 this->fNPixelsX = source.fNPixelsX;
82 this->fNPixelsZ = source.fNPixelsZ;
83 this->fHis = source.fHis;
86 //_____________________________________________________________________________
88 void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t dummy) {
90 const Float_t kEntoEl = 2.778e+8; // GeV->charge in electrons
92 const Float_t kconv = 10000.; // cm -> microns
94 Float_t spdLenght = fSegmentation->Dz();
95 Float_t spdWidth = fSegmentation->Dx();
97 Float_t difCoef = fResponse->DiffCoeff();
100 Float_t xPix0 = 1e+6;
101 Float_t yPix0 = 1e+6;
102 Float_t yPrev = 1e+6;
104 Float_t zPitch = fSegmentation->Dpz(0);
105 Float_t xPitch = fSegmentation->Dpx(0);
107 //cout << "pitch per z: " << zPitch << endl;
108 //cout << "pitch per r*phi: " << xPitch << endl;
110 TObjArray *fHits = mod->GetHits();
111 Int_t nhits = fHits->GetEntriesFast();
116 // Array of pointers to the label-signal list
118 Int_t maxNdigits = fNPixelsX*fNPixelsZ;
119 Float_t **pList = new Float_t* [maxNdigits];
120 memset(pList,0,sizeof(Float_t*)*maxNdigits);
121 Int_t indexRange[4] = {0,0,0,0};
123 // Fill detector maps with GEANT hits
124 // loop over hits in the module
126 Int_t layer,idtrack,status,trdown,ndZ,ndX,nsteps,iZi,nZpix,nXpix;
127 Int_t jzmin,jzmax,jxmin,jxmax,jx,jz,lz,lx,index;
128 Float_t zArg1,zArg2,xArg1,xArg2;
129 Float_t zProb1,zProb2,xProb1,xProb2;
130 Float_t dZCharge,dXCharge;
132 Float_t projDif; // RMS of xDif and zDif
133 Float_t dProjn; // RMS of dXn and dZn
134 Float_t depEnergy; // The deposited energy from this hit
135 Float_t zPix; // hit position in microns
136 Float_t xPix; // hit position in microns
137 Float_t yPix; // hit position in microns
138 Float_t zPixn; // hit position in microns
139 Float_t xPixn; // hit position in microns
140 Float_t charge,dCharge;// charge in e-
142 Float_t tAng,dZ,dX,dXn,dZn;
144 Float_t dZright,dZleft;
145 Float_t dXright,dXleft;
146 Float_t dZprev,dZnext,dXprev,dXnext;
148 static Bool_t first=kTRUE;
149 Int_t lasttrack = -2,hit;
150 for(hit=0;hit<nhits;hit++) {
151 AliITShit *iHit = (AliITShit*) fHits->At(hit);
152 layer = iHit->GetLayer();
154 // work with the idtrack=entry number in the TreeH
155 // Int_t idtrack=mod->GetHitTrackIndex(ii);
156 // or store straight away the particle position in the array
158 idtrack = iHit->GetTrack();
160 //if(module==11 || module==157) {
161 // Int_t track = iHit->fTrack;
162 // Int_t primary = gAlice->GetPrimary(track);
163 // Int_t parent = iHit->GetParticle()->GetFirstMother();
164 // printf("module,hit,track,primary,parent %d %d %d %d %d \n",
165 // md,hit,track,primary,parent);
168 // Get hit z and x(r*phi) cordinates for each module (detector)
171 zPix = kconv*iHit->GetZL(); // Geant cm to microns
172 xPix = kconv*iHit->GetXL(); // Geant cm to micron
173 yPix = kconv*iHit->GetYL(); // Geant cm to micron
176 status = iHit->GetTrackStatus();
177 if(status != 66 && status != 68) {
178 printf("!!!!! no order status %d\n",status);
183 // enter Si or after event in Si
190 if (layer == 1 && status == 66 && yPix > 71.) {
194 if (layer == 2 && status == 66 && yPix < -71.) {
197 depEnergy = iHit->GetIonization();
198 // skip if the input point to Si
199 if(depEnergy <= 0.) continue;
200 // if track returns to the opposite direction:
201 if (layer == 1 && yPix > yPrev) {
205 if (layer == 2 && yPix < yPrev) {
210 // take into account the holes diffusion inside the Silicon
211 // the straight line between the entrance and exit points in Si is
212 // divided into the several steps; the diffusion is considered
213 // for each end point of step and charge
214 // is distributed between the pixels through the diffusion.
217 // ---------- the diffusion in Z (beam) direction -------
219 charge = depEnergy*kEntoEl; // charge in e-
223 Float_t zDif = zPix - zPix0;
224 Float_t xDif = xPix - xPix0;
225 Float_t yDif = yPix - yPix0;
227 if(TMath::Abs(yDif) < 0.1) continue; // yDif is not zero
230 projDif = sqrt(xDif*xDif + zDif*zDif);
231 ndZ = (Int_t)TMath::Abs(zDif/zPitch) + 1;
232 ndX = (Int_t)TMath::Abs(xDif/xPitch) + 1;
234 // number of the steps along the track:
236 if(ndX > ndZ) nsteps = ndX;
237 if(nsteps < 6) nsteps = 6; // minimum number of the steps
239 if(TMath::Abs(projDif) > 5.0) tAng = yDif/projDif;
240 dCharge = charge/nsteps; // charge in e- for one step
244 if (TMath::Abs(projDif) < 5.0 ) {
246 drPath = TMath::Abs(drPath); // drift path in cm
247 sigmaDif = difCoef*sqrt(drPath); // sigma diffusion in cm
250 for(iZi = 1;iZi <= nsteps;iZi++) {
256 if(TMath::Abs(projDif) >= 5.) {
257 dProjn = sqrt(dZn*dZn+dXn*dXn);
259 drPath = dProjn*tAng*1.e-4; // drift path for iZi step in cm
260 drPath = TMath::Abs(drPath);
263 dProjn = projDif/nsteps;
264 drPath = (projDif-(iZi-1)*dProjn)*tAng*1.e-4;
265 drPath = TMath::Abs(drPath);
267 sigmaDif = difCoef*sqrt(drPath);
268 sigmaDif = sigmaDif*kconv; // sigma diffusion in microns
270 zPixn = (zPixn + spdLenght/2.);
271 xPixn = (xPixn + spdWidth/2.);
272 fSegmentation->GetCellIxz(xPixn,zPixn,nXpix,nZpix);
273 zPitch = fSegmentation->Dpz(nZpix);
274 // set the window for the integration
277 if(nZpix == 1) jzmin =2;
278 if(nZpix == fNPixelsZ) jzmax = 2;
282 if(nXpix == 1) jxmin =2;
283 if(nXpix == fNPixelsX) jxmax = 2;
286 dZright = zPitch*(zPix - zPixn);
287 dZleft = zPitch - dZright;
289 dXright = xPitch*(xPix - xPixn);
290 dXleft = xPitch - dXright;
296 for(jz=jzmin; jz <=jzmax; jz++) {
298 dZprev = -zPitch - dZleft;
307 dZnext = dZright + zPitch;
309 // lz changes from 1 to the fNofPixels(270)
312 zArg1 = dZprev/sigmaDif;
313 zArg2 = dZnext/sigmaDif;
314 zProb1 = TMath::Erfc(zArg1);
315 zProb2 = TMath::Erfc(zArg2);
316 dZCharge =0.5*(zProb1-zProb2)*dCharge;
318 //printf("dZCharge %f \n",dZCharge);
320 // ----------- holes diffusion in X(r*phi) direction --------
323 for(jx=jxmin; jx <=jxmax; jx++) {
325 dXprev = -xPitch - dXleft;
334 dXnext = dXright + xPitch;
338 xArg1 = dXprev/sigmaDif;
339 xArg2 = dXnext/sigmaDif;
340 xProb1 = TMath::Erfc(xArg1);
341 xProb2 = TMath::Erfc(xArg2);
342 dXCharge =0.5*(xProb1-xProb2)*dZCharge;
344 //printf("dXCharge %f \n",dXCharge);
349 indexRange[0]=indexRange[1]=index;
350 indexRange[2]=indexRange[3]=lx-1;
354 indexRange[0]=TMath::Min(indexRange[0],lz-1);
355 indexRange[1]=TMath::Max(indexRange[1],lz-1);
356 indexRange[2]=TMath::Min(indexRange[2],lx-1);
357 indexRange[3]=TMath::Max(indexRange[3],lx-1);
358 // build the list of digits for this module
359 signal=fMapA2->GetSignal(index,lx-1);
361 fMapA2->SetHit(index,lx-1,(double)signal);
368 if (status == 65) { // the step is inside of Si
374 if (lasttrack != idtrack || hit==(nhits-1)) {
375 GetList(idtrack,pList,indexRange);
379 } // hit loop inside the module
382 // introduce the electronics effects and do zero-suppression
383 ChargeToSignal(pList);
392 //---------------------------------------------
393 void AliITSsimulationSPD::GetList(Int_t label,Float_t **pList,Int_t *indexRange) {
394 // loop over nonzero digits
396 Int_t ix,iz,globalIndex;
398 Float_t highest,middle,lowest;
400 for(iz=indexRange[0];iz<indexRange[1]+1;iz++){
401 for(ix=indexRange[2];ix<indexRange[3]+1;ix++){
403 signal=fMapA2->GetSignal(iz,ix);
405 globalIndex = iz*fNPixelsX+ix; // globalIndex starts from 0!
406 if(!pList[globalIndex]){
409 // Create new list (6 elements - 3 signals and 3 tracks + total sig)
412 pList[globalIndex] = new Float_t [6];
416 *pList[globalIndex] = -2.;
417 *(pList[globalIndex]+1) = -2.;
418 *(pList[globalIndex]+2) = -2.;
419 *(pList[globalIndex]+3) = 0.;
420 *(pList[globalIndex]+4) = 0.;
421 *(pList[globalIndex]+5) = 0.;
424 *pList[globalIndex] = (float)label;
425 *(pList[globalIndex]+3) = signal;
429 // check the signal magnitude
431 highest = *(pList[globalIndex]+3);
432 middle = *(pList[globalIndex]+4);
433 lowest = *(pList[globalIndex]+5);
435 signal -= (highest+middle+lowest);
438 // compare the new signal with already existing list
441 if(signal<lowest) continue; // neglect this track
444 *(pList[globalIndex]+5) = middle;
445 *(pList[globalIndex]+4) = highest;
446 *(pList[globalIndex]+3) = signal;
448 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
449 *(pList[globalIndex]+1) = *pList[globalIndex];
450 *pList[globalIndex] = label;
452 else if (signal>middle){
453 *(pList[globalIndex]+5) = middle;
454 *(pList[globalIndex]+4) = signal;
456 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
457 *(pList[globalIndex]+1) = label;
460 *(pList[globalIndex]+5) = signal;
461 *(pList[globalIndex]+2) = label;
464 } // end of loop pixels in x
465 } // end of loop over pixels in z
471 //---------------------------------------------
472 void AliITSsimulationSPD::ChargeToSignal(Float_t **pList) {
475 AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
478 TRandom *random = new TRandom();
479 Float_t threshold = (float)fResponse->MinVal();
481 Int_t digits[3], tracks[3],gi,j1;
486 for(iz=0;iz<fNPixelsZ;iz++){
487 for(ix=0;ix<fNPixelsX;ix++){
488 electronics = fBaseline + fNoise*random->Gaus();
489 signal = (float)fMapA2->GetSignal(iz,ix);
490 signal += electronics;
491 if (signal > threshold) {
495 gi =iz*fNPixelsX+ix; // global index
497 tracks[j1] = (Int_t)(*(pList[gi]+j1));
501 aliITS->AddDigit(0,phys,digits,tracks,charges);
502 if(pList[gi]) delete [] pList[gi];
512 //____________________________________________
514 void AliITSsimulationSPD::CreateHistograms() {
518 for(i=0;i<fNPixelsZ;i++) {
519 TString *spdname = new TString("spd_");
521 sprintf(candnum,"%d",i+1);
522 spdname->Append(candnum);
523 (*fHis)[i] = new TH1F(spdname->Data(),"SPD maps",
524 fNPixelsX,0.,(Float_t) fNPixelsX);
530 //____________________________________________
532 void AliITSsimulationSPD::ResetHistograms() {
534 // Reset histograms for this detector
537 for(i=0;i<fNPixelsZ;i++ ) {
538 if ((*fHis)[i]) ((TH1F*)(*fHis)[i])->Reset();