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