1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 Revision 1.37 2002/10/14 14:57:07 hristov
19 Merging the VirtualMC branch to the main development branch (HEAD)
21 Revision 1.32.4.4 2002/10/14 13:14:08 hristov
22 Updating VirtualMC to v3-09-02
24 Revision 1.36 2002/09/11 10:32:41 hristov
25 Use new for arrays with variable size
27 Revision 1.35 2002/09/09 17:23:28 nilsen
28 Minor changes in support of changes to AliITSdigitS?D class'.
30 Revision 1.34 2002/06/07 16:32:28 nilsen
31 Latest SDD changes to speed up the SDD simulation code.
33 Revision 1.33 2002/04/24 22:02:31 nilsen
34 New SDigits and Digits routines, and related changes, (including new
39 #include <Riostream.h>
46 #include <TStopwatch.h>
58 #include "AliITShit.h"
59 #include "AliITSdigit.h"
60 #include "AliITSmodule.h"
61 #include "AliITSpList.h"
62 #include "AliITSMapA1.h"
63 #include "AliITSMapA2.h"
64 #include "AliITSetfSDD.h"
65 #include "AliITSRawData.h"
66 #include "AliITSHuffman.h"
67 #include "AliITSgeom.h"
68 #include "AliITSsegmentation.h"
69 #include "AliITSresponse.h"
70 #include "AliITSsegmentationSDD.h"
71 #include "AliITSresponseSDD.h"
72 #include "AliITSsimulationSDD.h"
74 ClassImp(AliITSsimulationSDD)
75 ////////////////////////////////////////////////////////////////////////
77 // Written by Piergiorgio Cerello
80 // AliITSsimulationSDD is the simulation of SDDs.
84 <img src="picts/ITS/AliITShit_Class_Diagram.gif">
87 <font size=+2 color=red>
88 <p>This show the relasionships between the ITS hit class and the rest of Aliroot.
93 //______________________________________________________________________
94 Int_t power(Int_t b, Int_t e) {
95 // compute b to the e power, where both b and e are Int_ts.
98 for(i=0; i<e; i++) power *= b;
101 //______________________________________________________________________
102 void FastFourierTransform(AliITSetfSDD *alisddetf,Double_t *real,
103 Double_t *imag,Int_t direction) {
104 // Do a Fast Fourier Transform
106 Int_t samples = alisddetf->GetSamples();
107 Int_t l = (Int_t) ((log((Float_t) samples)/log(2.))+0.5);
110 Int_t m2 = samples/m1;
112 for(i=1; i<=l; i++) {
113 for(j=0; j<samples; j += m1) {
115 for(k=j; k<= j+m-1; k++) {
116 Double_t wsr = alisddetf->GetWeightReal(p);
117 Double_t wsi = alisddetf->GetWeightImag(p);
118 if(direction == -1) wsi = -wsi;
119 Double_t xr = *(real+k+m);
120 Double_t xi = *(imag+k+m);
121 *(real+k+m) = wsr*(*(real+k)-xr) - wsi*(*(imag+k)-xi);
122 *(imag+k+m) = wsr*(*(imag+k)-xi) + wsi*(*(real+k)-xr);
133 for(j=0; j<samples; j++) {
137 for(i1=1; i1<=l; i1++) {
140 p = p + p + j2 - j1 - j1;
143 Double_t xr = *(real+j);
144 Double_t xi = *(imag+j);
145 *(real+j) = *(real+p);
146 *(imag+j) = *(imag+p);
151 if(direction == -1) {
152 for(i=0; i<samples; i++) {
153 *(real+i) /= samples;
154 *(imag+i) /= samples;
156 } // end if direction == -1
159 //______________________________________________________________________
160 AliITSsimulationSDD::AliITSsimulationSDD(){
161 // Default constructor
182 SetPerpendTracksFlag();
187 //______________________________________________________________________
188 AliITSsimulationSDD::AliITSsimulationSDD(AliITSsimulationSDD &source){
189 // Copy constructor to satify Coding roules only.
191 if(this==&source) return;
192 Error("AliITSsimulationSSD","Not allowed to make a copy of "
193 "AliITSsimulationSDD Using default creater instead");
194 AliITSsimulationSDD();
196 //______________________________________________________________________
197 AliITSsimulationSDD& AliITSsimulationSDD::operator=(AliITSsimulationSDD &src){
198 // Assignment operator to satify Coding roules only.
200 if(this==&src) return *this;
201 Error("AliITSsimulationSSD","Not allowed to make a = with "
202 "AliITSsimulationSDD Using default creater instead");
205 //______________________________________________________________________
206 AliITSsimulationSDD::AliITSsimulationSDD(AliITSsegmentation *seg,
207 AliITSresponse *resp){
208 // Standard Constructor
228 Init((AliITSsegmentationSDD*)seg,(AliITSresponseSDD*)resp);
230 //______________________________________________________________________
231 void AliITSsimulationSDD::Init(AliITSsegmentationSDD *seg,
232 AliITSresponseSDD *resp){
233 // Standard Constructor
238 SetPerpendTracksFlag();
243 fpList = new AliITSpList( fSegmentation->Npz(),
244 fScaleSize*fSegmentation->Npx() );
245 fHitSigMap2 = new AliITSMapA2(fSegmentation,fScaleSize,1);
246 fHitNoiMap2 = new AliITSMapA2(fSegmentation,fScaleSize,1);
247 fHitMap2 = fHitSigMap2;
249 fNofMaps = fSegmentation->Npz();
250 fMaxNofSamples = fSegmentation->Npx();
251 fAnodeFire = new Bool_t [fNofMaps];
253 Float_t sddLength = fSegmentation->Dx();
254 Float_t sddWidth = fSegmentation->Dz();
257 Float_t anodePitch = fSegmentation->Dpz(dummy);
258 Double_t timeStep = (Double_t)fSegmentation->Dpx(dummy);
259 Float_t driftSpeed = fResponse->DriftSpeed();
261 if(anodePitch*(fNofMaps/2) > sddWidth) {
262 Warning("AliITSsimulationSDD",
263 "Too many anodes %d or too big pitch %f \n",
264 fNofMaps/2,anodePitch);
267 if(timeStep*fMaxNofSamples < sddLength/driftSpeed) {
268 Error("AliITSsimulationSDD",
269 "Time Interval > Allowed Time Interval: exit\n");
273 fElectronics = new AliITSetfSDD(timeStep/fScaleSize,
274 fResponse->Electronics());
276 char opt1[20], opt2[20];
277 fResponse->ParamOptions(opt1,opt2);
279 char *same = strstr(opt1,"same");
284 fNoise.Set(fNofMaps);
285 fBaseline.Set(fNofMaps);
288 const char *kopt=fResponse->ZeroSuppOption();
289 if (strstr(fParam.Data(),"file") ) {
292 if (strstr(kopt,"2D")) {
295 Init2D(); // desactivate if param change module by module
296 } else if(strstr(kopt,"1D")) {
299 Init1D(); // desactivate if param change module by module
307 } // end if else strstr
309 Bool_t write = fResponse->OutputOption();
310 if(write && strstr(kopt,"2D")) MakeTreeB();
312 // call here if baseline does not change by module
315 fITS = (AliITS*)gAlice->GetModule("ITS");
316 Int_t size = fNofMaps*fMaxNofSamples;
317 fStream = new AliITSInStream(size);
319 fInZR = new Double_t [fScaleSize*fMaxNofSamples];
320 fInZI = new Double_t [fScaleSize*fMaxNofSamples];
321 fOutZR = new Double_t [fScaleSize*fMaxNofSamples];
322 fOutZI = new Double_t [fScaleSize*fMaxNofSamples];
325 //______________________________________________________________________
326 AliITSsimulationSDD::~AliITSsimulationSDD() {
341 if(fTreeB) delete fTreeB;
342 if(fInZR) delete [] fInZR;
343 if(fInZI) delete [] fInZI;
344 if(fOutZR) delete [] fOutZR;
345 if(fOutZI) delete [] fOutZI;
346 if(fAnodeFire) delete [] fAnodeFire;
348 //______________________________________________________________________
349 void AliITSsimulationSDD::InitSimulationModule( Int_t module, Int_t event ) {
350 // create maps to build the lists of tracks for each summable digit
354 memset(fAnodeFire,0,sizeof(Bool_t)*fNofMaps);
356 //______________________________________________________________________
357 void AliITSsimulationSDD::ClearMaps() {
360 fHitSigMap2->ClearMap();
361 fHitNoiMap2->ClearMap();
363 //______________________________________________________________________
364 void AliITSsimulationSDD::SDigitiseModule( AliITSmodule *mod, Int_t md, Int_t ev){
365 // digitize module using the "slow" detector simulator creating
368 TObjArray *fHits = mod->GetHits();
369 Int_t nhits = fHits->GetEntriesFast();
372 InitSimulationModule( md, ev );
373 HitsToAnalogDigits( mod );
374 ChargeToSignal( kFALSE ); // - Process signal without add noise
375 fHitMap2 = fHitNoiMap2; // - Swap to noise map
376 ChargeToSignal( kTRUE ); // - Process only noise
377 fHitMap2 = fHitSigMap2; // - Return to signal map
381 //______________________________________________________________________
382 Bool_t AliITSsimulationSDD::AddSDigitsToModule( TClonesArray *pItemArray, Int_t mask ) {
383 // Add Summable digits to module maps.
384 Int_t nItems = pItemArray->GetEntries();
385 Double_t maxadc = fResponse->MaxAdc();
386 //Bool_t sig = kFALSE;
388 // cout << "Adding "<< nItems <<" SDigits to module " << fModule << endl;
389 for( Int_t i=0; i<nItems; i++ ) {
390 AliITSpListItem * pItem = (AliITSpListItem *)(pItemArray->At( i ));
391 if( pItem->GetModule() != fModule ) {
392 Error( "AliITSsimulationSDD",
393 "Error reading, SDigits module %d != current module %d: exit\n",
394 pItem->GetModule(), fModule );
398 // if(pItem->GetSignal()>0.0 ) sig = kTRUE;
400 fpList->AddItemTo( mask, pItem ); // Add SignalAfterElect + noise
401 AliITSpListItem * pItem2 = fpList->GetpListItem( pItem->GetIndex() );
402 Double_t sigAE = pItem2->GetSignalAfterElect();
403 if( sigAE >= maxadc ) sigAE = maxadc-1; // avoid overflow signal
406 fpList->GetMapIndex( pItem->GetIndex(), ia, it );
407 fHitMap2->SetHit( ia, it, sigAE );
408 fAnodeFire[ia] = kTRUE;
412 //______________________________________________________________________
413 void AliITSsimulationSDD::FinishSDigitiseModule() {
414 // digitize module using the "slow" detector simulator from
415 // the sum of summable digits.
419 //______________________________________________________________________
420 void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
421 // create maps to build the lists of tracks for each digit
423 TObjArray *fHits = mod->GetHits();
424 Int_t nhits = fHits->GetEntriesFast();
426 InitSimulationModule( md, ev );
428 if( !nhits && fCheckNoise ) {
429 ChargeToSignal( kTRUE ); // process noise
436 HitsToAnalogDigits( mod );
437 ChargeToSignal( kTRUE ); // process signal + noise
439 for( Int_t i=0; i<fNofMaps; i++ ) {
440 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
441 Int_t jdx = j*fScaleSize;
442 Int_t index = fpList->GetHitIndex( i, j );
443 AliITSpListItem pItemTmp2( fModule, index, 0. );
444 // put the fScaleSize analog digits in only one
445 for( Int_t ik=0; ik<fScaleSize; ik++ ) {
446 AliITSpListItem *pItemTmp = fpList->GetpListItem( i, jdx+ik );
447 if( pItemTmp == 0 ) continue;
448 pItemTmp2.Add( pItemTmp );
450 fpList->DeleteHit( i, j );
451 fpList->AddItemTo( 0, &pItemTmp2 );
458 //______________________________________________________________________
459 void AliITSsimulationSDD::FinishDigits() {
460 // introduce the electronics effects and do zero-suppression if required
463 if( fCrosstalkFlag ) ApplyCrosstalk();
465 const char *kopt = fResponse->ZeroSuppOption();
466 ZeroSuppression( kopt );
468 //______________________________________________________________________
469 void AliITSsimulationSDD::HitsToAnalogDigits( AliITSmodule *mod ) {
470 // create maps to build the lists of tracks for each digit
472 TObjArray *fHits = mod->GetHits();
473 Int_t nhits = fHits->GetEntriesFast();
474 // Int_t arg[6] = {0,0,0,0,0,0};
476 Int_t nofAnodes = fNofMaps/2;
477 Float_t sddLength = fSegmentation->Dx();
478 Float_t sddWidth = fSegmentation->Dz();
479 Float_t anodePitch = fSegmentation->Dpz(dummy);
480 Float_t timeStep = fSegmentation->Dpx(dummy);
481 Float_t driftSpeed = fResponse->DriftSpeed();
482 Float_t maxadc = fResponse->MaxAdc();
483 Float_t topValue = fResponse->DynamicRange();
484 Float_t cHloss = fResponse->ChargeLoss();
485 Float_t norm = maxadc/topValue;
486 Float_t dfCoeff, s1; fResponse->DiffCoeff(dfCoeff,s1); // Signal 2d Shape
487 Double_t eVpairs = 3.6; // electron pair energy eV.
488 Float_t nsigma = fResponse->NSigmaIntegration(); //
489 Int_t nlookups = fResponse->GausNLookUp(); //
490 Float_t jitter = ((AliITSresponseSDD*)fResponse)->JitterError(); //
492 // Piergiorgio's part (apart for few variables which I made float
493 // when i thought that can be done
494 // Fill detector maps with GEANT hits
495 // loop over hits in the module
497 const Float_t kconv = 1.0e+6; // GeV->KeV
499 Int_t hitDetector; // detector number (lay,lad,hitDetector)
500 Int_t iWing; // which detector wing/side.
501 Int_t detector; // 2*(detector-1)+iWing
502 Int_t ii,kk,ka,kt; // loop indexs
503 Int_t ia,it,index; // sub-pixel integration indexies
504 Int_t iAnode; // anode number.
505 Int_t timeSample; // time buckett.
506 Int_t anodeWindow; // anode direction charge integration width
507 Int_t timeWindow; // time direction charge integration width
508 Int_t jamin,jamax; // anode charge integration window
509 Int_t jtmin,jtmax; // time charge integration window
510 Int_t ndiv; // Anode window division factor.
511 Int_t nsplit; // the number of splits in anode and time windows==1.
512 Int_t nOfSplits; // number of times track length is split into
513 Float_t nOfSplitsF; // Floating point version of nOfSplits.
514 Float_t kkF; // Floating point version of loop index kk.
515 Float_t pathInSDD; // Track length in SDD.
516 Float_t drPath; // average position of track in detector. in microns
517 Float_t drTime; // Drift time
518 Float_t nmul; // drift time window multiplication factor.
519 Float_t avDrft; // x position of path length segment in cm.
520 Float_t avAnode; // Anode for path length segment in Anode number (float)
521 Float_t xAnode; // Floating point anode number.
522 Float_t driftPath; // avDrft in microns.
523 Float_t width; // width of signal at anodes.
524 Double_t depEnergy; // Energy deposited in this GEANT step.
525 Double_t xL[3],dxL[3]; // local hit coordinates and diff.
526 Double_t sigA; // sigma of signal at anode.
527 Double_t sigT; // sigma in time/drift direction for track segment
528 Double_t aStep,aConst; // sub-pixel size and offset anode
529 Double_t tStep,tConst; // sub-pixel size and offset time
530 Double_t amplitude; // signal amplitude for track segment in nanoAmpere
531 Double_t chargeloss; // charge loss for track segment.
532 Double_t anodeAmplitude; // signal amplitude in anode direction
533 Double_t aExpo; // exponent of Gaussian anode direction
534 Double_t timeAmplitude; // signal amplitude in time direction
535 Double_t tExpo; // exponent of Gaussian time direction
536 // Double_t tof; // Time of flight in ns of this step.
538 for(ii=0; ii<nhits; ii++) {
539 if(!mod->LineSegmentL(ii,xL[0],dxL[0],xL[1],dxL[1],xL[2],dxL[2],
540 depEnergy,itrack)) continue;
541 xL[0] += 0.0001*gRandom->Gaus( 0, jitter ); //
543 hitDetector = mod->GetDet();
544 //tof = 1.E+09*(mod->GetHit(ii)->GetTOF()); // tof in ns.
545 //if(tof>sddLength/driftSpeed) continue; // hit happed too late.
547 // scale path to simulate a perpendicular track
548 // continue if the particle did not lose energy
549 // passing through detector
551 Warning("HitsToAnalogDigits",
552 "fTrack = %d hit=%d module=%d This particle has"
553 " passed without losing energy!",
554 itrack,ii,mod->GetIndex());
556 } // end if !depEnergy
558 pathInSDD = TMath::Sqrt(dxL[0]*dxL[0]+dxL[1]*dxL[1]+dxL[2]*dxL[2]);
560 if (fFlag && pathInSDD) { depEnergy *= (0.03/pathInSDD); }
561 drPath = 10000.*(dxL[0]+2.*xL[0])*0.5;
562 if(drPath < 0) drPath = -drPath;
563 drPath = sddLength-drPath;
565 Warning("HitsToAnalogDigits",
566 "negative drift path drPath=%e sddLength=%e dxL[0]=%e "
568 drPath,sddLength,dxL[0],xL[0]);
570 } // end if drPath < 0
572 // Compute number of segments to brake step path into
573 drTime = drPath/driftSpeed; // Drift Time
574 sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);// Sigma along the anodes
575 // calcuate the number of time the path length should be split into.
576 nOfSplits = (Int_t) (1. + 10000.*pathInSDD/sigA);
577 if(fFlag) nOfSplits = 1;
579 // loop over path segments, init. some variables.
580 depEnergy /= nOfSplits;
581 nOfSplitsF = (Float_t) nOfSplits;
582 for(kk=0;kk<nOfSplits;kk++) { // loop over path segments
583 kkF = (Float_t) kk + 0.5;
584 avDrft = xL[0]+dxL[0]*kkF/nOfSplitsF;
585 avAnode = xL[2]+dxL[2]*kkF/nOfSplitsF;
586 driftPath = 10000.*avDrft;
588 iWing = 2; // Assume wing is 2
589 if(driftPath < 0) { // if wing is not 2 it is 1.
591 driftPath = -driftPath;
592 } // end if driftPath < 0
593 driftPath = sddLength-driftPath;
594 detector = 2*(hitDetector-1) + iWing;
596 Warning("HitsToAnalogDigits","negative drift path "
597 "driftPath=%e sddLength=%e avDrft=%e dxL[0]=%e "
598 "xL[0]=%e",driftPath,sddLength,avDrft,dxL[0],xL[0]);
600 } // end if driftPath < 0
603 drTime = driftPath/driftSpeed; // drift time for segment.
604 timeSample = (Int_t) (fScaleSize*drTime/timeStep + 1);
605 // compute time Sample including tof information. The tof only
606 // effects the time of the signal is recoreded and not the
608 // timeSample = (Int_t) (fScaleSize*(drTime+tof)/timeStep + 1);
609 if(timeSample > fScaleSize*fMaxNofSamples) {
610 Warning("HitsToAnalogDigits","Wrong Time Sample: %e",
613 } // end if timeSample > fScaleSize*fMaxNoofSamples
616 xAnode = 10000.*(avAnode)/anodePitch + nofAnodes/2; // +1?
617 if(xAnode*anodePitch > sddWidth || xAnode*anodePitch < 0.)
618 Warning("HitsToAnalogDigits",
619 "Exceedubg sddWidth=%e Z = %e",
620 sddWidth,xAnode*anodePitch);
621 iAnode = (Int_t) (1.+xAnode); // xAnode?
622 if(iAnode < 1 || iAnode > nofAnodes) {
623 Warning("HitToAnalogDigits","Wrong iAnode: 1<%d>%d",
626 } // end if iAnode < 1 || iAnode > nofAnodes
628 // store straight away the particle position in the array
629 // of particles and take idhit=ii only when part is entering (this
630 // requires FillModules() in the macro for analysis) :
632 // Sigma along the anodes for track segment.
633 sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);
634 sigT = sigA/driftSpeed;
635 // Peak amplitude in nanoAmpere
636 amplitude = fScaleSize*160.*depEnergy/
637 (timeStep*eVpairs*2.*acos(-1.)*sigT*sigA);
638 amplitude *= timeStep/25.; // WARNING!!!!! Amplitude scaling to
639 // account for clock variations
640 // (reference value: 40 MHz)
641 chargeloss = 1.-cHloss*driftPath/1000;
642 amplitude *= chargeloss;
643 width = 2.*nsigma/(nlookups-1);
651 } // end if drTime > 1200.
653 nsplit = 4; // hard-wired //nsplit=4;nsplit = (nsplit+1)/2*2;
654 // Sub-pixel size see computation of aExpo and tExpo.
655 aStep = anodePitch/(nsplit*fScaleSize*sigA);
656 aConst = xAnode*anodePitch/sigA;
657 tStep = timeStep/(nsplit*fScaleSize*sigT);
658 tConst = drTime/sigT;
659 // Define SDD window corresponding to the hit
660 anodeWindow = (Int_t)(fScaleSize*nsigma*sigA/anodePitch+1);
661 timeWindow = (Int_t) (fScaleSize*nsigma*sigT/timeStep+1.);
662 jamin = (iAnode - anodeWindow/ndiv - 1)*fScaleSize*nsplit +1;
663 jamax = (iAnode + anodeWindow/ndiv)*fScaleSize*nsplit;
664 if(jamin <= 0) jamin = 1;
665 if(jamax > fScaleSize*nofAnodes*nsplit)
666 jamax = fScaleSize*nofAnodes*nsplit;
667 // jtmin and jtmax are Hard-wired
668 jtmin = (Int_t)(timeSample-timeWindow*nmul-1)*nsplit+1;
669 jtmax = (Int_t)(timeSample+timeWindow*nmul)*nsplit;
670 if(jtmin <= 0) jtmin = 1;
671 if(jtmax > fScaleSize*fMaxNofSamples*nsplit)
672 jtmax = fScaleSize*fMaxNofSamples*nsplit;
673 // Spread the charge in the anode-time window
674 for(ka=jamin; ka <=jamax; ka++) {
675 ia = (ka-1)/(fScaleSize*nsplit) + 1;
677 Warning("HitsToAnalogDigits","ia < 1: ");
680 if(ia > nofAnodes) ia = nofAnodes;
681 aExpo = (aStep*(ka-0.5)-aConst);
682 if(TMath::Abs(aExpo) > nsigma) anodeAmplitude = 0.;
684 dummy = (Int_t) ((aExpo+nsigma)/width);
685 anodeAmplitude = amplitude*fResponse->GausLookUp(dummy);
686 } // end if TMath::Abs(aEspo) > nsigma
687 // index starts from 0
688 index = ((detector+1)%2)*nofAnodes+ia-1;
689 if(anodeAmplitude) for(kt=jtmin; kt<=jtmax; kt++) {
690 it = (kt-1)/nsplit+1; // it starts from 1
692 Warning("HitsToAnalogDigits","it < 1:");
695 if(it>fScaleSize*fMaxNofSamples)
696 it = fScaleSize*fMaxNofSamples;
697 tExpo = (tStep*(kt-0.5)-tConst);
698 if(TMath::Abs(tExpo) > nsigma) timeAmplitude = 0.;
700 dummy = (Int_t) ((tExpo+nsigma)/width);
701 timeAmplitude = anodeAmplitude*
702 fResponse->GausLookUp(dummy);
703 } // end if TMath::Abs(tExpo) > nsigma
704 // build the list of Sdigits for this module
707 // arg[2] = itrack; // track number
708 // arg[3] = ii-1; // hit number.
709 timeAmplitude *= norm;
711 // ListOfFiredCells(arg,timeAmplitude,alst,padr);
712 Double_t charge = timeAmplitude;
713 charge += fHitMap2->GetSignal(index,it-1);
714 fHitMap2->SetHit(index, it-1, charge);
715 fpList->AddSignal(index,it-1,itrack,ii-1,
716 mod->GetIndex(),timeAmplitude);
717 fAnodeFire[index] = kTRUE;
718 } // end if anodeAmplitude and loop over time in window
719 } // loop over anodes in window
720 } // end loop over "sub-hits"
721 } // end loop over hits
725 //______________________________________________________________________
726 void AliITSsimulationSDD::ListOfFiredCells(Int_t *arg,Double_t timeAmplitude,
727 TObjArray *alist,TClonesArray *padr){
728 // Returns the list of "fired" cells.
730 Int_t index = arg[0];
732 Int_t idtrack = arg[2];
733 Int_t idhit = arg[3];
734 Int_t counter = arg[4];
735 Int_t countadr = arg[5];
736 Double_t charge = timeAmplitude;
737 charge += fHitMap2->GetSignal(index,ik-1);
738 fHitMap2->SetHit(index, ik-1, charge);
741 Int_t it = (Int_t)((ik-1)/fScaleSize);
744 digits[2] = (Int_t)timeAmplitude;
746 if (idtrack >= 0) phys = (Float_t)timeAmplitude;
749 Double_t cellcharge = 0.;
750 AliITSTransientDigit* pdigit;
751 // build the list of fired cells and update the info
752 if (!fHitMap1->TestHit(index, it)) {
753 new((*padr)[countadr++]) TVector(3);
754 TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
755 trinfo(0) = (Float_t)idtrack;
756 trinfo(1) = (Float_t)idhit;
757 trinfo(2) = (Float_t)timeAmplitude;
759 alist->AddAtAndExpand(new AliITSTransientDigit(phys,digits),counter);
760 fHitMap1->SetHit(index, it, counter);
762 pdigit=(AliITSTransientDigit*)alist->At(alist->GetLast());
764 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
765 trlist->Add(&trinfo);
767 pdigit = (AliITSTransientDigit*) fHitMap1->GetHit(index, it);
768 for(Int_t kk=0;kk<fScaleSize;kk++) {
769 cellcharge += fHitMap2->GetSignal(index,fScaleSize*it+kk);
772 (*pdigit).fSignal = (Int_t)cellcharge;
773 (*pdigit).fPhysics += phys;
774 // update list of tracks
775 TObjArray* trlist = (TObjArray*)pdigit->TrackList();
776 Int_t lastentry = trlist->GetLast();
777 TVector *ptrkp = (TVector*)trlist->At(lastentry);
778 TVector &trinfo = *ptrkp;
779 Int_t lasttrack = Int_t(trinfo(0));
780 Float_t lastcharge=(trinfo(2));
781 if (lasttrack==idtrack ) {
782 lastcharge += (Float_t)timeAmplitude;
783 trlist->RemoveAt(lastentry);
784 trinfo(0) = lasttrack;
786 trinfo(2) = lastcharge;
787 trlist->AddAt(&trinfo,lastentry);
789 new((*padr)[countadr++]) TVector(3);
790 TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
791 trinfo(0) = (Float_t)idtrack;
792 trinfo(1) = (Float_t)idhit;
793 trinfo(2) = (Float_t)timeAmplitude;
794 trlist->Add(&trinfo);
795 } // end if lasttrack==idtrack
798 // check the track list - debugging
799 Int_t trk[20], htrk[20];
801 Int_t nptracks = trlist->GetEntriesFast();
804 for (tr=0;tr<nptracks;tr++) {
805 TVector *pptrkp = (TVector*)trlist->At(tr);
806 TVector &pptrk = *pptrkp;
807 trk[tr] = Int_t(pptrk(0));
808 htrk[tr] = Int_t(pptrk(1));
809 chtrk[tr] = (pptrk(2));
810 cout << "nptracks "<<nptracks << endl;
816 // update counter and countadr for next call.
822 //____________________________________________
823 void AliITSsimulationSDD::AddDigit( Int_t i, Int_t j, Int_t signal ) {
825 Int_t size = AliITSdigitSPD::GetNTracks();
827 Int_t * tracks = new Int_t[size];
828 Int_t * hits = new Int_t[size];
830 Float_t * charges = new Float_t[size];
832 if( fResponse->Do10to8() ) signal = Convert8to10( signal );
837 AliITSpListItem *pItem = fpList->GetpListItem( i, j );
840 for( Int_t l=0; l<size; l++ ) {
846 Int_t idtrack = pItem->GetTrack( 0 );
847 if( idtrack >= 0 ) phys = pItem->GetSignal();
850 for( Int_t l=0; l<size; l++ ) if(l<pItem->GetMaxKept()) {
851 tracks[l] = pItem->GetTrack( l );
852 hits[l] = pItem->GetHit( l );
853 charges[l] = pItem->GetSignal( l );
861 fITS->AddSimDigit( 1, phys, digits, tracks, hits, charges );
868 //____________________________________________
869 void AliITSsimulationSDD::AddDigit(Int_t i, Int_t j, Int_t signal){
871 // tag with -1 signals coming from background tracks
872 // tag with -2 signals coming from pure electronic noise
874 Int_t digits[3], tracks[3], hits[3];
875 Float_t phys, charges[3];
877 Int_t trk[20], htrk[20];
880 Bool_t do10to8=fResponse->Do10to8();
882 if(do10to8) signal=Convert8to10(signal);
883 AliITSTransientDigit *obj = (AliITSTransientDigit*)fHitMap1->GetHit(i,j);
895 fITS->AddSimDigit(1,phys,digits,tracks,hits,charges);
898 TObjArray* trlist=(TObjArray*)obj->TrackList();
899 Int_t nptracks=trlist->GetEntriesFast();
901 Warning("AddDigit","nptracks=%d > 20 nptracks set to 20",nptracks);
903 } // end if nptracks > 20
905 for (tr=0;tr<nptracks;tr++) {
906 TVector &pp =*((TVector*)trlist->At(tr));
907 trk[tr]=Int_t(pp(0));
908 htrk[tr]=Int_t(pp(1));
912 SortTracks(trk,chtrk,htrk,nptracks);
913 } // end if nptracks > 1
916 for (i=0; i<nptracks; i++) {
921 for (i=nptracks; i<3; i++) {
927 for (i=0; i<3; i++) {
932 } // end if/else nptracks < 3
934 fITS->AddSimDigit(1,phys,digits,tracks,hits,charges);
936 } // end if/else !obj
940 //______________________________________________________________________
941 void AliITSsimulationSDD::SortTracks(Int_t *tracks,Float_t *charges,
942 Int_t *hits,Int_t ntr){
943 // Sort the list of tracks contributing to a given digit
944 // Only the 3 most significant tracks are acctually sorted
945 // Loop over signals, only 3 times
949 Int_t idx[3] = {-3,-3,-3};
950 Float_t jch[3] = {-3,-3,-3};
951 Int_t jtr[3] = {-3,-3,-3};
952 Int_t jhit[3] = {-3,-3,-3};
955 if (ntr<3) imax = ntr;
961 if((i == 1 && j == idx[i-1] )
962 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
963 if(charges[j] > qmax) {
966 } // end if charges[j]>qmax
970 jch[i] = charges[jmax];
971 jtr[i] = tracks[jmax];
972 jhit[i] = hits[jmax];
985 } // end if jtr[i] == -3
989 //______________________________________________________________________
990 void AliITSsimulationSDD::ChargeToSignal(Bool_t bAddNoise) {
991 // add baseline, noise, electronics and ADC saturation effects
993 char opt1[20], opt2[20];
994 fResponse->ParamOptions(opt1,opt2);
995 char *read = strstr(opt1,"file");
996 Float_t baseline, noise;
999 static Bool_t readfile=kTRUE;
1000 //read baseline and noise from file
1001 if (readfile) ReadBaseline();
1003 } else fResponse->GetNoiseParam(noise,baseline);
1007 Float_t maxadc = fResponse->MaxAdc();
1009 for (i=0;i<fNofMaps;i++) {
1010 if( !fAnodeFire[i] ) continue;
1011 if (read && i<fNofMaps) GetAnodeBaseline(i,baseline,noise);
1012 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
1013 fInZR[k] = fHitMap2->GetSignal(i,k);
1015 contrib = (baseline + noise*gRandom->Gaus());
1016 fInZR[k] += contrib;
1019 for(k=0; k<fMaxNofSamples; k++) {
1020 Double_t newcont = 0.;
1021 Double_t maxcont = 0.;
1022 for(kk=0;kk<fScaleSize;kk++) {
1023 newcont = fInZR[fScaleSize*k+kk];
1024 if(newcont > maxcont) maxcont = newcont;
1027 if (newcont >= maxadc) newcont = maxadc -1;
1028 if(newcont >= baseline){
1029 Warning("","newcont=%d>=baseline=%d",newcont,baseline);
1031 // back to analog: ?
1032 fHitMap2->SetHit(i,k,newcont);
1034 } // end for i loop over anodes
1038 for (i=0;i<fNofMaps;i++) {
1039 if( !fAnodeFire[i] ) continue;
1040 if (read && i<fNofMaps) GetAnodeBaseline(i,baseline,noise);
1041 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
1042 fInZR[k] = fHitMap2->GetSignal(i,k);
1044 contrib = (baseline + noise*gRandom->Gaus());
1045 fInZR[k] += contrib;
1049 FastFourierTransform(fElectronics,&fInZR[0],&fInZI[0],1);
1050 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
1051 Double_t rw = fElectronics->GetTraFunReal(k);
1052 Double_t iw = fElectronics->GetTraFunImag(k);
1053 fOutZR[k] = fInZR[k]*rw - fInZI[k]*iw;
1054 fOutZI[k] = fInZR[k]*iw + fInZI[k]*rw;
1056 FastFourierTransform(fElectronics,&fOutZR[0],&fOutZI[0],-1);
1057 for(k=0; k<fMaxNofSamples; k++) {
1058 Double_t newcont1 = 0.;
1059 Double_t maxcont1 = 0.;
1060 for(kk=0;kk<fScaleSize;kk++) {
1061 newcont1 = fOutZR[fScaleSize*k+kk];
1062 if(newcont1 > maxcont1) maxcont1 = newcont1;
1064 newcont1 = maxcont1;
1065 if (newcont1 >= maxadc) newcont1 = maxadc -1;
1066 fHitMap2->SetHit(i,k,newcont1);
1068 } // end for i loop over anodes
1071 //____________________________________________________________________
1072 void AliITSsimulationSDD::ApplyDeadChannels() {
1073 // Set dead channel signal to zero
1074 AliITSresponseSDD * response = (AliITSresponseSDD *)fResponse;
1077 if( response->GetDeadModules() == 0 &&
1078 response->GetDeadChips() == 0 &&
1079 response->GetDeadChannels() == 0 )
1082 static AliITS *iTS = (AliITS*)gAlice->GetModule( "ITS" );
1084 Int_t fMaxNofSamples = fSegmentation->Npx();
1085 AliITSgeom *geom = iTS->GetITSgeom();
1086 Int_t firstSDDMod = geom->GetStartDet( 1 );
1088 for( Int_t j=0; j<2; j++ ) {
1089 Int_t mod = (fModule-firstSDDMod)*2 + j;
1090 for( Int_t u=0; u<response->Chips(); u++ )
1091 for( Int_t v=0; v<response->Channels(); v++ ) {
1092 Float_t Gain = response->Gain( mod, u, v );
1093 for( Int_t k=0; k<fMaxNofSamples; k++ ) {
1094 Int_t i = j*response->Chips()*response->Channels() +
1095 u*response->Channels() +
1097 Double_t signal = Gain * fHitMap2->GetSignal( i, k );
1098 fHitMap2->SetHit( i, k, signal ); ///
1103 //______________________________________________________________________
1104 void AliITSsimulationSDD::ApplyCrosstalk() {
1105 // function add the crosstalk effect to signal
1106 // temporal function, should be checked...!!!
1108 Int_t fNofMaps = fSegmentation->Npz();
1109 Int_t fMaxNofSamples = fSegmentation->Npx();
1111 // create and inizialice crosstalk map
1112 Float_t* ctk = new Float_t[fNofMaps*fMaxNofSamples+1];
1114 Error( "ApplyCrosstalk", "no memory for temporal map: exit \n" );
1117 memset( ctk, 0, sizeof(Float_t)*(fNofMaps*fMaxNofSamples+1) );
1119 Float_t noise, baseline;
1120 fResponse->GetNoiseParam( noise, baseline );
1122 for( Int_t z=0; z<fNofMaps; z++ ) {
1128 for( Int_t l=0; l<fMaxNofSamples; l++ ) {
1129 Float_t fadc = (Float_t)fHitMap2->GetSignal( z, l );
1130 if( fadc > baseline ) {
1131 if( on == kFALSE && l<fMaxNofSamples-4 ) {
1132 Float_t fadc1 = (Float_t)fHitMap2->GetSignal( z, l+1 );
1133 if( fadc1 < fadc ) continue;
1140 else { // end fadc > baseline
1144 // make smooth derivative
1145 Float_t* dev = new Float_t[fMaxNofSamples+1];
1146 memset( dev, 0, sizeof(Float_t)*(fMaxNofSamples+1) );
1148 Error( "ApplyCrosstalk",
1149 "no memory for temporal array: exit \n" );
1152 for( Int_t i=tstart; i<tstop; i++ ) {
1153 if( i > 2 && i < fMaxNofSamples-2 )
1154 dev[i] = -0.2*fHitMap2->GetSignal( z,i-2 )
1155 -0.1*fHitMap2->GetSignal( z,i-1 )
1156 +0.1*fHitMap2->GetSignal( z,i+1 )
1157 +0.2*fHitMap2->GetSignal( z,i+2 );
1160 // add crosstalk contribution to neibourg anodes
1161 for( Int_t i=tstart; i<tstop; i++ ) {
1162 Int_t anode = z - 1;
1163 Int_t i1 = (Int_t)((i-tstart)*.61+tstart+0.5); //
1164 Float_t ctktmp = -dev[i1] * 0.25;
1166 ctk[anode*fMaxNofSamples+i] += ctktmp;
1169 if( anode < fNofMaps ) {
1170 ctk[anode*fMaxNofSamples+i] += ctktmp;
1175 } // if( nTsteps > 2 )
1177 } // if( on == kTRUE )
1182 for( Int_t a=0; a<fNofMaps; a++ )
1183 for( Int_t t=0; t<fMaxNofSamples; t++ ) {
1184 Float_t signal = fHitMap2->GetSignal( a, t ) + ctk[a*fMaxNofSamples+t];
1185 fHitMap2->SetHit( a, t, signal );
1190 //______________________________________________________________________
1191 void AliITSsimulationSDD::GetAnodeBaseline(Int_t i,Float_t &baseline,
1193 // Returns the Baseline for a particular anode.
1194 baseline = fBaseline[i];
1197 //______________________________________________________________________
1198 void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl,
1200 // Returns the compression alogirthm parameters
1201 Int_t size = fD.GetSize();
1203 db=fD[i]; tl=fT1[i]; th=fT2[i];
1205 if (size <= 2 && i>=fNofMaps/2) {
1206 db=fD[1]; tl=fT1[1]; th=fT2[1];
1208 db=fD[0]; tl=fT1[0]; th=fT2[0];
1209 } // end if size <=2 && i>=fNofMaps/2
1212 //______________________________________________________________________
1213 void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl){
1214 // returns the compression alogirthm parameters
1215 Int_t size = fD.GetSize();
1218 db=fD[i]; tl=fT1[i];
1220 if (size <= 2 && i>=fNofMaps/2) {
1221 db=fD[1]; tl=fT1[1];
1223 db=fD[0]; tl=fT1[0];
1224 } // end if size <=2 && i>=fNofMaps/2
1225 } // end if size > 2
1227 //______________________________________________________________________
1228 void AliITSsimulationSDD::SetCompressParam(){
1229 // Sets the compression alogirthm parameters
1232 fResponse->GiveCompressParam(cp);
1233 for (i=0; i<2; i++) {
1240 //______________________________________________________________________
1241 void AliITSsimulationSDD::ReadBaseline(){
1242 // read baseline and noise from file - either a .root file and in this
1243 // case data should be organised in a tree with one entry for each
1244 // module => reading should be done accordingly
1245 // or a classic file and do smth. like this:
1246 // Read baselines and noise for SDD
1250 char input[100], base[100], param[100];
1253 fResponse->Filenames(input,base,param);
1256 filtmp = gSystem->ExpandPathName(fFileName.Data());
1257 FILE *bline = fopen(filtmp,"r");
1261 while(fscanf(bline,"%d %f %f",&pos, &bl, &n) != EOF) {
1263 Error("ReadBaseline","Anode number not in increasing order!",
1266 } // end if pos != na+1
1272 Error("ReadBaseline"," THE BASELINE FILE %s DOES NOT EXIST !",filtmp);
1279 //______________________________________________________________________
1280 Int_t AliITSsimulationSDD::Convert10to8(Int_t signal) const {
1281 // To the 10 to 8 bit lossive compression.
1282 // code from Davide C. and Albert W.
1284 if (signal < 128) return signal;
1285 if (signal < 256) return (128+((signal-128)>>1));
1286 if (signal < 512) return (192+((signal-256)>>3));
1287 if (signal < 1024) return (224+((signal-512)>>4));
1290 //______________________________________________________________________
1291 Int_t AliITSsimulationSDD::Convert8to10(Int_t signal) const {
1292 // Undo the lossive 10 to 8 bit compression.
1293 // code from Davide C. and Albert W.
1294 if (signal < 0 || signal > 255) {
1295 Warning("Convert8to10","out of range signal=%d",signal);
1297 } // end if signal <0 || signal >255
1299 if (signal < 128) return signal;
1301 if (TMath::Odd(signal)) return (128+((signal-128)<<1));
1302 else return (128+((signal-128)<<1)+1);
1303 } // end if signal < 192
1305 if (TMath::Odd(signal)) return (256+((signal-192)<<3)+3);
1306 else return (256+((signal-192)<<3)+4);
1307 } // end if signal < 224
1308 if (TMath::Odd(signal)) return (512+((signal-224)<<4)+7);
1309 return (512+((signal-224)<<4)+8);
1313 //______________________________________________________________________
1314 AliITSMap* AliITSsimulationSDD::HitMap(Int_t i){
1315 //Return the correct map.
1317 return ((i==0)? fHitMap1 : fHitMap2);
1320 //______________________________________________________________________
1321 void AliITSsimulationSDD::ZeroSuppression(const char *option) {
1322 // perform the zero suppresion
1324 if (strstr(option,"2D")) {
1325 //Init2D(); // activate if param change module by module
1327 } else if (strstr(option,"1D")) {
1328 //Init1D(); // activate if param change module by module
1330 } else StoreAllDigits();
1332 //______________________________________________________________________
1333 void AliITSsimulationSDD::Init2D(){
1334 // read in and prepare arrays: fD, fT1, fT2
1335 // savemu[nanodes], savesigma[nanodes]
1336 // read baseline and noise from file - either a .root file and in this
1337 // case data should be organised in a tree with one entry for each
1338 // module => reading should be done accordingly
1339 // or a classic file and do smth. like this ( code from Davide C. and
1341 // Read 2D zero-suppression parameters for SDD
1343 if (!strstr(fParam.Data(),"file")) return;
1345 Int_t na,pos,tempTh;
1347 Float_t *savemu = new Float_t [fNofMaps];
1348 Float_t *savesigma = new Float_t [fNofMaps];
1349 char input[100],basel[100],par[100];
1351 Int_t minval = fResponse->MinVal();
1353 fResponse->Filenames(input,basel,par);
1356 filtmp = gSystem->ExpandPathName(fFileName.Data());
1357 FILE *param = fopen(filtmp,"r");
1361 while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) {
1363 Error("Init2D","Anode number not in increasing order!",filtmp);
1365 } // end if pos != na+1
1367 savesigma[na] = sigma;
1368 if ((2.*sigma) < mu) {
1369 fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5);
1372 tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval;
1373 if (tempTh < 0) tempTh=0;
1375 tempTh = (Int_t)floor(mu+3.0*sigma+0.5) - minval;
1376 if (tempTh < 0) tempTh=0;
1381 Error("Init2D","THE FILE %s DOES NOT EXIST !",filtmp);
1388 delete [] savesigma;
1390 //______________________________________________________________________
1391 void AliITSsimulationSDD::Compress2D(){
1392 // simple ITS cluster finder -- online zero-suppression conditions
1395 Int_t minval = fResponse->MinVal();
1396 Bool_t write = fResponse->OutputOption();
1397 Bool_t do10to8 = fResponse->Do10to8();
1398 Int_t nz, nl, nh, low, i, j;
1400 for (i=0; i<fNofMaps; i++) {
1401 CompressionParam(i,db,tl,th);
1406 for (j=0; j<fMaxNofSamples; j++) {
1407 Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j));
1408 signal -= db; // if baseline eq. is done here
1409 if (signal <= 0) {nz++; continue;}
1410 if ((signal - tl) < minval) low++;
1411 if ((signal - th) >= minval) {
1414 FindCluster(i,j,signal,minval,cond);
1416 ((TMath::Abs(fHitMap2->GetSignal(i,j-1))-th)>=minval)){
1417 if(do10to8) signal = Convert10to8(signal);
1418 AddDigit(i,j,signal);
1419 } // end if cond&&j&&()
1420 } else if ((signal - tl) >= minval) nl++;
1421 } // end for j loop time samples
1422 if (write) TreeB()->Fill(nz,nl,nh,low,i+1);
1423 } //end for i loop anodes
1427 sprintf(hname,"TNtuple%d_%d",fModule,fEvent);
1428 TreeB()->Write(hname);
1433 //______________________________________________________________________
1434 void AliITSsimulationSDD::FindCluster(Int_t i,Int_t j,Int_t signal,
1435 Int_t minval,Bool_t &cond){
1436 // Find clusters according to the online 2D zero-suppression algorithm
1437 Bool_t do10to8 = fResponse->Do10to8();
1438 Bool_t high = kFALSE;
1440 fHitMap2->FlagHit(i,j);
1442 // check the online zero-suppression conditions
1444 const Int_t kMaxNeighbours = 4;
1447 Int_t xList[kMaxNeighbours], yList[kMaxNeighbours];
1448 fSegmentation->Neighbours(i,j,&nn,xList,yList);
1450 for (in=0; in<nn; in++) {
1453 if (fHitMap2->TestHit(ix,iy)==kUnused) {
1454 CompressionParam(ix,dbx,tlx,thx);
1455 Int_t qn = (Int_t)(fHitMap2->GetSignal(ix,iy));
1456 qn -= dbx; // if baseline eq. is done here
1457 if ((qn-tlx) < minval) {
1458 fHitMap2->FlagHit(ix,iy);
1461 if ((qn - thx) >= minval) high=kTRUE;
1463 if(do10to8) signal = Convert10to8(signal);
1464 AddDigit(i,j,signal);
1466 if(do10to8) qns = Convert10to8(qn);
1468 if (!high) AddDigit(ix,iy,qns);
1470 if(!high) fHitMap2->FlagHit(ix,iy);
1471 } // end if qn-tlx < minval
1473 } // end for in loop over neighbours
1475 //______________________________________________________________________
1476 void AliITSsimulationSDD::Init1D(){
1477 // this is just a copy-paste of input taken from 2D algo
1478 // Torino people should give input
1479 // Read 1D zero-suppression parameters for SDD
1481 if (!strstr(fParam.Data(),"file")) return;
1483 Int_t na,pos,tempTh;
1485 Float_t *savemu = new Float_t [fNofMaps];
1486 Float_t *savesigma = new Float_t [fNofMaps];
1487 char input[100],basel[100],par[100];
1489 Int_t minval = fResponse->MinVal();
1491 fResponse->Filenames(input,basel,par);
1494 // set first the disable and tol param
1497 filtmp = gSystem->ExpandPathName(fFileName.Data());
1498 FILE *param = fopen(filtmp,"r");
1502 fscanf(param,"%d %d %d %d ", &fT2[0], &fT2[1], &fTol[0], &fTol[1]);
1503 while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) {
1505 Error("Init1D","Anode number not in increasing order!",filtmp);
1507 } // end if pos != na+1
1509 savesigma[na]=sigma;
1510 if ((2.*sigma) < mu) {
1511 fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5);
1514 tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval;
1515 if (tempTh < 0) tempTh=0;
1520 Error("Init1D","THE FILE %s DOES NOT EXIST !",filtmp);
1527 delete [] savesigma;
1529 //______________________________________________________________________
1530 void AliITSsimulationSDD::Compress1D(){
1531 // 1D zero-suppression algorithm (from Gianluca A.)
1532 Int_t dis,tol,thres,decr,diff;
1533 UChar_t *str=fStream->Stream();
1535 Bool_t do10to8=fResponse->Do10to8();
1539 for (k=0; k<2; k++) {
1542 for (i=0; i<fNofMaps/2; i++) {
1543 Bool_t firstSignal=kTRUE;
1544 Int_t idx=i+k*fNofMaps/2;
1545 if( !fAnodeFire[idx] ) continue;
1546 CompressionParam(idx,decr,thres);
1547 for (j=0; j<fMaxNofSamples; j++) {
1548 Int_t signal=(Int_t)(fHitMap2->GetSignal(idx,j));
1549 signal -= decr; // if baseline eq.
1550 if(do10to8) signal = Convert10to8(signal);
1551 if (signal <= thres) {
1555 // write diff in the buffer for HuffT
1556 str[counter]=(UChar_t)diff;
1559 } // end if signal <= thres
1561 if (diff > 127) diff=127;
1562 if (diff < -128) diff=-128;
1564 // tol has changed to 8 possible cases ? - one can write
1565 // this if(TMath::Abs(diff)<tol) ... else ...
1566 if(TMath::Abs(diff)<tol) diff=0;
1567 // or keep it as it was before
1569 if (tol==1 && (diff >= -2 && diff <= 1)) diff=0;
1570 if (tol==2 && (diff >= -4 && diff <= 3)) diff=0;
1571 if (tol==3 && (diff >= -16 && diff <= 15)) diff=0;
1573 AddDigit(idx,j,last+diff);
1575 AddDigit(idx,j,signal);
1576 } // end if singal < dis
1578 // write diff in the buffer used to compute Huffman tables
1579 if (firstSignal) str[counter]=(UChar_t)signal;
1580 else str[counter]=(UChar_t)diff;
1584 } // end for j loop time samples
1585 } // end for i loop anodes one half of detector
1589 fStream->CheckCount(counter);
1591 // open file and write out the stream of diff's
1592 static Bool_t open=kTRUE;
1593 static TFile *outFile;
1594 Bool_t write = fResponse->OutputOption();
1595 TDirectory *savedir = gDirectory;
1599 SetFileName("stream.root");
1600 cout<<"filename "<<fFileName<<endl;
1601 outFile=new TFile(fFileName,"recreate");
1602 cout<<"I have opened "<<fFileName<<" file "<<endl;
1609 fStream->ClearStream();
1611 // back to galice.root file
1612 if(savedir) savedir->cd();
1614 //______________________________________________________________________
1615 void AliITSsimulationSDD::StoreAllDigits(){
1616 // if non-zero-suppressed data
1617 Bool_t do10to8 = fResponse->Do10to8();
1618 Int_t i, j, digits[3];
1620 for (i=0; i<fNofMaps; i++) {
1621 for (j=0; j<fMaxNofSamples; j++) {
1622 Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j));
1623 if(do10to8) signal = Convert10to8(signal);
1624 if(do10to8) signal = Convert8to10(signal);
1628 fITS->AddRealDigit(1,digits);
1632 //______________________________________________________________________
1633 void AliITSsimulationSDD::CreateHistograms(Int_t scale){
1634 // Creates histograms of maps for debugging
1637 fHis=new TObjArray(fNofMaps);
1638 for (i=0;i<fNofMaps;i++) {
1639 TString sddName("sdd_");
1641 sprintf(candNum,"%d",i+1);
1642 sddName.Append(candNum);
1643 fHis->AddAt(new TH1F(sddName.Data(),"SDD maps",scale*fMaxNofSamples,
1644 0.,(Float_t) scale*fMaxNofSamples), i);
1647 //______________________________________________________________________
1648 void AliITSsimulationSDD::FillHistograms(){
1649 // fill 1D histograms from map
1653 for( Int_t i=0; i<fNofMaps; i++) {
1654 TH1F *hist =(TH1F *)fHis->UncheckedAt(i);
1655 Int_t nsamples = hist->GetNbinsX();
1656 for( Int_t j=0; j<nsamples; j++) {
1657 Double_t signal=fHitMap2->GetSignal(i,j);
1658 hist->Fill((Float_t)j,signal);
1662 //______________________________________________________________________
1663 void AliITSsimulationSDD::ResetHistograms(){
1664 // Reset histograms for this detector
1667 for (i=0;i<fNofMaps;i++ ) {
1668 if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset();
1671 //______________________________________________________________________
1672 TH1F *AliITSsimulationSDD::GetAnode(Int_t wing, Int_t anode) {
1673 // Fills a histogram from a give anode.
1675 if (!fHis) return 0;
1677 if(wing <=0 || wing > 2) {
1678 Warning("GetAnode","Wrong wing number: %d",wing);
1680 } // end if wing <=0 || wing >2
1681 if(anode <=0 || anode > fNofMaps/2) {
1682 Warning("GetAnode","Wrong anode number: %d",anode);
1684 } // end if ampde <=0 || andoe > fNofMaps/2
1686 Int_t index = (wing-1)*fNofMaps/2 + anode-1;
1687 return (TH1F*)(fHis->At(index));
1689 //______________________________________________________________________
1690 void AliITSsimulationSDD::WriteToFile(TFile *hfile) {
1691 // Writes the histograms to a file
1697 for(i=0; i<fNofMaps; i++) fHis->At(i)->Write(); //fAdcs[i]->Write();
1700 //______________________________________________________________________
1701 Float_t AliITSsimulationSDD::GetNoise() {
1702 // Returns the noise value
1703 //Bool_t do10to8=fResponse->Do10to8();
1704 //noise will always be in the liniar part of the signal
1706 Int_t threshold = fT1[0];
1707 char opt1[20], opt2[20];
1709 fResponse->ParamOptions(opt1,opt2);
1711 char *same = strstr(opt1,"same");
1712 Float_t noise,baseline;
1714 fResponse->GetNoiseParam(noise,baseline);
1716 static Bool_t readfile=kTRUE;
1717 //read baseline and noise from file
1718 if (readfile) ReadBaseline();
1722 TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2");
1723 if(c2) delete c2->GetPrimitive("noisehist");
1724 if(c2) delete c2->GetPrimitive("anode");
1725 else c2=new TCanvas("c2");
1727 c2->SetFillColor(0);
1729 TH1F *noisehist = new TH1F("noisehist","noise",100,0.,(float)2*threshold);
1730 TH1F *anode = new TH1F("anode","Anode Projection",fMaxNofSamples,0.,
1731 (float)fMaxNofSamples);
1733 for (i=0;i<fNofMaps;i++) {
1734 CompressionParam(i,decr,threshold);
1735 if (!same) GetAnodeBaseline(i,baseline,noise);
1737 for (k=0;k<fMaxNofSamples;k++) {
1738 Float_t signal=(Float_t)fHitMap2->GetSignal(i,k);
1739 //if (signal <= (float)threshold) noisehist->Fill(signal-baseline);
1740 if (signal <= (float)threshold) noisehist->Fill(signal);
1741 anode->Fill((float)k,signal);
1746 TF1 *gnoise = new TF1("gnoise","gaus",0.,threshold);
1747 noisehist->Fit("gnoise","RQ");
1750 Float_t mnoise = gnoise->GetParameter(1);
1751 cout << "mnoise : " << mnoise << endl;
1752 Float_t rnoise = gnoise->GetParameter(2);
1753 cout << "rnoise : " << rnoise << endl;
1757 //______________________________________________________________________
1758 void AliITSsimulationSDD::WriteSDigits(){
1759 // Fills the Summable digits Tree
1760 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
1762 for( Int_t i=0; i<fNofMaps; i++ ) {
1763 if( !fAnodeFire[i] ) continue;
1764 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
1765 Double_t sig = fHitMap2->GetSignal( i, j );
1767 Int_t jdx = j*fScaleSize;
1768 Int_t index = fpList->GetHitIndex( i, j );
1769 AliITSpListItem pItemTmp2( fModule, index, 0. );
1770 // put the fScaleSize analog digits in only one
1771 for( Int_t ik=0; ik<fScaleSize; ik++ ) {
1772 AliITSpListItem *pItemTmp = fpList->GetpListItem( i, jdx+ik );
1773 if( pItemTmp == 0 ) continue;
1774 pItemTmp2.Add( pItemTmp );
1776 pItemTmp2.AddSignalAfterElect( fModule, index, sig );
1777 pItemTmp2.AddNoise( fModule, index, fHitNoiMap2->GetSignal( i, j ) );
1778 aliITS->AddSumDigit( pItemTmp2 );
1779 } // end if (sig > 0.2)
1784 //______________________________________________________________________
1785 void AliITSsimulationSDD::Print() {
1786 // Print SDD simulation Parameters
1788 cout << "**************************************************" << endl;
1789 cout << " Silicon Drift Detector Simulation Parameters " << endl;
1790 cout << "**************************************************" << endl;
1791 cout << "Flag for Perpendicular tracks: " << (Int_t) fFlag << endl;
1792 cout << "Flag for noise checking: " << (Int_t) fCheckNoise << endl;
1793 cout << "Flag to switch off electronics: " << (Int_t) fDoFFT << endl;
1794 cout << "Number pf Anodes used: " << fNofMaps << endl;
1795 cout << "Number of Time Samples: " << fMaxNofSamples << endl;
1796 cout << "Scale size factor: " << fScaleSize << endl;
1797 cout << "**************************************************" << endl;