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