]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSsimulationSSD.cxx
4c01c9bdc717a1d37a2e7b3ec9e5557d0b80be3e
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSSD.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 /* $Id$ */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <Riostream.h>
21 #include <TObjArray.h>
22 #include <TRandom.h>
23
24 #include "AliITSmodule.h"
25 #include "AliITSMapA2.h"
26 #include "AliITSpList.h"
27 #include "AliITSCalibrationSSD.h"
28 #include "AliITSsegmentationSSD.h"
29 //#include "AliITSdcsSSD.h"
30 #include "AliITS.h"
31 #include "AliITShit.h"
32 #include "AliITSdigitSSD.h"
33 #include "AliRun.h"
34 #include "AliITSgeom.h"
35 #include "AliITSsimulationSSD.h"
36 #include "AliITSTableSSD.h"
37 //#include "AliITSresponseSSD.h"
38
39 ClassImp(AliITSsimulationSSD)
40 ////////////////////////////////////////////////////////////////////////
41 //                                                                    //
42 // Author: Enrico Fragiacomo                                          //
43 //         enrico.fragiacomo@ts.infn.it                               //
44 // Last revised: june 2008                                            // 
45 //                                                                    //
46 // AliITSsimulationSSD is the simulation of SSD.                     //
47 ////////////////////////////////////////////////////////////////////////
48
49 //----------------------------------------------------------------------
50 AliITSsimulationSSD::AliITSsimulationSSD():AliITSsimulation(),
51                                            //fDCS(0),
52 fMapA2(0),
53 fIonE(0.0),
54 fDifConst(),
55 fDriftVel(){
56     //default Constructor
57     //Inputs:
58     // none.
59     // Outputs:
60     // none.
61     // Return:
62     //  A default construction AliITSsimulationSSD class
63 }
64 //----------------------------------------------------------------------
65 AliITSsimulationSSD::AliITSsimulationSSD(AliITSDetTypeSim* dettyp):
66 AliITSsimulation(dettyp),
67 //fDCS(0),
68 fMapA2(0),
69 fIonE(0.0),
70 fDifConst(),
71 fDriftVel(){
72     // Constructor 
73     // Input:
74     //   AliITSDetTypeSim    Pointer to the SSD dettype to be used
75     // Outputs:
76     //   none.
77     // Return
78     //   A standard constructed AliITSsimulationSSD class
79
80     Init();
81 }
82 //----------------------------------------------------------------------
83 void AliITSsimulationSSD::Init(){
84   // Inilizer, Inilizes all of the variable as needed in a standard place.
85   // Input:
86   //   AliITSsegmentationSSD *seg  Pointer to the SSD segmentation to be used
87   //   AliITSCalibrationSSD   *resp Pointer to the SSD responce class to be used
88   // Outputs:
89   //   none.
90   // Return
91   //   none.
92   AliITSsegmentationSSD* seg = (AliITSsegmentationSSD*)GetSegmentationModel(2);
93   
94   SetDriftVelocity(); // use default values in .h file
95   SetIonizeE();       // use default values in .h file
96   SetDiffConst();     // use default values in .h file
97   fpList           = new AliITSpList(2,GetNStrips());
98   fMapA2           = new AliITSMapA2(seg);
99 }
100 //______________________________________________________________________
101 AliITSsimulationSSD& AliITSsimulationSSD::operator=(
102                                          const AliITSsimulationSSD &s){
103   // Operator =
104
105   if(this==&s) return *this;
106
107   //  this->fDCS         = new AliITSdcsSSD(*(s.fDCS));
108   this->fMapA2       = s.fMapA2;
109   this->fIonE        = s.fIonE;
110   this->fDifConst[0] = s.fDifConst[0];
111   this->fDifConst[1] = s.fDifConst[1];
112   this->fDriftVel[0] = s.fDriftVel[0];
113   this->fDriftVel[1] = s.fDriftVel[1];
114   return *this;
115 }
116 /*
117 //______________________________________________________________________
118 AliITSsimulation& AliITSsimulationSSD::operator=(
119                                          const AliITSsimulation &s){
120   // Operator =
121
122   if(this==&s) return *this;
123   Error("AliITSsimulationSSD","Not allowed to make a = with "
124         "AliITSsimulationSSD Using default creater instead");
125   
126   return *this;
127 }
128 */
129 //______________________________________________________________________
130 AliITSsimulationSSD::AliITSsimulationSSD(const AliITSsimulationSSD &source):
131     AliITSsimulation(source),
132 fMapA2(source.fMapA2),
133 fIonE(source.fIonE),
134 fDifConst(),
135 fDriftVel(){
136   // copy constructor
137   fDifConst[0] = source.fDifConst[0];
138   fDifConst[1] = source.fDifConst[1];
139   fDriftVel[0] = source.fDriftVel[0];
140   fDriftVel[1] = source.fDriftVel[1];
141 }
142 //______________________________________________________________________
143 AliITSsimulationSSD::~AliITSsimulationSSD() {
144   // destructor
145   delete fMapA2;
146   //delete fDCS;
147 }
148 //______________________________________________________________________
149 void AliITSsimulationSSD::InitSimulationModule(Int_t module,Int_t event){
150     // Creates maps to build the list of tracks for each sumable digit
151     // Inputs:
152     //   Int_t module    // Module number to be simulated
153     //   Int_t event     // Event number to be simulated
154     // Outputs:
155     //   none.
156     // Return
157     //    none.
158
159     SetModuleNumber(module);
160     SetEventNumber(event);
161     fMapA2->ClearMap();
162     fpList->ClearMap();
163 }
164 //______________________________________________________________________
165 void AliITSsimulationSSD::FinishSDigitiseModule(){
166     // Does the Sdigits to Digits work
167     // Inputs:
168     //   none.
169     // Outputs:
170     //   none.
171     // Return:
172     //   none.
173
174   FillMapFrompList(fpList);  // need to check if needed here or not????
175   SDigitToDigit(fModule,fpList);
176   fpList->ClearMap();
177   fMapA2->ClearMap();
178 }
179 //______________________________________________________________________
180 void AliITSsimulationSSD::DigitiseModule(AliITSmodule *mod,Int_t,Int_t) {
181   // Digitizes hits for one SSD module
182   SetModuleNumber(mod->GetIndex());
183   
184   HitsToAnalogDigits(mod,fpList);
185   SDigitToDigit(GetModuleNumber(),fpList);
186   
187   fpList->ClearMap();
188   fMapA2->ClearMap();
189 }
190 //______________________________________________________________________
191 void AliITSsimulationSSD::SDigitiseModule(AliITSmodule *mod,Int_t,Int_t) {
192   // Produces Summable/Analog digits and writes them to the SDigit tree. 
193
194     HitsToAnalogDigits(mod,fpList);
195
196     WriteSDigits(fpList);
197     
198     fpList->ClearMap();
199     fMapA2->ClearMap();
200 }
201 //______________________________________________________________________
202 void AliITSsimulationSSD::SDigitToDigit(Int_t module,AliITSpList *pList){
203   // Takes the pList and finishes the digitization.
204   
205   ApplyNoise(pList,module);
206   ApplyCoupling(pList,module);
207   ApplyDeadChannels(module);
208   
209   ChargeToSignal(module,pList);
210 }
211 //______________________________________________________________________
212 void AliITSsimulationSSD::HitsToAnalogDigits(AliITSmodule *mod,
213                                              AliITSpList *pList){
214     // Loops over all hits to produce Analog/floating point digits. This
215     // is also the first task in producing standard digits.
216   Int_t lasttrack     = -2;
217   Int_t idtrack       = -2;
218   Double_t x0=0.0, y0=0.0, z0=0.0;
219   Double_t x1=0.0, y1=0.0, z1=0.0;
220   Double_t de=0.0;
221   Int_t module = mod->GetIndex();
222   
223   AliITSsegmentationSSD* seg = (AliITSsegmentationSSD*)GetSegmentationModel(2);
224   
225   TObjArray *hits = mod->GetHits();
226   Int_t nhits     = hits->GetEntriesFast();
227   if (nhits<=0) return;
228   AliITSTableSSD * tav = new AliITSTableSSD(GetNStrips());
229   module = mod->GetIndex();
230   if ( mod->GetLayer() == 6 ) seg->SetLayer(6);
231   if ( mod->GetLayer() == 5 ) seg->SetLayer(5);
232   for(Int_t i=0; i<nhits; i++) {    
233     // LineSegmentL returns 0 if the hit is entering
234     // If hits is exiting returns positions of entering and exiting hits
235     // Returns also energy loss
236     if(GetDebug(4)){
237       cout << i << " ";
238       cout << mod->GetHit(i)->GetXL() << " "<<mod->GetHit(i)->GetYL();
239       cout << " " << mod->GetHit(i)->GetZL();
240       cout << endl;
241     } // end if
242     if (mod->LineSegmentL(i, x0, x1, y0, y1, z0, z1, de, idtrack)) {
243       HitToDigit(module, x0, y0, z0, x1, y1, z1, de,tav);
244       if (lasttrack != idtrack || i==(nhits-1)) {
245         GetList(idtrack,i,module,pList,tav);
246       } // end if
247       lasttrack=idtrack;
248     } // end if
249   }  // end loop over hits
250   delete tav; tav=0;
251   return;
252 }
253 //----------------------------------------------------------------------
254 void AliITSsimulationSSD::HitToDigit(Int_t module, Double_t x0, Double_t y0, 
255                                      Double_t z0, Double_t x1, Double_t y1, 
256                                      Double_t z1, Double_t de,
257                                      AliITSTableSSD *tav) {
258   
259   // hit to digit conversion
260   
261   AliITSsegmentationSSD* seg = (AliITSsegmentationSSD*)GetSegmentationModel(2);
262   // Turns hits in SSD module into one or more digits.
263   //Float_t tang[2] = {0.0,0.0};
264   //seg->Angles(tang[0], tang[1]);//stereo<<->tan(stereo)~=stereo
265   Double_t x, y, z;
266   Double_t dex=0.0, dey=0.0, dez=0.0; 
267   Double_t pairs; // pair generation energy per step.
268   Double_t sigma[2] = {0.,0.};// standard deviation of the diffusion gaussian
269   Double_t tdrift[2] = {0.,0.}; // time of drift
270   Double_t w;
271   Double_t inf[2], sup[2], par0[2];                 
272   
273   // Steps in the module are determined "manually" (i.e. No Geant)
274   // NumOfSteps divide path between entering and exiting hits in steps 
275   Int_t numOfSteps = NumOfSteps(x1, y1, z1, dex, dey, dez);
276   // Enery loss is equally distributed among steps
277   de    = de/numOfSteps;
278   pairs = de/GetIonizeE(); // e-h pairs generated
279
280   //-----------------------------------------------------
281   // stepping
282   //-----------------------------------------------------
283   for(Int_t j=0; j<numOfSteps; j++) {     // stepping
284
285     x = x0 + (j+0.5)*dex;
286     y = y0 + (j+0.5)*dey;
287     if ( y > (seg->Dy()/2+10)*1.0E-4 ) {
288       // check if particle is within the detector
289       Warning("HitToDigit",
290               "hit out of detector y0=%e,y=%e,dey=%e,j =%d module=%d,  exceed=%e",
291               y0,y,dey,j,module, y-(seg->Dy()/2+10)*1.0E-4);
292       return;
293     } // end if
294     z = z0 + (j+0.5)*dez;
295
296     if(GetDebug(4)) cout <<"HitToDigit "<<x<<" "<<y<<" "<<z<< " "
297                          <<dex<<" "<<dey<<" "<<dez<<endl;
298
299     if(seg->GetLayer()==6) {
300       y=-y; // Lay6 module has sensor up-side-down!!!
301     }
302     
303     // w is the coord. perpendicular to the strips
304     //    Float_t xp=x*1.e+4,zp=z*1.e+4; // microns    
305     Float_t xp=x,zp=z; 
306     seg->GetPadTxz(xp,zp);
307
308     Int_t k;
309     //---------------------------------------------------------
310     // Pside
311     //------------------------------------------------------------
312     k=0;
313     
314     // calculate drift time
315     // y is the minimum path
316     tdrift[0] = (y+(seg->Dy()*1.0E-4)/2)/GetDriftVelocity(0);
317     
318     w = xp; // P side strip number
319     
320     if((w<(-0.5)) || (w>(GetNStrips()-0.5))) {
321       // this check rejects hits in regions not covered by strips
322       // 0.5 takes into account boundaries 
323       if(GetDebug(4)) cout << "Dead SSD region, x,z="<<x<<","<<z<<endl;
324       return; // There are dead region on the SSD sensitive volume!!!
325     } // end if
326     
327       // sigma is the standard deviation of the diffusion gaussian
328     if(tdrift[k]<0) return;
329     
330     sigma[k] = TMath::Sqrt(2*GetDiffConst(k)*tdrift[k]);
331     sigma[k] /= (GetStripPitch()*1.0E-4);  //units of Pitch
332     
333     if(sigma[k]==0.0) {         
334       Error("HitToDigit"," sigma[%d]=0",k);
335       exit(0);
336     } // end if
337     
338     par0[k] = pairs;
339     // we integrate the diffusion gaussian from -3sigma to 3sigma 
340     inf[k] = w - 3*sigma[k]; // 3 sigma from the gaussian average  
341     sup[k] = w + 3*sigma[k]; // 3 sigma from the gaussian average
342     // IntegrateGaussian does the actual
343     // integration of diffusion gaussian
344     IntegrateGaussian(k, par0[k], w, sigma[k], inf[k], sup[k],tav);
345     
346     //------------------------------------------------------
347     // end Pside
348     //-------------------------------------------------------
349     
350     //------------------------------------------------------
351     // Nside
352     //-------------------------------------------------------
353     k=1;
354     tdrift[1] = ((seg->Dy()*1.0E-4)/2-y)/GetDriftVelocity(1);
355     
356     //tang[k]=TMath::Tan(tang[k]);
357     
358     w = zp; // N side strip number
359     
360     if((w<(-0.5)) || (w>(GetNStrips()-0.5))) {
361       // this check rejects hits in regions not covered by strips
362       // 0.5 takes into account boundaries 
363       if(GetDebug(4)) cout << "Dead SSD region, x,z="<<x<<","<<z<<endl;
364       return; // There are dead region on the SSD sensitive volume.
365     } // end if
366     
367       // sigma is the standard deviation of the diffusion gaussian
368     if(tdrift[k]<0) return;
369     
370     sigma[k] = TMath::Sqrt(2*GetDiffConst(k)*tdrift[k]);
371     sigma[k] /= (GetStripPitch()*1.0E-4);  //units of Pitch
372     
373     if(sigma[k]==0.0) {         
374       Error("HitToDigit"," sigma[%d]=0",k);
375       exit(0);
376     } // end if
377     
378     par0[k] = pairs;
379     // we integrate the diffusion gaussian from -3sigma to 3sigma 
380     inf[k] = w - 3*sigma[k]; // 3 sigma from the gaussian average  
381     sup[k] = w + 3*sigma[k]; // 3 sigma from the gaussian average
382     // IntegrateGaussian does the actual
383     // integration of diffusion gaussian
384     IntegrateGaussian(k, par0[k], w, sigma[k], inf[k], sup[k],tav);
385     
386     //-------------------------------------------------
387     // end Nside
388     //-------------------------------------------------
389     
390     
391   } // end stepping
392 }
393
394 //______________________________________________________________________
395 void AliITSsimulationSSD::ApplyNoise(AliITSpList *pList,Int_t module){
396   // Apply Noise.
397   Int_t ix;
398   Double_t signal,noise;
399   AliITSCalibrationSSD* res =(AliITSCalibrationSSD*)GetCalibrationModel(module);
400   
401   // Pside
402   for(ix=0;ix<GetNStrips();ix++){      // loop over strips
403     
404     // noise is gaussian
405     noise  = (Double_t) gRandom->Gaus(0,res->GetNoiseP().At(ix));
406     
407     // need to calibrate noise 
408     // NOTE. noise from the calibration database comes uncalibrated, 
409     // it needs to be calibrated in order to be added
410     // to the signal. It will be decalibrated later on together with the noise    
411     noise *= (Double_t) res->GetGainP(ix); 
412     
413     // noise comes in ADC channels from the calibration database
414     // It needs to be converted back to electronVolts
415     noise /= res->GetDEvToADC(1.);
416     
417     // Finally, noise is added to the signal
418     signal = noise + fMapA2->GetSignal(0,ix);//get signal from map
419     fMapA2->SetHit(0,ix,signal); // give back signal to map
420     if(signal>0.0) pList->AddNoise(0,ix,module,noise);
421   } // loop over strip 
422   
423     // Nside
424   for(ix=0;ix<GetNStrips();ix++){      // loop over strips
425     noise  = (Double_t) gRandom->Gaus(0,res->GetNoiseN().At(ix));// give noise to signal
426     noise *= (Double_t) res->GetGainN(ix); 
427     noise /= res->GetDEvToADC(1.);
428     signal = noise + fMapA2->GetSignal(1,ix);//get signal from map
429     fMapA2->SetHit(1,ix,signal); // give back signal to map
430     if(signal>0.0) pList->AddNoise(1,ix,module,noise);
431   } // loop over strip 
432   
433 }
434 //______________________________________________________________________
435 void AliITSsimulationSSD::ApplyCoupling(AliITSpList *pList,Int_t module) {
436   // Apply the effect of electronic coupling between channels
437   Int_t ix;
438   Double_t signal=0;
439   AliITSCalibrationSSD* res =(AliITSCalibrationSSD*)GetCalibrationModel(module);
440   
441   Double_t *contrLeft  = new Double_t[GetNStrips()];
442   Double_t *contrRight = new Double_t[GetNStrips()];
443   
444   // P side coupling
445   for(ix=0;ix<GetNStrips();ix++){
446     if(ix>0) contrLeft[ix] = fMapA2->GetSignal(0,ix-1)*res->GetCouplingPL();
447     else contrLeft[ix] = 0.0;
448     if(ix<(GetNStrips()-1)) contrRight[ix] = fMapA2->GetSignal(0,ix+1)*res->GetCouplingPR();
449     else contrRight[ix] = 0.0;
450   } // loop over strips 
451   
452   for(ix=0;ix<GetNStrips();ix++){
453     signal = contrLeft[ix] + contrRight[ix] - res->GetCouplingPL() * fMapA2->GetSignal(0,ix)
454       - res->GetCouplingPR() * fMapA2->GetSignal(0,ix);
455     fMapA2->AddSignal(0,ix,signal);
456     if(signal>0.0) pList->AddNoise(0,ix,module,signal);
457   } // loop over strips 
458   
459   // N side coupling
460   for(ix=0;ix<GetNStrips();ix++){
461     if(ix>0) contrLeft[ix] = fMapA2->GetSignal(1,ix-1)*res->GetCouplingNL();
462     else contrLeft[ix] = 0.0;
463     if(ix<(GetNStrips()-1)) contrRight[ix] = fMapA2->GetSignal(1,ix+1)*res->GetCouplingNR();
464     else contrRight[ix] = 0.0;
465   } // loop over strips 
466   
467   for(ix=0;ix<GetNStrips();ix++){
468     signal = contrLeft[ix] + contrRight[ix] - res->GetCouplingNL() * fMapA2->GetSignal(0,ix)
469       - res->GetCouplingNR() * fMapA2->GetSignal(0,ix);
470     fMapA2->AddSignal(1,ix,signal);
471     if(signal>0.0) pList->AddNoise(1,ix,module,signal);
472   } // loop over strips 
473   
474
475   delete [] contrLeft;
476   delete [] contrRight; 
477 }
478
479 //______________________________________________________________________
480 void AliITSsimulationSSD::ApplyDeadChannels(Int_t module) {
481   // Kill dead channels setting gain to zero
482
483   AliITSCalibrationSSD* res = (AliITSCalibrationSSD*)GetCalibrationModel(module);
484
485   for(Int_t i=0;i<GetNStrips();i++){
486
487     if(res->IsPChannelBad(i)) res->AddGainP(i,0.0);
488     if(res->IsNChannelBad(i)) res->AddGainN(i,0.0);
489
490   } // loop over strips 
491
492 }
493
494 //______________________________________________________________________
495 Float_t AliITSsimulationSSD::F(Float_t av, Float_t x, Float_t s) {
496     // Computes the integral of a gaussian using Error Function
497     Float_t sqrt2 = TMath::Sqrt(2.0);
498     Float_t sigm2 = sqrt2*s;
499     Float_t integral;
500
501     integral = 0.5 * TMath::Erf( (x - av) / sigm2);
502     return integral;
503 }
504 //______________________________________________________________________
505 void AliITSsimulationSSD::IntegrateGaussian(Int_t k,Double_t par, Double_t w,
506                                             Double_t sigma, 
507                                             Double_t inf, Double_t sup,
508                                             AliITSTableSSD *tav) {
509     // integrate the diffusion gaussian
510     // remind: inf and sup are w-3sigma and w+3sigma
511     //         we could define them here instead of passing them
512     //         this way we are free to introduce asimmetry
513
514     Double_t a=0.0, b=0.0;
515     Double_t dXCharge1 = 0.0, dXCharge2 = 0.0;
516     // dXCharge1 and 2 are the charge to two neighbouring strips
517     // Watch that we only involve at least two strips
518     // Numbers greater than 2 of strips in a cluster depend on
519     //  geometry of the track and delta rays, not charge diffusion!   
520
521     Double_t strip = TMath::Floor(w);         // closest strip on the left
522
523     if ( TMath::Abs((strip - w)) < 0.5) { 
524         // gaussian mean is closer to strip on the left
525         a = inf;                         // integration starting point
526         if((strip+0.5)<=sup) {
527             // this means that the tail of the gaussian goes beyond
528             // the middle point between strips ---> part of the signal
529             // is given to the strip on the right
530             b = strip + 0.5;               // integration stopping point
531             dXCharge1 = F( w, b, sigma) - F(w, a, sigma);
532             dXCharge2 = F( w, sup, sigma) - F(w ,b, sigma); 
533         }else { 
534             // this means that all the charge is given to the strip on the left
535             b = sup;
536             dXCharge1 = 0.9973;   // gaussian integral at 3 sigmas
537             dXCharge2 = 0.0;
538         } // end if
539         dXCharge1 = par * dXCharge1;// normalize by mean of number of carriers
540         dXCharge2 = par * dXCharge2;
541
542         // for the time being, signal is the charge
543         // in ChargeToSignal signal is converted in ADC channel
544         fMapA2->AddSignal(k,(Int_t)strip,dXCharge1);
545         tav->Add(k,(Int_t)strip);
546         if(((Int_t) strip) < (GetNStrips()-1)) {
547             // strip doesn't have to be the last (remind: last=GetNStrips()-1)
548             // otherwise part of the charge is lost
549             fMapA2->AddSignal(k,((Int_t)strip+1),dXCharge2);
550             tav->Add(k,((Int_t)(strip+1)));
551         } // end if
552     }else{
553         // gaussian mean is closer to strip on the right
554         strip++;     // move to strip on the rigth
555         b = sup;     // now you know where to stop integrating
556         if((strip-0.5)>=inf) { 
557             // tail of diffusion gaussian on the left goes left of
558             // middle point between strips
559             a = strip - 0.5;        // integration starting point
560             dXCharge1 = F(w, b, sigma) - F(w, a, sigma);
561             dXCharge2 = F(w, a, sigma) - F(w, inf, sigma);
562         }else {
563             a = inf;
564             dXCharge1 = 0.9973;   // gaussian integral at 3 sigmas
565             dXCharge2 = 0.0;
566         } // end if
567         dXCharge1 = par * dXCharge1;    // normalize by means of carriers
568         dXCharge2 = par * dXCharge2;
569         // for the time being, signal is the charge
570         // in ChargeToSignal signal is converted in ADC channel
571         fMapA2->AddSignal(k,(Int_t)strip,dXCharge1);
572         tav->Add(k,(Int_t)strip);
573         if(((Int_t) strip) > 0) {
574             // strip doesn't have to be the first
575             // otherwise part of the charge is lost
576             fMapA2->AddSignal(k,((Int_t)strip-1),dXCharge2);
577             tav->Add(k,((Int_t)(strip-1)));
578         } // end if
579     } // end if
580 }
581 //______________________________________________________________________
582 Int_t AliITSsimulationSSD::NumOfSteps(Double_t x, Double_t y, Double_t z,
583                                       Double_t &dex,Double_t &dey,
584                                       Double_t &dez){
585     // number of steps
586     // it also returns steps for each coord
587     //AliITSsegmentationSSD *seg = new AliITSsegmentationSSD();
588
589     Double_t step = 25E-4;
590     //step = (Double_t) seg->GetStepSize();  // step size (cm)
591     Int_t numOfSteps = (Int_t) (TMath::Sqrt(x*x+y*y+z*z)/step); 
592
593     if (numOfSteps < 1) numOfSteps = 1;       // one step, at least
594     //numOfSteps=1;
595
596     // we could condition the stepping depending on the incident angle
597     // of the track
598     dex = x/numOfSteps;
599     dey = y/numOfSteps;
600     dez = z/numOfSteps;
601     
602     return numOfSteps;
603 }
604 //----------------------------------------------------------------------
605 void AliITSsimulationSSD::GetList(Int_t label,Int_t hit,Int_t mod,
606                                   AliITSpList *pList,AliITSTableSSD *tav) {
607     // loop over nonzero digits
608     Int_t ix,i;
609     Double_t signal=0.;
610
611     for(Int_t k=0; k<2; k++) {
612         ix=tav->Use(k);
613         while(ix>-1){
614             signal = fMapA2->GetSignal(k,ix);
615             if(signal==0.0) {
616                 ix=tav->Use(k);
617                 continue;
618             } // end if signal==0.0
619             // check the signal magnitude
620             for(i=0;i<pList->GetNSignals(k,ix);i++){
621                 signal -= pList->GetTSignal(k,ix,i);
622             } // end for i
623             //  compare the new signal with already existing list
624             if(signal>0)pList->AddSignal(k,ix,label,hit,mod,signal);
625             ix=tav->Use(k);
626         } // end of loop on strips
627     } // end of loop on P/N side
628     tav->Clear();
629 }
630 //----------------------------------------------------------------------
631 void AliITSsimulationSSD::ChargeToSignal(Int_t module,AliITSpList *pList) {
632     // charge to signal
633     static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
634     Float_t threshold = 0.;
635     Int_t size = AliITSdigitSSD::GetNTracks();
636     Int_t * digits = new Int_t[size];
637     Int_t * tracks = new Int_t[size];
638     Int_t * hits = new Int_t[size];
639     Int_t j1;
640     Float_t charges[3] = {0.0,0.0,0.0};
641     Float_t signal;
642     AliITSCalibrationSSD* res =(AliITSCalibrationSSD*)GetCalibrationModel(module);
643
644     for(Int_t k=0;k<2;k++){         // both sides (0=Pside, 1=Nside)
645       for(Int_t ix=0;ix<GetNStrips();ix++){     // loop over strips
646
647         // if strip is dead -> gain=0
648         if( ((k==0)&&(res->GetGainP(ix)==0)) || ((k==1)&&(res->GetGainN(ix)==0))) continue;
649         
650         signal = fMapA2->GetSignal(k,ix);
651         // signal has to be uncalibrated
652         // In real life, gains are supposed to be calculated from calibration runs,
653         // stored in the calibration DB and used in the reconstruction
654         // (see AliITSClusterFinderSSD.cxx)
655         if(k==0) signal /= res->GetGainP(ix);
656         else signal /= res->GetGainN(ix);
657
658         // signal is converted in unit of ADC
659         signal = res->GetDEvToADC(signal);
660         if(signal>4096.) signal = 4096.;//if exceeding, accumulate last one
661
662         // threshold for zero suppression is set on the basis of the noise
663         // A good value is 3*sigma_noise
664         if(k==0) threshold = res->GetNoiseP().At(ix);
665         else threshold = res->GetNoiseN().At(ix);
666         threshold *= res->GetZSThreshold(); // threshold at 3 sigma noise
667         if(signal < threshold) continue;
668
669         digits[0] = k;
670         digits[1] = ix;
671         digits[2] = TMath::Nint(signal);
672         for(j1=0;j1<size;j1++)if(j1<pList->GetNEntries()){
673           // only three in digit.
674           tracks[j1]  = pList->GetTrack(k,ix,j1);
675           hits[j1]    = pList->GetHit(k,ix,j1);
676         }else{
677           tracks[j1]  = -3;
678           hits[j1]    = -1;
679         } // end for j1
680         // finally add digit
681         aliITS->AddSimDigit(2,0,digits,tracks,hits,charges);
682       } // end for ix
683     } // end for k
684     delete [] digits;
685     delete [] tracks;
686     delete [] hits;
687 }
688 //______________________________________________________________________
689 void AliITSsimulationSSD::WriteSDigits(AliITSpList *pList){
690     // Fills the Summable digits Tree
691     Int_t i,ni,j,nj;
692     static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
693
694     pList->GetMaxMapIndex(ni,nj);
695     for(i=0;i<ni;i++)for(j=0;j<nj;j++){
696         if(pList->GetSignalOnly(i,j)>0.0){
697             aliITS->AddSumDigit(*(pList->GetpListItem(i,j)));
698             if(GetDebug(4)) cout << "pListSSD: "<<*(pList->GetpListItem(i,j))
699                                 << endl;
700         } // end if
701     } // end for i,j
702   return;
703 }
704 //______________________________________________________________________
705 void AliITSsimulationSSD::FillMapFrompList(AliITSpList *pList){
706     // Fills fMap2A from the pList of Summable digits
707     Int_t k,ix;
708
709     for(k=0;k<2;k++)for(ix=0;ix<GetNStrips();ix++) 
710         fMapA2->AddSignal(k,ix,pList->GetSignal(k,ix));
711     return;
712 }
713 //______________________________________________________________________
714 void AliITSsimulationSSD::Print(ostream *os){
715     //Standard output format for this class
716
717     //AliITSsimulation::Print(os);
718     *os << fIonE <<",";
719     *os << fDifConst[0] <<","<< fDifConst[1] <<",";
720     *os << fDriftVel[0] <<","<< fDriftVel[1];
721     //*os <<","; fDCS->Print(os);
722     //*os <<","; fMapA2->Print(os);
723 }
724 //______________________________________________________________________
725 void AliITSsimulationSSD::Read(istream *is){
726     // Standard output streaming function.
727
728     //AliITSsimulation::Read(is);
729     *is >> fIonE;
730     *is >> fDifConst[0] >> fDifConst[1];
731     *is >> fDriftVel[0] >> fDriftVel[1];
732     //fDCS->Read(is);
733     //fMapA2->Read(is);
734 }
735 //______________________________________________________________________
736 ostream &operator<<(ostream &os,AliITSsimulationSSD &source){
737     // Standard output streaming function.
738
739     source.Print(&os);
740     return os;
741 }
742 //______________________________________________________________________
743 istream &operator>>(istream &os,AliITSsimulationSSD &source){
744     // Standard output streaming function.
745
746     source.Read(&os);
747     return os;
748 }
749 //______________________________________________________________________
750
751
752
753