LCOV - code coverage report
Current view: top level - ITS/ITSsim - AliITSsimulationSDD.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 364 579 62.9 %
Date: 2016-06-14 17:26:59 Functions: 18 32 56.2 %

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

Generated by: LCOV version 1.11