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