Coding conventions (Christian)
[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
30// storage `local://cdb' which is a directory in the current
31// directory.
32//
33#include "AliLog.h" // ALILOG_H
34#include "AliFMDCalibFaker.h" // ALIFMDCALIBFAKER_H
35#include "AliFMDCalibGain.h" // ALIFMDCALIBGAIN_H
36#include "AliFMDCalibPedestal.h" // ALIFMDCALIBPEDESTAL_H
37#include "AliFMDCalibSampleRate.h" // ALIFMDCALIBPEDESTAL_H
38#include "AliFMDAltroMapping.h" // ALIFMDALTROMAPPING_H
c2fc1258 39#include "AliFMDCalibStripRange.h" // ALIFMDCALIBSTRIPRANGE_H
20345ac5 40#include <AliCDBManager.h> // ALICDBMANAGER_H
41#include <AliCDBEntry.h> // ALICDBMANAGER_H
02a27b50 42//#include <Riostream.h>
20345ac5 43#include <TSystem.h>
02a27b50 44// #include <TMath.h>
1e8f773e 45#include <TROOT.h>
20345ac5 46#include <TRandom.h>
47
48//====================================================================
49ClassImp(AliFMDCalibFaker)
50#if 0
51 ; // This is here to keep Emacs for indenting the next line
52#endif
53
54//____________________________________________________________________
55AliFMDCalibFaker::AliFMDCalibFaker(Int_t mask, const char* loc)
56 : TTask("FMDCalibFaker", loc),
57 fMask(mask),
58 fGain(-1),
59 fThresholdFactor(.1),
60 fThreshold(-1),
61 fPedestalMin(20),
62 fPedestalMax(30),
63 fDeadChance(0),
64 fRate(1),
65 fZeroThreshold(0),
66 fRunMin(0),
c2fc1258 67 fRunMax(10),
68 fStripMin(0),
69 fStripMax(127)
20345ac5 70{
71 // Default constructor
72}
73
74
75#define MAKE_META(meta) \
76 do { \
77 meta = new AliCDBMetaData; \
78 meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data()); \
79 meta->SetAliRootVersion(gROOT->GetVersion()); \
80 meta->SetBeamPeriod(1); \
81 meta->SetComment("Dummy data for testing"); } while (false);
82
83
84//__________________________________________________________________
85void
86AliFMDCalibFaker::Exec(Option_t*)
87{
88 // Make the objects.
89 AliCDBManager* cdb = AliCDBManager::Instance();
90 AliFMDParameters* param = AliFMDParameters::Instance();
91 Float_t maxADC = param->GetAltroChannelSize();
92 TObjArray cleanup;
93
c2fc1258 94 if (GetTitle() && GetTitle()[0] != '\0') {
95 AliInfo(Form("Setting default storage to '%s'", GetTitle()));
96 cdb->SetDefaultStorage(GetTitle());
97 }
98
20345ac5 99
100 AliCDBMetaData* meta = 0;
101 if (TESTBIT(fMask, kPulseGain)) {
102 if (fGain <= 0)
103 fGain = (param->GetVA1MipRange() * param->GetEdepMip() / maxADC);
104 fThreshold = fThresholdFactor * param->GetEdepMip();
105 AliFMDCalibGain* gain = MakePulseGain();
02a27b50 106 AliCDBId id(AliFMDParameters::PulseGainPath(), fRunMin, fRunMax);
20345ac5 107 MAKE_META(meta);
108 meta->SetProperty("key1", gain);
109 cdb->Put(gain, id, meta);
110 cleanup.Add(gain);
111 cleanup.Add(meta);
112 }
113 if (TESTBIT(fMask, kPedestal)) {
114 fPedestalMin = TMath::Max(TMath::Min(fPedestalMin, maxADC), 0.F);
115 fPedestalMax = TMath::Max(TMath::Min(fPedestalMax, maxADC), fPedestalMin);
116 AliFMDCalibPedestal* pedestal = MakePedestal();
02a27b50 117 AliCDBId id(AliFMDParameters::PedestalPath(), fRunMin, fRunMax);
20345ac5 118 MAKE_META(meta);
119 meta->SetProperty("key1", pedestal);
120 cdb->Put(pedestal, id, meta);
121 cleanup.Add(pedestal);
122 cleanup.Add(meta);
123 }
124 if (TESTBIT(fMask, kDeadMap)) {
125 fDeadChance = TMath::Max(TMath::Min(fDeadChance, 1.F), 0.F);
126 AliFMDCalibDeadMap* deadMap = MakeDeadMap();
02a27b50 127 AliCDBId id(AliFMDParameters::DeadPath(), fRunMin, fRunMax);
20345ac5 128 MAKE_META(meta);
129 meta->SetProperty("key1", deadMap);
130 cdb->Put(deadMap, id, meta);
131 cleanup.Add(deadMap);
132 cleanup.Add(meta);
133 }
134 if (TESTBIT(fMask, kZeroSuppression)) {
135 fZeroThreshold = TMath::Min(fZeroThreshold, UShort_t(maxADC));
136 AliFMDCalibZeroSuppression* zeroSup = MakeZeroSuppression();
02a27b50 137 AliCDBId id(AliFMDParameters::ZeroSuppressionPath(),
20345ac5 138 fRunMin, fRunMax);
139 MAKE_META(meta);
140 meta->SetProperty("key1", zeroSup);
141 cdb->Put(zeroSup, id, meta);
142 cleanup.Add(zeroSup);
143 cleanup.Add(meta);
144 }
145 if (TESTBIT(fMask, kSampleRate)) {
146 fRate = TMath::Max(TMath::Min(fRate, UShort_t(8)), UShort_t(1));
147 AliFMDCalibSampleRate* rate = MakeSampleRate();
02a27b50 148 AliCDBId id(AliFMDParameters::SampleRatePath(),fRunMin,fRunMax);
20345ac5 149 MAKE_META(meta);
150 meta->SetProperty("key1", rate);
151 cdb->Put(rate, id, meta);
152 cleanup.Add(rate);
153 cleanup.Add(meta);
154 }
c2fc1258 155 if (TESTBIT(fMask, kStripRange)) {
156 fRate = TMath::Max(TMath::Min(fRate, UShort_t(8)), UShort_t(1));
157 AliFMDCalibStripRange* range = MakeStripRange();
02a27b50 158 AliCDBId id(AliFMDParameters::StripRangePath(),fRunMin,fRunMax);
c2fc1258 159 MAKE_META(meta);
160 meta->SetProperty("key1", range);
161 cdb->Put(range, id, meta);
162 cleanup.Add(range);
163 cleanup.Add(meta);
164 }
20345ac5 165 if (TESTBIT(fMask, kAltroMap)) {
166 AliFMDAltroMapping* altroMap = MakeAltroMap();
02a27b50 167 AliCDBId id(AliFMDParameters::AltroMapPath(), fRunMin, fRunMax);
20345ac5 168 MAKE_META(meta);
169 meta->SetProperty("key1", altroMap);
170 cdb->Put(altroMap, id, meta);
171 cleanup.Add(altroMap);
172 cleanup.Add(meta);
173 }
174 cdb->Destroy();
175 cleanup.Delete();
176}
177
178
179//__________________________________________________________________
180AliFMDCalibGain*
02a27b50 181AliFMDCalibFaker::MakePulseGain() const
20345ac5 182{
183 // Make the actual data
184 AliFMDCalibGain* gain = new AliFMDCalibGain;
185 // Set threshold
186 gain->Set(fThreshold);
187 for (UShort_t det = 1; det <= 3; det++) {
188 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
189 for (Char_t* ring = rings; *ring != '\0'; ring++) {
190 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
191 UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
192 for (UShort_t sec = 0; sec < nSec; sec++) {
193 for (UShort_t str = 0; str < nStr; str++) {
194 gain->Set(det, *ring, sec, str,
195 gRandom->Gaus(fGain, .01 * fGain));
196 }
197 }
198 }
199 }
200 return gain;
201}
202
203//__________________________________________________________________
204AliFMDCalibPedestal*
02a27b50 205AliFMDCalibFaker::MakePedestal() const
20345ac5 206{
207 // Make the actual data
208 AliFMDCalibPedestal* pedestal = new AliFMDCalibPedestal;
209 for (UShort_t det = 1; det <= 3; det++) {
210 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
211 for (Char_t* ring = rings; *ring != '\0'; ring++) {
212 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
213 UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
214 for (UShort_t sec = 0; sec < nSec; sec++) {
215 for (UShort_t str = 0; str < nStr; str++) {
216 pedestal->Set(det, *ring, sec, str,
217 gRandom->Uniform(fPedestalMin, fPedestalMax), 1.5);
218 }
219 }
220 }
221 }
222 return pedestal;
223}
224
225//__________________________________________________________________
226AliFMDCalibDeadMap*
02a27b50 227AliFMDCalibFaker::MakeDeadMap() const
20345ac5 228{
229 // Make the actual data
230 AliFMDCalibDeadMap* deadmap = new AliFMDCalibDeadMap;
231 for (UShort_t det = 1; det <= 3; det++) {
232 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
233 for (Char_t* ring = rings; *ring != '\0'; ring++) {
234 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
235 UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
236 for (UShort_t sec = 0; sec < nSec; sec++) {
237 for (UShort_t str = 0; str < nStr; str++) {
238 deadmap->operator()(det, *ring, sec, str) =
239 gRandom->Uniform(0, 1) < fDeadChance;
240 }
241 }
242 }
243 }
244 return deadmap;
245}
246
247//__________________________________________________________________
248AliFMDCalibZeroSuppression*
02a27b50 249AliFMDCalibFaker::MakeZeroSuppression() const
20345ac5 250{
251 // Make the actual data
252 AliFMDCalibZeroSuppression* zs = new AliFMDCalibZeroSuppression;
253 for (UShort_t det = 1; det <= 3; det++) {
254 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
255 for (Char_t* ring = rings; *ring != '\0'; ring++) {
256 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
257 UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
258 for (UShort_t sec = 0; sec < nSec; sec++) {
259 for (UShort_t str = 0; str < nStr; str++) {
260 zs->operator()(det, *ring, sec, str) = fZeroThreshold;
261 }
262 }
263 }
264 }
265 return zs;
266}
267
268//__________________________________________________________________
269AliFMDCalibSampleRate*
02a27b50 270AliFMDCalibFaker::MakeSampleRate() const
20345ac5 271{
02a27b50 272 // Make sample rates
20345ac5 273 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate;
c2fc1258 274 for (UShort_t det = 1; det <= 3; det++) {
275 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
276 for (Char_t* ring = rings; *ring != '\0'; ring++) {
277 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
278 for (UShort_t sec = 0; sec < nSec; sec++) {
279 sampleRate->Set(det, *ring, sec, 0, fRate);
280 }
281 }
282 }
20345ac5 283 return sampleRate;
284}
285
286//__________________________________________________________________
c2fc1258 287AliFMDCalibStripRange*
02a27b50 288AliFMDCalibFaker::MakeStripRange() const
c2fc1258 289{
02a27b50 290 // Make strip ranges
c2fc1258 291 AliFMDCalibStripRange* striprange = new AliFMDCalibStripRange;
292 for (UShort_t det = 1; det <= 3; det++) {
293 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
294 for (Char_t* ring = rings; *ring != '\0'; ring++) {
295 UShort_t nSec = ( *ring == 'I' ? 20 : 40 );
296 for (UShort_t sec = 0; sec < nSec; sec++) {
297 striprange->Set(det, *ring, sec, 0, fStripMin, fStripMax);
298 }
299 }
300 }
301 return striprange;
302}
303
304//__________________________________________________________________
20345ac5 305AliFMDAltroMapping*
02a27b50 306AliFMDCalibFaker::MakeAltroMap() const
20345ac5 307{
02a27b50 308 // Make hardware mapping
20345ac5 309 AliFMDAltroMapping* m = new AliFMDAltroMapping;
310 return m;
311}
312
313
314
315//____________________________________________________________________
316//
317// EOF
318//