]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSsimulationSDD.cxx
Typo corrected
[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 **************************************************************************/
48058160 15/*
16 $Id$
17 $Log$
b9d0a01d 18 Revision 1.32.4.4 2002/10/14 13:14:08 hristov
19 Updating VirtualMC to v3-09-02
20
21 Revision 1.36 2002/09/11 10:32:41 hristov
22 Use new for arrays with variable size
23
5c5273c2 24 Revision 1.35 2002/09/09 17:23:28 nilsen
25 Minor changes in support of changes to AliITSdigitS?D class'.
26
ee86d557 27 Revision 1.34 2002/06/07 16:32:28 nilsen
28 Latest SDD changes to speed up the SDD simulation code.
29
43217ad9 30 Revision 1.33 2002/04/24 22:02:31 nilsen
31 New SDigits and Digits routines, and related changes, (including new
32 noise values).
33
48058160 34 */
b0f5e3fc 35
b0f5e3fc 36#include <iostream.h>
37#include <stdlib.h>
38#include <stdio.h>
1ca7869b 39#include <string.h>
40
94de3818 41#include <TSystem.h>
42#include <TROOT.h>
608f25d8 43#include <TStopwatch.h>
ece86d9a 44#include <TCanvas.h>
45#include <TF1.h>
46#include <TRandom.h>
1ca7869b 47#include <TH1.h>
48#include <TFile.h>
49#include <TVector.h>
50#include <TArrayI.h>
51#include <TArrayF.h>
ece86d9a 52
b0f5e3fc 53#include "AliRun.h"
e8189707 54#include "AliITS.h"
ece86d9a 55#include "AliITShit.h"
56#include "AliITSdigit.h"
57#include "AliITSmodule.h"
c7a4dac0 58#include "AliITSpList.h"
e8189707 59#include "AliITSMapA1.h"
60#include "AliITSMapA2.h"
e8189707 61#include "AliITSetfSDD.h"
62#include "AliITSRawData.h"
b0f5e3fc 63#include "AliITSHuffman.h"
50d05d7b 64#include "AliITSgeom.h"
ece86d9a 65#include "AliITSsegmentation.h"
66#include "AliITSresponse.h"
c7a4dac0 67#include "AliITSsegmentationSDD.h"
68#include "AliITSresponseSDD.h"
1ca7869b 69#include "AliITSsimulationSDD.h"
b0f5e3fc 70
b0f5e3fc 71ClassImp(AliITSsimulationSDD)
72////////////////////////////////////////////////////////////////////////
73// Version: 0
74// Written by Piergiorgio Cerello
75// November 23 1999
76//
77// AliITSsimulationSDD is the simulation of SDDs.
78 //
79//Begin_Html
80/*
81<img src="picts/ITS/AliITShit_Class_Diagram.gif">
82</pre>
83<br clear=left>
84<font size=+2 color=red>
85<p>This show the relasionships between the ITS hit class and the rest of Aliroot.
86</font>
87<pre>
88*/
89//End_Html
8a33ae9e 90//______________________________________________________________________
b0f5e3fc 91Int_t power(Int_t b, Int_t e) {
8a33ae9e 92 // compute b to the e power, where both b and e are Int_ts.
93 Int_t power = 1,i;
b0f5e3fc 94
8a33ae9e 95 for(i=0; i<e; i++) power *= b;
96 return power;
97}
98//______________________________________________________________________
b0f5e3fc 99void FastFourierTransform(AliITSetfSDD *alisddetf,Double_t *real,
100 Double_t *imag,Int_t direction) {
8a33ae9e 101 // Do a Fast Fourier Transform
8a33ae9e 102
103 Int_t samples = alisddetf->GetSamples();
104 Int_t l = (Int_t) ((log((Float_t) samples)/log(2.))+0.5);
105 Int_t m1 = samples;
106 Int_t m = samples/2;
107 Int_t m2 = samples/m1;
108 Int_t i,j,k;
109 for(i=1; i<=l; i++) {
50d05d7b 110 for(j=0; j<samples; j += m1) {
111 Int_t p = 0;
112 for(k=j; k<= j+m-1; k++) {
113 Double_t wsr = alisddetf->GetWeightReal(p);
114 Double_t wsi = alisddetf->GetWeightImag(p);
115 if(direction == -1) wsi = -wsi;
116 Double_t xr = *(real+k+m);
117 Double_t xi = *(imag+k+m);
118 *(real+k+m) = wsr*(*(real+k)-xr) - wsi*(*(imag+k)-xi);
119 *(imag+k+m) = wsr*(*(imag+k)-xi) + wsi*(*(real+k)-xr);
120 *(real+k) += xr;
121 *(imag+k) += xi;
122 p += m2;
123 } // end for k
124 } // end for j
125 m1 = m;
126 m /= 2;
127 m2 += m2;
8a33ae9e 128 } // end for i
b0f5e3fc 129
8a33ae9e 130 for(j=0; j<samples; j++) {
50d05d7b 131 Int_t j1 = j;
132 Int_t p = 0;
133 Int_t i1;
134 for(i1=1; i1<=l; i1++) {
135 Int_t j2 = j1;
136 j1 /= 2;
137 p = p + p + j2 - j1 - j1;
138 } // end for i1
139 if(p >= j) {
140 Double_t xr = *(real+j);
141 Double_t xi = *(imag+j);
142 *(real+j) = *(real+p);
143 *(imag+j) = *(imag+p);
144 *(real+p) = xr;
145 *(imag+p) = xi;
146 } // end if p>=j
8a33ae9e 147 } // end for j
148 if(direction == -1) {
50d05d7b 149 for(i=0; i<samples; i++) {
150 *(real+i) /= samples;
151 *(imag+i) /= samples;
152 } // end for i
8a33ae9e 153 } // end if direction == -1
50d05d7b 154 return;
b0f5e3fc 155}
8a33ae9e 156//______________________________________________________________________
b0f5e3fc 157AliITSsimulationSDD::AliITSsimulationSDD(){
8a33ae9e 158 // Default constructor
159
160 fResponse = 0;
161 fSegmentation = 0;
162 fHis = 0;
50d05d7b 163// fpList = 0;
8a33ae9e 164 fHitMap2 = 0;
48058160 165 fHitSigMap2 = 0;
166 fHitNoiMap2 = 0;
8a33ae9e 167 fElectronics = 0;
168 fStream = 0;
169 fInZR = 0;
170 fInZI = 0;
171 fOutZR = 0;
172 fOutZI = 0;
173 fNofMaps = 0;
174 fMaxNofSamples = 0;
175 fITS = 0;
8604b270 176 fTreeB = 0;
43217ad9 177 fAnodeFire = 0;
8a33ae9e 178 SetScaleFourier();
179 SetPerpendTracksFlag();
50d05d7b 180 SetCrosstalkFlag();
8a33ae9e 181 SetDoFFT();
182 SetCheckNoise();
b0f5e3fc 183}
8a33ae9e 184//______________________________________________________________________
185AliITSsimulationSDD::AliITSsimulationSDD(AliITSsimulationSDD &source){
186 // Copy constructor to satify Coding roules only.
187
188 if(this==&source) return;
c7a4dac0 189 Error("AliITSsimulationSSD","Not allowed to make a copy of "
50d05d7b 190 "AliITSsimulationSDD Using default creater instead");
8a33ae9e 191 AliITSsimulationSDD();
b0f5e3fc 192}
8a33ae9e 193//______________________________________________________________________
c7a4dac0 194AliITSsimulationSDD& AliITSsimulationSDD::operator=(AliITSsimulationSDD &src){
8a33ae9e 195 // Assignment operator to satify Coding roules only.
196
c7a4dac0 197 if(this==&src) return *this;
198 Error("AliITSsimulationSSD","Not allowed to make a = with "
50d05d7b 199 "AliITSsimulationSDD Using default creater instead");
8a33ae9e 200 return *this ;
b0f5e3fc 201}
8a33ae9e 202//______________________________________________________________________
c7a4dac0 203AliITSsimulationSDD::AliITSsimulationSDD(AliITSsegmentation *seg,
50d05d7b 204 AliITSresponse *resp){
c7a4dac0 205 // Standard Constructor
206
c7a4dac0 207 fResponse = 0;
208 fSegmentation = 0;
209 fHis = 0;
50d05d7b 210// fpList = 0;
c7a4dac0 211 fHitMap2 = 0;
48058160 212 fHitSigMap2 = 0;
213 fHitNoiMap2 = 0;
c7a4dac0 214 fElectronics = 0;
215 fStream = 0;
216 fInZR = 0;
217 fInZI = 0;
218 fOutZR = 0;
219 fOutZI = 0;
220 fNofMaps = 0;
221 fMaxNofSamples = 0;
222 fITS = 0;
223 fTreeB = 0;
224
225 Init((AliITSsegmentationSDD*)seg,(AliITSresponseSDD*)resp);
226}
227//______________________________________________________________________
228void AliITSsimulationSDD::Init(AliITSsegmentationSDD *seg,
50d05d7b 229 AliITSresponseSDD *resp){
38867c90 230 // Standard Constructor
ece86d9a 231
38867c90 232 fResponse = resp;
233 fSegmentation = seg;
234 SetScaleFourier();
235 SetPerpendTracksFlag();
50d05d7b 236 SetCrosstalkFlag();
38867c90 237 SetDoFFT();
238 SetCheckNoise();
b0f5e3fc 239
50d05d7b 240 fpList = new AliITSpList( fSegmentation->Npz(),
241 fScaleSize*fSegmentation->Npx() );
48058160 242 fHitSigMap2 = new AliITSMapA2(fSegmentation,fScaleSize,1);
243 fHitNoiMap2 = new AliITSMapA2(fSegmentation,fScaleSize,1);
244 fHitMap2 = fHitSigMap2;
b0f5e3fc 245
8a33ae9e 246 fNofMaps = fSegmentation->Npz();
247 fMaxNofSamples = fSegmentation->Npx();
43217ad9 248 fAnodeFire = new Bool_t [fNofMaps];
249
38867c90 250 Float_t sddLength = fSegmentation->Dx();
8a33ae9e 251 Float_t sddWidth = fSegmentation->Dz();
b0f5e3fc 252
8a33ae9e 253 Int_t dummy = 0;
38867c90 254 Float_t anodePitch = fSegmentation->Dpz(dummy);
8a33ae9e 255 Double_t timeStep = (Double_t)fSegmentation->Dpx(dummy);
256 Float_t driftSpeed = fResponse->DriftSpeed();
b0f5e3fc 257
38867c90 258 if(anodePitch*(fNofMaps/2) > sddWidth) {
50d05d7b 259 Warning("AliITSsimulationSDD",
260 "Too many anodes %d or too big pitch %f \n",
261 fNofMaps/2,anodePitch);
38867c90 262 } // end if
b0f5e3fc 263
38867c90 264 if(timeStep*fMaxNofSamples < sddLength/driftSpeed) {
50d05d7b 265 Error("AliITSsimulationSDD",
266 "Time Interval > Allowed Time Interval: exit\n");
267 return;
38867c90 268 } // end if
b0f5e3fc 269
38867c90 270 fElectronics = new AliITSetfSDD(timeStep/fScaleSize,
50d05d7b 271 fResponse->Electronics());
b0f5e3fc 272
38867c90 273 char opt1[20], opt2[20];
274 fResponse->ParamOptions(opt1,opt2);
8a33ae9e 275 fParam = opt2;
38867c90 276 char *same = strstr(opt1,"same");
277 if (same) {
50d05d7b 278 fNoise.Set(0);
279 fBaseline.Set(0);
38867c90 280 } else {
50d05d7b 281 fNoise.Set(fNofMaps);
282 fBaseline.Set(fNofMaps);
38867c90 283 } // end if
b0f5e3fc 284
38867c90 285 const char *kopt=fResponse->ZeroSuppOption();
b9d0a01d 286 if (strstr(fParam.Data(),"file") ) {
50d05d7b 287 fD.Set(fNofMaps);
288 fT1.Set(fNofMaps);
289 if (strstr(kopt,"2D")) {
290 fT2.Set(fNofMaps);
b0f5e3fc 291 fTol.Set(0);
292 Init2D(); // desactivate if param change module by module
50d05d7b 293 } else if(strstr(kopt,"1D")) {
b0f5e3fc 294 fT2.Set(2);
295 fTol.Set(2);
296 Init1D(); // desactivate if param change module by module
50d05d7b 297 } // end if strstr
38867c90 298 } else {
50d05d7b 299 fD.Set(2);
300 fTol.Set(2);
301 fT1.Set(2);
302 fT2.Set(2);
303 SetCompressParam();
38867c90 304 } // end if else strstr
b0f5e3fc 305
8a33ae9e 306 Bool_t write = fResponse->OutputOption();
38867c90 307 if(write && strstr(kopt,"2D")) MakeTreeB();
b0f5e3fc 308
38867c90 309 // call here if baseline does not change by module
310 // ReadBaseline();
b0f5e3fc 311
8a33ae9e 312 fITS = (AliITS*)gAlice->GetModule("ITS");
313 Int_t size = fNofMaps*fMaxNofSamples;
314 fStream = new AliITSInStream(size);
b0f5e3fc 315
38867c90 316 fInZR = new Double_t [fScaleSize*fMaxNofSamples];
317 fInZI = new Double_t [fScaleSize*fMaxNofSamples];
318 fOutZR = new Double_t [fScaleSize*fMaxNofSamples];
319 fOutZI = new Double_t [fScaleSize*fMaxNofSamples];
5d18fa90 320
b0f5e3fc 321}
8a33ae9e 322//______________________________________________________________________
b0f5e3fc 323AliITSsimulationSDD::~AliITSsimulationSDD() {
8a33ae9e 324 // destructor
325
50d05d7b 326// delete fpList;
48058160 327 delete fHitSigMap2;
328 delete fHitNoiMap2;
8a33ae9e 329 delete fStream;
330 delete fElectronics;
331
8a33ae9e 332 fITS = 0;
333
334 if (fHis) {
50d05d7b 335 fHis->Delete();
336 delete fHis;
8a33ae9e 337 } // end if fHis
338 if(fTreeB) delete fTreeB;
339 if(fInZR) delete [] fInZR;
50d05d7b 340 if(fInZI) delete [] fInZI;
8a33ae9e 341 if(fOutZR) delete [] fOutZR;
342 if(fOutZI) delete [] fOutZI;
43217ad9 343 if(fAnodeFire) delete [] fAnodeFire;
b0f5e3fc 344}
8a33ae9e 345//______________________________________________________________________
50d05d7b 346void AliITSsimulationSDD::InitSimulationModule( Int_t module, Int_t event ) {
c7a4dac0 347 // create maps to build the lists of tracks for each summable digit
50d05d7b 348 fModule = module;
349 fEvent = event;
350 ClearMaps();
43217ad9 351 memset(fAnodeFire,0,sizeof(Bool_t)*fNofMaps);
50d05d7b 352}
353//______________________________________________________________________
354void AliITSsimulationSDD::ClearMaps() {
355 // clear maps
356 fpList->ClearMap();
48058160 357 fHitSigMap2->ClearMap();
358 fHitNoiMap2->ClearMap();
50d05d7b 359}
360//______________________________________________________________________
361void AliITSsimulationSDD::SDigitiseModule( AliITSmodule *mod, Int_t md, Int_t ev){
362 // digitize module using the "slow" detector simulator creating
363 // summable digits.
c7a4dac0 364
365 TObjArray *fHits = mod->GetHits();
366 Int_t nhits = fHits->GetEntriesFast();
50d05d7b 367 if( !nhits ) return;
c7a4dac0 368
50d05d7b 369 InitSimulationModule( md, ev );
370 HitsToAnalogDigits( mod );
48058160 371 ChargeToSignal( kFALSE ); // - Process signal without add noise
372 fHitMap2 = fHitNoiMap2; // - Swap to noise map
373 ChargeToSignal( kTRUE ); // - Process only noise
374 fHitMap2 = fHitSigMap2; // - Return to signal map
50d05d7b 375 WriteSDigits();
376 ClearMaps();
377}
378//______________________________________________________________________
48058160 379Bool_t AliITSsimulationSDD::AddSDigitsToModule( TClonesArray *pItemArray, Int_t mask ) {
50d05d7b 380 // Add Summable digits to module maps.
48058160 381 Int_t nItems = pItemArray->GetEntries();
382 Double_t maxadc = fResponse->MaxAdc();
43217ad9 383 //Bool_t sig = kFALSE;
48058160 384
50d05d7b 385 // cout << "Adding "<< nItems <<" SDigits to module " << fModule << endl;
386 for( Int_t i=0; i<nItems; i++ ) {
387 AliITSpListItem * pItem = (AliITSpListItem *)(pItemArray->At( i ));
388 if( pItem->GetModule() != fModule ) {
389 Error( "AliITSsimulationSDD",
390 "Error reading, SDigits module %d != current module %d: exit\n",
391 pItem->GetModule(), fModule );
43217ad9 392 return kFALSE;
50d05d7b 393 } // end if
48058160 394
43217ad9 395 // if(pItem->GetSignal()>0.0 ) sig = kTRUE;
396
48058160 397 fpList->AddItemTo( mask, pItem ); // Add SignalAfterElect + noise
398 AliITSpListItem * pItem2 = fpList->GetpListItem( pItem->GetIndex() );
399 Double_t sigAE = pItem2->GetSignalAfterElect();
400 if( sigAE >= maxadc ) sigAE = maxadc-1; // avoid overflow signal
401 Int_t ia;
402 Int_t it;
403 fpList->GetMapIndex( pItem->GetIndex(), ia, it );
404 fHitMap2->SetHit( ia, it, sigAE );
43217ad9 405 fAnodeFire[ia] = kTRUE;
50d05d7b 406 }
43217ad9 407 return kTRUE;
48058160 408}
50d05d7b 409//______________________________________________________________________
410void AliITSsimulationSDD::FinishSDigitiseModule() {
411 // digitize module using the "slow" detector simulator from
412 // the sum of summable digits.
413 FinishDigits() ;
414 ClearMaps();
c7a4dac0 415}
416//______________________________________________________________________
b0f5e3fc 417void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
8a33ae9e 418 // create maps to build the lists of tracks for each digit
b0f5e3fc 419
420 TObjArray *fHits = mod->GetHits();
8a33ae9e 421 Int_t nhits = fHits->GetEntriesFast();
8a33ae9e 422
50d05d7b 423 InitSimulationModule( md, ev );
424
425 if( !nhits && fCheckNoise ) {
48058160 426 ChargeToSignal( kTRUE ); // process noise
ece86d9a 427 GetNoise();
50d05d7b 428 ClearMaps();
ece86d9a 429 return;
50d05d7b 430 } else
431 if( !nhits ) return;
48058160 432
50d05d7b 433 HitsToAnalogDigits( mod );
48058160 434 ChargeToSignal( kTRUE ); // process signal + noise
435
436 for( Int_t i=0; i<fNofMaps; i++ ) {
437 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
438 Int_t jdx = j*fScaleSize;
439 Int_t index = fpList->GetHitIndex( i, j );
440 AliITSpListItem pItemTmp2( fModule, index, 0. );
441 // put the fScaleSize analog digits in only one
442 for( Int_t ik=0; ik<fScaleSize; ik++ ) {
443 AliITSpListItem *pItemTmp = fpList->GetpListItem( i, jdx+ik );
444 if( pItemTmp == 0 ) continue;
445 pItemTmp2.Add( pItemTmp );
446 }
447 fpList->DeleteHit( i, j );
448 fpList->AddItemTo( 0, &pItemTmp2 );
449 }
450 }
451
50d05d7b 452 FinishDigits();
453 ClearMaps();
c7a4dac0 454}
455//______________________________________________________________________
50d05d7b 456void AliITSsimulationSDD::FinishDigits() {
c7a4dac0 457 // introduce the electronics effects and do zero-suppression if required
8a33ae9e 458
50d05d7b 459 ApplyDeadChannels();
460 if( fCrosstalkFlag ) ApplyCrosstalk();
461
462 const char *kopt = fResponse->ZeroSuppOption();
463 ZeroSuppression( kopt );
c7a4dac0 464}
465//______________________________________________________________________
50d05d7b 466void AliITSsimulationSDD::HitsToAnalogDigits( AliITSmodule *mod ) {
c7a4dac0 467 // create maps to build the lists of tracks for each digit
468
469 TObjArray *fHits = mod->GetHits();
470 Int_t nhits = fHits->GetEntriesFast();
50d05d7b 471// Int_t arg[6] = {0,0,0,0,0,0};
8a33ae9e 472 Int_t dummy = 0;
473 Int_t nofAnodes = fNofMaps/2;
474 Float_t sddLength = fSegmentation->Dx();
475 Float_t sddWidth = fSegmentation->Dz();
476 Float_t anodePitch = fSegmentation->Dpz(dummy);
477 Float_t timeStep = fSegmentation->Dpx(dummy);
478 Float_t driftSpeed = fResponse->DriftSpeed();
479 Float_t maxadc = fResponse->MaxAdc();
480 Float_t topValue = fResponse->DynamicRange();
481 Float_t cHloss = fResponse->ChargeLoss();
482 Float_t norm = maxadc/topValue;
483 Float_t dfCoeff, s1; fResponse->DiffCoeff(dfCoeff,s1); // Signal 2d Shape
484 Double_t eVpairs = 3.6; // electron pair energy eV.
485 Float_t nsigma = fResponse->NSigmaIntegration(); //
486 Int_t nlookups = fResponse->GausNLookUp(); //
48058160 487 Float_t jitter = ((AliITSresponseSDD*)fResponse)->JitterError(); //
44a312c3 488
b0f5e3fc 489 // Piergiorgio's part (apart for few variables which I made float
490 // when i thought that can be done
b0f5e3fc 491 // Fill detector maps with GEANT hits
492 // loop over hits in the module
493
8a33ae9e 494 const Float_t kconv = 1.0e+6; // GeV->KeV
495 Int_t itrack = 0;
496 Int_t hitDetector; // detector number (lay,lad,hitDetector)
497 Int_t iWing; // which detector wing/side.
498 Int_t detector; // 2*(detector-1)+iWing
499 Int_t ii,kk,ka,kt; // loop indexs
500 Int_t ia,it,index; // sub-pixel integration indexies
501 Int_t iAnode; // anode number.
502 Int_t timeSample; // time buckett.
503 Int_t anodeWindow; // anode direction charge integration width
504 Int_t timeWindow; // time direction charge integration width
505 Int_t jamin,jamax; // anode charge integration window
506 Int_t jtmin,jtmax; // time charge integration window
507 Int_t ndiv; // Anode window division factor.
508 Int_t nsplit; // the number of splits in anode and time windows==1.
509 Int_t nOfSplits; // number of times track length is split into
510 Float_t nOfSplitsF; // Floating point version of nOfSplits.
511 Float_t kkF; // Floating point version of loop index kk.
512 Float_t pathInSDD; // Track length in SDD.
513 Float_t drPath; // average position of track in detector. in microns
514 Float_t drTime; // Drift time
515 Float_t nmul; // drift time window multiplication factor.
516 Float_t avDrft; // x position of path length segment in cm.
517 Float_t avAnode; // Anode for path length segment in Anode number (float)
518 Float_t xAnode; // Floating point anode number.
519 Float_t driftPath; // avDrft in microns.
520 Float_t width; // width of signal at anodes.
521 Double_t depEnergy; // Energy deposited in this GEANT step.
522 Double_t xL[3],dxL[3]; // local hit coordinates and diff.
523 Double_t sigA; // sigma of signal at anode.
524 Double_t sigT; // sigma in time/drift direction for track segment
525 Double_t aStep,aConst; // sub-pixel size and offset anode
526 Double_t tStep,tConst; // sub-pixel size and offset time
527 Double_t amplitude; // signal amplitude for track segment in nanoAmpere
528 Double_t chargeloss; // charge loss for track segment.
529 Double_t anodeAmplitude; // signal amplitude in anode direction
530 Double_t aExpo; // exponent of Gaussian anode direction
531 Double_t timeAmplitude; // signal amplitude in time direction
532 Double_t tExpo; // exponent of Gaussian time direction
533// Double_t tof; // Time of flight in ns of this step.
44a312c3 534
b0f5e3fc 535 for(ii=0; ii<nhits; ii++) {
50d05d7b 536 if(!mod->LineSegmentL(ii,xL[0],dxL[0],xL[1],dxL[1],xL[2],dxL[2],
537 depEnergy,itrack)) continue;
48058160 538 xL[0] += 0.0001*gRandom->Gaus( 0, jitter ); //
50d05d7b 539 depEnergy *= kconv;
540 hitDetector = mod->GetDet();
541 //tof = 1.E+09*(mod->GetHit(ii)->GetTOF()); // tof in ns.
542 //if(tof>sddLength/driftSpeed) continue; // hit happed too late.
543
544 // scale path to simulate a perpendicular track
545 // continue if the particle did not lose energy
546 // passing through detector
547 if (!depEnergy) {
548 Warning("HitsToAnalogDigits",
549 "fTrack = %d hit=%d module=%d This particle has"
550 " passed without losing energy!",
551 itrack,ii,mod->GetIndex());
552 continue;
553 } // end if !depEnergy
554
555 pathInSDD = TMath::Sqrt(dxL[0]*dxL[0]+dxL[1]*dxL[1]+dxL[2]*dxL[2]);
556
557 if (fFlag && pathInSDD) { depEnergy *= (0.03/pathInSDD); }
558 drPath = 10000.*(dxL[0]+2.*xL[0])*0.5;
559 if(drPath < 0) drPath = -drPath;
560 drPath = sddLength-drPath;
561 if(drPath < 0) {
562 Warning("HitsToAnalogDigits",
563 "negative drift path drPath=%e sddLength=%e dxL[0]=%e "
564 "xL[0]=%e",
565 drPath,sddLength,dxL[0],xL[0]);
566 continue;
567 } // end if drPath < 0
568
569 // Compute number of segments to brake step path into
570 drTime = drPath/driftSpeed; // Drift Time
571 sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);// Sigma along the anodes
572 // calcuate the number of time the path length should be split into.
573 nOfSplits = (Int_t) (1. + 10000.*pathInSDD/sigA);
574 if(fFlag) nOfSplits = 1;
575
576 // loop over path segments, init. some variables.
577 depEnergy /= nOfSplits;
578 nOfSplitsF = (Float_t) nOfSplits;
579 for(kk=0;kk<nOfSplits;kk++) { // loop over path segments
580 kkF = (Float_t) kk + 0.5;
581 avDrft = xL[0]+dxL[0]*kkF/nOfSplitsF;
582 avAnode = xL[2]+dxL[2]*kkF/nOfSplitsF;
583 driftPath = 10000.*avDrft;
584
585 iWing = 2; // Assume wing is 2
586 if(driftPath < 0) { // if wing is not 2 it is 1.
587 iWing = 1;
588 driftPath = -driftPath;
589 } // end if driftPath < 0
590 driftPath = sddLength-driftPath;
591 detector = 2*(hitDetector-1) + iWing;
592 if(driftPath < 0) {
593 Warning("HitsToAnalogDigits","negative drift path "
594 "driftPath=%e sddLength=%e avDrft=%e dxL[0]=%e "
595 "xL[0]=%e",driftPath,sddLength,avDrft,dxL[0],xL[0]);
596 continue;
597 } // end if driftPath < 0
598
599 // Drift Time
600 drTime = driftPath/driftSpeed; // drift time for segment.
601 timeSample = (Int_t) (fScaleSize*drTime/timeStep + 1);
602 // compute time Sample including tof information. The tof only
603 // effects the time of the signal is recoreded and not the
604 // the defusion.
605 // timeSample = (Int_t) (fScaleSize*(drTime+tof)/timeStep + 1);
606 if(timeSample > fScaleSize*fMaxNofSamples) {
607 Warning("HitsToAnalogDigits","Wrong Time Sample: %e",
608 timeSample);
609 continue;
610 } // end if timeSample > fScaleSize*fMaxNoofSamples
611
612 // Anode
613 xAnode = 10000.*(avAnode)/anodePitch + nofAnodes/2; // +1?
614 if(xAnode*anodePitch > sddWidth || xAnode*anodePitch < 0.)
615 Warning("HitsToAnalogDigits",
616 "Exceedubg sddWidth=%e Z = %e",
617 sddWidth,xAnode*anodePitch);
618 iAnode = (Int_t) (1.+xAnode); // xAnode?
619 if(iAnode < 1 || iAnode > nofAnodes) {
620 Warning("HitToAnalogDigits","Wrong iAnode: 1<%d>%d",
621 iAnode,nofAnodes);
622 continue;
623 } // end if iAnode < 1 || iAnode > nofAnodes
624
625 // store straight away the particle position in the array
626 // of particles and take idhit=ii only when part is entering (this
627 // requires FillModules() in the macro for analysis) :
b0f5e3fc 628
50d05d7b 629 // Sigma along the anodes for track segment.
630 sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);
631 sigT = sigA/driftSpeed;
632 // Peak amplitude in nanoAmpere
633 amplitude = fScaleSize*160.*depEnergy/
634 (timeStep*eVpairs*2.*acos(-1.)*sigT*sigA);
635 amplitude *= timeStep/25.; // WARNING!!!!! Amplitude scaling to
636 // account for clock variations
8a33ae9e 637 // (reference value: 40 MHz)
50d05d7b 638 chargeloss = 1.-cHloss*driftPath/1000;
639 amplitude *= chargeloss;
640 width = 2.*nsigma/(nlookups-1);
641 // Spread the charge
642 // Pixel index
643 ndiv = 2;
644 nmul = 3.;
645 if(drTime > 1200.) {
646 ndiv = 4;
647 nmul = 1.5;
648 } // end if drTime > 1200.
649 // Sub-pixel index
650 nsplit = 4; // hard-wired //nsplit=4;nsplit = (nsplit+1)/2*2;
651 // Sub-pixel size see computation of aExpo and tExpo.
652 aStep = anodePitch/(nsplit*fScaleSize*sigA);
653 aConst = xAnode*anodePitch/sigA;
654 tStep = timeStep/(nsplit*fScaleSize*sigT);
655 tConst = drTime/sigT;
656 // Define SDD window corresponding to the hit
657 anodeWindow = (Int_t)(fScaleSize*nsigma*sigA/anodePitch+1);
658 timeWindow = (Int_t) (fScaleSize*nsigma*sigT/timeStep+1.);
659 jamin = (iAnode - anodeWindow/ndiv - 1)*fScaleSize*nsplit +1;
660 jamax = (iAnode + anodeWindow/ndiv)*fScaleSize*nsplit;
661 if(jamin <= 0) jamin = 1;
662 if(jamax > fScaleSize*nofAnodes*nsplit)
663 jamax = fScaleSize*nofAnodes*nsplit;
664 // jtmin and jtmax are Hard-wired
665 jtmin = (Int_t)(timeSample-timeWindow*nmul-1)*nsplit+1;
666 jtmax = (Int_t)(timeSample+timeWindow*nmul)*nsplit;
667 if(jtmin <= 0) jtmin = 1;
668 if(jtmax > fScaleSize*fMaxNofSamples*nsplit)
669 jtmax = fScaleSize*fMaxNofSamples*nsplit;
670 // Spread the charge in the anode-time window
671 for(ka=jamin; ka <=jamax; ka++) {
672 ia = (ka-1)/(fScaleSize*nsplit) + 1;
673 if(ia <= 0) {
674 Warning("HitsToAnalogDigits","ia < 1: ");
675 continue;
676 } // end if
677 if(ia > nofAnodes) ia = nofAnodes;
678 aExpo = (aStep*(ka-0.5)-aConst);
679 if(TMath::Abs(aExpo) > nsigma) anodeAmplitude = 0.;
680 else {
681 dummy = (Int_t) ((aExpo+nsigma)/width);
682 anodeAmplitude = amplitude*fResponse->GausLookUp(dummy);
683 } // end if TMath::Abs(aEspo) > nsigma
684 // index starts from 0
685 index = ((detector+1)%2)*nofAnodes+ia-1;
686 if(anodeAmplitude) for(kt=jtmin; kt<=jtmax; kt++) {
687 it = (kt-1)/nsplit+1; // it starts from 1
688 if(it<=0){
689 Warning("HitsToAnalogDigits","it < 1:");
690 continue;
691 } // end if
692 if(it>fScaleSize*fMaxNofSamples)
693 it = fScaleSize*fMaxNofSamples;
694 tExpo = (tStep*(kt-0.5)-tConst);
695 if(TMath::Abs(tExpo) > nsigma) timeAmplitude = 0.;
696 else {
697 dummy = (Int_t) ((tExpo+nsigma)/width);
698 timeAmplitude = anodeAmplitude*
699 fResponse->GausLookUp(dummy);
700 } // end if TMath::Abs(tExpo) > nsigma
701 // build the list of Sdigits for this module
702// arg[0] = index;
703// arg[1] = it;
704// arg[2] = itrack; // track number
705// arg[3] = ii-1; // hit number.
706 timeAmplitude *= norm;
707 timeAmplitude *= 10;
708// ListOfFiredCells(arg,timeAmplitude,alst,padr);
48058160 709 Double_t charge = timeAmplitude;
710 charge += fHitMap2->GetSignal(index,it-1);
711 fHitMap2->SetHit(index, it-1, charge);
50d05d7b 712 fpList->AddSignal(index,it-1,itrack,ii-1,
713 mod->GetIndex(),timeAmplitude);
43217ad9 714 fAnodeFire[index] = kTRUE;
50d05d7b 715 } // end if anodeAmplitude and loop over time in window
716 } // loop over anodes in window
717 } // end loop over "sub-hits"
44a312c3 718 } // end loop over hits
b0f5e3fc 719}
50d05d7b 720
721/*
8a33ae9e 722//______________________________________________________________________
b0f5e3fc 723void AliITSsimulationSDD::ListOfFiredCells(Int_t *arg,Double_t timeAmplitude,
8a33ae9e 724 TObjArray *alist,TClonesArray *padr){
725 // Returns the list of "fired" cells.
726
727 Int_t index = arg[0];
728 Int_t ik = arg[1];
729 Int_t idtrack = arg[2];
730 Int_t idhit = arg[3];
731 Int_t counter = arg[4];
732 Int_t countadr = arg[5];
733 Double_t charge = timeAmplitude;
734 charge += fHitMap2->GetSignal(index,ik-1);
735 fHitMap2->SetHit(index, ik-1, charge);
736
737 Int_t digits[3];
738 Int_t it = (Int_t)((ik-1)/fScaleSize);
739 digits[0] = index;
740 digits[1] = it;
741 digits[2] = (Int_t)timeAmplitude;
742 Float_t phys;
743 if (idtrack >= 0) phys = (Float_t)timeAmplitude;
744 else phys = 0;
745
746 Double_t cellcharge = 0.;
747 AliITSTransientDigit* pdigit;
748 // build the list of fired cells and update the info
749 if (!fHitMap1->TestHit(index, it)) {
50d05d7b 750 new((*padr)[countadr++]) TVector(3);
751 TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
752 trinfo(0) = (Float_t)idtrack;
753 trinfo(1) = (Float_t)idhit;
754 trinfo(2) = (Float_t)timeAmplitude;
755
756 alist->AddAtAndExpand(new AliITSTransientDigit(phys,digits),counter);
757 fHitMap1->SetHit(index, it, counter);
758 counter++;
759 pdigit=(AliITSTransientDigit*)alist->At(alist->GetLast());
760 // list of tracks
761 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
762 trlist->Add(&trinfo);
8a33ae9e 763 } else {
50d05d7b 764 pdigit = (AliITSTransientDigit*) fHitMap1->GetHit(index, it);
765 for(Int_t kk=0;kk<fScaleSize;kk++) {
766 cellcharge += fHitMap2->GetSignal(index,fScaleSize*it+kk);
767 } // end for kk
768 // update charge
769 (*pdigit).fSignal = (Int_t)cellcharge;
770 (*pdigit).fPhysics += phys;
771 // update list of tracks
772 TObjArray* trlist = (TObjArray*)pdigit->TrackList();
773 Int_t lastentry = trlist->GetLast();
774 TVector *ptrkp = (TVector*)trlist->At(lastentry);
775 TVector &trinfo = *ptrkp;
776 Int_t lasttrack = Int_t(trinfo(0));
777 Float_t lastcharge=(trinfo(2));
778 if (lasttrack==idtrack ) {
779 lastcharge += (Float_t)timeAmplitude;
780 trlist->RemoveAt(lastentry);
781 trinfo(0) = lasttrack;
782 trinfo(1) = idhit;
783 trinfo(2) = lastcharge;
784 trlist->AddAt(&trinfo,lastentry);
785 } else {
786 new((*padr)[countadr++]) TVector(3);
787 TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
788 trinfo(0) = (Float_t)idtrack;
789 trinfo(1) = (Float_t)idhit;
790 trinfo(2) = (Float_t)timeAmplitude;
791 trlist->Add(&trinfo);
792 } // end if lasttrack==idtrack
b0f5e3fc 793
794#ifdef print
50d05d7b 795 // check the track list - debugging
796 Int_t trk[20], htrk[20];
797 Float_t chtrk[20];
798 Int_t nptracks = trlist->GetEntriesFast();
799 if (nptracks > 2) {
800 Int_t tr;
801 for (tr=0;tr<nptracks;tr++) {
802 TVector *pptrkp = (TVector*)trlist->At(tr);
803 TVector &pptrk = *pptrkp;
804 trk[tr] = Int_t(pptrk(0));
805 htrk[tr] = Int_t(pptrk(1));
806 chtrk[tr] = (pptrk(2));
807 cout << "nptracks "<<nptracks << endl;
808 } // end for tr
809 } // end if nptracks
b0f5e3fc 810#endif
8a33ae9e 811 } // end if pdigit
b0f5e3fc 812
8a33ae9e 813 // update counter and countadr for next call.
814 arg[4] = counter;
815 arg[5] = countadr;
b0f5e3fc 816}
50d05d7b 817*/
818
b0f5e3fc 819//____________________________________________
50d05d7b 820void AliITSsimulationSDD::AddDigit( Int_t i, Int_t j, Int_t signal ) {
821 // Adds a Digit.
ee86d557 822 Int_t size = AliITSdigitSPD::GetNTracks();
5c5273c2 823 Int_t digits[3];
824 Int_t * tracks = new Int_t[size];
825 Int_t * hits = new Int_t[size];
826 Float_t phys;
827 Float_t * charges = new Float_t[size];
50d05d7b 828
829 if( fResponse->Do10to8() ) signal = Convert8to10( signal );
830 digits[0] = i;
831 digits[1] = j;
832 digits[2] = signal;
833
48058160 834 AliITSpListItem *pItem = fpList->GetpListItem( i, j );
835 if( pItem == 0 ) {
836 phys = 0.0;
ee86d557 837 for( Int_t l=0; l<size; l++ ) {
48058160 838 tracks[l] = 0;
839 hits[l] = 0;
840 charges[l] = 0.0;
841 }
842 } else {
843 Int_t idtrack = pItem->GetTrack( 0 );
844 if( idtrack >= 0 ) phys = pItem->GetSignal();
845 else phys = 0.0;
846
ee86d557 847 for( Int_t l=0; l<size; l++ ) if(l<pItem->GetMaxKept()) {
48058160 848 tracks[l] = pItem->GetTrack( l );
849 hits[l] = pItem->GetHit( l );
850 charges[l] = pItem->GetSignal( l );
ee86d557 851 }else{
852 tracks[l] = -3;
853 hits[l] = -1;
854 charges[l] = 0.0;
855 }// end for if
50d05d7b 856 }
b0f5e3fc 857
50d05d7b 858 fITS->AddSimDigit( 1, phys, digits, tracks, hits, charges );
5c5273c2 859 delete [] tracks;
860 delete [] hits;
861 delete [] charges;
50d05d7b 862}
863
864/*
865//____________________________________________
b0f5e3fc 866void AliITSsimulationSDD::AddDigit(Int_t i, Int_t j, Int_t signal){
8a33ae9e 867 // Adds a Digit.
b0f5e3fc 868 // tag with -1 signals coming from background tracks
869 // tag with -2 signals coming from pure electronic noise
870
e8189707 871 Int_t digits[3], tracks[3], hits[3];
b0f5e3fc 872 Float_t phys, charges[3];
873
e8189707 874 Int_t trk[20], htrk[20];
b0f5e3fc 875 Float_t chtrk[20];
876
ece86d9a 877 Bool_t do10to8=fResponse->Do10to8();
878
879 if(do10to8) signal=Convert8to10(signal);
b0f5e3fc 880 AliITSTransientDigit *obj = (AliITSTransientDigit*)fHitMap1->GetHit(i,j);
8a33ae9e 881 digits[0] = i;
882 digits[1] = j;
883 digits[2] = signal;
b0f5e3fc 884 if (!obj) {
885 phys=0;
886 Int_t k;
e8189707 887 for (k=0;k<3;k++) {
50d05d7b 888 tracks[k]=-2;
889 charges[k]=0;
890 hits[k]=-1;
891 } // end for k
e8189707 892 fITS->AddSimDigit(1,phys,digits,tracks,hits,charges);
b0f5e3fc 893 } else {
50d05d7b 894 phys=obj->fPhysics;
895 TObjArray* trlist=(TObjArray*)obj->TrackList();
896 Int_t nptracks=trlist->GetEntriesFast();
897 if (nptracks > 20) {
898 Warning("AddDigit","nptracks=%d > 20 nptracks set to 20",nptracks);
899 nptracks=20;
900 } // end if nptracks > 20
901 Int_t tr;
902 for (tr=0;tr<nptracks;tr++) {
903 TVector &pp =*((TVector*)trlist->At(tr));
904 trk[tr]=Int_t(pp(0));
905 htrk[tr]=Int_t(pp(1));
906 chtrk[tr]=(pp(2));
907 } // end for tr
908 if (nptracks > 1) {
909 SortTracks(trk,chtrk,htrk,nptracks);
910 } // end if nptracks > 1
911 Int_t i;
912 if (nptracks < 3 ) {
913 for (i=0; i<nptracks; i++) {
914 tracks[i]=trk[i];
915 charges[i]=chtrk[i];
916 hits[i]=htrk[i];
917 } // end for i
918 for (i=nptracks; i<3; i++) {
919 tracks[i]=-3;
920 hits[i]=-1;
921 charges[i]=0;
922 } // end for i
923 } else {
924 for (i=0; i<3; i++) {
925 tracks[i]=trk[i];
926 charges[i]=chtrk[i];
927 hits[i]=htrk[i];
928 } // end for i
929 } // end if/else nptracks < 3
930
931 fITS->AddSimDigit(1,phys,digits,tracks,hits,charges);
b0f5e3fc 932
8a33ae9e 933 } // end if/else !obj
b0f5e3fc 934}
50d05d7b 935
936
8a33ae9e 937//______________________________________________________________________
938void AliITSsimulationSDD::SortTracks(Int_t *tracks,Float_t *charges,
50d05d7b 939 Int_t *hits,Int_t ntr){
8a33ae9e 940 // Sort the list of tracks contributing to a given digit
941 // Only the 3 most significant tracks are acctually sorted
942 // Loop over signals, only 3 times
943
944 Float_t qmax;
945 Int_t jmax;
946 Int_t idx[3] = {-3,-3,-3};
947 Float_t jch[3] = {-3,-3,-3};
948 Int_t jtr[3] = {-3,-3,-3};
949 Int_t jhit[3] = {-3,-3,-3};
950 Int_t i,j,imax;
951
952 if (ntr<3) imax = ntr;
953 else imax = 3;
954 for(i=0;i<imax;i++){
50d05d7b 955 qmax = 0;
956 jmax = 0;
957 for(j=0;j<ntr;j++){
958 if((i == 1 && j == idx[i-1] )
959 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
960 if(charges[j] > qmax) {
961 qmax = charges[j];
962 jmax=j;
963 } // end if charges[j]>qmax
964 } // end for j
965 if(qmax > 0) {
966 idx[i] = jmax;
967 jch[i] = charges[jmax];
968 jtr[i] = tracks[jmax];
969 jhit[i] = hits[jmax];
970 } // end if qmax > 0
8a33ae9e 971 } // end for i
972
973 for(i=0;i<3;i++){
50d05d7b 974 if (jtr[i] == -3) {
975 charges[i] = 0;
976 tracks[i] = -3;
977 hits[i] = -1;
978 } else {
979 charges[i] = jch[i];
980 tracks[i] = jtr[i];
981 hits[i] = jhit[i];
982 } // end if jtr[i] == -3
8a33ae9e 983 } // end for i
b0f5e3fc 984}
50d05d7b 985*/
8a33ae9e 986//______________________________________________________________________
48058160 987void AliITSsimulationSDD::ChargeToSignal(Bool_t bAddNoise) {
8a33ae9e 988 // add baseline, noise, electronics and ADC saturation effects
b0f5e3fc 989
8a33ae9e 990 char opt1[20], opt2[20];
991 fResponse->ParamOptions(opt1,opt2);
992 char *read = strstr(opt1,"file");
993 Float_t baseline, noise;
994
995 if (read) {
50d05d7b 996 static Bool_t readfile=kTRUE;
997 //read baseline and noise from file
998 if (readfile) ReadBaseline();
999 readfile=kFALSE;
8a33ae9e 1000 } else fResponse->GetNoiseParam(noise,baseline);
1001
1002 Float_t contrib=0;
1003 Int_t i,k,kk;
1004 Float_t maxadc = fResponse->MaxAdc();
1005 if(!fDoFFT) {
50d05d7b 1006 for (i=0;i<fNofMaps;i++) {
43217ad9 1007 if( !fAnodeFire[i] ) continue;
50d05d7b 1008 if (read && i<fNofMaps) GetAnodeBaseline(i,baseline,noise);
1009 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
1010 fInZR[k] = fHitMap2->GetSignal(i,k);
48058160 1011 if( bAddNoise ) {
1012 contrib = (baseline + noise*gRandom->Gaus());
1013 fInZR[k] += contrib;
1014 }
50d05d7b 1015 } // end for k
1016 for(k=0; k<fMaxNofSamples; k++) {
1017 Double_t newcont = 0.;
1018 Double_t maxcont = 0.;
1019 for(kk=0;kk<fScaleSize;kk++) {
1020 newcont = fInZR[fScaleSize*k+kk];
1021 if(newcont > maxcont) maxcont = newcont;
1022 } // end for kk
1023 newcont = maxcont;
1024 if (newcont >= maxadc) newcont = maxadc -1;
1025 if(newcont >= baseline){
1026 Warning("","newcont=%d>=baseline=%d",newcont,baseline);
1027 } // end if
1028 // back to analog: ?
1029 fHitMap2->SetHit(i,k,newcont);
1030 } // end for k
1031 } // end for i loop over anodes
1032 return;
8a33ae9e 1033 } // end if DoFFT
ece86d9a 1034
ece86d9a 1035 for (i=0;i<fNofMaps;i++) {
43217ad9 1036 if( !fAnodeFire[i] ) continue;
50d05d7b 1037 if (read && i<fNofMaps) GetAnodeBaseline(i,baseline,noise);
1038 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
1039 fInZR[k] = fHitMap2->GetSignal(i,k);
48058160 1040 if( bAddNoise ) {
1041 contrib = (baseline + noise*gRandom->Gaus());
1042 fInZR[k] += contrib;
1043 }
50d05d7b 1044 fInZI[k] = 0.;
1045 } // end for k
1046 FastFourierTransform(fElectronics,&fInZR[0],&fInZI[0],1);
1047 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
1048 Double_t rw = fElectronics->GetTraFunReal(k);
1049 Double_t iw = fElectronics->GetTraFunImag(k);
1050 fOutZR[k] = fInZR[k]*rw - fInZI[k]*iw;
1051 fOutZI[k] = fInZR[k]*iw + fInZI[k]*rw;
1052 } // end for k
1053 FastFourierTransform(fElectronics,&fOutZR[0],&fOutZI[0],-1);
1054 for(k=0; k<fMaxNofSamples; k++) {
1055 Double_t newcont1 = 0.;
1056 Double_t maxcont1 = 0.;
1057 for(kk=0;kk<fScaleSize;kk++) {
1058 newcont1 = fOutZR[fScaleSize*k+kk];
1059 if(newcont1 > maxcont1) maxcont1 = newcont1;
1060 } // end for kk
1061 newcont1 = maxcont1;
1062 if (newcont1 >= maxadc) newcont1 = maxadc -1;
1063 fHitMap2->SetHit(i,k,newcont1);
1064 } // end for k
8a33ae9e 1065 } // end for i loop over anodes
ece86d9a 1066 return;
b0f5e3fc 1067}
50d05d7b 1068//____________________________________________________________________
1069void AliITSsimulationSDD::ApplyDeadChannels() {
1070 // Set dead channel signal to zero
1071 AliITSresponseSDD * response = (AliITSresponseSDD *)fResponse;
1072
1073 // nothing to do
1074 if( response->GetDeadModules() == 0 &&
1075 response->GetDeadChips() == 0 &&
1076 response->GetDeadChannels() == 0 )
1077 return;
1078
1079 static AliITS *iTS = (AliITS*)gAlice->GetModule( "ITS" );
1080
1081 Int_t fMaxNofSamples = fSegmentation->Npx();
1082 AliITSgeom *geom = iTS->GetITSgeom();
1083 Int_t firstSDDMod = geom->GetStartDet( 1 );
1084 // loop over wings
1085 for( Int_t j=0; j<2; j++ ) {
1086 Int_t mod = (fModule-firstSDDMod)*2 + j;
1087 for( Int_t u=0; u<response->Chips(); u++ )
1088 for( Int_t v=0; v<response->Channels(); v++ ) {
1089 Float_t Gain = response->Gain( mod, u, v );
1090 for( Int_t k=0; k<fMaxNofSamples; k++ ) {
1091 Int_t i = j*response->Chips()*response->Channels() +
1092 u*response->Channels() +
1093 v;
1094 Double_t signal = Gain * fHitMap2->GetSignal( i, k );
1095 fHitMap2->SetHit( i, k, signal ); ///
1096 }
1097 }
1098 }
1099}
1100//______________________________________________________________________
1101void AliITSsimulationSDD::ApplyCrosstalk() {
1102 // function add the crosstalk effect to signal
1103 // temporal function, should be checked...!!!
1104
1105 Int_t fNofMaps = fSegmentation->Npz();
1106 Int_t fMaxNofSamples = fSegmentation->Npx();
1107
1108 // create and inizialice crosstalk map
1109 Float_t* ctk = new Float_t[fNofMaps*fMaxNofSamples+1];
1110 if( ctk == NULL ) {
1111 Error( "ApplyCrosstalk", "no memory for temporal map: exit \n" );
1112 return;
1113 }
1114 memset( ctk, 0, sizeof(Float_t)*(fNofMaps*fMaxNofSamples+1) );
1115
1116 Float_t noise, baseline;
1117 fResponse->GetNoiseParam( noise, baseline );
1118
1119 for( Int_t z=0; z<fNofMaps; z++ ) {
1120 Bool_t on = kFALSE;
1121 Int_t tstart = 0;
1122 Int_t tstop = 0;
1123 Int_t nTsteps = 0;
1124
1125 for( Int_t l=0; l<fMaxNofSamples; l++ ) {
1126 Float_t fadc = (Float_t)fHitMap2->GetSignal( z, l );
1127 if( fadc > baseline ) {
1128 if( on == kFALSE && l<fMaxNofSamples-4 ) {
1129 Float_t fadc1 = (Float_t)fHitMap2->GetSignal( z, l+1 );
1130 if( fadc1 < fadc ) continue;
1131 on = kTRUE;
1132 nTsteps = 0;
1133 tstart = l;
1134 }
1135 nTsteps++;
1136 }
1137 else { // end fadc > baseline
1138 if( on == kTRUE ) {
1139 if( nTsteps > 2 ) {
1140 tstop = l;
1141 // make smooth derivative
1142 Float_t* dev = new Float_t[fMaxNofSamples+1];
1143 memset( dev, 0, sizeof(Float_t)*(fMaxNofSamples+1) );
1144 if( ctk == NULL ) {
1145 Error( "ApplyCrosstalk",
1146 "no memory for temporal array: exit \n" );
1147 return;
1148 }
1149 for( Int_t i=tstart; i<tstop; i++ ) {
1150 if( i > 2 && i < fMaxNofSamples-2 )
1151 dev[i] = -0.2*fHitMap2->GetSignal( z,i-2 )
1152 -0.1*fHitMap2->GetSignal( z,i-1 )
1153 +0.1*fHitMap2->GetSignal( z,i+1 )
1154 +0.2*fHitMap2->GetSignal( z,i+2 );
1155 }
1156
1157 // add crosstalk contribution to neibourg anodes
1158 for( Int_t i=tstart; i<tstop; i++ ) {
1159 Int_t anode = z - 1;
1160 Int_t i1 = (Int_t)((i-tstart)*.61+tstart+0.5); //
1161 Float_t ctktmp = -dev[i1] * 0.25;
1162 if( anode > 0 ) {
1163 ctk[anode*fMaxNofSamples+i] += ctktmp;
1164 }
1165 anode = z + 1;
1166 if( anode < fNofMaps ) {
1167 ctk[anode*fMaxNofSamples+i] += ctktmp;
1168 }
1169 }
1170 delete [] dev;
1171
1172 } // if( nTsteps > 2 )
1173 on = kFALSE;
1174 } // if( on == kTRUE )
1175 } // else
1176 }
1177 }
1178
1179 for( Int_t a=0; a<fNofMaps; a++ )
1180 for( Int_t t=0; t<fMaxNofSamples; t++ ) {
1181 Float_t signal = fHitMap2->GetSignal( a, t ) + ctk[a*fMaxNofSamples+t];
1182 fHitMap2->SetHit( a, t, signal );
1183 }
1184
1185 delete [] ctk;
1186}
8a33ae9e 1187//______________________________________________________________________
b0f5e3fc 1188void AliITSsimulationSDD::GetAnodeBaseline(Int_t i,Float_t &baseline,
1189 Float_t &noise){
8a33ae9e 1190 // Returns the Baseline for a particular anode.
1191 baseline = fBaseline[i];
1192 noise = fNoise[i];
b0f5e3fc 1193}
8a33ae9e 1194//______________________________________________________________________
b0f5e3fc 1195void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl,
1196 Int_t &th){
8a33ae9e 1197 // Returns the compression alogirthm parameters
1198 Int_t size = fD.GetSize();
1199 if (size > 2 ) {
50d05d7b 1200 db=fD[i]; tl=fT1[i]; th=fT2[i];
8a33ae9e 1201 } else {
50d05d7b 1202 if (size <= 2 && i>=fNofMaps/2) {
1203 db=fD[1]; tl=fT1[1]; th=fT2[1];
1204 } else {
1205 db=fD[0]; tl=fT1[0]; th=fT2[0];
1206 } // end if size <=2 && i>=fNofMaps/2
8a33ae9e 1207 } // end if size >2
b0f5e3fc 1208}
8a33ae9e 1209//______________________________________________________________________
b0f5e3fc 1210void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl){
8a33ae9e 1211 // returns the compression alogirthm parameters
1212 Int_t size = fD.GetSize();
b0f5e3fc 1213
8a33ae9e 1214 if (size > 2 ) {
50d05d7b 1215 db=fD[i]; tl=fT1[i];
8a33ae9e 1216 } else {
50d05d7b 1217 if (size <= 2 && i>=fNofMaps/2) {
1218 db=fD[1]; tl=fT1[1];
1219 } else {
1220 db=fD[0]; tl=fT1[0];
1221 } // end if size <=2 && i>=fNofMaps/2
8a33ae9e 1222 } // end if size > 2
b0f5e3fc 1223}
8a33ae9e 1224//______________________________________________________________________
b0f5e3fc 1225void AliITSsimulationSDD::SetCompressParam(){
8a33ae9e 1226 // Sets the compression alogirthm parameters
1227 Int_t cp[8],i;
1228
1229 fResponse->GiveCompressParam(cp);
1230 for (i=0; i<2; i++) {
50d05d7b 1231 fD[i] = cp[i];
1232 fT1[i] = cp[i+2];
1233 fT2[i] = cp[i+4];
1234 fTol[i] = cp[i+6];
8a33ae9e 1235 } // end for i
b0f5e3fc 1236}
8a33ae9e 1237//______________________________________________________________________
b0f5e3fc 1238void AliITSsimulationSDD::ReadBaseline(){
8a33ae9e 1239 // read baseline and noise from file - either a .root file and in this
1240 // case data should be organised in a tree with one entry for each
1241 // module => reading should be done accordingly
1242 // or a classic file and do smth. like this:
1243 // Read baselines and noise for SDD
b0f5e3fc 1244
1245 Int_t na,pos;
1246 Float_t bl,n;
e8189707 1247 char input[100], base[100], param[100];
b0f5e3fc 1248 char *filtmp;
1249
e8189707 1250 fResponse->Filenames(input,base,param);
b0f5e3fc 1251 fFileName=base;
1252//
1253 filtmp = gSystem->ExpandPathName(fFileName.Data());
1254 FILE *bline = fopen(filtmp,"r");
b0f5e3fc 1255 na = 0;
1256
1257 if(bline) {
50d05d7b 1258 while(fscanf(bline,"%d %f %f",&pos, &bl, &n) != EOF) {
1259 if (pos != na+1) {
1260 Error("ReadBaseline","Anode number not in increasing order!",
1261 filtmp);
1262 exit(1);
1263 } // end if pos != na+1
1264 fBaseline[na]=bl;
1265 fNoise[na]=n;
1266 na++;
1267 } // end while
b0f5e3fc 1268 } else {
50d05d7b 1269 Error("ReadBaseline"," THE BASELINE FILE %s DOES NOT EXIST !",filtmp);
1270 exit(1);
b0f5e3fc 1271 } // end if(bline)
8a33ae9e 1272
b0f5e3fc 1273 fclose(bline);
1274 delete [] filtmp;
b0f5e3fc 1275}
8a33ae9e 1276//______________________________________________________________________
1277Int_t AliITSsimulationSDD::Convert10to8(Int_t signal) const {
1278 // To the 10 to 8 bit lossive compression.
1279 // code from Davide C. and Albert W.
1280
1281 if (signal < 128) return signal;
1282 if (signal < 256) return (128+((signal-128)>>1));
1283 if (signal < 512) return (192+((signal-256)>>3));
1284 if (signal < 1024) return (224+((signal-512)>>4));
1285 return 0;
b0f5e3fc 1286}
8a33ae9e 1287//______________________________________________________________________
1288Int_t AliITSsimulationSDD::Convert8to10(Int_t signal) const {
1289 // Undo the lossive 10 to 8 bit compression.
1290 // code from Davide C. and Albert W.
1291 if (signal < 0 || signal > 255) {
50d05d7b 1292 Warning("Convert8to10","out of range signal=%d",signal);
1293 return 0;
8a33ae9e 1294 } // end if signal <0 || signal >255
1295
1296 if (signal < 128) return signal;
1297 if (signal < 192) {
50d05d7b 1298 if (TMath::Odd(signal)) return (128+((signal-128)<<1));
1299 else return (128+((signal-128)<<1)+1);
8a33ae9e 1300 } // end if signal < 192
1301 if (signal < 224) {
50d05d7b 1302 if (TMath::Odd(signal)) return (256+((signal-192)<<3)+3);
1303 else return (256+((signal-192)<<3)+4);
8a33ae9e 1304 } // end if signal < 224
1305 if (TMath::Odd(signal)) return (512+((signal-224)<<4)+7);
48058160 1306 return (512+((signal-224)<<4)+8);
8a33ae9e 1307}
50d05d7b 1308
1309/*
8a33ae9e 1310//______________________________________________________________________
b0f5e3fc 1311AliITSMap* AliITSsimulationSDD::HitMap(Int_t i){
8a33ae9e 1312 //Return the correct map.
1313
b0f5e3fc 1314 return ((i==0)? fHitMap1 : fHitMap2);
50d05d7b 1315}*/
1316
8a33ae9e 1317//______________________________________________________________________
e8189707 1318void AliITSsimulationSDD::ZeroSuppression(const char *option) {
8a33ae9e 1319 // perform the zero suppresion
1320
1321 if (strstr(option,"2D")) {
50d05d7b 1322 //Init2D(); // activate if param change module by module
1323 Compress2D();
8a33ae9e 1324 } else if (strstr(option,"1D")) {
50d05d7b 1325 //Init1D(); // activate if param change module by module
1326 Compress1D();
8a33ae9e 1327 } else StoreAllDigits();
b0f5e3fc 1328}
8a33ae9e 1329//______________________________________________________________________
b0f5e3fc 1330void AliITSsimulationSDD::Init2D(){
8a33ae9e 1331 // read in and prepare arrays: fD, fT1, fT2
1332 // savemu[nanodes], savesigma[nanodes]
1333 // read baseline and noise from file - either a .root file and in this
1334 // case data should be organised in a tree with one entry for each
1335 // module => reading should be done accordingly
1336 // or a classic file and do smth. like this ( code from Davide C. and
1337 // Albert W.) :
1338 // Read 2D zero-suppression parameters for SDD
b0f5e3fc 1339
b9d0a01d 1340 if (!strstr(fParam.Data(),"file")) return;
b0f5e3fc 1341
1342 Int_t na,pos,tempTh;
1343 Float_t mu,sigma;
8a33ae9e 1344 Float_t *savemu = new Float_t [fNofMaps];
e8189707 1345 Float_t *savesigma = new Float_t [fNofMaps];
1346 char input[100],basel[100],par[100];
b0f5e3fc 1347 char *filtmp;
b0f5e3fc 1348 Int_t minval = fResponse->MinVal();
1349
e8189707 1350 fResponse->Filenames(input,basel,par);
8a33ae9e 1351 fFileName = par;
b0f5e3fc 1352//
1353 filtmp = gSystem->ExpandPathName(fFileName.Data());
1354 FILE *param = fopen(filtmp,"r");
1355 na = 0;
1356
1357 if(param) {
50d05d7b 1358 while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) {
1359 if (pos != na+1) {
1360 Error("Init2D","Anode number not in increasing order!",filtmp);
1361 exit(1);
1362 } // end if pos != na+1
1363 savemu[na] = mu;
8a33ae9e 1364 savesigma[na] = sigma;
b0f5e3fc 1365 if ((2.*sigma) < mu) {
1366 fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5);
1367 mu = 2.0 * sigma;
50d05d7b 1368 } else fD[na] = 0;
b0f5e3fc 1369 tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval;
1370 if (tempTh < 0) tempTh=0;
1371 fT1[na] = tempTh;
1372 tempTh = (Int_t)floor(mu+3.0*sigma+0.5) - minval;
1373 if (tempTh < 0) tempTh=0;
1374 fT2[na] = tempTh;
1375 na++;
50d05d7b 1376 } // end while
b0f5e3fc 1377 } else {
50d05d7b 1378 Error("Init2D","THE FILE %s DOES NOT EXIST !",filtmp);
1379 exit(1);
b0f5e3fc 1380 } // end if(param)
8a33ae9e 1381
b0f5e3fc 1382 fclose(param);
1383 delete [] filtmp;
5d18fa90 1384 delete [] savemu;
e8189707 1385 delete [] savesigma;
8a33ae9e 1386}
1387//______________________________________________________________________
b0f5e3fc 1388void AliITSsimulationSDD::Compress2D(){
8a33ae9e 1389 // simple ITS cluster finder -- online zero-suppression conditions
b0f5e3fc 1390
b0f5e3fc 1391 Int_t db,tl,th;
8a33ae9e 1392 Int_t minval = fResponse->MinVal();
1393 Bool_t write = fResponse->OutputOption();
1394 Bool_t do10to8 = fResponse->Do10to8();
b0f5e3fc 1395 Int_t nz, nl, nh, low, i, j;
1396
e8189707 1397 for (i=0; i<fNofMaps; i++) {
b0f5e3fc 1398 CompressionParam(i,db,tl,th);
8a33ae9e 1399 nz = 0;
1400 nl = 0;
1401 nh = 0;
1402 low = 0;
50d05d7b 1403 for (j=0; j<fMaxNofSamples; j++) {
1404 Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j));
1405 signal -= db; // if baseline eq. is done here
b0f5e3fc 1406 if (signal <= 0) {nz++; continue;}
50d05d7b 1407 if ((signal - tl) < minval) low++;
b0f5e3fc 1408 if ((signal - th) >= minval) {
50d05d7b 1409 nh++;
1410 Bool_t cond=kTRUE;
1411 FindCluster(i,j,signal,minval,cond);
1412 if(cond && j &&
1413 ((TMath::Abs(fHitMap2->GetSignal(i,j-1))-th)>=minval)){
1414 if(do10to8) signal = Convert10to8(signal);
1415 AddDigit(i,j,signal);
1416 } // end if cond&&j&&()
1417 } else if ((signal - tl) >= minval) nl++;
1418 } // end for j loop time samples
1419 if (write) TreeB()->Fill(nz,nl,nh,low,i+1);
8a33ae9e 1420 } //end for i loop anodes
b0f5e3fc 1421
8a33ae9e 1422 char hname[30];
1423 if (write) {
50d05d7b 1424 sprintf(hname,"TNtuple%d_%d",fModule,fEvent);
1425 TreeB()->Write(hname);
1426 // reset tree
b0f5e3fc 1427 TreeB()->Reset();
8a33ae9e 1428 } // end if write
1429}
1430//______________________________________________________________________
b0f5e3fc 1431void AliITSsimulationSDD::FindCluster(Int_t i,Int_t j,Int_t signal,
ece86d9a 1432 Int_t minval,Bool_t &cond){
8a33ae9e 1433 // Find clusters according to the online 2D zero-suppression algorithm
1434 Bool_t do10to8 = fResponse->Do10to8();
1435 Bool_t high = kFALSE;
b0f5e3fc 1436
1437 fHitMap2->FlagHit(i,j);
1438//
1439// check the online zero-suppression conditions
1440//
8a33ae9e 1441 const Int_t kMaxNeighbours = 4;
b0f5e3fc 1442 Int_t nn;
1443 Int_t dbx,tlx,thx;
8a33ae9e 1444 Int_t xList[kMaxNeighbours], yList[kMaxNeighbours];
e8189707 1445 fSegmentation->Neighbours(i,j,&nn,xList,yList);
ece86d9a 1446 Int_t in,ix,iy,qns;
e8189707 1447 for (in=0; in<nn; in++) {
50d05d7b 1448 ix=xList[in];
e8189707 1449 iy=yList[in];
b0f5e3fc 1450 if (fHitMap2->TestHit(ix,iy)==kUnused) {
50d05d7b 1451 CompressionParam(ix,dbx,tlx,thx);
1452 Int_t qn = (Int_t)(fHitMap2->GetSignal(ix,iy));
1453 qn -= dbx; // if baseline eq. is done here
1454 if ((qn-tlx) < minval) {
1455 fHitMap2->FlagHit(ix,iy);
1456 continue;
1457 } else {
1458 if ((qn - thx) >= minval) high=kTRUE;
1459 if (cond) {
1460 if(do10to8) signal = Convert10to8(signal);
1461 AddDigit(i,j,signal);
1462 } // end if cond
1463 if(do10to8) qns = Convert10to8(qn);
1464 else qns=qn;
1465 if (!high) AddDigit(ix,iy,qns);
1466 cond=kFALSE;
1467 if(!high) fHitMap2->FlagHit(ix,iy);
1468 } // end if qn-tlx < minval
1469 } // end if TestHit
8a33ae9e 1470 } // end for in loop over neighbours
b0f5e3fc 1471}
8a33ae9e 1472//______________________________________________________________________
b0f5e3fc 1473void AliITSsimulationSDD::Init1D(){
8a33ae9e 1474 // this is just a copy-paste of input taken from 2D algo
1475 // Torino people should give input
1476 // Read 1D zero-suppression parameters for SDD
b0f5e3fc 1477
b9d0a01d 1478 if (!strstr(fParam.Data(),"file")) return;
b0f5e3fc 1479
1480 Int_t na,pos,tempTh;
1481 Float_t mu,sigma;
8a33ae9e 1482 Float_t *savemu = new Float_t [fNofMaps];
e8189707 1483 Float_t *savesigma = new Float_t [fNofMaps];
1484 char input[100],basel[100],par[100];
b0f5e3fc 1485 char *filtmp;
b0f5e3fc 1486 Int_t minval = fResponse->MinVal();
8a33ae9e 1487
e8189707 1488 fResponse->Filenames(input,basel,par);
1489 fFileName=par;
b0f5e3fc 1490
1491// set first the disable and tol param
1492 SetCompressParam();
1493//
1494 filtmp = gSystem->ExpandPathName(fFileName.Data());
1495 FILE *param = fopen(filtmp,"r");
1496 na = 0;
1497
1498 if (param) {
50d05d7b 1499 fscanf(param,"%d %d %d %d ", &fT2[0], &fT2[1], &fTol[0], &fTol[1]);
1500 while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) {
1501 if (pos != na+1) {
1502 Error("Init1D","Anode number not in increasing order!",filtmp);
1503 exit(1);
1504 } // end if pos != na+1
1505 savemu[na]=mu;
1506 savesigma[na]=sigma;
1507 if ((2.*sigma) < mu) {
1508 fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5);
1509 mu = 2.0 * sigma;
1510 } else fD[na] = 0;
1511 tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval;
1512 if (tempTh < 0) tempTh=0;
1513 fT1[na] = tempTh;
1514 na++;
1515 } // end while
b0f5e3fc 1516 } else {
50d05d7b 1517 Error("Init1D","THE FILE %s DOES NOT EXIST !",filtmp);
1518 exit(1);
b0f5e3fc 1519 } // end if(param)
8a33ae9e 1520
b0f5e3fc 1521 fclose(param);
1522 delete [] filtmp;
749bd21a 1523 delete [] savemu;
e8189707 1524 delete [] savesigma;
8a33ae9e 1525}
1526//______________________________________________________________________
b0f5e3fc 1527void AliITSsimulationSDD::Compress1D(){
1528 // 1D zero-suppression algorithm (from Gianluca A.)
8a33ae9e 1529 Int_t dis,tol,thres,decr,diff;
b0f5e3fc 1530 UChar_t *str=fStream->Stream();
8a33ae9e 1531 Int_t counter=0;
1532 Bool_t do10to8=fResponse->Do10to8();
1533 Int_t last=0;
1534 Int_t k,i,j;
ece86d9a 1535
ece86d9a 1536 for (k=0; k<2; k++) {
50d05d7b 1537 tol = Tolerance(k);
1538 dis = Disable(k);
1539 for (i=0; i<fNofMaps/2; i++) {
1540 Bool_t firstSignal=kTRUE;
1541 Int_t idx=i+k*fNofMaps/2;
43217ad9 1542 if( !fAnodeFire[idx] ) continue;
50d05d7b 1543 CompressionParam(idx,decr,thres);
1544 for (j=0; j<fMaxNofSamples; j++) {
1545 Int_t signal=(Int_t)(fHitMap2->GetSignal(idx,j));
1546 signal -= decr; // if baseline eq.
1547 if(do10to8) signal = Convert10to8(signal);
1548 if (signal <= thres) {
1549 signal=0;
1550 diff=128;
1551 last=0;
1552 // write diff in the buffer for HuffT
1553 str[counter]=(UChar_t)diff;
1554 counter++;
1555 continue;
1556 } // end if signal <= thres
1557 diff=signal-last;
1558 if (diff > 127) diff=127;
1559 if (diff < -128) diff=-128;
1560 if (signal < dis) {
1561 // tol has changed to 8 possible cases ? - one can write
1562 // this if(TMath::Abs(diff)<tol) ... else ...
1563 if(TMath::Abs(diff)<tol) diff=0;
1564 // or keep it as it was before
1565 /*
b0f5e3fc 1566 if (tol==1 && (diff >= -2 && diff <= 1)) diff=0;
1567 if (tol==2 && (diff >= -4 && diff <= 3)) diff=0;
1568 if (tol==3 && (diff >= -16 && diff <= 15)) diff=0;
50d05d7b 1569 */
ece86d9a 1570 AddDigit(idx,j,last+diff);
50d05d7b 1571 } else {
1572 AddDigit(idx,j,signal);
1573 } // end if singal < dis
1574 diff += 128;
1575 // write diff in the buffer used to compute Huffman tables
1576 if (firstSignal) str[counter]=(UChar_t)signal;
1577 else str[counter]=(UChar_t)diff;
1578 counter++;
1579 last=signal;
1580 firstSignal=kFALSE;
1581 } // end for j loop time samples
1582 } // end for i loop anodes one half of detector
8a33ae9e 1583 } // end for k
b0f5e3fc 1584
1585 // check
1586 fStream->CheckCount(counter);
1587
1588 // open file and write out the stream of diff's
b0f5e3fc 1589 static Bool_t open=kTRUE;
e8189707 1590 static TFile *outFile;
b0f5e3fc 1591 Bool_t write = fResponse->OutputOption();
9ad8b5dd 1592 TDirectory *savedir = gDirectory;
b0f5e3fc 1593
1594 if (write ) {
50d05d7b 1595 if(open) {
1596 SetFileName("stream.root");
1597 cout<<"filename "<<fFileName<<endl;
1598 outFile=new TFile(fFileName,"recreate");
1599 cout<<"I have opened "<<fFileName<<" file "<<endl;
1600 } // end if open
1601 open = kFALSE;
1602 outFile->cd();
b0f5e3fc 1603 fStream->Write();
50d05d7b 1604 } // endif write
b0f5e3fc 1605
8a33ae9e 1606 fStream->ClearStream();
b0f5e3fc 1607
8a33ae9e 1608 // back to galice.root file
9ad8b5dd 1609 if(savedir) savedir->cd();
8a33ae9e 1610}
1611//______________________________________________________________________
b0f5e3fc 1612void AliITSsimulationSDD::StoreAllDigits(){
8a33ae9e 1613 // if non-zero-suppressed data
1614 Bool_t do10to8 = fResponse->Do10to8();
ece86d9a 1615 Int_t i, j, digits[3];
8a33ae9e 1616
e8189707 1617 for (i=0; i<fNofMaps; i++) {
1618 for (j=0; j<fMaxNofSamples; j++) {
50d05d7b 1619 Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j));
1620 if(do10to8) signal = Convert10to8(signal);
1621 if(do10to8) signal = Convert8to10(signal);
1622 digits[0] = i;
1623 digits[1] = j;
1624 digits[2] = signal;
1625 fITS->AddRealDigit(1,digits);
1626 } // end for j
8a33ae9e 1627 } // end for i
b0f5e3fc 1628}
8a33ae9e 1629//______________________________________________________________________
ece86d9a 1630void AliITSsimulationSDD::CreateHistograms(Int_t scale){
8a33ae9e 1631 // Creates histograms of maps for debugging
1632 Int_t i;
ece86d9a 1633
1634 fHis=new TObjArray(fNofMaps);
e8189707 1635 for (i=0;i<fNofMaps;i++) {
50d05d7b 1636 TString sddName("sdd_");
1637 Char_t candNum[4];
1638 sprintf(candNum,"%d",i+1);
1639 sddName.Append(candNum);
1640 fHis->AddAt(new TH1F(sddName.Data(),"SDD maps",scale*fMaxNofSamples,
1641 0.,(Float_t) scale*fMaxNofSamples), i);
8a33ae9e 1642 } // end for i
b0f5e3fc 1643}
8a33ae9e 1644//______________________________________________________________________
ece86d9a 1645void AliITSsimulationSDD::FillHistograms(){
8a33ae9e 1646 // fill 1D histograms from map
1647
1648 if (!fHis) return;
1649
1650 for( Int_t i=0; i<fNofMaps; i++) {
50d05d7b 1651 TH1F *hist =(TH1F *)fHis->UncheckedAt(i);
1652 Int_t nsamples = hist->GetNbinsX();
1653 for( Int_t j=0; j<nsamples; j++) {
1654 Double_t signal=fHitMap2->GetSignal(i,j);
1655 hist->Fill((Float_t)j,signal);
1656 } // end for j
8a33ae9e 1657 } // end for i
ece86d9a 1658}
8a33ae9e 1659//______________________________________________________________________
b0f5e3fc 1660void AliITSsimulationSDD::ResetHistograms(){
b0f5e3fc 1661 // Reset histograms for this detector
b0f5e3fc 1662 Int_t i;
8a33ae9e 1663
e8189707 1664 for (i=0;i<fNofMaps;i++ ) {
50d05d7b 1665 if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset();
8a33ae9e 1666 } // end for i
b0f5e3fc 1667}
8a33ae9e 1668//______________________________________________________________________
b0f5e3fc 1669TH1F *AliITSsimulationSDD::GetAnode(Int_t wing, Int_t anode) {
8a33ae9e 1670 // Fills a histogram from a give anode.
1671
1672 if (!fHis) return 0;
1673
1674 if(wing <=0 || wing > 2) {
50d05d7b 1675 Warning("GetAnode","Wrong wing number: %d",wing);
1676 return NULL;
8a33ae9e 1677 } // end if wing <=0 || wing >2
1678 if(anode <=0 || anode > fNofMaps/2) {
50d05d7b 1679 Warning("GetAnode","Wrong anode number: %d",anode);
1680 return NULL;
8a33ae9e 1681 } // end if ampde <=0 || andoe > fNofMaps/2
1682
1683 Int_t index = (wing-1)*fNofMaps/2 + anode-1;
8a33ae9e 1684 return (TH1F*)(fHis->At(index));
b0f5e3fc 1685}
8a33ae9e 1686//______________________________________________________________________
b0f5e3fc 1687void AliITSsimulationSDD::WriteToFile(TFile *hfile) {
8a33ae9e 1688 // Writes the histograms to a file
b0f5e3fc 1689
8a33ae9e 1690 if (!fHis) return;
1691
1692 hfile->cd();
1693 Int_t i;
8a33ae9e 1694 for(i=0; i<fNofMaps; i++) fHis->At(i)->Write(); //fAdcs[i]->Write();
1695 return;
b0f5e3fc 1696}
8a33ae9e 1697//______________________________________________________________________
ece86d9a 1698Float_t AliITSsimulationSDD::GetNoise() {
8a33ae9e 1699 // Returns the noise value
1700 //Bool_t do10to8=fResponse->Do10to8();
1701 //noise will always be in the liniar part of the signal
1702 Int_t decr;
1703 Int_t threshold = fT1[0];
1704 char opt1[20], opt2[20];
1705
1706 fResponse->ParamOptions(opt1,opt2);
1707 fParam=opt2;
1708 char *same = strstr(opt1,"same");
1709 Float_t noise,baseline;
1710 if (same) {
50d05d7b 1711 fResponse->GetNoiseParam(noise,baseline);
8a33ae9e 1712 } else {
50d05d7b 1713 static Bool_t readfile=kTRUE;
1714 //read baseline and noise from file
1715 if (readfile) ReadBaseline();
1716 readfile=kFALSE;
8a33ae9e 1717 } // end if same
1718
1719 TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2");
1720 if(c2) delete c2->GetPrimitive("noisehist");
1721 if(c2) delete c2->GetPrimitive("anode");
1722 else c2=new TCanvas("c2");
1723 c2->cd();
1724 c2->SetFillColor(0);
1725
1726 TH1F *noisehist = new TH1F("noisehist","noise",100,0.,(float)2*threshold);
1727 TH1F *anode = new TH1F("anode","Anode Projection",fMaxNofSamples,0.,
50d05d7b 1728 (float)fMaxNofSamples);
8a33ae9e 1729 Int_t i,k;
1730 for (i=0;i<fNofMaps;i++) {
50d05d7b 1731 CompressionParam(i,decr,threshold);
1732 if (!same) GetAnodeBaseline(i,baseline,noise);
1733 anode->Reset();
1734 for (k=0;k<fMaxNofSamples;k++) {
1735 Float_t signal=(Float_t)fHitMap2->GetSignal(i,k);
1736 //if (signal <= (float)threshold) noisehist->Fill(signal-baseline);
1737 if (signal <= (float)threshold) noisehist->Fill(signal);
1738 anode->Fill((float)k,signal);
1739 } // end for k
1740 anode->Draw();
1741 c2->Update();
8a33ae9e 1742 } // end for i
1743 TF1 *gnoise = new TF1("gnoise","gaus",0.,threshold);
1744 noisehist->Fit("gnoise","RQ");
1745 noisehist->Draw();
ece86d9a 1746 c2->Update();
8a33ae9e 1747 Float_t mnoise = gnoise->GetParameter(1);
1748 cout << "mnoise : " << mnoise << endl;
1749 Float_t rnoise = gnoise->GetParameter(2);
1750 cout << "rnoise : " << rnoise << endl;
1751 delete noisehist;
1752 return rnoise;
50d05d7b 1753}
1754//______________________________________________________________________
1755void AliITSsimulationSDD::WriteSDigits(){
c7a4dac0 1756 // Fills the Summable digits Tree
c7a4dac0 1757 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
1758
48058160 1759 for( Int_t i=0; i<fNofMaps; i++ ) {
43217ad9 1760 if( !fAnodeFire[i] ) continue;
48058160 1761 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
1762 Double_t sig = fHitMap2->GetSignal( i, j );
1763 if( sig > 0.2 ) {
1764 Int_t jdx = j*fScaleSize;
1765 Int_t index = fpList->GetHitIndex( i, j );
1766 AliITSpListItem pItemTmp2( fModule, index, 0. );
1767 // put the fScaleSize analog digits in only one
1768 for( Int_t ik=0; ik<fScaleSize; ik++ ) {
1769 AliITSpListItem *pItemTmp = fpList->GetpListItem( i, jdx+ik );
1770 if( pItemTmp == 0 ) continue;
1771 pItemTmp2.Add( pItemTmp );
1772 }
1773 pItemTmp2.AddSignalAfterElect( fModule, index, sig );
1774 pItemTmp2.AddNoise( fModule, index, fHitNoiMap2->GetSignal( i, j ) );
1775 aliITS->AddSumDigit( pItemTmp2 );
1776 } // end if (sig > 0.2)
1777 }
1778 }
c7a4dac0 1779 return;
b0f5e3fc 1780}
8a33ae9e 1781//______________________________________________________________________
44a312c3 1782void AliITSsimulationSDD::Print() {
8a33ae9e 1783 // Print SDD simulation Parameters
1784
1785 cout << "**************************************************" << endl;
1786 cout << " Silicon Drift Detector Simulation Parameters " << endl;
1787 cout << "**************************************************" << endl;
1788 cout << "Flag for Perpendicular tracks: " << (Int_t) fFlag << endl;
1789 cout << "Flag for noise checking: " << (Int_t) fCheckNoise << endl;
1790 cout << "Flag to switch off electronics: " << (Int_t) fDoFFT << endl;
1791 cout << "Number pf Anodes used: " << fNofMaps << endl;
1792 cout << "Number of Time Samples: " << fMaxNofSamples << endl;
1793 cout << "Scale size factor: " << fScaleSize << endl;
1794 cout << "**************************************************" << endl;
44a312c3 1795}