11 #include "AliITShit.h"
12 #include "AliITSdigit.h"
13 #include "AliITSmodule.h"
14 #include "AliITSMapA2.h"
15 #include "AliITSsimulationSPDbari.h"
16 #include "AliITSsegmentation.h"
17 #include "AliITSresponse.h"
20 ClassImp(AliITSsimulationSPDbari)
21 ////////////////////////////////////////////////////////////////////////
23 // Written by Rocco Caliandro
24 // from a model developed with T. Virgili and R.A. Fini
27 // AliITSsimulationSPD is the simulation of SPDs
29 //________________________________________________________________________
31 AliITSsimulationSPDbari::AliITSsimulationSPDbari(){
41 //_____________________________________________________________________________
43 AliITSsimulationSPDbari::AliITSsimulationSPDbari(AliITSsegmentation *seg, AliITSresponse *resp) {
48 fResponse->Thresholds(fThresh,fSigma);
49 fResponse->GetNoiseParam(fCouplCol,fCouplRow);
51 fMapA2 = new AliITSMapA2(fSegmentation);
54 fNPixelsZ=fSegmentation->Npz();
55 fNPixelsX=fSegmentation->Npx();
59 //_____________________________________________________________________________
61 AliITSsimulationSPDbari::~AliITSsimulationSPDbari() {
72 //__________________________________________________________________________
73 AliITSsimulationSPDbari::AliITSsimulationSPDbari(const AliITSsimulationSPDbari &source){
75 if(&source == this) return;
76 this->fMapA2 = source.fMapA2;
77 this->fThresh = source.fThresh;
78 this->fSigma = source.fSigma;
79 this->fCouplCol = source.fCouplCol;
80 this->fCouplRow = source.fCouplRow;
81 this->fNPixelsX = source.fNPixelsX;
82 this->fNPixelsZ = source.fNPixelsZ;
83 this->fHis = source.fHis;
87 //_________________________________________________________________________
88 AliITSsimulationSPDbari&
89 AliITSsimulationSPDbari::operator=(const AliITSsimulationSPDbari &source) {
90 // Assignment operator
91 if(&source == this) return *this;
92 this->fMapA2 = source.fMapA2;
93 this->fThresh = source.fThresh;
94 this->fSigma = source.fSigma;
95 this->fCouplCol = source.fCouplCol;
96 this->fCouplRow = source.fCouplRow;
97 this->fNPixelsX = source.fNPixelsX;
98 this->fNPixelsZ = source.fNPixelsZ;
99 this->fHis = source.fHis;
102 //_____________________________________________________________________________
104 void AliITSsimulationSPDbari::DigitiseModule(AliITSmodule *mod, Int_t module,
109 TObjArray *fHits = mod->GetHits();
110 Int_t nhits = fHits->GetEntriesFast();
114 //printf("Module %d (%d hits) \n",module+1,nhits);
118 Int_t *frowpixel = new Int_t[number];
119 Int_t *fcolpixel = new Int_t[number];
120 Double_t *fenepixel = new Double_t[number];
122 // Array of pointers to store the track index of the digits
123 // leave +1, otherwise pList crashes when col=256, row=192
124 Int_t maxNdigits = fNPixelsX*fNPixelsZ+fNPixelsX+1;
125 Float_t **pList = new Float_t* [maxNdigits];
126 memset(pList,0,sizeof(Float_t*)*maxNdigits);
130 SetFluctuations(pList);
134 // loop over hits in the module
136 for (hitpos=0;hitpos<nhits;hitpos++) {
137 HitToDigit(mod,hitpos,module,frowpixel,fcolpixel,fenepixel,pList);
138 }// end loop over digits
140 CreateDigit(nhits,module,pList);
150 //_____________________________________________________________________________
152 void AliITSsimulationSPDbari::UpdateMap( Int_t row, Int_t col, Double_t ene) {
154 // updates the Map of signal, adding the energy (ene) released by the current track
157 signal = fMapA2->GetSignal(row,col);
159 fMapA2->SetHit(row,col,signal);
162 //_____________________________________________________________________________
163 void AliITSsimulationSPDbari::HitToDigit(AliITSmodule *mod, Int_t hitpos, Int_t module,
164 Int_t *frowpixel, Int_t *fcolpixel,
165 Double_t *fenepixel, Float_t **pList) {
167 // Steering function to determine the digits associated to a given hit (hitpos)
168 // The digits are created by charge sharing (ChargeSharing) and by
169 // capacitive coupling (SetCoupling). At all the created digits is associated
170 // the track number of the hit (ntrack)
174 static Float_t x1l,y1l,z1l;
175 Float_t x2l,y2l,z2l,etot;
176 Int_t layer,r1,r2,c1,c2,row,col,npixel = 0;
179 const Float_t kconv = 10000.; // cm -> microns
181 TObjArray *fHits = mod->GetHits();
182 AliITShit *hit = (AliITShit*) fHits->At(hitpos);
183 layer = hit->GetLayer();
184 etot=hit->GetIonization();
185 ntrack=hit->GetTrack();
186 idhit=mod->GetHitHitIndex(hitpos);
190 printf("\n layer,etot,ntrack,status %d %f %d %d\n",layer,etot,ntrack,hit->GetTrackStatus()); //debug
191 Int_t idtrack; //debug
192 mod->GetHitTrackAndHitIndex(hitpos,idtrack,idhit);
193 printf("idtrack,idhit %d %d\n",idtrack,idhit); //debug
194 printf("(Dx, Dz)=(%f, %f)\n",fSegmentation->Dx(),fSegmentation->Dz()); //debug
199 if (hit->GetTrackStatus()==66) {
200 hit->GetPositionL(x1l,y1l,z1l);
201 // positions shifted and converted in microns
202 x1l = x1l*kconv + fSegmentation->Dx()/2.;
203 z1l = z1l*kconv + fSegmentation->Dz()/2.;
204 //printf("(x1l, z2l)=(%f, %f)\n",x1l,z1l); //debug
207 hit->GetPositionL(x2l,y2l,z2l);
208 // positions shifted and converted in microns
209 x2l = x2l*kconv + fSegmentation->Dx()/2.;
210 z2l = z2l*kconv + fSegmentation->Dz()/2.;
211 //printf("(x2l, z2l)=(%f, %f)\n",x2l,z2l); //debug
215 // to account for the effective sensitive area
216 // introduced in geometry
217 if (z1l<0 || z1l>fSegmentation->Dz()) return;
218 if (z2l<0 || z2l>fSegmentation->Dz()) return;
219 if (x1l<0 || x1l>fSegmentation->Dx()) return;
220 if (x2l<0 || x2l>fSegmentation->Dx()) return;
222 //Get the col and row number starting from 1
223 // the x direction is not inverted for the second layer!!!
224 fSegmentation->GetPadIxz(x1l, z1l, c1, r1);
225 fSegmentation->GetPadIxz(x2l, z2l, c2, r2);
227 //printf("(c1, r1)=(%d, %d) (c2, r2)=(%d, %d)\n",c1,r1,c2,r2); //debug
229 // to account for unexpected equal entrance and
231 if (x1l==x2l) x2l=x2l+x2l*0.000001;
232 if (z1l==z2l) z2l=z2l+z2l*0.000001;
235 if ((r1==r2) && (c1==c2))
239 frowpixel[npixel-1] = r1;
240 fcolpixel[npixel-1] = c1;
241 fenepixel[npixel-1] = etot;
245 ChargeSharing(x1l,z1l,x2l,z2l,c1,r1,c2,r2,etot,
246 npixel,frowpixel,fcolpixel,fenepixel);
251 for (Int_t npix=0;npix<npixel;npix++)
253 row = frowpixel[npix];
254 col = fcolpixel[npix];
255 ene = fenepixel[npix];
256 UpdateMap(row,col,ene);
257 GetList(ntrack,idhit,pList,row,col);
258 // Starting capacitive coupling effect
259 SetCoupling(row,col,ntrack,idhit,pList);
267 //_________________________________________________________________________
269 void AliITSsimulationSPDbari::ChargeSharing(Float_t x1l,Float_t z1l,Float_t x2l,
270 Float_t z2l,Int_t c1,Int_t r1,Int_t c2,
271 Int_t r2,Float_t etot,
272 Int_t &npixel,Int_t *frowpixel,
273 Int_t *fcolpixel,Double_t *fenepixel){
275 // Take into account the geometrical charge sharing when the track
276 // crosses more than one pixel.
280 <img src="picts/ITS/barimodel_2.gif">
283 <font size=+2 color=red>
284 <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
291 Float_t xa,za,xb,zb,dx,dz,dtot,dm,refr,refm,refc;
293 Float_t arefm, arefr, arefn, arefc, azb, az2l, axb, ax2l;
294 Int_t dirx,dirz,rb,cb;
297 Int_t flag,flagrow,flagcol;
305 dx = TMath::Abs(x1l-x2l);
306 dz = TMath::Abs(z1l-z2l);
307 dtot = TMath::Sqrt((dx*dx)+(dz*dz));
308 dm = (x2l - x1l) / (z2l - z1l);
310 dirx = (Int_t) ((x2l - x1l) / dx);
311 dirz = (Int_t) ((z2l - z1l) / dz);
314 // calculate the x coordinate of the pixel in the next column
315 // and the z coordinate of the pixel in the next row
319 fSegmentation->GetPadCxz(c1, r1-1, xpos, zpos);
321 Float_t xsize = fSegmentation->Dpx(0);
322 Float_t zsize = fSegmentation->Dpz(r1-1);
324 if (dirx == 1) refr = xpos+xsize/2.;
325 else refr = xpos-xsize/2.;
327 if (dirz == 1) refn = zpos+zsize/2.;
328 else refn = zpos-zsize/2.;
337 // calculate the x coordinate of the intersection with the pixel
338 // in the next cell in row direction
340 refm = (refn - z1l)*dm + x1l;
342 // calculate the z coordinate of the intersection with the pixel
343 // in the next cell in column direction
345 refc = (refr - x1l)/dm + z1l;
354 if ((arefm < arefr) && (arefn < arefc)){
356 // the track goes in the pixel in the next cell in row direction
363 if (rb == r2) flagrow=1;
369 // shift to the pixel in the next cell in row direction
370 Float_t zsizeNext = fSegmentation->Dpz(rb-1);
371 //to account for cell at the borders of the detector
372 if(zsizeNext==0) zsizeNext = zsize;
374 refn += zsizeNext*dirz;
379 // the track goes in the pixel in the next cell in column direction
386 if (cb == c2) flagcol=1;
392 // shift to the pixel in the next cell in column direction
393 Float_t xsizeNext = fSegmentation->Dpx(cb-1);
394 //to account for cell at the borders of the detector
395 if(xsizeNext==0) xsizeNext = xsize;
397 refr += xsizeNext*dirx;
401 //calculate the energy lost in the crossed pixel
402 epar = TMath::Sqrt((xb-xa)*(xb-xa)+(zb-za)*(zb-za));
403 epar = etot*(epar/dtot);
405 //store row, column and energy lost in the crossed pixel
406 frowpixel[npixel] = r1;
407 fcolpixel[npixel] = c1;
408 fenepixel[npixel] = epar;
411 // the exit point of the track is reached
412 if (epar == 0) flag = 1;
413 if ((r1 == r2) && (c1 == c2)) flag = 1;
424 //___________________________________________________________________________
425 void AliITSsimulationSPDbari::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
426 Int_t idhit, Float_t **pList) {
428 // Take into account the coupling between adiacent pixels.
429 // The parameters probcol and probrow are the fractions of the
430 // signal in one pixel shared in the two adjacent pixels along
431 // the column and row direction, respectively.
435 <img src="picts/ITS/barimodel_3.gif">
438 <font size=+2 color=red>
439 <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
447 Double_t pulse1,pulse2;
453 pulse1 = fMapA2->GetSignal(row,col);
456 for (Int_t isign=-1;isign<=1;isign+=2)
459 // loop in row direction
466 if ((j1 < 0) || (j1 > fNPixelsZ-1) || (pulse1 < fThresh))
468 pulse1 = fMapA2->GetSignal(row,col);
473 UpdateMap(j1,col,pulse1);
474 GetList(ntrack,idhit,pList,j1,col);
481 // loop in column direction
488 if ((j2 < 0) || (j2 > (fNPixelsX-1)) || (pulse2 < fThresh))
490 pulse2 = fMapA2->GetSignal(row,col);
495 UpdateMap(row,j2,pulse2);
496 GetList(ntrack,idhit,pList,row,j2);
505 //___________________________________________________________________________
506 void AliITSsimulationSPDbari::CreateDigit(Int_t nhits, Int_t module, Float_t
509 // The pixels are fired if the energy deposited inside them is above
510 // the threshold parameter ethr. Fired pixed are interpreted as digits
511 // and stored in the file digitfilename.
514 AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
525 for (Int_t r=1;r<=fNPixelsZ;r++) {
526 for (Int_t c=1;c<=fNPixelsX;c++) {
528 // check if the deposited energy in a pixel is above the threshold
529 Float_t signal = (Float_t) fMapA2->GetSignal(r,c);
530 gi =r*fNPixelsX+c; // global index
531 if ( signal > fThresh) {
532 digits[0] = r-1; // digits starts from 0
533 digits[1] = c-1; // digits starts from 0
535 signal = signal*1.0e9; //signal in eV
536 digits[2] = (Int_t) signal; // the signal is stored in eV
538 tracks[j1] = (Int_t)(*(pList[gi]+j1));
539 hits[j1] = (Int_t)(*(pList[gi]+j1+6));
543 printf("digits %d %d %d\n",digits[0],digits[1],digits[2]); //debug
544 printf("tracks %d %d %d\n",tracks[0],tracks[1],tracks[2]); //debug
545 printf("hits %d %d %d\n",hits[0],hits[1],hits[2]); //debug
548 aliITS->AddSimDigit(0,phys,digits,tracks,hits,charges);
549 }//endif of threshold condition
550 if(pList[gi]) delete [] pList[gi];
556 //_____________________________________________________________________________
558 void AliITSsimulationSPDbari::GetList(Int_t label,Int_t idhit, Float_t **pList,
559 Int_t row, Int_t col) {
560 // loop over nonzero digits
566 Float_t highest,middle,lowest;
569 signal=fMapA2->GetSignal(iz,ix);
572 globalIndex = iz*fNPixelsX+ix; // globalIndex starts from 1
575 if(!pList[globalIndex])
578 // Create new list (9 elements - 3 signals and 3 tracks + 3 hits)
581 pList[globalIndex] = new Float_t [9];
585 *(pList[globalIndex]) = -3.;
586 *(pList[globalIndex]+1) = -3.;
587 *(pList[globalIndex]+2) = -3.;
588 *(pList[globalIndex]+3) = 0.;
589 *(pList[globalIndex]+4) = 0.;
590 *(pList[globalIndex]+5) = 0.;
591 *(pList[globalIndex]+6) = -1.;
592 *(pList[globalIndex]+7) = -1.;
593 *(pList[globalIndex]+8) = -1.;
595 *pList[globalIndex] = (float)label;
596 *(pList[globalIndex]+3) = signal;
597 *(pList[globalIndex]+6) = (float)idhit;
602 // check the signal magnitude
603 highest = *(pList[globalIndex]+3);
604 middle = *(pList[globalIndex]+4);
605 lowest = *(pList[globalIndex]+5);
608 signal -= (highest+middle+lowest);
612 // compare the new signal with already existing list
614 if(signal<lowest) return; // neglect this track
618 *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
619 *(pList[globalIndex]+7) = *(pList[globalIndex]+6);
620 *(pList[globalIndex]+6) = idhit;
621 *(pList[globalIndex]+5) = middle;
622 *(pList[globalIndex]+4) = highest;
623 *(pList[globalIndex]+3) = signal;
624 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
625 *(pList[globalIndex]+1) = *pList[globalIndex];
626 *(pList[globalIndex]) = label;
628 else if (signal>middle)
630 *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
631 *(pList[globalIndex]+7) = idhit;
632 *(pList[globalIndex]+5) = middle;
633 *(pList[globalIndex]+4) = signal;
634 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
635 *(pList[globalIndex]+1) = label;
639 *(pList[globalIndex]+8) = idhit;
640 *(pList[globalIndex]+5) = signal;
641 *(pList[globalIndex]+2) = label;
645 //_________________________________________________________________________
646 void AliITSsimulationSPDbari::SetFluctuations(Float_t **pList) {
648 // Set the electronic noise and threshold non-uniformities to all the
649 // pixels in a detector.
650 // The parameter fSigma is the squared sum of the sigma due to noise
651 // and the sigma of the threshold distribution among pixels.
655 <img src="picts/ITS/barimodel_1.gif">
658 <font size=+2 color=red>
659 <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
669 for(iz=1;iz<=fNPixelsZ;iz++){
670 for(ix=1;ix<=fNPixelsX;ix++){
671 signal = fSigma*gRandom->Gaus();
672 fMapA2->SetHit(iz,ix,signal);
674 // insert in the label-signal-hit list the pixels fired only by noise
675 if ( signal > fThresh) {
676 Int_t globalIndex = iz*fNPixelsX+ix;
677 pList[globalIndex] = new Float_t [9];
678 *(pList[globalIndex]) = -2.;
679 *(pList[globalIndex]+1) = -2.;
680 *(pList[globalIndex]+2) = -2.;
681 *(pList[globalIndex]+3) = signal;
682 *(pList[globalIndex]+4) = 0.;
683 *(pList[globalIndex]+5) = 0.;
684 *(pList[globalIndex]+6) = -1.;
685 *(pList[globalIndex]+7) = -1.;
686 *(pList[globalIndex]+8) = -1.;
688 } // end of loop on pixels
689 } // end of loop on pixels
692 //____________________________________________
694 void AliITSsimulationSPDbari::CreateHistograms() {
698 fHis=new TObjArray(fNPixelsZ);
699 for(i=0;i<fNPixelsZ;i++) {
700 TString spdname("spd_");
702 sprintf(candnum,"%d",i+1);
703 spdname.Append(candnum);
704 (*fHis)[i] = new TH1F(spdname.Data(),"SPD maps",
705 fNPixelsX,0.,(Float_t) fNPixelsX);
710 //____________________________________________
712 void AliITSsimulationSPDbari::ResetHistograms() {
714 // Reset histograms for this detector
717 for(i=0;i<fNPixelsZ;i++ ) {
718 if ((*fHis)[i]) ((TH1F*)(*fHis)[i])->Reset();