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.35 2002/09/09 17:23:28 nilsen
19 Minor changes in support of changes to AliITSdigitS?D class'.
21 Revision 1.34 2002/06/07 16:32:28 nilsen
22 Latest SDD changes to speed up the SDD simulation code.
24 Revision 1.33 2002/04/24 22:02:31 nilsen
25 New SDigits and Digits routines, and related changes, (including new
37 #include <TStopwatch.h>
49 #include "AliITShit.h"
50 #include "AliITSdigit.h"
51 #include "AliITSmodule.h"
52 #include "AliITSpList.h"
53 #include "AliITSMapA1.h"
54 #include "AliITSMapA2.h"
55 #include "AliITSetfSDD.h"
56 #include "AliITSRawData.h"
57 #include "AliITSHuffman.h"
58 #include "AliITSgeom.h"
59 #include "AliITSsegmentation.h"
60 #include "AliITSresponse.h"
61 #include "AliITSsegmentationSDD.h"
62 #include "AliITSresponseSDD.h"
63 #include "AliITSsimulationSDD.h"
65 ClassImp(AliITSsimulationSDD)
66 ////////////////////////////////////////////////////////////////////////
68 // Written by Piergiorgio Cerello
71 // AliITSsimulationSDD is the simulation of SDDs.
75 <img src="picts/ITS/AliITShit_Class_Diagram.gif">
78 <font size=+2 color=red>
79 <p>This show the relasionships between the ITS hit class and the rest of Aliroot.
84 //______________________________________________________________________
85 Int_t power(Int_t b, Int_t e) {
86 // compute b to the e power, where both b and e are Int_ts.
89 for(i=0; i<e; i++) power *= b;
92 //______________________________________________________________________
93 void FastFourierTransform(AliITSetfSDD *alisddetf,Double_t *real,
94 Double_t *imag,Int_t direction) {
95 // Do a Fast Fourier Transform
97 Int_t samples = alisddetf->GetSamples();
98 Int_t l = (Int_t) ((log((Float_t) samples)/log(2.))+0.5);
101 Int_t m2 = samples/m1;
103 for(i=1; i<=l; i++) {
104 for(j=0; j<samples; j += m1) {
106 for(k=j; k<= j+m-1; k++) {
107 Double_t wsr = alisddetf->GetWeightReal(p);
108 Double_t wsi = alisddetf->GetWeightImag(p);
109 if(direction == -1) wsi = -wsi;
110 Double_t xr = *(real+k+m);
111 Double_t xi = *(imag+k+m);
112 *(real+k+m) = wsr*(*(real+k)-xr) - wsi*(*(imag+k)-xi);
113 *(imag+k+m) = wsr*(*(imag+k)-xi) + wsi*(*(real+k)-xr);
124 for(j=0; j<samples; j++) {
128 for(i1=1; i1<=l; i1++) {
131 p = p + p + j2 - j1 - j1;
134 Double_t xr = *(real+j);
135 Double_t xi = *(imag+j);
136 *(real+j) = *(real+p);
137 *(imag+j) = *(imag+p);
142 if(direction == -1) {
143 for(i=0; i<samples; i++) {
144 *(real+i) /= samples;
145 *(imag+i) /= samples;
147 } // end if direction == -1
150 //______________________________________________________________________
151 AliITSsimulationSDD::AliITSsimulationSDD(){
152 // Default constructor
173 SetPerpendTracksFlag();
178 //______________________________________________________________________
179 AliITSsimulationSDD::AliITSsimulationSDD(AliITSsimulationSDD &source){
180 // Copy constructor to satify Coding roules only.
182 if(this==&source) return;
183 Error("AliITSsimulationSSD","Not allowed to make a copy of "
184 "AliITSsimulationSDD Using default creater instead");
185 AliITSsimulationSDD();
187 //______________________________________________________________________
188 AliITSsimulationSDD& AliITSsimulationSDD::operator=(AliITSsimulationSDD &src){
189 // Assignment operator to satify Coding roules only.
191 if(this==&src) return *this;
192 Error("AliITSsimulationSSD","Not allowed to make a = with "
193 "AliITSsimulationSDD Using default creater instead");
196 //______________________________________________________________________
197 AliITSsimulationSDD::AliITSsimulationSDD(AliITSsegmentation *seg,
198 AliITSresponse *resp){
199 // Standard Constructor
219 Init((AliITSsegmentationSDD*)seg,(AliITSresponseSDD*)resp);
221 //______________________________________________________________________
222 void AliITSsimulationSDD::Init(AliITSsegmentationSDD *seg,
223 AliITSresponseSDD *resp){
224 // Standard Constructor
229 SetPerpendTracksFlag();
234 fpList = new AliITSpList( fSegmentation->Npz(),
235 fScaleSize*fSegmentation->Npx() );
236 fHitSigMap2 = new AliITSMapA2(fSegmentation,fScaleSize,1);
237 fHitNoiMap2 = new AliITSMapA2(fSegmentation,fScaleSize,1);
238 fHitMap2 = fHitSigMap2;
240 fNofMaps = fSegmentation->Npz();
241 fMaxNofSamples = fSegmentation->Npx();
242 fAnodeFire = new Bool_t [fNofMaps];
244 Float_t sddLength = fSegmentation->Dx();
245 Float_t sddWidth = fSegmentation->Dz();
248 Float_t anodePitch = fSegmentation->Dpz(dummy);
249 Double_t timeStep = (Double_t)fSegmentation->Dpx(dummy);
250 Float_t driftSpeed = fResponse->DriftSpeed();
252 if(anodePitch*(fNofMaps/2) > sddWidth) {
253 Warning("AliITSsimulationSDD",
254 "Too many anodes %d or too big pitch %f \n",
255 fNofMaps/2,anodePitch);
258 if(timeStep*fMaxNofSamples < sddLength/driftSpeed) {
259 Error("AliITSsimulationSDD",
260 "Time Interval > Allowed Time Interval: exit\n");
264 fElectronics = new AliITSetfSDD(timeStep/fScaleSize,
265 fResponse->Electronics());
267 char opt1[20], opt2[20];
268 fResponse->ParamOptions(opt1,opt2);
270 char *same = strstr(opt1,"same");
275 fNoise.Set(fNofMaps);
276 fBaseline.Set(fNofMaps);
279 const char *kopt=fResponse->ZeroSuppOption();
280 if (strstr(fParam,"file") ) {
283 if (strstr(kopt,"2D")) {
286 Init2D(); // desactivate if param change module by module
287 } else if(strstr(kopt,"1D")) {
290 Init1D(); // desactivate if param change module by module
298 } // end if else strstr
300 Bool_t write = fResponse->OutputOption();
301 if(write && strstr(kopt,"2D")) MakeTreeB();
303 // call here if baseline does not change by module
306 fITS = (AliITS*)gAlice->GetModule("ITS");
307 Int_t size = fNofMaps*fMaxNofSamples;
308 fStream = new AliITSInStream(size);
310 fInZR = new Double_t [fScaleSize*fMaxNofSamples];
311 fInZI = new Double_t [fScaleSize*fMaxNofSamples];
312 fOutZR = new Double_t [fScaleSize*fMaxNofSamples];
313 fOutZI = new Double_t [fScaleSize*fMaxNofSamples];
316 //______________________________________________________________________
317 AliITSsimulationSDD::~AliITSsimulationSDD() {
332 if(fTreeB) delete fTreeB;
333 if(fInZR) delete [] fInZR;
334 if(fInZI) delete [] fInZI;
335 if(fOutZR) delete [] fOutZR;
336 if(fOutZI) delete [] fOutZI;
337 if(fAnodeFire) delete [] fAnodeFire;
339 //______________________________________________________________________
340 void AliITSsimulationSDD::InitSimulationModule( Int_t module, Int_t event ) {
341 // create maps to build the lists of tracks for each summable digit
345 memset(fAnodeFire,0,sizeof(Bool_t)*fNofMaps);
347 //______________________________________________________________________
348 void AliITSsimulationSDD::ClearMaps() {
351 fHitSigMap2->ClearMap();
352 fHitNoiMap2->ClearMap();
354 //______________________________________________________________________
355 void AliITSsimulationSDD::SDigitiseModule( AliITSmodule *mod, Int_t md, Int_t ev){
356 // digitize module using the "slow" detector simulator creating
359 TObjArray *fHits = mod->GetHits();
360 Int_t nhits = fHits->GetEntriesFast();
363 InitSimulationModule( md, ev );
364 HitsToAnalogDigits( mod );
365 ChargeToSignal( kFALSE ); // - Process signal without add noise
366 fHitMap2 = fHitNoiMap2; // - Swap to noise map
367 ChargeToSignal( kTRUE ); // - Process only noise
368 fHitMap2 = fHitSigMap2; // - Return to signal map
372 //______________________________________________________________________
373 Bool_t AliITSsimulationSDD::AddSDigitsToModule( TClonesArray *pItemArray, Int_t mask ) {
374 // Add Summable digits to module maps.
375 Int_t nItems = pItemArray->GetEntries();
376 Double_t maxadc = fResponse->MaxAdc();
377 //Bool_t sig = kFALSE;
379 // cout << "Adding "<< nItems <<" SDigits to module " << fModule << endl;
380 for( Int_t i=0; i<nItems; i++ ) {
381 AliITSpListItem * pItem = (AliITSpListItem *)(pItemArray->At( i ));
382 if( pItem->GetModule() != fModule ) {
383 Error( "AliITSsimulationSDD",
384 "Error reading, SDigits module %d != current module %d: exit\n",
385 pItem->GetModule(), fModule );
389 // if(pItem->GetSignal()>0.0 ) sig = kTRUE;
391 fpList->AddItemTo( mask, pItem ); // Add SignalAfterElect + noise
392 AliITSpListItem * pItem2 = fpList->GetpListItem( pItem->GetIndex() );
393 Double_t sigAE = pItem2->GetSignalAfterElect();
394 if( sigAE >= maxadc ) sigAE = maxadc-1; // avoid overflow signal
397 fpList->GetMapIndex( pItem->GetIndex(), ia, it );
398 fHitMap2->SetHit( ia, it, sigAE );
399 fAnodeFire[ia] = kTRUE;
403 //______________________________________________________________________
404 void AliITSsimulationSDD::FinishSDigitiseModule() {
405 // digitize module using the "slow" detector simulator from
406 // the sum of summable digits.
410 //______________________________________________________________________
411 void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
412 // create maps to build the lists of tracks for each digit
414 TObjArray *fHits = mod->GetHits();
415 Int_t nhits = fHits->GetEntriesFast();
417 InitSimulationModule( md, ev );
419 if( !nhits && fCheckNoise ) {
420 ChargeToSignal( kTRUE ); // process noise
427 HitsToAnalogDigits( mod );
428 ChargeToSignal( kTRUE ); // process signal + noise
430 for( Int_t i=0; i<fNofMaps; i++ ) {
431 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
432 Int_t jdx = j*fScaleSize;
433 Int_t index = fpList->GetHitIndex( i, j );
434 AliITSpListItem pItemTmp2( fModule, index, 0. );
435 // put the fScaleSize analog digits in only one
436 for( Int_t ik=0; ik<fScaleSize; ik++ ) {
437 AliITSpListItem *pItemTmp = fpList->GetpListItem( i, jdx+ik );
438 if( pItemTmp == 0 ) continue;
439 pItemTmp2.Add( pItemTmp );
441 fpList->DeleteHit( i, j );
442 fpList->AddItemTo( 0, &pItemTmp2 );
449 //______________________________________________________________________
450 void AliITSsimulationSDD::FinishDigits() {
451 // introduce the electronics effects and do zero-suppression if required
454 if( fCrosstalkFlag ) ApplyCrosstalk();
456 const char *kopt = fResponse->ZeroSuppOption();
457 ZeroSuppression( kopt );
459 //______________________________________________________________________
460 void AliITSsimulationSDD::HitsToAnalogDigits( AliITSmodule *mod ) {
461 // create maps to build the lists of tracks for each digit
463 TObjArray *fHits = mod->GetHits();
464 Int_t nhits = fHits->GetEntriesFast();
465 // Int_t arg[6] = {0,0,0,0,0,0};
467 Int_t nofAnodes = fNofMaps/2;
468 Float_t sddLength = fSegmentation->Dx();
469 Float_t sddWidth = fSegmentation->Dz();
470 Float_t anodePitch = fSegmentation->Dpz(dummy);
471 Float_t timeStep = fSegmentation->Dpx(dummy);
472 Float_t driftSpeed = fResponse->DriftSpeed();
473 Float_t maxadc = fResponse->MaxAdc();
474 Float_t topValue = fResponse->DynamicRange();
475 Float_t cHloss = fResponse->ChargeLoss();
476 Float_t norm = maxadc/topValue;
477 Float_t dfCoeff, s1; fResponse->DiffCoeff(dfCoeff,s1); // Signal 2d Shape
478 Double_t eVpairs = 3.6; // electron pair energy eV.
479 Float_t nsigma = fResponse->NSigmaIntegration(); //
480 Int_t nlookups = fResponse->GausNLookUp(); //
481 Float_t jitter = ((AliITSresponseSDD*)fResponse)->JitterError(); //
483 // Piergiorgio's part (apart for few variables which I made float
484 // when i thought that can be done
485 // Fill detector maps with GEANT hits
486 // loop over hits in the module
488 const Float_t kconv = 1.0e+6; // GeV->KeV
490 Int_t hitDetector; // detector number (lay,lad,hitDetector)
491 Int_t iWing; // which detector wing/side.
492 Int_t detector; // 2*(detector-1)+iWing
493 Int_t ii,kk,ka,kt; // loop indexs
494 Int_t ia,it,index; // sub-pixel integration indexies
495 Int_t iAnode; // anode number.
496 Int_t timeSample; // time buckett.
497 Int_t anodeWindow; // anode direction charge integration width
498 Int_t timeWindow; // time direction charge integration width
499 Int_t jamin,jamax; // anode charge integration window
500 Int_t jtmin,jtmax; // time charge integration window
501 Int_t ndiv; // Anode window division factor.
502 Int_t nsplit; // the number of splits in anode and time windows==1.
503 Int_t nOfSplits; // number of times track length is split into
504 Float_t nOfSplitsF; // Floating point version of nOfSplits.
505 Float_t kkF; // Floating point version of loop index kk.
506 Float_t pathInSDD; // Track length in SDD.
507 Float_t drPath; // average position of track in detector. in microns
508 Float_t drTime; // Drift time
509 Float_t nmul; // drift time window multiplication factor.
510 Float_t avDrft; // x position of path length segment in cm.
511 Float_t avAnode; // Anode for path length segment in Anode number (float)
512 Float_t xAnode; // Floating point anode number.
513 Float_t driftPath; // avDrft in microns.
514 Float_t width; // width of signal at anodes.
515 Double_t depEnergy; // Energy deposited in this GEANT step.
516 Double_t xL[3],dxL[3]; // local hit coordinates and diff.
517 Double_t sigA; // sigma of signal at anode.
518 Double_t sigT; // sigma in time/drift direction for track segment
519 Double_t aStep,aConst; // sub-pixel size and offset anode
520 Double_t tStep,tConst; // sub-pixel size and offset time
521 Double_t amplitude; // signal amplitude for track segment in nanoAmpere
522 Double_t chargeloss; // charge loss for track segment.
523 Double_t anodeAmplitude; // signal amplitude in anode direction
524 Double_t aExpo; // exponent of Gaussian anode direction
525 Double_t timeAmplitude; // signal amplitude in time direction
526 Double_t tExpo; // exponent of Gaussian time direction
527 // Double_t tof; // Time of flight in ns of this step.
529 for(ii=0; ii<nhits; ii++) {
530 if(!mod->LineSegmentL(ii,xL[0],dxL[0],xL[1],dxL[1],xL[2],dxL[2],
531 depEnergy,itrack)) continue;
532 xL[0] += 0.0001*gRandom->Gaus( 0, jitter ); //
534 hitDetector = mod->GetDet();
535 //tof = 1.E+09*(mod->GetHit(ii)->GetTOF()); // tof in ns.
536 //if(tof>sddLength/driftSpeed) continue; // hit happed too late.
538 // scale path to simulate a perpendicular track
539 // continue if the particle did not lose energy
540 // passing through detector
542 Warning("HitsToAnalogDigits",
543 "fTrack = %d hit=%d module=%d This particle has"
544 " passed without losing energy!",
545 itrack,ii,mod->GetIndex());
547 } // end if !depEnergy
549 pathInSDD = TMath::Sqrt(dxL[0]*dxL[0]+dxL[1]*dxL[1]+dxL[2]*dxL[2]);
551 if (fFlag && pathInSDD) { depEnergy *= (0.03/pathInSDD); }
552 drPath = 10000.*(dxL[0]+2.*xL[0])*0.5;
553 if(drPath < 0) drPath = -drPath;
554 drPath = sddLength-drPath;
556 Warning("HitsToAnalogDigits",
557 "negative drift path drPath=%e sddLength=%e dxL[0]=%e "
559 drPath,sddLength,dxL[0],xL[0]);
561 } // end if drPath < 0
563 // Compute number of segments to brake step path into
564 drTime = drPath/driftSpeed; // Drift Time
565 sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);// Sigma along the anodes
566 // calcuate the number of time the path length should be split into.
567 nOfSplits = (Int_t) (1. + 10000.*pathInSDD/sigA);
568 if(fFlag) nOfSplits = 1;
570 // loop over path segments, init. some variables.
571 depEnergy /= nOfSplits;
572 nOfSplitsF = (Float_t) nOfSplits;
573 for(kk=0;kk<nOfSplits;kk++) { // loop over path segments
574 kkF = (Float_t) kk + 0.5;
575 avDrft = xL[0]+dxL[0]*kkF/nOfSplitsF;
576 avAnode = xL[2]+dxL[2]*kkF/nOfSplitsF;
577 driftPath = 10000.*avDrft;
579 iWing = 2; // Assume wing is 2
580 if(driftPath < 0) { // if wing is not 2 it is 1.
582 driftPath = -driftPath;
583 } // end if driftPath < 0
584 driftPath = sddLength-driftPath;
585 detector = 2*(hitDetector-1) + iWing;
587 Warning("HitsToAnalogDigits","negative drift path "
588 "driftPath=%e sddLength=%e avDrft=%e dxL[0]=%e "
589 "xL[0]=%e",driftPath,sddLength,avDrft,dxL[0],xL[0]);
591 } // end if driftPath < 0
594 drTime = driftPath/driftSpeed; // drift time for segment.
595 timeSample = (Int_t) (fScaleSize*drTime/timeStep + 1);
596 // compute time Sample including tof information. The tof only
597 // effects the time of the signal is recoreded and not the
599 // timeSample = (Int_t) (fScaleSize*(drTime+tof)/timeStep + 1);
600 if(timeSample > fScaleSize*fMaxNofSamples) {
601 Warning("HitsToAnalogDigits","Wrong Time Sample: %e",
604 } // end if timeSample > fScaleSize*fMaxNoofSamples
607 xAnode = 10000.*(avAnode)/anodePitch + nofAnodes/2; // +1?
608 if(xAnode*anodePitch > sddWidth || xAnode*anodePitch < 0.)
609 Warning("HitsToAnalogDigits",
610 "Exceedubg sddWidth=%e Z = %e",
611 sddWidth,xAnode*anodePitch);
612 iAnode = (Int_t) (1.+xAnode); // xAnode?
613 if(iAnode < 1 || iAnode > nofAnodes) {
614 Warning("HitToAnalogDigits","Wrong iAnode: 1<%d>%d",
617 } // end if iAnode < 1 || iAnode > nofAnodes
619 // store straight away the particle position in the array
620 // of particles and take idhit=ii only when part is entering (this
621 // requires FillModules() in the macro for analysis) :
623 // Sigma along the anodes for track segment.
624 sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);
625 sigT = sigA/driftSpeed;
626 // Peak amplitude in nanoAmpere
627 amplitude = fScaleSize*160.*depEnergy/
628 (timeStep*eVpairs*2.*acos(-1.)*sigT*sigA);
629 amplitude *= timeStep/25.; // WARNING!!!!! Amplitude scaling to
630 // account for clock variations
631 // (reference value: 40 MHz)
632 chargeloss = 1.-cHloss*driftPath/1000;
633 amplitude *= chargeloss;
634 width = 2.*nsigma/(nlookups-1);
642 } // end if drTime > 1200.
644 nsplit = 4; // hard-wired //nsplit=4;nsplit = (nsplit+1)/2*2;
645 // Sub-pixel size see computation of aExpo and tExpo.
646 aStep = anodePitch/(nsplit*fScaleSize*sigA);
647 aConst = xAnode*anodePitch/sigA;
648 tStep = timeStep/(nsplit*fScaleSize*sigT);
649 tConst = drTime/sigT;
650 // Define SDD window corresponding to the hit
651 anodeWindow = (Int_t)(fScaleSize*nsigma*sigA/anodePitch+1);
652 timeWindow = (Int_t) (fScaleSize*nsigma*sigT/timeStep+1.);
653 jamin = (iAnode - anodeWindow/ndiv - 1)*fScaleSize*nsplit +1;
654 jamax = (iAnode + anodeWindow/ndiv)*fScaleSize*nsplit;
655 if(jamin <= 0) jamin = 1;
656 if(jamax > fScaleSize*nofAnodes*nsplit)
657 jamax = fScaleSize*nofAnodes*nsplit;
658 // jtmin and jtmax are Hard-wired
659 jtmin = (Int_t)(timeSample-timeWindow*nmul-1)*nsplit+1;
660 jtmax = (Int_t)(timeSample+timeWindow*nmul)*nsplit;
661 if(jtmin <= 0) jtmin = 1;
662 if(jtmax > fScaleSize*fMaxNofSamples*nsplit)
663 jtmax = fScaleSize*fMaxNofSamples*nsplit;
664 // Spread the charge in the anode-time window
665 for(ka=jamin; ka <=jamax; ka++) {
666 ia = (ka-1)/(fScaleSize*nsplit) + 1;
668 Warning("HitsToAnalogDigits","ia < 1: ");
671 if(ia > nofAnodes) ia = nofAnodes;
672 aExpo = (aStep*(ka-0.5)-aConst);
673 if(TMath::Abs(aExpo) > nsigma) anodeAmplitude = 0.;
675 dummy = (Int_t) ((aExpo+nsigma)/width);
676 anodeAmplitude = amplitude*fResponse->GausLookUp(dummy);
677 } // end if TMath::Abs(aEspo) > nsigma
678 // index starts from 0
679 index = ((detector+1)%2)*nofAnodes+ia-1;
680 if(anodeAmplitude) for(kt=jtmin; kt<=jtmax; kt++) {
681 it = (kt-1)/nsplit+1; // it starts from 1
683 Warning("HitsToAnalogDigits","it < 1:");
686 if(it>fScaleSize*fMaxNofSamples)
687 it = fScaleSize*fMaxNofSamples;
688 tExpo = (tStep*(kt-0.5)-tConst);
689 if(TMath::Abs(tExpo) > nsigma) timeAmplitude = 0.;
691 dummy = (Int_t) ((tExpo+nsigma)/width);
692 timeAmplitude = anodeAmplitude*
693 fResponse->GausLookUp(dummy);
694 } // end if TMath::Abs(tExpo) > nsigma
695 // build the list of Sdigits for this module
698 // arg[2] = itrack; // track number
699 // arg[3] = ii-1; // hit number.
700 timeAmplitude *= norm;
702 // ListOfFiredCells(arg,timeAmplitude,alst,padr);
703 Double_t charge = timeAmplitude;
704 charge += fHitMap2->GetSignal(index,it-1);
705 fHitMap2->SetHit(index, it-1, charge);
706 fpList->AddSignal(index,it-1,itrack,ii-1,
707 mod->GetIndex(),timeAmplitude);
708 fAnodeFire[index] = kTRUE;
709 } // end if anodeAmplitude and loop over time in window
710 } // loop over anodes in window
711 } // end loop over "sub-hits"
712 } // end loop over hits
716 //______________________________________________________________________
717 void AliITSsimulationSDD::ListOfFiredCells(Int_t *arg,Double_t timeAmplitude,
718 TObjArray *alist,TClonesArray *padr){
719 // Returns the list of "fired" cells.
721 Int_t index = arg[0];
723 Int_t idtrack = arg[2];
724 Int_t idhit = arg[3];
725 Int_t counter = arg[4];
726 Int_t countadr = arg[5];
727 Double_t charge = timeAmplitude;
728 charge += fHitMap2->GetSignal(index,ik-1);
729 fHitMap2->SetHit(index, ik-1, charge);
732 Int_t it = (Int_t)((ik-1)/fScaleSize);
735 digits[2] = (Int_t)timeAmplitude;
737 if (idtrack >= 0) phys = (Float_t)timeAmplitude;
740 Double_t cellcharge = 0.;
741 AliITSTransientDigit* pdigit;
742 // build the list of fired cells and update the info
743 if (!fHitMap1->TestHit(index, it)) {
744 new((*padr)[countadr++]) TVector(3);
745 TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
746 trinfo(0) = (Float_t)idtrack;
747 trinfo(1) = (Float_t)idhit;
748 trinfo(2) = (Float_t)timeAmplitude;
750 alist->AddAtAndExpand(new AliITSTransientDigit(phys,digits),counter);
751 fHitMap1->SetHit(index, it, counter);
753 pdigit=(AliITSTransientDigit*)alist->At(alist->GetLast());
755 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
756 trlist->Add(&trinfo);
758 pdigit = (AliITSTransientDigit*) fHitMap1->GetHit(index, it);
759 for(Int_t kk=0;kk<fScaleSize;kk++) {
760 cellcharge += fHitMap2->GetSignal(index,fScaleSize*it+kk);
763 (*pdigit).fSignal = (Int_t)cellcharge;
764 (*pdigit).fPhysics += phys;
765 // update list of tracks
766 TObjArray* trlist = (TObjArray*)pdigit->TrackList();
767 Int_t lastentry = trlist->GetLast();
768 TVector *ptrkp = (TVector*)trlist->At(lastentry);
769 TVector &trinfo = *ptrkp;
770 Int_t lasttrack = Int_t(trinfo(0));
771 Float_t lastcharge=(trinfo(2));
772 if (lasttrack==idtrack ) {
773 lastcharge += (Float_t)timeAmplitude;
774 trlist->RemoveAt(lastentry);
775 trinfo(0) = lasttrack;
777 trinfo(2) = lastcharge;
778 trlist->AddAt(&trinfo,lastentry);
780 new((*padr)[countadr++]) TVector(3);
781 TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
782 trinfo(0) = (Float_t)idtrack;
783 trinfo(1) = (Float_t)idhit;
784 trinfo(2) = (Float_t)timeAmplitude;
785 trlist->Add(&trinfo);
786 } // end if lasttrack==idtrack
789 // check the track list - debugging
790 Int_t trk[20], htrk[20];
792 Int_t nptracks = trlist->GetEntriesFast();
795 for (tr=0;tr<nptracks;tr++) {
796 TVector *pptrkp = (TVector*)trlist->At(tr);
797 TVector &pptrk = *pptrkp;
798 trk[tr] = Int_t(pptrk(0));
799 htrk[tr] = Int_t(pptrk(1));
800 chtrk[tr] = (pptrk(2));
801 cout << "nptracks "<<nptracks << endl;
807 // update counter and countadr for next call.
813 //____________________________________________
814 void AliITSsimulationSDD::AddDigit( Int_t i, Int_t j, Int_t signal ) {
816 Int_t size = AliITSdigitSPD::GetNTracks();
818 Int_t * tracks = new Int_t[size];
819 Int_t * hits = new Int_t[size];
821 Float_t * charges = new Float_t[size];
823 if( fResponse->Do10to8() ) signal = Convert8to10( signal );
828 AliITSpListItem *pItem = fpList->GetpListItem( i, j );
831 for( Int_t l=0; l<size; l++ ) {
837 Int_t idtrack = pItem->GetTrack( 0 );
838 if( idtrack >= 0 ) phys = pItem->GetSignal();
841 for( Int_t l=0; l<size; l++ ) if(l<pItem->GetMaxKept()) {
842 tracks[l] = pItem->GetTrack( l );
843 hits[l] = pItem->GetHit( l );
844 charges[l] = pItem->GetSignal( l );
852 fITS->AddSimDigit( 1, phys, digits, tracks, hits, charges );
859 //____________________________________________
860 void AliITSsimulationSDD::AddDigit(Int_t i, Int_t j, Int_t signal){
862 // tag with -1 signals coming from background tracks
863 // tag with -2 signals coming from pure electronic noise
865 Int_t digits[3], tracks[3], hits[3];
866 Float_t phys, charges[3];
868 Int_t trk[20], htrk[20];
871 Bool_t do10to8=fResponse->Do10to8();
873 if(do10to8) signal=Convert8to10(signal);
874 AliITSTransientDigit *obj = (AliITSTransientDigit*)fHitMap1->GetHit(i,j);
886 fITS->AddSimDigit(1,phys,digits,tracks,hits,charges);
889 TObjArray* trlist=(TObjArray*)obj->TrackList();
890 Int_t nptracks=trlist->GetEntriesFast();
892 Warning("AddDigit","nptracks=%d > 20 nptracks set to 20",nptracks);
894 } // end if nptracks > 20
896 for (tr=0;tr<nptracks;tr++) {
897 TVector &pp =*((TVector*)trlist->At(tr));
898 trk[tr]=Int_t(pp(0));
899 htrk[tr]=Int_t(pp(1));
903 SortTracks(trk,chtrk,htrk,nptracks);
904 } // end if nptracks > 1
907 for (i=0; i<nptracks; i++) {
912 for (i=nptracks; i<3; i++) {
918 for (i=0; i<3; i++) {
923 } // end if/else nptracks < 3
925 fITS->AddSimDigit(1,phys,digits,tracks,hits,charges);
927 } // end if/else !obj
931 //______________________________________________________________________
932 void AliITSsimulationSDD::SortTracks(Int_t *tracks,Float_t *charges,
933 Int_t *hits,Int_t ntr){
934 // Sort the list of tracks contributing to a given digit
935 // Only the 3 most significant tracks are acctually sorted
936 // Loop over signals, only 3 times
940 Int_t idx[3] = {-3,-3,-3};
941 Float_t jch[3] = {-3,-3,-3};
942 Int_t jtr[3] = {-3,-3,-3};
943 Int_t jhit[3] = {-3,-3,-3};
946 if (ntr<3) imax = ntr;
952 if((i == 1 && j == idx[i-1] )
953 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
954 if(charges[j] > qmax) {
957 } // end if charges[j]>qmax
961 jch[i] = charges[jmax];
962 jtr[i] = tracks[jmax];
963 jhit[i] = hits[jmax];
976 } // end if jtr[i] == -3
980 //______________________________________________________________________
981 void AliITSsimulationSDD::ChargeToSignal(Bool_t bAddNoise) {
982 // add baseline, noise, electronics and ADC saturation effects
984 char opt1[20], opt2[20];
985 fResponse->ParamOptions(opt1,opt2);
986 char *read = strstr(opt1,"file");
987 Float_t baseline, noise;
990 static Bool_t readfile=kTRUE;
991 //read baseline and noise from file
992 if (readfile) ReadBaseline();
994 } else fResponse->GetNoiseParam(noise,baseline);
998 Float_t maxadc = fResponse->MaxAdc();
1000 for (i=0;i<fNofMaps;i++) {
1001 if( !fAnodeFire[i] ) continue;
1002 if (read && i<fNofMaps) GetAnodeBaseline(i,baseline,noise);
1003 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
1004 fInZR[k] = fHitMap2->GetSignal(i,k);
1006 contrib = (baseline + noise*gRandom->Gaus());
1007 fInZR[k] += contrib;
1010 for(k=0; k<fMaxNofSamples; k++) {
1011 Double_t newcont = 0.;
1012 Double_t maxcont = 0.;
1013 for(kk=0;kk<fScaleSize;kk++) {
1014 newcont = fInZR[fScaleSize*k+kk];
1015 if(newcont > maxcont) maxcont = newcont;
1018 if (newcont >= maxadc) newcont = maxadc -1;
1019 if(newcont >= baseline){
1020 Warning("","newcont=%d>=baseline=%d",newcont,baseline);
1022 // back to analog: ?
1023 fHitMap2->SetHit(i,k,newcont);
1025 } // end for i loop over anodes
1029 for (i=0;i<fNofMaps;i++) {
1030 if( !fAnodeFire[i] ) continue;
1031 if (read && i<fNofMaps) GetAnodeBaseline(i,baseline,noise);
1032 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
1033 fInZR[k] = fHitMap2->GetSignal(i,k);
1035 contrib = (baseline + noise*gRandom->Gaus());
1036 fInZR[k] += contrib;
1040 FastFourierTransform(fElectronics,&fInZR[0],&fInZI[0],1);
1041 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
1042 Double_t rw = fElectronics->GetTraFunReal(k);
1043 Double_t iw = fElectronics->GetTraFunImag(k);
1044 fOutZR[k] = fInZR[k]*rw - fInZI[k]*iw;
1045 fOutZI[k] = fInZR[k]*iw + fInZI[k]*rw;
1047 FastFourierTransform(fElectronics,&fOutZR[0],&fOutZI[0],-1);
1048 for(k=0; k<fMaxNofSamples; k++) {
1049 Double_t newcont1 = 0.;
1050 Double_t maxcont1 = 0.;
1051 for(kk=0;kk<fScaleSize;kk++) {
1052 newcont1 = fOutZR[fScaleSize*k+kk];
1053 if(newcont1 > maxcont1) maxcont1 = newcont1;
1055 newcont1 = maxcont1;
1056 if (newcont1 >= maxadc) newcont1 = maxadc -1;
1057 fHitMap2->SetHit(i,k,newcont1);
1059 } // end for i loop over anodes
1062 //____________________________________________________________________
1063 void AliITSsimulationSDD::ApplyDeadChannels() {
1064 // Set dead channel signal to zero
1065 AliITSresponseSDD * response = (AliITSresponseSDD *)fResponse;
1068 if( response->GetDeadModules() == 0 &&
1069 response->GetDeadChips() == 0 &&
1070 response->GetDeadChannels() == 0 )
1073 static AliITS *iTS = (AliITS*)gAlice->GetModule( "ITS" );
1075 Int_t fMaxNofSamples = fSegmentation->Npx();
1076 AliITSgeom *geom = iTS->GetITSgeom();
1077 Int_t firstSDDMod = geom->GetStartDet( 1 );
1079 for( Int_t j=0; j<2; j++ ) {
1080 Int_t mod = (fModule-firstSDDMod)*2 + j;
1081 for( Int_t u=0; u<response->Chips(); u++ )
1082 for( Int_t v=0; v<response->Channels(); v++ ) {
1083 Float_t Gain = response->Gain( mod, u, v );
1084 for( Int_t k=0; k<fMaxNofSamples; k++ ) {
1085 Int_t i = j*response->Chips()*response->Channels() +
1086 u*response->Channels() +
1088 Double_t signal = Gain * fHitMap2->GetSignal( i, k );
1089 fHitMap2->SetHit( i, k, signal ); ///
1094 //______________________________________________________________________
1095 void AliITSsimulationSDD::ApplyCrosstalk() {
1096 // function add the crosstalk effect to signal
1097 // temporal function, should be checked...!!!
1099 Int_t fNofMaps = fSegmentation->Npz();
1100 Int_t fMaxNofSamples = fSegmentation->Npx();
1102 // create and inizialice crosstalk map
1103 Float_t* ctk = new Float_t[fNofMaps*fMaxNofSamples+1];
1105 Error( "ApplyCrosstalk", "no memory for temporal map: exit \n" );
1108 memset( ctk, 0, sizeof(Float_t)*(fNofMaps*fMaxNofSamples+1) );
1110 Float_t noise, baseline;
1111 fResponse->GetNoiseParam( noise, baseline );
1113 for( Int_t z=0; z<fNofMaps; z++ ) {
1119 for( Int_t l=0; l<fMaxNofSamples; l++ ) {
1120 Float_t fadc = (Float_t)fHitMap2->GetSignal( z, l );
1121 if( fadc > baseline ) {
1122 if( on == kFALSE && l<fMaxNofSamples-4 ) {
1123 Float_t fadc1 = (Float_t)fHitMap2->GetSignal( z, l+1 );
1124 if( fadc1 < fadc ) continue;
1131 else { // end fadc > baseline
1135 // make smooth derivative
1136 Float_t* dev = new Float_t[fMaxNofSamples+1];
1137 memset( dev, 0, sizeof(Float_t)*(fMaxNofSamples+1) );
1139 Error( "ApplyCrosstalk",
1140 "no memory for temporal array: exit \n" );
1143 for( Int_t i=tstart; i<tstop; i++ ) {
1144 if( i > 2 && i < fMaxNofSamples-2 )
1145 dev[i] = -0.2*fHitMap2->GetSignal( z,i-2 )
1146 -0.1*fHitMap2->GetSignal( z,i-1 )
1147 +0.1*fHitMap2->GetSignal( z,i+1 )
1148 +0.2*fHitMap2->GetSignal( z,i+2 );
1151 // add crosstalk contribution to neibourg anodes
1152 for( Int_t i=tstart; i<tstop; i++ ) {
1153 Int_t anode = z - 1;
1154 Int_t i1 = (Int_t)((i-tstart)*.61+tstart+0.5); //
1155 Float_t ctktmp = -dev[i1] * 0.25;
1157 ctk[anode*fMaxNofSamples+i] += ctktmp;
1160 if( anode < fNofMaps ) {
1161 ctk[anode*fMaxNofSamples+i] += ctktmp;
1166 } // if( nTsteps > 2 )
1168 } // if( on == kTRUE )
1173 for( Int_t a=0; a<fNofMaps; a++ )
1174 for( Int_t t=0; t<fMaxNofSamples; t++ ) {
1175 Float_t signal = fHitMap2->GetSignal( a, t ) + ctk[a*fMaxNofSamples+t];
1176 fHitMap2->SetHit( a, t, signal );
1181 //______________________________________________________________________
1182 void AliITSsimulationSDD::GetAnodeBaseline(Int_t i,Float_t &baseline,
1184 // Returns the Baseline for a particular anode.
1185 baseline = fBaseline[i];
1188 //______________________________________________________________________
1189 void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl,
1191 // Returns the compression alogirthm parameters
1192 Int_t size = fD.GetSize();
1194 db=fD[i]; tl=fT1[i]; th=fT2[i];
1196 if (size <= 2 && i>=fNofMaps/2) {
1197 db=fD[1]; tl=fT1[1]; th=fT2[1];
1199 db=fD[0]; tl=fT1[0]; th=fT2[0];
1200 } // end if size <=2 && i>=fNofMaps/2
1203 //______________________________________________________________________
1204 void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl){
1205 // returns the compression alogirthm parameters
1206 Int_t size = fD.GetSize();
1209 db=fD[i]; tl=fT1[i];
1211 if (size <= 2 && i>=fNofMaps/2) {
1212 db=fD[1]; tl=fT1[1];
1214 db=fD[0]; tl=fT1[0];
1215 } // end if size <=2 && i>=fNofMaps/2
1216 } // end if size > 2
1218 //______________________________________________________________________
1219 void AliITSsimulationSDD::SetCompressParam(){
1220 // Sets the compression alogirthm parameters
1223 fResponse->GiveCompressParam(cp);
1224 for (i=0; i<2; i++) {
1231 //______________________________________________________________________
1232 void AliITSsimulationSDD::ReadBaseline(){
1233 // read baseline and noise from file - either a .root file and in this
1234 // case data should be organised in a tree with one entry for each
1235 // module => reading should be done accordingly
1236 // or a classic file and do smth. like this:
1237 // Read baselines and noise for SDD
1241 char input[100], base[100], param[100];
1244 fResponse->Filenames(input,base,param);
1247 filtmp = gSystem->ExpandPathName(fFileName.Data());
1248 FILE *bline = fopen(filtmp,"r");
1252 while(fscanf(bline,"%d %f %f",&pos, &bl, &n) != EOF) {
1254 Error("ReadBaseline","Anode number not in increasing order!",
1257 } // end if pos != na+1
1263 Error("ReadBaseline"," THE BASELINE FILE %s DOES NOT EXIST !",filtmp);
1270 //______________________________________________________________________
1271 Int_t AliITSsimulationSDD::Convert10to8(Int_t signal) const {
1272 // To the 10 to 8 bit lossive compression.
1273 // code from Davide C. and Albert W.
1275 if (signal < 128) return signal;
1276 if (signal < 256) return (128+((signal-128)>>1));
1277 if (signal < 512) return (192+((signal-256)>>3));
1278 if (signal < 1024) return (224+((signal-512)>>4));
1281 //______________________________________________________________________
1282 Int_t AliITSsimulationSDD::Convert8to10(Int_t signal) const {
1283 // Undo the lossive 10 to 8 bit compression.
1284 // code from Davide C. and Albert W.
1285 if (signal < 0 || signal > 255) {
1286 Warning("Convert8to10","out of range signal=%d",signal);
1288 } // end if signal <0 || signal >255
1290 if (signal < 128) return signal;
1292 if (TMath::Odd(signal)) return (128+((signal-128)<<1));
1293 else return (128+((signal-128)<<1)+1);
1294 } // end if signal < 192
1296 if (TMath::Odd(signal)) return (256+((signal-192)<<3)+3);
1297 else return (256+((signal-192)<<3)+4);
1298 } // end if signal < 224
1299 if (TMath::Odd(signal)) return (512+((signal-224)<<4)+7);
1300 return (512+((signal-224)<<4)+8);
1304 //______________________________________________________________________
1305 AliITSMap* AliITSsimulationSDD::HitMap(Int_t i){
1306 //Return the correct map.
1308 return ((i==0)? fHitMap1 : fHitMap2);
1311 //______________________________________________________________________
1312 void AliITSsimulationSDD::ZeroSuppression(const char *option) {
1313 // perform the zero suppresion
1315 if (strstr(option,"2D")) {
1316 //Init2D(); // activate if param change module by module
1318 } else if (strstr(option,"1D")) {
1319 //Init1D(); // activate if param change module by module
1321 } else StoreAllDigits();
1323 //______________________________________________________________________
1324 void AliITSsimulationSDD::Init2D(){
1325 // read in and prepare arrays: fD, fT1, fT2
1326 // savemu[nanodes], savesigma[nanodes]
1327 // read baseline and noise from file - either a .root file and in this
1328 // case data should be organised in a tree with one entry for each
1329 // module => reading should be done accordingly
1330 // or a classic file and do smth. like this ( code from Davide C. and
1332 // Read 2D zero-suppression parameters for SDD
1334 if (!strstr(fParam,"file")) return;
1336 Int_t na,pos,tempTh;
1338 Float_t *savemu = new Float_t [fNofMaps];
1339 Float_t *savesigma = new Float_t [fNofMaps];
1340 char input[100],basel[100],par[100];
1342 Int_t minval = fResponse->MinVal();
1344 fResponse->Filenames(input,basel,par);
1347 filtmp = gSystem->ExpandPathName(fFileName.Data());
1348 FILE *param = fopen(filtmp,"r");
1352 while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) {
1354 Error("Init2D","Anode number not in increasing order!",filtmp);
1356 } // end if pos != na+1
1358 savesigma[na] = sigma;
1359 if ((2.*sigma) < mu) {
1360 fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5);
1363 tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval;
1364 if (tempTh < 0) tempTh=0;
1366 tempTh = (Int_t)floor(mu+3.0*sigma+0.5) - minval;
1367 if (tempTh < 0) tempTh=0;
1372 Error("Init2D","THE FILE %s DOES NOT EXIST !",filtmp);
1379 delete [] savesigma;
1381 //______________________________________________________________________
1382 void AliITSsimulationSDD::Compress2D(){
1383 // simple ITS cluster finder -- online zero-suppression conditions
1386 Int_t minval = fResponse->MinVal();
1387 Bool_t write = fResponse->OutputOption();
1388 Bool_t do10to8 = fResponse->Do10to8();
1389 Int_t nz, nl, nh, low, i, j;
1391 for (i=0; i<fNofMaps; i++) {
1392 CompressionParam(i,db,tl,th);
1397 for (j=0; j<fMaxNofSamples; j++) {
1398 Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j));
1399 signal -= db; // if baseline eq. is done here
1400 if (signal <= 0) {nz++; continue;}
1401 if ((signal - tl) < minval) low++;
1402 if ((signal - th) >= minval) {
1405 FindCluster(i,j,signal,minval,cond);
1407 ((TMath::Abs(fHitMap2->GetSignal(i,j-1))-th)>=minval)){
1408 if(do10to8) signal = Convert10to8(signal);
1409 AddDigit(i,j,signal);
1410 } // end if cond&&j&&()
1411 } else if ((signal - tl) >= minval) nl++;
1412 } // end for j loop time samples
1413 if (write) TreeB()->Fill(nz,nl,nh,low,i+1);
1414 } //end for i loop anodes
1418 sprintf(hname,"TNtuple%d_%d",fModule,fEvent);
1419 TreeB()->Write(hname);
1424 //______________________________________________________________________
1425 void AliITSsimulationSDD::FindCluster(Int_t i,Int_t j,Int_t signal,
1426 Int_t minval,Bool_t &cond){
1427 // Find clusters according to the online 2D zero-suppression algorithm
1428 Bool_t do10to8 = fResponse->Do10to8();
1429 Bool_t high = kFALSE;
1431 fHitMap2->FlagHit(i,j);
1433 // check the online zero-suppression conditions
1435 const Int_t kMaxNeighbours = 4;
1438 Int_t xList[kMaxNeighbours], yList[kMaxNeighbours];
1439 fSegmentation->Neighbours(i,j,&nn,xList,yList);
1441 for (in=0; in<nn; in++) {
1444 if (fHitMap2->TestHit(ix,iy)==kUnused) {
1445 CompressionParam(ix,dbx,tlx,thx);
1446 Int_t qn = (Int_t)(fHitMap2->GetSignal(ix,iy));
1447 qn -= dbx; // if baseline eq. is done here
1448 if ((qn-tlx) < minval) {
1449 fHitMap2->FlagHit(ix,iy);
1452 if ((qn - thx) >= minval) high=kTRUE;
1454 if(do10to8) signal = Convert10to8(signal);
1455 AddDigit(i,j,signal);
1457 if(do10to8) qns = Convert10to8(qn);
1459 if (!high) AddDigit(ix,iy,qns);
1461 if(!high) fHitMap2->FlagHit(ix,iy);
1462 } // end if qn-tlx < minval
1464 } // end for in loop over neighbours
1466 //______________________________________________________________________
1467 void AliITSsimulationSDD::Init1D(){
1468 // this is just a copy-paste of input taken from 2D algo
1469 // Torino people should give input
1470 // Read 1D zero-suppression parameters for SDD
1472 if (!strstr(fParam,"file")) return;
1474 Int_t na,pos,tempTh;
1476 Float_t *savemu = new Float_t [fNofMaps];
1477 Float_t *savesigma = new Float_t [fNofMaps];
1478 char input[100],basel[100],par[100];
1480 Int_t minval = fResponse->MinVal();
1482 fResponse->Filenames(input,basel,par);
1485 // set first the disable and tol param
1488 filtmp = gSystem->ExpandPathName(fFileName.Data());
1489 FILE *param = fopen(filtmp,"r");
1493 fscanf(param,"%d %d %d %d ", &fT2[0], &fT2[1], &fTol[0], &fTol[1]);
1494 while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) {
1496 Error("Init1D","Anode number not in increasing order!",filtmp);
1498 } // end if pos != na+1
1500 savesigma[na]=sigma;
1501 if ((2.*sigma) < mu) {
1502 fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5);
1505 tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval;
1506 if (tempTh < 0) tempTh=0;
1511 Error("Init1D","THE FILE %s DOES NOT EXIST !",filtmp);
1518 delete [] savesigma;
1520 //______________________________________________________________________
1521 void AliITSsimulationSDD::Compress1D(){
1522 // 1D zero-suppression algorithm (from Gianluca A.)
1523 Int_t dis,tol,thres,decr,diff;
1524 UChar_t *str=fStream->Stream();
1526 Bool_t do10to8=fResponse->Do10to8();
1530 for (k=0; k<2; k++) {
1533 for (i=0; i<fNofMaps/2; i++) {
1534 Bool_t firstSignal=kTRUE;
1535 Int_t idx=i+k*fNofMaps/2;
1536 if( !fAnodeFire[idx] ) continue;
1537 CompressionParam(idx,decr,thres);
1538 for (j=0; j<fMaxNofSamples; j++) {
1539 Int_t signal=(Int_t)(fHitMap2->GetSignal(idx,j));
1540 signal -= decr; // if baseline eq.
1541 if(do10to8) signal = Convert10to8(signal);
1542 if (signal <= thres) {
1546 // write diff in the buffer for HuffT
1547 str[counter]=(UChar_t)diff;
1550 } // end if signal <= thres
1552 if (diff > 127) diff=127;
1553 if (diff < -128) diff=-128;
1555 // tol has changed to 8 possible cases ? - one can write
1556 // this if(TMath::Abs(diff)<tol) ... else ...
1557 if(TMath::Abs(diff)<tol) diff=0;
1558 // or keep it as it was before
1560 if (tol==1 && (diff >= -2 && diff <= 1)) diff=0;
1561 if (tol==2 && (diff >= -4 && diff <= 3)) diff=0;
1562 if (tol==3 && (diff >= -16 && diff <= 15)) diff=0;
1564 AddDigit(idx,j,last+diff);
1566 AddDigit(idx,j,signal);
1567 } // end if singal < dis
1569 // write diff in the buffer used to compute Huffman tables
1570 if (firstSignal) str[counter]=(UChar_t)signal;
1571 else str[counter]=(UChar_t)diff;
1575 } // end for j loop time samples
1576 } // end for i loop anodes one half of detector
1580 fStream->CheckCount(counter);
1582 // open file and write out the stream of diff's
1583 static Bool_t open=kTRUE;
1584 static TFile *outFile;
1585 Bool_t write = fResponse->OutputOption();
1586 TDirectory *savedir = gDirectory;
1590 SetFileName("stream.root");
1591 cout<<"filename "<<fFileName<<endl;
1592 outFile=new TFile(fFileName,"recreate");
1593 cout<<"I have opened "<<fFileName<<" file "<<endl;
1600 fStream->ClearStream();
1602 // back to galice.root file
1603 if(savedir) savedir->cd();
1605 //______________________________________________________________________
1606 void AliITSsimulationSDD::StoreAllDigits(){
1607 // if non-zero-suppressed data
1608 Bool_t do10to8 = fResponse->Do10to8();
1609 Int_t i, j, digits[3];
1611 for (i=0; i<fNofMaps; i++) {
1612 for (j=0; j<fMaxNofSamples; j++) {
1613 Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j));
1614 if(do10to8) signal = Convert10to8(signal);
1615 if(do10to8) signal = Convert8to10(signal);
1619 fITS->AddRealDigit(1,digits);
1623 //______________________________________________________________________
1624 void AliITSsimulationSDD::CreateHistograms(Int_t scale){
1625 // Creates histograms of maps for debugging
1628 fHis=new TObjArray(fNofMaps);
1629 for (i=0;i<fNofMaps;i++) {
1630 TString sddName("sdd_");
1632 sprintf(candNum,"%d",i+1);
1633 sddName.Append(candNum);
1634 fHis->AddAt(new TH1F(sddName.Data(),"SDD maps",scale*fMaxNofSamples,
1635 0.,(Float_t) scale*fMaxNofSamples), i);
1638 //______________________________________________________________________
1639 void AliITSsimulationSDD::FillHistograms(){
1640 // fill 1D histograms from map
1644 for( Int_t i=0; i<fNofMaps; i++) {
1645 TH1F *hist =(TH1F *)fHis->UncheckedAt(i);
1646 Int_t nsamples = hist->GetNbinsX();
1647 for( Int_t j=0; j<nsamples; j++) {
1648 Double_t signal=fHitMap2->GetSignal(i,j);
1649 hist->Fill((Float_t)j,signal);
1653 //______________________________________________________________________
1654 void AliITSsimulationSDD::ResetHistograms(){
1655 // Reset histograms for this detector
1658 for (i=0;i<fNofMaps;i++ ) {
1659 if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset();
1662 //______________________________________________________________________
1663 TH1F *AliITSsimulationSDD::GetAnode(Int_t wing, Int_t anode) {
1664 // Fills a histogram from a give anode.
1666 if (!fHis) return 0;
1668 if(wing <=0 || wing > 2) {
1669 Warning("GetAnode","Wrong wing number: %d",wing);
1671 } // end if wing <=0 || wing >2
1672 if(anode <=0 || anode > fNofMaps/2) {
1673 Warning("GetAnode","Wrong anode number: %d",anode);
1675 } // end if ampde <=0 || andoe > fNofMaps/2
1677 Int_t index = (wing-1)*fNofMaps/2 + anode-1;
1678 return (TH1F*)(fHis->At(index));
1680 //______________________________________________________________________
1681 void AliITSsimulationSDD::WriteToFile(TFile *hfile) {
1682 // Writes the histograms to a file
1688 for(i=0; i<fNofMaps; i++) fHis->At(i)->Write(); //fAdcs[i]->Write();
1691 //______________________________________________________________________
1692 Float_t AliITSsimulationSDD::GetNoise() {
1693 // Returns the noise value
1694 //Bool_t do10to8=fResponse->Do10to8();
1695 //noise will always be in the liniar part of the signal
1697 Int_t threshold = fT1[0];
1698 char opt1[20], opt2[20];
1700 fResponse->ParamOptions(opt1,opt2);
1702 char *same = strstr(opt1,"same");
1703 Float_t noise,baseline;
1705 fResponse->GetNoiseParam(noise,baseline);
1707 static Bool_t readfile=kTRUE;
1708 //read baseline and noise from file
1709 if (readfile) ReadBaseline();
1713 TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2");
1714 if(c2) delete c2->GetPrimitive("noisehist");
1715 if(c2) delete c2->GetPrimitive("anode");
1716 else c2=new TCanvas("c2");
1718 c2->SetFillColor(0);
1720 TH1F *noisehist = new TH1F("noisehist","noise",100,0.,(float)2*threshold);
1721 TH1F *anode = new TH1F("anode","Anode Projection",fMaxNofSamples,0.,
1722 (float)fMaxNofSamples);
1724 for (i=0;i<fNofMaps;i++) {
1725 CompressionParam(i,decr,threshold);
1726 if (!same) GetAnodeBaseline(i,baseline,noise);
1728 for (k=0;k<fMaxNofSamples;k++) {
1729 Float_t signal=(Float_t)fHitMap2->GetSignal(i,k);
1730 //if (signal <= (float)threshold) noisehist->Fill(signal-baseline);
1731 if (signal <= (float)threshold) noisehist->Fill(signal);
1732 anode->Fill((float)k,signal);
1737 TF1 *gnoise = new TF1("gnoise","gaus",0.,threshold);
1738 noisehist->Fit("gnoise","RQ");
1741 Float_t mnoise = gnoise->GetParameter(1);
1742 cout << "mnoise : " << mnoise << endl;
1743 Float_t rnoise = gnoise->GetParameter(2);
1744 cout << "rnoise : " << rnoise << endl;
1748 //______________________________________________________________________
1749 void AliITSsimulationSDD::WriteSDigits(){
1750 // Fills the Summable digits Tree
1751 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
1753 for( Int_t i=0; i<fNofMaps; i++ ) {
1754 if( !fAnodeFire[i] ) continue;
1755 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
1756 Double_t sig = fHitMap2->GetSignal( i, j );
1758 Int_t jdx = j*fScaleSize;
1759 Int_t index = fpList->GetHitIndex( i, j );
1760 AliITSpListItem pItemTmp2( fModule, index, 0. );
1761 // put the fScaleSize analog digits in only one
1762 for( Int_t ik=0; ik<fScaleSize; ik++ ) {
1763 AliITSpListItem *pItemTmp = fpList->GetpListItem( i, jdx+ik );
1764 if( pItemTmp == 0 ) continue;
1765 pItemTmp2.Add( pItemTmp );
1767 pItemTmp2.AddSignalAfterElect( fModule, index, sig );
1768 pItemTmp2.AddNoise( fModule, index, fHitNoiMap2->GetSignal( i, j ) );
1769 aliITS->AddSumDigit( pItemTmp2 );
1770 } // end if (sig > 0.2)
1775 //______________________________________________________________________
1776 void AliITSsimulationSDD::Print() {
1777 // Print SDD simulation Parameters
1779 cout << "**************************************************" << endl;
1780 cout << " Silicon Drift Detector Simulation Parameters " << endl;
1781 cout << "**************************************************" << endl;
1782 cout << "Flag for Perpendicular tracks: " << (Int_t) fFlag << endl;
1783 cout << "Flag for noise checking: " << (Int_t) fCheckNoise << endl;
1784 cout << "Flag to switch off electronics: " << (Int_t) fDoFFT << endl;
1785 cout << "Number pf Anodes used: " << fNofMaps << endl;
1786 cout << "Number of Time Samples: " << fMaxNofSamples << endl;
1787 cout << "Scale size factor: " << fScaleSize << endl;
1788 cout << "**************************************************" << endl;