]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDParameters.h
Included ReadFromFile and WriteToFile methods to read/write from ASCII files and...
[u/mrichter/AliRoot.git] / FMD / AliFMDParameters.h
1 #ifndef ALIFMDPARAMETERS_H
2 #define ALIFMDPARAMETERS_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights
4  * reserved. 
5  *
6  * Latest changes by Christian Holm Christensen <cholm@nbi.dk>
7  *
8  * See cxx source for full Copyright notice                               
9  */
10 //____________________________________________________________________
11 //
12 //  Singleton class to handle various parameters (not geometry) of the
13 //  FMD
14 //  Should get ata fromm Conditions DB.
15 //
16 /** @file    AliFMDParameters.h
17     @author  Christian Holm Christensen <cholm@nbi.dk>
18     @date    Mon Mar 27 12:44:43 2006
19     @brief   Manager of FMD parameters
20 */
21 #ifndef ROOT_TNamed
22 # include <TNamed.h>
23 #endif
24 #ifndef ROOT_TArrayI
25 # include <TArrayI.h>
26 #endif
27 #ifndef ALIFMDUSHORTMAP_H
28 # include <AliFMDUShortMap.h>
29 #endif
30 #ifndef ALIFMDBOOLMAP_H
31 # include <AliFMDBoolMap.h>
32 #endif
33 typedef AliFMDUShortMap AliFMDCalibZeroSuppression;
34 typedef AliFMDBoolMap   AliFMDCalibDeadMap;
35 class AliFMDCalibPedestal;
36 class AliFMDCalibGain;
37 class AliFMDCalibSampleRate;
38 class AliFMDCalibStripRange;
39 class AliFMDAltroMapping;
40 class AliCDBEntry;
41 class AliFMDPreprocessor;
42
43 //____________________________________________________________________
44 //
45 //  Singleton class to handle various parameters (not geometry) of the
46 //  FMD
47 //  Should get ata fromm Conditions DB.
48 //
49
50 /** @brief This class is a singleton that handles various parameters
51     of the FMD detectors.  
52     This class reads from the Conditions DB to get the various
53     parameters, which code can then request from here. In that way,
54     all code uses the same data, and the interface is consistent.
55      
56     Some of the parameter managed are 
57     - @c fPedestal, @c fPedestalWidth
58       Mean and width of the pedestal.  The pedestal is simulated
59       by a Guassian, but derived classes my override MakePedestal
60       to simulate it differently (or pick it up from a database).
61     - @c fVA1MipRange
62       The dymamic MIP range of the VA1_ALICE pre-amplifier chip 
63     - @c fAltroChannelSize
64       The largest number plus one that can be stored in one
65       channel in one time step in the ALTRO ADC chip. 
66     - @c fSampleRate
67       How many times the ALTRO ADC chip samples the VA1_ALICE
68       pre-amplifier signal.   The VA1_ALICE chip is read-out at
69       10MHz, while it's possible to drive the ALTRO chip at
70       25MHz.  That means, that the ALTRO chip can have time to
71       sample each VA1_ALICE signal up to 2 times.  Although it's
72       not certain this feature will be used in the production,
73       we'd like have the option, and so it should be reflected in
74       the code.
75
76     @ingroup FMD_base
77 */
78 class AliFMDParameters : public TNamed
79 {
80 public:
81   /** Enumeration of things to initialize */ 
82   enum What { 
83     /** Pulser gain */ 
84     kPulseGain = 0x1, // Pulser gain 
85     /** Pedestals and noise */ 
86     kPedestal = 0x2, // Pedestal and noise 
87     /** Dead channel map */ 
88     kDeadMap = 0x4, // Dead channel map
89     /**  Over sampling rate */ 
90     kSampleRate = 0x8, // Over sampling rate 
91     /** Zero suppression parameters */ 
92     kZeroSuppression = 0x10, // Zero suppression parameters 
93     /** ALTRO data map */ 
94     kAltroMap = 0x20 // Altro channel map
95   };
96   
97   /** Singleton access
98       @return  single to */
99   static AliFMDParameters* Instance();
100
101   /** Initialize the manager.  This tries to read the parameters from
102       CDB.  If that fails, the class uses the hard-coded parameters. 
103    */
104   void Init(Bool_t forceReInit=kFALSE, 
105             UInt_t what = (kPulseGain|kPedestal|kDeadMap|kSampleRate|
106                            kZeroSuppression|kAltroMap));
107   /** Initialize the manager.  This tries to read the parameters from
108       CDB.  If that fails, the class uses the hard-coded parameters. 
109    */
110   void Init(AliFMDPreprocessor* pp, 
111             Bool_t forceReInit=kFALSE, 
112             UInt_t what = (kPulseGain|kPedestal|kDeadMap|kSampleRate|
113                            kZeroSuppression|kAltroMap));
114   /** Print all parameters. 
115       @param option Option string */
116   void Print(Option_t* option="A") const;
117   /** Draw parameters. 
118       @param option What to draw. Should be one of 
119       - dead      Dead channels
120       - threshold Threshold
121       - gain      Gain
122       - pedestal  Pedestal
123       - noise     Noise (or pedestal width)
124       - zero      Zero suppression
125       - rate      Sampling rate (VA1 clock / ALTRO clock)
126       - min       Minimum strip read out
127       - max       Maximum strip read out
128       - map       hardware address
129   */
130   void Draw(Option_t* option="pedestal");
131   
132   /** @{ */
133   /** @name Set various `Fixed' parameters */
134   /** @param r How many MIP signals we can fit in the VA1
135       pre-amps. (default and design is 20) */
136   void SetVA1MipRange(UShort_t r=20)          { fVA1MipRange = r; }
137   /** @param s Maximum number of the ADC (ALTRO).  This is a 10 bit
138       ADC so, the maximum number is 1024 */
139   void SetAltroChannelSize(UShort_t s=1024)   { fAltroChannelSize = s;}
140   /** @param size The number of strips multiplexed into one ALTRO
141       channel. That is, how many strips is connected to one VA1
142       pre-amp. */
143   void SetChannelsPerAltro(UShort_t size=128) { fChannelsPerAltro = size; }
144   /** @param f Factor to use for accepting a signal. */
145   void SetPedestalFactor(Float_t f=3)         { fPedestalFactor = f; }
146   /** @} */
147
148   /** @{ */
149   /** @name Set various variable parameter defaults */
150   /** @param s Zero suppression threshold in ADC counts */
151   void SetZeroSuppression(UShort_t s=0)       { fFixedZeroSuppression = s; }
152   /** @param r How many times we oversample each strip. */
153   void SetSampleRate(UShort_t r=1)            { fFixedSampleRate = r ;}//(r>2?2:r);}
154   void SetSampleRate(AliFMDCalibSampleRate* r) { fSampleRate = r; }
155   /** @param p Pedestal value in ADC counts */
156   void SetPedestal(Float_t p=10)              { fFixedPedestal = p; }
157   /** @param w Pedestal width in ADC counts */
158   void SetPedestalWidth(Float_t w=1)          { fFixedPedestalWidth = w; }
159   /** @param t Threshold used for 1 MIP acceptance. */
160   void SetThreshold(Float_t t=0)              { fFixedThreshold = t; }
161   /** Range of strips read out 
162       @param min Minimum strip number (0-127). 
163       @param max Maximum strip number (0-127). */
164   void SetStripRange(UShort_t min=0, UShort_t max=127);
165   void SetStripRange(AliFMDCalibStripRange* r) { fStripRange = r; }
166   /** Whether raw data has full common data header (8 32bit words) or
167       the older invalid format (7 32bit words with bogus entries)
168       @param yes if true the raw data has complete data header */ 
169   void UseCompleteHeader(Bool_t yes=kTRUE) { fHasCompleteHeader = yes; } 
170   /** @} */
171
172   /** @{ */
173   /** @name Get `Fixed' various parameters */
174   /** @return Number of MIP signals that fit inside a VA1 channel  */
175   UShort_t GetVA1MipRange()          const { return fVA1MipRange; }
176   /** @return The maximum count in the ADC */
177   UShort_t GetAltroChannelSize()     const { return fAltroChannelSize; }
178   /** @return Number of strips muliplexed into one ADC channel */
179   UShort_t GetChannelsPerAltro()     const { return fChannelsPerAltro; }
180   /** @return The average energy deposited by one MIP */
181   Float_t  GetEdepMip()              const;
182   /** @return The factor used of signal acceptance */
183   Float_t  GetPedestalFactor()       const { return fPedestalFactor; }
184   /** @} */
185
186   /** @{ */
187   /** @name Get variable parameters */
188   /** Whether the strip is considered dead
189       @param detector Detector # (1-3)
190       @param ring     Ring ID ('I' or 'O')
191       @param sector   Sector number (0-39)
192       @param strip    Strip number (0-511)
193       @return @c true if the strip is considered dead, @c false if
194       it's OK. */
195   Bool_t   IsDead(UShort_t detector, 
196                   Char_t ring, 
197                   UShort_t sector, 
198                   UShort_t strip) const;
199   Float_t  GetThreshold() const;
200   /** Gain of pre-amp. 
201       @param detector Detector # (1-3)
202       @param ring     Ring ID ('I' or 'O')
203       @param sector   Sector number (0-39)
204       @param strip    Strip number (0-511)
205       @return Gain of pre-amp.  */
206   Float_t  GetPulseGain(UShort_t detector, 
207                         Char_t ring, 
208                         UShort_t sector, 
209                         UShort_t strip) const;
210   /** Get mean of pedestal
211       @param detector Detector # (1-3)
212       @param ring     Ring ID ('I' or 'O')
213       @param sector   Sector number (0-39)
214       @param strip    Strip number (0-511)
215       @return Mean of pedestal */
216   Float_t  GetPedestal(UShort_t detector, 
217                        Char_t ring, 
218                        UShort_t sector, 
219                        UShort_t strip) const;
220   /** Width of pedestal
221       @param detector Detector # (1-3)
222       @param ring     Ring ID ('I' or 'O')
223       @param sector   Sector number (0-39)
224       @param strip    Strip number (0-511)
225       @return Width of pedestal */
226   Float_t  GetPedestalWidth(UShort_t detector, 
227                             Char_t ring, 
228                             UShort_t sector, 
229                             UShort_t strip) const;
230   /** zero suppression threshold (in ADC counts)
231       @param detector Detector # (1-3)
232       @param ring     Ring ID ('I' or 'O')
233       @param sector   Sector number (0-39)
234       @param strip    Strip number (0-511)
235       @return zero suppression threshold (in ADC counts) */
236   UShort_t GetZeroSuppression(UShort_t detector, 
237                               Char_t ring, 
238                               UShort_t sector, 
239                               UShort_t strip) const;
240   /** Get the sampling rate
241       @param detector Detector # (1-3)
242       @param ring     Ring ID ('I' or 'O')
243       @param sector   Sector number (0-39)
244       @param strip    Strip number (0-511)
245       @return The sampling rate */
246   UShort_t GetSampleRate(UShort_t detector, 
247                          Char_t ring, 
248                          UShort_t sector, 
249                          UShort_t strip) const;
250   /** Get the minimum strip in the read-out range
251       @param detector Detector # (1-3)
252       @param ring     Ring ID ('I' or 'O')
253       @param sector   Sector number (0-39)
254       @param strip    Strip number (0-511)
255       @return Minimum strip */
256   UShort_t GetMinStrip(UShort_t detector, 
257                        Char_t ring, 
258                        UShort_t sector, 
259                        UShort_t strip) const;
260   /** Get the maximum strip in the read-out range
261       @param detector Detector # (1-3)
262       @param ring     Ring ID ('I' or 'O')
263       @param sector   Sector number (0-39)
264       @param strip    Strip number (0-511)
265       @return Maximum strip */
266   UShort_t GetMaxStrip(UShort_t detector, 
267                        Char_t ring, 
268                        UShort_t sector, 
269                        UShort_t strip) const;
270   /** Get the number of pre-samples in ALTRO channels
271       @param detector Detector # (1-3)
272       @param ring     Ring ID ('I' or 'O')
273       @param sector   Sector number (0-39)
274       @param strip    Strip number (0-511)
275       @return Maximum strip */
276   UShort_t GetPreSamples(UShort_t, 
277                          Char_t, 
278                          UShort_t, 
279                          UShort_t) const { return 14+5; }
280   /** Translate hardware address to detector coordinates 
281       @param ddl      DDL number 
282       @param board    Board address
283       @param chip     Chip #
284       @param channel  Channel #
285       @param det      On return, Detector # (1-3)
286       @param ring     On return, Ring ID ('I' or 'O')
287       @param sec      On return, Sector number (0-39)
288       @param str      On return, Strip number (0-511)
289       @return @c true on success. */
290   Bool_t   Hardware2Detector(UInt_t ddl,    UInt_t    board, 
291                              UInt_t chip,   UInt_t    channel, 
292                              UShort_t& det, Char_t&   ring, 
293                              UShort_t& sec, UShort_t& str) const;
294   /** Translate hardware address to detector coordinates 
295       @param ddl      DDL number 
296       @param addr     Hardware address
297       @param det      On return, Detector # (1-3)
298       @param ring     On return, Ring ID ('I' or 'O')
299       @param sec      On return, Sector number (0-39)
300       @param str      On return, Strip number (0-511)
301       @return @c true on success. */
302   Bool_t   Hardware2Detector(UInt_t ddl, UInt_t addr, UShort_t& det,
303                              Char_t& ring, UShort_t& sec, UShort_t& str) const;
304
305   /** Translate detector coordinates to hardware address 
306       @param det      Detector # (1-3)
307       @param ring     Ring ID ('I' or 'O')
308       @param sec      Sector number (0-39)
309       @param str      Strip number (0-511)
310       @param ddl      On return, DDL number 
311       @param board    On return, Board address
312       @param chip     On return, Chip #
313       @param channel  On return, Channel #
314       @return @c true on success. */
315   Bool_t   Detector2Hardware(UShort_t det, Char_t ring, 
316                              UShort_t sec, UShort_t str, 
317                              UInt_t& ddl,  UInt_t& board,
318                              UInt_t& chip, UInt_t& channel) const;
319   /** Translate detector coordinates to hardware address 
320       @param det      Detector # (1-3)
321       @param ring     Ring ID ('I' or 'O')
322       @param sec      Sector number (0-39)
323       @param str      Strip number (0-511)
324       @param ddl      On return, DDL number 
325       @param addr     On return, Hardware address
326       @return @c true on success. */
327   Bool_t   Detector2Hardware(UShort_t det, Char_t ring, UShort_t sec, 
328                              UShort_t str, UInt_t& ddl, UInt_t& addr) const;
329   /** Get the map that translates hardware to detector coordinates 
330       @return Get the map that translates hardware to detector
331       coordinates */ 
332   AliFMDAltroMapping* GetAltroMap() const;
333   /** Whether raw data has full common data header (8 32bit words) or
334       the older invalid format (7 32bit words with bogus entries)
335       @return false if the raw data has incomplete data header */ 
336   Bool_t HasCompleteHeader() const { return fHasCompleteHeader; } 
337
338   /** @} */
339
340   static const char* PulseGainPath()       { return fgkPulseGain; }
341   static const char* PedestalPath()        { return fgkPedestal; }
342   static const char* DeadPath()            { return fgkDead; }
343   static const char* SampleRatePath()      { return fgkSampleRate; }
344   static const char* AltroMapPath()        { return fgkAltroMap; }
345   static const char* ZeroSuppressionPath() { return fgkZeroSuppression; }
346   static const char* StripRangePath()      { return fgkStripRange; }
347   static const char* GetPedestalShuttleID()   {return fkPedestalShuttleID;}
348   static const char* GetGainShuttleID()       {return fkGainShuttleID;}
349   static const char* GetConditionsShuttleID()   {return fkConditionsShuttleID;}
350 protected:
351   /** CTOR  */
352   AliFMDParameters();
353   /** CTOR  */
354   AliFMDParameters(const AliFMDParameters& o) 
355     : TNamed(o), 
356       fIsInit(o.fIsInit),
357       fkSiDeDxMip(o.fkSiDeDxMip),
358       fVA1MipRange(o.fVA1MipRange),
359       fAltroChannelSize(o.fAltroChannelSize),
360       fChannelsPerAltro(o.fChannelsPerAltro),
361       fPedestalFactor(o.fPedestalFactor),
362       fFixedPedestal(o.fFixedPedestal),
363       fFixedPedestalWidth(o.fFixedPedestalWidth),
364       fFixedZeroSuppression(o.fFixedZeroSuppression),
365       fFixedSampleRate(o.fFixedSampleRate),
366       fFixedThreshold(o.fFixedThreshold),
367       fFixedMinStrip(o.fFixedMinStrip),
368       fFixedMaxStrip(o.fFixedMaxStrip),
369       fFixedPulseGain(o.fFixedPulseGain),
370       fEdepMip(o.fEdepMip),
371       fHasCompleteHeader(o.fHasCompleteHeader),
372       fZeroSuppression(o.fZeroSuppression),
373       fSampleRate(o.fSampleRate),
374       fPedestal(o.fPedestal),
375       fPulseGain(o.fPulseGain),
376       fDeadMap(o.fDeadMap),
377       fAltroMap(o.fAltroMap),
378       fStripRange(o.fStripRange)
379   {}
380   /** Assignement operator 
381       @return Reference to this */
382   AliFMDParameters& operator=(const AliFMDParameters&) { return *this; }
383   /** DTOR */
384   virtual ~AliFMDParameters() {}
385   /** Singleton instance  */
386   static AliFMDParameters* fgInstance;   // Static singleton instance
387   /** Get an entry from either global AliCDBManager or passed
388       AliFMDPreprocessor. 
389       @param path  Path to CDB object. 
390       @param pp    AliFMDPreprocessor 
391       @param fatal If true, raise a fatal flag if we didn't get the entry.
392       @return AliCDBEntry if found */ 
393   AliCDBEntry* GetEntry(const char* path, AliFMDPreprocessor* pp, 
394                         Bool_t fatal=kTRUE) const;
395   /** Initialize gains.  Try to get them from CDB */
396   void InitPulseGain(AliFMDPreprocessor* pp=0);
397   /** Initialize pedestals.  Try to get them from CDB */
398   void InitPedestal(AliFMDPreprocessor* pp=0);
399   /** Initialize dead map.  Try to get it from CDB */
400   void InitDeadMap(AliFMDPreprocessor* pp=0);
401   /** Initialize sample rates.  Try to get them from CDB */
402   void InitSampleRate(AliFMDPreprocessor* pp=0);
403   /** Initialize zero suppression thresholds.  Try to get them from CDB */
404   void InitZeroSuppression(AliFMDPreprocessor* pp=0);
405   /** Initialize hardware map.  Try to get it from CDB */
406   void InitAltroMap(AliFMDPreprocessor* pp=0);
407   /** Initialize strip range.  Try to get it from CDB */
408   void InitStripRange(AliFMDPreprocessor* pp=0);
409
410   Bool_t          fIsInit;                   // Whether we've been initialised  
411
412   static const char* fgkPulseGain;           // Path to PulseGain calib object
413   static const char* fgkPedestal;            // Path to Pedestal calib object
414   static const char* fgkDead;                // Path to Dead calib object
415   static const char* fgkSampleRate;          // Path to SampleRate calib object
416   static const char* fgkAltroMap;            // Path to AltroMap calib object
417   static const char* fgkZeroSuppression;     // Path to ZeroSuppression cal object
418   static const char* fgkStripRange;          // Path to strip range cal object
419   const Float_t   fkSiDeDxMip;               // MIP dE/dx in Silicon
420   UShort_t        fVA1MipRange;              // # MIPs the pre-amp can do    
421   UShort_t        fAltroChannelSize;         // Largest # to store in 1 ADC ch.
422   UShort_t        fChannelsPerAltro;         // Number of pre-amp. chan/adc chan.
423   Float_t         fPedestalFactor;           // Number of pedestal widths
424
425   Float_t         fFixedPedestal;            // Pedestal to subtract
426   Float_t         fFixedPedestalWidth;       // Width of pedestal
427   UShort_t        fFixedZeroSuppression;     // Threshold for zero-suppression
428   UShort_t        fFixedSampleRate;          // Times the ALTRO samples pre-amp.
429   Float_t         fFixedThreshold;           // Threshold in ADC counts
430   UShort_t        fFixedMinStrip;            // Minimum strip read-out
431   UShort_t        fFixedMaxStrip;            // Maximum strip read-out 
432   mutable Float_t fFixedPulseGain;           //! Gain (cached)
433   mutable Float_t fEdepMip;                  //! Cache of energy loss for a MIP
434   Bool_t          fHasCompleteHeader;        // raw data has incomplete data header
435   
436   static const char* fkPedestalShuttleID;    // Shuttle/preprocessor ID for pedestals
437   static const char* fkGainShuttleID;        // Shuttle/preprocessor ID for gains
438   static const char* fkConditionsShuttleID;  // Shuttle/preprocessor ID for conditions
439   
440   AliFMDCalibZeroSuppression* fZeroSuppression; // Zero suppression from CDB
441   AliFMDCalibSampleRate*      fSampleRate;      // Sample rate from CDB 
442   AliFMDCalibPedestal*        fPedestal;        // Pedestals 
443   AliFMDCalibGain*            fPulseGain;       // Pulser gain
444   AliFMDCalibDeadMap*         fDeadMap;         // Pulser gain
445   AliFMDAltroMapping*         fAltroMap;        // Map of hardware
446   AliFMDCalibStripRange*      fStripRange;      // Strip range
447   
448   ClassDef(AliFMDParameters,6) // Manager of parameters
449 };
450
451 #endif
452 //____________________________________________________________________
453 //
454 // Local Variables:
455 //   mode: C++
456 // End:
457 //
458 // EOF
459 //
460