Fixes for Febr. 2008 run
[u/mrichter/AliRoot.git] / ITS / AliITSCalibrationSDD.cxx
CommitLineData
fcf95fc7 1/**************************************************************************
c2bd28b6 2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
fcf95fc7 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
c2bd28b6 16/* $Id$ */
fcf95fc7 17
18#include <Riostream.h>
19#include <TRandom.h>
20#include "AliITSCalibrationSDD.h"
f45f6658 21#include "AliLog.h"
fcf95fc7 22
23//////////////////////////////////////////////////////
24// Calibration class for set:ITS //
25// Specific subdetector implementation //
26// for silicon drift detectors //
27// //
28// //
29//////////////////////////////////////////////////////
30
4bfbde86 31const Float_t AliITSCalibrationSDD::fgkTemperatureDefault = 296.;
32const Float_t AliITSCalibrationSDD::fgkNoiseDefault = 10.;
33const Float_t AliITSCalibrationSDD::fgkGainDefault = 1.;
34const Float_t AliITSCalibrationSDD::fgkBaselineDefault = 20.;
35const Float_t AliITSCalibrationSDD::fgkMinValDefault = 4;
fcf95fc7 36//______________________________________________________________________
37ClassImp(AliITSCalibrationSDD)
38
4bfbde86 39AliITSCalibrationSDD::AliITSCalibrationSDD():
40AliITSCalibration(),
41fDeadChips(0),
42fDeadChannels(0),
43fMinVal(fgkMinValDefault),
44fIsDead(kFALSE),
028a3709 45fBadChannels(),
c9a38d3d 46fUseACorrMap(0),
47fUseTCorrMap(0),
028a3709 48fMapAW0(0),
49fMapAW1(0),
50fMapTW0(0),
18da6e54 51fMapTW1(0),
52fDrSpeed0(0),
53fDrSpeed1(0)
4bfbde86 54{
fcf95fc7 55 // default constructor
56
57 SetDeadChannels();
f45f6658 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 }
fcf95fc7 69 SetThresholds(fgkMinValDefault,0.);
70 SetTemperature(fgkTemperatureDefault);
c9a38d3d 71 SetUseCorrectionMaps(kTRUE,kTRUE);
fcf95fc7 72 SetDataType();
fcf95fc7 73 }
74//______________________________________________________________________
4bfbde86 75AliITSCalibrationSDD::AliITSCalibrationSDD(const char *dataType):
76AliITSCalibration(),
77fDeadChips(0),
78fDeadChannels(0),
79fMinVal(fgkMinValDefault),
80fIsDead(kFALSE),
028a3709 81fBadChannels(),
c9a38d3d 82fUseACorrMap(0),
83fUseTCorrMap(0),
028a3709 84fMapAW0(0),
85fMapAW1(0),
86fMapTW0(0),
18da6e54 87fMapTW1(0),
88fDrSpeed0(0),
89fDrSpeed1(0)
90{
fcf95fc7 91 // constructor
92
93 SetDeadChannels();
f45f6658 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 }
fcf95fc7 105
c9a38d3d 106
fcf95fc7 107 SetThresholds(fgkMinValDefault,0.);
108 SetTemperature(fgkTemperatureDefault);
c9a38d3d 109 SetUseCorrectionMaps(kTRUE,kTRUE);
fcf95fc7 110 SetDataType(dataType);
fcf95fc7 111 }
028a3709 112//_____________________________________________________________________
113AliITSCalibrationSDD::~AliITSCalibrationSDD(){
fcf95fc7 114
028a3709 115 //destructor
116 if(fMapAW0) delete fMapAW0;
117 if(fMapAW1) delete fMapAW1;
118 if(fMapTW0) delete fMapTW0;
119 if(fMapTW1) delete fMapTW1;
18da6e54 120 if(fDrSpeed0) delete fDrSpeed0;
121 if(fDrSpeed1) delete fDrSpeed1;
028a3709 122}
fcf95fc7 123
124//______________________________________________________________________
f45f6658 125void AliITSCalibrationSDD::GiveCompressParam(Int_t cp[8],Int_t ian) const {
fcf95fc7 126 // give compression param
127
f45f6658 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;
fcf95fc7 136}
f45f6658 137//_____________________________________________________________________
138void AliITSCalibrationSDD::SetBadChannel(Int_t i,Int_t anode){
139 //Set bad anode (set gain=0 for these channels);
fcf95fc7 140
f45f6658 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}
4952f440 151//______________________________________________________________________
152Float_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}
c9a38d3d 159//______________________________________________________________________
160void 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}
f45f6658 175/*
fcf95fc7 176//______________________________________________________________________
177void 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;
f45f6658 189 fBadChannels.Set(fDeadChannels);
fcf95fc7 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();
fcf95fc7 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}
f45f6658 257*/
4952f440 258
259
fcf95fc7 260//______________________________________________________________________
261void 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}
e56160b8 283
fcf95fc7 284//______________________________________________________________________
285void 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;
f45f6658 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;
fcf95fc7 295 cout << "Temperature: " << Temperature() << " K " << endl;
296 cout << "Min. Value: " << fMinVal << endl;
297 PrintGains();
298
5bfe44ce 299}