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