]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSCalibrationSDD.cxx
Possibility of switching on/off the correction maps (F.Prino)
[u/mrichter/AliRoot.git] / ITS / AliITSCalibrationSDD.cxx
1 /**************************************************************************
2  * Copyright(c) 2007-2009, 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 #include "AliITSCalibrationSDD.h"
21 #include "AliLog.h"
22
23 //////////////////////////////////////////////////////
24 //  Calibration class for set:ITS                   //
25 //  Specific subdetector implementation             //
26 //  for silicon drift detectors                     //
27 //                                                  //
28 //                                                  //
29 //////////////////////////////////////////////////////
30
31 const Float_t AliITSCalibrationSDD::fgkTemperatureDefault = 296.;
32 const Float_t AliITSCalibrationSDD::fgkNoiseDefault = 10.;
33 const Float_t AliITSCalibrationSDD::fgkGainDefault = 1.;
34 const Float_t AliITSCalibrationSDD::fgkBaselineDefault = 20.;
35 const Float_t AliITSCalibrationSDD::fgkMinValDefault  = 4;
36 //______________________________________________________________________
37 ClassImp(AliITSCalibrationSDD)
38
39 AliITSCalibrationSDD::AliITSCalibrationSDD():
40 AliITSCalibration(),
41 fDeadChips(0),
42 fDeadChannels(0),
43 fMinVal(fgkMinValDefault),
44 fIsDead(kFALSE),
45 fBadChannels(),
46 fUseACorrMap(0),
47 fUseTCorrMap(0),
48 fMapAW0(0),
49 fMapAW1(0),
50 fMapTW0(0),
51 fMapTW1(0),
52 fDrSpeed0(0),
53 fDrSpeed1(0)
54 {
55   // default constructor
56
57   SetDeadChannels();
58   for(Int_t ian=0;ian<fgkWings*fgkChannels*fgkChips;ian++){
59     fBaseline[ian]=fgkBaselineDefault;
60     fNoise[ian]=fgkNoiseDefault;
61     SetNoiseAfterElectronics(ian);
62   }
63   for(Int_t iw=0;iw<fgkWings;iw++){
64     for(Int_t icp=0;icp<fgkChips;icp++){
65       for(Int_t ich=0;ich<fgkChannels;ich++)
66         fGain[iw][icp][ich]=1.;
67     }
68   }
69   SetThresholds(fgkMinValDefault,0.);
70   SetTemperature(fgkTemperatureDefault);
71   SetUseCorrectionMaps(kTRUE,kTRUE);
72   SetDataType();
73  }
74 //______________________________________________________________________
75 AliITSCalibrationSDD::AliITSCalibrationSDD(const char *dataType):
76 AliITSCalibration(),
77 fDeadChips(0),
78 fDeadChannels(0),
79 fMinVal(fgkMinValDefault),
80 fIsDead(kFALSE),
81 fBadChannels(),
82 fUseACorrMap(0),
83 fUseTCorrMap(0),
84 fMapAW0(0),
85 fMapAW1(0),
86 fMapTW0(0),
87 fMapTW1(0),
88 fDrSpeed0(0),
89 fDrSpeed1(0)
90 {
91   // constructor
92
93   SetDeadChannels();
94   for(Int_t ian=0;ian<fgkWings*fgkChannels*fgkChips;ian++){
95     fBaseline[ian]=fgkBaselineDefault;
96       fNoise[ian]=fgkNoiseDefault;
97       SetNoiseAfterElectronics(ian);
98   }  
99   for(Int_t iw=0;iw<fgkWings;iw++){
100     for(Int_t icp=0;icp<fgkChips;icp++){
101       for(Int_t ich=0;ich<fgkChannels;ich++)
102         fGain[iw][icp][ich]=1.;
103     }
104   }
105
106
107   SetThresholds(fgkMinValDefault,0.);
108   SetTemperature(fgkTemperatureDefault);
109   SetUseCorrectionMaps(kTRUE,kTRUE);
110   SetDataType(dataType);
111  }
112 //_____________________________________________________________________
113 AliITSCalibrationSDD::~AliITSCalibrationSDD(){
114
115   //destructor
116   if(fMapAW0) delete fMapAW0;
117   if(fMapAW1) delete fMapAW1;
118   if(fMapTW0) delete fMapTW0;
119   if(fMapTW1) delete fMapTW1;
120   if(fDrSpeed0) delete fDrSpeed0;
121   if(fDrSpeed1) delete fDrSpeed1;
122 }
123
124 //______________________________________________________________________
125 void AliITSCalibrationSDD::GiveCompressParam(Int_t  cp[8],Int_t ian) const {
126   // give compression param
127
128   cp[0]=(Int_t) fBaseline[ian];
129   cp[1]=(Int_t) fBaseline[ian];
130   cp[2]=(Int_t)(2.*fNoiseAfterEl[ian] + 0.5);
131   cp[3]=(Int_t)(2.*fNoiseAfterEl[ian] + 0.5);
132   cp[4]=0;
133   cp[5]=0;
134   cp[6]=0;
135   cp[7]=0;
136 }
137 //_____________________________________________________________________
138 void AliITSCalibrationSDD::SetBadChannel(Int_t i,Int_t anode){
139   //Set bad anode (set gain=0 for these channels);
140
141   if(anode<0 || anode >fgkChannels*fgkChips*fgkWings-1)AliError("Wrong anode number");
142   Int_t wing=0;
143   Int_t chip,channel;
144   chip=anode/fgkChannels;
145   channel=anode-(chip*fgkChannels);
146   if(anode>=fgkChips*fgkChannels) wing=1;
147   if(wing==1)chip-=fgkChips;
148   fBadChannels[i]=anode;
149   fGain[wing][chip][channel]=0;
150 }
151 //______________________________________________________________________
152 Float_t AliITSCalibrationSDD::GetChannelGain(Int_t anode) const{
153   // returns gain for givenanode
154   Int_t iWing=GetWing(anode);
155   Int_t iChip=GetChip(anode);
156   Int_t iChan=GetChipChannel(anode);
157   return fGain[iWing][iChip][iChan];
158 }
159 //______________________________________________________________________
160 void AliITSCalibrationSDD::GetCorrections(Float_t z, Float_t x, Float_t &devz, Float_t &devx, AliITSsegmentationSDD* seg){
161   //correction of coordinates using the maps stored in the DB
162   Int_t nSide=seg->GetSideFromLocalX(x);
163   devz=0;
164   if(fUseACorrMap){
165     if(nSide==0) devz=fMapAW0->GetCorrection(z,x,seg);
166     else devz=fMapAW1->GetCorrection(z,x,seg);
167   }
168   devx=0;
169   if(fUseTCorrMap){
170     if(nSide==0) devx=fMapTW0->GetCorrection(z,x,seg);
171     else devx=fMapTW1->GetCorrection(z,x,seg);
172   }
173   return;
174 }
175 /*
176 //______________________________________________________________________
177 void AliITSCalibrationSDD::SetDeadChannels(Int_t nchip, Int_t nchan){
178   // Set fGain to zero to simulate a random distribution of 
179   // dead modules, dead chips and single dead channels
180
181   for( Int_t m=0; m<fgkWings; m++ ) 
182     for( Int_t n=0; n<fgkChips; n++ ) 
183       for( Int_t p=0; p<fgkChannels; p++ ) 
184         fGain[m][n][p] = 1.;
185                  
186   //fDeadModules  = nmod;  
187   fDeadChips    = nchip;  
188   fDeadChannels = nchan; 
189   fBadChannels.Set(fDeadChannels);  
190   // nothing to do
191   //if( nmod == 0 && nchip == 0 && nchan == 0 ) return;
192
193   if( nchip == 0 && nchan == 0 ) return;
194   // if( nmod < 0 || nmod > fgkModules ) 
195   //  { 
196   //    cout << "Wrong number of dead modules: " << nmod << endl; 
197   //    return; 
198   //  }
199   
200   Int_t nmax = fgkWings*fgkChips; 
201   if( nchip < 0 || nchip > nmax ) 
202     { 
203       cout << "Wrong number of dead chips: " << nchip << endl; 
204       return; 
205     }
206   nmax = (fgkWings*fgkChips - nchip)*fgkChannels; 
207   if( nchan < 0 || nchan > nmax ) 
208     { 
209       cout << "Wrong number of dead channels: " << nchan << endl; 
210       return; 
211     }
212   
213   TRandom *gran = new TRandom();
214   //  cout << "chips" << endl;
215   Int_t * chip     = new Int_t[nchip];
216   Int_t i = 0;
217   while( i < nchip ) 
218     {
219       Int_t wing = (Int_t) (fgkWings*gran->Uniform() + 1.);
220       if( wing <=0 || wing > fgkWings ) Error("SetDeadChannels","Wrong wing");
221         
222       Int_t chi = (Int_t) (fgkChips*gran->Uniform() + 1.);
223       if( chi <=0 || chi > fgkChips ) Error("SetDeadChannels","Wrong chip:%d\n",chi);
224       i++;
225       chip[i-1] = chi; 
226       for( Int_t m=0; m<fgkChannels; m++ ) 
227         fGain[wing-1][chi-1][m] = 0.;
228     }
229
230   Int_t * channel      = new Int_t[nchan];
231   Int_t * channelChip = new Int_t[nchan];
232   i = 0;
233   while( i < nchan ) 
234     {
235       Int_t k; //loop variable
236       Int_t wing = (Int_t) (fgkWings*gran->Uniform() + 1.);
237       if( wing <=0 || wing > fgkWings ) Error("SetDeadChannels","Wrong wing:%d\n",wing);
238       Int_t chipp = (Int_t) (fgkChips*gran->Uniform() + 1.);
239       if( chipp <=0 || chipp > fgkChips ) Error("SetDeadChannels","Wrong chip:%d",chipp);
240       Int_t flagChip = 0;
241       for( k=0; k<nchip; k++) 
242         if( chipp == chip[k] ) { 
243           flagChip = 1; break; }
244       if( flagChip == 1 ) continue;
245       i++;
246       channel[i-1] = (Int_t) (fgkChannels*gran->Uniform() + 1.); 
247       if( channel[i-1] <=0 || channel[i-1] > fgkChannels ) 
248         Error("SetDeadChannels","Wrong channel:%d\n",channel[i-1]);
249       channelChip[i-1] = chipp;
250       fGain[wing-1][chipp-1][channel[i-1]-1] = 0.;
251     }
252     
253   delete [] chip;
254   delete [] channel;
255   delete [] channelChip;
256 }
257 */
258
259
260 //______________________________________________________________________
261 void AliITSCalibrationSDD::PrintGains() const{
262   //
263
264   if( GetDeadChips() == 0 && 
265       GetDeadChannels() == 0 )
266     return;  
267
268   // Print Electronics Gains
269   cout << "**************************************************" << endl; 
270   cout << "             Print Electronics Gains              " << endl;
271   cout << "**************************************************" << endl;
272
273   // Print SDD electronic gains
274   for(Int_t t=0; t<fgkWings;t++)
275     for(Int_t u=0; u<fgkChips;u++)
276       for(Int_t v=0; v<fgkChannels;v++)
277         {
278           if( fGain[t][u][v] != 1.0 )
279             cout << "Gain for wing: " << t+1 << ", Chip " << u+1 << 
280               ", Channel " << v+1 << " = " << fGain[t][u][v] << endl;
281         }
282 }
283
284 //______________________________________________________________________
285 void AliITSCalibrationSDD::Print(){
286   // Print SDD response Parameters
287
288   cout << "**************************************************" << endl;
289   cout << "   Silicon Drift Detector Response Parameters    " << endl;
290   cout << "**************************************************" << endl;
291   cout << "Hardware compression parameters: " << endl; 
292   cout << "Noise before electronics (arbitrary units): " << fNoise[0] << endl;
293   cout << "Baseline (ADC units): " << fBaseline[0] << endl;
294   cout << "Noise after electronics (ADC units): " << fNoiseAfterEl[0] << endl;
295   cout << "Temperature: " << Temperature() << " K " << endl;
296   cout << "Min. Value: " << fMinVal << endl;
297   PrintGains();
298
299 }