]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDCalibFaker.cxx
Moving the destructor to the implementation file
[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   = 1.F*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     // Info("Exec","Default gain to %f = %d * %f / %d", 
103     //      (param->GetVA1MipRange() * param->GetEdepMip() / maxADC),
104     //      param->GetVA1MipRange(), param->GetEdepMip(), Int_t(maxADC));
105     if (fGain <= 0) {
106       fGain = (param->GetVA1MipRange() * param->GetEdepMip() / maxADC);
107     }
108     fThreshold = fThresholdFactor * param->GetEdepMip();
109     AliFMDCalibGain* gain = MakePulseGain();
110     AliCDBId         id(AliFMDParameters::PulseGainPath(), fRunMin, fRunMax);
111     MAKE_META(meta);
112     meta->SetProperty("key1", gain);
113     cdb->Put(gain, id, meta);
114     cleanup.Add(gain);
115     cleanup.Add(meta);
116   }  
117   if (TESTBIT(fMask, kPedestal)) {
118     fPedestalMin = TMath::Max(TMath::Min(fPedestalMin, maxADC), 0.F);
119     fPedestalMax = TMath::Max(TMath::Min(fPedestalMax, maxADC), fPedestalMin);
120     AliFMDCalibPedestal* pedestal = MakePedestal();
121     AliCDBId             id(AliFMDParameters::PedestalPath(),fRunMin,fRunMax);
122     MAKE_META(meta);
123     meta->SetProperty("key1", pedestal);
124     cdb->Put(pedestal, id, meta);
125     cleanup.Add(pedestal);
126     cleanup.Add(meta);
127   }
128   if (TESTBIT(fMask, kDeadMap)) {
129     fDeadChance = TMath::Max(TMath::Min(fDeadChance, 1.F), 0.F);
130     AliFMDCalibDeadMap* deadMap = MakeDeadMap();
131     AliCDBId            id(AliFMDParameters::DeadPath(), fRunMin, fRunMax);
132     MAKE_META(meta);
133     meta->SetProperty("key1", deadMap);
134     cdb->Put(deadMap, id, meta);
135     cleanup.Add(deadMap);
136     cleanup.Add(meta);
137   }
138   if (TESTBIT(fMask, kZeroSuppression)) {
139     fZeroThreshold = TMath::Min(fZeroThreshold, UShort_t(maxADC));
140     AliFMDCalibZeroSuppression* zeroSup = MakeZeroSuppression();
141     AliCDBId                    id(AliFMDParameters::ZeroSuppressionPath(), 
142                                    fRunMin, fRunMax);
143     MAKE_META(meta);
144     meta->SetProperty("key1", zeroSup);
145     cdb->Put(zeroSup, id, meta);
146     cleanup.Add(zeroSup);
147     cleanup.Add(meta);
148   }
149   if (TESTBIT(fMask, kSampleRate)) {
150     fRate = TMath::Max(TMath::Min(fRate, UShort_t(8)), UShort_t(1));
151     AliFMDCalibSampleRate* rate = MakeSampleRate();
152     AliCDBId               id(AliFMDParameters::SampleRatePath(),
153                               fRunMin,fRunMax);
154     MAKE_META(meta);
155     meta->SetProperty("key1", rate);
156     cdb->Put(rate, id, meta);
157     cleanup.Add(rate);
158     cleanup.Add(meta);
159   }
160   if (TESTBIT(fMask, kStripRange)) {
161     fRate = TMath::Max(TMath::Min(fRate, UShort_t(8)), UShort_t(1));
162     AliFMDCalibStripRange* range = MakeStripRange();
163     AliCDBId               id(AliFMDParameters::StripRangePath(),
164                               fRunMin,fRunMax);
165     MAKE_META(meta);
166     meta->SetProperty("key1", range);
167     cdb->Put(range, id, meta);
168     cleanup.Add(range);
169     cleanup.Add(meta);
170   }
171   if (TESTBIT(fMask, kAltroMap)) {
172     AliFMDAltroMapping* altroMap = MakeAltroMap();
173     AliCDBId            id(AliFMDParameters::AltroMapPath(), fRunMin, fRunMax);
174     MAKE_META(meta);
175     meta->SetProperty("key1", altroMap);
176     cdb->Put(altroMap, id, meta);
177     cleanup.Add(altroMap);
178     cleanup.Add(meta);
179   }
180   cdb->Destroy();
181   cleanup.Delete();
182 }
183
184
185 //__________________________________________________________________
186 AliFMDCalibGain*
187 AliFMDCalibFaker::MakePulseGain() const
188 {
189   // Make the actual data
190   AliFMDCalibGain*  gain  = new AliFMDCalibGain;
191   // Set threshold 
192   gain->Set(fThreshold);
193   for (UShort_t det = 1; det <= 3; det++) {
194     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
195     for (Char_t* ring = rings; *ring != '\0'; ring++) {
196       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
197       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
198       for (UShort_t sec = 0; sec < nSec; sec++) {
199         for (UShort_t str = 0; str < nStr; str++) {
200           gain->Set(det, *ring, sec, str,
201                     gRandom->Gaus(fGain, .01 * fGain));
202         }
203       }
204     }
205   }
206   return gain;
207 }
208
209 //__________________________________________________________________
210 AliFMDCalibPedestal*
211 AliFMDCalibFaker::MakePedestal() const
212 {
213   // Make the actual data
214   AliFMDCalibPedestal*  pedestal  = new AliFMDCalibPedestal;
215   for (UShort_t det = 1; det <= 3; det++) {
216     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
217     for (Char_t* ring = rings; *ring != '\0'; ring++) {
218       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
219       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
220       for (UShort_t sec = 0; sec < nSec; sec++) {
221         for (UShort_t str = 0; str < nStr; str++) {
222           pedestal->Set(det, *ring, sec, str,
223                         gRandom->Uniform(fPedestalMin, fPedestalMax), 1.5);
224         }
225       }
226     }
227   }
228   return pedestal;
229 }
230
231 //__________________________________________________________________
232 AliFMDCalibDeadMap*
233 AliFMDCalibFaker::MakeDeadMap() const
234 {
235   // Make the actual data
236   AliFMDCalibDeadMap*  deadmap  = new AliFMDCalibDeadMap;
237   for (UShort_t det = 1; det <= 3; det++) {
238     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
239     for (Char_t* ring = rings; *ring != '\0'; ring++) {
240       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
241       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
242       for (UShort_t sec = 0; sec < nSec; sec++) {
243         for (UShort_t str = 0; str < nStr; str++) {
244           deadmap->operator()(det, *ring, sec, str) = 
245             gRandom->Uniform(0, 1) < fDeadChance;
246         }
247       }
248     }
249   }
250   return deadmap;
251 }
252
253 //__________________________________________________________________
254 AliFMDCalibZeroSuppression*
255 AliFMDCalibFaker::MakeZeroSuppression() const
256 {
257   // Make the actual data
258   AliFMDCalibZeroSuppression*  zs  = new AliFMDCalibZeroSuppression;
259   for (UShort_t det = 1; det <= 3; det++) {
260     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
261     for (Char_t* ring = rings; *ring != '\0'; ring++) {
262       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
263       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
264       for (UShort_t sec = 0; sec < nSec; sec++) {
265         for (UShort_t str = 0; str < nStr; str++) {
266           zs->operator()(det, *ring, sec, str) =  fZeroThreshold;
267         }
268       }
269     }
270   }
271   return zs;
272 }
273
274 //__________________________________________________________________
275 AliFMDCalibSampleRate*
276 AliFMDCalibFaker::MakeSampleRate() const
277 {
278   // Make sample rates 
279   AliFMDCalibSampleRate*  sampleRate  = new AliFMDCalibSampleRate;
280   for (UShort_t det = 1; det <= 3; det++) {
281     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
282     for (Char_t* ring = rings; *ring != '\0'; ring++) {
283       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
284       for (UShort_t sec = 0; sec < nSec; sec++) {
285         sampleRate->Set(det, *ring, sec, 0, fRate);
286       }
287     }
288   }
289   return sampleRate;
290 }
291
292 //__________________________________________________________________
293 AliFMDCalibStripRange*
294 AliFMDCalibFaker::MakeStripRange() const
295 {
296   // Make strip ranges 
297   AliFMDCalibStripRange*  striprange  = new AliFMDCalibStripRange;
298   for (UShort_t det = 1; det <= 3; det++) {
299     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
300     for (Char_t* ring = rings; *ring != '\0'; ring++) {
301       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
302       for (UShort_t sec = 0; sec < nSec; sec++) {
303         striprange->Set(det, *ring, sec, 0, fStripMin, fStripMax);
304       }
305     }
306   }
307   return striprange;
308 }
309
310 //__________________________________________________________________
311 AliFMDAltroMapping*
312 AliFMDCalibFaker::MakeAltroMap() const
313 {
314   // Make hardware mapping 
315   AliFMDAltroMapping*  m  = new AliFMDAltroMapping;
316   return m;
317 }
318   
319   
320   
321 //____________________________________________________________________
322 //
323 // EOF
324 //