bug fix
[u/mrichter/AliRoot.git] / FMD / AliFMDCalibFaker.cxx
CommitLineData
20345ac5 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 **************************************************************************/
20345ac5 15/* $Id$ */
c2fc1258 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
02a27b50 20 @ingroup FMD_util
c2fc1258 21*/
20345ac5 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
162637e4 30// storage `local://$ALICE_ROOT/OCDB' which is were the sources live (sigh!
6169f936 31// - why oh why do we need to shit where we eat - it's just not
32// healty).
20345ac5 33//
f95a63c4 34#include "AliFMDDebug.h" // ALIFMDDEBUG_H ALILOG_H
20345ac5 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
c2fc1258 40#include "AliFMDCalibStripRange.h" // ALIFMDCALIBSTRIPRANGE_H
20345ac5 41#include <AliCDBManager.h> // ALICDBMANAGER_H
42#include <AliCDBEntry.h> // ALICDBMANAGER_H
02a27b50 43//#include <Riostream.h>
20345ac5 44#include <TSystem.h>
02a27b50 45// #include <TMath.h>
1e8f773e 46#include <TROOT.h>
20345ac5 47#include <TRandom.h>
a9579262 48#include <TF1.h>
20345ac5 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),
2aeec17d 66 fRate(4),
20345ac5 67 fZeroThreshold(0),
68 fRunMin(0),
c2fc1258 69 fRunMax(10),
70 fStripMin(0),
71 fStripMax(127)
20345ac5 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();
8ec606c2 93 Float_t maxADC = 1.F*param->GetAltroChannelSize();
20345ac5 94 TObjArray cleanup;
95
c2fc1258 96 if (GetTitle() && GetTitle()[0] != '\0') {
97 AliInfo(Form("Setting default storage to '%s'", GetTitle()));
98 cdb->SetDefaultStorage(GetTitle());
99 }
100
20345ac5 101
102 AliCDBMetaData* meta = 0;
103 if (TESTBIT(fMask, kPulseGain)) {
8ec606c2 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 }
20345ac5 110 fThreshold = fThresholdFactor * param->GetEdepMip();
111 AliFMDCalibGain* gain = MakePulseGain();
02a27b50 112 AliCDBId id(AliFMDParameters::PulseGainPath(), fRunMin, fRunMax);
20345ac5 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();
8ec606c2 123 AliCDBId id(AliFMDParameters::PedestalPath(),fRunMin,fRunMax);
20345ac5 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();
02a27b50 133 AliCDBId id(AliFMDParameters::DeadPath(), fRunMin, fRunMax);
20345ac5 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();
02a27b50 143 AliCDBId id(AliFMDParameters::ZeroSuppressionPath(),
20345ac5 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();
8ec606c2 154 AliCDBId id(AliFMDParameters::SampleRatePath(),
155 fRunMin,fRunMax);
20345ac5 156 MAKE_META(meta);
157 meta->SetProperty("key1", rate);
158 cdb->Put(rate, id, meta);
159 cleanup.Add(rate);
160 cleanup.Add(meta);
161 }
c2fc1258 162 if (TESTBIT(fMask, kStripRange)) {
163 fRate = TMath::Max(TMath::Min(fRate, UShort_t(8)), UShort_t(1));
164 AliFMDCalibStripRange* range = MakeStripRange();
8ec606c2 165 AliCDBId id(AliFMDParameters::StripRangePath(),
166 fRunMin,fRunMax);
c2fc1258 167 MAKE_META(meta);
168 meta->SetProperty("key1", range);
169 cdb->Put(range, id, meta);
170 cleanup.Add(range);
171 cleanup.Add(meta);
172 }
20345ac5 173 if (TESTBIT(fMask, kAltroMap)) {
174 AliFMDAltroMapping* altroMap = MakeAltroMap();
02a27b50 175 AliCDBId id(AliFMDParameters::AltroMapPath(), fRunMin, fRunMax);
20345ac5 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*
02a27b50 189AliFMDCalibFaker::MakePulseGain() const
20345ac5 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//__________________________________________________________________
a9579262 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//__________________________________________________________________
20345ac5 239AliFMDCalibPedestal*
02a27b50 240AliFMDCalibFaker::MakePedestal() const
20345ac5 241{
242 // Make the actual data
243 AliFMDCalibPedestal* pedestal = new AliFMDCalibPedestal;
a9579262 244
20345ac5 245 for (UShort_t det = 1; det <= 3; det++) {
a9579262 246 Char_t rings[] = { 'I', 'O', '\0' };
20345ac5 247 for (Char_t* ring = rings; *ring != '\0'; ring++) {
a9579262 248 if (*ring == 'O' && det == 1) continue;
20345ac5 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++) {
a9579262 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 }
20345ac5 257 }
258 }
259 }
260 return pedestal;
261}
262
263//__________________________________________________________________
264AliFMDCalibDeadMap*
02a27b50 265AliFMDCalibFaker::MakeDeadMap() const
20345ac5 266{
267 // Make the actual data
133f1578 268 AliFMDCalibDeadMap* deadmap = new AliFMDCalibDeadMap(0);
269 TRandom* random = new TRandom(0);
20345ac5 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) =
133f1578 278 random->Uniform(0, 1) < fDeadChance;
20345ac5 279 }
280 }
281 }
282 }
133f1578 283 if (AliDebugLevel() > 20) deadmap->Print();
20345ac5 284 return deadmap;
285}
286
287//__________________________________________________________________
288AliFMDCalibZeroSuppression*
02a27b50 289AliFMDCalibFaker::MakeZeroSuppression() const
20345ac5 290{
291 // Make the actual data
133f1578 292 AliFMDCalibZeroSuppression* zs = new AliFMDCalibZeroSuppression(0);
20345ac5 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*
02a27b50 310AliFMDCalibFaker::MakeSampleRate() const
20345ac5 311{
02a27b50 312 // Make sample rates
20345ac5 313 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate;
c2fc1258 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 }
20345ac5 323 return sampleRate;
324}
325
326//__________________________________________________________________
c2fc1258 327AliFMDCalibStripRange*
02a27b50 328AliFMDCalibFaker::MakeStripRange() const
c2fc1258 329{
02a27b50 330 // Make strip ranges
c2fc1258 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//__________________________________________________________________
20345ac5 345AliFMDAltroMapping*
02a27b50 346AliFMDCalibFaker::MakeAltroMap() const
20345ac5 347{
02a27b50 348 // Make hardware mapping
20345ac5 349 AliFMDAltroMapping* m = new AliFMDAltroMapping;
350 return m;
351}
352
353
354
355//____________________________________________________________________
356//
357// EOF
358//