]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSsimulationSDD.cxx
update of the tracker
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSDD.cxx
CommitLineData
b0f5e3fc 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 **************************************************************************/
5c5273c2 15
88cb7938 16/* $Id$ */
b0f5e3fc 17
4ae5bbc4 18#include <Riostream.h>
b0f5e3fc 19#include <stdlib.h>
20#include <stdio.h>
29e923a3 21#include <cstring>
1ca7869b 22
ece86d9a 23#include <TCanvas.h>
24#include <TF1.h>
1ca7869b 25#include <TH1.h>
26#include <TFile.h>
e939a978 27#include <TRandom.h>
a1e17193 28#include <TROOT.h>
e8189707 29#include "AliITS.h"
e8189707 30#include "AliITSMapA2.h"
f77f13c8 31#include "AliITSdigitSPD.h"
32#include "AliITSetfSDD.h"
f77f13c8 33#include "AliITSmodule.h"
bee7f138 34#include "AliITShit.h"
f77f13c8 35#include "AliITSpList.h"
fcf95fc7 36#include "AliITSCalibrationSDD.h"
dfd6be22 37#include "AliITSresponseSDD.h"
1ca7869b 38#include "AliITSsimulationSDD.h"
f77f13c8 39#include "AliLog.h"
40#include "AliRun.h"
b0f5e3fc 41
fe7d86eb 42using std::endl;
43using std::cout;
b0f5e3fc 44ClassImp(AliITSsimulationSDD)
45////////////////////////////////////////////////////////////////////////
8ba39da9 46// Version: 0 //
47// Written by Piergiorgio Cerello //
48// November 23 1999 //
49// //
50// AliITSsimulationSDD is the simulation of SDDs. //
51////////////////////////////////////////////////////////////////////////
52
8a33ae9e 53//______________________________________________________________________
aacedc3e 54AliITSsimulationSDD::AliITSsimulationSDD():
55AliITSsimulation(),
56fITS(0),
57fHitMap2(0),
58fHitSigMap2(0),
59fHitNoiMap2(0),
aacedc3e 60fElectronics(0),
61fInZR(0),
62fInZI(0),
63fOutZR(0),
64fOutZI(0),
65fAnodeFire(0),
66fHis(0),
aacedc3e 67fFlag(kFALSE),
aacedc3e 68fCrosstalkFlag(kFALSE),
69fDoFFT(1),
70fNofMaps(0),
71fMaxNofSamples(0),
72fScaleSize(0){
73 // Default constructor
aacedc3e 74 SetPerpendTracksFlag();
75 SetCrosstalkFlag();
76 SetDoFFT();
b0f5e3fc 77}
d2f55a22 78
8a33ae9e 79//______________________________________________________________________
8ba39da9 80AliITSsimulationSDD::AliITSsimulationSDD(AliITSDetTypeSim* dettyp):
81AliITSsimulation(dettyp),
aacedc3e 82fITS(0),
83fHitMap2(0),
84fHitSigMap2(0),
85fHitNoiMap2(0),
aacedc3e 86fElectronics(0),
87fInZR(0),
88fInZI(0),
89fOutZR(0),
90fOutZI(0),
91fAnodeFire(0),
92fHis(0),
aacedc3e 93fFlag(kFALSE),
aacedc3e 94fCrosstalkFlag(kFALSE),
95fDoFFT(1),
96fNofMaps(0),
97fMaxNofSamples(0),
98fScaleSize(0){
f45f6658 99 // Default Constructor
100 Init();
c7a4dac0 101}
102//______________________________________________________________________
aacedc3e 103void AliITSsimulationSDD::Init(){
104 // Standard Constructor
105
dee45d79 106 AliITSsegmentationSDD* seg = (AliITSsegmentationSDD*)GetSegmentationModel(1);
107 fScaleSize = ScaleFourier(seg);
aacedc3e 108 SetPerpendTracksFlag();
109 SetCrosstalkFlag();
110 SetDoFFT();
aacedc3e 111
cd2a0045 112 AliITSSimuParam* simpar = fDetType->GetSimuParam();
8ba39da9 113 fpList = new AliITSpList( seg->Npz(),
114 fScaleSize*seg->Npx() );
115 fHitSigMap2 = new AliITSMapA2(seg,fScaleSize,1);
116 fHitNoiMap2 = new AliITSMapA2(seg,fScaleSize,1);
aacedc3e 117 fHitMap2 = fHitSigMap2;
118
8ba39da9 119 fNofMaps = seg->Npz();
120 fMaxNofSamples = seg->Npx();
aacedc3e 121 fAnodeFire = new Bool_t [fNofMaps];
43217ad9 122
8ba39da9 123 Float_t sddWidth = seg->Dz();
f6b6d58e 124 Float_t anodePitch = seg->Dpz(0);
125 Double_t timeStep = (Double_t)seg->Dpx(0);
aacedc3e 126
127 if(anodePitch*(fNofMaps/2) > sddWidth) {
a72dbdfe 128 AliWarning(Form("Too many anodes %d or too big pitch %f ",
129 fNofMaps/2,anodePitch));
aacedc3e 130 } // end if
b0f5e3fc 131
b0f5e3fc 132
aacedc3e 133 fElectronics = new AliITSetfSDD(timeStep/fScaleSize,
cd2a0045 134 simpar->GetSDDElectronics());
b0f5e3fc 135
aacedc3e 136
aacedc3e 137 fITS = (AliITS*)gAlice->GetModule("ITS");
20f3f947 138
aacedc3e 139 fInZR = new Double_t [fScaleSize*fMaxNofSamples];
140 fInZI = new Double_t [fScaleSize*fMaxNofSamples];
141 fOutZR = new Double_t [fScaleSize*fMaxNofSamples];
142 fOutZI = new Double_t [fScaleSize*fMaxNofSamples];
b0f5e3fc 143}
8a33ae9e 144//______________________________________________________________________
b0f5e3fc 145AliITSsimulationSDD::~AliITSsimulationSDD() {
aacedc3e 146 // destructor
147
148 // delete fpList;
149 delete fHitSigMap2;
150 delete fHitNoiMap2;
aacedc3e 151 delete fElectronics;
152
153 fITS = 0;
154
155 if (fHis) {
156 fHis->Delete();
157 delete fHis;
158 } // end if fHis
aacedc3e 159 if(fInZR) delete [] fInZR;
160 if(fInZI) delete [] fInZI;
161 if(fOutZR) delete [] fOutZR;
162 if(fOutZI) delete [] fOutZI;
163 if(fAnodeFire) delete [] fAnodeFire;
b0f5e3fc 164}
8a33ae9e 165//______________________________________________________________________
50d05d7b 166void AliITSsimulationSDD::InitSimulationModule( Int_t module, Int_t event ) {
aacedc3e 167 // create maps to build the lists of tracks for each summable digit
168 fModule = module;
169 fEvent = event;
170 ClearMaps();
171 memset(fAnodeFire,0,sizeof(Bool_t)*fNofMaps);
50d05d7b 172}
173//______________________________________________________________________
174void AliITSsimulationSDD::ClearMaps() {
aacedc3e 175 // clear maps
176 fpList->ClearMap();
177 fHitSigMap2->ClearMap();
178 fHitNoiMap2->ClearMap();
50d05d7b 179}
20f3f947 180//______________________________________________________________________
181void AliITSsimulationSDD::FastFourierTransform(Double_t *real,
182 Double_t *imag,Int_t direction) {
183 // Do a Fast Fourier Transform
184
185 Int_t samples = fElectronics->GetSamples();
186 Int_t l = (Int_t) ((log((Float_t) samples)/log(2.))+0.5);
187 Int_t m1 = samples;
188 Int_t m = samples/2;
189 Int_t m2 = samples/m1;
190 Int_t i,j,k;
191 for(i=1; i<=l; i++) {
192 for(j=0; j<samples; j += m1) {
193 Int_t p = 0;
194 for(k=j; k<= j+m-1; k++) {
195 Double_t wsr = fElectronics->GetWeightReal(p);
196 Double_t wsi = fElectronics->GetWeightImag(p);
197 if(direction == -1) wsi = -wsi;
198 Double_t xr = *(real+k+m);
199 Double_t xi = *(imag+k+m);
200 *(real+k+m) = wsr*(*(real+k)-xr) - wsi*(*(imag+k)-xi);
201 *(imag+k+m) = wsr*(*(imag+k)-xi) + wsi*(*(real+k)-xr);
202 *(real+k) += xr;
203 *(imag+k) += xi;
204 p += m2;
205 } // end for k
206 } // end for j
207 m1 = m;
208 m /= 2;
209 m2 += m2;
210 } // end for i
20f3f947 211 for(j=0; j<samples; j++) {
212 Int_t j1 = j;
213 Int_t p = 0;
214 Int_t i1;
215 for(i1=1; i1<=l; i1++) {
216 Int_t j2 = j1;
217 j1 /= 2;
218 p = p + p + j2 - j1 - j1;
219 } // end for i1
220 if(p >= j) {
221 Double_t xr = *(real+j);
222 Double_t xi = *(imag+j);
223 *(real+j) = *(real+p);
224 *(imag+j) = *(imag+p);
225 *(real+p) = xr;
226 *(imag+p) = xi;
227 } // end if p>=j
228 } // end for j
229 if(direction == -1) {
230 for(i=0; i<samples; i++) {
231 *(real+i) /= samples;
232 *(imag+i) /= samples;
233 } // end for i
234 } // end if direction == -1
235 return;
236}
237
50d05d7b 238//______________________________________________________________________
aacedc3e 239void AliITSsimulationSDD::SDigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
240 // digitize module using the "slow" detector simulator creating
241 // summable digits.
242
243 TObjArray *fHits = mod->GetHits();
244 Int_t nhits = fHits->GetEntriesFast();
245 if( !nhits ) return;
246
247 InitSimulationModule( md, ev );
5683bd96 248 HitsToAnalogDigits( mod ); // fills fHitMap2 which is = fHitSigmap2
249 ChargeToSignal( fModule,kFALSE,kTRUE ); // - Process signal adding gain without adding noise
aacedc3e 250 fHitMap2 = fHitNoiMap2; // - Swap to noise map
5683bd96 251 ChargeToSignal( fModule,kTRUE,kFALSE ); // - Process only noise
aacedc3e 252 fHitMap2 = fHitSigMap2; // - Return to signal map
253 WriteSDigits();
254 ClearMaps();
50d05d7b 255}
256//______________________________________________________________________
aacedc3e 257Bool_t AliITSsimulationSDD::AddSDigitsToModule(TClonesArray *pItemArray,
258 Int_t mask ) {
259 // Add Summable digits to module maps.
cd2a0045 260 AliITSSimuParam* simpar = fDetType->GetSimuParam();
aacedc3e 261 Int_t nItems = pItemArray->GetEntries();
cd2a0045 262 Double_t maxadc = simpar->GetSDDMaxAdc();
aacedc3e 263 Bool_t sig = kFALSE;
48058160 264
aacedc3e 265 // cout << "Adding "<< nItems <<" SDigits to module " << fModule << endl;
266 for( Int_t i=0; i<nItems; i++ ) {
267 AliITSpListItem * pItem = (AliITSpListItem *)(pItemArray->At( i ));
268 if( pItem->GetModule() != fModule ) {
269 Error( "AliITSsimulationSDD","Error reading, SDigits module "
270 "%d != current module %d: exit",
271 pItem->GetModule(), fModule );
272 return sig;
273 } // end if
274
275 if(pItem->GetSignal()>0.0 ) sig = kTRUE;
43217ad9 276
aacedc3e 277 fpList->AddItemTo( mask, pItem ); // Add SignalAfterElect + noise
278 AliITSpListItem * pItem2 = fpList->GetpListItem( pItem->GetIndex() );
279 Double_t sigAE = pItem2->GetSignalAfterElect();
280 if( sigAE >= maxadc ) sigAE = maxadc-1; // avoid overflow signal
281 Int_t ia;
282 Int_t it;
283 fpList->GetMapIndex( pItem->GetIndex(), ia, it );
284 fHitMap2->SetHit( ia, it, sigAE );
285 fAnodeFire[ia] = kTRUE;
286 }
287 return sig;
48058160 288}
50d05d7b 289//______________________________________________________________________
290void AliITSsimulationSDD::FinishSDigitiseModule() {
aacedc3e 291 // digitize module using the "slow" detector simulator from
292 // the sum of summable digits.
293 FinishDigits() ;
294 ClearMaps();
c7a4dac0 295}
296//______________________________________________________________________
b0f5e3fc 297void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
aacedc3e 298 // create maps to build the lists of tracks for each digit
b0f5e3fc 299
aacedc3e 300 TObjArray *fHits = mod->GetHits();
301 Int_t nhits = fHits->GetEntriesFast();
8a33ae9e 302
aacedc3e 303 InitSimulationModule( md, ev );
20f3f947 304 if( !nhits ) return;
48058160 305
aacedc3e 306 HitsToAnalogDigits( mod );
5683bd96 307 ChargeToSignal( fModule,kTRUE,kTRUE ); // process signal + noise
aacedc3e 308
309 for( Int_t i=0; i<fNofMaps; i++ ) {
310 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
311 Int_t jdx = j*fScaleSize;
312 Int_t index = fpList->GetHitIndex( i, j );
313 AliITSpListItem pItemTmp2( fModule, index, 0. );
314 // put the fScaleSize analog digits in only one
315 for( Int_t ik=0; ik<fScaleSize; ik++ ) {
316 AliITSpListItem *pItemTmp = fpList->GetpListItem( i, jdx+ik );
317 if( pItemTmp == 0 ) continue;
318 pItemTmp2.Add( pItemTmp );
319 }
320 fpList->DeleteHit( i, j );
321 fpList->AddItemTo( 0, &pItemTmp2 );
322 }
48058160 323 }
aacedc3e 324 FinishDigits();
325 ClearMaps();
c7a4dac0 326}
327//______________________________________________________________________
50d05d7b 328void AliITSsimulationSDD::FinishDigits() {
aacedc3e 329 // introduce the electronics effects and do zero-suppression if required
8a33ae9e 330
8ba39da9 331 if( fCrosstalkFlag ) ApplyCrosstalk(fModule);
50d05d7b 332
f45f6658 333 AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fModule);
253e68a0 334 Bool_t isZeroSupp = res->GetZeroSupp();
335 if (isZeroSupp) Compress2D();
20f3f947 336 else StoreAllDigits();
c7a4dac0 337}
338//______________________________________________________________________
50d05d7b 339void AliITSsimulationSDD::HitsToAnalogDigits( AliITSmodule *mod ) {
aacedc3e 340 // create maps to build the lists of tracks for each digit
8ba39da9 341 AliITSsegmentationSDD* seg = (AliITSsegmentationSDD*)GetSegmentationModel(1);
f45f6658 342 AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fModule);
cd2a0045 343 AliITSSimuParam* simpar = fDetType->GetSimuParam();
8ba39da9 344 TObjArray *hits = mod->GetHits();
bee7f138 345 Int_t nhits = hits->GetEntriesFast();
346
347 // Int_t arg[6] = {0,0,0,0,0,0};
348 Int_t nofAnodes = fNofMaps/2;
349 Double_t sddLength = seg->Dx();
bee7f138 350 Double_t anodePitch = seg->Dpz(0);
351 Double_t timeStep = seg->Dpx(0);
352 Double_t driftSpeed ; // drift velocity (anode dependent)
353 Double_t nanoampToADC = simpar->GetSDDMaxAdc()/simpar->GetSDDDynamicRange(); // maxadc/topValue;
354 Double_t cHloss = simpar->GetSDDChargeLoss();
355 Float_t dfCoeff, s1;
356 simpar->GetSDDDiffCoeff(dfCoeff,s1); // Signal 2d Shape
357 Double_t eVpairs = simpar->GetGeVToCharge()*1.0E9; // 3.6 eV by def.
358 Double_t nsigma = simpar->GetNSigmaIntegration(); //
359 Int_t nlookups = simpar->GetGausNLookUp(); //
360 Float_t jitter = simpar->GetSDDJitterError(); //
374200ee 361 Float_t mapsmear = simpar->GetSDDCorrMapPrecision(); //
dfd6be22 362 Float_t trigDelay = simpar->GetSDDTrigDelay(); // compensation for MC time zero
19dcb509 363 if(res->IsAMAt20MHz()) trigDelay+=12.5; // compensation for discretization step
374200ee 364
dfd6be22 365 Float_t timeZero=fDetType->GetResponseSDD()->GetTimeZero(fModule);
374200ee 366 Float_t adcscale = fDetType->GetResponseSDD()->GetADCtokeV(fModule);
367 adcscale/=simpar->GetSDDkeVtoADC();
417ff3f4 368
bee7f138 369 // Piergiorgio's part (apart for few variables which I made float
370 // when i thought that can be done
371 // Fill detector maps with GEANT hits
372 // loop over hits in the module
373
374 const Float_t kconv = 1.0e+6; // GeV->KeV
375 Int_t itrack = 0;
376 Int_t iWing; // which detector wing/side.
377 Int_t ii,kk,ka,kt; // loop indexs
378 Int_t ia,it,index; // sub-pixel integration indexies
379 Int_t iAnode; // anode number.
380 Int_t timeSample; // time buckett.
381 Int_t anodeWindow; // anode direction charge integration width
382 Int_t timeWindow; // time direction charge integration width
383 Int_t jamin,jamax; // anode charge integration window
384 Int_t jtmin,jtmax; // time charge integration window
385 Int_t nsplitAn; // the number of splits in anode and time windows
386 Int_t nsplitTb; // the number of splits in anode and time windows
387 Int_t nOfSplits; // number of times track length is split into
388 Float_t nOfSplitsF; // Floating point version of nOfSplits.
389 Float_t kkF; // Floating point version of loop index kk.
390 Double_t pathInSDD; // Track length in SDD.
391 Double_t drPath; // average position of track in detector. in microns
392 Double_t drTime; // Drift time
393 Double_t avDrft; // x position of path length segment in cm.
394 Double_t avAnode; // Anode for path length segment in Anode number (float)
395 Double_t zAnode; // Floating point anode number.
396 Double_t driftPath; // avDrft in microns.
397 Double_t width; // width of signal at anodes.
398 Double_t depEnergy; // Energy deposited in this GEANT step.
399 Double_t xL[3],dxL[3]; // local hit coordinates and diff.
400 Double_t sigA; // sigma of signal at anode.
401 Double_t sigT; // sigma in time/drift direction for track segment
402 Double_t aStep,aConst; // sub-pixel size and offset anode
403 Double_t tStep,tConst; // sub-pixel size and offset time
404 Double_t amplitude; // signal amplitude for track segment in nanoAmpere
405 Double_t chargeloss; // charge loss for track segment.
406 Double_t anodeAmplitude; // signal amplitude in anode direction
407 Double_t aExpo; // exponent of Gaussian anode direction
408 Double_t timeAmplitude; // signal amplitude in time direction
409 Double_t tExpo; // exponent of Gaussian time direction
410 Double_t tof; // Time of flight in ns of this step.
411
412 for(ii=0; ii<nhits; ii++) {
413 if(!mod->LineSegmentL(ii,xL[0],dxL[0],xL[1],dxL[1],xL[2],dxL[2],
414 depEnergy,itrack)) continue;
415 Float_t xloc=xL[0];
416 if(xloc>0) iWing=0; // left side, carlos channel 0
417 else iWing=1; // right side
cd2a0045 418
bee7f138 419 Float_t zloc=xL[2]+0.5*dxL[2];
420 zAnode=seg->GetAnodeFromLocal(xloc,zloc); // anode number in the range 0.-511.
421 driftSpeed = res->GetDriftSpeedAtAnode(zAnode);
374200ee 422 driftSpeed+= fDetType->GetResponseSDD()->GetDeltaVDrift(fModule,zAnode>255);
423
bee7f138 424 if(timeStep*fMaxNofSamples < sddLength/driftSpeed) {
a72dbdfe 425 AliWarning("Time Interval > Allowed Time Interval");
bee7f138 426 }
427 depEnergy *= kconv;
428 if (!depEnergy) {
429 AliDebug(1,
430 Form("fTrack = %d hit=%d module=%d This particle has passed without losing energy!",
431 itrack,ii,mod->GetIndex()));
432 continue;
f6b6d58e 433 // continue if the particle did not lose energy
434 // passing through detector
bee7f138 435 } // end if !depEnergy
436
437 tof=0.;
438 AliITShit* h=(AliITShit*)hits->At(ii);
2c4e6a6a 439 if(h){
440 tof=h->GetTOF()*1E9;
441 AliDebug(1,Form("TOF for hit %d on mod %d (particle %d)=%g",ii,fModule,h->Track(),tof));
442 }
443
374200ee 444 Float_t corrx=0, corrz=0;
445 res->GetShiftsForSimulation(xL[2],xL[0],corrz,corrx,seg);
446 xL[2]-=corrz;
447 xL[0]-=corrx;
448 xL[0] += 0.0001*gRandom->Gaus( 0, mapsmear); //
bee7f138 449 xL[0] += 0.0001*gRandom->Gaus( 0, jitter ); //
374200ee 450
bee7f138 451 pathInSDD = TMath::Sqrt(dxL[0]*dxL[0]+dxL[1]*dxL[1]+dxL[2]*dxL[2]);
452
453 if (fFlag && pathInSDD) { depEnergy *= (0.03/pathInSDD); }
454 drPath = TMath::Abs(10000.*(dxL[0]+2.*xL[0])*0.5);
455 drPath = sddLength-drPath;
456 if(drPath < 0) {
374200ee 457 AliInfo( // this should be fixed at geometry level
bee7f138 458 Form("negative drift path drPath=%e sddLength=%e dxL[0]=%e xL[0]=%e",
459 drPath,sddLength,dxL[0],xL[0]));
460 continue;
461 } // end if drPath < 0
462
463 // Compute number of segments to brake step path into
464 drTime = drPath/driftSpeed; // Drift Time
465 sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);// Sigma along the anodes
466 // calcuate the number of time the path length should be split into.
467 nOfSplits = (Int_t) (1. + 10000.*pathInSDD/sigA);
468 if(fFlag) nOfSplits = 1;
469
470 // loop over path segments, init. some variables.
471 depEnergy /= nOfSplits;
472 nOfSplitsF = (Float_t) nOfSplits;
473 Float_t theAverage=0.,theSteps=0.;
474 for(kk=0;kk<nOfSplits;kk++) { // loop over path segments
475 kkF = (Float_t) kk + 0.5;
476 avDrft = xL[0]+dxL[0]*kkF/nOfSplitsF;
477 avAnode = xL[2]+dxL[2]*kkF/nOfSplitsF;
478 theSteps+=1.;
479 theAverage+=avAnode;
480 zAnode = seg->GetAnodeFromLocal(avDrft,avAnode);
481 driftSpeed = res->GetDriftSpeedAtAnode(zAnode);
374200ee 482 driftSpeed+= fDetType->GetResponseSDD()->GetDeltaVDrift(fModule,zAnode>255);
bee7f138 483 driftPath = TMath::Abs(10000.*avDrft);
484 driftPath = sddLength-driftPath;
485 if(driftPath < 0) {
f6b6d58e 486 AliDebug(1, // this should be fixed at geometry level
bee7f138 487 Form("negative drift path driftPath=%e sddLength=%e avDrft=%e dxL[0]=%e xL[0]=%e",
488 driftPath,sddLength,avDrft,dxL[0],xL[0]));
489 continue;
490 } // end if driftPath < 0
491 drTime = driftPath/driftSpeed; // drift time for segment.
492 // Sigma along the anodes for track segment.
493 sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);
494 sigT = sigA/driftSpeed;
495
496 drTime+=tof; // take into account Time Of Flight from production point
dfd6be22 497 drTime-=trigDelay;
498 drTime+=timeZero;
a72dbdfe 499 timeSample = (Int_t) (fScaleSize*drTime/timeStep + 1.001); // time bin in range 1-256 !!!
bee7f138 500 if(zAnode>nofAnodes) zAnode-=nofAnodes; // to have the anode number between 0. and 256.
a72dbdfe 501 iAnode = (Int_t) (1.001+zAnode); // iAnode in range 1-256 !!!!
bee7f138 502
f6b6d58e 503 // Peak amplitude in nanoAmpere
bee7f138 504 amplitude = fScaleSize*160.*depEnergy/
505 (timeStep*eVpairs*2.*acos(-1.));
506 chargeloss = 1.-cHloss*driftPath/1000.;
507 amplitude *= chargeloss;
374200ee 508 amplitude *= adcscale;
bee7f138 509 width = 2.*nsigma/(nlookups-1);
510 // Spread the charge
511 nsplitAn = 4;
512 nsplitTb=4;
513 aStep = anodePitch/(nsplitAn*sigA);
514 aConst = zAnode*anodePitch/sigA;
515 tStep = timeStep/(nsplitTb*fScaleSize*sigT);
516 tConst = drTime/sigT;
517 // Define SDD window corresponding to the hit
518 anodeWindow = (Int_t)(nsigma*sigA/anodePitch+1);
519 timeWindow = (Int_t) (fScaleSize*nsigma*sigT/timeStep+1.);
520 jamin = (iAnode - anodeWindow - 2)*nsplitAn+1;
bee7f138 521 if(jamin <= 0) jamin = 1;
a72dbdfe 522 if(jamin > nofAnodes*nsplitAn){
523 AliDebug(1,Form("Energy deposition completely outside anode acceptance: anode min=%d",jamin));
524 continue;
525 }
526 jamax = (iAnode + anodeWindow + 2)*nsplitAn;
527 if(jamax > nofAnodes*nsplitAn) jamax = nofAnodes*nsplitAn;
528 if(jamax <=0){
529 AliDebug(1,Form("Energy deposition completely outside anode acceptance: anode max=%d",jamax));
530 continue;
531 }
bee7f138 532 jtmin = (Int_t)(timeSample-timeWindow-2)*nsplitTb+1;
bee7f138 533 if(jtmin <= 0) jtmin = 1;
a72dbdfe 534 if(jtmin > fScaleSize*fMaxNofSamples*nsplitTb){
535 AliDebug(1,Form("Energy deposition completely outside time acceptance: time sample min=%d tof=%f",jtmin,tof));
536 continue;
537 }
538 jtmax = (Int_t)(timeSample+timeWindow+2)*nsplitTb;
539 if(jtmax > fScaleSize*fMaxNofSamples*nsplitTb) jtmax = fScaleSize*fMaxNofSamples*nsplitTb;
540 if(jtmax <= 0){
541 AliDebug(1,Form("Energy deposition completely outside time acceptance: time sample max=%d tof=%f",jtmax,tof));
542 continue;
543 }
544
bee7f138 545 // Spread the charge in the anode-time window
546 for(ka=jamin; ka <=jamax; ka++) {
547 ia = (ka-1)/nsplitAn + 1;
548 if(ia <= 0) ia=1;
549 if(ia > nofAnodes) ia = nofAnodes;
550 aExpo = (aStep*(ka-0.5)-aConst);
551 if(TMath::Abs(aExpo) > nsigma) anodeAmplitude = 0.;
552 else {
553 Int_t theBin = (Int_t) ((aExpo+nsigma)/width+0.5);
554 anodeAmplitude = amplitude*simpar->GetGausLookUp(theBin);
555 }
556 // index starts from 0
557 index = iWing*nofAnodes+ia-1;
558 if(anodeAmplitude){
559 for(kt=jtmin; kt<=jtmax; kt++) {
560 it = (kt-1)/nsplitTb+1; // it starts from 1
561 if(it<=0) it=1;
562 if(it>fScaleSize*fMaxNofSamples)
563 it = fScaleSize*fMaxNofSamples;
564 tExpo = (tStep*(kt-0.5)-tConst);
565 if(TMath::Abs(tExpo) > nsigma) timeAmplitude = 0.;
566 else {
567 Int_t theBin = (Int_t) ((tExpo+nsigma)/width+0.5);
568 timeAmplitude = anodeAmplitude*simpar->GetGausLookUp(theBin)*aStep*tStep;
569 }
570 timeAmplitude *= nanoampToADC;
571 // ListOfFiredCells(arg,timeAmplitude,alst,padr);
572 Double_t charge = timeAmplitude;
573 charge += fHitMap2->GetSignal(index,it-1);
574 fHitMap2->SetHit(index, it-1, charge);
575 fpList->AddSignal(index,it-1,itrack,ii-1,
576 mod->GetIndex(),timeAmplitude);
577 fAnodeFire[index] = kTRUE;
578 } // end loop over time in window
579 } // end if anodeAmplitude
580 } // loop over anodes in window
581 } // end loop over "sub-hits"
582 } // end loop over hits
b0f5e3fc 583}
aacedc3e 584
b0f5e3fc 585//____________________________________________
83ec5e27 586void AliITSsimulationSDD::AddDigit( Int_t i, Int_t j, Int_t signalc, Int_t signale) {
20f3f947 587 // Adds a Digit.
588 Int_t size = AliITSdigit::GetNTracks();
589
590 Int_t digits[3];
591 Int_t * tracks = new Int_t[size];
592 Int_t * hits = new Int_t[size];
593 Float_t phys;
594 Float_t * charges = new Float_t[size];
595
596 digits[0] = i;
597 digits[1] = j;
83ec5e27 598 digits[2] = signalc;
20f3f947 599
600 AliITSpListItem *pItem = fpList->GetpListItem( i, j );
601 if( pItem == 0 ) {
602 phys = 0.0;
603 for( Int_t l=0; l<size; l++ ) {
604 tracks[l] = 0;
605 hits[l] = 0;
606 charges[l] = 0.0;
50d05d7b 607 }
20f3f947 608 } else {
609 Int_t idtrack = pItem->GetTrack( 0 );
610 if( idtrack >= 0 ) phys = pItem->GetSignal();
611 else phys = 0.0;
612
613 for( Int_t l=0; l<size; l++ ) if(l<pItem->GetMaxKept()) {
614 tracks[l] = pItem->GetTrack( l );
615 hits[l] = pItem->GetHit( l );
616 charges[l] = pItem->GetSignal( l );
617 }else{
618 tracks[l] = -3;
619 hits[l] = -1;
620 charges[l] = 0.0;
621 }// end for if
622 }
50d05d7b 623
83ec5e27 624 fITS->AddSimDigit( 1, phys, digits, tracks, hits, charges, signale );
20f3f947 625 delete [] tracks;
626 delete [] hits;
627 delete [] charges;
aacedc3e 628}
8a33ae9e 629//______________________________________________________________________
5683bd96 630void AliITSsimulationSDD::ChargeToSignal(Int_t mod,Bool_t bAddNoise, Bool_t bAddGain) {
631 // add baseline, noise, gain, electronics and ADC saturation effects
632 // apply dead channels
633
5683bd96 634 AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(mod);
5683bd96 635 Double_t baseline=0;
636 Double_t noise=0;
637 Double_t gain=0;
638 Float_t contrib=0;
639 Int_t i,k,kk;
cd2a0045 640 AliITSSimuParam* simpar = fDetType->GetSimuParam();
641 Float_t maxadc = simpar->GetSDDMaxAdc();
aebba721 642 Int_t nGroup=fScaleSize;
643 if(res->IsAMAt20MHz()){
644 nGroup=fScaleSize/2;
645 }
5683bd96 646
647 for (i=0;i<fNofMaps;i++) {
648 if( !fAnodeFire[i] ) continue;
649 baseline = res->GetBaseline(i);
650 noise = res->GetNoise(i);
cf8425ac 651 gain = res->GetChannelGain(i)/fDetType->GetAverageGainSDD();
eefec958 652 if(res->IsBad()) gain=0.;
13a2b50d 653 if( res->IsChipBad(res->GetChip(i)) )gain=0.;
5683bd96 654 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
655 fInZR[k] = fHitMap2->GetSignal(i,k);
656 if(bAddGain) fInZR[k]*=gain;
657 if( bAddNoise ) {
658 contrib = (baseline + noise*gRandom->Gaus());
659 fInZR[k] += contrib;
660 }
661 fInZI[k] = 0.;
662 } // end for k
b27af87f 663 if(!fDoFFT) {
5683bd96 664 for(k=0; k<fMaxNofSamples; k++) {
665 Double_t newcont = 0.;
666 Double_t maxcont = 0.;
667 for(kk=0;kk<fScaleSize;kk++) {
668 newcont = fInZR[fScaleSize*k+kk];
669 if(newcont > maxcont) maxcont = newcont;
670 } // end for kk
671 newcont = maxcont;
672 if (newcont >= maxadc) newcont = maxadc -1;
673 if(newcont >= baseline){
a5a317a9 674 Warning("","newcont=%f>=baseline=%f",newcont,baseline);
5683bd96 675 } // end if
676 // back to analog: ?
677 fHitMap2->SetHit(i,k,newcont);
678 } // end for k
679 }else{
20f3f947 680 FastFourierTransform(&fInZR[0],&fInZI[0],1);
5683bd96 681 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
682 Double_t rw = fElectronics->GetTraFunReal(k);
683 Double_t iw = fElectronics->GetTraFunImag(k);
684 fOutZR[k] = fInZR[k]*rw - fInZI[k]*iw;
685 fOutZI[k] = fInZR[k]*iw + fInZI[k]*rw;
686 } // end for k
20f3f947 687 FastFourierTransform(&fOutZR[0],&fOutZI[0],-1);
5683bd96 688 for(k=0; k<fMaxNofSamples; k++) {
689 Double_t newcont1 = 0.;
690 Double_t maxcont1 = 0.;
aebba721 691 for(kk=0;kk<nGroup;kk++) {
5683bd96 692 newcont1 = fOutZR[fScaleSize*k+kk];
693 if(newcont1 > maxcont1) maxcont1 = newcont1;
694 } // end for kk
695 newcont1 = maxcont1;
696 if (newcont1 >= maxadc) newcont1 = maxadc -1;
697 fHitMap2->SetHit(i,k,newcont1);
698 } // end for k
699 }
700 } // end for i loop over anodes
701 return;
50d05d7b 702}
5683bd96 703
50d05d7b 704//______________________________________________________________________
8ba39da9 705void AliITSsimulationSDD::ApplyCrosstalk(Int_t mod) {
aacedc3e 706 // function add the crosstalk effect to signal
707 // temporal function, should be checked...!!!
8ba39da9 708
aacedc3e 709 // create and inizialice crosstalk map
710 Float_t* ctk = new Float_t[fNofMaps*fMaxNofSamples+1];
aacedc3e 711 memset( ctk, 0, sizeof(Float_t)*(fNofMaps*fMaxNofSamples+1) );
f45f6658 712 AliITSCalibrationSDD* calibr = (AliITSCalibrationSDD*)GetCalibrationModel(mod);
aacedc3e 713 for( Int_t z=0; z<fNofMaps; z++ ) {
f45f6658 714 Double_t baseline = calibr->GetBaseline(z);
aacedc3e 715 Bool_t on = kFALSE;
716 Int_t tstart = 0;
717 Int_t tstop = 0;
718 Int_t nTsteps = 0;
50d05d7b 719
aacedc3e 720 for( Int_t l=0; l<fMaxNofSamples; l++ ) {
721 Float_t fadc = (Float_t)fHitMap2->GetSignal( z, l );
722 if( fadc > baseline ) {
723 if( on == kFALSE && l<fMaxNofSamples-4 ) {
724 Float_t fadc1 = (Float_t)fHitMap2->GetSignal( z, l+1 );
725 if( fadc1 < fadc ) continue;
726 on = kTRUE;
727 nTsteps = 0;
728 tstart = l;
729 }
730 nTsteps++;
731 }
732 else { // end fadc > baseline
733 if( on == kTRUE ) {
734 if( nTsteps > 2 ) {
735 tstop = l;
736 // make smooth derivative
737 Float_t* dev = new Float_t[fMaxNofSamples+1];
738 memset( dev, 0, sizeof(Float_t)*(fMaxNofSamples+1) );
aacedc3e 739 for( Int_t i=tstart; i<tstop; i++ ) {
740 if( i > 2 && i < fMaxNofSamples-2 )
741 dev[i] = -0.2*fHitMap2->GetSignal( z,i-2 )
742 -0.1*fHitMap2->GetSignal( z,i-1 )
743 +0.1*fHitMap2->GetSignal( z,i+1 )
744 +0.2*fHitMap2->GetSignal( z,i+2 );
745 }
50d05d7b 746
aacedc3e 747 // add crosstalk contribution to neibourg anodes
748 for( Int_t i=tstart; i<tstop; i++ ) {
749 Int_t anode = z - 1;
750 Int_t i1 = (Int_t)((i-tstart)*.61+tstart+0.5); //
751 Float_t ctktmp = -dev[i1] * 0.25;
752 if( anode > 0 ) {
753 ctk[anode*fMaxNofSamples+i] += ctktmp;
754 }
755 anode = z + 1;
756 if( anode < fNofMaps ) {
757 ctk[anode*fMaxNofSamples+i] += ctktmp;
758 }
759 }
760 delete [] dev;
50d05d7b 761
aacedc3e 762 } // if( nTsteps > 2 )
763 on = kFALSE;
764 } // if( on == kTRUE )
765 } // else
766 }
3d2c9d72 767 }
50d05d7b 768
aacedc3e 769 for( Int_t a=0; a<fNofMaps; a++ )
770 for( Int_t t=0; t<fMaxNofSamples; t++ ) {
771 Float_t signal = fHitMap2->GetSignal(a,t)+ctk[a*fMaxNofSamples+t];
772 fHitMap2->SetHit( a, t, signal );
773 }
774
775 delete [] ctk;
50d05d7b 776}
f45f6658 777
8a33ae9e 778//______________________________________________________________________
779Int_t AliITSsimulationSDD::Convert10to8(Int_t signal) const {
aacedc3e 780 // To the 10 to 8 bit lossive compression.
781 // code from Davide C. and Albert W.
782
783 if (signal < 128) return signal;
784 if (signal < 256) return (128+((signal-128)>>1));
785 if (signal < 512) return (192+((signal-256)>>3));
786 if (signal < 1024) return (224+((signal-512)>>4));
787 return 0;
b0f5e3fc 788}
8a33ae9e 789//______________________________________________________________________
83ec5e27 790Int_t AliITSsimulationSDD::Convert8to10(Int_t signal) const {
791 // Decompression from 8 to 10 bit
792
793 if (signal < 0 || signal > 255) {
794 AliWarning(Form("Signal value %d out of range",signal));
795 return 0;
796 } // end if signal <0 || signal >255
797
798 if (signal < 128) return signal;
799 if (signal < 192) {
800 if (TMath::Odd(signal)) return (128+((signal-128)<<1));
801 else return (128+((signal-128)<<1)+1);
802 } // end if signal < 192
803 if (signal < 224) {
804 if (TMath::Odd(signal)) return (256+((signal-192)<<3)+3);
805 else return (256+((signal-192)<<3)+4);
806 } // end if signal < 224
807 if (TMath::Odd(signal)) return (512+((signal-224)<<4)+7);
808 return (512+((signal-224)<<4)+8);
809}
810//______________________________________________________________________
b0f5e3fc 811void AliITSsimulationSDD::Compress2D(){
20f3f947 812 // 2D zero-suppression algorithm as described in ALICE-INT-1999-28 V10
813 AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fModule);
20f3f947 814 for (Int_t iWing=0; iWing<2; iWing++) {
815 Int_t tL=res->GetZSLowThreshold(iWing);
816 Int_t tH=res->GetZSHighThreshold(iWing);
817 for (Int_t i=0; i<fNofMaps/2; i++) {
818 Int_t ian=i+iWing*fNofMaps/2;
819 if( !fAnodeFire[ian] ) continue;
820 for (Int_t itb=0; itb<fMaxNofSamples; itb++) {
8343dab6 821 Int_t nLow=0, nHigh=0;
20f3f947 822 Float_t cC=fHitMap2->GetSignal(ian,itb);
823 if(cC<=tL) continue;
8343dab6 824 nLow++; // cC is greater than tL
825 if(cC>tH) nHigh++;
20f3f947 826 // N
827 // Get "quintuple": WCE
828 // S
829 Float_t wW=0.;
830 if(itb>0) wW=fHitMap2->GetSignal(ian,itb-1);
8343dab6 831 if(wW>tL) nLow++;
832 if(wW>tH) nHigh++;
20f3f947 833 Float_t eE=0.;
834 if(itb<fMaxNofSamples-1) eE=fHitMap2->GetSignal(ian,itb+1);
8343dab6 835 if(eE>tL) nLow++;
836 if(eE>tH) nHigh++;
20f3f947 837 Float_t nN=0.;
838 if(i<(fNofMaps/2-1)) nN=fHitMap2->GetSignal(ian+1,itb);
8343dab6 839 if(nN>tL) nLow++;
840 if(nN>tH) nHigh++;
20f3f947 841 Float_t sS=0.;
842 if(i>0) sS=fHitMap2->GetSignal(ian-1,itb);
8343dab6 843 if(sS>tL) nLow++;
844 if(sS>tH) nHigh++;
845
ad98389f 846 if(nLow>=2 && nHigh>=1){
83ec5e27 847 Int_t signal=(Int_t)cC;
848 Int_t signalc = Convert10to8(signal);
849 Int_t signale = Convert8to10(signalc);
850 signalc-=tL; // subtract low threshold after 10 to 8 bit compression
e55354a4 851 if(signalc>=4) AddDigit(ian,itb,signalc,signale); // store C
20f3f947 852 }
853 }
854 }
855 }
b0f5e3fc 856}
8ba39da9 857
aacedc3e 858
8a33ae9e 859//______________________________________________________________________
b0f5e3fc 860void AliITSsimulationSDD::StoreAllDigits(){
fa4f0f62 861 // store digits for non-zero-suppressed data
862 for (Int_t ian=0; ian<fNofMaps; ian++) {
863 for (Int_t itb=0; itb<fMaxNofSamples; itb++){
864 Int_t signal=(Int_t)(fHitMap2->GetSignal(ian,itb));
865 Int_t signalc = Convert10to8(signal);
866 Int_t signale = Convert8to10(signalc);
867 AddDigit(ian,itb,signalc,signale);
868 }
869 }
b0f5e3fc 870}
8a33ae9e 871//______________________________________________________________________
ece86d9a 872void AliITSsimulationSDD::CreateHistograms(Int_t scale){
2c4e6a6a 873 // Creates histograms of maps for debugging
874 Int_t i;
875
876 fHis=new TObjArray(fNofMaps);
877 for (i=0;i<fNofMaps;i++) {
878 TString sddName;
879 sddName.Form("sdd_%d",i+1);
880 fHis->AddAt(new TH1F(sddName.Data(),"SDD maps",scale*fMaxNofSamples,
881 0.,(Float_t) scale*fMaxNofSamples), i);
882 } // end for i
b0f5e3fc 883}
8a33ae9e 884//______________________________________________________________________
ece86d9a 885void AliITSsimulationSDD::FillHistograms(){
aacedc3e 886 // fill 1D histograms from map
8a33ae9e 887
aacedc3e 888 if (!fHis) return;
8a33ae9e 889
aacedc3e 890 for( Int_t i=0; i<fNofMaps; i++) {
891 TH1F *hist =(TH1F *)fHis->UncheckedAt(i);
892 Int_t nsamples = hist->GetNbinsX();
893 for( Int_t j=0; j<nsamples; j++) {
894 Double_t signal=fHitMap2->GetSignal(i,j);
895 hist->Fill((Float_t)j,signal);
896 } // end for j
897 } // end for i
ece86d9a 898}
8a33ae9e 899//______________________________________________________________________
b0f5e3fc 900void AliITSsimulationSDD::ResetHistograms(){
aacedc3e 901 // Reset histograms for this detector
902 Int_t i;
8a33ae9e 903
aacedc3e 904 for (i=0;i<fNofMaps;i++ ) {
905 if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset();
906 } // end for i
b0f5e3fc 907}
8a33ae9e 908//______________________________________________________________________
b0f5e3fc 909TH1F *AliITSsimulationSDD::GetAnode(Int_t wing, Int_t anode) {
aacedc3e 910 // Fills a histogram from a give anode.
8a33ae9e 911
aacedc3e 912 if (!fHis) return 0;
8a33ae9e 913
aacedc3e 914 if(wing <=0 || wing > 2) {
915 Warning("GetAnode","Wrong wing number: %d",wing);
916 return NULL;
917 } // end if wing <=0 || wing >2
918 if(anode <=0 || anode > fNofMaps/2) {
919 Warning("GetAnode","Wrong anode number: %d",anode);
920 return NULL;
921 } // end if ampde <=0 || andoe > fNofMaps/2
8a33ae9e 922
aacedc3e 923 Int_t index = (wing-1)*fNofMaps/2 + anode-1;
924 return (TH1F*)(fHis->At(index));
b0f5e3fc 925}
8a33ae9e 926//______________________________________________________________________
b0f5e3fc 927void AliITSsimulationSDD::WriteToFile(TFile *hfile) {
aacedc3e 928 // Writes the histograms to a file
b0f5e3fc 929
aacedc3e 930 if (!fHis) return;
8a33ae9e 931
aacedc3e 932 hfile->cd();
933 Int_t i;
934 for(i=0; i<fNofMaps; i++) fHis->At(i)->Write(); //fAdcs[i]->Write();
935 return;
b0f5e3fc 936}
8a33ae9e 937//______________________________________________________________________
50d05d7b 938void AliITSsimulationSDD::WriteSDigits(){
aacedc3e 939 // Fills the Summable digits Tree
940 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
941
942 for( Int_t i=0; i<fNofMaps; i++ ) {
943 if( !fAnodeFire[i] ) continue;
f6b6d58e 944 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
aacedc3e 945 Double_t sig = fHitMap2->GetSignal( i, j );
946 if( sig > 0.2 ) {
947 Int_t jdx = j*fScaleSize;
948 Int_t index = fpList->GetHitIndex( i, j );
949 AliITSpListItem pItemTmp2( fModule, index, 0. );
950 // put the fScaleSize analog digits in only one
951 for( Int_t ik=0; ik<fScaleSize; ik++ ) {
952 AliITSpListItem *pItemTmp = fpList->GetpListItem(i,jdx+ik);
953 if( pItemTmp == 0 ) continue;
954 pItemTmp2.Add( pItemTmp );
955 }
956 pItemTmp2.AddSignalAfterElect( fModule, index, sig );
957 pItemTmp2.AddNoise(fModule,index,fHitNoiMap2->GetSignal(i,j));
958 aliITS->AddSumDigit( pItemTmp2 );
959 } // end if (sig > 0.2)
960 }
48058160 961 }
aacedc3e 962 return;
b0f5e3fc 963}
8a33ae9e 964//______________________________________________________________________
d2f55a22 965void AliITSsimulationSDD::PrintStatus() const {
aacedc3e 966 // Print SDD simulation Parameters
967
968 cout << "**************************************************" << endl;
969 cout << " Silicon Drift Detector Simulation Parameters " << endl;
970 cout << "**************************************************" << endl;
971 cout << "Flag for Perpendicular tracks: " << (Int_t) fFlag << endl;
aacedc3e 972 cout << "Flag to switch off electronics: " << (Int_t) fDoFFT << endl;
20f3f947 973 cout << "Number of Anodes used: " << fNofMaps << endl;
aacedc3e 974 cout << "Number of Time Samples: " << fMaxNofSamples << endl;
975 cout << "Scale size factor: " << fScaleSize << endl;
976 cout << "**************************************************" << endl;
44a312c3 977}