]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDCalibFaker.cxx
DP:Misalignment of CPV added
[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' 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 "AliLog.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 //====================================================================
51 ClassImp(AliFMDCalibFaker)
52 #if 0
53   ; // This is here to keep Emacs for indenting the next line
54 #endif
55
56 //____________________________________________________________________
57 AliFMDCalibFaker::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(1),
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 //__________________________________________________________________
87 void
88 AliFMDCalibFaker::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 //__________________________________________________________________
188 AliFMDCalibGain*
189 AliFMDCalibFaker::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 //__________________________________________________________________
212 Float_t 
213 AliFMDCalibFaker::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 //__________________________________________________________________
239 AliFMDCalibPedestal*
240 AliFMDCalibFaker::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 //__________________________________________________________________
264 AliFMDCalibDeadMap*
265 AliFMDCalibFaker::MakeDeadMap() const
266 {
267   // Make the actual data
268   AliFMDCalibDeadMap*  deadmap  = new AliFMDCalibDeadMap;
269   for (UShort_t det = 1; det <= 3; det++) {
270     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
271     for (Char_t* ring = rings; *ring != '\0'; ring++) {
272       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
273       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
274       for (UShort_t sec = 0; sec < nSec; sec++) {
275         for (UShort_t str = 0; str < nStr; str++) {
276           deadmap->operator()(det, *ring, sec, str) = 
277             gRandom->Uniform(0, 1) < fDeadChance;
278         }
279       }
280     }
281   }
282   return deadmap;
283 }
284
285 //__________________________________________________________________
286 AliFMDCalibZeroSuppression*
287 AliFMDCalibFaker::MakeZeroSuppression() const
288 {
289   // Make the actual data
290   AliFMDCalibZeroSuppression*  zs  = new AliFMDCalibZeroSuppression;
291   for (UShort_t det = 1; det <= 3; det++) {
292     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
293     for (Char_t* ring = rings; *ring != '\0'; ring++) {
294       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
295       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
296       for (UShort_t sec = 0; sec < nSec; sec++) {
297         for (UShort_t str = 0; str < nStr; str++) {
298           zs->operator()(det, *ring, sec, str) =  fZeroThreshold;
299         }
300       }
301     }
302   }
303   return zs;
304 }
305
306 //__________________________________________________________________
307 AliFMDCalibSampleRate*
308 AliFMDCalibFaker::MakeSampleRate() const
309 {
310   // Make sample rates 
311   AliFMDCalibSampleRate*  sampleRate  = new AliFMDCalibSampleRate;
312   for (UShort_t det = 1; det <= 3; det++) {
313     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
314     for (Char_t* ring = rings; *ring != '\0'; ring++) {
315       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
316       for (UShort_t sec = 0; sec < nSec; sec++) {
317         sampleRate->Set(det, *ring, sec, 0, fRate);
318       }
319     }
320   }
321   return sampleRate;
322 }
323
324 //__________________________________________________________________
325 AliFMDCalibStripRange*
326 AliFMDCalibFaker::MakeStripRange() const
327 {
328   // Make strip ranges 
329   AliFMDCalibStripRange*  striprange  = new AliFMDCalibStripRange;
330   for (UShort_t det = 1; det <= 3; det++) {
331     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
332     for (Char_t* ring = rings; *ring != '\0'; ring++) {
333       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
334       for (UShort_t sec = 0; sec < nSec; sec++) {
335         striprange->Set(det, *ring, sec, 0, fStripMin, fStripMax);
336       }
337     }
338   }
339   return striprange;
340 }
341
342 //__________________________________________________________________
343 AliFMDAltroMapping*
344 AliFMDCalibFaker::MakeAltroMap() const
345 {
346   // Make hardware mapping 
347   AliFMDAltroMapping*  m  = new AliFMDAltroMapping;
348   return m;
349 }
350   
351   
352   
353 //____________________________________________________________________
354 //
355 // EOF
356 //