]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDCalibFaker.cxx
9c87aef9b81e180ec1fc9b9d00853524dc523e99
[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
16 /* $Id$ */
17
18 //____________________________________________________________________
19 //                                                                          
20 // Forward Multiplicity Detector based on Silicon wafers. 
21 //
22 // This task creates fake calibrations. Which calibration, depends on
23 // the bit mask passed to the constructor, or added by `AddCalib'.
24 //
25 // The default is to write all calibration parameters to a local
26 // storage `local://cdb' which is a directory in the current
27 // directory. 
28 //                                                       
29 #include "AliLog.h"                // ALILOG_H
30 #include "AliFMDCalibFaker.h"      // ALIFMDCALIBFAKER_H
31 #include "AliFMDCalibGain.h"       // ALIFMDCALIBGAIN_H
32 #include "AliFMDCalibPedestal.h"   // ALIFMDCALIBPEDESTAL_H
33 #include "AliFMDCalibSampleRate.h" // ALIFMDCALIBPEDESTAL_H
34 #include "AliFMDAltroMapping.h"    // ALIFMDALTROMAPPING_H
35 #include <AliCDBManager.h>         // ALICDBMANAGER_H
36 #include <AliCDBEntry.h>           // ALICDBMANAGER_H
37 #include <Riostream.h>
38 #include <TSystem.h>
39 #include <TMath.h>
40 #include <TRandom.h>
41
42 //====================================================================
43 ClassImp(AliFMDCalibFaker)
44 #if 0
45   ; // This is here to keep Emacs for indenting the next line
46 #endif
47
48 //____________________________________________________________________
49 AliFMDCalibFaker::AliFMDCalibFaker(Int_t mask, const char* loc) 
50   : TTask("FMDCalibFaker", loc),
51     fMask(mask),
52     fGain(-1),
53     fThresholdFactor(.1),
54     fThreshold(-1),
55     fPedestalMin(20),
56     fPedestalMax(30), 
57     fDeadChance(0),
58     fRate(1),
59     fZeroThreshold(0),
60     fRunMin(0),
61     fRunMax(10)
62 {
63   // Default constructor 
64 }
65
66
67 #define MAKE_META(meta) \
68   do { \
69     meta = new AliCDBMetaData; \
70     meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data()); \
71     meta->SetAliRootVersion(gROOT->GetVersion()); \
72     meta->SetBeamPeriod(1); \
73     meta->SetComment("Dummy data for testing"); } while (false);
74  
75
76 //__________________________________________________________________
77 void
78 AliFMDCalibFaker::Exec(Option_t*)
79 {
80   // Make the objects. 
81   AliCDBManager*     cdb      = AliCDBManager::Instance();
82   AliFMDParameters*  param    = AliFMDParameters::Instance();
83   Float_t            maxADC   = param->GetAltroChannelSize();
84   TObjArray          cleanup;
85
86   if (GetTitle()) cdb->SetDefaultStorage(GetTitle());
87     
88   AliCDBMetaData* meta = 0;
89   if (TESTBIT(fMask, kPulseGain)) {
90     if (fGain <= 0) 
91       fGain      = (param->GetVA1MipRange() * param->GetEdepMip() / maxADC);
92     fThreshold = fThresholdFactor * param->GetEdepMip();
93     AliFMDCalibGain* gain = MakePulseGain();
94     AliCDBId         id(AliFMDParameters::fgkPulseGain, fRunMin, fRunMax);
95     MAKE_META(meta);
96     meta->SetProperty("key1", gain);
97     cdb->Put(gain, id, meta);
98     cleanup.Add(gain);
99     cleanup.Add(meta);
100   }  
101   if (TESTBIT(fMask, kPedestal)) {
102     fPedestalMin = TMath::Max(TMath::Min(fPedestalMin, maxADC), 0.F);
103     fPedestalMax = TMath::Max(TMath::Min(fPedestalMax, maxADC), fPedestalMin);
104     AliFMDCalibPedestal* pedestal = MakePedestal();
105     AliCDBId             id(AliFMDParameters::fgkPedestal, fRunMin, fRunMax);
106     MAKE_META(meta);
107     meta->SetProperty("key1", pedestal);
108     cdb->Put(pedestal, id, meta);
109     cleanup.Add(pedestal);
110     cleanup.Add(meta);
111   }
112   if (TESTBIT(fMask, kDeadMap)) {
113     fDeadChance = TMath::Max(TMath::Min(fDeadChance, 1.F), 0.F);
114     AliFMDCalibDeadMap* deadMap = MakeDeadMap();
115     AliCDBId            id(AliFMDParameters::fgkDead, fRunMin, fRunMax);
116     MAKE_META(meta);
117     meta->SetProperty("key1", deadMap);
118     cdb->Put(deadMap, id, meta);
119     cleanup.Add(deadMap);
120     cleanup.Add(meta);
121   }
122   if (TESTBIT(fMask, kZeroSuppression)) {
123     fZeroThreshold = TMath::Min(fZeroThreshold, UShort_t(maxADC));
124     AliFMDCalibZeroSuppression* zeroSup = MakeZeroSuppression();
125     AliCDBId                    id(AliFMDParameters::fgkZeroSuppression, 
126                                    fRunMin, fRunMax);
127     MAKE_META(meta);
128     meta->SetProperty("key1", zeroSup);
129     cdb->Put(zeroSup, id, meta);
130     cleanup.Add(zeroSup);
131     cleanup.Add(meta);
132   }
133   if (TESTBIT(fMask, kSampleRate)) {
134     fRate = TMath::Max(TMath::Min(fRate, UShort_t(8)), UShort_t(1));
135     AliFMDCalibSampleRate* rate = MakeSampleRate();
136     AliCDBId               id(AliFMDParameters::fgkSampleRate,fRunMin,fRunMax);
137     MAKE_META(meta);
138     meta->SetProperty("key1", rate);
139     cdb->Put(rate, id, meta);
140     cleanup.Add(rate);
141     cleanup.Add(meta);
142   }
143   if (TESTBIT(fMask, kAltroMap)) {
144     AliFMDAltroMapping* altroMap = MakeAltroMap();
145     AliCDBId            id(AliFMDParameters::fgkAltroMap, fRunMin, fRunMax);
146     MAKE_META(meta);
147     meta->SetProperty("key1", altroMap);
148     cdb->Put(altroMap, id, meta);
149     cleanup.Add(altroMap);
150     cleanup.Add(meta);
151   }
152   cdb->Destroy();
153   cleanup.Delete();
154 }
155
156
157 //__________________________________________________________________
158 AliFMDCalibGain*
159 AliFMDCalibFaker::MakePulseGain()
160 {
161   // Make the actual data
162   AliFMDCalibGain*  gain  = new AliFMDCalibGain;
163   // Set threshold 
164   gain->Set(fThreshold);
165   for (UShort_t det = 1; det <= 3; det++) {
166     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
167     for (Char_t* ring = rings; *ring != '\0'; ring++) {
168       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
169       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
170       for (UShort_t sec = 0; sec < nSec; sec++) {
171         for (UShort_t str = 0; str < nStr; str++) {
172           gain->Set(det, *ring, sec, str,
173                     gRandom->Gaus(fGain, .01 * fGain));
174         }
175       }
176     }
177   }
178   return gain;
179 }
180
181 //__________________________________________________________________
182 AliFMDCalibPedestal*
183 AliFMDCalibFaker::MakePedestal()
184 {
185   // Make the actual data
186   AliFMDCalibPedestal*  pedestal  = new AliFMDCalibPedestal;
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           pedestal->Set(det, *ring, sec, str,
195                         gRandom->Uniform(fPedestalMin, fPedestalMax), 1.5);
196         }
197       }
198     }
199   }
200   return pedestal;
201 }
202
203 //__________________________________________________________________
204 AliFMDCalibDeadMap*
205 AliFMDCalibFaker::MakeDeadMap()
206 {
207   // Make the actual data
208   AliFMDCalibDeadMap*  deadmap  = new AliFMDCalibDeadMap;
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           deadmap->operator()(det, *ring, sec, str) = 
217             gRandom->Uniform(0, 1) < fDeadChance;
218         }
219       }
220     }
221   }
222   return deadmap;
223 }
224
225 //__________________________________________________________________
226 AliFMDCalibZeroSuppression*
227 AliFMDCalibFaker::MakeZeroSuppression()
228 {
229   // Make the actual data
230   AliFMDCalibZeroSuppression*  zs  = new AliFMDCalibZeroSuppression;
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           zs->operator()(det, *ring, sec, str) =  fZeroThreshold;
239         }
240       }
241     }
242   }
243   return zs;
244 }
245
246 //__________________________________________________________________
247 AliFMDCalibSampleRate*
248 AliFMDCalibFaker::MakeSampleRate()
249 {
250   AliFMDCalibSampleRate*  sampleRate  = new AliFMDCalibSampleRate;
251   for (int i = 0; i < 3; i++)
252     sampleRate->Set(AliFMDParameters::kBaseDDL+i, fRate);
253   return sampleRate;
254 }
255
256 //__________________________________________________________________
257 AliFMDAltroMapping*
258 AliFMDCalibFaker::MakeAltroMap()
259 {
260   AliFMDAltroMapping*  m  = new AliFMDAltroMapping;
261   return m;
262 }
263   
264   
265   
266 //____________________________________________________________________
267 //
268 // EOF
269 //