]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSsimulationSPD.cxx
Minor changes in support of changes to AliITSdigitS?D class'.
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSPD.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.18  2002/08/21 22:11:13  nilsen
19 Debug output now settable via a DEBUG flag.
20
21 Revision 1.17  2002/07/16 17:00:17  barbera
22 Fixes added to make the slow simulation running with the current HEAD (from M. Masera)
23
24 Revision 1.16  2002/06/19 16:02:22  hristov
25 Division by zero corrected
26
27 Revision 1.15  2002/03/15 17:32:14  nilsen
28 Reintroduced SDigitization, and Digitization from SDigits, along with
29 functions InitSimulationModule, and FinishSDigitizModule.
30
31 Revision 1.14  2001/11/23 13:04:07  barbera
32 Some protection added in case of high multiplicity
33
34 Revision 1.13  2001/11/13 11:13:24  barbera
35 A protection against tracks with the same entrance and exit has been made more strict
36
37 Revision 1.12  2001/10/04 22:44:31  nilsen
38 Major changes in supppor of PreDigits (SDigits). Changes made with will make
39 it easier to suppor expected changes in AliITSHit class. Added use of new
40 class AliITSpList. Both SPD and SDD have added effects of Dead Channels. Both
41 of these will require addtional work as data bases of detectors and the like
42 are developed.
43
44 */
45 #include <iostream.h>
46 #include <TRandom.h>
47 #include <TH1.h>
48 #include <TMath.h>
49 #include <TString.h>
50 #include <TParticle.h>
51
52 #include "AliRun.h"
53 #include "AliITS.h"
54 #include "AliITShit.h"
55 #include "AliITSdigit.h"
56 #include "AliITSmodule.h"
57 #include "AliITSMapA2.h"
58 #include "AliITSpList.h"
59 #include "AliITSsimulationSPD.h"
60 #include "AliITSsegmentation.h"
61 #include "AliITSresponse.h"
62 #include "AliITSsegmentationSPD.h"
63 #include "AliITSresponseSPD.h"
64
65 //#define DEBUG
66
67 ClassImp(AliITSsimulationSPD)
68 ////////////////////////////////////////////////////////////////////////
69 // Version: 0
70 // Written by Rocco Caliandro
71 // from a model developed with T. Virgili and R.A. Fini
72 // June 15 2000
73 //
74 // AliITSsimulationSPD is the simulation of SPDs
75 //
76 //______________________________________________________________________
77 AliITSsimulationSPD::AliITSsimulationSPD(){
78     // Default constructor
79
80     fResponse     = 0;
81     fSegmentation = 0;
82     fHis          = 0;
83     fMapA2        = 0;
84
85 /*
86     fThresh       = 0.;
87     fSigma        = 0.;
88     fCouplCol     = 0.;
89     fCouplRow     = 0.; */
90 }
91 //______________________________________________________________________
92 AliITSsimulationSPD::AliITSsimulationSPD(AliITSsegmentation *seg,
93                                          AliITSresponse *resp) {
94     // Standard constructor
95
96     fResponse     = 0;
97     fSegmentation = 0;
98     fHis          = 0;
99     fMapA2        = 0;
100
101 /*
102     fThresh       = 0.;
103     fSigma        = 0.;
104     fCouplCol     = 0.;
105     fCouplRow     = 0.*/
106     Init((AliITSsegmentationSPD*)seg,(AliITSresponseSPD*)resp);
107 }
108 //______________________________________________________________________
109 void AliITSsimulationSPD::Init(AliITSsegmentationSPD *seg,
110                                AliITSresponseSPD *resp) {
111     // Initilizes the variables of AliITSsimulation SPD.
112
113     fHis = 0;
114     fResponse     = resp;
115     fSegmentation = seg;
116     fMapA2  = new AliITSMapA2(fSegmentation);
117     fpList  = new AliITSpList(GetNPixelsZ()+1,GetNPixelsX()+1);
118 /*
119     fResponse->Thresholds(fThresh,fSigma);
120     fResponse->GetNoiseParam(fCouplCol,fCouplRow);
121     fNPixelsZ = fSegmentation->Npz();
122     fNPixelsX = fSegmentation->Npx();
123 */
124 }
125 //______________________________________________________________________
126 AliITSsimulationSPD::~AliITSsimulationSPD() { 
127     // destructor
128
129     delete fMapA2;
130 //    delete fpList;
131
132     if (fHis) {
133         fHis->Delete(); 
134         delete fHis;     
135     } // end if
136 }
137 //______________________________________________________________________
138 AliITSsimulationSPD::AliITSsimulationSPD(const AliITSsimulationSPD &source){
139     // Copy Constructor
140
141     if(&source == this) return;
142
143     this->fMapA2    = source.fMapA2;
144     this->fHis      = source.fHis;
145 /*
146     this->fThresh   = source.fThresh;
147     this->fSigma    = source.fSigma;
148     this->fCouplCol = source.fCouplCol;
149     this->fCouplRow = source.fCouplRow;
150     this->fNPixelsX = source.fNPixelsX;
151     this->fNPixelsZ = source.fNPixelsZ;
152 */
153     return;
154 }
155 //______________________________________________________________________
156 AliITSsimulationSPD& AliITSsimulationSPD::operator=(const AliITSsimulationSPD 
157                                                     &source) {
158     //    Assignment operator
159
160     if(&source == this) return *this;
161
162     this->fMapA2    = source.fMapA2;
163     this->fHis      = source.fHis;
164 /*
165     this->fThresh   = source.fThresh;
166     this->fSigma    = source.fSigma;
167     this->fCouplCol = source.fCouplCol;
168     this->fCouplRow = source.fCouplRow;
169     this->fNPixelsX = source.fNPixelsX;
170     this->fNPixelsZ = source.fNPixelsZ;
171 */
172     return *this;
173
174 //______________________________________________________________________
175 void AliITSsimulationSPD::InitSimulationModule(Int_t module,Int_t event){
176     // Creates maps to build the list of tracks for each sumable digit
177     // Inputs:
178     //   Int_t module    // Module number to be simulated
179     //   Int_t event     // Event number to be simulated
180     // Outputs:
181     //   none.
182     // Return
183     //    none.
184  
185     fModule = module;
186     fEvent  = event;
187     fMapA2->ClearMap();
188     fpList->ClearMap();
189 }
190 //______________________________________________________________________
191 void AliITSsimulationSPD::FinishSDigitiseModule(){
192     // Does the Sdigits to Digits work
193     // Inputs:
194     //   none.
195     // Outputs:
196     //   none.
197     // Return:
198     //   none.
199
200     SDigitsToDigits(fModule,fpList);
201 }
202 //______________________________________________________________________
203 void AliITSsimulationSPD::SDigitiseModule(AliITSmodule *mod, Int_t dummy0,
204                                              Int_t dummy1) {
205     // Sum digitize module
206     if (!(mod->GetNhits())) return; // if module has no hits then no Sdigits.
207     Int_t    number     = 10000;
208     Int_t    *frowpixel = new Int_t[number];
209     Int_t    *fcolpixel = new Int_t[number];
210     Double_t *fenepixel = new Double_t[number];
211
212     fModule = mod->GetIndex();
213
214     // Array of pointers to store the track index of the digits
215     // leave +1, otherwise pList crashes when col=256, row=192
216
217     HitsToAnalogDigits(mod,frowpixel,fcolpixel,fenepixel,fpList);
218
219     WriteSDigits(fpList);
220
221     // clean memory
222     delete[] frowpixel;
223     delete[] fcolpixel;
224     delete[] fenepixel;
225     fMapA2->ClearMap();
226     fpList->ClearMap();
227 }
228 //______________________________________________________________________
229 void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t dummy0,
230                                              Int_t dummy1) {
231     // digitize module. Also need to digitize modules with only noise.
232
233     Int_t    number     = 10000;
234     Int_t    *frowpixel = new Int_t[number];
235     Int_t    *fcolpixel = new Int_t[number];
236     Double_t *fenepixel = new Double_t[number];
237
238     // Array of pointers to store the track index of the digits
239     // leave +1, otherwise pList crashes when col=256, row=192
240     fModule = mod->GetIndex();
241     // noise setting
242     SetFluctuations(fpList,fModule);
243
244     HitsToAnalogDigits(mod,frowpixel,fcolpixel,fenepixel,fpList);
245
246     // apply mask to SPD module
247     SetMask();
248
249     CreateDigit(fModule,fpList);
250
251     // clean memory
252     delete[] frowpixel;
253     delete[] fcolpixel;
254     delete[] fenepixel;
255     fMapA2->ClearMap();
256     fpList->ClearMap();
257 }
258 //______________________________________________________________________
259 void AliITSsimulationSPD::SDigitsToDigits(Int_t module,AliITSpList *pList) {
260     // sum digits to Digits.
261
262 #ifdef DEBUG
263     cout << "Entering AliITSsimulatinSPD::SDigitsToDigits for module=";
264     cout << module << endl;
265 #endif
266     fModule = module;
267
268     // noise setting
269     SetFluctuations(pList,module);
270
271     fMapA2->ClearMap(); // since noise is in pList aready. Zero Map so that
272     // noise is not doubled when calling FillMapFrompList.
273
274     FillMapFrompList(pList);
275
276     // apply mask to SPD module
277     SetMask();
278
279     CreateDigit(module,pList);
280
281     fMapA2->ClearMap();
282     pList->ClearMap();
283 }
284 //______________________________________________________________________
285 void AliITSsimulationSPD::UpdateMapSignal(Int_t row,Int_t col,Int_t trk,
286                                           Int_t hit,Int_t mod,Double_t ene,
287                                           AliITSpList *pList) {
288     // updates the Map of signal, adding the energy  (ene) released by
289     // the current track
290
291     fMapA2->AddSignal(row,col,ene);
292     pList->AddSignal(row,col,trk,hit,mod,ene);
293 }
294 //______________________________________________________________________
295 void AliITSsimulationSPD::UpdateMapNoise(Int_t row,Int_t col,Int_t mod,
296                                          Double_t ene,AliITSpList *pList) {
297     // updates the Map of noise, adding the energy  (ene) give my noise
298
299     fMapA2->AddSignal(row,col,ene);
300     pList->AddNoise(row,col,mod,ene);
301 }
302 //______________________________________________________________________
303 void AliITSsimulationSPD::HitsToAnalogDigits(AliITSmodule *mod,
304                                              Int_t *frowpixel,Int_t *fcolpixel,
305                                              Double_t *fenepixel,
306                                              AliITSpList *pList) {
307     // Loops over all hits to produce Analog/floting point digits. This
308     // is also the first task in producing standard digits.
309     
310     // loop over hits in the module
311     Int_t hitpos,nhits = mod->GetNhits();
312     for (hitpos=0;hitpos<nhits;hitpos++) {
313         HitToDigit(mod,hitpos,frowpixel,fcolpixel,fenepixel,pList);
314     }// end loop over digits
315 }
316 //______________________________________________________________________
317 void AliITSsimulationSPD::HitToDigit(AliITSmodule *mod,Int_t hitpos,
318                                      Int_t *frowpixel,Int_t *fcolpixel,
319                                      Double_t *fenepixel,AliITSpList *pList) {
320     //  Steering function to determine the digits associated to a given
321     // hit (hitpos)
322     // The digits are created by charge sharing (ChargeSharing) and by
323     // capacitive coupling (SetCoupling). At all the created digits is
324     // associated the track number of the hit (ntrack)
325     Double_t x1l=0.0,y1l=0.0,z1l=0.0,x2l=0.0,y2l=0.0,z2l=0.0;
326     Int_t r1,r2,c1,c2,row,col,npixel = 0;
327     Int_t ntrack;
328     Double_t ene=0.0,etot=0.0;
329     const Float_t kconv = 10000.;     // cm -> microns
330     const Float_t kconv1= 0.277e9;    // GeV -> electrons equivalent
331
332     if(!(mod->LineSegmentL(hitpos,x1l,x2l,y1l,y2l,z1l,z2l,etot,ntrack)))return;
333
334     x2l += x1l; y2l += y1l; z2l += z1l; // Convert to ending coordinate.
335     // positions shifted and converted in microns
336     x1l   = x1l*kconv + fSegmentation->Dx()/2.;
337     z1l   = z1l*kconv + fSegmentation->Dz()/2.;
338     // positions  shifted and converted in microns
339     x2l   = x2l*kconv + fSegmentation->Dx()/2.;
340     z2l   = z2l*kconv + fSegmentation->Dz()/2.;
341     etot *= kconv1; // convert from GeV to electrons equivalent.
342     Int_t module = mod->GetIndex();
343
344     // to account for the effective sensitive area
345     // introduced in geometry 
346     if (z1l<0 || z1l>fSegmentation->Dz()) return;
347     if (z2l<0 || z2l>fSegmentation->Dz()) return;
348     if (x1l<0 || x1l>fSegmentation->Dx()) return;
349     if (x2l<0 || x2l>fSegmentation->Dx()) return;
350
351     //Get the col and row number starting from 1
352     // the x direction is not inverted for the second layer!!!
353     fSegmentation->GetPadIxz(x1l, z1l, c1, r1); 
354     fSegmentation->GetPadIxz(x2l, z2l, c2, r2);
355
356     // to account for unexpected equal entrance and 
357     // exit coordinates
358     if (x1l==x2l) x2l=x2l+x2l*0.1;
359     if (z1l==z2l) z2l=z2l+z2l*0.1;
360
361     if ((r1==r2) && (c1==c2)){
362         // no charge sharing
363         npixel = 1;              
364         frowpixel[npixel-1] = r1;
365         fcolpixel[npixel-1] = c1;
366         fenepixel[npixel-1] = etot;
367     } else {
368         // charge sharing
369         ChargeSharing(x1l,z1l,x2l,z2l,c1,r1,c2,r2,etot,
370                       npixel,frowpixel,fcolpixel,fenepixel);
371     } // end if r1==r2 && c1==c2.
372
373     for (Int_t npix=0;npix<npixel;npix++){
374         row = frowpixel[npix];
375         col = fcolpixel[npix];
376         ene = fenepixel[npix];
377         UpdateMapSignal(row,col,ntrack,hitpos,module,ene,pList); 
378         // Starting capacitive coupling effect
379         SetCoupling(row,col,ntrack,hitpos,module,pList); 
380     } // end for npix
381 }
382 //______________________________________________________________________
383 void AliITSsimulationSPD::ChargeSharing(Float_t x1l,Float_t z1l,Float_t x2l,
384                                         Float_t z2l,Int_t c1,Int_t r1,Int_t c2,
385                                         Int_t r2,Float_t etot,
386                                         Int_t &npixel,Int_t *frowpixel,
387                                         Int_t *fcolpixel,Double_t *fenepixel){
388     //  Take into account the geometrical charge sharing when the track
389     //  crosses more than one pixel.
390     //
391     //Begin_Html
392     /*
393       <img src="picts/ITS/barimodel_2.gif">
394       </pre>
395       <br clear=left>
396       <font size=+2 color=red>
397       <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
398       </font>
399       <pre>
400     */
401     //End_Html
402     //Float_t dm;
403     Float_t xa,za,xb,zb,dx,dz,dtot,refr,refm,refc;
404     Float_t refn=0.;
405     Float_t arefm, arefr, arefn, arefc, azb, az2l, axb, ax2l;
406     Int_t   dirx,dirz,rb,cb;
407     Int_t flag,flagrow,flagcol;
408     Double_t epar;
409
410     npixel = 0;
411     xa     = x1l;
412     za     = z1l;
413 //    dx     = x1l-x2l;
414 //    dz     = z1l-z2l;
415     dx     = x2l-x1l;
416     dz     = z2l-z1l;
417     dtot   = TMath::Sqrt((dx*dx)+(dz*dz));   
418     if (dtot==0.0) dtot = 0.01;
419     dirx   = (Int_t) TMath::Sign((Float_t)1,dx);
420     dirz   = (Int_t) TMath::Sign((Float_t)1,dz);
421
422     // calculate the x coordinate of  the pixel in the next column    
423     // and the z coordinate of  the pixel in the next row
424     Float_t xpos, zpos;
425
426     fSegmentation->GetPadCxz(c1, r1-1, xpos, zpos); 
427
428     Float_t xsize = fSegmentation->Dpx(0);
429     Float_t zsize = fSegmentation->Dpz(r1-1);
430     
431     if (dirx == 1) refr = xpos+xsize/2.;
432     else refr = xpos-xsize/2.;
433
434     if (dirz == 1) refn = zpos+zsize/2.;
435     else refn = zpos-zsize/2.;
436
437     flag = 0;
438     flagrow = 0;
439     flagcol = 0;
440     do{
441         // calculate the x coordinate of the intersection with the pixel
442         // in the next cell in row  direction
443       if(dz!=0)
444         refm = dx*((refn - z1l)/dz) + x1l;
445       else
446         refm = refr+dirx*xsize;
447    
448         // calculate the z coordinate of the intersection with the pixel
449         // in the next cell in column direction
450       if (dx!=0)
451         refc = dz*((refr - x1l)/dx) + z1l;
452       else
453         refc = refn+dirz*zsize;
454
455         arefm = refm * dirx;
456         arefr = refr * dirx;
457         arefn = refn * dirz;
458         arefc = refc * dirz;
459
460         if ((arefm < arefr) && (arefn < arefc)){
461             // the track goes in the pixel in the next cell in row direction
462             xb = refm;
463             zb = refn;
464             cb = c1;
465             rb = r1 + dirz;
466             azb = zb * dirz;
467             az2l = z2l * dirz;
468             if (rb == r2) flagrow=1;
469             if (azb > az2l) {
470                 zb = z2l;
471                 xb = x2l;
472             } // end if
473             // shift to the pixel in the next cell in row direction
474             Float_t zsizeNext = fSegmentation->Dpz(rb-1);
475             //to account for cell at the borders of the detector
476             if(zsizeNext==0) zsizeNext = zsize;
477             refn += zsizeNext*dirz;
478         }else {
479             // the track goes in the pixel in the next cell in column direction
480             xb = refr;
481             zb = refc;
482             cb = c1 + dirx;
483             rb = r1;
484             axb = xb * dirx;
485             ax2l = x2l * dirx;
486             if (cb == c2) flagcol=1;
487             if (axb > ax2l) {
488                 zb = z2l;
489                 xb = x2l;
490             } // end ifaxb > ax2l
491
492             // shift to the pixel in the next cell in column direction
493             Float_t xsizeNext = fSegmentation->Dpx(cb-1);
494             //to account for cell at the borders of the detector
495             if(xsizeNext==0) xsizeNext = xsize;
496             refr += xsizeNext*dirx;
497         } // end if (arefm < arefr) && (arefn < arefc)
498
499         //calculate the energy lost in the crossed pixel      
500         epar = TMath::Sqrt((xb-xa)*(xb-xa)+(zb-za)*(zb-za)); 
501         epar = etot*(epar/dtot);
502
503         //store row, column and energy lost in the crossed pixel
504         frowpixel[npixel] = r1;
505         fcolpixel[npixel] = c1;
506         fenepixel[npixel] = epar;
507         npixel++;
508  
509         // the exit point of the track is reached
510         if (epar == 0) flag = 1;
511         if ((r1 == r2) && (c1 == c2)) flag = 1;
512         if (flag!=1) {
513             r1 = rb;
514             c1 = cb;
515             xa = xb;
516             za = zb;
517         } // end if flag!=1
518     } while (flag==0);
519 }
520 //______________________________________________________________________
521 void AliITSsimulationSPD::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
522                                       Int_t idhit,Int_t module,
523                                       AliITSpList *pList) {
524     //  Take into account the coupling between adiacent pixels.
525     //  The parameters probcol and probrow are the fractions of the
526     //  signal in one pixel shared in the two adjacent pixels along
527     //  the column and row direction, respectively.
528     //
529     //Begin_Html
530     /*
531       <img src="picts/ITS/barimodel_3.gif">
532       </pre>
533       <br clear=left>
534       <font size=+2 color=red>
535       <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
536       </font>
537       <pre>
538     */
539     //End_Html
540     Int_t j1,j2,flag=0;
541     Double_t pulse1,pulse2;
542     Float_t couplR=0.0,couplC=0.0;
543
544     GetCouplings(couplR,couplC);
545     j1 = row;
546     j2 = col;
547     pulse1 = fMapA2->GetSignal(row,col);
548     pulse2 = pulse1;
549     for (Int_t isign=-1;isign<=1;isign+=2){// loop in row direction
550         do{
551             j1 += isign;
552             pulse1 *= couplR;
553             if ((j1<0) || (j1>GetNPixelsZ()-1) || (pulse1<GetThreshold())){
554                 pulse1 = fMapA2->GetSignal(row,col);
555                 j1 = row;
556                 flag = 1;
557             }else{
558                 UpdateMapSignal(j1,col,ntrack,idhit,module,pulse1,pList);
559                 flag = 0;
560             } // end if
561         } while(flag == 0);
562         // loop in column direction
563       do{
564           j2 += isign;
565           pulse2 *= couplC;
566           if ((j2<0) || (j2>(GetNPixelsX()-1)) || (pulse2<GetThreshold())){
567               pulse2 = fMapA2->GetSignal(row,col);
568               j2 = col;
569               flag = 1;
570           }else{
571               UpdateMapSignal(row,j2,ntrack,idhit,module,pulse2,pList);
572               flag = 0;
573           } // end if
574       } while(flag == 0);
575     } // for isign
576 }
577 //______________________________________________________________________
578 void AliITSsimulationSPD::CreateDigit(Int_t module,AliITSpList *pList) {
579     // The pixels are fired if the energy deposited inside them is above
580     // the threshold parameter ethr. Fired pixed are interpreted as digits
581     // and stored in the file digitfilename. One also needs to write out
582     // cases when there is only noise (nhits==0).
583
584     static AliITS *aliITS  = (AliITS*)gAlice->GetModule("ITS");
585
586     Int_t size = AliITSdigitSPD::GetNTracks();
587     Int_t digits[size];
588     Int_t tracks[size];
589     Int_t hits[size];
590     Float_t charges[size]; 
591     Int_t j1;
592
593     for (Int_t r=1;r<=GetNPixelsZ();r++) {
594         for (Int_t c=1;c<=GetNPixelsX();c++) {
595             // check if the deposited energy in a pixel is above the
596             // threshold 
597             Float_t signal = (Float_t) fMapA2->GetSignal(r,c);
598             if ( signal > GetThreshold()) {
599                 digits[0] = r-1;  // digits starts from 0
600                 digits[1] = c-1;  // digits starts from 0
601                 //digits[2] = 1;  
602                 digits[2] =  (Int_t) signal;  // the signal is stored in
603                                               //  electrons
604                 for(j1=0;j1<size;j1++){
605                     if(j1<pList->GetNEnteries()){
606                         tracks[j1] = pList->GetTrack(r,c,j1);
607                         hits[j1]   = pList->GetHit(r,c,j1);
608                     }else{
609                         tracks[j1] = -3;
610                         hits[j1]   = -1;
611                     } // end if
612                     charges[j1] = 0;
613                 } // end for j1
614                 Float_t phys = 0;
615                 aliITS->AddSimDigit(0,phys,digits,tracks,hits,charges);
616 #ifdef DEBUG
617                 cout << " CreateSPDDigit mod=" << fModule << " r,c=" << r;
618                 cout <<","<<c<< " sig=" << fpList->GetSignalOnly(r,c);
619                 cout << " noise=" << fpList->GetNoise(r,c);
620                 cout << " Msig="<< signal << " Thres=" << GetThreshold()<<endl;
621 #endif
622             } // end if of threshold condition
623         } // for c
624     }// end do on pixels
625 }
626 //______________________________________________________________________
627 void AliITSsimulationSPD::SetFluctuations(AliITSpList *pList,Int_t module) {
628     //  Set the electronic noise and threshold non-uniformities to all the
629     //  pixels in a detector.
630     //  The parameter fSigma is the squared sum of the sigma due to noise
631     //  and the sigma of the threshold distribution among pixels.
632     //
633     //Begin_Html
634     /*
635       <img src="picts/ITS/barimodel_1.gif">
636       </pre>
637       <br clear=left>
638       <font size=+2 color=red>
639       <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
640       </font>
641       <pre>
642     */
643     //End_Html
644     Float_t  thr=0.0,sigm=0.0;
645     Double_t signal,sigma;
646     Int_t iz,ix;
647
648     GetThresholds(thr,sigm);
649     sigma = (Double_t) sigm;
650     for(iz=1;iz<=GetNPixelsZ();iz++){
651         for(ix=1;ix<=GetNPixelsX();ix++){
652             signal = sigma*gRandom->Gaus(); 
653             fMapA2->SetHit(iz,ix,signal);
654             // insert in the label-signal-hit list the pixels fired
655             // only by noise
656             pList->AddNoise(iz,ix,module,signal);
657         } // end of loop on pixels
658     } // end of loop on pixels
659 }
660 //______________________________________________________________________
661 void AliITSsimulationSPD::SetMask() {
662     //  Apply a mask to the SPD module. 1% of the pixel channels are
663     //  masked. When the database will be ready, the masked pixels
664     //  should be read from it.
665     Double_t signal;
666     Int_t iz,ix,im;
667     Float_t totMask;
668     Float_t perc = ((AliITSresponseSPD*)fResponse)->GetFractionDead();
669     // in this way we get the same set of random numbers for all runs.
670     // This is a cluge for now.
671     static TRandom *rnd = new TRandom();
672
673     totMask= perc*GetNPixelsZ()*GetNPixelsX();
674     for(im=1;im<totMask;im++){
675         do{
676             ix=(Int_t)(rnd->Rndm()*(GetNPixelsX()-1.) + 1.);
677         } while(ix<=0 || ix>GetNPixelsX());
678         do{
679             iz=(Int_t)(rnd->Rndm()*(GetNPixelsZ()-1.) + 1.);
680         } while(iz<=0 || iz>GetNPixelsZ());
681         signal = -1.;
682         fMapA2->SetHit(iz,ix,signal);
683     } // end loop on masked pixels
684 }
685 //______________________________________________________________________
686 void AliITSsimulationSPD::CreateHistograms() {
687     // Create Histograms
688     Int_t i;
689
690     fHis=new TObjArray(GetNPixelsZ());
691     for(i=0;i<GetNPixelsZ();i++) {
692         TString spdname("spd_");
693         Char_t candnum[4];
694         sprintf(candnum,"%d",i+1);
695         spdname.Append(candnum);
696         (*fHis)[i] = new TH1F(spdname.Data(),"SPD maps",
697                               GetNPixelsX(),0.,(Float_t) GetNPixelsX());
698     } // end for i
699 }
700 //______________________________________________________________________
701 void AliITSsimulationSPD::ResetHistograms() {
702     // Reset histograms for this detector
703     Int_t i;
704
705     for(i=0;i<GetNPixelsZ();i++ ) {
706         if ((*fHis)[i])    ((TH1F*)(*fHis)[i])->Reset();
707     } // end for i
708 }
709 //______________________________________________________________________
710 void AliITSsimulationSPD::WriteSDigits(AliITSpList *pList){
711     // Fills the Summable digits Tree
712     Int_t i,ni,j,nj;
713     static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
714
715     pList->GetMaxMapIndex(ni,nj);
716     for(i=0;i<ni;i++)for(j=0;j<nj;j++){
717         if(pList->GetSignalOnly(i,j)>0.0){
718             aliITS->AddSumDigit(*(pList->GetpListItem(i,j)));
719 #ifdef DEBUG
720             cout << "pListSPD: " << *(pList->GetpListItem(i,j)) << endl;
721             cout << " CreateSPDSDigit mod=" << fModule << " r,c=";
722             cout << i  <<","<< j << " sig=" << fpList->GetSignalOnly(i,j);
723             cout << " noise=" << fpList->GetNoise(i,j) <<endl;
724 #endif
725         } // end if
726     } // end for i,j
727     return;
728 }
729 //______________________________________________________________________
730 void AliITSsimulationSPD::FillMapFrompList(AliITSpList *pList){
731     // Fills fMap2A from the pList of Summable digits
732     Int_t ix,iz;
733
734     for(iz=0;iz<GetNPixelsZ();iz++)for(ix=0;ix<GetNPixelsX();ix++) 
735         fMapA2->AddSignal(iz,ix,pList->GetSignal(iz,ix));
736     return;
737 }