]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSresponseSDD.cxx
New SDD code for much improved SDigit handling. Also bug fix made in the
[u/mrichter/AliRoot.git] / ITS / AliITSresponseSDD.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 #include <TString.h>
17 #include <TRandom.h>
18
19 #include "AliITSresponseSDD.h"
20
21
22 //___________________________________________
23 ClassImp(AliITSresponseSDD)    
24
25 AliITSresponseSDD::AliITSresponseSDD()
26 {
27   // default constructor
28    fGaus = 0;
29    SetDeadChannels();
30    SetMaxAdc();
31    SetDiffCoeff();
32    SetDriftSpeed();
33    SetNSigmaIntegration();
34    SetNLookUp();
35    // SetClock();
36    SetNoiseParam();
37    SetNoiseAfterElectronics();
38    SetElectronics();
39    SetDynamicRange();
40    SetChargeLoss();
41    SetMinVal();
42    SetParamOptions();
43    SetTemperature();
44    SetZeroSupp();
45    SetDataType();
46    SetFilenames();
47    SetOutputOption();
48    SetDo10to8();
49    // set the default zero suppression parameters
50    fCPar[0]=0;
51    fCPar[1]=0;
52    fCPar[2]=(Int_t)(fBaseline + 2.*fNoiseAfterEl + 0.2);
53    fCPar[3]=(Int_t)(fBaseline + 2.*fNoiseAfterEl + 0.2);
54    fCPar[4]=0;
55    fCPar[5]=0;
56    fCPar[6]=0;
57    fCPar[7]=0;
58 }
59
60 AliITSresponseSDD::AliITSresponseSDD(const char *dataType)
61 {
62   // constructor
63    fGaus = 0;
64    SetDeadChannels();
65    SetMaxAdc();
66    SetDiffCoeff();
67    SetDriftSpeed();
68    SetNSigmaIntegration();
69    SetNLookUp();
70    // SetClock();
71    SetNoiseParam();
72    SetNoiseAfterElectronics();
73    SetElectronics();
74    SetDynamicRange();
75    SetChargeLoss();
76    SetMinVal();
77    SetParamOptions();
78    SetTemperature();
79    SetZeroSupp();
80    SetDataType(dataType);
81    SetFilenames();
82    SetOutputOption();
83    SetDo10to8();
84    // set the default zero suppression parameters
85    fCPar[0]=0;
86    fCPar[1]=0;
87    fCPar[2]=(Int_t)(fBaseline + 2.*fNoiseAfterEl + 0.2);
88    fCPar[3]=(Int_t)(fBaseline + 2.*fNoiseAfterEl + 0.2);
89    fCPar[4]=0;
90    fCPar[5]=0;
91    fCPar[6]=0;
92    fCPar[7]=0;
93 }
94
95 AliITSresponseSDD::~AliITSresponseSDD() { 
96
97   if(fGaus) delete fGaus;
98
99 }
100
101 void AliITSresponseSDD::SetCompressParam(Int_t  cp[8])
102 {
103   // set compression param
104
105     Int_t i;
106     for (i=0; i<8; i++) {
107         fCPar[i]=cp[i];
108         //printf("\n CompressPar %d %d \n",i,fCPar[i]);
109     
110     }
111 }
112
113 void AliITSresponseSDD::GiveCompressParam(Int_t  cp[8])
114 {
115   // give compression param
116
117     Int_t i;
118     for (i=0; i<8; i++) {
119         cp[i]=fCPar[i];
120     }
121 }
122
123 void AliITSresponseSDD::SetDeadChannels(Int_t nmod, Int_t nchip, Int_t nchan) 
124 {
125     // Set fGain to zero to simulate a random distribution of 
126     // dead modules, dead chips and single dead channels
127
128     for( Int_t m=0; m<fModules; m++ ) 
129         for( Int_t n=0; n<fChips; n++ ) 
130             for( Int_t p=0; p<fChannels; p++ ) 
131                  fGain[m][n][p] = 1.;
132                  
133     fDeadModules  = nmod;  
134     fDeadChips    = nchip;  
135     fDeadChannels = nchan; 
136     
137     // nothing to do
138     if( nmod == 0 && nchip == 0 && nchan == 0 ) return;
139
140     if( nmod < 0 || nmod > fModules ) 
141     { 
142         cout << "Wrong number of dead modules: " << nmod << endl; 
143         return; 
144     }
145     Int_t nmax = (fModules-nmod)*fChips; 
146     if( nchip < 0 || nchip > nmax ) 
147     { 
148         cout << "Wrong number of dead chips: " << nchip << endl; 
149         return; 
150     }
151     nmax = ((fModules - nmod)*fChips - nchip)*fChannels; 
152     if( nchan < 0 || nchan > nmax ) 
153     { 
154         cout << "Wrong number of dead channels: " << nchan << endl; 
155         return; 
156     }
157   
158     TRandom *gran = new TRandom();
159   
160     //  cout << "modules" << endl;
161     Int_t * mod = new Int_t [nmod];
162     Int_t i; //loop variable
163     for( i=0; i<nmod; i++ ) 
164     {
165         mod[i] = (Int_t) (1.+fModules*gran->Uniform());
166         cout << i+1 << ": Dead module nr: " << mod[i] << endl;
167         for(Int_t n=0; n<fChips; n++)
168             for(Int_t p=0; p<fChannels; p++)
169                 fGain[mod[i]-1][n][p] = 0.;
170     }
171
172     //  cout << "chips" << endl;
173     Int_t * chip     = new Int_t[nchip];
174     Int_t * chip_mod = new Int_t[nchip];
175     i = 0;
176     while( i < nchip ) 
177     {
178         Int_t module = (Int_t) (fModules*gran->Uniform() + 1.);
179         if( module <=0 || module > fModules ) 
180             cout << "Wrong module: " << module << endl;
181         Int_t flag_mod = 0;
182         for( Int_t k=0; k<nmod; k++ ) 
183             if( module == mod[k] ) { flag_mod = 1; break; }
184         if( flag_mod == 1 ) continue;
185         
186         Int_t chi = (Int_t) (fChips*gran->Uniform() + 1.);
187         if( chi <=0 || chi > fChips ) cout << "Wrong chip: " << chi << endl;
188         i++;
189         chip[i-1] = chi; 
190         chip_mod[i-1] = module;
191         for( Int_t m=0; m<fChannels; m++ ) 
192             fGain[module-1][chi-1][m] = 0.;
193         cout << i << ": Dead chip nr. " << chip[i-1] << " in module nr: " << chip_mod[i-1] << endl;
194     }
195
196     //  cout << "channels" << endl;
197     Int_t * channel      = new Int_t[nchan];
198     Int_t * channel_chip = new Int_t[nchan];
199     Int_t * channel_mod  = new Int_t[nchan];
200     i = 0;
201     while( i < nchan ) 
202     {
203         Int_t k; //loop variable
204         Int_t module = (Int_t) (fModules*gran->Uniform() + 1.);
205         if( module <=0 || module > fModules ) 
206             cout << "Wrong module: " << module << endl;
207         Int_t flag_mod = 0;
208         for( k=0; k<nmod; k++ ) 
209             if( module == mod[k] ) { flag_mod = 1; break; }
210         if( flag_mod == 1 ) continue;
211         Int_t chipp = (Int_t) (fChips*gran->Uniform() + 1.);
212         if( chipp <=0 || chipp > fChips ) cout << "Wrong chip: " << chipp << endl;
213         Int_t flag_chip = 0;
214         for( k=0; k<nchip; k++) 
215             if( chipp == chip[k] && module == chip_mod[k] ) { flag_chip = 1; break; }
216         if( flag_chip == 1 ) continue;
217         i++;
218         channel[i-1] = (Int_t) (fChannels*gran->Uniform() + 1.); 
219         if( channel[i-1] <=0 || channel[i-1] > fChannels ) 
220             cout << "Wrong channel: " << channel[i-1] << endl;
221         channel_chip[i-1] = chipp;
222         channel_mod[i-1] = module;
223         fGain[module-1][chipp-1][channel[i-1]-1] = 0.;
224         cout << i << ": Dead channel nr. " << channel[i-1] << " in chip nr. " << channel_chip[i-1] << " in module nr: " << channel_mod[i-1] << endl;
225     }
226     
227     delete [] mod;
228     delete [] chip;
229     delete [] chip_mod;
230     delete [] channel;
231     delete [] channel_mod;
232     delete [] channel_chip;
233 }
234
235 void AliITSresponseSDD::PrintGains()
236 {
237     // Print Electronics Gains
238   cout << "**************************************************" << endl; 
239   cout << "             Print Electronics Gains              " << endl;
240   cout << "**************************************************" << endl;
241
242 //  FILE *f = fopen( "gains.txt", "w" );
243 //  fprintf( f, "    Module    Chip   Channel   Gain\n" );
244
245   // Print SDD electronic gains
246   for(Int_t t=0; t<fModules;t++)
247     for(Int_t u=0; u<fChips;u++)
248       for(Int_t v=0; v<fChannels;v++)
249       {
250         cout << "Gain for Module: " << t+1 << ", Chip " << u+1 << ", Channel " << v+1 << " = " << fGain[t][u][v] << endl;
251 //        if( fGain[t][u][v] != 1.0 )
252 //          fprintf( f, " %8d %8d %8d   %f\n", t+1, u+1, v+1, fGain[t][u][v] );
253       }
254 //  fclose( f );
255 }
256
257 void AliITSresponseSDD::Print()
258 {
259   // Print SDD response Parameters
260
261    cout << "**************************************************" << endl;
262    cout << "   Silicon Drift Detector Response Parameters    " << endl;
263    cout << "**************************************************" << endl;
264    cout << "Diffusion Coefficients: " << fDiffCoeff << ", " << fDiffCoeff1 << endl;
265
266    cout << "Hardware compression parameters: " << endl; 
267    for(Int_t i=0; i<8; i++) cout << "fCPar[" << i << "] = " << fCPar[i] << endl;
268    cout << "Noise before electronics (arbitrary units): " << fNoise << endl;
269    cout << "Baseline (ADC units): " << fBaseline << endl;
270    cout << "Noise after electronics (ADC units): " << fNoiseAfterEl << endl;
271
272    cout << "Dynamic Range: " << fDynamicRange << endl;
273    cout << "Charge Loss: " << fChargeLoss << endl;
274    cout << "Temperature: " << fTemperature << endl;
275    cout << "Drift Speed: " << fDriftSpeed << endl;
276    cout << "Electronics (1=PASCAL, 2=OLA): " << fElectronics << endl;
277
278    cout << "N. of Sigma for signal integration: " << fNsigmas << endl;
279    cout << "N. of bins in lookup table: " << fNcomps << endl;
280
281    cout << "Max. ADC Value: " << fMaxAdc << endl;
282    cout << "Min. Value: " << fMinVal << endl;
283
284    PrintGains();
285
286 }
287
288
289