]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDCalibFaker.cxx
Coding conventions (Christian)
[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://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
39 #include "AliFMDCalibStripRange.h" // ALIFMDCALIBSTRIPRANGE_H
40 #include <AliCDBManager.h>         // ALICDBMANAGER_H
41 #include <AliCDBEntry.h>           // ALICDBMANAGER_H
42 //#include <Riostream.h>
43 #include <TSystem.h>
44 // #include <TMath.h>
45 #include <TROOT.h>
46 #include <TRandom.h>
47
48 //====================================================================
49 ClassImp(AliFMDCalibFaker)
50 #if 0
51   ; // This is here to keep Emacs for indenting the next line
52 #endif
53
54 //____________________________________________________________________
55 AliFMDCalibFaker::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),
67     fRunMax(10),
68     fStripMin(0),
69     fStripMax(127)
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 //__________________________________________________________________
85 void
86 AliFMDCalibFaker::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
94   if (GetTitle() && GetTitle()[0] != '\0') { 
95     AliInfo(Form("Setting default storage to '%s'", GetTitle()));
96     cdb->SetDefaultStorage(GetTitle());
97   }
98   
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();
106     AliCDBId         id(AliFMDParameters::PulseGainPath(), fRunMin, fRunMax);
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();
117     AliCDBId             id(AliFMDParameters::PedestalPath(), fRunMin, fRunMax);
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();
127     AliCDBId            id(AliFMDParameters::DeadPath(), fRunMin, fRunMax);
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();
137     AliCDBId                    id(AliFMDParameters::ZeroSuppressionPath(), 
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();
148     AliCDBId               id(AliFMDParameters::SampleRatePath(),fRunMin,fRunMax);
149     MAKE_META(meta);
150     meta->SetProperty("key1", rate);
151     cdb->Put(rate, id, meta);
152     cleanup.Add(rate);
153     cleanup.Add(meta);
154   }
155   if (TESTBIT(fMask, kStripRange)) {
156     fRate = TMath::Max(TMath::Min(fRate, UShort_t(8)), UShort_t(1));
157     AliFMDCalibStripRange* range = MakeStripRange();
158     AliCDBId               id(AliFMDParameters::StripRangePath(),fRunMin,fRunMax);
159     MAKE_META(meta);
160     meta->SetProperty("key1", range);
161     cdb->Put(range, id, meta);
162     cleanup.Add(range);
163     cleanup.Add(meta);
164   }
165   if (TESTBIT(fMask, kAltroMap)) {
166     AliFMDAltroMapping* altroMap = MakeAltroMap();
167     AliCDBId            id(AliFMDParameters::AltroMapPath(), fRunMin, fRunMax);
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 //__________________________________________________________________
180 AliFMDCalibGain*
181 AliFMDCalibFaker::MakePulseGain() const
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 //__________________________________________________________________
204 AliFMDCalibPedestal*
205 AliFMDCalibFaker::MakePedestal() const
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 //__________________________________________________________________
226 AliFMDCalibDeadMap*
227 AliFMDCalibFaker::MakeDeadMap() const
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 //__________________________________________________________________
248 AliFMDCalibZeroSuppression*
249 AliFMDCalibFaker::MakeZeroSuppression() const
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 //__________________________________________________________________
269 AliFMDCalibSampleRate*
270 AliFMDCalibFaker::MakeSampleRate() const
271 {
272   // Make sample rates 
273   AliFMDCalibSampleRate*  sampleRate  = new AliFMDCalibSampleRate;
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   }
283   return sampleRate;
284 }
285
286 //__________________________________________________________________
287 AliFMDCalibStripRange*
288 AliFMDCalibFaker::MakeStripRange() const
289 {
290   // Make strip ranges 
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 //__________________________________________________________________
305 AliFMDAltroMapping*
306 AliFMDCalibFaker::MakeAltroMap() const
307 {
308   // Make hardware mapping 
309   AliFMDAltroMapping*  m  = new AliFMDAltroMapping;
310   return m;
311 }
312   
313   
314   
315 //____________________________________________________________________
316 //
317 // EOF
318 //