]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDCalibFaker.cxx
New RAW I/O. I rolled my own, because I wasn't happy with the old
[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 <TROOT.h>
41 #include <TRandom.h>
42
43 //====================================================================
44 ClassImp(AliFMDCalibFaker)
45 #if 0
46   ; // This is here to keep Emacs for indenting the next line
47 #endif
48
49 //____________________________________________________________________
50 AliFMDCalibFaker::AliFMDCalibFaker(Int_t mask, const char* loc) 
51   : TTask("FMDCalibFaker", loc),
52     fMask(mask),
53     fGain(-1),
54     fThresholdFactor(.1),
55     fThreshold(-1),
56     fPedestalMin(20),
57     fPedestalMax(30), 
58     fDeadChance(0),
59     fRate(1),
60     fZeroThreshold(0),
61     fRunMin(0),
62     fRunMax(10)
63 {
64   // Default constructor 
65 }
66
67
68 #define MAKE_META(meta) \
69   do { \
70     meta = new AliCDBMetaData; \
71     meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data()); \
72     meta->SetAliRootVersion(gROOT->GetVersion()); \
73     meta->SetBeamPeriod(1); \
74     meta->SetComment("Dummy data for testing"); } while (false);
75  
76
77 //__________________________________________________________________
78 void
79 AliFMDCalibFaker::Exec(Option_t*)
80 {
81   // Make the objects. 
82   AliCDBManager*     cdb      = AliCDBManager::Instance();
83   AliFMDParameters*  param    = AliFMDParameters::Instance();
84   Float_t            maxADC   = param->GetAltroChannelSize();
85   TObjArray          cleanup;
86
87   if (GetTitle()) cdb->SetDefaultStorage(GetTitle());
88     
89   AliCDBMetaData* meta = 0;
90   if (TESTBIT(fMask, kPulseGain)) {
91     if (fGain <= 0) 
92       fGain      = (param->GetVA1MipRange() * param->GetEdepMip() / maxADC);
93     fThreshold = fThresholdFactor * param->GetEdepMip();
94     AliFMDCalibGain* gain = MakePulseGain();
95     AliCDBId         id(AliFMDParameters::fgkPulseGain, fRunMin, fRunMax);
96     MAKE_META(meta);
97     meta->SetProperty("key1", gain);
98     cdb->Put(gain, id, meta);
99     cleanup.Add(gain);
100     cleanup.Add(meta);
101   }  
102   if (TESTBIT(fMask, kPedestal)) {
103     fPedestalMin = TMath::Max(TMath::Min(fPedestalMin, maxADC), 0.F);
104     fPedestalMax = TMath::Max(TMath::Min(fPedestalMax, maxADC), fPedestalMin);
105     AliFMDCalibPedestal* pedestal = MakePedestal();
106     AliCDBId             id(AliFMDParameters::fgkPedestal, fRunMin, fRunMax);
107     MAKE_META(meta);
108     meta->SetProperty("key1", pedestal);
109     cdb->Put(pedestal, id, meta);
110     cleanup.Add(pedestal);
111     cleanup.Add(meta);
112   }
113   if (TESTBIT(fMask, kDeadMap)) {
114     fDeadChance = TMath::Max(TMath::Min(fDeadChance, 1.F), 0.F);
115     AliFMDCalibDeadMap* deadMap = MakeDeadMap();
116     AliCDBId            id(AliFMDParameters::fgkDead, fRunMin, fRunMax);
117     MAKE_META(meta);
118     meta->SetProperty("key1", deadMap);
119     cdb->Put(deadMap, id, meta);
120     cleanup.Add(deadMap);
121     cleanup.Add(meta);
122   }
123   if (TESTBIT(fMask, kZeroSuppression)) {
124     fZeroThreshold = TMath::Min(fZeroThreshold, UShort_t(maxADC));
125     AliFMDCalibZeroSuppression* zeroSup = MakeZeroSuppression();
126     AliCDBId                    id(AliFMDParameters::fgkZeroSuppression, 
127                                    fRunMin, fRunMax);
128     MAKE_META(meta);
129     meta->SetProperty("key1", zeroSup);
130     cdb->Put(zeroSup, id, meta);
131     cleanup.Add(zeroSup);
132     cleanup.Add(meta);
133   }
134   if (TESTBIT(fMask, kSampleRate)) {
135     fRate = TMath::Max(TMath::Min(fRate, UShort_t(8)), UShort_t(1));
136     AliFMDCalibSampleRate* rate = MakeSampleRate();
137     AliCDBId               id(AliFMDParameters::fgkSampleRate,fRunMin,fRunMax);
138     MAKE_META(meta);
139     meta->SetProperty("key1", rate);
140     cdb->Put(rate, id, meta);
141     cleanup.Add(rate);
142     cleanup.Add(meta);
143   }
144   if (TESTBIT(fMask, kAltroMap)) {
145     AliFMDAltroMapping* altroMap = MakeAltroMap();
146     AliCDBId            id(AliFMDParameters::fgkAltroMap, fRunMin, fRunMax);
147     MAKE_META(meta);
148     meta->SetProperty("key1", altroMap);
149     cdb->Put(altroMap, id, meta);
150     cleanup.Add(altroMap);
151     cleanup.Add(meta);
152   }
153   cdb->Destroy();
154   cleanup.Delete();
155 }
156
157
158 //__________________________________________________________________
159 AliFMDCalibGain*
160 AliFMDCalibFaker::MakePulseGain()
161 {
162   // Make the actual data
163   AliFMDCalibGain*  gain  = new AliFMDCalibGain;
164   // Set threshold 
165   gain->Set(fThreshold);
166   for (UShort_t det = 1; det <= 3; det++) {
167     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
168     for (Char_t* ring = rings; *ring != '\0'; ring++) {
169       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
170       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
171       for (UShort_t sec = 0; sec < nSec; sec++) {
172         for (UShort_t str = 0; str < nStr; str++) {
173           gain->Set(det, *ring, sec, str,
174                     gRandom->Gaus(fGain, .01 * fGain));
175         }
176       }
177     }
178   }
179   return gain;
180 }
181
182 //__________________________________________________________________
183 AliFMDCalibPedestal*
184 AliFMDCalibFaker::MakePedestal()
185 {
186   // Make the actual data
187   AliFMDCalibPedestal*  pedestal  = new AliFMDCalibPedestal;
188   for (UShort_t det = 1; det <= 3; det++) {
189     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
190     for (Char_t* ring = rings; *ring != '\0'; ring++) {
191       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
192       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
193       for (UShort_t sec = 0; sec < nSec; sec++) {
194         for (UShort_t str = 0; str < nStr; str++) {
195           pedestal->Set(det, *ring, sec, str,
196                         gRandom->Uniform(fPedestalMin, fPedestalMax), 1.5);
197         }
198       }
199     }
200   }
201   return pedestal;
202 }
203
204 //__________________________________________________________________
205 AliFMDCalibDeadMap*
206 AliFMDCalibFaker::MakeDeadMap()
207 {
208   // Make the actual data
209   AliFMDCalibDeadMap*  deadmap  = new AliFMDCalibDeadMap;
210   for (UShort_t det = 1; det <= 3; det++) {
211     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
212     for (Char_t* ring = rings; *ring != '\0'; ring++) {
213       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
214       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
215       for (UShort_t sec = 0; sec < nSec; sec++) {
216         for (UShort_t str = 0; str < nStr; str++) {
217           deadmap->operator()(det, *ring, sec, str) = 
218             gRandom->Uniform(0, 1) < fDeadChance;
219         }
220       }
221     }
222   }
223   return deadmap;
224 }
225
226 //__________________________________________________________________
227 AliFMDCalibZeroSuppression*
228 AliFMDCalibFaker::MakeZeroSuppression()
229 {
230   // Make the actual data
231   AliFMDCalibZeroSuppression*  zs  = new AliFMDCalibZeroSuppression;
232   for (UShort_t det = 1; det <= 3; det++) {
233     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
234     for (Char_t* ring = rings; *ring != '\0'; ring++) {
235       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
236       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
237       for (UShort_t sec = 0; sec < nSec; sec++) {
238         for (UShort_t str = 0; str < nStr; str++) {
239           zs->operator()(det, *ring, sec, str) =  fZeroThreshold;
240         }
241       }
242     }
243   }
244   return zs;
245 }
246
247 //__________________________________________________________________
248 AliFMDCalibSampleRate*
249 AliFMDCalibFaker::MakeSampleRate()
250 {
251   AliFMDCalibSampleRate*  sampleRate  = new AliFMDCalibSampleRate;
252   for (int i = 0; i < 3; i++)
253     sampleRate->Set(AliFMDParameters::kBaseDDL+i, fRate);
254   return sampleRate;
255 }
256
257 //__________________________________________________________________
258 AliFMDAltroMapping*
259 AliFMDCalibFaker::MakeAltroMap()
260 {
261   AliFMDAltroMapping*  m  = new AliFMDAltroMapping;
262   return m;
263 }
264   
265   
266   
267 //____________________________________________________________________
268 //
269 // EOF
270 //