]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDParameters.cxx
Coding conventions (Christian)
[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     fkSiDeDxMip(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   // Print information. 
120   // If option contains an 'A' then everything is printed. 
121   TString opt(option);
122   Bool_t showStrips = opt.Contains("a", TString::kIgnoreCase);
123   for (UShort_t det=1 ; det <= 3; det++) {
124     std::cout << "FMD" << det << std::endl;
125     Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
126     for (Char_t* ring = rings; *ring != '\0'; ring++) {
127       std::cout << " Ring " << *ring << std::endl;
128       UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
129       UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
130       for (UShort_t sec = 0; sec < nSec; sec++) {
131         UShort_t min  = GetMinStrip(det, *ring, sec, 0);
132         UShort_t max  = GetMaxStrip(det, *ring, sec, 0);
133         UShort_t rate = GetSampleRate(det, *ring, sec, 0);
134         std::cout << "  Sector " << std::setw(2) << sec 
135                   << "  Strip range: " << std::setw(3) << min << "," 
136                   << std::setw(3) << max << "  Rate: " << std::setw(2) 
137                   << rate << std::endl;
138         if (!showStrips) continue;
139         std::cout 
140           << "  Strip |     Pedestal      |   Gain   | ZS thr. | Address\n" 
141           << "--------+-------------------+----------+---------+---------" 
142           << std::endl;
143         for (UShort_t str = 0; str < nStr; str++) {
144           std::cout << "    " << std::setw(3) << str << " | ";
145           if (IsDead(det, *ring, sec, str)) {
146             std::cout << "dead" << std::endl;
147             continue;
148           }
149           UInt_t ddl, addr;
150           Detector2Hardware(det, *ring, sec, str, ddl, addr);
151           std::cout << std::setw(7) << GetPedestal(det, *ring, sec, str) 
152                     << "+/-" << std::setw(7) 
153                     << GetPedestalWidth(det, *ring, sec, str) 
154                     << " | " << std::setw(8) 
155                     << GetPulseGain(det, *ring, sec, str) 
156                     << " | " << std::setw(5) 
157                     << GetZeroSuppression(det, *ring, sec, str) 
158                     << " | 0x" << std::hex << std::setw(4) 
159                     << std::setfill('0') << ddl << ",0x" << std::setw(3) 
160                     << addr << std::dec << std::setfill(' ') << std::endl;
161         }
162       }
163     }
164   }
165 }
166
167 //__________________________________________________________________
168 void
169 AliFMDParameters::SetStripRange(UShort_t min, UShort_t max) 
170 {
171   // Set fixed strip range 
172   fFixedMinStrip = min;
173   fFixedMaxStrip = max;
174 }
175
176 //__________________________________________________________________
177 void
178 AliFMDParameters::InitPulseGain()
179 {
180   // Get pulse gain from CDB or used fixed 
181   AliCDBManager* cdb      = AliCDBManager::Instance();
182   AliCDBEntry*   gain     = cdb->Get(fgkPulseGain);
183   if (!gain) {
184     AliWarning(Form("No %s found in CDB, perhaps you need to "
185                     "use AliFMDCalibFaker?", fgkPulseGain));
186     return;
187   }
188   
189   AliDebug(1, Form("Got gain from CDB"));
190   fPulseGain = dynamic_cast<AliFMDCalibGain*>(gain->GetObject());
191   if (!fPulseGain) AliWarning("Invalid pulser gain object from CDB");
192 }
193 //__________________________________________________________________
194 void
195 AliFMDParameters::InitPedestal()
196 {
197   // Initialize the pedestals from CDB 
198   AliCDBManager* cdb      = AliCDBManager::Instance();
199   AliCDBEntry*   pedestal = cdb->Get(fgkPedestal);
200   if (!pedestal) {
201     AliWarning(Form("No %s found in CDB, perhaps you need to "
202                     "use AliFMDCalibFaker?", fgkPedestal));
203     return;
204   }
205   AliDebug(1, Form("Got pedestal from CDB"));
206   fPedestal = dynamic_cast<AliFMDCalibPedestal*>(pedestal->GetObject());
207   if (!fPedestal) AliWarning("Invalid pedestal object from CDB");
208 }
209
210 //__________________________________________________________________
211 void
212 AliFMDParameters::InitDeadMap()
213 {
214   // Get Dead-channel-map from CDB 
215   AliCDBManager* cdb      = AliCDBManager::Instance();
216   AliCDBEntry*   deadMap  = cdb->Get(fgkDead);
217   if (!deadMap) {
218     AliWarning(Form("No %s found in CDB, perhaps you need to "
219                     "use AliFMDCalibFaker?", fgkDead));
220     return;
221   }
222   AliDebug(1, Form("Got dead map from CDB"));
223   fDeadMap = dynamic_cast<AliFMDCalibDeadMap*>(deadMap->GetObject());
224   if (!fDeadMap) AliWarning("Invalid dead map object from CDB");
225 }
226
227 //__________________________________________________________________
228 void
229 AliFMDParameters::InitZeroSuppression()
230 {
231   // Get 0-suppression from CDB 
232   AliCDBManager* cdb      = AliCDBManager::Instance();
233   AliCDBEntry*   zeroSup  = cdb->Get(fgkZeroSuppression);
234   if (!zeroSup) {
235     AliWarning(Form("No %s found in CDB, perhaps you need to "
236                     "use AliFMDCalibFaker?", fgkZeroSuppression));
237     return;
238   }
239   AliDebug(1, Form("Got zero suppression from CDB"));
240   fZeroSuppression = 
241     dynamic_cast<AliFMDCalibZeroSuppression*>(zeroSup->GetObject());
242   if (!fZeroSuppression)AliWarning("Invalid zero suppression object from CDB");
243 }
244
245 //__________________________________________________________________
246 void
247 AliFMDParameters::InitSampleRate()
248 {
249   // get Sample rate from CDB
250   AliCDBManager* cdb      = AliCDBManager::Instance();
251   AliCDBEntry*   sampRat  = cdb->Get(fgkSampleRate);
252   if (!sampRat) {
253     AliWarning(Form("No %s found in CDB, perhaps you need to "
254                     "use AliFMDCalibFaker?", fgkSampleRate));
255     return;
256   }
257   AliDebug(1, Form("Got zero suppression from CDB"));
258   fSampleRate = dynamic_cast<AliFMDCalibSampleRate*>(sampRat->GetObject());
259   if (!fSampleRate) AliWarning("Invalid zero suppression object from CDB");
260 }
261
262 //__________________________________________________________________
263 void
264 AliFMDParameters::InitAltroMap()
265 {
266   // Get hardware mapping from CDB
267   AliCDBManager* cdb      = AliCDBManager::Instance();
268   AliCDBEntry*   hwMap    = cdb->Get(fgkAltroMap);       
269   if (!hwMap) {
270     AliWarning(Form("No %s found in CDB, perhaps you need to "
271                     "use AliFMDCalibFaker?", fgkAltroMap));
272     fAltroMap = new AliFMDAltroMapping;
273     return;
274   }
275   AliDebug(1, Form("Got ALTRO map from CDB"));
276   fAltroMap = dynamic_cast<AliFMDAltroMapping*>(hwMap->GetObject());
277   if (!fAltroMap) {
278     AliWarning("Invalid ALTRO map object from CDB");
279     fAltroMap = new AliFMDAltroMapping;
280   }
281 }
282
283 //__________________________________________________________________
284 void
285 AliFMDParameters::InitStripRange()
286 {
287   // Get strips read-out from CDB
288   AliCDBManager* cdb      = AliCDBManager::Instance();
289   AliCDBEntry*   range    = cdb->Get(fgkStripRange);
290   if (!range) {
291     AliWarning(Form("No %s found in CDB, perhaps you need to "
292                     "use AliFMDCalibFaker?", fgkStripRange));
293     return;
294   }
295   AliDebug(1, Form("Got strip range from CDB"));
296   fStripRange = dynamic_cast<AliFMDCalibStripRange*>(range->GetObject());
297   if (!fStripRange) AliWarning("Invalid strip range object from CDB");
298 }
299
300
301 //__________________________________________________________________
302 Float_t
303 AliFMDParameters::GetThreshold() const
304 {
305   // Get threshold from CDB
306   if (!fPulseGain) return fFixedThreshold;
307   return fPulseGain->Threshold();
308 }
309
310 //__________________________________________________________________
311 Float_t
312 AliFMDParameters::GetPulseGain(UShort_t detector, Char_t ring, 
313                                UShort_t sector, UShort_t strip) const
314 {
315   // Returns the pulser calibrated gain for strip # strip in sector #
316   // sector or ring id ring of detector # detector. 
317   // 
318   // For simulation, this is normally set to 
319   // 
320   //       VA1_MIP_Range 
321   //    ------------------ * MIP_Energy_Loss
322   //    ALTRO_channel_size
323   // 
324   if (!fPulseGain) { 
325     if (fFixedPulseGain <= 0)
326       fFixedPulseGain = fVA1MipRange * GetEdepMip() / fAltroChannelSize;
327     return fFixedPulseGain;
328   }  
329   AliDebug(50, Form("pulse gain for FMD%d%c[%2d,%3d]=%f",
330                     detector, ring, sector, strip,
331                     fPulseGain->Value(detector, ring, sector, strip)));
332   return fPulseGain->Value(detector, ring, sector, strip);
333 }
334
335 //__________________________________________________________________
336 Bool_t
337 AliFMDParameters::IsDead(UShort_t detector, Char_t ring, 
338                          UShort_t sector, UShort_t strip) const
339 {
340   // Check if the channel is dead 
341   if (!fDeadMap) return kFALSE;
342   AliDebug(50, Form("Dead for FMD%d%c[%2d,%3d]=%s",
343                     detector, ring, sector, strip,
344                     fDeadMap->operator()(detector, ring, sector, strip) ? 
345                     "no" : "yes"));
346   return fDeadMap->operator()(detector, ring, sector, strip);
347 }
348
349 //__________________________________________________________________
350 UShort_t
351 AliFMDParameters::GetZeroSuppression(UShort_t detector, Char_t ring, 
352                                      UShort_t sector, UShort_t strip) const
353 {
354   // Get zero suppression threshold 
355   if (!fZeroSuppression) return fFixedZeroSuppression;
356   // Need to map strip to ALTRO chip. 
357   AliDebug(50, Form("zero sup. for FMD%d%c[%2d,%3d]=%f",
358                     detector, ring, sector, strip,
359                     fZeroSuppression->operator()(detector, ring, 
360                                                  sector, strip)));
361   return fZeroSuppression->operator()(detector, ring, sector, strip/128);
362 }
363
364 //__________________________________________________________________
365 UShort_t
366 AliFMDParameters::GetSampleRate(UShort_t det, Char_t ring, UShort_t sector, 
367                                 UShort_t str) const
368 {
369   // Get sampl rate 
370   if (!fSampleRate) return fFixedSampleRate;
371   // Need to map sector to digitizier card. 
372   UInt_t ret = fSampleRate->Rate(det, ring, sector, str);
373   AliDebug(50, Form("Sample rate for FMD%d%c[%2d,%3d]=%d", 
374                     det, ring, sector, str, ret));
375   return ret;
376 }
377
378 //__________________________________________________________________
379 UShort_t
380 AliFMDParameters::GetMinStrip(UShort_t det, Char_t ring, UShort_t sector, 
381                               UShort_t str) const
382 {
383   // Get strip range read out 
384   if (!fStripRange) return fFixedMinStrip;
385   // Need to map sector to digitizier card. 
386   UInt_t ret = fStripRange->Min(det, ring, sector, str);
387   AliDebug(50, Form("Min strip # for FMD%d%c[%2d,%3d]=%d", 
388                     det, ring, sector, str, ret));
389   return ret;
390 }
391
392 //__________________________________________________________________
393 UShort_t
394 AliFMDParameters::GetMaxStrip(UShort_t det, Char_t ring, UShort_t sector, 
395                               UShort_t str) const
396 {
397   // Get strip range read out 
398   if (!fStripRange) return fFixedMaxStrip;
399   // Need to map sector to digitizier card. 
400   UInt_t ret = fStripRange->Max(det, ring, sector, str);
401   AliDebug(50, Form("Max strip # for FMD%d%c[%2d,%3d]=%d", 
402                     det, ring, sector, str, ret));
403   return ret;
404 }
405
406 //__________________________________________________________________
407 Float_t
408 AliFMDParameters::GetPedestal(UShort_t detector, Char_t ring, 
409                               UShort_t sector, UShort_t strip) const
410 {
411   // Get the pedesal 
412   if (!fPedestal) return fFixedPedestal;
413   AliDebug(50, Form("pedestal for FMD%d%c[%2d,%3d]=%f",
414                     detector, ring, sector, strip,
415                     fPedestal->Value(detector, ring, sector, strip)));
416   return fPedestal->Value(detector, ring, sector, strip);
417 }
418
419 //__________________________________________________________________
420 Float_t
421 AliFMDParameters::GetPedestalWidth(UShort_t detector, Char_t ring, 
422                                    UShort_t sector, UShort_t strip) const
423 {
424   // Get the pedesal 
425   if (!fPedestal) return fFixedPedestalWidth;
426   AliDebug(50, Form("pedetal width for FMD%d%c[%2d,%3d]=%f",
427                     detector, ring, sector, strip,
428                     fPedestal->Width(detector, ring, sector, strip)));
429   return fPedestal->Width(detector, ring, sector, strip);
430 }
431   
432 //__________________________________________________________________
433 AliFMDAltroMapping*
434 AliFMDParameters::GetAltroMap() const
435 {
436   // Get the hardware address to detector index map 
437   return fAltroMap;
438 }
439
440
441 //__________________________________________________________________
442 Bool_t
443 AliFMDParameters::Hardware2Detector(UInt_t ddl, UInt_t addr, UShort_t& det,
444                                     Char_t& ring, UShort_t& sec, 
445                                     UShort_t& str) const
446 {
447   // Map hardware address to detector index
448   if (!fAltroMap) return kFALSE;
449   return fAltroMap->Hardware2Detector(ddl, addr, det, ring, sec, str);
450 }
451
452 //__________________________________________________________________
453 Bool_t
454 AliFMDParameters::Detector2Hardware(UShort_t det, Char_t ring, UShort_t sec, 
455                                     UShort_t str, UInt_t& ddl, 
456                                     UInt_t& addr) const                       
457 {
458   // Map detector index to hardware address
459   if (!fAltroMap) return kFALSE;
460   return fAltroMap->Detector2Hardware(det, ring, sec, str, ddl, addr);
461 }
462
463
464 //__________________________________________________________________
465 Float_t
466 AliFMDParameters::GetEdepMip() const 
467
468   // Get energy deposited by a MIP in the silicon sensors
469   if (fEdepMip <= 0){
470     AliFMDGeometry* fmd = AliFMDGeometry::Instance();
471     fEdepMip = (fkSiDeDxMip 
472                 * fmd->GetRing('I')->GetSiThickness() 
473                 * fmd->GetSiDensity());
474   }
475   return fEdepMip;
476 }
477
478
479   
480   
481   
482 //____________________________________________________________________
483 //
484 // EOF
485 //