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 #include <Riostream.h>
25 #include <TStopwatch.h>
37 #include "AliITShit.h"
38 #include "AliITSdigit.h"
39 #include "AliITSmodule.h"
40 #include "AliITSpList.h"
41 #include "AliITSMapA1.h"
42 #include "AliITSMapA2.h"
43 #include "AliITSetfSDD.h"
44 #include "AliITSRawData.h"
45 #include "AliITSHuffman.h"
46 #include "AliITSgeom.h"
47 #include "AliITSsegmentation.h"
48 #include "AliITSresponse.h"
49 #include "AliITSsegmentationSDD.h"
50 #include "AliITSresponseSDD.h"
51 #include "AliITSsimulationSDD.h"
53 ClassImp(AliITSsimulationSDD)
54 ////////////////////////////////////////////////////////////////////////
56 // Written by Piergiorgio Cerello
59 // AliITSsimulationSDD is the simulation of SDDs.
63 <img src="picts/ITS/AliITShit_Class_Diagram.gif">
66 <font size=+2 color=red>
67 <p>This show the relasionships between the ITS hit class and the rest of Aliroot.
72 //______________________________________________________________________
73 Int_t power(Int_t b, Int_t e) {
74 // compute b to the e power, where both b and e are Int_ts.
77 for(i=0; i<e; i++) power *= b;
80 //______________________________________________________________________
81 void FastFourierTransform(AliITSetfSDD *alisddetf,Double_t *real,
82 Double_t *imag,Int_t direction) {
83 // Do a Fast Fourier Transform
85 Int_t samples = alisddetf->GetSamples();
86 Int_t l = (Int_t) ((log((Float_t) samples)/log(2.))+0.5);
89 Int_t m2 = samples/m1;
92 for(j=0; j<samples; j += m1) {
94 for(k=j; k<= j+m-1; k++) {
95 Double_t wsr = alisddetf->GetWeightReal(p);
96 Double_t wsi = alisddetf->GetWeightImag(p);
97 if(direction == -1) wsi = -wsi;
98 Double_t xr = *(real+k+m);
99 Double_t xi = *(imag+k+m);
100 *(real+k+m) = wsr*(*(real+k)-xr) - wsi*(*(imag+k)-xi);
101 *(imag+k+m) = wsr*(*(imag+k)-xi) + wsi*(*(real+k)-xr);
112 for(j=0; j<samples; j++) {
116 for(i1=1; i1<=l; i1++) {
119 p = p + p + j2 - j1 - j1;
122 Double_t xr = *(real+j);
123 Double_t xi = *(imag+j);
124 *(real+j) = *(real+p);
125 *(imag+j) = *(imag+p);
130 if(direction == -1) {
131 for(i=0; i<samples; i++) {
132 *(real+i) /= samples;
133 *(imag+i) /= samples;
135 } // end if direction == -1
138 //______________________________________________________________________
139 AliITSsimulationSDD::AliITSsimulationSDD() {
140 // Default constructor
161 SetPerpendTracksFlag();
166 //______________________________________________________________________
167 AliITSsimulationSDD::AliITSsimulationSDD(AliITSsimulationSDD &source) :
168 AliITSsimulation(source){
169 // Copy constructor to satify Coding roules only.
171 if(this==&source) return;
172 Error("AliITSsimulationSSD","Not allowed to make a copy of "
173 "AliITSsimulationSDD Using default creater instead");
174 AliITSsimulationSDD();
176 //______________________________________________________________________
177 AliITSsimulationSDD& AliITSsimulationSDD::operator=(AliITSsimulationSDD &src){
178 // Assignment operator to satify Coding roules only.
180 if(this==&src) return *this;
181 Error("AliITSsimulationSSD","Not allowed to make a = with "
182 "AliITSsimulationSDD Using default creater instead");
185 //______________________________________________________________________
186 AliITSsimulationSDD::AliITSsimulationSDD(AliITSsegmentation *seg,
187 AliITSresponse *resp){
188 // Standard Constructor
209 Init((AliITSsegmentationSDD*)seg,(AliITSresponseSDD*)resp);
211 //______________________________________________________________________
212 void AliITSsimulationSDD::Init(AliITSsegmentationSDD *seg,
213 AliITSresponseSDD *resp){
214 // Standard Constructor
219 SetPerpendTracksFlag();
224 fpList = new AliITSpList( fSegmentation->Npz(),
225 fScaleSize*fSegmentation->Npx() );
226 fHitSigMap2 = new AliITSMapA2(fSegmentation,fScaleSize,1);
227 fHitNoiMap2 = new AliITSMapA2(fSegmentation,fScaleSize,1);
228 fHitMap2 = fHitSigMap2;
230 fNofMaps = fSegmentation->Npz();
231 fMaxNofSamples = fSegmentation->Npx();
232 fAnodeFire = new Bool_t [fNofMaps];
234 Float_t sddLength = fSegmentation->Dx();
235 Float_t sddWidth = fSegmentation->Dz();
238 Float_t anodePitch = fSegmentation->Dpz(dummy);
239 Double_t timeStep = (Double_t)fSegmentation->Dpx(dummy);
240 Float_t driftSpeed = fResponse->DriftSpeed();
242 if(anodePitch*(fNofMaps/2) > sddWidth) {
243 Warning("AliITSsimulationSDD",
244 "Too many anodes %d or too big pitch %f \n",
245 fNofMaps/2,anodePitch);
248 if(timeStep*fMaxNofSamples < sddLength/driftSpeed) {
249 Error("AliITSsimulationSDD",
250 "Time Interval > Allowed Time Interval: exit\n");
254 fElectronics = new AliITSetfSDD(timeStep/fScaleSize,
255 fResponse->Electronics());
257 char opt1[20], opt2[20];
258 fResponse->ParamOptions(opt1,opt2);
260 char *same = strstr(opt1,"same");
265 fNoise.Set(fNofMaps);
266 fBaseline.Set(fNofMaps);
269 const char *kopt=fResponse->ZeroSuppOption();
270 if (strstr(fParam.Data(),"file") ) {
273 if (strstr(kopt,"2D")) {
276 Init2D(); // desactivate if param change module by module
277 } else if(strstr(kopt,"1D")) {
280 Init1D(); // desactivate if param change module by module
288 } // end if else strstr
290 Bool_t write = fResponse->OutputOption();
291 if(write && strstr(kopt,"2D")) MakeTreeB();
293 // call here if baseline does not change by module
296 fITS = (AliITS*)gAlice->GetModule("ITS");
297 Int_t size = fNofMaps*fMaxNofSamples;
298 fStream = new AliITSInStream(size);
300 fInZR = new Double_t [fScaleSize*fMaxNofSamples];
301 fInZI = new Double_t [fScaleSize*fMaxNofSamples];
302 fOutZR = new Double_t [fScaleSize*fMaxNofSamples];
303 fOutZI = new Double_t [fScaleSize*fMaxNofSamples];
306 //______________________________________________________________________
307 AliITSsimulationSDD::~AliITSsimulationSDD() {
322 if(fTreeB) delete fTreeB;
323 if(fInZR) delete [] fInZR;
324 if(fInZI) delete [] fInZI;
325 if(fOutZR) delete [] fOutZR;
326 if(fOutZI) delete [] fOutZI;
327 if(fAnodeFire) delete [] fAnodeFire;
329 //______________________________________________________________________
330 void AliITSsimulationSDD::InitSimulationModule( Int_t module, Int_t event ) {
331 // create maps to build the lists of tracks for each summable digit
335 memset(fAnodeFire,0,sizeof(Bool_t)*fNofMaps);
337 //______________________________________________________________________
338 void AliITSsimulationSDD::ClearMaps() {
341 fHitSigMap2->ClearMap();
342 fHitNoiMap2->ClearMap();
344 //______________________________________________________________________
345 void AliITSsimulationSDD::SDigitiseModule( AliITSmodule *mod, Int_t md, Int_t ev){
346 // digitize module using the "slow" detector simulator creating
349 TObjArray *fHits = mod->GetHits();
350 Int_t nhits = fHits->GetEntriesFast();
353 InitSimulationModule( md, ev );
354 HitsToAnalogDigits( mod );
355 ChargeToSignal( kFALSE ); // - Process signal without add noise
356 fHitMap2 = fHitNoiMap2; // - Swap to noise map
357 ChargeToSignal( kTRUE ); // - Process only noise
358 fHitMap2 = fHitSigMap2; // - Return to signal map
362 //______________________________________________________________________
363 Bool_t AliITSsimulationSDD::AddSDigitsToModule( TClonesArray *pItemArray, Int_t mask ) {
364 // Add Summable digits to module maps.
365 Int_t nItems = pItemArray->GetEntries();
366 Double_t maxadc = fResponse->MaxAdc();
367 //Bool_t sig = kFALSE;
369 // cout << "Adding "<< nItems <<" SDigits to module " << fModule << endl;
370 for( Int_t i=0; i<nItems; i++ ) {
371 AliITSpListItem * pItem = (AliITSpListItem *)(pItemArray->At( i ));
372 if( pItem->GetModule() != fModule ) {
373 Error( "AliITSsimulationSDD",
374 "Error reading, SDigits module %d != current module %d: exit\n",
375 pItem->GetModule(), fModule );
379 // if(pItem->GetSignal()>0.0 ) sig = kTRUE;
381 fpList->AddItemTo( mask, pItem ); // Add SignalAfterElect + noise
382 AliITSpListItem * pItem2 = fpList->GetpListItem( pItem->GetIndex() );
383 Double_t sigAE = pItem2->GetSignalAfterElect();
384 if( sigAE >= maxadc ) sigAE = maxadc-1; // avoid overflow signal
387 fpList->GetMapIndex( pItem->GetIndex(), ia, it );
388 fHitMap2->SetHit( ia, it, sigAE );
389 fAnodeFire[ia] = kTRUE;
393 //______________________________________________________________________
394 void AliITSsimulationSDD::FinishSDigitiseModule() {
395 // digitize module using the "slow" detector simulator from
396 // the sum of summable digits.
400 //______________________________________________________________________
401 void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
402 // create maps to build the lists of tracks for each digit
404 TObjArray *fHits = mod->GetHits();
405 Int_t nhits = fHits->GetEntriesFast();
407 InitSimulationModule( md, ev );
409 if( !nhits && fCheckNoise ) {
410 ChargeToSignal( kTRUE ); // process noise
417 HitsToAnalogDigits( mod );
418 ChargeToSignal( kTRUE ); // process signal + noise
420 for( Int_t i=0; i<fNofMaps; i++ ) {
421 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
422 Int_t jdx = j*fScaleSize;
423 Int_t index = fpList->GetHitIndex( i, j );
424 AliITSpListItem pItemTmp2( fModule, index, 0. );
425 // put the fScaleSize analog digits in only one
426 for( Int_t ik=0; ik<fScaleSize; ik++ ) {
427 AliITSpListItem *pItemTmp = fpList->GetpListItem( i, jdx+ik );
428 if( pItemTmp == 0 ) continue;
429 pItemTmp2.Add( pItemTmp );
431 fpList->DeleteHit( i, j );
432 fpList->AddItemTo( 0, &pItemTmp2 );
439 //______________________________________________________________________
440 void AliITSsimulationSDD::FinishDigits() {
441 // introduce the electronics effects and do zero-suppression if required
444 if( fCrosstalkFlag ) ApplyCrosstalk();
446 const char *kopt = fResponse->ZeroSuppOption();
447 ZeroSuppression( kopt );
449 //______________________________________________________________________
450 void AliITSsimulationSDD::HitsToAnalogDigits( AliITSmodule *mod ) {
451 // create maps to build the lists of tracks for each digit
453 TObjArray *fHits = mod->GetHits();
454 Int_t nhits = fHits->GetEntriesFast();
455 // Int_t arg[6] = {0,0,0,0,0,0};
457 Int_t nofAnodes = fNofMaps/2;
458 Float_t sddLength = fSegmentation->Dx();
459 Float_t sddWidth = fSegmentation->Dz();
460 Float_t anodePitch = fSegmentation->Dpz(dummy);
461 Float_t timeStep = fSegmentation->Dpx(dummy);
462 Float_t driftSpeed = fResponse->DriftSpeed();
463 Float_t maxadc = fResponse->MaxAdc();
464 Float_t topValue = fResponse->DynamicRange();
465 Float_t cHloss = fResponse->ChargeLoss();
466 Float_t norm = maxadc/topValue;
467 Float_t dfCoeff, s1; fResponse->DiffCoeff(dfCoeff,s1); // Signal 2d Shape
468 Double_t eVpairs = 3.6; // electron pair energy eV.
469 Float_t nsigma = fResponse->NSigmaIntegration(); //
470 Int_t nlookups = fResponse->GausNLookUp(); //
471 Float_t jitter = ((AliITSresponseSDD*)fResponse)->JitterError(); //
473 // Piergiorgio's part (apart for few variables which I made float
474 // when i thought that can be done
475 // Fill detector maps with GEANT hits
476 // loop over hits in the module
478 const Float_t kconv = 1.0e+6; // GeV->KeV
480 Int_t hitDetector; // detector number (lay,lad,hitDetector)
481 Int_t iWing; // which detector wing/side.
482 Int_t detector; // 2*(detector-1)+iWing
483 Int_t ii,kk,ka,kt; // loop indexs
484 Int_t ia,it,index; // sub-pixel integration indexies
485 Int_t iAnode; // anode number.
486 Int_t timeSample; // time buckett.
487 Int_t anodeWindow; // anode direction charge integration width
488 Int_t timeWindow; // time direction charge integration width
489 Int_t jamin,jamax; // anode charge integration window
490 Int_t jtmin,jtmax; // time charge integration window
491 Int_t ndiv; // Anode window division factor.
492 Int_t nsplit; // the number of splits in anode and time windows==1.
493 Int_t nOfSplits; // number of times track length is split into
494 Float_t nOfSplitsF; // Floating point version of nOfSplits.
495 Float_t kkF; // Floating point version of loop index kk.
496 Float_t pathInSDD; // Track length in SDD.
497 Float_t drPath; // average position of track in detector. in microns
498 Float_t drTime; // Drift time
499 Float_t nmul; // drift time window multiplication factor.
500 Float_t avDrft; // x position of path length segment in cm.
501 Float_t avAnode; // Anode for path length segment in Anode number (float)
502 Float_t xAnode; // Floating point anode number.
503 Float_t driftPath; // avDrft in microns.
504 Float_t width; // width of signal at anodes.
505 Double_t depEnergy; // Energy deposited in this GEANT step.
506 Double_t xL[3],dxL[3]; // local hit coordinates and diff.
507 Double_t sigA; // sigma of signal at anode.
508 Double_t sigT; // sigma in time/drift direction for track segment
509 Double_t aStep,aConst; // sub-pixel size and offset anode
510 Double_t tStep,tConst; // sub-pixel size and offset time
511 Double_t amplitude; // signal amplitude for track segment in nanoAmpere
512 Double_t chargeloss; // charge loss for track segment.
513 Double_t anodeAmplitude; // signal amplitude in anode direction
514 Double_t aExpo; // exponent of Gaussian anode direction
515 Double_t timeAmplitude; // signal amplitude in time direction
516 Double_t tExpo; // exponent of Gaussian time direction
517 // Double_t tof; // Time of flight in ns of this step.
519 for(ii=0; ii<nhits; ii++) {
520 if(!mod->LineSegmentL(ii,xL[0],dxL[0],xL[1],dxL[1],xL[2],dxL[2],
521 depEnergy,itrack)) continue;
522 xL[0] += 0.0001*gRandom->Gaus( 0, jitter ); //
524 hitDetector = mod->GetDet();
525 //tof = 1.E+09*(mod->GetHit(ii)->GetTOF()); // tof in ns.
526 //if(tof>sddLength/driftSpeed) continue; // hit happed too late.
528 // scale path to simulate a perpendicular track
529 // continue if the particle did not lose energy
530 // passing through detector
533 Warning("HitsToAnalogDigits",
534 "fTrack = %d hit=%d module=%d This particle has"
535 " passed without losing energy!",
536 itrack,ii,mod->GetIndex());
539 } // end if !depEnergy
541 pathInSDD = TMath::Sqrt(dxL[0]*dxL[0]+dxL[1]*dxL[1]+dxL[2]*dxL[2]);
543 if (fFlag && pathInSDD) { depEnergy *= (0.03/pathInSDD); }
544 drPath = 10000.*(dxL[0]+2.*xL[0])*0.5;
545 if(drPath < 0) drPath = -drPath;
546 drPath = sddLength-drPath;
548 if(GetDebug()){ // this should be fixed at geometry level
549 Warning("HitsToAnalogDigits",
550 "negative drift path drPath=%e sddLength=%e dxL[0]=%e "
552 drPath,sddLength,dxL[0],xL[0]);
555 } // end if drPath < 0
557 // Compute number of segments to brake step path into
558 drTime = drPath/driftSpeed; // Drift Time
559 sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);// Sigma along the anodes
560 // calcuate the number of time the path length should be split into.
561 nOfSplits = (Int_t) (1. + 10000.*pathInSDD/sigA);
562 if(fFlag) nOfSplits = 1;
564 // loop over path segments, init. some variables.
565 depEnergy /= nOfSplits;
566 nOfSplitsF = (Float_t) nOfSplits;
567 for(kk=0;kk<nOfSplits;kk++) { // loop over path segments
568 kkF = (Float_t) kk + 0.5;
569 avDrft = xL[0]+dxL[0]*kkF/nOfSplitsF;
570 avAnode = xL[2]+dxL[2]*kkF/nOfSplitsF;
571 driftPath = 10000.*avDrft;
573 iWing = 2; // Assume wing is 2
574 if(driftPath < 0) { // if wing is not 2 it is 1.
576 driftPath = -driftPath;
577 } // end if driftPath < 0
578 driftPath = sddLength-driftPath;
579 detector = 2*(hitDetector-1) + iWing;
581 if(GetDebug()){ // this should be fixed at geometry level
582 Warning("HitsToAnalogDigits","negative drift path "
583 "driftPath=%e sddLength=%e avDrft=%e dxL[0]=%e "
584 "xL[0]=%e",driftPath,sddLength,avDrft,dxL[0],xL[0]);
587 } // end if driftPath < 0
590 drTime = driftPath/driftSpeed; // drift time for segment.
591 timeSample = (Int_t) (fScaleSize*drTime/timeStep + 1);
592 // compute time Sample including tof information. The tof only
593 // effects the time of the signal is recoreded and not the
595 // timeSample = (Int_t) (fScaleSize*(drTime+tof)/timeStep + 1);
596 if(timeSample > fScaleSize*fMaxNofSamples) {
597 Warning("HitsToAnalogDigits","Wrong Time Sample: %e",
600 } // end if timeSample > fScaleSize*fMaxNoofSamples
603 xAnode = 10000.*(avAnode)/anodePitch + nofAnodes/2; // +1?
604 if(xAnode*anodePitch > sddWidth || xAnode*anodePitch < 0.)
605 Warning("HitsToAnalogDigits",
606 "Exceedubg sddWidth=%e Z = %e",
607 sddWidth,xAnode*anodePitch);
608 iAnode = (Int_t) (1.+xAnode); // xAnode?
609 if(iAnode < 1 || iAnode > nofAnodes) {
610 Warning("HitToAnalogDigits","Wrong iAnode: 1<%d>%d",
613 } // end if iAnode < 1 || iAnode > nofAnodes
615 // store straight away the particle position in the array
616 // of particles and take idhit=ii only when part is entering (this
617 // requires FillModules() in the macro for analysis) :
619 // Sigma along the anodes for track segment.
620 sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);
621 sigT = sigA/driftSpeed;
622 // Peak amplitude in nanoAmpere
623 amplitude = fScaleSize*160.*depEnergy/
624 (timeStep*eVpairs*2.*acos(-1.)*sigT*sigA);
625 amplitude *= timeStep/25.; // WARNING!!!!! Amplitude scaling to
626 // account for clock variations
627 // (reference value: 40 MHz)
628 chargeloss = 1.-cHloss*driftPath/1000;
629 amplitude *= chargeloss;
630 width = 2.*nsigma/(nlookups-1);
638 } // end if drTime > 1200.
640 nsplit = 4; // hard-wired //nsplit=4;nsplit = (nsplit+1)/2*2;
641 // Sub-pixel size see computation of aExpo and tExpo.
642 aStep = anodePitch/(nsplit*fScaleSize*sigA);
643 aConst = xAnode*anodePitch/sigA;
644 tStep = timeStep/(nsplit*fScaleSize*sigT);
645 tConst = drTime/sigT;
646 // Define SDD window corresponding to the hit
647 anodeWindow = (Int_t)(fScaleSize*nsigma*sigA/anodePitch+1);
648 timeWindow = (Int_t) (fScaleSize*nsigma*sigT/timeStep+1.);
649 jamin = (iAnode - anodeWindow/ndiv - 1)*fScaleSize*nsplit +1;
650 jamax = (iAnode + anodeWindow/ndiv)*fScaleSize*nsplit;
651 if(jamin <= 0) jamin = 1;
652 if(jamax > fScaleSize*nofAnodes*nsplit)
653 jamax = fScaleSize*nofAnodes*nsplit;
654 // jtmin and jtmax are Hard-wired
655 jtmin = (Int_t)(timeSample-timeWindow*nmul-1)*nsplit+1;
656 jtmax = (Int_t)(timeSample+timeWindow*nmul)*nsplit;
657 if(jtmin <= 0) jtmin = 1;
658 if(jtmax > fScaleSize*fMaxNofSamples*nsplit)
659 jtmax = fScaleSize*fMaxNofSamples*nsplit;
660 // Spread the charge in the anode-time window
661 for(ka=jamin; ka <=jamax; ka++) {
662 ia = (ka-1)/(fScaleSize*nsplit) + 1;
664 Warning("HitsToAnalogDigits","ia < 1: ");
667 if(ia > nofAnodes) ia = nofAnodes;
668 aExpo = (aStep*(ka-0.5)-aConst);
669 if(TMath::Abs(aExpo) > nsigma) anodeAmplitude = 0.;
671 dummy = (Int_t) ((aExpo+nsigma)/width);
672 anodeAmplitude = amplitude*fResponse->GausLookUp(dummy);
673 } // end if TMath::Abs(aEspo) > nsigma
674 // index starts from 0
675 index = ((detector+1)%2)*nofAnodes+ia-1;
676 if(anodeAmplitude) for(kt=jtmin; kt<=jtmax; kt++) {
677 it = (kt-1)/nsplit+1; // it starts from 1
679 Warning("HitsToAnalogDigits","it < 1:");
682 if(it>fScaleSize*fMaxNofSamples)
683 it = fScaleSize*fMaxNofSamples;
684 tExpo = (tStep*(kt-0.5)-tConst);
685 if(TMath::Abs(tExpo) > nsigma) timeAmplitude = 0.;
687 dummy = (Int_t) ((tExpo+nsigma)/width);
688 timeAmplitude = anodeAmplitude*
689 fResponse->GausLookUp(dummy);
690 } // end if TMath::Abs(tExpo) > nsigma
691 // build the list of Sdigits for this module
694 // arg[2] = itrack; // track number
695 // arg[3] = ii-1; // hit number.
696 timeAmplitude *= norm;
698 // ListOfFiredCells(arg,timeAmplitude,alst,padr);
699 Double_t charge = timeAmplitude;
700 charge += fHitMap2->GetSignal(index,it-1);
701 fHitMap2->SetHit(index, it-1, charge);
702 fpList->AddSignal(index,it-1,itrack,ii-1,
703 mod->GetIndex(),timeAmplitude);
704 fAnodeFire[index] = kTRUE;
705 } // end if anodeAmplitude and loop over time in window
706 } // loop over anodes in window
707 } // end loop over "sub-hits"
708 } // end loop over hits
712 //______________________________________________________________________
713 void AliITSsimulationSDD::ListOfFiredCells(Int_t *arg,Double_t timeAmplitude,
714 TObjArray *alist,TClonesArray *padr){
715 // Returns the list of "fired" cells.
717 Int_t index = arg[0];
719 Int_t idtrack = arg[2];
720 Int_t idhit = arg[3];
721 Int_t counter = arg[4];
722 Int_t countadr = arg[5];
723 Double_t charge = timeAmplitude;
724 charge += fHitMap2->GetSignal(index,ik-1);
725 fHitMap2->SetHit(index, ik-1, charge);
728 Int_t it = (Int_t)((ik-1)/fScaleSize);
731 digits[2] = (Int_t)timeAmplitude;
733 if (idtrack >= 0) phys = (Float_t)timeAmplitude;
736 Double_t cellcharge = 0.;
737 AliITSTransientDigit* pdigit;
738 // build the list of fired cells and update the info
739 if (!fHitMap1->TestHit(index, it)) {
740 new((*padr)[countadr++]) TVector(3);
741 TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
742 trinfo(0) = (Float_t)idtrack;
743 trinfo(1) = (Float_t)idhit;
744 trinfo(2) = (Float_t)timeAmplitude;
746 alist->AddAtAndExpand(new AliITSTransientDigit(phys,digits),counter);
747 fHitMap1->SetHit(index, it, counter);
749 pdigit=(AliITSTransientDigit*)alist->At(alist->GetLast());
751 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
752 trlist->Add(&trinfo);
754 pdigit = (AliITSTransientDigit*) fHitMap1->GetHit(index, it);
755 for(Int_t kk=0;kk<fScaleSize;kk++) {
756 cellcharge += fHitMap2->GetSignal(index,fScaleSize*it+kk);
759 (*pdigit).fSignal = (Int_t)cellcharge;
760 (*pdigit).fPhysics += phys;
761 // update list of tracks
762 TObjArray* trlist = (TObjArray*)pdigit->TrackList();
763 Int_t lastentry = trlist->GetLast();
764 TVector *ptrkp = (TVector*)trlist->At(lastentry);
765 TVector &trinfo = *ptrkp;
766 Int_t lasttrack = Int_t(trinfo(0));
767 Float_t lastcharge=(trinfo(2));
768 if (lasttrack==idtrack ) {
769 lastcharge += (Float_t)timeAmplitude;
770 trlist->RemoveAt(lastentry);
771 trinfo(0) = lasttrack;
773 trinfo(2) = lastcharge;
774 trlist->AddAt(&trinfo,lastentry);
776 new((*padr)[countadr++]) TVector(3);
777 TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
778 trinfo(0) = (Float_t)idtrack;
779 trinfo(1) = (Float_t)idhit;
780 trinfo(2) = (Float_t)timeAmplitude;
781 trlist->Add(&trinfo);
782 } // end if lasttrack==idtrack
785 // check the track list - debugging
786 Int_t trk[20], htrk[20];
788 Int_t nptracks = trlist->GetEntriesFast();
791 for (tr=0;tr<nptracks;tr++) {
792 TVector *pptrkp = (TVector*)trlist->At(tr);
793 TVector &pptrk = *pptrkp;
794 trk[tr] = Int_t(pptrk(0));
795 htrk[tr] = Int_t(pptrk(1));
796 chtrk[tr] = (pptrk(2));
797 cout << "nptracks "<<nptracks << endl;
803 // update counter and countadr for next call.
809 //____________________________________________
810 void AliITSsimulationSDD::AddDigit( Int_t i, Int_t j, Int_t signal ) {
812 Int_t size = AliITSdigitSPD::GetNTracks();
814 Int_t * tracks = new Int_t[size];
815 Int_t * hits = new Int_t[size];
817 Float_t * charges = new Float_t[size];
819 // if( fResponse->Do10to8() ) signal = Convert8to10( signal );
824 AliITSpListItem *pItem = fpList->GetpListItem( i, j );
827 for( Int_t l=0; l<size; l++ ) {
833 Int_t idtrack = pItem->GetTrack( 0 );
834 if( idtrack >= 0 ) phys = pItem->GetSignal();
837 for( Int_t l=0; l<size; l++ ) if(l<pItem->GetMaxKept()) {
838 tracks[l] = pItem->GetTrack( l );
839 hits[l] = pItem->GetHit( l );
840 charges[l] = pItem->GetSignal( l );
848 fITS->AddSimDigit( 1, phys, digits, tracks, hits, charges );
854 //______________________________________________________________________
855 void AliITSsimulationSDD::ChargeToSignal(Bool_t bAddNoise) {
856 // add baseline, noise, electronics and ADC saturation effects
858 char opt1[20], opt2[20];
859 fResponse->ParamOptions(opt1,opt2);
860 char *read = strstr(opt1,"file");
861 Float_t baseline, noise;
864 static Bool_t readfile=kTRUE;
865 //read baseline and noise from file
866 if (readfile) ReadBaseline();
868 } else fResponse->GetNoiseParam(noise,baseline);
872 Float_t maxadc = fResponse->MaxAdc();
874 for (i=0;i<fNofMaps;i++) {
875 if( !fAnodeFire[i] ) continue;
876 if (read && i<fNofMaps) GetAnodeBaseline(i,baseline,noise);
877 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
878 fInZR[k] = fHitMap2->GetSignal(i,k);
880 contrib = (baseline + noise*gRandom->Gaus());
884 for(k=0; k<fMaxNofSamples; k++) {
885 Double_t newcont = 0.;
886 Double_t maxcont = 0.;
887 for(kk=0;kk<fScaleSize;kk++) {
888 newcont = fInZR[fScaleSize*k+kk];
889 if(newcont > maxcont) maxcont = newcont;
892 if (newcont >= maxadc) newcont = maxadc -1;
893 if(newcont >= baseline){
894 Warning("","newcont=%d>=baseline=%d",newcont,baseline);
897 fHitMap2->SetHit(i,k,newcont);
899 } // end for i loop over anodes
903 for (i=0;i<fNofMaps;i++) {
904 if( !fAnodeFire[i] ) continue;
905 if (read && i<fNofMaps) GetAnodeBaseline(i,baseline,noise);
906 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
907 fInZR[k] = fHitMap2->GetSignal(i,k);
909 contrib = (baseline + noise*gRandom->Gaus());
914 FastFourierTransform(fElectronics,&fInZR[0],&fInZI[0],1);
915 for(k=0; k<fScaleSize*fMaxNofSamples; k++) {
916 Double_t rw = fElectronics->GetTraFunReal(k);
917 Double_t iw = fElectronics->GetTraFunImag(k);
918 fOutZR[k] = fInZR[k]*rw - fInZI[k]*iw;
919 fOutZI[k] = fInZR[k]*iw + fInZI[k]*rw;
921 FastFourierTransform(fElectronics,&fOutZR[0],&fOutZI[0],-1);
922 for(k=0; k<fMaxNofSamples; k++) {
923 Double_t newcont1 = 0.;
924 Double_t maxcont1 = 0.;
925 for(kk=0;kk<fScaleSize;kk++) {
926 newcont1 = fOutZR[fScaleSize*k+kk];
927 if(newcont1 > maxcont1) maxcont1 = newcont1;
930 if (newcont1 >= maxadc) newcont1 = maxadc -1;
931 fHitMap2->SetHit(i,k,newcont1);
933 } // end for i loop over anodes
936 //____________________________________________________________________
937 void AliITSsimulationSDD::ApplyDeadChannels() {
938 // Set dead channel signal to zero
939 AliITSresponseSDD * response = (AliITSresponseSDD *)fResponse;
942 if( response->GetDeadModules() == 0 &&
943 response->GetDeadChips() == 0 &&
944 response->GetDeadChannels() == 0 )
947 static AliITS *iTS = (AliITS*)gAlice->GetModule( "ITS" );
949 Int_t fMaxNofSamples = fSegmentation->Npx();
950 AliITSgeom *geom = iTS->GetITSgeom();
951 Int_t firstSDDMod = geom->GetStartDet( 1 );
953 for( Int_t j=0; j<2; j++ ) {
954 Int_t mod = (fModule-firstSDDMod)*2 + j;
955 for( Int_t u=0; u<response->Chips(); u++ )
956 for( Int_t v=0; v<response->Channels(); v++ ) {
957 Float_t Gain = response->Gain( mod, u, v );
958 for( Int_t k=0; k<fMaxNofSamples; k++ ) {
959 Int_t i = j*response->Chips()*response->Channels() +
960 u*response->Channels() +
962 Double_t signal = Gain * fHitMap2->GetSignal( i, k );
963 fHitMap2->SetHit( i, k, signal ); ///
968 //______________________________________________________________________
969 void AliITSsimulationSDD::ApplyCrosstalk() {
970 // function add the crosstalk effect to signal
971 // temporal function, should be checked...!!!
973 Int_t fNofMaps = fSegmentation->Npz();
974 Int_t fMaxNofSamples = fSegmentation->Npx();
976 // create and inizialice crosstalk map
977 Float_t* ctk = new Float_t[fNofMaps*fMaxNofSamples+1];
979 Error( "ApplyCrosstalk", "no memory for temporal map: exit \n" );
982 memset( ctk, 0, sizeof(Float_t)*(fNofMaps*fMaxNofSamples+1) );
984 Float_t noise, baseline;
985 fResponse->GetNoiseParam( noise, baseline );
987 for( Int_t z=0; z<fNofMaps; z++ ) {
993 for( Int_t l=0; l<fMaxNofSamples; l++ ) {
994 Float_t fadc = (Float_t)fHitMap2->GetSignal( z, l );
995 if( fadc > baseline ) {
996 if( on == kFALSE && l<fMaxNofSamples-4 ) {
997 Float_t fadc1 = (Float_t)fHitMap2->GetSignal( z, l+1 );
998 if( fadc1 < fadc ) continue;
1005 else { // end fadc > baseline
1009 // make smooth derivative
1010 Float_t* dev = new Float_t[fMaxNofSamples+1];
1011 memset( dev, 0, sizeof(Float_t)*(fMaxNofSamples+1) );
1013 Error( "ApplyCrosstalk",
1014 "no memory for temporal array: exit \n" );
1017 for( Int_t i=tstart; i<tstop; i++ ) {
1018 if( i > 2 && i < fMaxNofSamples-2 )
1019 dev[i] = -0.2*fHitMap2->GetSignal( z,i-2 )
1020 -0.1*fHitMap2->GetSignal( z,i-1 )
1021 +0.1*fHitMap2->GetSignal( z,i+1 )
1022 +0.2*fHitMap2->GetSignal( z,i+2 );
1025 // add crosstalk contribution to neibourg anodes
1026 for( Int_t i=tstart; i<tstop; i++ ) {
1027 Int_t anode = z - 1;
1028 Int_t i1 = (Int_t)((i-tstart)*.61+tstart+0.5); //
1029 Float_t ctktmp = -dev[i1] * 0.25;
1031 ctk[anode*fMaxNofSamples+i] += ctktmp;
1034 if( anode < fNofMaps ) {
1035 ctk[anode*fMaxNofSamples+i] += ctktmp;
1040 } // if( nTsteps > 2 )
1042 } // if( on == kTRUE )
1047 for( Int_t a=0; a<fNofMaps; a++ )
1048 for( Int_t t=0; t<fMaxNofSamples; t++ ) {
1049 Float_t signal = fHitMap2->GetSignal( a, t ) + ctk[a*fMaxNofSamples+t];
1050 fHitMap2->SetHit( a, t, signal );
1055 //______________________________________________________________________
1056 void AliITSsimulationSDD::GetAnodeBaseline(Int_t i,Float_t &baseline,
1058 // Returns the Baseline for a particular anode.
1059 baseline = fBaseline[i];
1062 //______________________________________________________________________
1063 void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl,
1065 // Returns the compression alogirthm parameters
1066 Int_t size = fD.GetSize();
1068 db=fD[i]; tl=fT1[i]; th=fT2[i];
1070 if (size <= 2 && i>=fNofMaps/2) {
1071 db=fD[1]; tl=fT1[1]; th=fT2[1];
1073 db=fD[0]; tl=fT1[0]; th=fT2[0];
1074 } // end if size <=2 && i>=fNofMaps/2
1077 //______________________________________________________________________
1078 void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl){
1079 // returns the compression alogirthm parameters
1080 Int_t size = fD.GetSize();
1083 db=fD[i]; tl=fT1[i];
1085 if (size <= 2 && i>=fNofMaps/2) {
1086 db=fD[1]; tl=fT1[1];
1088 db=fD[0]; tl=fT1[0];
1089 } // end if size <=2 && i>=fNofMaps/2
1090 } // end if size > 2
1092 //______________________________________________________________________
1093 void AliITSsimulationSDD::SetCompressParam(){
1094 // Sets the compression alogirthm parameters
1097 fResponse->GiveCompressParam(cp);
1098 for (i=0; i<2; i++) {
1105 //______________________________________________________________________
1106 void AliITSsimulationSDD::ReadBaseline(){
1107 // read baseline and noise from file - either a .root file and in this
1108 // case data should be organised in a tree with one entry for each
1109 // module => reading should be done accordingly
1110 // or a classic file and do smth. like this:
1111 // Read baselines and noise for SDD
1115 char input[100], base[100], param[100];
1118 fResponse->Filenames(input,base,param);
1121 filtmp = gSystem->ExpandPathName(fFileName.Data());
1122 FILE *bline = fopen(filtmp,"r");
1126 while(fscanf(bline,"%d %f %f",&pos, &bl, &n) != EOF) {
1128 Error("ReadBaseline","Anode number not in increasing order!",
1131 } // end if pos != na+1
1137 Error("ReadBaseline"," THE BASELINE FILE %s DOES NOT EXIST !",filtmp);
1144 //______________________________________________________________________
1145 Int_t AliITSsimulationSDD::Convert10to8(Int_t signal) const {
1146 // To the 10 to 8 bit lossive compression.
1147 // code from Davide C. and Albert W.
1149 if (signal < 128) return signal;
1150 if (signal < 256) return (128+((signal-128)>>1));
1151 if (signal < 512) return (192+((signal-256)>>3));
1152 if (signal < 1024) return (224+((signal-512)>>4));
1155 //______________________________________________________________________
1156 Int_t AliITSsimulationSDD::Convert8to10(Int_t signal) const {
1157 // Undo the lossive 10 to 8 bit compression.
1158 // code from Davide C. and Albert W.
1159 if (signal < 0 || signal > 255) {
1160 Warning("Convert8to10","out of range signal=%d",signal);
1162 } // end if signal <0 || signal >255
1164 if (signal < 128) return signal;
1166 if (TMath::Odd(signal)) return (128+((signal-128)<<1));
1167 else return (128+((signal-128)<<1)+1);
1168 } // end if signal < 192
1170 if (TMath::Odd(signal)) return (256+((signal-192)<<3)+3);
1171 else return (256+((signal-192)<<3)+4);
1172 } // end if signal < 224
1173 if (TMath::Odd(signal)) return (512+((signal-224)<<4)+7);
1174 return (512+((signal-224)<<4)+8);
1178 //______________________________________________________________________
1179 AliITSMap* AliITSsimulationSDD::HitMap(Int_t i){
1180 //Return the correct map.
1182 return ((i==0)? fHitMap1 : fHitMap2);
1185 //______________________________________________________________________
1186 void AliITSsimulationSDD::ZeroSuppression(const char *option) {
1187 // perform the zero suppresion
1189 if (strstr(option,"2D")) {
1190 //Init2D(); // activate if param change module by module
1192 } else if (strstr(option,"1D")) {
1193 //Init1D(); // activate if param change module by module
1195 } else StoreAllDigits();
1197 //______________________________________________________________________
1198 void AliITSsimulationSDD::Init2D(){
1199 // read in and prepare arrays: fD, fT1, fT2
1200 // savemu[nanodes], savesigma[nanodes]
1201 // read baseline and noise from file - either a .root file and in this
1202 // case data should be organised in a tree with one entry for each
1203 // module => reading should be done accordingly
1204 // or a classic file and do smth. like this ( code from Davide C. and
1206 // Read 2D zero-suppression parameters for SDD
1208 if (!strstr(fParam.Data(),"file")) return;
1210 Int_t na,pos,tempTh;
1212 Float_t *savemu = new Float_t [fNofMaps];
1213 Float_t *savesigma = new Float_t [fNofMaps];
1214 char input[100],basel[100],par[100];
1216 Int_t minval = fResponse->MinVal();
1218 fResponse->Filenames(input,basel,par);
1221 filtmp = gSystem->ExpandPathName(fFileName.Data());
1222 FILE *param = fopen(filtmp,"r");
1226 while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) {
1228 Error("Init2D","Anode number not in increasing order!",filtmp);
1230 } // end if pos != na+1
1232 savesigma[na] = sigma;
1233 if ((2.*sigma) < mu) {
1234 fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5);
1237 tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval;
1238 if (tempTh < 0) tempTh=0;
1240 tempTh = (Int_t)floor(mu+3.0*sigma+0.5) - minval;
1241 if (tempTh < 0) tempTh=0;
1246 Error("Init2D","THE FILE %s DOES NOT EXIST !",filtmp);
1253 delete [] savesigma;
1255 //______________________________________________________________________
1256 void AliITSsimulationSDD::Compress2D(){
1257 // simple ITS cluster finder -- online zero-suppression conditions
1260 Int_t minval = fResponse->MinVal();
1261 Bool_t write = fResponse->OutputOption();
1262 Bool_t do10to8 = fResponse->Do10to8();
1263 Int_t nz, nl, nh, low, i, j;
1265 for (i=0; i<fNofMaps; i++) {
1266 CompressionParam(i,db,tl,th);
1271 for (j=0; j<fMaxNofSamples; j++) {
1272 Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j));
1273 signal -= db; // if baseline eq. is done here
1274 if (signal <= 0) {nz++; continue;}
1275 if ((signal - tl) < minval) low++;
1276 if ((signal - th) >= minval) {
1279 FindCluster(i,j,signal,minval,cond);
1281 ((TMath::Abs(fHitMap2->GetSignal(i,j-1))-th)>=minval)){
1282 if(do10to8) signal = Convert10to8(signal);
1283 AddDigit(i,j,signal);
1284 } // end if cond&&j&&()
1285 } else if ((signal - tl) >= minval) nl++;
1286 } // end for j loop time samples
1287 if (write) TreeB()->Fill(nz,nl,nh,low,i+1);
1288 } //end for i loop anodes
1292 sprintf(hname,"TNtuple%d_%d",fModule,fEvent);
1293 TreeB()->Write(hname);
1298 //______________________________________________________________________
1299 void AliITSsimulationSDD::FindCluster(Int_t i,Int_t j,Int_t signal,
1300 Int_t minval,Bool_t &cond){
1301 // Find clusters according to the online 2D zero-suppression algorithm
1302 Bool_t do10to8 = fResponse->Do10to8();
1303 Bool_t high = kFALSE;
1305 fHitMap2->FlagHit(i,j);
1307 // check the online zero-suppression conditions
1309 const Int_t kMaxNeighbours = 4;
1312 Int_t xList[kMaxNeighbours], yList[kMaxNeighbours];
1313 fSegmentation->Neighbours(i,j,&nn,xList,yList);
1315 for (in=0; in<nn; in++) {
1318 if (fHitMap2->TestHit(ix,iy)==kUnused) {
1319 CompressionParam(ix,dbx,tlx,thx);
1320 Int_t qn = (Int_t)(fHitMap2->GetSignal(ix,iy));
1321 qn -= dbx; // if baseline eq. is done here
1322 if ((qn-tlx) < minval) {
1323 fHitMap2->FlagHit(ix,iy);
1326 if ((qn - thx) >= minval) high=kTRUE;
1328 if(do10to8) signal = Convert10to8(signal);
1329 AddDigit(i,j,signal);
1331 if(do10to8) qns = Convert10to8(qn);
1333 if (!high) AddDigit(ix,iy,qns);
1335 if(!high) fHitMap2->FlagHit(ix,iy);
1336 } // end if qn-tlx < minval
1338 } // end for in loop over neighbours
1340 //______________________________________________________________________
1341 void AliITSsimulationSDD::Init1D(){
1342 // this is just a copy-paste of input taken from 2D algo
1343 // Torino people should give input
1344 // Read 1D zero-suppression parameters for SDD
1346 if (!strstr(fParam.Data(),"file")) return;
1348 Int_t na,pos,tempTh;
1350 Float_t *savemu = new Float_t [fNofMaps];
1351 Float_t *savesigma = new Float_t [fNofMaps];
1352 char input[100],basel[100],par[100];
1354 Int_t minval = fResponse->MinVal();
1356 fResponse->Filenames(input,basel,par);
1359 // set first the disable and tol param
1362 filtmp = gSystem->ExpandPathName(fFileName.Data());
1363 FILE *param = fopen(filtmp,"r");
1367 fscanf(param,"%d %d %d %d ", &fT2[0], &fT2[1], &fTol[0], &fTol[1]);
1368 while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) {
1370 Error("Init1D","Anode number not in increasing order!",filtmp);
1372 } // end if pos != na+1
1374 savesigma[na]=sigma;
1375 if ((2.*sigma) < mu) {
1376 fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5);
1379 tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval;
1380 if (tempTh < 0) tempTh=0;
1385 Error("Init1D","THE FILE %s DOES NOT EXIST !",filtmp);
1392 delete [] savesigma;
1394 //______________________________________________________________________
1395 void AliITSsimulationSDD::Compress1D(){
1396 // 1D zero-suppression algorithm (from Gianluca A.)
1397 Int_t dis,tol,thres,decr,diff;
1398 UChar_t *str=fStream->Stream();
1400 Bool_t do10to8=fResponse->Do10to8();
1404 for (k=0; k<2; k++) {
1407 for (i=0; i<fNofMaps/2; i++) {
1408 Bool_t firstSignal=kTRUE;
1409 Int_t idx=i+k*fNofMaps/2;
1410 if( !fAnodeFire[idx] ) continue;
1411 CompressionParam(idx,decr,thres);
1412 for (j=0; j<fMaxNofSamples; j++) {
1413 Int_t signal=(Int_t)(fHitMap2->GetSignal(idx,j));
1414 signal -= decr; // if baseline eq.
1415 if(do10to8) signal = Convert10to8(signal);
1416 if (signal <= thres) {
1420 // write diff in the buffer for HuffT
1421 str[counter]=(UChar_t)diff;
1424 } // end if signal <= thres
1426 if (diff > 127) diff=127;
1427 if (diff < -128) diff=-128;
1429 // tol has changed to 8 possible cases ? - one can write
1430 // this if(TMath::Abs(diff)<tol) ... else ...
1431 if(TMath::Abs(diff)<tol) diff=0;
1432 // or keep it as it was before
1433 AddDigit(idx,j,last+diff);
1435 AddDigit(idx,j,signal);
1436 } // end if singal < dis
1438 // write diff in the buffer used to compute Huffman tables
1439 if (firstSignal) str[counter]=(UChar_t)signal;
1440 else str[counter]=(UChar_t)diff;
1444 } // end for j loop time samples
1445 } // end for i loop anodes one half of detector
1449 fStream->CheckCount(counter);
1451 // open file and write out the stream of diff's
1452 static Bool_t open=kTRUE;
1453 static TFile *outFile;
1454 Bool_t write = fResponse->OutputOption();
1455 TDirectory *savedir = gDirectory;
1459 SetFileName("stream.root");
1460 cout<<"filename "<<fFileName<<endl;
1461 outFile=new TFile(fFileName,"recreate");
1462 cout<<"I have opened "<<fFileName<<" file "<<endl;
1469 fStream->ClearStream();
1471 // back to galice.root file
1472 if(savedir) savedir->cd();
1474 //______________________________________________________________________
1475 void AliITSsimulationSDD::StoreAllDigits(){
1476 // if non-zero-suppressed data
1477 Bool_t do10to8 = fResponse->Do10to8();
1478 Int_t i, j, digits[3];
1480 for (i=0; i<fNofMaps; i++) {
1481 for (j=0; j<fMaxNofSamples; j++) {
1482 Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j));
1483 if(do10to8) signal = Convert10to8(signal);
1484 if(do10to8) signal = Convert8to10(signal);
1488 fITS->AddRealDigit(1,digits);
1492 //______________________________________________________________________
1493 void AliITSsimulationSDD::CreateHistograms(Int_t scale){
1494 // Creates histograms of maps for debugging
1497 fHis=new TObjArray(fNofMaps);
1498 for (i=0;i<fNofMaps;i++) {
1499 TString sddName("sdd_");
1501 sprintf(candNum,"%d",i+1);
1502 sddName.Append(candNum);
1503 fHis->AddAt(new TH1F(sddName.Data(),"SDD maps",scale*fMaxNofSamples,
1504 0.,(Float_t) scale*fMaxNofSamples), i);
1507 //______________________________________________________________________
1508 void AliITSsimulationSDD::FillHistograms(){
1509 // fill 1D histograms from map
1513 for( Int_t i=0; i<fNofMaps; i++) {
1514 TH1F *hist =(TH1F *)fHis->UncheckedAt(i);
1515 Int_t nsamples = hist->GetNbinsX();
1516 for( Int_t j=0; j<nsamples; j++) {
1517 Double_t signal=fHitMap2->GetSignal(i,j);
1518 hist->Fill((Float_t)j,signal);
1522 //______________________________________________________________________
1523 void AliITSsimulationSDD::ResetHistograms(){
1524 // Reset histograms for this detector
1527 for (i=0;i<fNofMaps;i++ ) {
1528 if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset();
1531 //______________________________________________________________________
1532 TH1F *AliITSsimulationSDD::GetAnode(Int_t wing, Int_t anode) {
1533 // Fills a histogram from a give anode.
1535 if (!fHis) return 0;
1537 if(wing <=0 || wing > 2) {
1538 Warning("GetAnode","Wrong wing number: %d",wing);
1540 } // end if wing <=0 || wing >2
1541 if(anode <=0 || anode > fNofMaps/2) {
1542 Warning("GetAnode","Wrong anode number: %d",anode);
1544 } // end if ampde <=0 || andoe > fNofMaps/2
1546 Int_t index = (wing-1)*fNofMaps/2 + anode-1;
1547 return (TH1F*)(fHis->At(index));
1549 //______________________________________________________________________
1550 void AliITSsimulationSDD::WriteToFile(TFile *hfile) {
1551 // Writes the histograms to a file
1557 for(i=0; i<fNofMaps; i++) fHis->At(i)->Write(); //fAdcs[i]->Write();
1560 //______________________________________________________________________
1561 Float_t AliITSsimulationSDD::GetNoise() {
1562 // Returns the noise value
1563 //Bool_t do10to8=fResponse->Do10to8();
1564 //noise will always be in the liniar part of the signal
1566 Int_t threshold = fT1[0];
1567 char opt1[20], opt2[20];
1569 fResponse->ParamOptions(opt1,opt2);
1571 char *same = strstr(opt1,"same");
1572 Float_t noise,baseline;
1574 fResponse->GetNoiseParam(noise,baseline);
1576 static Bool_t readfile=kTRUE;
1577 //read baseline and noise from file
1578 if (readfile) ReadBaseline();
1582 TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2");
1583 if(c2) delete c2->GetPrimitive("noisehist");
1584 if(c2) delete c2->GetPrimitive("anode");
1585 else c2=new TCanvas("c2");
1587 c2->SetFillColor(0);
1589 TH1F *noisehist = new TH1F("noisehist","noise",100,0.,(float)2*threshold);
1590 TH1F *anode = new TH1F("anode","Anode Projection",fMaxNofSamples,0.,
1591 (float)fMaxNofSamples);
1593 for (i=0;i<fNofMaps;i++) {
1594 CompressionParam(i,decr,threshold);
1595 if (!same) GetAnodeBaseline(i,baseline,noise);
1597 for (k=0;k<fMaxNofSamples;k++) {
1598 Float_t signal=(Float_t)fHitMap2->GetSignal(i,k);
1599 //if (signal <= (float)threshold) noisehist->Fill(signal-baseline);
1600 if (signal <= (float)threshold) noisehist->Fill(signal);
1601 anode->Fill((float)k,signal);
1606 TF1 *gnoise = new TF1("gnoise","gaus",0.,threshold);
1607 noisehist->Fit("gnoise","RQ");
1610 Float_t mnoise = gnoise->GetParameter(1);
1611 cout << "mnoise : " << mnoise << endl;
1612 Float_t rnoise = gnoise->GetParameter(2);
1613 cout << "rnoise : " << rnoise << endl;
1617 //______________________________________________________________________
1618 void AliITSsimulationSDD::WriteSDigits(){
1619 // Fills the Summable digits Tree
1620 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
1622 for( Int_t i=0; i<fNofMaps; i++ ) {
1623 if( !fAnodeFire[i] ) continue;
1624 for( Int_t j=0; j<fMaxNofSamples; j++ ) {
1625 Double_t sig = fHitMap2->GetSignal( i, j );
1627 Int_t jdx = j*fScaleSize;
1628 Int_t index = fpList->GetHitIndex( i, j );
1629 AliITSpListItem pItemTmp2( fModule, index, 0. );
1630 // put the fScaleSize analog digits in only one
1631 for( Int_t ik=0; ik<fScaleSize; ik++ ) {
1632 AliITSpListItem *pItemTmp = fpList->GetpListItem( i, jdx+ik );
1633 if( pItemTmp == 0 ) continue;
1634 pItemTmp2.Add( pItemTmp );
1636 pItemTmp2.AddSignalAfterElect( fModule, index, sig );
1637 pItemTmp2.AddNoise( fModule, index, fHitNoiMap2->GetSignal( i, j ) );
1638 aliITS->AddSumDigit( pItemTmp2 );
1639 } // end if (sig > 0.2)
1644 //______________________________________________________________________
1645 void AliITSsimulationSDD::Print() {
1646 // Print SDD simulation Parameters
1648 cout << "**************************************************" << endl;
1649 cout << " Silicon Drift Detector Simulation Parameters " << endl;
1650 cout << "**************************************************" << endl;
1651 cout << "Flag for Perpendicular tracks: " << (Int_t) fFlag << endl;
1652 cout << "Flag for noise checking: " << (Int_t) fCheckNoise << endl;
1653 cout << "Flag to switch off electronics: " << (Int_t) fDoFFT << endl;
1654 cout << "Number pf Anodes used: " << fNofMaps << endl;
1655 cout << "Number of Time Samples: " << fMaxNofSamples << endl;
1656 cout << "Scale size factor: " << fScaleSize << endl;
1657 cout << "**************************************************" << endl;