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