1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include <Riostream.h>
30 #include "AliITSMapA2.h"
31 #include "AliITSdigitSPD.h"
32 #include "AliITSetfSDD.h"
33 #include "AliITSmodule.h"
34 #include "AliITShit.h"
35 #include "AliITSpList.h"
36 #include "AliITSCalibrationSDD.h"
37 #include "AliITSresponseSDD.h"
38 #include "AliITSsimulationSDD.h"
44 ClassImp(AliITSsimulationSDD)
45 ////////////////////////////////////////////////////////////////////////
47 // Written by Piergiorgio Cerello //
48 // November 23 1999 //
50 // AliITSsimulationSDD is the simulation of SDDs. //
51 ////////////////////////////////////////////////////////////////////////
53 //______________________________________________________________________
54 AliITSsimulationSDD::AliITSsimulationSDD():
68 fCrosstalkFlag(kFALSE),
73 // Default constructor
74 SetPerpendTracksFlag();
79 //______________________________________________________________________
80 AliITSsimulationSDD::AliITSsimulationSDD(AliITSDetTypeSim* dettyp):
81 AliITSsimulation(dettyp),
94 fCrosstalkFlag(kFALSE),
99 // Default Constructor
102 //______________________________________________________________________
103 void AliITSsimulationSDD::Init(){
104 // Standard Constructor
106 AliITSsegmentationSDD* seg = (AliITSsegmentationSDD*)GetSegmentationModel(1);
107 fScaleSize = ScaleFourier(seg);
108 SetPerpendTracksFlag();
112 AliITSSimuParam* simpar = fDetType->GetSimuParam();
113 fpList = new AliITSpList( seg->Npz(),
114 fScaleSize*seg->Npx() );
115 fHitSigMap2 = new AliITSMapA2(seg,fScaleSize,1);
116 fHitNoiMap2 = new AliITSMapA2(seg,fScaleSize,1);
117 fHitMap2 = fHitSigMap2;
119 fNofMaps = seg->Npz();
120 fMaxNofSamples = seg->Npx();
121 fAnodeFire = new Bool_t [fNofMaps];
123 Float_t sddWidth = seg->Dz();
124 Float_t anodePitch = seg->Dpz(0);
125 Double_t timeStep = (Double_t)seg->Dpx(0);
127 if(anodePitch*(fNofMaps/2) > sddWidth) {
128 AliWarning(Form("Too many anodes %d or too big pitch %f ",
129 fNofMaps/2,anodePitch));
133 fElectronics = new AliITSetfSDD(timeStep/fScaleSize,
134 simpar->GetSDDElectronics());
137 fITS = (AliITS*)gAlice->GetModule("ITS");
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];
144 //______________________________________________________________________
145 AliITSsimulationSDD::~AliITSsimulationSDD() {
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;
165 //______________________________________________________________________
166 void AliITSsimulationSDD::InitSimulationModule( Int_t module, Int_t event ) {
167 // create maps to build the lists of tracks for each summable digit
171 memset(fAnodeFire,0,sizeof(Bool_t)*fNofMaps);
173 //______________________________________________________________________
174 void AliITSsimulationSDD::ClearMaps() {
177 fHitSigMap2->ClearMap();
178 fHitNoiMap2->ClearMap();
180 //______________________________________________________________________
181 void AliITSsimulationSDD::FastFourierTransform(Double_t *real,
182 Double_t *imag,Int_t direction) {
183 // Do a Fast Fourier Transform
185 Int_t samples = fElectronics->GetSamples();
186 Int_t l = (Int_t) ((log((Float_t) samples)/log(2.))+0.5);
189 Int_t m2 = samples/m1;
191 for(i=1; i<=l; i++) {
192 for(j=0; j<samples; j += m1) {
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);
211 for(j=0; j<samples; j++) {
215 for(i1=1; i1<=l; i1++) {
218 p = p + p + j2 - j1 - j1;
221 Double_t xr = *(real+j);
222 Double_t xi = *(imag+j);
223 *(real+j) = *(real+p);
224 *(imag+j) = *(imag+p);
229 if(direction == -1) {
230 for(i=0; i<samples; i++) {
231 *(real+i) /= samples;
232 *(imag+i) /= samples;
234 } // end if direction == -1
238 //______________________________________________________________________
239 void AliITSsimulationSDD::SDigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
240 // digitize module using the "slow" detector simulator creating
243 TObjArray *fHits = mod->GetHits();
244 Int_t nhits = fHits->GetEntriesFast();
247 InitSimulationModule( md, ev );
248 HitsToAnalogDigits( mod ); // fills fHitMap2 which is = fHitSigmap2
249 ChargeToSignal( fModule,kFALSE,kTRUE ); // - Process signal adding gain without adding noise
250 fHitMap2 = fHitNoiMap2; // - Swap to noise map
251 ChargeToSignal( fModule,kTRUE,kFALSE ); // - Process only noise
252 fHitMap2 = fHitSigMap2; // - Return to signal map
256 //______________________________________________________________________
257 Bool_t AliITSsimulationSDD::AddSDigitsToModule(TClonesArray *pItemArray,
259 // Add Summable digits to module maps.
260 AliITSSimuParam* simpar = fDetType->GetSimuParam();
261 Int_t nItems = pItemArray->GetEntries();
262 Double_t maxadc = simpar->GetSDDMaxAdc();
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 );
275 if(pItem->GetSignal()>0.0 ) sig = kTRUE;
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
283 fpList->GetMapIndex( pItem->GetIndex(), ia, it );
284 fHitMap2->SetHit( ia, it, sigAE );
285 fAnodeFire[ia] = kTRUE;
289 //______________________________________________________________________
290 void AliITSsimulationSDD::FinishSDigitiseModule() {
291 // digitize module using the "slow" detector simulator from
292 // the sum of summable digits.
296 //______________________________________________________________________
297 void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
298 // create maps to build the lists of tracks for each digit
300 TObjArray *fHits = mod->GetHits();
301 Int_t nhits = fHits->GetEntriesFast();
303 InitSimulationModule( md, ev );
306 HitsToAnalogDigits( mod );
307 ChargeToSignal( fModule,kTRUE,kTRUE ); // process signal + noise
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 );
320 fpList->DeleteHit( i, j );
321 fpList->AddItemTo( 0, &pItemTmp2 );
327 //______________________________________________________________________
328 void AliITSsimulationSDD::FinishDigits() {
329 // introduce the electronics effects and do zero-suppression if required
331 if( fCrosstalkFlag ) ApplyCrosstalk(fModule);
333 AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fModule);
334 Bool_t isZeroSupp = res->GetZeroSupp();
335 if (isZeroSupp) Compress2D();
336 else StoreAllDigits();
338 //______________________________________________________________________
339 void AliITSsimulationSDD::HitsToAnalogDigits( AliITSmodule *mod ) {
340 // create maps to build the lists of tracks for each digit
341 AliITSsegmentationSDD* seg = (AliITSsegmentationSDD*)GetSegmentationModel(1);
342 AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fModule);
343 AliITSSimuParam* simpar = fDetType->GetSimuParam();
344 TObjArray *hits = mod->GetHits();
345 Int_t nhits = hits->GetEntriesFast();
347 // Int_t arg[6] = {0,0,0,0,0,0};
348 Int_t nofAnodes = fNofMaps/2;
349 Double_t sddLength = seg->Dx();
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();
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(); //
361 Float_t mapsmear = simpar->GetSDDCorrMapPrecision(); //
362 Float_t trigDelay = simpar->GetSDDTrigDelay(); // compensation for MC time zero
363 if(res->IsAMAt20MHz()) trigDelay+=12.5; // compensation for discretization step
365 Float_t timeZero=fDetType->GetResponseSDD()->GetTimeZero(fModule);
366 Float_t adcscale = fDetType->GetResponseSDD()->GetADCtokeV(fModule);
367 adcscale/=simpar->GetSDDkeVtoADC();
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
374 const Float_t kconv = 1.0e+6; // GeV->KeV
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.
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;
416 if(xloc>0) iWing=0; // left side, carlos channel 0
417 else iWing=1; // right side
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);
422 driftSpeed+= fDetType->GetResponseSDD()->GetDeltaVDrift(fModule,zAnode>255);
424 if(timeStep*fMaxNofSamples < sddLength/driftSpeed) {
425 AliWarning("Time Interval > Allowed Time Interval");
430 Form("fTrack = %d hit=%d module=%d This particle has passed without losing energy!",
431 itrack,ii,mod->GetIndex()));
433 // continue if the particle did not lose energy
434 // passing through detector
435 } // end if !depEnergy
438 AliITShit* h=(AliITShit*)hits->At(ii);
441 AliDebug(1,Form("TOF for hit %d on mod %d (particle %d)=%g",ii,fModule,h->Track(),tof));
444 Float_t corrx=0, corrz=0;
445 res->GetShiftsForSimulation(xL[2],xL[0],corrz,corrx,seg);
448 xL[0] += 0.0001*gRandom->Gaus( 0, mapsmear); //
449 xL[0] += 0.0001*gRandom->Gaus( 0, jitter ); //
451 pathInSDD = TMath::Sqrt(dxL[0]*dxL[0]+dxL[1]*dxL[1]+dxL[2]*dxL[2]);
453 if (fFlag && pathInSDD) { depEnergy *= (0.03/pathInSDD); }
454 drPath = TMath::Abs(10000.*(dxL[0]+2.*xL[0])*0.5);
455 drPath = sddLength-drPath;
457 AliInfo( // this should be fixed at geometry level
458 Form("negative drift path drPath=%e sddLength=%e dxL[0]=%e xL[0]=%e",
459 drPath,sddLength,dxL[0],xL[0]));
461 } // end if drPath < 0
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;
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;
480 zAnode = seg->GetAnodeFromLocal(avDrft,avAnode);
481 driftSpeed = res->GetDriftSpeedAtAnode(zAnode);
482 driftSpeed+= fDetType->GetResponseSDD()->GetDeltaVDrift(fModule,zAnode>255);
483 driftPath = TMath::Abs(10000.*avDrft);
484 driftPath = sddLength-driftPath;
486 AliDebug(1, // this should be fixed at geometry level
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]));
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;
496 drTime+=tof; // take into account Time Of Flight from production point
499 timeSample = (Int_t) (fScaleSize*drTime/timeStep + 1.001); // time bin in range 1-256 !!!
500 if(zAnode>nofAnodes) zAnode-=nofAnodes; // to have the anode number between 0. and 256.
501 iAnode = (Int_t) (1.001+zAnode); // iAnode in range 1-256 !!!!
503 // Peak amplitude in nanoAmpere
504 amplitude = fScaleSize*160.*depEnergy/
505 (timeStep*eVpairs*2.*acos(-1.));
506 chargeloss = 1.-cHloss*driftPath/1000.;
507 amplitude *= chargeloss;
508 amplitude *= adcscale;
509 width = 2.*nsigma/(nlookups-1);
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;
521 if(jamin <= 0) jamin = 1;
522 if(jamin > nofAnodes*nsplitAn){
523 AliDebug(1,Form("Energy deposition completely outside anode acceptance: anode min=%d",jamin));
526 jamax = (iAnode + anodeWindow + 2)*nsplitAn;
527 if(jamax > nofAnodes*nsplitAn) jamax = nofAnodes*nsplitAn;
529 AliDebug(1,Form("Energy deposition completely outside anode acceptance: anode max=%d",jamax));
532 jtmin = (Int_t)(timeSample-timeWindow-2)*nsplitTb+1;
533 if(jtmin <= 0) jtmin = 1;
534 if(jtmin > fScaleSize*fMaxNofSamples*nsplitTb){
535 AliDebug(1,Form("Energy deposition completely outside time acceptance: time sample min=%d tof=%f",jtmin,tof));
538 jtmax = (Int_t)(timeSample+timeWindow+2)*nsplitTb;
539 if(jtmax > fScaleSize*fMaxNofSamples*nsplitTb) jtmax = fScaleSize*fMaxNofSamples*nsplitTb;
541 AliDebug(1,Form("Energy deposition completely outside time acceptance: time sample max=%d tof=%f",jtmax,tof));
545 // Spread the charge in the anode-time window
546 for(ka=jamin; ka <=jamax; ka++) {
547 ia = (ka-1)/nsplitAn + 1;
549 if(ia > nofAnodes) ia = nofAnodes;
550 aExpo = (aStep*(ka-0.5)-aConst);
551 if(TMath::Abs(aExpo) > nsigma) anodeAmplitude = 0.;
553 Int_t theBin = (Int_t) ((aExpo+nsigma)/width+0.5);
554 anodeAmplitude = amplitude*simpar->GetGausLookUp(theBin);
556 // index starts from 0
557 index = iWing*nofAnodes+ia-1;
559 for(kt=jtmin; kt<=jtmax; kt++) {
560 it = (kt-1)/nsplitTb+1; // it starts from 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.;
567 Int_t theBin = (Int_t) ((tExpo+nsigma)/width+0.5);
568 timeAmplitude = anodeAmplitude*simpar->GetGausLookUp(theBin)*aStep*tStep;
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
585 //____________________________________________
586 void AliITSsimulationSDD::AddDigit( Int_t i, Int_t j, Int_t signalc, Int_t signale) {
588 Int_t size = AliITSdigit::GetNTracks();
591 Int_t * tracks = new Int_t[size];
592 Int_t * hits = new Int_t[size];
594 Float_t * charges = new Float_t[size];
600 AliITSpListItem *pItem = fpList->GetpListItem( i, j );
603 for( Int_t l=0; l<size; l++ ) {
609 Int_t idtrack = pItem->GetTrack( 0 );
610 if( idtrack >= 0 ) phys = pItem->GetSignal();
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 );
624 fITS->AddSimDigit( 1, phys, digits, tracks, hits, charges, signale );
629 //______________________________________________________________________
630 void 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
634 AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(mod);
640 AliITSSimuParam* simpar = fDetType->GetSimuParam();
641 Float_t maxadc = simpar->GetSDDMaxAdc();
642 Int_t nGroup=fScaleSize;
643 if(res->IsAMAt20MHz()){
647 for (i=0;i<fNofMaps;i++) {
648 if( !fAnodeFire[i] ) continue;
649 baseline = res->GetBaseline(i);
650 noise = res->GetNoise(i);
651 gain = res->GetChannelGain(i)/fDetType->GetAverageGainSDD();
652 if(res->IsBad()) gain=0.;
653 if( res->IsChipBad(res->GetChip(i)) )gain=0.;
654 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
655 fInZR[k] = fHitMap2->GetSignal(i,k);
656 if(bAddGain) fInZR[k]*=gain;
658 contrib = (baseline + noise*gRandom->Gaus());
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;
672 if (newcont >= maxadc) newcont = maxadc -1;
673 if(newcont >= baseline){
674 Warning("","newcont=%f>=baseline=%f",newcont,baseline);
677 fHitMap2->SetHit(i,k,newcont);
680 FastFourierTransform(&fInZR[0],&fInZI[0],1);
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;
687 FastFourierTransform(&fOutZR[0],&fOutZI[0],-1);
688 for(k=0; k<fMaxNofSamples; k++) {
689 Double_t newcont1 = 0.;
690 Double_t maxcont1 = 0.;
691 for(kk=0;kk<nGroup;kk++) {
692 newcont1 = fOutZR[fScaleSize*k+kk];
693 if(newcont1 > maxcont1) maxcont1 = newcont1;
696 if (newcont1 >= maxadc) newcont1 = maxadc -1;
697 fHitMap2->SetHit(i,k,newcont1);
700 } // end for i loop over anodes
704 //______________________________________________________________________
705 void AliITSsimulationSDD::ApplyCrosstalk(Int_t mod) {
706 // function add the crosstalk effect to signal
707 // temporal function, should be checked...!!!
709 // create and inizialice crosstalk map
710 Float_t* ctk = new Float_t[fNofMaps*fMaxNofSamples+1];
711 memset( ctk, 0, sizeof(Float_t)*(fNofMaps*fMaxNofSamples+1) );
712 AliITSCalibrationSDD* calibr = (AliITSCalibrationSDD*)GetCalibrationModel(mod);
713 for( Int_t z=0; z<fNofMaps; z++ ) {
714 Double_t baseline = calibr->GetBaseline(z);
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;
732 else { // end fadc > baseline
736 // make smooth derivative
737 Float_t* dev = new Float_t[fMaxNofSamples+1];
738 memset( dev, 0, sizeof(Float_t)*(fMaxNofSamples+1) );
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 );
747 // add crosstalk contribution to neibourg anodes
748 for( Int_t i=tstart; i<tstop; i++ ) {
750 Int_t i1 = (Int_t)((i-tstart)*.61+tstart+0.5); //
751 Float_t ctktmp = -dev[i1] * 0.25;
753 ctk[anode*fMaxNofSamples+i] += ctktmp;
756 if( anode < fNofMaps ) {
757 ctk[anode*fMaxNofSamples+i] += ctktmp;
762 } // if( nTsteps > 2 )
764 } // if( on == kTRUE )
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 );
778 //______________________________________________________________________
779 Int_t AliITSsimulationSDD::Convert10to8(Int_t signal) const {
780 // To the 10 to 8 bit lossive compression.
781 // code from Davide C. and Albert W.
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));
789 //______________________________________________________________________
790 Int_t AliITSsimulationSDD::Convert8to10(Int_t signal) const {
791 // Decompression from 8 to 10 bit
793 if (signal < 0 || signal > 255) {
794 AliWarning(Form("Signal value %d out of range",signal));
796 } // end if signal <0 || signal >255
798 if (signal < 128) return signal;
800 if (TMath::Odd(signal)) return (128+((signal-128)<<1));
801 else return (128+((signal-128)<<1)+1);
802 } // end if signal < 192
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);
810 //______________________________________________________________________
811 void AliITSsimulationSDD::Compress2D(){
812 // 2D zero-suppression algorithm as described in ALICE-INT-1999-28 V10
813 AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fModule);
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++) {
821 Int_t nLow=0, nHigh=0;
822 Float_t cC=fHitMap2->GetSignal(ian,itb);
824 nLow++; // cC is greater than tL
827 // Get "quintuple": WCE
830 if(itb>0) wW=fHitMap2->GetSignal(ian,itb-1);
834 if(itb<fMaxNofSamples-1) eE=fHitMap2->GetSignal(ian,itb+1);
838 if(i<(fNofMaps/2-1)) nN=fHitMap2->GetSignal(ian+1,itb);
842 if(i>0) sS=fHitMap2->GetSignal(ian-1,itb);
846 if(nLow>=2 && nHigh>=1){
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
851 if(signalc>=4) AddDigit(ian,itb,signalc,signale); // store C
859 //______________________________________________________________________
860 void AliITSsimulationSDD::StoreAllDigits(){
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);
871 //______________________________________________________________________
872 void AliITSsimulationSDD::CreateHistograms(Int_t scale){
873 // Creates histograms of maps for debugging
876 fHis=new TObjArray(fNofMaps);
877 for (i=0;i<fNofMaps;i++) {
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);
884 //______________________________________________________________________
885 void AliITSsimulationSDD::FillHistograms(){
886 // fill 1D histograms from map
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);
899 //______________________________________________________________________
900 void AliITSsimulationSDD::ResetHistograms(){
901 // Reset histograms for this detector
904 for (i=0;i<fNofMaps;i++ ) {
905 if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset();
908 //______________________________________________________________________
909 TH1F *AliITSsimulationSDD::GetAnode(Int_t wing, Int_t anode) {
910 // Fills a histogram from a give anode.
914 if(wing <=0 || wing > 2) {
915 Warning("GetAnode","Wrong wing number: %d",wing);
917 } // end if wing <=0 || wing >2
918 if(anode <=0 || anode > fNofMaps/2) {
919 Warning("GetAnode","Wrong anode number: %d",anode);
921 } // end if ampde <=0 || andoe > fNofMaps/2
923 Int_t index = (wing-1)*fNofMaps/2 + anode-1;
924 return (TH1F*)(fHis->At(index));
926 //______________________________________________________________________
927 void AliITSsimulationSDD::WriteToFile(TFile *hfile) {
928 // Writes the histograms to a file
934 for(i=0; i<fNofMaps; i++) fHis->At(i)->Write(); //fAdcs[i]->Write();
937 //______________________________________________________________________
938 void AliITSsimulationSDD::WriteSDigits(){
939 // Fills the Summable digits Tree
940 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
942 for( Int_t i=0; i<fNofMaps; i++ ) {
943 if( !fAnodeFire[i] ) continue;
944 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
945 Double_t sig = fHitMap2->GetSignal( i, j );
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 );
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)
964 //______________________________________________________________________
965 void AliITSsimulationSDD::PrintStatus() const {
966 // Print SDD simulation Parameters
968 cout << "**************************************************" << endl;
969 cout << " Silicon Drift Detector Simulation Parameters " << endl;
970 cout << "**************************************************" << endl;
971 cout << "Flag for Perpendicular tracks: " << (Int_t) fFlag << endl;
972 cout << "Flag to switch off electronics: " << (Int_t) fDoFFT << endl;
973 cout << "Number of Anodes used: " << fNofMaps << endl;
974 cout << "Number of Time Samples: " << fMaxNofSamples << endl;
975 cout << "Scale size factor: " << fScaleSize << endl;
976 cout << "**************************************************" << endl;