]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - FMD/AliFMDCalibFaker.cxx
bug fix
[u/mrichter/AliRoot.git] / FMD / AliFMDCalibFaker.cxx
... / ...
CommitLineData
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/* $Id$ */
16/** @file AliFMDCalibFaker.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Sun Mar 26 18:29:21 2006
19 @brief Make fake calibration data
20 @ingroup FMD_util
21*/
22//____________________________________________________________________
23//
24// Forward Multiplicity Detector based on Silicon wafers.
25//
26// This task creates fake calibrations. Which calibration, depends on
27// the bit mask passed to the constructor, or added by `AddCalib'.
28//
29// The default is to write all calibration parameters to a local
30// storage `local://$ALICE_ROOT/OCDB' which is were the sources live (sigh!
31// - why oh why do we need to shit where we eat - it's just not
32// healty).
33//
34#include "AliFMDDebug.h" // ALIFMDDEBUG_H ALILOG_H
35#include "AliFMDCalibFaker.h" // ALIFMDCALIBFAKER_H
36#include "AliFMDCalibGain.h" // ALIFMDCALIBGAIN_H
37#include "AliFMDCalibPedestal.h" // ALIFMDCALIBPEDESTAL_H
38#include "AliFMDCalibSampleRate.h" // ALIFMDCALIBPEDESTAL_H
39#include "AliFMDAltroMapping.h" // ALIFMDALTROMAPPING_H
40#include "AliFMDCalibStripRange.h" // ALIFMDCALIBSTRIPRANGE_H
41#include <AliCDBManager.h> // ALICDBMANAGER_H
42#include <AliCDBEntry.h> // ALICDBMANAGER_H
43//#include <Riostream.h>
44#include <TSystem.h>
45// #include <TMath.h>
46#include <TROOT.h>
47#include <TRandom.h>
48#include <TF1.h>
49
50//====================================================================
51ClassImp(AliFMDCalibFaker)
52#if 0
53 ; // This is here to keep Emacs for indenting the next line
54#endif
55
56//____________________________________________________________________
57AliFMDCalibFaker::AliFMDCalibFaker(Int_t mask, const char* loc)
58 : TTask("FMDCalibFaker", loc),
59 fMask(mask),
60 fGain(-1),
61 fThresholdFactor(.1),
62 fThreshold(-1),
63 fPedestalMin(20),
64 fPedestalMax(30),
65 fDeadChance(0),
66 fRate(4),
67 fZeroThreshold(0),
68 fRunMin(0),
69 fRunMax(10),
70 fStripMin(0),
71 fStripMax(127)
72{
73 // Default constructor
74}
75
76
77#define MAKE_META(meta) \
78 do { \
79 meta = new AliCDBMetaData; \
80 meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data()); \
81 meta->SetAliRootVersion(gROOT->GetVersion()); \
82 meta->SetBeamPeriod(1); \
83 meta->SetComment("Dummy data for testing"); } while (false);
84
85
86//__________________________________________________________________
87void
88AliFMDCalibFaker::Exec(Option_t*)
89{
90 // Make the objects.
91 AliCDBManager* cdb = AliCDBManager::Instance();
92 AliFMDParameters* param = AliFMDParameters::Instance();
93 Float_t maxADC = 1.F*param->GetAltroChannelSize();
94 TObjArray cleanup;
95
96 if (GetTitle() && GetTitle()[0] != '\0') {
97 AliInfo(Form("Setting default storage to '%s'", GetTitle()));
98 cdb->SetDefaultStorage(GetTitle());
99 }
100
101
102 AliCDBMetaData* meta = 0;
103 if (TESTBIT(fMask, kPulseGain)) {
104 // Info("Exec","Default gain to %f = %d * %f / %d",
105 // (param->GetVA1MipRange() * param->GetEdepMip() / maxADC),
106 // param->GetVA1MipRange(), param->GetEdepMip(), Int_t(maxADC));
107 if (fGain <= 0) {
108 fGain = (param->GetVA1MipRange() * param->GetEdepMip() / maxADC);
109 }
110 fThreshold = fThresholdFactor * param->GetEdepMip();
111 AliFMDCalibGain* gain = MakePulseGain();
112 AliCDBId id(AliFMDParameters::PulseGainPath(), fRunMin, fRunMax);
113 MAKE_META(meta);
114 meta->SetProperty("key1", gain);
115 cdb->Put(gain, id, meta);
116 cleanup.Add(gain);
117 cleanup.Add(meta);
118 }
119 if (TESTBIT(fMask, kPedestal)) {
120 fPedestalMin = TMath::Max(TMath::Min(fPedestalMin, maxADC), 0.F);
121 fPedestalMax = TMath::Max(TMath::Min(fPedestalMax, maxADC), fPedestalMin);
122 AliFMDCalibPedestal* pedestal = MakePedestal();
123 AliCDBId id(AliFMDParameters::PedestalPath(),fRunMin,fRunMax);
124 MAKE_META(meta);
125 meta->SetProperty("key1", pedestal);
126 cdb->Put(pedestal, id, meta);
127 cleanup.Add(pedestal);
128 cleanup.Add(meta);
129 }
130 if (TESTBIT(fMask, kDeadMap)) {
131 fDeadChance = TMath::Max(TMath::Min(fDeadChance, 1.F), 0.F);
132 AliFMDCalibDeadMap* deadMap = MakeDeadMap();
133 AliCDBId id(AliFMDParameters::DeadPath(), fRunMin, fRunMax);
134 MAKE_META(meta);
135 meta->SetProperty("key1", deadMap);
136 cdb->Put(deadMap, id, meta);
137 cleanup.Add(deadMap);
138 cleanup.Add(meta);
139 }
140 if (TESTBIT(fMask, kZeroSuppression)) {
141 fZeroThreshold = TMath::Min(fZeroThreshold, UShort_t(maxADC));
142 AliFMDCalibZeroSuppression* zeroSup = MakeZeroSuppression();
143 AliCDBId id(AliFMDParameters::ZeroSuppressionPath(),
144 fRunMin, fRunMax);
145 MAKE_META(meta);
146 meta->SetProperty("key1", zeroSup);
147 cdb->Put(zeroSup, id, meta);
148 cleanup.Add(zeroSup);
149 cleanup.Add(meta);
150 }
151 if (TESTBIT(fMask, kSampleRate)) {
152 fRate = TMath::Max(TMath::Min(fRate, UShort_t(8)), UShort_t(1));
153 AliFMDCalibSampleRate* rate = MakeSampleRate();
154 AliCDBId id(AliFMDParameters::SampleRatePath(),
155 fRunMin,fRunMax);
156 MAKE_META(meta);
157 meta->SetProperty("key1", rate);
158 cdb->Put(rate, id, meta);
159 cleanup.Add(rate);
160 cleanup.Add(meta);
161 }
162 if (TESTBIT(fMask, kStripRange)) {
163 fRate = TMath::Max(TMath::Min(fRate, UShort_t(8)), UShort_t(1));
164 AliFMDCalibStripRange* range = MakeStripRange();
165 AliCDBId id(AliFMDParameters::StripRangePath(),
166 fRunMin,fRunMax);
167 MAKE_META(meta);
168 meta->SetProperty("key1", range);
169 cdb->Put(range, id, meta);
170 cleanup.Add(range);
171 cleanup.Add(meta);
172 }
173 if (TESTBIT(fMask, kAltroMap)) {
174 AliFMDAltroMapping* altroMap = MakeAltroMap();
175 AliCDBId id(AliFMDParameters::AltroMapPath(), fRunMin, fRunMax);
176 MAKE_META(meta);
177 meta->SetProperty("key1", altroMap);
178 cdb->Put(altroMap, id, meta);
179 cleanup.Add(altroMap);
180 cleanup.Add(meta);
181 }
182 cdb->Destroy();
183 cleanup.Delete();
184}
185
186
187//__________________________________________________________________
188AliFMDCalibGain*
189AliFMDCalibFaker::MakePulseGain() const
190{
191 // Make the actual data
192 AliFMDCalibGain* gain = new AliFMDCalibGain;
193 // Set threshold
194 gain->Set(fThreshold);
195 for (UShort_t det = 1; det <= 3; det++) {
196 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
197 for (Char_t* ring = rings; *ring != '\0'; ring++) {
198 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
199 UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
200 for (UShort_t sec = 0; sec < nSec; sec++) {
201 for (UShort_t str = 0; str < nStr; str++) {
202 gain->Set(det, *ring, sec, str,
203 gRandom->Gaus(fGain, .01 * fGain));
204 }
205 }
206 }
207 }
208 return gain;
209}
210
211//__________________________________________________________________
212Float_t
213AliFMDCalibFaker::MakeNoise(Char_t ring, UShort_t str) const
214{
215 const UShort_t innerN = 512;
216 const UShort_t outerN = 256;
217 const UShort_t innerCut = 350;
218 const UShort_t outerCut = 190;
219 const Float_t innerBase = 1.2;
220 const Float_t outerBase = 2.1;
221 const Float_t innerInc = 0.5;
222 const Float_t outerInc = 0.8;
223 Float_t cut, base, inc, n;
224 switch (ring) {
225 case 'I':
226 cut = innerCut; base = innerBase; inc = innerInc; n = innerN; break;
227 case 'O':
228 cut = outerCut; base = outerBase; inc = outerInc; n = outerN; break;
229 default:
230 return -1;
231 }
232 Float_t bare = base + (str < cut ?
233 str / cut * inc :
234 inc - (str - cut) / (n - cut) * inc);
235 return bare + gRandom->Uniform(-.07, .07);
236}
237
238//__________________________________________________________________
239AliFMDCalibPedestal*
240AliFMDCalibFaker::MakePedestal() const
241{
242 // Make the actual data
243 AliFMDCalibPedestal* pedestal = new AliFMDCalibPedestal;
244
245 for (UShort_t det = 1; det <= 3; det++) {
246 Char_t rings[] = { 'I', 'O', '\0' };
247 for (Char_t* ring = rings; *ring != '\0'; ring++) {
248 if (*ring == 'O' && det == 1) continue;
249 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
250 UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
251 for (UShort_t sec = 0; sec < nSec; sec++) {
252 for (UShort_t str = 0; str < nStr; str++) {
253 Float_t noise = MakeNoise(*ring, str);
254 Float_t ped = gRandom->Uniform(fPedestalMin, fPedestalMax);
255 pedestal->Set(det, *ring, sec, str, ped, noise);
256 }
257 }
258 }
259 }
260 return pedestal;
261}
262
263//__________________________________________________________________
264AliFMDCalibDeadMap*
265AliFMDCalibFaker::MakeDeadMap() const
266{
267 // Make the actual data
268 AliFMDCalibDeadMap* deadmap = new AliFMDCalibDeadMap(0);
269 TRandom* random = new TRandom(0);
270 for (UShort_t det = 1; det <= 3; det++) {
271 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
272 for (Char_t* ring = rings; *ring != '\0'; ring++) {
273 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
274 UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
275 for (UShort_t sec = 0; sec < nSec; sec++) {
276 for (UShort_t str = 0; str < nStr; str++) {
277 deadmap->operator()(det, *ring, sec, str) =
278 random->Uniform(0, 1) < fDeadChance;
279 }
280 }
281 }
282 }
283 if (AliDebugLevel() > 20) deadmap->Print();
284 return deadmap;
285}
286
287//__________________________________________________________________
288AliFMDCalibZeroSuppression*
289AliFMDCalibFaker::MakeZeroSuppression() const
290{
291 // Make the actual data
292 AliFMDCalibZeroSuppression* zs = new AliFMDCalibZeroSuppression(0);
293 for (UShort_t det = 1; det <= 3; det++) {
294 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
295 for (Char_t* ring = rings; *ring != '\0'; ring++) {
296 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
297 UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
298 for (UShort_t sec = 0; sec < nSec; sec++) {
299 for (UShort_t str = 0; str < nStr; str++) {
300 zs->operator()(det, *ring, sec, str) = fZeroThreshold;
301 }
302 }
303 }
304 }
305 return zs;
306}
307
308//__________________________________________________________________
309AliFMDCalibSampleRate*
310AliFMDCalibFaker::MakeSampleRate() const
311{
312 // Make sample rates
313 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate;
314 for (UShort_t det = 1; det <= 3; det++) {
315 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
316 for (Char_t* ring = rings; *ring != '\0'; ring++) {
317 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
318 for (UShort_t sec = 0; sec < nSec; sec++) {
319 sampleRate->Set(det, *ring, sec, 0, fRate);
320 }
321 }
322 }
323 return sampleRate;
324}
325
326//__________________________________________________________________
327AliFMDCalibStripRange*
328AliFMDCalibFaker::MakeStripRange() const
329{
330 // Make strip ranges
331 AliFMDCalibStripRange* striprange = new AliFMDCalibStripRange;
332 for (UShort_t det = 1; det <= 3; det++) {
333 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
334 for (Char_t* ring = rings; *ring != '\0'; ring++) {
335 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
336 for (UShort_t sec = 0; sec < nSec; sec++) {
337 striprange->Set(det, *ring, sec, 0, fStripMin, fStripMax);
338 }
339 }
340 }
341 return striprange;
342}
343
344//__________________________________________________________________
345AliFMDAltroMapping*
346AliFMDCalibFaker::MakeAltroMap() const
347{
348 // Make hardware mapping
349 AliFMDAltroMapping* m = new AliFMDAltroMapping;
350 return m;
351}
352
353
354
355//____________________________________________________________________
356//
357// EOF
358//