]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSresponseSDD.cxx
Correct the number of buspatches for station 1 & 2 and for R2 & R3 type slat (Christian)
[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 /* $Id$ */
17
18 #include <Riostream.h>
19 #include <TRandom.h>
20
21 #include "AliITSresponseSDD.h"
22 //////////////////////////////////////////////////
23 //  Response class for set:ITS                      //
24 //  Specific subdetector implementation             //
25 //  for silicon drift detectors                     //
26 //                                                  //
27 //                                                  //
28 //////////////////////////////////////////////////////
29
30 const Int_t AliITSresponseSDD::fgkWings;   
31 const Int_t AliITSresponseSDD::fgkChips;  
32 const Int_t AliITSresponseSDD::fgkChannels; 
33 const Int_t AliITSresponseSDD::fgkMaxAdcDefault = 1024;
34 const Double_t AliITSresponseSDD::fgkDynamicRangeDefault = 132.;
35 const Double_t AliITSresponseSDD::fgkfChargeLossDefault = 0;
36 const Double_t AliITSresponseSDD::fgkDiffCoeffDefault = 3.23;
37 const Double_t AliITSresponseSDD::fgkDiffCoeff1Default = 30.;
38 const Double_t AliITSresponseSDD::fgkTemperatureDefault = 296.;
39 const TString AliITSresponseSDD::fgkParam1Default = "same";
40 const TString AliITSresponseSDD::fgkParam2Default = "same";
41 const Double_t AliITSresponseSDD::fgkNoiseDefault = 10.;
42 const Double_t AliITSresponseSDD::fgkBaselineDefault = 20.;
43 const TString AliITSresponseSDD::fgkOptionDefault = "1D";
44 const Double_t AliITSresponseSDD::fgkMinValDefault  = 4;
45 const Double_t AliITSresponseSDD::fgkDriftSpeedDefault = 7.3;
46 const Double_t AliITSresponseSDD::fgkNsigmasDefault = 3.;
47 const Int_t AliITSresponseSDD::fgkNcompsDefault = 121;
48 //______________________________________________________________________
49 ClassImp(AliITSresponseSDD)
50
51   AliITSresponseSDD::AliITSresponseSDD(){
52   // default constructor
53   fGaus = 0;
54   SetDeadChannels();
55   SetMaxAdc(fgkMaxAdcDefault);
56   SetDiffCoeff(fgkDiffCoeffDefault,fgkDiffCoeff1Default);
57   SetDriftSpeed(fgkDriftSpeedDefault);
58   SetNSigmaIntegration(fgkNsigmasDefault);
59   SetNLookUp(fgkNcompsDefault);
60   // SetClock();
61   for(Int_t i=0;i<fgkWings;i++){
62     for(Int_t j=0;j<fgkChips;j++){
63       fBaseline=0;
64       fNoise=0;
65     }
66   }
67   SetNoiseParam(fgkNoiseDefault,fgkBaselineDefault);
68   SetNoiseAfterElectronics();
69   SetJitterError();
70   SetElectronics();
71   SetDynamicRange(fgkDynamicRangeDefault);
72   SetChargeLoss(fgkfChargeLossDefault);
73   SetThresholds(fgkMinValDefault,0.);
74   SetParamOptions(fgkParam1Default.Data(),fgkParam2Default.Data());
75   SetTemperature(fgkTemperatureDefault);
76   SetZeroSupp(fgkOptionDefault);
77   SetDataType();
78   SetFilenames();
79   SetOutputOption();
80   SetDo10to8();
81   // set the default zero suppression parameters
82   fCPar[0]=(Int_t) fBaseline;
83   fCPar[1]=(Int_t) fBaseline;
84   fCPar[2]=(Int_t)(2.*fNoiseAfterEl + 0.5);
85   fCPar[3]=(Int_t)(2.*fNoiseAfterEl + 0.5);
86   fCPar[4]=0;
87   fCPar[5]=0;
88   fCPar[6]=0;
89   fCPar[7]=0;
90 }
91 //______________________________________________________________________
92 AliITSresponseSDD::AliITSresponseSDD(const char *dataType){
93   // constructor
94   fGaus = 0;
95   SetDeadChannels();
96   SetMaxAdc(fgkMaxAdcDefault);
97   SetDiffCoeff(fgkDiffCoeffDefault,fgkDiffCoeff1Default);
98   SetDriftSpeed(fgkDriftSpeedDefault);
99   SetNSigmaIntegration(fgkNsigmasDefault);
100   SetNLookUp(fgkNcompsDefault);
101   // SetClock();
102   for(Int_t i=0;i<fgkWings;i++){
103     for(Int_t j=0;j<fgkChips*fgkChannels;j++){
104       fBaseline=0;
105       fNoise=0;
106     }
107   }
108   SetNoiseParam(fgkNoiseDefault,fgkBaselineDefault);
109   SetNoiseAfterElectronics();
110   SetJitterError();
111   SetElectronics();
112   SetDynamicRange(fgkDynamicRangeDefault);
113   SetChargeLoss(fgkfChargeLossDefault);
114   SetThresholds(fgkMinValDefault,0.);
115   SetParamOptions(fgkParam1Default.Data(),fgkParam2Default.Data());
116   SetTemperature(fgkTemperatureDefault);
117   SetZeroSupp(fgkOptionDefault);
118   SetDataType(dataType);
119   SetFilenames();
120   SetOutputOption();
121   SetDo10to8();
122   // set the default zero suppression parameters
123   fCPar[0]=(Int_t) fBaseline;
124   fCPar[1]=(Int_t) fBaseline;
125   fCPar[2]=(Int_t)(2.*fNoiseAfterEl + 0.5);
126   fCPar[3]=(Int_t)(2.*fNoiseAfterEl + 0.5);
127   fCPar[4]=0;
128   fCPar[5]=0;
129   fCPar[6]=0;
130   fCPar[7]=0;
131 }
132 //______________________________________________________________________
133 AliITSresponseSDD::AliITSresponseSDD(const AliITSresponseSDD &ob) : AliITSresponse(ob) {
134   // Copy constructor
135   // Copies are not allowed. The method is protected to avoid misuse.
136   Error("AliITSresponseSDD","Copy constructor not allowed\n");
137 }
138
139 //______________________________________________________________________
140 AliITSresponseSDD& AliITSresponseSDD::operator=(const AliITSresponseSDD& /* ob */){
141   // Assignment operator
142   // Assignment is not allowed. The method is protected to avoid misuse.
143   Error("= operator","Assignment operator not allowed\n");
144   return *this;
145 }
146
147 //______________________________________________________________________
148 AliITSresponseSDD::~AliITSresponseSDD() { 
149
150   if(fGaus) delete fGaus;
151 }
152
153 //______________________________________________________________________
154 Int_t AliITSresponseSDD::Convert8to10(Int_t signal) const {
155   // Undo the lossive 10 to 8 bit compression.
156   // code from Davide C. and Albert W.
157   if(Do10to8()){  // kTRUE if the compression is active
158     if (signal < 0 || signal > 255) {
159       Warning("Convert8to10","out of range signal=%d",signal);
160       return 0;
161     } // end if signal <0 || signal >255
162
163     if (signal < 128) return signal;
164     if (signal < 192) {
165       if (TMath::Odd(signal)) return (128+((signal-128)<<1));
166       else  return (128+((signal-128)<<1)+1);
167     } // end if signal < 192
168     if (signal < 224) {
169       if (TMath::Odd(signal)) return (256+((signal-192)<<3)+3);
170       else  return (256+((signal-192)<<3)+4);
171     } // end if signal < 224
172     if (TMath::Odd(signal)) return (512+((signal-224)<<4)+7);
173     return (512+((signal-224)<<4)+8);
174   }
175   else {  
176     return signal;
177   }
178 }
179
180 //______________________________________________________________________
181 void AliITSresponseSDD::SetCompressParam(Int_t  cp[8]){
182   // set compression param
183
184   Int_t i;
185   for (i=0; i<8; i++) {
186     fCPar[i]=cp[i];
187     //printf("\n CompressPar %d %d \n",i,fCPar[i]);    
188   } // end for i
189 }
190 //______________________________________________________________________
191 void AliITSresponseSDD::GiveCompressParam(Int_t  cp[8]) const {
192   // give compression param
193
194   Int_t i;
195   for (i=0; i<8; i++) {
196     cp[i]=fCPar[i];
197   } // end for i
198 }
199 //______________________________________________________________________
200 void AliITSresponseSDD::SetNLookUp(Int_t p1){
201   // Set number of sigmas over which cluster disintegration is performed
202   fNcomps=p1;
203   fGaus = new TArrayF(fNcomps+1);
204   for(Int_t i=0; i<=fNcomps; i++) {
205     Double_t x = -fNsigmas + (2.*i*fNsigmas)/(fNcomps-1);
206     (*fGaus)[i] = exp(-((x*x)/2));
207     //     cout << "fGaus[" << i << "]: " << fGaus->At(i) << endl;
208   }
209 }
210 //______________________________________________________________________
211 void AliITSresponseSDD::SetDeadChannels(Int_t nchip, Int_t nchan){
212   // Set fGain to zero to simulate a random distribution of 
213   // dead modules, dead chips and single dead channels
214
215   for( Int_t m=0; m<fgkWings; m++ ) 
216     for( Int_t n=0; n<fgkChips; n++ ) 
217       for( Int_t p=0; p<fgkChannels; p++ ) 
218         fGain[m][n][p] = 1.;
219                  
220   //fDeadModules  = nmod;  
221   fDeadChips    = nchip;  
222   fDeadChannels = nchan; 
223     
224   // nothing to do
225   //if( nmod == 0 && nchip == 0 && nchan == 0 ) return;
226
227   if( nchip == 0 && nchan == 0 ) return;
228   // if( nmod < 0 || nmod > fgkModules ) 
229   //  { 
230   //    cout << "Wrong number of dead modules: " << nmod << endl; 
231   //    return; 
232   //  }
233   
234   Int_t nmax = fgkWings*fgkChips; 
235   if( nchip < 0 || nchip > nmax ) 
236     { 
237       cout << "Wrong number of dead chips: " << nchip << endl; 
238       return; 
239     }
240   nmax = (fgkWings*fgkChips - nchip)*fgkChannels; 
241   if( nchan < 0 || nchan > nmax ) 
242     { 
243       cout << "Wrong number of dead channels: " << nchan << endl; 
244       return; 
245     }
246   
247   TRandom *gran = new TRandom();
248   /*
249   //  cout << "modules" << endl;
250   Int_t * mod = new Int_t [nmod];
251   Int_t i; //loop variable
252   for( i=0; i<nmod; i++ ) 
253     {
254       mod[i] = (Int_t) (1.+fgkModules*gran->Uniform());
255       cout << i+1 << ": Dead module nr: " << mod[i] << endl;
256       for(Int_t n=0; n<fgkChips; n++)
257         for(Int_t p=0; p<fgkChannels; p++)
258           fGain[mod[i]-1][n][p] = 0.;
259     }
260   */
261   //  cout << "chips" << endl;
262   Int_t * chip     = new Int_t[nchip];
263   Int_t i = 0;
264   while( i < nchip ) 
265     {
266       Int_t wing = (Int_t) (fgkWings*gran->Uniform() + 1.);
267       if( wing <=0 || wing > fgkWings ) Error("SetDeadChannels","Wrong wing");
268         
269       Int_t chi = (Int_t) (fgkChips*gran->Uniform() + 1.);
270       if( chi <=0 || chi > fgkChips ) Error("SetDeadChannels","Wrong chip:%d\n",chi);
271       i++;
272       chip[i-1] = chi; 
273       for( Int_t m=0; m<fgkChannels; m++ ) 
274         fGain[wing-1][chi-1][m] = 0.;
275     }
276
277   Int_t * channel      = new Int_t[nchan];
278   Int_t * channelChip = new Int_t[nchan];
279   i = 0;
280   while( i < nchan ) 
281     {
282       Int_t k; //loop variable
283       Int_t wing = (Int_t) (fgkWings*gran->Uniform() + 1.);
284       if( wing <=0 || wing > fgkWings ) Error("SetDeadChannels","Wrong wing:%d\n",wing);
285       Int_t chipp = (Int_t) (fgkChips*gran->Uniform() + 1.);
286       if( chipp <=0 || chipp > fgkChips ) Error("SetDeadChannels","Wrong chip:%d",chipp);
287       Int_t flagChip = 0;
288       for( k=0; k<nchip; k++) 
289         if( chipp == chip[k] ) { 
290           flagChip = 1; break; }
291       if( flagChip == 1 ) continue;
292       i++;
293       channel[i-1] = (Int_t) (fgkChannels*gran->Uniform() + 1.); 
294       if( channel[i-1] <=0 || channel[i-1] > fgkChannels ) 
295         Error("SetDeadChannels","Wrong channel:%d\n",channel[i-1]);
296       channelChip[i-1] = chipp;
297       fGain[wing-1][chipp-1][channel[i-1]-1] = 0.;
298     }
299     
300   delete [] chip;
301   delete [] channel;
302   delete [] channelChip;
303 }
304 //______________________________________________________________________
305 void AliITSresponseSDD::PrintGains() const{
306   //
307
308   if( GetDeadChips() == 0 && 
309       GetDeadChannels() == 0 )
310     return;  
311
312   // Print Electronics Gains
313   cout << "**************************************************" << endl; 
314   cout << "             Print Electronics Gains              " << endl;
315   cout << "**************************************************" << endl;
316
317   // Print SDD electronic gains
318   for(Int_t t=0; t<fgkWings;t++)
319     for(Int_t u=0; u<fgkChips;u++)
320       for(Int_t v=0; v<fgkChannels;v++)
321         {
322           if( fGain[t][u][v] != 1.0 )
323             cout << "Gain for wing: " << t+1 << ", Chip " << u+1 << 
324               ", Channel " << v+1 << " = " << fGain[t][u][v] << endl;
325         }
326 }
327 //______________________________________________________________________
328 void AliITSresponseSDD::Print(){
329   // Print SDD response Parameters
330
331   cout << "**************************************************" << endl;
332   cout << "   Silicon Drift Detector Response Parameters    " << endl;
333   cout << "**************************************************" << endl;
334   cout << "Diffusion Coefficients: "<< fDiffCoeff<< ", "<<fDiffCoeff1 << endl;
335
336   cout << "Hardware compression parameters: " << endl; 
337   for(Int_t i=0; i<8; i++) cout << "fCPar[" << i << "] = " << fCPar[i] <<endl;
338   cout << "Noise before electronics (arbitrary units): " << fNoise << endl;
339   cout << "Baseline (ADC units): " << fBaseline << endl;
340   cout << "Noise after electronics (ADC units): " << fNoiseAfterEl << endl;
341
342   cout << "Dynamic Range: " << fDynamicRange << endl;
343   cout << "Charge Loss: " << fChargeLoss << endl;
344   cout << "Temperature: " << Temperature() << " K " << endl;
345   cout << "Drift Speed: " << fDriftSpeed << endl;
346   cout << "Electronics (1=PASCAL, 2=OLA): " << fElectronics << endl;
347
348   cout << "N. of Sigma for signal integration: " << fNsigmas << endl;
349   cout << "N. of bins in lookup table: " << fNcomps << endl;
350
351   cout << "Max. ADC Value: " << fMaxAdc << endl;
352   cout << "Min. Value: " << fMinVal << endl;
353
354   PrintGains();
355
356 }
357
358
359