]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDParameters.cxx
Correct raw data reconstruction in case of trigger
[u/mrichter/AliRoot.git] / FMD / AliFMDParameters.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    AliFMDParameters.cxx
17     @author  Christian Holm Christensen <cholm@nbi.dk>
18     @date    Mon Mar 27 12:44:26 2006
19     @brief   Manager of FMD parameters     
20 */
21 //____________________________________________________________________
22 //                                                                          
23 // Forward Multiplicity Detector based on Silicon wafers. 
24 //
25 // This class is a singleton that handles various parameters of
26 // the FMD detectors.  
27 // Eventually, this class will use the Conditions DB to get the
28 // various parameters, which code can then request from here.
29 //                                                       
30 #include "AliLog.h"                // ALILOG_H
31 #include "AliFMDParameters.h"      // ALIFMDPARAMETERS_H
32 #include "AliFMDGeometry.h"        // ALIFMDGEOMETRY_H
33 #include "AliFMDRing.h"            // ALIFMDRING_H
34 #include "AliFMDCalibGain.h"       // ALIFMDCALIBGAIN_H
35 #include "AliFMDCalibPedestal.h"   // ALIFMDCALIBPEDESTAL_H
36 #include "AliFMDCalibSampleRate.h" // ALIFMDCALIBSAMPLERATE_H
37 #include "AliFMDCalibStripRange.h" // ALIFMDCALIBSTRIPRANGE_H
38 #include "AliFMDAltroMapping.h"    // ALIFMDALTROMAPPING_H
39 #include <AliCDBManager.h>         // ALICDBMANAGER_H
40 #include <AliCDBEntry.h>           // ALICDBMANAGER_H
41 #include <Riostream.h>
42
43 //====================================================================
44 ClassImp(AliFMDParameters)
45 #if 0
46   ; // This is here to keep Emacs for indenting the next line
47 #endif
48
49 //____________________________________________________________________
50 AliFMDParameters* AliFMDParameters::fgInstance = 0;
51
52 //____________________________________________________________________
53 const char* AliFMDParameters::fgkPulseGain       = "FMD/Calib/PulseGain";
54 const char* AliFMDParameters::fgkPedestal        = "FMD/Calib/Pedestal";
55 const char* AliFMDParameters::fgkDead            = "FMD/Calib/Dead";
56 const char* AliFMDParameters::fgkSampleRate      = "FMD/Calib/SampleRate";
57 const char* AliFMDParameters::fgkAltroMap        = "FMD/Calib/AltroMap";
58 const char* AliFMDParameters::fgkZeroSuppression = "FMD/Calib/ZeroSuppression";
59 const char* AliFMDParameters::fgkStripRange      = "FMD/Calib/StripRange";
60
61
62 //____________________________________________________________________
63 AliFMDParameters* 
64 AliFMDParameters::Instance() 
65 {
66   // Get static instance 
67   if (!fgInstance) fgInstance = new AliFMDParameters;
68   return fgInstance;
69 }
70
71 //____________________________________________________________________
72 AliFMDParameters::AliFMDParameters() 
73   : fIsInit(kFALSE),
74     fSiDeDxMip(1.664), 
75     fFixedPulseGain(0), 
76     fEdepMip(0),
77     fZeroSuppression(0), 
78     fSampleRate(0), 
79     fPedestal(0), 
80     fPulseGain(0), 
81     fDeadMap(0), 
82     fAltroMap(0), 
83     fStripRange(0)
84 {
85   // Default constructor 
86   SetVA1MipRange();
87   SetAltroChannelSize();
88   SetChannelsPerAltro();
89   SetZeroSuppression();
90   SetSampleRate();
91   SetPedestal();
92   SetPedestalWidth();
93   SetPedestalFactor();
94   SetThreshold();
95   SetStripRange();
96 }
97
98 //__________________________________________________________________
99 void
100 AliFMDParameters::Init()
101 {
102   // Initialize the parameters manager.  We need to get stuff from the
103   // CDB here. 
104   if (fIsInit) return;
105   InitPulseGain();
106   InitPedestal();
107   InitDeadMap();
108   InitSampleRate();
109   InitZeroSuppression();
110   InitAltroMap();
111   fIsInit = kTRUE;
112   
113 }
114
115 //__________________________________________________________________
116 void
117 AliFMDParameters::Print(Option_t* option) const
118 {
119   TString opt(option);
120   Bool_t showStrips = opt.Contains("a", TString::kIgnoreCase);
121   for (UShort_t det=1 ; det <= 3; det++) {
122     std::cout << "FMD" << det << std::endl;
123     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
124     for (Char_t* ring = rings; *ring != '\0'; ring++) {
125       std::cout << " Ring " << *ring << std::endl;
126       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
127       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
128       for (UShort_t sec = 0; sec < nSec; sec++) {
129         UShort_t min  = GetMinStrip(det, *ring, sec, 0);
130         UShort_t max  = GetMaxStrip(det, *ring, sec, 0);
131         UShort_t rate = GetSampleRate(det, *ring, sec, 0);
132         std::cout << "  Sector " << std::setw(2) << sec 
133                   << "  Strip range: " << std::setw(3) << min << "," 
134                   << std::setw(3) << max << "  Rate: " << std::setw(2) 
135                   << rate << std::endl;
136         if (!showStrips) continue;
137         std::cout 
138           << "  Strip |     Pedestal      |   Gain   | ZS thr. | Address\n" 
139           << "--------+-------------------+----------+---------+---------" 
140           << std::endl;
141         for (UShort_t str = 0; str < nStr; str++) {
142           std::cout << "    " << std::setw(3) << str << " | ";
143           if (IsDead(det, *ring, sec, str)) {
144             std::cout << "dead" << std::endl;
145             continue;
146           }
147           UInt_t ddl, addr;
148           Detector2Hardware(det, *ring, sec, str, ddl, addr);
149           std::cout << std::setw(7) << GetPedestal(det, *ring, sec, str) 
150                     << "+/-" << std::setw(7) 
151                     << GetPedestalWidth(det, *ring, sec, str) 
152                     << " | " << std::setw(8) 
153                     << GetPulseGain(det, *ring, sec, str) 
154                     << " | " << std::setw(5) 
155                     << GetZeroSuppression(det, *ring, sec, str) 
156                     << " | 0x" << std::hex << std::setw(4) 
157                     << std::setfill('0') << ddl << ",0x" << std::setw(3) 
158                     << addr << std::dec << std::setfill(' ') << std::endl;
159         }
160       }
161     }
162   }
163 }
164
165 //__________________________________________________________________
166 void
167 AliFMDParameters::SetStripRange(UShort_t min, UShort_t max) 
168 {
169   fFixedMinStrip = min;
170   fFixedMaxStrip = max;
171 }
172
173 //__________________________________________________________________
174 void
175 AliFMDParameters::InitPulseGain()
176 {
177   AliCDBManager* cdb      = AliCDBManager::Instance();
178   AliCDBEntry*   gain     = cdb->Get(fgkPulseGain);
179   if (!gain) {
180     AliWarning(Form("No %s found in CDB, perhaps you need to "
181                     "use AliFMDCalibFaker?", fgkPulseGain));
182     return;
183   }
184   
185   AliDebug(1, Form("Got gain from CDB"));
186   fPulseGain = dynamic_cast<AliFMDCalibGain*>(gain->GetObject());
187   if (!fPulseGain) AliWarning("Invalid pulser gain object from CDB");
188 }
189 //__________________________________________________________________
190 void
191 AliFMDParameters::InitPedestal()
192 {
193   AliCDBManager* cdb      = AliCDBManager::Instance();
194   AliCDBEntry*   pedestal = cdb->Get(fgkPedestal);
195   if (!pedestal) {
196     AliWarning(Form("No %s found in CDB, perhaps you need to "
197                     "use AliFMDCalibFaker?", fgkPedestal));
198     return;
199   }
200   AliDebug(1, Form("Got pedestal from CDB"));
201   fPedestal = dynamic_cast<AliFMDCalibPedestal*>(pedestal->GetObject());
202   if (!fPedestal) AliWarning("Invalid pedestal object from CDB");
203 }
204
205 //__________________________________________________________________
206 void
207 AliFMDParameters::InitDeadMap()
208 {
209   AliCDBManager* cdb      = AliCDBManager::Instance();
210   AliCDBEntry*   deadMap  = cdb->Get(fgkDead);
211   if (!deadMap) {
212     AliWarning(Form("No %s found in CDB, perhaps you need to "
213                     "use AliFMDCalibFaker?", fgkDead));
214     return;
215   }
216   AliDebug(1, Form("Got dead map from CDB"));
217   fDeadMap = dynamic_cast<AliFMDCalibDeadMap*>(deadMap->GetObject());
218   if (!fDeadMap) AliWarning("Invalid dead map object from CDB");
219 }
220
221 //__________________________________________________________________
222 void
223 AliFMDParameters::InitZeroSuppression()
224 {
225   AliCDBManager* cdb      = AliCDBManager::Instance();
226   AliCDBEntry*   zeroSup  = cdb->Get(fgkZeroSuppression);
227   if (!zeroSup) {
228     AliWarning(Form("No %s found in CDB, perhaps you need to "
229                     "use AliFMDCalibFaker?", fgkZeroSuppression));
230     return;
231   }
232   AliDebug(1, Form("Got zero suppression from CDB"));
233   fZeroSuppression = 
234     dynamic_cast<AliFMDCalibZeroSuppression*>(zeroSup->GetObject());
235   if (!fZeroSuppression)AliWarning("Invalid zero suppression object from CDB");
236 }
237
238 //__________________________________________________________________
239 void
240 AliFMDParameters::InitSampleRate()
241 {
242   AliCDBManager* cdb      = AliCDBManager::Instance();
243   AliCDBEntry*   sampRat  = cdb->Get(fgkSampleRate);
244   if (!sampRat) {
245     AliWarning(Form("No %s found in CDB, perhaps you need to "
246                     "use AliFMDCalibFaker?", fgkSampleRate));
247     return;
248   }
249   AliDebug(1, Form("Got zero suppression from CDB"));
250   fSampleRate = dynamic_cast<AliFMDCalibSampleRate*>(sampRat->GetObject());
251   if (!fSampleRate) AliWarning("Invalid zero suppression object from CDB");
252 }
253
254 //__________________________________________________________________
255 void
256 AliFMDParameters::InitAltroMap()
257 {
258   AliCDBManager* cdb      = AliCDBManager::Instance();
259   AliCDBEntry*   hwMap    = cdb->Get(fgkAltroMap);       
260   if (!hwMap) {
261     AliWarning(Form("No %s found in CDB, perhaps you need to "
262                     "use AliFMDCalibFaker?", fgkAltroMap));
263     fAltroMap = new AliFMDAltroMapping;
264     return;
265   }
266   AliDebug(1, Form("Got ALTRO map from CDB"));
267   fAltroMap = dynamic_cast<AliFMDAltroMapping*>(hwMap->GetObject());
268   if (!fAltroMap) {
269     AliWarning("Invalid ALTRO map object from CDB");
270     fAltroMap = new AliFMDAltroMapping;
271   }
272 }
273
274 //__________________________________________________________________
275 void
276 AliFMDParameters::InitStripRange()
277 {
278   AliCDBManager* cdb      = AliCDBManager::Instance();
279   AliCDBEntry*   range    = cdb->Get(fgkStripRange);
280   if (!range) {
281     AliWarning(Form("No %s found in CDB, perhaps you need to "
282                     "use AliFMDCalibFaker?", fgkStripRange));
283     return;
284   }
285   AliDebug(1, Form("Got strip range from CDB"));
286   fStripRange = dynamic_cast<AliFMDCalibStripRange*>(range->GetObject());
287   if (!fStripRange) AliWarning("Invalid strip range object from CDB");
288 }
289
290
291 //__________________________________________________________________
292 Float_t
293 AliFMDParameters::GetThreshold() const
294 {
295   if (!fPulseGain) return fFixedThreshold;
296   return fPulseGain->Threshold();
297 }
298
299 //__________________________________________________________________
300 Float_t
301 AliFMDParameters::GetPulseGain(UShort_t detector, Char_t ring, 
302                                UShort_t sector, UShort_t strip) const
303 {
304   // Returns the pulser calibrated gain for strip # strip in sector #
305   // sector or ring id ring of detector # detector. 
306   // 
307   // For simulation, this is normally set to 
308   // 
309   //       VA1_MIP_Range 
310   //    ------------------ * MIP_Energy_Loss
311   //    ALTRO_channel_size
312   // 
313   if (!fPulseGain) { 
314     if (fFixedPulseGain <= 0)
315       fFixedPulseGain = fVA1MipRange * GetEdepMip() / fAltroChannelSize;
316     return fFixedPulseGain;
317   }  
318   AliDebug(50, Form("pulse gain for FMD%d%c[%2d,%3d]=%f",
319                     detector, ring, sector, strip,
320                     fPulseGain->Value(detector, ring, sector, strip)));
321   return fPulseGain->Value(detector, ring, sector, strip);
322 }
323
324 //__________________________________________________________________
325 Bool_t
326 AliFMDParameters::IsDead(UShort_t detector, Char_t ring, 
327                          UShort_t sector, UShort_t strip) const
328 {
329   if (!fDeadMap) return kFALSE;
330   AliDebug(50, Form("Dead for FMD%d%c[%2d,%3d]=%s",
331                     detector, ring, sector, strip,
332                     fDeadMap->operator()(detector, ring, sector, strip) ? 
333                     "no" : "yes"));
334   return fDeadMap->operator()(detector, ring, sector, strip);
335 }
336
337 //__________________________________________________________________
338 UShort_t
339 AliFMDParameters::GetZeroSuppression(UShort_t detector, Char_t ring, 
340                                      UShort_t sector, UShort_t strip) const
341 {
342   if (!fZeroSuppression) return fFixedZeroSuppression;
343   // Need to map strip to ALTRO chip. 
344   AliDebug(50, Form("zero sup. for FMD%d%c[%2d,%3d]=%f",
345                     detector, ring, sector, strip,
346                     fZeroSuppression->operator()(detector, ring, 
347                                                  sector, strip)));
348   return fZeroSuppression->operator()(detector, ring, sector, strip/128);
349 }
350
351 //__________________________________________________________________
352 UShort_t
353 AliFMDParameters::GetSampleRate(UShort_t det, Char_t ring, UShort_t sector, 
354                                 UShort_t str) const
355 {
356   if (!fSampleRate) return fFixedSampleRate;
357   // Need to map sector to digitizier card. 
358   UInt_t ret = fSampleRate->Rate(det, ring, sector, str);
359   AliDebug(50, Form("Sample rate for FMD%d%c[%2d,%3d]=%d", 
360                     det, ring, sector, str, ret));
361   return ret;
362 }
363
364 //__________________________________________________________________
365 UShort_t
366 AliFMDParameters::GetMinStrip(UShort_t det, Char_t ring, UShort_t sector, 
367                               UShort_t str) const
368 {
369   if (!fStripRange) return fFixedMinStrip;
370   // Need to map sector to digitizier card. 
371   UInt_t ret = fStripRange->Min(det, ring, sector, str);
372   AliDebug(50, Form("Min strip # for FMD%d%c[%2d,%3d]=%d", 
373                     det, ring, sector, str, ret));
374   return ret;
375 }
376
377 //__________________________________________________________________
378 UShort_t
379 AliFMDParameters::GetMaxStrip(UShort_t det, Char_t ring, UShort_t sector, 
380                               UShort_t str) const
381 {
382   if (!fStripRange) return fFixedMaxStrip;
383   // Need to map sector to digitizier card. 
384   UInt_t ret = fStripRange->Max(det, ring, sector, str);
385   AliDebug(50, Form("Max strip # for FMD%d%c[%2d,%3d]=%d", 
386                     det, ring, sector, str, ret));
387   return ret;
388 }
389
390 //__________________________________________________________________
391 Float_t
392 AliFMDParameters::GetPedestal(UShort_t detector, Char_t ring, 
393                               UShort_t sector, UShort_t strip) const
394 {
395   if (!fPedestal) return fFixedPedestal;
396   AliDebug(50, Form("pedestal for FMD%d%c[%2d,%3d]=%f",
397                     detector, ring, sector, strip,
398                     fPedestal->Value(detector, ring, sector, strip)));
399   return fPedestal->Value(detector, ring, sector, strip);
400 }
401
402 //__________________________________________________________________
403 Float_t
404 AliFMDParameters::GetPedestalWidth(UShort_t detector, Char_t ring, 
405                                    UShort_t sector, UShort_t strip) const
406 {
407   if (!fPedestal) return fFixedPedestalWidth;
408   AliDebug(50, Form("pedetal width for FMD%d%c[%2d,%3d]=%f",
409                     detector, ring, sector, strip,
410                     fPedestal->Width(detector, ring, sector, strip)));
411   return fPedestal->Width(detector, ring, sector, strip);
412 }
413   
414 //__________________________________________________________________
415 AliFMDAltroMapping*
416 AliFMDParameters::GetAltroMap() const
417 {
418   return fAltroMap;
419 }
420
421
422 //__________________________________________________________________
423 Bool_t
424 AliFMDParameters::Hardware2Detector(UInt_t ddl, UInt_t addr, UShort_t& det,
425                                     Char_t& ring, UShort_t& sec, 
426                                     UShort_t& str) const
427 {
428   if (!fAltroMap) return kFALSE;
429   return fAltroMap->Hardware2Detector(ddl, addr, det, ring, sec, str);
430 }
431
432 //__________________________________________________________________
433 Bool_t
434 AliFMDParameters::Detector2Hardware(UShort_t det, Char_t ring, UShort_t sec, 
435                                     UShort_t str, UInt_t& ddl, 
436                                     UInt_t& addr) const                       
437 {
438   if (!fAltroMap) return kFALSE;
439   return fAltroMap->Detector2Hardware(det, ring, sec, str, ddl, addr);
440 }
441
442
443 //__________________________________________________________________
444 Float_t
445 AliFMDParameters::GetEdepMip() const 
446
447   // Get energy deposited by a MIP in the silicon sensors
448   if (fEdepMip <= 0){
449     AliFMDGeometry* fmd = AliFMDGeometry::Instance();
450     fEdepMip = (fSiDeDxMip 
451                 * fmd->GetRing('I')->GetSiThickness() 
452                 * fmd->GetSiDensity());
453   }
454   return fEdepMip;
455 }
456
457
458   
459   
460   
461 //____________________________________________________________________
462 //
463 // EOF
464 //