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