Separating well and badly reconstructed pileup vertices. Adding statistics of associa...
[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
66b89079 24#include <TGeoGlobalMagField.h>
fd61217e 25#include "AliITSmodule.h"
57817f7c 26#include "AliITSMapA2.h"
c7a4dac0 27#include "AliITSpList.h"
fcf95fc7 28#include "AliITSCalibrationSSD.h"
c7a4dac0 29#include "AliITSsegmentationSSD.h"
14a74335 30//#include "AliITSdcsSSD.h"
b0f5e3fc 31#include "AliITS.h"
3a97c582 32#include "AliITShit.h"
e869281d 33#include "AliITSdigitSSD.h"
b0f5e3fc 34#include "AliRun.h"
66b89079 35#include "AliMagF.h"
569a17d8 36#include "AliITSgeom.h"
57817f7c 37#include "AliITSsimulationSSD.h"
84541af4 38#include "AliITSTableSSD.h"
7d3b8602 39#include <TF1.h>
bb7e41dd 40#include "AliMathBase.h"
b0f5e3fc 41
fe7d86eb 42using std::endl;
43using std::cout;
925e6570 44ClassImp(AliITSsimulationSSD)
fd61217e 45////////////////////////////////////////////////////////////////////////
8ba39da9 46// //
14a74335 47// Author: Enrico Fragiacomo //
48// enrico.fragiacomo@ts.infn.it //
82adfb7d 49// Last revised: june 2008 //
14a74335 50// //
51// AliITSsimulationSSD is the simulation of SSD. //
8ba39da9 52////////////////////////////////////////////////////////////////////////
fd61217e 53
0315d466 54//----------------------------------------------------------------------
aacedc3e 55AliITSsimulationSSD::AliITSsimulationSSD():AliITSsimulation(),
14a74335 56 //fDCS(0),
aacedc3e 57fMapA2(0),
58fIonE(0.0),
59fDifConst(),
e06798d9 60fDriftVel(),
66b89079 61fTimeResponse(NULL),
62fLorentz(kFALSE),
63fTanLorAngP(0),
64fTanLorAngN(0)
65{
2727462b 66 //default Constructor
67 //Inputs:
68 // none.
69 // Outputs:
70 // none.
71 // Return:
72 // A default construction AliITSsimulationSSD class
57817f7c 73}
74//----------------------------------------------------------------------
8ba39da9 75AliITSsimulationSSD::AliITSsimulationSSD(AliITSDetTypeSim* dettyp):
76AliITSsimulation(dettyp),
14a74335 77//fDCS(0),
aacedc3e 78fMapA2(0),
79fIonE(0.0),
80fDifConst(),
7d3b8602 81fDriftVel(),
66b89079 82fTimeResponse(NULL),
83fLorentz(kFALSE),
84fTanLorAngP(0),
85fTanLorAngN(0)
86{
2727462b 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
7d3b8602 95 fTimeResponse = new TF1("ftimeresponse",".5*x*exp(1.-.5*x)");
2727462b 96 Init();
c7a4dac0 97}
98//----------------------------------------------------------------------
aacedc3e 99void AliITSsimulationSSD::Init(){
2727462b 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);
66b89079 109 AliITSSimuParam* simpar = fDetType->GetSimuParam();
2727462b 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);
66b89079 116 SetLorentzDrift(simpar->GetSSDLorentzDrift());
117 if (fLorentz) SetTanLorAngle();
b0f5e3fc 118}
66b89079 119
120//______________________________________________________________________
121Bool_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
0315d466 141//______________________________________________________________________
57817f7c 142AliITSsimulationSSD& AliITSsimulationSSD::operator=(
2727462b 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];
7d3b8602 155 this->fTimeResponse = s.fTimeResponse;
66b89079 156 this->fLorentz = s.fLorentz;
157 this->fTanLorAngP = s.fTanLorAngP;
158 this->fTanLorAngN = s.fTanLorAngN;
2727462b 159 return *this;
b0f5e3fc 160}
85f5e9c2 161/*
57817f7c 162//______________________________________________________________________
5402d9ca 163AliITSsimulation& AliITSsimulationSSD::operator=(
2727462b 164 const AliITSsimulation &s){
165 // Operator =
d2f55a22 166
2727462b 167 if(this==&s) return *this;
168 Error("AliITSsimulationSSD","Not allowed to make a = with "
d2f55a22 169 "AliITSsimulationSSD Using default creater instead");
2727462b 170
171 return *this;
d2f55a22 172}
85f5e9c2 173*/
d2f55a22 174//______________________________________________________________________
ac74f489 175AliITSsimulationSSD::AliITSsimulationSSD(const AliITSsimulationSSD &source):
2727462b 176 AliITSsimulation(source),
7537d03c 177fMapA2(source.fMapA2),
178fIonE(source.fIonE),
179fDifConst(),
7d3b8602 180fDriftVel(),
66b89079 181fTimeResponse(source.fTimeResponse),
182fLorentz(source.fLorentz),
183fTanLorAngP(source.fTanLorAngP),
184fTanLorAngN(source.fTanLorAngN)
185{
2727462b 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];
b0f5e3fc 191}
0315d466 192//______________________________________________________________________
b0f5e3fc 193AliITSsimulationSSD::~AliITSsimulationSSD() {
2727462b 194 // destructor
195 delete fMapA2;
7d3b8602 196 delete fTimeResponse;
2727462b 197 //delete fDCS;
0315d466 198}
57817f7c 199//______________________________________________________________________
3a97c582 200void AliITSsimulationSSD::InitSimulationModule(Int_t module,Int_t event){
2727462b 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();
3a97c582 214}
215//______________________________________________________________________
216void AliITSsimulationSSD::FinishSDigitiseModule(){
2727462b 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();
3a97c582 229}
230//______________________________________________________________________
aacedc3e 231void AliITSsimulationSSD::DigitiseModule(AliITSmodule *mod,Int_t,Int_t) {
2727462b 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();
c7a4dac0 240}
241//______________________________________________________________________
aacedc3e 242void AliITSsimulationSSD::SDigitiseModule(AliITSmodule *mod,Int_t,Int_t) {
2727462b 243 // Produces Summable/Analog digits and writes them to the SDigit tree.
c7a4dac0 244
2727462b 245 HitsToAnalogDigits(mod,fpList);
c7a4dac0 246
2727462b 247 WriteSDigits(fpList);
248
249 fpList->ClearMap();
250 fMapA2->ClearMap();
c7a4dac0 251}
252//______________________________________________________________________
253void AliITSsimulationSSD::SDigitToDigit(Int_t module,AliITSpList *pList){
2727462b 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);
c7a4dac0 261}
262//______________________________________________________________________
263void AliITSsimulationSSD::HitsToAnalogDigits(AliITSmodule *mod,
2727462b 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();
7d3b8602 273 Double_t tof = 0.;
274
2727462b 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);
66b89079 285
2727462b 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)) {
7d3b8602 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
c9f26a45 303 if(tof<2.) de = de * fTimeResponse->Eval(-1.*tof+2.);
304 else de = 0.;
7d3b8602 305 //
306
2727462b 307 HitToDigit(module, x0, y0, z0, x1, y1, z1, de,tav);
308 if (lasttrack != idtrack || i==(nhits-1)) {
82adfb7d 309 GetList(idtrack,i,module,pList,tav);
2727462b 310 } // end if
311 lasttrack=idtrack;
312 } // end if
313 } // end loop over hits
314 delete tav; tav=0;
315 return;
b0f5e3fc 316}
0315d466 317//----------------------------------------------------------------------
fd61217e 318void AliITSsimulationSSD::HitToDigit(Int_t module, Double_t x0, Double_t y0,
2727462b 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];
66b89079 336
337 // Set up corrections for Lorentz drift (ExB)
6f67f5b3 338 Double_t tanLorAngP = fTanLorAngP;
339 Double_t tanLorAngN = fTanLorAngN;
66b89079 340 if(seg->GetLayer()==6) {
6f67f5b3 341 tanLorAngP = -1.*fTanLorAngP;
342 tanLorAngN = -1.*fTanLorAngN;
66b89079 343 }
344
2727462b 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",
d35ad08f 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);
2727462b 364 return;
365 } // end if
366 z = z0 + (j+0.5)*dez;
82adfb7d 367
2727462b 368 if(GetDebug(4)) cout <<"HitToDigit "<<x<<" "<<y<<" "<<z<< " "
14a74335 369 <<dex<<" "<<dey<<" "<<dez<<endl;
82adfb7d 370
2727462b 371 if(seg->GetLayer()==6) {
372 y=-y; // Lay6 module has sensor up-side-down!!!
373 }
374
2727462b 375 Int_t k;
376 //---------------------------------------------------------
377 // Pside
378 //------------------------------------------------------------
379 k=0;
66b89079 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) {
6f67f5b3 387 Float_t deltaxp = (y+(seg->Dy()*1.0E-4)/2)*tanLorAngP;
66b89079 388 xp+=deltaxp;
389 }
390
391 seg->GetPadTxz(xp,zp);
2727462b 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
66b89079 405 // sigma is the standard deviation of the diffusion gaussian
2727462b 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;
66b89079 432
433 xp=x; zp=z;
434
435 // correction for the Lorentz's angle
436 if(fLorentz) {
6f67f5b3 437 Float_t deltaxn = ((seg->Dy()*1.0E-4)/2-y)*tanLorAngN;
66b89079 438 xp+=deltaxn;
439 }
440
441
442 seg->GetPadTxz(xp,zp);
443
2727462b 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
b0f5e3fc 482}
14a74335 483
57817f7c 484//______________________________________________________________________
c7a4dac0 485void AliITSsimulationSSD::ApplyNoise(AliITSpList *pList,Int_t module){
2727462b 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
b0f5e3fc 523}
0315d466 524//______________________________________________________________________
c7a4dac0 525void AliITSsimulationSSD::ApplyCoupling(AliITSpList *pList,Int_t module) {
2727462b 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;
b0f5e3fc 568}
14a74335 569
570//______________________________________________________________________
571void AliITSsimulationSSD::ApplyDeadChannels(Int_t module) {
2727462b 572 // Kill dead channels setting gain to zero
14a74335 573
2727462b 574 AliITSCalibrationSSD* res = (AliITSCalibrationSSD*)GetCalibrationModel(module);
14a74335 575
2727462b 576 for(Int_t i=0;i<GetNStrips();i++){
14a74335 577
2727462b 578 if(res->IsPChannelBad(i)) res->SetGainP(i,0.0);
579 if(res->IsNChannelBad(i)) res->SetGainN(i,0.0);
a64f9843 580
2727462b 581 } // loop over strips
14a74335 582
583}
584
0315d466 585//______________________________________________________________________
fd61217e 586Float_t AliITSsimulationSSD::F(Float_t av, Float_t x, Float_t s) {
2727462b 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;
fd61217e 591
bb7e41dd 592 integral = 0.5 * AliMathBase::ErfFast( (x - av) / sigm2);
2727462b 593 return integral;
0315d466 594}
595//______________________________________________________________________
fd61217e 596void AliITSsimulationSSD::IntegrateGaussian(Int_t k,Double_t par, Double_t w,
2727462b 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
b0f5e3fc 671}
0315d466 672//______________________________________________________________________
fd61217e 673Int_t AliITSsimulationSSD::NumOfSteps(Double_t x, Double_t y, Double_t z,
2727462b 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;
fd61217e 694}
0315d466 695//----------------------------------------------------------------------
c7a4dac0 696void AliITSsimulationSSD::GetList(Int_t label,Int_t hit,Int_t mod,
2727462b 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();
fd61217e 720}
0315d466 721//----------------------------------------------------------------------
18f63405 722void AliITSsimulationSSD::ChargeToSignal(Int_t module,const AliITSpList *pList) {
2727462b 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
14a74335 738
739 // if strip is dead -> gain=0
740 if( ((k==0)&&(res->GetGainP(ix)==0)) || ((k==1)&&(res->GetGainN(ix)==0))) continue;
741
3a4139a2 742 signal = fMapA2->GetSignal(k,ix);
14a74335 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
8be4e1b1 751 signal = res->GetSSDDEvToADC(signal);
f957a032 752 if(signal>4095.) signal = 4095.;//if exceeding, accumulate last one
14a74335 753
754 // threshold for zero suppression is set on the basis of the noise
755 // A good value is 3*sigma_noise
ced4d9bc 756 if(k==0) threshold = res->GetNoiseP(ix);
757 else threshold = res->GetNoiseN(ix);
758
8be4e1b1 759 threshold *= simpar->GetSSDZSThreshold(); // threshold at 3 sigma noise
ced4d9bc 760
14a74335 761 if(signal < threshold) continue;
ced4d9bc 762 //cout<<signal<<" "<<threshold<<endl;
14a74335 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);
2727462b 777 } // end for ix
778 } // end for k
779 delete [] digits;
780 delete [] tracks;
781 delete [] hits;
c7a4dac0 782}
783//______________________________________________________________________
784void AliITSsimulationSSD::WriteSDigits(AliITSpList *pList){
2727462b 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;
c7a4dac0 798}
799//______________________________________________________________________
800void AliITSsimulationSSD::FillMapFrompList(AliITSpList *pList){
2727462b 801 // Fills fMap2A from the pList of Summable digits
802 Int_t k,ix;
c7a4dac0 803
2727462b 804 for(k=0;k<2;k++)for(ix=0;ix<GetNStrips();ix++)
805 fMapA2->AddSignal(k,ix,pList->GetSignal(k,ix));
806 return;
b0f5e3fc 807}
57817f7c 808//______________________________________________________________________
809void AliITSsimulationSSD::Print(ostream *os){
2727462b 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);
57817f7c 818}
819//______________________________________________________________________
820void AliITSsimulationSSD::Read(istream *is){
2727462b 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);
57817f7c 829}
830//______________________________________________________________________
831ostream &operator<<(ostream &os,AliITSsimulationSSD &source){
2727462b 832 // Standard output streaming function.
57817f7c 833
2727462b 834 source.Print(&os);
835 return os;
57817f7c 836}
837//______________________________________________________________________
838istream &operator>>(istream &os,AliITSsimulationSSD &source){
2727462b 839 // Standard output streaming function.
57817f7c 840
2727462b 841 source.Read(&os);
842 return os;
57817f7c 843}
c7a4dac0 844//______________________________________________________________________
2727462b 845
846
847