1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
21 #include <TObjArray.h>
25 #include "AliITSmodule.h"
26 #include "AliITSMapA2.h"
27 #include "AliITSsegmentationSSD.h"
28 #include "AliITSresponseSSD.h"
29 #include "AliITSdcsSSD.h"
32 #include "AliITSgeom.h"
33 #include "AliITSsimulationSSD.h"
35 ClassImp(AliITSsimulationSSD);
36 ////////////////////////////////////////////////////////////////////////
38 // Written by Enrico Fragiacomo
41 // AliITSsimulationSSD is the simulation of SSDs.
43 //----------------------------------------------------------------------
44 AliITSsimulationSSD::AliITSsimulationSSD(){
48 fNstrips = GetSegmentation()->Npx();
49 fPitch = GetSegmentation()->Dpx(0);
50 fDifConst[0] = fDifConst[1] = 0.0;
51 fDriftVel[0] = fDriftVel[1] = 0.0;
54 //----------------------------------------------------------------------
55 AliITSsimulationSSD::AliITSsimulationSSD(AliITSsegmentation *seg,
56 AliITSresponse *resp){
61 Float_t noise[2] = {0.,0.};
62 fResponse->GetNoiseParam(noise[0],noise[1]); // retrieves noise parameters
63 fDCS = new AliITSdcsSSD(seg,resp);
65 fNstrips = GetSegmentation()->Npx();
66 fPitch = GetSegmentation()->Dpx(0);
67 SetDriftVelocity(); // use default values in .h file
68 SetIonizeE(); // use default values in .h file
69 SetDiffConst(); // use default values in .h file
70 fMapA2 = new AliITSMapA2(fSegmentation);
72 //______________________________________________________________________
73 AliITSsimulationSSD& AliITSsimulationSSD::operator=(
74 const AliITSsimulationSSD &s){
77 if(this==&s) return *this;
79 this->fDCS = new AliITSdcsSSD(*(s.fDCS));
80 this->fMapA2 = s.fMapA2;
81 this->fNstrips = s.fNstrips;
82 this->fPitch = s.fPitch;
83 this->fIonE = s.fIonE;
84 this->fDifConst[0] = s.fDifConst[0];
85 this->fDifConst[1] = s.fDifConst[1];
86 this->fDriftVel[0] = s.fDriftVel[0];
87 this->fDriftVel[1] = s.fDriftVel[1];
90 //______________________________________________________________________
91 AliITSsimulationSSD::AliITSsimulationSSD(const AliITSsimulationSSD &source){
96 //______________________________________________________________________
97 AliITSsimulationSSD::~AliITSsimulationSSD() {
102 //______________________________________________________________________
103 void AliITSsimulationSSD::DigitiseModule(AliITSmodule *mod,Int_t module,
105 // Digitizes hits for one SSD module
107 Int_t lay, lad, detect;
108 AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
109 AliITSgeom *geom = aliITS->GetITSgeom();
110 geom->GetModuleId(module,lay, lad, detect);
111 if ( lay == 6 ) GetSegmentation()->SetLayer(6);
112 if ( lay == 5 ) GetSegmentation()->SetLayer(5);
114 TObjArray *hits = mod->GetHits();
115 Int_t nhits = hits->GetEntriesFast();
118 Double_t x0=0.0, y0=0.0, z0=0.0;
119 Double_t x1=0.0, y1=0.0, z1=0.0;
121 Int_t maxNdigits = 2*fNstrips;
122 Float_t **pList = new Float_t* [maxNdigits];
123 memset(pList,0,sizeof(Float_t*)*maxNdigits);
124 Int_t indexRange[4] = {0,0,0,0};
125 static Bool_t first = kTRUE;
126 Int_t lasttrack = -2;
129 for(Int_t i=0; i<nhits; i++) {
130 // LineSegmentL returns 0 if the hit is entering
131 // If hits is exiting returns positions of entering and exiting hits
132 // Returns also energy loss
134 if (mod->LineSegmentL(i, x0, x1, y0, y1, z0, z1, de, idtrack)) {
135 HitToDigit(module, x0, y0, z0, x1, y1, z1, de, indexRange, first);
137 if (lasttrack != idtrack || i==(nhits-1)) {
138 GetList(idtrack,pList,indexRange);
143 } // end loop over hits
148 ChargeToSignal(pList);
152 //----------------------------------------------------------------------
153 void AliITSsimulationSSD::HitToDigit(Int_t module, Double_t x0, Double_t y0,
154 Double_t z0, Double_t x1, Double_t y1,
155 Double_t z1, Double_t de,
156 Int_t *indexRange, Bool_t first) {
157 // Turns hits in SSD module into one or more digits.
159 Float_t tang[2] = {0.0,0.0};
160 GetSegmentation()->Angles(tang[0], tang[1]);//stereo<<->tan(stereo)~=stereo
162 Double_t dex=0.0, dey=0.0, dez=0.0;
163 Double_t pairs; // pair generation energy per step.
164 Double_t sigma[2] = {0.,0.};// standard deviation of the diffusion gaussian
165 Double_t tdrift[2] = {0.,0.}; // time of drift
167 Double_t inf[2], sup[2], par0[2];
169 // Steps in the module are determined "manually" (i.e. No Geant)
170 // NumOfSteps divide path between entering and exiting hits in steps
171 Int_t numOfSteps = NumOfSteps(x1, y1, z1, dex, dey, dez);
173 // Enery loss is equally distributed among steps
175 pairs = de/GetIonizeE(); // e-h pairs generated
177 for(Int_t j=0; j<numOfSteps; j++) { // stepping
178 x = x0 + (j+0.5)*dex;
179 y = y0 + (j+0.5)*dey;
180 if ( y > (GetSegmentation()->Dy()/2+10)*1.0E-4 ) {
181 // check if particle is within the detector
182 cout<<"AliITSsimulationSSD::HitToDigit: Warning: hit "
183 "out of detector y0,y,dey,j ="
184 <<y0<<","<<y<<","<<dey<<","<<j<<endl;
187 z = z0 + (j+0.5)*dez;
189 // calculate drift time
190 // y is the minimum path
191 tdrift[0] = (y+(GetSegmentation()->Dy()*1.0E-4)/2)/GetDriftVelocity(0);
192 tdrift[1] = ((GetSegmentation()->Dy()*1.0E-4)/2-y)/GetDriftVelocity(1);
194 for(Int_t k=0; k<2; k++) { // both sides remember: 0=Pside 1=Nside
196 tang[k]=TMath::Tan(tang[k]);
198 // w is the coord. perpendicular to the strips
200 w = (x+(GetSegmentation()->Dx()*1.0E-4)/2) -
201 (z+(GetSegmentation()->Dz()*1.0E-4)/2)*tang[k];
203 w = (x+(GetSegmentation()->Dx()*1.0E-4)/2) +
204 (z-(GetSegmentation()->Dz()*1.0E-4)/2)*tang[k];
206 w = w / (fPitch*1.0E-4); // w is converted in units of pitch
208 if((w<(-0.5)) || (w>(fNstrips-0.5))) {
209 // this check rejects hits in regions not covered by strips
210 // 0.5 takes into account boundaries
211 if(k==0) cout<<"AliITSsimulationSSD::HitToDigit: "
212 "Warning: no strip in this region of P side"
214 else cout<<"AliITSsimulationSSD::HitToDigit: "
215 "Warning: no strip in this region of N side"<<endl;
219 // sigma is the standard deviation of the diffusion gaussian
220 if(tdrift[k]<0) return;
221 sigma[k] = TMath::Sqrt(2*GetDiffConst(k)*tdrift[k]);
222 sigma[k] = sigma[k] /(fPitch*1.0E-4); //units of Pitch
224 cout<<"AliITSsimulationSSD::DigitiseModule: Error: sigma=0"
230 // we integrate the diffusion gaussian from -3sigma to 3sigma
231 inf[k] = w - 3*sigma[k]; // 3 sigma from the gaussian average
232 sup[k] = w + 3*sigma[k]; // 3 sigma from the gaussian average
233 // IntegrateGaussian does the actual
234 // integration of diffusion gaussian
235 IntegrateGaussian(k, par0[k], w, sigma[k], inf[k], sup[k],
237 } // end for loop over side (0=Pside, 1=Nside)
241 //______________________________________________________________________
242 void AliITSsimulationSSD::ApplyNoise() {
246 Double_t noise[2] = {0.,0.};
248 fResponse->GetNoiseParam(a,b); // retrieves noise parameters
249 noise[0] = (Double_t) a; noise[1] = (Double_t) b;
250 for(Int_t k=0;k<2;k++){ // both sides (0=Pside, 1=Nside)
251 for(Int_t ix=0;ix<fNstrips;ix++){ // loop over strips
252 signal = fMapA2->GetSignal(k,ix); // retrieves signal from map
253 signal += gRandom->Gaus(0,noise[k]);// add noise to signal
254 if(signal<0.) signal=0.0; // in case noise is negative...
255 fMapA2->SetHit(k,ix,signal); // give back signal to map
257 } // loop over k (P or N side)
259 //______________________________________________________________________
260 void AliITSsimulationSSD::ApplyCoupling() {
261 // Apply the effect of electronic coupling between channels
262 Double_t signalLeft=0, signalRight=0;
264 for(Int_t ix=0;ix<fNstrips;ix++){
265 if(ix>0.)signalLeft = fMapA2->GetSignal(0,ix-1)*fDCS->GetCouplingPL();
266 else signalLeft = 0.0;
267 if(ix<(fNstrips-1)) signalRight = fMapA2->GetSignal(0,ix+1)*
268 fDCS->GetCouplingPR();
269 else signalRight = 0.0;
270 fMapA2->AddSignal(0,ix,signalLeft + signalRight);
272 if(ix>0.) signalLeft = fMapA2->GetSignal(1,ix-1)*fDCS->GetCouplingNL();
273 else signalLeft = 0.0;
274 if(ix<(fNstrips-1)) signalRight = fMapA2->GetSignal(1,ix+1)*
275 fDCS->GetCouplingNR();
276 else signalRight = 0.0;
277 fMapA2->AddSignal(1,ix,signalLeft + signalRight);
278 } // loop over strips
280 //______________________________________________________________________
281 Float_t AliITSsimulationSSD::F(Float_t av, Float_t x, Float_t s) {
282 // Computes the integral of a gaussian using Error Function
283 Float_t sqrt2 = TMath::Sqrt(2.0);
284 Float_t sigm2 = sqrt2*s;
287 integral = 0.5 * TMath::Erf( (x - av) / sigm2);
290 //______________________________________________________________________
291 void AliITSsimulationSSD::IntegrateGaussian(Int_t k,Double_t par, Double_t w,
293 Double_t inf, Double_t sup,
294 Int_t *indexRange, Bool_t first) {
295 // integrate the diffusion gaussian
296 // remind: inf and sup are w-3sigma and w+3sigma
297 // we could define them here instead of passing them
298 // this way we are free to introduce asimmetry
300 Double_t a=0.0, b=0.0;
301 Double_t dXCharge1 = 0.0, dXCharge2 = 0.0;
302 // dXCharge1 and 2 are the charge to two neighbouring strips
303 // Watch that we only involve at least two strips
304 // Numbers greater than 2 of strips in a cluster depend on
305 // geometry of the track and delta rays, not charge diffusion!
307 Double_t strip = TMath::Floor(w); // clostest strip on the left
309 if ( TMath::Abs((strip - w)) < 0.5) {
310 // gaussian mean is closer to strip on the left
311 a = inf; // integration starting point
312 if((strip+0.5)<=sup) {
313 // this means that the tail of the gaussian goes beyond
314 // the middle point between strips ---> part of the signal
315 // is given to the strip on the right
316 b = strip + 0.5; // integration stopping point
317 dXCharge1 = F( w, b, sigma) - F(w, a, sigma);
318 dXCharge2 = F( w, sup, sigma) - F(w ,b, sigma);
320 // this means that all the charge is given to the strip on the left
322 dXCharge1 = 0.9973; // gaussian integral at 3 sigmas
326 dXCharge1 = par * dXCharge1;// normalize by mean of number of carriers
327 dXCharge2 = par * dXCharge2;
329 // for the time being, signal is the charge
330 // in ChargeToSignal signal is converted in ADC channel
331 fMapA2->AddSignal(k,strip,dXCharge1);
332 if(((Int_t) strip) < (fNstrips-1)) {
333 // strip doesn't have to be the last (remind: last=fNstrips-1)
334 // otherwise part of the charge is lost
335 fMapA2->AddSignal(k,(strip+1),dXCharge2);
340 indexRange[k*2+0] = indexRange[k*2+1]=(Int_t) strip;
344 indexRange[k*2+0]=TMath::Min(indexRange[k*2+0],(Int_t) strip);
345 indexRange[k*2+1]=TMath::Max(indexRange[k*2+1],(Int_t) strip);
349 // gaussian mean is closer to strip on the right
350 strip++; // move to strip on the rigth
351 b = sup; // now you know where to stop integrating
352 if((strip-0.5)>=inf) {
353 // tail of diffusion gaussian on the left goes left of
354 // middle point between strips
355 a = strip - 0.5; // integration starting point
356 dXCharge1 = F(w, b, sigma) - F(w, a, sigma);
357 dXCharge2 = F(w, a, sigma) - F(w, inf, sigma);
360 dXCharge1 = 0.9973; // gaussian integral at 3 sigmas
364 dXCharge1 = par * dXCharge1; // normalize by means of carriers
365 dXCharge2 = par * dXCharge2;
367 // for the time being, signal is the charge
368 // in ChargeToSignal signal is converted in ADC channel
369 fMapA2->AddSignal(k,strip,dXCharge1);
370 if(((Int_t) strip) > 0) {
371 // strip doesn't have to be the first
372 // otherwise part of the charge is lost
373 fMapA2->AddSignal(k,(strip-1),dXCharge2);
378 indexRange[k*2+0]=indexRange[k*2+1]=(Int_t) strip;
382 indexRange[k*2+0]=TMath::Min(indexRange[k*2+0],(Int_t) strip);
383 indexRange[k*2+1]=TMath::Max(indexRange[k*2+1],(Int_t) strip);
387 //______________________________________________________________________
388 Int_t AliITSsimulationSSD::NumOfSteps(Double_t x, Double_t y, Double_t z,
389 Double_t & dex,Double_t & dey,Double_t & dez){
391 // it also returns steps for each coord
392 //AliITSsegmentationSSD *seg = new AliITSsegmentationSSD();
394 Double_t step = 25E-4;
395 //step = (Double_t) seg->GetStepSize(); // step size (cm)
396 Int_t numOfSteps = (Int_t) (TMath::Sqrt(x*x+y*y+z*z)/step);
398 if (numOfSteps < 1) numOfSteps = 1; // one step, at least
400 // we could condition the stepping depending on the incident angle
408 //----------------------------------------------------------------------
409 void AliITSsimulationSSD::GetList(Int_t label,Float_t **pList,
411 // loop over nonzero digits
412 Int_t ix,globalIndex;
414 Float_t highest,middle,lowest;
416 for(Int_t k=0; k<2; k++) {
417 for(ix=indexRange[k*2+0];ix<indexRange[k*2+1]+1;ix++){
418 if(indexRange[k*2+0]<indexRange[k*2+1])
419 signal = fMapA2->GetSignal(k,ix);
421 globalIndex = k*fNstrips+ix; // globalIndex starts from 0!
422 if(!pList[globalIndex]){
424 //Create new list (6 elements-3 signals and 3 tracks+total sig)
426 pList[globalIndex] = new Float_t [6];
428 *pList[globalIndex] = -2.;
429 *(pList[globalIndex]+1) = -2.;
430 *(pList[globalIndex]+2) = -2.;
431 *(pList[globalIndex]+3) = 0.;
432 *(pList[globalIndex]+4) = 0.;
433 *(pList[globalIndex]+5) = 0.;
434 *pList[globalIndex] = (float)label;
435 *(pList[globalIndex]+3) = signal;
437 // check the signal magnitude
438 highest = *(pList[globalIndex]+3);
439 middle = *(pList[globalIndex]+4);
440 lowest = *(pList[globalIndex]+5);
441 signal -= (highest+middle+lowest);
443 // compare the new signal with already existing list
445 if(signal<lowest) continue; // neglect this track
447 *(pList[globalIndex]+5) = middle;
448 *(pList[globalIndex]+4) = highest;
449 *(pList[globalIndex]+3) = signal;
450 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
451 *(pList[globalIndex]+1) = *pList[globalIndex];
452 *pList[globalIndex] = label;
453 }else if (signal>middle){
454 *(pList[globalIndex]+5) = middle;
455 *(pList[globalIndex]+4) = signal;
456 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
457 *(pList[globalIndex]+1) = label;
459 *(pList[globalIndex]+5) = signal;
460 *(pList[globalIndex]+2) = label;
463 } // end of loop pixels in x
464 } // end of loop over pixels in z
466 //----------------------------------------------------------------------
467 void AliITSsimulationSSD::ChargeToSignal(Float_t **pList) {
469 AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
470 Float_t threshold = 0.;
471 Int_t digits[3], tracks[3],hits[3],gi,j1;
474 Float_t noise[2] = {0.,0.};
476 fResponse->GetNoiseParam(noise[0],noise[1]);
478 for(Int_t k=0;k<2;k++){ // both sides (0=Pside, 1=Nside)
480 // Threshold for zero-suppression
481 // It can be defined in AliITSresponseSSD
482 // threshold = (Float_t)fResponse->MinVal(k);
483 // I prefer to think adjusting the threshold "manually", looking
484 // at the scope, and considering noise standard deviation
485 threshold = 4.0*noise[k]; // 4 times noise is a choice
486 for(Int_t ix=0;ix<fNstrips;ix++){ // loop over strips
488 signal = (Float_t) fMapA2->GetSignal(k,ix);
489 gi =k*fNstrips+ix; // global index
490 if (signal > threshold) {
494 // convert to ADC signal
495 // conversion factor are rather arbitrary (need tuning)
496 // minimum ionizing particle--> ~30000 pairs--> ADC channel 50
497 signal = signal*50.0/30000.0;
498 if(signal>1000.) signal = 1000.0;//if exceeding, accumulate
500 digits[2]=(Int_t) signal;
503 tracks[j1] = (Int_t)(*(pList[gi]+j1));
505 tracks[j1]=-2; //noise
516 aliITS->AddSimDigit(2,phys,digits,tracks,hits,charges);
517 } // end if signal > threshold
518 if(pList[gi]) delete [] pList[gi];
523 //______________________________________________________________________
524 void AliITSsimulationSSD::Print(ostream *os){
525 //Standard output format for this class
527 //AliITSsimulation::Print(os);
528 *os << fNstrips <<","<< fPitch <<","<< fIonE <<",";
529 *os << fDifConst[0] <<","<< fDifConst[1] <<",";
530 *os << fDriftVel[0] <<","<< fDriftVel[1];
531 //*os <<","; fDCS->Print(os);
532 //*os <<","; fMapA2->Print(os);
534 //______________________________________________________________________
535 void AliITSsimulationSSD::Read(istream *is){
536 // Standard output streaming function.
538 //AliITSsimulation::Read(is);
539 *is >> fNstrips >> fPitch >> fIonE;
540 *is >> fDifConst[0] >> fDifConst[1];
541 *is >> fDriftVel[0] >> fDriftVel[1];
545 //______________________________________________________________________
546 ostream &operator<<(ostream &os,AliITSsimulationSSD &source){
547 // Standard output streaming function.
552 //______________________________________________________________________
553 istream &operator>>(istream &os,AliITSsimulationSSD &source){
554 // Standard output streaming function.