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"
22 ClassImp(AliITSsimulationSPD)
23 ////////////////////////////////////////////////////////////////////////
25 // Written by Boris Batyunya
28 // AliITSsimulationSPD is the simulation of SPDs
29 //________________________________________________________________________
32 AliITSsimulationSPD::AliITSsimulationSPD()
46 //_____________________________________________________________________________
48 AliITSsimulationSPD::AliITSsimulationSPD(AliITSsegmentation *seg, AliITSresponse *resp) {
49 // standard constructor
55 fResponse->GetNoiseParam(fNoise,fBaseline);
57 fMapA2 = new AliITSMapA2(fSegmentation);
61 fNPixelsZ=fSegmentation->Npz();
62 fNPixelsX=fSegmentation->Npx();
66 //_____________________________________________________________________________
68 AliITSsimulationSPD::~AliITSsimulationSPD() {
80 //__________________________________________________________________________
81 AliITSsimulationSPD::AliITSsimulationSPD(const AliITSsimulationSPD &source){
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;
93 //_________________________________________________________________________
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;
106 //_____________________________________________________________________________
108 void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t dummy)
112 const Float_t kEnToEl = 2.778e+8; // GeV->charge in electrons
114 const Float_t kconv = 10000.; // cm -> microns
116 Float_t spdLength = fSegmentation->Dz();
117 Float_t spdWidth = fSegmentation->Dx();
119 Float_t difCoef, dum;
120 fResponse->DiffCoeff(difCoef,dum);
122 Float_t zPix0 = 1e+6;
123 Float_t xPix0 = 1e+6;
124 Float_t yPrev = 1e+6;
126 Float_t zPitch = fSegmentation->Dpz(0);
127 Float_t xPitch = fSegmentation->Dpx(0);
129 TObjArray *fHits = mod->GetHits();
130 Int_t nhits = fHits->GetEntriesFast();
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
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};
141 // Fill detector maps with GEANT hits
142 // loop over hits in the module
145 Int_t hit, iZi, jz, jx;
146 //cout<<"SPD: module,nhits ="<<module<<","<<nhits<<endl;
147 for (hit=0;hit<nhits;hit++) {
148 AliITShit *iHit = (AliITShit*) fHits->At(hit);
149 Int_t layer = iHit->GetLayer();
151 if(layer == 1) yPix0 = -77;
153 // work with the idtrack=entry number in the TreeH
155 mod->GetHitTrackAndHitIndex(hit,idtrack,idhit);
156 //Int_t idtrack=mod->GetHitTrackIndex(hit);
157 // or store straight away the particle position in the array
160 //b.b. if(iHit->StatusEntering()) idhit=hit;
161 Int_t itrack = iHit->GetTrack();
164 if (lasttrack != itrack || hit==(nhits-1)) first = kTRUE;
166 // Int_t parent = iHit->GetParticle()->GetFirstMother();
167 Int_t partcode = iHit->GetParticle()->GetPdgCode();
169 // partcode (pdgCode): 11 - e-, 13 - mu-, 22 - gamma, 111 - pi0, 211 - pi+
170 // 310 - K0s, 321 - K+, 2112 - n, 2212 - p, 3122 - lambda
173 Float_t px = iHit->GetPXL(); // the momenta at the
174 Float_t py = iHit->GetPYL(); // each GEANT step
175 Float_t pz = iHit->GetPZL();
176 Float_t ptot = 1000*sqrt(px*px+py*py+pz*pz);
179 Float_t pmod = iHit->GetParticle()->P(); // total momentum at the
184 if(partcode == 11 && pmod < 6) dray = 1; // delta ray is e-
188 // Get hit z and x(r*phi) cordinates for each module (detector)
191 Float_t zPix = kconv*iHit->GetZL();
192 Float_t xPix = kconv*iHit->GetXL();
193 Float_t yPix = kconv*iHit->GetYL();
196 Int_t status = iHit->GetTrackStatus();
197 //cout<<"hit,status,y ="<<hit<<","<<status<<","<<yPix<<endl;
200 if(zPix > spdLength/2) {
201 //cout<<"!!!1 z outside ="<<zPix<<endl;
202 zPix = spdLength/2 - 10;
203 //cout<<"!!!2 z outside ="<<zPix<<endl;
205 if(zPix < 0 && zPix < -spdLength/2) {
206 //cout<<"!!!1 z outside ="<<zPix<<endl;
207 zPix = -spdLength/2 + 10;
208 //cout<<"!!!2 z outside ="<<zPix<<endl;
210 if(xPix > spdWidth/2) {
211 //cout<<"!!!1 x outside ="<<xPix<<endl;
212 xPix = spdWidth/2 - 10;
213 //cout<<"!!!2 x outside ="<<xPix<<endl;
215 if(xPix < 0 && xPix < -spdWidth/2) {
216 //cout<<"!!!1 x outside ="<<xPix<<endl;
217 xPix = -spdWidth/2 + 10;
218 //cout<<"!!!2 x outside ="<<xPix<<endl;
222 // enter Si or after event in Si
229 Float_t depEnergy = iHit->GetIonization();
230 // skip if the input point to Si
232 if(depEnergy <= 0.) continue;
234 // if track returns to the opposite direction:
240 // take into account the holes diffusion inside the Silicon
241 // the straight line between the entrance and exit points in Si is
242 // divided into the several steps; the diffusion is considered
243 // for each end point of step and charge
244 // is distributed between the pixels through the diffusion.
247 // ---------- the diffusion in Z (beam) direction -------
249 Float_t charge = depEnergy*kEnToEl; // charge in e-
252 Float_t sigmaDif = 0.;
253 Float_t zdif = zPix - zPix0;
254 Float_t xdif = xPix - xPix0;
255 Float_t ydif = TMath::Abs(yPix - yPrev);
256 Float_t ydif0 = TMath::Abs(yPrev - yPix0);
258 if(ydif < 1) continue; // ydif is not zero
260 Float_t projDif = sqrt(xdif*xdif + zdif*zdif);
262 Int_t ndZ = (Int_t)TMath::Abs(zdif/zPitch) + 1;
263 Int_t ndX = (Int_t)TMath::Abs(xdif/xPitch) + 1;
265 // number of the steps along the track:
267 if(ndX > ndZ) nsteps = ndX;
268 if(nsteps < 6) nsteps = 6; // minimum number of the steps
271 drPath = (yPix-yPix0)*1.e-4;
272 drPath = TMath::Abs(drPath); // drift path in cm
273 sigmaDif = difCoef*sqrt(drPath); // sigma diffusion in cm
274 sigmaDif = sigmaDif*kconv; // sigma diffusion in microns
278 if(projDif > 5) tang = ydif/projDif;
279 Float_t dCharge = charge/nsteps; // charge in e- for one step
280 Float_t dZ = zdif/nsteps;
281 Float_t dX = xdif/nsteps;
283 for (iZi = 1;iZi <= nsteps;iZi++) {
284 Float_t dZn = iZi*dZ;
285 Float_t dXn = iZi*dX;
286 Float_t zPixn = zPix0 + dZn;
287 Float_t xPixn = xPix0 + dXn;
290 Float_t dProjn = sqrt(dZn*dZn+dXn*dXn);
291 drPath = dProjn*tang*1.e-4; // drift path for iZi step in cm
293 drPath = TMath::Abs(drPath) + ydif0*1.e-4;
296 drPath = ydif0*1.e-4 - TMath::Abs(drPath);
297 drPath = TMath::Abs(drPath);
299 sigmaDif = difCoef*sqrt(drPath);
300 sigmaDif = sigmaDif*kconv; // sigma diffusion in microns
303 zPixn = (zPixn + spdLength/2.);
304 xPixn = (xPixn + spdWidth/2.);
306 fSegmentation->GetPadIxz(xPixn,zPixn,nXpix,nZpix);
307 zPitch = fSegmentation->Dpz(nZpix);
308 fSegmentation->GetPadTxz(xPixn,zPixn);
309 // set the window for the integration
312 if(nZpix == 1) jzmin =2;
313 if(nZpix == fNPixelsZ) jzmax = 2;
317 if(nXpix == 1) jxmin =2;
318 if(nXpix == fNPixelsX) jxmax = 2;
320 Float_t zpix = nZpix;
321 Float_t dZright = zPitch*(zpix - zPixn);
322 Float_t dZleft = zPitch - dZright;
324 Float_t xpix = nXpix;
325 Float_t dXright = xPitch*(xpix - xPixn);
326 Float_t dXleft = xPitch - dXright;
333 for(jz=jzmin; jz <=jzmax; jz++) {
335 dZprev = -zPitch - dZleft;
344 dZnext = dZright + zPitch;
346 // kz changes from 1 to the fNofPixels(270)
347 Int_t kz = nZpix + jz -2;
349 Float_t zArg1 = dZprev/sigmaDif;
350 Float_t zArg2 = dZnext/sigmaDif;
351 Float_t zProb1 = TMath::Erfc(zArg1);
352 Float_t zProb2 = TMath::Erfc(zArg2);
353 Float_t dZCharge =0.5*(zProb1-zProb2)*dCharge;
356 // ----------- holes diffusion in X(r*phi) direction --------
359 for(jx=jxmin; jx <=jxmax; jx++) {
361 dXprev = -xPitch - dXleft;
370 dXnext = dXright + xPitch;
372 Int_t kx = nXpix + jx -2;
374 Float_t xArg1 = dXprev/sigmaDif;
375 Float_t xArg2 = dXnext/sigmaDif;
376 Float_t xProb1 = TMath::Erfc(xArg1);
377 Float_t xProb2 = TMath::Erfc(xArg2);
378 Float_t dXCharge =0.5*(xProb1-xProb2)*dZCharge;
384 indexRange[0]=indexRange[1]=index;
385 indexRange[2]=indexRange[3]=kx-1;
389 indexRange[0]=TMath::Min(indexRange[0],kz-1);
390 indexRange[1]=TMath::Max(indexRange[1],kz-1);
391 indexRange[2]=TMath::Min(indexRange[2],kx-1);
392 indexRange[3]=TMath::Max(indexRange[3],kx-1);
394 // build the list of digits for this module
395 Double_t signal=fMapA2->GetSignal(index,kx-1);
397 fMapA2->SetHit(index,kx-1,(double)signal);
404 if (status == 65) { // the step is inside of Si
411 GetList(itrack,idhit,pList,indexRange);
415 } // hit loop inside the module
418 // introduce the electronics effects and do zero-suppression
419 ChargeToSignal(pList);
428 //---------------------------------------------
429 void AliITSsimulationSPD::GetList(Int_t label,Int_t idhit,Float_t **pList,Int_t *indexRange)
431 // lop over nonzero digits
435 for(int k=0;k<4;k++) {
436 if (indexRange[k] < 0) indexRange[k]=0;
439 for(Int_t iz=indexRange[0];iz<indexRange[1]+1;iz++){
440 for(Int_t ix=indexRange[2];ix<indexRange[3]+1;ix++){
442 Float_t signal=fMapA2->GetSignal(iz,ix);
444 if (!signal) continue;
446 Int_t globalIndex = iz*fNPixelsX+ix; // GlobalIndex starts from 0!
447 if(!pList[globalIndex]){
450 // Create new list (9 elements - 3 signals and 3 tracks + 3 hits)
453 pList[globalIndex] = new Float_t [9];
457 *pList[globalIndex] = -3.;
458 *(pList[globalIndex]+1) = -3.;
459 *(pList[globalIndex]+2) = -3.;
460 *(pList[globalIndex]+3) = 0.;
461 *(pList[globalIndex]+4) = 0.;
462 *(pList[globalIndex]+5) = 0.;
463 *(pList[globalIndex]+6) = -1.;
464 *(pList[globalIndex]+7) = -1.;
465 *(pList[globalIndex]+8) = -1.;
468 *pList[globalIndex] = (float)label;
469 *(pList[globalIndex]+3) = signal;
470 *(pList[globalIndex]+6) = (float)idhit;
474 // check the signal magnitude
476 Float_t highest = *(pList[globalIndex]+3);
477 Float_t middle = *(pList[globalIndex]+4);
478 Float_t lowest = *(pList[globalIndex]+5);
480 signal -= (highest+middle+lowest);
483 // compare the new signal with already existing list
486 if(signal<lowest) continue; // neglect this track
489 *(pList[globalIndex]+5) = middle;
490 *(pList[globalIndex]+4) = highest;
491 *(pList[globalIndex]+3) = signal;
493 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
494 *(pList[globalIndex]+1) = *pList[globalIndex];
495 *pList[globalIndex] = label;
497 *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
498 *(pList[globalIndex]+7) = *(pList[globalIndex]+6);
499 *(pList[globalIndex]+6) = idhit;
501 else if (signal>middle){
502 *(pList[globalIndex]+5) = middle;
503 *(pList[globalIndex]+4) = signal;
505 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
506 *(pList[globalIndex]+1) = label;
508 *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
509 *(pList[globalIndex]+7) = idhit;
512 *(pList[globalIndex]+5) = signal;
513 *(pList[globalIndex]+2) = label;
514 *(pList[globalIndex]+8) = idhit;
517 } // end of loop pixels in x
518 } // end of loop over pixels in z
524 //---------------------------------------------
525 void AliITSsimulationSPD::ChargeToSignal(Float_t **pList)
527 // add noise and electronics, perform the zero suppression and add the
530 AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
533 TRandom *random = new TRandom();
534 Float_t threshold = (float)fResponse->MinVal();
536 Int_t digits[3], tracks[3], hits[3],gi,j1;
540 for(Int_t iz=0;iz<fNPixelsZ;iz++){
541 for(Int_t ix=0;ix<fNPixelsX;ix++){
542 electronics = fBaseline + fNoise*random->Gaus();
543 signal = (float)fMapA2->GetSignal(iz,ix);
544 signal += electronics;
545 gi =iz*fNPixelsX+ix; // global index
546 if (signal > threshold) {
552 //b.b. tracks[j1]=-3;
553 tracks[j1] = (Int_t)(*(pList[gi]+j1));
554 hits[j1] = (Int_t)(*(pList[gi]+j1+6));
556 tracks[j1]=-2; //noise
562 if(tracks[0] == tracks[1] && tracks[0] == tracks[2]) {
568 if(tracks[0] == tracks[1] && tracks[0] != tracks[2]) {
572 if(tracks[0] == tracks[2] && tracks[0] != tracks[1]) {
576 if(tracks[1] == tracks[2] && tracks[0] != tracks[1]) {
582 aliITS->AddSimDigit(0,phys,digits,tracks,hits,charges);
584 if(pList[gi]) delete [] pList[gi];
592 //____________________________________________
594 void AliITSsimulationSPD::CreateHistograms()
596 // create 1D histograms for tests
598 printf("SPD - create histograms\n");
600 fHis=new TObjArray(fNPixelsZ);
601 TString spdName("spd_");
602 for (Int_t i=0;i<fNPixelsZ;i++) {
604 sprintf(pixelz,"%d",i+1);
605 spdName.Append(pixelz);
606 (*fHis)[i] = new TH1F(spdName.Data(),"SPD maps",
607 fNPixelsX,0.,(Float_t) fNPixelsX);
611 //____________________________________________
613 void AliITSsimulationSPD::ResetHistograms()
616 // Reset histograms for this detector
619 for ( int i=0;i<fNPixelsZ;i++ ) {
620 if ((*fHis)[i]) ((TH1F*)(*fHis)[i])->Reset();