]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/StoreCalibSDD.C
macro used to prepare default SDD calibration files
[u/mrichter/AliRoot.git] / ITS / StoreCalibSDD.C
CommitLineData
d5d0cab2 1#if !defined(__CINT__) || defined(__MAKECINT__)
2#include "AliCDBManager.h"
3#include "AliITSCalibrationSDD.h"
4#include "AliITSresponseSDD.h"
5#include "AliCDBMetaData.h"
6#include "AliCDBStorage.h"
7#include "AliCDBId.h"
8#include "AliCDBPath.h"
9#include "AliCDBEntry.h"
10#include <TObjArray.h>
11#include <TRandom3.h>
12#endif
13
14void StoreCalibSDD(Int_t firstRun=0,Int_t lastRun=9999999 ){
15 ///////////////////////////////////////////////////////////////////////
16 // Macro to generate and store the calibration files for SDD //
17 // Generates: //
18 // 1 file with 260 AliITSCalibrationSDD objects with //
19 // baselines, noise, gain, drift speed for each module (CalibSDD) //
20 // 1 file with the AliITSrespionseSDD object (RespSDD) //
21 ///////////////////////////////////////////////////////////////////////
22
23 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
24 AliCDBManager::Instance()->SetDefaultStorage("local://OCDB");
25 }
26
27
28 AliCDBMetaData *md1= new AliCDBMetaData(); // metaData describing the object
29 md1->SetObjectClassName("AliITSCalibration");
30 md1->SetResponsible("Elisabetta Crescio, Francesco Prino");
31 md1->SetBeamPeriod(0);
32 md1->SetAliRootVersion("Head 20 nov. 2007"); //root version
33 md1->SetComment("This is a test");
34 // TObject* str;
35 // md1->SetProperty("key1",str);
36
37 AliCDBMetaData *md2 = new AliCDBMetaData();
38 md2->SetObjectClassName("AliITSresponse");
39 md2->SetResponsible("Elisabetta Crescio, Francesco Prino");
40 md2->SetBeamPeriod(0);
41 md2->SetAliRootVersion("Head 20 nov. 2007"); //root version
42 md2->SetComment("This is a test");
43
44
45 AliCDBId idCalSDD("ITS/Calib/CalibSDD",firstRun, lastRun);
46 TObjArray respSDD(260);
47 respSDD.SetOwner(kFALSE);
48
49
50
51 AliCDBId idRespSDD("ITS/Calib/RespSDD",firstRun, lastRun);
52 AliITSresponseSDD* rd = new AliITSresponseSDD();
53 const Int_t nData = 209;
54 Int_t anodeUp[209] = {0,36,0,12,20,32,0,0,12,76,28,8,16,0,0,0,8,0,0,0,20,4,0,0,0,0,0,0
55 ,0,0,8,0,0,0,0,0,0,0,0,0,0,0,12,0,8,0,4,4,0,160,0,0,0,252,16,0,8,8
56 ,0,0,12,0,0,0,12,0,15,20,0,0,0,0,0,0,0,12,12,0,0,0,0,0,8,8,3,240,212
57 ,12,0,8,0,12,0,0,12,0,8,24,0,0,12,0,0,0,0,40,0,0,40,12,28,0,0,12,12
58 ,0,0,0,0,20,0,0,0,12,0,24,0,0,0,0,0,0,0,8,16,0,0,0,0,0,256,0,0,0,0,0,20
59 ,0,12,0,0,0,0,24,0,0,0,0,0,0,0,20,0,0,16,0,0,0,0,24,0,0,0,8,0,16,40,0
60 ,0,0,0,0,0,0,0,0,4,0,32,12,8,28,0,76,0,0,0,12,60,144,0,0,0,0,16,0,16,0,3 };
61
62 Int_t anodeDown[209] = {0,8,0,48,0,12,0,8,0,80,12,0,4,4,0,0,24,0,0,20,0,0,0,0,20,0,0,0,0,0,0,0
63 ,0,0,0,0,4,0,24,4,0,0,8,0,0,36,20,0,12,236,0,0,12,256,16,8,32,4,0,0,24
64 ,24,10,0,16,8,0,2,40,0,0,0,24,0,0,0,8,0,0,0,0,0,32,240,0,92,60,28,8,0,0
65 ,2,0,0,0,0,12,48,0,0,0,0,0,36,11,12,0,0,0,12,12,11,0,20,0,0,12,20,0,0,4
66 ,0,8,12,0,0,0,16,16,0,32,72,12,0,88,20,16,112,8,0,244,28,256,28,0,24,236
67 ,56,0,68,0,4,20,208,20,12,4,28,12,0,0,20,12,0,100,0,16,8,8,0,24,16,0,12,12
68 ,16,0,16,20,0,28,0,8,24,0,12,8,4,40,0,104,96,32,140,20,12,8,20,24,16,16,20
69 ,8,140,96,0,32,20,44};
70
71
72 Float_t drVelParam[4]={7.75,0.002344,-0.000009,0};
73 Float_t edrVelParam[4]={0,0,0,0};
74 Float_t drVel[4];
75 TRandom3 *gran = new TRandom3();
76
77 for(Int_t mod=0;mod<260;mod++){
78 AliITSCalibrationSDD* resd = new AliITSCalibrationSDD("simulated");
79
80 // drift velocity wing 0 and 1
81 for(Int_t ic=0;ic<4;ic++) drVel[ic]=gran->Gaus(drVelParam[ic],edrVelParam[ic]);
82 resd->SetDriftSpeedParam(0,drVel);
83 for(Int_t ic=0;ic<4;ic++) drVel[ic]=gran->Gaus(drVelParam[ic],edrVelParam[ic]);
84 resd->SetDriftSpeedParam(1,drVel);
85 Int_t nBadUp = 0;
86 Int_t nBadDown = 0;
87
88
89 // gain
90 for(Int_t iWing=0; iWing<2;iWing++){
91 for(Int_t iChip=0; iChip<4;iChip++){
92 Float_t chipgain=gran->Gaus(1.,0.1);
93 if(chipgain<0.1) chipgain=0.1;
94 for(Int_t iChan=0; iChan<64;iChan++){
95 Float_t gain=gran->Gaus(chipgain,0.01);
96 if(gain<0.1) gain=0.1;
97 resd->SetGain(gain,iWing,iChip,iChan);
98 }
99 }
100 }
101
102 // bad channels
103 Int_t count=0;
104 do {
105 Int_t ranMod = Int_t(nData*gran->Uniform());
106 nBadUp = anodeUp[ranMod];
107 nBadDown = anodeDown[ranMod];
108 }while (nBadUp+nBadDown>25);
109
110 resd->SetDeadChannels(nBadDown+nBadUp);
111 Int_t remainingBad = nBadDown;
112 while (remainingBad>0) {
113 Int_t nBadChannel;
114 if (remainingBad<5) {
115 nBadChannel = remainingBad;
116 } else {
117 Int_t width = remainingBad-(5-1);
118 if (width>4) width = 4;
119 nBadChannel = 5 + Int_t(width*gran->Uniform());
120 }
121
122
123 Int_t iChannelPos = Int_t( (4*64-nBadChannel)*gran->Uniform() );
124 // Int_t iChip = iChannelPos/64;
125 // Int_t iChan = iChannelPos - iChip*64;
126 if(resd->IsBadChannel(iChannelPos)) continue;
127 Int_t *clus = new Int_t[nBadChannel];
128 Int_t ich = iChannelPos;
129 for(Int_t i=0;i<nBadChannel;i++){
130 clus[i]=ich;
131 ich++;
132 }
133
134 for(Int_t i=0;i<nBadChannel;i++){
135 if(resd->IsBadChannel(clus[i])) break;
136 resd->SetBadChannel(count,clus[i]);
137 count++;
138 }
139 remainingBad -= nBadChannel;
140 delete [] clus;
141 }
142
143 // May happen that, due to overlapping clusters, we
144 // have less bad channels than requested
145 // Let's put the remaining one per one ...
146 Int_t nSeToBad = 0;
147 for (Int_t i=0; i<4; i++){
148 for(Int_t j=0;j<64;j++){
149 if (resd->Gain(0,i,j)<0.0001) nSeToBad++;
150 }
151 }
152 while (nSeToBad<nBadDown) {
153 Int_t i = Int_t(4*64*gran->Uniform());
154 if(resd->IsBadChannel(i)==kFALSE){
155 resd->SetBadChannel(count,i);
156 count++;
157 nSeToBad++;
158 }
159 }
160
161 remainingBad = nBadUp;
162 while (remainingBad>0) {
163 Int_t nBadChannel;
164 if (remainingBad<5) {
165 nBadChannel = remainingBad;
166 } else {
167 Int_t width = remainingBad-(5-1);
168 if (width>4) width = 4;
169 nBadChannel = 5 + Int_t(width*gran->Uniform());
170 }
171
172 Int_t iChannelPos = Int_t( (4*64-nBadChannel)*gran->Uniform() );
173 // Int_t iChip = iChannelPos/64;
174 // Int_t iChan = iChannelPos - iChip*64;
175 if(resd->IsBadChannel(iChannelPos)) continue;
176
177 Int_t *clus = new Int_t[nBadChannel];
178 Int_t ich = iChannelPos;
179 for(Int_t i=0;i<nBadChannel;i++){
180 clus[i]=ich+256;
181 ich++;
182 }
183 for(Int_t i=0;i<nBadChannel;i++){
184
185 if(resd->IsBadChannel(clus[i])) break;
186 resd->SetBadChannel(count,clus[i]);
187 count++;
188
189 }
190 remainingBad -= nBadChannel;
191 delete [] clus;
192 }
193
194 nSeToBad = 0;
195 for (Int_t i=0; i<4; i++){
196 for(Int_t j=0;j<64;j++){
197 if (resd->Gain(1,i,j)<0.0001) nSeToBad++;
198 }
199 }
200
201 while (nSeToBad<nBadUp) {
202 Int_t i = Int_t(4*64*gran->Uniform());
203 if(resd->IsBadChannel(i+256)==kFALSE){
204 resd->SetBadChannel(count,i+256);
205 count++;
206 nSeToBad++;
207 }
208 }
209
210 //baselines
211 /*
212 for(Int_t nan=0;nan<512;nan++){
213
214 Int_t baseline = resd->GetBaseline(0);
215 Double_t noise = resd->GetNoiseAfterElectronics(0);
216 resd->SetBaseline(nan,baseline+(Int_t)gran->Gaus(0,4)); //baseline di def. e' 20, ho messo variazione di 4
217 resd->SetNoiseAfterElectronics(nan,noise+(Double_t)gran->Gaus(0,0.6));
218
219 }
220 */
221
222
223 if(mod==88) resd->SetDead();
224 respSDD.Add(resd);
225 printf("Added module %d\n",mod);
226 }
227
228 FILE* out = fopen("deadchannels.dat","w");
229 for(Int_t i=0;i<260;i++){
230 fprintf(out,"MODULE=%d\n",i);
231 AliITSCalibrationSDD* cl = (AliITSCalibrationSDD*)respSDD.At(i);
232 Int_t ndead=cl->GetDeadChannels();
233 fprintf(out,"n %d\n",ndead);
234 for(Int_t n=0;n<ndead;n++){
235 fprintf(out,"%d\n",cl->GetBadChannel(n));
236 }
237 }
238 fclose(out);
239 AliCDBManager::Instance()->GetDefaultStorage()->Put(&respSDD, idCalSDD, md1);
240 AliCDBManager::Instance()->GetDefaultStorage()->Put(rd, idRespSDD, md2);
241}