]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/FMDutil/AliFMDPedestalDA.h
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / FMD / FMDutil / AliFMDPedestalDA.h
1 #ifndef ALIFMDPEDESTALDA_H
2 #define ALIFMDPEDESTALDA_H
3
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights
5  * reserved. 
6  *
7  * See cxx source for full Copyright notice                               
8  */
9 // This class implements the pedestal detector algorithm (DA) for the FMD.
10 // It uses 51200 TH1S histograms to store the data for each channel of the FMD.
11 // The mean and standard deviation of a histogram define the pedestal and 
12 // the noise for that channel.
13
14
15 #include "AliFMDBaseDA.h"
16 #include "TH1.h"
17 #include "TObjArray.h"
18 class TH2;
19
20 class AliFMDPedestalDA: public AliFMDBaseDA 
21 {
22 public:
23   typedef AliFMDBaseDA::Array Array;
24
25   /** 
26    * Constructor.
27    * 
28    */  
29   AliFMDPedestalDA();
30   /** 
31    * Copy constructor 
32    * 
33    * @param pedDA Object to copy from
34    */  
35   AliFMDPedestalDA(const AliFMDPedestalDA & pedDA);
36   /** 
37    * Assignment operator 
38    * 
39    * @param pedDA Object to assign from
40    */  
41   AliFMDPedestalDA& operator=(const AliFMDPedestalDA&) { return *this; }
42   /** 
43    * Destructor
44    * 
45    */
46   virtual ~AliFMDPedestalDA();
47   /**
48    * Open our output files 
49    *
50    * The output files are named 
51    *
52    *   peds.csv
53    *   conditions.csv 
54    *   ddl3072.csv
55    *   ddl3073.csv
56    *   ddl3074.csv
57    *
58    * and existing files are rotated, or 
59    * 
60    *   peds_XXXXXXXXX.csv 
61    *   conditions_XXXXXXXXX.csv 
62    *   ddl3072.csv
63    *   ddl3073.csv
64    *   ddl3074.csv
65    *
66    * in case the run number is to be appended. 
67    * 
68    * @param appendRun if true, append run number (9 digits, zero
69    * padded) to the output file name(s).
70    *
71    * @return true on success 
72    */
73   Bool_t OpenFiles(Bool_t appendRun=false);
74   /** 
75    * Initialiser
76    * 
77    */  
78   void Init();
79  
80 protected:
81   enum { 
82     kPedestalOffset = 1, 
83     kNoiseOffset   = 2
84   };
85   /** 
86    * Add a channel to the containers. 
87    * 
88    * @param sectorArray  Array of sectors
89    * @param det          Detector 
90    * @param ring         Ring
91    * @param sec          Sector 
92    * @param strip        Strip
93    */
94   void AddChannelContainer(Array* sectorArray, UShort_t det, 
95                            Char_t ring, UShort_t sec, UShort_t strip);
96   /** 
97    * Add summary(s) for sectors 
98    * 
99    * @param secArray 
100    * @param det 
101    * @param ring 
102    * @param sector 
103    * @param nStrip 
104    */
105   virtual void AddSectorSummary(Array* secArray, UShort_t det, 
106                                 Char_t ring, UShort_t sector, 
107                                 UShort_t nStrip);
108   /** 
109    * Fill ADC values from a digit into the corresponding histogram.
110    * 
111    * @param digit Digit to fill ADC values for.
112    */
113   void FillChannels(AliFMDDigit* digit);
114   /** 
115    * Analyse a strip.  That is, compute the mean and spread of the ADC
116    * spectra for all strips.  Also output on files the values. 
117    * 
118    * @param det   Detector
119    * @param ring  Ring
120    * @param sec   Sector 
121    * @param strip Strip.
122    * @param h     Summary histogram with bins for sector and strip
123    */
124   void Analyse(UShort_t det, Char_t ring, UShort_t sec, UShort_t strip);
125   /** 
126    * Write headers to files. 
127    * 
128    */  
129   void WriteHeaderToFile();
130   /** 
131    * Called at the end of an event.
132    * 
133    */  
134   void FinishEvent() {}
135   /** 
136    * Called at the end of a job.  Fills in missing time-bins and
137    * closes output files  
138    * 
139    */  
140   void Terminate(TFile* );
141 private:
142   /** 
143    * Get the histogram corresponding to a strip sample.
144    * 
145    * @param det    Detector
146    * @param ring   Ring
147    * @param sec    Sector
148    * @param strip  Strip
149    * @param sample Sample
150    * 
151    * @return ADC spectra of a strip.
152    */
153   TH1S* GetChannel(UShort_t det, Char_t ring, UShort_t sec, 
154                    UShort_t strip, UInt_t sample);
155   /** 
156    * Get the summary for a sector
157    * 
158    * @param det    Detector
159    * @param ring   Ring 
160    * @param sec    Sector 
161    * @param pedNotNoise Option
162    * 
163    * @return histogram 
164    */
165   TH1F* GetSectorSummary(UShort_t det, Char_t   ring, UShort_t sec, 
166                          Bool_t   pedNotNoise);
167   /** 
168    * Calculate the hardware index
169    * 
170    * @param ddl    DDL number
171    * @param board  Board number
172    * @param altro  ALTRO number
173    * @param chan   Channel number
174    * 
175    * @return Index into hardware cache.
176    */
177   Int_t HWIndex(UShort_t ddl, UShort_t board, UShort_t altro, 
178                 UShort_t chan) const;
179   void FillinTimebins(std::ofstream& out, UShort_t ddl);
180   /** Current strip */ 
181   Int_t fCurrentChannel;                           //The current channel
182   /** Pedestal summary */ 
183   TH1F  fPedSummary;                               //Summary of pedestals
184   /** Noise summary */
185   TH1F  fNoiseSummary;                             //Summary of noises
186   /** Output file for zero-suppression for FMD1 */
187   std::ofstream fZSfileFMD1;                       //Stream for ZS FMD1
188   /** Output file for zero-suppression for FMD2 */
189   std::ofstream fZSfileFMD2;                       //Stream for ZS FMD2
190   /** Output file for zero-suppression for FMD3 */
191   std::ofstream fZSfileFMD3;                       //Stream for ZS FMD3 
192   /** The minimum timebin seen for all channels */
193   TArrayS fMinTimebin;                             //minimum timebin
194   /** The maximum timebin seen for all channels */
195   TArrayS fMaxTimebin;                             //maximum timebin
196   
197   void  MakeSummary(UShort_t det, Char_t ring);
198
199   TH2* fSummaryFMD1i;                              //Summary of FMD1
200   TH2* fSummaryFMD2i;                              //Summary of FMD2I 
201   TH2* fSummaryFMD2o;                              //Summary of FMD2O
202   TH2* fSummaryFMD3i;                              //Summary of FMD3I
203   TH2* fSummaryFMD3o;                              //Summary of FMD3O
204   
205   ClassDef(AliFMDPedestalDA,0)
206 };
207
208 inline Int_t
209 AliFMDPedestalDA::HWIndex(UShort_t ddl, UShort_t b, 
210                           UShort_t a, UShort_t c) const
211 {
212   // Save some array entries 
213   UShort_t lb = (b > 1 ? b-16+2 : b);
214   const Int_t kNDDL     = 3;
215   const Int_t kNBoard   = 4;
216   const Int_t kNAltro   = 3;
217   const Int_t kNChannel = 16;
218   Int_t idx =  c + kNChannel * (a + kNAltro * (lb + kNBoard * ddl));
219   if (idx > kNDDL * kNBoard * kNAltro * kNChannel) return -1;
220   return idx;
221 }
222
223 #endif
224 //
225 // Local Variables:
226 //  mode: C++
227 // End:
228 //